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