CMS 3D CMS Logo

CaloRecHitsProducer.cc

Go to the documentation of this file.
00001 
00002 #include "FWCore/ParameterSet/interface/ParameterSet.h"
00003 #include "FWCore/Framework/interface/Event.h"
00004 #include "FWCore/Framework/interface/MakerMacros.h"
00005 #include "FWCore/ServiceRegistry/interface/Service.h"
00006 #include "FWCore/Utilities/interface/RandomNumberGenerator.h"
00007 #include "DataFormats/HcalRecHit/interface/HcalRecHitCollections.h"
00008 #include "DataFormats/EcalRecHit/interface/EcalRecHitCollections.h"
00009 #include "DataFormats/EcalDigi/interface/EcalDigiCollections.h"
00010 #include "DataFormats/HcalDigi/interface/HcalDigiCollections.h"
00011 #include "FastSimulation/CaloRecHitsProducer/interface/CaloRecHitsProducer.h"
00012 #include "FastSimulation/CaloRecHitsProducer/interface/HcalRecHitsMaker.h"
00013 #include "FastSimulation/CaloRecHitsProducer/interface/EcalBarrelRecHitsMaker.h"
00014 #include "FastSimulation/CaloRecHitsProducer/interface/EcalEndcapRecHitsMaker.h"
00015 #include "FastSimulation/CaloRecHitsProducer/interface/EcalPreshowerRecHitsMaker.h"
00016 
00017 // Random engine
00018 #include "FastSimulation/Utilities/interface/RandomEngine.h"
00019 
00020 //#include <iostream>
00021 
00022 CaloRecHitsProducer::CaloRecHitsProducer(edm::ParameterSet const & p)
00023   : HcalRecHitsMaker_(NULL)
00024 {    
00025 
00026   // Initialize the random number generator service
00027   edm::Service<edm::RandomNumberGenerator> rng;
00028   if ( ! rng.isAvailable() ) {
00029     throw cms::Exception("Configuration")
00030       << "CaloRecHitsProducer requires the RandomGeneratorService\n"
00031          "which is not present in the configuration file.\n"
00032          "You must add the service in the configuration file\n"
00033          "or remove the module that requires it";
00034   }
00035 
00036   random = new RandomEngine(&(*rng));
00037 
00038   edm::ParameterSet RecHitsParameters = p.getParameter<edm::ParameterSet>("RecHitsFactory");
00039   edm::ParameterSet CalibParameters = p.getParameter<edm::ParameterSet>("ContFact"); 
00040 
00041   EBrechitCollection_ = RecHitsParameters.getParameter<std::string>("EBrechitCollection");
00042   EErechitCollection_ = RecHitsParameters.getParameter<std::string>("EErechitCollection");
00043   ESrechitCollection_ = RecHitsParameters.getParameter<std::string>("ESrechitCollection");
00044   
00045   doDigis_ = RecHitsParameters.getParameter<bool>("doDigis");
00046   doMiscalib_ = RecHitsParameters.getParameter<bool>("doMiscalib");
00047 
00048   produces<HBHERecHitCollection>();
00049   produces<HORecHitCollection>();
00050   produces<HFRecHitCollection>();
00051   produces<EBRecHitCollection>(EBrechitCollection_);
00052   produces<EERecHitCollection>(EErechitCollection_);
00053   produces<ESRecHitCollection>(ESrechitCollection_);
00054   if(doDigis_)
00055     {
00056       produces<HBHEDigiCollection>();
00057       produces<HODigiCollection>();
00058       produces<HFDigiCollection>();
00059       produces<EBDigiCollection>();
00060       produces<EEDigiCollection>();
00061     }
00062 
00063 
00064   HcalRecHitsMaker_ = 
00065     new HcalRecHitsMaker(RecHitsParameters,p,random);
00066   EcalBarrelRecHitsMaker_ = 
00067     new EcalBarrelRecHitsMaker(RecHitsParameters,CalibParameters,random);
00068   EcalEndcapRecHitsMaker_ = 
00069     new EcalEndcapRecHitsMaker(RecHitsParameters,CalibParameters,random);
00070   EcalPreshowerRecHitsMaker_ = 
00071     new EcalPreshowerRecHitsMaker(RecHitsParameters,random);
00072 }
00073 
00074 CaloRecHitsProducer::~CaloRecHitsProducer() 
00075 { 
00076   if ( random ) { 
00077     delete random;
00078   }
00079 }
00080 
00081 void 
00082 CaloRecHitsProducer::beginRun(edm::Run & run, const edm::EventSetup & es) {
00083   // std::cout << " (Fast)RecHitsProducer initializing " << std::endl;
00084   EcalBarrelRecHitsMaker_->init(es,doDigis_,doMiscalib_);
00085   EcalEndcapRecHitsMaker_->init(es,doDigis_,doMiscalib_);
00086   EcalPreshowerRecHitsMaker_->init(es); 
00087   HcalRecHitsMaker_->init(es,doDigis_,doMiscalib_);
00088 }
00089 
00090 void CaloRecHitsProducer::endJob()
00091 { 
00092   //std::cout << " (Fast)RecHitsProducer terminating " << std::endl; 
00093   if (EcalBarrelRecHitsMaker_) delete EcalBarrelRecHitsMaker_;
00094   if (EcalEndcapRecHitsMaker_) delete EcalEndcapRecHitsMaker_;
00095   if (EcalPreshowerRecHitsMaker_) delete EcalPreshowerRecHitsMaker_;
00096   if (HcalRecHitsMaker_) delete HcalRecHitsMaker_; 
00097 }
00098 
00099 void CaloRecHitsProducer::produce(edm::Event & iEvent, const edm::EventSetup & es)
00100 {
00101 
00102   // create empty outputs for HCAL 
00103   // see RecoLocalCalo/HcalRecProducers/src/HcalSimpleReconstructor.cc
00104   std::auto_ptr<EBRecHitCollection> receb(new EBRecHitCollection);  // ECAL Barrel
00105   std::auto_ptr<EERecHitCollection> recee(new EERecHitCollection);  // ECAL Endcap
00106   std::auto_ptr<ESRecHitCollection> reces(new ESRecHitCollection);  // ECAL pre-shower
00107 
00108   std::auto_ptr<HBHERecHitCollection> rec1(new HBHERecHitCollection); // Barrel+Endcap
00109   std::auto_ptr<HORecHitCollection> rec2(new HORecHitCollection);     // Outer
00110   std::auto_ptr<HFRecHitCollection> rec3(new HFRecHitCollection);     // Forward
00111  
00112   std::auto_ptr<EBDigiCollection> digieb(new EBDigiCollection(1));
00113   std::auto_ptr<EEDigiCollection> digiee(new EEDigiCollection(1));
00114   std::auto_ptr<HBHEDigiCollection> digihbhe(new HBHEDigiCollection);
00115   std::auto_ptr<HODigiCollection> digiho(new HODigiCollection);
00116   std::auto_ptr<HFDigiCollection> digihf(new HFDigiCollection);
00117  
00118 
00119   EcalBarrelRecHitsMaker_->loadEcalBarrelRecHits(iEvent,*receb,*digieb);
00120 
00121   EcalEndcapRecHitsMaker_->loadEcalEndcapRecHits(iEvent,*recee,*digiee);
00122 
00123   EcalPreshowerRecHitsMaker_->loadEcalPreshowerRecHits(iEvent,*reces);
00124 
00125   HcalRecHitsMaker_->loadHcalRecHits(iEvent,*rec1,*rec2,*rec3,*digihbhe,*digiho,*digihf);
00126 
00127   iEvent.put(receb,EBrechitCollection_);
00128   iEvent.put(recee,EErechitCollection_);
00129   iEvent.put(reces,ESrechitCollection_);
00130   iEvent.put(rec1);
00131   iEvent.put(rec2);
00132   iEvent.put(rec3);
00133   if(doDigis_)
00134     {
00135       iEvent.put(digihbhe);
00136       iEvent.put(digiho);
00137       iEvent.put(digihf);
00138       iEvent.put(digieb);
00139       iEvent.put(digiee);
00140     }
00141 }
00142 
00143 DEFINE_FWK_MODULE(CaloRecHitsProducer);

Generated on Tue Jun 9 17:35:02 2009 for CMSSW by  doxygen 1.5.4