CMS 3D CMS Logo

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