00001 #include "EventFilter/EcalRawToDigi/plugins/EcalRawToRecHitProducer.h" 00002 #include "RecoLocalCalo/EcalRecAlgos/interface/EcalCleaningAlgo.h" 00003 00004 EcalRawToRecHitProducer::EcalRawToRecHitProducer(const edm::ParameterSet& iConfig) 00005 { 00006 lsourceTag_=iConfig.getParameter<edm::InputTag>("lazyGetterTag"); 00007 sourceTag_=iConfig.getParameter<edm::InputTag>("sourceTag"); 00008 00009 splitOutput_=iConfig.getParameter<bool>("splitOutput"); 00010 if (splitOutput_){ 00011 EBrechitCollection_=iConfig.getParameter<std::string>("EBrechitCollection"); 00012 EErechitCollection_=iConfig.getParameter<std::string>("EErechitCollection"); 00013 produces<EBRecHitCollection>(EBrechitCollection_); 00014 produces<EERecHitCollection>(EErechitCollection_); 00015 LogDebug("EcalRawToRecHit|Producer")<<"ready to create rechits from lazy getter: "<<lsourceTag_ 00016 <<"\n using region ref from: "<<sourceTag_ 00017 <<"\n splitting in two collections" 00018 <<"\n EB instance: "<<EBrechitCollection_ 00019 <<"\n EE instance: "<<EErechitCollection_; 00020 } 00021 else{ 00022 rechitCollection_=iConfig.getParameter<std::string>("rechitCollection"); 00023 produces<EcalRecHitCollection>(rechitCollection_); 00024 LogDebug("EcalRawToRecHit|Producer")<<"ready to create rechits from lazy getter: "<<lsourceTag_ 00025 <<"\n using region ref from: "<<sourceTag_ 00026 <<"\n not splitting the output collection."; 00027 } 00028 00029 cleaningAlgo_=0; 00030 if (iConfig.exists("cleaningConfig")){ 00031 const edm::ParameterSet & cleaning=iConfig.getParameter<edm::ParameterSet>("cleaningConfig"); 00032 if (!cleaning.empty()) 00033 cleaningAlgo_ = new EcalCleaningAlgo(cleaning); 00034 } 00035 } 00036 00037 00038 EcalRawToRecHitProducer::~EcalRawToRecHitProducer() 00039 { 00040 if (cleaningAlgo_) delete cleaningAlgo_; 00041 } 00042 00043 00044 // 00045 // member functions 00046 // 00047 00048 // ------------ method called to produce the data ------------ 00049 void 00050 EcalRawToRecHitProducer::produce(edm::Event& iEvent, const edm::EventSetup& iSetup) 00051 { 00052 using namespace edm; 00053 00054 // MyWatcher watcher("Producer"); 00055 // LogDebug("EcalRawToRecHit|Producer")<<watcher.lap(); 00056 00057 //retrieve a lazygetter 00058 edm::Handle<EcalRecHitLazyGetter> lgetter; 00059 iEvent.getByLabel(lsourceTag_, lgetter); 00060 LogDebug("EcalRawToRecHit|Producer")<<"lazy getter retreived from: "<<lsourceTag_<<(lgetter.failedToGet()?" not valid ":"valid") ; 00061 // <<watcher.lap(); 00062 00063 //retrieve a refgetter 00064 edm::Handle<EcalRecHitRefGetter> rgetter; 00065 iEvent.getByLabel(sourceTag_ ,rgetter); 00066 LogDebug("EcalRawToRecHit|Producer")<<"ref getter retreived from: "<<sourceTag_<<(rgetter.failedToGet()?" not valid ":"valid"); 00067 // <<watcher.lap(); 00068 00069 00070 if (splitOutput_){ 00071 //prepare the output collection 00072 std::auto_ptr<EBRecHitCollection> EBrechits( new EBRecHitCollection ); 00073 std::auto_ptr<EERecHitCollection> EErechits( new EERecHitCollection ); 00074 //loop the refgetter 00075 unsigned int iR=0; 00076 EcalRecHitRefGetter::const_iterator iRegion=rgetter->begin(); 00077 EcalRecHitRefGetter::const_iterator iRegionEnd=rgetter->end(); 00078 for (;iRegion!=iRegionEnd;++iRegion){ 00079 LogDebug("EcalRawToRecHit|Producer")<<"looping over refgetter region: "<<iR; 00080 //<<watcher.lap(); 00081 lgetter->setEvent(iEvent); 00082 std::vector<EcalRecHit>::const_iterator iRecHit=lgetter->begin_record()+iRegion->start(); 00083 std::vector<EcalRecHit>::const_iterator iRecHitEnd =lgetter->begin_record()+iRegion->finish(); 00084 for (;iRecHit!=iRecHitEnd;iRecHit++){ 00085 DetId detid =iRecHit->id(); 00086 //split barrel and endcap 00087 int EcalNum=detid.subdetId(); //1 stands for Barrel, 2 for endcaps 00088 LogDebug("EcalRawToRecHit|Producer")<<"subdetId is: "<<EcalNum; 00089 if (EcalNum==1) EBrechits->push_back(*iRecHit); 00090 else if (EcalNum==2) EErechits->push_back(*iRecHit); 00091 else { 00092 edm::LogError("IncorrectRecHit")<<" a subdetid is not recognized. recHit on :"<< iRecHit->id().rawId() 00093 <<" is lost."; 00094 }//subdetid 00095 }//loop over things in region 00096 LogDebug("EcalRawToRecHit|Producer")<<"looping over refgetter region: "<<iR++<<" done"; 00097 // <<watcher.lap(); 00098 }//loop over regions 00099 00100 LogDebug("EcalRawToRecHit|Producer")<<EBrechits->size()<<" EB recHits to be put with instance: "<<EBrechitCollection_ 00101 <<"\n"<<EErechits->size()<<" EE recHits to be put with instance: "<<EErechitCollection_ ; 00102 // << watcher.lap(); 00103 00104 // cleaning of anomalous signals, aka spikes 00105 // only doable once we have a "global" collection of hits 00106 if (cleaningAlgo_){ 00107 EBrechits->sort(); 00108 EErechits->sort(); 00109 cleaningAlgo_->setFlags(*EBrechits); 00110 cleaningAlgo_->setFlags(*EErechits); 00111 } 00112 00113 iEvent.put(EBrechits, EBrechitCollection_); 00114 iEvent.put(EErechits, EErechitCollection_); 00115 LogDebug("EcalRawToRecHit|Producer")<<"collections uploaded."; 00116 // << watcher.lap(); 00117 } 00118 else{ 00119 //prepare the output collection 00120 std::auto_ptr< EcalRecHitCollection > rechits( new EcalRecHitCollection); 00121 //loop the refgetter 00122 unsigned int iR=0; 00123 EcalRecHitRefGetter::const_iterator iRegion=rgetter->begin(); 00124 EcalRecHitRefGetter::const_iterator iRegionEnd=rgetter->end(); 00125 for (;iRegion!=iRegionEnd;++iRegion){ 00126 LogDebug("EcalRawToRecHit|Producer")<<"looping over refgetter region: "<<iR ; 00127 //<<watcher.lap(); 00128 lgetter->setEvent(iEvent); 00129 std::vector<EcalRecHit>::const_iterator iRecHit=lgetter->begin_record()+iRegion->start(); 00130 std::vector<EcalRecHit>::const_iterator iRecHitEnd=lgetter->begin_record()+iRegion->finish(); 00131 for (;iRecHit!=iRecHitEnd;iRecHit++){ 00132 LogDebug("EcalRawToRecHit|Producer")<<"dereferencing rechit ref."; 00133 DetId detid =iRecHit->id(); 00134 int EcalNum=detid.subdetId(); //1 stands for Barrel, 2 for endcaps 00135 LogDebug("EcalRawToRecHit|Producer")<<"subdetId is: "<<EcalNum; 00136 rechits->push_back(*iRecHit); 00137 }//loop over things in region 00138 LogDebug("EcalRawToRecHit|Producer")<<"looping over refgetter region: "<<iR++<<" done" ; 00139 //<<watcher.lap(); 00140 }//loop over regions 00141 00142 if (cleaningAlgo_){ 00143 rechits->sort(); 00144 cleaningAlgo_->setFlags(*rechits); 00145 } 00146 LogDebug("EcalRawToRecHit|Producer")<<rechits->size()<<" rechits to be put." ; 00147 //<< watcher.lap(); 00148 iEvent.put(rechits,rechitCollection_); 00149 LogDebug("EcalRawToRecHit|Producer")<<"collections uploaded." ; 00150 // << watcher.lap(); 00151 } 00152 00153 } 00154