CMS 3D CMS Logo

MuonSimHitsValidAnalyzer.cc
Go to the documentation of this file.
2 
3 #include "TFile.h"
4 #include "TTree.h"
5 #include "TBranch.h"
6 #include "TH1F.h"
7 
8 #include <iostream>
9 #include <string>
10 
11 using namespace edm;
12 using namespace std;
13 
15  : fName(""),
16  verbosity(0),
17  label(""),
18  getAllProvenances(false),
19  printProvenanceInfo(false),
20  nRawGenPart(0),
21  count(0)
22 
23 {
25  fName = iPSet.getUntrackedParameter<std::string>("Name");
26  verbosity = iPSet.getUntrackedParameter<int>("Verbosity");
27  label = iPSet.getParameter<std::string>("Label");
28  edm::ParameterSet m_Prov = iPSet.getParameter<edm::ParameterSet>("ProvenanceLookup");
29  getAllProvenances = m_Prov.getUntrackedParameter<bool>("GetAllProvenances");
30  printProvenanceInfo = m_Prov.getUntrackedParameter<bool>("PrintProvenanceInfo");
31 
32  nRawGenPart = 0;
33 
35  DTHitsToken_ = consumes<edm::PSimHitContainer>(iPSet.getParameter<edm::InputTag>("DTHitsSrc"));
36 
38 
39  if (verbosity) {
40  Labels l;
42  edm::LogInfo("MuonSimHitsValidAnalyzer::MuonSimHitsValidAnalyzer")
43  << "\n===============================\n"
44  << "Initialized as EDAnalyzer with parameter values:\n"
45  << " Name = " << fName << "\n"
46  << " Verbosity = " << verbosity << "\n"
47  << " Label = " << label << "\n"
48  << " GetProv = " << getAllProvenances << "\n"
49  << " PrintProv = " << printProvenanceInfo
50  << "\n"
51  // << " CSCHitsSrc= " <<CSCHitsSrc_.label()
52  // << ":" << CSCHitsSrc_.instance() << "\n"
53  << " DTHitsSrc = " << l.module << ":" << l.productInstance
54  << "\n"
55  // << " RPCHitsSrc= " <<RPCHitsSrc_.label()
56  // << ":" << RPCHitsSrc_.instance() << "\n"
57  << "===============================\n";
58  }
59 
60  pow6 = 1000000.0;
61  mom4 = 0.;
62  mom1 = 0;
63  costeta = 0.;
64  radius = 0;
65  sinteta = 0.;
66  globposx = 0.;
67  globposy = 0;
68  nummu_DT = 0;
69  nummu_CSC = 0;
70  nummu_RPC = 0;
71 }
72 
74 
76  edm::Run const& iRun,
77  edm::EventSetup const& /* iSetup */) {
78  meAllDTHits = nullptr;
79  meMuDTHits = nullptr;
80  meToF = nullptr;
81  meEnergyLoss = nullptr;
82  meMomentumMB1 = nullptr;
83  meMomentumMB4 = nullptr;
84  meLossMomIron = nullptr;
85  meLocalXvsZ = nullptr;
86  meLocalXvsY = nullptr;
87  meGlobalXvsZ = nullptr;
88  meGlobalXvsY = nullptr;
89  meGlobalXvsZWm2 = nullptr;
90  meGlobalXvsZWm1 = nullptr;
91  meGlobalXvsZW0 = nullptr;
92  meGlobalXvsZWp1 = nullptr;
93  meGlobalXvsZWp2 = nullptr;
94  meGlobalXvsYWm2 = nullptr;
95  meGlobalXvsYWm1 = nullptr;
96  meGlobalXvsYW0 = nullptr;
97  meGlobalXvsYWp1 = nullptr;
98  meGlobalXvsYWp2 = nullptr;
99  meWheelOccup = nullptr;
100  meStationOccup = nullptr;
101  meSectorOccup = nullptr;
102  meSuperLOccup = nullptr;
103  meLayerOccup = nullptr;
104  meWireOccup = nullptr;
105  mePathMuon = nullptr;
106  meChamberOccup = nullptr;
107  meHitRadius = nullptr;
108  meCosTheta = nullptr;
109  meGlobalEta = nullptr;
110  meGlobalPhi = nullptr;
111 
112  Char_t histo_n[100];
113  Char_t histo_t[100];
114 
115  iBooker.setCurrentFolder("MuonDTHitsV/DTHitsValidationTask");
116 
117  sprintf(histo_n, "Number_of_all_DT_hits");
118  sprintf(histo_t, "Number_of_all_DT_hits");
119  meAllDTHits = iBooker.book1D(histo_n, histo_t, 200, 1.0, 201.0);
120 
121  sprintf(histo_n, "Number_of_muon_DT_hits");
122  sprintf(histo_t, "Number_of_muon_DT_hits");
123  meMuDTHits = iBooker.book1D(histo_n, histo_t, 150, 1.0, 151.0);
124 
125  sprintf(histo_n, "Tof_of_hits ");
126  sprintf(histo_t, "Tof_of_hits ");
127  meToF = iBooker.book1D(histo_n, histo_t, 100, -0.5, 50.);
128 
129  sprintf(histo_n, "DT_energy_loss_keV");
130  sprintf(histo_t, "DT_energy_loss_keV");
131  meEnergyLoss = iBooker.book1D(histo_n, histo_t, 100, 0.0, 10.0);
132 
133  sprintf(histo_n, "Momentum_at_MB1");
134  sprintf(histo_t, "Momentum_at_MB1");
135  meMomentumMB1 = iBooker.book1D(histo_n, histo_t, 100, 10.0, 200.0);
136 
137  sprintf(histo_n, "Momentum_at_MB4");
138  sprintf(histo_t, "Momentum_at_MB4");
139  meMomentumMB4 = iBooker.book1D(histo_n, histo_t, 100, 10.0, 200.0);
140 
141  sprintf(histo_n, "Loss_of_muon_Momentum_in_Iron");
142  sprintf(histo_t, "Loss_of_muon_Momentum_in_Iron");
143  meLossMomIron = iBooker.book1D(histo_n, histo_t, 80, 0.0, 40.0);
144 
145  sprintf(histo_n, "Local_x-coord_vs_local_z-coord_of_muon_hit");
146  sprintf(histo_t, "Local_x-coord_vs_local_z-coord_of_muon_hit");
147  meLocalXvsZ = iBooker.book2D(histo_n, histo_t, 100, -150., 150., 100, -0.8, 0.8);
148 
149  sprintf(histo_n, "local_x-coord_vs_local_y-coord_of_muon_hit");
150  sprintf(histo_t, "local_x-coord_vs_local_y-coord_of_muon_hit");
151  meLocalXvsY = iBooker.book2D(histo_n, histo_t, 100, -150., 150., 100, -150., 150.);
152 
153  sprintf(histo_n, "Global_x-coord_vs_global_z-coord_of_muon_hit");
154  sprintf(histo_t, "Global_x-coord_vs_global_z-coord_of_muon_hit");
155  meGlobalXvsZ = iBooker.book2D(histo_n, histo_t, 100, -800., 800., 100, -800., 800.);
156 
157  sprintf(histo_n, "Global_x-coord_vs_global_y-coord_of_muon_hit");
158  sprintf(histo_t, "Global_x-coord_vs_global_y-coord_of_muon_hit");
159  meGlobalXvsY = iBooker.book2D(histo_n, histo_t, 100, -800., 800., 100, -800., 800.);
160 
161  // New histos
162 
163  sprintf(histo_n, "Global_x-coord_vs_global_z-coord_of_muon_hit_w-2");
164  sprintf(histo_t, "Global_x-coord_vs_global_z-coord_of_muon_hit_w-2");
165  meGlobalXvsZWm2 = iBooker.book2D(histo_n, histo_t, 100, -800., 800., 100, -800., 800.);
166 
167  sprintf(histo_n, "Global_x-coord_vs_global_y-coord_of_muon_hit_w-2");
168  sprintf(histo_t, "Global_x-coord_vs_global_y-coord_of_muon_hit_w-2");
169  meGlobalXvsYWm2 = iBooker.book2D(histo_n, histo_t, 100, -800., 800., 100, -800., 800.);
170 
171  sprintf(histo_n, "Global_x-coord_vs_global_z-coord_of_muon_hit_w-1");
172  sprintf(histo_t, "Global_x-coord_vs_global_z-coord_of_muon_hit_w-1");
173  meGlobalXvsZWm1 = iBooker.book2D(histo_n, histo_t, 100, -800., 800., 100, -800., 800.);
174 
175  sprintf(histo_n, "Global_x-coord_vs_global_y-coord_of_muon_hit_w-1");
176  sprintf(histo_t, "Global_x-coord_vs_global_y-coord_of_muon_hit_w-1");
177  meGlobalXvsYWm1 = iBooker.book2D(histo_n, histo_t, 100, -800., 800., 100, -800., 800.);
178 
179  sprintf(histo_n, "Global_x-coord_vs_global_z-coord_of_muon_hit_w0");
180  sprintf(histo_t, "Global_x-coord_vs_global_z-coord_of_muon_hit_w0");
181  meGlobalXvsZW0 = iBooker.book2D(histo_n, histo_t, 100, -800., 800., 100, -800., 800.);
182 
183  sprintf(histo_n, "Global_x-coord_vs_global_y-coord_of_muon_hit_w0");
184  sprintf(histo_t, "Global_x-coord_vs_global_y-coord_of_muon_hit_w0");
185  meGlobalXvsYW0 = iBooker.book2D(histo_n, histo_t, 100, -800., 800., 100, -800., 800.);
186 
187  sprintf(histo_n, "Global_x-coord_vs_global_z-coord_of_muon_hit_w1");
188  sprintf(histo_t, "Global_x-coord_vs_global_z-coord_of_muon_hit_w1");
189  meGlobalXvsZWp1 = iBooker.book2D(histo_n, histo_t, 100, -800., 800., 100, -800., 800.);
190 
191  sprintf(histo_n, "Global_x-coord_vs_global_y-coord_of_muon_hit_w1");
192  sprintf(histo_t, "Global_x-coord_vs_global_y-coord_of_muon_hit_w1");
193  meGlobalXvsYWp1 = iBooker.book2D(histo_n, histo_t, 100, -800., 800., 100, -800., 800.);
194 
195  sprintf(histo_n, "Global_x-coord_vs_global_z-coord_of_muon_hit_w2");
196  sprintf(histo_t, "Global_x-coord_vs_global_z-coord_of_muon_hit_w2");
197  meGlobalXvsZWp2 = iBooker.book2D(histo_n, histo_t, 100, -800., 800., 100, -800., 800.);
198 
199  sprintf(histo_n, "Global_x-coord_vs_global_y-coord_of_muon_hit_w2");
200  sprintf(histo_t, "Global_x-coord_vs_global_y-coord_of_muon_hit_w2");
201  meGlobalXvsYWp2 = iBooker.book2D(histo_n, histo_t, 100, -800., 800., 100, -800., 800.);
202 
203  //
204 
205  sprintf(histo_n, "Wheel_occupancy");
206  sprintf(histo_t, "Wheel_occupancy");
207  meWheelOccup = iBooker.book1D(histo_n, histo_t, 10, -5.0, 5.0);
208 
209  sprintf(histo_n, "Station_occupancy");
210  sprintf(histo_t, "Station_occupancy");
211  meStationOccup = iBooker.book1D(histo_n, histo_t, 6, 0., 6.0);
212 
213  sprintf(histo_n, "Sector_occupancy");
214  sprintf(histo_t, "Sector_occupancy");
215  meSectorOccup = iBooker.book1D(histo_n, histo_t, 20, 0., 20.);
216 
217  sprintf(histo_n, "SuperLayer_occupancy");
218  sprintf(histo_t, "SuperLayer_occupancy");
219  meSuperLOccup = iBooker.book1D(histo_n, histo_t, 5, 0., 5.);
220 
221  sprintf(histo_n, "Layer_occupancy");
222  sprintf(histo_t, "Layer_occupancy");
223  meLayerOccup = iBooker.book1D(histo_n, histo_t, 6, 0., 6.);
224 
225  sprintf(histo_n, "Wire_occupancy");
226  sprintf(histo_t, "Wire_occupancy");
227  meWireOccup = iBooker.book1D(histo_n, histo_t, 100, 0., 100.);
228 
229  sprintf(histo_n, "path_followed_by_muon");
230  sprintf(histo_t, "path_followed_by_muon");
231  mePathMuon = iBooker.book1D(histo_n, histo_t, 160, 0., 160.);
232 
233  sprintf(histo_n, "chamber_occupancy");
234  sprintf(histo_t, "chamber_occupancy");
235  meChamberOccup = iBooker.book1D(histo_n, histo_t, 251, 0., 251.);
236 
237  sprintf(histo_n, "radius_of_hit");
238  sprintf(histo_t, "radius_of_hit");
239  meHitRadius = iBooker.book1D(histo_n, histo_t, 100, 0., 1200.);
240 
241  sprintf(histo_n, "costheta_of_hit");
242  sprintf(histo_t, "costheta_of_hit");
243  meCosTheta = iBooker.book1D(histo_n, histo_t, 100, -1., 1.);
244 
245  sprintf(histo_n, "global_eta_of_hit");
246  sprintf(histo_t, "global_eta_of_hit");
247  meGlobalEta = iBooker.book1D(histo_n, histo_t, 60, -2.7, 2.7);
248 
249  sprintf(histo_n, "global_phi_of_hit");
250  sprintf(histo_t, "global_phi_of_hit");
251  meGlobalPhi = iBooker.book1D(histo_n, histo_t, 60, -3.14, 3.14);
252 }
253 
256  ++count;
257 
259  edm::RunNumber_t nrun = iEvent.id().run();
260  edm::EventNumber_t nevt = iEvent.id().event();
261 
262  if (verbosity > 0) {
263  edm::LogInfo("MuonSimHitsValidAnalyzer::analyze") << "Processing run " << nrun << ", event " << nevt;
264  }
265 
267  if (getAllProvenances) {
268  std::vector<const edm::StableProvenance*> AllProv;
269  iEvent.getAllStableProvenance(AllProv);
270 
271  if (verbosity > 0)
272  edm::LogInfo("MuonSimHitsValidAnalyzer::analyze") << "Number of Provenances = " << AllProv.size();
273 
274  if (printProvenanceInfo && (verbosity > 0)) {
275  TString eventout("\nProvenance info:\n");
276 
277  for (unsigned int i = 0; i < AllProv.size(); ++i) {
278  eventout += "\n ******************************";
279  eventout += "\n Module : ";
280  eventout += AllProv[i]->moduleLabel();
281  eventout += "\n ProductID : ";
282  eventout += AllProv[i]->productID().id();
283  eventout += "\n ClassName : ";
284  eventout += AllProv[i]->className();
285  eventout += "\n InstanceName : ";
286  eventout += AllProv[i]->productInstanceName();
287  eventout += "\n BranchName : ";
288  eventout += AllProv[i]->branchName();
289  }
290  eventout += " ******************************\n";
291  edm::LogInfo("MuonSimHitsValidAnalyzer::analyze") << eventout << "\n";
292  }
293  }
294 
295  fillDT(iEvent, iSetup);
296 
297  if (verbosity > 0)
298  edm::LogInfo("MuonSimHitsValidAnalyzer::analyze") << "Done gathering data from event.";
299 
300  return;
301 }
302 
304  TString eventout;
305  if (verbosity > 0)
306  eventout = "\nGathering DT info:";
307 
309  edm::PSimHitContainer::const_iterator itHit;
310 
313  edm::ESHandle<DTGeometry> theDTGeometry;
314  iSetup.get<MuonGeometryRecord>().get(theDTGeometry);
315  if (!theDTGeometry.isValid()) {
316  edm::LogWarning("MuonSimHitsValidAnalyzer::fillDT")
317  << "Unable to find MuonGeometryRecord for the DTGeometry in event!";
318  return;
319  }
320  const DTGeometry& theDTMuon(*theDTGeometry);
321 
323  edm::Handle<edm::PSimHitContainer> MuonDTContainer;
324  iEvent.getByToken(DTHitsToken_, MuonDTContainer);
325  if (!MuonDTContainer.isValid()) {
326  edm::LogWarning("MuonSimHitsValidAnalyzer::fillDT") << "Unable to find MuonDTHits in event!";
327  return;
328  }
329 
330  touch1 = 0;
331  touch4 = 0;
332  nummu_DT = 0;
333 
334  meAllDTHits->Fill(MuonDTContainer->size());
335 
337  int i = 0, j = 0;
338  for (itHit = MuonDTContainer->begin(); itHit != MuonDTContainer->end(); ++itHit) {
339  ++i;
340 
342  DetId theDetUnitId(itHit->detUnitId());
343  int detector = theDetUnitId.det();
344  int subdetector = theDetUnitId.subdetId();
345 
347  if ((detector == dMuon) && (subdetector == sdMuonDT)) {
349  const GeomDetUnit* theDet = theDTMuon.idToDetUnit(theDetUnitId);
350 
351  if (!theDet) {
352  edm::LogWarning("MuonSimHitsValidAnalyzer::fillDT") << "Unable to get GeomDetUnit from theDTMuon for hit " << i;
353  continue;
354  }
355 
356  ++j;
357 
359  const BoundPlane& bsurf = theDet->surface();
360 
362 
363  if (abs(itHit->particleType()) == 13) {
364  nummu_DT++;
365  meToF->Fill(itHit->tof());
366  meEnergyLoss->Fill(itHit->energyLoss() * pow6);
367 
368  iden = itHit->detUnitId();
369 
370  wheel = ((iden >> 15) & 0x7) - 3;
371  station = ((iden >> 22) & 0x7);
372  sector = ((iden >> 18) & 0xf);
373  superlayer = ((iden >> 13) & 0x3);
374  layer = ((iden >> 10) & 0x7);
375  wire = ((iden >> 3) & 0x7f);
376 
377  meWheelOccup->Fill((float)wheel);
378  meStationOccup->Fill((float)station);
379  meSectorOccup->Fill((float)sector);
380  meSuperLOccup->Fill((float)superlayer);
381  meLayerOccup->Fill((float)layer);
382  meWireOccup->Fill((float)wire);
383 
384  // Define a quantity to take into account station, splayer and layer being hit.
385  path = (station - 1) * 40 + superlayer * 10 + layer;
386  mePathMuon->Fill((float)path);
387 
388  // Define a quantity to take into chamber being hit.
389  pathchamber = (wheel + 2) * 50 + (station - 1) * 12 + sector;
391 
393  if (station == 1) {
394  if (touch1 == 0) {
395  mom1 = itHit->pabs();
397  touch1 = 1;
398  }
399  }
400 
402  if (station == 4) {
403  if (touch4 == 0) {
404  mom4 = itHit->pabs();
405  touch4 = 1;
407  if (touch1 == 1) {
409  }
410  }
411  }
412 
414  meLocalXvsZ->Fill(itHit->localPosition().x(), itHit->localPosition().z());
415 
417  meLocalXvsY->Fill(itHit->localPosition().x(), itHit->localPosition().y());
418 
420 
421  globposz = bsurf.toGlobal(itHit->localPosition()).z();
422  globposeta = bsurf.toGlobal(itHit->localPosition()).eta();
423  globposphi = bsurf.toGlobal(itHit->localPosition()).phi();
424 
425  radius = globposz * (1. + exp(-2. * globposeta)) / (1. - exp(-2. * globposeta));
426 
427  costeta = (1. - exp(-2. * globposeta)) / (1. + exp(-2. * globposeta));
428  sinteta = 2. * exp(-globposeta) / (1. + exp(-2. * globposeta));
429 
434 
437 
438  // New Histos
439  if (wheel == -2) {
442  }
443  if (wheel == -1) {
446  }
447  if (wheel == 0) {
450  }
451  if (wheel == 1) {
454  }
455  if (wheel == 2) {
458  }
459  //
461  meCosTheta->Fill(costeta);
464  }
465  } else {
466  edm::LogWarning("MuonSimHitsValidAnalyzer::fillDT")
467  << "MuonDT PSimHit " << i << " is expected to be (det,subdet) = (" << dMuon << "," << sdMuonDT
468  << "); value returned is: (" << detector << "," << subdetector << ")";
469  continue;
470  }
471  }
472 
473  if (verbosity > 1) {
474  eventout += "\n Number of DT muon Hits collected:......... ";
475  eventout += j;
476  }
477  meMuDTHits->Fill((float)nummu_DT);
478 
479  if (verbosity > 0)
480  edm::LogInfo("MuonSimHitsValidAnalyzer::fillDT") << eventout << "\n";
481  return;
482 }
RunNumber_t run() const
Definition: EventID.h:38
MonitorElement * book1D(TString const &name, TString const &title, int const nchX, double const lowX, double const highX)
Definition: DQMStore.cc:239
T getParameter(std::string const &) const
EventNumber_t event() const
Definition: EventID.h:40
T getUntrackedParameter(std::string const &, T const &) const
static const int sdMuonDT
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:525
TString subdetector
void setCurrentFolder(std::string const &fullpath)
Definition: DQMStore.cc:418
Sin< T >::type sin(const T &t)
Definition: Sin.h:22
unsigned long long EventNumber_t
edm::EDGetTokenT< edm::PSimHitContainer > DTHitsToken_
Input tags.
const Plane & surface() const
The nominal surface of the GeomDet.
Definition: GeomDet.h:37
void Fill(long long x)
char const * label
int iEvent
Definition: GenABIO.cc:224
const GeomDet * idToDetUnit(DetId) const override
Return the pointer to the GeomDetUnit corresponding to a given DetId.
Definition: DTGeometry.cc:75
Cos< T >::type cos(const T &t)
Definition: Cos.h:22
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
bool isValid() const
Definition: HandleBase.h:70
char const * module
Definition: ProductLabels.h:5
Definition: DetId.h:17
MuonSimHitsValidAnalyzer(const edm::ParameterSet &)
std::string fName
parameter information
void labelsForToken(EDGetToken iToken, Labels &oLabels) const
edm::EventID id() const
Definition: EventBase.h:59
char const * productInstance
Definition: ProductLabels.h:6
static const int dMuon
HLT enums.
MonitorElement * book2D(TString const &name, TString const &title, int nchX, double lowX, double highX, int nchY, double lowY, double highY)
Definition: DQMStore.cc:266
T get() const
Definition: EventSetup.h:73
void analyze(const edm::Event &, const edm::EventSetup &) override
void bookHistograms(DQMStore::IBooker &, edm::Run const &, edm::EventSetup const &) override
unsigned int RunNumber_t
bool isValid() const
Definition: ESHandle.h:44
unsigned int count
private statistics information
Definition: Run.h:45
void fillDT(const edm::Event &, const edm::EventSetup &)
void getAllStableProvenance(std::vector< StableProvenance const * > &provenances) const
Definition: Event.cc:126