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<std::string>("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  // DQM ROOT output
31  outputFile_ = ps.getUntrackedParameter<std::string>("outputFile", "");
32 
33  if (!outputFile_.empty()) {
34  edm::LogInfo("OutputInfo") << " Ecal SimHits Task histograms will be saved to " << outputFile_.c_str();
35  } else {
36  edm::LogInfo("OutputInfo") << " Ecal SimHits Task histograms will NOT be saved";
37  }
38 
39  // verbosity switch
40  verbose_ = ps.getUntrackedParameter<bool>("verbose", false);
41 
42  // DQMServices
43  dbe_ = nullptr;
44 
45  // get hold of back-end interface
46  dbe_ = edm::Service<DQMStore>().operator->();
47  if (dbe_) {
48  if (verbose_) {
49  dbe_->setVerbose(1);
50  } else {
51  dbe_->setVerbose(0);
52  }
53  }
54 
55  if (dbe_) {
56  if (verbose_)
57  dbe_->showDirStructure();
58  }
59 
60  meGunEnergy_ = nullptr;
61  meGunEta_ = nullptr;
62  meGunPhi_ = nullptr;
63  meEBEnergyFraction_ = nullptr;
64  meEEEnergyFraction_ = nullptr;
65  meESEnergyFraction_ = nullptr;
66 
67  Char_t histo[200];
68 
69  if (dbe_) {
70  dbe_->setCurrentFolder("EcalHitsV/EcalSimHitsValidation");
71 
72  sprintf(histo, "EcalSimHitsValidation Gun Momentum");
73  meGunEnergy_ = dbe_->book1D(histo, histo, 100, 0., 1000.);
74 
75  sprintf(histo, "EcalSimHitsValidation Gun Eta");
76  meGunEta_ = dbe_->book1D(histo, histo, 700, -3.5, 3.5);
77 
78  sprintf(histo, "EcalSimHitsValidation Gun Phi");
79  meGunPhi_ = dbe_->book1D(histo, histo, 360, 0., 360.);
80 
81  sprintf(histo, "EcalSimHitsValidation Barrel fraction of energy");
82  meEBEnergyFraction_ = dbe_->book1D(histo, histo, 100, 0., 1.1);
83 
84  sprintf(histo, "EcalSimHitsValidation Endcap fraction of energy");
85  meEEEnergyFraction_ = dbe_->book1D(histo, histo, 100, 0., 1.1);
86 
87  sprintf(histo, "EcalSimHitsValidation Preshower fraction of energy");
88  meESEnergyFraction_ = dbe_->book1D(histo, histo, 60, 0., 0.001);
89  }
90 }
91 
93  if (!outputFile_.empty() && dbe_)
94  dbe_->save(outputFile_);
95 }
96 
98 
100 
102  edm::LogInfo("EventInfo") << " Run = " << e.id().run() << " Event = " << e.id().event();
103 
104  std::vector<PCaloHit> theEBCaloHits;
105  std::vector<PCaloHit> theEECaloHits;
106  std::vector<PCaloHit> theESCaloHits;
107 
112 
113  e.getByToken(HepMCToken, MCEvt);
114  e.getByToken(EBHitsCollectionToken, EcalHitsEB);
115  e.getByToken(EEHitsCollectionToken, EcalHitsEE);
116  e.getByToken(ESHitsCollectionToken, EcalHitsES);
117 
118  for (HepMC::GenEvent::particle_const_iterator p = MCEvt->GetEvent()->particles_begin();
119  p != MCEvt->GetEvent()->particles_end();
120  ++p) {
121  double htheta = (*p)->momentum().theta();
122  double heta = -99999.;
123  if (tan(htheta * 0.5) > 0) {
124  heta = -log(tan(htheta * 0.5));
125  }
126  double hphi = (*p)->momentum().phi();
127  hphi = (hphi >= 0) ? hphi : hphi + 2 * M_PI;
128  hphi = hphi / M_PI * 180.;
129 
130  LogDebug("EventInfo") << "Particle gun type form MC = " << abs((*p)->pdg_id()) << "\n"
131  << "Energy = " << (*p)->momentum().e() << " Eta = " << heta << " Phi = " << hphi;
132 
133  if (meGunEnergy_)
134  meGunEnergy_->Fill((*p)->momentum().e());
135  if (meGunEta_)
136  meGunEta_->Fill(heta);
137  if (meGunPhi_)
138  meGunPhi_->Fill(hphi);
139  }
140 
141  double EBEnergy_ = 0.;
142  if (EcalHitsEB.isValid()) {
143  theEBCaloHits.insert(theEBCaloHits.end(), EcalHitsEB->begin(), EcalHitsEB->end());
144  for (std::vector<PCaloHit>::iterator isim = theEBCaloHits.begin(); isim != theEBCaloHits.end(); ++isim) {
145  EBEnergy_ += isim->energy();
146  }
147  }
148 
149  double EEEnergy_ = 0.;
150  if (EcalHitsEE.isValid()) {
151  theEECaloHits.insert(theEECaloHits.end(), EcalHitsEE->begin(), EcalHitsEE->end());
152  for (std::vector<PCaloHit>::iterator isim = theEECaloHits.begin(); isim != theEECaloHits.end(); ++isim) {
153  EEEnergy_ += isim->energy();
154  }
155  }
156 
157  double ESEnergy_ = 0.;
158  if (EcalHitsES.isValid()) {
159  theESCaloHits.insert(theESCaloHits.end(), EcalHitsES->begin(), EcalHitsES->end());
160  for (std::vector<PCaloHit>::iterator isim = theESCaloHits.begin(); isim != theESCaloHits.end(); ++isim) {
161  ESEnergy_ += isim->energy();
162  }
163  }
164 
165  double etot = EBEnergy_ + EEEnergy_ + ESEnergy_;
166  double fracEB = 0.0;
167  double fracEE = 0.0;
168  double fracES = 0.0;
169 
170  if (etot > 0.0) {
171  fracEB = EBEnergy_ / etot;
172  fracEE = EEEnergy_ / etot;
173  fracES = ESEnergy_ / etot;
174  }
175 
177  meEBEnergyFraction_->Fill(fracEB);
178 
180  meEEEnergyFraction_->Fill(fracEE);
181 
183  meESEnergyFraction_->Fill(fracES);
184 }
#define LogDebug(id)
RunNumber_t run() const
Definition: EventID.h:39
MonitorElement * meEBEnergyFraction_
T getParameter(std::string const &) const
EventNumber_t event() const
Definition: EventID.h:41
T getUntrackedParameter(std::string const &, T const &) const
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:517
~EcalSimHitsValidation() override
Destructor.
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
bool isValid() const
Definition: HandleBase.h:74
edm::EDGetTokenT< edm::PCaloHitContainer > EEHitsCollectionToken
EcalSimHitsValidation(const edm::ParameterSet &ps)
Constructor.
#define M_PI
Namespace of DDCMS conversion namespace.
edm::EDGetTokenT< edm::PCaloHitContainer > ESHitsCollectionToken
const HepMC::GenEvent * GetEvent() const
Definition: HepMCProduct.h:38
MonitorElement * meEEEnergyFraction_
void analyze(const edm::Event &e, const edm::EventSetup &c) override
Analyze.
edm::EventID id() const
Definition: EventBase.h:59
HLT enums.
MonitorElement * meESEnergyFraction_
void endJob(void) override