00001 #include "RecoTBCalo/EcalTBTDCReconstructor/interface/EcalTBTDCRecInfoProducer.h" 00002 #include "TBDataFormats/EcalTBObjects/interface/EcalTBTDCRawInfo.h" 00003 #include "TBDataFormats/EcalTBObjects/interface/EcalTBTDCRecInfo.h" 00004 #include "DataFormats/Common/interface/EDCollection.h" 00005 #include "DataFormats/Common/interface/Handle.h" 00006 #include "FWCore/Framework/interface/ESHandle.h" 00007 #include "FWCore/Framework/interface/EventSetup.h" 00008 00009 #include "FWCore/MessageLogger/interface/MessageLogger.h" 00010 00011 EcalTBTDCRecInfoProducer::EcalTBTDCRecInfoProducer(edm::ParameterSet const& ps) 00012 { 00013 rawInfoCollection_ = ps.getParameter<std::string>("rawInfoCollection"); 00014 rawInfoProducer_ = ps.getParameter<std::string>("rawInfoProducer"); 00015 eventHeaderCollection_ = ps.getParameter<std::string>("eventHeaderCollection"); 00016 eventHeaderProducer_ = ps.getParameter<std::string>("eventHeaderProducer"); 00017 recInfoCollection_ = ps.getParameter<std::string>("recInfoCollection"); 00018 00019 // std::vector<double> planeShift_def; 00020 // planeShift_def.push_back( -0.333 ); 00021 // planeShift_def.push_back( -0.333 ); 00022 // planeShift_def.push_back( -0.333 ); 00023 // planeShift_def.push_back( -0.333 ); 00024 00025 00026 // std::vector<double> zPosition_def; 00027 // zPosition_def.push_back( -0.333 ); 00028 // zPosition_def.push_back( -0.333 ); 00029 // zPosition_def.push_back( -0.333 ); 00030 // zPosition_def.push_back( -0.333 ); 00031 std::vector<EcalTBTDCRecInfoAlgo::EcalTBTDCRanges> tdcRanges; 00032 00033 typedef std::vector< edm::ParameterSet > Parameters; 00034 Parameters ranges=ps.getParameter<Parameters>("tdcRanges"); 00035 for(Parameters::iterator itRanges = ranges.begin(); itRanges != ranges.end(); ++itRanges) 00036 { 00037 EcalTBTDCRecInfoAlgo::EcalTBTDCRanges aRange; 00038 aRange.runRanges.first = itRanges->getParameter<int>("startRun"); 00039 aRange.runRanges.second = itRanges->getParameter<int>("endRun"); 00040 aRange.tdcMin = itRanges->getParameter< std::vector<double> >("tdcMin"); 00041 aRange.tdcMax = itRanges->getParameter< std::vector<double> >("tdcMax"); 00042 tdcRanges.push_back(aRange); 00043 } 00044 00045 use2004OffsetConvention_ = ps.getUntrackedParameter< bool >("use2004OffsetConvention",false); 00046 00047 produces<EcalTBTDCRecInfo>(recInfoCollection_); 00048 00049 algo_ = new EcalTBTDCRecInfoAlgo(tdcRanges); 00050 } 00051 00052 EcalTBTDCRecInfoProducer::~EcalTBTDCRecInfoProducer() { 00053 if (algo_) 00054 delete algo_; 00055 } 00056 00057 void EcalTBTDCRecInfoProducer::produce(edm::Event& e, const edm::EventSetup& es) 00058 { 00059 // Get input 00060 edm::Handle<EcalTBTDCRawInfo> ecalRawTDC; 00061 const EcalTBTDCRawInfo* ecalTDCRawInfo = 0; 00062 00063 //evt.getByLabel( digiProducer_, digiCollection_, pDigis); 00064 e.getByLabel( rawInfoProducer_, ecalRawTDC); 00065 if (ecalRawTDC.isValid()) { 00066 ecalTDCRawInfo = ecalRawTDC.product(); 00067 } 00068 00069 if (! ecalTDCRawInfo ) 00070 { 00071 edm::LogError("EcalTBTDCRecInfoError") << "Error! can't get the product " << rawInfoCollection_.c_str() ; 00072 return; 00073 } 00074 00075 if ( (*ecalTDCRawInfo).size() < 1 ) 00076 { 00077 edm::LogError("EcalTBTDcRecInfoError") << "Less than one TDC good channel found. Aborting" << rawInfoCollection_.c_str() ; 00078 return; 00079 } 00080 // Get input 00081 edm::Handle<EcalTBEventHeader> tbEventHeader; 00082 const EcalTBEventHeader* ecalEventHeader = 0; 00083 //evt.getByLabel( digiProducer_, digiCollection_, pDigis); 00084 e.getByLabel( eventHeaderProducer_, tbEventHeader); 00085 if (tbEventHeader.isValid()) { 00086 ecalEventHeader = tbEventHeader.product(); 00087 } 00088 00089 if (! ecalEventHeader ) 00090 { 00091 edm::LogError("EcalTBTDCRecInfoError") << "Error! can't get the product " << eventHeaderCollection_.c_str(); 00092 return; 00093 } 00094 00095 // Create empty output 00096 std::auto_ptr<EcalTBTDCRecInfo> recInfo(new EcalTBTDCRecInfo(algo_->reconstruct(*ecalRawTDC,*tbEventHeader,use2004OffsetConvention_))); 00097 00098 e.put(recInfo,recInfoCollection_); 00099 } 00100 00101