15 |
|
showLegend = false; |
16 |
|
logY = true; |
17 |
|
addTrackJets = true; |
18 |
+ |
addHitDetInfo = true; |
19 |
+ |
diTrackMass = true; |
20 |
+ |
addTrigger = true; |
21 |
+ |
addTrackJets = false; |
22 |
+ |
addEventInfo = false; |
23 |
+ |
addTower = false; |
24 |
|
verbose = true; |
25 |
|
|
26 |
+ |
globalCuts=""; |
27 |
+ |
|
28 |
+ |
recreateTree = false; //force recreation of friend tree |
29 |
+ |
|
30 |
|
} |
31 |
|
|
32 |
|
//------------------------------------------------------------------ |
33 |
|
//Fill object PlotTool with Chains constructed from files from given source |
34 |
|
|
35 |
|
int PlotTool::init(string fileName, string dirPath, string treeName, |
36 |
< |
string fileLabel) { |
37 |
< |
this->New(this->GetEntries() ); |
38 |
< |
int currChain = this->GetEntries() - 1; |
39 |
< |
|
40 |
< |
if (currChain < 0) |
41 |
< |
return currChain; |
42 |
< |
|
43 |
< |
TStopwatch timer; |
44 |
< |
timer.Start(); |
45 |
< |
|
46 |
< |
|
47 |
< |
fileNames.clear(); |
48 |
< |
|
49 |
< |
//check if alternative label is different from default(searchString) |
50 |
< |
if (fileLabel=="") { |
51 |
< |
fileLabel=fileName; |
52 |
< |
} |
53 |
< |
((TChain*) this->At(currChain))->SetName(fileLabel.c_str()); |
54 |
< |
TSystemDirectory dir("sourceDir", dirPath.c_str()); |
55 |
< |
TList *files = dir.GetListOfFiles(); |
56 |
< |
if (files) { |
57 |
< |
TIter next(files); |
58 |
< |
TSystemFile *file; |
59 |
< |
TString fname; |
60 |
< |
string filePath; |
61 |
< |
|
62 |
< |
if(verbose) cout<<"Open"<<dirPath.c_str()<<" Search for .root files that contain: " |
63 |
< |
<<fileName.c_str()<<endl; |
64 |
< |
|
65 |
< |
while ((file=(TSystemFile*)next())) { |
66 |
< |
fname = file->GetName(); |
67 |
< |
if (!fname.EndsWith(".root")) |
68 |
< |
continue; |
69 |
< |
if (!fname.Contains(fileName.c_str())) |
70 |
< |
continue; |
71 |
< |
|
72 |
< |
filePath = dirPath; |
73 |
< |
filePath += fname.Data(); |
74 |
< |
//fwlite::ChainEvent to lop over events, jets, etc |
75 |
< |
fileNames.push_back(filePath.c_str()); |
76 |
< |
|
77 |
< |
if (((TChain*) this->At(currChain))->AddFile(filePath.c_str(), -1, |
78 |
< |
treeName.c_str()) ) |
79 |
< |
if(verbose) cout<<"Chained "<<((TChain*) this->At(currChain))->GetNtrees()<<" file(s) with "<<((TChain*) this->At(currChain))->GetEntries()<<" events."<<endl; |
80 |
< |
else |
81 |
< |
return -1; |
82 |
< |
|
83 |
< |
} |
84 |
< |
} else |
85 |
< |
return -1; |
86 |
< |
|
87 |
< |
for (int i=0; i<((TChain*) this->At(currChain))->GetListOfBranches()->GetEntries(); ++i) { |
88 |
< |
|
89 |
< |
string s(((TChain*) this->At(currChain))->GetListOfBranches()->At(i)->GetName()); |
90 |
< |
|
91 |
< |
string branch_alias = s; |
92 |
< |
string branch_name = s; |
93 |
< |
if (s.find(".", s.size()-1) != string::npos) |
94 |
< |
branch_name += "obj"; |
95 |
< |
|
96 |
< |
size_t a = s.find("_"); |
97 |
< |
if (a != string::npos) { |
98 |
< |
size_t b = s.find("_", a+1); |
99 |
< |
if (b != string::npos) { |
100 |
< |
size_t c = s.find("_", b+1); |
101 |
< |
if (c != string::npos) { |
92 |
< |
string _prod =s.substr(0,a); |
93 |
< |
string _label =s.substr(a+1, b-a-1); |
94 |
< |
string _instance =s.substr(b+1, c-b-1); |
95 |
< |
branch_alias = _label; |
96 |
< |
if(_instance.length() > 0 ) { |
97 |
< |
branch_alias += "_"; |
98 |
< |
branch_alias += _instance; |
99 |
< |
((TChain*) this->At(currChain))->SetAlias(_instance.c_str(), |
100 |
< |
branch_name.c_str()); |
101 |
< |
} |
102 |
< |
string branch_alias_full = _prod + "_" + branch_alias; |
103 |
< |
((TChain*) this->At(currChain))->SetAlias(branch_alias_full.c_str(), |
104 |
< |
branch_name.c_str()); |
105 |
< |
} |
106 |
< |
} |
107 |
< |
} |
108 |
< |
|
109 |
< |
((TChain*) this->At(currChain))->SetAlias(branch_alias.c_str(), |
110 |
< |
branch_name.c_str()); |
36 |
> |
string fileLabel) { |
37 |
> |
this->New(this->GetEntries() ); |
38 |
> |
int currChain = this->GetEntries() - 1; |
39 |
> |
|
40 |
> |
if (currChain < 0) |
41 |
> |
return currChain; |
42 |
> |
|
43 |
> |
TStopwatch timer; |
44 |
> |
timer.Start(); |
45 |
> |
|
46 |
> |
|
47 |
> |
fileNames.clear(); |
48 |
> |
|
49 |
> |
//check if alternative label is different from default(searchString) |
50 |
> |
if (fileLabel=="") { |
51 |
> |
fileLabel=fileName; |
52 |
> |
} |
53 |
> |
((TChain*) this->At(currChain))->SetName(fileLabel.c_str()); |
54 |
> |
|
55 |
> |
TList *files = new TList(); |
56 |
> |
TSystemFile* sysFile = 0; |
57 |
> |
if(fileName.find(".") != string::npos) { |
58 |
> |
ifstream f(fileName.c_str()); |
59 |
> |
if( ! f.is_open() ) return -1; |
60 |
> |
string line; |
61 |
> |
|
62 |
> |
while (!f.eof()) { |
63 |
> |
getline(f,line); |
64 |
> |
sysFile = new TSystemFile(line.c_str(),dirPath.c_str()); |
65 |
> |
files->Add(sysFile); |
66 |
> |
} |
67 |
> |
|
68 |
> |
|
69 |
> |
} else { |
70 |
> |
TSystemDirectory dir("sourceDir", dirPath.c_str()); |
71 |
> |
files = dir.GetListOfFiles(); |
72 |
> |
} |
73 |
> |
if (files->GetEntries()>0) { |
74 |
> |
TIter next(files); |
75 |
> |
TSystemFile *file; |
76 |
> |
TString fname; |
77 |
> |
string filePath; |
78 |
> |
|
79 |
> |
if(verbose && fileName.find(".") == string::npos ) cout<<"Open"<<dirPath.c_str()<<" Search for .root files that contain: " |
80 |
> |
<<fileName.c_str()<<endl; |
81 |
> |
if(verbose && fileName.find(".") != string::npos ) cout<<"Open"<<dirPath.c_str()<<" Search lines with .root in: " |
82 |
> |
<<fileName.c_str()<<endl; |
83 |
> |
|
84 |
> |
|
85 |
> |
while ((file=(TSystemFile*)next())) { |
86 |
> |
fname = file->GetName(); |
87 |
> |
if (!fname.EndsWith(".root")) |
88 |
> |
continue; |
89 |
> |
if (!fname.Contains(fileName.c_str()) && fileName.find(".") == string::npos ) |
90 |
> |
continue; |
91 |
> |
|
92 |
> |
filePath = dirPath; |
93 |
> |
filePath += fname.Data(); |
94 |
> |
//fwlite::ChainEvent to lop over events, jets, etc |
95 |
> |
fileNames.push_back(filePath.c_str()); |
96 |
> |
|
97 |
> |
if (((TChain*) this->At(currChain))->AddFile(filePath.c_str(), -1, |
98 |
> |
treeName.c_str()) ) |
99 |
> |
if(verbose) cout<<"Chained "<<((TChain*) this->At(currChain))->GetNtrees()<<" file(s) with "<<((TChain*) this->At(currChain))->GetEntries()<<" events."<<endl; |
100 |
> |
else |
101 |
> |
return -1; |
102 |
|
|
103 |
+ |
} |
104 |
+ |
} else |
105 |
+ |
return -1; |
106 |
+ |
|
107 |
+ |
for (int i=0; i<((TChain*) this->At(currChain))->GetListOfBranches()->GetEntries(); ++i) { |
108 |
+ |
|
109 |
+ |
string s(((TChain*) this->At(currChain))->GetListOfBranches()->At(i)->GetName()); |
110 |
+ |
|
111 |
+ |
string branch_alias = s; |
112 |
+ |
string branch_name = s; |
113 |
+ |
if (s.find(".", s.size()-1) != string::npos) |
114 |
+ |
branch_name += "obj"; |
115 |
+ |
|
116 |
+ |
size_t a = s.find("_"); |
117 |
+ |
if (a != string::npos) { |
118 |
+ |
size_t b = s.find("_", a+1); |
119 |
+ |
if (b != string::npos) { |
120 |
+ |
size_t c = s.find("_", b+1); |
121 |
+ |
if (c != string::npos) { |
122 |
+ |
string _prod =s.substr(0,a); |
123 |
+ |
string _label =s.substr(a+1, b-a-1); |
124 |
+ |
string _instance =s.substr(b+1, c-b-1); |
125 |
+ |
branch_alias = _label; |
126 |
+ |
if(_instance.length() > 0 ) { |
127 |
+ |
branch_alias += "_"; |
128 |
+ |
branch_alias += _instance; |
129 |
+ |
((TChain*) this->At(currChain))->SetAlias(_instance.c_str(), |
130 |
+ |
branch_name.c_str()); |
131 |
+ |
} |
132 |
+ |
string branch_alias_full = _prod + "_" + branch_alias; |
133 |
+ |
((TChain*) this->At(currChain))->SetAlias(branch_alias_full.c_str(), |
134 |
+ |
branch_name.c_str()); |
135 |
|
} |
136 |
+ |
} |
137 |
+ |
} |
138 |
|
|
139 |
< |
// add branch with track Jets |
140 |
< |
|
116 |
< |
if( addTrackJets ) { |
117 |
< |
|
118 |
< |
//make file for tree friends (adding additional, computed branches) |
119 |
< |
string friendFileName("/scratch/hh/current/cms/user/"); |
120 |
< |
friendFileName += gSystem->GetUserInfo()->fUser; |
121 |
< |
friendFileName += "/temp/", |
122 |
< |
friendFileName += fileName; |
123 |
< |
friendFileName += ".root"; |
124 |
< |
TFile *f = new TFile(friendFileName.c_str(),"recreate"); |
139 |
> |
((TChain*) this->At(currChain))->SetAlias(branch_alias.c_str(), |
140 |
> |
branch_name.c_str()); |
141 |
|
|
142 |
< |
if( f->IsZombie() ) return -1; |
142 |
> |
} |
143 |
|
|
144 |
< |
string friendTreeName("friendTree"); |
145 |
< |
//char number = currChain; |
146 |
< |
//friendTreeName += number; |
147 |
< |
//TTree *friendTree = new TTree("friendTree","friendTree"); |
148 |
< |
TTree *friendTree = new TTree(friendTreeName.c_str(),friendTreeName.c_str()); |
149 |
< |
|
150 |
< |
int nJetsKT; |
151 |
< |
TrackJetKT = new float [100]; |
152 |
< |
fwlite::ChainEvent ev(fileNames); |
144 |
> |
if( addEventInfo || addTrackJets || addTower || addTrackJets || addHitDetInfo || diTrackMass || addTrigger) { |
145 |
> |
|
146 |
> |
if(verbose) cout<<"add friend tree with additional variables..."<<endl; |
147 |
> |
|
148 |
> |
//make file for tree friends (adding additional, computed branches) |
149 |
> |
string friendFileName("/scratch/hh/current/cms/user/"); |
150 |
> |
friendFileName += gSystem->GetUserInfo()->fUser; |
151 |
> |
friendFileName += "/temp/"; |
152 |
> |
friendFileName += fileLabel; |
153 |
> |
friendFileName += ".root"; |
154 |
> |
string fileOpt = "update"; |
155 |
> |
if( recreateTree ) fileOpt = "recreate"; |
156 |
> |
|
157 |
> |
TFile *f = new TFile(friendFileName.c_str(),fileOpt.c_str()); |
158 |
> |
|
159 |
> |
if( f->IsZombie() ) return -1; |
160 |
> |
|
161 |
> |
string friendTreeName("friendTree"); |
162 |
> |
//char number = currChain; |
163 |
> |
//friendTreeName += number; |
164 |
> |
//TTree *friendTree = new TTree("friendTree","friendTree"); |
165 |
> |
|
166 |
> |
if(! f->FindKey(friendTreeName.c_str())) { |
167 |
> |
if(verbose) cout<<"calculating additional variables..."<<endl; |
168 |
> |
|
169 |
> |
|
170 |
> |
TTree *friendTree = new TTree(friendTreeName.c_str(),friendTreeName.c_str()); |
171 |
> |
fwlite::ChainEvent ev(fileNames); |
172 |
> |
int _event, _run, _lumi; |
173 |
> |
|
174 |
> |
//tower data |
175 |
> |
const int kMAX = 10000; |
176 |
> |
int NobjTowCal; |
177 |
> |
towet = new float [ kMAX ]; |
178 |
> |
toweta = new float [ kMAX ]; |
179 |
> |
towphi = new float [ kMAX ]; |
180 |
> |
towen = new float [ kMAX ]; |
181 |
> |
towem = new float [ kMAX ]; |
182 |
> |
towhd = new float [ kMAX ]; |
183 |
> |
towoe = new float [ kMAX ]; |
184 |
> |
towid_phi = new int[ kMAX ]; |
185 |
> |
towid_eta = new int[ kMAX ]; |
186 |
> |
towid = new int[ kMAX ]; |
187 |
> |
|
188 |
> |
int nJetsKT; |
189 |
> |
TrackJetKT = new float [100]; |
190 |
> |
int nTracks; |
191 |
> |
TrackDetE = new float [3000]; |
192 |
> |
TrackDetEECAL = new float [3000]; |
193 |
> |
float DiTrackMass; |
194 |
> |
bool Trigger; |
195 |
> |
bool Trigger1; |
196 |
> |
|
197 |
> |
|
198 |
> |
|
199 |
> |
if( addEventInfo ) { |
200 |
> |
|
201 |
> |
|
202 |
> |
friendTree->Branch("event", &_event, "event/I"); |
203 |
> |
friendTree->Branch("run", &_run, "run/I"); |
204 |
> |
friendTree->Branch("lumi", &_lumi, "lumi/I"); |
205 |
> |
|
206 |
> |
} |
207 |
> |
|
208 |
> |
if( addTrackJets ) { |
209 |
> |
|
210 |
> |
|
211 |
> |
friendTree->Branch("nJetsKT", &nJetsKT, "nJetsKT/I"); |
212 |
> |
friendTree->Branch("TrackJetKT", TrackJetKT, "TrackJetKT[nJetsKT]/F"); |
213 |
> |
} |
214 |
> |
|
215 |
> |
if( addTower) { |
216 |
> |
|
217 |
> |
// CaloTower branches |
218 |
> |
friendTree->Branch( "NobjTowCal",&NobjTowCal,"NobjTowCal/I" ); |
219 |
> |
friendTree->Branch( "TowId", towid, "TowId[NobjTowCal]/I" ); |
220 |
> |
friendTree->Branch( "TowId_phi", towid_phi, "TowId_phi[NobjTowCal]/I" ); |
221 |
> |
friendTree->Branch( "TowId_eta", towid_eta, "TowId_eta[NobjTowCal]/I" ); |
222 |
> |
friendTree->Branch( "TowEt", towet, "TowEt[NobjTowCal]/F" ); |
223 |
> |
friendTree->Branch( "TowEta", toweta, "TowEta[NobjTowCal]/F" ); |
224 |
> |
friendTree->Branch( "TowPhi", towphi, "TowPhi[NobjTowCal]/F" ); |
225 |
> |
friendTree->Branch( "TowE", towen, "TowE[NobjTowCal]/F" ); |
226 |
> |
friendTree->Branch( "TowEm", towem, "TowEm[NobjTowCal]/F" ); |
227 |
> |
friendTree->Branch( "TowHad", towhd, "TowHad[NobjTowCal]/F" ); |
228 |
> |
friendTree ->Branch( "TowOE", towoe, "TowOE[NobjTowCal]/F" ); |
229 |
> |
|
230 |
> |
|
231 |
> |
} |
232 |
> |
|
233 |
> |
if( addTrackJets){ |
234 |
> |
friendTree->Branch("nJetsKT", &nJetsKT, "nJetsKT/I"); |
235 |
> |
friendTree->Branch("TrackJetKT", TrackJetKT, "TrackJetKT[nJetsKT]/F"); |
236 |
> |
} |
237 |
> |
|
238 |
> |
if( addHitDetInfo){ |
239 |
> |
friendTree->Branch("nTracks", &nTracks, "nTracks/I"); |
240 |
> |
friendTree->Branch("TrackDetE", TrackDetE, "TrackDetE[nTracks]/F"); |
241 |
> |
friendTree->Branch("TrackDetEECAL", TrackDetEECAL, "TrackDetEECAL[nTracks]/F"); |
242 |
> |
} |
243 |
> |
if(diTrackMass) friendTree->Branch("DiTrackMass", &DiTrackMass, "DiTrackMass/F"); |
244 |
> |
if(addTrigger) { |
245 |
> |
friendTree->Branch("Trigger", &Trigger, "Trigger/O"); |
246 |
> |
friendTree->Branch("Trigger1", &Trigger1, "Trigger1/O"); |
247 |
> |
} |
248 |
> |
|
249 |
> |
int tenth = ev.size() / 10; |
250 |
> |
int eventNum =0; |
251 |
> |
for (ev.toBegin(); !ev.atEnd(); ++ev, ++eventNum) { |
252 |
> |
|
253 |
> |
|
254 |
> |
if( addEventInfo ) { |
255 |
> |
|
256 |
> |
|
257 |
> |
if(eventNum==0) { |
258 |
> |
// fwlite::Handle<edm::TriggerResults> hltHandle; |
259 |
> |
// hltHandle.getByLabel(ev, "TriggerResults"); |
260 |
> |
|
261 |
> |
// fwlite::Handle<edm::TriggerResults> hTriggerResults; |
262 |
> |
|
263 |
> |
// hTriggerResults.getByLabel(ev, "TriggerResults","","TEST"); |
264 |
> |
// fwlite::TriggerNames const& triggerNames = ev.triggerNames(*hTriggerResults); |
265 |
> |
|
266 |
> |
|
267 |
> |
// // std::vector<std::string> const& names = triggerNames.triggerNames(); |
268 |
> |
// for (unsigned i = 0; i < triggerNames.size(); ++i) { |
269 |
> |
// std::cout << i << " " << triggerNames.triggerName(i) << std::endl; |
270 |
> |
// } |
271 |
> |
} |
272 |
|
|
273 |
< |
friendTree->Branch("nJetsKT", &nJetsKT, "nJetsKT/I"); |
274 |
< |
friendTree->Branch("TrackJetKT", TrackJetKT, "TrackJetKT[nJetsKT]/F"); |
273 |
> |
_event = ev.id().event(); |
274 |
> |
_run = ev.id().run(); |
275 |
> |
_lumi = ev.luminosityBlock(); |
276 |
|
|
277 |
< |
if(verbose) cout<<"calculating additional variables..."<<endl; |
142 |
< |
|
143 |
< |
|
144 |
< |
|
145 |
< |
int tenth = ev.size() / 10; |
146 |
< |
int eventNum =0; |
147 |
< |
for (ev.toBegin(); !ev.atEnd(); ++ev, ++eventNum) { |
277 |
> |
} |
278 |
|
|
279 |
+ |
if( addTrackJets) |
280 |
+ |
{ |
281 |
|
fwlite::Handle<reco::CaloJetCollection> jets; |
282 |
|
jets.getByLabel(ev, "antikt5CaloJets"); |
283 |
< |
|
283 |
> |
|
284 |
|
fwlite::Handle<reco::TrackCollection> tracks; |
285 |
|
tracks.getByLabel(ev, "generalTracks"); |
286 |
< |
|
286 |
> |
|
287 |
|
if (!jets.isValid()) |
288 |
|
continue; |
289 |
|
if (!tracks.isValid()) |
302 |
|
TrackJetKT[nJetsKT] = trackSum; |
303 |
|
nJetsKT++; |
304 |
|
} |
305 |
< |
friendTree->Fill(); |
306 |
< |
|
307 |
< |
if( eventNum != 0 && eventNum%tenth == 0) cout<<"Processed "<<eventNum <<" of "<<ev.size()<<" events. "<<endl; |
305 |
> |
} |
306 |
> |
|
307 |
> |
if(addHitDetInfo) |
308 |
> |
{ |
309 |
> |
fwlite::Handle<reco::TrackCollection> tracks; |
310 |
> |
tracks.getByLabel(ev, "generalTracks"); |
311 |
> |
|
312 |
> |
nTracks = 0; |
313 |
> |
|
314 |
> |
if (!tracks.isValid()) |
315 |
> |
continue; |
316 |
> |
|
317 |
> |
for (reco::TrackCollection::const_iterator track = tracks->begin(); track |
318 |
> |
!=tracks->end(); track++) { |
319 |
> |
fwlite::Handle<vector <reco::CaloCluster> > CaloClusters; |
320 |
> |
CaloClusters.getByLabel(ev, "hybridSuperClusters"); //add instance |
321 |
> |
//CaloClusters.getByLabel(ev, "multi5x5BasicClusters"); |
322 |
> |
|
323 |
> |
//fwlite::Handle<vector <CaloTower> > CaloTowers; |
324 |
> |
//CaloTowers.getByLabel(ev, "towerMaker"); |
325 |
> |
|
326 |
> |
double DR = 100; |
327 |
> |
double DetE = 0; |
328 |
> |
double DetEECAL = 0; |
329 |
> |
|
330 |
> |
if (CaloClusters.isValid()){ //always fails |
331 |
> |
//if (CaloTowers.isValid()){ |
332 |
> |
for (vector<reco::CaloCluster>::const_iterator CaloCluster = CaloClusters->begin(); CaloCluster |
333 |
> |
!=CaloClusters->end(); CaloCluster++) { |
334 |
> |
// int DetectorId = track->outerDetId(); //unfortuately only the Tracker DetId... |
335 |
> |
// /DetId *dId = new DetId(DetectorId); |
336 |
> |
//cout<<dId->det()<<endl; |
337 |
> |
|
338 |
> |
|
339 |
> |
if(deltaR( CaloCluster->eta(), CaloCluster->phi(), track->outerEta(), track->phi()) < DR) |
340 |
> |
{ |
341 |
> |
DetE = CaloCluster->energy(); |
342 |
> |
if(CaloCluster->caloID().detector(reco::CaloID::DET_ECAL_BARREL) ||CaloCluster->caloID().detector(reco::CaloID::DET_ECAL_ENDCAP)) |
343 |
> |
DetEECAL = CaloCluster->energy(); |
344 |
> |
} |
345 |
> |
} |
346 |
> |
} |
347 |
> |
|
348 |
> |
TrackDetE[nTracks] = DetE; |
349 |
> |
TrackDetEECAL[nTracks] = DetEECAL; |
350 |
> |
|
351 |
> |
|
352 |
> |
nTracks++; |
353 |
> |
if(nTracks > 2990) cout<<"To many Tracks!!!!!!!!!"<<endl; |
354 |
> |
} |
355 |
> |
} |
356 |
> |
|
357 |
> |
if(diTrackMass) |
358 |
> |
{ |
359 |
> |
fwlite::Handle<reco::TrackCollection> tracks; |
360 |
> |
tracks.getByLabel(ev, "generalTracks"); |
361 |
> |
|
362 |
> |
DiTrackMass = 0; |
363 |
> |
|
364 |
> |
if (!tracks.isValid()) |
365 |
> |
continue; |
366 |
> |
|
367 |
> |
for (reco::TrackCollection::const_iterator track = tracks->begin(); track |
368 |
> |
!=tracks->end(); track++) { |
369 |
> |
if(!(track->d0() < 2 && track->dz() < 10 && track->numberOfValidHits() > 7)) continue; |
370 |
> |
for (reco::TrackCollection::const_iterator track1 = tracks->begin(); track1 |
371 |
> |
!=tracks->end(); track1++) { |
372 |
> |
if(!(track1->d0() < 2 && track1->dz() < 10 && track1->numberOfValidHits() > 7) || track1 == track) continue; |
373 |
> |
|
374 |
> |
TLorentzVector tr1(track->px(), track->py(), track->pz(), track->p() ); |
375 |
> |
TLorentzVector tr2(track1->px(), track1->py(), track1->pz(), track1->p() ); |
376 |
> |
|
377 |
> |
double result = (tr1 + tr2).Mag(); |
378 |
> |
|
379 |
> |
if(result > DiTrackMass) DiTrackMass = result; |
380 |
> |
|
381 |
> |
} |
382 |
> |
} |
383 |
> |
|
384 |
> |
} |
385 |
> |
|
386 |
> |
if(addTrigger) |
387 |
> |
{ |
388 |
> |
|
389 |
> |
Trigger = false; |
390 |
> |
Trigger1 = false; |
391 |
> |
|
392 |
> |
fwlite::Handle< L1GlobalTriggerReadoutRecord> gtReadoutRecord; |
393 |
> |
gtReadoutRecord.getByLabel(ev, "gtDigis"); |
394 |
> |
//edm::Handle< L1GlobalTriggerReadoutRecord > gtReadoutRecord; |
395 |
> |
//event.getByLabel( edm::InputTag("gtDigis"), gtReadoutRecord); |
396 |
> |
|
397 |
> |
if(!gtReadoutRecord.isValid()) continue; |
398 |
> |
|
399 |
> |
|
400 |
> |
const TechnicalTriggerWord& technicalTriggerWordBeforeMask = gtReadoutRecord->technicalTriggerWord(); |
401 |
> |
|
402 |
> |
|
403 |
> |
//std::vector<bool>& technicalTriggerWordBeforeMask = gtReadoutRecord->technicalTriggerWord(); |
404 |
> |
|
405 |
> |
bool techTrigger0 = technicalTriggerWordBeforeMask.at(0); |
406 |
> |
bool techTrigger40 = technicalTriggerWordBeforeMask.at(40); |
407 |
> |
bool techTrigger41 = technicalTriggerWordBeforeMask.at(41); |
408 |
> |
bool techTrigger36 = technicalTriggerWordBeforeMask.at(36); |
409 |
> |
bool techTrigger37 = technicalTriggerWordBeforeMask.at(37); |
410 |
> |
bool techTrigger38 = technicalTriggerWordBeforeMask.at(38); |
411 |
> |
bool techTrigger39 = technicalTriggerWordBeforeMask.at(39); |
412 |
> |
|
413 |
> |
if(techTrigger0 && (techTrigger40 || techTrigger41)) Trigger = true; |
414 |
> |
if(Trigger && !techTrigger36 && !techTrigger37 && !techTrigger38 && !techTrigger39) Trigger1 = true; |
415 |
> |
} |
416 |
|
|
417 |
+ |
if( addTower) { |
418 |
+ |
fwlite::Handle<CaloTowerCollection> towers; |
419 |
+ |
towers.getByLabel(ev, "towerMaker"); |
420 |
+ |
|
421 |
+ |
int jtow = 0; |
422 |
+ |
NobjTowCal=towers->size(); |
423 |
+ |
for(CaloTowerCollection::const_iterator tow = towers->begin(); |
424 |
+ |
tow != towers->end(); ++tow, ++jtow){ |
425 |
+ |
towet [jtow] = tow->et(); |
426 |
+ |
toweta[jtow] = tow->eta(); |
427 |
+ |
towphi[jtow] = tow->phi(); |
428 |
+ |
towen [jtow] = tow->energy(); |
429 |
+ |
towem [jtow] = tow->emEnergy(); |
430 |
+ |
towhd [jtow] = tow->hadEnergy(); |
431 |
+ |
towoe [jtow] = tow->outerEnergy(); |
432 |
+ |
towid_phi[jtow] = tow->id().iphi(); |
433 |
+ |
towid_eta[jtow] = tow->id().ieta(); |
434 |
+ |
towid [jtow] = tow->id().rawId(); |
435 |
|
} |
178 |
– |
f->cd(); |
179 |
– |
friendTree->Write(); |
180 |
– |
f->Close(); |
181 |
– |
((TChain*) this->At(currChain))->AddFriend(friendTreeName.c_str(), |
182 |
– |
friendFileName.c_str()); |
436 |
|
} |
437 |
+ |
friendTree->Fill(); |
438 |
+ |
|
439 |
+ |
if( eventNum != 0 && eventNum%tenth == 0) cout<<"Processed "<<eventNum <<" of "<<ev.size()<<" events. "<<endl; |
440 |
+ |
|
441 |
+ |
} |
442 |
+ |
f->cd(); |
443 |
+ |
friendTree->Write(); |
444 |
+ |
} |
445 |
+ |
f->Close(); |
446 |
+ |
((TChain*) this->At(currChain))->AddFriend(friendTreeName.c_str(), |
447 |
+ |
friendFileName.c_str()); |
448 |
+ |
|
449 |
+ |
} |
450 |
+ |
|
451 |
|
|
452 |
< |
timer.Stop(); |
453 |
< |
if(verbose) timer.Print(); |
452 |
> |
timer.Stop(); |
453 |
> |
if(verbose) timer.Print(); |
454 |
|
|
455 |
< |
return this->GetEntries(); |
455 |
> |
return this->GetEntries(); |
456 |
|
|
457 |
|
} |
458 |
|
//------------------------------------------------------------------ |
464 |
|
return -1; |
465 |
|
|
466 |
|
TStopwatch timer; |
467 |
< |
timer.Start(); |
467 |
> |
if(verbose) { |
468 |
> |
cout<<"Plot: "<<histName<<" "<<cutName<<" from chain "<<this->At(chainIndex)->GetName()<<endl; |
469 |
> |
timer.Start(); |
470 |
> |
} |
471 |
|
|
472 |
|
int currN = nEntries; |
473 |
|
if (nEntries < 0) |
528 |
|
|
529 |
|
|
530 |
|
//Draw histogram: |
531 |
< |
int draw_err = ((TChain*) this->At(chainIndex))->Draw(histName.c_str(), cutName.c_str(), |
531 |
> |
string cutNameWithGlobal = cutName; |
532 |
> |
if(cutName!="" && globalCuts!="") cutNameWithGlobal += "&&"; |
533 |
> |
if(globalCuts!="") cutNameWithGlobal += globalCuts; |
534 |
> |
|
535 |
> |
int draw_err = ((TChain*) this->At(chainIndex))->Draw(histName.c_str(), cutNameWithGlobal.c_str(), |
536 |
|
currOpt.c_str(), currN); |
537 |
|
if (draw_err < 0) |
538 |
|
return draw_err; |
559 |
|
setCanvas( pads_[currPadName.str()] ); |
560 |
|
} |
561 |
|
|
562 |
< |
timer.Stop(); |
563 |
< |
if(verbose) { |
564 |
< |
cout<<"Done: "<<currN<<" events in "<<histName<<" "<<cutName<<" from chain "<<this->At(chainIndex)->GetName()<<endl; |
562 |
> |
|
563 |
> |
if(verbose && draw_err > 0) { |
564 |
> |
timer.Stop(); |
565 |
> |
cout<<"Done: Selected "<<draw_err<<" objects in "<< currN <<" processed events."<<endl; |
566 |
|
timer.Print(); |
567 |
|
} |
568 |
|
return draw_err; |
646 |
|
int PlotTool::updatePads() { |
647 |
|
|
648 |
|
for (map< string, TCanvas* >::iterator it=pads_.begin() ; it != pads_.end(); ++it) { |
649 |
< |
if (gROOT->GetListOfCanvases()->FindObject((*it).first.c_str() ) ) { |
650 |
< |
(*it).second->Draw(); |
651 |
< |
setCanvas((*it).second); |
652 |
< |
} else |
653 |
< |
pads_.erase(it); |
649 |
> |
if ( ! gROOT->GetListOfCanvases()->FindObject((*it).first.c_str() ) ) { |
650 |
> |
pads_.erase(it); |
651 |
> |
continue; |
652 |
> |
} |
653 |
> |
if( (*it).second->GetListOfPrimitives()->GetEntries() == 0 ) { |
654 |
> |
(*it).second->Close(); |
655 |
> |
pads_.erase(it); |
656 |
> |
continue; |
657 |
> |
} |
658 |
> |
(*it).second->Draw(); |
659 |
> |
setCanvas((*it).second); |
660 |
> |
|
661 |
|
} |
662 |
|
|
663 |
|
return pads_.size(); |
802 |
|
string x = thisHist->GetXaxis()->GetTitle(); |
803 |
|
string y = thisHist->GetYaxis()->GetTitle(); |
804 |
|
|
805 |
< |
if (t.find(".phi()") != string::npos) |
806 |
< |
t.replace(t.find(".phi()"), 6, " #phi"); |
805 |
> |
// if (x.find("__") != string::npos) |
806 |
> |
// x = x.substr(0,x.find("__")); |
807 |
> |
// if (y.find("__") != string::npos) |
808 |
> |
// y = y.substr(0,y.find("__")); |
809 |
> |
|
810 |
|
if (x.find(".phi()") != string::npos) |
811 |
|
x.replace(x.find(".phi()"), 6, " #phi"); |
812 |
|
if (y.find(".phi()") != string::npos) |
813 |
|
y.replace(y.find(".phi()"), 6, " #phi"); |
814 |
|
|
530 |
– |
if (t.find(".eta()") != string::npos) |
531 |
– |
t.replace(t.find(".eta()"), 6, " #eta"); |
815 |
|
if (x.find(".eta()") != string::npos) |
816 |
|
x.replace(x.find(".eta()"), 6, " #eta"); |
817 |
|
if (y.find(".eta()") != string::npos) |
818 |
|
y.replace(y.find(".eta()"), 6, " #eta"); |
819 |
|
|
820 |
< |
if (t.find(".pt()") != string::npos) |
821 |
< |
t.replace(t.find(".pt()"), 5, " p_{T}"); |
820 |
> |
if (x.find(".theta()") != string::npos) |
821 |
> |
x.replace(x.find(".theta()"), 6, " #theta"); |
822 |
> |
if (y.find(".theta()") != string::npos) |
823 |
> |
y.replace(y.find(".theta()"), 6, " #theta"); |
824 |
> |
|
825 |
> |
if (x.find(".chi2()") != string::npos) |
826 |
> |
x.replace(x.find(".chi2()"), 7, " #chi^{2}"); |
827 |
> |
if (y.find(".chi2()") != string::npos) |
828 |
> |
y.replace(y.find(".chi2()"), 7, " #chi^{2}"); |
829 |
> |
|
830 |
|
if (x.find(".pt()") != string::npos) |
831 |
< |
x.replace(x.find(".pt()"), 5, " p_{T}"); |
831 |
> |
x.replace(x.find(".pt()"), 5, " p_{T} [GeV]"); |
832 |
|
if (y.find(".pt()") != string::npos) |
833 |
< |
y.replace(y.find(".pt()"), 5, " p_{T}"); |
833 |
> |
y.replace(y.find(".pt()"), 5, " p_{T} [GeV]"); |
834 |
> |
|
835 |
> |
if (x.find(".et()") != string::npos) |
836 |
> |
x.replace(x.find(".et()"), 5, " E_{T} [GeV]"); |
837 |
> |
if (y.find(".et()") != string::npos) |
838 |
> |
y.replace(y.find(".et()"), 5, " E_{T} [GeV]"); |
839 |
> |
|
840 |
> |
//splitlines for many cuts |
841 |
> |
string test1= "{" + globalCuts + "}"; |
842 |
> |
string test2= "&&" + globalCuts; |
843 |
> |
|
844 |
> |
if(t.find(test1) != string::npos) t.replace(t.find(test1),test1.length(),""); |
845 |
> |
if(t.find(test2) != string::npos) t.replace(t.find(test2),test2.length(),""); |
846 |
> |
|
847 |
> |
if (t.find("{") != string::npos && t.find("#splitline") == string::npos) { |
848 |
> |
t.replace(t.find_last_of("{"), 1, "}{"); |
849 |
> |
string t_old = t; |
850 |
> |
t = "#splitline{"; |
851 |
> |
t += t_old; |
852 |
> |
} |
853 |
|
|
854 |
|
thisHist ->SetTitle(t.c_str()); |
855 |
|
thisHist->GetXaxis()->SetTitle(x.c_str()); |
984 |
|
|
985 |
|
int savedCanvs =0; |
986 |
|
|
677 |
– |
TPostScript ps(namePs.c_str(),112); |
678 |
– |
TFile rt(nameRt.c_str(),"recreate"); |
987 |
|
|
988 |
|
TIter next(gROOT->GetListOfCanvases()); |
989 |
|
TCanvas* canv; |
990 |
|
while ((canv=(TCanvas*)next())) { |
991 |
+ |
string modName = (*canv).GetName(); |
992 |
+ |
if(modName.find("{") != string::npos) modName = modName.substr(0,modName.find("{")); |
993 |
+ |
(*canv).SetTitle( modName.c_str() ); |
994 |
+ |
|
995 |
+ |
} |
996 |
+ |
|
997 |
+ |
|
998 |
+ |
TPostScript ps(namePs.c_str(),112); |
999 |
+ |
TFile rt(nameRt.c_str(),"recreate"); |
1000 |
+ |
|
1001 |
+ |
next.Reset(); |
1002 |
+ |
while ((canv=(TCanvas*)next())) { |
1003 |
|
ps.NewPage(); |
1004 |
+ |
|
1005 |
+ |
|
1006 |
+ |
(*canv).Write(); |
1007 |
|
(*canv).Draw(); |
1008 |
|
(*canv).Update(); |
1009 |
< |
(*canv).Write(); |
1009 |
> |
|
1010 |
> |
|
1011 |
|
++savedCanvs; |
1012 |
|
|
1013 |
|
} |
1015 |
|
ps.Close(); |
1016 |
|
rt.Close(); |
1017 |
|
|
1018 |
+ |
|
1019 |
+ |
if(verbose && savedCanvs) { |
1020 |
+ |
cout<<"Saved file "<<rt.GetName()<<" with "<<savedCanvs<<" canvases."<<endl; |
1021 |
+ |
cout<<"Saved file "<<ps.GetName()<<" with "<<savedCanvs<<" pages."<<endl; |
1022 |
+ |
} |
1023 |
|
return savedCanvs; |
1024 |
|
|
1025 |
|
} |
1026 |
|
//------------------------------------------------------------------ |
698 |
– |
void PlotTool::showChainInfo() |
699 |
– |
{ |
700 |
– |
|
1027 |
|
|
1028 |
< |
cout<<endl; |
1029 |
< |
cout<<"****** Show Chain Information:"<<endl; |
1028 |
> |
int PlotTool::clearCanvases() |
1029 |
> |
{ |
1030 |
|
|
1031 |
+ |
while(gROOT->GetListOfCanvases()->GetEntries()) ((TCanvas*) gROOT->GetListOfCanvases()->At(0))->Close(); |
1032 |
+ |
pads_.clear(); |
1033 |
+ |
autoVars.clear(); |
1034 |
+ |
return pads_.size() + gROOT->GetListOfCanvases()->GetEntries(); |
1035 |
|
|
1036 |
< |
this->ls(); |
1036 |
> |
} |
1037 |
> |
//------------------------------------------------------------------ |
1038 |
> |
int PlotTool::setVariables(string label) |
1039 |
> |
{ |
1040 |
|
|
708 |
– |
cout<<endl; |
709 |
– |
cout<<"We have "<<this->GetEntries()<<" TChains with following aliases set:"<<endl; |
1041 |
|
for (int i=0; i< this->GetEntries(); ++i) { |
1042 |
< |
cout<<endl; |
1042 |
> |
cout<<"--------------------------------"<<endl; |
1043 |
|
cout<<((TChain*) this->At(i))->GetName()<<endl; |
1044 |
< |
((TChain*) this->At(i))->GetListOfAliases()->ls(); |
1044 |
> |
cout<<"------------"<<endl; |
1045 |
|
|
1046 |
< |
} |
1046 |
> |
TList* leaves = (TList*) ((TChain*) this->At(i))->GetListOfLeaves(); |
1047 |
> |
for (int j=0; j< leaves->GetEntries(); ++j) { |
1048 |
> |
TString leafName ( leaves->At(j)->GetName() ); |
1049 |
> |
if(! leafName.EndsWith(".") ) continue; |
1050 |
> |
if(! leafName.Contains(label.c_str() ) ) continue; |
1051 |
> |
|
1052 |
> |
TClass cl( ( (TLeafElement*) leaves->At(j) )->GetTypeName() ); |
1053 |
> |
cout<<"++++++"<<endl; |
1054 |
> |
cout<< leafName.Data() <<endl; |
1055 |
> |
for(int k=0;k<cl.GetListOfAllPublicMethods()->GetEntries();++k) { |
1056 |
> |
string typeName ( ((TMethod*) cl.GetListOfAllPublicMethods()->At(k))->GetReturnTypeName() ); |
1057 |
> |
string methName ( cl.GetListOfAllPublicMethods()->At(k)->GetName() ); |
1058 |
> |
if( methName != "product") continue; |
1059 |
> |
cout<< typeName <<endl; |
1060 |
> |
string _type; |
1061 |
> |
TString testString( typeName.c_str() ); |
1062 |
> |
if( testString.BeginsWith("vector<") ) { |
1063 |
> |
_type = typeName.substr(typeName.find("<")+1,typeName.find(">")-typeName.find("<")-1); |
1064 |
> |
string _varSize = leafName.Data(); |
1065 |
> |
_varSize += "obj@.size()"; |
1066 |
> |
autoVars.push_back( _varSize ); |
1067 |
> |
} |
1068 |
> |
else _type = typeName.substr(0,typeName.find("*")); |
1069 |
> |
TClass _cl( _type.c_str() ); |
1070 |
> |
for(int l=0;l<_cl.GetListOfAllPublicMethods()->GetEntries();++l) { |
1071 |
> |
string _typeName ( ((TMethod*) _cl.GetListOfAllPublicMethods()->At(l))->GetReturnTypeName() ); |
1072 |
> |
string _methName ( _cl.GetListOfAllPublicMethods()->At(l)->GetName() ); |
1073 |
> |
// if(_typeName.find("void") != string::npos ) continue; |
1074 |
> |
// cout<<" "<<_typeName<<" "<<_methName<<endl; |
1075 |
> |
|
1076 |
> |
cout<<" "<<_typeName<<" "<<_methName<<endl; |
1077 |
> |
if(_methName.find("operator")==string::npos&&(_typeName=="float"||_typeName=="double"||_typeName=="int"||_typeName=="unsigned int"||_typeName=="bool"||_typeName=="unsigned short"||_typeName=="unsigned long"||_typeName=="unsigned long long")) { |
1078 |
> |
|
1079 |
> |
cout<<"--> "<<_typeName<<" "<<_methName<<endl; |
1080 |
> |
|
1081 |
> |
string _varName = leafName.Data(); |
1082 |
> |
_varName += "obj."; |
1083 |
> |
_varName += _methName; |
1084 |
> |
_varName += "()"; |
1085 |
> |
autoVars.push_back( _varName ); |
1086 |
> |
} |
1087 |
> |
} |
1088 |
> |
|
1089 |
> |
|
1090 |
> |
} |
1091 |
|
|
1092 |
+ |
} |
1093 |
+ |
|
1094 |
+ |
} |
1095 |
|
|
1096 |
+ |
return autoVars.size(); |
1097 |
|
|
1098 |
|
} |
1099 |
|
//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |