CMS 3D CMS Logo

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: "<<sourceTag_
00015                                         <<"\n "<<((global_)?" global":"regional")<<" RAW->RecHit"
00016                                         <<"\n splitting in two collections"
00017                                         <<"\n EB instance: "<<EBrechitCollection_
00018                                         <<"\n EE instance: "<<EErechitCollection_;
00019   }
00020   else{
00021     produces<EcalRecHitCollection>();
00022     LogDebug("EcalRawToRecHit|Producer")<<"ready to create rechits from lazy getter: "<<sourceTag_
00023                                         <<"\n "<<((global_)?" global":"regional")<<" RAW->RecHit";
00024   }
00025 }
00026 
00027 
00028 EcalRawToRecHitProducer::~EcalRawToRecHitProducer()
00029 {
00030 }
00031 
00032 
00033 //
00034 // member functions
00035 //
00036 
00037 // ------------ method called to produce the data  ------------
00038 void
00039 EcalRawToRecHitProducer::produce(edm::Event& iEvent, const edm::EventSetup& iSetup)
00040 {
00041   using namespace edm;
00042 
00043   MyWatcher watcher("Producer");
00044   LogDebug("EcalRawToRecHit|Producer")<<watcher.lap();
00045 
00046   //retrieve a lazygetter
00047   edm::Handle<EcalRecHitLazyGetter> lgetter;
00048   iEvent.getByLabel(lsourceTag_, lgetter);
00049   LogDebug("EcalRawToRecHit|Producer")<<"lazy getter retreived."
00050                                       <<watcher.lap();
00051   
00052   //retrieve a refgetter
00053   edm::Handle<EcalRecHitRefGetter> rgetter;
00054   iEvent.getByLabel(sourceTag_ ,rgetter);
00055   LogDebug("EcalRawToRecHit|Producer")<<"ref getter retreived."
00056                                       <<watcher.lap();
00057 
00058  
00059   if (splitOutput_){
00060     //prepare the output collection
00061     std::auto_ptr<EBRecHitCollection> EBrechits( new EBRecHitCollection );
00062     std::auto_ptr<EERecHitCollection> EErechits( new EERecHitCollection );
00063     //loop the refgetter
00064     uint iR=0;
00065     EcalRecHitRefGetter::const_iterator iRegion=rgetter->begin();
00066     EcalRecHitRefGetter::const_iterator iRegionEnd=rgetter->end();
00067     for (;iRegion!=iRegionEnd;++iRegion){
00068       LogDebug("EcalRawToRecHit|Producer")<<"looping over refgetter region: "<<iR<<watcher.lap();
00069       std::vector<EcalRecHit>::const_iterator iRecHit=lgetter->begin_record()+iRegion->start();
00070       std::vector<EcalRecHit>::const_iterator iRecHitEnd =lgetter->begin_record()+iRegion->finish();
00071       for (;iRecHit!=iRecHitEnd;iRecHit++){
00072         DetId detid =iRecHit->id();
00073         //split barrel and endcap
00074         int EcalNum=detid.subdetId(); //1 stands for Barrel, 2 for endcaps
00075         LogDebug("EcalRawToRecHit|Producer")<<"subdetId is: "<<EcalNum;
00076         if (EcalNum==1) EBrechits->push_back(*iRecHit);
00077         else if (EcalNum==2) EErechits->push_back(*iRecHit);
00078         else {
00079           edm::LogError("EcalRawToRecHit|Producer")<<" a subdetid is not recognized. recHit on :"<< iRecHit->id().rawId() 
00080                                                    <<" is lost.";
00081         }//subdetid
00082       }//loop over things in region
00083       LogDebug("EcalRawToRecHit|Producer")<<"looping over refgetter region: "<<iR++<<" done"
00084                                           <<watcher.lap();
00085     }//loop over regions
00086 
00087     LogDebug("EcalRawToRecHit|Producer")<<EBrechits->size()<<" EB recHits to be put with instance: "<<EBrechitCollection_
00088                                         <<"\n"<<EErechits->size()<<" EE recHits to be put with instance: "<<EErechitCollection_
00089                                         << watcher.lap();
00090     iEvent.put(EBrechits, EBrechitCollection_);
00091     iEvent.put(EErechits, EErechitCollection_);
00092     LogDebug("EcalRawToRecHit|Producer")<<"collections uploaded."
00093                                         << watcher.lap();
00094   }
00095   else{
00096     //prepare the output collection
00097     std::auto_ptr< EcalRecHitCollection > rechits( new EcalRecHitCollection);
00098     //loop the refgetter
00099     EcalRecHitRefGetter::const_iterator iRegion=rgetter->begin();
00100     EcalRecHitRefGetter::const_iterator iRegionEnd=rgetter->end();
00101     for (;iRegion!=iRegionEnd;++iRegion){
00102       std::vector<EcalRecHit>::const_iterator iRecHit=lgetter->begin_record()+iRegion->start();
00103       std::vector<EcalRecHit>::const_iterator iRecHitEnd=lgetter->begin_record()+iRegion->finish();
00104       for (;iRecHit!=iRecHitEnd;iRecHit++){
00105         rechits->push_back(*iRecHit);
00106       }//loop over things in region
00107     }//loop over regions
00108     LogDebug("EcalRawToRecHit|Producer")<<rechits->size()<<" rechits to be put."
00109                                         << watcher.lap();
00110     iEvent.put(rechits);
00111     LogDebug("EcalRawToRecHit|Producer")<<"collections uploaded."
00112                                         << watcher.lap();
00113   }
00114 
00115 }
00116 
00117 // ------------ method called once each job just before starting event loop  ------------
00118 void 
00119 EcalRawToRecHitProducer::beginJob(const edm::EventSetup&)
00120 {
00121 }
00122 
00123 // ------------ method called once each job just after ending the event loop  ------------
00124 void 
00125 EcalRawToRecHitProducer::endJob() {
00126 }

Generated on Tue Jun 9 17:34:32 2009 for CMSSW by  doxygen 1.5.4