Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-09-05 22:25:51

0001 /**
0002  * \file EcalDigiDisplay.cc 
0003  * dummy module  for the test of  DaqFileInputService
0004  *   
0005  * 
0006  * \author Keti Kaadze
0007  * \author G. Franzoni
0008  *
0009  */
0010 
0011 #include <FWCore/MessageLogger/interface/MessageLogger.h>
0012 
0013 #include "CaloOnlineTools/EcalTools/plugins/EcalDigiDisplay.h"
0014 #include "CaloOnlineTools/EcalTools/interface/EcalFedMap.h"
0015 #include "DataFormats/EcalDetId/interface/EcalDetIdCollections.h"
0016 #include "DataFormats/EcalRawData/interface/EcalDCCHeaderBlock.h"
0017 
0018 #include "DataFormats/EcalDigi/interface/EcalTriggerPrimitiveDigi.h"
0019 #include "DataFormats/EcalDigi/interface/EcalTriggerPrimitiveSample.h"
0020 
0021 #include <iostream>
0022 #include <vector>
0023 
0024 //==========================================================================
0025 EcalDigiDisplay::EcalDigiDisplay(const edm::ParameterSet& ps)
0026     : ebDigiCollection_(ps.getParameter<std::string>("ebDigiCollection")),
0027       eeDigiCollection_(ps.getParameter<std::string>("eeDigiCollection")),
0028       digiProducer_(ps.getParameter<std::string>("digiProducer")),
0029       rawDataToken_(consumes<EcalRawDataCollection>(edm::InputTag(digiProducer_))),
0030       ebDigiToken_(consumes<EBDigiCollection>(edm::InputTag(digiProducer_, ebDigiCollection_))),
0031       eeDigiToken_(consumes<EEDigiCollection>(edm::InputTag(digiProducer_, eeDigiCollection_))),
0032       pnDiodeDigiToken_(consumes<EcalPnDiodeDigiCollection>(edm::InputTag(digiProducer_))),
0033       ecalMappingToken_(esConsumes<edm::Transition::BeginRun>()) {
0034   //=========================================================================
0035   requestedFeds_ = ps.getUntrackedParameter<std::vector<int> >("requestedFeds");
0036   requestedEbs_ = ps.getUntrackedParameter<std::vector<std::string> >("requestedEbs");
0037 
0038   cryDigi = ps.getUntrackedParameter<bool>("cryDigi");
0039   ttDigi = ps.getUntrackedParameter<bool>("ttDigi");
0040   pnDigi = ps.getUntrackedParameter<bool>("pnDigi");
0041 
0042   mode = ps.getUntrackedParameter<int>("mode");
0043   listChannels = ps.getUntrackedParameter<std::vector<int> >("listChannels");
0044   listTowers = ps.getUntrackedParameter<std::vector<int> >("listTowers");
0045   listPns = ps.getUntrackedParameter<std::vector<int> >("listPns");
0046 
0047   std::vector<int> listDefaults;
0048   listDefaults.push_back(-1);
0049   requestedFeds_ = ps.getUntrackedParameter<std::vector<int> >("requestedFeds", listDefaults);
0050   bool fedIsGiven = false;
0051 
0052   std::vector<std::string> ebDefaults;
0053   ebDefaults.push_back("none");
0054   requestedEbs_ = ps.getUntrackedParameter<std::vector<std::string> >("requestedEbs", ebDefaults);
0055   // FEDs and EBs
0056   if (requestedFeds_[0] != -1) {
0057     edm::LogInfo("EcalDigiDisplay") << "FED id is given! Goining to beginRun! ";
0058     fedIsGiven = true;
0059   } else {
0060     if (requestedEbs_[0] != "none") {
0061       //EB id is given and convert to FED id
0062       requestedFeds_.clear();
0063       fedMap = new EcalFedMap();
0064       for (std::vector<std::string>::const_iterator ebItr = requestedEbs_.begin(); ebItr != requestedEbs_.end();
0065            ++ebItr) {
0066         requestedFeds_.push_back(fedMap->getFedFromSlice(*ebItr));
0067       }
0068       delete fedMap;
0069     } else {
0070       //Select all FEDs in the Event
0071       for (int i = 601; i < 655; ++i) {
0072         requestedFeds_.push_back(i);
0073       }
0074     }
0075   }
0076 
0077   //Channel list
0078   listChannels = ps.getUntrackedParameter<std::vector<int> >("listChannels", listDefaults);
0079   //Tower list
0080   listTowers = ps.getUntrackedParameter<std::vector<int> >("listTowers", listDefaults);
0081 
0082   //Consistancy checks:
0083   std::vector<int>::iterator fedIter;
0084   std::vector<int>::iterator intIter;
0085   inputIsOk = true;
0086 
0087   if (fedIsGiven) {
0088     for (fedIter = requestedFeds_.begin(); fedIter != requestedFeds_.end(); ++fedIter) {
0089       if ((*fedIter) < 601 || (*fedIter) > 655) {
0090         edm::LogError("EcalDigiDisplay") << " FED value: " << (*fedIter) << " found in requetsedFeds. "
0091                                          << " Valid range is 601-654. Returning.";
0092         inputIsOk = false;
0093         return;
0094       }  //Loop over requetsed FEDS
0095     }
0096   }
0097   bool barrelSM = false;
0098   //Loop over and Check if Barrel SM is picked up
0099   for (fedIter = requestedFeds_.begin(); fedIter != requestedFeds_.end(); ++fedIter) {
0100     if ((*fedIter) > 609 && (*fedIter) < 646 && inputIsOk)  // if EB SM is being picked up
0101       barrelSM = true;
0102   }
0103 
0104   if (barrelSM) {
0105     if (cryDigi) {
0106       // Check with channels in Barrel
0107       for (intIter = listChannels.begin(); intIter != listChannels.end(); intIter++) {
0108         if (((*intIter) < 1) || (1700 < (*intIter))) {
0109           edm::LogError("EcalDigiDisplay") << " ic value: " << (*intIter) << " found in listChannels. "
0110                                            << " Valid range is 1-1700. Returning.";
0111           inputIsOk = false;
0112           return;
0113         }
0114       }
0115     }
0116     //Check with Towers in Barrel
0117     if (ttDigi) {
0118       for (intIter = listTowers.begin(); intIter != listTowers.end(); intIter++) {
0119         if (((*intIter) < 1) || (70 < (*intIter))) {
0120           edm::LogError("EcalDigiDisplay") << " TT value: " << (*intIter) << " found in listTowers. "
0121                                            << " Valid range for EB SM is 1-70. Returning.";
0122           inputIsOk = false;
0123           return;
0124         }
0125       }
0126     }
0127   } else  //if EE DCC is being picked up
0128       if (ttDigi) {
0129     //Check with Towers in Endcap
0130     for (intIter = listTowers.begin(); intIter != listTowers.end(); intIter++) {
0131       if ((*intIter) > 34) {
0132         edm::LogError("EcalDigiDisplay") << " TT value: " << (*intIter) << " found in listTowers. "
0133                                          << " Valid range for EE DCC is 1-34. Returning.";
0134         inputIsOk = false;
0135         return;
0136       }
0137     }
0138   }
0139 
0140   //PNs
0141   listPns = ps.getUntrackedParameter<std::vector<int> >("listPns", listDefaults);
0142   /*
0143   if ( listPns[0] != -1 ) pnDigi = true;
0144   else {
0145     listPns.clear();
0146     for ( int i=1; i < 11; ++i ) {
0147       listPns.push_back(i);
0148     }
0149   }
0150   */
0151   if (pnDigi) {
0152     for (intIter = listPns.begin(); intIter != listPns.end(); intIter++) {
0153       if (((*intIter) < 1) || (10 < (*intIter))) {
0154         edm::LogError("EcalDigiDisplay") << " Pn number : " << (*intIter) << " found in listPns. "
0155                                          << " Valid range is 1-10. Returning.";
0156         inputIsOk = false;
0157         return;
0158       }
0159     }
0160   }
0161 }
0162 //=========================================================================
0163 EcalDigiDisplay::~EcalDigiDisplay() {
0164   //=========================================================================
0165   //delete *;
0166 }
0167 
0168 //========================================================================
0169 void EcalDigiDisplay::beginRun(edm::Run const&, edm::EventSetup const& c) {
0170   //========================================================================
0171   edm::LogInfo("EcalDigiDisplay") << "entering beginRun! ";
0172 
0173   ecalElectronicsMap_ = &c.getData(ecalMappingToken_);
0174 }
0175 
0176 //========================================================================
0177 void EcalDigiDisplay::endRun(edm::Run const&, edm::EventSetup const& c) {}
0178 //========================================================================
0179 
0180 //========================================================================
0181 void EcalDigiDisplay::analyze(edm::Event const& e, edm::EventSetup const& c) {
0182   //========================================================================
0183 
0184   if (!inputIsOk)
0185     return;
0186 
0187   //Get DCC headers
0188   edm::Handle<EcalRawDataCollection> dccHeader;
0189   e.getByToken(rawDataToken_, dccHeader);
0190   if (!dccHeader.isValid()) {
0191     edm::LogError("EcalDigiUnpackerModule") << "Can't get DCC Headers!";
0192   }
0193 
0194   //
0195   bool ebDigisFound = false;
0196   bool eeDigisFound = false;
0197   bool pnDigisFound = false;
0198   // retrieving crystal data from Event
0199   edm::Handle<EBDigiCollection> eb_digis;
0200   e.getByToken(ebDigiToken_, eb_digis);
0201   if (!eb_digis.isValid()) {
0202     edm::LogError("EcalDigiUnpackerModule") << "EB Digis were not found!";
0203   }
0204   if (!eb_digis->empty())
0205     ebDigisFound = true;
0206 
0207   //
0208   edm::Handle<EEDigiCollection> ee_digis;
0209   e.getByToken(eeDigiToken_, ee_digis);
0210   if (!ee_digis.isValid()) {
0211     edm::LogError("EcalDigiUnpackerModule") << "EE Digis were not found!";
0212   }
0213   if (!ee_digis->empty())
0214     eeDigisFound = true;
0215 
0216   // retrieving crystal PN diodes from Event
0217   edm::Handle<EcalPnDiodeDigiCollection> pn_digis;
0218   e.getByToken(pnDiodeDigiToken_, pn_digis);
0219   if (!pn_digis.isValid()) {
0220     edm::LogError("EcalDigiUnpackerModule") << "PNs were not found!";
0221   }
0222   if (!pn_digis->empty())
0223     pnDigisFound = true;
0224 
0225   //=============================
0226   //Call for funcitons
0227   //=============================
0228   if (cryDigi || ttDigi) {
0229     if (ebDigisFound)
0230       readEBDigis(eb_digis, mode);
0231     if (eeDigisFound)
0232       readEEDigis(ee_digis, mode);
0233     if (!(ebDigisFound || eeDigisFound)) {
0234       edm::LogWarning("EcalDigiUnpackerModule") << "No Digis were found! Returning..";
0235       return;
0236     }
0237   }
0238   if (pnDigi) {
0239     if (pnDigisFound)
0240       readPNDigis(pn_digis, mode);
0241   }
0242 }
0243 
0244 ///////////////////////////////////
0245 // FUNCTIONS
0246 //////////////////////////////////
0247 
0248 void EcalDigiDisplay::readEBDigis(edm::Handle<EBDigiCollection> digis, int Mode) {
0249   for (EBDigiCollection::const_iterator digiItr = digis->begin(); digiItr != digis->end(); ++digiItr) {
0250     EBDetId detId = EBDetId((*digiItr).id());
0251     EcalElectronicsId elecId = ecalElectronicsMap_->getElectronicsId(detId);
0252 
0253     int FEDid = elecId.dccId() + 600;
0254     std::vector<int>::iterator fedIter = find(requestedFeds_.begin(), requestedFeds_.end(), FEDid);
0255     if (fedIter == requestedFeds_.end())
0256       continue;
0257 
0258     int ic = EBDetId((*digiItr).id()).ic();
0259     int tt = EBDetId((*digiItr).id()).tower().iTT();
0260 
0261     //Check if Mode is set 1 or 2
0262     if (Mode == 1) {
0263       edm::LogInfo("EcalDigiDisplay") << "\n\n^^^^^^^^^^^^^^^^^^ [EcalDigiDisplay]  digi cry collection size "
0264                                       << digis->size();
0265       edm::LogInfo("EcalDigiDisplay") << "                       [EcalDigiDisplay]  dumping first " << listChannels[0]
0266                                       << " crystals\n";
0267       //It will break if all required digis are dumpped
0268       if (ic > listChannels[0])
0269         continue;
0270     } else if (Mode == 2) {
0271       std::vector<int>::iterator icIterCh;
0272       std::vector<int>::iterator icIterTt;
0273       icIterCh = find(listChannels.begin(), listChannels.end(), ic);
0274       icIterTt = find(listTowers.begin(), listTowers.end(), tt);
0275       if (icIterCh == listChannels.end() && icIterTt == listTowers.end())
0276         continue;
0277       edm::LogInfo("EcalDigiDisplay") << "\n\n^^^^^^^^^^^^^^^^^^ [EcalDigiDisplay]  digi cry collection size "
0278                                       << digis->size();
0279     } else {
0280       edm::LogInfo("EcalDigiDisplay") << "[EcalDigiDisplay] parameter mode set to: " << Mode
0281                                       << ". Only mode 1 and 2 are allowed. Returning...";
0282       inputIsOk = false;
0283       return;
0284     }
0285     std::cout << "FEDID: " << FEDid << std::endl;
0286     std::cout << "Tower: " << EBDetId((*digiItr).id()).tower().iTT() << " ic-cry: " << EBDetId((*digiItr).id()).ic()
0287               << " i-phi: " << EBDetId((*digiItr).id()).iphi() << " j-eta: " << EBDetId((*digiItr).id()).ieta()
0288               << std::endl;
0289     //Get Samples
0290     for (unsigned int i = 0; i < (*digiItr).size(); ++i) {
0291       EBDataFrame df(*digiItr);
0292       if (!(i % 3))
0293         std::cout << "\n\t";
0294       std::cout << "sId: " << (i + 1) << " " << df.sample(i) << "\t";
0295     }
0296     std::cout << " " << std::endl;
0297   }
0298 }
0299 
0300 //Function for EE Digis
0301 void EcalDigiDisplay::readEEDigis(edm::Handle<EEDigiCollection> digis, int Mode) {
0302   //For Endcap so far works only  Mode 2
0303   if (Mode != 2) {
0304     std::cout << "For Endcap mode needs to be set to 2" << std::endl;
0305     return;
0306   }
0307 
0308   for (EEDigiCollection::const_iterator digiItr = digis->begin(); digiItr != digis->end(); ++digiItr) {
0309     //Make sure that digis are form requested place
0310     EEDetId detId = EEDetId((*digiItr).id());
0311     EcalElectronicsId elecId = ecalElectronicsMap_->getElectronicsId(detId);
0312 
0313     int FEDid = elecId.dccId() + 600;
0314     std::vector<int>::iterator fedIter = find(requestedFeds_.begin(), requestedFeds_.end(), FEDid);
0315     if (fedIter == requestedFeds_.end())
0316       continue;
0317 
0318     edm::LogInfo("EcalDigiDisplay") << "\n\n^^^^^^^^^^^^^^^^^^ [EcalDigiDisplay]  digi cry collection size "
0319                                     << digis->size();
0320 
0321     int crystalId = 10000 * FEDid + 100 * elecId.towerId() + 5 * (elecId.stripId() - 1) + elecId.xtalId();
0322     int chId = elecId.towerId();  // this is a channel in Endcap DCC, sometimes also called as Super Crystal
0323 
0324     std::vector<int>::iterator icIterCh;
0325     std::vector<int>::iterator icIterTt;
0326     icIterCh = find(listChannels.begin(), listChannels.end(), crystalId);
0327     icIterTt = find(listTowers.begin(), listTowers.end(), chId);
0328     if (icIterCh == listChannels.end() && icIterTt == listTowers.end())
0329       continue;
0330 
0331     std::cout << "FEDID: " << FEDid << std::endl;
0332     std::cout << "Tower: " << elecId.towerId() << "crystalId: " << crystalId
0333               << " i-x: " << EEDetId((*digiItr).id()).ix() << " j-y: " << EEDetId((*digiItr).id()).iy() << std::endl;
0334 
0335     //Get samples
0336     for (unsigned int i = 0; i < (*digiItr).size(); ++i) {
0337       EEDataFrame df(*digiItr);
0338       if (!(i % 3))
0339         std::cout << "\n\t";
0340       std::cout << "sId: " << (i + 1) << " " << df.sample(i) << "\t";
0341     }
0342     std::cout << " " << std::endl;
0343   }
0344 }
0345 
0346 void EcalDigiDisplay::readPNDigis(edm::Handle<EcalPnDiodeDigiCollection> PNs, int Mode) {
0347   int pnDigiCounter = 0;
0348 
0349   //Loop over PN digis
0350   for (EcalPnDiodeDigiCollection::const_iterator pnItr = PNs->begin(); pnItr != PNs->end(); ++pnItr) {
0351     EcalPnDiodeDetId pnDetId = EcalPnDiodeDetId((*pnItr).id());
0352     //Make sure that we look at the requested place
0353     int FEDid = pnDetId.iDCCId() + 600;
0354     std::vector<int>::iterator fedIter = find(requestedFeds_.begin(), requestedFeds_.end(), FEDid);
0355     if (fedIter == requestedFeds_.end())
0356       continue;
0357     int pnNum = (*pnItr).id().iPnId();
0358 
0359     if (Mode == 1) {
0360       edm::LogInfo("EcalDigiDisplay") << "\n\n^^^^^^^^^^^^^^^^^^ EcalDigiDisplay  digi PN collection.  Size: "
0361                                       << PNs->size();
0362       edm::LogInfo("EcalDigiDisplay") << "                       [EcalDigiDisplay]  dumping first " << listPns[0]
0363                                       << " PNs ";
0364 
0365       if ((pnDigiCounter++) >= listPns[0])
0366         break;
0367     } else if (Mode == 2) {
0368       edm::LogInfo("EcalDigiDisplay") << "\n\n^^^^^^^^^^^^^^^^^^ EcalDigiDisplay  digi PN collection.  Size: "
0369                                       << PNs->size();
0370 
0371       // Check that we look at PN from the given list
0372       std::vector<int>::iterator pnIter;
0373       pnIter = find(listPns.begin(), listPns.end(), pnNum);
0374       if (pnIter == listPns.end())
0375         continue;
0376     } else {
0377       edm::LogError("EcalDigiDisplay") << "[EcalDigiDisplay] parameter mode set to: " << Mode
0378                                        << ". Only mode 1 and 2 are allowed. Returning...";
0379       inputIsOk = false;
0380       return;
0381     }
0382 
0383     std::cout << "DCCID: " << pnDetId.iDCCId() << std::endl;
0384     std::cout << "\nPN num: " << (*pnItr).id().iPnId();
0385     for (int samId = 0; samId < (*pnItr).size(); samId++) {
0386       if (!(samId % 3))
0387         std::cout << "\n\t";
0388       std::cout << "sId: " << (samId + 1) << " " << (*pnItr).sample(samId) << "\t";
0389     }
0390   }
0391 }
0392 
0393 //===================================================
0394 void EcalDigiDisplay::endJob() {
0395   //==================================================
0396   edm::LogInfo("EcalDigiDisplay") << "DONE!.... ";
0397 }