Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 12:27:56

0001 #include "RecoTBCalo/EcalTBTDCReconstructor/interface/EcalTBH2TDCRecInfoProducer.h"
0002 #include "TBDataFormats/HcalTBObjects/interface/HcalTBTiming.h"
0003 #include "TBDataFormats/HcalTBObjects/interface/HcalTBTriggerData.h"
0004 #include "TBDataFormats/EcalTBObjects/interface/EcalTBTDCRecInfo.h"
0005 #include "DataFormats/Common/interface/EDCollection.h"
0006 #include "DataFormats/Common/interface/Handle.h"
0007 #include "FWCore/Framework/interface/ESHandle.h"
0008 #include "FWCore/Framework/interface/EventSetup.h"
0009 
0010 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0011 
0012 EcalTBH2TDCRecInfoProducer::EcalTBH2TDCRecInfoProducer(edm::ParameterSet const& ps) {
0013   rawInfoCollection_ = ps.getParameter<std::string>("rawInfoCollection");
0014   rawInfoProducer_ = ps.getParameter<std::string>("rawInfoProducer");
0015   triggerDataCollection_ = ps.getParameter<std::string>("triggerDataCollection");
0016   triggerDataProducer_ = ps.getParameter<std::string>("triggerDataProducer");
0017   recInfoCollection_ = ps.getParameter<std::string>("recInfoCollection");
0018 
0019   std::vector<EcalTBH2TDCRecInfoAlgo::EcalTBH2TDCRanges> tdcRanges;
0020 
0021   typedef std::vector<edm::ParameterSet> Parameters;
0022   Parameters ranges = ps.getParameter<Parameters>("tdcZeros");
0023   for (Parameters::iterator itRanges = ranges.begin(); itRanges != ranges.end(); ++itRanges) {
0024     EcalTBH2TDCRecInfoAlgo::EcalTBH2TDCRanges aRange;
0025     aRange.runRanges.first = itRanges->getParameter<int>("startRun");
0026     aRange.runRanges.second = itRanges->getParameter<int>("endRun");
0027     aRange.tdcZero = itRanges->getParameter<double>("tdcZero");
0028     tdcRanges.push_back(aRange);
0029   }
0030 
0031   produces<EcalTBTDCRecInfo>(recInfoCollection_);
0032 
0033   algo_ = new EcalTBH2TDCRecInfoAlgo(tdcRanges);
0034 }
0035 
0036 EcalTBH2TDCRecInfoProducer::~EcalTBH2TDCRecInfoProducer() {
0037   if (algo_)
0038     delete algo_;
0039 }
0040 
0041 void EcalTBH2TDCRecInfoProducer::produce(edm::Event& e, const edm::EventSetup& es) {
0042   int runNumber = e.id().run();
0043   // Get input
0044   edm::Handle<HcalTBTiming> ecalRawTDC;
0045   const HcalTBTiming* ecalTDCRawInfo = nullptr;
0046 
0047   //evt.getByLabel( digiProducer_, digiCollection_, pDigis);
0048   e.getByLabel(rawInfoProducer_, ecalRawTDC);
0049   if (ecalRawTDC.isValid()) {
0050     ecalTDCRawInfo = ecalRawTDC.product();
0051   }
0052 
0053   if (!ecalTDCRawInfo) {
0054     edm::LogError("EcalTBTDCRecInfoError") << "Error! can't get the product " << rawInfoCollection_.c_str();
0055     return;
0056   }
0057 
0058   // Get input
0059   edm::Handle<HcalTBTriggerData> triggerData;
0060   const HcalTBTriggerData* h2TriggerData = nullptr;
0061   //evt.getByLabel( digiProducer_, digiCollection_, pDigis);
0062   e.getByLabel(triggerDataProducer_, triggerData);
0063   if (triggerData.isValid()) {
0064     h2TriggerData = triggerData.product();
0065   }
0066 
0067   if (!h2TriggerData) {
0068     edm::LogError("EcalTBTDCRecInfoError") << "Error! can't get the product " << triggerDataCollection_.c_str();
0069     return;
0070   }
0071 
0072   if (!h2TriggerData->wasBeamTrigger()) {
0073     e.put(std::make_unique<EcalTBTDCRecInfo>(0.5), recInfoCollection_);
0074   } else {
0075     e.put(std::make_unique<EcalTBTDCRecInfo>(algo_->reconstruct(runNumber, *ecalRawTDC)), recInfoCollection_);
0076   }
0077 }