CMS 3D CMS Logo

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

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