Back to home page

Project CMSSW displayed by LXR

 
 

    


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

0001 #include "FWCore/Framework/interface/Frameworkfwd.h"
0002 #include "FWCore/Framework/interface/stream/EDProducer.h"
0003 #include "FWCore/Framework/interface/Event.h"
0004 #include "FWCore/Framework/interface/EventSetup.h"
0005 #include "FWCore/Framework/interface/MakerMacros.h"
0006 #include "FWCore/Utilities/interface/EDGetToken.h"
0007 #include "FWCore/Utilities/interface/ESGetToken.h"
0008 #include "FWCore/Utilities/interface/InputTag.h"
0009 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0010 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0011 //
0012 #include "DataFormats/Common/interface/Handle.h"
0013 #include "DataFormats/Provenance/interface/ProductID.h"
0014 #include "DataFormats/Provenance/interface/ParameterSetID.h"
0015 #include "DataFormats/Provenance/interface/Provenance.h"
0016 #include "DataFormats/EcalDigi/interface/EcalDigiCollections.h"
0017 #include "CondFormats/EcalObjects/interface/EcalLiteDTUPedestals.h"
0018 #include "CondFormats/DataRecord/interface/EcalLiteDTUPedestalsRcd.h"
0019 
0020 #include "CondFormats/DataRecord/interface/EcalTPGCrystalStatusRcd.h"
0021 #include "CondFormats/EcalObjects/interface/EcalTPGCrystalStatus.h"
0022 #include "CondFormats/DataRecord/interface/EcalEBPhase2TPGPedestalsRcd.h"
0023 #include "CondFormats/DataRecord/interface/EcalEBPhase2TPGLinearizationConstRcd.h"
0024 #include "CondFormats/DataRecord/interface/EcalEBPhase2TPGAmplWeightIdMapRcd.h"
0025 #include "CondFormats/DataRecord/interface/EcalEBPhase2TPGTimeWeightIdMapRcd.h"
0026 #include "CondFormats/DataRecord/interface/EcalTPGWeightGroupRcd.h"
0027 #include "CondFormats/EcalObjects/interface/EcalEBPhase2TPGAmplWeightIdMap.h"
0028 #include "CondFormats/EcalObjects/interface/EcalEBPhase2TPGTimeWeightIdMap.h"
0029 #include "CondFormats/EcalObjects/interface/EcalEBPhase2TPGLinearizationConst.h"
0030 #include "CondFormats/EcalObjects/interface/EcalEBPhase2TPGPedestals.h"
0031 #include "CondFormats/EcalObjects/interface/EcalTPGWeightGroup.h"
0032 #include "CondFormats/DataRecord/interface/EcalTPGTowerStatusRcd.h"
0033 #include "CondFormats/DataRecord/interface/EcalTPGSpikeRcd.h"
0034 #include "CondFormats/EcalObjects/interface/EcalTPGSpike.h"
0035 #include "CondFormats/EcalObjects/interface/EcalTPGTowerStatus.h"
0036 
0037 #include "Geometry/CaloGeometry/interface/CaloGeometry.h"
0038 #include "Geometry/CaloTopology/interface/EcalTrigTowerConstituentsMap.h"
0039 #include "Geometry/Records/interface/CaloGeometryRecord.h"
0040 
0041 // We keep these lines for future posssible necessary additions
0042 //#include "CondFormats/EcalObjects/interface/EcalTPGTowerStatus.h"
0043 //#include "CondFormats/DataRecord/interface/EcalTPGStripStatusRcd.h"
0044 //#include "CondFormats/EcalObjects/interface/EcalTPGStripStatus.h"
0045 #include "SimCalorimetry/EcalEBTrigPrimAlgos/interface/EcalEBPhase2TrigPrimAlgo.h"
0046 #include <memory>
0047 
0048 // Class declaration
0049 /** \class EcalEBTrigPrimPhase2Producer                                                                                                                                                   \author L. Lutton, N. Marinelli - Univ. of Notre Dame                                                                                                                                   Description: forPhase II                                                                                                                                                               It consumes the new Phase2 digis based on the new EB electronics                                                                                                                       and plugs in the main steering algo for TP emulation                                                                                                                                   It produces the EcalEBPhase2TrigPrimDigiCollection                                                                                                                                 */
0050 
0051 class EcalEBPhase2TrigPrimAlgo;
0052 
0053 class EcalEBTrigPrimPhase2Producer : public edm::stream::EDProducer<> {
0054 public:
0055   explicit EcalEBTrigPrimPhase2Producer(const edm::ParameterSet& conf);
0056 
0057   ~EcalEBTrigPrimPhase2Producer() override;
0058 
0059   void beginRun(const edm::Run& run, const edm::EventSetup& es) override;
0060   void endRun(const edm::Run&, const edm::EventSetup&) override;
0061   void produce(edm::Event& e, const edm::EventSetup& c) override;
0062   static void fillDescriptions(edm::ConfigurationDescriptions&);
0063 
0064 private:
0065   std::unique_ptr<EcalEBPhase2TrigPrimAlgo> algo_;
0066   bool debug_;
0067   bool famos_;
0068   int nEvent_;
0069   edm::EDGetTokenT<EBDigiCollectionPh2> tokenEBdigi_;
0070   edm::ESGetToken<EcalEBPhase2TPGLinearizationConst, EcalEBPhase2TPGLinearizationConstRcd>
0071       theEcalEBPhase2TPGLinearization_Token_;
0072   edm::ESGetToken<EcalEBPhase2TPGPedestalsMap, EcalEBPhase2TPGPedestalsRcd> theEcalEBPhase2TPGPedestals_Token_;
0073 
0074   edm::ESGetToken<EcalLiteDTUPedestalsMap, EcalLiteDTUPedestalsRcd> theEcalTPGPedestals_Token_;
0075 
0076   edm::ESGetToken<EcalTPGCrystalStatus, EcalTPGCrystalStatusRcd> theEcalTPGCrystalStatus_Token_;
0077   edm::ESGetToken<EcalEBPhase2TPGAmplWeightIdMap, EcalEBPhase2TPGAmplWeightIdMapRcd> theEcalEBTPGAmplWeightIdMap_Token_;
0078   edm::ESGetToken<EcalEBPhase2TPGTimeWeightIdMap, EcalEBPhase2TPGTimeWeightIdMapRcd> theEcalEBTPGTimeWeightIdMap_Token_;
0079 
0080   edm::ESGetToken<EcalTPGWeightGroup, EcalTPGWeightGroupRcd> theEcalTPGWeightGroup_Token_;
0081 
0082   edm::ESGetToken<EcalTPGTowerStatus, EcalTPGTowerStatusRcd> theEcalTPGTowerStatus_Token_;
0083   edm::ESGetToken<EcalTPGSpike, EcalTPGSpikeRcd> theEcalTPGSpike_Token_;
0084 
0085   edm::ESGetToken<EcalTrigTowerConstituentsMap, IdealGeometryRecord> eTTmapToken_;
0086   edm::ESGetToken<CaloGeometry, CaloGeometryRecord> theGeometryToken_;
0087 
0088   int binOfMaximum_;
0089   bool fillBinOfMaximumFromHistory_;
0090 
0091   unsigned long long getRecords(edm::EventSetup const& setup);
0092   unsigned long long cacheID_;
0093 };
0094 
0095 EcalEBTrigPrimPhase2Producer::EcalEBTrigPrimPhase2Producer(const edm::ParameterSet& iConfig)
0096     : debug_(iConfig.getParameter<bool>("Debug")),
0097       famos_(iConfig.getParameter<bool>("Famos")),
0098       binOfMaximum_(iConfig.getParameter<int>("binOfMaximum")) {
0099   tokenEBdigi_ = consumes<EBDigiCollectionPh2>(iConfig.getParameter<edm::InputTag>("barrelEcalDigis"));
0100 
0101   eTTmapToken_ = esConsumes<edm::Transition::BeginRun>();
0102   theGeometryToken_ = esConsumes<edm::Transition::BeginRun>();
0103 
0104   theEcalTPGPedestals_Token_ =
0105       esConsumes<EcalLiteDTUPedestalsMap, EcalLiteDTUPedestalsRcd, edm::Transition::BeginRun>();
0106   theEcalEBPhase2TPGPedestals_Token_ =
0107       esConsumes<EcalEBPhase2TPGPedestalsMap, EcalEBPhase2TPGPedestalsRcd, edm::Transition::BeginRun>();
0108 
0109   theEcalTPGCrystalStatus_Token_ =
0110       esConsumes<EcalTPGCrystalStatus, EcalTPGCrystalStatusRcd, edm::Transition::BeginRun>();
0111   theEcalEBPhase2TPGLinearization_Token_ =
0112       esConsumes<EcalEBPhase2TPGLinearizationConst, EcalEBPhase2TPGLinearizationConstRcd, edm::Transition::BeginRun>();
0113   theEcalEBTPGAmplWeightIdMap_Token_ =
0114       esConsumes<EcalEBPhase2TPGAmplWeightIdMap, EcalEBPhase2TPGAmplWeightIdMapRcd, edm::Transition::BeginRun>();
0115   theEcalEBTPGTimeWeightIdMap_Token_ =
0116       esConsumes<EcalEBPhase2TPGTimeWeightIdMap, EcalEBPhase2TPGTimeWeightIdMapRcd, edm::Transition::BeginRun>();
0117   theEcalTPGWeightGroup_Token_ = esConsumes<EcalTPGWeightGroup, EcalTPGWeightGroupRcd, edm::Transition::BeginRun>();
0118 
0119   //register your products
0120   produces<EcalEBPhase2TrigPrimDigiCollection>();
0121 }
0122 
0123 void EcalEBTrigPrimPhase2Producer::beginRun(edm::Run const& run, edm::EventSetup const& setup) {
0124   auto const& theGeometry = setup.getData(theGeometryToken_);
0125   auto const& eTTmap = setup.getData(eTTmapToken_);
0126 
0127   algo_ = std::make_unique<EcalEBPhase2TrigPrimAlgo>(&eTTmap, &theGeometry, binOfMaximum_, debug_);
0128 
0129   // get a first version of the records
0130   cacheID_ = this->getRecords(setup);
0131 
0132   nEvent_ = 0;
0133 }
0134 
0135 void EcalEBTrigPrimPhase2Producer::fillDescriptions(edm::ConfigurationDescriptions& descriptions) {
0136   edm::ParameterSetDescription desc;
0137   desc.add<bool>("Debug", false);
0138   desc.add<bool>("Famos", false);
0139   desc.add<int>("BinOfMaximum", 6);  // this needs to be at the same value used for the Phase2 LiteDTU digis !
0140   desc.add<edm::InputTag>("barrelEcalDigis", edm::InputTag("simEcalUnsuppressedDigis"));
0141 }
0142 
0143 unsigned long long EcalEBTrigPrimPhase2Producer::getRecords(edm::EventSetup const& setup) {
0144   // get parameter records for xtals
0145   auto theEcalEBPhase2TPGLinearization_handle = setup.getHandle(theEcalEBPhase2TPGLinearization_Token_);
0146   const EcalEBPhase2TPGLinearizationConst* ecaltpLin = theEcalEBPhase2TPGLinearization_handle.product();
0147   //
0148   edm::ESHandle<EcalLiteDTUPedestalsMap> theEcalTPGPedestals_handle = setup.getHandle(theEcalTPGPedestals_Token_);
0149   const EcalLiteDTUPedestalsMap* ecaltpPed = theEcalTPGPedestals_handle.product();
0150   //
0151   // auto theEcalEBPhase2TPGPedestals_handle = setup.getHandle(theEcalEBPhase2TPGPedestals_Token_);
0152   //const EcalEBPhase2TPGPedestalsMap* ebTPPedestals = theEcalEBPhase2TPGPedestals_handle.product();
0153   //
0154   edm::ESHandle<EcalTPGCrystalStatus> theEcalTPGCrystalStatus_handle = setup.getHandle(theEcalTPGCrystalStatus_Token_);
0155   const EcalTPGCrystalStatus* ecaltpgBadX = theEcalTPGCrystalStatus_handle.product();
0156   //
0157   edm::ESHandle<EcalEBPhase2TPGAmplWeightIdMap> theEcalEBTPGAmplWeightIdMap_handle =
0158       setup.getHandle(theEcalEBTPGAmplWeightIdMap_Token_);
0159   const EcalEBPhase2TPGAmplWeightIdMap* ecaltpgAmplWeightMap = theEcalEBTPGAmplWeightIdMap_handle.product();
0160   //
0161   edm::ESHandle<EcalEBPhase2TPGTimeWeightIdMap> theEcalEBTPGTimeWeightIdMap_handle =
0162       setup.getHandle(theEcalEBTPGTimeWeightIdMap_Token_);
0163   const EcalEBPhase2TPGTimeWeightIdMap* ecaltpgTimeWeightMap = theEcalEBTPGTimeWeightIdMap_handle.product();
0164   //
0165   edm::ESHandle<EcalTPGWeightGroup> theEcalTPGWeightGroup_handle = setup.getHandle(theEcalTPGWeightGroup_Token_);
0166   const EcalTPGWeightGroup* ecaltpgWeightGroup = theEcalTPGWeightGroup_handle.product();
0167   // These commented out lines are for reminder for possible needed implementations
0168   //edm::ESHandle<EcalTPGTowerStatus> theEcalTPGTowerStatus_handle = setup.getHandle(theEcalTPGTowerStatus_Token_);
0169   //const EcalTPGTowerStatus* ecaltpgBadTT = theEcalTPGTowerStatus_handle.product();
0170   //
0171   //edm::ESHandle<EcalTPGSpike> theEcalTPGSpike_handle = setup.getHandle(theEcalTPGSpike_Token_);
0172   //const EcalTPGSpike* ecaltpgSpike = theEcalTPGSpike_handle.product();
0173 
0174   ////////////////
0175   algo_->setPointers(ecaltpPed, ecaltpLin, ecaltpgBadX, ecaltpgAmplWeightMap, ecaltpgTimeWeightMap, ecaltpgWeightGroup);
0176 
0177   return setup.get<EcalEBPhase2TPGLinearizationConstRcd>().cacheIdentifier();
0178   //  return setup.get<EcalLiteDTUPedestalsRcd>().cacheIdentifier();
0179 }
0180 
0181 void EcalEBTrigPrimPhase2Producer::endRun(edm::Run const& run, edm::EventSetup const& setup) { algo_.reset(); }
0182 
0183 EcalEBTrigPrimPhase2Producer::~EcalEBTrigPrimPhase2Producer() {}
0184 
0185 // ------------ method called to produce the data  ------------
0186 void EcalEBTrigPrimPhase2Producer::produce(edm::Event& e, const edm::EventSetup& iSetup) {
0187   nEvent_++;
0188 
0189   // get input collections
0190   edm::Handle<EBDigiCollectionPh2> barrelDigiHandle;
0191 
0192   if (!e.getByToken(tokenEBdigi_, barrelDigiHandle)) {
0193     edm::EDConsumerBase::Labels labels;
0194     labelsForToken(tokenEBdigi_, labels);
0195     edm::LogWarning("EcalTPG") << " Couldnt find Barrel digis " << labels.module << " and label "
0196                                << labels.productInstance << "!!!";
0197   }
0198   const auto* ebdigi = barrelDigiHandle.product();
0199 
0200   if (debug_)
0201     LogDebug("EcalEBTrigPrimPhase2Producer")
0202         << " EcalTPG"
0203         << " =================> Treating event  " << nEvent_ << ", Number of EB digis "
0204         << barrelDigiHandle.product()->size() << std::endl;
0205 
0206   auto pOut = std::make_unique<EcalEBPhase2TrigPrimDigiCollection>();
0207 
0208   // invoke algorithm
0209   algo_->run(ebdigi, *pOut);
0210 
0211   if (debug_) {
0212     LogDebug("EcalEBTrigPrimPhase2Producer")
0213         << "produce"
0214         << " For Barrel  " << pOut->size() << " TP  Digis were produced" << std::endl;
0215   }
0216 
0217   //  debug prints if TP > 0. The number of TP with Et>0 is also used later for a LogInfo
0218   int nonZeroTP = 0;
0219   int nXstal = 0;
0220   for (unsigned int i = 0; i < pOut->size(); ++i) {
0221     nXstal++;
0222     for (int isam = 0; isam < (*pOut)[i].size(); ++isam) {
0223       if ((*pOut)[i][isam].encodedEt() > 0) {
0224         nonZeroTP++;
0225         if (debug_) {
0226           LogDebug("EcalEBTrigPrimPhase2Producer")
0227               << " For xStal n " << nXstal << " xTsal Id " << (((*pOut)[i])).id() << ", TP is " << (*pOut)[i]
0228               << " (*pOut)[i][isam].raw() " << (*pOut)[i][isam].raw() << "  (*pOut)[i][isam].encodedEt() "
0229               << (*pOut)[i][isam].encodedEt() << "  (*pOut)[i][isam].time() " << (*pOut)[i][isam].time() << std::endl;
0230         }
0231       }
0232     }
0233   }
0234 
0235   edm::LogInfo("EcalEBTrigPrimPhase2Producer")
0236       << "EcalTPG"
0237       << "\n =================> For Barrel , " << pOut->size() << " TP  Digis were produced (including zero ones)"
0238       << " Non zero primitives were " << nonZeroTP << std::endl;
0239 
0240   // put result into the Event
0241   e.put(std::move(pOut));
0242 }
0243 
0244 DEFINE_FWK_MODULE(EcalEBTrigPrimPhase2Producer);