CMS 3D CMS Logo

CSCValidation.cc
Go to the documentation of this file.
1 /*
2  * validation package for CSC DIGIs, RECHITs and SEGMENTs + more.
3  *
4  * original authors:
5  * Michael Schmitt (Northwestern University)
6  * Andy Kubik (Northwestern University)
7  *
8  * CONTACT: CSC DPG (Jul-2022)
9  *
10  */
11 
12 // UPDATED AND RUNNING IN 12_x 15.07.2022 TIM COX - includes updates from external version
13 
15 
16 using namespace std;
17 using namespace edm;
18 
20 // CONSTRUCTOR //
22 CSCValidation::CSCValidation(const ParameterSet& pset) {
23  // Get the various input parameters
24  rootFileName = pset.getUntrackedParameter<std::string>("rootFileName", "valHists.root");
25  isSimulation = pset.getUntrackedParameter<bool>("isSimulation", false);
26  writeTreeToFile = pset.getUntrackedParameter<bool>("writeTreeToFile", true);
27  detailedAnalysis = pset.getUntrackedParameter<bool>("detailedAnalysis", false);
28  useDigis = pset.getUntrackedParameter<bool>("useDigis", true);
29 
30  // event quality filter
31  useQualityFilter = pset.getUntrackedParameter<bool>("useQualityFilter", false);
32  pMin = pset.getUntrackedParameter<double>("pMin", 4.);
33  chisqMax = pset.getUntrackedParameter<double>("chisqMax", 20.);
34  nCSCHitsMin = pset.getUntrackedParameter<int>("nCSCHitsMin", 10);
35  nCSCHitsMax = pset.getUntrackedParameter<int>("nCSCHitsMax", 25);
36  lengthMin = pset.getUntrackedParameter<double>("lengthMin", 140.);
37  lengthMax = pset.getUntrackedParameter<double>("lengthMax", 600.);
38  deltaPhiMax = pset.getUntrackedParameter<double>("deltaPhiMax", 0.2);
39  polarMax = pset.getUntrackedParameter<double>("polarMax", 0.7);
40  polarMin = pset.getUntrackedParameter<double>("polarMin", 0.3);
41 
42  // trigger filter
43  useTriggerFilter = pset.getUntrackedParameter<bool>("useTriggerFilter", false);
44 
45  // input tags for collections
46  rd_token = consumes<FEDRawDataCollection>(pset.getParameter<edm::InputTag>("rawDataTag"));
47  sd_token = consumes<CSCStripDigiCollection>(pset.getParameter<edm::InputTag>("stripDigiTag"));
48  wd_token = consumes<CSCWireDigiCollection>(pset.getParameter<edm::InputTag>("wireDigiTag"));
49  cd_token = consumes<CSCComparatorDigiCollection>(pset.getParameter<edm::InputTag>("compDigiTag"));
50  al_token = consumes<CSCALCTDigiCollection>(pset.getParameter<edm::InputTag>("alctDigiTag"));
51  cl_token = consumes<CSCCLCTDigiCollection>(pset.getParameter<edm::InputTag>("clctDigiTag"));
52  co_token = consumes<CSCCorrelatedLCTDigiCollection>(pset.getParameter<edm::InputTag>("corrlctDigiTag"));
53  rh_token = consumes<CSCRecHit2DCollection>(pset.getParameter<edm::InputTag>("cscRecHitTag"));
54  se_token = consumes<CSCSegmentCollection>(pset.getParameter<edm::InputTag>("cscSegTag"));
55  sa_token = consumes<reco::TrackCollection>(pset.getParameter<edm::InputTag>("saMuonTag"));
56  l1_token = consumes<L1MuGMTReadoutCollection>(pset.getParameter<edm::InputTag>("l1aTag"));
57  tr_token = consumes<TriggerResults>(pset.getParameter<edm::InputTag>("hltTag"));
58  sh_token = consumes<PSimHitContainer>(pset.getParameter<edm::InputTag>("simHitTag"));
59  // conditions
60  pedestalsToken_ = esConsumes<CSCDBPedestals, CSCDBPedestalsRcd>();
61  gainsToken_ = esConsumes<CSCDBGains, CSCDBGainsRcd>();
62  noiseToken_ = esConsumes<CSCDBNoiseMatrix, CSCDBNoiseMatrixRcd>();
63  crosstalkToken_ = esConsumes<CSCDBCrosstalk, CSCDBCrosstalkRcd>();
64 
65  crateToken_ = esConsumes<CSCCrateMap, CSCCrateMapRcd>();
66 
67  // flags to switch on/off individual modules
68  makeOccupancyPlots = pset.getUntrackedParameter<bool>("makeOccupancyPlots", true);
69  makeTriggerPlots = pset.getUntrackedParameter<bool>("makeTriggerPlots", false);
70  makeStripPlots = pset.getUntrackedParameter<bool>("makeStripPlots", true);
71  makeWirePlots = pset.getUntrackedParameter<bool>("makeWirePlots", true);
72  makeRecHitPlots = pset.getUntrackedParameter<bool>("makeRecHitPlots", true);
73  makeSimHitPlots = pset.getUntrackedParameter<bool>("makeSimHitPlots", true);
74  makeSegmentPlots = pset.getUntrackedParameter<bool>("makeSegmentPlots", true);
75  makeResolutionPlots = pset.getUntrackedParameter<bool>("makeResolutionPlots", true);
76  makePedNoisePlots = pset.getUntrackedParameter<bool>("makePedNoisePlots", true);
77  makeEfficiencyPlots = pset.getUntrackedParameter<bool>("makeEfficiencyPlots", true);
78  makeGasGainPlots = pset.getUntrackedParameter<bool>("makeGasGainPlots", true);
79  makeAFEBTimingPlots = pset.getUntrackedParameter<bool>("makeAFEBTimingPlots", true);
80  makeCompTimingPlots = pset.getUntrackedParameter<bool>("makeCompTimingPlots", true);
81  makeADCTimingPlots = pset.getUntrackedParameter<bool>("makeADCTimingPlots", true);
82  makeRHNoisePlots = pset.getUntrackedParameter<bool>("makeRHNoisePlots", false);
83  makeCalibPlots = pset.getUntrackedParameter<bool>("makeCalibPlots", false);
84  makeStandalonePlots = pset.getUntrackedParameter<bool>("makeStandalonePlots", false);
85  makeTimeMonitorPlots = pset.getUntrackedParameter<bool>("makeTimeMonitorPlots", false);
86  makeHLTPlots = pset.getUntrackedParameter<bool>("makeHLTPlots", false);
87 
88  // set counters to zero
89  nEventsAnalyzed = 0;
90  rhTreeCount = 0;
91  segTreeCount = 0;
92  firstEvent = true;
93 
94  // Create the root file for the histograms
95  theFile = new TFile(rootFileName.c_str(), "RECREATE");
96  theFile->cd();
97 
98  // Create object of class CSCValHists to manage histograms
99  histos = new CSCValHists();
100 
101  // book Occupancy Histos
102  hOWires = new TH2I("hOWires", "Wire Digi Occupancy", 36, 0.5, 36.5, 20, 0.5, 20.5);
103  hOStrips = new TH2I("hOStrips", "Strip Digi Occupancy", 36, 0.5, 36.5, 20, 0.5, 20.5);
104  hORecHits = new TH2I("hORecHits", "RecHit Occupancy", 36, 0.5, 36.5, 20, 0.5, 20.5);
105  hOSegments = new TH2I("hOSegments", "Segments Occupancy", 36, 0.5, 36.5, 20, 0.5, 20.5);
106 
107  // book Eff histos
108  hSSTE = new TH1F("hSSTE", "hSSTE", 40, 0, 40);
109  hRHSTE = new TH1F("hRHSTE", "hRHSTE", 40, 0, 40);
110  hSEff = new TH1F("hSEff", "Segment Efficiency", 20, 0.5, 20.5);
111  hRHEff = new TH1F("hRHEff", "recHit Efficiency", 20, 0.5, 20.5);
112 
113  const int nChambers = 36;
114  const int nTypes = 20;
115  float nCH_min = 0.5;
116  float nCh_max = float(nChambers) + 0.5;
117  float nT_min = 0.5;
118  float nT_max = float(nTypes) + 0.5;
119 
120  hSSTE2 = new TH2F("hSSTE2", "hSSTE2", nChambers, nCH_min, nCh_max, nTypes, nT_min, nT_max);
121  hRHSTE2 = new TH2F("hRHSTE2", "hRHSTE2", nChambers, nCH_min, nCh_max, nTypes, nT_min, nT_max);
122  hStripSTE2 = new TH2F("hStripSTE2", "hStripSTE2", nChambers, nCH_min, nCh_max, nTypes, nT_min, nT_max);
123  hWireSTE2 = new TH2F("hWireSTE2", "hWireSTE2", nChambers, nCH_min, nCh_max, nTypes, nT_min, nT_max);
124 
125  hEffDenominator = new TH2F("hEffDenominator", "hEffDenominator", nChambers, nCH_min, nCh_max, nTypes, nT_min, nT_max);
126  hSEff2 = new TH2F("hSEff2", "Segment Efficiency 2D", nChambers, nCH_min, nCh_max, nTypes, nT_min, nT_max);
127  hRHEff2 = new TH2F("hRHEff2", "recHit Efficiency 2D", nChambers, nCH_min, nCh_max, nTypes, nT_min, nT_max);
128 
129  hStripEff2 = new TH2F("hStripEff2", "strip Efficiency 2D", nChambers, nCH_min, nCh_max, nTypes, nT_min, nT_max);
130  hWireEff2 = new TH2F("hWireEff2", "wire Efficiency 2D", nChambers, nCH_min, nCh_max, nTypes, nT_min, nT_max);
131 
132  hSensitiveAreaEvt =
133  new TH2F("hSensitiveAreaEvt", "events in sensitive area", nChambers, nCH_min, nCh_max, nTypes, nT_min, nT_max);
134 
135  hSSTETight = new TH1F("hSSTETight", "hSSTE Tight", 40, 0, 40);
136  hRHSTETight = new TH1F("hRHSTETight", "hRHSTE Tight", 40, 0, 40);
137 
138  hSSTE2Tight = new TH2F("hSSTE2Tight", "hSSTE2 Tight", nChambers, nCH_min, nCh_max, nTypes, nT_min, nT_max);
139  hRHSTE2Tight = new TH2F("hRHSTE2Tight", "hRHSTE2 Tight", nChambers, nCH_min, nCh_max, nTypes, nT_min, nT_max);
140  hStripSTE2Tight =
141  new TH2F("hStripSTE2Tight", "hStripSTE2 Tight", nChambers, nCH_min, nCh_max, nTypes, nT_min, nT_max);
142  hWireSTE2Tight = new TH2F("hWireSTE2Tight", "hWireSTE2 Tight", nChambers, nCH_min, nCh_max, nTypes, nT_min, nT_max);
143  hEffDenominatorTight =
144  new TH2F("hEffDenominatorTight", "hEffDenominator Tight", nChambers, nCH_min, nCh_max, nTypes, nT_min, nT_max);
145 
146  // setup trees to hold global position data for rechits and segments
147  if (writeTreeToFile)
148  histos->setupTrees();
149 
150  geomToken_ = esConsumes<CSCGeometry, MuonGeometryRecord>();
151 }
152 
154 // DESTRUCTOR //
156 CSCValidation::~CSCValidation() {
157  // produce final efficiency histograms
158  histoEfficiency(hRHSTE, hRHEff);
159  histoEfficiency(hSSTE, hSEff);
160  hSEff2->Divide(hSSTE2, hEffDenominator, 1., 1., "B");
161  hRHEff2->Divide(hRHSTE2, hEffDenominator, 1., 1., "B");
162  hStripEff2->Divide(hStripSTE2, hEffDenominator, 1., 1., "B");
163  hWireEff2->Divide(hWireSTE2, hEffDenominator, 1., 1., "B");
164 
165  histos->insertPlot(hRHSTETight, "hRHSTETight", "Efficiency");
166  histos->insertPlot(hSSTETight, "hSSTETight", "Efficiency");
167  histos->insertPlot(hStripSTE2Tight, "hStripSTE2Tight", "Efficiency");
168  histos->insertPlot(hWireSTE2Tight, "hWireSTE2Tight", "Efficiency");
169  histos->insertPlot(hRHSTE2Tight, "hRHSTE2Tight", "Efficiency");
170  histos->insertPlot(hSSTE2Tight, "hSSTE2Tight", "Efficiency");
171  histos->insertPlot(hEffDenominatorTight, "hEffDenominatorTight", "Efficiency");
172 
173  histos->insertPlot(hRHSTE, "hRHSTE", "Efficiency");
174  histos->insertPlot(hSSTE, "hSSTE", "Efficiency");
175  histos->insertPlot(hSSTE2, "hSSTE2", "Efficiency");
176  histos->insertPlot(hEffDenominator, "hEffDenominator", "Efficiency");
177  histos->insertPlot(hRHSTE2, "hRHSTE2", "Efficiency");
178  histos->insertPlot(hStripSTE2, "hStripSTE2", "Efficiency");
179  histos->insertPlot(hWireSTE2, "hWireSTE2", "Efficiency");
180 
181  //moving this to post job macros
182  histos->insertPlot(hSEff, "hSEff", "Efficiency");
183  histos->insertPlot(hRHEff, "hRHEff", "Efficiency");
184 
185  histos->insertPlot(hSEff2, "hSEff2", "Efficiency");
186  histos->insertPlot(hRHEff2, "hRHEff2", "Efficiency");
187  histos->insertPlot(hStripEff2, "hStripff2", "Efficiency");
188  histos->insertPlot(hWireEff2, "hWireff2", "Efficiency");
189 
190  histos->insertPlot(hSensitiveAreaEvt, "", "Efficiency");
191 
192  // throw in occupancy plots so they're saved
193  histos->insertPlot(hOWires, "hOWires", "Digis");
194  histos->insertPlot(hOStrips, "hOStrips", "Digis");
195  histos->insertPlot(hORecHits, "hORecHits", "recHits");
196  histos->insertPlot(hOSegments, "hOSegments", "Segments");
197 
198  // write histos to the specified file
199  histos->writeHists(theFile);
200  if (writeTreeToFile)
201  histos->writeTrees(theFile);
202  theFile->Close();
203 }
204 
206 // Analysis //
209  // increment counter
210  nEventsAnalyzed++;
211 
212  //int iRun = event.id().run();
213  //int iEvent = event.id().event();
214 
215  // Get the Digis
222  if (useDigis) {
223  event.getByToken(sd_token, strips);
224  event.getByToken(wd_token, wires);
225  event.getByToken(cd_token, compars);
226  event.getByToken(al_token, alcts);
227  event.getByToken(cl_token, clcts);
228  event.getByToken(co_token, correlatedlcts);
229  }
230 
231  // Get the CSC Geometry :
232  edm::ESHandle<CSCGeometry> cscGeom = eventSetup.getHandle(geomToken_);
233 
234  // Get the RecHits collection :
236  event.getByToken(rh_token, recHits);
237 
238  //CSCRecHit2DCollection::const_iterator recIt;
239  //for (recIt = recHits->begin(); recIt != recHits->end(); recIt++) {
240  // recIt->print();
241  // }
242 
243  // Get the SimHits (if applicable)
245  if (isSimulation)
246  event.getByToken(sh_token, simHits);
247 
248  // get CSC segment collection
250  event.getByToken(se_token, cscSegments);
251 
252  // get the trigger collection
254  if (makeTriggerPlots || useTriggerFilter || (useDigis && makeTimeMonitorPlots)) {
255  event.getByToken(l1_token, pCollection);
256  }
258  if (makeHLTPlots) {
259  event.getByToken(tr_token, hlt);
260  }
261 
262  // get the standalone muon collection
264  if (makeStandalonePlots || useQualityFilter) {
265  event.getByToken(sa_token, saMuons);
266  }
267 
269  // Run the modules //
271 
272  // Only do this for the first event
273  // this is probably outdated and needs to be looked at
274  if (nEventsAnalyzed == 1 && makeCalibPlots)
275  doCalibrations(eventSetup);
276 
277  // Look at the l1a trigger info (returns true if csc L1A present)
278  bool CSCL1A = false;
279  if (makeTriggerPlots || useTriggerFilter)
280  CSCL1A = doTrigger(pCollection);
281  if (!useTriggerFilter)
282  CSCL1A = true; // always true if not filtering on trigger
283 
284  cleanEvent = false;
285  if (makeStandalonePlots || useQualityFilter)
286  cleanEvent = filterEvents(recHits, cscSegments, saMuons);
287  if (!useQualityFilter)
288  cleanEvent = true; // always true if not filtering on event quality
289 
290  // look at various chamber occupancies
291  // keep this outside of filter for diagnostics???
292  if (makeOccupancyPlots && CSCL1A)
293  doOccupancies(strips, wires, recHits, cscSegments);
294 
295  if (makeHLTPlots)
296  doHLT(hlt);
297 
298  if (cleanEvent && CSCL1A) {
299  // general look at strip digis
300  if (makeStripPlots && useDigis)
301  doStripDigis(strips);
302 
303  // general look at wire digis
304  if (makeWirePlots && useDigis)
305  doWireDigis(wires);
306 
307  // general look at rechits
308  if (makeRecHitPlots)
309  doRecHits(recHits, cscGeom);
310 
311  // look at simHits
312  if (isSimulation && makeSimHitPlots)
314 
315  // general look at Segments
316  if (makeSegmentPlots)
317  doSegments(cscSegments, cscGeom);
318 
319  // look at hit resolution
320  if (makeResolutionPlots)
321  doResolution(cscSegments, cscGeom);
322 
323  // look at Pedestal Noise
324  if (makePedNoisePlots && useDigis)
325  doPedestalNoise(strips);
326 
327  // look at recHit and segment efficiencies
328  if (makeEfficiencyPlots)
329  doEfficiencies(wires, strips, recHits, cscSegments, cscGeom);
330 
331  // gas gain
332  if (makeGasGainPlots && useDigis)
333  doGasGain(*wires, *strips, *recHits);
334 
335  // AFEB timing
336  if (makeAFEBTimingPlots && useDigis)
337  doAFEBTiming(*wires);
338 
339  // Comparators timing
340  if (makeCompTimingPlots && useDigis)
341  doCompTiming(*compars);
342 
343  // strip ADC timing
344  if (makeADCTimingPlots)
345  doADCTiming(*recHits);
346 
347  // recHit Noise
348  if (makeRHNoisePlots && useDigis)
349  doNoiseHits(recHits, cscSegments, cscGeom, strips);
350 
351  // look at standalone muons (not implemented yet)
352  if (makeStandalonePlots)
353  doStandalone(saMuons);
354 
355  // make plots for monitoring the trigger and offline timing
356  if (makeTimeMonitorPlots)
357  doTimeMonitoring(recHits, cscSegments, alcts, clcts, correlatedlcts, pCollection, cscGeom, eventSetup, event);
358 
359  firstEvent = false;
360  }
361 }
362 
363 // ==============================================
364 //
365 // event filter, returns true only for events with "good" standalone muon
366 //
367 // ==============================================
368 
369 bool CSCValidation::filterEvents(edm::Handle<CSCRecHit2DCollection> recHits,
372  //int nGoodSAMuons = 0;
373 
374  if (recHits->size() < 4 || recHits->size() > 100)
375  return false;
376  if (cscSegments->size() < 1 || cscSegments->size() > 15)
377  return false;
378  return true;
379  //if (saMuons->size() != 1) return false;
380  /*
381  for(reco::TrackCollection::const_iterator muon = saMuons->begin(); muon != saMuons->end(); ++ muon ) {
382  double p = muon->p();
383  double reducedChisq = muon->normalizedChi2();
384 
385  GlobalPoint innerPnt(muon->innerPosition().x(),muon->innerPosition().y(),muon->innerPosition().z());
386  GlobalPoint outerPnt(muon->outerPosition().x(),muon->outerPosition().y(),muon->outerPosition().z());
387  GlobalVector innerKin(muon->innerMomentum().x(),muon->innerMomentum().y(),muon->innerMomentum().z());
388  GlobalVector outerKin(muon->outerMomentum().x(),muon->outerMomentum().y(),muon->outerMomentum().z());
389  GlobalVector deltaPnt = innerPnt - outerPnt;
390  double crudeLength = deltaPnt.mag();
391  double deltaPhi = innerPnt.phi() - outerPnt.phi();
392  double innerGlobalPolarAngle = innerKin.theta();
393  double outerGlobalPolarAngle = outerKin.theta();
394 
395  int nCSCHits = 0;
396  for (trackingRecHit_iterator hit = muon->recHitsBegin(); hit != muon->recHitsEnd(); ++hit ) {
397  if ( (*hit)->isValid() ) {
398  const DetId detId( (*hit)->geographicalId() );
399  if (detId.det() == DetId::Muon) {
400  if (detId.subdetId() == MuonSubdetId::CSC) {
401  nCSCHits++;
402  } // this is a CSC hit
403  } // this is a muon hit
404  } // hit is valid
405  } // end loop over rechits
406 
407  bool goodSAMuon = (p > pMin)
408  && ( reducedChisq < chisqMax )
409  && ( nCSCHits >= nCSCHitsMin )
410  && ( nCSCHits <= nCSCHitsMax )
411  && ( crudeLength > lengthMin )
412  && ( crudeLength < lengthMax );
413 
414 
415  goodSAMuon = goodSAMuon && ( fabs(deltaPhi) < deltaPhiMax );
416  goodSAMuon = goodSAMuon &&
417  (
418  ( ( innerGlobalPolarAngle > polarMin) && ( innerGlobalPolarAngle < polarMax) ) ||
419  ( (M_PI-innerGlobalPolarAngle > polarMin) && (M_PI-innerGlobalPolarAngle < polarMax) )
420  );
421  goodSAMuon = goodSAMuon &&
422  (
423  ( ( outerGlobalPolarAngle > polarMin) && ( outerGlobalPolarAngle < polarMax) ) ||
424  ( (M_PI-outerGlobalPolarAngle > polarMin) && (M_PI-outerGlobalPolarAngle < polarMax) )
425  );
426 
427  //goodSAMuon = goodSAMuon && (nCSCHits > nCSCHitsMin) && (nCSCHits < 13);
428  //goodSAMuon = goodSAMuon && (nCSCHits > 13) && (nCSCHits < 19);
429  //goodSAMuon = goodSAMuon && (nCSCHits > 19) && (nCSCHits < nCSCHitsMax);
430 
431 
432  if (goodSAMuon) nGoodSAMuons++;
433 
434  } // end loop over stand-alone muon collection
435 
436 
437  histos->fill1DHist(nGoodSAMuons,"hNGoodMuons", "Number of Good STA Muons per Event",11,-0.5,10.5,"STAMuons");
438 
439  if (nGoodSAMuons == 1) return true;
440  return false;
441  */
442 }
443 
444 // ==============================================
445 //
446 // look at Occupancies
447 //
448 // ==============================================
449 
450 void CSCValidation::doOccupancies(edm::Handle<CSCStripDigiCollection> strips,
454  bool wireo[2][4][4][36];
455  bool stripo[2][4][4][36];
456  bool rechito[2][4][4][36];
457  bool segmento[2][4][4][36];
458 
459  bool hasWires = false;
460  bool hasStrips = false;
461  bool hasRecHits = false;
462  bool hasSegments = false;
463 
464  for (int e = 0; e < 2; e++) {
465  for (int s = 0; s < 4; s++) {
466  for (int r = 0; r < 4; r++) {
467  for (int c = 0; c < 36; c++) {
468  wireo[e][s][r][c] = false;
469  stripo[e][s][r][c] = false;
470  rechito[e][s][r][c] = false;
471  segmento[e][s][r][c] = false;
472  }
473  }
474  }
475  }
476 
477  if (useDigis) {
478  //wires
479  for (CSCWireDigiCollection::DigiRangeIterator wi = wires->begin(); wi != wires->end(); wi++) {
480  CSCDetId id = (CSCDetId)(*wi).first;
481  int kEndcap = id.endcap();
482  int kRing = id.ring();
483  int kStation = id.station();
484  int kChamber = id.chamber();
485  std::vector<CSCWireDigi>::const_iterator wireIt = (*wi).second.first;
486  std::vector<CSCWireDigi>::const_iterator lastWire = (*wi).second.second;
487  for (; wireIt != lastWire; ++wireIt) {
488  if (!wireo[kEndcap - 1][kStation - 1][kRing - 1][kChamber - 1]) {
489  wireo[kEndcap - 1][kStation - 1][kRing - 1][kChamber - 1] = true;
490  hOWires->Fill(kChamber, typeIndex(id));
491  histos->fill1DHist(
492  chamberSerial(id), "hOWireSerial", "Wire Occupancy by Chamber Serial", 601, -0.5, 600.5, "Digis");
493  hasWires = true;
494  }
495  }
496  }
497 
498  //strips
499  for (CSCStripDigiCollection::DigiRangeIterator si = strips->begin(); si != strips->end(); si++) {
500  CSCDetId id = (CSCDetId)(*si).first;
501  int kEndcap = id.endcap();
502  int kRing = id.ring();
503  int kStation = id.station();
504  int kChamber = id.chamber();
505  std::vector<CSCStripDigi>::const_iterator stripIt = (*si).second.first;
506  std::vector<CSCStripDigi>::const_iterator lastStrip = (*si).second.second;
507  for (; stripIt != lastStrip; ++stripIt) {
508  std::vector<int> myADCVals = stripIt->getADCCounts();
509  bool thisStripFired = false;
510  float thisPedestal = 0.5 * (float)(myADCVals[0] + myADCVals[1]);
511  float threshold = 13.3;
512  float diff = 0.;
513  for (unsigned int iCount = 0; iCount < myADCVals.size(); iCount++) {
514  diff = (float)myADCVals[iCount] - thisPedestal;
515  if (diff > threshold) {
516  thisStripFired = true;
517  }
518  }
519  if (thisStripFired) {
520  if (!stripo[kEndcap - 1][kStation - 1][kRing - 1][kChamber - 1]) {
521  stripo[kEndcap - 1][kStation - 1][kRing - 1][kChamber - 1] = true;
522  hOStrips->Fill(kChamber, typeIndex(id));
523  histos->fill1DHist(
524  chamberSerial(id), "hOStripSerial", "Strip Occupancy by Chamber Serial", 601, -0.5, 600.5, "Digis");
525  hasStrips = true;
526  }
527  }
528  }
529  }
530  }
531 
532  //rechits
534  for (recIt = recHits->begin(); recIt != recHits->end(); recIt++) {
535  CSCDetId idrec = (CSCDetId)(*recIt).cscDetId();
536  int kEndcap = idrec.endcap();
537  int kRing = idrec.ring();
538  int kStation = idrec.station();
539  int kChamber = idrec.chamber();
540  if (!rechito[kEndcap - 1][kStation - 1][kRing - 1][kChamber - 1]) {
541  rechito[kEndcap - 1][kStation - 1][kRing - 1][kChamber - 1] = true;
542  histos->fill1DHist(
543  chamberSerial(idrec), "hORecHitsSerial", "RecHit Occupancy by Chamber Serial", 601, -0.5, 600.5, "recHits");
544  hORecHits->Fill(kChamber, typeIndex(idrec));
545  hasRecHits = true;
546  }
547  }
548 
549  //segments
550  for (CSCSegmentCollection::const_iterator segIt = cscSegments->begin(); segIt != cscSegments->end(); segIt++) {
551  CSCDetId id = (CSCDetId)(*segIt).cscDetId();
552  int kEndcap = id.endcap();
553  int kRing = id.ring();
554  int kStation = id.station();
555  int kChamber = id.chamber();
556  if (!segmento[kEndcap - 1][kStation - 1][kRing - 1][kChamber - 1]) {
557  segmento[kEndcap - 1][kStation - 1][kRing - 1][kChamber - 1] = true;
558  histos->fill1DHist(
559  chamberSerial(id), "hOSegmentsSerial", "Segment Occupancy by Chamber Serial", 601, -0.5, 600.5, "Segments");
560  hOSegments->Fill(kChamber, typeIndex(id));
561  hasSegments = true;
562  }
563  }
564 
565  // overall CSC occupancy (events with CSC data compared to total)
566  histos->fill1DHist(1, "hCSCOccupancy", "overall CSC occupancy", 15, -0.5, 14.5, "GeneralHists");
567  if (hasWires)
568  histos->fill1DHist(3, "hCSCOccupancy", "overall CSC occupancy", 15, -0.5, 14.5, "GeneralHists");
569  if (hasStrips)
570  histos->fill1DHist(5, "hCSCOccupancy", "overall CSC occupancy", 15, -0.5, 14.5, "GeneralHists");
571  if (hasWires && hasStrips)
572  histos->fill1DHist(7, "hCSCOccupancy", "overall CSC occupancy", 15, -0.5, 14.5, "GeneralHists");
573  if (hasRecHits)
574  histos->fill1DHist(9, "hCSCOccupancy", "overall CSC occupancy", 15, -0.5, 14.5, "GeneralHists");
575  if (hasSegments)
576  histos->fill1DHist(11, "hCSCOccupancy", "overall CSC occupancy", 15, -0.5, 14.5, "GeneralHists");
577  if (!cleanEvent)
578  histos->fill1DHist(13, "hCSCOccupancy", "overall CSC occupancy", 15, -0.5, 14.5, "GeneralHists");
579 }
580 
581 // ==============================================
582 //
583 // look at Trigger info
584 //
585 // ==============================================
586 
587 bool CSCValidation::doTrigger(edm::Handle<L1MuGMTReadoutCollection> pCollection) {
588  std::vector<L1MuGMTReadoutRecord> L1Mrec = pCollection->getRecords();
589  std::vector<L1MuGMTReadoutRecord>::const_iterator igmtrr;
590 
591  bool csc_l1a = false;
592  bool dt_l1a = false;
593  bool rpcf_l1a = false;
594  bool rpcb_l1a = false;
595  bool beamHaloTrigger = false;
596 
597  int myBXNumber = -1000;
598 
599  for (igmtrr = L1Mrec.begin(); igmtrr != L1Mrec.end(); igmtrr++) {
600  std::vector<L1MuRegionalCand>::const_iterator iter1;
601  std::vector<L1MuRegionalCand> rmc;
602 
603  // CSC
604  int icsc = 0;
605  rmc = igmtrr->getCSCCands();
606  for (iter1 = rmc.begin(); iter1 != rmc.end(); iter1++) {
607  if (!(*iter1).empty()) {
608  icsc++;
609  int kQuality = (*iter1).quality(); // kQuality = 1 means beam halo
610  if (kQuality == 1)
611  beamHaloTrigger = true;
612  }
613  }
614  if (igmtrr->getBxInEvent() == 0 && icsc > 0)
615  csc_l1a = true;
616  if (igmtrr->getBxInEvent() == 0) {
617  myBXNumber = igmtrr->getBxNr();
618  }
619 
620  // DT
621  int idt = 0;
622  rmc = igmtrr->getDTBXCands();
623  for (iter1 = rmc.begin(); iter1 != rmc.end(); iter1++) {
624  if (!(*iter1).empty()) {
625  idt++;
626  }
627  }
628  if (igmtrr->getBxInEvent() == 0 && idt > 0)
629  dt_l1a = true;
630 
631  // RPC Barrel
632  int irpcb = 0;
633  rmc = igmtrr->getBrlRPCCands();
634  for (iter1 = rmc.begin(); iter1 != rmc.end(); iter1++) {
635  if (!(*iter1).empty()) {
636  irpcb++;
637  }
638  }
639  if (igmtrr->getBxInEvent() == 0 && irpcb > 0)
640  rpcb_l1a = true;
641 
642  // RPC Forward
643  int irpcf = 0;
644  rmc = igmtrr->getFwdRPCCands();
645  for (iter1 = rmc.begin(); iter1 != rmc.end(); iter1++) {
646  if (!(*iter1).empty()) {
647  irpcf++;
648  }
649  }
650  if (igmtrr->getBxInEvent() == 0 && irpcf > 0)
651  rpcf_l1a = true;
652  }
653 
654  // Fill some histograms with L1A info
655  if (csc_l1a)
656  histos->fill1DHist(myBXNumber, "vtBXNumber", "BX Number", 4001, -0.5, 4000.5, "Trigger");
657  if (csc_l1a)
658  histos->fill1DHist(1, "vtBits", "trigger bits", 11, -0.5, 10.5, "Trigger");
659  if (dt_l1a)
660  histos->fill1DHist(2, "vtBits", "trigger bits", 11, -0.5, 10.5, "Trigger");
661  if (rpcb_l1a)
662  histos->fill1DHist(3, "vtBits", "trigger bits", 11, -0.5, 10.5, "Trigger");
663  if (rpcf_l1a)
664  histos->fill1DHist(4, "vtBits", "trigger bits", 11, -0.5, 10.5, "Trigger");
665  if (beamHaloTrigger)
666  histos->fill1DHist(8, "vtBits", "trigger bits", 11, -0.5, 10.5, "Trigger");
667 
668  if (csc_l1a) {
669  histos->fill1DHist(1, "vtCSCY", "trigger bits", 11, -0.5, 10.5, "Trigger");
670  if (dt_l1a)
671  histos->fill1DHist(2, "vtCSCY", "trigger bits", 11, -0.5, 10.5, "Trigger");
672  if (rpcb_l1a)
673  histos->fill1DHist(3, "vtCSCY", "trigger bits", 11, -0.5, 10.5, "Trigger");
674  if (rpcf_l1a)
675  histos->fill1DHist(4, "vtCSCY", "trigger bits", 11, -0.5, 10.5, "Trigger");
676  if (dt_l1a || rpcb_l1a || rpcf_l1a)
677  histos->fill1DHist(5, "vtCSCY", "trigger bits", 11, -0.5, 10.5, "Trigger");
678  if (!(dt_l1a || rpcb_l1a || rpcf_l1a))
679  histos->fill1DHist(6, "vtCSCY", "trigger bits", 11, -0.5, 10.5, "Trigger");
680  } else {
681  histos->fill1DHist(1, "vtCSCN", "trigger bits", 11, -0.5, 10.5, "Trigger");
682  if (dt_l1a)
683  histos->fill1DHist(2, "vtCSCN", "trigger bits", 11, -0.5, 10.5, "Trigger");
684  if (rpcb_l1a)
685  histos->fill1DHist(3, "vtCSCN", "trigger bits", 11, -0.5, 10.5, "Trigger");
686  if (rpcf_l1a)
687  histos->fill1DHist(4, "vtCSCN", "trigger bits", 11, -0.5, 10.5, "Trigger");
688  if (dt_l1a || rpcb_l1a || rpcf_l1a)
689  histos->fill1DHist(5, "vtCSCN", "trigger bits", 11, -0.5, 10.5, "Trigger");
690  if (!(dt_l1a || rpcb_l1a || rpcf_l1a))
691  histos->fill1DHist(6, "vtCSCN", "trigger bits", 11, -0.5, 10.5, "Trigger");
692  }
693 
694  // if valid CSC L1A then return true for possible use elsewhere
695 
696  if (csc_l1a)
697  return true;
698 
699  return false;
700 }
701 
702 // ==============================================
703 //
704 // look at HLT Trigger
705 //
706 // ==============================================
707 
708 bool CSCValidation::doHLT(Handle<TriggerResults> hlt) {
709  // HLT stuff
710  int hltSize = hlt->size();
711  for (int i = 0; i < hltSize; ++i) {
712  if (hlt->accept(i))
713  histos->fill1DHist(i, "hltBits", "HLT Trigger Bits", hltSize + 1, -0.5, (float)hltSize + 0.5, "Trigger");
714  }
715 
716  return true;
717 }
718 
719 // ==============================================
720 //
721 // look at Calibrations
722 //
723 // ==============================================
724 
725 void CSCValidation::doCalibrations(const edm::EventSetup& eventSetup) {
726  // Only do this for the first event
727  if (nEventsAnalyzed == 1) {
728  LogDebug("Calibrations") << "Loading Calibrations...";
729 
730  // get the gains
731  edm::ESHandle<CSCDBGains> hGains = eventSetup.getHandle(gainsToken_);
732  const CSCDBGains* pGains = hGains.product();
733  // get the crosstalks
734  edm::ESHandle<CSCDBCrosstalk> hCrosstalk = eventSetup.getHandle(crosstalkToken_);
735  const CSCDBCrosstalk* pCrosstalk = hCrosstalk.product();
736  // get the noise matrix
737  edm::ESHandle<CSCDBNoiseMatrix> hNoiseMatrix = eventSetup.getHandle(noiseToken_);
738  const CSCDBNoiseMatrix* pNoiseMatrix = hNoiseMatrix.product();
739  // get pedestals
740  edm::ESHandle<CSCDBPedestals> hPedestals = eventSetup.getHandle(pedestalsToken_);
741  const CSCDBPedestals* pPedestals = hPedestals.product();
742 
743  LogDebug("Calibrations") << "Calibrations Loaded!";
744 
745  for (int i = 0; i < 400; i++) {
746  int bin = i + 1;
747  histos->fillCalibHist(pGains->gains[i].gain_slope, "hCalibGainsS", "Gains Slope", 400, 0, 400, bin, "Calib");
748  histos->fillCalibHist(
749  pCrosstalk->crosstalk[i].xtalk_slope_left, "hCalibXtalkSL", "Xtalk Slope Left", 400, 0, 400, bin, "Calib");
750  histos->fillCalibHist(
751  pCrosstalk->crosstalk[i].xtalk_slope_right, "hCalibXtalkSR", "Xtalk Slope Right", 400, 0, 400, bin, "Calib");
752  histos->fillCalibHist(pCrosstalk->crosstalk[i].xtalk_intercept_left,
753  "hCalibXtalkIL",
754  "Xtalk Intercept Left",
755  400,
756  0,
757  400,
758  bin,
759  "Calib");
760  histos->fillCalibHist(pCrosstalk->crosstalk[i].xtalk_intercept_right,
761  "hCalibXtalkIR",
762  "Xtalk Intercept Right",
763  400,
764  0,
765  400,
766  bin,
767  "Calib");
768  histos->fillCalibHist(pPedestals->pedestals[i].ped, "hCalibPedsP", "Peds", 400, 0, 400, bin, "Calib");
769  histos->fillCalibHist(pPedestals->pedestals[i].rms, "hCalibPedsR", "Peds RMS", 400, 0, 400, bin, "Calib");
770  histos->fillCalibHist(
771  pNoiseMatrix->matrix[i].elem33, "hCalibNoise33", "Noise Matrix 33", 400, 0, 400, bin, "Calib");
772  histos->fillCalibHist(
773  pNoiseMatrix->matrix[i].elem34, "hCalibNoise34", "Noise Matrix 34", 400, 0, 400, bin, "Calib");
774  histos->fillCalibHist(
775  pNoiseMatrix->matrix[i].elem35, "hCalibNoise35", "Noise Matrix 35", 400, 0, 400, bin, "Calib");
776  histos->fillCalibHist(
777  pNoiseMatrix->matrix[i].elem44, "hCalibNoise44", "Noise Matrix 44", 400, 0, 400, bin, "Calib");
778  histos->fillCalibHist(
779  pNoiseMatrix->matrix[i].elem45, "hCalibNoise45", "Noise Matrix 45", 400, 0, 400, bin, "Calib");
780  histos->fillCalibHist(
781  pNoiseMatrix->matrix[i].elem46, "hCalibNoise46", "Noise Matrix 46", 400, 0, 400, bin, "Calib");
782  histos->fillCalibHist(
783  pNoiseMatrix->matrix[i].elem55, "hCalibNoise55", "Noise Matrix 55", 400, 0, 400, bin, "Calib");
784  histos->fillCalibHist(
785  pNoiseMatrix->matrix[i].elem56, "hCalibNoise56", "Noise Matrix 56", 400, 0, 400, bin, "Calib");
786  histos->fillCalibHist(
787  pNoiseMatrix->matrix[i].elem57, "hCalibNoise57", "Noise Matrix 57", 400, 0, 400, bin, "Calib");
788  histos->fillCalibHist(
789  pNoiseMatrix->matrix[i].elem66, "hCalibNoise66", "Noise Matrix 66", 400, 0, 400, bin, "Calib");
790  histos->fillCalibHist(
791  pNoiseMatrix->matrix[i].elem67, "hCalibNoise67", "Noise Matrix 67", 400, 0, 400, bin, "Calib");
792  histos->fillCalibHist(
793  pNoiseMatrix->matrix[i].elem77, "hCalibNoise77", "Noise Matrix 77", 400, 0, 400, bin, "Calib");
794  }
795  }
796 }
797 
798 // ==============================================
799 //
800 // look at WIRE DIGIs
801 //
802 // ==============================================
803 
804 void CSCValidation::doWireDigis(edm::Handle<CSCWireDigiCollection> wires) {
805  int nWireGroupsTotal = 0;
806  for (CSCWireDigiCollection::DigiRangeIterator dWDiter = wires->begin(); dWDiter != wires->end(); dWDiter++) {
807  CSCDetId id = (CSCDetId)(*dWDiter).first;
808  std::vector<CSCWireDigi>::const_iterator wireIter = (*dWDiter).second.first;
809  std::vector<CSCWireDigi>::const_iterator lWire = (*dWDiter).second.second;
810  for (; wireIter != lWire; ++wireIter) {
811  int myWire = wireIter->getWireGroup();
812  int myTBin = wireIter->getTimeBin();
813  nWireGroupsTotal++;
814  histos->fill1DHistByType(myWire, "hWireWire", "Wiregroup Numbers Fired", id, 113, -0.5, 112.5, "Digis");
815  histos->fill1DHistByType(myTBin, "hWireTBin", "Wire TimeBin Fired", id, 17, -0.5, 16.5, "Digis");
816  histos->fillProfile(
817  chamberSerial(id), myTBin, "hWireTBinProfile", "Wire TimeBin Fired", 601, -0.5, 600.5, -0.5, 16.5, "Digis");
818  if (detailedAnalysis) {
819  histos->fill1DHistByLayer(
820  myWire, "hWireWire", "Wiregroup Numbers Fired", id, 113, -0.5, 112.5, "WireNumberByLayer");
821  histos->fill1DHistByLayer(myTBin, "hWireTBin", "Wire TimeBin Fired", id, 17, -0.5, 16.5, "WireTimeByLayer");
822  }
823  }
824  } // end wire loop
825 
826  // this way you can zero suppress but still store info on # events with no digis
827  if (nWireGroupsTotal == 0)
828  nWireGroupsTotal = -1;
829 
830  histos->fill1DHist(nWireGroupsTotal, "hWirenGroupsTotal", "Wires Fired Per Event", 251, -0.5, 250.5, "Digis");
831 }
832 
833 // ==============================================
834 //
835 // look at STRIP DIGIs
836 //
837 // ==============================================
838 
839 void CSCValidation::doStripDigis(edm::Handle<CSCStripDigiCollection> strips) {
840  int nStripsFired = 0;
841  for (CSCStripDigiCollection::DigiRangeIterator dSDiter = strips->begin(); dSDiter != strips->end(); dSDiter++) {
842  CSCDetId id = (CSCDetId)(*dSDiter).first;
843  std::vector<CSCStripDigi>::const_iterator stripIter = (*dSDiter).second.first;
844  std::vector<CSCStripDigi>::const_iterator lStrip = (*dSDiter).second.second;
845  for (; stripIter != lStrip; ++stripIter) {
846  int myStrip = stripIter->getStrip();
847  std::vector<int> myADCVals = stripIter->getADCCounts();
848  bool thisStripFired = false;
849  float thisPedestal = 0.5 * (float)(myADCVals[0] + myADCVals[1]);
850  float threshold = 13.3;
851  float diff = 0.;
852  for (unsigned int iCount = 0; iCount < myADCVals.size(); iCount++) {
853  diff = (float)myADCVals[iCount] - thisPedestal;
854  if (diff > threshold) {
855  thisStripFired = true;
856  }
857  }
858  if (thisStripFired) {
859  nStripsFired++;
860  // fill strip histos
861  histos->fill1DHistByType(myStrip, "hStripStrip", "Strip Number", id, 81, -0.5, 80.5, "Digis");
862  if (detailedAnalysis) {
863  histos->fill1DHistByLayer(myStrip, "hStripStrip", "Strip Number", id, 81, -0.5, 80.5, "StripNumberByLayer");
864  }
865  }
866  }
867  } // end strip loop
868 
869  if (nStripsFired == 0)
870  nStripsFired = -1;
871 
872  histos->fill1DHist(nStripsFired, "hStripNFired", "Fired Strips per Event", 351, -0.5, 350.5, "Digis");
873 }
874 
875 //=======================================================
876 //
877 // Look at the Pedestal Noise Distributions
878 //
879 //=======================================================
880 
881 void CSCValidation::doPedestalNoise(edm::Handle<CSCStripDigiCollection> strips) {
882  constexpr float threshold = 13.3;
883  for (CSCStripDigiCollection::DigiRangeIterator dPNiter = strips->begin(); dPNiter != strips->end(); dPNiter++) {
884  CSCDetId id = (CSCDetId)(*dPNiter).first;
885  std::vector<CSCStripDigi>::const_iterator pedIt = (*dPNiter).second.first;
886  std::vector<CSCStripDigi>::const_iterator lStrip = (*dPNiter).second.second;
887  for (; pedIt != lStrip; ++pedIt) {
888  int myStrip = pedIt->getStrip();
889  std::vector<int> myADCVals = pedIt->getADCCounts();
890  float TotalADC = getSignal(*strips, id, myStrip);
891  float thisPedestal = 0.5 * (float)(myADCVals[0] + myADCVals[1]);
892  float thisSignal =
893  (1. / 6) * (myADCVals[2] + myADCVals[3] + myADCVals[4] + myADCVals[5] + myADCVals[6] + myADCVals[7]);
894  bool thisStripFired = TotalADC > threshold;
895  if (!thisStripFired) {
896  float ADC = thisSignal - thisPedestal;
897  histos->fill1DHist(ADC, "hStripPed", "Pedestal Noise Distribution", 50, -25., 25., "PedestalNoise");
898  histos->fill1DHistByType(ADC, "hStripPedME", "Pedestal Noise Distribution", id, 50, -25., 25., "PedestalNoise");
899  histos->fillProfile(chamberSerial(id),
900  ADC,
901  "hStripPedMEProfile",
902  "Wire TimeBin Fired",
903  601,
904  -0.5,
905  600.5,
906  -25,
907  25,
908  "PedestalNoise");
909  if (detailedAnalysis) {
910  histos->fill1DHistByLayer(
911  ADC, "hStripPedME", "Pedestal Noise Distribution", id, 50, -25., 25., "PedestalNoiseByLayer");
912  }
913  }
914  }
915  }
916 }
917 
918 // ==============================================
919 //
920 // look at RECHITs
921 //
922 // ==============================================
923 
924 void CSCValidation::doRecHits(edm::Handle<CSCRecHit2DCollection> recHits, edm::ESHandle<CSCGeometry> cscGeom) {
925  // Get the RecHits collection :
926  int nRecHits = recHits->size();
927 
928  // ---------------------
929  // Loop over rechits
930  // ---------------------
931  int iHit = 0;
932 
933  // Build iterator for rechits and loop :
935  for (dRHIter = recHits->begin(); dRHIter != recHits->end(); dRHIter++) {
936  iHit++;
937 
938  // Find chamber with rechits in CSC
939  CSCDetId idrec = (CSCDetId)(*dRHIter).cscDetId();
940  int kEndcap = idrec.endcap();
941  int kRing = idrec.ring();
942  int kStation = idrec.station();
943  int kChamber = idrec.chamber();
944  int kLayer = idrec.layer();
945 
946  // Store rechit as a Local Point:
947  LocalPoint rhitlocal = (*dRHIter).localPosition();
948  float xreco = rhitlocal.x();
949  float yreco = rhitlocal.y();
950  LocalError rerrlocal = (*dRHIter).localPositionError();
951  //these errors are squared!
952  float xxerr = rerrlocal.xx();
953  float yyerr = rerrlocal.yy();
954  float xyerr = rerrlocal.xy();
955  // errors in strip units
956  float stpos = (*dRHIter).positionWithinStrip();
957  float sterr = (*dRHIter).errorWithinStrip();
958 
959  // Find the charge associated with this hit
960  float rHSumQ = 0;
961  float sumsides = 0.;
962  int adcsize = dRHIter->nStrips() * dRHIter->nTimeBins();
963  for (unsigned int i = 0; i < dRHIter->nStrips(); i++) {
964  for (unsigned int j = 0; j < dRHIter->nTimeBins() - 1; j++) {
965  rHSumQ += dRHIter->adcs(i, j);
966  if (i != 1)
967  sumsides += dRHIter->adcs(i, j);
968  }
969  }
970 
971  float rHratioQ = sumsides / rHSumQ;
972  if (adcsize != 12)
973  rHratioQ = -99;
974 
975  // Get the signal timing of this hit
976  float rHtime = 0;
977  rHtime = (*dRHIter).tpeak() / 50.;
978 
979  // Get pointer to the layer:
980  const CSCLayer* csclayer = cscGeom->layer(idrec);
981 
982  // Transform hit position from local chamber geometry to global CMS geom
983  GlobalPoint rhitglobal = csclayer->toGlobal(rhitlocal);
984  float grecx = rhitglobal.x();
985  float grecy = rhitglobal.y();
986 
987  // Fill the rechit position branch
988  if (writeTreeToFile && rhTreeCount < 1500000) {
989  histos->fillRechitTree(xreco, yreco, grecx, grecy, kEndcap, kStation, kRing, kChamber, kLayer);
990  rhTreeCount++;
991  }
992 
993  // Fill some histograms
994  // only fill if 3 strips were used in the hit
995  histos->fill2DHistByStation(
996  grecx, grecy, "hRHGlobal", "recHit Global Position", idrec, 100, -800., 800., 100, -800., 800., "recHits");
997  if (kStation == 1 && (kRing == 1 || kRing == 4))
998  histos->fill1DHistByType(rHSumQ, "hRHSumQ", "Sum 3x3 recHit Charge", idrec, 125, 0, 4000, "recHits");
999  else
1000  histos->fill1DHistByType(rHSumQ, "hRHSumQ", "Sum 3x3 recHit Charge", idrec, 125, 0, 2000, "recHits");
1001  histos->fill1DHistByType(rHratioQ, "hRHRatioQ", "Charge Ratio (Ql+Qr)/Qt", idrec, 120, -0.1, 1.1, "recHits");
1002  histos->fill1DHistByType(rHtime, "hRHTiming", "recHit Timing", idrec, 200, -10, 10, "recHits");
1003  histos->fill1DHistByType(sqrt(xxerr), "hRHxerr", "RecHit Error on Local X", idrec, 100, -0.1, 2, "recHits");
1004  histos->fill1DHistByType(sqrt(yyerr), "hRHyerr", "RecHit Error on Local Y", idrec, 100, -0.1, 2, "recHits");
1005  histos->fill1DHistByType(xyerr, "hRHxyerr", "Corr. RecHit XY Error", idrec, 100, -1, 2, "recHits");
1006  if (adcsize == 12)
1007  histos->fill1DHistByType(stpos, "hRHstpos", "Reconstructed Position on Strip", idrec, 120, -0.6, 0.6, "recHits");
1008  histos->fill1DHistByType(
1009  sterr, "hRHsterr", "Estimated Error on Strip Measurement", idrec, 120, -0.05, 0.25, "recHits");
1010  histos->fillProfile(
1011  chamberSerial(idrec), rHSumQ, "hRHSumQProfile", "Sum 3x3 recHit Charge", 601, -0.5, 600.5, 0, 4000, "recHits");
1012  histos->fillProfile(
1013  chamberSerial(idrec), rHtime, "hRHTimingProfile", "recHit Timing", 601, -0.5, 600.5, -11, 11, "recHits");
1014  if (detailedAnalysis) {
1015  if (kStation == 1 && (kRing == 1 || kRing == 4))
1016  histos->fill1DHistByLayer(rHSumQ, "hRHSumQ", "Sum 3x3 recHit Charge", idrec, 125, 0, 4000, "RHQByLayer");
1017  else
1018  histos->fill1DHistByLayer(rHSumQ, "hRHSumQ", "Sum 3x3 recHit Charge", idrec, 125, 0, 2000, "RHQByLayer");
1019  histos->fill1DHistByLayer(rHratioQ, "hRHRatioQ", "Charge Ratio (Ql+Qr)/Qt", idrec, 120, -0.1, 1.1, "RHQByLayer");
1020  histos->fill1DHistByLayer(rHtime, "hRHTiming", "recHit Timing", idrec, 200, -10, 10, "RHTimingByLayer");
1021  histos->fill2DHistByLayer(xreco,
1022  yreco,
1023  "hRHLocalXY",
1024  "recHit Local Position",
1025  idrec,
1026  50,
1027  -100.,
1028  100.,
1029  75,
1030  -150.,
1031  150.,
1032  "RHLocalXYByLayer");
1033  histos->fill1DHistByLayer(
1034  sqrt(xxerr), "hRHxerr", "RecHit Error on Local X", idrec, 100, -0.1, 2, "RHErrorsByLayer");
1035  histos->fill1DHistByLayer(
1036  sqrt(yyerr), "hRHyerr", "RecHit Error on Local Y", idrec, 100, -0.1, 2, "RHErrorsByLayer");
1037  histos->fill1DHistByType(
1038  stpos, "hRHstpos", "Reconstructed Position on Strip", idrec, 120, -0.6, 0.6, "RHStripPosByLayer");
1039  histos->fill1DHistByType(
1040  sterr, "hRHsterr", "Estimated Error on Strip Measurement", idrec, 120, -0.05, 0.25, "RHStripPosByLayer");
1041  }
1042 
1043  } //end rechit loop
1044 
1045  if (nRecHits == 0)
1046  nRecHits = -1;
1047 
1048  histos->fill1DHist(nRecHits, "hRHnrechits", "recHits per Event (all chambers)", 201, -0.5, 200.5, "recHits");
1049 }
1050 
1051 // ==============================================
1052 //
1053 // look at SIMHITS
1054 //
1055 // ==============================================
1056 
1059  for (dSHrecIter = recHits->begin(); dSHrecIter != recHits->end(); dSHrecIter++) {
1060  CSCDetId idrec = (CSCDetId)(*dSHrecIter).cscDetId();
1061  LocalPoint rhitlocal = (*dSHrecIter).localPosition();
1062  float xreco = rhitlocal.x();
1063  float yreco = rhitlocal.y();
1064  float xError = sqrt((*dSHrecIter).localPositionError().xx());
1065  float yError = sqrt((*dSHrecIter).localPositionError().yy());
1066  float simHitXres = -99;
1067  float simHitYres = -99;
1068  float xPull = -99;
1069  float yPull = -99;
1070  float mindiffX = 99;
1071  float mindiffY = 10;
1072  // If MC, find closest muon simHit to check resolution:
1073  PSimHitContainer::const_iterator dSHsimIter;
1074  for (dSHsimIter = simHits->begin(); dSHsimIter != simHits->end(); dSHsimIter++) {
1075  // Get DetID for this simHit:
1076  CSCDetId sId = (CSCDetId)(*dSHsimIter).detUnitId();
1077  // Check if the simHit detID matches that of current recHit
1078  // and make sure it is a muon hit:
1079  if (sId == idrec && abs((*dSHsimIter).particleType()) == 13) {
1080  // Get the position of this simHit in local coordinate system:
1081  LocalPoint sHitlocal = (*dSHsimIter).localPosition();
1082  // Now we need to make reasonably sure that this simHit is
1083  // responsible for this recHit:
1084  if ((sHitlocal.x() - xreco) < mindiffX && (sHitlocal.y() - yreco) < mindiffY) {
1085  simHitXres = (sHitlocal.x() - xreco);
1086  simHitYres = (sHitlocal.y() - yreco);
1087  mindiffX = (sHitlocal.x() - xreco);
1088  xPull = simHitXres / xError;
1089  yPull = simHitYres / yError;
1090  }
1091  }
1092  }
1093 
1094  histos->fill1DHistByType(
1095  simHitXres, "hSimXResid", "SimHitX - Reconstructed X", idrec, 100, -1.0, 1.0, "Resolution");
1096  histos->fill1DHistByType(
1097  simHitYres, "hSimYResid", "SimHitY - Reconstructed Y", idrec, 100, -5.0, 5.0, "Resolution");
1098  histos->fill1DHistByType(xPull, "hSimXPull", "Local X Pulls", idrec, 100, -5.0, 5.0, "Resolution");
1099  histos->fill1DHistByType(yPull, "hSimYPull", "Local Y Pulls", idrec, 100, -5.0, 5.0, "Resolution");
1100  }
1101 }
1102 
1103 // ==============================================
1104 //
1105 // look at SEGMENTs
1106 //
1107 // ===============================================
1108 
1109 void CSCValidation::doSegments(edm::Handle<CSCSegmentCollection> cscSegments, edm::ESHandle<CSCGeometry> cscGeom) {
1110  // get CSC segment collection
1111  int nSegments = cscSegments->size();
1112 
1113  // -----------------------
1114  // loop over segments
1115  // -----------------------
1116  int iSegment = 0;
1117  for (CSCSegmentCollection::const_iterator dSiter = cscSegments->begin(); dSiter != cscSegments->end(); dSiter++) {
1118  iSegment++;
1119  //
1120  CSCDetId id = (CSCDetId)(*dSiter).cscDetId();
1121  int kEndcap = id.endcap();
1122  int kRing = id.ring();
1123  int kStation = id.station();
1124  int kChamber = id.chamber();
1125 
1126  //
1127  float chisq = (*dSiter).chi2();
1128  int nhits = (*dSiter).nRecHits();
1129  int nDOF = 2 * nhits - 4;
1130  double chisqProb = ChiSquaredProbability((double)chisq, nDOF);
1131  LocalPoint localPos = (*dSiter).localPosition();
1132  float segX = localPos.x();
1133  float segY = localPos.y();
1134  LocalVector segDir = (*dSiter).localDirection();
1135  double theta = segDir.theta();
1136 
1137  // global transformation
1138  float globX = 0.;
1139  float globY = 0.;
1140  float globTheta = 0.;
1141  float globPhi = 0.;
1142  const CSCChamber* cscchamber = cscGeom->chamber(id);
1143  if (cscchamber) {
1144  GlobalPoint globalPosition = cscchamber->toGlobal(localPos);
1145  globX = globalPosition.x();
1146  globY = globalPosition.y();
1147  GlobalVector globalDirection = cscchamber->toGlobal(segDir);
1148  globTheta = globalDirection.theta();
1149  globPhi = globalDirection.phi();
1150  }
1151 
1152  // Fill segment position branch
1153  if (writeTreeToFile && segTreeCount < 1500000) {
1154  histos->fillSegmentTree(segX, segY, globX, globY, kEndcap, kStation, kRing, kChamber);
1155  segTreeCount++;
1156  }
1157 
1158  // Fill histos
1159  histos->fill2DHistByStation(globX,
1160  globY,
1161  "hSGlobal",
1162  "Segment Global Positions;global x (cm)",
1163  id,
1164  100,
1165  -800.,
1166  800.,
1167  100,
1168  -800.,
1169  800.,
1170  "Segments");
1171  histos->fill1DHistByType(nhits, "hSnHits", "N hits on Segments", id, 8, -0.5, 7.5, "Segments");
1172  histos->fill1DHistByType(theta, "hSTheta", "local theta segments", id, 128, -3.2, 3.2, "Segments");
1173  histos->fill1DHistByType((chisq / nDOF), "hSChiSq", "segments chi-squared/ndof", id, 110, -0.05, 10.5, "Segments");
1174  histos->fill1DHistByType(
1175  chisqProb, "hSChiSqProb", "segments chi-squared probability", id, 110, -0.05, 1.05, "Segments");
1176  histos->fill1DHist(globTheta, "hSGlobalTheta", "segment global theta", 128, 0, 3.2, "Segments");
1177  histos->fill1DHist(globPhi, "hSGlobalPhi", "segment global phi", 128, -3.2, 3.2, "Segments");
1178  histos->fillProfile(
1179  chamberSerial(id), nhits, "hSnHitsProfile", "N hits on Segments", 601, -0.5, 600.5, -0.5, 7.5, "Segments");
1180  if (detailedAnalysis) {
1181  histos->fill1DHistByChamber(nhits, "hSnHits", "N hits on Segments", id, 8, -0.5, 7.5, "HitsOnSegmentByChamber");
1182  histos->fill1DHistByChamber(theta, "hSTheta", "local theta segments", id, 128, -3.2, 3.2, "DetailedSegments");
1183  histos->fill1DHistByChamber(
1184  (chisq / nDOF), "hSChiSq", "segments chi-squared/ndof", id, 110, -0.05, 10.5, "SegChi2ByChamber");
1185  histos->fill1DHistByChamber(
1186  chisqProb, "hSChiSqProb", "segments chi-squared probability", id, 110, -0.05, 1.05, "SegChi2ByChamber");
1187  }
1188 
1189  } // end segment loop
1190 
1191  if (nSegments == 0)
1192  nSegments = -1;
1193 
1194  histos->fill1DHist(nSegments, "hSnSegments", "Segments per Event", 31, -0.5, 30.5, "Segments");
1195 }
1196 
1197 // ==============================================
1198 //
1199 // look at hit Resolution
1200 //
1201 // ===============================================
1202 
1203 void CSCValidation::doResolution(edm::Handle<CSCSegmentCollection> cscSegments, edm::ESHandle<CSCGeometry> cscGeom) {
1204  for (CSCSegmentCollection::const_iterator dSiter = cscSegments->begin(); dSiter != cscSegments->end(); dSiter++) {
1205  CSCDetId id = (CSCDetId)(*dSiter).cscDetId();
1206 
1207  //
1208  // try to get the CSC recHits that contribute to this segment.
1209  std::vector<CSCRecHit2D> theseRecHits = (*dSiter).specificRecHits();
1210  int nRH = (*dSiter).nRecHits();
1211  int jRH = 0;
1212  CLHEP::HepMatrix sp(6, 1);
1213  CLHEP::HepMatrix se(6, 1);
1214  for (std::vector<CSCRecHit2D>::const_iterator iRH = theseRecHits.begin(); iRH != theseRecHits.end(); iRH++) {
1215  jRH++;
1216  CSCDetId idRH = (CSCDetId)(*iRH).cscDetId();
1217  int kRing = idRH.ring();
1218  int kStation = idRH.station();
1219  int kLayer = idRH.layer();
1220 
1221  // Find the strip containing this hit
1222  int centerid = iRH->nStrips() / 2;
1223  int centerStrip = iRH->channels(centerid);
1224 
1225  // If this segment has 6 hits, find the position of each hit on the strip in units of stripwidth and store values
1226  if (nRH == 6) {
1227  float stpos = (*iRH).positionWithinStrip();
1228  se(kLayer, 1) = (*iRH).errorWithinStrip();
1229  // Take into account half-strip staggering of layers (ME1/1 has no staggering)
1230  if (kStation == 1 && (kRing == 1 || kRing == 4))
1231  sp(kLayer, 1) = stpos + centerStrip;
1232  else {
1233  if (kLayer == 1 || kLayer == 3 || kLayer == 5)
1234  sp(kLayer, 1) = stpos + centerStrip;
1235  if (kLayer == 2 || kLayer == 4 || kLayer == 6)
1236  sp(kLayer, 1) = stpos - 0.5 + centerStrip;
1237  }
1238  }
1239  }
1240 
1241  float residual = -99;
1242  float pull = -99;
1243  // Fit all points except layer 3, then compare expected value for layer 3 to reconstructed value
1244  if (nRH == 6) {
1245  float expected = fitX(sp, se);
1246  residual = expected - sp(3, 1);
1247  pull = residual / se(3, 1);
1248  }
1249 
1250  // Fill histos
1251  histos->fill1DHistByType(
1252  residual, "hSResid", "Fitted Position on Strip - Reconstructed for Layer 3", id, 100, -0.5, 0.5, "Resolution");
1253  histos->fill1DHistByType(pull, "hSStripPosPull", "Strip Measurement Pulls", id, 100, -5.0, 5.0, "Resolution");
1254  histos->fillProfile(chamberSerial(id),
1255  residual,
1256  "hSResidProfile",
1257  "Fitted Position on Strip - Reconstructed for Layer 3",
1258  601,
1259  -0.5,
1260  600.5,
1261  -0.5,
1262  0.5,
1263  "Resolution");
1264  if (detailedAnalysis) {
1265  histos->fill1DHistByChamber(residual,
1266  "hSResid",
1267  "Fitted Position on Strip - Reconstructed for Layer 3",
1268  id,
1269  100,
1270  -0.5,
1271  0.5,
1272  "DetailedResolution");
1273  histos->fill1DHistByChamber(pull, "hSStripPosPull", "Strip Measurement Pulls", id, 100, -5.0, 5.0, "Resolution");
1274  }
1275  }
1276 }
1277 
1278 // ==============================================
1279 //
1280 // look at Standalone Muons
1281 //
1282 // ==============================================
1283 
1284 void CSCValidation::doStandalone(Handle<reco::TrackCollection> saMuons) {
1285  int nSAMuons = saMuons->size();
1286  histos->fill1DHist(nSAMuons, "trNSAMuons", "N Standalone Muons per Event", 6, -0.5, 5.5, "STAMuons");
1287 
1288  for (reco::TrackCollection::const_iterator muon = saMuons->begin(); muon != saMuons->end(); ++muon) {
1289  float preco = muon->p();
1290  float ptreco = muon->pt();
1291  int n = muon->recHitsSize();
1292  float chi2 = muon->chi2();
1293  float normchi2 = muon->normalizedChi2();
1294 
1295  // loop over hits
1296  int nDTHits = 0;
1297  int nCSCHits = 0;
1298  int nCSCHitsp = 0;
1299  int nCSCHitsm = 0;
1300  int nRPCHits = 0;
1301  int nRPCHitsp = 0;
1302  int nRPCHitsm = 0;
1303  int np = 0;
1304  int nm = 0;
1305  std::vector<CSCDetId> staChambers;
1306  for (trackingRecHit_iterator hit = muon->recHitsBegin(); hit != muon->recHitsEnd(); ++hit) {
1307  const DetId detId((*hit)->geographicalId());
1308  if (detId.det() == DetId::Muon) {
1309  if (detId.subdetId() == MuonSubdetId::RPC) {
1310  RPCDetId rpcId(detId.rawId());
1311  nRPCHits++;
1312  if (rpcId.region() == 1) {
1313  nRPCHitsp++;
1314  np++;
1315  }
1316  if (rpcId.region() == -1) {
1317  nRPCHitsm++;
1318  nm++;
1319  }
1320  }
1321  if (detId.subdetId() == MuonSubdetId::DT) {
1322  nDTHits++;
1323  } else if (detId.subdetId() == MuonSubdetId::CSC) {
1324  CSCDetId cscId(detId.rawId());
1325  staChambers.push_back(detId.rawId());
1326  nCSCHits++;
1327  if (cscId.endcap() == 1) {
1328  nCSCHitsp++;
1329  np++;
1330  }
1331  if (cscId.endcap() == 2) {
1332  nCSCHitsm++;
1333  nm++;
1334  }
1335  }
1336  }
1337  }
1338 
1339  GlobalPoint innerPnt(muon->innerPosition().x(), muon->innerPosition().y(), muon->innerPosition().z());
1340  GlobalPoint outerPnt(muon->outerPosition().x(), muon->outerPosition().y(), muon->outerPosition().z());
1341  GlobalVector innerKin(muon->innerMomentum().x(), muon->innerMomentum().y(), muon->innerMomentum().z());
1342  GlobalVector outerKin(muon->outerMomentum().x(), muon->outerMomentum().y(), muon->outerMomentum().z());
1343  GlobalVector deltaPnt = innerPnt - outerPnt;
1344  double crudeLength = deltaPnt.mag();
1345  double deltaPhi = innerPnt.phi() - outerPnt.phi();
1346  double innerGlobalPolarAngle = innerKin.theta();
1347  double outerGlobalPolarAngle = outerKin.theta();
1348 
1349  // fill histograms
1350  histos->fill1DHist(n, "trN", "N hits on a STA Muon Track", 51, -0.5, 50.5, "STAMuons");
1351  if (np != 0)
1352  histos->fill1DHist(np, "trNp", "N hits on a STA Muon Track (plus endcap)", 51, -0.5, 50.5, "STAMuons");
1353  if (nm != 0)
1354  histos->fill1DHist(nm, "trNm", "N hits on a STA Muon Track (minus endcap)", 51, -0.5, 50.5, "STAMuons");
1355  histos->fill1DHist(nDTHits, "trNDT", "N DT hits on a STA Muon Track", 51, -0.5, 50.5, "STAMuons");
1356  histos->fill1DHist(nCSCHits, "trNCSC", "N CSC hits on a STA Muon Track", 51, -0.5, 50.5, "STAMuons");
1357  if (nCSCHitsp != 0)
1358  histos->fill1DHist(nCSCHitsp, "trNCSCp", "N CSC hits on a STA Muon Track (+ endcap)", 51, -0.5, 50.5, "STAMuons");
1359  if (nCSCHitsm != 0)
1360  histos->fill1DHist(nCSCHitsm, "trNCSCm", "N CSC hits on a STA Muon Track (- endcap)", 51, -0.5, 50.5, "STAMuons");
1361  histos->fill1DHist(nRPCHits, "trNRPC", "N RPC hits on a STA Muon Track", 51, -0.5, 50.5, "STAMuons");
1362  if (nRPCHitsp != 0)
1363  histos->fill1DHist(nRPCHitsp, "trNRPCp", "N RPC hits on a STA Muon Track (+ endcap)", 51, -0.5, 50.5, "STAMuons");
1364  if (nRPCHitsm != 0)
1365  histos->fill1DHist(nRPCHitsm, "trNRPCm", "N RPC hits on a STA Muon Track (- endcap)", 51, -0.5, 50.5, "STAMuons");
1366  histos->fill1DHist(preco, "trP", "STA Muon Momentum", 100, 0, 300, "STAMuons");
1367  histos->fill1DHist(ptreco, "trPT", "STA Muon pT", 100, 0, 40, "STAMuons");
1368  histos->fill1DHist(chi2, "trChi2", "STA Muon Chi2", 100, 0, 200, "STAMuons");
1369  histos->fill1DHist(normchi2, "trNormChi2", "STA Muon Normalized Chi2", 100, 0, 10, "STAMuons");
1370  histos->fill1DHist(crudeLength, "trLength", "Straight Line Length of STA Muon", 120, 0., 2400., "STAMuons");
1371  histos->fill1DHist(
1372  deltaPhi, "trDeltaPhi", "Delta-Phi Between Inner and Outer STA Muon Pos.", 100, -0.5, 0.5, "STAMuons");
1373  histos->fill1DHist(
1374  innerGlobalPolarAngle, "trInnerPolar", "Polar Angle of Inner P Vector (STA muons)", 128, 0, 3.2, "STAMuons");
1375  histos->fill1DHist(
1376  outerGlobalPolarAngle, "trOuterPolar", "Polar Angle of Outer P Vector (STA muons)", 128, 0, 3.2, "STAMuons");
1377  histos->fill1DHist(innerPnt.phi(), "trInnerPhi", "Phi of Inner Position (STA muons)", 256, -3.2, 3.2, "STAMuons");
1378  histos->fill1DHist(outerPnt.phi(), "trOuterPhi", "Phi of Outer Position (STA muons)", 256, -3.2, 3.2, "STAMuons");
1379  }
1380 }
1381 
1382 //--------------------------------------------------------------
1383 // Compute a serial number for the chamber.
1384 // This is useful when filling histograms and working with arrays.
1385 //--------------------------------------------------------------
1386 int CSCValidation::chamberSerial(CSCDetId id) {
1387  int st = id.station();
1388  int ri = id.ring();
1389  int ch = id.chamber();
1390  int ec = id.endcap();
1391  int kSerial = ch;
1392  if (st == 1 && ri == 1)
1393  kSerial = ch;
1394  if (st == 1 && ri == 2)
1395  kSerial = ch + 36;
1396  if (st == 1 && ri == 3)
1397  kSerial = ch + 72;
1398  if (st == 1 && ri == 4)
1399  kSerial = ch;
1400  if (st == 2 && ri == 1)
1401  kSerial = ch + 108;
1402  if (st == 2 && ri == 2)
1403  kSerial = ch + 126;
1404  if (st == 3 && ri == 1)
1405  kSerial = ch + 162;
1406  if (st == 3 && ri == 2)
1407  kSerial = ch + 180;
1408  if (st == 4 && ri == 1)
1409  kSerial = ch + 216;
1410  if (st == 4 && ri == 2)
1411  kSerial = ch + 234;
1412  if (ec == 2)
1413  kSerial = kSerial + 300;
1414  return kSerial;
1415 }
1416 
1417 //--------------------------------------------------------------
1418 // Compute a serial number for the ring.
1419 // This is useful when filling histograms and working with arrays.
1420 //--------------------------------------------------------------
1421 int CSCValidation::ringSerial(CSCDetId id) {
1422  int st = id.station();
1423  int ri = id.ring();
1424  int ec = id.endcap();
1425  int kSerial = 0;
1426  if (st == 1 && ri == 1)
1427  kSerial = ri;
1428  if (st == 1 && ri == 2)
1429  kSerial = ri;
1430  if (st == 1 && ri == 3)
1431  kSerial = ri;
1432  if (st == 1 && ri == 4)
1433  kSerial = 1;
1434  if (st == 2)
1435  kSerial = ri + 3;
1436  if (st == 3)
1437  kSerial = ri + 5;
1438  if (st == 4)
1439  kSerial = ri + 7;
1440  if (ec == 2)
1441  kSerial = kSerial * (-1);
1442  return kSerial;
1443 }
1444 
1445 //-------------------------------------------------------------------------------------
1446 // Fits a straight line to a set of 5 points with errors. Functions assumes 6 points
1447 // and removes hit in layer 3. It then returns the expected position value in layer 3
1448 // based on the fit.
1449 //-------------------------------------------------------------------------------------
1450 float CSCValidation::fitX(const CLHEP::HepMatrix& points, const CLHEP::HepMatrix& errors) {
1451  float S = 0;
1452  float Sx = 0;
1453  float Sy = 0;
1454  float Sxx = 0;
1455  float Sxy = 0;
1456  float sigma2 = 0;
1457 
1458  for (int i = 1; i < 7; i++) {
1459  if (i != 3) {
1460  sigma2 = errors(i, 1) * errors(i, 1);
1461  S = S + (1 / sigma2);
1462  Sy = Sy + (points(i, 1) / sigma2);
1463  Sx = Sx + ((i) / sigma2);
1464  Sxx = Sxx + (i * i) / sigma2;
1465  Sxy = Sxy + (((i)*points(i, 1)) / sigma2);
1466  }
1467  }
1468 
1469  float delta = S * Sxx - Sx * Sx;
1470  float intercept = (Sxx * Sy - Sx * Sxy) / delta;
1471  float slope = (S * Sxy - Sx * Sy) / delta;
1472 
1473  //float chi = 0;
1474  //float chi2 = 0;
1475 
1476  // calculate chi2 (not currently used)
1477  //for (int i=1;i<7;i++){
1478  // chi = (points(i,1) - intercept - slope*i)/(errors(i,1));
1479  // chi2 = chi2 + chi*chi;
1480  //}
1481 
1482  return (intercept + slope * 3);
1483 }
1484 
1485 //----------------------------------------------------------------------------
1486 // Calculate basic efficiencies for recHits and Segments
1487 // Author: S. Stoynev
1488 //----------------------------------------------------------------------------
1489 
1490 void CSCValidation::doEfficiencies(edm::Handle<CSCWireDigiCollection> wires,
1494  edm::ESHandle<CSCGeometry> cscGeom) {
1495  bool allWires[2][4][4][36][6];
1496  bool allStrips[2][4][4][36][6];
1497  bool AllRecHits[2][4][4][36][6];
1498  bool AllSegments[2][4][4][36];
1499 
1500  //bool MultiSegments[2][4][4][36];
1501  for (int iE = 0; iE < 2; iE++) {
1502  for (int iS = 0; iS < 4; iS++) {
1503  for (int iR = 0; iR < 4; iR++) {
1504  for (int iC = 0; iC < 36; iC++) {
1505  AllSegments[iE][iS][iR][iC] = false;
1506  //MultiSegments[iE][iS][iR][iC] = false;
1507  for (int iL = 0; iL < 6; iL++) {
1508  allWires[iE][iS][iR][iC][iL] = false;
1509  allStrips[iE][iS][iR][iC][iL] = false;
1510  AllRecHits[iE][iS][iR][iC][iL] = false;
1511  }
1512  }
1513  }
1514  }
1515  }
1516 
1517  if (useDigis) {
1518  // Wires
1519  for (CSCWireDigiCollection::DigiRangeIterator dWDiter = wires->begin(); dWDiter != wires->end(); dWDiter++) {
1520  CSCDetId idrec = (CSCDetId)(*dWDiter).first;
1521  std::vector<CSCWireDigi>::const_iterator wireIter = (*dWDiter).second.first;
1522  std::vector<CSCWireDigi>::const_iterator lWire = (*dWDiter).second.second;
1523  for (; wireIter != lWire; ++wireIter) {
1524  allWires[idrec.endcap() - 1][idrec.station() - 1][idrec.ring() - 1][idrec.chamber() - 1][idrec.layer() - 1] =
1525  true;
1526  break;
1527  }
1528  }
1529 
1530  //---- STRIPS
1531  for (CSCStripDigiCollection::DigiRangeIterator dSDiter = strips->begin(); dSDiter != strips->end(); dSDiter++) {
1532  CSCDetId idrec = (CSCDetId)(*dSDiter).first;
1533  std::vector<CSCStripDigi>::const_iterator stripIter = (*dSDiter).second.first;
1534  std::vector<CSCStripDigi>::const_iterator lStrip = (*dSDiter).second.second;
1535  for (; stripIter != lStrip; ++stripIter) {
1536  std::vector<int> myADCVals = stripIter->getADCCounts();
1537  bool thisStripFired = false;
1538  float thisPedestal = 0.5 * (float)(myADCVals[0] + myADCVals[1]);
1539  float threshold = 13.3;
1540  float diff = 0.;
1541  for (unsigned int iCount = 0; iCount < myADCVals.size(); iCount++) {
1542  diff = (float)myADCVals[iCount] - thisPedestal;
1543  if (diff > threshold) {
1544  thisStripFired = true;
1545  break;
1546  }
1547  }
1548  if (thisStripFired) {
1549  allStrips[idrec.endcap() - 1][idrec.station() - 1][idrec.ring() - 1][idrec.chamber() - 1][idrec.layer() - 1] =
1550  true;
1551  break;
1552  }
1553  }
1554  }
1555  }
1556 
1557  // Rechits
1558  for (CSCRecHit2DCollection::const_iterator recEffIt = recHits->begin(); recEffIt != recHits->end(); recEffIt++) {
1559  //CSCDetId idrec = (CSCDetId)(*recIt).cscDetId();
1560  CSCDetId idrec = (CSCDetId)(*recEffIt).cscDetId();
1561  AllRecHits[idrec.endcap() - 1][idrec.station() - 1][idrec.ring() - 1][idrec.chamber() - 1][idrec.layer() - 1] =
1562  true;
1563  }
1564 
1565  std::vector<unsigned int> seg_ME2(2, 0);
1566  std::vector<unsigned int> seg_ME3(2, 0);
1567  std::vector<std::pair<CSCDetId, CSCSegment> > theSegments(4);
1568  // Segments
1569  for (CSCSegmentCollection::const_iterator segEffIt = cscSegments->begin(); segEffIt != cscSegments->end();
1570  segEffIt++) {
1571  CSCDetId idseg = (CSCDetId)(*segEffIt).cscDetId();
1572  //if(AllSegments[idrec.endcap() -1][idrec.station() -1][idrec.ring() -1][idrec.chamber()]){
1573  //MultiSegments[idrec.endcap() -1][idrec.station() -1][idrec.ring() -1][idrec.chamber()] = true;
1574  //}
1575  AllSegments[idseg.endcap() - 1][idseg.station() - 1][idseg.ring() - 1][idseg.chamber() - 1] = true;
1576  // "Intrinsic" efficiency measurement relies on "good" segment extrapolation - we need the pre-selection below
1577  // station 2 "good" segment will be used for testing efficiencies in ME1 and ME3
1578  // station 3 "good" segment will be used for testing efficiencies in ME2 and ME4
1579  if (2 == idseg.station() || 3 == idseg.station()) {
1580  unsigned int seg_tmp;
1581  if (2 == idseg.station()) {
1582  ++seg_ME2[idseg.endcap() - 1];
1583  seg_tmp = seg_ME2[idseg.endcap() - 1];
1584  } else {
1585  ++seg_ME3[idseg.endcap() - 1];
1586  seg_tmp = seg_ME3[idseg.endcap() - 1];
1587  }
1588  // is the segment good
1589  if (1 == seg_tmp && 6 == (*segEffIt).nRecHits() && (*segEffIt).chi2() / (*segEffIt).degreesOfFreedom() < 3.) {
1590  std::pair<CSCDetId, CSCSegment> specSeg = make_pair((CSCDetId)(*segEffIt).cscDetId(), *segEffIt);
1591  theSegments[2 * (idseg.endcap() - 1) + (idseg.station() - 2)] = specSeg;
1592  }
1593  }
1594  /*
1595  if(2==idseg.station()){
1596  ++seg_ME2[idseg.endcap() -1];
1597  if(1==seg_ME2[idseg.endcap() -1] && 6==(*segEffIt).nRecHits() && (*segEffIt).chi2()/(*segEffIt).degreesOfFreedom()<3.){
1598  std::pair <CSCDetId, CSCSegment> specSeg = make_pair( (CSCDetId)(*segEffIt).cscDetId(),*segEffIt);
1599  theSegments[2*(idseg.endcap()-1)+(idseg.station() -2)] = specSeg;
1600  }
1601  }
1602  else if(3==idseg.station()){
1603  ++seg_ME3[idseg.endcap() -1];
1604  if(1==seg_ME3[idseg.endcap() -1] && 6==(*segEffIt).nRecHits() && (*segEffIt).chi2()/(*segEffIt).degreesOfFreedom()<3.){
1605  std::pair <CSCDetId, CSCSegment> specSeg = make_pair( (CSCDetId)(*segEffIt).cscDetId(),*segEffIt);
1606  theSegments[2*(idseg.endcap()-1)+(idseg.station() -2)] = specSeg;
1607  }
1608  }
1609  */
1610  }
1611  // Simple efficiency calculations
1612  for (int iE = 0; iE < 2; iE++) {
1613  for (int iS = 0; iS < 4; iS++) {
1614  for (int iR = 0; iR < 4; iR++) {
1615  for (int iC = 0; iC < 36; iC++) {
1616  int NumberOfLayers = 0;
1617  for (int iL = 0; iL < 6; iL++) {
1618  if (AllRecHits[iE][iS][iR][iC][iL]) {
1619  NumberOfLayers++;
1620  }
1621  }
1622  int bin = 0;
1623  if (iS == 0)
1624  bin = iR + 1 + (iE * 10);
1625  else
1626  bin = (iS + 1) * 2 + (iR + 1) + (iE * 10);
1627  if (NumberOfLayers > 1) {
1628  //if(!(MultiSegments[iE][iS][iR][iC])){
1629  if (AllSegments[iE][iS][iR][iC]) {
1630  //---- Efficient segment events
1631  //hSSTE->AddBinContent(bin);
1632  hSSTE->Fill(bin - 0.5);
1633  if (NumberOfLayers > 3)
1634  hSSTETight->Fill(bin - 0.5);
1635  }
1636  //---- All segment events (normalization)
1637  //hSSTE->AddBinContent(20+bin);
1638  hSSTE->Fill(20 + bin - 0.5);
1639  if (NumberOfLayers > 3)
1640  hSSTETight->Fill(20 + bin - 0.5);
1641  //} //}
1642  }
1643  if (AllSegments[iE][iS][iR][iC]) {
1644  if (NumberOfLayers == 6) {
1645  //---- Efficient rechit events
1646  //hRHSTE->AddBinContent(bin);
1647  hRHSTE->Fill(bin - 0.5);
1648  hRHSTETight->Fill(bin - 0.5);
1649  ;
1650  }
1651  //---- All rechit events (normalization)
1652  //hRHSTE->AddBinContent(20+bin);
1653  hRHSTE->Fill(20 + bin - 0.5);
1654  if (NumberOfLayers > 3)
1655  hRHSTETight->Fill(20 + bin - 0.5);
1656  ;
1657  }
1658  }
1659  }
1660  }
1661  }
1662 
1663  // pick a segment only if there are no others in the station
1664  std::vector<std::pair<CSCDetId, CSCSegment>*> theSeg;
1665  if (1 == seg_ME2[0])
1666  theSeg.push_back(&theSegments[0]);
1667  if (1 == seg_ME3[0])
1668  theSeg.push_back(&theSegments[1]);
1669  if (1 == seg_ME2[1])
1670  theSeg.push_back(&theSegments[2]);
1671  if (1 == seg_ME3[1])
1672  theSeg.push_back(&theSegments[3]);
1673 
1674  // Needed for plots
1675  // at the end the chamber types will be numbered as 1 to 20
1676  // (ME-4/2, ME-4/1, -ME3/2, -ME3/1, ..., +ME3/1, +ME3/2, ME+4/1, ME+4/2 )
1677  std::map<std::string, float> chamberTypes;
1678  chamberTypes["ME1/a"] = 0.5;
1679  chamberTypes["ME1/b"] = 1.5;
1680  chamberTypes["ME1/2"] = 2.5;
1681  chamberTypes["ME1/3"] = 3.5;
1682  chamberTypes["ME2/1"] = 4.5;
1683  chamberTypes["ME2/2"] = 5.5;
1684  chamberTypes["ME3/1"] = 6.5;
1685  chamberTypes["ME3/2"] = 7.5;
1686  chamberTypes["ME4/1"] = 8.5;
1687  chamberTypes["ME4/2"] = 9.5;
1688 
1689  if (!theSeg.empty()) {
1690  std::map<int, GlobalPoint> extrapolatedPoint;
1691  std::map<int, GlobalPoint>::iterator it;
1692  const CSCGeometry::ChamberContainer& ChamberContainer = cscGeom->chambers();
1693  // Pick which chamber with which segment to test
1694  for (size_t nCh = 0; nCh < ChamberContainer.size(); nCh++) {
1695  const CSCChamber* cscchamber = ChamberContainer[nCh];
1696  std::pair<CSCDetId, CSCSegment>* thisSegment = nullptr;
1697  for (size_t iSeg = 0; iSeg < theSeg.size(); ++iSeg) {
1698  if (cscchamber->id().endcap() == theSeg[iSeg]->first.endcap()) {
1699  if (1 == cscchamber->id().station() || 3 == cscchamber->id().station()) {
1700  if (2 == theSeg[iSeg]->first.station()) {
1701  thisSegment = theSeg[iSeg];
1702  }
1703  } else if (2 == cscchamber->id().station() || 4 == cscchamber->id().station()) {
1704  if (3 == theSeg[iSeg]->first.station()) {
1705  thisSegment = theSeg[iSeg];
1706  }
1707  }
1708  }
1709  }
1710  // this chamber is to be tested with thisSegment
1711  if (thisSegment) {
1712  CSCSegment* seg = &(thisSegment->second);
1713  const CSCChamber* segChamber = cscGeom->chamber(thisSegment->first);
1714  LocalPoint localCenter(0., 0., 0);
1715  GlobalPoint cscchamberCenter = cscchamber->toGlobal(localCenter);
1716  // try to save some time (extrapolate a segment to a certain position only once)
1717  it = extrapolatedPoint.find(int(cscchamberCenter.z()));
1718  if (it == extrapolatedPoint.end()) {
1719  GlobalPoint segPos = segChamber->toGlobal(seg->localPosition());
1720  GlobalVector segDir = segChamber->toGlobal(seg->localDirection());
1721  double paramaterLine = lineParametrization(segPos.z(), cscchamberCenter.z(), segDir.z());
1722  double xExtrapolated = extrapolate1D(segPos.x(), segDir.x(), paramaterLine);
1723  double yExtrapolated = extrapolate1D(segPos.y(), segDir.y(), paramaterLine);
1724  GlobalPoint globP(xExtrapolated, yExtrapolated, cscchamberCenter.z());
1725  extrapolatedPoint[int(cscchamberCenter.z())] = globP;
1726  }
1727  // Where does the extrapolated point lie in the (tested) chamber local frame? Here:
1728  LocalPoint extrapolatedPointLocal = cscchamber->toLocal(extrapolatedPoint[int(cscchamberCenter.z())]);
1729  const CSCLayer* layer_p = cscchamber->layer(1); //layer 1
1730  const CSCLayerGeometry* layerGeom = layer_p->geometry();
1731  const std::array<const float, 4>& layerBounds = layerGeom->parameters();
1732  float shiftFromEdge = 15.; //cm
1733  float shiftFromDeadZone = 10.;
1734  // is the extrapolated point within a sensitive region
1735  bool pass = withinSensitiveRegion(extrapolatedPointLocal,
1736  layerBounds,
1737  cscchamber->id().station(),
1738  cscchamber->id().ring(),
1739  shiftFromEdge,
1740  shiftFromDeadZone);
1741  if (pass) { // the extrapolation point of the segment lies within sensitive region of that chamber
1742  // how many rechit layers are there in the chamber?
1743  // 0 - maybe the muon died or is deflected at large angle? do not use that case
1744  // 1 - could be noise...
1745  // 2 or more - this is promissing; this is our definition of a reliable signal; use it below
1746  // is other definition better?
1747  int nRHLayers = 0;
1748  for (int iL = 0; iL < 6; ++iL) {
1749  if (AllRecHits[cscchamber->id().endcap() - 1][cscchamber->id().station() - 1][cscchamber->id().ring() - 1]
1750  [cscchamber->id().chamber() - 1][iL]) {
1751  ++nRHLayers;
1752  }
1753  }
1754  //std::cout<<" nRHLayers = "<<nRHLayers<<std::endl;
1755  float verticalScale = chamberTypes[cscchamber->specs()->chamberTypeName()];
1756  if (cscchamberCenter.z() < 0) {
1757  verticalScale = -verticalScale;
1758  }
1759  verticalScale += 10.5;
1760  hSensitiveAreaEvt->Fill(float(cscchamber->id().chamber()), verticalScale);
1761  if (nRHLayers > 1) { // this chamber contains a reliable signal
1762  //chamberTypes[cscchamber->specs()->chamberTypeName()];
1763  // "intrinsic" efficiencies
1764  //std::cout<<" verticalScale = "<<verticalScale<<" chType = "<<cscchamber->specs()->chamberTypeName()<<std::endl;
1765  // this is the denominator forr all efficiencies
1766  hEffDenominator->Fill(float(cscchamber->id().chamber()), verticalScale);
1767  if (nRHLayers > 3)
1768  hEffDenominatorTight->Fill(float(cscchamber->id().chamber()), verticalScale);
1769  // Segment efficiency
1770  if (AllSegments[cscchamber->id().endcap() - 1][cscchamber->id().station() - 1][cscchamber->id().ring() - 1]
1771  [cscchamber->id().chamber() - 1]) {
1772  hSSTE2->Fill(float(cscchamber->id().chamber()), float(verticalScale));
1773  if (nRHLayers > 3)
1774  hSSTE2Tight->Fill(float(cscchamber->id().chamber()), float(verticalScale));
1775  }
1776 
1777  for (int iL = 0; iL < 6; ++iL) {
1778  float weight = 1. / 6.;
1779  // one shold account for the weight in the efficiency...
1780  // Rechit efficiency
1781  if (AllRecHits[cscchamber->id().endcap() - 1][cscchamber->id().station() - 1][cscchamber->id().ring() - 1]
1782  [cscchamber->id().chamber() - 1][iL]) {
1783  hRHSTE2->Fill(float(cscchamber->id().chamber()), float(verticalScale), weight);
1784  if (nRHLayers > 3)
1785  hRHSTE2Tight->Fill(float(cscchamber->id().chamber()), float(verticalScale), weight);
1786  }
1787  if (useDigis) {
1788  // Wire efficiency
1789  if (allWires[cscchamber->id().endcap() - 1][cscchamber->id().station() - 1][cscchamber->id().ring() - 1]
1790  [cscchamber->id().chamber() - 1][iL]) {
1791  // one shold account for the weight in the efficiency...
1792  hWireSTE2->Fill(float(cscchamber->id().chamber()), float(verticalScale), weight);
1793  if (nRHLayers > 3)
1794  hWireSTE2Tight->Fill(float(cscchamber->id().chamber()), float(verticalScale), weight);
1795  }
1796  // Strip efficiency
1797  if (allStrips[cscchamber->id().endcap() - 1][cscchamber->id().station() - 1]
1798  [cscchamber->id().ring() - 1][cscchamber->id().chamber() - 1][iL]) {
1799  // one shold account for the weight in the efficiency...
1800  hStripSTE2->Fill(float(cscchamber->id().chamber()), float(verticalScale), weight);
1801  if (nRHLayers > 3)
1802  hStripSTE2Tight->Fill(float(cscchamber->id().chamber()), float(verticalScale), weight);
1803  }
1804  }
1805  }
1806  }
1807  }
1808  }
1809  }
1810  }
1811  //
1812 }
1813 
1814 void CSCValidation::getEfficiency(float bin, float Norm, std::vector<float>& eff) {
1815  //---- Efficiency with binomial error
1816  float Efficiency = 0.;
1817  float EffError = 0.;
1818  if (fabs(Norm) > 0.000000001) {
1819  Efficiency = bin / Norm;
1820  if (bin < Norm) {
1821  EffError = sqrt((1. - Efficiency) * Efficiency / Norm);
1822  }
1823  }
1824  eff[0] = Efficiency;
1825  eff[1] = EffError;
1826 }
1827 
1828 void CSCValidation::histoEfficiency(TH1F* readHisto, TH1F* writeHisto) {
1829  std::vector<float> eff(2);
1830  int Nbins = readHisto->GetSize() - 2; //without underflows and overflows
1831  std::vector<float> bins(Nbins);
1832  std::vector<float> Efficiency(Nbins);
1833  std::vector<float> EffError(Nbins);
1834  float Num = 1;
1835  float Den = 1;
1836  for (int i = 0; i < 20; i++) {
1837  Num = readHisto->GetBinContent(i + 1);
1838  Den = readHisto->GetBinContent(i + 21);
1839  getEfficiency(Num, Den, eff);
1840  Efficiency[i] = eff[0];
1841  EffError[i] = eff[1];
1842  writeHisto->SetBinContent(i + 1, Efficiency[i]);
1843  writeHisto->SetBinError(i + 1, EffError[i]);
1844  }
1845 }
1846 
1847 bool CSCValidation::withinSensitiveRegion(LocalPoint localPos,
1848  const std::array<const float, 4>& layerBounds,
1849  int station,
1850  int ring,
1851  float shiftFromEdge,
1852  float shiftFromDeadZone) {
1853  //---- check if it is in a good local region (sensitive area - geometrical and HV boundaries excluded)
1854  bool pass = false;
1855 
1856  float y_center = 0.;
1857  double yUp = layerBounds[3] + y_center;
1858  double yDown = -layerBounds[3] + y_center;
1859  double xBound1Shifted = layerBounds[0] - shiftFromEdge; //
1860  double xBound2Shifted = layerBounds[1] - shiftFromEdge; //
1861  double lineSlope = (yUp - yDown) / (xBound2Shifted - xBound1Shifted);
1862  double lineConst = yUp - lineSlope * xBound2Shifted;
1863  double yBorder = lineSlope * abs(localPos.x()) + lineConst;
1864 
1865  //bool withinChamberOnly = false;// false = "good region"; true - boundaries only
1866  std::vector<float> deadZoneCenter(6);
1867  float cutZone = shiftFromDeadZone; //cm
1868  //---- hardcoded... not good
1869  if (station > 1 && station < 5) {
1870  if (2 == ring) {
1871  deadZoneCenter[0] = -162.48;
1872  deadZoneCenter[1] = -81.8744;
1873  deadZoneCenter[2] = -21.18165;
1874  deadZoneCenter[3] = 39.51105;
1875  deadZoneCenter[4] = 100.2939;
1876  deadZoneCenter[5] = 160.58;
1877 
1878  if (localPos.y() > yBorder &&
1879  ((localPos.y() > deadZoneCenter[0] + cutZone && localPos.y() < deadZoneCenter[1] - cutZone) ||
1880  (localPos.y() > deadZoneCenter[1] + cutZone && localPos.y() < deadZoneCenter[2] - cutZone) ||
1881  (localPos.y() > deadZoneCenter[2] + cutZone && localPos.y() < deadZoneCenter[3] - cutZone) ||
1882  (localPos.y() > deadZoneCenter[3] + cutZone && localPos.y() < deadZoneCenter[4] - cutZone) ||
1883  (localPos.y() > deadZoneCenter[4] + cutZone && localPos.y() < deadZoneCenter[5] - cutZone))) {
1884  pass = true;
1885  }
1886  } else if (1 == ring) {
1887  if (2 == station) {
1888  deadZoneCenter[0] = -95.80;
1889  deadZoneCenter[1] = -27.47;
1890  deadZoneCenter[2] = 33.67;
1891  deadZoneCenter[3] = 90.85;
1892  } else if (3 == station) {
1893  deadZoneCenter[0] = -89.305;
1894  deadZoneCenter[1] = -39.705;
1895  deadZoneCenter[2] = 20.195;
1896  deadZoneCenter[3] = 77.395;
1897  } else if (4 == station) {
1898  deadZoneCenter[0] = -75.645;
1899  deadZoneCenter[1] = -26.055;
1900  deadZoneCenter[2] = 23.855;
1901  deadZoneCenter[3] = 70.575;
1902  }
1903  if (localPos.y() > yBorder &&
1904  ((localPos.y() > deadZoneCenter[0] + cutZone && localPos.y() < deadZoneCenter[1] - cutZone) ||
1905  (localPos.y() > deadZoneCenter[1] + cutZone && localPos.y() < deadZoneCenter[2] - cutZone) ||
1906  (localPos.y() > deadZoneCenter[2] + cutZone && localPos.y() < deadZoneCenter[3] - cutZone))) {
1907  pass = true;
1908  }
1909  }
1910  } else if (1 == station) {
1911  if (3 == ring) {
1912  deadZoneCenter[0] = -83.155;
1913  deadZoneCenter[1] = -22.7401;
1914  deadZoneCenter[2] = 27.86665;
1915  deadZoneCenter[3] = 81.005;
1916  if (localPos.y() > yBorder &&
1917  ((localPos.y() > deadZoneCenter[0] + cutZone && localPos.y() < deadZoneCenter[1] - cutZone) ||
1918  (localPos.y() > deadZoneCenter[1] + cutZone && localPos.y() < deadZoneCenter[2] - cutZone) ||
1919  (localPos.y() > deadZoneCenter[2] + cutZone && localPos.y() < deadZoneCenter[3] - cutZone))) {
1920  pass = true;
1921  }
1922  } else if (2 == ring) {
1923  deadZoneCenter[0] = -86.285;
1924  deadZoneCenter[1] = -32.88305;
1925  deadZoneCenter[2] = 32.867423;
1926  deadZoneCenter[3] = 88.205;
1927  if (localPos.y() > (yBorder) &&
1928  ((localPos.y() > deadZoneCenter[0] + cutZone && localPos.y() < deadZoneCenter[1] - cutZone) ||
1929  (localPos.y() > deadZoneCenter[1] + cutZone && localPos.y() < deadZoneCenter[2] - cutZone) ||
1930  (localPos.y() > deadZoneCenter[2] + cutZone && localPos.y() < deadZoneCenter[3] - cutZone))) {
1931  pass = true;
1932  }
1933  } else if (1 == ring) { // ME1/1b
1934  deadZoneCenter[0] = -31.5;
1935  deadZoneCenter[1] = 86.0;
1936  if (localPos.y() > (yBorder) &&
1937  (localPos.y() > deadZoneCenter[0] && localPos.y() < deadZoneCenter[1] - cutZone)) {
1938  pass = true;
1939  }
1940  } else if (4 == ring) { // ME1/1a
1941  deadZoneCenter[0] = -86.0;
1942  deadZoneCenter[1] = -31.5;
1943  if (localPos.y() > (yBorder) &&
1944  (localPos.y() > deadZoneCenter[0] + cutZone && localPos.y() < deadZoneCenter[1])) {
1945  pass = true;
1946  }
1947  }
1948  }
1949  return pass;
1950 }
1951 
1952 //---------------------------------------------------------------------------------------
1953 // Given a set of digis, the CSCDetId, and the central strip of your choosing, returns
1954 // the avg. Signal-Pedestal for 6 time bin x 5 strip .
1955 //
1956 // Author: P. Jindal
1957 //---------------------------------------------------------------------------------------
1958 
1959 float CSCValidation::getSignal(const CSCStripDigiCollection& stripdigis, CSCDetId idCS, int centerStrip) {
1960  float SigADC[5];
1961  float TotalADC = 0;
1962  SigADC[0] = 0;
1963  SigADC[1] = 0;
1964  SigADC[2] = 0;
1965  SigADC[3] = 0;
1966  SigADC[4] = 0;
1967 
1968  // Loop over strip digis
1970 
1971  for (sIt = stripdigis.begin(); sIt != stripdigis.end(); sIt++) {
1972  CSCDetId id = (CSCDetId)(*sIt).first;
1973  if (id == idCS) {
1974  // First, find the Signal-Pedestal for center strip
1975  std::vector<CSCStripDigi>::const_iterator digiItr = (*sIt).second.first;
1976  std::vector<CSCStripDigi>::const_iterator last = (*sIt).second.second;
1977  for (; digiItr != last; ++digiItr) {
1978  int thisStrip = digiItr->getStrip();
1979  if (thisStrip == (centerStrip)) {
1980  std::vector<int> myADCVals = digiItr->getADCCounts();
1981  float thisPedestal = 0.5 * (float)(myADCVals[0] + myADCVals[1]);
1982  float thisSignal = (myADCVals[2] + myADCVals[3] + myADCVals[4] + myADCVals[5] + myADCVals[6] + myADCVals[7]);
1983  SigADC[0] = thisSignal - 6 * thisPedestal;
1984  }
1985  // Now,find the Signal-Pedestal for neighbouring 4 strips
1986  if (thisStrip == (centerStrip + 1)) {
1987  std::vector<int> myADCVals = digiItr->getADCCounts();
1988  float thisPedestal = 0.5 * (float)(myADCVals[0] + myADCVals[1]);
1989  float thisSignal = (myADCVals[2] + myADCVals[3] + myADCVals[4] + myADCVals[5] + myADCVals[6] + myADCVals[7]);
1990  SigADC[1] = thisSignal - 6 * thisPedestal;
1991  }
1992  if (thisStrip == (centerStrip + 2)) {
1993  std::vector<int> myADCVals = digiItr->getADCCounts();
1994  float thisPedestal = 0.5 * (float)(myADCVals[0] + myADCVals[1]);
1995  float thisSignal = (myADCVals[2] + myADCVals[3] + myADCVals[4] + myADCVals[5] + myADCVals[6] + myADCVals[7]);
1996  SigADC[2] = thisSignal - 6 * thisPedestal;
1997  }
1998  if (thisStrip == (centerStrip - 1)) {
1999  std::vector<int> myADCVals = digiItr->getADCCounts();
2000  float thisPedestal = 0.5 * (float)(myADCVals[0] + myADCVals[1]);
2001  float thisSignal = (myADCVals[2] + myADCVals[3] + myADCVals[4] + myADCVals[5] + myADCVals[6] + myADCVals[7]);
2002  SigADC[3] = thisSignal - 6 * thisPedestal;
2003  }
2004  if (thisStrip == (centerStrip - 2)) {
2005  std::vector<int> myADCVals = digiItr->getADCCounts();
2006  float thisPedestal = 0.5 * (float)(myADCVals[0] + myADCVals[1]);
2007  float thisSignal = (myADCVals[2] + myADCVals[3] + myADCVals[4] + myADCVals[5] + myADCVals[6] + myADCVals[7]);
2008  SigADC[4] = thisSignal - 6 * thisPedestal;
2009  }
2010  }
2011  TotalADC = 0.2 * (SigADC[0] + SigADC[1] + SigADC[2] + SigADC[3] + SigADC[4]);
2012  }
2013  }
2014  return TotalADC;
2015 }
2016 
2017 //---------------------------------------------------------------------------------------
2018 // Look at non-associated recHits
2019 // Author: P. Jindal
2020 //---------------------------------------------------------------------------------------
2021 
2022 void CSCValidation::doNoiseHits(edm::Handle<CSCRecHit2DCollection> recHits,
2027  for (recIt = recHits->begin(); recIt != recHits->end(); recIt++) {
2028  CSCDetId idrec = (CSCDetId)(*recIt).cscDetId();
2029 
2030  //Store the Rechits into a Map
2031  AllRechits.insert(std::pair<CSCDetId, CSCRecHit2D>(idrec, *recIt));
2032 
2033  // Find the strip containing this hit
2034  int centerid = recIt->nStrips() / 2;
2035  int centerStrip = recIt->channels(centerid);
2036 
2037  float rHsignal = getthisSignal(*strips, idrec, centerStrip);
2038  histos->fill1DHist(
2039  rHsignal, "hrHSignal", "Signal in the 4th time bin for centre strip", 1100, -99, 1000, "recHits");
2040  }
2041 
2042  for (CSCSegmentCollection::const_iterator it = cscSegments->begin(); it != cscSegments->end(); it++) {
2043  std::vector<CSCRecHit2D> theseRecHits = (*it).specificRecHits();
2044  for (std::vector<CSCRecHit2D>::const_iterator iRH = theseRecHits.begin(); iRH != theseRecHits.end(); iRH++) {
2045  CSCDetId idRH = (CSCDetId)(*iRH).cscDetId();
2046  LocalPoint lpRH = (*iRH).localPosition();
2047  float xrec = lpRH.x();
2048  float yrec = lpRH.y();
2049  float zrec = lpRH.z();
2050  bool RHalreadyinMap = false;
2051  //Store the rechits associated with segments into a Map
2052  multimap<CSCDetId, CSCRecHit2D>::iterator segRHit;
2053  segRHit = SegRechits.find(idRH);
2054  if (segRHit != SegRechits.end()) {
2055  for (; segRHit != SegRechits.upper_bound(idRH); ++segRHit) {
2056  //for( segRHit = SegRechits.begin(); segRHit != SegRechits.end() ;++segRHit){
2057  LocalPoint lposRH = (segRHit->second).localPosition();
2058  float xpos = lposRH.x();
2059  float ypos = lposRH.y();
2060  float zpos = lposRH.z();
2061  if (xrec == xpos && yrec == ypos && zrec == zpos) {
2062  RHalreadyinMap = true;
2063  //std::cout << " Already exists " <<std ::endl;
2064  break;
2065  }
2066  }
2067  }
2068  if (!RHalreadyinMap) {
2069  SegRechits.insert(std::pair<CSCDetId, CSCRecHit2D>(idRH, *iRH));
2070  }
2071  }
2072  }
2073 
2074  findNonAssociatedRecHits(cscGeom, strips);
2075 }
2076 
2077 //---------------------------------------------------------------------------------------
2078 // Given the list of all rechits and the rechits on a segment finds the rechits
2079 // not associated to a segment and stores in a list
2080 //
2081 //---------------------------------------------------------------------------------------
2082 
2083 void CSCValidation::findNonAssociatedRecHits(edm::ESHandle<CSCGeometry> cscGeom,
2085  for (std::multimap<CSCDetId, CSCRecHit2D>::iterator allRHiter = AllRechits.begin(); allRHiter != AllRechits.end();
2086  ++allRHiter) {
2087  CSCDetId idRH = allRHiter->first;
2088  LocalPoint lpRH = (allRHiter->second).localPosition();
2089  float xrec = lpRH.x();
2090  float yrec = lpRH.y();
2091  float zrec = lpRH.z();
2092 
2093  bool foundmatch = false;
2094  multimap<CSCDetId, CSCRecHit2D>::iterator segRHit;
2095  segRHit = SegRechits.find(idRH);
2096  if (segRHit != SegRechits.end()) {
2097  for (; segRHit != SegRechits.upper_bound(idRH); ++segRHit) {
2098  LocalPoint lposRH = (segRHit->second).localPosition();
2099  float xpos = lposRH.x();
2100  float ypos = lposRH.y();
2101  float zpos = lposRH.z();
2102 
2103  if (xrec == xpos && yrec == ypos && zrec == zpos) {
2104  foundmatch = true;
2105  }
2106 
2107  float d = 0.;
2108  float dclose = 1000.;
2109 
2110  if (!foundmatch) {
2111  d = sqrt(pow(xrec - xpos, 2) + pow(yrec - ypos, 2) + pow(zrec - zpos, 2));
2112  if (d < dclose) {
2113  dclose = d;
2114  if (distRHmap.find((allRHiter->second)) ==
2115  distRHmap.end()) { // entry for rechit does not yet exist, create one
2116  distRHmap.insert(make_pair(allRHiter->second, dclose));
2117  } else {
2118  // we already have an entry for the detid.
2119  distRHmap.erase(allRHiter->second);
2120  distRHmap.insert(
2121  make_pair(allRHiter->second, dclose)); // fill rechits for the segment with the given detid
2122  }
2123  }
2124  }
2125  }
2126  }
2127  if (!foundmatch) {
2128  NonAssociatedRechits.insert(std::pair<CSCDetId, CSCRecHit2D>(idRH, allRHiter->second));
2129  }
2130  }
2131 
2132  for (std::map<CSCRecHit2D, float, ltrh>::iterator iter = distRHmap.begin(); iter != distRHmap.end(); ++iter) {
2133  histos->fill1DHist(iter->second,
2134  "hdistRH",
2135  "Distance of Non Associated RecHit from closest Segment RecHit",
2136  500,
2137  0.,
2138  100.,
2139  "NonAssociatedRechits");
2140  }
2141 
2142  for (std::multimap<CSCDetId, CSCRecHit2D>::iterator iter = NonAssociatedRechits.begin();
2143  iter != NonAssociatedRechits.end();
2144  ++iter) {
2145  CSCDetId idrec = iter->first;
2146  int kEndcap = idrec.endcap();
2147  int cEndcap = idrec.endcap();
2148  if (kEndcap == 2)
2149  cEndcap = -1;
2150  int kRing = idrec.ring();
2151  int kStation = idrec.station();
2152  int kChamber = idrec.chamber();
2153  int kLayer = idrec.layer();
2154 
2155  // Store rechit as a Local Point:
2156  LocalPoint rhitlocal = (iter->second).localPosition();
2157  float xreco = rhitlocal.x();
2158  float yreco = rhitlocal.y();
2159 
2160  // Find the strip containing this hit
2161  int centerid = (iter->second).nStrips() / 2;
2162  int centerStrip = (iter->second).channels(centerid);
2163 
2164  // Find the charge associated with this hit
2165  float rHSumQ = 0;
2166  float sumsides = 0.;
2167  int adcsize = (iter->second).nStrips() * (iter->second).nTimeBins();
2168  for (unsigned int i = 0; i < (iter->second).nStrips(); i++) {
2169  for (unsigned int j = 0; j < (iter->second).nTimeBins() - 1; j++) {
2170  rHSumQ += (iter->second).adcs(i, j);
2171  if (i != 1)
2172  sumsides += (iter->second).adcs(i, j);
2173  }
2174  }
2175 
2176  float rHratioQ = sumsides / rHSumQ;
2177  if (adcsize != 12)
2178  rHratioQ = -99;
2179 
2180  // Get the signal timing of this hit
2181  float rHtime = (iter->second).tpeak() / 50;
2182 
2183  // Get the width of this hit
2184  int rHwidth = getWidth(*strips, idrec, centerStrip);
2185 
2186  // Get pointer to the layer:
2187  const CSCLayer* csclayer = cscGeom->layer(idrec);
2188 
2189  // Transform hit position from local chamber geometry to global CMS geom
2190  GlobalPoint rhitglobal = csclayer->toGlobal(rhitlocal);
2191  float grecx = rhitglobal.x();
2192  float grecy = rhitglobal.y();
2193 
2194  // Simple occupancy variables
2195  int kCodeBroad = cEndcap * (4 * (kStation - 1) + kRing);
2196  int kCodeNarrow = cEndcap * (100 * (kRing - 1) + kChamber);
2197 
2198  //Fill the non-associated rechits parameters in histogram
2199  histos->fill1DHist(
2200  kCodeBroad, "hNARHCodeBroad", "broad scope code for recHits", 33, -16.5, 16.5, "NonAssociatedRechits");
2201  if (kStation == 1)
2202  histos->fill1DHist(kCodeNarrow,
2203  "hNARHCodeNarrow1",
2204  "narrow scope recHit code station 1",
2205  801,
2206  -400.5,
2207  400.5,
2208  "NonAssociatedRechits");
2209  if (kStation == 2)
2210  histos->fill1DHist(kCodeNarrow,
2211  "hNARHCodeNarrow2",
2212  "narrow scope recHit code station 2",
2213  801,
2214  -400.5,
2215  400.5,
2216  "NonAssociatedRechits");
2217  if (kStation == 3)
2218  histos->fill1DHist(kCodeNarrow,
2219  "hNARHCodeNarrow3",
2220  "narrow scope recHit code station 3",
2221  801,
2222  -400.5,
2223  400.5,
2224  "NonAssociatedRechits");
2225  if (kStation == 4)
2226  histos->fill1DHist(kCodeNarrow,
2227  "hNARHCodeNarrow4",
2228  "narrow scope recHit code station 4",
2229  801,
2230  -400.5,
2231  400.5,
2232  "NonAssociatedRechits");
2233  histos->fill1DHistByType(kLayer, "hNARHLayer", "RecHits per Layer", idrec, 8, -0.5, 7.5, "NonAssociatedRechits");
2234  histos->fill1DHistByType(xreco, "hNARHX", "Local X of recHit", idrec, 160, -80., 80., "NonAssociatedRechits");
2235  histos->fill1DHistByType(yreco, "hNARHY", "Local Y of recHit", idrec, 60, -180., 180., "NonAssociatedRechits");
2236  if (kStation == 1 && (kRing == 1 || kRing == 4))
2237  histos->fill1DHistByType(
2238  rHSumQ, "hNARHSumQ", "Sum 3x3 recHit Charge", idrec, 250, 0, 4000, "NonAssociatedRechits");
2239  else
2240  histos->fill1DHistByType(
2241  rHSumQ, "hNARHSumQ", "Sum 3x3 recHit Charge", idrec, 250, 0, 2000, "NonAssociatedRechits");
2242  histos->fill1DHistByType(
2243  rHratioQ, "hNARHRatioQ", "Ratio (Ql+Qr)/Qt)", idrec, 120, -0.1, 1.1, "NonAssociatedRechits");
2244  histos->fill1DHistByType(rHtime, "hNARHTiming", "recHit Timing", idrec, 200, -10, 10, "NonAssociatedRechits");
2245  histos->fill2DHistByStation(grecx,
2246  grecy,
2247  "hNARHGlobal",
2248  "recHit Global Position",
2249  idrec,
2250  400,
2251  -800.,
2252  800.,
2253  400,
2254  -800.,
2255  800.,
2256  "NonAssociatedRechits");
2257  histos->fill1DHistByType(
2258  rHwidth, "hNARHwidth", "width for Non associated recHit", idrec, 21, -0.5, 20.5, "NonAssociatedRechits");
2259  }
2260 
2261  for (std::multimap<CSCDetId, CSCRecHit2D>::iterator iter = SegRechits.begin(); iter != SegRechits.end(); ++iter) {
2262  CSCDetId idrec = iter->first;
2263  int kEndcap = idrec.endcap();
2264  int cEndcap = idrec.endcap();
2265  if (kEndcap == 2)
2266  cEndcap = -1;
2267  int kRing = idrec.ring();
2268  int kStation = idrec.station();
2269  int kChamber = idrec.chamber();
2270  int kLayer = idrec.layer();
2271 
2272  // Store rechit as a Local Point:
2273  LocalPoint rhitlocal = (iter->second).localPosition();
2274  float xreco = rhitlocal.x();
2275  float yreco = rhitlocal.y();
2276 
2277  // Find the strip containing this hit
2278  int centerid = (iter->second).nStrips() / 2;
2279  int centerStrip = (iter->second).channels(centerid);
2280 
2281  // Find the charge associated with this hit
2282 
2283  float rHSumQ = 0;
2284  float sumsides = 0.;
2285  int adcsize = (iter->second).nStrips() * (iter->second).nTimeBins();
2286  for (unsigned int i = 0; i < (iter->second).nStrips(); i++) {
2287  for (unsigned int j = 0; j < (iter->second).nTimeBins() - 1; j++) {
2288  rHSumQ += (iter->second).adcs(i, j);
2289  if (i != 1)
2290  sumsides += (iter->second).adcs(i, j);
2291  }
2292  }
2293 
2294  float rHratioQ = sumsides / rHSumQ;
2295  if (adcsize != 12)
2296  rHratioQ = -99;
2297 
2298  // Get the signal timing of this hit
2299  float rHtime = (iter->second).tpeak() / 50;
2300 
2301  // Get the width of this hit
2302  int rHwidth = getWidth(*strips, idrec, centerStrip);
2303 
2304  // Get pointer to the layer:
2305  const CSCLayer* csclayer = cscGeom->layer(idrec);
2306 
2307  // Transform hit position from local chamber geometry to global CMS geom
2308  GlobalPoint rhitglobal = csclayer->toGlobal(rhitlocal);
2309  float grecx = rhitglobal.x();
2310  float grecy = rhitglobal.y();
2311 
2312  // Simple occupancy variables
2313  int kCodeBroad = cEndcap * (4 * (kStation - 1) + kRing);
2314  int kCodeNarrow = cEndcap * (100 * (kRing - 1) + kChamber);
2315 
2316  //Fill the non-associated rechits global position in histogram
2317  histos->fill1DHist(
2318  kCodeBroad, "hSegRHCodeBroad", "broad scope code for recHits", 33, -16.5, 16.5, "AssociatedRechits");
2319  if (kStation == 1)
2320  histos->fill1DHist(kCodeNarrow,
2321  "hSegRHCodeNarrow1",
2322  "narrow scope recHit code station 1",
2323  801,
2324  -400.5,
2325  400.5,
2326  "AssociatedRechits");
2327  if (kStation == 2)
2328  histos->fill1DHist(kCodeNarrow,
2329  "hSegRHCodeNarrow2",
2330  "narrow scope recHit code station 2",
2331  801,
2332  -400.5,
2333  400.5,
2334  "AssociatedRechits");
2335  if (kStation == 3)
2336  histos->fill1DHist(kCodeNarrow,
2337  "hSegRHCodeNarrow3",
2338  "narrow scope recHit code station 3",
2339  801,
2340  -400.5,
2341  400.5,
2342  "AssociatedRechits");
2343  if (kStation == 4)
2344  histos->fill1DHist(kCodeNarrow,
2345  "hSegRHCodeNarrow4",
2346  "narrow scope recHit code station 4",
2347  801,
2348  -400.5,
2349  400.5,
2350  "AssociatedRechits");
2351  histos->fill1DHistByType(kLayer, "hSegRHLayer", "RecHits per Layer", idrec, 8, -0.5, 7.5, "AssociatedRechits");
2352  histos->fill1DHistByType(xreco, "hSegRHX", "Local X of recHit", idrec, 160, -80., 80., "AssociatedRechits");
2353  histos->fill1DHistByType(yreco, "hSegRHY", "Local Y of recHit", idrec, 60, -180., 180., "AssociatedRechits");
2354  if (kStation == 1 && (kRing == 1 || kRing == 4))
2355  histos->fill1DHistByType(rHSumQ, "hSegRHSumQ", "Sum 3x3 recHit Charge", idrec, 250, 0, 4000, "AssociatedRechits");
2356  else
2357  histos->fill1DHistByType(rHSumQ, "hSegRHSumQ", "Sum 3x3 recHit Charge", idrec, 250, 0, 2000, "AssociatedRechits");
2358  histos->fill1DHistByType(rHratioQ, "hSegRHRatioQ", "Ratio (Ql+Qr)/Qt)", idrec, 120, -0.1, 1.1, "AssociatedRechits");
2359  histos->fill1DHistByType(rHtime, "hSegRHTiming", "recHit Timing", idrec, 200, -10, 10, "AssociatedRechits");
2360  histos->fill2DHistByStation(grecx,
2361  grecy,
2362  "hSegRHGlobal",
2363  "recHit Global Position",
2364  idrec,
2365  400,
2366  -800.,
2367  800.,
2368  400,
2369  -800.,
2370  800.,
2371  "AssociatedRechits");
2372  histos->fill1DHistByType(
2373  rHwidth, "hSegRHwidth", "width for Non associated recHit", idrec, 21, -0.5, 20.5, "AssociatedRechits");
2374  }
2375 
2376  distRHmap.clear();
2377  AllRechits.clear();
2378  SegRechits.clear();
2379  NonAssociatedRechits.clear();
2380 }
2381 
2382 float CSCValidation::getthisSignal(const CSCStripDigiCollection& stripdigis, CSCDetId idRH, int centerStrip) {
2383  // Loop over strip digis responsible for this recHit
2385  float thisADC = 0.;
2386  //bool foundRHid = false;
2387  // std::cout<<"iD S/R/C/L = "<<idRH<<" "<<idRH.station()<<"/"<<idRH.ring()<<"/"<<idRH.chamber()<<"/"<<idRH.layer()<<std::endl;
2388  for (sIt = stripdigis.begin(); sIt != stripdigis.end(); sIt++) {
2389  CSCDetId id = (CSCDetId)(*sIt).first;
2390  //std::cout<<"STRIPS: id S/R/C/L = "<<id<<" "<<id.station()<<"/"<<id.ring()<<"/"<<id.chamber()<<"/"<<id.layer()<<std::endl;
2391  if (id == idRH) {
2392  //foundRHid = true;
2393  vector<CSCStripDigi>::const_iterator digiItr = (*sIt).second.first;
2394  vector<CSCStripDigi>::const_iterator last = (*sIt).second.second;
2395  //if(digiItr == last ) {std::cout << " Attention1 :: Size of digi collection is zero " << std::endl;}
2396  int St = idRH.station();
2397  int Rg = idRH.ring();
2398  if (St == 1 && Rg == 4) {
2399  while (centerStrip > 16)
2400  centerStrip -= 16;
2401  }
2402  for (; digiItr != last; ++digiItr) {
2403  int thisStrip = digiItr->getStrip();
2404  //std::cout<<" thisStrip = "<<thisStrip<<" centerStrip = "<<centerStrip<<std::endl;
2405  std::vector<int> myADCVals = digiItr->getADCCounts();
2406  float thisPedestal = 0.5 * (float)(myADCVals[0] + myADCVals[1]);
2407  float Signal = (float)myADCVals[3];
2408  if (thisStrip == (centerStrip)) {
2409  thisADC = Signal - thisPedestal;
2410  //if(thisADC >= 0. && thisADC <2.) {std::cout << " Attention2 :: The Signal is equal to the pedestal " << std::endl;
2411  //}
2412  //if(thisADC < 0.) {std::cout << " Attention3 :: The Signal is less than the pedestal " << std::endl;
2413  //}
2414  }
2415  if (thisStrip == (centerStrip + 1)) {
2416  std::vector<int> myADCVals = digiItr->getADCCounts();
2417  }
2418  if (thisStrip == (centerStrip - 1)) {
2419  std::vector<int> myADCVals = digiItr->getADCCounts();
2420  }
2421  }
2422  }
2423  }
2424  //if(!foundRHid){std::cout << " Attention4 :: Did not find a matching RH id in the Strip Digi collection " << std::endl;}
2425  return thisADC;
2426 }
2427 
2428 //---------------------------------------------------------------------------------------
2429 //
2430 // Function is meant to take the DetId and center strip number of a recHit and return
2431 // the width in terms of strips
2432 //---------------------------------------------------------------------------------------
2433 
2434 int CSCValidation::getWidth(const CSCStripDigiCollection& stripdigis, CSCDetId idRH, int centerStrip) {
2435  int width = 1;
2436  int widthpos = 0;
2437  int widthneg = 0;
2438 
2439  // Loop over strip digis responsible for this recHit and sum charge
2441 
2442  for (sIt = stripdigis.begin(); sIt != stripdigis.end(); sIt++) {
2443  CSCDetId id = (CSCDetId)(*sIt).first;
2444  if (id == idRH) {
2445  std::vector<CSCStripDigi>::const_iterator digiItr = (*sIt).second.first;
2446  std::vector<CSCStripDigi>::const_iterator first = (*sIt).second.first;
2447  std::vector<CSCStripDigi>::const_iterator last = (*sIt).second.second;
2448  std::vector<CSCStripDigi>::const_iterator it = (*sIt).second.first;
2449  std::vector<CSCStripDigi>::const_iterator itr = (*sIt).second.first;
2450  //std::cout << " IDRH " << id <<std::endl;
2451  int St = idRH.station();
2452  int Rg = idRH.ring();
2453  if (St == 1 && Rg == 4) {
2454  while (centerStrip > 16)
2455  centerStrip -= 16;
2456  }
2457  for (; digiItr != last; ++digiItr) {
2458  int thisStrip = digiItr->getStrip();
2459  if (thisStrip == (centerStrip)) {
2460  it = digiItr;
2461  for (; it != last; ++it) {
2462  int strip = it->getStrip();
2463  std::vector<int> myADCVals = it->getADCCounts();
2464  float thisPedestal = 0.5 * (float)(myADCVals[0] + myADCVals[1]);
2465  if (((float)myADCVals[3] - thisPedestal) < 6 || widthpos == 10 || it == last) {
2466  break;
2467  }
2468  if (strip != centerStrip) {
2469  widthpos += 1;
2470  }
2471  }
2472  itr = digiItr;
2473  for (; itr != first; --itr) {
2474  int strip = itr->getStrip();
2475  std::vector<int> myADCVals = itr->getADCCounts();
2476  float thisPedestal = 0.5 * (float)(myADCVals[0] + myADCVals[1]);
2477  if (((float)myADCVals[3] - thisPedestal) < 6 || widthneg == 10 || itr == first) {
2478  break;
2479  }
2480  if (strip != centerStrip) {
2481  widthneg += 1;
2482  }
2483  }
2484  }
2485  }
2486  }
2487  }
2488  //std::cout << "Widthneg - " << widthneg << "Widthpos + " << widthpos << std::endl;
2489  width = width + widthneg + widthpos;
2490  //std::cout << "Width " << width << std::endl;
2491  return width;
2492 }
2493 
2494 //---------------------------------------------------------------------------
2495 // Module for looking at gas gains
2496 // Author N. Terentiev
2497 //---------------------------------------------------------------------------
2498 
2499 void CSCValidation::doGasGain(const CSCWireDigiCollection& wirecltn,
2500  const CSCStripDigiCollection& strpcltn,
2501  const CSCRecHit2DCollection& rechitcltn) {
2502  int channel = 0, mult, wire, layer, idlayer, idchamber, ring;
2503  int wire_strip_rechit_present;
2504  std::string name, title, endcapstr;
2505  ostringstream ss;
2506  CSCIndexer indexer;
2507  std::map<int, int>::iterator intIt;
2508 
2509  m_single_wire_layer.clear();
2510 
2511  if (firstEvent) {
2512  // HV segments, their # and location in terms of wire groups
2513 
2514  m_wire_hvsegm.clear();
2515  std::map<int, std::vector<int> >::iterator intvecIt;
2516  // ME1a ME1b ME1/2 ME1/3 ME2/1 ME2/2 ME3/1 ME3/2 ME4/1 ME4/2
2517  int csctype[10] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10};
2518  int hvsegm_layer[10] = {1, 1, 3, 3, 3, 5, 3, 5, 3, 5};
2519  int id;
2520  nmbhvsegm.clear();
2521  for (int i = 0; i < 10; i++)
2522  nmbhvsegm.push_back(hvsegm_layer[i]);
2523  // For ME1/1a
2524  std::vector<int> zer_1_1a(49, 0);
2525  id = csctype[0];
2526  if (m_wire_hvsegm.find(id) == m_wire_hvsegm.end())
2527  m_wire_hvsegm[id] = zer_1_1a;
2528  intvecIt = m_wire_hvsegm.find(id);
2529  for (int wire = 1; wire <= 48; wire++)
2530  intvecIt->second[wire] = 1; // Segment 1
2531 
2532  // For ME1/1b
2533  std::vector<int> zer_1_1b(49, 0);
2534  id = csctype[1];
2535  if (m_wire_hvsegm.find(id) == m_wire_hvsegm.end())
2536  m_wire_hvsegm[id] = zer_1_1b;
2537  intvecIt = m_wire_hvsegm.find(id);
2538  for (int wire = 1; wire <= 48; wire++)
2539  intvecIt->second[wire] = 1; // Segment 1
2540 
2541  // For ME1/2
2542  std::vector<int> zer_1_2(65, 0);
2543  id = csctype[2];
2544  if (m_wire_hvsegm.find(id) == m_wire_hvsegm.end())
2545  m_wire_hvsegm[id] = zer_1_2;
2546  intvecIt = m_wire_hvsegm.find(id);
2547  for (int wire = 1; wire <= 24; wire++)
2548  intvecIt->second[wire] = 1; // Segment 1
2549  for (int wire = 25; wire <= 48; wire++)
2550  intvecIt->second[wire] = 2; // Segment 2
2551  for (int wire = 49; wire <= 64; wire++)
2552  intvecIt->second[wire] = 3; // Segment 3
2553 
2554  // For ME1/3
2555  std::vector<int> zer_1_3(33, 0);
2556  id = csctype[3];
2557  if (m_wire_hvsegm.find(id) == m_wire_hvsegm.end())
2558  m_wire_hvsegm[id] = zer_1_3;
2559  intvecIt = m_wire_hvsegm.find(id);
2560  for (int wire = 1; wire <= 12; wire++)
2561  intvecIt->second[wire] = 1; // Segment 1
2562  for (int wire = 13; wire <= 22; wire++)
2563  intvecIt->second[wire] = 2; // Segment 2
2564  for (int wire = 23; wire <= 32; wire++)
2565  intvecIt->second[wire] = 3; // Segment 3
2566 
2567  // For ME2/1
2568  std::vector<int> zer_2_1(113, 0);
2569  id = csctype[4];
2570  if (m_wire_hvsegm.find(id) == m_wire_hvsegm.end())
2571  m_wire_hvsegm[id] = zer_2_1;
2572  intvecIt = m_wire_hvsegm.find(id);
2573  for (int wire = 1; wire <= 44; wire++)
2574  intvecIt->second[wire] = 1; // Segment 1
2575  for (int wire = 45; wire <= 80; wire++)
2576  intvecIt->second[wire] = 2; // Segment 2
2577  for (int wire = 81; wire <= 112; wire++)
2578  intvecIt->second[wire] = 3; // Segment 3
2579 
2580  // For ME2/2
2581  std::vector<int> zer_2_2(65, 0);
2582  id = csctype[5];
2583  if (m_wire_hvsegm.find(id) == m_wire_hvsegm.end())
2584  m_wire_hvsegm[id] = zer_2_2;
2585  intvecIt = m_wire_hvsegm.find(id);
2586  for (int wire = 1; wire <= 16; wire++)
2587  intvecIt->second[wire] = 1; // Segment 1
2588  for (int wire = 17; wire <= 28; wire++)
2589  intvecIt->second[wire] = 2; // Segment 2
2590  for (int wire = 29; wire <= 40; wire++)
2591  intvecIt->second[wire] = 3; // Segment 3
2592  for (int wire = 41; wire <= 52; wire++)
2593  intvecIt->second[wire] = 4; // Segment 4
2594  for (int wire = 53; wire <= 64; wire++)
2595  intvecIt->second[wire] = 5; // Segment 5
2596 
2597  // For ME3/1
2598  std::vector<int> zer_3_1(97, 0);
2599  id = csctype[6];
2600  if (m_wire_hvsegm.find(id) == m_wire_hvsegm.end())
2601  m_wire_hvsegm[id] = zer_3_1;
2602  intvecIt = m_wire_hvsegm.find(id);
2603  for (int wire = 1; wire <= 32; wire++)
2604  intvecIt->second[wire] = 1; // Segment 1
2605  for (int wire = 33; wire <= 64; wire++)
2606  intvecIt->second[wire] = 2; // Segment 2
2607  for (int wire = 65; wire <= 96; wire++)
2608  intvecIt->second[wire] = 3; // Segment 3
2609 
2610  // For ME3/2
2611  std::vector<int> zer_3_2(65, 0);
2612  id = csctype[7];
2613  if (m_wire_hvsegm.find(id) == m_wire_hvsegm.end())
2614  m_wire_hvsegm[id] = zer_3_2;
2615  intvecIt = m_wire_hvsegm.find(id);
2616  for (int wire = 1; wire <= 16; wire++)
2617  intvecIt->second[wire] = 1; // Segment 1
2618  for (int wire = 17; wire <= 28; wire++)
2619  intvecIt->second[wire] = 2; // Segment 2
2620  for (int wire = 29; wire <= 40; wire++)
2621  intvecIt->second[wire] = 3; // Segment 3
2622  for (int wire = 41; wire <= 52; wire++)
2623  intvecIt->second[wire] = 4; // Segment 4
2624  for (int wire = 53; wire <= 64; wire++)
2625  intvecIt->second[wire] = 5; // Segment 5
2626 
2627  // For ME4/1
2628  std::vector<int> zer_4_1(97, 0);
2629  id = csctype[8];
2630  if (m_wire_hvsegm.find(id) == m_wire_hvsegm.end())
2631  m_wire_hvsegm[id] = zer_4_1;
2632  intvecIt = m_wire_hvsegm.find(id);
2633  for (int wire = 1; wire <= 32; wire++)
2634  intvecIt->second[wire] = 1; // Segment 1
2635  for (int wire = 33; wire <= 64; wire++)
2636  intvecIt->second[wire] = 2; // Segment 2
2637  for (int wire = 65; wire <= 96; wire++)
2638  intvecIt->second[wire] = 3; // Segment 3
2639 
2640  // For ME4/2
2641  std::vector<int> zer_4_2(65, 0);
2642  id = csctype[9];
2643  if (m_wire_hvsegm.find(id) == m_wire_hvsegm.end())
2644  m_wire_hvsegm[id] = zer_4_2;
2645  intvecIt = m_wire_hvsegm.find(id);
2646  for (int wire = 1; wire <= 16; wire++)
2647  intvecIt->second[wire] = 1; // Segment 1
2648  for (int wire = 17; wire <= 28; wire++)
2649  intvecIt->second[wire] = 2; // Segment 2
2650  for (int wire = 29; wire <= 40; wire++)
2651  intvecIt->second[wire] = 3; // Segment 3
2652  for (int wire = 41; wire <= 52; wire++)
2653  intvecIt->second[wire] = 4; // Segment 4
2654  for (int wire = 53; wire <= 64; wire++)
2655  intvecIt->second[wire] = 5; // Segment 5
2656 
2657  } // end of if(nEventsAnalyzed==1)
2658 
2659  // do wires, strips and rechits present?
2660  wire_strip_rechit_present = 0;
2661  if (wirecltn.begin() != wirecltn.end())
2662  wire_strip_rechit_present = wire_strip_rechit_present + 1;
2663  if (strpcltn.begin() != strpcltn.end())
2664  wire_strip_rechit_present = wire_strip_rechit_present + 2;
2665  if (rechitcltn.begin() != rechitcltn.end())
2666  wire_strip_rechit_present = wire_strip_rechit_present + 4;
2667 
2668  if (wire_strip_rechit_present == 7) {
2669  // std::cout<<"Event "<<nEventsAnalyzed<<std::endl;
2670  // std::cout<<std::endl;
2671 
2672  // cycle on wire collection for all CSC to select single wire hit layers
2674 
2675  for (wiredetUnitIt = wirecltn.begin(); wiredetUnitIt != wirecltn.end(); ++wiredetUnitIt) {
2676  const CSCDetId id = (*wiredetUnitIt).first;
2677  idlayer = indexer.dbIndex(id, channel);
2678  // looping in the layer of given CSC
2679  mult = 0;
2680  wire = 0;
2681  const CSCWireDigiCollection::Range& range = (*wiredetUnitIt).second;
2682  for (CSCWireDigiCollection::const_iterator digiIt = range.first; digiIt != range.second; ++digiIt) {
2683  wire = (*digiIt).getWireGroup();
2684  mult++;
2685  } // end of digis loop in layer
2686 
2687  // select layers with single wire hit
2688  if (mult == 1) {
2689  if (m_single_wire_layer.find(idlayer) == m_single_wire_layer.end())
2690  m_single_wire_layer[idlayer] = wire;
2691  } // end of if(mult==1)
2692  } // end of cycle on detUnit
2693 
2694  // Looping thru rechit collection
2697 
2698  for (recIt = rechitcltn.begin(); recIt != rechitcltn.end(); ++recIt) {
2699  CSCDetId id = (CSCDetId)(*recIt).cscDetId();
2700  idlayer = indexer.dbIndex(id, channel);
2701  idchamber = idlayer / 10;
2702  layer = id.layer();
2703  // select layer with single wire rechit
2704  if (m_single_wire_layer.find(idlayer) != m_single_wire_layer.end()) {
2705  if (recIt->nStrips() == 3) {
2706  // get 3X3 ADC Sum
2707  unsigned int binmx = 0;
2708  float adcmax = 0.0;
2709 
2710  for (unsigned int i = 0; i < recIt->nStrips(); i++)
2711  for (unsigned int j = 0; j < recIt->nTimeBins(); j++)
2712  if (recIt->adcs(i, j) > adcmax) {
2713  adcmax = recIt->adcs(i, j);
2714  binmx = j;
2715  }
2716 
2717  float adc_3_3_sum = 0.0;
2718  //well, this really only works for 3 strips in readout - not sure the right fix for general case
2719  for (unsigned int i = 0; i < recIt->nStrips(); i++)
2720  for (unsigned int j = binmx - 1; j <= binmx + 1; j++)
2721  adc_3_3_sum += recIt->adcs(i, j);
2722 
2723  if (adc_3_3_sum > 0.0 && adc_3_3_sum < 2000.0) {
2724  // temporary fix for ME1/1a to avoid triple entries
2725  int flag = 0;
2726  if (id.station() == 1 && id.ring() == 4 && recIt->channels(1) > 16)
2727  flag = 1;
2728  // end of temporary fix
2729  if (flag == 0) {
2730  wire = m_single_wire_layer[idlayer];
2731  int chambertype = id.iChamberType(id.station(), id.ring());
2732  int hvsgmtnmb = m_wire_hvsegm[chambertype][wire];
2733  int nmbofhvsegm = nmbhvsegm[chambertype - 1];
2734  int location = (layer - 1) * nmbofhvsegm + hvsgmtnmb;
2735 
2736  ss << "gas_gain_rechit_adc_3_3_sum_location_ME_" << idchamber;
2737  name = ss.str();
2738  ss.str("");
2739  if (id.endcap() == 1)
2740  endcapstr = "+";
2741  ring = id.ring();
2742  if (id.station() == 1 && id.ring() == 4)
2743  ring = 1;
2744  if (id.endcap() == 2)
2745  endcapstr = "-";
2746  ss << "Gas Gain Rechit ADC3X3 Sum ME" << endcapstr << id.station() << "/" << ring << "/" << id.chamber();
2747  title = ss.str();
2748  ss.str("");
2749  float x = location;
2750  float y = adc_3_3_sum;
2751  histos->fill2DHist(x, y, name, title, 30, 1.0, 31.0, 50, 0.0, 2000.0, "GasGain");
2752 
2753  /*
2754  std::cout<<idchamber<<" "<<id.station()<<" "<<id.ring()<<" "
2755  <<id.chamber()<<" "<<layer<<" "<< wire<<" "<<m_strip[1]<<" "<<
2756  chambertype<<" "<< hvsgmtnmb<<" "<< nmbofhvsegm<<" "<<
2757  location<<" "<<adc_3_3_sum<<std::endl;
2758  */
2759  } // end of if flag==0
2760  } // end if(adcsum>0.0 && adcsum<2000.0)
2761  } // end of if if(m_strip.size()==3
2762  } // end of if single wire
2763  } // end of looping thru rechit collection
2764  } // end of if wire and strip and rechit present
2765 }
2766 
2767 //---------------------------------------------------------------------------
2768 // Module for looking at AFEB Timing
2769 // Author N. Terentiev
2770 //---------------------------------------------------------------------------
2771 
2772 void CSCValidation::doAFEBTiming(const CSCWireDigiCollection& wirecltn) {
2773  ostringstream ss;
2774  std::string name, title, endcapstr;
2775  float x, y;
2776  int wire, wiretbin, nmbwiretbin, layer, afeb, idlayer, idchamber;
2777  int channel = 0; // for CSCIndexer::dbIndex(id, channel); irrelevant here
2778  CSCIndexer indexer;
2779 
2780  if (wirecltn.begin() != wirecltn.end()) {
2781  //std::cout<<std::endl;
2782  //std::cout<<"Event "<<nEventsAnalyzed<<std::endl;
2783  //std::cout<<std::endl;
2784 
2785  // cycle on wire collection for all CSC
2787  for (wiredetUnitIt = wirecltn.begin(); wiredetUnitIt != wirecltn.end(); ++wiredetUnitIt) {
2788  const CSCDetId id = (*wiredetUnitIt).first;
2789  idlayer = indexer.dbIndex(id, channel);
2790  idchamber = idlayer / 10;
2791  layer = id.layer();
2792 
2793  if (id.endcap() == 1)
2794  endcapstr = "+";
2795  if (id.endcap() == 2)
2796  endcapstr = "-";
2797 
2798  // looping in the layer of given CSC
2799 
2800  const CSCWireDigiCollection::Range& range = (*wiredetUnitIt).second;
2801  for (CSCWireDigiCollection::const_iterator digiIt = range.first; digiIt != range.second; ++digiIt) {
2802  wire = (*digiIt).getWireGroup();
2803  wiretbin = (*digiIt).getTimeBin();
2804  nmbwiretbin = (*digiIt).getTimeBinsOn().size();
2805  afeb = 3 * ((wire - 1) / 8) + (layer + 1) / 2;
2806 
2807  // Anode wire group time bin vs afeb for each CSC
2808  x = afeb;
2809  y = wiretbin;
2810  ss << "afeb_time_bin_vs_afeb_occupancy_ME_" << idchamber;
2811  name = ss.str();
2812  ss.str("");
2813  ss << "Time Bin vs AFEB Occupancy ME" << endcapstr << id.station() << "/" << id.ring() << "/" << id.chamber();
2814  title = ss.str();
2815  ss.str("");
2816  histos->fill2DHist(x, y, name, title, 42, 1., 43., 16, 0., 16., "AFEBTiming");
2817 
2818  // Number of anode wire group time bin vs afeb for each CSC
2819  x = afeb;
2820  y = nmbwiretbin;
2821  ss << "nmb_afeb_time_bins_vs_afeb_ME_" << idchamber;
2822  name = ss.str();
2823  ss.str("");
2824  ss << "Number of Time Bins vs AFEB ME" << endcapstr << id.station() << "/" << id.ring() << "/" << id.chamber();
2825  title = ss.str();
2826  ss.str("");
2827  histos->fill2DHist(x, y, name, title, 42, 1., 43., 16, 0., 16., "AFEBTiming");
2828 
2829  } // end of digis loop in layer
2830  } // end of wire collection loop
2831  } // end of if(wirecltn.begin() != wirecltn.end())
2832 }
2833 
2834 //---------------------------------------------------------------------------
2835 // Module for looking at Comparator Timing
2836 // Author N. Terentiev
2837 //---------------------------------------------------------------------------
2838 
2839 void CSCValidation::doCompTiming(const CSCComparatorDigiCollection& compars) {
2840  ostringstream ss;
2842  float x, y;
2843  int strip, tbin, cfeb, idlayer, idchamber;
2844  int channel = 0; // for CSCIndexer::dbIndex(id, channel); irrelevant here
2845  CSCIndexer indexer;
2846 
2847  if (compars.begin() != compars.end()) {
2848  //std::cout<<std::endl;
2849  //std::cout<<"Event "<<nEventsAnalyzed<<std::endl;
2850  //std::cout<<std::endl;
2851 
2852  // cycle on comparators collection for all CSC
2854  for (compdetUnitIt = compars.begin(); compdetUnitIt != compars.end(); ++compdetUnitIt) {
2855  const CSCDetId id = (*compdetUnitIt).first;
2856  idlayer = indexer.dbIndex(id, channel); // channel irrelevant here
2857  idchamber = idlayer / 10;
2858 
2859  if (id.endcap() == 1)
2860  endcap = "+";
2861  if (id.endcap() == 2)
2862  endcap = "-";
2863  // looping in the layer of given CSC
2864  const CSCComparatorDigiCollection::Range& range = (*compdetUnitIt).second;
2865  for (CSCComparatorDigiCollection::const_iterator digiIt = range.first; digiIt != range.second; ++digiIt) {
2866  strip = (*digiIt).getStrip();
2867  /*
2868  if(id.station()==1 && (id.ring()==1 || id.ring()==4))
2869  std::cout<<idchamber<<" "<<id.station()<<" "<<id.ring()<<" "
2870  <<strip <<std::endl;
2871  */
2872  indexer.dbIndex(id, strip); // strips 1-16 of ME1/1a
2873  // become strips 65-80 of ME1/1
2874  tbin = (*digiIt).getTimeBin();
2875  cfeb = (strip - 1) / 16 + 1;
2876 
2877  // time bin vs cfeb for each CSC
2878 
2879  x = cfeb;
2880  y = tbin;
2881  ss << "comp_time_bin_vs_cfeb_occupancy_ME_" << idchamber;
2882  name = ss.str();
2883  ss.str("");
2884  ss << "Comparator Time Bin vs CFEB Occupancy ME" << endcap << id.station() << "/" << id.ring() << "/"
2885  << id.chamber();
2886  title = ss.str();
2887  ss.str("");
2888  histos->fill2DHist(x, y, name, title, 5, 1., 6., 16, 0., 16., "CompTiming");
2889 
2890  } // end of digis loop in layer
2891  } // end of collection loop
2892  } // end of if(compars.begin() !=compars.end())
2893 }
2894 
2895 //---------------------------------------------------------------------------
2896 // Module for looking at Strip Timing
2897 // Author N. Terentiev
2898 //---------------------------------------------------------------------------
2899 
2900 void CSCValidation::doADCTiming(const CSCRecHit2DCollection& rechitcltn) {
2901  float adc_3_3_sum, adc_3_3_wtbin, x, y;
2902  int cfeb, idchamber, ring;
2903 
2904  std::string name, title, endcapstr;
2905  ostringstream ss;
2906  std::vector<float> zer(6, 0.0);
2907 
2908  CSCIndexer indexer;
2909  std::map<int, int>::iterator intIt;
2910 
2911  if (rechitcltn.begin() != rechitcltn.end()) {
2912  // std::cout<<"Event "<<nEventsAnalyzed <<std::endl;
2913 
2914  // Looping thru rechit collection
2917  for (recIt = rechitcltn.begin(); recIt != rechitcltn.end(); ++recIt) {
2918  CSCDetId id = (CSCDetId)(*recIt).cscDetId();
2919  // getting strips comprising rechit
2920  if (recIt->nStrips() == 3) {
2921  // get 3X3 ADC Sum
2922  // get 3X3 ADC Sum
2923  unsigned int binmx = 0;
2924  float adcmax = 0.0;
2925 
2926  for (unsigned int i = 0; i < recIt->nStrips(); i++)
2927  for (unsigned int j = 0; j < recIt->nTimeBins(); j++)
2928  if (recIt->adcs(i, j) > adcmax) {
2929  adcmax = recIt->adcs(i, j);
2930  binmx = j;
2931  }
2932 
2933  adc_3_3_sum = 0.0;
2934  //well, this really only works for 3 strips in readout - not sure the right fix for general case
2935  for (unsigned int i = 0; i < recIt->nStrips(); i++)
2936  for (unsigned int j = binmx - 1; j <= binmx + 1; j++)
2937  adc_3_3_sum += recIt->adcs(i, j);
2938 
2939  // ADC weighted time bin
2940  if (adc_3_3_sum > 100.0) {
2941  int centerStrip = recIt->channels(1); //take central from 3 strips;
2942  // temporary fix
2943  int flag = 0;
2944  if (id.station() == 1 && id.ring() == 4 && centerStrip > 16)
2945  flag = 1;
2946  // end of temporary fix
2947  if (flag == 0) {
2948  adc_3_3_wtbin = (*recIt).tpeak() / 50; //getTiming(strpcltn, id, centerStrip);
2949  idchamber = indexer.dbIndex(id, centerStrip) / 10; //strips 1-16 ME1/1a
2950  // become strips 65-80 ME1/1 !!!
2951  /*
2952  if(id.station()==1 && (id.ring()==1 || id.ring()==4))
2953  std::cout<<idchamber<<" "<<id.station()<<" "<<id.ring()<<" "<<m_strip[1]<<" "<<
2954  " "<<centerStrip<<
2955  " "<<adc_3_3_wtbin<<" "<<adc_3_3_sum<<std::endl;
2956  */
2957  ss << "adc_3_3_weight_time_bin_vs_cfeb_occupancy_ME_" << idchamber;
2958  name = ss.str();
2959  ss.str("");
2960 
2961  std::string endcapstr;
2962  if (id.endcap() == 1)
2963  endcapstr = "+";
2964  if (id.endcap() == 2)
2965  endcapstr = "-";
2966  ring = id.ring();
2967  if (id.ring() == 4)
2968  ring = 1;
2969  ss << "ADC 3X3 Weighted Time Bin vs CFEB Occupancy ME" << endcapstr << id.station() << "/" << ring << "/"
2970  << id.chamber();
2971  title = ss.str();
2972  ss.str("");
2973 
2974  cfeb = (centerStrip - 1) / 16 + 1;
2975  x = cfeb;
2976  y = adc_3_3_wtbin;
2977  histos->fill2DHist(x, y, name, title, 5, 1., 6., 80, -8., 8., "ADCTiming");
2978  } // end of if flag==0
2979  } // end of if (adc_3_3_sum > 100.0)
2980  } // end of if if(m_strip.size()==3
2981  } // end of the pass thru CSCRecHit2DCollection
2982  } // end of if (rechitcltn.begin() != rechitcltn.end())
2983 }
2984 
2985 //---------------------------------------------------------------------------------------
2986 // Construct histograms for monitoring the trigger and offline timing
2987 // Author: A. Deisher
2988 //---------------------------------------------------------------------------------------
2989 
2990 void CSCValidation::doTimeMonitoring(edm::Handle<CSCRecHit2DCollection> recHits,
2997  const edm::EventSetup& eventSetup,
2998  const edm::Event& event) {
2999  map<CSCDetId, float> segment_median_map; //structure for storing the median time for segments in a chamber
3000  map<CSCDetId, GlobalPoint> segment_position_map; //structure for storing the global position for segments in a chamber
3001 
3002  // -----------------------
3003  // loop over segments
3004  // -----------------------
3005  int iSegment = 0;
3006  for (CSCSegmentCollection::const_iterator dSiter = cscSegments->begin(); dSiter != cscSegments->end(); dSiter++) {
3007  iSegment++;
3008 
3009  CSCDetId id = (CSCDetId)(*dSiter).cscDetId();
3010  LocalPoint localPos = (*dSiter).localPosition();
3011  GlobalPoint globalPosition = GlobalPoint(0.0, 0.0, 0.0);
3012  const CSCChamber* cscchamber = cscGeom->chamber(id);
3013  if (cscchamber) {
3014  globalPosition = cscchamber->toGlobal(localPos);
3015  }
3016 
3017  // try to get the CSC recHits that contribute to this segment.
3018  std::vector<CSCRecHit2D> theseRecHits = (*dSiter).specificRecHits();
3019  int nRH = (*dSiter).nRecHits();
3020  if (nRH < 4)
3021  continue;
3022 
3023  //Store the recHit times of a segment in a vector for later sorting
3024  vector<float> non_zero;
3025 
3026  for (vector<CSCRecHit2D>::const_iterator iRH = theseRecHits.begin(); iRH != theseRecHits.end(); iRH++) {
3027  non_zero.push_back(iRH->tpeak());
3028 
3029  } // end rechit loop
3030 
3031  //Sort the vector of hit times for this segment and average the center two
3032  sort(non_zero.begin(), non_zero.end());
3033  int middle_index = non_zero.size() / 2;
3034  float average_two = (non_zero.at(middle_index - 1) + non_zero.at(middle_index)) / 2.;
3035  if (non_zero.size() % 2)
3036  average_two = non_zero.at(middle_index);
3037 
3038  //If we've vetoed events with multiple segments per chamber, this should never overwrite informations
3039  segment_median_map[id] = average_two;
3040  segment_position_map[id] = globalPosition;
3041 
3042  double distToIP = sqrt(globalPosition.x() * globalPosition.x() + globalPosition.y() * globalPosition.y() +
3043  globalPosition.z() * globalPosition.z());
3044 
3045  histos->fillProfile(chamberSerial(id),
3046  average_two,
3047  "timeChamber",
3048  "Segment mean time",
3049  601,
3050  -0.5,
3051  600.5,
3052  -400.,
3053  400.,
3054  "TimeMonitoring");
3055  histos->fillProfileByType(id.chamber(),
3056  average_two,
3057  "timeChamberByType",
3058  "Segment mean time by chamber",
3059  id,
3060  36,
3061  0.5,
3062  36.5,
3063  -400,
3064  400.,
3065  "TimeMonitoring");
3066  histos->fill2DHist(distToIP,
3067  average_two,
3068  "seg_time_vs_distToIP",
3069  "Segment time vs. Distance to IP",
3070  80,
3071  600.,
3072  1400.,
3073  800,
3074  -400,
3075  400.,
3076  "TimeMonitoring");
3077  histos->fill2DHist(globalPosition.z(),
3078  average_two,
3079  "seg_time_vs_globZ",
3080  "Segment time vs. z position",
3081  240,
3082  -1200,
3083  1200,
3084  800,
3085  -400.,
3086  400.,
3087  "TimeMonitoring");
3088  histos->fill2DHist(fabs(globalPosition.z()),
3089  average_two,
3090  "seg_time_vs_absglobZ",
3091  "Segment time vs. abs(z position)",
3092  120,
3093  0.,
3094  1200.,
3095  800,
3096  -400.,
3097  400.,
3098  "TimeMonitoring");
3099 
3100  } //end segment loop
3101 
3102  //Now that the information for each segment we're interest in is stored, it is time to go through the pairs and make plots
3103  map<CSCDetId, float>::const_iterator it_outer; //for the outer loop
3104  map<CSCDetId, float>::const_iterator it_inner; //for the nested inner loop
3105  for (it_outer = segment_median_map.begin(); it_outer != segment_median_map.end(); it_outer++) {
3106  CSCDetId id_outer = it_outer->first;
3107  float t_outer = it_outer->second;
3108 
3109  //begin the inner loop
3110  for (it_inner = segment_median_map.begin(); it_inner != segment_median_map.end(); it_inner++) {
3111  CSCDetId id_inner = it_inner->first;
3112  float t_inner = it_inner->second;
3113 
3114  // we're looking at ordered pairs, so combinations will be double counted
3115  // (chamber a, chamber b) will be counted as well as (chamber b, chamber a)
3116  // We will avoid (chamber a, chamber a) with the following line
3117  if (chamberSerial(id_outer) == chamberSerial(id_inner))
3118  continue;
3119 
3120  // Calculate expected TOF (in ns units)
3121  // GlobalPoint gp_outer = segment_position_map.find(id_outer)->second;
3122  // GlobalPoint gp_inner = segment_position_map.find(id_inner)->second;
3123  // GlobalVector flight = gp_outer - gp_inner; //in cm
3124  // float TOF = flight.mag()/30.0; //to ns
3125 
3126  //Plot t(ME+) - t(ME-) for chamber pairs in the same stations and rings but opposite endcaps
3127  if (id_outer.endcap() == 1 && id_inner.endcap() == 2 && id_outer.station() == id_inner.station() &&
3128  id_outer.ring() == id_inner.ring()) {
3129  histos->fill1DHist(t_outer - t_inner,
3130  "diff_opposite_endcaps",
3131  "#Delta t [ME+]-[ME-] for chambers in same station and ring",
3132  800,
3133  -400.,
3134  400.,
3135  "TimeMonitoring");
3136  histos->fill1DHistByType(t_outer - t_inner,
3137  "diff_opposite_endcaps_byType",
3138  "#Delta t [ME+]-[ME-] for chambers in same station and ring",
3139  id_outer,
3140  800,
3141  -400.,
3142  400.,
3143  "TimeMonitoring");
3144  }
3145 
3146  } //end inner loop of segment pairs
3147  } //end outer loop of segment pairs
3148 
3149  //if the digis, return here
3150  if (!useDigis)
3151  return;
3152 
3153  //looking for the global trigger number
3154  vector<L1MuGMTReadoutRecord> L1Mrec = pCollection->getRecords();
3155  vector<L1MuGMTReadoutRecord>::const_iterator igmtrr;
3156  int L1GMT_BXN = -100;
3157  bool has_CSCTrigger = false;
3158  bool has_beamHaloTrigger = false;
3159  for (igmtrr = L1Mrec.begin(); igmtrr != L1Mrec.end(); igmtrr++) {
3160  std::vector<L1MuRegionalCand>::const_iterator iter1;
3161  std::vector<L1MuRegionalCand> rmc;
3162  // CSC
3163  int icsc = 0;
3164  rmc = igmtrr->getCSCCands();
3165  for (iter1 = rmc.begin(); iter1 != rmc.end(); iter1++) {
3166  if (!(*iter1).empty()) {
3167  icsc++;
3168  int kQuality = (*iter1).quality(); // kQuality = 1 means beam halo
3169  if (kQuality == 1)
3170  has_beamHaloTrigger = true;
3171  }
3172  }
3173  if (igmtrr->getBxInEvent() == 0 && icsc > 0) {
3174  //printf("L1 CSCCands exist. L1MuGMTReadoutRecord BXN = %d \n", igmtrr->getBxNr());
3175  L1GMT_BXN = igmtrr->getBxNr();
3176  has_CSCTrigger = true;
3177  } else if (igmtrr->getBxInEvent() == 0) {
3178  //printf("L1 CSCCands do not exist. L1MuGMTReadoutRecord BXN = %d \n", igmtrr->getBxNr());
3179  L1GMT_BXN = igmtrr->getBxNr();
3180  }
3181  }
3182 
3183  // *************************************************
3184  // *** ALCT Digis **********************************
3185  // *************************************************
3186 
3187  int n_alcts = 0;
3188  map<CSCDetId, int> ALCT_KeyWG_map; //structure for storing the key wire group for the first ALCT for each chamber
3189  for (CSCALCTDigiCollection::DigiRangeIterator j = alcts->begin(); j != alcts->end(); j++) {
3190  const CSCALCTDigiCollection::Range& range = (*j).second;
3191  const CSCDetId& idALCT = (*j).first;
3192  for (CSCALCTDigiCollection::const_iterator digiIt = range.first; digiIt != range.second; ++digiIt) {
3193  // Valid digi in the chamber (or in neighbouring chamber)
3194  if ((*digiIt).isValid()) {
3195  n_alcts++;
3196  histos->fill1DHist((*digiIt).getBX(), "ALCT_getBX", "ALCT.getBX()", 11, -0.5, 10.5, "TimeMonitoring");
3197  histos->fill1DHist(
3198  (*digiIt).getFullBX(), "ALCT_getFullBX", "ALCT.getFullBX()", 3601, -0.5, 3600.5, "TimeMonitoring");
3199  //if we don't already have digi information stored for this chamber, then we fill it
3200  if (ALCT_KeyWG_map.find(idALCT.chamberId()) == ALCT_KeyWG_map.end()) {
3201  ALCT_KeyWG_map[idALCT.chamberId()] = (*digiIt).getKeyWG();
3202  //printf("I did fill ALCT info for Chamber %d %d %d %d \n",idALCT.chamberId().endcap(), idALCT.chamberId().station(), idALCT.chamberId().ring(), idALCT.chamberId().chamber());
3203  }
3204  }
3205  }
3206  }
3207 
3208  // *************************************************
3209  // *** CLCT Digis **********************************
3210  // *************************************************
3211  int n_clcts = 0;
3212  map<CSCDetId, int> CLCT_getFullBx_map; //structure for storing the pretrigger bxn for the first CLCT for each chamber
3213  for (CSCCLCTDigiCollection::DigiRangeIterator j = clcts->begin(); j != clcts->end(); j++) {
3214  const CSCCLCTDigiCollection::Range& range = (*j).second;
3215  const CSCDetId& idCLCT = (*j).first;
3216  for (CSCCLCTDigiCollection::const_iterator digiIt = range.first; digiIt != range.second; ++digiIt) {
3217  // Valid digi in the chamber (or in neighbouring chamber)
3218  if ((*digiIt).isValid()) {
3219  n_clcts++;
3220  histos->fill1DHist((*digiIt).getBX(), "CLCT_getBX", "CLCT.getBX()", 11, -0.5, 10.5, "TimeMonitoring");
3221  histos->fill1DHist(
3222  (*digiIt).getFullBX(), "CLCT_getFullBX", "CLCT.getFullBX()", 3601, -0.5, 3600.5, "TimeMonitoring");
3223  //if we don't already have digi information stored for this chamber, then we fill it
3224  if (CLCT_getFullBx_map.find(idCLCT.chamberId()) == CLCT_getFullBx_map.end()) {
3225  CLCT_getFullBx_map[idCLCT.chamberId()] = (*digiIt).getFullBX();
3226  //printf("I did fill CLCT info for Chamber %d %d %d %d \n",idCLCT.chamberId().endcap(), idCLCT.chamberId().station(), idCLCT.chamberId().ring(), idCLCT.chamberId().chamber());
3227  }
3228  }
3229  }
3230  }
3231 
3232  // *************************************************
3233  // *** CorrelatedLCT Digis *************************
3234  // *************************************************
3235  int n_correlatedlcts = 0;
3236  for (CSCCorrelatedLCTDigiCollection::DigiRangeIterator j = correlatedlcts->begin(); j != correlatedlcts->end(); j++) {
3237  const CSCCorrelatedLCTDigiCollection::Range& range = (*j).second;
3238  for (CSCCorrelatedLCTDigiCollection::const_iterator digiIt = range.first; digiIt != range.second; ++digiIt) {
3239  if ((*digiIt).isValid()) {
3240  n_correlatedlcts++;
3241  histos->fill1DHist(
3242  (*digiIt).getBX(), "CorrelatedLCTS_getBX", "CorrelatedLCT.getBX()", 11, -0.5, 10.5, "TimeMonitoring");
3243  }
3244  }
3245  }
3246 
3247  int nRecHits = recHits->size();
3248  int nSegments = cscSegments->size();
3249  if (has_CSCTrigger) {
3250  histos->fill1DHist(L1GMT_BXN, "BX_L1CSCCand", "BX of L1 CSC Cand", 4001, -0.5, 4000.5, "TimeMonitoring");
3251  histos->fill2DHist(L1GMT_BXN,
3252  n_alcts,
3253  "n_ALCTs_v_BX_L1CSCCand",
3254  "Number of ALCTs vs. BX of L1 CSC Cand",
3255  4001,
3256  -0.5,
3257  4000.5,
3258  51,
3259  -0.5,
3260  50.5,
3261  "TimeMonitoring");
3262  histos->fill2DHist(L1GMT_BXN,
3263  n_clcts,
3264  "n_CLCTs_v_BX_L1CSCCand",
3265  "Number of CLCTs vs. BX of L1 CSC Cand",
3266  4001,
3267  -0.5,
3268  4000.5,
3269  51,
3270  -0.5,
3271  50.5,
3272  "TimeMonitoring");
3273  histos->fill2DHist(L1GMT_BXN,
3274  n_correlatedlcts,
3275  "n_CorrelatedLCTs_v_BX_L1CSCCand",
3276  "Number of CorrelatedLCTs vs. BX of L1 CSC Cand",
3277  4001,
3278  -0.5,
3279  4000.5,
3280  51,
3281  -0.5,
3282  50.5,
3283  "TimeMonitoring");
3284  histos->fill2DHist(L1GMT_BXN,
3285  nRecHits,
3286  "n_RecHits_v_BX_L1CSCCand",
3287  "Number of RecHits vs. BX of L1 CSC Cand",
3288  4001,
3289  -0.5,
3290  4000.5,
3291  101,
3292  -0.5,
3293  100.5,
3294  "TimeMonitoring");
3295  histos->fill2DHist(L1GMT_BXN,
3296  nSegments,
3297  "n_Segments_v_BX_L1CSCCand",
3298  "Number of Segments vs. BX of L1 CSC Cand",
3299  4001,
3300  -0.5,
3301  4000.5,
3302  51,
3303  -0.5,
3304  50.5,
3305  "TimeMonitoring");
3306  }
3307  if (has_CSCTrigger && has_beamHaloTrigger) {
3308  histos->fill1DHist(
3309  L1GMT_BXN, "BX_L1CSCCand_w_beamHalo", "BX of L1 CSC (w beamHalo bit)", 4001, -0.5, 4000.5, "TimeMonitoring");
3310  histos->fill2DHist(L1GMT_BXN,
3311  n_alcts,
3312  "n_ALCTs_v_BX_L1CSCCand_w_beamHalo",
3313  "Number of ALCTs vs. BX of L1 CSC Cand (w beamHalo bit)",
3314  4001,
3315  -0.5,
3316  4000.5,
3317  51,
3318  -0.5,
3319  50.5,
3320  "TimeMonitoring");
3321  histos->fill2DHist(L1GMT_BXN,
3322  n_clcts,
3323  "n_CLCTs_v_BX_L1CSCCand_w_beamHalo",
3324  "Number of CLCTs vs. BX of L1 CSC Cand (w beamHalo bit)",
3325  4001,
3326  -0.5,
3327  4000.5,
3328  51,
3329  -0.5,
3330  50.5,
3331  "TimeMonitoring");
3332  histos->fill2DHist(L1GMT_BXN,
3333  n_correlatedlcts,
3334  "n_CorrelatedLCTs_v_BX_L1CSCCand_w_beamHalo",
3335  "Number of CorrelatedLCTs vs. BX of L1 CSC Cand (w beamHalo bit)",
3336  4001,
3337  -0.5,
3338  4000.5,
3339  51,
3340  -0.5,
3341  50.5,
3342  "TimeMonitoring");
3343  histos->fill2DHist(L1GMT_BXN,
3344  nRecHits,
3345  "n_RecHits_v_BX_L1CSCCand_w_beamHalo",
3346  "Number of RecHits vs. BX of L1 CSC Cand (w beamHalo bit)",
3347  4001,
3348  -0.5,
3349  4000.5,
3350  101,
3351  -0.5,
3352  100.5,
3353  "TimeMonitoring");
3354  histos->fill2DHist(L1GMT_BXN,
3355  nSegments,
3356  "n_Segments_v_BX_L1CSCCand_w_beamHalo",
3357  "Number of Segments vs. BX of L1 CSC Cand (w beamHalo bit)",
3358  4001,
3359  -0.5,
3360  4000.5,
3361  51,
3362  -0.5,
3363  50.5,
3364  "TimeMonitoring");
3365  }
3366 
3367  // *******************************************************************
3368  // Get information from the TMB header.
3369  // Can this eventually come out of the digis?
3370  // Taking code from EventFilter/CSCRawToDigis/CSCDCCUnpacker.cc
3371  // *******************************************************************
3372 
3373  edm::ESHandle<CSCCrateMap> hcrate = eventSetup.getHandle(crateToken_);
3374  const CSCCrateMap* pcrate = hcrate.product();
3375 
3378  event.getByToken(rd_token, rawdata);
3379  // If set selective unpacking mode
3380  // hardcoded examiner mask below to check for DCC and DDU level errors will be used first
3381  // then examinerMask for CSC level errors will be used during unpacking of each CSC block
3382  unsigned long dccBinCheckMask = 0x06080016;
3383  unsigned int examinerMask = 0x1FEBF3F6;
3384  unsigned int errorMask = 0x0;
3385 
3386  for (int id = FEDNumbering::MINCSCFEDID; id <= FEDNumbering::MAXCSCFEDID; ++id) {
3387  // loop over DCCs
3390 
3392  const FEDRawData& fedData = rawdata->FEDData(id);
3393  unsigned long length = fedData.size();
3394 
3395  if (length >= 32) {
3396  std::stringstream examiner_out, examiner_err;
3398  CSCDCCExaminer* examiner = new CSCDCCExaminer();
3399  if (examinerMask & 0x40000)
3400  examiner->crcCFEB(true);
3401  if (examinerMask & 0x8000)
3402  examiner->crcTMB(true);
3403  if (examinerMask & 0x0400)
3404  examiner->crcALCT(true);
3405  examiner->setMask(examinerMask);
3406  const short unsigned int* data = (short unsigned int*)fedData.data();
3407 
3408  bool goodEvent;
3409  if (examiner->check(data, long(fedData.size() / 2)) < 0) {
3410  goodEvent = false;
3411  } else {
3412  goodEvent = !(examiner->errors() & dccBinCheckMask);
3413  }
3414 
3415  if (goodEvent) {
3417  CSCDCCExaminer* ptrExaminer = examiner;
3418  CSCDCCEventData dccData((short unsigned int*)fedData.data(), ptrExaminer);
3419 
3421  const std::vector<CSCDDUEventData>& dduData = dccData.dduData();
3422 
3424  CSCDetId layer(1, 1, 1, 1, 1);
3425 
3426  for (unsigned int iDDU = 0; iDDU < dduData.size(); ++iDDU) { // loop over DDUs
3429  if (dduData[iDDU].trailer().errorstat() & errorMask) {
3430  LogTrace("CSCDCCUnpacker|CSCRawToDigi") << "DDU# " << iDDU << " has serious error - no digis unpacked! "
3431  << std::hex << dduData[iDDU].trailer().errorstat();
3432  continue; // to next iteration of DDU loop
3433  }
3434 
3436  const std::vector<CSCEventData>& cscData = dduData[iDDU].cscData();
3437  for (unsigned int iCSC = 0; iCSC < cscData.size(); ++iCSC) { // loop over CSCs
3438 
3439  int vmecrate = cscData[iCSC].dmbHeader()->crateID();
3440  int dmb = cscData[iCSC].dmbHeader()->dmbID();
3441 
3443  // SKIPPING MTCC redefinition of vmecrate
3444 
3445  int icfeb = 0;
3446  int ilayer = 0;
3447 
3448  if ((vmecrate >= 1) && (vmecrate <= 60) && (dmb >= 1) && (dmb <= 10) && (dmb != 6)) {
3449  layer = pcrate->detId(vmecrate, dmb, icfeb, ilayer);
3450  } else {
3451  LogTrace("CSCTimingAlignment|CSCDCCUnpacker|CSCRawToDigi") << " detID input out of range!!! ";
3452  LogTrace("CSCTimingAlignment|CSCDCCUnpacker|CSCRawToDigi")
3453  << " skipping chamber vme= " << vmecrate << " dmb= " << dmb;
3454  continue; // to next iteration of iCSC loop
3455  }
3456 
3458  int nalct = cscData[iCSC].dmbHeader()->nalct();
3459  bool goodALCT = false;
3460  //if (nalct&&(cscData[iCSC].dataPresent>>6&0x1)==1) {
3461  if (nalct && cscData[iCSC].alctHeader()) {
3462  if (cscData[iCSC].alctHeader()->check()) {
3463  goodALCT = true;
3464  }
3465  }
3466 
3468  int nclct = cscData[iCSC].dmbHeader()->nclct();
3469  bool goodTMB = false;
3470  if (nclct && cscData[iCSC].tmbData()) {
3471  if (cscData[iCSC].tmbHeader()->check()) {
3472  if (cscData[iCSC].comparatorData()->check())
3473  goodTMB = true;
3474  }
3475  }
3476 
3477  if (goodTMB && goodALCT) {
3478  if (ALCT_KeyWG_map.find(layer) == ALCT_KeyWG_map.end()) {
3479  printf("no ALCT info for Chamber %d %d %d %d \n",
3480  layer.endcap(),
3481  layer.station(),
3482  layer.ring(),
3483  layer.chamber());
3484  continue;
3485  }
3486  if (CLCT_getFullBx_map.find(layer) == CLCT_getFullBx_map.end()) {
3487  printf("no CLCT info for Chamber %d %d %d %d \n",
3488  layer.endcap(),
3489  layer.station(),
3490  layer.ring(),
3491  layer.chamber());
3492  continue;
3493  }
3494  int ALCT0Key = ALCT_KeyWG_map.find(layer)->second;
3495  int CLCTPretrigger = CLCT_getFullBx_map.find(layer)->second;
3496 
3497  const CSCTMBHeader* tmbHead = cscData[iCSC].tmbHeader();
3498 
3499  histos->fill1DHistByStation(tmbHead->BXNCount(),
3500  "TMB_BXNCount",
3501  "TMB_BXNCount",
3502  layer.chamberId(),
3503  3601,
3504  -0.5,
3505  3600.5,
3506  "TimeMonitoring");
3507  histos->fill1DHistByStation(tmbHead->ALCTMatchTime(),
3508  "TMB_ALCTMatchTime",
3509  "TMB_ALCTMatchTime",
3510  layer.chamberId(),
3511  7,
3512  -0.5,
3513  6.5,
3514  "TimeMonitoring");
3515 
3516  histos->fill1DHist(
3517  tmbHead->BXNCount(), "TMB_BXNCount", "TMB_BXNCount", 3601, -0.5, 3600.5, "TimeMonitoring");
3518  histos->fill1DHist(
3519  tmbHead->ALCTMatchTime(), "TMB_ALCTMatchTime", "TMB_ALCTMatchTime", 7, -0.5, 6.5, "TimeMonitoring");
3520 
3521  histos->fill1DHistByType(tmbHead->ALCTMatchTime(),
3522  "TMB_ALCTMatchTime",
3523  "TMB_ALCTMatchTime",
3524  layer.chamberId(),
3525  7,
3526  -0.5,
3527  6.5,
3528  "TimeMonitoring");
3529 
3530  histos->fillProfile(chamberSerial(layer.chamberId()),
3531  tmbHead->ALCTMatchTime(),
3532  "prof_TMB_ALCTMatchTime",
3533  "prof_TMB_ALCTMatchTime",
3534  601,
3535  -0.5,
3536  600.5,
3537  -0.5,
3538  7.5,
3539  "TimeMonitoring");
3540  histos->fillProfile(ALCT0Key,
3541  tmbHead->ALCTMatchTime(),
3542  "prof_TMB_ALCTMatchTime_v_ALCT0KeyWG",
3543  "prof_TMB_ALCTMatchTime_v_ALCT0KeyWG",
3544  128,
3545  -0.5,
3546  127.5,
3547  0,
3548  7,
3549  "TimeMonitoring");
3550  histos->fillProfileByType(ALCT0Key,
3551  tmbHead->ALCTMatchTime(),
3552  "prf_TMB_ALCTMatchTime_v_ALCT0KeyWG",
3553  "prf_TMB_ALCTMatchTime_v_ALCT0KeyWG",
3554  layer.chamberId(),
3555  128,
3556  -0.5,
3557  127.5,
3558  0,
3559  7,
3560  "TimeMonitoring");
3561 
3562  //Attempt to make a few sum plots
3563 
3564  int TMB_ALCT_rel_L1A = tmbHead->BXNCount() - (CLCTPretrigger + 2 + tmbHead->ALCTMatchTime());
3565  if (TMB_ALCT_rel_L1A > 3563)
3566  TMB_ALCT_rel_L1A = TMB_ALCT_rel_L1A - 3564;
3567  if (TMB_ALCT_rel_L1A < 0)
3568  TMB_ALCT_rel_L1A = TMB_ALCT_rel_L1A + 3564;
3569 
3570  //Plot TMB_ALCT_rel_L1A
3571  histos->fill1DHist(
3572  TMB_ALCT_rel_L1A, "h1D_TMB_ALCT_rel_L1A", "h1D_TMB_ALCT_rel_L1A", 11, 144.5, 155.5, "TimeMonitoring");
3573  histos->fill2DHist(chamberSerial(layer.chamberId()),
3574  TMB_ALCT_rel_L1A,
3575  "h2D_TMB_ALCT_rel_L1A",
3576  "h2D_TMB_ALCT_rel_L1A",
3577  601,
3578  -0.5,
3579  600.5,
3580  11,
3581  144.5,
3582  155.5,
3583  "TimeMonitoring");
3584  histos->fill2DHist(ringSerial(layer.chamberId()),
3585  TMB_ALCT_rel_L1A,
3586  "h2D_TMB_ALCT_rel_L1A_by_ring",
3587  "h2D_TMB_ALCT_rel_L1A_by_ring",
3588  19,
3589  -9.5,
3590  9.5,
3591  11,
3592  144.5,
3593  155.5,
3594  "TimeMonitoring");
3595  histos->fillProfile(chamberSerial(layer.chamberId()),
3596  TMB_ALCT_rel_L1A,
3597  "prof_TMB_ALCT_rel_L1A",
3598  "prof_TMB_ALCT_rel_L1A",
3599  601,
3600  -0.5,
3601  600.5,
3602  145,
3603  155,
3604  "TimeMonitoring");
3605  histos->fillProfile(ringSerial(layer.chamberId()),
3606  TMB_ALCT_rel_L1A,
3607  "prof_TMB_ALCT_rel_L1A_by_ring",
3608  "prof_TMB_ALCT_rel_L1A_by_ring",
3609  19,
3610  -9.5,
3611  9.5,
3612  145,
3613  155,
3614  "TimeMonitoring");
3615 
3616  histos->fill2DHist(ALCT0Key,
3617  TMB_ALCT_rel_L1A,
3618  "h2D_TMB_ALCT_rel_L1A_v_ALCT0KeyWG",
3619  "h2D_TMB_ALCT_rel_L1A_v_ALCT0KeyWG",
3620  128,
3621  -0.5,
3622  127.5,
3623  11,
3624  144.5,
3625  155.5,
3626  "TimeMonitoring");
3627  histos->fillProfile(ALCT0Key,
3628  TMB_ALCT_rel_L1A,
3629  "prof_TMB_ALCT_rel_L1A_v_ALCT0KeyWG",
3630  "prof_TMB_ALCT_rel_L1A_v_ALCT0KeyWG",
3631  128,
3632  -0.5,
3633  127.5,
3634  145,
3635  155,
3636  "TimeMonitoring");
3637  histos->fillProfileByType(ALCT0Key,
3638  TMB_ALCT_rel_L1A,
3639  "prf_TMB_ALCT_rel_L1A_v_ALCT0KeyWG",
3640  "prf_TMB_ALCT_rel_L1A_v_ALCT0KeyWG",
3641  layer.chamberId(),
3642  128,
3643  -0.5,
3644  127.5,
3645  145,
3646  155,
3647  "TimeMonitoring");
3648  }
3649 
3650  } // end CSCData loop
3651  } // end ddu data loop
3652  } // end if goodEvent
3653  if (examiner != nullptr)
3654  delete examiner;
3655  } // end if non-zero fed data
3656  } // end DCC loop for NON-REFERENCE
3657 }
3658 
3659 void CSCValidation::beginJob() { std::cout << "CSCValidation starting..." << std::endl; }
3660 
3661 void CSCValidation::endJob() { std::cout << "CSCValidation: Events analyzed " << nEventsAnalyzed << std::endl; }
3662 
01/20/05 A.Tumanov
void crcCFEB(bool enable)
const CSCLayer * layer(CSCDetId id) const
Return the layer corresponding to the given id.
Definition: CSCChamber.cc:30
LocalPoint localPosition() const override
Definition: CSCSegment.h:39
const CSCChamber * chamber(CSCDetId id) const
Return the chamber corresponding to given DetId.
Definition: CSCGeometry.cc:100
LocalPoint toLocal(const GlobalPoint &gp) const
Conversion to the R.F. of the GeomDet.
Definition: GeomDet.h:58
T z() const
Definition: PV3DBase.h:61
for(int i=first, nt=offsets[nh];i< nt;i+=gridDim.x *blockDim.x)
Geom::Phi< T > phi() const
Definition: PV3DBase.h:66
static const double slope[3]
Global3DPoint GlobalPoint
Definition: GlobalPoint.h:10
size_t size() const
Lenght of the data buffer in bytes.
Definition: FEDRawData.h:45
Definition: weight.py:1
GainContainer gains
Definition: CSCDBGains.h:24
int layer() const
Definition: CSCDetId.h:56
std::string chamberTypeName() const
void crcALCT(bool enable)
example_stream void analyze(const edm::Event &, const edm::EventSetup &) override
nStrips
1.2 is to make the matching window safely the two nearest strips 0.35 is the size of an ME0 chamber i...
#define LogTrace(id)
const CSCLayerGeometry * geometry() const
Definition: CSCLayer.h:44
void beginJob()
Definition: Breakpoints.cc:14
constexpr std::array< uint8_t, layerIndexSize > layer
LocalVector localDirection() const override
Local direction.
Definition: CSCSegment.h:42
C::const_iterator const_iterator
constant access iterator type
Definition: RangeMap.h:43
float yy() const
Definition: LocalError.h:24
T x() const
Definition: PV3DBase.h:59
T y() const
Definition: PV3DBase.h:60
uint16_t ALCTMatchTime() const
Definition: CSCTMBHeader.h:44
const std::vector< CSCDDUEventData > & dduData() const
accessor to dduData
T const * product() const
Definition: ESHandle.h:86
uint16_t BXNCount() const
Definition: CSCTMBHeader.h:43
int np
Definition: AMPTWrapper.h:43
int dbIndex(const CSCDetId &id, int &channel)
Definition: CSCIndexer.cc:235
T sqrt(T t)
Definition: SSEVec.h:19
void crcTMB(bool enable)
T mag() const
Definition: PV3DBase.h:64
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
float ChiSquaredProbability(double chiSquared, double nrDOF)
int chamber() const
Definition: CSCDetId.h:62
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
static const std::string kLayer("layer")
d
Definition: ztail.py:151
GlobalPoint toGlobal(const Local2DPoint &lp) const
Conversion to the global R.F. from the R.F. of the GeomDet.
Definition: GeomDet.h:49
const FEDRawData & FEDData(int fedid) const
retrieve data for fed
float xy() const
Definition: LocalError.h:23
Definition: DetId.h:17
std::vector< L1MuGMTReadoutRecord > const & getRecords() const
CSCDetId detId(int vme, int dmb, int cfeb, int layer=0) const
Definition: CSCCrateMap.cc:9
int station() const
Definition: CSCDetId.h:79
CSCDetId chamberId() const
Definition: CSCDetId.h:47
virtual const std::array< const float, 4 > parameters() const
std::pair< const_iterator, const_iterator > Range
static constexpr int RPC
Definition: MuonSubdetId.h:13
int endcap() const
Definition: CSCDetId.h:85
std::vector< DigiType >::const_iterator const_iterator
int32_t check(const uint16_t *&buffer, int32_t length)
histos
Definition: combine.py:4
std::vector< const CSCChamber * > ChamberContainer
Definition: CSCGeometry.h:30
PedestalContainer pedestals
HLT enums.
char data[epos_bytes_allocation]
Definition: EPOS_Wrapper.h:79
ExaminerStatusType errors(void) const
float x
const unsigned char * data() const
Return a const pointer to the beginning of the data buffer.
Definition: FEDRawData.cc:24
strips
#turn off noise in all subdetectors simHcalUnsuppressedDigis.doNoise = False mix.digitizers.hcal.doNoise = False simEcalUnsuppressedDigis.doNoise = False mix.digitizers.ecal.doNoise = False simEcalUnsuppressedDigis.doESNoise = False simSiPixelDigis.AddNoise = False mix.digitizers.pixel.AddNoise = False simSiStripDigis.Noise = False mix.digitizers.strip.AddNoise = False
Definition: DigiDM_cff.py:32
Definition: errors.py:1
CrosstalkContainer crosstalk
NoiseMatrixContainer matrix
static constexpr int DT
Definition: MuonSubdetId.h:11
int ring() const
Definition: CSCDetId.h:68
const ChamberContainer & chambers() const
Return a vector of all chambers.
Definition: CSCGeometry.cc:96
const CSCLayer * layer(CSCDetId id) const
Return the layer corresponding to given DetId.
Definition: CSCGeometry.cc:105
static constexpr int CSC
Definition: MuonSubdetId.h:12
Geom::Theta< T > theta() const
const CSCChamberSpecs * specs() const
Definition: CSCChamber.h:39
void setMask(ExaminerMaskType mask)
Power< A, B >::type pow(const A &a, const B &b)
Definition: Power.h:29
float xx() const
Definition: LocalError.h:22
Definition: event.py:1
Geom::Theta< T > theta() const
Definition: PV3DBase.h:72
#define LogDebug(id)
CSCDetId id() const
Get the (concrete) DetId.
Definition: CSCChamber.h:34