CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
EcalPedHists.cc
Go to the documentation of this file.
1 
12 
14  runNum_(-1),
15  fileName_ (ps.getUntrackedParameter<std::string>("fileName", std::string("ecalPedDigiDump"))),
16  barrelDigiCollection_ (ps.getParameter<edm::InputTag> ("EBdigiCollection")),
17  endcapDigiCollection_ (ps.getParameter<edm::InputTag> ("EEdigiCollection")),
18  headerProducer_ (ps.getParameter<edm::InputTag> ("headerProducer"))
19 {
20  using namespace std;
21 
22  fedMap_ = new EcalFedMap();
23  histsFilled_ = false;
24  //for(int i=601; i<655; ++i)
25  //{
26  // listDefaults.push_back(i);
27  //}
28  listFEDs_ = ps.getUntrackedParameter<vector<int> >("listFEDs");
29  listEBs_ = ps.getUntrackedParameter<vector<string> >("listEBs");
30 
31  if(listFEDs_.size()==0)
32  {
33  allFEDsSelected_ = false;
34  //if "actual" EB id given, then convert to FEDid and put in listFEDs_
35  if(listEBs_.size() > 0)
36  {
37  listFEDs_.clear();
38  for(vector<string>::const_iterator itr = listEBs_.begin(); itr != listEBs_.end(); ++itr)
39  {
40  listFEDs_.push_back(fedMap_->getFedFromSlice(*itr));
41  }
42  }
43  }
44  else if(listFEDs_[0]==-1)
45  {
46  // Apply no selection if -1 is passed in FED list
47  allFEDsSelected_ = true;
48  //debug
49  //cout << "no selection on FEDs!" << endl;
50  //inputIsOk_=false;
51  //return;
52  //listFEDs_ = listDefaults;
53  }
54  else
55  {
56  //in this case, listFEDs should be populated
57  allFEDsSelected_ = false;
58  }
59 
60  if(!allFEDsSelected_)
61  {
62  // Verify FED numbers are valid
63  for (vector<int>::const_iterator intIter = listFEDs_.begin(); intIter != listFEDs_.end(); intIter++)
64  {
65  if ( ((*intIter) < 601)||(654 < (*intIter)) )
66  {
67  cout << "[EcalPedHists] FED value: " << (*intIter) << " found in listFEDs. "
68  << " Valid range is 601-654. Returning." << endl;
69  inputIsOk_ = false;
70  return;
71  }
72  else
73  theRealFedSet_.insert(*intIter);
74  }
75  }
76 
77  vector<int> listDefaults = vector<int>();
78  listDefaults.clear();
79  for(int i=1; i<1701; ++i)
80  {
81  listDefaults.push_back(i);
82  }
83  listChannels_ = ps.getUntrackedParameter<vector<int> >("listChannels", listDefaults);
84  listDefaults.clear();
85  // Get samples to plot (default to 1,2,3)
86  listDefaults.push_back(0);
87  listDefaults.push_back(1);
88  listDefaults.push_back(2);
89  listSamples_ = ps.getUntrackedParameter<vector<int> >("listSamples", listDefaults);
90 
91  inputIsOk_ = true;
92  vector<int>::iterator intIter;
93 
94  // Verify crystal numbers are valid
95  for (intIter = listChannels_.begin(); intIter != listChannels_.end(); ++intIter)
96  {
97  //TODO: Fix crystal index checking?
98  //if ( ((*intIter) < 1)||(1700 < (*intIter)) )
99  //{
100  // cout << "[EcalPedHists] ic value: " << (*intIter) << " found in listChannels. "
101  // << " Valid range is 1-1700. Returning." << endl;
102  // inputIsOk_ = false;
103  // return;
104  //}
105  }
106  // Verify sample numbers are valid
107  for (intIter = listSamples_.begin(); intIter != listSamples_.end(); intIter++)
108  {
109  if ( ((*intIter) < 1)||(10 < (*intIter)) )
110  {
111  cout << "[EcalPedHists] sample number: " << (*intIter) << " found in listSamples. "
112  << " Valid range is 1-10. Returning." << endl;
113  inputIsOk_ = false;
114  return;
115  }
116  }
117 
118 }
119 
121 {
122 }
123 
125 {
127  c.get<EcalMappingRcd>().get(elecHandle);
128  ecalElectronicsMap_ = elecHandle.product();
129 }
130 
132 {
133  using namespace std;
134  if(inputIsOk_)
135  {
136  //debug
137  //cout << "endJob:creating root file!" << endl;
138 
139  fileName_ += "-"+intToString(runNum_)+".graph.root";
140 
141  TFile root_file_(fileName_.c_str() , "RECREATE");
142  //Loop over FEDs first
143  for(set<int>::const_iterator FEDitr = theRealFedSet_.begin(); FEDitr != theRealFedSet_.end(); ++FEDitr)
144  {
145  if(!histsFilled_)
146  break;
147  string dir = fedMap_->getSliceFromFed(*FEDitr);
148  TDirectory* FEDdir = gDirectory->mkdir(dir.c_str());
149  FEDdir->cd();
150  //root_file_.mkdir(dir.c_str());
151  //root_file_.cd(dir.c_str());
152  map<string,TH1F*> mapHistos = FEDsAndHistMaps_[*FEDitr];
153 
154  //Loop over channels; write histos and directory structure
155  for (vector<int>::const_iterator itr = listChannels_.begin(); itr!=listChannels_.end(); itr++)
156  {
157  //debug
158  //cout << "loop over channels" << endl;
159 
160  TH1F* hist = 0;
161  string chnl = intToString(*itr);
162  string name1 = "Cry";
163  name1.append(chnl+"Gain1");
164  string name2 = "Cry";
165  name2.append(chnl+"Gain6");
166  string name3 = "Cry";
167  name3.append(chnl+"Gain12");
168  hist = mapHistos[name1];
169  // This is a sanity check only
170  if(hist!=0)
171  {
172  string cryDirName = "Cry_"+chnl;
173  TDirectory* cryDir = FEDdir->mkdir(cryDirName.c_str());
174  cryDir->cd();
175  hist->SetDirectory(cryDir);
176  hist->Write();
177  hist = mapHistos[name2];
178  hist->SetDirectory(cryDir);
179  hist->Write();
180  hist = mapHistos[name3];
181  hist->SetDirectory(cryDir);
182  hist->Write();
183  //root_file_.cd(dir.c_str());
184  root_file_.cd();
185  }
186  else
187  {
188  cerr << "EcalPedHists: Error: This shouldn't happen!" << endl;
189  }
190  }
191  root_file_.cd();
192  }
193  root_file_.Close();
194  }
195 }
196 
198 {
199  using namespace std;
200  using namespace edm;
201 
202  if (!inputIsOk_)
203  return;
204 
205  // loop over the headers, this is to detect missing FEDs if all are selected
206  if(allFEDsSelected_)
207  {
209  try {
210  e.getByLabel (headerProducer_, DCCHeaders);
211  } catch ( std::exception& ex ) {
212  edm::LogError ("EcalPedHists") << "Error! can't get the product "
213  << headerProducer_;
214  return;
215  }
216 
217  for (EcalRawDataCollection::const_iterator headerItr= DCCHeaders->begin();
218  headerItr != DCCHeaders->end ();
219  ++headerItr)
220  {
221  int FEDid = 600+headerItr->id();
222  theRealFedSet_.insert(FEDid);
223  }
224  }
225 
226  // loop over fed list and make sure that there are histo maps
227  for(set<int>::const_iterator fedItr = theRealFedSet_.begin(); fedItr != theRealFedSet_.end(); ++fedItr)
228  {
229  if(FEDsAndHistMaps_.find(*fedItr)==FEDsAndHistMaps_.end())
230  initHists(*fedItr);
231  }
232 
233  //debug
234  //cout << "analyze...input is ok? " << inputIsOk_ << endl;
235 
236  bool barrelDigisFound = true;
237  bool endcapDigisFound = true;
238  // get the barrel digis
239  // (one digi for each crystal)
240  // TODO; SIC: fix this behavior
241  Handle<EBDigiCollection> barrelDigis;
242  try {
243  e.getByLabel (barrelDigiCollection_, barrelDigis);
244  } catch ( std::exception& ex )
245  {
246  edm::LogError ("EcalPedOffset") << "Error! can't get the product "
248  barrelDigisFound = false;
249  }
250  // get the endcap digis
251  // (one digi for each crystal)
252  // TODO; SIC: fix this behavior
253  Handle<EEDigiCollection> endcapDigis;
254  try {
255  e.getByLabel (endcapDigiCollection_, endcapDigis);
256  } catch ( std::exception& ex )
257  {
258  edm::LogError ("EcalPedOffset") << "Error! can't get the product "
260  endcapDigisFound = false;
261  }
262 
263  if(barrelDigisFound)
264  readEBdigis(barrelDigis);
265  if(endcapDigisFound)
266  readEEdigis(endcapDigis);
267  if(!barrelDigisFound && !endcapDigisFound)
268  edm::LogError ("EcalPedOffset") << "No digis found in the event!";
269 
270  if(runNum_==-1)
271  runNum_ = e.id().run();
272 }
273 
274 // insert the 3-entry hist map into the map keyed by FED number
276 {
277  using namespace std;
278  //using namespace edm;
279 
280  std::map<string,TH1F*> histMap;
281  //debug
282  //cout << "Initializing map for FED:" << *FEDitr << endl;
283  for (vector<int>::const_iterator intIter = listChannels_.begin(); intIter != listChannels_.end(); ++intIter)
284  {
285  //Put 3 histos (1 per gain) for the channel into the map
286  string FEDid = intToString(FED);
287  string chnl = intToString(*intIter);
288  string title1 = "Gain1 ADC Counts for channel ";
289  title1.append(chnl);
290  string name1 = "Cry";
291  name1.append(chnl+"Gain1");
292  string title2 = "Gain6 ADC Counts for channel ";
293  title2.append(chnl);
294  string name2 = "Cry";
295  name2.append(chnl+"Gain6");
296  string title3 = "Gain12 ADC Counts for channel ";
297  title3.append(chnl);
298  string name3 = "Cry";
299  name3.append(chnl+"Gain12");
300  histMap.insert(make_pair(name1,new TH1F(name1.c_str(),title1.c_str(),75,175.0,250.0)));
301  histMap[name1]->SetDirectory(0);
302  histMap.insert(make_pair(name2,new TH1F(name2.c_str(),title2.c_str(),75,175.0,250.0)));
303  histMap[name2]->SetDirectory(0);
304  histMap.insert(make_pair(name3,new TH1F(name3.c_str(),title3.c_str(),75,175.0,250.0)));
305  histMap[name3]->SetDirectory(0);
306  }
307  FEDsAndHistMaps_.insert(make_pair(FED,histMap));
308 }
309 
310 
312 {
313  using namespace std;
314  using namespace edm;
315  //debug
316  //cout << "readEBdigis" << endl;
317 
318  // Loop over digis
319  for (EBDigiCollection::const_iterator digiItr= digis->begin();digiItr != digis->end(); ++digiItr )
320  {
321  EBDetId detId = EBDetId(digiItr->id());
323  int FEDid = 600+elecId.dccId();
324  int crystalId = detId.ic();
325 
326  //debug
327  //cout << "FEDid:" << FEDid << " cryId:" << crystalId << endl;
328  //cout << "FEDid:" << FEDid << endl;
329  //Select desired supermodules only
330  set<int>::const_iterator fedIter = find(theRealFedSet_.begin(), theRealFedSet_.end(), FEDid);
331  if (fedIter == theRealFedSet_.end())
332  continue;
333 
334  // Select desired channels only
335  vector<int>::iterator icIter;
336  icIter = find(listChannels_.begin(), listChannels_.end(), crystalId);
337  if (icIter == listChannels_.end())
338  continue;
339 
340  // Get the adc counts from the selected samples and fill the corresponding histogram
341  // Must subtract 1 from user-given sample list (e.g., user's sample 1 -> sample 0)
342  for (vector<int>::iterator itr = listSamples_.begin(); itr!=listSamples_.end(); itr++)
343  {
344  histsFilled_ = true;
345  map<string,TH1F*> mapHistos = FEDsAndHistMaps_[FEDid];
346  string chnl = intToString(crystalId);
347  string name1 = "Cry";
348  name1.append(chnl+"Gain1");
349  string name2 = "Cry";
350  name2.append(chnl+"Gain6");
351  string name3 = "Cry";
352  name3.append(chnl+"Gain12");
353  TH1F* hist = 0;
354  if(((EBDataFrame)(*digiItr)).sample(*itr-1).gainId()==3)
355  hist = mapHistos[name1];
356  if(((EBDataFrame)(*digiItr)).sample(*itr-1).gainId()==2)
357  hist = mapHistos[name2];
358  if(((EBDataFrame)(*digiItr)).sample(*itr-1).gainId()==1)
359  hist = mapHistos[name3];
360  if(hist!=0)
361  hist->Fill(((EBDataFrame)(*digiItr)).sample(*itr-1).adc());
362  else
363  cerr << "EcalPedHistDumper: Error: This shouldn't happen!" << endl;
364  }
365  }
366 }
367 
368 
370 {
371  using namespace std;
372  using namespace edm;
373  //debug
374  //cout << "readEEdigis" << endl;
375 
376  // Loop over digis
377  for (EEDigiCollection::const_iterator digiItr= digis->begin();digiItr != digis->end(); ++digiItr )
378  {
379  EEDetId detId = EEDetId(digiItr->id());
381  int FEDid = 600+elecId.dccId();
382  int crystalId = 10000*FEDid+100*elecId.towerId()+5*(elecId.stripId()-1)+elecId.xtalId();
383 
384  //Select desired FEDs only
385  set<int>::const_iterator fedIter = find(theRealFedSet_.begin(), theRealFedSet_.end(), FEDid);
386  if (fedIter == theRealFedSet_.end())
387  continue;
388 
389  // Select desired channels only
390  vector<int>::iterator icIter;
391  icIter = find(listChannels_.begin(), listChannels_.end(), crystalId);
392  if (icIter == listChannels_.end())
393  continue;
394 
395  // Get the adc counts from the selected samples and fill the corresponding histogram
396  // Must subtract 1 from user-given sample list (e.g., user's sample 1 -> sample 0)
397  for (vector<int>::iterator itr = listSamples_.begin(); itr!=listSamples_.end(); itr++)
398  {
399  histsFilled_ = true;
400  map<string,TH1F*> mapHistos = FEDsAndHistMaps_[FEDid];
401  string chnl = intToString(crystalId);
402  string name1 = "Cry";
403  name1.append(chnl+"Gain1");
404  string name2 = "Cry";
405  name2.append(chnl+"Gain6");
406  string name3 = "Cry";
407  name3.append(chnl+"Gain12");
408  TH1F* hist = 0;
409  if(((EBDataFrame)(*digiItr)).sample(*itr-1).gainId()==3)
410  hist = mapHistos[name1];
411  if(((EBDataFrame)(*digiItr)).sample(*itr-1).gainId()==2)
412  hist = mapHistos[name2];
413  if(((EBDataFrame)(*digiItr)).sample(*itr-1).gainId()==1)
414  hist = mapHistos[name3];
415  if(hist!=0)
416  hist->Fill(((EBDataFrame)(*digiItr)).sample(*itr-1).adc());
417  else
418  cerr << "EcalPedHistDumper: Error: This shouldn't happen!" << endl;
419  }
420  }
421 }
422 
423 
425 {
426  using namespace std;
427  //
428  // outputs the number into the string stream and then flushes
429  // the buffer (makes sure the output is put into the stream)
430  //
431  ostringstream myStream; //creates an ostringstream object
432  myStream << num << flush;
433  return(myStream.str()); //returns the string form of the stringstream object
434 }
435 
436 
int adc(sample_type sample)
get the ADC sample (12 bits)
RunNumber_t run() const
Definition: EventID.h:39
std::vector< int > listFEDs_
Definition: EcalPedHists.h:61
T getUntrackedParameter(std::string const &, T const &) const
int i
Definition: DBlmapReader.cc:9
std::set< int > theRealFedSet_
Definition: EcalPedHists.h:64
boost::transform_iterator< IterHelp, boost::counting_iterator< int > > const_iterator
void initHists(int FED)
int gainId(sample_type sample)
get the gainId (2 bits)
Ecal readout channel identification [32:20] Unused (so far) [19:13] DCC id [12:6] tower [5:3] strip [...
std::string intToString(int num)
int getFedFromSlice(std::string)
Definition: EcalFedMap.cc:104
std::vector< EcalDCCHeaderBlock >::const_iterator const_iterator
void find(edm::Handle< EcalRecHitCollection > &hits, DetId thisDet, std::vector< EcalRecHitCollection::const_iterator > &hit, bool debug=false)
Definition: FindCaloHit.cc:7
std::map< int, stringHistMap > FEDsAndHistMaps_
Definition: EcalPedHists.h:63
std::string getSliceFromFed(int)
Definition: EcalFedMap.cc:93
EcalElectronicsId getElectronicsId(const DetId &id) const
Get the electronics id for this det id.
std::vector< std::string > listEBs_
Definition: EcalPedHists.h:62
edm::InputTag endcapDigiCollection_
Definition: EcalPedHists.h:57
void endJob(void)
int dccId() const
get the DCC (Ecal Local DCC value not global one) id
bool getByLabel(InputTag const &tag, Handle< PROD > &result) const
Definition: Event.h:418
edm::InputTag headerProducer_
Definition: EcalPedHists.h:58
int ic() const
get ECAL/crystal number inside SM
Definition: EBDetId.cc:46
void readEBdigis(edm::Handle< EBDigiCollection > digis)
bool histsFilled_
Definition: EcalPedHists.h:54
const EcalElectronicsMapping * ecalElectronicsMap_
Definition: EcalPedHists.h:67
EcalFedMap * fedMap_
Definition: EcalPedHists.h:65
const T & get() const
Definition: EventSetup.h:56
std::vector< int > listChannels_
Definition: EcalPedHists.h:59
T const * product() const
Definition: ESHandle.h:86
EcalPedHists(const edm::ParameterSet &ps)
Definition: EcalPedHists.cc:13
bool allFEDsSelected_
Definition: EcalPedHists.h:53
edm::EventID id() const
Definition: EventBase.h:59
void analyze(const edm::Event &e, const edm::EventSetup &c)
std::string fileName_
Definition: EcalPedHists.h:55
void beginRun(edm::Run const &, edm::EventSetup const &c)
tuple cout
Definition: gather_cfg.py:145
dbl *** dir
Definition: mlp_gen.cc:35
void readEEdigis(edm::Handle< EEDigiCollection > digis)
edm::InputTag barrelDigiCollection_
Definition: EcalPedHists.h:56
Definition: Run.h:43
TFile * root_file_
Definition: EcalPedHists.h:66
std::vector< int > listSamples_
Definition: EcalPedHists.h:60