1 |
|
#include "PlotTool.h" |
2 |
|
//------------------------------------------------------------------ |
3 |
|
//Constructur: Set some global Variables to define canvas output |
4 |
< |
PlotTool::PlotTool() |
5 |
< |
{ |
4 |
> |
PlotTool::PlotTool() { |
5 |
|
|
6 |
< |
this->SetClass("TChain",100); |
6 |
> |
this->SetClass("TChain", 100); |
7 |
|
|
8 |
< |
samePad_trees = true; |
9 |
< |
samePad_vars = false; |
10 |
< |
samePad_cuts = false; |
11 |
< |
sameCanv_trees = false; |
12 |
< |
sameCanv_vars = false; |
13 |
< |
sameCanv_cuts = false; |
8 |
> |
samePad_trees = true; |
9 |
> |
samePad_vars = false; |
10 |
> |
samePad_cuts = false; |
11 |
> |
sameCanv_trees = false; |
12 |
> |
sameCanv_vars = false; |
13 |
> |
sameCanv_cuts = false; |
14 |
> |
|
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 |
< |
showLegend = false; |
17 |
< |
logY = true; |
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 |
< |
int PlotTool::init(string fileName, string dirPath, string treeName) |
35 |
< |
{ |
36 |
< |
this->New( this->GetEntries() ); |
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 ) return currChain; |
40 |
> |
if (currChain < 0) |
41 |
> |
return currChain; |
42 |
> |
|
43 |
> |
TStopwatch timer; |
44 |
> |
timer.Start(); |
45 |
|
|
46 |
|
|
47 |
< |
((TChain*) this->At(currChain))->SetName(fileName.c_str()); |
48 |
< |
TSystemDirectory dir("sourceDir",dirPath.c_str()); |
49 |
< |
TList *files = dir.GetListOfFiles(); |
50 |
< |
if (files) { |
51 |
< |
TIter next(files); |
52 |
< |
TSystemFile *file; |
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 |
< |
cout<<"Open"<<dirPath.c_str()<<" Search for .root files that contain: "<<fileName.c_str()<<endl; |
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 |
< |
while ((file=(TSystemFile*)next())) { |
85 |
< |
fname = file->GetName(); |
86 |
< |
if (!fname.EndsWith(".root")) continue; |
87 |
< |
if (!fname.Contains(fileName.c_str())) continue; |
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 |
< |
if( ((TChain*) this->At(currChain))->AddFile(filePath.c_str(), -1, treeName.c_str()) ) cout<<"Chained "<<((TChain*) this->At(currChain))->GetNtrees()<<" file(s) with "<<((TChain*) this->At(currChain))->GetEntries()<<" events."<<endl; |
95 |
< |
else return -1; |
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 return -1; |
104 |
> |
} else |
105 |
> |
return -1; |
106 |
|
|
107 |
< |
for(int i=0;i<((TChain*) this->At(currChain))->GetListOfBranches()->GetEntries();++i){ |
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 |
< |
size_t a = s.find("_"); |
111 |
< |
if(a == string::npos) a = 0; |
61 |
< |
size_t b = s.find("_", a+1); |
62 |
< |
if(b == string::npos) b = 50; |
63 |
< |
string branch_alias = s.substr(a+1,b-a-1); |
110 |
> |
|
111 |
> |
string branch_alias = s; |
112 |
|
string branch_name = s; |
113 |
< |
if(s.find(".",s.size()-1) != string::npos ) branch_name += "obj"; |
114 |
< |
((TChain*) this->At(currChain))->SetAlias(branch_alias.c_str(),branch_name.c_str()); |
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 |
> |
((TChain*) this->At(currChain))->SetAlias(branch_alias.c_str(), |
140 |
> |
branch_name.c_str()); |
141 |
|
|
142 |
|
} |
143 |
|
|
144 |
< |
return this->GetEntries(); |
144 |
> |
if( addEventInfo || addTrackJets || addTower || addTrackJets || addHitDetInfo || diTrackMass || addTrigger) { |
145 |
|
|
146 |
< |
} |
73 |
< |
//------------------------------------------------------------------ |
74 |
< |
//Draw given Chain with given variable and given cuts |
75 |
< |
int PlotTool::plot(int chainIndex, string histName, string cutName, int nEntries, string drwOpt) |
76 |
< |
{ |
146 |
> |
if(verbose) cout<<"add friend tree with additional variables..."<<endl; |
147 |
|
|
148 |
< |
if( chainIndex >= this->GetEntries() ) return -1; |
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 |
< |
int currN = nEntries; |
203 |
< |
if(nEntries < 0) currN = ((TChain*) this->At(chainIndex))->GetEntries(); //nEntries<0 : all entries are plotted! |
202 |
> |
friendTree->Branch("event", &_event, "event/I"); |
203 |
> |
friendTree->Branch("run", &_run, "run/I"); |
204 |
> |
friendTree->Branch("lumi", &_lumi, "lumi/I"); |
205 |
|
|
206 |
< |
//++++ Create and name Canvases according to global variables +++++++++++++ |
84 |
< |
ostringstream currHistName; |
85 |
< |
if( samePad_trees) currHistName<<((TChain*) this->At(chainIndex))->GetName()<<":"; |
86 |
< |
if( samePad_vars) currHistName<<histName; |
87 |
< |
if( samePad_cuts) currHistName<<"{"<<cutName<<"}"; |
206 |
> |
} |
207 |
|
|
208 |
< |
ostringstream currPadName; |
90 |
< |
if(! samePad_trees) currPadName<<((TChain*) this->At(chainIndex))->GetName()<<":"; |
91 |
< |
if(! samePad_vars) currPadName<<histName; |
92 |
< |
if(! samePad_cuts) currPadName<<"{"<<cutName<<"}"; |
208 |
> |
if( addTrackJets ) { |
209 |
|
|
94 |
– |
ostringstream currCanvName; |
95 |
– |
if(! sameCanv_trees && ! samePad_trees ) currCanvName<<((TChain*) this->At(chainIndex))->GetName()<<":"; |
96 |
– |
if(! sameCanv_vars && ! samePad_vars) currCanvName<<histName; |
97 |
– |
if(! sameCanv_cuts && ! samePad_cuts) currCanvName<<"{"<<cutName<<"}"; |
210 |
|
|
211 |
< |
if( (sameCanv_trees || samePad_trees) && (sameCanv_vars || samePad_vars) && (sameCanv_cuts || samePad_cuts) ) currCanvName<<"All"; |
211 |
> |
friendTree->Branch("nJetsKT", &nJetsKT, "nJetsKT/I"); |
212 |
> |
friendTree->Branch("TrackJetKT", TrackJetKT, "TrackJetKT[nJetsKT]/F"); |
213 |
> |
} |
214 |
|
|
215 |
< |
|
102 |
< |
string currOpt = drwOpt; |
103 |
< |
bool useSubPads = (sameCanv_trees && !samePad_trees) || (sameCanv_vars && !samePad_vars) || (sameCanv_cuts && !samePad_cuts); |
215 |
> |
if( addTower) { |
216 |
|
|
217 |
< |
if( useSubPads ) { |
218 |
< |
if( ! canvases_[currCanvName.str()] || ! gROOT->FindObject(currCanvName.str().c_str()) ) { |
219 |
< |
canvases_[currCanvName.str()] = new TCanvas(currCanvName.str().c_str(), currCanvName.str().c_str()); |
220 |
< |
} else if ( canvases_[currCanvName.str()]->GetNumber() >= 0 ) { |
221 |
< |
canvases_[currCanvName.str()]->SetNumber(canvases_[currCanvName.str()]->GetNumber()+1); |
222 |
< |
} |
223 |
< |
} |
224 |
< |
|
225 |
< |
if( ! pads_[currPadName.str()] || ! gROOT->FindObject(currPadName.str().c_str()) ) { |
226 |
< |
pads_[currPadName.str()] = new TCanvas(currPadName.str().c_str(), currPadName.str().c_str()); |
227 |
< |
if(logY) pads_[currPadName.str()]->SetLogy(1); |
228 |
< |
} else { |
117 |
< |
pads_[currPadName.str()]->cd(); |
118 |
< |
currOpt += "SAMES"; |
119 |
< |
if(useSubPads) canvases_[currCanvName.str()]->SetNumber(canvases_[currCanvName.str()]->GetNumber()-1); |
120 |
< |
} |
121 |
< |
//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
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 |
< |
//Draw histogram: |
125 |
< |
int draw_err = ((TChain*) this->At(chainIndex))->Draw(histName.c_str(), cutName.c_str(), currOpt.c_str(), currN); |
126 |
< |
if( draw_err < 0 ) return draw_err; |
127 |
< |
|
128 |
< |
//++++ Fix for histos with no entries +++++++++++++ |
129 |
< |
if( draw_err == 0 ) { |
130 |
< |
if( currOpt.find("SAMES") == string::npos ) { |
131 |
< |
pads_[currPadName.str()]->Close(); |
132 |
< |
pads_.erase( currPadName.str() ); |
133 |
< |
if(useSubPads) canvases_[currCanvName.str()]->SetNumber(canvases_[currCanvName.str()]->GetNumber()-1); |
134 |
< |
} |
135 |
< |
cout<< "Warning: "<<currHistName.str().c_str()<<" in "<<currPadName.str()<<" has no entries and is not drawn!"<<endl; |
136 |
< |
return draw_err; |
137 |
< |
} |
138 |
< |
//++++++++++++++++++++++++++++++++++++++++++++++++++ |
231 |
> |
} |
232 |
|
|
233 |
< |
((TH1F*) pads_[currPadName.str()]->GetPrimitive("htemp"))->SetName(currHistName.str().c_str()); // Set Name of histogram |
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 |
|
|
143 |
– |
return draw_err; |
253 |
|
|
254 |
< |
} |
146 |
< |
//------------------------------------------------------------------ |
147 |
< |
//Standard loop to draw all chains and multiple variables and cuts |
148 |
< |
int PlotTool::loop(vector<string> _histName, vector<string> _cutName, int nEntries, string drwOpt, bool correspond) |
149 |
< |
{ |
254 |
> |
if( addEventInfo ) { |
255 |
|
|
256 |
|
|
257 |
+ |
if(eventNum==0) { |
258 |
+ |
// fwlite::Handle<edm::TriggerResults> hltHandle; |
259 |
+ |
// hltHandle.getByLabel(ev, "TriggerResults"); |
260 |
|
|
261 |
< |
int numProcessed = 0; |
261 |
> |
// fwlite::Handle<edm::TriggerResults> hTriggerResults; |
262 |
|
|
263 |
< |
if( correspond == false ) { |
263 |
> |
// hTriggerResults.getByLabel(ev, "TriggerResults","","TEST"); |
264 |
> |
// fwlite::TriggerNames const& triggerNames = ev.triggerNames(*hTriggerResults); |
265 |
|
|
157 |
– |
for(int i=0; i<this->GetEntries(); ++i) { |
158 |
– |
for(vector<string>::iterator it1 =_histName.begin(); it1 != _histName.end(); ++it1) { |
159 |
– |
for(vector<string>::iterator it2 =_cutName.begin(); it2 != _cutName.end(); ++it2) { |
266 |
|
|
267 |
< |
numProcessed += plot(i, *it1, *it2, nEntries, drwOpt); |
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 |
> |
_event = ev.id().event(); |
274 |
> |
_run = ev.id().run(); |
275 |
> |
_lumi = ev.luminosityBlock(); |
276 |
> |
|
277 |
> |
} |
278 |
> |
|
279 |
> |
if( addTrackJets) |
280 |
> |
{ |
281 |
> |
fwlite::Handle<reco::CaloJetCollection> jets; |
282 |
> |
jets.getByLabel(ev, "antikt5CaloJets"); |
283 |
> |
|
284 |
> |
fwlite::Handle<reco::TrackCollection> tracks; |
285 |
> |
tracks.getByLabel(ev, "generalTracks"); |
286 |
> |
|
287 |
> |
if (!jets.isValid()) |
288 |
> |
continue; |
289 |
> |
if (!tracks.isValid()) |
290 |
> |
continue; |
291 |
> |
double trackSum; |
292 |
> |
nJetsKT = 0; |
293 |
> |
for (reco::CaloJetCollection::const_iterator jet = jets->begin(); jet |
294 |
> |
!=jets->end(); jet++) { |
295 |
> |
trackSum = 0; |
296 |
> |
for (reco::TrackCollection::const_iterator track = tracks->begin(); track |
297 |
> |
!=tracks->end(); track++) { |
298 |
> |
if (deltaR(jet->eta(), jet->phi(), track->eta(), track->phi()) |
299 |
> |
< 0.5) |
300 |
> |
trackSum += track->pt(); |
301 |
> |
} |
302 |
> |
TrackJetKT[nJetsKT] = trackSum; |
303 |
> |
nJetsKT++; |
304 |
> |
} |
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 |
+ |
} |
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 |
< |
} else { |
445 |
> |
f->Close(); |
446 |
> |
((TChain*) this->At(currChain))->AddFriend(friendTreeName.c_str(), |
447 |
> |
friendFileName.c_str()); |
448 |
> |
|
449 |
> |
} |
450 |
|
|
168 |
– |
if( _histName.size() != _cutName.size() ) return -1; |
451 |
|
|
452 |
< |
for(int i=0; i<this->GetEntries(); ++i) { |
453 |
< |
for(vector<string>::iterator it1 =_histName.begin(),it2 =_cutName.begin(); it1 != _cutName.end()&&it2 != _cutName.end(); ++it1, ++it2) { |
452 |
> |
timer.Stop(); |
453 |
> |
if(verbose) timer.Print(); |
454 |
> |
|
455 |
> |
return this->GetEntries(); |
456 |
> |
|
457 |
> |
} |
458 |
> |
//------------------------------------------------------------------ |
459 |
> |
//Draw given Chain with given variable and given cuts |
460 |
> |
int PlotTool::plot(int chainIndex, string histName, string cutName, |
461 |
> |
int nEntries, string drwOpt) { |
462 |
|
|
463 |
< |
numProcessed += plot(i, *it1, *it2, nEntries, drwOpt); |
463 |
> |
if (chainIndex >= this->GetEntries() ) |
464 |
> |
return -1; |
465 |
|
|
466 |
+ |
TStopwatch timer; |
467 |
+ |
if(verbose) { |
468 |
+ |
cout<<"Plot: "<<histName<<" "<<cutName<<" from chain "<<this->At(chainIndex)->GetName()<<endl; |
469 |
+ |
timer.Start(); |
470 |
+ |
} |
471 |
|
|
472 |
< |
} |
473 |
< |
} |
474 |
< |
} |
472 |
> |
int currN = nEntries; |
473 |
> |
if (nEntries < 0) |
474 |
> |
currN = ((TChain*) this->At(chainIndex))->GetEntries(); //nEntries<0 : all entries are plotted! |
475 |
> |
|
476 |
> |
//++++ Create and name Canvases according to global variables +++++++++++++ |
477 |
> |
ostringstream currHistName; |
478 |
> |
if (samePad_trees) |
479 |
> |
currHistName<<((TChain*) this->At(chainIndex))->GetName()<<":"; |
480 |
> |
if (samePad_vars) |
481 |
> |
currHistName<<histName; |
482 |
> |
if (samePad_cuts) |
483 |
> |
currHistName<<"{"<<cutName<<"}"; |
484 |
> |
|
485 |
> |
ostringstream currPadName; |
486 |
> |
if (!samePad_trees) |
487 |
> |
currPadName<<((TChain*) this->At(chainIndex))->GetName()<<":"; |
488 |
> |
if (!samePad_vars) |
489 |
> |
currPadName<<histName; |
490 |
> |
if (!samePad_cuts) |
491 |
> |
currPadName<<"{"<<cutName<<"}"; |
492 |
> |
|
493 |
> |
ostringstream currCanvName; |
494 |
> |
if (!sameCanv_trees && !samePad_trees) |
495 |
> |
currCanvName<<((TChain*) this->At(chainIndex))->GetName()<<":"; |
496 |
> |
if (!sameCanv_vars && !samePad_vars) |
497 |
> |
currCanvName<<histName; |
498 |
> |
if (!sameCanv_cuts && !samePad_cuts) |
499 |
> |
currCanvName<<"{"<<cutName<<"}"; |
500 |
> |
|
501 |
> |
if ( (sameCanv_trees || samePad_trees) && (sameCanv_vars || samePad_vars) |
502 |
> |
&& (sameCanv_cuts || samePad_cuts)) |
503 |
> |
currCanvName<<"All"; |
504 |
> |
|
505 |
> |
string currOpt = drwOpt; |
506 |
> |
bool useSubPads = (sameCanv_trees && !samePad_trees) || (sameCanv_vars |
507 |
> |
&& !samePad_vars) || (sameCanv_cuts && !samePad_cuts); |
508 |
> |
|
509 |
> |
if (useSubPads) { |
510 |
> |
if ( !canvases_[currCanvName.str()] || !gROOT->GetListOfCanvases()->FindObject(currCanvName.str().c_str()) ) { |
511 |
> |
canvases_[currCanvName.str()] = new TCanvas(currCanvName.str().c_str(), currCanvName.str().c_str()); |
512 |
> |
} else if (canvases_[currCanvName.str()]->GetNumber() >= 0) { |
513 |
> |
canvases_[currCanvName.str()]->SetNumber(canvases_[currCanvName.str()]->GetNumber()+1); |
514 |
> |
} |
515 |
> |
} |
516 |
|
|
517 |
< |
updatePads(); |
518 |
< |
fillCanvases(); |
517 |
> |
if ( !pads_[currPadName.str()] || !gROOT->GetListOfCanvases()->FindObject(currPadName.str().c_str()) ) { |
518 |
> |
pads_[currPadName.str()] = new TCanvas(currPadName.str().c_str(), currPadName.str().c_str()); |
519 |
> |
// if (logY) |
520 |
> |
// pads_[currPadName.str()]->SetLogy(1); |
521 |
> |
} else { |
522 |
> |
pads_[currPadName.str()]->cd(); |
523 |
> |
currOpt += "SAMES"; |
524 |
> |
if (useSubPads) |
525 |
> |
canvases_[currCanvName.str()]->SetNumber(canvases_[currCanvName.str()]->GetNumber()-1); |
526 |
> |
} |
527 |
> |
//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
528 |
> |
|
529 |
> |
|
530 |
> |
//Draw histogram: |
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; |
539 |
> |
|
540 |
> |
//++++ Fix for histos with no entries +++++++++++++ |
541 |
> |
if (draw_err == 0) { |
542 |
> |
if (currOpt.find("SAMES") == string::npos) { |
543 |
> |
pads_[currPadName.str()]->Close(); |
544 |
> |
pads_.erase(currPadName.str() ); |
545 |
> |
if (useSubPads) |
546 |
> |
canvases_[currCanvName.str()]->SetNumber(canvases_[currCanvName.str()]->GetNumber()-1); |
547 |
> |
} |
548 |
> |
cout<< "Warning: "<<currHistName.str().c_str()<<" in "<<currPadName.str() |
549 |
> |
<<" has no entries and is not drawn!"<<endl; |
550 |
> |
return draw_err; |
551 |
> |
} |
552 |
> |
//++++++++++++++++++++++++++++++++++++++++++++++++++ |
553 |
> |
|
554 |
> |
((TH1F*) pads_[currPadName.str()]->GetPrimitive("htemp"))->SetName(currHistName.str().c_str()); // Set Name of histogram |
555 |
> |
|
556 |
> |
// Update for 2D histograms |
557 |
> |
if( pads_[currPadName.str()]->GetPrimitive(currHistName.str().c_str())->InheritsFrom("TH2") ) { |
558 |
> |
pads_[currPadName.str()]->Draw(); |
559 |
> |
setCanvas( pads_[currPadName.str()] ); |
560 |
> |
} |
561 |
> |
|
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; |
569 |
> |
|
570 |
> |
} |
571 |
> |
//------------------------------------------------------------------ |
572 |
> |
//Standard loop to draw all chains and multiple variables and cuts |
573 |
> |
int PlotTool::loop(vector<string> _histName, vector<string> _cutName, |
574 |
> |
int nEntries, string drwOpt, bool correspond) { |
575 |
|
|
576 |
< |
return numProcessed; |
576 |
> |
int numProcessed = 0; |
577 |
> |
|
578 |
> |
if (correspond == false) { |
579 |
> |
|
580 |
> |
for (int i=0; i<this->GetEntries(); ++i) { |
581 |
> |
for (vector<string>::iterator it1 =_histName.begin(); it1 |
582 |
> |
!= _histName.end(); ++it1) { |
583 |
> |
for (vector<string>::iterator it2 =_cutName.begin(); it2 |
584 |
> |
!= _cutName.end(); ++it2) { |
585 |
> |
|
586 |
> |
numProcessed += plot(i, *it1, *it2, nEntries, drwOpt); |
587 |
> |
|
588 |
> |
|
589 |
> |
} |
590 |
> |
} |
591 |
> |
} |
592 |
> |
} else { |
593 |
> |
|
594 |
> |
if (_histName.size() != _cutName.size() ) |
595 |
> |
return -1; |
596 |
> |
|
597 |
> |
for (int i=0; i<this->GetEntries(); ++i) { |
598 |
> |
for (vector<string>::iterator it1 =_histName.begin(), it2 = |
599 |
> |
_cutName.begin(); it1 != _cutName.end()&&it2 |
600 |
> |
!= _cutName.end(); ++it1, ++it2) { |
601 |
> |
|
602 |
> |
numProcessed += plot(i, *it1, *it2, nEntries, drwOpt); |
603 |
> |
|
604 |
> |
} |
605 |
> |
} |
606 |
> |
} |
607 |
> |
|
608 |
> |
updatePads(); |
609 |
> |
fillCanvases(); |
610 |
> |
|
611 |
> |
return numProcessed; |
612 |
|
} |
613 |
|
|
614 |
|
//Helper methods to allow for using simple strings as input |
615 |
< |
int PlotTool::loop(string histName, string cutName, int nEntries, string drwOpt) |
188 |
< |
{ |
615 |
> |
int PlotTool::loop(string histName, string cutName, int nEntries, string drwOpt) { |
616 |
|
|
617 |
< |
vector<string> _histName; |
618 |
< |
_histName.push_back( histName ); |
619 |
< |
vector<string> _cutName; |
620 |
< |
_cutName.push_back( cutName ); |
617 |
> |
vector<string> _histName; |
618 |
> |
_histName.push_back(histName); |
619 |
> |
vector<string> _cutName; |
620 |
> |
_cutName.push_back(cutName); |
621 |
|
|
622 |
< |
return loop(_histName, _cutName, nEntries, drwOpt); |
622 |
> |
return loop(_histName, _cutName, nEntries, drwOpt); |
623 |
|
|
624 |
|
} |
625 |
|
|
626 |
< |
int PlotTool::loop(vector<string> _histName, string cutName, int nEntries, string drwOpt) |
627 |
< |
{ |
626 |
> |
int PlotTool::loop(vector<string> _histName, string cutName, int nEntries, |
627 |
> |
string drwOpt) { |
628 |
|
|
629 |
< |
vector<string> _cutName; |
630 |
< |
_cutName.push_back( cutName ); |
629 |
> |
vector<string> _cutName; |
630 |
> |
_cutName.push_back(cutName); |
631 |
|
|
632 |
< |
return loop(_histName, _cutName, nEntries, drwOpt); |
632 |
> |
return loop(_histName, _cutName, nEntries, drwOpt); |
633 |
|
|
634 |
|
} |
635 |
|
|
636 |
< |
int PlotTool::loop(string histName, vector<string> _cutName, int nEntries, string drwOpt) |
637 |
< |
{ |
636 |
> |
int PlotTool::loop(string histName, vector<string> _cutName, int nEntries, |
637 |
> |
string drwOpt) { |
638 |
|
|
639 |
< |
vector<string> _histName; |
640 |
< |
_histName.push_back( histName ); |
639 |
> |
vector<string> _histName; |
640 |
> |
_histName.push_back(histName); |
641 |
|
|
642 |
< |
return loop(_histName, _cutName, nEntries, drwOpt); |
642 |
> |
return loop(_histName, _cutName, nEntries, drwOpt); |
643 |
|
} |
644 |
|
//------------------------------------------------------------------ |
645 |
|
//redraw the canvas to make changes in style visible |
646 |
< |
int PlotTool::updatePads() { |
646 |
> |
int PlotTool::updatePads() { |
647 |
|
|
648 |
< |
for(map< string, TCanvas* >::iterator it=pads_.begin() ; it != pads_.end(); ++it ) { |
649 |
< |
if( gROOT->FindObject( (*it).first.c_str() ) ) { |
650 |
< |
(*it).second->Draw(); |
651 |
< |
setCanvas( (*it).second ); |
652 |
< |
} else pads_.erase( it ); |
653 |
< |
} |
648 |
> |
for (map< string, TCanvas* >::iterator it=pads_.begin() ; it != pads_.end(); ++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 |
< |
return pads_.size(); |
661 |
> |
} |
662 |
> |
|
663 |
> |
return pads_.size(); |
664 |
|
|
665 |
|
} |
666 |
|
|
667 |
|
int PlotTool::fillCanvases() { |
668 |
|
|
669 |
+ |
for (map< string, TCanvas* >::iterator it=canvases_.begin() ; it |
670 |
+ |
!= canvases_.end(); ++it) { |
671 |
+ |
string canvName = (*it).first; |
672 |
+ |
if (gROOT->GetListOfCanvases()->FindObject(canvName.c_str()) ) { |
673 |
+ |
|
674 |
+ |
int numP = (*it).second->GetNumber()+1; |
675 |
+ |
|
676 |
+ |
if (numP <= 0) |
677 |
+ |
continue; |
678 |
+ |
|
679 |
+ |
int x = int( sqrt(numP) ); |
680 |
+ |
int y = x; |
681 |
+ |
if (x*y < numP) |
682 |
+ |
x += 1; |
683 |
+ |
if (x*y < numP) |
684 |
+ |
x += 1; |
685 |
+ |
if (x*y < numP) { |
686 |
+ |
x -= 1; |
687 |
+ |
y += 1; |
688 |
+ |
} |
689 |
+ |
|
690 |
+ |
|
691 |
+ |
(*it).second->Divide(x, y); |
692 |
+ |
int padIndex = 1; |
693 |
+ |
for (map< string, TCanvas* >::iterator it2=pads_.begin() ; it2 |
694 |
+ |
!= pads_.end(); ++it2) { |
695 |
+ |
string padName = (*it2).first; |
696 |
+ |
if (gROOT->GetListOfCanvases()->FindObject(padName.c_str() ) ) { |
697 |
+ |
string n1 = canvName.substr(0,canvName.find(":")); |
698 |
+ |
string n2(""); |
699 |
+ |
if(canvName.find("{") != string::npos ) n2 = canvName.substr(canvName.find("{"),canvName.find("}")); |
700 |
+ |
|
701 |
+ |
if ( (padName.find(canvName.c_str()) != string::npos ) || (padName.find(n1) != string::npos && padName.find(n2) != string::npos) || !strcmp( canvName.c_str(), "All") ) { |
702 |
+ |
(*it).second->cd(padIndex); |
703 |
+ |
(*it2).second->DrawClonePad(); |
704 |
+ |
(*it2).second->Close(); |
705 |
+ |
pads_.erase(it2); |
706 |
+ |
++padIndex; |
707 |
+ |
} |
708 |
+ |
} else |
709 |
+ |
pads_.erase(it2); |
710 |
+ |
} |
711 |
+ |
(*it).second->SetNumber(-1); |
712 |
|
|
713 |
< |
for(map< string, TCanvas* >::iterator it=canvases_.begin() ; it != canvases_.end(); ++it ) { |
714 |
< |
const char* canvName = (*it).first.c_str(); |
715 |
< |
if( gROOT->FindObject( canvName ) ) { |
238 |
< |
|
239 |
< |
int numP = (*it).second->GetNumber()+1; |
240 |
< |
|
241 |
< |
if( numP <= 0 ) continue; |
242 |
< |
|
243 |
< |
int x = int( sqrt(numP) ); |
244 |
< |
int y = x; |
245 |
< |
if( x*y < numP ) x += 1; |
246 |
< |
if( x*y < numP ) x += 1; |
247 |
< |
if( x*y < numP ) { |
248 |
< |
x -= 1; |
249 |
< |
y += 1; |
250 |
< |
} |
251 |
< |
|
252 |
< |
(*it).second->Divide(x,y); |
253 |
< |
int padIndex = 1; |
254 |
< |
for(map< string, TCanvas* >::iterator it2=pads_.begin() ; it2 != pads_.end(); ++it2 ) { |
255 |
< |
string padName = (*it2).first; |
256 |
< |
if( gROOT->FindObject( padName.c_str() ) ) { |
257 |
< |
if( ( padName.find(canvName) != string::npos ) || !strcmp(canvName,"All") ) { |
258 |
< |
(*it).second->cd(padIndex); |
259 |
< |
(*it2).second->DrawClonePad(); |
260 |
< |
(*it2).second->Close(); |
261 |
< |
pads_.erase( it2 ); |
262 |
< |
++padIndex; |
263 |
< |
} |
264 |
< |
} else pads_.erase( it2 ); |
265 |
< |
} |
266 |
< |
(*it).second->SetNumber(-1); |
267 |
< |
|
268 |
< |
} else canvases_.erase( it ); |
269 |
< |
} |
713 |
> |
} else |
714 |
> |
canvases_.erase(it); |
715 |
> |
} |
716 |
|
|
717 |
< |
return canvases_.size(); |
717 |
> |
return canvases_.size(); |
718 |
|
|
719 |
|
} |
720 |
|
//------------------------------------------------------------------ |
721 |
|
void PlotTool::setCanvas(TCanvas* thisCanvas) { |
722 |
|
|
723 |
+ |
TH1* thisHist = 0; |
724 |
+ |
TPaveStats* thisStatsBox = 0; |
725 |
+ |
TPaletteAxis* palette =0; |
726 |
+ |
TLegend* thisLeg = 0; |
727 |
+ |
int counter =0; |
728 |
+ |
double maxEntry=0; |
729 |
|
|
730 |
< |
TH1* thisHist = 0; |
731 |
< |
TPaveStats* thisStatsBox = 0; |
280 |
< |
TPaletteAxis* palette =0; |
281 |
< |
TLegend* thisLeg = 0; |
282 |
< |
int counter =0; |
283 |
< |
double maxEntry=0; |
284 |
< |
|
285 |
< |
|
286 |
< |
((TFrame*) thisCanvas->GetFrame())->Delete(); |
287 |
< |
thisCanvas->GetFrame()->SetLineWidth( gStyle->GetLineWidth() ); |
288 |
< |
|
289 |
< |
thisCanvas->SetLeftMargin(0.2); |
290 |
< |
thisCanvas->SetRightMargin(0.06); |
291 |
< |
thisCanvas->SetBottomMargin(0.2); |
292 |
< |
thisCanvas->SetTopMargin(0.1); |
730 |
> |
((TFrame*) thisCanvas->GetFrame())->Delete(); |
731 |
> |
thisCanvas->GetFrame()->SetLineWidth(gStyle->GetLineWidth() ); |
732 |
|
|
733 |
< |
if(logY) thisCanvas->SetLogy(1); |
734 |
< |
else thisCanvas->SetLogy(0); |
733 |
> |
thisCanvas->SetLeftMargin(0.2); |
734 |
> |
thisCanvas->SetRightMargin(0.06); |
735 |
> |
thisCanvas->SetBottomMargin(0.2); |
736 |
> |
thisCanvas->SetTopMargin(0.1); |
737 |
|
|
738 |
< |
if(showLegend) thisLeg = new TLegend(); |
739 |
< |
|
738 |
> |
if (logY) |
739 |
> |
thisCanvas->SetLogy(1); |
740 |
> |
else |
741 |
> |
thisCanvas->SetLogy(0); |
742 |
|
|
743 |
< |
for(int i = 0; i != thisCanvas->GetListOfPrimitives()->GetSize(); ++i){ |
743 |
> |
if (showLegend) |
744 |
> |
thisLeg = new TLegend(); |
745 |
|
|
746 |
+ |
for (int i = 0; i != thisCanvas->GetListOfPrimitives()->GetSize(); ++i) { |
747 |
|
|
748 |
< |
if( ! thisCanvas->GetListOfPrimitives()->At(i)->InheritsFrom("TH1")) continue; |
748 |
> |
if ( !thisCanvas->GetListOfPrimitives()->At(i)->InheritsFrom("TH1")) |
749 |
> |
continue; |
750 |
|
|
751 |
< |
thisHist = ((TH1*) thisCanvas->GetListOfPrimitives()->At(i)); |
752 |
< |
setColor(thisHist, counter); |
753 |
< |
setMathLabels(thisHist); |
751 |
> |
thisHist = ((TH1*) thisCanvas->GetListOfPrimitives()->At(i)); |
752 |
> |
setColor(thisHist, counter); |
753 |
> |
setMathLabels(thisHist); |
754 |
|
|
755 |
< |
if(thisHist->GetMaximum() > maxEntry) maxEntry = thisHist->GetMaximum(); |
755 |
> |
if (thisHist->GetMaximum() > maxEntry) |
756 |
> |
maxEntry = thisHist->GetMaximum(); |
757 |
|
|
758 |
< |
thisStatsBox = (TPaveStats*) thisHist->GetListOfFunctions()->FindObject("stats"); |
759 |
< |
if(thisStatsBox) setStats(thisCanvas, thisStatsBox, thisHist, counter); |
758 |
> |
thisStatsBox = (TPaveStats*) thisHist->GetListOfFunctions()->FindObject("stats"); |
759 |
> |
if (thisStatsBox) |
760 |
> |
setStats(thisCanvas, thisStatsBox, thisHist, counter); |
761 |
|
|
762 |
< |
palette = (TPaletteAxis*) thisHist->GetListOfFunctions()->FindObject("palette"); |
763 |
< |
if(palette) setPalette(thisCanvas, palette); |
762 |
> |
palette = (TPaletteAxis*) thisHist->GetListOfFunctions()->FindObject("palette"); |
763 |
> |
if (palette) |
764 |
> |
setPalette(thisCanvas, palette); |
765 |
|
|
766 |
< |
if(thisLeg) thisLeg->AddEntry(thisHist,thisHist->GetName())->SetTextSize(0.04); |
766 |
> |
if (thisLeg) |
767 |
> |
thisLeg->AddEntry(thisHist,thisHist->GetName())->SetTextSize(0.04); |
768 |
|
|
769 |
+ |
++counter; |
770 |
|
|
771 |
< |
++counter; |
321 |
< |
|
322 |
< |
} |
771 |
> |
} |
772 |
|
|
773 |
< |
if( maxEntry != 0) setHistMax(thisCanvas, maxEntry); |
774 |
< |
|
773 |
> |
if (maxEntry != 0) |
774 |
> |
setHistMax(thisCanvas, maxEntry); |
775 |
|
|
776 |
< |
thisCanvas->cd(); |
777 |
< |
thisCanvas->Update(); |
776 |
> |
thisCanvas->cd(); |
777 |
> |
thisCanvas->Update(); |
778 |
> |
|
779 |
> |
if (thisLeg) |
780 |
> |
setLegend(thisCanvas, thisLeg, counter); |
781 |
|
|
330 |
– |
if(thisLeg) setLegend( thisCanvas, thisLeg, counter); |
331 |
– |
|
332 |
– |
|
782 |
|
} |
783 |
|
//------------------------------------------------------------------ |
784 |
|
//private helper classes to set the canvas and hist style |
785 |
< |
void PlotTool::setStats(TCanvas* thisCanvas, TPaveStats* thisStatsBox, TH1* thisHist, int counter) { |
785 |
> |
void PlotTool::setStats(TCanvas* thisCanvas, TPaveStats* thisStatsBox, |
786 |
> |
TH1* thisHist, int counter) { |
787 |
|
|
788 |
+ |
if (thisCanvas->GetRightMargin() < .2) |
789 |
+ |
thisCanvas->SetRightMargin(.2); |
790 |
|
|
791 |
< |
if(thisCanvas->GetRightMargin() < .2) thisCanvas->SetRightMargin(.2); |
791 |
> |
thisStatsBox->SetLineColor(thisHist->GetLineColor()); |
792 |
> |
thisStatsBox->SetX2NDC(1.); |
793 |
> |
thisStatsBox->SetY2NDC(1-thisCanvas->GetTopMargin()-0.16*counter); |
794 |
> |
thisStatsBox->SetX1NDC(1-thisCanvas->GetRightMargin()+0.01); |
795 |
> |
thisStatsBox->SetY1NDC(thisStatsBox->GetY2NDC()-.15); |
796 |
|
|
797 |
< |
thisStatsBox->SetLineColor(thisHist->GetLineColor()); |
342 |
< |
thisStatsBox->SetX2NDC(1.); |
343 |
< |
thisStatsBox->SetY2NDC(1-thisCanvas->GetTopMargin()-0.16*counter); |
344 |
< |
thisStatsBox->SetX1NDC(1-thisCanvas->GetRightMargin()+0.01); |
345 |
< |
thisStatsBox->SetY1NDC(thisStatsBox->GetY2NDC()-.15); |
797 |
> |
} |
798 |
|
|
799 |
+ |
void PlotTool::setMathLabels(TH1* thisHist) { |
800 |
|
|
801 |
+ |
string t = thisHist ->GetTitle(); |
802 |
+ |
string x = thisHist->GetXaxis()->GetTitle(); |
803 |
+ |
string y = thisHist->GetYaxis()->GetTitle(); |
804 |
+ |
|
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 |
+ |
|
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 (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} [GeV]"); |
832 |
+ |
if (y.find(".pt()") != string::npos) |
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()); |
856 |
+ |
thisHist->GetYaxis()->SetTitle(y.c_str()); |
857 |
|
|
858 |
|
} |
859 |
|
|
860 |
< |
void PlotTool::setMathLabels(TH1* thisHist) { |
860 |
> |
void PlotTool::setColor(TH1* thisHist, int counter) { |
861 |
|
|
862 |
+ |
if (counter == 0) { |
863 |
|
|
864 |
< |
string t = thisHist ->GetTitle(); |
865 |
< |
string x = thisHist->GetXaxis()->GetTitle(); |
866 |
< |
string y = thisHist->GetYaxis()->GetTitle(); |
867 |
< |
|
868 |
< |
if(t.find(".phi()") != string::npos ) t.replace(t.find(".phi()"),6," #phi"); |
869 |
< |
if(x.find(".phi()") != string::npos ) x.replace(x.find(".phi()"),6," #phi"); |
870 |
< |
if(y.find(".phi()") != string::npos ) y.replace(y.find(".phi()"),6," #phi"); |
871 |
< |
|
872 |
< |
if(t.find(".eta()") != string::npos ) t.replace(t.find(".eta()"),6," #eta"); |
873 |
< |
if(x.find(".eta()") != string::npos ) x.replace(x.find(".eta()"),6," #eta"); |
874 |
< |
if(y.find(".eta()") != string::npos ) y.replace(y.find(".eta()"),6," #eta"); |
875 |
< |
|
876 |
< |
if(t.find(".pt()") != string::npos ) t.replace(t.find(".pt()"),5," p_{T}"); |
877 |
< |
if(x.find(".pt()") != string::npos ) x.replace(x.find(".pt()"),5," p_{T}"); |
878 |
< |
if(y.find(".pt()") != string::npos ) y.replace(y.find(".pt()"),5," p_{T}"); |
879 |
< |
|
880 |
< |
thisHist ->SetTitle(t.c_str()); |
881 |
< |
thisHist->GetXaxis()->SetTitle(x.c_str()); |
882 |
< |
thisHist->GetYaxis()->SetTitle(y.c_str()); |
864 |
> |
thisHist->SetLineColor(kRed+1); |
865 |
> |
//if( gStyle->GetHistFillStyle() ) thisHist->SetFillColor (kRed+1); |
866 |
> |
//else |
867 |
> |
thisHist->SetFillStyle(0); |
868 |
> |
thisHist->SetMarkerColor(kRed+1); |
869 |
> |
} else if (counter == 1) { |
870 |
> |
thisHist->SetLineColor(kBlue+1); |
871 |
> |
//if( gStyle->GetHistFillStyle() ) thisHist->SetFillColor (kBlue+1); |
872 |
> |
//else |
873 |
> |
thisHist->SetFillStyle(0); |
874 |
> |
thisHist->SetMarkerColor(kBlue+1); |
875 |
> |
|
876 |
> |
} else if (counter == 2) { |
877 |
> |
thisHist->SetLineColor(kGreen+2); |
878 |
> |
//if( gStyle->GetHistFillStyle() ) thisHist->SetFillColor (kGreen+2); |
879 |
> |
//else |
880 |
> |
thisHist->SetFillStyle(0); |
881 |
> |
thisHist->SetMarkerColor(kGreen+2); |
882 |
> |
|
883 |
> |
} else if (counter == 3) { |
884 |
> |
thisHist->SetLineColor(kMagenta+2); |
885 |
> |
//if( gStyle->GetHistFillStyle() ) thisHist->SetFillColor (kMagenta+2); |
886 |
> |
//else |
887 |
> |
thisHist->SetFillStyle(0); |
888 |
> |
thisHist->SetMarkerColor(kMagenta+2); |
889 |
> |
|
890 |
> |
} else if (counter == 4) { |
891 |
> |
thisHist->SetLineColor(kCyan+2); |
892 |
> |
//if( gStyle->GetHistFillStyle() ) thisHist->SetFillColor (kCyan+2); |
893 |
> |
//else |
894 |
> |
thisHist->SetFillStyle(0); |
895 |
> |
thisHist->SetMarkerColor(kCyan+2); |
896 |
> |
|
897 |
> |
} else { |
898 |
> |
thisHist->SetLineColor(kBlack); |
899 |
> |
//if( gStyle->GetHistFillStyle() ) thisHist->SetFillColor (kBlack); |
900 |
> |
//else |
901 |
> |
thisHist->SetFillStyle(0); |
902 |
> |
thisHist->SetMarkerColor(kBlack); |
903 |
|
|
904 |
+ |
} |
905 |
|
|
906 |
|
} |
907 |
|
|
908 |
+ |
void PlotTool::setPalette(TCanvas* thisCanvas, TPaletteAxis* palette) { |
909 |
|
|
910 |
< |
void PlotTool::setColor(TH1* thisHist, int counter) { |
910 |
> |
palette->SetLabelSize(0.045); |
911 |
> |
if (thisCanvas->GetRightMargin() < .15) |
912 |
> |
thisCanvas->SetRightMargin(.15); |
913 |
> |
palette->SetX1NDC(1-thisCanvas->GetRightMargin()+0.01); |
914 |
> |
palette->SetY1NDC(thisCanvas->GetBottomMargin()); |
915 |
> |
palette->SetX2NDC(palette->GetX1NDC()+0.05); |
916 |
> |
palette->SetY2NDC(1-thisCanvas->GetTopMargin()); |
917 |
|
|
918 |
+ |
} |
919 |
|
|
920 |
< |
if(counter == 0) { |
920 |
> |
void PlotTool::setHistMax(TCanvas* thisCanvas, double maxEntry) { |
921 |
|
|
922 |
< |
thisHist->SetLineColor (kRed+1); |
384 |
< |
if( gStyle->GetHistFillStyle() ) thisHist->SetFillColor (kRed+1); |
385 |
< |
else thisHist->SetFillStyle(0); |
386 |
< |
thisHist->SetMarkerColor(kRed+1); |
387 |
< |
} else if(counter == 1) { |
388 |
< |
thisHist->SetLineColor (kBlue+1); |
389 |
< |
if( gStyle->GetHistFillStyle() ) thisHist->SetFillColor (kBlue+1); |
390 |
< |
else thisHist->SetFillStyle(0); |
391 |
< |
thisHist->SetMarkerColor(kBlue+1); |
392 |
< |
|
393 |
< |
} else if(counter == 2) { |
394 |
< |
thisHist->SetLineColor (kGreen+2); |
395 |
< |
if( gStyle->GetHistFillStyle() ) thisHist->SetFillColor (kGreen+2); |
396 |
< |
else thisHist->SetFillStyle(0); |
397 |
< |
thisHist->SetMarkerColor(kGreen+2); |
398 |
< |
|
399 |
< |
} else if(counter == 3) { |
400 |
< |
thisHist->SetLineColor (kMagenta+2); |
401 |
< |
if( gStyle->GetHistFillStyle() ) thisHist->SetFillColor (kMagenta+2); |
402 |
< |
else thisHist->SetFillStyle(0); |
403 |
< |
thisHist->SetMarkerColor(kMagenta+2); |
404 |
< |
|
405 |
< |
} else if(counter == 4) { |
406 |
< |
thisHist->SetLineColor (kCyan+2); |
407 |
< |
if( gStyle->GetHistFillStyle() ) thisHist->SetFillColor (kCyan+2); |
408 |
< |
else thisHist->SetFillStyle(0); |
409 |
< |
thisHist->SetMarkerColor(kCyan+2); |
410 |
< |
|
411 |
< |
} else { |
412 |
< |
thisHist->SetLineColor (kBlack); |
413 |
< |
if( gStyle->GetHistFillStyle() ) thisHist->SetFillColor (kBlack); |
414 |
< |
else thisHist->SetFillStyle(0); |
415 |
< |
thisHist->SetMarkerColor(kBlack); |
922 |
> |
TH1* thisHist = 0; |
923 |
|
|
924 |
< |
} |
924 |
> |
for (int i = 0; i != thisCanvas->GetListOfPrimitives()->GetSize(); ++i) { |
925 |
> |
|
926 |
> |
if ( !thisCanvas->GetListOfPrimitives()->At(i)->InheritsFrom("TH1") ) |
927 |
> |
continue; |
928 |
> |
thisHist = ((TH1*) thisCanvas->GetListOfPrimitives()->At(i)); |
929 |
> |
if (thisHist->GetMaximum() < maxEntry) { |
930 |
> |
double minEntry=thisHist->GetBinContent(thisHist->GetMinimumBin()); |
931 |
> |
if (logY) { |
932 |
> |
int bin = (thisHist->GetMinimumBin()+1); |
933 |
> |
minEntry=thisHist->GetBinContent(bin); |
934 |
> |
} |
935 |
> |
thisHist->GetYaxis()->SetRangeUser(minEntry, maxEntry*1.2); |
936 |
> |
} |
937 |
> |
break; |
938 |
> |
|
939 |
> |
} |
940 |
|
|
941 |
|
} |
942 |
|
|
943 |
< |
void PlotTool::setPalette(TCanvas* thisCanvas, TPaletteAxis* palette) { |
943 |
> |
void PlotTool::setLegend(TCanvas* thisCanvas, TLegend* thisLeg, int counter) { |
944 |
|
|
945 |
+ |
thisLeg->SetFillStyle(0); |
946 |
+ |
thisLeg->SetX1NDC(1-thisCanvas->GetRightMargin()-0.5); |
947 |
+ |
thisLeg->SetY1NDC(1-thisCanvas->GetTopMargin()-0.05*counter); |
948 |
+ |
thisLeg->SetX2NDC(1-thisCanvas->GetRightMargin()); |
949 |
+ |
thisLeg->SetY2NDC(1-thisCanvas->GetTopMargin()); |
950 |
+ |
thisLeg->SetEntrySeparation(0.5); |
951 |
+ |
thisLeg->Draw("NDC"); |
952 |
|
|
953 |
< |
palette->SetLabelSize(0.045); |
425 |
< |
if(thisCanvas->GetRightMargin() < .15) thisCanvas->SetRightMargin(.15); |
426 |
< |
palette->SetX1NDC(1-thisCanvas->GetRightMargin()+0.01); |
427 |
< |
palette->SetY1NDC(thisCanvas->GetBottomMargin()); |
428 |
< |
palette->SetX2NDC(palette->GetX1NDC()+0.05); |
429 |
< |
palette->SetY2NDC(1-thisCanvas->GetTopMargin()); |
953 |
> |
} |
954 |
|
|
955 |
+ |
void PlotTool::createColors() { |
956 |
+ |
const Int_t NRGBs = 5; |
957 |
+ |
const Int_t NCont = 255; |
958 |
+ |
|
959 |
+ |
Double_t stops[NRGBs] = { 0.00, 0.34, 0.61, 0.84, 1.00 }; |
960 |
+ |
Double_t red[NRGBs] = { 0.00, 0.00, 0.87, 1.00, 0.51 }; |
961 |
+ |
Double_t green[NRGBs] = { 0.00, 0.81, 1.00, 0.20, 0.00 }; |
962 |
+ |
Double_t blue[NRGBs] = { 0.51, 1.00, 0.12, 0.00, 0.00 }; |
963 |
+ |
TColor::CreateGradientColorTable(NRGBs, stops, red, green, blue, NCont); |
964 |
+ |
gStyle->SetNumberContours(NCont); |
965 |
|
|
966 |
|
} |
967 |
|
|
968 |
< |
void PlotTool::setHistMax(TCanvas* thisCanvas, double maxEntry) { |
968 |
> |
//------------------------------------------------------------------ |
969 |
|
|
970 |
< |
TH1* thisHist = 0; |
970 |
> |
int PlotTool::saveCanvases(string name, string path) { |
971 |
|
|
972 |
< |
for(int i = 0; i != thisCanvas->GetListOfPrimitives()->GetSize(); ++i){ |
972 |
> |
TSystemDirectory d("", path.c_str()); |
973 |
> |
if (!d.GetListOfFiles()) |
974 |
> |
return -1; |
975 |
|
|
976 |
< |
if( ! thisCanvas->GetListOfPrimitives()->At(i)->InheritsFrom("TH1") ) continue; |
977 |
< |
thisHist = ((TH1*) thisCanvas->GetListOfPrimitives()->At(i)); |
442 |
< |
if( thisHist->GetMaximum() < maxEntry ) thisHist->GetYaxis()->SetRangeUser(thisHist->GetMinimum(),maxEntry*1.2); |
443 |
< |
break; |
976 |
> |
string namePs = path +"/" + name; |
977 |
> |
string nameRt = path +"/" + name; |
978 |
|
|
979 |
< |
} |
979 |
> |
if (name.find(".ps") == string::npos) |
980 |
> |
namePs += ".ps"; |
981 |
|
|
982 |
+ |
if (name.find(".root") == string::npos) |
983 |
+ |
nameRt += ".root"; |
984 |
|
|
985 |
< |
} |
985 |
> |
int savedCanvs =0; |
986 |
> |
|
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 |
|
|
450 |
– |
void PlotTool::setLegend(TCanvas* thisCanvas, TLegend* thisLeg, int counter) { |
997 |
|
|
998 |
< |
thisLeg->SetFillStyle(0); |
999 |
< |
thisLeg->SetX1NDC(1-thisCanvas->GetRightMargin()-0.5); |
454 |
< |
thisLeg->SetY1NDC(1-thisCanvas->GetTopMargin()-0.05*counter); |
455 |
< |
thisLeg->SetX2NDC(1-thisCanvas->GetRightMargin()); |
456 |
< |
thisLeg->SetY2NDC(1-thisCanvas->GetTopMargin()); |
457 |
< |
thisLeg->SetEntrySeparation(0.5); |
458 |
< |
thisLeg->Draw("NDC"); |
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 |
+ |
|
1010 |
+ |
|
1011 |
+ |
++savedCanvs; |
1012 |
+ |
|
1013 |
+ |
} |
1014 |
+ |
|
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 |
< |
void PlotTool::createColors() |
1025 |
> |
} |
1026 |
> |
//------------------------------------------------------------------ |
1027 |
> |
|
1028 |
> |
int PlotTool::clearCanvases() |
1029 |
|
{ |
464 |
– |
const Int_t NRGBs = 5; |
465 |
– |
const Int_t NCont = 255; |
1030 |
|
|
1031 |
< |
Double_t stops[NRGBs] = { 0.00, 0.34, 0.61, 0.84, 1.00 }; |
1032 |
< |
Double_t red[NRGBs] = { 0.00, 0.00, 0.87, 1.00, 0.51 }; |
1033 |
< |
Double_t green[NRGBs] = { 0.00, 0.81, 1.00, 0.20, 0.00 }; |
1034 |
< |
Double_t blue[NRGBs] = { 0.51, 1.00, 0.12, 0.00, 0.00 }; |
471 |
< |
TColor::CreateGradientColorTable(NRGBs, stops, red, green, blue, NCont); |
472 |
< |
gStyle->SetNumberContours(NCont); |
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 |
|
} |
1037 |
+ |
//------------------------------------------------------------------ |
1038 |
+ |
int PlotTool::setVariables(string label) |
1039 |
+ |
{ |
1040 |
|
|
1041 |
+ |
for (int i=0; i< this->GetEntries(); ++i) { |
1042 |
+ |
cout<<"--------------------------------"<<endl; |
1043 |
+ |
cout<<((TChain*) this->At(i))->GetName()<<endl; |
1044 |
+ |
cout<<"------------"<<endl; |
1045 |
+ |
|
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 |
< |
//------------------------------------------------------------------ |
1092 |
> |
} |
1093 |
|
|
1094 |
< |
int PlotTool::saveCanvases(string type, string path) { |
1094 |
> |
} |
1095 |
|
|
1096 |
+ |
return autoVars.size(); |
1097 |
|
|
1098 |
< |
TSystemDirectory d("",path.c_str()); |
1099 |
< |
if(!d.GetListOfFiles()) return -1; |
1100 |
< |
if(type.find(".") == string::npos) return -1; |
1098 |
> |
} |
1099 |
> |
//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
1100 |
> |
//Draw efficiencies |
1101 |
> |
int PlotTool::plotEff(int chainIndex, string histName, string cutName, int nEntries, double fitXmin, double fitXmax, string fitFormula) |
1102 |
> |
{ |
1103 |
|
|
1104 |
< |
int savedFiles =0; |
1104 |
> |
if( chainIndex >= this->GetEntries() ) return -1; |
1105 |
|
|
1106 |
< |
TIter next(gROOT->GetListOfCanvases()); |
1107 |
< |
TCanvas* canv; |
1108 |
< |
while ((canv=(TCanvas*)next())) { |
1109 |
< |
|
1110 |
< |
string s = ""; |
1111 |
< |
s += path; |
1112 |
< |
s += canv->GetName(); |
1113 |
< |
s += type; |
1106 |
> |
int currN = nEntries; |
1107 |
> |
if(nEntries < 0) currN = ((TChain*) this->At(chainIndex))->GetEntries(); //nEntries<0 : all entries are plotted! |
1108 |
> |
|
1109 |
> |
//++++ Create and name Canvases according to global variables +++++++++++++ |
1110 |
> |
ostringstream currHistName; |
1111 |
> |
if( samePad_trees) currHistName<<((TChain*) this->At(chainIndex))->GetName()<<":"; |
1112 |
> |
if( samePad_vars) currHistName<<histName; |
1113 |
> |
if( samePad_cuts) currHistName<<"{"<<cutName<<"}"; |
1114 |
|
|
1115 |
< |
canv->SaveAs(s.c_str()); |
1116 |
< |
++savedFiles; |
1115 |
> |
ostringstream currPadName; |
1116 |
> |
if(! samePad_trees) currPadName<<((TChain*) this->At(chainIndex))->GetName()<<":"; |
1117 |
> |
if(! samePad_vars) currPadName<<histName; |
1118 |
> |
if(! samePad_cuts) currPadName<<"{"<<cutName<<"}"; |
1119 |
|
|
1120 |
+ |
|
1121 |
+ |
//Draw total histogram: |
1122 |
+ |
if( ! pads_["total"] || ! gROOT->FindObject("total") ) { |
1123 |
+ |
pads_["total"] = new TCanvas("total", "total"); |
1124 |
+ |
} else { |
1125 |
+ |
pads_["total"]->cd(); |
1126 |
|
} |
1127 |
+ |
ostringstream bins_total; |
1128 |
+ |
bins_total<<histName; |
1129 |
+ |
bins_total<<">>total(100,0,1000)"; |
1130 |
+ |
|
1131 |
+ |
|
1132 |
+ |
int draw_err = ((TChain*) this->At(chainIndex))->Draw(bins_total.str().c_str(), "", "", currN); |
1133 |
+ |
if( draw_err <= 0 ) return draw_err; |
1134 |
+ |
|
1135 |
+ |
|
1136 |
+ |
TH1* total = ((TH1*) pads_["total"]->GetPrimitive("total")); |
1137 |
+ |
|
1138 |
+ |
ostringstream bins_bkg; |
1139 |
+ |
bins_bkg<<histName; |
1140 |
+ |
bins_bkg<<">>bkg("; |
1141 |
+ |
bins_bkg<<total->GetNbinsX(); |
1142 |
+ |
bins_bkg<<","; |
1143 |
+ |
bins_bkg<<total->GetXaxis()->GetXmin(); |
1144 |
+ |
bins_bkg<<","; |
1145 |
+ |
bins_bkg<<total->GetXaxis()->GetXmax(); |
1146 |
+ |
bins_bkg<<")"; |
1147 |
|
|
1148 |
< |
return savedFiles; |
1148 |
> |
//Draw bkg histogram: |
1149 |
> |
if( ! pads_["bkg"] || ! gROOT->FindObject("bkg") ) { |
1150 |
> |
pads_["bkg"] = new TCanvas("bkg", currPadName.str().c_str()); |
1151 |
> |
} else { |
1152 |
> |
pads_["bkg"]->cd(); |
1153 |
> |
} |
1154 |
> |
|
1155 |
> |
draw_err = ((TChain*) this->At(chainIndex))->Draw(bins_bkg.str().c_str(), cutName.c_str(),"" , currN); |
1156 |
> |
if( draw_err <= 0 ) return draw_err; |
1157 |
> |
|
1158 |
> |
|
1159 |
> |
TH1* bkg = ((TH1*) pads_["bkg"]->GetPrimitive("bkg")); |
1160 |
> |
|
1161 |
> |
//Draw pass histogram: |
1162 |
> |
ostringstream bins_pass; |
1163 |
> |
bins_pass<<histName; |
1164 |
> |
bins_pass<<">>pass("; |
1165 |
> |
bins_pass<<total->GetNbinsX(); |
1166 |
> |
bins_pass<<","; |
1167 |
> |
bins_pass<<total->GetXaxis()->GetXmin(); |
1168 |
> |
bins_pass<<","; |
1169 |
> |
bins_pass<<total->GetXaxis()->GetXmax(); |
1170 |
> |
bins_pass<<")"; |
1171 |
> |
|
1172 |
> |
ostringstream cut_pass; |
1173 |
> |
cut_pass<<"!("; |
1174 |
> |
cut_pass<<cutName; |
1175 |
> |
cut_pass<<")"; |
1176 |
> |
|
1177 |
> |
|
1178 |
> |
if( ! pads_["pass"] || ! gROOT->FindObject("pass") ) { |
1179 |
> |
pads_["pass"] = new TCanvas("pass", currPadName.str().c_str()); |
1180 |
> |
} else { |
1181 |
> |
pads_["pass"]->cd(); |
1182 |
> |
} |
1183 |
> |
|
1184 |
> |
draw_err = ((TChain*) this->At(chainIndex))->Draw(bins_pass.str().c_str(),cut_pass.str().c_str() ,"" , currN); |
1185 |
> |
if( draw_err <= 0 ) return draw_err; |
1186 |
> |
|
1187 |
> |
|
1188 |
> |
TH1* pass = ((TH1*) pads_["pass"]->GetPrimitive("pass")); |
1189 |
> |
|
1190 |
> |
|
1191 |
> |
currPadName<<"Eff"; |
1192 |
> |
//Draw Efficiency Graph: |
1193 |
> |
if( ! pads_["EffGraph"] || ! gROOT->FindObject("EffGraph") ) { |
1194 |
> |
pads_["EffGraph"] = new TCanvas("EffGraph", currPadName.str().c_str()); |
1195 |
> |
} else { |
1196 |
> |
pads_["EffGraph"]->cd(); |
1197 |
> |
} |
1198 |
> |
|
1199 |
> |
TGraphAsymmErrors* EffGraph = new TGraphAsymmErrors(bkg, total); |
1200 |
> |
EffGraph->SetName(currHistName.str().c_str()); |
1201 |
> |
|
1202 |
> |
TF1* reverse = new TF2("reverse","1/y-1",total->GetXaxis()->GetXmin(),total->GetXaxis()->GetXmax()); |
1203 |
> |
EffGraph->Apply(reverse); |
1204 |
> |
EffGraph->Draw("A*"); |
1205 |
> |
|
1206 |
> |
TF1* fitfunc = new TF1("fitfunc",fitFormula.c_str(),fitXmin,fitXmax); |
1207 |
> |
EffGraph->Fit("fitfunc","R+"); |
1208 |
> |
|
1209 |
> |
|
1210 |
> |
//Save fit function |
1211 |
> |
|
1212 |
> |
ostringstream savefuncName; |
1213 |
> |
savefuncName<<histName; |
1214 |
> |
savefuncName<<"_"; |
1215 |
> |
|
1216 |
> |
if(cutName.find("<") != std::string::npos ) cutName.replace(cutName.find("<"),1,"_"); |
1217 |
> |
if(cutName.find(">") != std::string::npos ) cutName.replace(cutName.find(">"),1,"_"); |
1218 |
> |
savefuncName<<cutName; |
1219 |
> |
|
1220 |
> |
|
1221 |
> |
TFile file("ABCDFunctions.root","UPDATE"); |
1222 |
> |
TF1* savefunc = new TF1(savefuncName.str().c_str(), fitfunc->GetExpFormula().Data(),0,10000); |
1223 |
> |
savefunc->SetParameters( fitfunc->GetParameters() ); |
1224 |
> |
savefunc->SetParErrors ( fitfunc->GetParErrors() ); |
1225 |
> |
|
1226 |
> |
//Show results |
1227 |
> |
if( ! pads_["abcd"] || ! gROOT->FindObject("abcd") ) { |
1228 |
> |
pads_["abcd"] = new TCanvas("abcd", "abcd"); |
1229 |
> |
} else { |
1230 |
> |
pads_["abcd"]->cd(); |
1231 |
> |
} |
1232 |
> |
|
1233 |
> |
bkg->Multiply(savefunc); |
1234 |
> |
bkg->Draw(); |
1235 |
> |
|
1236 |
> |
// total->Add(bkg,-1); |
1237 |
> |
pass->SetLineColor(kRed); |
1238 |
> |
pass->Draw("sames,e"); |
1239 |
> |
pads_["abcd"]->SetLogy(); |
1240 |
> |
|
1241 |
> |
|
1242 |
> |
savefunc->Write(); |
1243 |
> |
// file.Close(); |
1244 |
> |
|
1245 |
> |
|
1246 |
> |
return draw_err; |
1247 |
|
|
1248 |
|
} |
1249 |
|
//------------------------------------------------------------------ |