CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_5_3_1/src/Validation/HcalRecHits/src/NoiseRates.cc

Go to the documentation of this file.
00001 //
00002 // NoiseRates.cc
00003 //
00004 //   description: Calculation for single particle response corrections
00005 //
00006 //   author: J.P. Chou, Brown
00007 //
00008 //
00009 
00010 #include "Validation/HcalRecHits/interface/NoiseRates.h"
00011 #include "DataFormats/METReco/interface/HcalNoiseRBX.h"
00012 #include "FWCore/Utilities/interface/EDMException.h"
00013 
00014 //
00015 // constructors and destructor
00016 //
00017 
00018 NoiseRates::NoiseRates(const edm::ParameterSet& iConfig)
00019 {
00020 
00021   // DQM ROOT output
00022   outputFile_ = iConfig.getUntrackedParameter<std::string>("outputFile","myfile.root");
00023 
00024   dbe_ = 0;
00025   // get hold of back-end interface
00026   dbe_ = edm::Service<DQMStore>().operator->();
00027    
00028   Char_t histo[100];
00029 
00030   if ( dbe_ ) {
00031     dbe_->setCurrentFolder("NoiseRatesV/NoiseRatesTask");
00032   }
00033 
00034   // set parameters
00035   rbxCollName_   = iConfig.getUntrackedParameter<edm::InputTag>("rbxCollName");
00036   minRBXEnergy_  = iConfig.getUntrackedParameter<double>("minRBXEnergy");
00037   minHitEnergy_  = iConfig.getUntrackedParameter<double>("minHitEnergy");
00038 
00039   useAllHistos_  = iConfig.getUntrackedParameter<bool>("useAllHistos", false);
00040 
00041   // book histograms
00042 
00043   //Lumi block is not drawn; the rest are
00044   if (useAllHistos_){
00045     sprintf  (histo, "hLumiBlockCount" );
00046     hLumiBlockCount_ = dbe_->book1D(histo, histo, 1, -0.5, 0.5);
00047   }
00048   
00049   sprintf  (histo, "hRBXEnergy" );
00050   hRBXEnergy_ = dbe_->book1D(histo, histo, 300, 0, 3000);
00051 
00052   sprintf  (histo, "hRBXEnergyType1" );
00053   hRBXEnergyType1_ = dbe_->book1D(histo, histo, 300, 0, 3000);
00054 
00055   sprintf  (histo, "hRBXEnergyType2" );
00056   hRBXEnergyType2_ = dbe_->book1D(histo, histo, 300, 0, 3000);
00057 
00058   sprintf  (histo, "hRBXEnergyType3" );
00059   hRBXEnergyType3_ = dbe_->book1D(histo, histo, 300, 0, 3000);
00060 
00061   sprintf  (histo, "hRBXNHits" );
00062   hRBXNHits_ = dbe_->book1D(histo, histo, 73,-0.5,72.5);
00063 
00064 }
00065   
00066   
00067 NoiseRates::~NoiseRates()
00068 {
00069 }
00070   
00071   
00072 //
00073 // member functions
00074 //
00075   
00076 // ------------ method called to for each event  ------------
00077 void
00078 NoiseRates::analyze(const edm::Event& iEvent, const edm::EventSetup& evSetup)
00079 {
00080 
00081   // get the lumi section
00082   int lumiSection = iEvent.luminosityBlock();
00083   lumiCountMap_[lumiSection]++;
00084 
00085   // get the RBX Noise collection
00086   edm::Handle<reco::HcalNoiseRBXCollection> handle;
00087   iEvent.getByLabel(rbxCollName_,handle);
00088   if(!handle.isValid()) {
00089     throw edm::Exception(edm::errors::ProductNotFound)
00090       << " could not find HcalNoiseRBXCollection named " << rbxCollName_ << ".\n";
00091     return;
00092   }
00093 
00094   // loop over the RBXs and fill the histograms
00095   for(reco::HcalNoiseRBXCollection::const_iterator it=handle->begin(); it!=handle->end(); ++it) {
00096     const reco::HcalNoiseRBX &rbx=(*it);
00097 
00098     double energy = rbx.recHitEnergy(minHitEnergy_);
00099 
00100     int nhits = rbx.numRecHits(minHitEnergy_);
00101 
00102     if(energy < minRBXEnergy_) continue;
00103 
00104     hRBXEnergy_->Fill(energy);
00105     
00106     if      (nhits <= 9)  hRBXEnergyType1_->Fill(energy);
00107     else if (nhits <= 18) hRBXEnergyType2_->Fill(energy);
00108     else                  hRBXEnergyType3_->Fill(energy);
00109     
00110     hRBXNHits_->Fill(nhits);
00111     
00112   }   // done looping over RBXs
00113 
00114 }
00115 
00116 
00117 // ------------ method called once each job just before starting event loop  ------------
00118 void 
00119 NoiseRates::beginJob(){}
00120 
00121 // ------------ method called once each job just after ending the event loop  ------------
00122 void 
00123 NoiseRates::endJob() {
00124 /*  
00125   if (useAllHistos_) hLumiBlockCount_->Fill(0.0, lumiCountMap_.size());
00126   
00127   if ( outputFile_.size() != 0 && dbe_ ) dbe_->save(outputFile_);
00128 */
00129 }
00130 
00131 
00132 //define this as a plug-in
00133 DEFINE_FWK_MODULE(NoiseRates);