Back to home page

Project CMSSW displayed by LXR

 
 

    


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

0001 #include "RecoTBCalo/EcalTBTDCReconstructor/interface/EcalTBTDCRecInfoProducer.h"
0002 #include "TBDataFormats/EcalTBObjects/interface/EcalTBTDCRawInfo.h"
0003 #include "TBDataFormats/EcalTBObjects/interface/EcalTBTDCRecInfo.h"
0004 #include "DataFormats/Common/interface/EDCollection.h"
0005 #include "DataFormats/Common/interface/Handle.h"
0006 #include "FWCore/Framework/interface/ESHandle.h"
0007 #include "FWCore/Framework/interface/EventSetup.h"
0008 
0009 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0010 
0011 EcalTBTDCRecInfoProducer::EcalTBTDCRecInfoProducer(edm::ParameterSet const& ps) {
0012   rawInfoCollection_ = ps.getParameter<std::string>("rawInfoCollection");
0013   rawInfoProducer_ = ps.getParameter<std::string>("rawInfoProducer");
0014   eventHeaderCollection_ = ps.getParameter<std::string>("eventHeaderCollection");
0015   eventHeaderProducer_ = ps.getParameter<std::string>("eventHeaderProducer");
0016   recInfoCollection_ = ps.getParameter<std::string>("recInfoCollection");
0017 
0018   //   std::vector<double> planeShift_def;
0019   //   planeShift_def.push_back( -0.333 );
0020   //   planeShift_def.push_back( -0.333 );
0021   //   planeShift_def.push_back( -0.333 );
0022   //   planeShift_def.push_back( -0.333 );
0023 
0024   //   std::vector<double> zPosition_def;
0025   //   zPosition_def.push_back( -0.333 );
0026   //   zPosition_def.push_back( -0.333 );
0027   //   zPosition_def.push_back( -0.333 );
0028   //   zPosition_def.push_back( -0.333 );
0029   std::vector<EcalTBTDCRecInfoAlgo::EcalTBTDCRanges> tdcRanges;
0030 
0031   typedef std::vector<edm::ParameterSet> Parameters;
0032   Parameters ranges = ps.getParameter<Parameters>("tdcRanges");
0033   for (Parameters::iterator itRanges = ranges.begin(); itRanges != ranges.end(); ++itRanges) {
0034     EcalTBTDCRecInfoAlgo::EcalTBTDCRanges aRange;
0035     aRange.runRanges.first = itRanges->getParameter<int>("startRun");
0036     aRange.runRanges.second = itRanges->getParameter<int>("endRun");
0037     aRange.tdcMin = itRanges->getParameter<std::vector<double> >("tdcMin");
0038     aRange.tdcMax = itRanges->getParameter<std::vector<double> >("tdcMax");
0039     tdcRanges.push_back(aRange);
0040   }
0041 
0042   use2004OffsetConvention_ = ps.getUntrackedParameter<bool>("use2004OffsetConvention", false);
0043 
0044   produces<EcalTBTDCRecInfo>(recInfoCollection_);
0045 
0046   algo_ = new EcalTBTDCRecInfoAlgo(tdcRanges);
0047 }
0048 
0049 EcalTBTDCRecInfoProducer::~EcalTBTDCRecInfoProducer() {
0050   if (algo_)
0051     delete algo_;
0052 }
0053 
0054 void EcalTBTDCRecInfoProducer::produce(edm::Event& e, const edm::EventSetup& es) {
0055   // Get input
0056   edm::Handle<EcalTBTDCRawInfo> ecalRawTDC;
0057   const EcalTBTDCRawInfo* ecalTDCRawInfo = nullptr;
0058 
0059   //evt.getByLabel( digiProducer_, digiCollection_, pDigis);
0060   e.getByLabel(rawInfoProducer_, ecalRawTDC);
0061   if (ecalRawTDC.isValid()) {
0062     ecalTDCRawInfo = ecalRawTDC.product();
0063   }
0064 
0065   if (!ecalTDCRawInfo) {
0066     edm::LogError("EcalTBTDCRecInfoError") << "Error! can't get the product " << rawInfoCollection_.c_str();
0067     return;
0068   }
0069 
0070   if ((*ecalTDCRawInfo).size() < 1) {
0071     edm::LogError("EcalTBTDcRecInfoError")
0072         << "Less than one TDC good channel found. Aborting" << rawInfoCollection_.c_str();
0073     return;
0074   }
0075   // Get input
0076   edm::Handle<EcalTBEventHeader> tbEventHeader;
0077   const EcalTBEventHeader* ecalEventHeader = nullptr;
0078   //evt.getByLabel( digiProducer_, digiCollection_, pDigis);
0079   e.getByLabel(eventHeaderProducer_, tbEventHeader);
0080   if (tbEventHeader.isValid()) {
0081     ecalEventHeader = tbEventHeader.product();
0082   }
0083 
0084   if (!ecalEventHeader) {
0085     edm::LogError("EcalTBTDCRecInfoError") << "Error! can't get the product " << eventHeaderCollection_.c_str();
0086     return;
0087   }
0088 
0089   // Create empty output
0090 
0091   e.put(std::make_unique<EcalTBTDCRecInfo>(algo_->reconstruct(*ecalRawTDC, *tbEventHeader, use2004OffsetConvention_)),
0092         recInfoCollection_);
0093 }