Back to home page

Project CMSSW displayed by LXR

 
 

    


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

0001 
0002 #include "SimCalorimetry/EcalZeroSuppressionProducers/interface/EcalZeroSuppressionProducer.h"
0003 
0004 EcalZeroSuppressionProducer::EcalZeroSuppressionProducer(const edm::ParameterSet &params)
0005     : glbBarrelThreshold_(params.getUntrackedParameter<double>("glbBarrelThreshold", 0.2)),
0006       glbEndcapThreshold_(params.getUntrackedParameter<double>("glbEndcapThreshold", 0.4)),
0007       digiProducer_(params.getParameter<std::string>("digiProducer")),
0008       ebDigiCollection_(params.getParameter<std::string>("EBdigiCollection")),
0009       eeDigiCollection_(params.getParameter<std::string>("EEdigiCollection")),
0010       ebZSdigiCollection_(params.getParameter<std::string>("EBZSdigiCollection")),
0011       eeZSdigiCollection_(params.getParameter<std::string>("EEZSdigiCollection")),
0012       ebToken_(consumes<EBDigiCollection>(edm::InputTag(digiProducer_))),
0013       eeToken_(consumes<EEDigiCollection>(edm::InputTag(digiProducer_))),
0014       pedestalToken_(esConsumes()) {
0015   produces<EBDigiCollection>(ebZSdigiCollection_);
0016   produces<EEDigiCollection>(eeZSdigiCollection_);
0017 }
0018 
0019 EcalZeroSuppressionProducer::~EcalZeroSuppressionProducer() {}
0020 
0021 void EcalZeroSuppressionProducer::produce(edm::Event &event, const edm::EventSetup &eventSetup) {
0022   // Get Inputs
0023 
0024   initCalibrations(eventSetup);
0025 
0026   edm::Handle<EBDigiCollection> pEBDigis;
0027   edm::Handle<EEDigiCollection> pEEDigis;
0028 
0029   const EBDigiCollection *fullBarrelDigis = nullptr;
0030   const EEDigiCollection *fullEndcapDigis = nullptr;
0031 
0032   event.getByToken(ebToken_, pEBDigis);
0033   if (pEBDigis.isValid()) {
0034     fullBarrelDigis = pEBDigis.product();  // get a ptr to the produc
0035     edm::LogInfo("ZeroSuppressionInfo") << "total # fullBarrelDigis: " << fullBarrelDigis->size();
0036   } else {
0037     edm::LogError("ZeroSuppressionError") << "Error! can't get the product " << ebDigiCollection_.c_str();
0038   }
0039 
0040   event.getByToken(eeToken_, pEEDigis);
0041   if (pEEDigis.isValid()) {
0042     fullEndcapDigis = pEEDigis.product();  // get a ptr to the product
0043     edm::LogInfo("ZeroSuppressionInfo") << "total # fullEndcapDigis: " << fullEndcapDigis->size();
0044   } else {
0045     edm::LogError("ZeroSuppressionError") << "Error! can't get the product " << eeDigiCollection_.c_str();
0046   }
0047 
0048   // collection of zero suppressed digis to put in the event
0049 
0050   auto gzsBarrelDigis = std::make_unique<EBDigiCollection>();
0051   auto gzsEndcapDigis = std::make_unique<EEDigiCollection>();
0052 
0053   CaloDigiCollectionSorter sorter(5);
0054 
0055   // Barrel zero suppression
0056 
0057   if (fullBarrelDigis) {
0058     for (EBDigiCollection::const_iterator digiItr = (*fullBarrelDigis).begin(); digiItr != (*fullBarrelDigis).end();
0059          ++digiItr) {
0060       bool isAccepted = theBarrelZeroSuppressor_.accept(*digiItr, glbBarrelThreshold_);
0061       if (isAccepted) {
0062         (*gzsBarrelDigis).push_back(digiItr->id(), digiItr->begin());
0063       }
0064     }
0065     edm::LogInfo("ZeroSuppressionInfo") << "EB Digis: " << gzsBarrelDigis->size();
0066 
0067     // std::vector<EBDataFrame> sortedDigisEB =
0068     // sorter.sortedVector(*gzsBarrelDigis); LogDebug("ZeroSuppressionDump") <<
0069     // "Top 10 EB digis"; for(int i = 0; i < std::min(10,(int)
0070     // sortedDigisEB.size()); ++i)
0071     //  {
0072     //    LogDebug("ZeroSuppressionDump") << sortedDigisEB[i];
0073     //  }
0074   }
0075 
0076   // Endcap zero suppression
0077 
0078   if (fullEndcapDigis) {
0079     for (EEDigiCollection::const_iterator digiItr = (*fullEndcapDigis).begin(); digiItr != (*fullEndcapDigis).end();
0080          ++digiItr) {
0081       bool isAccepted = theEndcapZeroSuppressor_.accept(*digiItr, glbEndcapThreshold_);
0082       if (isAccepted) {
0083         (*gzsEndcapDigis).push_back(digiItr->id(), digiItr->begin());
0084       }
0085     }
0086     edm::LogInfo("ZeroSuppressionInfo") << "EB Digis: " << gzsBarrelDigis->size();
0087 
0088     //    std::vector<EEDataFrame> sortedDigisEE =
0089     //    sorter.sortedVector(*gzsEndcapDigis);
0090     // LogDebug("ZeroSuppressionDump")  << "Top 10 EE digis";
0091     // for(int i = 0; i < std::min(10,(int) sortedDigisEE.size()); ++i)
0092     //  {
0093     //    LogDebug("ZeroSuppressionDump") << sortedDigisEE[i];
0094     //  }
0095   }
0096   // Step D: Put outputs into event
0097   event.put(std::move(gzsBarrelDigis), ebZSdigiCollection_);
0098   event.put(std::move(gzsEndcapDigis), eeZSdigiCollection_);
0099 }
0100 
0101 void EcalZeroSuppressionProducer::initCalibrations(const edm::EventSetup &eventSetup) {
0102   // Pedestals from event setup
0103   const auto &thePedestals = eventSetup.getData(pedestalToken_);
0104 
0105   theBarrelZeroSuppressor_.setPedestals(&thePedestals);
0106   theEndcapZeroSuppressor_.setPedestals(&thePedestals);
0107 }