CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_5_3_1/src/FastSimulation/CaloRecHitsProducer/src/CaloRecHitsProducer.cc

Go to the documentation of this file.
00001 #include "FWCore/ParameterSet/interface/ParameterSet.h"
00002 #include "FWCore/Framework/interface/Event.h"
00003 #include "FWCore/Framework/interface/MakerMacros.h"
00004 #include "FWCore/ServiceRegistry/interface/Service.h"
00005 #include "FWCore/Utilities/interface/RandomNumberGenerator.h"
00006 #include "DataFormats/HcalRecHit/interface/HcalRecHitCollections.h"
00007 #include "DataFormats/EcalRecHit/interface/EcalRecHitCollections.h"
00008 #include "DataFormats/EcalDigi/interface/EcalDigiCollections.h"
00009 #include "DataFormats/HcalDigi/interface/HcalDigiCollections.h"
00010 #include "FastSimulation/CaloRecHitsProducer/interface/CaloRecHitsProducer.h"
00011 #include "FastSimulation/CaloRecHitsProducer/interface/HcalRecHitsMaker.h"
00012 #include "FastSimulation/CaloRecHitsProducer/interface/EcalBarrelRecHitsMaker.h"
00013 #include "FastSimulation/CaloRecHitsProducer/interface/EcalEndcapRecHitsMaker.h"
00014 #include "FastSimulation/CaloRecHitsProducer/interface/EcalPreshowerRecHitsMaker.h"
00015 
00016 // Random engine
00017 #include "FastSimulation/Utilities/interface/RandomEngine.h"
00018 
00019 //#include <iostream>
00020 
00021 CaloRecHitsProducer::CaloRecHitsProducer(edm::ParameterSet const & p)
00022   : EcalPreshowerRecHitsMaker_(NULL),EcalBarrelRecHitsMaker_(NULL),  EcalEndcapRecHitsMaker_(NULL), HcalRecHitsMaker_(NULL)
00023 {    
00024 
00025   // Initialize the random number generator service
00026   edm::Service<edm::RandomNumberGenerator> rng;
00027   if ( ! rng.isAvailable() ) {
00028     throw cms::Exception("Configuration")
00029       << "CaloRecHitsProducer requires the RandomGeneratorService\n"
00030          "which is not present in the configuration file.\n"
00031          "You must add the service in the configuration file\n"
00032          "or remove the module that requires it";
00033   }
00034   random = new RandomEngine(&(*rng));
00035   theInputRecHitCollectionTypes = p.getParameter<std::vector<unsigned> >("InputRecHitCollectionTypes");
00036   theOutputRecHitCollections = p.getParameter<std::vector<std::string> >("OutputRecHitCollections");
00037   doDigis_ = p.getParameter<bool>("doDigis");
00038   doMiscalib_ = p.getParameter<bool>("doMiscalib");  
00039   edm::ParameterSet RecHitsParameters = p.getParameter<edm::ParameterSet>("RecHitsFactory");
00040     
00041   for ( unsigned input=0; input<theInputRecHitCollectionTypes.size(); ++input ) { 
00042 
00043     switch ( theInputRecHitCollectionTypes[input] ) { 
00044       
00045     case 1: 
00046       {
00047         //Preshower
00048         if (theOutputRecHitCollections.size()&&theOutputRecHitCollections[input].size()) 
00049           produces<ESRecHitCollection>(theOutputRecHitCollections[input]);
00050         else
00051           produces<ESRecHitCollection>();
00052 
00053         if (doDigis_) 
00054           std::cout << " The digitization of the preshower is not implemented " << std::endl;
00055         
00056         EcalPreshowerRecHitsMaker_ =  new EcalPreshowerRecHitsMaker(RecHitsParameters,random);  
00057       }
00058       break;
00059       
00060     case 2:
00061       { 
00062         //Ecal Barrel 
00063         if (theOutputRecHitCollections.size()&&theOutputRecHitCollections[input].size()) 
00064           produces<EBRecHitCollection>(theOutputRecHitCollections[input]);
00065         else
00066           produces<EBRecHitCollection>();
00067         
00068         if (doDigis_)  produces<EBDigiCollection>();
00069         EcalBarrelRecHitsMaker_ =  new EcalBarrelRecHitsMaker(RecHitsParameters,random);
00070       }
00071       break;
00072       
00073     case 3:
00074       { 
00075         //EcalEndcap
00076         if (theOutputRecHitCollections.size()&&theOutputRecHitCollections[input].size()) 
00077           produces<EERecHitCollection>(theOutputRecHitCollections[input]);
00078         else
00079           produces<EERecHitCollection>();
00080         if (doDigis_) produces<EEDigiCollection>();
00081         EcalEndcapRecHitsMaker_ =  new EcalEndcapRecHitsMaker(RecHitsParameters,random);
00082       }
00083       break;
00084       
00085     case 4:
00086       { 
00087         //HBHE
00088         if (theOutputRecHitCollections.size()&&theOutputRecHitCollections[input].size()) 
00089             produces<HBHERecHitCollection>(theOutputRecHitCollections[input]);
00090         else
00091             produces<HBHERecHitCollection>();
00092         
00093         if (doDigis_) produces<HBHEDigiCollection>();
00094         HcalRecHitsMaker_ =  new HcalRecHitsMaker(RecHitsParameters,4,random);
00095       }
00096       break;
00097       
00098     case 5:
00099       { 
00100         //HO
00101         if (theOutputRecHitCollections.size()&&theOutputRecHitCollections[input].size()) 
00102           produces<HORecHitCollection>(theOutputRecHitCollections[input]);
00103         else
00104           produces<HORecHitCollection>();
00105 
00106         if (doDigis_)  produces<HODigiCollection>();
00107 
00108         HcalRecHitsMaker_ =  new HcalRecHitsMaker(RecHitsParameters,5,random);
00109       }
00110       break;
00111       
00112     case 6:
00113       { 
00114         //HF
00115         if (theOutputRecHitCollections.size()&&theOutputRecHitCollections[input].size()) 
00116           produces<HFRecHitCollection>(theOutputRecHitCollections[input]);
00117         else
00118           produces<HFRecHitCollection>();       
00119         if(doDigis_)   produces<HFDigiCollection>();
00120 
00121         HcalRecHitsMaker_ =  new HcalRecHitsMaker(RecHitsParameters,6,random);
00122       }
00123       break;
00124       
00125     default:
00126       // Should not happen
00127       break;
00128       
00129     }
00130     
00131   }
00132  
00133 }
00134 
00135 CaloRecHitsProducer::~CaloRecHitsProducer() 
00136 { 
00137   if ( random ) { 
00138     delete random;
00139   }
00140 }
00141 
00142 void 
00143 CaloRecHitsProducer::beginRun(edm::Run & run, const edm::EventSetup & es) {
00144 
00145   for ( unsigned input=0; input<theInputRecHitCollectionTypes.size(); ++input ) { 
00146     switch ( theInputRecHitCollectionTypes[input] ) {       
00147     case 1: 
00148       {
00149         // preshower
00150         EcalPreshowerRecHitsMaker_->init(es);   
00151       }
00152       break;
00153     case 2:
00154       {
00155         // ecal barrel
00156         EcalBarrelRecHitsMaker_->init(es,doDigis_,doMiscalib_);
00157       }
00158       break;
00159     case 3:
00160       {
00161         // ecal endcap
00162         EcalEndcapRecHitsMaker_->init(es,doDigis_,doMiscalib_);
00163       }
00164       break;
00165     case 4:
00166     case 5:
00167     case 6:
00168       {
00169         HcalRecHitsMaker_->init(es,doDigis_,doMiscalib_);
00170       }
00171       break;
00172     default:
00173       break;
00174     }
00175   }
00176 }
00177 
00178 void CaloRecHitsProducer::endJob()
00179 { 
00180   //std::cout << " (Fast)RecHitsProducer terminating " << std::endl; 
00181   if (EcalBarrelRecHitsMaker_) delete EcalBarrelRecHitsMaker_;
00182   if (EcalEndcapRecHitsMaker_) delete EcalEndcapRecHitsMaker_;
00183   if (EcalPreshowerRecHitsMaker_) delete EcalPreshowerRecHitsMaker_;
00184   if (HcalRecHitsMaker_) delete HcalRecHitsMaker_; 
00185 }
00186 
00187 void CaloRecHitsProducer::produce(edm::Event & iEvent, const edm::EventSetup & es)
00188 {
00189 
00190   // create empty outputs for HCAL 
00191   // see RecoLocalCalo/HcalRecProducers/src/HcalSimpleReconstructor.cc
00192   for ( unsigned input=0; input<theInputRecHitCollectionTypes.size(); ++input ) { 
00193     switch ( theInputRecHitCollectionTypes[input] ) {       
00194     case 1: 
00195       {
00196         // preshower
00197         std::auto_ptr<ESRecHitCollection> reces(new ESRecHitCollection);  // ECAL pre-shower
00198         EcalPreshowerRecHitsMaker_->loadEcalPreshowerRecHits(iEvent,*reces);
00199         if ( theOutputRecHitCollections.size()&& theOutputRecHitCollections[input].size()) 
00200           iEvent.put(reces,theOutputRecHitCollections[input]);
00201         else
00202           iEvent.put(reces);
00203         break;
00204       }
00205 
00206     case 2:
00207       {
00208         // ecal barrel
00209         std::auto_ptr<EBRecHitCollection> receb(new EBRecHitCollection);  // ECAL Barrel
00210         std::auto_ptr<EBDigiCollection> digieb(new EBDigiCollection(1));
00211         EcalBarrelRecHitsMaker_->loadEcalBarrelRecHits(iEvent,*receb,*digieb);
00212         //      std::cout << " ECALBarrel " << receb->size() << std::endl;
00213         if ( theOutputRecHitCollections.size()&&theOutputRecHitCollections[input].size())
00214           iEvent.put(receb,theOutputRecHitCollections[input]);
00215         else
00216           iEvent.put(receb);
00217 
00218         if(doDigis_)
00219           iEvent.put(digieb);     
00220       }
00221       break;
00222     case 3:
00223       {
00224         // ecal endcap
00225         std::auto_ptr<EERecHitCollection> recee(new EERecHitCollection);  // ECAL Endcap
00226         std::auto_ptr<EEDigiCollection> digiee(new EEDigiCollection(1));
00227         EcalEndcapRecHitsMaker_->loadEcalEndcapRecHits(iEvent,*recee,*digiee);
00228         //      std::cout << " ECALEndcap " << recee->size() << std::endl;
00229         if ( theOutputRecHitCollections.size()&& theOutputRecHitCollections[input].size())
00230           iEvent.put(recee,theOutputRecHitCollections[input]);
00231         else
00232           iEvent.put(recee);
00233 
00234         if(doDigis_)
00235           iEvent.put(digiee);
00236       }
00237       break;
00238     case 4:
00239       {
00240         // hbhe
00241         std::auto_ptr<HBHERecHitCollection> rec1(new HBHERecHitCollection); // Barrel+Endcap
00242         std::auto_ptr<HBHEDigiCollection> digihbhe(new HBHEDigiCollection);
00243         HcalRecHitsMaker_->loadHcalRecHits(iEvent,*rec1,*digihbhe);
00244         if ( theOutputRecHitCollections.size()&& theOutputRecHitCollections[input].size())                  
00245           iEvent.put(rec1,theOutputRecHitCollections[input]);
00246         else
00247           iEvent.put(rec1);
00248 
00249         if(doDigis_)
00250           iEvent.put(digihbhe);
00251       }
00252       break;
00253     case 5:
00254       {
00255         //ho
00256         std::auto_ptr<HORecHitCollection> rec2(new HORecHitCollection);     // Outer
00257         std::auto_ptr<HODigiCollection> digiho(new HODigiCollection);
00258 
00259         HcalRecHitsMaker_->loadHcalRecHits(iEvent,*rec2,*digiho);
00260         if(theOutputRecHitCollections.size()&& theOutputRecHitCollections[input].size())          
00261           iEvent.put(rec2,theOutputRecHitCollections[input]);
00262         else
00263           iEvent.put(rec2);
00264         if(doDigis_)
00265           iEvent.put(digiho);
00266       }
00267       break;
00268     case 6:
00269       {
00270         //hf 
00271         std::auto_ptr<HFRecHitCollection> rec3(new HFRecHitCollection);     // Forward
00272         std::auto_ptr<HFDigiCollection> digihf(new HFDigiCollection);
00273         HcalRecHitsMaker_->loadHcalRecHits(iEvent,*rec3,*digihf);
00274         if(theOutputRecHitCollections.size()&& theOutputRecHitCollections[input].size())
00275           iEvent.put(rec3,theOutputRecHitCollections[input]);
00276         else
00277           iEvent.put(rec3);
00278         if(doDigis_)
00279           iEvent.put(digihf);     
00280       }
00281       break;
00282     default:
00283       break;
00284     }
00285   }
00286 }
00287 
00288 DEFINE_FWK_MODULE(CaloRecHitsProducer);