CMS 3D CMS Logo

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