CMS 3D CMS Logo

EcalDigiDisplay.cc
Go to the documentation of this file.
1 
12 
17 
20 
21 #include <iostream>
22 #include <vector>
23 
24 //==========================================================================
26  : ebDigiCollection_(ps.getParameter<std::string>("ebDigiCollection")),
27  eeDigiCollection_(ps.getParameter<std::string>("eeDigiCollection")),
28  digiProducer_(ps.getParameter<std::string>("digiProducer")),
29  rawDataToken_(consumes<EcalRawDataCollection>(edm::InputTag(digiProducer_))),
30  ebDigiToken_(consumes<EBDigiCollection>(edm::InputTag(digiProducer_, ebDigiCollection_))),
31  eeDigiToken_(consumes<EEDigiCollection>(edm::InputTag(digiProducer_, eeDigiCollection_))),
32  pnDiodeDigiToken_(consumes<EcalPnDiodeDigiCollection>(edm::InputTag(digiProducer_))),
33  ecalMappingToken_(esConsumes<edm::Transition::BeginRun>()) {
34  //=========================================================================
35  requestedFeds_ = ps.getUntrackedParameter<std::vector<int> >("requestedFeds");
36  requestedEbs_ = ps.getUntrackedParameter<std::vector<std::string> >("requestedEbs");
37 
38  cryDigi = ps.getUntrackedParameter<bool>("cryDigi");
39  ttDigi = ps.getUntrackedParameter<bool>("ttDigi");
40  pnDigi = ps.getUntrackedParameter<bool>("pnDigi");
41 
42  mode = ps.getUntrackedParameter<int>("mode");
43  listChannels = ps.getUntrackedParameter<std::vector<int> >("listChannels");
44  listTowers = ps.getUntrackedParameter<std::vector<int> >("listTowers");
45  listPns = ps.getUntrackedParameter<std::vector<int> >("listPns");
46 
47  std::vector<int> listDefaults;
48  listDefaults.push_back(-1);
49  requestedFeds_ = ps.getUntrackedParameter<std::vector<int> >("requestedFeds", listDefaults);
50  bool fedIsGiven = false;
51 
52  std::vector<std::string> ebDefaults;
53  ebDefaults.push_back("none");
54  requestedEbs_ = ps.getUntrackedParameter<std::vector<std::string> >("requestedEbs", ebDefaults);
55  // FEDs and EBs
56  if (requestedFeds_[0] != -1) {
57  edm::LogInfo("EcalDigiDisplay") << "FED id is given! Goining to beginRun! ";
58  fedIsGiven = true;
59  } else {
60  if (requestedEbs_[0] != "none") {
61  //EB id is given and convert to FED id
62  requestedFeds_.clear();
63  fedMap = new EcalFedMap();
64  for (std::vector<std::string>::const_iterator ebItr = requestedEbs_.begin(); ebItr != requestedEbs_.end();
65  ++ebItr) {
66  requestedFeds_.push_back(fedMap->getFedFromSlice(*ebItr));
67  }
68  delete fedMap;
69  } else {
70  //Select all FEDs in the Event
71  for (int i = 601; i < 655; ++i) {
72  requestedFeds_.push_back(i);
73  }
74  }
75  }
76 
77  //Channel list
78  listChannels = ps.getUntrackedParameter<std::vector<int> >("listChannels", listDefaults);
79  //Tower list
80  listTowers = ps.getUntrackedParameter<std::vector<int> >("listTowers", listDefaults);
81 
82  //Consistancy checks:
83  std::vector<int>::iterator fedIter;
84  std::vector<int>::iterator intIter;
85  inputIsOk = true;
86 
87  if (fedIsGiven) {
88  for (fedIter = requestedFeds_.begin(); fedIter != requestedFeds_.end(); ++fedIter) {
89  if ((*fedIter) < 601 || (*fedIter) > 655) {
90  edm::LogError("EcalDigiDisplay") << " FED value: " << (*fedIter) << " found in requetsedFeds. "
91  << " Valid range is 601-654. Returning.";
92  inputIsOk = false;
93  return;
94  } //Loop over requetsed FEDS
95  }
96  }
97  bool barrelSM = false;
98  //Loop over and Check if Barrel SM is picked up
99  for (fedIter = requestedFeds_.begin(); fedIter != requestedFeds_.end(); ++fedIter) {
100  if ((*fedIter) > 609 && (*fedIter) < 646 && inputIsOk) // if EB SM is being picked up
101  barrelSM = true;
102  }
103 
104  if (barrelSM) {
105  if (cryDigi) {
106  // Check with channels in Barrel
107  for (intIter = listChannels.begin(); intIter != listChannels.end(); intIter++) {
108  if (((*intIter) < 1) || (1700 < (*intIter))) {
109  edm::LogError("EcalDigiDisplay") << " ic value: " << (*intIter) << " found in listChannels. "
110  << " Valid range is 1-1700. Returning.";
111  inputIsOk = false;
112  return;
113  }
114  }
115  }
116  //Check with Towers in Barrel
117  if (ttDigi) {
118  for (intIter = listTowers.begin(); intIter != listTowers.end(); intIter++) {
119  if (((*intIter) < 1) || (70 < (*intIter))) {
120  edm::LogError("EcalDigiDisplay") << " TT value: " << (*intIter) << " found in listTowers. "
121  << " Valid range for EB SM is 1-70. Returning.";
122  inputIsOk = false;
123  return;
124  }
125  }
126  }
127  } else //if EE DCC is being picked up
128  if (ttDigi) {
129  //Check with Towers in Endcap
130  for (intIter = listTowers.begin(); intIter != listTowers.end(); intIter++) {
131  if ((*intIter) > 34) {
132  edm::LogError("EcalDigiDisplay") << " TT value: " << (*intIter) << " found in listTowers. "
133  << " Valid range for EE DCC is 1-34. Returning.";
134  inputIsOk = false;
135  return;
136  }
137  }
138  }
139 
140  //PNs
141  listPns = ps.getUntrackedParameter<std::vector<int> >("listPns", listDefaults);
142  /*
143  if ( listPns[0] != -1 ) pnDigi = true;
144  else {
145  listPns.clear();
146  for ( int i=1; i < 11; ++i ) {
147  listPns.push_back(i);
148  }
149  }
150  */
151  if (pnDigi) {
152  for (intIter = listPns.begin(); intIter != listPns.end(); intIter++) {
153  if (((*intIter) < 1) || (10 < (*intIter))) {
154  edm::LogError("EcalDigiDisplay") << " Pn number : " << (*intIter) << " found in listPns. "
155  << " Valid range is 1-10. Returning.";
156  inputIsOk = false;
157  return;
158  }
159  }
160  }
161 }
162 //=========================================================================
164  //=========================================================================
165  //delete *;
166 }
167 
168 //========================================================================
170  //========================================================================
171  edm::LogInfo("EcalDigiDisplay") << "entering beginRun! ";
172 
174 }
175 
176 //========================================================================
178 //========================================================================
179 
180 //========================================================================
182  //========================================================================
183 
184  if (!inputIsOk)
185  return;
186 
187  //Get DCC headers
189  e.getByToken(rawDataToken_, dccHeader);
190  if (!dccHeader.isValid()) {
191  edm::LogError("EcalDigiUnpackerModule") << "Can't get DCC Headers!";
192  }
193 
194  //
195  bool ebDigisFound = false;
196  bool eeDigisFound = false;
197  bool pnDigisFound = false;
198  // retrieving crystal data from Event
200  e.getByToken(ebDigiToken_, eb_digis);
201  if (!eb_digis.isValid()) {
202  edm::LogError("EcalDigiUnpackerModule") << "EB Digis were not found!";
203  }
204  if (!eb_digis->empty())
205  ebDigisFound = true;
206 
207  //
209  e.getByToken(eeDigiToken_, ee_digis);
210  if (!ee_digis.isValid()) {
211  edm::LogError("EcalDigiUnpackerModule") << "EE Digis were not found!";
212  }
213  if (!ee_digis->empty())
214  eeDigisFound = true;
215 
216  // retrieving crystal PN diodes from Event
218  e.getByToken(pnDiodeDigiToken_, pn_digis);
219  if (!pn_digis.isValid()) {
220  edm::LogError("EcalDigiUnpackerModule") << "PNs were not found!";
221  }
222  if (!pn_digis->empty())
223  pnDigisFound = true;
224 
225  //=============================
226  //Call for funcitons
227  //=============================
228  if (cryDigi || ttDigi) {
229  if (ebDigisFound)
230  readEBDigis(eb_digis, mode);
231  if (eeDigisFound)
232  readEEDigis(ee_digis, mode);
233  if (!(ebDigisFound || eeDigisFound)) {
234  edm::LogWarning("EcalDigiUnpackerModule") << "No Digis were found! Returning..";
235  return;
236  }
237  }
238  if (pnDigi) {
239  if (pnDigisFound)
240  readPNDigis(pn_digis, mode);
241  }
242 }
243 
245 // FUNCTIONS
247 
249  for (EBDigiCollection::const_iterator digiItr = digis->begin(); digiItr != digis->end(); ++digiItr) {
250  EBDetId detId = EBDetId((*digiItr).id());
252 
253  int FEDid = elecId.dccId() + 600;
254  std::vector<int>::iterator fedIter = find(requestedFeds_.begin(), requestedFeds_.end(), FEDid);
255  if (fedIter == requestedFeds_.end())
256  continue;
257 
258  int ic = EBDetId((*digiItr).id()).ic();
259  int tt = EBDetId((*digiItr).id()).tower().iTT();
260 
261  //Check if Mode is set 1 or 2
262  if (Mode == 1) {
263  edm::LogInfo("EcalDigiDisplay") << "\n\n^^^^^^^^^^^^^^^^^^ [EcalDigiDisplay] digi cry collection size "
264  << digis->size();
265  edm::LogInfo("EcalDigiDisplay") << " [EcalDigiDisplay] dumping first " << listChannels[0]
266  << " crystals\n";
267  //It will break if all required digis are dumpped
268  if (ic > listChannels[0])
269  continue;
270  } else if (Mode == 2) {
271  std::vector<int>::iterator icIterCh;
272  std::vector<int>::iterator icIterTt;
273  icIterCh = find(listChannels.begin(), listChannels.end(), ic);
274  icIterTt = find(listTowers.begin(), listTowers.end(), tt);
275  if (icIterCh == listChannels.end() && icIterTt == listTowers.end())
276  continue;
277  edm::LogInfo("EcalDigiDisplay") << "\n\n^^^^^^^^^^^^^^^^^^ [EcalDigiDisplay] digi cry collection size "
278  << digis->size();
279  } else {
280  edm::LogInfo("EcalDigiDisplay") << "[EcalDigiDisplay] parameter mode set to: " << Mode
281  << ". Only mode 1 and 2 are allowed. Returning...";
282  inputIsOk = false;
283  return;
284  }
285  std::cout << "FEDID: " << FEDid << std::endl;
286  std::cout << "Tower: " << EBDetId((*digiItr).id()).tower().iTT() << " ic-cry: " << EBDetId((*digiItr).id()).ic()
287  << " i-phi: " << EBDetId((*digiItr).id()).iphi() << " j-eta: " << EBDetId((*digiItr).id()).ieta()
288  << std::endl;
289  //Get Samples
290  for (unsigned int i = 0; i < (*digiItr).size(); ++i) {
291  EBDataFrame df(*digiItr);
292  if (!(i % 3))
293  std::cout << "\n\t";
294  std::cout << "sId: " << (i + 1) << " " << df.sample(i) << "\t";
295  }
296  std::cout << " " << std::endl;
297  }
298 }
299 
300 //Function for EE Digis
302  //For Endcap so far works only Mode 2
303  if (Mode != 2) {
304  std::cout << "For Endcap mode needs to be set to 2" << std::endl;
305  return;
306  }
307 
308  for (EEDigiCollection::const_iterator digiItr = digis->begin(); digiItr != digis->end(); ++digiItr) {
309  //Make sure that digis are form requested place
310  EEDetId detId = EEDetId((*digiItr).id());
312 
313  int FEDid = elecId.dccId() + 600;
314  std::vector<int>::iterator fedIter = find(requestedFeds_.begin(), requestedFeds_.end(), FEDid);
315  if (fedIter == requestedFeds_.end())
316  continue;
317 
318  edm::LogInfo("EcalDigiDisplay") << "\n\n^^^^^^^^^^^^^^^^^^ [EcalDigiDisplay] digi cry collection size "
319  << digis->size();
320 
321  int crystalId = 10000 * FEDid + 100 * elecId.towerId() + 5 * (elecId.stripId() - 1) + elecId.xtalId();
322  int chId = elecId.towerId(); // this is a channel in Endcap DCC, sometimes also called as Super Crystal
323 
324  std::vector<int>::iterator icIterCh;
325  std::vector<int>::iterator icIterTt;
326  icIterCh = find(listChannels.begin(), listChannels.end(), crystalId);
327  icIterTt = find(listTowers.begin(), listTowers.end(), chId);
328  if (icIterCh == listChannels.end() && icIterTt == listTowers.end())
329  continue;
330 
331  std::cout << "FEDID: " << FEDid << std::endl;
332  std::cout << "Tower: " << elecId.towerId() << "crystalId: " << crystalId
333  << " i-x: " << EEDetId((*digiItr).id()).ix() << " j-y: " << EEDetId((*digiItr).id()).iy() << std::endl;
334 
335  //Get samples
336  for (unsigned int i = 0; i < (*digiItr).size(); ++i) {
337  EEDataFrame df(*digiItr);
338  if (!(i % 3))
339  std::cout << "\n\t";
340  std::cout << "sId: " << (i + 1) << " " << df.sample(i) << "\t";
341  }
342  std::cout << " " << std::endl;
343  }
344 }
345 
347  int pnDigiCounter = 0;
348 
349  //Loop over PN digis
350  for (EcalPnDiodeDigiCollection::const_iterator pnItr = PNs->begin(); pnItr != PNs->end(); ++pnItr) {
351  EcalPnDiodeDetId pnDetId = EcalPnDiodeDetId((*pnItr).id());
352  //Make sure that we look at the requested place
353  int FEDid = pnDetId.iDCCId() + 600;
354  std::vector<int>::iterator fedIter = find(requestedFeds_.begin(), requestedFeds_.end(), FEDid);
355  if (fedIter == requestedFeds_.end())
356  continue;
357  int pnNum = (*pnItr).id().iPnId();
358 
359  if (Mode == 1) {
360  edm::LogInfo("EcalDigiDisplay") << "\n\n^^^^^^^^^^^^^^^^^^ EcalDigiDisplay digi PN collection. Size: "
361  << PNs->size();
362  edm::LogInfo("EcalDigiDisplay") << " [EcalDigiDisplay] dumping first " << listPns[0]
363  << " PNs ";
364 
365  if ((pnDigiCounter++) >= listPns[0])
366  break;
367  } else if (Mode == 2) {
368  edm::LogInfo("EcalDigiDisplay") << "\n\n^^^^^^^^^^^^^^^^^^ EcalDigiDisplay digi PN collection. Size: "
369  << PNs->size();
370 
371  // Check that we look at PN from the given list
372  std::vector<int>::iterator pnIter;
373  pnIter = find(listPns.begin(), listPns.end(), pnNum);
374  if (pnIter == listPns.end())
375  continue;
376  } else {
377  edm::LogError("EcalDigiDisplay") << "[EcalDigiDisplay] parameter mode set to: " << Mode
378  << ". Only mode 1 and 2 are allowed. Returning...";
379  inputIsOk = false;
380  return;
381  }
382 
383  std::cout << "DCCID: " << pnDetId.iDCCId() << std::endl;
384  std::cout << "\nPN num: " << (*pnItr).id().iPnId();
385  for (int samId = 0; samId < (*pnItr).size(); samId++) {
386  if (!(samId % 3))
387  std::cout << "\n\t";
388  std::cout << "sId: " << (samId + 1) << " " << (*pnItr).sample(samId) << "\t";
389  }
390  }
391 }
392 
393 //===================================================
395  //==================================================
396  edm::LogInfo("EcalDigiDisplay") << "DONE!.... ";
397 }
const edm::EDGetTokenT< EcalRawDataCollection > rawDataToken_
ESGetTokenH3DDVariant esConsumes(std::string const &Record, edm::ConsumesCollector &)
Definition: DeDxTools.cc:283
const edm::EDGetTokenT< EEDigiCollection > eeDigiToken_
std::vector< int > requestedFeds_
size_type size() const
Ecal readout channel identification [32:20] Unused (so far) [19:13] DCC id [12:6] tower [5:3] strip [...
void endRun(edm::Run const &, edm::EventSetup const &c) override
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
const edm::ESGetToken< EcalElectronicsMapping, EcalMappingRcd > ecalMappingToken_
const edm::EDGetTokenT< EcalPnDiodeDigiCollection > pnDiodeDigiToken_
void analyze(edm::Event const &e, edm::EventSetup const &c) override
std::vector< int > listPns
void readEBDigis(edm::Handle< EBDigiCollection > digis, int Mode)
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 readEEDigis(edm::Handle< EEDigiCollection > digis, int Mode)
EcalFedMap * fedMap
T getUntrackedParameter(std::string const &, T const &) const
Definition: TTTypes.h:54
void beginRun(edm::Run const &, edm::EventSetup const &c) override
Transition
Definition: Transition.h:12
void readPNDigis(edm::Handle< EcalPnDiodeDigiCollection > PNs, int Mode)
const_iterator begin() const
void endJob() override
const_iterator end() const
const_iterator end() const
std::vector< int > listTowers
const EcalElectronicsMapping * ecalElectronicsMap_
Log< level::Info, false > LogInfo
~EcalDigiDisplay() override
std::vector< int > listChannels
const_iterator begin() const
The iterator returned can not safely be used across threads.
boost::transform_iterator< IterHelp, boost::counting_iterator< int > > const_iterator
bool isValid() const
Definition: HandleBase.h:70
EcalDigiDisplay(const edm::ParameterSet &ps)
HLT enums.
EcalElectronicsId getElectronicsId(const DetId &id) const
Get the electronics id for this det id.
Log< level::Warning, false > LogWarning
int iDCCId() const
get the DCCId
std::vector< std::string > requestedEbs_
const edm::EDGetTokenT< EBDigiCollection > ebDigiToken_
Definition: Run.h:45