CMS 3D CMS Logo

EcalSimHitsValidation.cc
Go to the documentation of this file.
1 /*
2  * \file EcalSimHitsValidation.cc
3  *
4  * \author C.Rovelli
5  *
6  */
7 
15 
16 using namespace cms;
17 using namespace edm;
18 using namespace std;
19 
21  : g4InfoLabel(ps.getParameter<std::string>("moduleLabelG4")),
22  HepMCToken(consumes<edm::HepMCProduct>(ps.getParameter<edm::InputTag>("moduleLabelMC"))) {
24  consumes<edm::PCaloHitContainer>(edm::InputTag(g4InfoLabel, ps.getParameter<std::string>("EBHitsCollection")));
26  consumes<edm::PCaloHitContainer>(edm::InputTag(g4InfoLabel, ps.getParameter<std::string>("EEHitsCollection")));
28  consumes<edm::PCaloHitContainer>(edm::InputTag(g4InfoLabel, ps.getParameter<std::string>("ESHitsCollection")));
29 
30  // verbosity switch
31  verbose_ = ps.getUntrackedParameter<bool>("verbose", false);
32 }
33 
35  ib.setCurrentFolder("EcalHitsV/EcalSimHitsValidation");
36  ib.setScope(MonitorElementData::Scope::RUN);
37 
38  std::string histo = "EcalSimHitsValidation Gun Momentum";
39  meGunEnergy_ = ib.book1D(histo, histo, 100, 0., 1000.);
40 
41  histo = "EcalSimHitsValidation Gun Eta";
42  meGunEta_ = ib.book1D(histo, histo, 700, -3.5, 3.5);
43 
44  histo = "EcalSimHitsValidation Gun Phi";
45  meGunPhi_ = ib.book1D(histo, histo, 360, 0., 360.);
46 
47  histo = "EcalSimHitsValidation Barrel fraction of energy";
48  meEBEnergyFraction_ = ib.book1D(histo, histo, 100, 0., 1.1);
49 
50  histo = "EcalSimHitsValidation Endcap fraction of energy";
51  meEEEnergyFraction_ = ib.book1D(histo, histo, 100, 0., 1.1);
52 
53  histo = "EcalSimHitsValidation Preshower fraction of energy";
54  meESEnergyFraction_ = ib.book1D(histo, histo, 60, 0., 0.001);
55 }
56 
58  edm::LogInfo("EventInfo") << " Run = " << e.id().run() << " Event = " << e.id().event();
59 
60  std::vector<PCaloHit> theEBCaloHits;
61  std::vector<PCaloHit> theEECaloHits;
62  std::vector<PCaloHit> theESCaloHits;
63 
68 
69  e.getByToken(HepMCToken, MCEvt);
70  e.getByToken(EBHitsCollectionToken, EcalHitsEB);
71  e.getByToken(EEHitsCollectionToken, EcalHitsEE);
72  e.getByToken(ESHitsCollectionToken, EcalHitsES);
73 
74  for (HepMC::GenEvent::particle_const_iterator p = MCEvt->GetEvent()->particles_begin();
75  p != MCEvt->GetEvent()->particles_end();
76  ++p) {
77  double htheta = (*p)->momentum().theta();
78  double heta = -99999.;
79  if (tan(htheta * 0.5) > 0) {
80  heta = -log(tan(htheta * 0.5));
81  }
82  double hphi = (*p)->momentum().phi();
83  hphi = (hphi >= 0) ? hphi : hphi + 2 * M_PI;
84  hphi = hphi / M_PI * 180.;
85 
86  LogDebug("EventInfo") << "Particle gun type form MC = " << abs((*p)->pdg_id()) << "\n"
87  << "Energy = " << (*p)->momentum().e() << " Eta = " << heta << " Phi = " << hphi;
88 
89  meGunEnergy_->Fill((*p)->momentum().e());
90  meGunEta_->Fill(heta);
91  meGunPhi_->Fill(hphi);
92  }
93 
94  double EBEnergy_ = 0.;
95  if (EcalHitsEB.isValid()) {
96  theEBCaloHits.insert(theEBCaloHits.end(), EcalHitsEB->begin(), EcalHitsEB->end());
97  for (std::vector<PCaloHit>::iterator isim = theEBCaloHits.begin(); isim != theEBCaloHits.end(); ++isim) {
98  EBEnergy_ += isim->energy();
99  }
100  }
101 
102  double EEEnergy_ = 0.;
103  if (EcalHitsEE.isValid()) {
104  theEECaloHits.insert(theEECaloHits.end(), EcalHitsEE->begin(), EcalHitsEE->end());
105  for (std::vector<PCaloHit>::iterator isim = theEECaloHits.begin(); isim != theEECaloHits.end(); ++isim) {
106  EEEnergy_ += isim->energy();
107  }
108  }
109 
110  double ESEnergy_ = 0.;
111  if (EcalHitsES.isValid()) {
112  theESCaloHits.insert(theESCaloHits.end(), EcalHitsES->begin(), EcalHitsES->end());
113  for (std::vector<PCaloHit>::iterator isim = theESCaloHits.begin(); isim != theESCaloHits.end(); ++isim) {
114  ESEnergy_ += isim->energy();
115  }
116  }
117 
118  double etot = EBEnergy_ + EEEnergy_ + ESEnergy_;
119  double fracEB = 0.0;
120  double fracEE = 0.0;
121  double fracES = 0.0;
122 
123  if (etot > 0.0) {
124  fracEB = EBEnergy_ / etot;
125  fracEE = EEEnergy_ / etot;
126  fracES = ESEnergy_ / etot;
127  }
128 
129  meEBEnergyFraction_->Fill(fracEB);
130  meEEEnergyFraction_->Fill(fracEE);
131  meESEnergyFraction_->Fill(fracES);
132 }
MonitorElement * meEBEnergyFraction_
T getParameter(std::string const &) const
Definition: ParameterSet.h:307
void bookHistograms(DQMStore::IBooker &ib, edm::Run const &, edm::EventSetup const &c) override
T getUntrackedParameter(std::string const &, T const &) const
void Fill(long long x)
edm::EDGetTokenT< edm::PCaloHitContainer > EBHitsCollectionToken
edm::EDGetTokenT< edm::HepMCProduct > HepMCToken
MonitorElement * meGunEnergy_
Tan< T >::type tan(const T &t)
Definition: Tan.h:22
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
edm::EDGetTokenT< edm::PCaloHitContainer > EEHitsCollectionToken
EcalSimHitsValidation(const edm::ParameterSet &ps)
Constructor.
const HepMC::GenEvent * GetEvent() const
Definition: HepMCProduct.h:37
#define M_PI
Namespace of DDCMS conversion namespace.
edm::EDGetTokenT< edm::PCaloHitContainer > ESHitsCollectionToken
Log< level::Info, false > LogInfo
MonitorElement * meEEEnergyFraction_
void analyze(const edm::Event &e, const edm::EventSetup &c) override
Analyze.
bool isValid() const
Definition: HandleBase.h:70
HLT enums.
MonitorElement * meESEnergyFraction_
Definition: Run.h:45
ib
Definition: cuy.py:661
#define LogDebug(id)