Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2022-06-11 03:13:07

0001 /**
0002  * \file EcalDigiDumperModule.h 
0003  * dummy module  for the test of  DaqFileInputService
0004  *   
0005  * 
0006  * \author N. Amapane - S. Argiro'
0007  * \author G. Franzoni
0008  *
0009  */
0010 
0011 #include <FWCore/Framework/interface/one/EDAnalyzer.h>
0012 #include <FWCore/Framework/interface/Event.h>
0013 #include <FWCore/Framework/interface/MakerMacros.h>
0014 #include <DataFormats/EcalDigi/interface/EcalDigiCollections.h>
0015 #include <DataFormats/EcalDetId/interface/EcalDetIdCollections.h>
0016 
0017 #include <iostream>
0018 #include <vector>
0019 
0020 class EcalDigiDumperModule : public edm::one::EDAnalyzer<> {
0021 public:
0022   EcalDigiDumperModule(const edm::ParameterSet& ps) {
0023     verbosity = ps.getUntrackedParameter<int>("verbosity", 1);
0024 
0025     ieb_id = ps.getUntrackedParameter<int>("ieb_id", -1);
0026 
0027     memErrors = ps.getUntrackedParameter<bool>("memErrors", true);
0028     cryDigi = ps.getUntrackedParameter<bool>("cryDigi", true);
0029     pnDigi = ps.getUntrackedParameter<bool>("pnDigi", true);
0030     tpDigi = ps.getUntrackedParameter<bool>("tpDigi", true);
0031 
0032     mode = ps.getUntrackedParameter<int>("mode", 2);
0033 
0034     numChannel = ps.getUntrackedParameter<int>("numChannel", 10);
0035     numPN = ps.getUntrackedParameter<int>("numPN", 2);
0036 
0037     listChannels = ps.getUntrackedParameter<std::vector<int> >("listChannels", std::vector<int>());
0038     listTowers = ps.getUntrackedParameter<std::vector<int> >("listTowers", std::vector<int>());
0039     listPns = ps.getUntrackedParameter<std::vector<int> >("listPns", std::vector<int>());
0040 
0041     inputIsOk = true;
0042     // consistency checks checks
0043 
0044     if ((!(mode == 1)) && (!(mode == 2))) {
0045       std::cout << "[EcalDigiDumperModule] parameter mode set to: " << mode
0046                 << ". Only mode 1 and 2 are allowed, returning." << std::endl;
0047       inputIsOk = false;
0048       return;
0049     }
0050 
0051     std::vector<int>::iterator intIter;
0052 
0053     for (intIter = listChannels.begin(); intIter != listChannels.end(); intIter++) {
0054       if (((*intIter) < 1) || (1700 < (*intIter))) {
0055         std::cout << "[EcalDigiDumperModule] ic value: " << (*intIter) << " found in listChannels. "
0056                   << " Valid range is 1-1700. Returning." << std::endl;
0057         inputIsOk = false;
0058         return;
0059       }
0060     }
0061 
0062     for (intIter = listTowers.begin(); intIter != listTowers.end(); intIter++) {
0063       if (((*intIter) < 1) || (70 < (*intIter))) {
0064         std::cout << "[EcalDigiDumperModule] ic value: " << (*intIter) << " found in listTowers. "
0065                   << " Valid range is 1-70. Returning." << std::endl;
0066         inputIsOk = false;
0067         return;
0068       }
0069     }
0070 
0071     for (intIter = listPns.begin(); intIter != listPns.end(); intIter++) {
0072       if (((*intIter) < 1) || (10 < (*intIter))) {
0073         std::cout << "[EcalDigiDumperModule] pn number : " << (*intIter) << " found in listPns. "
0074                   << " Valid range is 1-10. Returning." << std::endl;
0075         inputIsOk = false;
0076         return;
0077       }
0078     }
0079   }
0080 
0081 protected:
0082   int verbosity;
0083   bool memErrors;
0084   bool cryDigi;
0085   bool pnDigi;
0086   bool tpDigi;
0087 
0088   bool inputIsOk;
0089 
0090   int ieb_id;
0091 
0092   int mode;
0093 
0094   int numChannel;
0095   int numPN;
0096 
0097   std::vector<int> listChannels;
0098   std::vector<int> listTowers;
0099   std::vector<int> listPns;
0100 
0101   void analyze(const edm::Event& e, const edm::EventSetup& c) {
0102     if (!inputIsOk)
0103       return;
0104 
0105     // retrieving crystal data from Event
0106     edm::Handle<EBDigiCollection> digis;
0107     e.getByLabel("ecalEBunpacker", "ebDigis", digis);
0108 
0109     // retrieving crystal PN diodes from Event
0110     edm::Handle<EcalPnDiodeDigiCollection> PNs;
0111     e.getByLabel("ecalEBunpacker", PNs);
0112 
0113     // retrieve collection of errors in the mem gain data
0114     edm::Handle<EcalElectronicsIdCollection> gainMem;
0115     e.getByLabel("ecalEBunpacker", "EcalIntegrityMemChIdErrors", gainMem);
0116 
0117     // retrieve collection of errors in the mem gain data
0118     edm::Handle<EcalElectronicsIdCollection> MemId;
0119     e.getByLabel("ecalEBunpacker", "EcalIntegrityMemTtIdErrors", MemId);
0120 
0121     std::cout << "\n\n";
0122 
0123     if (gainMem->size() && memErrors) {
0124       std::cout << "\n\n^^^^^^^^^^^^^^^^^^ [EcalDigiDumperModule]  Size of collection of mem gain errors is: "
0125                 << gainMem->size() << std::endl;
0126       std::cout << "                                  [EcalDigiDumperModule]  dumping the bit gain errors\n"
0127                 << std::endl;
0128       for (EcalElectronicsIdCollection::const_iterator errItr = gainMem->begin(); errItr != gainMem->end(); ++errItr) {
0129         EcalElectronicsId id = (*errItr);
0130         std::cout << "channel: dccNum= " << id.dccId() << "\t tower= " << id.towerId()
0131                   << "\t channelNum= " << id.channelId() << " has problems in the gain bits" << std::endl;
0132       }  // end of loop on gain errors in the mem
0133     }    // end if
0134 
0135     if (MemId->size() && memErrors) {
0136       std::cout << "\n\n^^^^^^^^^^^^^^^^^^ [EcalDigiDumperModule]  Size of collection of mem tt_block_id errors is: "
0137                 << MemId->size() << std::endl;
0138       std::cout << "                                  [EcalDigiDumperModule]  dumping the mem tt_block_idb errors\n"
0139                 << std::endl;
0140       for (EcalElectronicsIdCollection::const_iterator errItr = MemId->begin(); errItr != MemId->end(); ++errItr) {
0141         EcalElectronicsId id = (*errItr);
0142         std::cout << "tower_block: dccNum= " << id.dccId() << "\t tower= " << id.towerId() << " has ID problems "
0143                   << std::endl;
0144       }  // end of loop tower_block_id errors in the mem
0145     }    // end if
0146 
0147     short dumpCounter = 0;
0148 
0149     if (verbosity > 0 && cryDigi && (mode == 1)) {
0150       std::cout << "\n\n^^^^^^^^^^^^^^^^^^ [EcalDigiDumperModule]  digi cry collection size " << digis->size()
0151                 << std::endl;
0152       std::cout << "                                  [EcalDigiDumperModule]  dumping first " << numChannel
0153                 << " crystals\n";
0154       dumpCounter = 0;
0155       for (EBDigiCollection::const_iterator digiItr = digis->begin(); digiItr != digis->end(); ++digiItr) {
0156         {
0157           if ((dumpCounter++) >= numChannel)
0158             break;
0159           if (!((EBDetId((*digiItr).id()).ism() == ieb_id) || (ieb_id == -1)))
0160             continue;
0161 
0162           std::cout << "ic-cry: " << EBDetId((*digiItr).id()).ic() << " i-phi: " << EBDetId((*digiItr).id()).iphi()
0163                     << " j-eta: " << EBDetId((*digiItr).id()).ieta();
0164 
0165           for (unsigned int i = 0; i < (*digiItr).size(); ++i) {
0166             EBDataFrame df(*digiItr);
0167             if (!(i % 3))
0168               std::cout << "\n\t";
0169             std::cout << "sId: " << (i + 1) << " " << df.sample(i) << "\t";
0170           }
0171           std::cout << " " << std::endl;
0172         }
0173       }
0174     }
0175 
0176     if (verbosity > 0 && cryDigi && (mode == 2)) {
0177       std::cout << "\n\n^^^^^^^^^^^^^^^^^^ [EcalDigiDumperModule]  digi cry collection size " << digis->size()
0178                 << std::endl;
0179       for (EBDigiCollection::const_iterator digiItr = digis->begin(); digiItr != digis->end(); ++digiItr) {
0180         {
0181           int ic = EBDetId((*digiItr).id()).ic();
0182           int tt = EBDetId((*digiItr).id()).tower().iTT();
0183 
0184           if (!((EBDetId((*digiItr).id()).ism() == ieb_id) || (ieb_id == -1)))
0185             continue;
0186 
0187           std::vector<int>::iterator icIterCh;
0188           std::vector<int>::iterator icIterTt;
0189           icIterCh = find(listChannels.begin(), listChannels.end(), ic);
0190           icIterTt = find(listTowers.begin(), listTowers.end(), tt);
0191           if (icIterCh == listChannels.end() && icIterTt == listTowers.end()) {
0192             continue;
0193           }
0194 
0195           std::cout << "ic-cry: " << ic << " i-phi: " << EBDetId((*digiItr).id()).iphi()
0196                     << " j-eta: " << EBDetId((*digiItr).id()).ieta() << " tower: " << tt;
0197 
0198           for (unsigned int i = 0; i < (*digiItr).size(); ++i) {
0199             EBDataFrame df(*digiItr);
0200             if (!(i % 3))
0201               std::cout << "\n\t";
0202             std::cout << "sId: " << (i + 1) << " " << df.sample(i) << "\t";
0203           }
0204           std::cout << " " << std::endl;
0205         }
0206       }
0207     }
0208 
0209     if (verbosity > 0 && pnDigi && (mode == 1)) {
0210       std::cout << "\n\n^^^^^^^^^^^^^^^^^^ EcalDigiDumperModule  digi PN collection.  Size: " << PNs->size()
0211                 << std::endl;
0212       std::cout << "                                  [EcalDigiDumperModule]  dumping first " << numPN << " PNs ";
0213       dumpCounter = 0;
0214       for (EcalPnDiodeDigiCollection::const_iterator pnItr = PNs->begin(); pnItr != PNs->end(); ++pnItr) {
0215         if ((dumpCounter++) >= numPN)
0216           break;
0217         if (!((EcalPnDiodeDetId((*pnItr).id()).iDCCId() == ieb_id) || (ieb_id == -1)))
0218           continue;
0219 
0220         std::cout << "\nPN num: " << (*pnItr).id().iPnId();
0221 
0222         for (int samId = 0; samId < (*pnItr).size(); samId++) {
0223           if (!(samId % 3))
0224             std::cout << "\n\t";
0225           std::cout << "sId: " << (samId + 1) << " " << (*pnItr).sample(samId) << "\t";
0226         }  //  PN samples
0227 
0228       }  // PNs
0229     }
0230 
0231     if (verbosity > 0 && pnDigi && (mode == 2)) {
0232       std::cout << "\n\n^^^^^^^^^^^^^^^^^^ EcalDigiDumperModule  digi PN collection.  Size: " << PNs->size()
0233                 << std::endl;
0234 
0235       for (EcalPnDiodeDigiCollection::const_iterator pnItr = PNs->begin(); pnItr != PNs->end(); ++pnItr) {
0236         int pnNum = (*pnItr).id().iPnId();
0237 
0238         if (!((EcalPnDiodeDetId((*pnItr).id()).iDCCId() == ieb_id) || (ieb_id == -1)))
0239           continue;
0240 
0241         std::vector<int>::iterator pnIter;
0242         pnIter = find(listPns.begin(), listPns.end(), pnNum);
0243         if (pnIter == listPns.end()) {
0244           continue;
0245         }
0246 
0247         std::cout << "\nPN num: " << (*pnItr).id().iPnId();
0248         for (int samId = 0; samId < (*pnItr).size(); samId++) {
0249           if (!(samId % 3))
0250             std::cout << "\n\t";
0251           std::cout << "sId: " << (samId + 1) << " " << (*pnItr).sample(samId) << "\t";
0252         }  //  PN samples
0253 
0254       }  // PNs
0255     }
0256 
0257     //     // retrieving crystal TP from the Event
0258     //     edm::Handle<EcalTrigPrimDigiCollection>  primitives;
0259     //     e.getByLabel("ecalEBunpacker", primitives);
0260 
0261     //     if (verbosity>0 && tpDigi)
0262     //       {
0263     //  std::cout << "\n\n^^^^^^^^^^^^^^^^^^ EcalDigiDumperModule  digi TP collection.  Size: " << primitives->size() << std::endl;
0264     //  std::cout << "                                  [EcalDigiDumperModule]  dumping primitives "  << std::endl;
0265     //  for ( EcalTrigPrimDigiCollection::const_iterator TPtr = primitives->begin();
0266     //        ( TPtr != primitives->end()  && (TPtr-primitives->begin())<4 );
0267     //      ++TPtr ) {
0268 
0269     //    if (!  ((EcalTrigTowerDetId((*TPtr).id()).iDCC()==ieb_id) || (ieb_id==-1))   ) continue;
0270 
0271     //    std::cout << "[EcalDigiDumperModule] tower: " << ( (TPtr-primitives->begin()) +1)
0272     //         << "\n" << (*TPtr) << std::endl;
0273     //  }
0274     //       }
0275 
0276   }  // produce
0277 
0278 };  // class EcalDigiDumperModule
0279 
0280 DEFINE_FWK_MODULE(EcalDigiDumperModule);