-
Notifications
You must be signed in to change notification settings - Fork 0
/
all_hits.C
177 lines (157 loc) · 6.63 KB
/
all_hits.C
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
#include <DDG4/DDG4Dict.h>
#include <DDG4/Geant4DataDump.h>
#include <TVector.h>
#include <TTree.h>
#include <TBranch.h>
#include <TLeaf.h>
#include <TH1.h>
#include <TH2.h>
#include <TCanvas.h>
#include <TMath.h>
#include <TLorentzVector.h>
#include <TLatex.h>
#include <time.h>
int singlebkg(TTree *tree, const char *hitname) {
tree->ResetBranchAddresses();
std::cout << "Processing " << hitname << std::endl;
int hitcnt = 0;
vector<dd4hep::sim::Geant4Calorimeter::Hit*> *hits = new vector<dd4hep::sim::Geant4Calorimeter::Hit*>;
tree -> SetBranchAddress(hitname, &hits);
std::cout << "open up branch " << hitname << std::endl;
for (int i = 0; i < tree->GetEntries(); ++i) {
tree -> GetEntry(i);
std::cout << "Processing event " << i << std::endl;
std::cout << "hit number " << hits -> size() << std::endl;
for (size_t j = 0; j < hits -> size(); ++j) {
dd4hep::sim::Geant4Calorimeter::Hit* hit = (*hits)[j];
double energy = hit -> energyDeposit;
hitcnt++;
/*
if (energy != 0 ){
hitcnt++;
}
*/
}
}
std::cout << hitcnt << std::endl;
delete hits;
return hitcnt;
}
int singlebkg_tracker(TTree *tree, const char *hitname) {
tree->ResetBranchAddresses();
int hitcnt = 0;
vector<dd4hep::sim::Geant4Tracker::Hit*> *hits = new vector<dd4hep::sim::Geant4Tracker::Hit*>;
tree -> SetBranchAddress(hitname, &hits);
for (int i = 0; i < tree->GetEntries(); ++i) {
tree -> GetEntry(i);
for (size_t j = 0; j < hits -> size(); ++j) {
dd4hep::sim::Geant4Tracker::Hit* hit = (*hits)[j];
double energy = hit -> energyDeposit;
if (energy != 0 ){
hitcnt++;
}
}
}
std::cout << hitcnt << std::endl;
delete hits;
return hitcnt;
}
void all_hits(const char *inputFile_sp, const char *inputFile_spw) {
gSystem -> Load("libDDG4Plugins.so");
gSystem -> Load("libDDG4.so");
gSystem -> Load("libDDCore.so");
TFile *file_sp = new TFile(inputFile_sp);
TFile *file_spw = new TFile(inputFile_spw);
TTree *tree_sp = (TTree*) file_sp -> Get("EVENT");
TTree *tree_spw = (TTree*) file_spw -> Get("EVENT");
int ecalbarrel_sp = singlebkg(tree_sp, "ECalBarrelHits");
int ecalendcap_sp = singlebkg(tree_sp, "ECalEndcapHits");
int hcalbarrel_sp = singlebkg(tree_sp, "HCalBarrelHits");
int hcalendcap_sp = singlebkg(tree_sp, "HCalEndcapHits");
int muonbarrel_sp = singlebkg(tree_sp, "MuonBarrelHits");
int muonendcap_sp = singlebkg(tree_sp, "MuonEndcapHits");
int lumical_sp = singlebkg(tree_sp, "LumiCalHits");
int beamcal_sp = singlebkg(tree_sp, "BeamCalHits");
int sivertexbarrel_sp = singlebkg_tracker(tree_sp, "SiVertexBarrelHits");
int sivertexendcap_sp = singlebkg_tracker(tree_sp, "SiVertexEndcapHits");
int sitrackerbarrel_sp = singlebkg_tracker(tree_sp, "SiTrackerBarrelHits");
int sitrackerendcap_sp = singlebkg_tracker(tree_sp, "SiTrackerEndcapHits");
int ecalbarrel_spw = singlebkg(tree_spw, "ECalBarrelHits");
int ecalendcap_spw = singlebkg(tree_spw, "ECalEndcapHits");
int hcalbarrel_spw = singlebkg(tree_spw, "HCalBarrelHits");
int hcalendcap_spw = singlebkg(tree_spw, "HCalEndcapHits");
int muonbarrel_spw = singlebkg(tree_spw, "MuonBarrelHits");
int muonendcap_spw = singlebkg(tree_spw, "MuonEndcapHits");
int lumical_spw = singlebkg(tree_spw, "LumiCalHits");
int beamcal_spw = singlebkg(tree_spw, "BeamCalHits");
int sivertexbarrel_spw = singlebkg_tracker(tree_spw, "SiVertexBarrelHits");
int sivertexendcap_spw = singlebkg_tracker(tree_spw, "SiVertexEndcapHits");
int sitrackerbarrel_spw = singlebkg_tracker(tree_spw, "SiTrackerBarrelHits");
int sitrackerendcap_spw = singlebkg_tracker(tree_spw, "SiTrackerEndcapHits");
TCanvas *c1 = new TCanvas("c1", "Comparison Bar Chart", 2400, 1800);
c1 -> SetLogy(1);
c1 -> SetGrid();
TH1F *h_sp = new TH1F("h_sp", "", 12, 0, 12);
h_sp -> SetMinimum(1);
h_sp -> SetBinContent(1, ecalbarrel_sp);
h_sp -> SetBinContent(2, ecalendcap_sp);
h_sp -> SetBinContent(3, hcalbarrel_sp);
h_sp -> SetBinContent(4, hcalendcap_sp);
h_sp -> SetBinContent(5, muonbarrel_sp);
h_sp -> SetBinContent(6, muonendcap_sp);
h_sp -> SetBinContent(7, lumical_sp);
h_sp -> SetBinContent(8, beamcal_sp);
h_sp -> SetBinContent(9, sivertexbarrel_sp);
h_sp -> SetBinContent(10, sivertexendcap_sp);
h_sp -> SetBinContent(11, sitrackerbarrel_sp);
h_sp -> SetBinContent(12, sitrackerendcap_sp);
h_sp -> SetFillColor(kRed);
h_sp -> SetFillStyle(1001);
h_sp -> SetBarWidth(0.8);
h_sp -> SetBarOffset(0.1);
h_sp -> SetStats(0);
TH1F *h_spw = new TH1F("h_spw", "", 12, 0, 12);
h_spw -> SetBinContent(1, ecalbarrel_spw);
h_spw -> SetBinContent(2, ecalendcap_spw);
h_spw -> SetBinContent(3, hcalbarrel_spw);
h_spw -> SetBinContent(4, hcalendcap_spw);
h_spw -> SetBinContent(5, muonbarrel_spw);
h_spw -> SetBinContent(6, muonendcap_spw);
h_spw -> SetBinContent(7, lumical_spw);
h_spw -> SetBinContent(8, beamcal_spw);
h_spw -> SetBinContent(9, sivertexbarrel_spw);
h_spw -> SetBinContent(10, sivertexendcap_spw);
h_spw -> SetBinContent(11, sitrackerbarrel_spw);
h_spw -> SetBinContent(12, sitrackerendcap_spw);
h_spw -> SetFillStyle(1001);
h_spw -> SetFillColor(kWhite);
h_spw -> SetBarWidth(0.8);
h_spw -> SetBarOffset(0.1);
h_spw -> SetStats(0);
h_sp -> GetXaxis() -> SetBinLabel(1, "ECalBarrel");
h_sp -> GetXaxis() -> SetBinLabel(2, "ECalEndcap");
h_sp -> GetXaxis() -> SetBinLabel(3, "HCalBarrel");
h_sp -> GetXaxis() -> SetBinLabel(4, "HCalEndcap");
h_sp -> GetXaxis() -> SetBinLabel(5, "MuonBarrel");
h_sp -> GetXaxis() -> SetBinLabel(6, "MuonEndcap");
h_sp -> GetXaxis() -> SetBinLabel(7, "LumiCal");
h_sp -> GetXaxis() -> SetBinLabel(8, "BeamCal");
h_sp -> GetXaxis() -> SetBinLabel(9, "SiVertexBarrel");
h_sp -> GetXaxis() -> SetBinLabel(10, "SiVertexEndcap");
h_sp -> GetXaxis() -> SetBinLabel(11, "SiTrackerBarrel");
h_sp -> GetXaxis() -> SetBinLabel(12, "SiTrackerEndcap");
h_sp -> GetYaxis() -> SetTitle("Number of Hits");
h_sp -> Draw("B");
h_spw -> Draw("SAME B");
TH1F* h_spw_copy = new TH1F(*h_spw);
h_spw_copy -> SetFillStyle(3353);
h_spw_copy -> SetFillColor(kRed);
h_spw_copy -> Draw("SAME B");
TLegend *leg = new TLegend(0.75, 0.75, 0.9, 0.9);
leg -> AddEntry(h_sp, "5 Spoilers", "f");
leg -> AddEntry(h_spw, "5 Spoilers + Wall", "f");
leg -> Draw("SAME");
c1 -> Update();
c1 -> SaveAs("SubDetector.png");
file_sp -> Close();
}