Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 12:29:23

0001 /** \class EcalEBTrigPrimProducer
0002  * For Phase II
0003  * EcalEBTrigPrimProducer produces a EcalEBTrigPrimDigiCollection
0004  * out of PhaseI Digis. This is a simple starting point to fill in the chain
0005  * for Phase II
0006  * 
0007  *
0008  *
0009  ************************************************************/
0010 #include "FWCore/Framework/interface/Frameworkfwd.h"
0011 
0012 #include "FWCore/Framework/interface/Event.h"
0013 #include "FWCore/Framework/interface/MakerMacros.h"
0014 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0015 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0016 #include "FWCore/Utilities/interface/InputTag.h"
0017 
0018 #include "DataFormats/Provenance/interface/ProductID.h"
0019 #include "DataFormats/Provenance/interface/ParameterSetID.h"
0020 #include "DataFormats/Provenance/interface/Provenance.h"
0021 #include "DataFormats/EcalDigi/interface/EcalDigiCollections.h"
0022 //
0023 
0024 /*
0025 #include "CondFormats/DataRecord/interface/EcalTPGFineGrainEBGroupRcd.h"
0026 #include "CondFormats/DataRecord/interface/EcalTPGFineGrainEBIdMapRcd.h"
0027 #include "CondFormats/DataRecord/interface/EcalTPGFineGrainTowerEERcd.h"
0028 
0029 #include "CondFormats/EcalObjects/interface/EcalTPGFineGrainEBGroup.h"
0030 #include "CondFormats/EcalObjects/interface/EcalTPGFineGrainEBIdMap.h"
0031 #include "CondFormats/EcalObjects/interface/EcalTPGFineGrainTowerEE.h"
0032 #include "CondFormats/DataRecord/interface/EcalTPGFineGrainStripEERcd.h"
0033 #include "CondFormats/EcalObjects/interface/EcalTPGWeightIdMap.h"
0034 #include "CondFormats/EcalObjects/interface/EcalTPGWeightGroup.h"
0035 #include "CondFormats/EcalObjects/interface/EcalTPGFineGrainStripEE.h"
0036 #include "CondFormats/EcalObjects/interface/EcalTPGTowerStatus.h"
0037 #include "CondFormats/DataRecord/interface/EcalTPGStripStatusRcd.h"
0038 #include "CondFormats/EcalObjects/interface/EcalTPGStripStatus.h"
0039 */
0040 
0041 #include "EcalEBTrigPrimProducer.h"
0042 
0043 #include <memory>
0044 
0045 #include "SimCalorimetry/EcalEBTrigPrimAlgos/interface/EcalEBTrigPrimTestAlgo.h"
0046 
0047 EcalEBTrigPrimProducer::EcalEBTrigPrimProducer(const edm::ParameterSet& iConfig)
0048     : barrelOnly_(iConfig.getParameter<bool>("BarrelOnly")),
0049       tcpFormat_(iConfig.getParameter<bool>("TcpOutput")),
0050       debug_(iConfig.getParameter<bool>("Debug")),
0051       famos_(iConfig.getParameter<bool>("Famos")),
0052       nSamples_(iConfig.getParameter<int>("nOfSamples")),
0053       binOfMaximum_(iConfig.getParameter<int>("binOfMaximum")) {
0054   tokenEBdigi_ = consumes<EBDigiCollection>(iConfig.getParameter<edm::InputTag>("barrelEcalDigis"));
0055   theEcalTPGLinearization_Token_ =
0056       esConsumes<EcalTPGLinearizationConst, EcalTPGLinearizationConstRcd, edm::Transition::BeginRun>();
0057   theEcalTPGPedestals_Token_ = esConsumes<EcalTPGPedestals, EcalTPGPedestalsRcd, edm::Transition::BeginRun>();
0058   theEcalTPGCrystalStatus_Token_ =
0059       esConsumes<EcalTPGCrystalStatus, EcalTPGCrystalStatusRcd, edm::Transition::BeginRun>();
0060   theEcalTPGWEightIdMap_Token_ = esConsumes<EcalTPGWeightIdMap, EcalTPGWeightIdMapRcd, edm::Transition::BeginRun>();
0061   theEcalTPGWEightGroup_Token_ = esConsumes<EcalTPGWeightGroup, EcalTPGWeightGroupRcd, edm::Transition::BeginRun>();
0062   theEcalTPGSlidingWindow_Token_ =
0063       esConsumes<EcalTPGSlidingWindow, EcalTPGSlidingWindowRcd, edm::Transition::BeginRun>();
0064   theEcalTPGLutGroup_Token_ = esConsumes<EcalTPGLutGroup, EcalTPGLutGroupRcd, edm::Transition::BeginRun>();
0065   theEcalTPGLutIdMap_Token_ = esConsumes<EcalTPGLutIdMap, EcalTPGLutIdMapRcd, edm::Transition::BeginRun>();
0066   theEcalTPGTowerStatus_Token_ = esConsumes<EcalTPGTowerStatus, EcalTPGTowerStatusRcd, edm::Transition::BeginRun>();
0067   theEcalTPGSpike_Token_ = esConsumes<EcalTPGSpike, EcalTPGSpikeRcd, edm::Transition::BeginRun>();
0068   //register your products
0069   produces<EcalEBTrigPrimDigiCollection>();
0070   if (tcpFormat_)
0071     produces<EcalEBTrigPrimDigiCollection>("formatTCP");
0072   if (not barrelOnly_) {
0073     eTTmapToken_ = esConsumes<edm::Transition::BeginRun>();
0074     theGeometryToken_ = esConsumes<edm::Transition::BeginRun>();
0075   }
0076 }
0077 
0078 void EcalEBTrigPrimProducer::beginRun(edm::Run const& run, edm::EventSetup const& setup) {
0079   //ProcessHistory is guaranteed to be constant for an entire Run
0080   //binOfMaximum_ = findBinOfMaximum(fillBinOfMaximumFromHistory_,binOfMaximum_,run.processHistory());
0081 
0082   if (barrelOnly_) {
0083     algo_ = std::make_unique<EcalEBTrigPrimTestAlgo>(nSamples_, binOfMaximum_, tcpFormat_, debug_, famos_);
0084   } else {
0085     auto const& theGeometry = setup.getData(theGeometryToken_);
0086     auto const& eTTmap = setup.getData(eTTmapToken_);
0087     algo_ = std::make_unique<EcalEBTrigPrimTestAlgo>(
0088         &eTTmap, &theGeometry, nSamples_, binOfMaximum_, tcpFormat_, debug_, famos_);
0089   }
0090   // get a first version of the records
0091   cacheID_ = this->getRecords(setup);
0092   nEvent_ = 0;
0093 }
0094 
0095 unsigned long long EcalEBTrigPrimProducer::getRecords(edm::EventSetup const& setup) {
0096   // get parameter records for xtals
0097   auto theEcalTPGLinearization_handle = setup.getHandle(theEcalTPGLinearization_Token_);
0098   const EcalTPGLinearizationConst* ecaltpLin = theEcalTPGLinearization_handle.product();
0099   //
0100   edm::ESHandle<EcalTPGPedestals> theEcalTPGPedestals_handle = setup.getHandle(theEcalTPGPedestals_Token_);
0101   const EcalTPGPedestals* ecaltpPed = theEcalTPGPedestals_handle.product();
0102   //
0103   edm::ESHandle<EcalTPGCrystalStatus> theEcalTPGCrystalStatus_handle = setup.getHandle(theEcalTPGCrystalStatus_Token_);
0104   const EcalTPGCrystalStatus* ecaltpgBadX = theEcalTPGCrystalStatus_handle.product();
0105   //
0106   //for strips
0107   //
0108   edm::ESHandle<EcalTPGWeightIdMap> theEcalTPGWEightIdMap_handle = setup.getHandle(theEcalTPGWEightIdMap_Token_);
0109   const EcalTPGWeightIdMap* ecaltpgWeightMap = theEcalTPGWEightIdMap_handle.product();
0110   //
0111   edm::ESHandle<EcalTPGWeightGroup> theEcalTPGWEightGroup_handle = setup.getHandle(theEcalTPGWEightGroup_Token_);
0112   const EcalTPGWeightGroup* ecaltpgWeightGroup = theEcalTPGWEightGroup_handle.product();
0113   //
0114   edm::ESHandle<EcalTPGSlidingWindow> theEcalTPGSlidingWindow_handle = setup.getHandle(theEcalTPGSlidingWindow_Token_);
0115   const EcalTPGSlidingWindow* ecaltpgSlidW = theEcalTPGSlidingWindow_handle.product();
0116   //  TCP
0117   edm::ESHandle<EcalTPGLutGroup> theEcalTPGLutGroup_handle = setup.getHandle(theEcalTPGLutGroup_Token_);
0118   const EcalTPGLutGroup* ecaltpgLutGroup = theEcalTPGLutGroup_handle.product();
0119   //
0120   edm::ESHandle<EcalTPGLutIdMap> theEcalTPGLutIdMap_handle = setup.getHandle(theEcalTPGLutIdMap_Token_);
0121   const EcalTPGLutIdMap* ecaltpgLut = theEcalTPGLutIdMap_handle.product();
0122   //
0123   edm::ESHandle<EcalTPGTowerStatus> theEcalTPGTowerStatus_handle = setup.getHandle(theEcalTPGTowerStatus_Token_);
0124   const EcalTPGTowerStatus* ecaltpgBadTT = theEcalTPGTowerStatus_handle.product();
0125   //
0126   edm::ESHandle<EcalTPGSpike> theEcalTPGSpike_handle = setup.getHandle(theEcalTPGSpike_Token_);
0127   const EcalTPGSpike* ecaltpgSpike = theEcalTPGSpike_handle.product();
0128 
0129   ////////////////
0130   algo_->setPointers(ecaltpLin,
0131                      ecaltpPed,
0132                      ecaltpgBadX,
0133                      ecaltpgWeightMap,
0134                      ecaltpgWeightGroup,
0135                      ecaltpgSlidW,
0136                      ecaltpgLutGroup,
0137                      ecaltpgLut,
0138                      ecaltpgBadTT,
0139                      ecaltpgSpike);
0140   return setup.get<EcalTPGLinearizationConstRcd>().cacheIdentifier();
0141 }
0142 
0143 void EcalEBTrigPrimProducer::endRun(edm::Run const& run, edm::EventSetup const& setup) { algo_.reset(); }
0144 
0145 EcalEBTrigPrimProducer::~EcalEBTrigPrimProducer() {}
0146 
0147 // ------------ method called to produce the data  ------------
0148 void EcalEBTrigPrimProducer::produce(edm::Event& e, const edm::EventSetup& iSetup) {
0149   nEvent_++;
0150 
0151   // get input collections
0152   edm::Handle<EBDigiCollection> barrelDigiHandle;
0153 
0154   if (!e.getByToken(tokenEBdigi_, barrelDigiHandle)) {
0155     edm::EDConsumerBase::Labels labels;
0156     labelsForToken(tokenEBdigi_, labels);
0157     edm::LogWarning("EcalTPG") << " Couldnt find Barrel digis " << labels.module << " and label "
0158                                << labels.productInstance << "!!!";
0159   }
0160 
0161   if (debug_)
0162     std::cout << "EcalTPG"
0163               << " =================> Treating event  " << nEvent_ << ", Number of EB digis "
0164               << barrelDigiHandle.product()->size() << std::endl;
0165 
0166   auto pOut = std::make_unique<EcalEBTrigPrimDigiCollection>();
0167   auto pOutTcp = std::make_unique<EcalEBTrigPrimDigiCollection>();
0168 
0169   // if ( e.id().event() != 648 ) return;
0170 
0171   //std::cout << " Event number " << e.id().event() << std::endl;
0172 
0173   // invoke algorithm
0174 
0175   const EBDigiCollection* ebdigi = nullptr;
0176   ebdigi = barrelDigiHandle.product();
0177   algo_->run(ebdigi, *pOut, *pOutTcp);
0178 
0179   if (debug_)
0180     std::cout << "produce"
0181               << " For Barrel  " << pOut->size() << " TP  Digis were produced" << std::endl;
0182 
0183   //  debug prints if TP >0
0184 
0185   int nonZeroTP = 0;
0186   for (unsigned int i = 0; i < pOut->size(); ++i) {
0187     if (debug_) {
0188       std::cout << "EcalTPG Printing only non zero TP "
0189                 << " For tower  " << (((*pOut)[i])).id() << ", TP is " << (*pOut)[i];
0190       for (int isam = 0; isam < (*pOut)[i].size(); ++isam) {
0191         if ((*pOut)[i][isam].encodedEt() > 0) {
0192           nonZeroTP++;
0193           std::cout << " (*pOut)[i][isam].raw() " << (*pOut)[i][isam].raw() << "  (*pOut)[i][isam].encodedEt() "
0194                     << (*pOut)[i][isam].encodedEt() << std::endl;
0195         }
0196       }
0197     }
0198   }
0199   if (debug_)
0200     std::cout << "EcalTPG"
0201               << "\n =================> For Barrel , " << pOut->size()
0202               << " TP  Digis were produced (including zero ones)"
0203               << " Non zero primitives were " << nonZeroTP << std::endl;
0204 
0205   // put result into the Event
0206   e.put(std::move(pOut));
0207   if (tcpFormat_)
0208     e.put(std::move(pOutTcp), "formatTCP");
0209 }