CMS 3D CMS Logo

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