CMS 3D CMS Logo

/afs/cern.ch/work/a/aaltunda/public/www/CMSSW_5_3_13_patch3/src/RecoEgamma/EgammaHLTProducers/src/EcalRecHitsMerger.cc

Go to the documentation of this file.
00001 
00002 //#include <FWCore/Framework/interface/Handle.h>
00003 #include <FWCore/Framework/interface/Event.h>
00004 #include <FWCore/Framework/interface/EventSetup.h>
00005 #include <FWCore/Framework/interface/ESHandle.h>
00006 
00007 #include "DataFormats/EcalRecHit/interface/EcalRecHitCollections.h"
00008 #include "RecoEgamma/EgammaHLTProducers/interface/EcalRecHitsMerger.h"
00009 
00010 #include "FWCore/Utilities/interface/Exception.h"
00011 
00012 
00013 using namespace edm;
00014 using namespace std;
00015 
00016 
00017 EcalRecHitsMerger::EcalRecHitsMerger(const edm::ParameterSet& pset) {
00018 
00019  debug_ = pset.getUntrackedParameter<bool>("debug");
00020 
00021  EgammaSourceEB_ = pset.getUntrackedParameter<edm::InputTag>("EgammaSource_EB");
00022  MuonsSourceEB_  = pset.getUntrackedParameter<edm::InputTag>("MuonsSource_EB");
00023  TausSourceEB_  = pset.getUntrackedParameter<edm::InputTag>("TausSource_EB");
00024  JetsSourceEB_   = pset.getUntrackedParameter<edm::InputTag>("JetsSource_EB");
00025  RestSourceEB_   = pset.getUntrackedParameter<edm::InputTag>("RestSource_EB");
00026  Pi0SourceEB_   = pset.getUntrackedParameter<edm::InputTag>("Pi0Source_EB",edm::InputTag("dummyPi0"));
00027 
00028  EgammaSourceEE_ = pset.getUntrackedParameter<edm::InputTag>("EgammaSource_EE");
00029  MuonsSourceEE_  = pset.getUntrackedParameter<edm::InputTag>("MuonsSource_EE");
00030  TausSourceEE_  = pset.getUntrackedParameter<edm::InputTag>("TausSource_EE");
00031  JetsSourceEE_   = pset.getUntrackedParameter<edm::InputTag>("JetsSource_EE");
00032  RestSourceEE_   = pset.getUntrackedParameter<edm::InputTag>("RestSource_EE");
00033  Pi0SourceEE_   = pset.getUntrackedParameter<edm::InputTag>("Pi0Source_EE",edm::InputTag("dummyPi0"));
00034 
00035  OutputLabelEB_ = pset.getUntrackedParameter<std::string>("OutputLabel_EB");
00036  OutputLabelEE_ = pset.getUntrackedParameter<std::string>("OutputLabel_EE");
00037 
00038  InputRecHitEB_ = pset.getUntrackedParameter<std::string>("EcalRecHitCollectionEB");
00039  InputRecHitEE_ = pset.getUntrackedParameter<std::string>("EcalRecHitCollectionEE");
00040 
00041  produces<EcalRecHitCollection>(OutputLabelEB_);
00042  produces<EcalRecHitCollection>(OutputLabelEE_);
00043 
00044 }
00045 
00046 
00047 
00048 EcalRecHitsMerger::~EcalRecHitsMerger() {
00049 }
00050 
00051 
00052 void EcalRecHitsMerger::beginJob(){
00053 }
00054 
00055 void EcalRecHitsMerger::endJob(){
00056 }
00057 
00058 void EcalRecHitsMerger::produce(edm::Event & e, const edm::EventSetup& iSetup){
00059 
00060  if (debug_) std::cout << " EcalRecHitMerger : Run " << e.id().run() << " Event " << e.id().event() << std::endl;
00061 
00062  std::vector< edm::Handle<EcalRecHitCollection> > EcalRecHits_done;
00063  e.getManyByType(EcalRecHits_done);
00064 
00065  std::auto_ptr<EcalRecHitCollection> EBMergedRecHits(new EcalRecHitCollection);
00066  std::auto_ptr<EcalRecHitCollection> EEMergedRecHits(new EcalRecHitCollection);
00067 
00068  unsigned int nColl = EcalRecHits_done.size();
00069 
00070  int nEB = 0;
00071  int nEE = 0;
00072 
00073 
00074  for (unsigned int i=0; i < nColl; i++) {
00075 
00076    std::string instance = EcalRecHits_done[i].provenance()->productInstanceName();
00077    std::string module_label = EcalRecHits_done[i].provenance()->moduleLabel();
00078 
00079    if ( module_label != EgammaSourceEB_.label() && 
00080         module_label != MuonsSourceEB_.label() &&
00081         module_label != JetsSourceEB_.label() &&
00082         module_label != TausSourceEB_.label() &&
00083         module_label != RestSourceEB_.label() &&
00084         module_label != Pi0SourceEB_.label() ) continue;
00085 
00086    if (instance == InputRecHitEB_)  {
00087         nEB += EcalRecHits_done[i] -> size();
00088    }
00089    else if (instance == InputRecHitEE_) {
00090         nEE += EcalRecHits_done[i] -> size();
00091    }
00092 
00093  }
00094 
00095  EBMergedRecHits -> reserve(nEB);
00096  EEMergedRecHits -> reserve(nEE);
00097  if (debug_) std::cout << " Number of EB Rechits to merge  = " << nEB << std::endl;
00098  if (debug_) std::cout << " Number of EE Rechits to merge  = " << nEE << std::endl;
00099 
00100  for (unsigned int i=0; i < nColl; i++) {
00101    std::string instance = EcalRecHits_done[i].provenance()->productInstanceName(); 
00102 
00103    std::string module_label = EcalRecHits_done[i].provenance()->moduleLabel();
00104    if ( module_label != EgammaSourceEB_.label() && 
00105         module_label != MuonsSourceEB_.label() &&
00106         module_label != JetsSourceEB_.label() &&
00107         module_label != TausSourceEB_.label() &&
00108         module_label != RestSourceEB_.label() &&
00109         module_label != Pi0SourceEB_.label() ) continue;
00110 
00111     if (instance == InputRecHitEB_) {
00112         for (EcalRecHitCollection::const_iterator it=EcalRecHits_done[i]->begin(); it !=EcalRecHits_done[i]->end(); it++) {
00113                 EBMergedRecHits -> push_back(*it);
00114         }
00115    }
00116    else if (instance == InputRecHitEE_) {
00117         for (EcalRecHitCollection::const_iterator it=EcalRecHits_done[i]->begin(); it !=EcalRecHits_done[i]->end(); it++) {
00118                 EEMergedRecHits -> push_back(*it);
00119         }
00120    }
00121 
00122  }
00123 
00124 
00125  // std::cout << " avant le put " << std::endl;
00126  e.put(EBMergedRecHits,OutputLabelEB_);
00127  e.put(EEMergedRecHits,OutputLabelEE_);
00128  // std::cout << " apres le put " << std::endl;
00129 
00130 }
00131