CMS 3D CMS Logo

EcalPreshowerSimHitsValidation.cc
Go to the documentation of this file.
1 /*
2  * \file EcalPreshowerSimHitsValidation.cc
3  *
4  * \author C.Rovelli
5  *
6  */
7 
13 
14 using namespace cms;
15 using namespace edm;
16 using namespace std;
17 
19  :
20 
21  HepMCLabel(ps.getParameter<std::string>("moduleLabelMC")),
22  g4InfoLabel(ps.getParameter<std::string>("moduleLabelG4")),
23  EEHitsCollection(ps.getParameter<std::string>("EEHitsCollection")),
24  ESHitsCollection(ps.getParameter<std::string>("ESHitsCollection")) {
25  HepMCToken = consumes<edm::HepMCProduct>(HepMCLabel);
26  EEHitsToken =
27  consumes<edm::PCaloHitContainer>(edm::InputTag(std::string(g4InfoLabel), std::string(EEHitsCollection)));
28  ESHitsToken =
29  consumes<edm::PCaloHitContainer>(edm::InputTag(std::string(g4InfoLabel), std::string(ESHitsCollection)));
30  // verbosity switch
31  verbose_ = ps.getUntrackedParameter<bool>("verbose", false);
32 
33  // get hold of back-end interface
34  dbe_ = nullptr;
35  dbe_ = edm::Service<DQMStore>().operator->();
36  if (dbe_) {
37  if (verbose_) {
38  dbe_->setVerbose(1);
39  } else {
40  dbe_->setVerbose(0);
41  }
42  }
43 
44  if (dbe_) {
45  if (verbose_)
46  dbe_->showDirStructure();
47  }
48 
49  menESHits1zp_ = nullptr;
50  menESHits2zp_ = nullptr;
51  menESHits1zm_ = nullptr;
52  menESHits2zm_ = nullptr;
53 
54  meESEnergyHits1zp_ = nullptr;
55  meESEnergyHits2zp_ = nullptr;
56  meESEnergyHits1zm_ = nullptr;
57  meESEnergyHits2zm_ = nullptr;
58 
59  meEShitLog10Energy_ = nullptr;
60  meEShitLog10EnergyNorm_ = nullptr;
61 
62  meE1alphaE2zp_ = nullptr;
63  meE1alphaE2zm_ = nullptr;
64  meEEoverESzp_ = nullptr;
65  meEEoverESzm_ = nullptr;
66 
67  me2eszpOver1eszp_ = nullptr;
68  me2eszmOver1eszm_ = nullptr;
69 
70  Char_t histo[200];
71 
72  if (dbe_) {
73  dbe_->setCurrentFolder("EcalHitsV/EcalSimHitsValidation");
74 
75  sprintf(histo, "ES hits layer 1 multiplicity z+");
76  menESHits1zp_ = dbe_->book1D(histo, histo, 50, 0., 50.);
77 
78  sprintf(histo, "ES hits layer 2 multiplicity z+");
79  menESHits2zp_ = dbe_->book1D(histo, histo, 50, 0., 50.);
80 
81  sprintf(histo, "ES hits layer 1 multiplicity z-");
82  menESHits1zm_ = dbe_->book1D(histo, histo, 50, 0., 50.);
83 
84  sprintf(histo, "ES hits layer 2 multiplicity z-");
85  menESHits2zm_ = dbe_->book1D(histo, histo, 50, 0., 50.);
86 
87  sprintf(histo, "ES hits energy layer 1 z+");
88  meESEnergyHits1zp_ = dbe_->book1D(histo, histo, 100, 0., 0.05);
89 
90  sprintf(histo, "ES hits energy layer 2 z+");
91  meESEnergyHits2zp_ = dbe_->book1D(histo, histo, 100, 0., 0.05);
92 
93  sprintf(histo, "ES hits energy layer 1 z-");
94  meESEnergyHits1zm_ = dbe_->book1D(histo, histo, 100, 0., 0.05);
95 
96  sprintf(histo, "ES hits energy layer 2 z-");
97  meESEnergyHits2zm_ = dbe_->book1D(histo, histo, 100, 0., 0.05);
98 
99  sprintf(histo, "ES hits log10energy spectrum");
100  meEShitLog10Energy_ = dbe_->book1D(histo, histo, 140, -10., 4.);
101 
102  sprintf(histo, "ES hits log10energy spectrum vs normalized energy");
103  meEShitLog10EnergyNorm_ = dbe_->bookProfile(histo, histo, 140, -10., 4., 100, 0., 1.);
104 
105  sprintf(histo, "ES E1+07E2 z+");
106  meE1alphaE2zp_ = dbe_->book1D(histo, histo, 100, 0., 0.05);
107 
108  sprintf(histo, "ES E1+07E2 z-");
109  meE1alphaE2zm_ = dbe_->book1D(histo, histo, 100, 0., 0.05);
110 
111  sprintf(histo, "EE vs ES z+");
112  meEEoverESzp_ = dbe_->bookProfile(histo, histo, 250, 0., 500., 200, 0., 200.);
113 
114  sprintf(histo, "EE vs ES z-");
115  meEEoverESzm_ = dbe_->bookProfile(histo, histo, 250, 0., 500., 200, 0., 200.);
116 
117  sprintf(histo, "ES ene2oEne1 z+");
118  me2eszpOver1eszp_ = dbe_->book1D(histo, histo, 50, 0., 10.);
119 
120  sprintf(histo, "ES ene2oEne1 z-");
121  me2eszmOver1eszm_ = dbe_->book1D(histo, histo, 50, 0., 10.);
122  }
123 }
124 
126 
128 
130 
132  edm::LogInfo("EventInfo") << " Run = " << e.id().run() << " Event = " << e.id().event();
133 
135  e.getByToken(HepMCToken, MCEvt);
136 
138  e.getByToken(EEHitsToken, EcalHitsEE);
139 
141  e.getByToken(ESHitsToken, EcalHitsES);
142 
143  std::vector<PCaloHit> theEECaloHits;
144  if (EcalHitsEE.isValid()) {
145  theEECaloHits.insert(theEECaloHits.end(), EcalHitsEE->begin(), EcalHitsEE->end());
146  }
147 
148  std::vector<PCaloHit> theESCaloHits;
149  if (EcalHitsES.isValid()) {
150  theESCaloHits.insert(theESCaloHits.end(), EcalHitsES->begin(), EcalHitsES->end());
151  }
152 
153  double ESEnergy_ = 0.;
154  // std::map<unsigned int, std::vector<PCaloHit>,std::less<unsigned int> >
155  // CaloHitMap;
156 
157  // endcap
158  double EEetzp_ = 0.;
159  double EEetzm_ = 0.;
160  for (std::vector<PCaloHit>::iterator isim = theEECaloHits.begin(); isim != theEECaloHits.end(); ++isim) {
161  EEDetId eeid(isim->id());
162  if (eeid.zside() > 0)
163  EEetzp_ += isim->energy();
164  if (eeid.zside() < 0)
165  EEetzm_ += isim->energy();
166  }
167 
168  uint32_t nESHits1zp = 0;
169  uint32_t nESHits1zm = 0;
170  uint32_t nESHits2zp = 0;
171  uint32_t nESHits2zm = 0;
172  double ESet1zp_ = 0.;
173  double ESet2zp_ = 0.;
174  double ESet1zm_ = 0.;
175  double ESet2zm_ = 0.;
176  std::vector<double> econtr(140, 0.);
177 
178  for (std::vector<PCaloHit>::iterator isim = theESCaloHits.begin(); isim != theESCaloHits.end(); ++isim) {
179  // CaloHitMap[(*isim).id()].push_back((*isim));
180 
181  ESDetId esid(isim->id());
182 
183  LogDebug("HitInfo") << " CaloHit " << isim->getName() << "\n"
184  << " DetID = " << isim->id() << " ESDetId: z side " << esid.zside() << " plane "
185  << esid.plane() << esid.six() << ',' << esid.siy() << ':' << esid.strip() << "\n"
186  << " Time = " << isim->time() << "\n"
187  << " Track Id = " << isim->geantTrackId() << "\n"
188  << " Energy = " << isim->energy();
189 
190  ESEnergy_ += isim->energy();
191  if (isim->energy() > 0) {
192  meEShitLog10Energy_->Fill(log10(isim->energy()));
193  int log10i = int((log10(isim->energy()) + 10.) * 10.);
194  if (log10i >= 0 && log10i < 140)
195  econtr[log10i] += isim->energy();
196  }
197 
198  if (esid.plane() == 1) {
199  if (esid.zside() > 0) {
200  nESHits1zp++;
201  ESet1zp_ += isim->energy();
202  if (meESEnergyHits1zp_)
203  meESEnergyHits1zp_->Fill(isim->energy());
204  } else if (esid.zside() < 0) {
205  nESHits1zm++;
206  ESet1zm_ += isim->energy();
207  if (meESEnergyHits1zm_)
208  meESEnergyHits1zm_->Fill(isim->energy());
209  }
210  } else if (esid.plane() == 2) {
211  if (esid.zside() > 0) {
212  nESHits2zp++;
213  ESet2zp_ += isim->energy();
214  if (meESEnergyHits2zp_)
215  meESEnergyHits2zp_->Fill(isim->energy());
216  } else if (esid.zside() < 0) {
217  nESHits2zm++;
218  ESet2zm_ += isim->energy();
219  if (meESEnergyHits2zm_)
220  meESEnergyHits2zm_->Fill(isim->energy());
221  }
222  }
223  }
224 
225  if (menESHits1zp_)
226  menESHits1zp_->Fill(nESHits1zp);
227  if (menESHits1zm_)
228  menESHits1zm_->Fill(nESHits1zm);
229 
230  if (menESHits2zp_)
231  menESHits2zp_->Fill(nESHits2zp);
232  if (menESHits2zm_)
233  menESHits2zm_->Fill(nESHits2zm);
234 
235  if (meEShitLog10EnergyNorm_ && ESEnergy_ != 0) {
236  for (int i = 0; i < 140; i++) {
237  meEShitLog10EnergyNorm_->Fill(-10. + (float(i) + 0.5) / 10., econtr[i] / ESEnergy_);
238  }
239  }
240 
241  for (HepMC::GenEvent::particle_const_iterator p = MCEvt->GetEvent()->particles_begin();
242  p != MCEvt->GetEvent()->particles_end();
243  ++p) {
244  double htheta = (*p)->momentum().theta();
245  double heta = -99999.;
246  if (tan(htheta * 0.5) > 0) {
247  heta = -log(tan(htheta * 0.5));
248  }
249 
250  if (heta > 1.653 && heta < 2.6) {
251  if (meE1alphaE2zp_)
252  meE1alphaE2zp_->Fill(ESet1zp_ + 0.7 * ESet2zp_);
253  if (meEEoverESzp_)
254  meEEoverESzp_->Fill((ESet1zp_ + 0.7 * ESet2zp_) / 0.00009, EEetzp_);
255  if ((me2eszpOver1eszp_) && (ESet1zp_ != 0.))
256  me2eszpOver1eszp_->Fill(ESet2zp_ / ESet1zp_);
257  }
258  if (heta < -1.653 && heta > -2.6) {
259  if (meE1alphaE2zm_)
260  meE1alphaE2zm_->Fill(ESet1zm_ + 0.7 * ESet2zm_);
261  if (meEEoverESzm_)
262  meEEoverESzm_->Fill((ESet1zm_ + 0.7 * ESet2zm_) / 0.00009, EEetzm_);
263  if ((me2eszmOver1eszm_) && (ESet1zm_ != 0.))
264  me2eszmOver1eszm_->Fill(ESet2zm_ / ESet1zm_);
265  }
266  }
267 }
268 
269 // LocalWords: EcalSimHitsValidation
#define LogDebug(id)
RunNumber_t run() const
Definition: EventID.h:39
EventNumber_t event() const
Definition: EventID.h:41
T getUntrackedParameter(std::string const &, T const &) const
EcalPreshowerSimHitsValidation(const edm::ParameterSet &ps)
Constructor.
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:517
void Fill(long long x)
void analyze(const edm::Event &e, const edm::EventSetup &c) override
Analyze.
edm::EDGetTokenT< edm::HepMCProduct > HepMCToken
Tan< T >::type tan(const T &t)
Definition: Tan.h:22
bool isValid() const
Definition: HandleBase.h:74
Namespace of DDCMS conversion namespace.
const HepMC::GenEvent * GetEvent() const
Definition: HepMCProduct.h:38
edm::EventID id() const
Definition: EventBase.h:59
HLT enums.
edm::EDGetTokenT< edm::PCaloHitContainer > EEHitsToken
edm::EDGetTokenT< edm::PCaloHitContainer > ESHitsToken