CMS 3D CMS Logo

CSCValHists.cc
Go to the documentation of this file.
2 #include <algorithm>
3 
4 using namespace std;
5 
6 CSCValHists::CSCValHists() { std::cout << "Initializing Histogram Manager..." << std::endl; }
7 
9 
11  std::vector<std::string> theFolders;
12  std::vector<std::string>::iterator fit;
13  theFile->cd();
14 
15  std::map<std::string, std::pair<TH1*, string> >::const_iterator mapit;
16  for (mapit = theMap.begin(); mapit != theMap.end(); mapit++) {
17  std::string folder = (*mapit).second.second;
18  fit = find(theFolders.begin(), theFolders.end(), folder);
19  if (fit == theFolders.end()) {
20  theFolders.push_back(folder);
21  theFile->mkdir(folder.c_str());
22  }
23  theFile->cd((*mapit).second.second.c_str());
24  (*mapit).second.first->Write();
25  theFile->cd();
26  }
27 }
28 
30  theFile->cd("recHits");
31  rHTree->Write();
32  theFile->cd();
33 
34  theFile->cd("Segments");
35  segTree->Write();
36  theFile->cd();
37 }
38 
40  // Create the root tree to hold position info
41  rHTree = new TTree("rHPositions", "Local and Global reconstructed positions for recHits");
42  segTree = new TTree("segPositions", "Local and Global reconstructed positions for segments");
43 
44  // Create a branch on the tree
45  rHTree->Branch("rHpos", &rHpos, "endcap/I:station/I:ring/I:chamber/I:layer/I:localx/F:localy/F:globalx/F:globaly/F");
46  segTree->Branch(
47  "segpos", &segpos, "endcap/I:station/I:ring/I:chamber/I:layer/I:localx/F:localy/F:globalx/F:globaly/F");
48 }
49 
50 void CSCValHists::fillRechitTree(float x, float y, float gx, float gy, int en, int st, int ri, int ch, int la) {
51  // Fill the rechit position branch
52  rHpos.localx = x;
53  rHpos.localy = y;
54  rHpos.globalx = gx;
55  rHpos.globaly = gy;
56  rHpos.endcap = en;
57  rHpos.ring = ri;
58  rHpos.station = st;
59  rHpos.chamber = ch;
60  rHpos.layer = la;
61  rHTree->Fill();
62 }
63 
64 void CSCValHists::fillSegmentTree(float x, float y, float gx, float gy, int en, int st, int ri, int ch) {
65  // Fill the segment position branch
66  segpos.localx = x;
67  segpos.localy = y;
68  segpos.globalx = gx;
69  segpos.globaly = gy;
70  segpos.endcap = en;
71  segpos.ring = ri;
72  segpos.station = st;
73  segpos.chamber = ch;
74  segpos.layer = 0;
75  segTree->Fill();
76 }
77 
79  theMap[name] = std::pair<TH1*, string>(thePlot, folder);
80 }
81 
83  float x, std::string name, std::string title, int bins, float xmin, float xmax, int bin, std::string folder) {
84  std::map<std::string, std::pair<TH1*, string> >::iterator it;
85  it = theMap.find(name);
86  if (it == theMap.end()) {
87  theMap[name] = std::pair<TH1*, string>(new TH1I(name.c_str(), title.c_str(), bins, xmin, xmax), folder);
88  }
89 
90  theMap[name].first->SetBinContent(bin, x);
91 }
92 
94  float x, std::string name, std::string title, int bins, float xmin, float xmax, std::string folder) {
95  std::map<std::string, std::pair<TH1*, string> >::iterator it;
96  it = theMap.find(name);
97  if (it == theMap.end()) {
98  theMap[name] = std::pair<TH1*, string>(new TH1I(name.c_str(), title.c_str(), bins, xmin, xmax), folder);
99  }
100 
101  theMap[name].first->Fill(x);
102 }
103 
105  float y,
108  int binsx,
109  float xmin,
110  float xmax,
111  int binsy,
112  float ymin,
113  float ymax,
115  std::map<std::string, std::pair<TH1*, string> >::iterator it;
116  it = theMap.find(name);
117  if (it == theMap.end()) {
118  theMap[name] =
119  std::pair<TH1*, string>(new TH2F(name.c_str(), title.c_str(), binsx, xmin, xmax, binsy, ymin, ymax), folder);
120  }
121 
122  theMap[name].first->Fill(x, y);
123 }
124 
126  float x, std::string name, std::string title, CSCDetId id, int bins, float xmin, float xmax, std::string folder) {
128  if (id.endcap() == 1)
129  endcap = "+";
130  if (id.endcap() == 2)
131  endcap = "-";
132 
133  std::map<std::string, std::pair<TH1*, string> >::iterator it;
134  ostringstream oss1;
135  ostringstream oss2;
136  oss1 << name << endcap << id.station() << id.ring();
137  oss2 << title << " (ME " << endcap << id.station() << "/" << id.ring() << ")";
138  name = oss1.str();
139  title = oss2.str();
140  it = theMap.find(name);
141  if (it == theMap.end()) {
142  theMap[name] = std::pair<TH1*, string>(new TH1F(name.c_str(), title.c_str(), bins, xmin, xmax), folder);
143  }
144 
145  theMap[name].first->Fill(x);
146 }
147 
149  float y,
152  CSCDetId id,
153  int binsx,
154  float xmin,
155  float xmax,
156  int binsy,
157  float ymin,
158  float ymax,
161  if (id.endcap() == 1)
162  endcap = "+";
163  if (id.endcap() == 2)
164  endcap = "-";
165 
166  std::map<std::string, std::pair<TH1*, string> >::iterator it;
167  ostringstream oss1;
168  ostringstream oss2;
169  oss1 << name << endcap << id.station() << id.ring();
170  oss2 << title << " (ME " << endcap << id.station() << "/" << id.ring() << ")";
171  name = oss1.str();
172  title = oss2.str();
173  it = theMap.find(name);
174  if (it == theMap.end()) {
175  theMap[name] =
176  std::pair<TH1*, string>(new TH2F(name.c_str(), title.c_str(), binsx, xmin, xmax, binsy, ymin, ymax), folder);
177  }
178 
179  theMap[name].first->Fill(x, y);
180 }
181 
183  float x, string name, string title, CSCDetId id, int bins, float xmin, float xmax, string folder) {
184  int crate = crate_lookup(id);
185 
186  map<string, pair<TH1*, string> >::iterator it;
187  ostringstream oss1;
188  ostringstream oss2;
189  oss1 << name << "_crate_" << crate;
190  oss2 << title << " (crate " << crate << ")";
191  name = oss1.str();
192  title = oss2.str();
193  it = theMap.find(name);
194  if (it == theMap.end()) {
195  theMap[name] = pair<TH1*, string>(new TH1F(name.c_str(), title.c_str(), bins, xmin, xmax), folder);
196  }
197 
198  theMap[name].first->Fill(x);
199 }
200 
202  float y,
203  string name,
204  string title,
205  CSCDetId id,
206  int binsx,
207  float xmin,
208  float xmax,
209  int binsy,
210  float ymin,
211  float ymax,
212  string folder) {
213  int crate = crate_lookup(id);
214 
215  map<string, pair<TH1*, string> >::iterator it;
216  ostringstream oss1;
217  ostringstream oss2;
218  oss1 << name << "_crate_" << crate;
219  oss2 << title << " (crate " << crate << ")";
220  name = oss1.str();
221  title = oss2.str();
222  it = theMap.find(name);
223  if (it == theMap.end()) {
224  theMap[name] =
225  pair<TH1*, string>(new TH2F(name.c_str(), title.c_str(), binsx, xmin, xmax, binsy, ymin, ymax), folder);
226  }
227 
228  theMap[name].first->Fill(x, y);
229 }
230 
232  float x, string name, string title, CSCDetId id, int bins, float xmin, float xmax, string folder) {
233  string endcap;
234  if (id.endcap() == 1)
235  endcap = "+";
236  if (id.endcap() == 2)
237  endcap = "-";
238 
239  map<string, pair<TH1*, string> >::iterator it;
240  ostringstream oss1;
241  ostringstream oss2;
242  oss1 << name << endcap << id.station();
243  oss2 << title << " (Station " << endcap << id.station() << ")";
244  name = oss1.str();
245  title = oss2.str();
246  it = theMap.find(name);
247  if (it == theMap.end()) {
248  theMap[name] = pair<TH1*, string>(new TH1F(name.c_str(), title.c_str(), bins, xmin, xmax), folder);
249  }
250 
251  theMap[name].first->Fill(x);
252 }
253 
255  float y,
256  string name,
257  string title,
258  CSCDetId id,
259  int binsx,
260  float xmin,
261  float xmax,
262  int binsy,
263  float ymin,
264  float ymax,
267  if (id.endcap() == 1)
268  endcap = "+";
269  if (id.endcap() == 2)
270  endcap = "-";
271 
272  std::map<std::string, std::pair<TH1*, string> >::iterator it;
273  ostringstream oss1;
274  ostringstream oss2;
275  oss1 << name << endcap << id.station();
276  oss2 << title << " (Station " << endcap << id.station() << ")";
277  name = oss1.str();
278  title = oss2.str();
279  it = theMap.find(name);
280  if (it == theMap.end()) {
281  theMap[name] =
282  std::pair<TH1*, string>(new TH2F(name.c_str(), title.c_str(), binsx, xmin, xmax, binsy, ymin, ymax), folder);
283  }
284 
285  theMap[name].first->Fill(x, y);
286 }
287 
289  float x, std::string name, std::string title, CSCDetId id, int bins, float xmin, float xmax, std::string folder) {
291  if (id.endcap() == 1)
292  endcap = "+";
293  if (id.endcap() == 2)
294  endcap = "-";
295 
296  std::map<std::string, std::pair<TH1*, string> >::iterator it;
297  ostringstream oss1;
298  ostringstream oss2;
299  oss1 << name << "_" << endcap << id.station() << "_" << id.ring() << "_" << id.chamber();
300  oss2 << title << " (ME " << endcap << id.station() << "/" << id.ring() << "/" << id.chamber() << ")";
301  name = oss1.str();
302  title = oss2.str();
303  it = theMap.find(name);
304  if (it == theMap.end()) {
305  theMap[name] = std::pair<TH1*, string>(new TH1F(name.c_str(), title.c_str(), bins, xmin, xmax), folder);
306  }
307 
308  theMap[name].first->Fill(x);
309 }
310 
312  float y,
315  CSCDetId id,
316  int binsx,
317  float xmin,
318  float xmax,
319  int binsy,
320  float ymin,
321  float ymax,
324  if (id.endcap() == 1)
325  endcap = "+";
326  if (id.endcap() == 2)
327  endcap = "-";
328 
329  std::map<std::string, std::pair<TH1*, string> >::iterator it;
330  ostringstream oss1;
331  ostringstream oss2;
332  oss1 << name << "_" << endcap << id.station() << "_" << id.ring() << "_" << id.chamber();
333  oss2 << title << " (ME " << endcap << id.station() << "/" << id.ring() << "/" << id.chamber() << ")";
334  name = oss1.str();
335  title = oss2.str();
336  it = theMap.find(name);
337  if (it == theMap.end()) {
338  theMap[name] =
339  std::pair<TH1*, string>(new TH2F(name.c_str(), title.c_str(), binsx, xmin, xmax, binsy, ymin, ymax), folder);
340  }
341 
342  theMap[name].first->Fill(x, y);
343 }
344 
345 void CSCValHists::fill2DHistByEvent(int run, int event, float z, string name, string title, CSCDetId id, string folder) {
346  string endcap;
347  if (id.endcap() == 1)
348  endcap = "+";
349  if (id.endcap() == 2)
350  endcap = "-";
351 
352  map<string, pair<TH1*, string> >::iterator it;
353  ostringstream oss1;
354  ostringstream oss2;
355  oss1 << name << "_" << run << "_" << event;
356  oss2 << title << " ( Run: " << run << " Event: " << event << " )";
357  name = oss1.str();
358  title = oss2.str();
359  it = theMap.find(name);
360  if (it == theMap.end()) {
361  theMap[name] = pair<TH1*, string>(new TH2F(name.c_str(), title.c_str(), 36, 0.5, 36.5, 18, 0.5, 18.5), folder);
362  }
363 
364  int x = id.chamber();
365  int y = id.ring();
366  if (y == 4)
367  y = 1; //collapsing ME1/1a into ME1/1
368  if (id.station() > 1)
369  y = y + 3 + (id.station() - 2) * 2;
370 
371  if (id.endcap() == 1)
372  y = y + 9;
373  else
374  y = -1 * y + 10;
375 
376  dynamic_cast<TH2F*>(theMap[name].first)->Fill(x, y, z);
377 }
378 
379 void CSCValHists::fill2DHist(float z, string name, string title, CSCDetId id, string folder) {
380  map<string, pair<TH1*, string> >::iterator it;
381  it = theMap.find(name);
382  if (it == theMap.end()) {
383  theMap[name] = pair<TH1*, string>(new TH2F(name.c_str(), title.c_str(), 36, 0.5, 36.5, 18, 0.5, 18.5), folder);
384  }
385 
386  int x = id.chamber();
387  int y = id.ring();
388  if (y == 4)
389  y = 1; //collapsing ME1/1a into ME1/1
390  if (id.station() > 1)
391  y = y + 3 + (id.station() - 2) * 2;
392 
393  if (id.endcap() == 1)
394  y = y + 9;
395  else
396  y = -1 * y + 10;
397 
398  dynamic_cast<TH2F*>(theMap[name].first)->Fill(x, y, z);
399 }
400 
402  float x, string name, string title, CSCDetId id, int bins, float xmin, float xmax, string folder) {
404  if (id.endcap() == 1)
405  endcap = "+";
406  if (id.endcap() == 2)
407  endcap = "-";
408 
409  std::map<std::string, std::pair<TH1*, string> >::iterator it;
410  ostringstream oss1;
411  ostringstream oss2;
412  oss1 << name << "_" << endcap << id.station() << "_" << id.ring() << "_" << id.chamber() << "_L" << id.layer();
413  oss2 << title << " (ME " << endcap << id.station() << "/" << id.ring() << "/" << id.chamber() << "/L" << id.layer()
414  << ")";
415  name = oss1.str();
416  title = oss2.str();
417  it = theMap.find(name);
418  if (it == theMap.end()) {
419  theMap[name] = std::pair<TH1*, string>(new TH1F(name.c_str(), title.c_str(), bins, xmin, xmax), folder);
420  }
421 
422  theMap[name].first->Fill(x);
423 }
424 
426  float y,
429  CSCDetId id,
430  int binsx,
431  float xmin,
432  float xmax,
433  int binsy,
434  float ymin,
435  float ymax,
438  if (id.endcap() == 1)
439  endcap = "+";
440  if (id.endcap() == 2)
441  endcap = "-";
442 
443  std::map<std::string, std::pair<TH1*, string> >::iterator it;
444  ostringstream oss1;
445  ostringstream oss2;
446  oss1 << name << "_" << endcap << id.station() << "_" << id.ring() << "_" << id.chamber() << "_L" << id.layer();
447  ;
448  oss2 << title << " (ME " << endcap << id.station() << "/" << id.ring() << "/" << id.chamber() << "/L" << id.layer()
449  << ")";
450  name = oss1.str();
451  title = oss2.str();
452  it = theMap.find(name);
453  if (it == theMap.end()) {
454  theMap[name] =
455  std::pair<TH1*, string>(new TH2F(name.c_str(), title.c_str(), binsx, xmin, xmax, binsy, ymin, ymax), folder);
456  }
457 
458  theMap[name].first->Fill(x, y);
459 }
460 
462  float y,
465  int binsx,
466  float xmin,
467  float xmax,
468  float ymin,
469  float ymax,
471  std::map<std::string, std::pair<TH1*, string> >::iterator it;
472  it = theMap.find(name);
473  if (it == theMap.end()) {
474  theMap[name] =
475  std::pair<TProfile*, string>(new TProfile(name.c_str(), title.c_str(), binsx, xmin, xmax, ymin, ymax), folder);
476  }
477 
478  theMap[name].first->Fill(x, y);
479 }
480 
482  float y,
485  CSCDetId id,
486  int binsx,
487  float xmin,
488  float xmax,
489  float ymin,
490  float ymax,
492  std::map<std::string, std::pair<TH1*, string> >::iterator it;
494  if (id.endcap() == 1)
495  endcap = "+";
496  if (id.endcap() == 2)
497  endcap = "-";
498 
499  ostringstream oss1;
500  ostringstream oss2;
501  oss1 << name << endcap << id.station() << id.ring();
502  oss2 << title << " (ME " << endcap << id.station() << "/" << id.ring() << ")";
503  name = oss1.str();
504  title = oss2.str();
505 
506  it = theMap.find(name);
507  if (it == theMap.end()) {
508  theMap[name] =
509  std::pair<TProfile*, string>(new TProfile(name.c_str(), title.c_str(), binsx, xmin, xmax, ymin, ymax), folder);
510  }
511 
512  theMap[name].first->Fill(x, y);
513 }
514 
516  float y,
519  CSCDetId id,
520  int binsx,
521  float xmin,
522  float xmax,
523  float ymin,
524  float ymax,
526  std::map<std::string, std::pair<TH1*, string> >::iterator it;
528  if (id.endcap() == 1)
529  endcap = "+";
530  if (id.endcap() == 2)
531  endcap = "-";
532 
533  ostringstream oss1;
534  ostringstream oss2;
535  oss1 << name << "_" << endcap << id.station() << "_" << id.ring() << "_" << id.chamber();
536  oss2 << title << " (ME " << endcap << id.station() << "/" << id.ring() << "/" << id.chamber() << ")";
537  name = oss1.str();
538  title = oss2.str();
539 
540  it = theMap.find(name);
541  if (it == theMap.end()) {
542  theMap[name] =
543  std::pair<TProfile*, string>(new TProfile(name.c_str(), title.c_str(), binsx, xmin, xmax, ymin, ymax), folder);
544  }
545 
546  theMap[name].first->Fill(x, y);
547 }
548 
550  float y,
551  float z,
554  int binsx,
555  float xmin,
556  float xmax,
557  int binsy,
558  float ymin,
559  float ymax,
560  float zmin,
561  float zmax,
563  std::map<std::string, std::pair<TH1*, string> >::iterator it;
564 
565  it = theMap.find(name);
566  if (it == theMap.end()) {
567  theMap[name] = std::pair<TProfile2D*, string>(
568  new TProfile2D(name.c_str(), title.c_str(), binsx, xmin, xmax, binsy, ymin, ymax, zmin, zmax), folder);
569  }
570 
571  TProfile2D* tempp = (TProfile2D*)theMap[name].first;
572  tempp->Fill(x, y, z);
573 }
574 
576  int crate = 0;
577 
578  if (id.station() == 1) {
579  if (id.chamber() == 36 || id.chamber() == 1 || id.chamber() == 2)
580  crate = 1;
581  if (id.chamber() == 3 || id.chamber() == 4 || id.chamber() == 5)
582  crate = 2;
583  if (id.chamber() == 6 || id.chamber() == 7 || id.chamber() == 8)
584  crate = 3;
585  if (id.chamber() == 9 || id.chamber() == 10 || id.chamber() == 11)
586  crate = 4;
587  if (id.chamber() == 12 || id.chamber() == 13 || id.chamber() == 14)
588  crate = 5;
589  if (id.chamber() == 15 || id.chamber() == 16 || id.chamber() == 17)
590  crate = 6;
591  if (id.chamber() == 18 || id.chamber() == 19 || id.chamber() == 20)
592  crate = 7;
593  if (id.chamber() == 21 || id.chamber() == 22 || id.chamber() == 23)
594  crate = 8;
595  if (id.chamber() == 24 || id.chamber() == 25 || id.chamber() == 26)
596  crate = 9;
597  if (id.chamber() == 27 || id.chamber() == 28 || id.chamber() == 29)
598  crate = 10;
599  if (id.chamber() == 30 || id.chamber() == 31 || id.chamber() == 32)
600  crate = 11;
601  if (id.chamber() == 33 || id.chamber() == 34 || id.chamber() == 35)
602  crate = 12;
603  } else {
604  crate = 12 + id.triggerSector() + (id.station() - 2) * 6;
605  }
606 
607  if (id.endcap() == 2)
608  crate = crate + 30;
609 
610  return crate;
611 }
int crate_lookup(CSCDetId id)
Definition: CSCValHists.cc:575
void fill2DHistByStation(float x, float y, std::string name, std::string title, CSCDetId id, int binsx, float xmin, float xmax, int binsy, float ymin, float ymax, std::string folder)
Definition: CSCValHists.cc:254
void fillProfileByType(float x, float y, std::string name, std::string title, CSCDetId id, int binsx, float xmin, float xmax, float ymin, float ymax, std::string folder)
Definition: CSCValHists.cc:481
void setupTrees()
Definition: CSCValHists.cc:39
void fillProfile(float x, float y, std::string name, std::string title, int binsx, float xmin, float xmax, float ymin, float ymax, std::string folder)
Definition: CSCValHists.cc:461
void writeTrees(TFile *theFile)
Definition: CSCValHists.cc:29
void find(edm::Handle< EcalRecHitCollection > &hits, DetId thisDet, std::vector< EcalRecHitCollection::const_iterator > &hit, bool debug=false)
Definition: FindCaloHit.cc:19
void fill1DHist(float x, std::string name, std::string title, int bins, float xmin, float xmax, std::string folder)
Definition: CSCValHists.cc:93
void fill2DHistByCrate(float x, float y, std::string name, std::string title, CSCDetId id, int binsx, float xmin, float xmax, int binsy, float ymin, float ymax, std::string folder)
Definition: CSCValHists.cc:201
void fill1DHistByLayer(float x, std::string name, std::string title, CSCDetId id, int bins, float xmin, float xmax, std::string folder)
Definition: CSCValHists.cc:401
void fillProfileByChamber(float x, float y, std::string name, std::string title, CSCDetId id, int binsx, float xmin, float xmax, float ymin, float ymax, std::string folder)
Definition: CSCValHists.cc:515
void writeHists(TFile *theFile)
Definition: CSCValHists.cc:10
void insertPlot(TH1 *thePlot, std::string name, std::string folder)
Definition: CSCValHists.cc:78
void Fill(HcalDetId &id, double val, std::vector< TH2F > &depth)
void fill1DHistByType(float x, std::string name, std::string title, CSCDetId id, int bins, float xmin, float xmax, std::string folder)
Definition: CSCValHists.cc:125
void fillRechitTree(float x, float y, float gx, float gy, int en, int st, int ri, int ch, int la)
Definition: CSCValHists.cc:50
void fill1DHistByCrate(float x, std::string name, std::string title, CSCDetId id, int bins, float xmin, float xmax, std::string folder)
Definition: CSCValHists.cc:182
void fill2DHistByLayer(float x, float y, std::string name, std::string title, CSCDetId id, int binsx, float xmin, float xmax, int binsy, float ymin, float ymax, std::string folder)
Definition: CSCValHists.cc:425
void fill1DHistByStation(float x, std::string name, std::string title, CSCDetId id, int bins, float xmin, float xmax, std::string folder)
Definition: CSCValHists.cc:231
void fill1DHistByChamber(float x, std::string name, std::string title, CSCDetId id, int bins, float xmin, float xmax, std::string folder)
Definition: CSCValHists.cc:288
void fill2DHistByChamber(float x, float y, std::string name, std::string title, CSCDetId id, int binsx, float xmin, float xmax, int binsy, float ymin, float ymax, std::string folder)
Definition: CSCValHists.cc:311
void fill2DHistByEvent(int run, int event, float x, std::string name, std::string title, CSCDetId id, std::string folder)
Definition: CSCValHists.cc:345
void fill2DHist(float x, float y, std::string name, std::string title, int binsx, float xmin, float xmax, int binsy, float ymin, float ymax, std::string folder)
Definition: CSCValHists.cc:104
void fill2DHistByType(float x, float y, std::string name, std::string title, CSCDetId id, int binsx, float xmin, float xmax, int binsy, float ymin, float ymax, std::string folder)
Definition: CSCValHists.cc:148
float x
void fillSegmentTree(float x, float y, float gx, float gy, int en, int st, int ri, int ch)
Definition: CSCValHists.cc:64
void fill2DProfile(float x, float y, float z, std::string name, std::string title, int binsx, float xmin, float xmax, int binsy, float ymin, float ymax, float zmin, float zmax, std::string folder)
Definition: CSCValHists.cc:549
void fillCalibHist(float x, std::string name, std::string title, int bins, float xmin, float xmax, int bin, std::string folder)
Definition: CSCValHists.cc:82
Definition: event.py:1