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