CMS 3D CMS Logo

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