14 |
|
|
15 |
|
showLegend = false; |
16 |
|
logY = true; |
17 |
– |
addTrackJets = false; |
18 |
– |
addEventInfo = false; |
19 |
– |
addTower = false; |
17 |
|
verbose = true; |
18 |
|
|
19 |
|
globalCuts=""; |
20 |
|
|
21 |
+ |
varBlockNames = ""; //Set to "ALL" or add Names, i.e. varBlockNames += "CaloTower" |
22 |
|
recreateTree = false; //force recreation of friend tree |
23 |
|
|
24 |
+ |
normHists = false; //scale all histos intergrals to 1 |
25 |
+ |
|
26 |
|
} |
27 |
|
|
28 |
|
//------------------------------------------------------------------ |
91 |
|
fileNames.push_back(filePath.c_str()); |
92 |
|
|
93 |
|
if (((TChain*) this->At(currChain))->AddFile(filePath.c_str(), -1, |
94 |
< |
treeName.c_str()) ) |
94 |
> |
treeName.c_str()) ) { |
95 |
|
if(verbose) cout<<"Chained "<<((TChain*) this->At(currChain))->GetNtrees()<<" file(s) with "<<((TChain*) this->At(currChain))->GetEntries()<<" events."<<endl; |
96 |
< |
else |
97 |
< |
return -1; |
96 |
> |
} else { |
97 |
> |
return -1; |
98 |
> |
} |
99 |
|
|
100 |
|
} |
101 |
|
} else |
138 |
|
|
139 |
|
} |
140 |
|
|
140 |
– |
if( addEventInfo || addTrackJets || addTower ) { |
141 |
– |
|
142 |
– |
if(verbose) cout<<"add friend tree with additional variables..."<<endl; |
141 |
|
|
144 |
– |
//make file for tree friends (adding additional, computed branches) |
145 |
– |
string friendFileName("/scratch/hh/current/cms/user/"); |
146 |
– |
friendFileName += gSystem->GetUserInfo()->fUser; |
147 |
– |
friendFileName += "/temp/"; |
148 |
– |
friendFileName += fileLabel; |
149 |
– |
friendFileName += ".root"; |
150 |
– |
string fileOpt = "update"; |
151 |
– |
if( recreateTree ) fileOpt = "recreate"; |
152 |
– |
|
153 |
– |
TFile *f = new TFile(friendFileName.c_str(),fileOpt.c_str()); |
154 |
– |
|
155 |
– |
if( f->IsZombie() ) return -1; |
156 |
– |
|
157 |
– |
string friendTreeName("friendTree"); |
158 |
– |
//char number = currChain; |
159 |
– |
//friendTreeName += number; |
160 |
– |
//TTree *friendTree = new TTree("friendTree","friendTree"); |
161 |
– |
|
162 |
– |
if(! f->FindKey(friendTreeName.c_str())) { |
163 |
– |
if(verbose) cout<<"calculating additional variables..."<<endl; |
164 |
– |
|
165 |
– |
|
166 |
– |
TTree *friendTree = new TTree(friendTreeName.c_str(),friendTreeName.c_str()); |
167 |
– |
fwlite::ChainEvent ev(fileNames); |
168 |
– |
int _event, _run, _lumi; |
169 |
– |
int nJetsKT; |
170 |
– |
TrackJetKT = new float [100]; |
171 |
– |
|
172 |
– |
//tower data |
173 |
– |
const int kMAX = 10000; |
174 |
– |
int NobjTowCal; |
175 |
– |
towet = new float [ kMAX ]; |
176 |
– |
toweta = new float [ kMAX ]; |
177 |
– |
towphi = new float [ kMAX ]; |
178 |
– |
towen = new float [ kMAX ]; |
179 |
– |
towem = new float [ kMAX ]; |
180 |
– |
towhd = new float [ kMAX ]; |
181 |
– |
towoe = new float [ kMAX ]; |
182 |
– |
towid_phi = new int[ kMAX ]; |
183 |
– |
towid_eta = new int[ kMAX ]; |
184 |
– |
towid = new int[ kMAX ]; |
185 |
– |
|
142 |
|
|
187 |
– |
if( addEventInfo ) { |
143 |
|
|
144 |
+ |
|
145 |
+ |
string friendTreeName("friendTree"); |
146 |
|
|
147 |
< |
friendTree->Branch("event", &_event, "event/I"); |
148 |
< |
friendTree->Branch("run", &_run, "run/I"); |
149 |
< |
friendTree->Branch("lumi", &_lumi, "lumi/I"); |
150 |
< |
|
151 |
< |
} |
152 |
< |
|
153 |
< |
if( addTrackJets ) { |
154 |
< |
|
155 |
< |
|
156 |
< |
friendTree->Branch("nJetsKT", &nJetsKT, "nJetsKT/I"); |
157 |
< |
friendTree->Branch("TrackJetKT", TrackJetKT, "TrackJetKT[nJetsKT]/F"); |
158 |
< |
} |
159 |
< |
|
203 |
< |
if( addTower) { |
204 |
< |
|
205 |
< |
// CaloTower branches |
206 |
< |
friendTree->Branch( "NobjTowCal",&NobjTowCal,"NobjTowCal/I" ); |
207 |
< |
friendTree->Branch( "TowId", towid, "TowId[NobjTowCal]/I" ); |
208 |
< |
friendTree->Branch( "TowId_phi", towid_phi, "TowId_phi[NobjTowCal]/I" ); |
209 |
< |
friendTree->Branch( "TowId_eta", towid_eta, "TowId_eta[NobjTowCal]/I" ); |
210 |
< |
friendTree->Branch( "TowEt", towet, "TowEt[NobjTowCal]/F" ); |
211 |
< |
friendTree->Branch( "TowEta", toweta, "TowEta[NobjTowCal]/F" ); |
212 |
< |
friendTree->Branch( "TowPhi", towphi, "TowPhi[NobjTowCal]/F" ); |
213 |
< |
friendTree->Branch( "TowE", towen, "TowE[NobjTowCal]/F" ); |
214 |
< |
friendTree->Branch( "TowEm", towem, "TowEm[NobjTowCal]/F" ); |
215 |
< |
friendTree->Branch( "TowHad", towhd, "TowHad[NobjTowCal]/F" ); |
216 |
< |
friendTree ->Branch( "TowOE", towoe, "TowOE[NobjTowCal]/F" ); |
217 |
< |
|
218 |
< |
|
219 |
< |
} |
220 |
< |
|
221 |
< |
|
222 |
< |
int tenth = ev.size() / 10; |
223 |
< |
int eventNum =0; |
224 |
< |
for (ev.toBegin(); !ev.atEnd(); ++ev, ++eventNum) { |
225 |
< |
|
226 |
< |
|
227 |
< |
if( addEventInfo ) { |
228 |
< |
|
229 |
< |
|
230 |
< |
if(eventNum==0) { |
231 |
< |
// fwlite::Handle<edm::TriggerResults> hltHandle; |
232 |
< |
// hltHandle.getByLabel(ev, "TriggerResults"); |
233 |
< |
|
234 |
< |
// fwlite::Handle<edm::TriggerResults> hTriggerResults; |
235 |
< |
|
236 |
< |
// hTriggerResults.getByLabel(ev, "TriggerResults","","TEST"); |
237 |
< |
// fwlite::TriggerNames const& triggerNames = ev.triggerNames(*hTriggerResults); |
238 |
< |
|
239 |
< |
|
240 |
< |
// // std::vector<std::string> const& names = triggerNames.triggerNames(); |
241 |
< |
// for (unsigned i = 0; i < triggerNames.size(); ++i) { |
242 |
< |
// std::cout << i << " " << triggerNames.triggerName(i) << std::endl; |
243 |
< |
// } |
244 |
< |
} |
245 |
< |
|
246 |
< |
_event = ev.id().event(); |
247 |
< |
_run = ev.id().run(); |
248 |
< |
_lumi = ev.luminosityBlock(); |
249 |
< |
|
250 |
< |
} |
251 |
< |
|
252 |
< |
if( addTrackJets ) { |
253 |
< |
|
254 |
< |
fwlite::Handle<reco::CaloJetCollection> jets; |
255 |
< |
jets.getByLabel(ev, "ak5CaloJets"); |
256 |
< |
|
257 |
< |
fwlite::Handle<reco::TrackCollection> tracks; |
258 |
< |
tracks.getByLabel(ev, "generalTracks"); |
259 |
< |
|
260 |
< |
if (!jets.isValid()) |
261 |
< |
continue; |
262 |
< |
if (!tracks.isValid()) |
263 |
< |
continue; |
264 |
< |
double trackSum; |
265 |
< |
nJetsKT = 0; |
266 |
< |
for (reco::CaloJetCollection::const_iterator jet = jets->begin(); jet |
267 |
< |
!=jets->end(); jet++) { |
268 |
< |
trackSum = 0; |
269 |
< |
for (reco::TrackCollection::const_iterator track = tracks->begin(); track |
270 |
< |
!=tracks->end(); track++) { |
271 |
< |
if (deltaR(jet->eta(), jet->phi(), track->eta(), track->phi()) |
272 |
< |
< 0.5) |
273 |
< |
trackSum += track->pt(); |
274 |
< |
} |
275 |
< |
TrackJetKT[nJetsKT] = trackSum; |
276 |
< |
nJetsKT++; |
277 |
< |
} |
278 |
< |
} |
279 |
< |
if( addTower) { |
280 |
< |
|
281 |
< |
fwlite::Handle<CaloTowerCollection> towers; |
282 |
< |
towers.getByLabel(ev, "towerMaker"); |
283 |
< |
|
284 |
< |
int jtow = 0; |
285 |
< |
NobjTowCal=towers->size(); |
286 |
< |
for(CaloTowerCollection::const_iterator tow = towers->begin(); |
287 |
< |
tow != towers->end(); ++tow, ++jtow){ |
288 |
< |
towet [jtow] = tow->et(); |
289 |
< |
toweta[jtow] = tow->eta(); |
290 |
< |
towphi[jtow] = tow->phi(); |
291 |
< |
towen [jtow] = tow->energy(); |
292 |
< |
towem [jtow] = tow->emEnergy(); |
293 |
< |
towhd [jtow] = tow->hadEnergy(); |
294 |
< |
towoe [jtow] = tow->outerEnergy(); |
295 |
< |
towid_phi[jtow] = tow->id().iphi(); |
296 |
< |
towid_eta[jtow] = tow->id().ieta(); |
297 |
< |
towid [jtow] = tow->id().rawId(); |
298 |
< |
} |
299 |
< |
|
300 |
< |
|
301 |
< |
} |
302 |
< |
friendTree->Fill(); |
303 |
< |
|
304 |
< |
if( eventNum != 0 && eventNum%tenth == 0) cout<<"Processed "<<eventNum <<" of "<<ev.size()<<" events. "<<endl; |
305 |
< |
|
306 |
< |
} |
307 |
< |
f->cd(); |
308 |
< |
friendTree->Write(); |
309 |
< |
} |
310 |
< |
f->Close(); |
147 |
> |
string friendFileName("/scratch/hh/current/cms/user/"); |
148 |
> |
friendFileName += gSystem->GetUserInfo()->fUser; |
149 |
> |
friendFileName += "/temp/"; |
150 |
> |
friendFileName += fileLabel; |
151 |
> |
friendFileName += ".root"; |
152 |
> |
string fileOpt = "update"; |
153 |
> |
if( recreateTree ) fileOpt = "recreate"; |
154 |
> |
|
155 |
> |
FWliteVariables fwVars(friendTreeName, friendFileName, fileOpt); |
156 |
> |
|
157 |
> |
if(varBlockNames.length() > 1 ) { |
158 |
> |
fwVars.loop(fileNames, varBlockNames); |
159 |
> |
if(verbose) cout<<"add friend tree with additional variables: "<<varBlockNames<<endl; |
160 |
|
((TChain*) this->At(currChain))->AddFriend(friendTreeName.c_str(), |
161 |
|
friendFileName.c_str()); |
162 |
< |
|
163 |
< |
|
315 |
< |
|
162 |
> |
} else { |
163 |
> |
if(verbose) cout<<"No additional variables added."<<endl; |
164 |
|
} |
165 |
|
|
166 |
+ |
|
167 |
+ |
|
168 |
+ |
|
169 |
|
|
170 |
|
timer.Stop(); |
171 |
|
if(verbose) timer.Print(); |
175 |
|
} |
176 |
|
//------------------------------------------------------------------ |
177 |
|
//Draw given Chain with given variable and given cuts |
178 |
< |
int PlotTool::plot(int chainIndex, string histName, string cutName, |
179 |
< |
int nEntries, string drwOpt) { |
178 |
> |
TH1* PlotTool::plot(int chainIndex, string histName, string cutName, |
179 |
> |
int nEntries, string bins, string drwOpt) { |
180 |
> |
|
181 |
> |
TH1* thisHist = 0; |
182 |
|
|
183 |
|
if (chainIndex >= this->GetEntries() ) |
184 |
< |
return -1; |
184 |
> |
return thisHist; |
185 |
|
|
186 |
|
TStopwatch timer; |
187 |
|
if(verbose) { |
248 |
|
|
249 |
|
|
250 |
|
//Draw histogram: |
251 |
< |
string cutNameWithGlobal = cutName; |
251 |
> |
string cutNameWithGlobal = ""; |
252 |
> |
if(cutName!="" && globalCuts!="") cutNameWithGlobal += "("; |
253 |
> |
if(cutName!="") cutNameWithGlobal += cutName; |
254 |
> |
if(cutName!="" && globalCuts!="") cutNameWithGlobal += ")"; |
255 |
|
if(cutName!="" && globalCuts!="") cutNameWithGlobal += "&&"; |
256 |
+ |
if(cutName!="" && globalCuts!="") cutNameWithGlobal += "("; |
257 |
|
if(globalCuts!="") cutNameWithGlobal += globalCuts; |
258 |
+ |
if(cutName!="" && globalCuts!="") cutNameWithGlobal += ")"; |
259 |
+ |
|
260 |
+ |
histName += ">>htemp"; |
261 |
+ |
if(bins != "") histName += bins; |
262 |
+ |
|
263 |
+ |
|
264 |
+ |
|
265 |
|
|
266 |
|
int draw_err = ((TChain*) this->At(chainIndex))->Draw(histName.c_str(), cutNameWithGlobal.c_str(), |
267 |
|
currOpt.c_str(), currN); |
268 |
|
if (draw_err < 0) |
269 |
< |
return draw_err; |
269 |
> |
return thisHist; |
270 |
|
|
271 |
|
//++++ Fix for histos with no entries +++++++++++++ |
272 |
|
if (draw_err == 0) { |
276 |
|
if (useSubPads) |
277 |
|
canvases_[currCanvName.str()]->SetNumber(canvases_[currCanvName.str()]->GetNumber()-1); |
278 |
|
} |
279 |
< |
cout<< "Warning: "<<currHistName.str().c_str()<<" in "<<currPadName.str() |
279 |
> |
if(verbose) cout<< "Warning: "<<currHistName.str().c_str()<<" in "<<currPadName.str() |
280 |
|
<<" has no entries and is not drawn!"<<endl; |
281 |
< |
return draw_err; |
281 |
> |
return thisHist; |
282 |
|
} |
283 |
|
//++++++++++++++++++++++++++++++++++++++++++++++++++ |
284 |
|
|
285 |
< |
((TH1F*) pads_[currPadName.str()]->GetPrimitive("htemp"))->SetName(currHistName.str().c_str()); // Set Name of histogram |
285 |
> |
thisHist = (TH1*) pads_[currPadName.str()]->GetPrimitive("htemp"); |
286 |
> |
|
287 |
> |
thisHist->SetName(currHistName.str().c_str()); |
288 |
|
|
289 |
|
// Update for 2D histograms |
290 |
< |
if( pads_[currPadName.str()]->GetPrimitive(currHistName.str().c_str())->InheritsFrom("TH2") ) { |
290 |
> |
if( thisHist->InheritsFrom("TH2") ) { |
291 |
|
pads_[currPadName.str()]->Draw(); |
292 |
|
setCanvas( pads_[currPadName.str()] ); |
293 |
|
} |
298 |
|
cout<<"Done: Selected "<<draw_err<<" objects in "<< currN <<" processed events."<<endl; |
299 |
|
timer.Print(); |
300 |
|
} |
301 |
< |
return draw_err; |
301 |
> |
return thisHist; |
302 |
|
|
303 |
|
} |
304 |
|
//------------------------------------------------------------------ |
305 |
|
//Standard loop to draw all chains and multiple variables and cuts |
306 |
|
int PlotTool::loop(vector<string> _histName, vector<string> _cutName, |
307 |
< |
int nEntries, string drwOpt, bool correspond) { |
307 |
> |
int nEntries, string bins, string drwOpt, bool correspond) { |
308 |
|
|
309 |
|
int numProcessed = 0; |
310 |
|
|
311 |
+ |
TH1* currHist = 0; |
312 |
+ |
|
313 |
+ |
|
314 |
|
if (correspond == false) { |
315 |
|
|
316 |
|
for (int i=0; i<this->GetEntries(); ++i) { |
319 |
|
for (vector<string>::iterator it2 =_cutName.begin(); it2 |
320 |
|
!= _cutName.end(); ++it2) { |
321 |
|
|
322 |
< |
numProcessed += plot(i, *it1, *it2, nEntries, drwOpt); |
322 |
> |
currHist = plot(i, *it1, *it2, nEntries, bins, drwOpt); |
323 |
> |
if(currHist) numProcessed += int(currHist->GetEntries()); |
324 |
|
|
325 |
|
|
326 |
|
} |
336 |
|
_cutName.begin(); it1 != _cutName.end()&&it2 |
337 |
|
!= _cutName.end(); ++it1, ++it2) { |
338 |
|
|
339 |
< |
numProcessed += plot(i, *it1, *it2, nEntries, drwOpt); |
339 |
> |
currHist = plot(i, *it1, *it2, nEntries, bins, drwOpt); |
340 |
> |
if(currHist) numProcessed += int(currHist->GetEntries()); |
341 |
|
|
342 |
|
} |
343 |
|
} |
350 |
|
} |
351 |
|
|
352 |
|
//Helper methods to allow for using simple strings as input |
353 |
< |
int PlotTool::loop(string histName, string cutName, int nEntries, string drwOpt) { |
353 |
> |
int PlotTool::loop(string histName, string cutName, int nEntries, string bins, string drwOpt) { |
354 |
|
|
355 |
|
vector<string> _histName; |
356 |
|
_histName.push_back(histName); |
357 |
|
vector<string> _cutName; |
358 |
|
_cutName.push_back(cutName); |
359 |
|
|
360 |
< |
return loop(_histName, _cutName, nEntries, drwOpt); |
360 |
> |
return loop(_histName, _cutName, nEntries, bins, drwOpt); |
361 |
|
|
362 |
|
} |
363 |
|
|
364 |
< |
int PlotTool::loop(vector<string> _histName, string cutName, int nEntries, |
364 |
> |
int PlotTool::loop(vector<string> _histName, string cutName, int nEntries, string bins, |
365 |
|
string drwOpt) { |
366 |
|
|
367 |
|
vector<string> _cutName; |
368 |
|
_cutName.push_back(cutName); |
369 |
|
|
370 |
< |
return loop(_histName, _cutName, nEntries, drwOpt); |
370 |
> |
return loop(_histName, _cutName, nEntries, bins, drwOpt); |
371 |
|
|
372 |
|
} |
373 |
|
|
374 |
< |
int PlotTool::loop(string histName, vector<string> _cutName, int nEntries, |
374 |
> |
int PlotTool::loop(string histName, vector<string> _cutName, int nEntries, string bins, |
375 |
|
string drwOpt) { |
376 |
|
|
377 |
|
vector<string> _histName; |
378 |
|
_histName.push_back(histName); |
379 |
|
|
380 |
< |
return loop(_histName, _cutName, nEntries, drwOpt); |
380 |
> |
return loop(_histName, _cutName, nEntries, bins, drwOpt); |
381 |
|
} |
382 |
|
//------------------------------------------------------------------ |
383 |
|
//redraw the canvas to make changes in style visible |
458 |
|
//------------------------------------------------------------------ |
459 |
|
void PlotTool::setCanvas(TCanvas* thisCanvas) { |
460 |
|
|
461 |
+ |
|
462 |
|
TH1* thisHist = 0; |
463 |
|
TPaveStats* thisStatsBox = 0; |
464 |
|
TPaletteAxis* palette =0; |
484 |
|
|
485 |
|
for (int i = 0; i != thisCanvas->GetListOfPrimitives()->GetSize(); ++i) { |
486 |
|
|
487 |
+ |
|
488 |
+ |
|
489 |
|
if ( !thisCanvas->GetListOfPrimitives()->At(i)->InheritsFrom("TH1")) |
490 |
|
continue; |
491 |
|
|
492 |
+ |
|
493 |
|
thisHist = ((TH1*) thisCanvas->GetListOfPrimitives()->At(i)); |
494 |
+ |
|
495 |
+ |
TString testString( thisHist->GetName() ); |
496 |
+ |
if( testString.BeginsWith("frame_") ) continue; |
497 |
+ |
|
498 |
|
setColor(thisHist, counter); |
499 |
|
setMathLabels(thisHist); |
500 |
|
|
501 |
+ |
if(normHists) thisHist->Scale(1/thisHist->GetSumOfWeights()); |
502 |
+ |
|
503 |
|
if (thisHist->GetMaximum() > maxEntry) |
504 |
|
maxEntry = thisHist->GetMaximum(); |
505 |
|
|
587 |
|
|
588 |
|
//splitlines for many cuts |
589 |
|
string test1= "{" + globalCuts + "}"; |
590 |
< |
string test2= "&&" + globalCuts; |
590 |
> |
string test2= "&&(" + globalCuts + ")"; |
591 |
|
|
592 |
|
if(t.find(test1) != string::npos) t.replace(t.find(test1),test1.length(),""); |
593 |
|
if(t.find(test2) != string::npos) t.replace(t.find(test2),test2.length(),""); |
607 |
|
|
608 |
|
void PlotTool::setColor(TH1* thisHist, int counter) { |
609 |
|
|
610 |
+ |
thisHist->SetLineWidth(gStyle->GetLineWidth()); |
611 |
+ |
|
612 |
|
if (counter == 0) { |
613 |
|
|
614 |
|
thisHist->SetLineColor(kRed+1); |
653 |
|
|
654 |
|
} |
655 |
|
|
656 |
+ |
|
657 |
|
} |
658 |
|
|
659 |
|
void PlotTool::setPalette(TCanvas* thisCanvas, TPaletteAxis* palette) { |
847 |
|
return autoVars.size(); |
848 |
|
|
849 |
|
} |
966 |
– |
//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
967 |
– |
//Draw efficiencies |
968 |
– |
int PlotTool::plotEff(int chainIndex, string histName, string cutName, int nEntries, double fitXmin, double fitXmax, string fitFormula) |
969 |
– |
{ |
970 |
– |
|
971 |
– |
if( chainIndex >= this->GetEntries() ) return -1; |
972 |
– |
|
973 |
– |
int currN = nEntries; |
974 |
– |
if(nEntries < 0) currN = ((TChain*) this->At(chainIndex))->GetEntries(); //nEntries<0 : all entries are plotted! |
975 |
– |
|
976 |
– |
//++++ Create and name Canvases according to global variables +++++++++++++ |
977 |
– |
ostringstream currHistName; |
978 |
– |
if( samePad_trees) currHistName<<((TChain*) this->At(chainIndex))->GetName()<<":"; |
979 |
– |
if( samePad_vars) currHistName<<histName; |
980 |
– |
if( samePad_cuts) currHistName<<"{"<<cutName<<"}"; |
981 |
– |
|
982 |
– |
ostringstream currPadName; |
983 |
– |
if(! samePad_trees) currPadName<<((TChain*) this->At(chainIndex))->GetName()<<":"; |
984 |
– |
if(! samePad_vars) currPadName<<histName; |
985 |
– |
if(! samePad_cuts) currPadName<<"{"<<cutName<<"}"; |
986 |
– |
|
987 |
– |
|
988 |
– |
//Draw total histogram: |
989 |
– |
if( ! pads_["total"] || ! gROOT->FindObject("total") ) { |
990 |
– |
pads_["total"] = new TCanvas("total", "total"); |
991 |
– |
} else { |
992 |
– |
pads_["total"]->cd(); |
993 |
– |
} |
994 |
– |
ostringstream bins_total; |
995 |
– |
bins_total<<histName; |
996 |
– |
bins_total<<">>total(100,0,1000)"; |
997 |
– |
|
998 |
– |
|
999 |
– |
int draw_err = ((TChain*) this->At(chainIndex))->Draw(bins_total.str().c_str(), "", "", currN); |
1000 |
– |
if( draw_err <= 0 ) return draw_err; |
1001 |
– |
|
1002 |
– |
|
1003 |
– |
TH1* total = ((TH1*) pads_["total"]->GetPrimitive("total")); |
1004 |
– |
|
1005 |
– |
ostringstream bins_bkg; |
1006 |
– |
bins_bkg<<histName; |
1007 |
– |
bins_bkg<<">>bkg("; |
1008 |
– |
bins_bkg<<total->GetNbinsX(); |
1009 |
– |
bins_bkg<<","; |
1010 |
– |
bins_bkg<<total->GetXaxis()->GetXmin(); |
1011 |
– |
bins_bkg<<","; |
1012 |
– |
bins_bkg<<total->GetXaxis()->GetXmax(); |
1013 |
– |
bins_bkg<<")"; |
1014 |
– |
|
1015 |
– |
//Draw bkg histogram: |
1016 |
– |
if( ! pads_["bkg"] || ! gROOT->FindObject("bkg") ) { |
1017 |
– |
pads_["bkg"] = new TCanvas("bkg", currPadName.str().c_str()); |
1018 |
– |
} else { |
1019 |
– |
pads_["bkg"]->cd(); |
1020 |
– |
} |
1021 |
– |
|
1022 |
– |
draw_err = ((TChain*) this->At(chainIndex))->Draw(bins_bkg.str().c_str(), cutName.c_str(),"" , currN); |
1023 |
– |
if( draw_err <= 0 ) return draw_err; |
1024 |
– |
|
1025 |
– |
|
1026 |
– |
TH1* bkg = ((TH1*) pads_["bkg"]->GetPrimitive("bkg")); |
1027 |
– |
|
1028 |
– |
//Draw pass histogram: |
1029 |
– |
ostringstream bins_pass; |
1030 |
– |
bins_pass<<histName; |
1031 |
– |
bins_pass<<">>pass("; |
1032 |
– |
bins_pass<<total->GetNbinsX(); |
1033 |
– |
bins_pass<<","; |
1034 |
– |
bins_pass<<total->GetXaxis()->GetXmin(); |
1035 |
– |
bins_pass<<","; |
1036 |
– |
bins_pass<<total->GetXaxis()->GetXmax(); |
1037 |
– |
bins_pass<<")"; |
1038 |
– |
|
1039 |
– |
ostringstream cut_pass; |
1040 |
– |
cut_pass<<"!("; |
1041 |
– |
cut_pass<<cutName; |
1042 |
– |
cut_pass<<")"; |
1043 |
– |
|
1044 |
– |
|
1045 |
– |
if( ! pads_["pass"] || ! gROOT->FindObject("pass") ) { |
1046 |
– |
pads_["pass"] = new TCanvas("pass", currPadName.str().c_str()); |
1047 |
– |
} else { |
1048 |
– |
pads_["pass"]->cd(); |
1049 |
– |
} |
1050 |
– |
|
1051 |
– |
draw_err = ((TChain*) this->At(chainIndex))->Draw(bins_pass.str().c_str(),cut_pass.str().c_str() ,"" , currN); |
1052 |
– |
if( draw_err <= 0 ) return draw_err; |
1053 |
– |
|
1054 |
– |
|
1055 |
– |
TH1* pass = ((TH1*) pads_["pass"]->GetPrimitive("pass")); |
1056 |
– |
|
1057 |
– |
|
1058 |
– |
currPadName<<"Eff"; |
1059 |
– |
//Draw Efficiency Graph: |
1060 |
– |
if( ! pads_["EffGraph"] || ! gROOT->FindObject("EffGraph") ) { |
1061 |
– |
pads_["EffGraph"] = new TCanvas("EffGraph", currPadName.str().c_str()); |
1062 |
– |
} else { |
1063 |
– |
pads_["EffGraph"]->cd(); |
1064 |
– |
} |
1065 |
– |
|
1066 |
– |
TGraphAsymmErrors* EffGraph = new TGraphAsymmErrors(bkg, total); |
1067 |
– |
EffGraph->SetName(currHistName.str().c_str()); |
1068 |
– |
|
1069 |
– |
TF1* reverse = new TF2("reverse","1/y-1",total->GetXaxis()->GetXmin(),total->GetXaxis()->GetXmax()); |
1070 |
– |
EffGraph->Apply(reverse); |
1071 |
– |
EffGraph->Draw("A*"); |
1072 |
– |
|
1073 |
– |
TF1* fitfunc = new TF1("fitfunc",fitFormula.c_str(),fitXmin,fitXmax); |
1074 |
– |
EffGraph->Fit("fitfunc","R+"); |
1075 |
– |
|
1076 |
– |
|
1077 |
– |
//Save fit function |
850 |
|
|
1079 |
– |
ostringstream savefuncName; |
1080 |
– |
savefuncName<<histName; |
1081 |
– |
savefuncName<<"_"; |
1082 |
– |
|
1083 |
– |
if(cutName.find("<") != std::string::npos ) cutName.replace(cutName.find("<"),1,"_"); |
1084 |
– |
if(cutName.find(">") != std::string::npos ) cutName.replace(cutName.find(">"),1,"_"); |
1085 |
– |
savefuncName<<cutName; |
1086 |
– |
|
1087 |
– |
|
1088 |
– |
TFile file("ABCDFunctions.root","UPDATE"); |
1089 |
– |
TF1* savefunc = new TF1(savefuncName.str().c_str(), fitfunc->GetExpFormula().Data(),0,10000); |
1090 |
– |
savefunc->SetParameters( fitfunc->GetParameters() ); |
1091 |
– |
savefunc->SetParErrors ( fitfunc->GetParErrors() ); |
1092 |
– |
|
1093 |
– |
//Show results |
1094 |
– |
if( ! pads_["abcd"] || ! gROOT->FindObject("abcd") ) { |
1095 |
– |
pads_["abcd"] = new TCanvas("abcd", "abcd"); |
1096 |
– |
} else { |
1097 |
– |
pads_["abcd"]->cd(); |
1098 |
– |
} |
1099 |
– |
|
1100 |
– |
bkg->Multiply(savefunc); |
1101 |
– |
bkg->Draw(); |
1102 |
– |
|
1103 |
– |
// total->Add(bkg,-1); |
1104 |
– |
pass->SetLineColor(kRed); |
1105 |
– |
pass->Draw("sames,e"); |
1106 |
– |
pads_["abcd"]->SetLogy(); |
1107 |
– |
|
1108 |
– |
|
1109 |
– |
savefunc->Write(); |
1110 |
– |
// file.Close(); |
1111 |
– |
|
1112 |
– |
|
1113 |
– |
return draw_err; |
1114 |
– |
|
1115 |
– |
} |
851 |
|
//------------------------------------------------------------------ |