CMS 3D CMS Logo

GlobalRecHitsAnalyzer.cc
Go to the documentation of this file.
1 
14 using namespace std;
15 
17  : fName(""),
18  verbosity(0),
19  frequency(0),
20  label(""),
21  getAllProvenances(false),
22  printProvenanceInfo(false),
23  trackerHitAssociatorConfig_(iPSet, consumesCollector()),
24  caloGeomToken_(esConsumes()),
25  tTopoToken_(esConsumes()),
26  tGeomToken_(esConsumes()),
27  dtGeomToken_(esConsumes()),
28  cscGeomToken_(esConsumes()),
29  rpcGeomToken_(esConsumes()),
30  count(0) {
31  consumesMany<edm::SortedCollection<HBHERecHit, edm::StrictWeakOrdering<HBHERecHit>>>();
32  consumesMany<edm::SortedCollection<HFRecHit, edm::StrictWeakOrdering<HFRecHit>>>();
33  consumesMany<edm::SortedCollection<HORecHit, edm::StrictWeakOrdering<HORecHit>>>();
34  std::string MsgLoggerCat = "GlobalRecHitsAnalyzer_GlobalRecHitsAnalyzer";
35 
36  // get information from parameter set
37  fName = iPSet.getUntrackedParameter<std::string>("Name");
38  verbosity = iPSet.getUntrackedParameter<int>("Verbosity");
39  frequency = iPSet.getUntrackedParameter<int>("Frequency");
40  edm::ParameterSet m_Prov = iPSet.getParameter<edm::ParameterSet>("ProvenanceLookup");
41  getAllProvenances = m_Prov.getUntrackedParameter<bool>("GetAllProvenances");
42  printProvenanceInfo = m_Prov.getUntrackedParameter<bool>("PrintProvenanceInfo");
43  hitsProducer = iPSet.getParameter<std::string>("hitsProducer");
44 
45  //get Labels to use to extract information
46  ECalEBSrc_ = iPSet.getParameter<edm::InputTag>("ECalEBSrc");
47  ECalUncalEBSrc_ = iPSet.getParameter<edm::InputTag>("ECalUncalEBSrc");
48  ECalEESrc_ = iPSet.getParameter<edm::InputTag>("ECalEESrc");
49  ECalUncalEESrc_ = iPSet.getParameter<edm::InputTag>("ECalUncalEESrc");
50  ECalESSrc_ = iPSet.getParameter<edm::InputTag>("ECalESSrc");
51  HCalSrc_ = iPSet.getParameter<edm::InputTag>("HCalSrc");
52  SiStripSrc_ = iPSet.getParameter<edm::InputTag>("SiStripSrc");
53  SiPxlSrc_ = iPSet.getParameter<edm::InputTag>("SiPxlSrc");
54  MuDTSrc_ = iPSet.getParameter<edm::InputTag>("MuDTSrc");
55  MuDTSimSrc_ = iPSet.getParameter<edm::InputTag>("MuDTSimSrc");
56  MuCSCSrc_ = iPSet.getParameter<edm::InputTag>("MuCSCSrc");
57  MuRPCSrc_ = iPSet.getParameter<edm::InputTag>("MuRPCSrc");
58  MuRPCSimSrc_ = iPSet.getParameter<edm::InputTag>("MuRPCSimSrc");
59 
60  // fix for consumes
61  ECalUncalEBSrc_Token_ = consumes<EBUncalibratedRecHitCollection>(iPSet.getParameter<edm::InputTag>("ECalUncalEBSrc"));
62  ECalUncalEESrc_Token_ = consumes<EEUncalibratedRecHitCollection>(iPSet.getParameter<edm::InputTag>("ECalUncalEESrc"));
63  ECalEBSrc_Token_ = consumes<EBRecHitCollection>(iPSet.getParameter<edm::InputTag>("ECalEBSrc"));
64  ECalEESrc_Token_ = consumes<EERecHitCollection>(iPSet.getParameter<edm::InputTag>("ECalEESrc"));
65  ECalESSrc_Token_ = consumes<ESRecHitCollection>(iPSet.getParameter<edm::InputTag>("ECalESSrc"));
66  HCalSrc_Token_ = consumes<edm::PCaloHitContainer>(iPSet.getParameter<edm::InputTag>("HCalSrc"));
67  SiStripSrc_Token_ = consumes<SiStripMatchedRecHit2DCollection>(iPSet.getParameter<edm::InputTag>("SiStripSrc"));
68  SiPxlSrc_Token_ = consumes<SiPixelRecHitCollection>(iPSet.getParameter<edm::InputTag>("SiPxlSrc"));
69 
70  MuDTSrc_Token_ = consumes<DTRecHitCollection>(iPSet.getParameter<edm::InputTag>("MuDTSrc"));
71  MuDTSimSrc_Token_ = consumes<edm::PSimHitContainer>(iPSet.getParameter<edm::InputTag>("MuDTSimSrc"));
72 
73  MuCSCSrc_Token_ = consumes<CSCRecHit2DCollection>(iPSet.getParameter<edm::InputTag>("MuCSCSrc"));
74  MuCSCHits_Token_ = consumes<CrossingFrame<PSimHit>>(
75  edm::InputTag(std::string("mix"), iPSet.getParameter<std::string>("hitsProducer") + std::string("MuonCSCHits")));
76 
77  MuRPCSrc_Token_ = consumes<RPCRecHitCollection>(iPSet.getParameter<edm::InputTag>("MuRPCSrc"));
78  MuRPCSimSrc_Token_ = consumes<edm::PSimHitContainer>(iPSet.getParameter<edm::InputTag>("MuRPCSimSrc"));
79 
80  EBHits_Token_ = consumes<CrossingFrame<PCaloHit>>(
81  edm::InputTag(std::string("mix"), iPSet.getParameter<std::string>("hitsProducer") + std::string("EcalHitsEB")));
82  EEHits_Token_ = consumes<CrossingFrame<PCaloHit>>(
83  edm::InputTag(std::string("mix"), iPSet.getParameter<std::string>("hitsProducer") + std::string("EcalHitsEE")));
84  ESHits_Token_ = consumes<CrossingFrame<PCaloHit>>(
85  edm::InputTag(std::string("mix"), iPSet.getParameter<std::string>("hitsProducer") + std::string("EcalHitsES")));
86 
87  // use value of first digit to determine default output level (inclusive)
88  // 0 is none, 1 is basic, 2 is fill output, 3 is gather output
89  verbosity %= 10;
90 
91  // create persistent object
92  // produces<PGlobalRecHit>(label);
93 
94  // print out Parameter Set information being used
95  if (verbosity >= 0) {
96  edm::LogInfo(MsgLoggerCat) << "\n===============================\n"
97  << "Initialized as EDProducer with parameter values:\n"
98  << " Name = " << fName << "\n"
99  << " Verbosity = " << verbosity << "\n"
100  << " Frequency = " << frequency << "\n"
101  << " GetProv = " << getAllProvenances << "\n"
102  << " PrintProv = " << printProvenanceInfo << "\n"
103  << " ECalEBSrc = " << ECalEBSrc_.label() << ":" << ECalEBSrc_.instance() << "\n"
104  << " ECalUncalEBSrc = " << ECalUncalEBSrc_.label() << ":"
105  << ECalUncalEBSrc_.instance() << "\n"
106  << " ECalEESrc = " << ECalEESrc_.label() << ":" << ECalUncalEESrc_.instance()
107  << "\n"
108  << " ECalUncalEESrc = " << ECalUncalEESrc_.label() << ":" << ECalEESrc_.instance()
109  << "\n"
110  << " ECalESSrc = " << ECalESSrc_.label() << ":" << ECalESSrc_.instance() << "\n"
111  << " HCalSrc = " << HCalSrc_.label() << ":" << HCalSrc_.instance() << "\n"
112  << " SiStripSrc = " << SiStripSrc_.label() << ":" << SiStripSrc_.instance()
113  << "\n"
114  << " SiPixelSrc = " << SiPxlSrc_.label() << ":" << SiPxlSrc_.instance() << "\n"
115  << " MuDTSrc = " << MuDTSrc_.label() << ":" << MuDTSrc_.instance() << "\n"
116  << " MuDTSimSrc = " << MuDTSimSrc_.label() << ":" << MuDTSimSrc_.instance()
117  << "\n"
118  << " MuCSCSrc = " << MuCSCSrc_.label() << ":" << MuCSCSrc_.instance() << "\n"
119  << " MuRPCSrc = " << MuRPCSrc_.label() << ":" << MuRPCSrc_.instance() << "\n"
120  << " MuRPCSimSrc = " << MuRPCSimSrc_.label() << ":" << MuRPCSimSrc_.instance()
121  << "\n"
122  << "===============================\n";
123  }
124 }
125 
127 
129  // Si Strip
130  string SiStripString[19] = {"TECW1",
131  "TECW2",
132  "TECW3",
133  "TECW4",
134  "TECW5",
135  "TECW6",
136  "TECW7",
137  "TECW8",
138  "TIBL1",
139  "TIBL2",
140  "TIBL3",
141  "TIBL4",
142  "TIDW1",
143  "TIDW2",
144  "TIDW3",
145  "TOBL1",
146  "TOBL2",
147  "TOBL3",
148  "TOBL4"};
149  for (int i = 0; i < 19; ++i) {
150  mehSiStripn[i] = nullptr;
151  mehSiStripResX[i] = nullptr;
152  mehSiStripResY[i] = nullptr;
153  }
154  string hcharname, hchartitle;
155  iBooker.setCurrentFolder("GlobalRecHitsV/SiStrips");
156  for (int amend = 0; amend < 19; ++amend) {
157  hcharname = "hSiStripn_" + SiStripString[amend];
158  hchartitle = SiStripString[amend] + " rechits";
159  mehSiStripn[amend] = iBooker.book1D(hcharname, hchartitle, 200, 0., 200.);
160  mehSiStripn[amend]->setAxisTitle("Number of hits in " + SiStripString[amend], 1);
161  mehSiStripn[amend]->setAxisTitle("Count", 2);
162  hcharname = "hSiStripResX_" + SiStripString[amend];
163  hchartitle = SiStripString[amend] + " rechit x resolution";
164  mehSiStripResX[amend] = iBooker.book1D(hcharname, hchartitle, 200, -0.02, .02);
165  mehSiStripResX[amend]->setAxisTitle("X-resolution in " + SiStripString[amend], 1);
166  mehSiStripResX[amend]->setAxisTitle("Count", 2);
167  hcharname = "hSiStripResY_" + SiStripString[amend];
168  hchartitle = SiStripString[amend] + " rechit y resolution";
169  mehSiStripResY[amend] = iBooker.book1D(hcharname, hchartitle, 200, -0.02, .02);
170  mehSiStripResY[amend]->setAxisTitle("Y-resolution in " + SiStripString[amend], 1);
171  mehSiStripResY[amend]->setAxisTitle("Count", 2);
172  }
173 
174  //HCal
175  //string hcharname, hchartitle;
176  string HCalString[4] = {"HB", "HE", "HF", "HO"};
177  float HCalnUpper[4] = {3000., 3000., 3000., 3000.};
178  float HCalnLower[4] = {0., 0., 0., 0.};
179  for (int j = 0; j < 4; ++j) {
180  mehHcaln[j] = nullptr;
181  mehHcalRes[j] = nullptr;
182  }
183 
184  iBooker.setCurrentFolder("GlobalRecHitsV/HCals");
185  for (int amend = 0; amend < 4; ++amend) {
186  hcharname = "hHcaln_" + HCalString[amend];
187  hchartitle = HCalString[amend] + " rechits";
188  mehHcaln[amend] = iBooker.book1D(hcharname, hchartitle, 1000, HCalnLower[amend], HCalnUpper[amend]);
189  mehHcaln[amend]->setAxisTitle("Number of RecHits", 1);
190  mehHcaln[amend]->setAxisTitle("Count", 2);
191  hcharname = "hHcalRes_" + HCalString[amend];
192  hchartitle = HCalString[amend] + " rechit resolution";
193  mehHcalRes[amend] = iBooker.book1D(hcharname, hchartitle, 25, -2., 2.);
194  mehHcalRes[amend]->setAxisTitle("RecHit E - SimHit E", 1);
195  mehHcalRes[amend]->setAxisTitle("Count", 2);
196  }
197 
198  //Ecal
199  string ECalString[3] = {"EB", "EE", "ES"};
200  int ECalnBins[3] = {1000, 3000, 150};
201  float ECalnUpper[3] = {20000., 62000., 3000.};
202  float ECalnLower[3] = {0., 0., 0.};
203  int ECalResBins[3] = {200, 200, 200};
204  float ECalResUpper[3] = {1., 0.3, .0002};
205  float ECalResLower[3] = {-1., -0.3, -.0002};
206  for (int i = 0; i < 3; ++i) {
207  mehEcaln[i] = nullptr;
208  mehEcalRes[i] = nullptr;
209  }
210  iBooker.setCurrentFolder("GlobalRecHitsV/ECals");
211 
212  for (int amend = 0; amend < 3; ++amend) {
213  hcharname = "hEcaln_" + ECalString[amend];
214  hchartitle = ECalString[amend] + " rechits";
215  mehEcaln[amend] = iBooker.book1D(hcharname, hchartitle, ECalnBins[amend], ECalnLower[amend], ECalnUpper[amend]);
216  mehEcaln[amend]->setAxisTitle("Number of RecHits", 1);
217  mehEcaln[amend]->setAxisTitle("Count", 2);
218  hcharname = "hEcalRes_" + ECalString[amend];
219  hchartitle = ECalString[amend] + " rechit resolution";
220  mehEcalRes[amend] =
221  iBooker.book1D(hcharname, hchartitle, ECalResBins[amend], ECalResLower[amend], ECalResUpper[amend]);
222  mehEcalRes[amend]->setAxisTitle("RecHit E - SimHit E", 1);
223  mehEcalRes[amend]->setAxisTitle("Count", 2);
224  }
225 
226  //Si Pixels
227  string SiPixelString[7] = {"BRL1", "BRL2", "BRL3", "FWD1n", "FWD1p", "FWD2n", "FWD2p"};
228  for (int j = 0; j < 7; ++j) {
229  mehSiPixeln[j] = nullptr;
230  mehSiPixelResX[j] = nullptr;
231  mehSiPixelResY[j] = nullptr;
232  }
233 
234  iBooker.setCurrentFolder("GlobalRecHitsV/SiPixels");
235  for (int amend = 0; amend < 7; ++amend) {
236  hcharname = "hSiPixeln_" + SiPixelString[amend];
237  hchartitle = SiPixelString[amend] + " rechits";
238  mehSiPixeln[amend] = iBooker.book1D(hcharname, hchartitle, 200, 0., 200.);
239  mehSiPixeln[amend]->setAxisTitle("Number of hits in " + SiPixelString[amend], 1);
240  mehSiPixeln[amend]->setAxisTitle("Count", 2);
241  hcharname = "hSiPixelResX_" + SiPixelString[amend];
242  hchartitle = SiPixelString[amend] + " rechit x resolution";
243  mehSiPixelResX[amend] = iBooker.book1D(hcharname, hchartitle, 200, -0.02, .02);
244  mehSiPixelResX[amend]->setAxisTitle("X-resolution in " + SiPixelString[amend], 1);
245  mehSiPixelResX[amend]->setAxisTitle("Count", 2);
246  hcharname = "hSiPixelResY_" + SiPixelString[amend];
247  hchartitle = SiPixelString[amend] + " rechit y resolution";
248 
249  mehSiPixelResY[amend] = iBooker.book1D(hcharname, hchartitle, 200, -0.02, .02);
250  mehSiPixelResY[amend]->setAxisTitle("Y-resolution in " + SiPixelString[amend], 1);
251  mehSiPixelResY[amend]->setAxisTitle("Count", 2);
252  }
253 
254  //Muons
255  iBooker.setCurrentFolder("GlobalRecHitsV/Muons");
256 
257  mehDtMuonn = nullptr;
258  mehCSCn = nullptr;
259  mehRPCn = nullptr;
260 
261  string n_List[3] = {"hDtMuonn", "hCSCn", "hRPCn"};
262  string hist_string[3] = {"Dt", "CSC", "RPC"};
263 
264  for (int amend = 0; amend < 3; ++amend) {
265  hchartitle = hist_string[amend] + " rechits";
266  if (amend == 0) {
267  mehDtMuonn = iBooker.book1D(n_List[amend], hchartitle, 50, 0., 500.);
268  mehDtMuonn->setAxisTitle("Number of Rechits", 1);
269  mehDtMuonn->setAxisTitle("Count", 2);
270  }
271  if (amend == 1) {
272  mehCSCn = iBooker.book1D(n_List[amend], hchartitle, 50, 0., 500.);
273  mehCSCn->setAxisTitle("Number of Rechits", 1);
274  mehCSCn->setAxisTitle("Count", 2);
275  }
276  if (amend == 2) {
277  mehRPCn = iBooker.book1D(n_List[amend], hchartitle, 50, 0., 500.);
278  mehRPCn->setAxisTitle("Number of Rechits", 1);
279  mehRPCn->setAxisTitle("Count", 2);
280  }
281  }
282 
283  mehDtMuonRes = nullptr;
284  mehCSCResRDPhi = nullptr;
285  mehRPCResX = nullptr;
286 
287  hcharname = "hDtMuonRes";
288  hchartitle = "DT wire distance resolution";
289  mehDtMuonRes = iBooker.book1D(hcharname, hchartitle, 200, -0.2, 0.2);
290  hcharname = "CSCResRDPhi";
291  hchartitle = "CSC perp*dphi resolution";
292  mehCSCResRDPhi = iBooker.book1D(hcharname, hchartitle, 200, -0.2, 0.2);
293  hcharname = "hRPCResX";
294  hchartitle = "RPC rechits x resolution";
295  mehRPCResX = iBooker.book1D(hcharname, hchartitle, 50, -5., 5.);
296 }
297 
299  std::string MsgLoggerCat = "GlobalRecHitsAnalyzer_analyze";
300 
301  // keep track of number of events processed
302  ++count;
303 
304  // get event id information
305  edm::RunNumber_t nrun = iEvent.id().run();
306  edm::EventNumber_t nevt = iEvent.id().event();
307 
308  if (verbosity > 0) {
309  edm::LogInfo(MsgLoggerCat) << "Processing run " << nrun << ", event " << nevt << " (" << count << " events total)";
310  } else if (verbosity == 0) {
311  if (nevt % frequency == 0 || nevt == 1) {
312  edm::LogInfo(MsgLoggerCat) << "Processing run " << nrun << ", event " << nevt << " (" << count
313  << " events total)";
314  }
315  }
316 
317  // look at information available in the event
318  if (getAllProvenances) {
319  std::vector<const edm::StableProvenance*> AllProv;
320  iEvent.getAllStableProvenance(AllProv);
321 
322  if (verbosity >= 0)
323  edm::LogInfo(MsgLoggerCat) << "Number of Provenances = " << AllProv.size();
324 
325  if (printProvenanceInfo && (verbosity >= 0)) {
326  TString eventout("\nProvenance info:\n");
327 
328  for (unsigned int i = 0; i < AllProv.size(); ++i) {
329  eventout += "\n ******************************";
330  eventout += "\n Module : ";
331  eventout += AllProv[i]->moduleLabel();
332  eventout += "\n ProductID : ";
333  eventout += AllProv[i]->productID().id();
334  eventout += "\n ClassName : ";
335  eventout += AllProv[i]->className();
336  eventout += "\n InstanceName : ";
337  eventout += AllProv[i]->productInstanceName();
338  eventout += "\n BranchName : ";
339  eventout += AllProv[i]->branchName();
340  }
341  eventout += "\n ******************************\n";
342  edm::LogInfo(MsgLoggerCat) << eventout << "\n";
343  printProvenanceInfo = false;
344  }
345  getAllProvenances = false;
346  }
347 
348  // call fill functions
349  // gather Ecal information from event
350  fillECal(iEvent, iSetup);
351  // gather Hcal information from event
352  fillHCal(iEvent, iSetup);
353  // gather Track information from event
354  fillTrk(iEvent, iSetup);
355  // gather Muon information from event
356  fillMuon(iEvent, iSetup);
357 
358  if (verbosity > 0)
359  edm::LogInfo(MsgLoggerCat) << "Done gathering data from event.";
360 
361  return;
362 }
363 
365  std::string MsgLoggerCat = "GlobalRecHitsAnalyzer_fillECal";
366 
367  TString eventout;
368  if (verbosity > 0)
369  eventout = "\nGathering info:";
370 
371  // extract crossing frame from event
373 
375  //extract EB information
378  iEvent.getByToken(ECalUncalEBSrc_Token_, EcalUncalibRecHitEB);
379  bool validUncalibRecHitEB = EcalUncalibRecHitEB.isValid();
380  if (!validUncalibRecHitEB) {
381  LogDebug(MsgLoggerCat) << "Unable to find EcalUncalRecHitEB in event!";
382  }
383 
384  edm::Handle<EBRecHitCollection> EcalRecHitEB;
385  iEvent.getByToken(ECalEBSrc_Token_, EcalRecHitEB);
386  bool validRecHitEB = EcalRecHitEB.isValid();
387  if (!validRecHitEB) {
388  LogDebug(MsgLoggerCat) << "Unable to find EcalRecHitEB in event!";
389  }
390 
391  // loop over simhits
392  iEvent.getByToken(EBHits_Token_, crossingFrame);
393  bool validXFrame = crossingFrame.isValid();
394  if (!validXFrame) {
395  LogDebug(MsgLoggerCat) << "Unable to find cal barrel crossingFrame in event!";
396  }
397 
398  MapType ebSimMap;
399  if (validXFrame) {
400  const MixCollection<PCaloHit> barrelHits(crossingFrame.product());
401  // keep track of sum of simhit energy in each crystal
402  for (auto const& iHit : barrelHits) {
403  EBDetId ebid = EBDetId(iHit.id());
404 
405  uint32_t crystid = ebid.rawId();
406  ebSimMap[crystid] += iHit.energy();
407  }
408  }
409 
410  int nEBRecHits = 0;
411  // loop over RecHits
412  if (validUncalibRecHitEB && validRecHitEB) {
413  const EBUncalibratedRecHitCollection* EBUncalibRecHit = EcalUncalibRecHitEB.product();
414  const EBRecHitCollection* EBRecHit = EcalRecHitEB.product();
415 
417  uncalibRecHit != EBUncalibRecHit->end();
418  ++uncalibRecHit) {
419  EBDetId EBid = EBDetId(uncalibRecHit->id());
420 
421  EcalRecHitCollection::const_iterator myRecHit = EBRecHit->find(EBid);
422 
423  if (myRecHit != EBRecHit->end()) {
424  ++nEBRecHits;
425  mehEcalRes[1]->Fill(myRecHit->energy() - ebSimMap[EBid.rawId()]);
426  }
427  }
428 
429  if (verbosity > 1) {
430  eventout += "\n Number of EBRecHits collected:............ ";
431  eventout += nEBRecHits;
432  }
433  mehEcaln[1]->Fill((float)nEBRecHits);
434  }
435 
437  //extract EE information
440  iEvent.getByToken(ECalUncalEESrc_Token_, EcalUncalibRecHitEE);
441  bool validuncalibRecHitEE = EcalUncalibRecHitEE.isValid();
442  if (!validuncalibRecHitEE) {
443  LogDebug(MsgLoggerCat) << "Unable to find EcalUncalRecHitEE in event!";
444  }
445 
446  edm::Handle<EERecHitCollection> EcalRecHitEE;
447  iEvent.getByToken(ECalEESrc_Token_, EcalRecHitEE);
448  bool validRecHitEE = EcalRecHitEE.isValid();
449  if (!validRecHitEE) {
450  LogDebug(MsgLoggerCat) << "Unable to find EcalRecHitEE in event!";
451  }
452 
453  // loop over simhits
454  iEvent.getByToken(EEHits_Token_, crossingFrame);
455  validXFrame = crossingFrame.isValid();
456  if (!validXFrame) {
457  LogDebug(MsgLoggerCat) << "Unable to find cal endcap crossingFrame in event!";
458  }
459 
460  MapType eeSimMap;
461  if (validXFrame) {
462  const MixCollection<PCaloHit> endcapHits(crossingFrame.product());
463  // keep track of sum of simhit energy in each crystal
464  for (auto const& iHit : endcapHits) {
465  EEDetId eeid = EEDetId(iHit.id());
466 
467  uint32_t crystid = eeid.rawId();
468  eeSimMap[crystid] += iHit.energy();
469  }
470  }
471 
472  int nEERecHits = 0;
473  if (validuncalibRecHitEE && validRecHitEE) {
474  // loop over RecHits
475  const EEUncalibratedRecHitCollection* EEUncalibRecHit = EcalUncalibRecHitEE.product();
476  const EERecHitCollection* EERecHit = EcalRecHitEE.product();
477 
479  uncalibRecHit != EEUncalibRecHit->end();
480  ++uncalibRecHit) {
481  EEDetId EEid = EEDetId(uncalibRecHit->id());
482 
483  EcalRecHitCollection::const_iterator myRecHit = EERecHit->find(EEid);
484 
485  if (myRecHit != EERecHit->end()) {
486  ++nEERecHits;
487  mehEcalRes[0]->Fill(myRecHit->energy() - eeSimMap[EEid.rawId()]);
488  }
489  }
490 
491  if (verbosity > 1) {
492  eventout += "\n Number of EERecHits collected:............ ";
493  eventout += nEERecHits;
494  }
495  mehEcaln[0]->Fill((float)nEERecHits);
496  }
497 
499  //extract ES information
501  edm::Handle<ESRecHitCollection> EcalRecHitES;
502  iEvent.getByToken(ECalESSrc_Token_, EcalRecHitES);
503  bool validRecHitES = EcalRecHitES.isValid();
504  if (!validRecHitES) {
505  LogDebug(MsgLoggerCat) << "Unable to find EcalRecHitES in event!";
506  }
507 
508  // loop over simhits
509  iEvent.getByToken(ESHits_Token_, crossingFrame);
510  validXFrame = crossingFrame.isValid();
511  if (!validXFrame) {
512  LogDebug(MsgLoggerCat) << "Unable to find cal preshower crossingFrame in event!";
513  }
514 
515  MapType esSimMap;
516  if (validXFrame) {
517  const MixCollection<PCaloHit> preshowerHits(crossingFrame.product());
518  // keep track of sum of simhit energy in each crystal
519  for (auto const& iHit : preshowerHits) {
520  ESDetId esid = ESDetId(iHit.id());
521 
522  uint32_t crystid = esid.rawId();
523  esSimMap[crystid] += iHit.energy();
524  }
525  }
526 
527  int nESRecHits = 0;
528  if (validRecHitES) {
529  // loop over RecHits
530  const ESRecHitCollection* ESRecHit = EcalRecHitES.product();
531  for (EcalRecHitCollection::const_iterator recHit = ESRecHit->begin(); recHit != ESRecHit->end(); ++recHit) {
532  ESDetId ESid = ESDetId(recHit->id());
533 
534  ++nESRecHits;
535  mehEcalRes[2]->Fill(recHit->energy() - esSimMap[ESid.rawId()]);
536  }
537 
538  if (verbosity > 1) {
539  eventout += "\n Number of ESRecHits collected:............ ";
540  eventout += nESRecHits;
541  }
542  mehEcaln[2]->Fill(float(nESRecHits));
543  }
544 
545  if (verbosity > 0)
546  edm::LogInfo(MsgLoggerCat) << eventout << "\n";
547 
548  return;
549 }
550 
552  std::string MsgLoggerCat = "GlobalRecHitsAnalyzer_fillHCal";
553 
554  TString eventout;
555  if (verbosity > 0)
556  eventout = "\nGathering info:";
557 
558  // get geometry
559  const auto& geometry = iSetup.getHandle(caloGeomToken_);
560  if (!geometry.isValid()) {
561  edm::LogWarning(MsgLoggerCat) << "Unable to find CaloGeometry in event!";
562  return;
563  }
564 
566  // extract simhit info
569  iEvent.getByToken(HCalSrc_Token_, hcalHits);
570  bool validhcalHits = hcalHits.isValid();
571  if (!validhcalHits) {
572  LogDebug(MsgLoggerCat) << "Unable to find hcalHits in event!";
573  }
574 
575  std::map<HcalDetId, float> fHBEnergySimHits;
576  std::map<HcalDetId, float> fHEEnergySimHits;
577  std::map<HcalDetId, float> fHOEnergySimHits;
578  std::map<HcalDetId, float> fHFEnergySimHits;
579  if (validhcalHits) {
580  const edm::PCaloHitContainer* simhitResult = hcalHits.product();
581 
582  for (std::vector<PCaloHit>::const_iterator simhits = simhitResult->begin(); simhits != simhitResult->end();
583  ++simhits) {
584  HcalDetId detId(simhits->id());
585 
586  if (detId.subdet() == sdHcalBrl) {
587  fHBEnergySimHits[detId] += simhits->energy();
588  }
589  if (detId.subdet() == sdHcalEC) {
590  fHEEnergySimHits[detId] += simhits->energy();
591  }
592  if (detId.subdet() == sdHcalOut) {
593  fHOEnergySimHits[detId] += simhits->energy();
594  }
595  if (detId.subdet() == sdHcalFwd) {
596  fHFEnergySimHits[detId] += simhits->energy();
597  }
598  }
599  }
600 
602  // get HBHE information
604  std::vector<edm::Handle<HBHERecHitCollection>> hbhe;
605  iEvent.getManyByType(hbhe);
606 
607  bool validHBHE = hbhe[0].isValid();
608 
609  if (!validHBHE) {
610  LogDebug(MsgLoggerCat) << "Unable to find any HBHERecHitCollections in event!";
611  }
612 
613  else {
614  std::vector<edm::Handle<HBHERecHitCollection>>::iterator ihbhe;
615  int iHB = 0;
616  int iHE = 0;
617  for (ihbhe = hbhe.begin(); ihbhe != hbhe.end(); ++ihbhe) {
618  for (HBHERecHitCollection::const_iterator jhbhe = (*ihbhe)->begin(); jhbhe != (*ihbhe)->end(); ++jhbhe) {
619  HcalDetId cell(jhbhe->id());
620 
621  if (cell.subdet() == sdHcalBrl) {
622  ++iHB;
623  mehHcalRes[0]->Fill(jhbhe->energy() - fHBEnergySimHits[cell]);
624  }
625 
626  else if (cell.subdet() == sdHcalEC) {
627  ++iHE;
628  mehHcalRes[1]->Fill(jhbhe->energy() - fHEEnergySimHits[cell]);
629  }
630  }
631  } // end loop through collection
632 
633  if (verbosity > 1) {
634  eventout += "\n Number of HBRecHits collected:............ ";
635  eventout += iHB;
636  }
637 
638  if (verbosity > 1) {
639  eventout += "\n Number of HERecHits collected:............ ";
640  eventout += iHE;
641  }
642  mehHcaln[0]->Fill((float)iHB);
643  mehHcaln[1]->Fill((float)iHE);
644  }
645 
647  // get HF information
649  std::vector<edm::Handle<HFRecHitCollection>> hf;
650  iEvent.getManyByType(hf);
651  bool validHF = hf[0].isValid();
652  if (!validHF) {
653  LogDebug(MsgLoggerCat) << "Unable to find any HFRecHitCollections in event!";
654  } else {
655  std::vector<edm::Handle<HFRecHitCollection>>::iterator ihf;
656 
657  int iHF = 0;
658  for (ihf = hf.begin(); ihf != hf.end(); ++ihf) {
659  for (HFRecHitCollection::const_iterator jhf = (*ihf)->begin(); jhf != (*ihf)->end(); ++jhf) {
660  HcalDetId cell(jhf->id());
661 
662  if (cell.subdet() == sdHcalFwd) {
663  ++iHF;
664  mehHcalRes[2]->Fill(jhf->energy() - fHFEnergySimHits[cell]);
665  }
666  }
667  } // end loop through collection
668 
669  if (verbosity > 1) {
670  eventout += "\n Number of HFDigis collected:.............. ";
671  eventout += iHF;
672  }
673  mehHcaln[2]->Fill((float)iHF);
674  }
675 
677  // get HO information
679  std::vector<edm::Handle<HORecHitCollection>> ho;
680  iEvent.getManyByType(ho);
681  bool validHO = ho[0].isValid();
682  if (!validHO) {
683  LogDebug(MsgLoggerCat) << "Unable to find any HORecHitCollections in event!";
684  } else {
685  std::vector<edm::Handle<HORecHitCollection>>::iterator iho;
686 
687  int iHO = 0;
688  for (iho = ho.begin(); iho != ho.end(); ++iho) {
689  for (HORecHitCollection::const_iterator jho = (*iho)->begin(); jho != (*iho)->end(); ++jho) {
690  HcalDetId cell(jho->id());
691 
692  if (cell.subdet() == sdHcalOut) {
693  ++iHO;
694  mehHcalRes[3]->Fill(jho->energy() - fHOEnergySimHits[cell]);
695  }
696  }
697  } // end loop through collection
698 
699  if (verbosity > 1) {
700  eventout += "\n Number of HODigis collected:.............. ";
701  eventout += iHO;
702  }
703  mehHcaln[3]->Fill((float)iHO);
704  }
705 
706  if (verbosity > 0)
707  edm::LogInfo(MsgLoggerCat) << eventout << "\n";
708 
709  return;
710 }
711 
713  //Retrieve tracker topology from geometry
714  const TrackerTopology* const tTopo = &iSetup.getData(tTopoToken_);
715  std::string MsgLoggerCat = "GlobalRecHitsAnalyzer_fillTrk";
716  TString eventout;
717  if (verbosity > 0)
718  eventout = "\nGathering info:";
719 
720  // get strip information
722  iEvent.getByToken(SiStripSrc_Token_, rechitsmatched);
723  bool validstrip = rechitsmatched.isValid();
724  if (!validstrip) {
725  LogDebug(MsgLoggerCat) << "Unable to find stripmatchedrechits in event!";
726  }
727 
729 
730  const auto& tGeomHandle = iSetup.getHandle(tGeomToken_);
731  if (!tGeomHandle.isValid()) {
732  edm::LogWarning(MsgLoggerCat) << "Unable to find TrackerDigiGeometry in event!";
733  return;
734  }
735  const TrackerGeometry& tracker(*tGeomHandle);
736 
737  if (validstrip) {
738  int nStripBrl = 0, nStripFwd = 0;
739 
740  // loop over det units
741  for (TrackerGeometry::DetContainer::const_iterator it = tGeomHandle->dets().begin();
742  it != tGeomHandle->dets().end();
743  ++it) {
744  uint32_t myid = ((*it)->geographicalId()).rawId();
745  DetId detid = ((*it)->geographicalId());
746 
747  //loop over rechits-matched in the same subdetector
748  SiStripMatchedRecHit2DCollection::const_iterator rechitmatchedMatch = rechitsmatched->find(detid);
749 
750  if (rechitmatchedMatch != rechitsmatched->end()) {
751  SiStripMatchedRecHit2DCollection::DetSet rechitmatchedRange = *rechitmatchedMatch;
752  SiStripMatchedRecHit2DCollection::DetSet::const_iterator rechitmatchedRangeIteratorBegin =
753  rechitmatchedRange.begin();
754  SiStripMatchedRecHit2DCollection::DetSet::const_iterator rechitmatchedRangeIteratorEnd =
755  rechitmatchedRange.end();
757 
758  for (itermatched = rechitmatchedRangeIteratorBegin; itermatched != rechitmatchedRangeIteratorEnd;
759  ++itermatched) {
760  SiStripMatchedRecHit2D const rechit = *itermatched;
761  LocalPoint position = rechit.localPosition();
762 
763  float mindist = 999999.;
764  float distx = 999999.;
765  float disty = 999999.;
766  float dist = 999999.;
767  std::pair<LocalPoint, LocalVector> closestPair;
768  matched.clear();
769 
770  float rechitmatchedx = position.x();
771  float rechitmatchedy = position.y();
772 
773  matched = associate.associateHit(rechit);
774 
775  if (!matched.empty()) {
776  //project simhit;
777  const GluedGeomDet* gluedDet = (const GluedGeomDet*)tracker.idToDet(rechit.geographicalId());
778  const StripGeomDetUnit* partnerstripdet = (StripGeomDetUnit*)gluedDet->stereoDet();
779  std::pair<LocalPoint, LocalVector> hitPair;
780 
781  for (std::vector<PSimHit>::const_iterator m = matched.begin(); m != matched.end(); m++) {
782  //project simhit;
783  hitPair = projectHit((*m), partnerstripdet, gluedDet->surface());
784  distx = fabs(rechitmatchedx - hitPair.first.x());
785  disty = fabs(rechitmatchedy - hitPair.first.y());
786  dist = sqrt(distx * distx + disty * disty);
787 
788  if (dist < mindist) {
789  mindist = dist;
790  closestPair = hitPair;
791  }
792  }
793 
794  // get TIB
795  if (detid.subdetId() == sdSiTIB) {
796  ++nStripBrl;
797 
798  if (tTopo->tibLayer(myid) == 1) {
799  mehSiStripResX[8]->Fill(rechitmatchedx - closestPair.first.x());
800  mehSiStripResY[8]->Fill(rechitmatchedy - closestPair.first.y());
801  }
802  if (tTopo->tibLayer(myid) == 2) {
803  mehSiStripResX[9]->Fill(rechitmatchedx - closestPair.first.x());
804  mehSiStripResY[9]->Fill(rechitmatchedy - closestPair.first.y());
805  }
806  if (tTopo->tibLayer(myid) == 3) {
807  mehSiStripResX[10]->Fill(rechitmatchedx - closestPair.first.x());
808  mehSiStripResY[10]->Fill(rechitmatchedy - closestPair.first.y());
809  }
810  if (tTopo->tibLayer(myid) == 4) {
811  mehSiStripResX[11]->Fill(rechitmatchedx - closestPair.first.x());
812  mehSiStripResY[11]->Fill(rechitmatchedy - closestPair.first.y());
813  }
814  }
815 
816  // get TOB
817  if (detid.subdetId() == sdSiTOB) {
818  ++nStripBrl;
819 
820  if (tTopo->tobLayer(myid) == 1) {
821  mehSiStripResX[15]->Fill(rechitmatchedx - closestPair.first.x());
822  mehSiStripResY[15]->Fill(rechitmatchedy - closestPair.first.y());
823  }
824  if (tTopo->tobLayer(myid) == 2) {
825  mehSiStripResX[16]->Fill(rechitmatchedx - closestPair.first.x());
826  mehSiStripResY[16]->Fill(rechitmatchedy - closestPair.first.y());
827  }
828  if (tTopo->tobLayer(myid) == 3) {
829  mehSiStripResX[17]->Fill(rechitmatchedx - closestPair.first.x());
830  mehSiStripResY[17]->Fill(rechitmatchedy - closestPair.first.y());
831  }
832  if (tTopo->tobLayer(myid) == 4) {
833  mehSiStripResX[18]->Fill(rechitmatchedx - closestPair.first.x());
834  mehSiStripResY[18]->Fill(rechitmatchedy - closestPair.first.y());
835  }
836  }
837 
838  // get TID
839  if (detid.subdetId() == sdSiTID) {
840  ++nStripFwd;
841 
842  if (tTopo->tidWheel(myid) == 1) {
843  mehSiStripResX[12]->Fill(rechitmatchedx - closestPair.first.x());
844  mehSiStripResY[12]->Fill(rechitmatchedy - closestPair.first.y());
845  }
846  if (tTopo->tidWheel(myid) == 2) {
847  mehSiStripResX[13]->Fill(rechitmatchedx - closestPair.first.x());
848  mehSiStripResY[13]->Fill(rechitmatchedy - closestPair.first.y());
849  }
850  if (tTopo->tidWheel(myid) == 3) {
851  mehSiStripResX[14]->Fill(rechitmatchedx - closestPair.first.x());
852  mehSiStripResY[14]->Fill(rechitmatchedy - closestPair.first.y());
853  }
854  }
855 
856  // get TEC
857  if (detid.subdetId() == sdSiTEC) {
858  ++nStripFwd;
859 
860  if (tTopo->tecWheel(myid) == 1) {
861  mehSiStripResX[0]->Fill(rechitmatchedx - closestPair.first.x());
862  mehSiStripResY[0]->Fill(rechitmatchedy - closestPair.first.y());
863  }
864  if (tTopo->tecWheel(myid) == 2) {
865  mehSiStripResX[1]->Fill(rechitmatchedx - closestPair.first.x());
866  mehSiStripResY[1]->Fill(rechitmatchedy - closestPair.first.y());
867  }
868  if (tTopo->tecWheel(myid) == 3) {
869  mehSiStripResX[2]->Fill(rechitmatchedx - closestPair.first.x());
870  mehSiStripResY[2]->Fill(rechitmatchedy - closestPair.first.y());
871  }
872  if (tTopo->tecWheel(myid) == 4) {
873  mehSiStripResX[3]->Fill(rechitmatchedx - closestPair.first.x());
874  mehSiStripResY[3]->Fill(rechitmatchedy - closestPair.first.y());
875  }
876  if (tTopo->tecWheel(myid) == 5) {
877  mehSiStripResX[4]->Fill(rechitmatchedx - closestPair.first.x());
878  mehSiStripResY[4]->Fill(rechitmatchedy - closestPair.first.y());
879  }
880  if (tTopo->tecWheel(myid) == 6) {
881  mehSiStripResX[5]->Fill(rechitmatchedx - closestPair.first.x());
882  mehSiStripResY[5]->Fill(rechitmatchedy - closestPair.first.y());
883  }
884  if (tTopo->tecWheel(myid) == 7) {
885  mehSiStripResX[6]->Fill(rechitmatchedx - closestPair.first.x());
886  mehSiStripResY[6]->Fill(rechitmatchedy - closestPair.first.y());
887  }
888  if (tTopo->tecWheel(myid) == 8) {
889  mehSiStripResX[7]->Fill(rechitmatchedx - closestPair.first.x());
890  mehSiStripResY[7]->Fill(rechitmatchedy - closestPair.first.y());
891  }
892  }
893 
894  } // end if matched empty
895  }
896  }
897  } // end loop over det units
898 
899  if (verbosity > 1) {
900  eventout += "\n Number of BrlStripRecHits collected:...... ";
901  eventout += nStripBrl;
902  }
903 
904  for (int i = 8; i < 12; ++i) {
905  mehSiStripn[i]->Fill((float)nStripBrl);
906  }
907  for (int i = 16; i < 19; ++i) {
908  mehSiStripn[i]->Fill((float)nStripBrl);
909  }
910 
911  if (verbosity > 1) {
912  eventout += "\n Number of FrwdStripRecHits collected:..... ";
913  eventout += nStripFwd;
914  }
915  for (int i = 0; i < 8; ++i) {
916  mehSiStripn[i]->Fill((float)nStripFwd);
917  }
918  for (int i = 12; i < 16; ++i) {
919  mehSiStripn[i]->Fill((float)nStripFwd);
920  }
921  }
922 
923  // get pixel information
924  //Get RecHits
926  iEvent.getByToken(SiPxlSrc_Token_, recHitColl);
927  bool validpixel = recHitColl.isValid();
928  if (!validpixel) {
929  LogDebug(MsgLoggerCat) << "Unable to find SiPixelRecHitCollection in event!";
930  } else {
931  int nPxlBrl = 0, nPxlFwd = 0;
932  //iterate over detunits
933  for (TrackerGeometry::DetContainer::const_iterator it = tGeomHandle->dets().begin();
934  it != tGeomHandle->dets().end();
935  ++it) {
936  uint32_t myid = ((*it)->geographicalId()).rawId();
937  DetId detId = ((*it)->geographicalId());
938  int subid = detId.subdetId();
939 
940  if (!((subid == sdPxlBrl) || (subid == sdPxlFwd)))
941  continue;
942 
943  SiPixelRecHitCollection::const_iterator pixeldet = recHitColl->find(detId);
944  if (pixeldet == recHitColl->end())
945  continue;
946  SiPixelRecHitCollection::DetSet pixelrechitRange = *pixeldet;
947  SiPixelRecHitCollection::DetSet::const_iterator pixelrechitRangeIteratorBegin = pixelrechitRange.begin();
948  SiPixelRecHitCollection::DetSet::const_iterator pixelrechitRangeIteratorEnd = pixelrechitRange.end();
949  SiPixelRecHitCollection::DetSet::const_iterator pixeliter = pixelrechitRangeIteratorBegin;
950 
951  std::vector<PSimHit> matched;
952 
953  //----Loop over rechits for this detId
954  for (; pixeliter != pixelrechitRangeIteratorEnd; ++pixeliter) {
955  matched.clear();
956  matched = associate.associateHit(*pixeliter);
957 
958  if (!matched.empty()) {
959  float closest = 9999.9;
960  LocalPoint lp = pixeliter->localPosition();
961  float rechit_x = lp.x();
962  float rechit_y = lp.y();
963 
964  float sim_x = 0.;
965  float sim_y = 0.;
966 
967  //loop over sim hits and fill closet
968  for (std::vector<PSimHit>::const_iterator m = matched.begin(); m != matched.end(); ++m) {
969  float sim_x1 = (*m).entryPoint().x();
970  float sim_x2 = (*m).exitPoint().x();
971  float sim_xpos = 0.5 * (sim_x1 + sim_x2);
972 
973  float sim_y1 = (*m).entryPoint().y();
974  float sim_y2 = (*m).exitPoint().y();
975  float sim_ypos = 0.5 * (sim_y1 + sim_y2);
976 
977  float x_res = fabs(sim_xpos - rechit_x);
978  float y_res = fabs(sim_ypos - rechit_y);
979 
980  float dist = sqrt(x_res * x_res + y_res * y_res);
981 
982  if (dist < closest) {
983  closest = dist;
984  sim_x = sim_xpos;
985  sim_y = sim_ypos;
986  }
987  } // end sim hit loop
988 
989  // get Barrel pixels ***************Pixel STuff******************
990  if (subid == sdPxlBrl) {
991  ++nPxlBrl;
992 
993  if (tTopo->pxbLayer(myid) == 1) {
994  mehSiPixelResX[0]->Fill(rechit_x - sim_x);
995  mehSiPixelResY[0]->Fill(rechit_y - sim_y);
996  }
997  if (tTopo->pxbLayer(myid) == 2) {
998  mehSiPixelResX[1]->Fill(rechit_x - sim_x);
999  mehSiPixelResY[1]->Fill(rechit_y - sim_y);
1000  }
1001  if (tTopo->pxbLayer(myid) == 3) {
1002  mehSiPixelResX[2]->Fill(rechit_x - sim_x);
1003  mehSiPixelResY[2]->Fill(rechit_y - sim_y);
1004  }
1005  }
1006 
1007  // get Forward pixels
1008  if (subid == sdPxlFwd) {
1009  ++nPxlFwd;
1010 
1011  if (tTopo->pxfDisk(myid) == 1) {
1012  if (tTopo->pxfSide(myid) == 1) {
1013  mehSiPixelResX[3]->Fill(rechit_x - sim_x);
1014  mehSiPixelResY[3]->Fill(rechit_y - sim_y);
1015  }
1016  if (tTopo->pxfSide(myid) == 2) {
1017  mehSiPixelResX[4]->Fill(rechit_x - sim_x);
1018  mehSiPixelResY[4]->Fill(rechit_y - sim_y);
1019  }
1020  }
1021  if (tTopo->pxfDisk(myid) == 2) {
1022  if (tTopo->pxfSide(myid) == 1) {
1023  mehSiPixelResX[5]->Fill(rechit_x - sim_x);
1024  mehSiPixelResY[5]->Fill(rechit_y - sim_y);
1025  }
1026  if (tTopo->pxfSide(myid) == 2) {
1027  mehSiPixelResX[6]->Fill(rechit_x - sim_x);
1028  mehSiPixelResY[6]->Fill(rechit_y - sim_y);
1029  }
1030  }
1031  }
1032  } // end matched emtpy
1033  } // <-----end rechit loop
1034  } // <------ end detunit loop
1035 
1036  if (verbosity > 1) {
1037  eventout += "\n Number of BrlPixelRecHits collected:...... ";
1038  eventout += nPxlBrl;
1039  }
1040  for (int i = 0; i < 3; ++i) {
1041  mehSiPixeln[i]->Fill((float)nPxlBrl);
1042  }
1043 
1044  if (verbosity > 1) {
1045  eventout += "\n Number of FrwdPixelRecHits collected:..... ";
1046  eventout += nPxlFwd;
1047  }
1048 
1049  for (int i = 3; i < 7; ++i) {
1050  mehSiPixeln[i]->Fill((float)nPxlFwd);
1051  }
1052  }
1053 
1054  if (verbosity > 0)
1055  edm::LogInfo(MsgLoggerCat) << eventout << "\n";
1056 
1057  return;
1058 }
1059 
1061  std::string MsgLoggerCat = "GlobalRecHitsAnalyzer_fillMuon";
1062 
1063  TString eventout;
1064  if (verbosity > 0)
1065  eventout = "\nGathering info:";
1066 
1067  // get DT information
1068  const auto& dtGeom = iSetup.getHandle(dtGeomToken_);
1069  if (!dtGeom.isValid()) {
1070  edm::LogWarning(MsgLoggerCat) << "Unable to find DTMuonGeometryRecord in event!";
1071  return;
1072  }
1073 
1075  iEvent.getByToken(MuDTSimSrc_Token_, dtsimHits);
1076  bool validdtsim = dtsimHits.isValid();
1077  if (!validdtsim) {
1078  LogDebug(MsgLoggerCat) << "Unable to find dtsimHits in event!";
1079  }
1080 
1082  iEvent.getByToken(MuDTSrc_Token_, dtRecHits);
1083  bool validdtrec = dtRecHits.isValid();
1084  if (!validdtrec) {
1085  LogDebug(MsgLoggerCat) << "Unable to find dtRecHits in event!";
1086  }
1087 
1088  if (validdtsim && validdtrec) {
1089  std::map<DTWireId, edm::PSimHitContainer> simHitsPerWire =
1091 
1092  std::map<DTWireId, std::vector<DTRecHit1DPair>> recHitsPerWire = map1DRecHitsPerWire(dtRecHits.product());
1093 
1094  int nDt = compute(dtGeom.product(), simHitsPerWire, recHitsPerWire, 1);
1095 
1096  if (verbosity > 1) {
1097  eventout += "\n Number of DtMuonRecHits collected:........ ";
1098  eventout += nDt;
1099  }
1100  mehDtMuonn->Fill(float(nDt));
1101  }
1102 
1103  // get CSC Strip information
1104  // get map of sim hits
1105  theMap.clear();
1107 
1108  iEvent.getByToken(MuCSCHits_Token_, cf);
1109  bool validXFrame = cf.isValid();
1110  if (!validXFrame) {
1111  LogDebug(MsgLoggerCat) << "Unable to find muo CSC crossingFrame in event!";
1112  } else {
1114 
1115  // arrange the hits by detUnit
1116  for (auto const& iHit : simHits) {
1117  theMap[iHit.detUnitId()].push_back(iHit);
1118  }
1119  }
1120 
1121  // get geometry
1122  const auto& hGeom = iSetup.getHandle(cscGeomToken_);
1123  if (!hGeom.isValid()) {
1124  edm::LogWarning(MsgLoggerCat) << "Unable to find CSCMuonGeometryRecord in event!";
1125  return;
1126  }
1127  const CSCGeometry* theCSCGeometry = &*hGeom;
1128 
1129  // get rechits
1131  iEvent.getByToken(MuCSCSrc_Token_, hRecHits);
1132  bool validCSC = hRecHits.isValid();
1133  if (!validCSC) {
1134  LogDebug(MsgLoggerCat) << "Unable to find CSC RecHits in event!";
1135  } else {
1136  const CSCRecHit2DCollection* cscRecHits = hRecHits.product();
1137 
1138  int nCSC = 0;
1139  for (CSCRecHit2DCollection::const_iterator recHitItr = cscRecHits->begin(); recHitItr != cscRecHits->end();
1140  ++recHitItr) {
1141  int detId = (*recHitItr).cscDetId().rawId();
1142 
1144  std::map<int, edm::PSimHitContainer>::const_iterator mapItr = theMap.find(detId);
1145  if (mapItr != theMap.end()) {
1146  simHits = mapItr->second;
1147  }
1148 
1149  if (simHits.size() == 1) {
1150  ++nCSC;
1151 
1152  const GeomDetUnit* detUnit = theCSCGeometry->idToDetUnit(CSCDetId(detId));
1153  const CSCLayer* layer = dynamic_cast<const CSCLayer*>(detUnit);
1154 
1155  int chamberType = layer->chamber()->specs()->chamberType();
1156  plotResolution(simHits[0], *recHitItr, layer, chamberType);
1157  }
1158  }
1159 
1160  if (verbosity > 1) {
1161  eventout += "\n Number of CSCRecHits collected:........... ";
1162  eventout += nCSC;
1163  }
1164  mehCSCn->Fill((float)nCSC);
1165  }
1166 
1167  // get RPC information
1168  std::map<double, int> mapsim, maprec;
1169  std::map<int, double> nmapsim, nmaprec;
1170  const auto& rpcGeom = iSetup.getHandle(rpcGeomToken_);
1171  if (!rpcGeom.isValid()) {
1172  edm::LogWarning(MsgLoggerCat) << "Unable to find RPCMuonGeometryRecord in event!";
1173  return;
1174  }
1175 
1177  iEvent.getByToken(MuRPCSimSrc_Token_, simHit);
1178  bool validrpcsim = simHit.isValid();
1179  if (!validrpcsim) {
1180  LogDebug(MsgLoggerCat) << "Unable to find RPCSimHit in event!";
1181  }
1182 
1184  iEvent.getByToken(MuRPCSrc_Token_, recHit);
1185  bool validrpc = recHit.isValid();
1186  if (!validrpc) {
1187  LogDebug(MsgLoggerCat) << "Unable to find RPCRecHit in event!";
1188  }
1189 
1190  if (validrpc) {
1191  int nRPC = 0;
1193  int nrec = 0;
1194  for (recIt = recHit->begin(); recIt != recHit->end(); ++recIt) {
1195  RPCDetId Rid = (RPCDetId)(*recIt).rpcId();
1196  const RPCRoll* roll = dynamic_cast<const RPCRoll*>(rpcGeom->roll(Rid));
1197  if (roll->isForward()) {
1198  if (verbosity > 1) {
1199  eventout += "\n Number of RPCRecHits collected:........... ";
1200  eventout += nRPC;
1201  }
1202 
1203  if (verbosity > 0)
1204  edm::LogInfo(MsgLoggerCat) << eventout << "\n";
1205  return;
1206  }
1207  nrec = nrec + 1;
1208  LocalPoint rhitlocal = (*recIt).localPosition();
1209  double rhitlocalx = rhitlocal.x();
1210  maprec[rhitlocalx] = nrec;
1211  }
1212 
1213  int i = 0;
1214  for (std::map<double, int>::iterator iter = maprec.begin(); iter != maprec.end(); ++iter) {
1215  i = i + 1;
1216  nmaprec[i] = (*iter).first;
1217  }
1218 
1219  int nsim = 0;
1220  if (validrpcsim) {
1221  edm::PSimHitContainer::const_iterator simIt;
1222  for (simIt = simHit->begin(); simIt != simHit->end(); simIt++) {
1223  int ptype = (*simIt).particleType();
1224  if (ptype == 13 || ptype == -13) {
1225  nsim = nsim + 1;
1226  LocalPoint shitlocal = (*simIt).localPosition();
1227  double shitlocalx = shitlocal.x();
1228  mapsim[shitlocalx] = nsim;
1229  }
1230  }
1231 
1232  i = 0;
1233  for (std::map<double, int>::iterator iter = mapsim.begin(); iter != mapsim.end(); ++iter) {
1234  i = i + 1;
1235  nmapsim[i] = (*iter).first;
1236  }
1237  }
1238 
1239  if (nsim == nrec) {
1240  for (int r = 0; r < nsim; r++) {
1241  ++nRPC;
1242  mehRPCResX->Fill(nmaprec[r + 1] - nmapsim[r + 1]);
1243  }
1244  }
1245 
1246  if (verbosity > 1) {
1247  eventout += "\n Number of RPCRecHits collected:........... ";
1248  eventout += nRPC;
1249  }
1250  mehRPCn->Fill((float)nRPC);
1251  }
1252 
1253  if (verbosity > 0)
1254  edm::LogInfo(MsgLoggerCat) << eventout << "\n";
1255 
1256  return;
1257 }
1258 
1259 //needed by to do the residual for matched hits in SiStrip
1260 std::pair<LocalPoint, LocalVector> GlobalRecHitsAnalyzer::projectHit(const PSimHit& hit,
1261  const StripGeomDetUnit* stripDet,
1262  const BoundPlane& plane) {
1263  const StripTopology& topol = stripDet->specificTopology();
1264  GlobalPoint globalpos = stripDet->surface().toGlobal(hit.localPosition());
1265  LocalPoint localHit = plane.toLocal(globalpos);
1266  //track direction
1267  LocalVector locdir = hit.localDirection();
1268  //rotate track in new frame
1269 
1270  GlobalVector globaldir = stripDet->surface().toGlobal(locdir);
1271  LocalVector dir = plane.toLocal(globaldir);
1272  float scale = -localHit.z() / dir.z();
1273 
1274  LocalPoint projectedPos = localHit + scale * dir;
1275 
1276  float selfAngle = topol.stripAngle(topol.strip(hit.localPosition()));
1277 
1278  // vector along strip in hit frame
1279  LocalVector stripDir(sin(selfAngle), cos(selfAngle), 0);
1280 
1281  LocalVector localStripDir(plane.toLocal(stripDet->surface().toGlobal(stripDir)));
1282 
1283  return std::pair<LocalPoint, LocalVector>(projectedPos, localStripDir);
1284 }
1285 
1286 // Return a map between DTRecHit1DPair and wireId
1287 std::map<DTWireId, std::vector<DTRecHit1DPair>> GlobalRecHitsAnalyzer::map1DRecHitsPerWire(
1288  const DTRecHitCollection* dt1DRecHitPairs) {
1289  std::map<DTWireId, std::vector<DTRecHit1DPair>> ret;
1290 
1291  for (DTRecHitCollection::const_iterator rechit = dt1DRecHitPairs->begin(); rechit != dt1DRecHitPairs->end();
1292  rechit++) {
1293  ret[(*rechit).wireId()].push_back(*rechit);
1294  }
1295 
1296  return ret;
1297 }
1298 
1299 // Compute SimHit distance from wire (cm)
1301  float xwire = layer->specificTopology().wirePosition(wireId.wire());
1302  LocalPoint entryP = hit.entryPoint();
1303  LocalPoint exitP = hit.exitPoint();
1304  float xEntry = entryP.x() - xwire;
1305  float xExit = exitP.x() - xwire;
1306 
1307  //FIXME: check...
1308  return fabs(xEntry - (entryP.z() * (xExit - xEntry)) / (exitP.z() - entryP.z()));
1309 }
1310 
1311 // Find the RecHit closest to the muon SimHit
1312 template <typename type>
1314  DTWireId wireId,
1315  const std::vector<type>& recHits,
1316  const float simHitDist) {
1317  float res = 99999;
1318  const type* theBestRecHit = nullptr;
1319  // Loop over RecHits within the cell
1320  for (typename std::vector<type>::const_iterator recHit = recHits.begin(); recHit != recHits.end(); recHit++) {
1321  float distTmp = recHitDistFromWire(*recHit, layer);
1322  if (fabs(distTmp - simHitDist) < res) {
1323  res = fabs(distTmp - simHitDist);
1324  theBestRecHit = &(*recHit);
1325  }
1326  } // End of loop over RecHits within the cell
1327 
1328  return theBestRecHit;
1329 }
1330 
1331 // Compute the distance from wire (cm) of a hits in a DTRecHit1DPair
1333  // Compute the rechit distance from wire
1334  return fabs(hitPair.localPosition(DTEnums::Left).x() - hitPair.localPosition(DTEnums::Right).x()) / 2.;
1335 }
1336 
1337 // Compute the distance from wire (cm) of a hits in a DTRecHit1D
1339  return fabs(recHit.localPosition().x() - layer->specificTopology().wirePosition(recHit.wireId().wire()));
1340 }
1341 
1342 template <typename type>
1344  const std::map<DTWireId, std::vector<PSimHit>>& _simHitsPerWire,
1345  const std::map<DTWireId, std::vector<type>>& _recHitsPerWire,
1346  int step) {
1347  std::map<DTWireId, std::vector<PSimHit>> simHitsPerWire = _simHitsPerWire;
1348  std::map<DTWireId, std::vector<type>> recHitsPerWire = _recHitsPerWire;
1349  int nDt = 0;
1350  // Loop over cells with a muon SimHit
1351  for (std::map<DTWireId, std::vector<PSimHit>>::const_iterator wireAndSHits = simHitsPerWire.begin();
1352  wireAndSHits != simHitsPerWire.end();
1353  wireAndSHits++) {
1354  DTWireId wireId = (*wireAndSHits).first;
1355  std::vector<PSimHit> simHitsInCell = (*wireAndSHits).second;
1356 
1357  // Get the layer
1358  const DTLayer* layer = dtGeom->layer(wireId);
1359 
1360  // Look for a mu hit in the cell
1361  const PSimHit* muSimHit = DTHitQualityUtils::findMuSimHit(simHitsInCell);
1362  if (muSimHit == nullptr) {
1363  continue; // Skip this cell
1364  }
1365 
1366  // Find the distance of the simhit from the wire
1367  float simHitWireDist = simHitDistFromWire(layer, wireId, *muSimHit);
1368  // Skip simhits out of the cell
1369  if (simHitWireDist > 2.1) {
1370  continue; // Skip this cell
1371  }
1372 
1373  // Look for RecHits in the same cell
1374  if (recHitsPerWire.find(wireId) == recHitsPerWire.end()) {
1375  continue; // No RecHit found in this cell
1376  } else {
1377  std::vector<type> recHits = recHitsPerWire[wireId];
1378 
1379  // Find the best RecHit
1380  const type* theBestRecHit = findBestRecHit(layer, wireId, recHits, simHitWireDist);
1381 
1382  float recHitWireDist = recHitDistFromWire(*theBestRecHit, layer);
1383 
1384  ++nDt;
1385 
1386  mehDtMuonRes->Fill(recHitWireDist - simHitWireDist);
1387 
1388  } // find rechits
1389  } // loop over simhits
1390 
1391  return nDt;
1392 }
1393 
1395  const CSCRecHit2D& recHit,
1396  const CSCLayer* layer,
1397  int chamberType) {
1398  GlobalPoint simHitPos = layer->toGlobal(simHit.localPosition());
1399  GlobalPoint recHitPos = layer->toGlobal(recHit.localPosition());
1400 
1401  mehCSCResRDPhi->Fill(recHitPos.phi() - simHitPos.phi());
1402 }
edm::EDGetTokenT< SiPixelRecHitCollection > SiPxlSrc_Token_
GlobalRecHitsAnalyzer(const edm::ParameterSet &)
MonitorElement * mehCSCResRDPhi
ESGetTokenH3DDVariant esConsumes(std::string const &Record, edm::ConsumesCollector &)
Definition: DeDxTools.cc:283
T getParameter(std::string const &) const
Definition: ParameterSet.h:303
unsigned int tobLayer(const DetId &id) const
std::map< DTWireId, edm::PSimHitContainer > mapSimHitsPerWire(const edm::PSimHitContainer &simhits)
unsigned int pxbLayer(const DetId &id) const
std::vector< PCaloHit > PCaloHitContainer
T const & getData(const ESGetToken< T, R > &iToken) const noexcept(false)
Definition: EventSetup.h:119
virtual float stripAngle(float strip) const =0
edm::ESGetToken< DTGeometry, MuonGeometryRecord > dtGeomToken_
edm::EDGetTokenT< EBRecHitCollection > ECalEBSrc_Token_
static const int sdHcalOut
int wire() const
Return the wire number.
Definition: DTWireId.h:42
std::vector< PSimHit > matched
virtual void setCurrentFolder(std::string const &fullpath)
Definition: DQMStore.cc:36
edm::EDGetTokenT< ESRecHitCollection > ECalESSrc_Token_
T z() const
Definition: PV3DBase.h:61
edm::EDGetTokenT< CrossingFrame< PCaloHit > > ESHits_Token_
bool isForward() const
Definition: RPCRoll.cc:43
MonitorElement * mehHcalRes[4]
ret
prodAgent to be discontinued
std::string const & instance() const
Definition: InputTag.h:37
Geom::Phi< T > phi() const
Definition: PV3DBase.h:66
int closest(std::vector< int > const &vec, int value)
unsigned int tidWheel(const DetId &id) const
static const int sdSiTID
unsigned int tecWheel(const DetId &id) const
Sin< T >::type sin(const T &t)
Definition: Sin.h:22
edm::EDGetTokenT< CrossingFrame< PSimHit > > MuCSCHits_Token_
T const * product() const
Definition: Handle.h:70
void fillMuon(const edm::Event &, const edm::EventSetup &)
std::vector< T >::const_iterator const_iterator
unsigned long long EventNumber_t
edm::EDGetTokenT< CrossingFrame< PCaloHit > > EEHits_Token_
float recHitDistFromWire(const DTRecHit1DPair &hitPair, const DTLayer *layer)
LocalPoint localPosition() const override
edm::ESGetToken< TrackerGeometry, TrackerDigiGeometryRecord > tGeomToken_
std::string const & label() const
Definition: InputTag.h:36
float simHitDistFromWire(const DTLayer *layer, DTWireId wireId, const PSimHit &hit)
MonitorElement * mehEcalRes[3]
edm::EDGetTokenT< edm::PSimHitContainer > MuDTSimSrc_Token_
MonitorElement * mehSiStripn[19]
Definition: Electron.h:6
const_iterator end(bool update=false) const
virtual float strip(const LocalPoint &) const =0
void plotResolution(const PSimHit &simHit, const CSCRecHit2D &recHit, const CSCLayer *layer, int chamberType)
T getUntrackedParameter(std::string const &, T const &) const
constexpr std::array< uint8_t, layerIndexSize< TrackerTraits > > layer
void Fill(long long x)
void analyze(const edm::Event &, const edm::EventSetup &) override
std::map< int, edm::PSimHitContainer > theMap
int compute(const DTGeometry *dtGeom, const std::map< DTWireId, std::vector< PSimHit >> &simHitsPerWire, const std::map< DTWireId, std::vector< type >> &recHitsPerWire, int step)
std::map< DTWireId, std::vector< DTRecHit1DPair > > map1DRecHitsPerWire(const DTRecHitCollection *dt1DRecHitPairs)
C::const_iterator const_iterator
constant access iterator type
Definition: RangeMap.h:43
char const * label
T x() const
Definition: PV3DBase.h:59
T y() const
Definition: PV3DBase.h:60
void bookHistograms(DQMStore::IBooker &, edm::Run const &, edm::EventSetup const &) override
edm::ESGetToken< CaloGeometry, CaloGeometryRecord > caloGeomToken_
int iEvent
Definition: GenABIO.cc:224
edm::EDGetTokenT< EBUncalibratedRecHitCollection > ECalUncalEBSrc_Token_
static const int sdSiTIB
static const int sdPxlBrl
std::vector< PSimHit > associateHit(const TrackingRecHit &thit) const
T sqrt(T t)
Definition: SSEVec.h:19
edm::EDGetTokenT< CSCRecHit2DCollection > MuCSCSrc_Token_
MonitorElement * mehSiPixelResX[7]
Cos< T >::type cos(const T &t)
Definition: Cos.h:22
unsigned int pxfDisk(const DetId &id) const
virtual const StripTopology & specificTopology() const
Returns a reference to the strip proxy topology.
MonitorElement * mehEcaln[3]
const type * findBestRecHit(const DTLayer *layer, DTWireId wireId, const std::vector< type > &recHits, const float simHitDist)
constexpr int subdetId() const
get the contents of the subdetector field (not cast into any detector&#39;s numbering enum) ...
Definition: DetId.h:48
static const int sdSiTOB
const_iterator begin() const
const PSimHit * findMuSimHit(const edm::PSimHitContainer &hits)
Select the SimHit from a muon in a vector of SimHits.
MonitorElement * mehSiPixelResY[7]
MonitorElement * mehSiStripResY[19]
ESHandle< T > getHandle(const ESGetToken< T, R > &iToken) const
Definition: EventSetup.h:130
edm::EDGetTokenT< RPCRecHitCollection > MuRPCSrc_Token_
std::pair< LocalPoint, LocalVector > projectHit(const PSimHit &hit, const StripGeomDetUnit *stripDet, const BoundPlane &plane)
const int verbosity
const_iterator end() const
GlobalPoint toGlobal(const Point2DBase< Scalar, LocalTag > lp) const
Definition: Surface.h:79
Log< level::Info, false > LogInfo
boost::transform_iterator< IterHelp, const_IdIter > const_iterator
Definition: DetId.h:17
std::map< uint32_t, float, std::less< uint32_t > > MapType
unsigned int pxfSide(const DetId &id) const
edm::EDGetTokenT< CrossingFrame< PCaloHit > > EBHits_Token_
const Plane & surface() const
The nominal surface of the GeomDet.
Definition: GeomDet.h:37
DetId geographicalId() const
constexpr uint32_t rawId() const
get the raw id
Definition: DetId.h:57
edm::EDGetTokenT< edm::PCaloHitContainer > HCalSrc_Token_
MonitorElement * mehSiPixeln[7]
static const int sdHcalFwd
edm::ESGetToken< CSCGeometry, MuonGeometryRecord > cscGeomToken_
const GeomDetUnit * stereoDet() const
Definition: GluedGeomDet.h:20
static const int sdHcalBrl
void fillTrk(const edm::Event &, const edm::EventSetup &)
bool isValid() const
Definition: HandleBase.h:70
edm::EDGetTokenT< DTRecHitCollection > MuDTSrc_Token_
static const int sdSiTEC
MonitorElement * mehHcaln[4]
iterator end()
Definition: DetSetNew.h:56
const_iterator find(id_type i, bool update=false) const
edm::EDGetTokenT< EEUncalibratedRecHitCollection > ECalUncalEESrc_Token_
LocalPoint localPosition() const override
static int position[264][3]
Definition: ReadPGInfo.cc:289
void fillECal(const edm::Event &, const edm::EventSetup &)
std::vector< PSimHit > PSimHitContainer
edm::ESGetToken< TrackerTopology, TrackerTopologyRcd > tTopoToken_
unsigned int RunNumber_t
unsigned int tibLayer(const DetId &id) const
step
Definition: StallMonitor.cc:98
static const int sdPxlFwd
edm::ESGetToken< RPCGeometry, MuonGeometryRecord > rpcGeomToken_
TrackerHitAssociator::Config trackerHitAssociatorConfig_
Log< level::Warning, false > LogWarning
MonitorElement * book1D(TString const &name, TString const &title, int const nchX, double const lowX, double const highX, FUNC onbooking=NOOP())
Definition: DQMStore.h:98
edm::EDGetTokenT< edm::PSimHitContainer > MuRPCSimSrc_Token_
MonitorElement * mehSiStripResX[19]
static const int sdHcalEC
Definition: Run.h:45
void fillHCal(const edm::Event &, const edm::EventSetup &)
edm::EDGetTokenT< EERecHitCollection > ECalEESrc_Token_
const GeomDet * idToDetUnit(DetId) const override
Return the pointer to the GeomDetUnit corresponding to a given DetId.
Definition: CSCGeometry.cc:89
#define LogDebug(id)
const DTLayer * layer(const DTLayerId &id) const
Return a layer given its id.
Definition: DTGeometry.cc:96
virtual void setAxisTitle(const std::string &title, int axis=1)
set x-, y- or z-axis title (axis=1, 2, 3 respectively)
iterator begin()
Definition: DetSetNew.h:54
edm::EDGetTokenT< SiStripMatchedRecHit2DCollection > SiStripSrc_Token_