CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_5_3_4/src/EventFilter/EcalRawToDigi/plugins/EcalRawToRecHitProducer.cc

Go to the documentation of this file.
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       std::vector<EcalRecHit>::const_iterator iRecHit=lgetter->begin_record()+iRegion->start();
00082       std::vector<EcalRecHit>::const_iterator iRecHitEnd =lgetter->begin_record()+iRegion->finish();
00083       for (;iRecHit!=iRecHitEnd;iRecHit++){
00084         DetId detid =iRecHit->id();
00085         //split barrel and endcap
00086         int EcalNum=detid.subdetId(); //1 stands for Barrel, 2 for endcaps
00087         LogDebug("EcalRawToRecHit|Producer")<<"subdetId is: "<<EcalNum;
00088         if (EcalNum==1) EBrechits->push_back(*iRecHit);
00089         else if (EcalNum==2) EErechits->push_back(*iRecHit);
00090         else {
00091           edm::LogError("IncorrectRecHit")<<" a subdetid is not recognized. recHit on :"<< iRecHit->id().rawId() 
00092                                                    <<" is lost.";
00093         }//subdetid
00094       }//loop over things in region
00095       LogDebug("EcalRawToRecHit|Producer")<<"looping over refgetter region: "<<iR++<<" done";
00096 //                                        <<watcher.lap();
00097     }//loop over regions
00098 
00099     LogDebug("EcalRawToRecHit|Producer")<<EBrechits->size()<<" EB recHits to be put with instance: "<<EBrechitCollection_
00100                                         <<"\n"<<EErechits->size()<<" EE recHits to be put with instance: "<<EErechitCollection_ ;
00101 //                                      << watcher.lap();
00102     
00103     // cleaning of anomalous signals, aka spikes
00104     // only doable once we have a "global" collection of hits
00105     if (cleaningAlgo_){
00106       EBrechits->sort();
00107       EErechits->sort();
00108       cleaningAlgo_->setFlags(*EBrechits);
00109       cleaningAlgo_->setFlags(*EErechits);
00110     }
00111 
00112     iEvent.put(EBrechits, EBrechitCollection_);
00113     iEvent.put(EErechits, EErechitCollection_);
00114     LogDebug("EcalRawToRecHit|Producer")<<"collections uploaded.";
00115 //                                      << watcher.lap();
00116   }
00117   else{
00118     //prepare the output collection
00119     std::auto_ptr< EcalRecHitCollection > rechits( new EcalRecHitCollection);
00120     //loop the refgetter
00121     unsigned int iR=0;
00122     EcalRecHitRefGetter::const_iterator iRegion=rgetter->begin();
00123     EcalRecHitRefGetter::const_iterator iRegionEnd=rgetter->end();
00124     for (;iRegion!=iRegionEnd;++iRegion){
00125       LogDebug("EcalRawToRecHit|Producer")<<"looping over refgetter region: "<<iR ;
00126 //<<watcher.lap();
00127       std::vector<EcalRecHit>::const_iterator iRecHit=lgetter->begin_record()+iRegion->start();
00128       std::vector<EcalRecHit>::const_iterator iRecHitEnd=lgetter->begin_record()+iRegion->finish();
00129       for (;iRecHit!=iRecHitEnd;iRecHit++){
00130         LogDebug("EcalRawToRecHit|Producer")<<"dereferencing rechit ref.";
00131         DetId detid =iRecHit->id();
00132         int EcalNum=detid.subdetId(); //1 stands for Barrel, 2 for endcaps
00133         LogDebug("EcalRawToRecHit|Producer")<<"subdetId is: "<<EcalNum;
00134         rechits->push_back(*iRecHit);
00135       }//loop over things in region
00136       LogDebug("EcalRawToRecHit|Producer")<<"looping over refgetter region: "<<iR++<<" done" ;
00137 //<<watcher.lap();
00138     }//loop over regions
00139 
00140     if (cleaningAlgo_){
00141       rechits->sort();
00142       cleaningAlgo_->setFlags(*rechits);
00143     }
00144     LogDebug("EcalRawToRecHit|Producer")<<rechits->size()<<" rechits to be put." ;
00145 //<< watcher.lap();
00146     iEvent.put(rechits,rechitCollection_);
00147     LogDebug("EcalRawToRecHit|Producer")<<"collections uploaded." ;
00148 //                                      << watcher.lap();
00149   }
00150 
00151 }
00152