00001
00002
00003
00004
00005
00006
00007
00008 #include <DataFormats/EcalDetId/interface/EBDetId.h>
00009 #include <DataFormats/EcalDetId/interface/EEDetId.h>
00010 #include <DataFormats/EcalDetId/interface/ESDetId.h>
00011 #include "FWCore/Utilities/interface/Exception.h"
00012 #include "Validation/EcalHits/interface/EcalSimHitsValidation.h"
00013 #include "DQMServices/Core/interface/DQMStore.h"
00014
00015 using namespace cms;
00016 using namespace edm;
00017 using namespace std;
00018
00019 EcalSimHitsValidation::EcalSimHitsValidation(const edm::ParameterSet& ps):
00020 HepMCLabel(ps.getParameter<std::string>("moduleLabelMC")),
00021 g4InfoLabel(ps.getParameter<std::string>("moduleLabelG4")),
00022 EBHitsCollection(ps.getParameter<std::string>("EBHitsCollection")),
00023 EEHitsCollection(ps.getParameter<std::string>("EEHitsCollection")),
00024 ESHitsCollection(ps.getParameter<std::string>("ESHitsCollection")){
00025
00026
00027 outputFile_ = ps.getUntrackedParameter<std::string>("outputFile", "");
00028
00029 if ( outputFile_.size() != 0 ) {
00030 edm::LogInfo("OutputInfo") << " Ecal SimHits Task histograms will be saved to " << outputFile_.c_str();
00031 } else {
00032 edm::LogInfo("OutputInfo") << " Ecal SimHits Task histograms will NOT be saved";
00033 }
00034
00035
00036 verbose_ = ps.getUntrackedParameter<bool>("verbose", false);
00037
00038
00039 dbe_ = 0;
00040
00041
00042 dbe_ = edm::Service<DQMStore>().operator->();
00043 if ( dbe_ ) {
00044 if ( verbose_ ) { dbe_->setVerbose(1); }
00045 else { dbe_->setVerbose(0); }
00046 }
00047
00048 if ( dbe_ ) {
00049 if ( verbose_ ) dbe_->showDirStructure();
00050 }
00051
00052 meGunEnergy_ = 0;
00053 meGunEta_ = 0;
00054 meGunPhi_ = 0;
00055 meEBEnergyFraction_ = 0;
00056 meEEEnergyFraction_ = 0;
00057 meESEnergyFraction_ = 0;
00058
00059 Char_t histo[200];
00060
00061
00062 if ( dbe_ ) {
00063 dbe_->setCurrentFolder("EcalHitsV/EcalSimHitsValidation");
00064
00065 sprintf (histo, "EcalSimHitsValidation Gun Momentum" ) ;
00066 meGunEnergy_ = dbe_->book1D(histo, histo, 100, 0., 1000.);
00067
00068 sprintf (histo, "EcalSimHitsValidation Gun Eta" ) ;
00069 meGunEta_ = dbe_->book1D(histo, histo, 700, -3.5, 3.5);
00070
00071 sprintf (histo, "EcalSimHitsValidation Gun Phi" ) ;
00072 meGunPhi_ = dbe_->book1D(histo, histo, 360, 0., 360.);
00073
00074 sprintf (histo, "EcalSimHitsValidation Barrel fraction of energy" ) ;
00075 meEBEnergyFraction_ = dbe_->book1D(histo, histo, 100 , 0. , 1.1);
00076
00077 sprintf (histo, "EcalSimHitsValidation Endcap fraction of energy" ) ;
00078 meEEEnergyFraction_ = dbe_->book1D(histo, histo, 100 , 0. , 1.1);
00079
00080 sprintf (histo, "EcalSimHitsValidation Preshower fraction of energy" ) ;
00081 meESEnergyFraction_ = dbe_->book1D(histo, histo, 60 , 0. , 0.001);
00082 }
00083
00084 }
00085
00086 EcalSimHitsValidation::~EcalSimHitsValidation(){
00087
00088 if ( outputFile_.size() != 0 && dbe_ ) dbe_->save(outputFile_);
00089
00090 }
00091
00092 void EcalSimHitsValidation::beginJob(const edm::EventSetup& c){
00093
00094 }
00095
00096 void EcalSimHitsValidation::endJob(){
00097
00098 }
00099
00100 void EcalSimHitsValidation::analyze(const edm::Event& e, const edm::EventSetup& c){
00101
00102 edm::LogInfo("EventInfo") << " Run = " << e.id().run() << " Event = " << e.id().event();
00103
00104 std::vector<PCaloHit> theEBCaloHits;
00105 std::vector<PCaloHit> theEECaloHits;
00106 std::vector<PCaloHit> theESCaloHits;
00107
00108 edm::Handle<edm::HepMCProduct> MCEvt;
00109 edm::Handle<edm::PCaloHitContainer> EcalHitsEB;
00110 edm::Handle<edm::PCaloHitContainer> EcalHitsEE;
00111 edm::Handle<edm::PCaloHitContainer> EcalHitsES;
00112
00113 e.getByLabel(HepMCLabel, MCEvt);
00114 e.getByLabel(g4InfoLabel,EBHitsCollection,EcalHitsEB);
00115 e.getByLabel(g4InfoLabel,EEHitsCollection,EcalHitsEE);
00116 e.getByLabel(g4InfoLabel,ESHitsCollection,EcalHitsES);
00117
00118 for ( HepMC::GenEvent::particle_const_iterator p = MCEvt->GetEvent()->particles_begin();
00119 p != MCEvt->GetEvent()->particles_end(); ++p ) {
00120
00121 double htheta = (*p)->momentum().theta();
00122 double heta = -log(tan(htheta * 0.5));
00123 double hphi = (*p)->momentum().phi();
00124 hphi = (hphi>=0) ? hphi : hphi+2*M_PI;
00125 hphi = hphi / M_PI * 180.;
00126
00127 LogDebug("EventInfo") << "Particle gun type form MC = " << abs((*p)->pdg_id()) << "\n" << "Energy = "<< (*p)->momentum().e() << " Eta = " << heta << " Phi = " << hphi;
00128
00129 if (meGunEnergy_) meGunEnergy_->Fill((*p)->momentum().e());
00130 if (meGunEta_) meGunEta_ ->Fill(heta);
00131 if (meGunPhi_) meGunPhi_ ->Fill(hphi);
00132
00133 }
00134
00135 double EBEnergy_ = 0.;
00136 if ( EcalHitsEB.isValid() ) {
00137 theEBCaloHits.insert(theEBCaloHits.end(), EcalHitsEB->begin(), EcalHitsEB->end());
00138 for (std::vector<PCaloHit>::iterator isim = theEBCaloHits.begin();
00139 isim != theEBCaloHits.end(); ++isim){
00140 EBEnergy_ += isim->energy();
00141 }
00142 }
00143
00144 double EEEnergy_ = 0.;
00145 if ( EcalHitsEE.isValid() ) {
00146 theEECaloHits.insert(theEECaloHits.end(), EcalHitsEE->begin(), EcalHitsEE->end());
00147 for (std::vector<PCaloHit>::iterator isim = theEECaloHits.begin();
00148 isim != theEECaloHits.end(); ++isim){
00149 EEEnergy_ += isim->energy();
00150 }
00151 }
00152
00153 double ESEnergy_ = 0.;
00154 if ( EcalHitsES.isValid() ) {
00155 theESCaloHits.insert(theESCaloHits.end(), EcalHitsES->begin(), EcalHitsES->end());
00156 for (std::vector<PCaloHit>::iterator isim = theESCaloHits.begin();
00157 isim != theESCaloHits.end(); ++isim){
00158 ESEnergy_ += isim->energy();
00159 }
00160 }
00161
00162 double etot = EBEnergy_ + EEEnergy_ + ESEnergy_ ;
00163 double fracEB = 0.0;
00164 double fracEE = 0.0;
00165 double fracES = 0.0;
00166
00167 if (etot>0.0) {
00168 fracEB = EBEnergy_/etot;
00169 fracEE = EEEnergy_/etot;
00170 fracES = ESEnergy_/etot;
00171 }
00172
00173 if (meEBEnergyFraction_) meEBEnergyFraction_->Fill(fracEB);
00174
00175 if (meEEEnergyFraction_) meEEEnergyFraction_->Fill(fracEE);
00176
00177 if (meESEnergyFraction_) meESEnergyFraction_->Fill(fracES);
00178 }
00179