CMS 3D CMS Logo

HistoManager.cc
Go to the documentation of this file.
1 #include "HistoManager.h"
2 #include "TProfile.h"
3 #include <iostream>
4 
6 {
7  pedHistDir = (TDirectory*)parent->Get("PEDESTAL");
8  ledHistDir = (TDirectory*)parent->Get("LED");
9  laserHistDir = (TDirectory*)parent->Get("LASER");
10  beamHistDir = (TDirectory*)parent->Get("BEAM");
11  otherHistDir = (TDirectory*)parent->Get("OTHER");
12 }
13 
15 {
16  switch (ht) {
17  case(ENERGY) : return "Energy"; break;
18  case(TIME) : return "Time"; break;
19  case(PULSE) : return "Pulse"; break;
20  case(ADC) : return "ADC"; break;
21  default : return ""; break;
22  }
23 }
24 
26 {
27  switch(et) {
28  case(PEDESTAL) : return "Pedestal"; break;
29  case(LED) : return "LED"; break;
30  case(LASER) : return "Laser"; break;
31  case(BEAM) : return "Beam"; break;
32  default : return "Other"; break;
33  }
34 }
35 
37  HistType ht,
38  EventType et)
39 {
40  std::string flavor=nameForFlavor(ht);
41  TDirectory* td;
42 
43  switch (et) {
44  case(PEDESTAL) : td=pedHistDir; break;
45  case(LED) : td=ledHistDir; break;
46  case(LASER) : td=laserHistDir; break;
47  case(BEAM) : td=beamHistDir; break;
48  case(UNKNOWN) : td=otherHistDir; break;
49  default : td=0; break;
50  }
51 
52  if (!td) {
53  printf("Event type not known, et=%d\n", et);
54  return 0;
55  }
56 
57  char name[120];
58 
59  std::string subdetStr;
60  switch (id.subdet) {
61  case (HcalBarrel) : subdetStr="HB"; break;
62  case (HcalEndcap) : subdetStr="HE"; break;
63  case (HcalOuter) : subdetStr="HO"; break;
64  case (HcalForward) : subdetStr="HF"; break;
65  default : subdetStr="Other"; break;
66  }
67 
68  TH1* retval=0;
69  sprintf(name,"%s_%s_%d_%d_%d",
70  flavor.c_str(),subdetStr.c_str(),id.ieta,id.iphi,id.depth);
71 
72  TList* keyList = td->GetListOfKeys();
73 
74  for(int keyindex = 0; keyindex<keyList->GetEntries(); ++keyindex) {
75  std::string keyname = keyList->At(keyindex)->GetName();
76  if (strstr(keyname.c_str(),name)) {
77  retval=(TH1*)td->Get(keyname.c_str());
78  break;
79  }
80  }
81 
82  return retval;
83 }
84 
85 
86 
87 
89  HistType ht,
90  EventType et)
91 {
92  std::string flavor=nameForFlavor(ht);
93  TDirectory* td;
94 
95  switch (et) {
96  case(PEDESTAL): td=pedHistDir; break;
97  case(LED): td=ledHistDir; break;
98  case(LASER): td=laserHistDir; break;
99  case(BEAM): td=beamHistDir; break;
100  case(UNKNOWN): td=otherHistDir; break;
101  default: td=0; break;
102  }
103 
104  if (td==0) {
105  printf("Unknown %d !\n", et);
106  return 0;
107  }
108 
109  char name[120];
110 
111 
112  char topbot;
113  if (eid.tb==0){topbot = 'b';}
114  else{topbot='t';}
115  TH1* retval=0;
116  sprintf(name,"%d_%d_HTR_%d:%d%c",
117  eid.fiber, eid.fiberChan, eid.crate, eid.Slot,topbot);
118  TList* keyList = td->GetListOfKeys();
119 
120  for(int keyindex = 0; keyindex<keyList->GetEntries(); ++keyindex) {
121  std::string keyname = keyList->At(keyindex)->GetName();
122  if ((strstr(keyname.c_str(),name))&&(strstr(keyname.c_str(),flavor.c_str()))) {
123  retval=(TH1*)td->Get(keyname.c_str());
124  break;
125  }
126  }
127 
128  return retval;
129 }
130 
131 
132 std::vector<MyHcalDetId> HistoManager::getDetIdsForType(HistType ht,
133  EventType et)
134 {
135  char keyflavor[100];
136  char keysubDet[100];
137  MyHcalDetId mydetid;
138  TDirectory* td;
139  TList* keyList;
140  std::vector<MyHcalDetId> retvals;
141 
142  std::string flavor=nameForFlavor(ht);
143 
144  switch (et) {
145  case(PEDESTAL) : td=pedHistDir; break;
146  case(LED) : td=ledHistDir; break;
147  case(LASER) : td=laserHistDir; break;
148  case(BEAM) : td=beamHistDir; break;
149  case(UNKNOWN) : td=otherHistDir; break;
150  default : td=0; break;
151  }
152 
153  if (!td) {
154  printf("Event type not known, et=%d\n", et);
155  return retvals;
156  }
157 
158  keyList = td->GetListOfKeys();
159 
160  for(int keyindex = 0; keyindex<keyList->GetEntries(); ++keyindex) {
161  int converted;
162  std::string keyname = keyList->At(keyindex)->GetName();
163  // cout << keyindex << " " << keyname << endl;
164  while (keyname.find("_")!=std::string::npos)
165  keyname.replace(keyname.find("_"),1," ");
166  converted = sscanf(keyname.c_str(),"%s %s %d %d %d",
167  keyflavor,keysubDet,
168  &mydetid.ieta,&mydetid.iphi,&mydetid.depth);
169  if( (flavor==keyflavor) && (converted==5) ) {
170  if (!strcmp(keysubDet,"HB")) mydetid.subdet=HcalBarrel;
171  else if (!strcmp(keysubDet,"HE")) mydetid.subdet=HcalEndcap;
172  else if (!strcmp(keysubDet,"HO")) mydetid.subdet=HcalOuter;
173  else if (!strcmp(keysubDet,"HF")) mydetid.subdet=HcalForward;
174  else continue; // and do not include this in the list!
175 
176  retvals.push_back(mydetid);
177  }
178  }
179 
180 
181  return retvals;
182 }
183 
184 
185 std::vector<MyElectronicsId> HistoManager::getElecIdsForType(HistType ht,
186  EventType et)
187 {
188  char keyflavor[100];
189  char keysubDet[100];
190  MyElectronicsId mydeteid;
191  TDirectory* td;
192  TList* keyList;
193  std::vector<MyElectronicsId> retvals;
194 
195  std::string flavor=nameForFlavor(ht);
196 
197  switch (et) {
198  case(PEDESTAL): td=pedHistDir; break;
199  case(LED): td=ledHistDir; break;
200  case(LASER): td=laserHistDir; break;
201  case(BEAM): td=beamHistDir; break;
202  case(UNKNOWN): td=otherHistDir; break;
203  default: td=0; break;
204  }
205  if (!td) {
206  printf("Event type not known, et=%d\n", et);
207  return retvals;
208  }
209 
210  keyList = td->GetListOfKeys();
211  if (keyList==0) return retvals;
212 
213  for(int keyindex = 0; keyindex<keyList->GetEntries(); ++keyindex) {
214  int converted;
215  std::string keyname = keyList->At(keyindex)->GetName();
216  while (keyname.find("_")!=std::string::npos)
217  keyname.replace(keyname.find("_"),1," ");
218  char bottop;
219 
220  //printf("%s\n",keyname.c_str());
221 
222  if(strstr(keyname.c_str(),"CALIB")){
223  converted = sscanf(keyname.c_str(),"%s %*s %s %*d %*d chan=%*s eid=%*d %*d %d %d HTR %d:%d%c ",
224  keyflavor,keysubDet, &mydeteid.fiber,&mydeteid.fiberChan,&mydeteid.crate,&mydeteid.Slot,&bottop);
225 
226  if (bottop=='t')
227  {mydeteid.tb=1;}
228  else
229  {mydeteid.tb=0;}
230 
231  // printf("%d converts to %d %d %d %d %c\n",converted,mydeteid.fiber,mydeteid.fiberChan,mydeteid.crate,mydeteid.Slot,bottop);
232 
233  }else{
234  converted = sscanf(keyname.c_str(),"%s %s %*d %*d %*d eid=%*d %*d %d %d HTR %d:%d%c ",
235  keyflavor,keysubDet, &mydeteid.fiber,&mydeteid.fiberChan,&mydeteid.crate,&mydeteid.Slot,&bottop);
236 
237 
238  if (bottop=='t')
239  {mydeteid.tb=1;}
240  else
241  {mydeteid.tb=0;}
242  }
243  //printf("converts to %d %d %d %d %d\n",mydeteid.fiber,mydeteid.fiberChan,mydeteid.crate,mydeteid.Slot,mydeteid.tb);
244 
245 
246  if( (flavor==keyflavor) && (converted==7) )
247 
248  retvals.push_back(mydeteid);
249 
250  }
251 
252 
253  return retvals;
254 }
255 
256 
MyHcalSubdetector subdet
Definition: MyHcalClasses.h:12
static std::string nameForEvent(EventType et)
Definition: HistoManager.cc:25
TDirectory * laserHistDir
Definition: HistoManager.h:33
TDirectory * ledHistDir
Definition: HistoManager.h:32
std::vector< MyHcalDetId > getDetIdsForType(HistType ht, EventType et)
std::vector< MyElectronicsId > getElecIdsForType(HistType ht, EventType et)
TDirectory * pedHistDir
Definition: HistoManager.h:31
TDirectory * otherHistDir
Definition: HistoManager.h:35
TH1 * GetAHistogram(const MyHcalDetId &id, HistType ht, EventType et)
Definition: HistoManager.cc:36
HistoManager(TDirectory *parent)
Definition: HistoManager.cc:5
et
define resolution functions of each parameter
static std::string nameForFlavor(HistType ht)
Definition: HistoManager.cc:14
TDirectory * beamHistDir
Definition: HistoManager.h:34