CMS 3D CMS Logo

CSCTriggerPrimitivesReader.cc
Go to the documentation of this file.
1 //-------------------------------------------------
2 //
3 // Class: CSCTriggerPrimitivesReader
4 //
5 // Description: Basic analyzer class which accesses ALCTs, CLCTs, and
6 // correlated LCTs and plot various quantities.
7 //
8 // Author List: S. Valuev, UCLA.
9 //
10 //
11 // Modifications:
12 //
13 //--------------------------------------------------
14 
15 //-----------------------
16 // This Class's Header --
17 //-----------------------
19 
20 //-------------------------------
21 // Collaborating Class Headers --
22 //-------------------------------
23 
29 
31 
34 
35 // MC data
37 
38 // MC tests
43 
44 #include "TCanvas.h"
45 #include "TFile.h"
46 #include "TH1.h"
47 #include "TText.h"
48 #include "TPaveLabel.h"
49 #include "TPostScript.h"
50 #include "TStyle.h"
51 #include "TROOT.h"
52 
55 
56 #define MAXSTUBS 100
57 using namespace std;
58 
59 //-----------------
60 // Static variables
61 //-----------------
62 
63 
64 // Various useful constants
65 const double CSCTriggerPrimitivesReader::TWOPI = 2.*M_PI;
67  "ME1/1", "ME1/2", "ME1/3", "ME1/A", "ME2/1", "ME2/2",
68  "ME3/1", "ME3/2", "ME4/1", "ME4/2"};
70  "ME+1/1", "ME+1/2", "ME+1/3", "ME+1/A", "ME+2/1", "ME+2/2",
71  "ME+3/1", "ME+3/2", "ME+4/1", "ME+4/2"};
73  "ME-1/1", "ME-1/2", "ME-1/3", "ME-1/A", "ME-2/1", "ME-2/2",
74  "ME-3/1", "ME-3/2", "ME-4/1", "ME-4/2"};
76  36, 36, 36, 36, 18, 36, 18, 36, 18, 36};
78  48, 64, 32, 48, 112, 64, 96, 64, 96, 64};//max. number of wiregroups
80  128, 160, 128, 96, 160, 160, 160, 160, 160, 160}; // max. # of halfstrips
82  -999, -5, 4, -4, 3, -3, 2, -2, 1, -1, 0}; // "signed" pattern (== phiBend)
83 
84 // LCT counters
89 
95 
97 
100 
102 
103 // LUT for which ME1/1 wire group can cross which ME1/a halfstrip
104 // 1st index: WG number
105 // 2nd index: inclusive HS range
107  {0, 95},{0, 95},{0, 95},{0, 95},{0, 95},
108  {0, 95},{0, 95},{0, 95},{0, 95},{0, 95},
109  {0, 95},{0, 95},{0, 77},{0, 61},{0, 39},
110  {0, 22},{-1,-1},{-1,-1},{-1,-1},{-1,-1},
111  {-1,-1},{-1,-1},{-1,-1},{-1,-1},{-1,-1},
112  {-1,-1},{-1,-1},{-1,-1},{-1,-1},{-1,-1},
113  {-1,-1},{-1,-1},{-1,-1},{-1,-1},{-1,-1},
114  {-1,-1},{-1,-1},{-1,-1},{-1,-1},{-1,-1},
115  {-1,-1},{-1,-1},{-1,-1},{-1,-1},{-1,-1},
116  {-1,-1},{-1,-1},{-1,-1} };
117 // a modified LUT for ganged ME1a
119  {0, 31},{0, 31},{0, 31},{0, 31},{0, 31},
120  {0, 31},{0, 31},{0, 31},{0, 31},{0, 31},
121  {0, 31},{0, 31},{0, 31},{0, 31},{0, 31},
122  {0, 22},{-1,-1},{-1,-1},{-1,-1},{-1,-1},
123  {-1,-1},{-1,-1},{-1,-1},{-1,-1},{-1,-1},
124  {-1,-1},{-1,-1},{-1,-1},{-1,-1},{-1,-1},
125  {-1,-1},{-1,-1},{-1,-1},{-1,-1},{-1,-1},
126  {-1,-1},{-1,-1},{-1,-1},{-1,-1},{-1,-1},
127  {-1,-1},{-1,-1},{-1,-1},{-1,-1},{-1,-1},
128  {-1,-1},{-1,-1},{-1,-1} };
129 
130 // LUT for which ME1/1 wire group can cross which ME1/b halfstrip
131 // 1st index: WG number
132 // 2nd index: inclusive HS range
134  {-1,-1},{-1,-1},{-1,-1},{-1,-1},{-1,-1},
135  {-1,-1},{-1,-1},{-1,-1},{-1,-1},{-1,-1},
136  {100, 127},{73, 127},{47, 127},{22, 127},{0, 127},
137  {0, 127},{0, 127},{0, 127},{0, 127},{0, 127},
138  {0, 127},{0, 127},{0, 127},{0, 127},{0, 127},
139  {0, 127},{0, 127},{0, 127},{0, 127},{0, 127},
140  {0, 127},{0, 127},{0, 127},{0, 127},{0, 127},
141  {0, 127},{0, 127},{0, 127},{0, 127},{0, 127},
142  {0, 127},{0, 127},{0, 127},{0, 127},{0, 105},
143  {0, 93},{0, 78},{0, 63} };
144 
145 //init My ttree
146 void TreePerStub::init(int run, int event){
147 
148  t_EventNumberAnalyzed = -1;
149  t_RUN = run;
150  t_Event = event;
151  t_nStubs = 0;
152  t_nStubs_readout = 0;
153 
154  t_chamber = -1;
155  t_ring = -1;
156  t_station = -1;
157  t_chambertype = -1;
158  t_endcap = -2;
159 }
160 
161 TTree *TreePerStub::bookTree(TTree *t, const std::string & name)
162 {
164  t = fs->make<TTree>(name.c_str(), name.c_str());
165 
166  t->Branch("t_EventNumberAnalyzed",&t_EventNumberAnalyzed,"t_EventNumberAnalyzed/I");
167  t->Branch("t_RUN",&t_RUN,"t_RUN/I");
168  t->Branch("t_Event",&t_Event,"t_Event/I");
169  t->Branch("t_nStubs",&t_nStubs,"t_nStubs/I");
170  t->Branch("t_nStubs_readout",&t_nStubs_readout,"t_nStubs_readout/I");
171  t->Branch("t_nStubs_ME119",&t_nStubs_ME119,"t_nStubs_ME119/I");
172  t->Branch("t_nStubs_ME11no911",&t_nStubs_ME11no911,"t_nStubs_ME11no911/I");
173  t->Branch("t_nStubs_noMEpm11",&t_nStubs_noMEpm11,"t_nStubs_noMEpm11/I");
174 
175  t->Branch("t_chamber", &t_chamber, "t_chamber/I");
176  t->Branch("t_ring", &t_ring, "t_ring/I");
177  t->Branch("t_endcap", &t_endcap, "t_endcap/I");
178  t->Branch("t_station", &t_station, "t_station/I");
179  t->Branch("t_chambertype", &t_chambertype, "t_chambertype/I");
180 
181  return t;
182 }
183 
184 
185 //init stub comparison struct
187 
188  nEvents = -1;
189  nRUN = run;
190  nEvent = event;
191  firstfill = false;
192  totStubs_data = -1;
193  totStubs_emul = -1;
194  totStubs_emul_readout = -1;
195  nStub_data = 0;
196  nStub_emul = 0;
197  chamber = -1;
198  ring =-1;
199  endcap =-1;
200  station = -1;
201  chambertype = -1;
202  has_data = false;
203  has_emul = false;
204 
205  npretrig = 0;
206  quality_pretrig = -1;
207  maxquality_pretrig = -1;
208  bend_pretrig = -1;
209  bx_pretrig = -1;
210  key_hs_pretrig = -1;
211  pattern_pretrig = -1;
212  maxpattern_pretrig = -1;
213  quality_data = -1;
214  bend_data = -1;
215  bx_data = -1;
216  quality_emul = -1;
217  bend_emul = -1;
218  pattern_data = -1;
219  pattern_emul = -1;
220  bx_emul = -1;
221  bx_corr_emul = -1;//corrected
222  key_WG_data = -1;
223  key_WG_emul = -1;
224  key_hs_data = -1;
225  key_hs_emul = -1;
226  WGcrossHS_data = false;
227  WGcrossHS_emul = false;
228  trknmb_data = -1;
229  trknmb_emul = -1;
230  dphi_data = -1;
231  dphi_emul = -1;
232  eta_data = -1;
233  eta_emul = -1;
234  phi_data = -1;
235  phi_emul = -1;
236 }
237 
238 
240 {
242  t = fs->make<TTree>(name.c_str(), name.c_str());
243 
244  t->Branch("nEvents",&nEvents);
245  t->Branch("nRUN",&nRUN);
246  t->Branch("nEvent",&nEvent);
247  t->Branch("firstfill",&firstfill);
248  t->Branch("totStubs_data",&totStubs_data);
249  t->Branch("totStubs_emul",&totStubs_emul);
250  t->Branch("totStubs_emul_readout",&totStubs_emul_readout);
251  t->Branch("nStub_data",&nStub_data);
252  t->Branch("nStub_emul",&nStub_emul);
253 
254  t->Branch("chamber",&chamber);
255  t->Branch("ring",&ring);
256  t->Branch("endcap",&endcap);
257  t->Branch("station",&station);
258  t->Branch("chambertype",&chambertype);
259  t->Branch("has_data",&has_data);
260  t->Branch("has_emul",&has_emul);
261  t->Branch("quality_data",&quality_data);
262  t->Branch("quality_emul",&quality_emul);
263  t->Branch("npretrig",&npretrig);
264  t->Branch("quality_pretrig",&quality_pretrig);
265  t->Branch("maxquality_pretrig",&maxquality_pretrig);
266  t->Branch("pattern_data",&pattern_data);
267  t->Branch("pattern_emul",&pattern_emul);
268  t->Branch("pattern_pretrig",&pattern_pretrig);
269  t->Branch("maxpattern_pretrig",&maxpattern_pretrig);
270  t->Branch("bend_data",&bend_data);
271  t->Branch("bx_data",&bx_data);
272  t->Branch("fullbx_data",&fullbx_data);
273  t->Branch("bend_emul",&bend_emul);
274  t->Branch("bx_emul",&bx_emul);
275  t->Branch("fullbx_emul",&fullbx_emul);
276  t->Branch("bend_pretrig",&bend_pretrig);
277  t->Branch("bx_pretrig",&bx_pretrig);
278  t->Branch("bx_corr_emul",&bx_corr_emul);
279  t->Branch("WGcrossHS_data",&WGcrossHS_data);
280  t->Branch("WGcrossHS_emul",&WGcrossHS_emul);
281  t->Branch("key_WG_data",&key_WG_data);
282  t->Branch("key_WG_emul",&key_WG_emul);
283  t->Branch("key_hs_data",&key_hs_data);
284  t->Branch("key_hs_emul",&key_hs_emul);
285  t->Branch("key_hs_pretrig",&key_hs_pretrig);
286  t->Branch("trknmb_data",&trknmb_data);
287  t->Branch("trknmb_emul",&trknmb_emul);
288  t->Branch("dphi_data",&dphi_data);
289  t->Branch("dphi_emul",&dphi_emul);
290  t->Branch("eta_data",&eta_data);
291  t->Branch("eta_emul",&eta_emul);
292  t->Branch("phi_data", &phi_data);
293  t->Branch("phi_emul", &phi_emul);
294 
295  return t;
296 
297 }
298 
299 
300 //----------------
301 // Constructor --
302 //----------------
305  // rootFileName = conf.getUntrackedParameter<string>("rootFileName","TPEHists.root");
306  // Create the root file for the histograms
307  // theFile = new TFile(rootFileName.c_str(), "RECREATE");
308  // theFile->cd();
309 
310  // Various input parameters.
311 
312  printps = conf.getParameter<bool>("printps");
313  dataLctsIn_ = conf.getParameter<bool>("dataLctsIn");
314  emulLctsIn_ = conf.getParameter<bool>("emulLctsIn");
315  edm::ParameterSet commonParams =
316  conf.getParameter<edm::ParameterSet>("commonParam");
317 
318  // Switch for a new (2007) version of the TMB firmware.
319  gangedME1a = commonParams.getParameter<bool>("gangedME1a");
320 
321  // is it (non-upgrade algorithm) run along with upgrade one?
322  plotME1A = true;
323  plotME42 = true;
324  lctProducerData_ = conf.getUntrackedParameter<string>("CSCLCTProducerData",
325  "cscunpacker");
326  mpclctProducerData_ = conf.getUntrackedParameter<string>("CSCMPCLCTProducerData",
327  "csctfDigis");
328  lctProducerEmul_ = conf.getUntrackedParameter<string>("CSCLCTProducerEmul",
329  "cscTriggerPrimitiveDigis");
330 
331  simHitProducer_ = conf.getParameter<edm::InputTag>("CSCSimHitProducer");
332  wireDigiProducer_ = conf.getParameter<edm::InputTag>("CSCWireDigiProducer");
333  compDigiProducer_ = conf.getParameter<edm::InputTag>("CSCComparatorDigiProducer");
334 
335  simHit_token_ = consumes<edm::PSimHitContainer>(simHitProducer_);
336  wireDigi_token_ = consumes<CSCWireDigiCollection>(wireDigiProducer_);
337  compDigi_token_ = consumes<CSCComparatorDigiCollection>(compDigiProducer_);
338 
339  alcts_d_token_ = consumes<CSCALCTDigiCollection>(edm::InputTag(lctProducerData_, "MuonCSCALCTDigi"));
340  clcts_d_token_ = consumes<CSCCLCTDigiCollection>(edm::InputTag(lctProducerData_, "MuonCSCCLCTDigi"));
341  lcts_tmb_d_token_ = consumes<CSCCorrelatedLCTDigiCollection>(edm::InputTag(lctProducerData_, "MuonCSCCorrelatedLCTDigi"));
342  lcts_mpc_d_token_ = consumes<CSCCorrelatedLCTDigiCollection>(edm::InputTag(mpclctProducerData_));
343 
344  alcts_e_token_ = consumes<CSCALCTDigiCollection>(edm::InputTag(lctProducerEmul_));
345  clcts_e_token_ = consumes<CSCCLCTDigiCollection>(edm::InputTag(lctProducerEmul_));
346  pretrigs_e_token_ = consumes<CSCCLCTPreTriggerDigiCollection>(edm::InputTag(lctProducerEmul_));
347  lcts_tmb_e_token_ = consumes<CSCCorrelatedLCTDigiCollection>(edm::InputTag(lctProducerEmul_));
348  lcts_mpc_e_token_ = consumes<CSCCorrelatedLCTDigiCollection>(edm::InputTag(lctProducerEmul_, "MPCSORTED"));
349 
350  consumesMany<edm::HepMCProduct>();
351  resultsFileNamesPrefix_ = conf.getUntrackedParameter<string>("resultsFileNamesPrefix","");
352  checkBadChambers_ = conf.getUntrackedParameter<bool>("checkBadChambers",true);
353  debug = conf.getUntrackedParameter<bool>("debug", false);
354  dataIsAnotherMC_ = conf.getUntrackedParameter<bool>("dataIsAnotherMC", false);
355 
356  //rootFileName = conf.getUntrackedParameter<string>("rootFileName");
357  // Create the root file.
358  // Not sure we really need it - comment out for now. -Slava.
359  //theFile = new TFile(rootFileName.c_str(), "RECREATE");
360  //theFile->cd();
361  stub_tree[0] = stubs_comparison[0].bookTree(stub_tree[0],"alcttree");
362  stub_tree[1] = stubs_comparison[1].bookTree(stub_tree[1],"clcttree");
363  stub_tree[2] = stubs_comparison[2].bookTree(stub_tree[2],"lcttree");
364  stub_tree[3] = stubs_comparison[3].bookTree(stub_tree[3],"mpclcttree");
365  // Per event TTree
366  event_tree[0] = perStub[0].bookTree(event_tree[0],"Ev_alcttree");
367  event_tree[1] = perStub[1].bookTree(event_tree[1],"Ev_emul_alcttree");
368  event_tree[2] = perStub[2].bookTree(event_tree[2],"Ev_clcttree");
369  event_tree[3] = perStub[3].bookTree(event_tree[3],"Ev_emul_clcttree");
370  event_tree[4] = perStub[4].bookTree(event_tree[4],"Ev_lcttree");
371  event_tree[5] = perStub[5].bookTree(event_tree[5],"Ev_emul_lcttree");
372  // My favourite ROOT settings.
373  setRootStyle();
374 }
375 
376 //----------------
377 // Destructor --
378 //----------------
380  // histos->writeHists(theFile);
381  // theFile->Close();
382  //delete theFile;
383 }
384 
385 
387 {
388  if (station == 1) {
389  if (plotME1A) return 4;
390  else return 3;
391  }
392  return 2;
393 }
394 
395 
397  const edm::EventSetup& setup) {
398  ++eventsAnalyzed;
399  //if (ev.id().event()%10 == 0)
400  LogTrace("CSCTriggerPrimitivesReader")
401  << "\n** CSCTriggerPrimitivesReader: processing run #"
402  << ev.id().run() << " event #" << ev.id().event()
403  << "; events so far: " << eventsAnalyzed << " **";
404  RUN_ = ev.id().run();
405  Event_ = ev.id().event();
406 
407  // Find the geometry for this event & cache it. Needed in LCTAnalyzer
408  // modules.
410  setup.get<MuonGeometryRecord>().get(cscGeom);
411  geom_ = &*cscGeom;
412 
413  // Find conditions data for bad chambers & cache it. Needed for efficiency
414  // calculations.
415  if (checkBadChambers_) {
417  setup.get<CSCBadChambersRcd>().get(pBad);
418  badChambers_ = pBad.product();
419  }
420 
421  // Get the collections of ALCTs, CLCTs, and correlated LCTs from event.
431 
432  // Data
433  if (dataLctsIn_) {
434  HotWires(ev);
435  // ev.getByLabel(lctProducerData_, alcts_data);
436  // ev.getByLabel(lctProducerData_, clcts_data);
437  // ev.getByLabel(lctProducerData_, lcts_tmb_data);
438  ev.getByToken(alcts_d_token_, alcts_data);
439  ev.getByToken(clcts_d_token_, clcts_data);
440  ev.getByToken(lcts_tmb_d_token_, lcts_tmb_data);
441  ev.getByToken(lcts_mpc_d_token_, lcts_mpc_data);
442 
443  if (!alcts_data.isValid()) {
444  edm::LogWarning("L1CSCTPEmulatorWrongInput")
445  << "+++ Warning: Collection of ALCTs with label MuonCSCALCTDigi"
446  << " requested, but not found in the event... Skipping the rest +++\n";
447  return;
448  }
449  if (!clcts_data.isValid()) {
450  edm::LogWarning("L1CSCTPEmulatorWrongInput")
451  << "+++ Warning: Collection of CLCTs with label MuonCSCCLCTDigi"
452  << " requested, but not found in the event... Skipping the rest +++\n";
453  return;
454  }
455  if (!lcts_tmb_data.isValid()) {
456  edm::LogWarning("L1CSCTPEmulatorWrongInput")
457  << "+++ Warning: Collection of correlated LCTs with label"
458  << " MuonCSCCorrelatedLCTDigi requested, but not found in the"
459  << " event... Skipping the rest +++\n";
460  return;
461  }
462  /*
463  if (!lcts_mpc_data.isValid()) {
464  edm::LogWarning("L1CSCTPEmulatorWrongInput")
465  << "+++ Warning: Collection of MPC correlated LCTs with label"
466  << " MuonCSCCorrelatedLCTDigi + MCPSorted requested, but not found in the"
467  << " event... Skipping the rest +++\n";
468  //return;
469  }*/
470  }
471 
472  // Emulator
473  if (emulLctsIn_) {
474  // ev.getByLabel(lctProducerEmul_, alcts_emul);
475  // ev.getByLabel(lctProducerEmul_, clcts_emul);
476  // ev.getByLabel(lctProducerEmul_, lcts_tmb_emul);
477  // ev.getByLabel(lctProducerEmul_, "MPCSORTED", lcts_mpc_emul);
478  ev.getByToken(alcts_e_token_, alcts_emul);
479  ev.getByToken(clcts_e_token_, clcts_emul);
480  ev.getByToken(pretrigs_e_token_, pretrigs_emul);
481  ev.getByToken(lcts_tmb_e_token_, lcts_tmb_emul);
482  ev.getByToken(lcts_mpc_e_token_, lcts_mpc_emul);
483 
484  if (!alcts_emul.isValid()) {
485  edm::LogWarning("L1CSCTPEmulatorWrongInput")
486  << "+++ Warning: Collection of emulated ALCTs"
487  << " requested, but not found in the event... Skipping the rest +++\n";
488  return;
489  }
490  if (!clcts_emul.isValid()) {
491  edm::LogWarning("L1CSCTPEmulatorWrongInput")
492  << "+++ Warning: Collection of emulated CLCTs"
493  << " requested, but not found in the event... Skipping the rest +++\n";
494  return;
495  }
496  if (!lcts_tmb_emul.isValid()) {
497  edm::LogWarning("L1CSCTPEmulatorWrongInput")
498  << "+++ Warning: Collection of emulated correlated LCTs"
499  << " requested, but not found in the event... Skipping the rest +++\n";
500  return;
501  }
502  /*
503  if (!lcts_mpc_emul.isValid()) {
504  edm::LogWarning("L1CSCTPEmulatorWrongInput")
505  << "+++ Warning: Collection of emulated correlated LCTs (MPCs)"
506  << " requested, but not found in the event... Skipping the rest +++\n";
507  //return;
508  }*/
509  }
510 
511  // Fill histograms with reconstructed or emulated quantities. If both are
512  // present, plot LCTs in data.
513  if (dataLctsIn_) {
514  fillALCTHistos(alcts_data.product());
515  fillCLCTHistos(clcts_data.product());
516  fillLCTTMBHistos(lcts_tmb_data.product());
517  }
518  else if (emulLctsIn_) {
519  fillALCTHistos(alcts_emul.product());
520  fillCLCTHistos(clcts_emul.product());
521  fillLCTTMBHistos(lcts_tmb_emul.product());
522  //fillLCTMPCHistos(lcts_mpc_emul.product());
523  }
524 
525  // Compare LCTs in the data with the ones produced by the emulator.
526  if (dataLctsIn_ && emulLctsIn_) {
527  compare(alcts_data.product(), alcts_emul.product(),
528  clcts_data.product(), clcts_emul.product(),
529  pretrigs_emul.product(), lcts_tmb_data.product(), lcts_tmb_emul.product()
530  );
531  }
532  // Fill MC-based resolution/efficiency histograms, if needed.
533  if (emulLctsIn_) {
534  MCStudies(ev, alcts_emul.product(), clcts_emul.product());
535  }
536 } // analyze
537 
539  // Note: all operations involving ROOT should be placed here and not in the
540  // destructor.
541  // Plot histos if they were booked/filled.
542  if(printps) {
546  //if (bookedLCTMPCHistos) drawLCTMPCHistos();
547 
549 
552  }
553  //drawHistosForTalks();
554 
555  //theFile->cd();
556  //theFile->Write();
557  //theFile->Close();
558 
559  // Job summary.
560  edm::LogInfo("CSCTriggerPrimitivesReader")
561  << "\n Average number of ALCTs/event = "
562  << static_cast<float>(numALCT)/eventsAnalyzed << endl;
563  edm::LogInfo("CSCTriggerPrimitivesReader")
564  << " Average number of CLCTs/event = "
565  << static_cast<float>(numCLCT)/eventsAnalyzed << endl;
566  edm::LogInfo("CSCTriggerPrimitivesReader")
567  << " Average number of TMB LCTs/event = "
568  << static_cast<float>(numLCTTMB)/eventsAnalyzed << endl;
569  edm::LogInfo("CSCTriggerPrimitivesReader")
570  << " Average number of MPC LCTs/event = "
571  << static_cast<float>(numLCTMPC)/eventsAnalyzed << endl;
572 
573  if (bookedEfficHistos) {
574  {
575  edm::LogInfo("CSCTriggerPrimitivesReader") << "\n ALCT efficiencies:";
576  double tot_simh = 0.0, tot_alct = 0.0;
577  for (int idh = 0; idh < CSC_TYPES; idh++) {
578  double simh = hEfficHitsEtaCsc[idh]->Integral();
579  double alct = hEfficALCTEtaCsc[idh]->Integral();
580  double eff = 0.;
581  if (simh > 0) eff = alct/simh;
582  edm::LogInfo("CSCTriggerPrimitivesReader")
583  << " " << csc_type[idh]
584  << ": alct = " << alct << ", simh = " << simh << " eff = " << eff;
585  tot_simh += simh;
586  tot_alct += alct;
587  }
588  edm::LogInfo("CSCTriggerPrimitivesReader")
589  << " overall: alct = " << tot_alct << ", simh = " << tot_simh
590  << " eff = " << tot_alct/tot_simh;
591  }
592 
593  {
594  edm::LogInfo("CSCTriggerPrimitivesReader") << "\n CLCT efficiencies:";
595  double tot_simh = 0.0, tot_clct = 0.0;
596  for (int idh = 0; idh < CSC_TYPES; idh++) {
597  double simh = hEfficHitsEtaCsc[idh]->Integral();
598  double clct = hEfficCLCTEtaCsc[idh]->Integral();
599  double eff = 0.;
600  if (simh > 0.) eff = clct/simh;
601  edm::LogInfo("CSCTriggerPrimitivesReader")
602  << " " << csc_type[idh]
603  << ": clct = " << clct << ", simh = " << simh << " eff = " << eff;
604  tot_simh += simh;
605  tot_clct += clct;
606  }
607  edm::LogInfo("CSCTriggerPrimitivesReader")
608  << " overall: clct = " << tot_clct << ", simh = " << tot_simh
609  << " eff = " << tot_clct/tot_simh;
610  }
611  }
612 
613  if (bookedResolHistos) {
614  double cor = 0.0, tot = 0.0;
615  cor = hResolDeltaHS->GetBinContent(hResolDeltaHS->FindBin(0.));
616  tot = hResolDeltaHS->GetEntries();
617  edm::LogInfo("CSCTriggerPrimitivesReader")
618  << "\n Correct half-strip assigned in " << cor << "/" << tot
619  << " = " << cor/tot << " of half-strip CLCTs";
620  //cor = hResolDeltaDS->GetBinContent(hResolDeltaDS->FindBin(0.));
621  //tot = hResolDeltaDS->GetEntries();
622  //edm::LogInfo("CSCTriggerPrimitivesReader")
623  // << " Correct di-strip assigned in " << cor << "/" << tot
624  // << " = " << cor/tot << " of di-strip CLCTs";
625  cor = hResolDeltaWG->GetBinContent(hResolDeltaWG->FindBin(0.));
626  tot = hResolDeltaWG->GetEntries();
627  edm::LogInfo("CSCTriggerPrimitivesReader")
628  << " Correct wire group assigned in " << cor << "/" << tot
629  << " = " << cor/tot << " of ALCTs";
630  }
631 }
632 
633 //---------------
634 // ROOT settings
635 //---------------
637  TH1::AddDirectory(false);
638 
639  gROOT->SetStyle("Plain");
640  gStyle->SetFillColor(0);
641  gStyle->SetOptDate();
642  gStyle->SetOptStat(111110);
643  gStyle->SetOptFit(1111);
644  gStyle->SetPadTickX(1);
645  gStyle->SetPadTickY(1);
646  gStyle->SetMarkerSize(0.5);
647  gStyle->SetMarkerStyle(8);
648  gStyle->SetGridStyle(3);
649  gStyle->SetPaperSize(TStyle::kA4);
650  gStyle->SetStatW(0.25); // width of statistics box; default is 0.19
651  gStyle->SetStatH(0.10); // height of statistics box; default is 0.1
652  gStyle->SetStatFormat("6.4g"); // leave default format for now
653  gStyle->SetTitleSize(0.055, ""); // size for pad title; default is 0.02
654  // Really big; useful for talks.
655  //gStyle->SetTitleSize(0.1, ""); // size for pad title; default is 0.02
656  gStyle->SetLabelSize(0.05, "XYZ"); // size for axis labels; default is 0.04
657  gStyle->SetStatFontSize(0.06); // size for stat. box
658  gStyle->SetTitleFont(32, "XYZ"); // times-bold-italic font (p. 153) for axes
659  gStyle->SetTitleFont(32, ""); // same for pad title
660  gStyle->SetLabelFont(32, "XYZ"); // same for axis labels
661  gStyle->SetStatFont(32); // same for stat. box
662  gStyle->SetLabelOffset(0.006, "Y"); // default is 0.005
663 }
664 
665 //---------------------
666 // Histograms for LCTs
667 //---------------------
670  hHotWire1 = fs->make<TH1F>("hHotWire1", "hHotWire1",570*6*112,0,570*6*112);
671  hHotCham1 = fs->make<TH1F>("hHotCham1", "hHotCham1",570,0,570);
672  bookedHotWireHistos = true;
673 }
674 
676  string s;
677 
679  hAlctPerEvent = fs->make<TH1F>("ALCTs_per_event", "ALCTs per event", 31, -0.5, 30.5);
680  hAlctPerChamber= fs->make<TH1F>("ALCTs_per_chamber", "ALCTs per chamber", 4, -0.5, 3.5);
681  hAlctPerCSC = fs->make<TH1F>("ALCTs_per_CSCtype", "ALCTs per CSC type", 10, -0.5, 9.5);
682  for (int i = 0; i < MAX_ENDCAPS; i++) { // endcaps
683  for (int j = 0; j < CSC_TYPES; j++) { // station/ring
684  float csc_max = NCHAMBERS[j] + 0.5;
685  char asdf[256];
686  sprintf(asdf,"ALCTs_%i",i*CSC_TYPES+j);
687  if (i == 0) s = "ALCTs, " + csc_type_plus[j];
688  else s = "ALCTs, " + csc_type_minus[j];
689  hAlctCsc[i][j] = fs->make<TH1F>(asdf, s.c_str(), NCHAMBERS[j], 0.5, csc_max);
690  }
691  }
692 
693  hAlctValid = fs->make<TH1F>("ALCT_validity", "ALCT validity", 3, -0.5, 2.5);
694  hAlctQuality = fs->make<TH1F>("ALCT_quality", "ALCT quality", 5, -0.5, 4.5);
695  hAlctAccel = fs->make<TH1F>("ALCT_accel_flag", "ALCT accel. flag", 3, -0.5, 2.5);
696  hAlctCollis = fs->make<TH1F>("ALCT_collision_flag", "ALCT collision. flag", 3, -0.5, 2.5);
697  hAlctKeyGroup = fs->make<TH1F>("ALCT_key_wiregroup", "ALCT key wiregroup", 120, -0.5, 119.5);
698  hAlctBXN = fs->make<TH1F>("ALCT_bx", "ALCT bx", 20, -0.5, 19.5);
699 
700  hAlctKeyGroupME11 = fs->make<TH1F>("hAlctKeyGroupME11", "ALCT key wiregroup ME1/1", 50, -0.5, 49.5);
701 
702  bookedALCTHistos = true;
703  std::cout <<" bookedALCTHistos " << std::endl;
704 }
705 
707  string s;
708 
710  hClctPerEvent = fs->make<TH1F>("CLCTs_per_event", "CLCTs per event", 31, -0.5, 30.5);
711  hClctPerChamber= fs->make<TH1F>("CLCTs_per_chamber", "CLCTs per chamber", 3, -0.5, 2.5);
712  hClctPerCSC = fs->make<TH1F>("CLCTs_per_CSCtype", "CLCTs per CSC type", 10, -0.5, 9.5);
713  for (int i = 0; i < MAX_ENDCAPS; i++) { // endcaps
714  for (int j = 0; j < CSC_TYPES; j++) { // station/ring
715  char asdf[256];
716  sprintf(asdf,"CLCTs_%i",i*CSC_TYPES+j);
717  float csc_max = NCHAMBERS[j] + 0.5;
718  if (i == 0) s = "CLCTs, " + csc_type_plus[j];
719  else s = "CLCTs, " + csc_type_minus[j];
720  hClctCsc[i][j] = fs->make<TH1F>(asdf, s.c_str(), NCHAMBERS[j], 0.5, csc_max);
721  }
722  }
723 
724  hClctValid = fs->make<TH1F>("CLCT_validity", "CLCT validity", 3, -0.5, 2.5);
725  hClctQuality = fs->make<TH1F>("CLCT_layers_hit", "CLCT layers hit", 9, -0.5, 8.5);
726  hClctStripType = fs->make<TH1F>("CLCT_strip_type", "CLCT strip type", 3, -0.5, 2.5);
727  hClctSign = fs->make<TH1F>("CLCT_sing_(L/R)", "CLCT sign (L/R)", 3, -0.5, 2.5);
728  hClctCFEB = fs->make<TH1F>("CLCT_cfeb_#", "CLCT cfeb #", 6, -0.5, 5.5);
729  hClctBXN = fs->make<TH1F>("CLCT_bx", "CLCT bx", 20, -0.5, 19.5);
730 
731  hClctKeyStrip[0] = fs->make<TH1F>("CLCT_keystrip_distrips","CLCT keystrip, distrips", 40, -0.5, 39.5);
732  //hClctKeyStrip[0] = fs->make<TH1F>("","CLCT keystrip, distrips", 160, -0.5, 159.5);
733  hClctKeyStrip[1] = fs->make<TH1F>("CLCT_keystrip_halfstrips","CLCT keystrip, halfstrips",160, -0.5, 159.5);
734  hClctPattern[0] = fs->make<TH1F>("CLCT_pattern_distrips","CLCT pattern, distrips", 13, -0.5, 12.5);
735  hClctPattern[1] = fs->make<TH1F>("CLCT_pattern_halfstrips","CLCT pattern, halfstrips", 13, -0.5, 12.5);
736 
737  for (int i = 0; i < CSC_TYPES; i++) {
738  char asdf[256];
739  string s1 = "CLCT bend, " + csc_type[i];
740  sprintf(asdf,"CLCT_bend0_%i",i+1);
741  hClctBendCsc[i][0] = fs->make<TH1F>(asdf, s1.c_str(), 5, -0.5, 4.5);
742  sprintf(asdf,"CLCT_bend1_%i",i+1);
743  hClctBendCsc[i][1] = fs->make<TH1F>(asdf, s1.c_str(), 5, -0.5, 4.5);
744 
745  sprintf(asdf,"CLCT_keystrip_%i",i+1);
746  string s2 = "CLCT keystrip, " + csc_type[i];
747  int max_ds = MAX_HS[i]/4;
748  hClctKeyStripCsc[i] = fs->make<TH1F>(asdf, s2.c_str(), max_ds, 0., max_ds);
749  }
750 
751  hClctKeyStripME11 = fs->make<TH1F>("hClctKeyStripME11","CLCT keystrip, halfstrips ME1/1",161, -0.5, 160.5);
752 
753  bookedCLCTHistos = true;
754  std::cout <<" bookedCLCTHistos " << std::endl;
755 }
756 
758  string s;
759 
761  hLctTMBPerEvent = fs->make<TH1F>("LCTs_per_event", "LCTs per event", 31, -0.5, 30.5);
762  hLctTMBPerChamber= fs->make<TH1F>("LCTs_per_chamber", "LCTs per chamber", 3, -0.5, 2.5);
763  hLctTMBPerCSC = fs->make<TH1F>("LCTs_per_CSCtype", "LCTs per CSC type", 10, -0.5, 9.5);
764  hCorrLctTMBPerCSC= fs->make<TH1F>("CorrLCTs_per_CSCtype", "Corr. LCTs per CSC type", 10, -0.5, 9.5);
765  hLctTMBEndcap = fs->make<TH1F>("LCTS_endcap", "Endcap", 4, -0.5, 3.5);
766  hLctTMBStation = fs->make<TH1F>("LCTS_station", "Station", 6, -0.5, 5.5);
767  hLctTMBSector = fs->make<TH1F>("LCTS_sector", "Sector", 8, -0.5, 7.5);
768  hLctTMBRing = fs->make<TH1F>("LCTS_ring", "Ring", 5, -0.5, 4.5);
769  for (int i = 0; i < MAX_ENDCAPS; i++) { // endcaps
770  for (int j = 0; j < CSC_TYPES; j++) { // station/ring
771  char asdf[256];
772  float csc_max = NCHAMBERS[j] + 0.5;
773  if (i == 0) s = "LCTs, " + csc_type_plus[j];
774  else s = "LCTs, " + csc_type_minus[j];
775  sprintf(asdf,"LCTs_%i",i*CSC_TYPES+j);
776  hLctTMBCsc[i][j] = fs->make<TH1F>(s.c_str(), s.c_str(), NCHAMBERS[j], 0.5, csc_max);
777  }
778  }
779 
780  hLctTMBValid = fs->make<TH1F>("LCT_validity", "LCT validity", 3, -0.5, 2.5);
781  hLctTMBQuality = fs->make<TH1F>("LCT_quality", "LCT quality", 17, -0.5, 16.5);
782  hLctTMBKeyGroup = fs->make<TH1F>("LCT_key_wiregroup", "LCT key wiregroup", 120, -0.5, 119.5);
783  hLctTMBKeyStrip = fs->make<TH1F>("LCT_key_strip", "LCT key strip", 160, -0.5, 159.5);
784  hLctTMBStripType = fs->make<TH1F>("LCT_strip_type", "LCT strip type", 3, -0.5, 2.5);
785  hLctTMBPattern = fs->make<TH1F>("LCT_pattern", "LCT pattern", 13, -0.5, 12.5);
786  hLctTMBBend = fs->make<TH1F>("LCT_bend", "LCT L/R bend", 3, -0.5, 2.5);
787  hLctTMBBXN = fs->make<TH1F>("LCT_bx", "LCT bx", 20, -0.5, 19.5);
788 
789  // LCT quantities per station
790  char histname[60];
791  for (int istat = 0; istat < MAX_STATIONS; istat++) {
792  sprintf(histname, "LCT_CSCId, station %d", istat+1);
793  hLctTMBChamber[istat] = fs->make<TH1F>("", histname, 10, -0.5, 9.5);
794  }
795 
796  hLctTMBKeyGroupME11 = fs->make<TH1F>("hLctTMBKeyGroupME11", "LCT key wiregroup ME1/1", 50, -0.5, 49.5);
797  hLctTMBKeyStripME11 = fs->make<TH1F>("hLctTMBKeyStripME11", "LCT key strip ME1/1", 161, -0.5, 160.5);
798 
799  bookedLCTTMBHistos = true;
800  std::cout <<" bookedLCTTMBHistos " << std::endl;
801 }
802 
804  // 1/1 1/2 1/3 2/1 2/2 3/1 3/2 4/1 4/2 -1/1 -1/2 -1/3 -2/1 -2/2 -3/1 -3/2 -4/1 -4/2
805  //ix= 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
806  int ix=0;
807  if(id.station()!=1) {
808 
809  ix=(id.station()-2)*2+3;
810  }
811  ix+=id.ring()-1;
812  if(id.endcap()==2) {
813  ix+=9;
814  }
815  return ix;
816 }
817 
819  int ix=1;
820  if(id.station()!=1) {
821  ix=(id.station()-2)*2+3+1;
822  }
823  ix+=id.ring()-1;
824  if(id.endcap()==2) {
825  ix*=-1;
826  }
827  return ix;
828 }
829 
831  int st = id.station();
832  int ri = id.ring();
833  int ch = id.chamber();
834  int ec = id.endcap();
835  int kSerial = ch;
836  if (st == 1 && ri == 1) kSerial = ch;
837  if (st == 1 && ri == 2) kSerial = ch + 36;
838  if (st == 1 && ri == 3) kSerial = ch + 72;
839  if (st == 1 && ri == 4) kSerial = ch;
840  if (st == 2 && ri == 1) kSerial = ch + 108;
841  if (st == 2 && ri == 2) kSerial = ch + 126;
842  if (st == 3 && ri == 1) kSerial = ch + 162;
843  if (st == 3 && ri == 2) kSerial = ch + 180;
844  if (st == 4 && ri == 1) kSerial = ch + 216;
845  if (st == 4 && ri == 2) kSerial = ch + 234; // one day...
846  if (ec == 2) kSerial = kSerial + 300;
847  return kSerial;
848 }
849 
850 
853  hLctMPCPerEvent = fs->make<TH1F>("MPC_per_event", "LCTs per event", 31, -0.5, 30.5);
854  hLctMPCPerCSC = fs->make<TH1F>("MPC_per_CSCtype", "LCTs per CSC type", 10, -0.5, 9.5);
855  hCorrLctMPCPerCSC= fs->make<TH1F>("CorrMPC_per_CSCtype", "Corr. LCTs per CSC type", 10, -0.5,9.5);
856  hLctMPCEndcap = fs->make<TH1F>("MPC_Endcap", "Endcap", 4, -0.5, 3.5);
857  hLctMPCStation = fs->make<TH1F>("MPC_Station", "Station", 6, -0.5, 5.5);
858  hLctMPCSector = fs->make<TH1F>("MPC_Sector", "Sector", 8, -0.5, 7.5);
859  hLctMPCRing = fs->make<TH1F>("MPC_Ring", "Ring", 5, -0.5, 4.5);
860 
861  hLctMPCValid = fs->make<TH1F>("MPC_validity", "LCT validity", 3, -0.5, 2.5);
862  hLctMPCQuality = fs->make<TH1F>("MPC_quality", "LCT quality", 17, -0.5, 16.5);
863  hLctMPCKeyGroup = fs->make<TH1F>("MPC_key_wiregroup", "LCT key wiregroup", 120, -0.5, 119.5);
864  hLctMPCKeyStrip = fs->make<TH1F>("MPC_key_strip", "LCT key strip", 160, -0.5, 159.5);
865  hLctMPCStripType = fs->make<TH1F>("MPC_strip_type", "LCT strip type", 3, -0.5, 2.5);
866  hLctMPCPattern = fs->make<TH1F>("MPC_pattern", "LCT pattern", 13, -0.5, 12.5);
867  hLctMPCBend = fs->make<TH1F>("MPC_bend", "LCT L/R bend", 3, -0.5, 2.5);
868  hLctMPCBXN = fs->make<TH1F>("MPC_bx", "LCT bx", 20, -0.5, 19.5);
869 
870  // LCT quantities per station
871  char histname[60];
872  for (int istat = 0; istat < MAX_STATIONS; istat++) {
873  sprintf(histname, "MPC_CSCId, station %d", istat+1);
874  hLctMPCChamber[istat] = fs->make<TH1F>("", histname, 10, -0.5, 9.5);
875  }
876 
877  hLctMPCKeyGroupME11 = fs->make<TH1F>("hLctMPCKeyGroupME11", "MPC LCT key wiregroup ME1/1", 50, -0.5, 49.5);
878  hLctMPCKeyStripME11 = fs->make<TH1F>("hLctMPCKeyStripME11", "MPC LCT key strip ME1/1", 161, -0.5, 160.5);
879 
880  bookedLCTMPCHistos = true;
881  if (debug) LogTrace("CSCTriggerPrimitivesReader")
882  <<"bookedLCTMPCHistos ";
883  std::cout <<" bookedLCTMPCHistos " << std::endl;
884 
885 }
886 
888  string s;
889 
890 
891 
893  // hAlctCompMatch;
894 
895  hAlctCompFound = fs->make<TH1F>("h_ALCT_found","h_ALCT_found",600,0.5,600.5);
896  hAlctCompFound2 = fs->make<TH2F>("h_ALCT_found2","h_ALCT_found2",19,-9.5,9.5,36,0.5,36.5);
897  hAlctCompFound2x = fs->make<TH2F>("h_ALCT_found2x","h_ALCT_found2x",19,-9.5,9.5,18,0.5,36.5);
898 
899 
900  hAlctCompSameN = fs->make<TH1F>("h_ALCT_SameN","h_ALCT_SameN",600,0.5,600.5);
901  hAlctCompSameN2 = fs->make<TH2F>("h_ALCT_SameN2","h_ALCT_SameN2",19,-9.5,9.5,36,0.5,36.5);
902  hAlctCompSameN2x = fs->make<TH2F>("h_ALCT_SameN2x","h_ALCT_SameN2x",19,-9.5,9.5,18,0.5,36.5);
903 
904 
905  hAlctCompMatch = fs->make<TH1F>("h_ALCT_match","h_ALCT_match",600,0.5,600.5);
906  hAlctCompMatch2 = fs->make<TH2F>("h_ALCT_match2","h_ALCT_match2",19,-9.5,9.5,36,0.5,36.5);
907  hAlctCompMatch2x = fs->make<TH2F>("h_ALCT_match2x","h_ALCT_match2x",19,-9.5,9.5,18,0.5,36.5);
908 
909  hAlctCompTotal = fs->make<TH1F>("h_ALCT_total","h_ALCT_total",600,0.5,600.5);
910  hAlctCompTotal2 = fs->make<TH2F>("h_ALCT_total2","h_ALCT_total2",19,-9.5,9.5,36,0.5,36.5);
911  hAlctCompTotal2x = fs->make<TH2F>("h_ALCT_total2x","h_ALCT_total2x",19,-9.5,9.5,18,0.5,36.5);
912 
913  hClctCompFound = fs->make<TH1F>("h_CLCT_found","h_CLCT_found",600,0.5,600.5);
914  hClctCompFound2 = fs->make<TH2F>("h_CLCT_found2","h_CLCT_found2",19,-9.5,9.5,36,0.5,36.5);
915  hClctCompFound2x = fs->make<TH2F>("h_CLCT_found2x","h_CLCT_found2x",19,-9.5,9.5,18,0.5,36.5);
916 
917  hClctCompSameN = fs->make<TH1F>("h_CLCT_SameN","h_CLCT_SameN",600,0.5,600.5);
918  hClctCompSameN2 = fs->make<TH2F>("h_CLCT_SameN2","h_CLCT_SameN2",19,-9.5,9.5,36,0.5,36.5);
919  hClctCompSameN2x = fs->make<TH2F>("h_CLCT_SameN2x","h_CLCT_SameN2x",19,-9.5,9.5,18,0.5,36.5);
920 
921  hClctCompMatch = fs->make<TH1F>("h_CLCT_match","h_CLCT_match",600,0.5,600.5);
922  hClctCompMatch2 = fs->make<TH2F>("h_CLCT_match2","h_CLCT_match2",19,-9.5,9.5,36,0.5,36.5);
923  hClctCompMatch2x = fs->make<TH2F>("h_CLCT_match2x","h_CLCT_match2x",19,-9.5,9.5,18,0.5,36.5);
924 
925  hClctCompTotal = fs->make<TH1F>("h_CLCT_total","h_CLCT_total",600,0.5,600.5);
926  hClctCompTotal2 = fs->make<TH2F>("h_CLCT_total2","h_CLCT_total2",19,-9.5,9.5,36,0.5,36.5);
927  hClctCompTotal2x = fs->make<TH2F>("h_CLCT_total2x","h_CLCT_total2x",19,-9.5,9.5,18,0.5,36.5);
928 
929  hLCTCompFound = fs->make<TH1F>("h_LCT_found","h_LCT_found",600,0.5,600.5);
930  hLCTCompFound2 = fs->make<TH2F>("h_LCT_found2","h_LCT_found2",19,-9.5,9.5,36,0.5,36.5);
931  hLCTCompFound2x = fs->make<TH2F>("h_LCT_found2x","h_LCT_found2x",19,-9.5,9.5,18,0.5,36.5);
932 
933  hLCTCompSameN = fs->make<TH1F>("h_LCT_SameN","h_LCT_SameN",600,0.5,600.5);
934  hLCTCompSameN2 = fs->make<TH2F>("h_LCT_SameN2","h_LCT_SameN2",19,-9.5,9.5,36,0.5,36.5);
935  hLCTCompSameN2x = fs->make<TH2F>("h_LCT_SameN2x","h_LCT_SameN2x",19,-9.5,9.5,18,0.5,36.5);
936 
937  hLCTCompMatch = fs->make<TH1F>("h_LCT_match","h_LCT_match",600,0.5,600.5);
938  hLCTCompMatch2 = fs->make<TH2F>("h_LCT_match2","h_LCT_match2",19,-9.5,9.5,36,0.5,36.5);
939  hLCTCompMatch2x = fs->make<TH2F>("h_LCT_match2x","h_LCT_match2x",19,-9.5,9.5,18,0.5,36.5);
940 
941  hLCTCompTotal = fs->make<TH1F>("h_LCT_total","h_LCT_total",600,0.5,600.5);
942  hLCTCompTotal2 = fs->make<TH2F>("h_LCT_total2","h_LCT_total2",19,-9.5,9.5,36,0.5,36.5);
943  hLCTCompTotal2x = fs->make<TH2F>("h_LCT_total2x","h_LCT_total2x",19,-9.5,9.5,18,0.5,36.5);
944 
945  //Chad's improved historgrams
946  hAlctCompFound2i = fs->make<TH2F>("h_ALCT_found2i","h_ALCT_found2i",18,0,18,36,0.5,36.5);
947  hAlctCompSameN2i = fs->make<TH2F>("h_ALCT_SameN2i","h_ALCT_SameN2i",18,0,18,36,0.5,36.5);
948  hAlctCompMatch2i = fs->make<TH2F>("h_ALCT_match2i","h_ALCT_match2i",18,0,18,36,0.5,36.5);
949  hAlctCompTotal2i = fs->make<TH2F>("h_ALCT_total2i","h_ALCT_total2i",18,0,18,36,0.5,36.5);
950  hClctCompFound2i = fs->make<TH2F>("h_CLCT_found2i","h_CLCT_found2i",18,0,18,36,0.5,36.5);
951  hClctCompSameN2i = fs->make<TH2F>("h_CLCT_SameN2i","h_CLCT_SameN2i",18,0,18,36,0.5,36.5);
952  hClctCompMatch2i = fs->make<TH2F>("h_CLCT_match2i","h_CLCT_match2i",18,0,18,36,0.5,36.5);
953  hClctCompTotal2i = fs->make<TH2F>("h_CLCT_total2i","h_CLCT_total2i",18,0,18,36,0.5,36.5);
954  hLCTCompFound2i = fs->make<TH2F>("h_LCT_found2i","h_LCT_found2i",18,0,18,36,0.5,36.5);
955  hLCTCompSameN2i = fs->make<TH2F>("h_LCT_SameN2i","h_LCT_SameN2i",18,0,18,36,0.5,36.5);
956  hLCTCompMatch2i = fs->make<TH2F>("h_LCT_match2i","h_LCT_match2i",18,0,18,36,0.5,36.5);
957  hLCTCompTotal2i = fs->make<TH2F>("h_LCT_total2i","h_LCT_total2i",18,0,18,36,0.5,36.5);
958 
959  // hAlctCompFound = fs->make<TH1F>("h_ALCT_found","h_ALCT_found",600,0.5,600.5);
960 
961  // ALCTs.
962  for (int i = 0; i < MAX_ENDCAPS; i++) { // endcaps
963  for (int j = 0; j < CSC_TYPES; j++) { // station/ring
964  char asdf[256];
965 
966  float csc_max = NCHAMBERS[j] + 0.5;
967  if (i == 0) s = "Comp_ALCTs, " + csc_type_plus[j];
968  else s = "Comp_ALCTs, " + csc_type_minus[j];
969  sprintf(asdf,"Comp_ALCTsFound_%i",i*CSC_TYPES+j);
970  hAlctCompFoundCsc[i][j] =
971  fs->make<TH1F>(asdf, s.c_str(), NCHAMBERS[j], 0.5, csc_max);
972  sprintf(asdf,"Comp_ALCTsSame_%i",i*CSC_TYPES+j);
973  hAlctCompSameNCsc[i][j] =
974  fs->make<TH1F>(asdf, s.c_str(), NCHAMBERS[j], 0.5, csc_max);
975  sprintf(asdf,"Comp_ALCTsTotal_%i",i*CSC_TYPES+j);
976  hAlctCompTotalCsc[i][j] =
977  fs->make<TH1F>(asdf, s.c_str(), NCHAMBERS[j], 0.5, csc_max);
978  sprintf(asdf,"Comp_ALCTsMatch_%i",i*CSC_TYPES+j);
979  hAlctCompMatchCsc[i][j] =
980  fs->make<TH1F>(asdf, s.c_str(), NCHAMBERS[j], 0.5, csc_max);
981  hAlctCompFoundCsc[i][j]->Sumw2();
982  hAlctCompSameNCsc[i][j]->Sumw2();
983  hAlctCompTotalCsc[i][j]->Sumw2();
984  hAlctCompMatchCsc[i][j]->Sumw2();
985  }
986  }
987 
988  // CLCTs.
989  for (int i = 0; i < MAX_ENDCAPS; i++) { // endcaps
990  for (int j = 0; j < CSC_TYPES; j++) { // station/ring
991  float csc_max = NCHAMBERS[j] + 0.5;
992  char asdf[256];
993  if (i == 0) s = "Comp_CLCTs, " + csc_type_plus[j];
994  else s = "Comp_CLCTs, " + csc_type_minus[j];
995  sprintf(asdf,"Comp_CLCTsFound_%i",i*CSC_TYPES+j);
996  hClctCompFoundCsc[i][j] =
997  fs->make<TH1F>(asdf, s.c_str(), NCHAMBERS[j], 0.5, csc_max);
998  sprintf(asdf,"Comp_CLCTsSame_%i",i*CSC_TYPES+j);
999  hClctCompSameNCsc[i][j] =
1000  fs->make<TH1F>(asdf, s.c_str(), NCHAMBERS[j], 0.5, csc_max);
1001  sprintf(asdf,"Comp_CLCTsTotal_%i",i*CSC_TYPES+j);
1002  hClctCompTotalCsc[i][j] =
1003  fs->make<TH1F>(asdf, s.c_str(), NCHAMBERS[j], 0.5, csc_max);
1004  sprintf(asdf,"Comp_CLCTsMatch_%i",i*CSC_TYPES+j);
1005  hClctCompMatchCsc[i][j] =
1006  fs->make<TH1F>(asdf, s.c_str(), NCHAMBERS[j], 0.5, csc_max);
1007  hClctCompFoundCsc[i][j]->Sumw2();
1008  hClctCompSameNCsc[i][j]->Sumw2();
1009  hClctCompTotalCsc[i][j]->Sumw2();
1010  hClctCompMatchCsc[i][j]->Sumw2();
1011  }
1012  }
1013 
1014  // Correlated LCTs.
1015  for (int i = 0; i < MAX_ENDCAPS; i++) { // endcaps
1016  for (int j = 0; j < CSC_TYPES; j++) { // station/ring
1017  float csc_max = NCHAMBERS[j] + 0.5;
1018  char asdf[256];
1019  if (i == 0) s = "LCTs, " + csc_type_plus[j];
1020  else s = "LCTs, " + csc_type_minus[j];
1021  sprintf(asdf,"LCTs_CompFound_%i",i*CSC_TYPES+j);
1022  hLctCompFoundCsc[i][j] =
1023  fs->make<TH1F>(asdf, s.c_str(), NCHAMBERS[j], 0.5, csc_max);
1024  sprintf(asdf,"LCTs_CompSame_%i",i*CSC_TYPES+j);
1025  hLctCompSameNCsc[i][j] =
1026  fs->make<TH1F>(asdf, s.c_str(), NCHAMBERS[j], 0.5, csc_max);
1027  sprintf(asdf,"LCTs_CompTotal_%i",i*CSC_TYPES+j);
1028  hLctCompTotalCsc[i][j] =
1029  fs->make<TH1F>(asdf, s.c_str(), NCHAMBERS[j], 0.5, csc_max);
1030  sprintf(asdf,"LCTs_CompMatch_%i",i*CSC_TYPES+j);
1031  hLctCompMatchCsc[i][j] =
1032  fs->make<TH1F>(asdf, s.c_str(), NCHAMBERS[j], 0.5, csc_max);
1033  hLctCompFoundCsc[i][j]->Sumw2();
1034  hLctCompSameNCsc[i][j]->Sumw2();
1035  hLctCompTotalCsc[i][j]->Sumw2();
1036  hLctCompMatchCsc[i][j]->Sumw2();
1037  }
1038  }
1039 
1040  bookedCompHistos = true;
1041  if (debug) LogTrace("CSCTriggerPrimitivesReader")
1042  <<"bookedCompHistos ";
1043  std::cout <<"bookCompHistos "<< std::endl;
1044 }
1045 
1048 
1049  // Limits for resolution histograms
1050  const double EDMIN = -0.05; // eta min
1051  const double EDMAX = 0.05; // eta max
1052  const double PDMIN = -5.0; // phi min (mrad)
1053  const double PDMAX = 5.0; // phi max (mrad)
1054 
1055  hResolDeltaWG = fs->make<TH1F>("", "Delta key wiregroup", 10, -5., 5.);
1056 
1057  hResolDeltaHS = fs->make<TH1F>("", "Delta key halfstrip", 10, -5., 5.);
1058  hResolDeltaDS = fs->make<TH1F>("", "Delta key distrip", 10, -5., 5.);
1059 
1060  hResolDeltaEta = fs->make<TH1F>("", "#eta_rec-#eta_sim", 100, EDMIN, EDMAX);
1061  hResolDeltaPhi = fs->make<TH1F>("", "#phi_rec-#phi_sim (mrad)", 100, -10., 10.);
1062  hResolDeltaPhiHS = fs->make<TH1F>("", "#phi_rec-#phi_sim (mrad), halfstrips", 100, -10., 10.);
1063  hResolDeltaPhiDS = fs->make<TH1F>("", "#phi_rec-#phi_sim (mrad), distrips", 100, -10., 10.);
1064 
1065  hEtaRecVsSim = fs->make<TH2F>("", "#eta_rec vs #eta_sim", 64, 0.9, 2.5, 64, 0.9, 2.5);
1066  hPhiRecVsSim = fs->make<TH2F>("", "#phi_rec vs #phi_sim", 100, 0., TWOPI, 100, 0., TWOPI);
1067 
1068  // LCT quantities per station
1069  char histname[60];
1070  for (int i = 0; i < MAX_STATIONS; i++) {
1071  sprintf(histname, "ALCTs vs eta, station %d", i+1);
1072  hAlctVsEta[i] = fs->make<TH1F>("", histname, 66, 0.875, 2.525);
1073 
1074  sprintf(histname, "CLCTs vs phi, station %d", i+1);
1075  hClctVsPhi[i] = fs->make<TH1F>("", histname, 100, 0., TWOPI);
1076 
1077  sprintf(histname, "#LT#eta_rec-#eta_sim#GT, station %d", i+1);
1078  hEtaDiffVsEta[i] = fs->make<TH1F>("", histname, 66, 0.875, 2.525);
1079 
1080  sprintf(histname, "#LT#phi_rec-#phi_sim#GT, station %d", i+1);
1081  hPhiDiffVsPhi[i] = fs->make<TH1F>("", histname, 100, 0., TWOPI);
1082  }
1083 
1084  for (int i = 0; i < CSC_TYPES; i++) {
1085  string t0 = "#eta_rec-#eta_sim, " + csc_type[i];
1086  hEtaDiffCsc[i][0] = fs->make<TH1F>("", t0.c_str(), 100, EDMIN, EDMAX);
1087  string t1 = t0 + ", endcap1";
1088  hEtaDiffCsc[i][1] = fs->make<TH1F>("", t1.c_str(), 100, EDMIN, EDMAX);
1089  string t2 = t0 + ", endcap2";
1090  hEtaDiffCsc[i][2] = fs->make<TH1F>("", t2.c_str(), 100, EDMIN, EDMAX);
1091 
1092  string t4 = "#eta_rec-#eta_sim vs wiregroup, " + csc_type[i];
1093  hEtaDiffVsWireCsc[i] =
1094  fs->make<TH2F>("", t4.c_str(), MAX_WG[i], 0., MAX_WG[i], 100, EDMIN, EDMAX);
1095 
1096  string u0 = "#phi_rec-#phi_sim, " + csc_type[i];
1097  hPhiDiffCsc[i][0] = fs->make<TH1F>("", u0.c_str(), 100, PDMIN, PDMAX);
1098  string u1 = u0 + ", endcap1";
1099  hPhiDiffCsc[i][1] = fs->make<TH1F>("", u1.c_str(), 100, PDMIN, PDMAX);
1100  string u2 = u0 + ", endcap2";
1101  hPhiDiffCsc[i][2] = fs->make<TH1F>("", u2.c_str(), 100, PDMIN, PDMAX);
1102  hPhiDiffCsc[i][3] = fs->make<TH1F>("", u0.c_str(), 100, PDMIN, PDMAX);
1103  hPhiDiffCsc[i][4] = fs->make<TH1F>("", u0.c_str(), 100, PDMIN, PDMAX);
1104 
1105  int MAX_DS = MAX_HS[i]/4;
1106  string u5 = "#phi_rec-#phi_sim (mrad) vs distrip, " + csc_type[i];
1107  hPhiDiffVsStripCsc[i][0] =
1108  fs->make<TH2F>("", u5.c_str(), MAX_DS, 0., MAX_DS, 100, PDMIN, PDMAX);
1109  string u6 = "#phi_rec-#phi_sim (mrad) vs halfstrip, " + csc_type[i];
1110  hPhiDiffVsStripCsc[i][1] =
1111  fs->make<TH2F>("", u6.c_str(), MAX_HS[i], 0., MAX_HS[i], 100, PDMIN, PDMAX);
1112 
1113  string u7 = "#phi(layer 1)-#phi(layer 6), mrad, " + csc_type[i];
1114  hTrueBendCsc[i] =fs->make<TH1F>("", u7.c_str(), 100, -10., 10.);
1115  }
1116 
1117  int max_patterns, phibend;
1118  max_patterns = CSCConstants::NUM_CLCT_PATTERNS;
1119  for (int i = 0; i < max_patterns; i++) {
1120  phibend = ptype_TMB07[i];
1121  sprintf(histname, "#phi_rec-#phi_sim, bend = %d", phibend);
1122  hPhiDiffPattern[i] = fs->make<TH1F>("", histname, 100, PDMIN, PDMAX);
1123  }
1124 
1125  bookedResolHistos = true;
1126  if (debug) LogTrace("CSCTriggerPrimitivesReader")
1127  <<"bookedResolHistos ";
1128 }
1129 
1132 
1133  // Efficiencies per station.
1134  char histname[60];
1135  for (int i = 0; i < MAX_STATIONS; i++) {
1136  sprintf(histname, "SimHits vs eta, station %d", i+1);
1137  hEfficHitsEta[i] = fs->make<TH1F>("", histname, 66, 0.875, 2.525);
1138 
1139  sprintf(histname, "ALCTs vs eta, station %d", i+1);
1140  hEfficALCTEta[i] = fs->make<TH1F>("", histname, 66, 0.875, 2.525);
1141 
1142  sprintf(histname, "CLCTs vs eta, station %d", i+1);
1143  hEfficCLCTEta[i] = fs->make<TH1F>("", histname, 66, 0.875, 2.525);
1144  }
1145 
1146  // Efficiencies per chamber type.
1147  for (int i = 0; i < CSC_TYPES; i++) {
1148  string t0 = "SimHits vs eta, " + csc_type[i];
1149  hEfficHitsEtaCsc[i] = fs->make<TH1F>("", t0.c_str(), 66, 0.875, 2.525);
1150  string t1 = "ALCTs vs eta, " + csc_type[i];
1151  hEfficALCTEtaCsc[i] = fs->make<TH1F>("", t1.c_str(), 66, 0.875, 2.525);
1152  string t2 = "CLCTs vs eta, " + csc_type[i];
1153  hEfficCLCTEtaCsc[i] = fs->make<TH1F>("", t1.c_str(), 66, 0.875, 2.525);
1154  }
1155 
1156  bookedEfficHistos = true;
1157  if (debug) LogTrace("CSCTriggerPrimitivesReader")
1158  <<"bookedEfficHistos ";
1159  std::cout <<" bookedEfficHistos " << std::endl;
1160 }
1161 
1163  // Book histos when called for the first time.
1165 
1166  int nValidALCTs = 0;
1167  for (auto detUnitIt = alcts->begin(); detUnitIt != alcts->end(); detUnitIt++) {
1168  int nValidALCTsPerCSC = 0;
1169  const CSCDetId& id = (*detUnitIt).first;
1170  if (checkBadChambers_ && badChambers_->isInBadChamber(id)) continue;
1171  const auto& range = (*detUnitIt).second;
1172  for (auto digiIt = range.first;
1173  digiIt != range.second; digiIt++) {
1174 
1175  bool alct_valid = (*digiIt).isValid();
1176  hAlctValid->Fill(alct_valid);
1177  if (alct_valid) {
1178  hAlctQuality->Fill((*digiIt).getQuality());
1179  hAlctAccel->Fill((*digiIt).getAccelerator());
1180  hAlctCollis->Fill((*digiIt).getCollisionB());
1181  hAlctKeyGroup->Fill((*digiIt).getKeyWG());
1182  hAlctBXN->Fill((*digiIt).getBX());
1183 
1184  int csctype = getCSCType(id);
1185  hAlctPerCSC->Fill(csctype);
1186  hAlctCsc[id.endcap()-1][csctype]->Fill(id.chamber());
1187 
1188  if (csctype==0) hAlctKeyGroupME11->Fill((*digiIt).getKeyWG());
1189 
1190  nValidALCTs++;
1191  nValidALCTsPerCSC++;
1192 
1193  if (debug) LogTrace("CSCTriggerPrimitivesReader")
1194  << (*digiIt) << " found in ME" << ((id.endcap() == 1) ? "+" : "-")
1195  << id.station() << "/" << id.ring() << "/" << id.chamber()
1196  << " (sector " << id.triggerSector()
1197  << " trig id. " << id.triggerCscId() << ")";
1198  //cout << "raw id = " << id.rawId() << endl;
1199  }
1200  }
1201  hAlctPerChamber->Fill(nValidALCTsPerCSC);
1202  }
1203  hAlctPerEvent->Fill(nValidALCTs);
1204  if (debug) LogTrace("CSCTriggerPrimitivesReader")
1205  << nValidALCTs << " valid ALCTs found in this event";
1206  numALCT += nValidALCTs;
1207 }
1208 
1210  // Book histos when called for the first time.
1212 
1213  int nValidCLCTs = 0;
1214  for (auto detUnitIt = clcts->begin(); detUnitIt != clcts->end(); detUnitIt++) {
1215  int nValidCLCTsPerCSC = 0;
1216  const CSCDetId& id = (*detUnitIt).first;
1217  if (checkBadChambers_ && badChambers_->isInBadChamber(id)) continue;
1218  const auto& range = (*detUnitIt).second;
1219  for (auto digiIt = range.first;
1220  digiIt != range.second; digiIt++) {
1221 
1222  bool clct_valid = (*digiIt).isValid();
1223  hClctValid->Fill(clct_valid);
1224  if (clct_valid) {
1225  int striptype = (*digiIt).getStripType();
1226  int keystrip = (*digiIt).getKeyStrip(); // halfstrip #
1227  if (striptype == 0) keystrip /= 4; // distrip # for distrip ptns
1228  hClctQuality->Fill((*digiIt).getQuality());
1229  hClctStripType->Fill(striptype);
1230  hClctSign->Fill((*digiIt).getBend());
1231  hClctCFEB->Fill((*digiIt).getCFEB());
1232  hClctBXN->Fill((*digiIt).getBX());
1233  hClctKeyStrip[striptype]->Fill(keystrip);
1234  hClctPattern[striptype]->Fill((*digiIt).getPattern());
1235 
1236  int csctype = getCSCType(id);
1237  hClctPerCSC->Fill(csctype);
1238  hClctCsc[id.endcap()-1][csctype]->Fill(id.chamber());
1239 
1240  if (striptype==1 && csctype==0) hClctKeyStripME11->Fill(keystrip);
1241 
1242  int phibend;
1243  int pattern = (*digiIt).getPattern();
1244  phibend = ptype_TMB07[pattern];
1245  hClctBendCsc[csctype][striptype]->Fill(abs(phibend));
1246 
1247  if (striptype == 0) // distrips
1248  hClctKeyStripCsc[csctype]->Fill(keystrip);
1249 
1250  nValidCLCTs++;
1251  nValidCLCTsPerCSC++;
1252 
1253  if (debug) LogTrace("CSCTriggerPrimitivesReader")
1254  << (*digiIt) << " found in ME" << ((id.endcap() == 1) ? "+" : "-")
1255  << id.station() << "/" << id.ring() << "/" << id.chamber()
1256  << " (sector " << id.triggerSector()
1257  << " trig id. " << id.triggerCscId() << ")";
1258  }
1259  }
1260  hClctPerChamber->Fill(nValidCLCTsPerCSC);
1261  }
1262  hClctPerEvent->Fill(nValidCLCTs);
1263  if (debug) LogTrace("CSCTriggerPrimitivesReader")
1264  << nValidCLCTs << " valid CLCTs found in this event";
1265  numCLCT += nValidCLCTs;
1266 }
1267 
1269  // Book histos when called for the first time.
1271 
1272  int nValidLCTs = 0;
1273  bool alct_valid, clct_valid;
1274 
1275  for (auto detUnitIt = lcts->begin(); detUnitIt != lcts->end(); detUnitIt++) {
1276  int nValidLCTsPerCSC = 0;
1277  const CSCDetId& id = (*detUnitIt).first;
1278  if (checkBadChambers_ && badChambers_->isInBadChamber(id)) continue;
1279  const auto& range = (*detUnitIt).second;
1280  for (auto digiIt = range.first;
1281  digiIt != range.second; digiIt++) {
1282 
1283  bool lct_valid = (*digiIt).isValid();
1284  hLctTMBValid->Fill(lct_valid);
1285  if (lct_valid) {
1286  hLctTMBEndcap->Fill(id.endcap());
1287  hLctTMBStation->Fill(id.station());
1288  hLctTMBSector->Fill(id.triggerSector());
1289  hLctTMBRing->Fill(id.ring());
1290  hLctTMBChamber[id.station()-1]->Fill(id.triggerCscId());
1291 
1292  int quality = (*digiIt).getQuality();
1293  hLctTMBQuality->Fill(quality);
1294  hLctTMBBXN->Fill((*digiIt).getBX());
1295 
1296  alct_valid = (quality != 0 && quality != 2);
1297  if (alct_valid) {
1298  hLctTMBKeyGroup->Fill((*digiIt).getKeyWG());
1299  }
1300 
1301  clct_valid = (quality != 0 && quality != 1);
1302  if (clct_valid) {
1303  hLctTMBKeyStrip->Fill((*digiIt).getStrip());
1304  hLctTMBStripType->Fill(1.);
1305  hLctTMBPattern->Fill((*digiIt).getPattern());
1306  hLctTMBBend->Fill((*digiIt).getBend());
1307  }
1308 
1309  int csctype = getCSCType(id);
1310  hLctTMBPerCSC->Fill(csctype);
1311  hLctTMBCsc[id.endcap()-1][csctype]->Fill(id.chamber());
1312  // Truly correlated LCTs; for DAQ
1313  if (alct_valid && clct_valid) hCorrLctTMBPerCSC->Fill(csctype);
1314 
1315  if (alct_valid && csctype==0) {
1316  hLctTMBKeyGroupME11->Fill((*digiIt).getKeyWG());
1317  }
1318  if (clct_valid && csctype==0) {
1319  hLctTMBKeyStripME11->Fill((*digiIt).getStrip());
1320  }
1321 
1322  nValidLCTs++;
1323  nValidLCTsPerCSC++;
1324 
1325  if (debug) LogTrace("CSCTriggerPrimitivesReader")
1326  << (*digiIt) << " found in ME" << ((id.endcap() == 1) ? "+" : "-")
1327  << id.station() << "/" << id.ring() << "/" << id.chamber()
1328  << " (sector " << id.triggerSector()
1329  << " trig id. " << id.triggerCscId() << ")";
1330  }
1331  }
1332  hLctTMBPerChamber->Fill(nValidLCTsPerCSC);
1333  }
1334  hLctTMBPerEvent->Fill(nValidLCTs);
1335  if (debug) LogTrace("CSCTriggerPrimitivesReader")
1336  << nValidLCTs << " valid LCTs found in this event";
1337  numLCTTMB += nValidLCTs;
1338 }
1339 
1341  // Book histos when called for the first time.
1343 
1344  int nValidLCTs = 0;
1345  bool alct_valid, clct_valid;
1346 
1347  for (auto detUnitIt = lcts->begin(); detUnitIt != lcts->end(); detUnitIt++) {
1348  const CSCDetId& id = (*detUnitIt).first;
1349  if (checkBadChambers_ && badChambers_->isInBadChamber(id)) continue;
1350  const auto& range = (*detUnitIt).second;
1351  for (auto digiIt = range.first;
1352  digiIt != range.second; digiIt++) {
1353 
1354  bool lct_valid = (*digiIt).isValid();
1355  hLctMPCValid->Fill(lct_valid);
1356  if (lct_valid) {
1357  hLctMPCEndcap->Fill(id.endcap());
1358  hLctMPCStation->Fill(id.station());
1359  hLctMPCSector->Fill(id.triggerSector());
1360  hLctMPCRing->Fill(id.ring());
1361  hLctMPCChamber[id.station()-1]->Fill(id.triggerCscId());
1362 
1363  int quality = (*digiIt).getQuality();
1364  hLctMPCQuality->Fill(quality);
1365  hLctMPCBXN->Fill((*digiIt).getBX());
1366 
1367  alct_valid = (quality != 0 && quality != 2);
1368  if (alct_valid) {
1369  hLctMPCKeyGroup->Fill((*digiIt).getKeyWG());
1370  }
1371 
1372  clct_valid = (quality != 0 && quality != 1);
1373  if (clct_valid) {
1374  hLctMPCKeyStrip->Fill((*digiIt).getStrip());
1375  hLctMPCStripType->Fill(1.);
1376  hLctMPCPattern->Fill((*digiIt).getPattern());
1377  hLctMPCBend->Fill((*digiIt).getBend());
1378  }
1379 
1380  int csctype = getCSCType(id);
1381  hLctMPCPerCSC->Fill(csctype);
1382  // Truly correlated LCTs; for DAQ
1383  if (alct_valid && clct_valid) hCorrLctMPCPerCSC->Fill(csctype);
1384 
1385 
1386  if (alct_valid && csctype==0) {
1387  hLctMPCKeyGroupME11->Fill((*digiIt).getKeyWG());
1388  }
1389  if (clct_valid && csctype==0) {
1390  hLctMPCKeyStripME11->Fill((*digiIt).getStrip());
1391  }
1392 
1393  nValidLCTs++;
1394 
1395  if (debug) LogTrace("CSCTriggerPrimitivesReader")
1396  << "MPC "
1397  << (*digiIt) << " found in ME" << ((id.endcap() == 1) ? "+" : "-")
1398  << id.station() << "/" << id.ring() << "/" << id.chamber()
1399  << " (sector " << id.triggerSector()
1400  << " trig id. " << id.triggerCscId() << ")";
1401  }
1402  }
1403  }
1404  hLctMPCPerEvent->Fill(nValidLCTs);
1405  if (debug) LogTrace("CSCTriggerPrimitivesReader")
1406  << nValidLCTs << " MPC LCTs found in this event";
1407  numLCTMPC += nValidLCTs;
1408 }
1409 
1411  const CSCALCTDigiCollection* alcts_emul,
1412  const CSCCLCTDigiCollection* clcts_data,
1413  const CSCCLCTDigiCollection* clcts_emul,
1414  const CSCCLCTPreTriggerDigiCollection* pretrigs_emul,
1415  const CSCCorrelatedLCTDigiCollection* lcts_data,
1416  const CSCCorrelatedLCTDigiCollection* lcts_emul){
1417 
1418  // Book histos when called for the first time.
1420 
1421  // Comparisons
1422  compareALCTs(alcts_data, alcts_emul);
1423  compareCLCTs(clcts_data, clcts_emul, pretrigs_emul);
1424  compareLCTs(lcts_data, lcts_emul, alcts_data, clcts_data);
1425  //compareMPCLCTs(mpclcts_data, mpclcts_emul, alcts_data, clcts_data);
1426 }
1427 
1429  const CSCALCTDigiCollection* alcts_emul) {
1430  int emul_corr_bx;
1431 
1432  // Should be taken from config. parameters.
1433  int fifo_pretrig = 10;
1434  int fpga_latency = 6;
1435  int l1a_window_width = 7;
1436  // Time offset of raw hits w.r.t. the full 12-bit BXN.
1437  int rawhit_tbin_offset =
1438  (fifo_pretrig - fpga_latency) + (l1a_window_width-1)/2;
1439  // Extra difference due to additional register stages; determined
1440  // empirically.
1441  int register_delay = 2;
1442  // Loop over all chambers in search for ALCTs.
1443  std::vector<CSCALCTDigi>::const_iterator pd, pe;
1444  for (int endc = 1; endc <= 2; endc++) {
1445  for (int stat = 1; stat <= 4; stat++) {
1446  for (int ring = 1; ring <= maxRing(stat); ring++) {
1447  for (int cham = 1; cham <= 36; cham++) {
1448  // Calculate DetId. 0th layer means whole chamber.
1449  CSCDetId detid(endc, stat, ring, cham, 0);
1450 
1451  // Skip chambers marked as bad.
1452  if (checkBadChambers_ && badChambers_->isInBadChamber(detid)) continue;
1453  std::vector<CSCALCTDigi> alctV_data, alctV_emul;
1454  const auto& drange = alcts_data->get(detid);
1455  for (auto digiIt = drange.first; digiIt != drange.second; digiIt++) {
1456  if ((*digiIt).isValid()) {
1457  alctV_data.push_back(*digiIt);
1458  }
1459  }
1460 
1461  const auto& erange = alcts_emul->get(detid);
1462  std::vector<bool> bookedalctV_emul;
1463  for (auto digiIt = erange.first; digiIt != erange.second; digiIt++) {
1464  if ((*digiIt).isValid()) {
1465  alctV_emul.push_back(*digiIt);
1466  bookedalctV_emul.push_back(false);
1467  }
1468  }
1469 
1470  int ndata = alctV_data.size();
1471  int nemul = alctV_emul.size();
1472 
1473  if (ndata == 0 && nemul == 0) continue;
1474  bool firstfill = true;
1475 
1476  if (debug or (stat == 1 and ring== 1 and (ndata != nemul)) ) {
1477  ostringstream strstrm;
1478  strstrm << "\n--- ME" << ((detid.endcap() == 1) ? "+" : "-")
1479  << detid.station() << "/" << detid.ring() << "/"
1480  << detid.chamber()
1481  << " (sector " << detid.triggerSector()
1482  << " trig id. " << detid.triggerCscId() << "):\n";
1483  strstrm << " **** " << ndata << " valid data ALCTs found:\n";
1484  for (pd = alctV_data.begin(); pd != alctV_data.end(); pd++) {
1485  strstrm << " " << (*pd)
1486  << " Full BX = " << (*pd).getFullBX() << "\n";
1487  }
1488  strstrm << " **** " << nemul << " valid emul ALCTs found:\n";
1489  for (pe = alctV_emul.begin(); pe != alctV_emul.end(); pe++) {
1490  strstrm << " " << (*pe);
1491  for (pd = alctV_data.begin(); pd != alctV_data.end(); pd++) {
1492  if ((*pd).getTrknmb() == (*pe).getTrknmb()) {
1493  int emul_bx = (*pe).getBX();
1494  emul_corr_bx =
1495  emul_bx - rawhit_tbin_offset + register_delay;
1496  strstrm << " Corr BX = " << emul_corr_bx;
1497  break;
1498  }
1499  }
1500  strstrm << "\n";
1501  }
1502  LogTrace("CSCTriggerPrimitivesReader") << strstrm.str();
1503  //if (stat==1 && ring==1)
1504  // std::cout <<"ME11 CompareALCTs "<< strstrm.str()<< std::endl;
1505  }
1506 
1507  //Data, add HS quality later
1508  int perEv_nStub_data = 0;
1509  int perEv_nStub_emul = 0;
1510  perStub[0].init(RUN_, Event_);
1511  perStub[1].init(RUN_, Event_);
1512  for (pd = alctV_data.begin(); pd != alctV_data.end(); pd++){
1513  perEv_nStub_data++;
1514  }
1515  perStub[0].t_endcap = endc;
1516  perStub[0].t_station = stat;
1517  perStub[0].t_chamber = cham;
1518  perStub[0].t_ring = ring;
1520  perStub[0].t_nStubs = ndata;
1521  perStub[0].t_nStubs_readout = ndata;
1522  event_tree[0]->Fill();
1523  //Emul
1524  for (pe = alctV_emul.begin(); pe != alctV_emul.end(); pe++){
1525  perEv_nStub_emul++;
1526  }
1527  perStub[1].t_endcap = endc;
1528  perStub[1].t_station = stat;
1529  perStub[1].t_chamber = cham;
1530  perStub[1].t_ring = ring;
1532  perStub[1].t_nStubs = nemul;
1533  perStub[1].t_nStubs_readout = nemul;
1534  event_tree[1]->Fill();
1535 
1536  int csctype = getCSCType(detid);
1537  hAlctCompFoundCsc[endc-1][csctype]->Fill(cham);
1538  int mychamber = chamberSerial(detid);
1539  hAlctCompFound->Fill(mychamber);
1540  int ix = chamberIX(detid);
1541  int ix2 = chamberIXi(detid);
1542  // printf("station %i, ring %i, chamber %i, ix+(detid.ring()-1) %i\n",
1543  // detid.station(),detid.ring(),detid.chamber(),ix);
1544  if(detid.station()>1 && detid.ring()==1) {
1545  hAlctCompFound2x->Fill(ix,detid.chamber()*2);
1546  }
1547  else {
1548  hAlctCompFound2->Fill(ix,detid.chamber());
1549  }
1550  hAlctCompFound2i->Fill(ix2,detid.chamber());
1551 
1552  if (ndata != nemul) {
1553  LogTrace("CSCTriggerPrimitivesReader")
1554  << " +++ Different numbers of ALCTs found in ME"
1555  << ((endc == 1) ? "+" : "-") << stat << "/"
1556  << ring << "/" << cham
1557  << ": data = " << ndata << " emulator = " << nemul << " +++\n";
1558  }
1559  else {
1560  hAlctCompSameNCsc[endc-1][csctype]->Fill(cham);
1561  if(detid.station()>1 && detid.ring()==1) {
1562  hAlctCompSameN2x->Fill(ix,detid.chamber()*2);
1563  }
1564  else {
1565  hAlctCompSameN2->Fill(ix,detid.chamber());
1566  }
1567  hAlctCompSameN2i->Fill(ix2,detid.chamber());
1568  }
1569 
1570  for (int i = 0; i < ndata; i++) {
1571  if (alctV_data[i].isValid() == 0) continue;
1572  int data_trknmb = alctV_data[i].getTrknmb();
1573  //int data_quality = alctV_data[i].getQuality();
1574  //int data_accel = alctV_data[i].getAccelerator();
1575  //int data_collB = alctV_data[i].getCollisionB();
1576  int data_wiregroup = alctV_data[i].getKeyWG();
1577  int data_bx = alctV_data[i].getBX();
1578 
1580  stubs_comparison[0].firstfill = firstfill;
1581  if (firstfill) firstfill = false;
1583  stubs_comparison[0].endcap = endc;
1585  stubs_comparison[0].ring = ring;
1588  stubs_comparison[0].totStubs_data = ndata;
1589  stubs_comparison[0].totStubs_emul = nemul;
1591  stubs_comparison[0].nStub_data = i+1;
1592  stubs_comparison[0].has_data = true;
1593  stubs_comparison[0].quality_data = alctV_data[i].getQuality();
1594  stubs_comparison[0].key_WG_data = alctV_data[i].getKeyWG();
1595  stubs_comparison[0].bx_data = data_bx;
1596  stubs_comparison[0].fullbx_data = alctV_data[i].getFullBX();
1597  stubs_comparison[0].trknmb_data = data_trknmb;
1598  GlobalPoint gp_alct_data(getGlobalPosition(detid.rawId(), data_wiregroup, 60));
1599  stubs_comparison[0].eta_data = gp_alct_data.eta();
1600  for (int j=0; j<nemul; j++){
1601  if (alctV_emul[j].isValid() == 0) continue;
1602  if (bookedalctV_emul[j]) continue; //used alct
1603 
1604  int emul_trknmb = alctV_emul[j].getTrknmb();
1605  //int emul_quality = alctV_emul[j].getQuality();
1606  //int emul_accel = alctV_emul[j].getAccelerator();
1607  //int emul_collB = alctV_emul[j].getCollisionB();
1608  int emul_wiregroup = alctV_emul[j].getKeyWG();
1609  int emul_bx = alctV_emul[j].getBX();
1610  // Emulator BX re-calculated for comparison with BX in the data.
1611  emul_corr_bx = emul_bx - rawhit_tbin_offset + register_delay;
1612  if (dataIsAnotherMC_)
1613  emul_corr_bx = emul_bx;
1614 
1615  if (ndata == nemul) {
1616  hAlctCompTotal->Fill(mychamber);
1617  hAlctCompTotalCsc[endc-1][csctype]->Fill(cham);
1618  if(detid.station()>1 && detid.ring()==1) {
1619  hAlctCompTotal2x->Fill(ix,detid.chamber()*2);
1620  }
1621  else {
1622  hAlctCompTotal2->Fill(ix,detid.chamber());
1623  }
1624  hAlctCompTotal2i->Fill(ix2,detid.chamber());
1625  }
1626  if (data_trknmb == emul_trknmb ) {
1627  if (abs(data_wiregroup - emul_wiregroup) <= 2){
1628  hAlctCompMatchCsc[endc-1][csctype]->Fill(cham);
1629  hAlctCompMatch->Fill(mychamber);
1630  if(detid.station()>1 && detid.ring()==1) {
1631  hAlctCompMatch2x->Fill(ix,detid.chamber()*2);
1632  }
1633  else {
1634  hAlctCompMatch2->Fill(ix,detid.chamber());
1635  }
1636  hAlctCompMatch2i->Fill(ix2,detid.chamber());
1637  }
1638  if (debug) LogTrace("CSCTriggerPrimitivesReader")
1639  << " Identical ALCTs #" << data_trknmb;
1640  stubs_comparison[0].nStub_emul = j+1;
1641  stubs_comparison[0].has_emul = true;
1642  stubs_comparison[0].quality_emul = alctV_emul[j].getQuality();
1643  stubs_comparison[0].key_WG_emul = alctV_emul[j].getKeyWG();
1644  stubs_comparison[0].bx_emul = alctV_emul[j].getBX();
1645  stubs_comparison[0].trknmb_emul = emul_trknmb;
1646  GlobalPoint gp_alct_emul(getGlobalPosition(detid.rawId(), emul_wiregroup, 60));
1647  stubs_comparison[0].eta_emul = gp_alct_emul.eta();
1648  stubs_comparison[0].bx_corr_emul = emul_corr_bx;
1649  bookedalctV_emul[j] = true;
1650  break;
1651  }
1652  else {
1653  LogTrace("CSCTriggerPrimitivesReader")
1654  << " Different ALCTs #" << data_trknmb << " in ME"
1655  << ((endc == 1) ? "+" : "-") << stat << "/"
1656  << ring << "/" << cham;
1657  }
1658 
1659  }//loop emul
1660  if (debug and stubs_comparison[0].key_WG_data != stubs_comparison[0].key_WG_emul)
1661  LogTrace("CSCTriggerPrimitivesReader")
1662  <<" not matched ALCT from data "<< alctV_data[i]
1663  <<" stubs_comparison 0 key_WG_data "<<stubs_comparison[0].key_WG_data <<" key_WG_emul "<< stubs_comparison[0].key_WG_emul;
1664  //if (stat==1) std::cout <<" stub_tree filled , ring "<< stubs_comparison[0].ring << std::endl;
1665  //cout <<"ALCT data BX "<< stubs_comparison[0].bx_data <<" WG "<< stubs_comparison[0].key_WG_data <<" emul BX "<< stubs_comparison[0].bx_emul<<" emul BX corrected "<< stubs_comparison[0].bx_corr_emul <<" WG "<< stubs_comparison[0].key_WG_emul << endl;
1666  stub_tree[0]->Fill();
1667  }//loop data
1668  for (int i = 0; i<nemul; i++){
1669  if (alctV_emul[i].isValid() == 0 or bookedalctV_emul[i]) continue;
1670  int emul_bx = alctV_emul[i].getBX();
1672  stubs_comparison[0].firstfill = firstfill;
1673  if (firstfill) firstfill = false;
1675  stubs_comparison[0].endcap = endc;
1677  stubs_comparison[0].ring = ring;
1680  stubs_comparison[0].totStubs_data = ndata;
1681  stubs_comparison[0].totStubs_emul = nemul;
1683  stubs_comparison[0].nStub_data = -1;
1684  stubs_comparison[0].nStub_emul = i+1;
1685  stubs_comparison[0].has_data = false;
1686  stubs_comparison[0].has_emul = true;
1687  stubs_comparison[0].trknmb_emul = alctV_emul[i].getTrknmb();
1688  stubs_comparison[0].quality_emul = alctV_emul[i].getQuality();
1689  stubs_comparison[0].key_WG_emul = alctV_emul[i].getKeyWG();
1690  stubs_comparison[0].bx_emul = alctV_emul[i].getBX();
1691  stubs_comparison[0].fullbx_emul = alctV_emul[i].getFullBX();
1692  GlobalPoint gp_alct_emul(getGlobalPosition(detid.rawId(), alctV_emul[i].getKeyWG(), 60));
1693  stubs_comparison[0].eta_emul = gp_alct_emul.eta();
1694  // Emulator BX re-calculated for comparison with BX in the data.
1695  emul_corr_bx = emul_bx - rawhit_tbin_offset + register_delay;
1696  if (dataIsAnotherMC_)
1697  emul_corr_bx = emul_bx;
1698  stubs_comparison[0].bx_corr_emul = emul_corr_bx;
1699  stub_tree[0]->Fill();
1700  if (debug)
1701  LogTrace("CSCTriggerPrimitivesReader")
1702  <<"not matched ALCT from emulation "<< alctV_emul[i];
1703 
1704  }//loop emul
1705  }
1706  }
1707  }
1708  }
1709 }// compare ALCT
1710 
1712  const CSCCLCTDigiCollection* clcts_emul,
1713  const CSCCLCTPreTriggerDigiCollection* pretrigs_emul) {
1714  // Number of Tbins before pre-trigger for raw cathode hits.
1715  const int tbin_cathode_offset = 7;
1716  //const int tbin_cathode_offset = 8;//in MC, it became 8, Tao
1717  const int pretrig_trig_zone = 5;// max distance between CLCT key hs and pretrigger hs
1718 
1719  // Loop over all chambers in search for CLCTs.
1720  std::vector<CSCCLCTDigi>::const_iterator pd, pe;
1721  std::vector<CSCCLCTPreTriggerDigi>::const_iterator pretrig;
1722  perStub[2].init(RUN_, Event_);
1723  perStub[3].init(RUN_, Event_);
1724  for (int endc = 1; endc <= 2; endc++) {
1725  for (int stat = 1; stat <= 4; stat++) {
1726  for (int ring = 1; ring <= maxRing(stat); ring++) {
1727  for (int cham = 1; cham <= 36; cham++) {
1728  // Calculate DetId. 0th layer means whole chamber.
1729  CSCDetId detid(endc, stat, ring, cham, 0);
1730 
1731  // Skip chambers marked as bad.
1732  if (checkBadChambers_ && badChambers_->isInBadChamber(detid)) continue;
1733 
1734  std::vector<CSCCLCTDigi> clctV_data, clctV_emul;
1735  const auto& drange = clcts_data->get(detid);
1736  for (auto digiIt = drange.first; digiIt != drange.second; digiIt++) {
1737  if ((*digiIt).isValid()) {
1738  clctV_data.push_back(*digiIt);
1739  }
1740  }
1741 
1742  const auto& erange = clcts_emul->get(detid);
1743  std::vector<bool> bookedclctV_emul;
1744  for (auto digiIt = erange.first; digiIt != erange.second; digiIt++) {
1745  if ((*digiIt).isValid()) {
1746  for (auto pclct : clctV_emul){
1747  if (digiIt->getBX() != pclct.getBX() and abs(digiIt->getBX() - pclct.getBX())< 5)
1748  LogTrace("CSCTriggerPrimitivesReader") <<"Two CLCTs very close in timing!!! Special event: first clct "<< pclct <<" second clct "<<*digiIt << std::endl;
1749  }
1750  clctV_emul.push_back(*digiIt);
1751  bookedclctV_emul.push_back(false);
1752  }
1753  }
1754 
1755  std::vector<CSCCLCTPreTriggerDigi> pretrigV_emul;
1756  const auto& pretrigrange = pretrigs_emul->get(detid);
1757  for (auto pretrigIt = pretrigrange.first; pretrigIt != pretrigrange.second; pretrigIt++){
1758  if ((*pretrigIt).isValid()){
1759  pretrigV_emul.push_back(*pretrigIt);
1760  }
1761  }
1762 
1763  int ndata = clctV_data.size();
1764  int nemul = clctV_emul.size();
1765  if (ndata == 0 && nemul == 0) continue;
1766  bool firstfill = true;
1767  int nemul_readout = 0;
1768  for (pe = clctV_emul.begin(); pe != clctV_emul.end(); pe++) {
1769  for (pd = clctV_data.begin(); pd != clctV_data.end(); pd++) {
1770  int emul_bx = (*pe).getBX();
1771  int corr_bx =
1772  ((*pd).getFullBX() + emul_bx - tbin_cathode_offset) & 0x03;
1773  int bx_data = pd->getBX();
1774  //if (corr_bx == bx_data or abs(pe->getKeyStrip() - pd->getKeyStrip())<=1){//if emulated BX after correction is same as data bx, it will be readout
1775  if (corr_bx == bx_data){//if emulated BX after correction is same as data bx, it will be readout
1776  nemul_readout++;
1777  break;
1778  }
1779  }
1780  }
1781 
1782  if (debug or nemul>ndata or (ndata != nemul) or ndata != nemul_readout) {
1783  LogTrace("CSCTriggerPrimitivesReader") << " CLCTs from data "<< ndata <<" CLCTs from emul "<< nemul <<" readout "<< nemul_readout;
1784  ostringstream strstrm;
1785  strstrm << "\n--- ME" << ((detid.endcap() == 1) ? "+" : "-")
1786  << detid.station() << "/" << detid.ring() << "/"
1787  << detid.chamber()
1788  << " (sector " << detid.triggerSector()
1789  << " trig id. " << detid.triggerCscId() << "):\n";
1790  strstrm << " **** " << ndata << " valid data CLCTs found:\n";
1791  for (pd = clctV_data.begin(); pd != clctV_data.end(); pd++) {
1792  strstrm << " " << (*pd)
1793  << " Full BX = " << (*pd).getFullBX() << "\n";
1794  }
1795  strstrm << " **** " << nemul << " valid emul CLCTs found:\n";
1796  for (pe = clctV_emul.begin(); pe != clctV_emul.end(); pe++) {
1797  strstrm << " " << (*pe);
1798  for (pd = clctV_data.begin(); pd != clctV_data.end(); pd++) {
1799  if ((*pd).getTrknmb() == (*pe).getTrknmb() or abs((*pe).getKeyStrip() - (*pd).getKeyStrip())<5) {
1800  int emul_bx = (*pe).getBX();
1801  int corr_bx =
1802  ((*pd).getFullBX() + emul_bx - tbin_cathode_offset) & 0x03;
1803  strstrm << " Corr BX = " << corr_bx;
1804  break;
1805  }
1806  }
1807  strstrm << "\n";
1808  }
1809  LogTrace("CSCTriggerPrimitivesReader") << strstrm.str();
1810  }
1811  if (nemul_readout > 2){ //reduce nemul_readout to 2 by hand
1812  //cout <<"CLCT matching nemul readout is "<< nemul_readout <<", larger than 2. reduce it to 2 by hand"<<endl;
1813  nemul_readout = 2;
1814  }
1815 
1816 
1817  //Per event Fill, From Luca
1818  //Data, add HS quality later
1819  int perEv_nStub_data = 0;
1820  int perEv_nStub_emul = 0;
1821  perStub[2].init(RUN_, Event_);
1822  perStub[3].init(RUN_, Event_);
1823  for (pd = clctV_data.begin(); pd != clctV_data.end(); pd++){
1824  perEv_nStub_data++;
1825  }
1826  perStub[2].t_endcap = endc;
1827  perStub[2].t_station = stat;
1828  perStub[2].t_chamber = cham;
1829  perStub[2].t_ring = ring;
1831  perStub[2].t_nStubs = ndata;
1832  perStub[2].t_nStubs_readout = ndata;
1833  event_tree[2]->Fill();
1834  //Emul
1835  for (pe = clctV_emul.begin(); pe != clctV_emul.end(); pe++){
1836  perEv_nStub_emul++;
1837  }
1838  perStub[3].t_endcap = endc;
1839  perStub[3].t_station = stat;
1840  perStub[3].t_chamber = cham;
1841  perStub[3].t_ring = ring;
1843  perStub[3].t_nStubs = nemul;
1844  perStub[3].t_nStubs_readout = nemul_readout;
1845  event_tree[3]->Fill();
1846 
1847 
1848  int csctype = getCSCType(detid);
1849  hClctCompFoundCsc[endc-1][csctype]->Fill(cham);
1850  int ix = chamberIX(detid);
1851  int ix2 = chamberIXi(detid);
1852  if(detid.station()>1 && detid.ring()==1) {
1853  hClctCompFound2x->Fill(ix,detid.chamber()*2);
1854  }
1855  else {
1856  hClctCompFound2->Fill(ix,detid.chamber());
1857  }
1858  hClctCompFound2i->Fill(ix2,detid.chamber());
1859  if (ndata != nemul) {
1860  LogTrace("CSCTriggerPrimitivesReader")
1861  //cerr
1862  << " +++ Different numbers of CLCTs found in ME"
1863  << ((endc == 1) ? "+" : "-") << stat << "/"
1864  << ring << "/" << cham
1865  << ": data = " << ndata << " emulator = " << nemul << " +++\n";
1866  }
1867  else {
1868  hClctCompSameNCsc[endc-1][csctype]->Fill(cham);
1869  if(detid.station()>1 && detid.ring()==1) {
1870  hClctCompSameN2x->Fill(ix,detid.chamber()*2);
1871  }
1872  else {
1873  hClctCompSameN2->Fill(ix,detid.chamber());
1874  }
1875  hClctCompSameN2i->Fill(ix2,detid.chamber());
1876  }
1877  int i=-1;
1878  int testwg = 20;
1879  for (pd = clctV_data.begin(); pd != clctV_data.end(); pd++) {
1880  i++;
1881  if ((*pd).isValid() == 0) continue;
1882  int data_trknmb = (*pd).getTrknmb();
1883  int data_quality = (*pd).getQuality();
1884  int data_pattern = (*pd).getPattern();
1885  int data_striptype = (*pd).getStripType();
1886  int data_bend = (*pd).getBend();
1887  int data_keystrip = (*pd).getKeyStrip();
1888  int data_cfeb = (*pd).getCFEB();
1889  int data_bx = (*pd).getBX();
1890  int fullBX = (*pd).getFullBX(); // 12-bit full BX
1891 
1892  if (data_keystrip >= 128 and stat == 1 and ring == 1) testwg=5;
1893  else testwg = 20;
1894 
1896  stubs_comparison[1].firstfill = firstfill;
1897  if (firstfill) firstfill = false;
1899  stubs_comparison[1].endcap = endc;
1901  stubs_comparison[1].ring = ring;
1904  stubs_comparison[1].totStubs_data = ndata;
1905  stubs_comparison[1].totStubs_emul = nemul;
1906  stubs_comparison[1].totStubs_emul_readout = nemul_readout;
1907  stubs_comparison[1].nStub_data = i+1;
1908  stubs_comparison[1].has_data = true;
1909  stubs_comparison[1].quality_data = (*pd).getQuality();
1910  stubs_comparison[1].key_hs_data = (*pd).getKeyStrip();
1911  stubs_comparison[1].bend_data = (*pd).getBend();
1912  stubs_comparison[1].pattern_data = (*pd).getPattern();
1913  stubs_comparison[1].bx_data = (*pd).getBX();
1914  stubs_comparison[1].fullbx_data = (*pd).getFullBX();
1915  stubs_comparison[1].trknmb_data = data_trknmb;
1916  GlobalPoint gp_clct_data(getGlobalPosition(detid.rawId(), testwg, (*pd).getKeyStrip()));
1917  stubs_comparison[1].phi_data = gp_clct_data.phi();
1918 
1919  int j=-1;
1920  for (pe = clctV_emul.begin(); pe != clctV_emul.end(); pe++) {
1921  j++;
1922  if ((*pe).isValid() == 0) continue;
1923  if (bookedclctV_emul[j]) continue; //used alct
1924  int emul_trknmb = (*pe).getTrknmb();
1925  int emul_quality = (*pe).getQuality();
1926  int emul_pattern = (*pe).getPattern();
1927  int emul_striptype = (*pe).getStripType();
1928  int emul_bend = (*pe).getBend();
1929  int emul_keystrip = (*pe).getKeyStrip();
1930  int emul_cfeb = (*pe).getCFEB();
1931  int emul_bx = (*pe).getBX();
1932 
1933  if (abs(data_keystrip - emul_keystrip) <= 2){
1934  // Emulator BX re-calculated using 12-bit full BX number.
1935  // Used for comparison with BX in the data.
1936  int emul_corr_bx =
1937  (fullBX + emul_bx - tbin_cathode_offset) & 0x03;
1938  //std::cout <<"CLCT data_bx "<< data_bx <<" emul_corr_bx "<< emul_corr_bx << std::endl;
1939  if (dataIsAnotherMC_)
1940  emul_corr_bx = (emul_bx & 0x03);
1941  if (ndata == nemul) {
1942  hClctCompTotalCsc[endc-1][csctype]->Fill(cham);
1943  if(detid.station()>1 && detid.ring()==1) {
1944  hClctCompTotal2x->Fill(ix,detid.chamber()*2);
1945  }
1946  else {
1947  hClctCompTotal2->Fill(ix,detid.chamber());
1948  }
1949  hClctCompTotal2i->Fill(ix2,detid.chamber());
1950  }
1951  if (data_quality == emul_quality &&
1952  data_pattern == emul_pattern &&
1953  data_striptype == emul_striptype &&
1954  data_bend == emul_bend &&
1955  data_keystrip == emul_keystrip &&
1956  data_cfeb == emul_cfeb ){
1957  if (ndata == nemul) {
1958  hClctCompMatchCsc[endc-1][csctype]->Fill(cham);
1959  if(detid.station()>1 && detid.ring()==1) {
1960  hClctCompMatch2x->Fill(ix,detid.chamber()*2);
1961  }
1962  else {
1963  hClctCompMatch2->Fill(ix,detid.chamber());
1964  }
1965  hClctCompMatch2i->Fill(ix2,detid.chamber());
1966  }
1967  if (debug) LogTrace("CSCTriggerPrimitivesReader")
1968  << " Identical CLCTs #" << data_trknmb;
1969  }
1970  else {
1971  LogTrace("CSCTriggerPrimitivesReader")
1972  << " Different CLCTs #" << data_trknmb << " in ME"
1973  << ((endc == 1) ? "+" : "-") << stat << "/"
1974  << ring << "/" << cham <<" data_bx "<< data_bx <<" emul_corr_bx "<< emul_corr_bx;
1975  }
1976  stubs_comparison[1].nStub_emul = j+1;
1977  stubs_comparison[1].has_emul = true;
1978  stubs_comparison[1].quality_emul = (*pe).getQuality();
1979  stubs_comparison[1].key_hs_emul = (*pe).getKeyStrip();
1980  stubs_comparison[1].bend_emul = (*pe).getBend();
1981  stubs_comparison[1].pattern_emul = (*pe).getPattern();
1982  stubs_comparison[1].bx_emul = (*pe).getBX();
1983  stubs_comparison[1].bx_corr_emul = emul_corr_bx;
1984  stubs_comparison[1].trknmb_emul = emul_trknmb;
1985  GlobalPoint gp_clct_emul(getGlobalPosition(detid.rawId(), testwg, (*pe).getKeyStrip()));
1986  stubs_comparison[1].phi_emul = gp_clct_emul.phi();
1987  bookedclctV_emul[j] = true;
1988 
1989  //int mingap_trig_pretrig = pretrig_trig_zone*2;
1990  int num_pretrig = 0;
1991  for (pretrig = pretrigV_emul.begin(); pretrig != pretrigV_emul.end(); pretrig++){
1992  if ((*pretrig).getBX() != (*pe).getBX()) continue;
1993  int hsgap = std::abs((*pretrig).getKeyStrip() - (*pe).getKeyStrip());
1994  bool samechamber = true;
1995  if (stat == 1 and ring == 1)
1996  samechamber = (((*pretrig).getKeyStrip() <128 and (*pe).getKeyStrip() <128 ) || ((*pretrig).getKeyStrip() >= 128 and (*pe).getKeyStrip() >=128 ));
1997  if (not samechamber)
1998  continue;
1999 
2000  if (hsgap <= pretrig_trig_zone)
2001  num_pretrig ++;
2002  else
2003  continue;
2004  if ((*pretrig).getPattern() > stubs_comparison[1].maxpattern_pretrig)
2005  stubs_comparison[1].maxpattern_pretrig = (*pretrig).getPattern();
2006  if ((*pretrig).getQuality() > stubs_comparison[1].maxquality_pretrig){
2007  stubs_comparison[1].quality_pretrig = (*pretrig).getQuality();
2008  stubs_comparison[1].key_hs_pretrig = (*pretrig).getKeyStrip();
2009  stubs_comparison[1].bend_pretrig = (*pretrig).getBend();
2010  stubs_comparison[1].pattern_pretrig = (*pretrig).getPattern();
2011  stubs_comparison[1].bx_pretrig = (*pretrig).getBX();
2012  }
2013  }
2014  stubs_comparison[1].npretrig = num_pretrig;
2015  break;
2016  }//if (data_trknmb == emul_trknmb)
2017  }//loop emul
2018  if (debug and stubs_comparison[1].key_hs_data != stubs_comparison[1].key_hs_emul)
2019  LogTrace("CSCTriggerPrimitivesReader")
2020  <<"CSCDetid "<< detid <<" not matched CLCT from data "<< (*pd)
2021  <<" stubs_comparison 1 key_hs_data "<<stubs_comparison[1].key_hs_data <<" key_hs_emul "<< stubs_comparison[1].key_hs_emul << endl;
2022  //cout <<"CLCT data BX "<< stubs_comparison[1].bx_data <<" emul BX "<< stubs_comparison[1].bx_emul<<" emul BX corrected "<< stubs_comparison[1].bx_corr_emul << endl;
2023  stub_tree[1]->Fill();
2024  }//loop data
2025  for (int k=0; k<nemul; k++){
2026  if (clctV_emul[i].isValid() == 0) continue;
2027  if (bookedclctV_emul[k]) continue;
2029  stubs_comparison[1].firstfill = firstfill;
2030  if (firstfill) firstfill = false;
2032  stubs_comparison[1].endcap = endc;
2034  stubs_comparison[1].ring = ring;
2037  stubs_comparison[1].totStubs_data = ndata;
2038  stubs_comparison[1].totStubs_emul = nemul;
2039  stubs_comparison[1].totStubs_emul_readout = nemul_readout;
2040  stubs_comparison[1].trknmb_emul = clctV_emul[i].getTrknmb();
2042  stubs_comparison[1].has_data = false;
2043  stubs_comparison[1].nStub_emul = k+1;
2044  stubs_comparison[1].has_emul = true;
2045  stubs_comparison[1].quality_emul = clctV_emul[k].getQuality();
2046  stubs_comparison[1].key_hs_emul = clctV_emul[k].getKeyStrip();
2047  stubs_comparison[1].bend_emul = clctV_emul[k].getBend();
2048  stubs_comparison[1].pattern_emul = clctV_emul[k].getPattern();
2049  stubs_comparison[1].bx_emul = clctV_emul[k].getBX();
2050  stubs_comparison[1].fullbx_emul = clctV_emul[k].getFullBX();
2051  if (clctV_emul[k].getKeyStrip()>= 128 and stat == 1 and ring == 1) testwg=5;
2052  else testwg = 20;
2053  // Emulator BX NOT Known from the data.
2054  GlobalPoint gp_clct_emul(getGlobalPosition(detid.rawId(), testwg, clctV_emul[k].getKeyStrip()));
2055  stubs_comparison[1].phi_emul = gp_clct_emul.phi();
2056  bookedclctV_emul[k] = true;
2057  stub_tree[1]->Fill();
2058  }
2059  }
2060  }
2061  }
2062  } // for all chambers
2063 } // compareCLCTs
2064 
2066  const CSCCorrelatedLCTDigiCollection* lcts_emul,
2067  const CSCALCTDigiCollection* alcts_data,
2068  const CSCCLCTDigiCollection* clcts_data) {
2069  // Need ALCT and CLCT digi collections to convert emulator bx into
2070  // hardware bx.
2071  // Loop over all chambers in search for correlated LCTs.
2072  std::vector<CSCCorrelatedLCTDigi>::const_iterator pd, pe;
2073  for (int endc = 1; endc <= 2; endc++) {
2074  for (int stat = 1; stat <= 4; stat++) {
2075  for (int ring = 1; ring <= maxRing(stat); ring++) {
2076  for (int cham = 1; cham <= 36; cham++) {
2077  // Calculate DetId. 0th layer means whole chamber.
2078  CSCDetId detid(endc, stat, ring, cham, 0);
2079 
2080  // Skip chambers marked as bad.
2081  if (checkBadChambers_ && badChambers_->isInBadChamber(detid)) continue;
2082 
2083  std::vector<CSCCorrelatedLCTDigi> lctV_data, lctV_emul;
2084  std::vector<bool> bookedlctV_emul;
2085  const auto& drange = lcts_data->get(detid);
2086  for (auto digiIt = drange.first; digiIt != drange.second; digiIt++) {
2087  if ((*digiIt).isValid()) {
2088  lctV_data.push_back(*digiIt);
2089  }
2090  }
2091 
2092  const auto& erange = lcts_emul->get(detid);
2093  for (auto digiIt = erange.first; digiIt != erange.second; digiIt++) {
2094  if ((*digiIt).isValid()) {
2095  lctV_emul.push_back(*digiIt);
2096  bookedlctV_emul.push_back(false);
2097  }
2098  }
2099 
2100  int ndata = lctV_data.size();
2101  int nemul = lctV_emul.size();
2102  if (ndata == 0 && nemul == 0) continue;
2103  bool firstfill = true;
2104  int nemul_readout = 0;
2105  for (pe = lctV_emul.begin(); pe != lctV_emul.end(); pe++) {
2106  for (pd = lctV_data.begin(); pd != lctV_data.end(); pd++) {
2107  int bx_data = pd->getBX();
2108  int bx_corr = convertBXofLCT((*pe).getBX(), detid,
2109  alcts_data, clcts_data);
2110  if ((bx_data == bx_corr) or (abs(pe->getKeyWG() - pd->getKeyWG())<=2 ) ){
2111  nemul_readout++;
2112  break;
2113  }
2114 
2115  }
2116  }
2117 
2118  if (debug or nemul>ndata or (nemul_readout != ndata) or nemul != ndata) {
2119 
2120  LogTrace("CSCTriggerPrimitivesReader") << " LCTs from data "<< ndata <<" LCTs from emul "<< nemul <<" readout "<< nemul_readout;
2121  ostringstream strstrm;
2122  strstrm << "\n--- ME" << ((detid.endcap() == 1) ? "+" : "-")
2123  << detid.station() << "/" << detid.ring() << "/"
2124  << detid.chamber()
2125  << " (sector " << detid.triggerSector()
2126  << " trig id. " << detid.triggerCscId() << "):\n";
2127  strstrm << " **** " << ndata << " valid data LCTs found:\n";
2128  for (pd = lctV_data.begin(); pd != lctV_data.end(); pd++) {
2129  strstrm << " " << (*pd);
2130  }
2131  strstrm << "\n **** " << nemul << " valid emul LCTs found:\n";
2132  for (pe = lctV_emul.begin(); pe != lctV_emul.end(); pe++) {
2133  strstrm << " " << (*pe);
2134  strstrm << " corr BX = "
2135  << convertBXofLCT((*pe).getBX(), detid,
2136  alcts_data, clcts_data);
2137  strstrm << " LCT pattern = " << (*pe).getPattern();
2138  strstrm << "\n";
2139 
2140  }
2141  LogTrace("CSCTriggerPrimitivesReader") << strstrm.str();
2142  //std::cout <<"CompareLCTs "<< strstrm.str()<< std::endl;
2143  }
2144  if (nemul_readout > 2){//reduce nemul_readout to 2 by hand
2145  //cout <<"LCT matching nemul readout is "<< nemul_readout <<", larger than 2. reduce it to 2 by hand"<<endl;
2146  nemul_readout = 2;
2147  }
2148 
2149  //
2150  //Data, add HS quality later
2151  int perEv_nStub_data = 0;
2152  int perEv_nStub_emul = 0;
2153  perStub[4].init(RUN_, Event_);
2154  perStub[5].init(RUN_, Event_);
2155  for (pd = lctV_data.begin(); pd != lctV_data.end(); pd++){
2156  perEv_nStub_data++;
2157  }
2158  perStub[4].t_endcap = endc;
2159  perStub[4].t_station = stat;
2160  perStub[4].t_chamber = cham;
2161  perStub[4].t_ring = ring;
2163  perStub[4].t_nStubs = ndata;
2164  perStub[4].t_nStubs_readout = ndata;
2165  event_tree[4]->Fill();
2166  //Emul
2167  for (pe = lctV_emul.begin(); pe != lctV_emul.end(); pe++){
2168  perEv_nStub_emul++;
2169  }
2170  perStub[5].t_endcap = endc;
2171  perStub[5].t_station = stat;
2172  perStub[5].t_chamber = cham;
2173  perStub[5].t_ring = ring;
2175  perStub[5].t_nStubs = nemul;
2176  perStub[5].t_nStubs_readout = nemul_readout;
2177  event_tree[5]->Fill();
2178 
2179  int csctype = getCSCType(detid);
2180  hLctCompFoundCsc[endc-1][csctype]->Fill(cham);
2181  int ix = chamberIX(detid);
2182  int ix2 = chamberIXi(detid);
2183  if(detid.station()>1 && detid.ring()==1) {
2184  hLCTCompFound2x->Fill(ix,detid.chamber()*2);
2185  }
2186  else {
2187  hLCTCompFound2->Fill(ix,detid.chamber());
2188  }
2189  hLCTCompFound2i->Fill(ix2,detid.chamber());
2190  if (ndata != nemul) {
2191  LogTrace("CSCTriggerPrimitivesReader")
2192  //cerr
2193  << " +++ Different numbers of LCTs found in ME"
2194  << ((endc == 1) ? "+" : "-") << stat << "/"
2195  << ring << "/" << cham
2196  << ": data = " << ndata << " emulator = " << nemul << " +++\n";
2197  }
2198  else {
2199  hLctCompSameNCsc[endc-1][csctype]->Fill(cham);
2200  if(detid.station()>1 && detid.ring()==1) {
2201  hLCTCompSameN2x->Fill(ix,detid.chamber()*2);
2202  }
2203  else {
2204  hLCTCompSameN2->Fill(ix,detid.chamber());
2205  }
2206  hLCTCompSameN2i->Fill(ix2,detid.chamber());
2207  }
2208  int i =-1;
2209  for (pd = lctV_data.begin(); pd != lctV_data.end(); pd++) {
2210  i++;
2211  if ((*pd).isValid() == 0) continue;
2212  int data_trknmb = (*pd).getTrknmb();
2213  int data_quality = (*pd).getQuality();
2214  int data_wiregroup = (*pd).getKeyWG();
2215  int data_keystrip = (*pd).getStrip();
2216  int data_pattern = (*pd).getCLCTPattern();
2217  int data_striptype = (*pd).getStripType();
2218  int data_bend = (*pd).getBend();
2219  int data_bx = (*pd).getBX();
2220 
2222  stubs_comparison[2].firstfill = firstfill;
2223  if (firstfill) firstfill = false;
2225  stubs_comparison[2].endcap = endc;
2227  stubs_comparison[2].ring = ring;
2230  stubs_comparison[2].totStubs_data = ndata;
2231  stubs_comparison[2].totStubs_emul = nemul;
2232  stubs_comparison[2].totStubs_emul_readout = nemul_readout;
2233  stubs_comparison[2].nStub_data = i+1;
2234  stubs_comparison[2].has_data = true;
2235  stubs_comparison[2].quality_data = (*pd).getQuality();
2236  stubs_comparison[2].key_WG_data = (*pd).getKeyWG();
2237  stubs_comparison[2].key_hs_data = (*pd).getStrip();
2238  //cout <<" CSC detid "<< detid <<" LCT in data "<< (*pd) <<" do doesALCTCrossCLCT "<< endl;
2239  stubs_comparison[2].WGcrossHS_data = doesALCTCrossCLCT(detid, (*pd).getKeyWG(), (*pd).getStrip());
2240  stubs_comparison[2].bend_data = (*pd).getBend();
2241  stubs_comparison[2].pattern_data = (*pd).getCLCTPattern();
2242  stubs_comparison[2].bx_data = (*pd).getBX();
2243  stubs_comparison[2].trknmb_data = data_trknmb;
2244  GlobalPoint gp_lct_data(getGlobalPosition(detid.rawId(), (*pd).getKeyWG(), (*pd).getStrip()));
2245  stubs_comparison[2].eta_data = gp_lct_data.eta();
2246  stubs_comparison[2].phi_data = gp_lct_data.phi();
2247  int j=-1;
2248  for (pe = lctV_emul.begin(); pe != lctV_emul.end(); pe++) {
2249  j++;
2250  if ((*pe).isValid() == 0) continue;
2251  if (bookedlctV_emul[j]) continue; //used alct
2252  int emul_trknmb = (*pe).getTrknmb();
2253  int emul_quality = (*pe).getQuality();
2254  int emul_wiregroup = (*pe).getKeyWG();
2255  int emul_keystrip = (*pe).getStrip();
2256  int emul_pattern = (*pe).getCLCTPattern();
2257  int emul_striptype = (*pe).getStripType();
2258  int emul_bend = (*pe).getBend();
2259  int emul_bx = (*pe).getBX();
2260  if (abs(data_keystrip - emul_keystrip) <= 2 || abs(data_wiregroup - emul_wiregroup) <= 2){
2261  // Convert emulator BX into hardware BX using full 12-bit
2262  // BX words in ALCT and CLCT digi collections.
2263  int emul_corr_bx = convertBXofLCT(emul_bx, detid,
2264  alcts_data, clcts_data);
2265  //std::cout <<"LCT data_bx "<< data_bx <<" emul_corr_bx "<< emul_corr_bx << std::endl;
2266  if (dataIsAnotherMC_)
2267  emul_corr_bx = (emul_bx & 0x01);
2268 
2269  if (ndata == nemul) {
2270  hLctCompTotalCsc[endc-1][csctype]->Fill(cham);
2271  if(detid.station()>1 && detid.ring()==1) {
2272  hLCTCompTotal2x->Fill(ix,detid.chamber()*2);
2273  }
2274  else {
2275  hLCTCompTotal2->Fill(ix,detid.chamber());
2276  }
2277  hLCTCompTotal2i->Fill(ix2,detid.chamber());
2278  }
2279  if (data_quality == emul_quality &&
2280  data_wiregroup == emul_wiregroup &&
2281  data_keystrip == emul_keystrip &&
2282  data_pattern == emul_pattern &&
2283  data_striptype == emul_striptype &&
2284  data_bend == emul_bend ){
2285  if (ndata == nemul) {
2286  hLctCompMatchCsc[endc-1][csctype]->Fill(cham);
2287  if(detid.station()>1 && detid.ring()==1) {
2288  hLCTCompMatch2x->Fill(ix,detid.chamber()*2);
2289  }
2290  else {
2291  hLCTCompMatch2->Fill(ix,detid.chamber());
2292  }
2293  hLCTCompMatch2i->Fill(ix2,detid.chamber());
2294  }
2295  if (debug) LogTrace("CSCTriggerPrimitivesReader")
2296  << " Identical LCTs #" << data_trknmb;
2297  }
2298  else {
2299  LogTrace("CSCTriggerPrimitivesReader")
2300  << " Different LCTs #" << data_trknmb << " in ME"
2301  << ((endc == 1) ? "+" : "-") << stat << "/"
2302  << ring << "/" << cham <<" data_lct bx "<< data_bx<< " emul bx "<< emul_corr_bx;
2303  }
2304  stubs_comparison[2].nStub_emul = j+1;
2305  stubs_comparison[2].has_emul = true;
2306  stubs_comparison[2].quality_emul = (*pe).getQuality();
2307  stubs_comparison[2].key_WG_emul = (*pe).getKeyWG();
2308  stubs_comparison[2].key_hs_emul = (*pe).getStrip();
2309  stubs_comparison[2].bend_emul = (*pe).getBend();
2310  stubs_comparison[2].pattern_emul = (*pe).getCLCTPattern();
2311  stubs_comparison[2].bx_emul = (*pe).getBX();
2312  //cout <<" CSC detid "<< detid <<" LCT in emul "<< (*pe) <<" do doesALCTCrossCLCT "<< endl;
2313  stubs_comparison[2].WGcrossHS_emul = doesALCTCrossCLCT(detid, (*pe).getKeyWG(), (*pe).getStrip());
2314  stubs_comparison[2].bx_corr_emul = emul_corr_bx;
2315  stubs_comparison[2].trknmb_emul = emul_trknmb;
2316  GlobalPoint gp_lct_emul(getGlobalPosition(detid.rawId(), (*pe).getKeyWG(), (*pe).getStrip()));
2317  stubs_comparison[2].eta_emul = gp_lct_emul.eta();
2318  stubs_comparison[2].phi_emul = gp_lct_emul.phi();
2319  bookedlctV_emul[j] = true;
2320  break;
2321  }//if (data_trknmb == emul_trknmb)
2322  }//loop emul
2323  if (debug and stubs_comparison[2].key_hs_data != stubs_comparison[2].key_hs_emul)
2324  LogTrace("CSCTriggerPrimitivesReader")
2325  <<"CSCDetid "<< detid <<" not matched LCT from Data "<< (*pd)
2326  <<" stubs_comparison 2 key_hs_data "<<stubs_comparison[2].key_hs_data <<" key_hs_emul "<< stubs_comparison[2].key_hs_emul << endl;
2327  stub_tree[2]->Fill();
2328  }//loop data
2329  for (int k=0; k<nemul; k++){
2330  if (bookedlctV_emul[k]) continue;
2331  if (lctV_emul[i].isValid() == 0) continue;
2334  stubs_comparison[2].endcap = endc;
2336  stubs_comparison[2].ring = ring;
2339  stubs_comparison[2].totStubs_data = ndata;
2340  stubs_comparison[2].totStubs_emul = nemul;
2341  stubs_comparison[2].totStubs_emul_readout = nemul_readout;
2342  stubs_comparison[2].trknmb_emul = lctV_emul[i].getTrknmb();
2344  stubs_comparison[2].has_data = false;
2345  stubs_comparison[2].nStub_emul = k+1;
2346  stubs_comparison[2].has_emul = true;
2347  stubs_comparison[2].WGcrossHS_emul = doesALCTCrossCLCT(detid, lctV_emul[k].getKeyWG(), lctV_emul[k].getStrip());
2348  stubs_comparison[2].quality_emul = lctV_emul[k].getQuality();
2349  stubs_comparison[2].key_WG_emul = lctV_emul[k].getKeyWG();
2350  stubs_comparison[2].key_hs_emul = lctV_emul[k].getStrip();
2351  stubs_comparison[2].bend_emul = lctV_emul[k].getBend();
2352  stubs_comparison[2].pattern_emul = lctV_emul[k].getCLCTPattern();
2353  stubs_comparison[2].bx_emul = lctV_emul[k].getBX();
2354  //stubs_comparison[2].fullbx_emul = lctV_emul[k].getFullBX();
2355  // Emulator BX NOT Known from the data.
2356  GlobalPoint gp_lct_emul(getGlobalPosition(detid.rawId(), lctV_emul[k].getKeyWG(), lctV_emul[k].getStrip()));
2357  stubs_comparison[2].eta_emul = gp_lct_emul.eta();
2358  stubs_comparison[2].phi_emul = gp_lct_emul.phi();
2359  bookedlctV_emul[k] = true;
2360  stub_tree[2]->Fill();
2361 
2362  }
2363  }
2364  }
2365  }
2366  }
2367 }
2368 
2369 
2371  const CSCCorrelatedLCTDigiCollection* lcts_data,
2372  const CSCCorrelatedLCTDigiCollection* lcts_emul,
2373  const CSCALCTDigiCollection* alcts_data,
2374  const CSCCLCTDigiCollection* clcts_data) {
2375 
2376  // Need ALCT and CLCT digi collections to convert emulator bx into
2377  // hardware bx.
2378  // Loop over all chambers in search for correlated LCTs.
2379  std::vector<CSCCorrelatedLCTDigi>::const_iterator pd, pe;
2380  for (int endc = 1; endc <= 2; endc++) {
2381  for (int stat = 1; stat <= 4; stat++) {
2382  for (int ring = 1; ring <= maxRing(stat); ring++) {
2383  for (int cham = 1; cham <= 36; cham++) {
2384  // Calculate DetId. 0th layer means whole chamber.
2385  CSCDetId detid(endc, stat, ring, cham, 0);
2386 
2387  // Skip chambers marked as bad.
2388  if (checkBadChambers_ && badChambers_->isInBadChamber(detid)) continue;
2389 
2390  std::vector<CSCCorrelatedLCTDigi> lctV_data, lctV_emul;
2391  std::vector<bool> bookedlctV_emul;
2392  const auto& drange = lcts_data->get(detid);
2393  for (auto digiIt = drange.first; digiIt != drange.second; digiIt++) {
2394  if ((*digiIt).isValid()) {
2395  lctV_data.push_back(*digiIt);
2396  }
2397  }
2398 
2399  const auto& erange = lcts_emul->get(detid);
2400  for (auto digiIt = erange.first; digiIt != erange.second; digiIt++) {
2401  if ((*digiIt).isValid()) {
2402  lctV_emul.push_back(*digiIt);
2403  bookedlctV_emul.push_back(false);
2404  }
2405  }
2406 
2407  int ndata = lctV_data.size();
2408  int nemul = lctV_emul.size();
2409  if (ndata == 0 && nemul == 0) continue;
2410  bool firstfill = true;
2411 
2412  if (debug) {
2413  ostringstream strstrm;
2414  strstrm << "\n--- ME" << ((detid.endcap() == 1) ? "+" : "-")
2415  << detid.station() << "/" << detid.ring() << "/"
2416  << detid.chamber()
2417  << " (sector " << detid.triggerSector()
2418  << " trig id. " << detid.triggerCscId() << "):\n";
2419  strstrm << " **** " << ndata << " valid data LCTs found:\n";
2420  for (pd = lctV_data.begin(); pd != lctV_data.end(); pd++) {
2421  strstrm << " " << (*pd);
2422  }
2423  strstrm << "\n **** " << nemul << " valid emul LCTs found:\n";
2424  for (pe = lctV_emul.begin(); pe != lctV_emul.end(); pe++) {
2425  strstrm << " " << (*pe);
2426  strstrm << " corr BX = "
2427  << convertBXofLCT((*pe).getBX(), detid,
2428  alcts_data, clcts_data);
2429  strstrm << " LCT pattern = " << (*pe).getPattern();
2430  strstrm << "\n";
2431  }
2432  LogTrace("CSCTriggerPrimitivesReader") << strstrm.str();
2433  //std::cout <<"CompareLCTs "<< strstrm.str()<< std::endl;
2434  }
2435 
2436  //int ix = chamberIX(detid);
2437  //int ix2 = chamberIXi(detid);
2438  if (ndata != nemul) {
2439  LogTrace("CSCTriggerPrimitivesReader")
2440  << " +++ Different numbers of MPC LCTs found in ME"
2441  << ((endc == 1) ? "+" : "-") << stat << "/"
2442  << ring << "/" << cham
2443  << ": data = " << ndata << " emulator = " << nemul << " +++\n";
2444  }
2445  /*else {
2446  hLctCompSameNCsc[endc-1][csctype]->Fill(cham);
2447  if(detid.station()>1 && detid.ring()==1) {
2448  hLCTCompSameN2x->Fill(ix,detid.chamber()*2);
2449  }
2450  else {
2451  hLCTCompSameN2->Fill(ix,detid.chamber());
2452  }
2453  hLCTCompSameN2i->Fill(ix2,detid.chamber());
2454  }*/
2455  int i =-1;
2456  for (pd = lctV_data.begin(); pd != lctV_data.end(); pd++) {
2457  i++;
2458  if ((*pd).isValid() == 0) continue;
2459  int data_trknmb = (*pd).getTrknmb();
2460  int data_quality = (*pd).getQuality();
2461  int data_wiregroup = (*pd).getKeyWG();
2462  int data_keystrip = (*pd).getStrip();
2463  int data_pattern = (*pd).getCLCTPattern();
2464  int data_striptype = (*pd).getStripType();
2465  int data_bend = (*pd).getBend();
2466  int data_bx = (*pd).getBX();
2467 
2469  stubs_comparison[3].firstfill = firstfill;
2470  if (firstfill) firstfill = false;
2472  stubs_comparison[3].endcap = endc;
2474  stubs_comparison[3].ring = ring;
2477  stubs_comparison[3].totStubs_data = ndata;
2478  stubs_comparison[3].totStubs_emul = nemul;
2479  stubs_comparison[3].nStub_data = i+1;
2480  stubs_comparison[3].has_data = true;
2481  stubs_comparison[3].WGcrossHS_data = doesALCTCrossCLCT(detid, (*pd).getKeyWG(), (*pd).getStrip());
2482  stubs_comparison[3].quality_data = (*pd).getQuality();
2483  stubs_comparison[3].key_WG_data = (*pd).getKeyWG();
2484  stubs_comparison[3].key_hs_data = (*pd).getStrip();
2485  stubs_comparison[3].bend_data = (*pd).getBend();
2486  stubs_comparison[3].pattern_data = (*pd).getCLCTPattern();
2487  stubs_comparison[3].bx_data = (*pd).getBX();
2488  stubs_comparison[3].trknmb_data = data_trknmb;
2489  GlobalPoint gp_lct_data(getGlobalPosition(detid.rawId(), (*pd).getKeyWG(), (*pd).getStrip()));
2490  stubs_comparison[3].eta_data = gp_lct_data.eta();
2491  stubs_comparison[3].phi_data = gp_lct_data.phi();
2492  int j=-1;
2493  for (pe = lctV_emul.begin(); pe != lctV_emul.end(); pe++) {
2494  j++;
2495  if ((*pe).isValid() == 0) continue;
2496  int emul_trknmb = (*pe).getTrknmb();
2497  int emul_quality = (*pe).getQuality();
2498  int emul_wiregroup = (*pe).getKeyWG();
2499  int emul_keystrip = (*pe).getStrip();
2500  int emul_pattern = (*pe).getCLCTPattern();
2501  int emul_striptype = (*pe).getStripType();
2502  int emul_bend = (*pe).getBend();
2503  int emul_bx = (*pe).getBX();
2504  if (data_trknmb == emul_trknmb) {
2505  // Convert emulator BX into hardware BX using full 12-bit
2506  // BX words in ALCT and CLCT digi collections.
2507  int emul_corr_bx = convertBXofLCT(emul_bx, detid,
2508  alcts_data, clcts_data);
2509  //std::cout <<"LCT data_bx "<< data_bx <<" emul_corr_bx "<< emul_corr_bx << std::endl;
2510  if (dataIsAnotherMC_)
2511  emul_corr_bx = (emul_bx & 0x01);
2512 
2513  /*if (ndata == nemul) {
2514  hLctCompTotalCsc[endc-1][csctype]->Fill(cham);
2515  if(detid.station()>1 && detid.ring()==1) {
2516  hLCTCompTotal2x->Fill(ix,detid.chamber()*2);
2517  }
2518  else {
2519  hLCTCompTotal2->Fill(ix,detid.chamber());
2520  }
2521  hLCTCompTotal2i->Fill(ix2,detid.chamber());
2522  }*/
2523  if (data_quality == emul_quality &&
2524  data_wiregroup == emul_wiregroup &&
2525  data_keystrip == emul_keystrip &&
2526  data_pattern == emul_pattern &&
2527  data_striptype == emul_striptype &&
2528  data_bend == emul_bend ){
2529  //data_bx == emul_corr_bx) {
2530  /*if (ndata == nemul) {
2531  hLctCompMatchCsc[endc-1][csctype]->Fill(cham);
2532  if(detid.station()>1 && detid.ring()==1) {
2533  hLCTCompMatch2x->Fill(ix,detid.chamber()*2);
2534  }
2535  else {
2536  hLCTCompMatch2->Fill(ix,detid.chamber());
2537  }
2538  hLCTCompMatch2i->Fill(ix2,detid.chamber());
2539  }*/
2540  if (debug) LogTrace("CSCTriggerPrimitivesReader")
2541  << " Identical LCTs #" << data_trknmb;
2542  stubs_comparison[3].nStub_emul = j+1;
2543  stubs_comparison[3].has_emul = true;
2544  stubs_comparison[3].WGcrossHS_emul = doesALCTCrossCLCT(detid, (*pe).getKeyWG(), (*pe).getStrip());
2545  stubs_comparison[3].quality_emul = (*pe).getQuality();
2546  stubs_comparison[3].key_WG_emul = (*pe).getKeyWG();
2547  stubs_comparison[3].key_hs_emul = (*pe).getStrip();
2548  stubs_comparison[3].bend_emul = (*pe).getBend();
2549  stubs_comparison[3].pattern_emul = (*pe).getCLCTPattern();
2550  stubs_comparison[3].bx_emul = (*pe).getBX();
2551  stubs_comparison[3].bx_corr_emul = emul_corr_bx;
2552  stubs_comparison[3].trknmb_emul = emul_trknmb;
2553  GlobalPoint gp_lct_emul(getGlobalPosition(detid.rawId(), (*pe).getKeyWG(), (*pe).getStrip()));
2554  stubs_comparison[3].eta_emul = gp_lct_emul.eta();
2555  stubs_comparison[3].phi_emul = gp_lct_emul.phi();
2556  bookedlctV_emul[j] = true;
2557  break;
2558  }
2559  else {
2560  LogTrace("CSCTriggerPrimitivesReader")
2561  //cerr
2562  << " Different LCTs #" << data_trknmb << " in ME"
2563  << ((endc == 1) ? "+" : "-") << stat << "/"
2564  << ring << "/" << cham <<" data_lct bx "<< data_bx<< " emul bx "<< emul_corr_bx;
2565  }
2566  }
2567  }//loop emul
2568  if (debug and stubs_comparison[3].key_hs_data != stubs_comparison[3].key_hs_emul)
2569  LogTrace("CSCTriggerPrimitivesReader")
2570  <<"stubs_comparison 2 key_hs_data "<<stubs_comparison[3].key_hs_data <<" key_hs_emul "<< stubs_comparison[3].key_hs_emul;
2571  stub_tree[3]->Fill();
2572  }//loop data
2573 
2574  for (int k=0; k<nemul; k++){
2575  if (bookedlctV_emul[k]) continue;
2577  stubs_comparison[3].firstfill = firstfill;
2578  if (firstfill) firstfill = false;
2580  stubs_comparison[3].endcap = endc;
2582  stubs_comparison[3].ring = ring;
2585  stubs_comparison[3].totStubs_data = ndata;
2586  stubs_comparison[3].totStubs_emul = nemul;
2587  stubs_comparison[3].trknmb_emul = lctV_emul[i].getTrknmb();
2589  stubs_comparison[3].has_data = false;
2590  stubs_comparison[3].nStub_emul = k+1;
2591  stubs_comparison[3].has_emul = true;
2592  stubs_comparison[3].WGcrossHS_emul = doesALCTCrossCLCT(detid, lctV_emul[k].getKeyWG(), lctV_emul[k].getStrip());
2593  stubs_comparison[3].quality_emul = lctV_emul[k].getQuality();
2594  stubs_comparison[3].key_WG_emul = lctV_emul[k].getKeyWG();
2595  stubs_comparison[3].key_hs_emul = lctV_emul[k].getStrip();
2596  stubs_comparison[3].bend_emul = lctV_emul[k].getBend();
2597  stubs_comparison[3].pattern_emul = lctV_emul[k].getCLCTPattern();
2598  stubs_comparison[3].bx_emul = lctV_emul[k].getBX();
2599  //stubs_comparison[2].fullbx_emul = lctV_emul[k].getFullBX();
2600  // Emulator BX NOT Known from the data.
2601  GlobalPoint gp_lct_emul(getGlobalPosition(detid.rawId(), lctV_emul[k].getKeyWG(), lctV_emul[k].getStrip()));
2602  stubs_comparison[3].eta_emul = gp_lct_emul.eta();
2603  stubs_comparison[3].phi_emul = gp_lct_emul.phi();
2604  bookedlctV_emul[k] = true;
2605  stub_tree[3]->Fill();
2606 
2607  }
2608  }//end loop of chambers
2609  }
2610  }
2611  }
2612 }
2613 
2614 
2615 
2616 
2618  const int emul_bx, const CSCDetId& detid,
2619  const CSCALCTDigiCollection* alcts_data,
2620  const CSCCLCTDigiCollection* clcts_data) {
2621  int full_anode_bx = -999;
2622  //int full_cathode_bx = -999;
2623  int lct_bx = -999;
2624  int tbin_anode_offset = 5; // 2007, run 14419.
2625 
2626  // Extract full 12-bit anode BX word from ALCT collections.
2627  const auto& arange = alcts_data->get(detid);
2628  for (auto digiIt = arange.first; digiIt != arange.second; digiIt++) {
2629  if ((*digiIt).isValid()) {
2630  full_anode_bx = (*digiIt).getFullBX();
2631  break;
2632  }
2633  }
2634 
2635  // Extract full 12-bit cathode BX word from CLCT collections.
2636  const auto& crange = clcts_data->get(detid);
2637  for (auto digiIt = crange.first; digiIt != crange.second; digiIt++) {
2638  if ((*digiIt).isValid()) {
2639  //full_cathode_bx = (*digiIt).getFullBX();
2640  break;
2641  }
2642  }
2643 
2644  // Use these 12-bit BX's to convert emulator BX into hardware BX.
2645  if (full_anode_bx == -999) {
2646  // What to do???
2647  edm::LogWarning("L1CSCTPEmulatorWrongInput")
2648  << "+++ Warning in convertBXofLCT(): full anode BX is not available!"
2649  << " +++\n";
2650  }
2651  else {
2652  // LCT BX has two bits: the least-significant bit is the LSB of ALCT BX;
2653  // the MSB is 1/0 depending on whether the 12-bit full cathode BX is 0
2654  // or not.
2655  lct_bx = (full_anode_bx + emul_bx - tbin_anode_offset) & 0x01;
2656  // SV, 12/Jun/08: it looks like this bit is never set - docu must be
2657  // wrong.
2658  //lct_bx = lct_bx | ((full_cathode_bx == 0) << 1);
2659  }
2660  //std::cout <<"convertBXofLCT old emul_bx "<< emul_bx <<" new lct bx "<< lct_bx <<" ful_anode_bx "<< full_anode_bx << std::endl;
2661  return lct_bx;
2662 }
2663 
2664 
2668  // iEvent.getByLabel(wireDigiProducer_.label(), wireDigiProducer_.instance(), wires);
2669  iEvent.getByToken(wireDigi_token_, wires);
2670 
2671  int serial_old=-1;
2672  for (auto dWDiter=wires->begin(); dWDiter!=wires->end(); dWDiter++) {
2673  CSCDetId id = (CSCDetId)(*dWDiter).first;
2674  int serial = chamberSerial(id)-1;
2675  // printf("serial %i\n",serial);
2676  std::vector<CSCWireDigi>::const_iterator wireIter = (*dWDiter).second.first;
2677  std::vector<CSCWireDigi>::const_iterator lWire = (*dWDiter).second.second;
2678  bool has_layer=false;
2679  for( ; wireIter != lWire; ++wireIter) {
2680  has_layer=true;
2681  int i_layer= id.layer()-1;
2682  int i_wire = wireIter->getWireGroup()-1;
2683  int nbins = wireIter->getTimeBinsOn().size();
2684  int serial2=serial*(6*112)+i_layer*112+i_wire;
2685  /*
2686  printf("endcap %i, station %i, ring %i, chamber %i, serial %i, serial2 %i, layer %i, wg %i\n",
2687  id.endcap(), id.station(), id.ring(), id.chamber(), serial, serial2, i_layer, i_wire);
2688  */
2689  hHotWire1->Fill(serial2,nbins);
2690  /*
2691  if(id.station()==1) {
2692  printf("ring %i, chamber type %i, wg %i\n",id.ring(),id.iChamberType(),i_wire);
2693  }
2694  */
2695  }
2696  if(serial_old!=serial && has_layer) {
2697  // nHotCham[serial]++;
2698  hHotCham1->Fill(serial);
2699  // printf("serial %i filled\n",serial);
2700  serial_old=serial;
2701  }
2702  }
2703 }
2704 
2706  const CSCALCTDigiCollection* alcts,
2707  const CSCCLCTDigiCollection* clcts) {
2708  // MC particles, if any.
2709  //edm::Handle<edm::HepMCProduct> mcp;
2710  //ev.getByLabel("source", mcp);
2711  //ev.getByType(mcp);
2712  vector<edm::Handle<edm::HepMCProduct> > allhepmcp;
2713  // Use "getManyByType" to be able to check the existence of MC info.
2714  ev.getManyByType(allhepmcp);
2715 
2716  //cout << "HepMC info: " << allhepmcp.size() << endl;
2717  if (allhepmcp.size() > 0) {
2718  const HepMC::GenEvent& mc = allhepmcp[0]->getHepMCData();
2719  int i = 0;
2720  for (HepMC::GenEvent::particle_const_iterator p = mc.particles_begin();
2721  p != mc.particles_end(); ++p) {
2722  int id = (*p)->pdg_id();
2723  double phitmp = (*p)->momentum().phi();
2724  if (phitmp < 0) phitmp += 2.*M_PI;
2725  if (debug) LogDebug("CSCTriggerPrimitivesReader")
2726  << "MC part #" << ++i << ": id = " << id
2727  << ", status = " << (*p)->status()
2728  << "\n pX = " << (*p)->momentum().x()
2729  << ", pY = " << (*p)->momentum().y()
2730  << ", pT = " << (*p)->momentum().perp() << " GeV"
2731  << ", p = " << (*p)->momentum().rho() << " GeV"
2732  << "\n eta = " << (*p)->momentum().pseudoRapidity()
2733  << ", phi = " << phitmp << " (" << phitmp*180./M_PI << " deg)";
2734  }
2735 
2736  // If hepMC info is there, try to get wire and comparator digis,
2737  // and SimHits.
2741  // ev.getByLabel(wireDigiProducer_.label(), wireDigiProducer_.instance(),
2742  // wireDigis);
2743  // ev.getByLabel(compDigiProducer_.label(), compDigiProducer_.instance(),
2744  // compDigis);
2745  // ev.getByLabel(simHitProducer_.label(), simHitProducer_.instance(),
2746  // simHits);
2747  ev.getByToken(wireDigi_token_, wireDigis);
2748  ev.getByToken(compDigi_token_, compDigis);
2749  ev.getByToken(simHit_token_, simHitsH);
2750  const edm::PSimHitContainer& simHits = *simHitsH.product();
2751 
2752  if (!wireDigis.isValid()) {
2753  edm::LogWarning("L1CSCTPEmulatorWrongInput")
2754  << "+++ Warning: Collection of wire digis with label"
2756  << " requested, but not found in the event... Skipping the rest +++\n";
2757  return;
2758  }
2759  if (!compDigis.isValid()) {
2760  edm::LogWarning("L1CSCTPEmulatorWrongInput")
2761  << "+++ Warning: Collection of comparator digis with label"
2763  << " requested, but not found in the event... Skipping the rest +++\n";
2764  return;
2765  }
2766  if (!simHitsH.isValid()) {
2767  edm::LogWarning("L1CSCTPEmulatorWrongInput")
2768  << "+++ Warning: Collection of SimHits with label"
2769  << simHitProducer_.label()
2770  << " requested, but not found in the event... Skipping the rest +++\n";
2771  return;
2772  }
2773 
2774 
2775  if (debug) LogTrace("CSCTriggerPrimitivesReader")
2776  << " #CSC SimHits: " << simHits.size();
2777 
2778  // MC-based resolution studies.
2779  calcResolution(alcts, clcts, wireDigis.product(), compDigis.product(),
2780  simHits);
2781 
2782  // MC-based efficiency studies.
2783  calcEfficiency(alcts, clcts, simHits);
2784  }
2785 }
2786 
2788  const CSCWireDigiCollection* wiredc,
2789  const CSCComparatorDigiCollection* compdc,
2790  const edm::PSimHitContainer& allSimHits) {
2791 
2792  // Book histos when called for the first time.
2794 
2795  // ALCT resolution
2796  CSCAnodeLCTAnalyzer alct_analyzer;
2797  alct_analyzer.setGeometry(geom_);
2798 
2799  for (auto adetUnitIt = alcts->begin(); adetUnitIt != alcts->end(); adetUnitIt++) {
2800  const CSCDetId& id = (*adetUnitIt).first;
2801  if (checkBadChambers_ && badChambers_->isInBadChamber(id)) continue;
2802  const auto& range = (*adetUnitIt).second;
2803  for (auto digiIt = range.first;
2804  digiIt != range.second; digiIt++) {
2805 
2806  bool alct_valid = (*digiIt).isValid();
2807  if (alct_valid) {
2808  vector<CSCAnodeLayerInfo> alctInfo =
2809  alct_analyzer.getSimInfo(*digiIt, id, wiredc, &allSimHits);
2810 
2811  double hitPhi = -999.0, hitEta = -999.0;
2812  int hitWG = alct_analyzer.nearestWG(alctInfo, hitPhi, hitEta);
2813  if (hitWG >= 0.) {
2814  // Key wire group and key layer id.
2815  int wiregroup = (*digiIt).getKeyWG();
2816 
2817  CSCDetId layerId(id.endcap(), id.station(), id.ring(),
2819  int endc = id.endcap();
2820  int stat = id.station();
2821  int csctype = getCSCType(id);
2822 
2823  double alctEta = alct_analyzer.getWGEta(layerId, wiregroup);
2824  double deltaEta = alctEta - hitEta;
2825  hResolDeltaEta->Fill(deltaEta);
2826 
2827  double deltaWG = wiregroup - hitWG;
2828  if (debug) LogTrace("CSCTriggerPrimitivesReader")
2829  << "WG: MC = " << hitWG << " rec = " << wiregroup
2830  << " delta = " << deltaWG;
2831  hResolDeltaWG->Fill(deltaWG);
2832 
2833  hEtaRecVsSim->Fill(fabs(hitEta), fabs(alctEta));
2834  hEtaDiffCsc[csctype][0]->Fill(deltaEta);
2835  hEtaDiffCsc[csctype][endc]->Fill(deltaEta);
2836  hAlctVsEta[stat-1]->Fill(fabs(alctEta));
2837  hEtaDiffVsEta[stat-1]->Fill(fabs(alctEta), fabs(deltaEta));
2838  hEtaDiffVsWireCsc[csctype]->Fill(wiregroup, deltaEta);
2839  }
2840  // should I comment out this "else"?
2841  //else {
2842  // edm::LogWarning("L1CSCTPEmulatorWrongInput")
2843  // << "+++ Warning in calcResolution(): no matched SimHit"
2844  // << " found! +++\n";
2845  //}
2846  }
2847  }
2848  }
2849 
2850  // CLCT resolution
2851  static const int key_layer = CSCConstants::KEY_CLCT_LAYER;
2852  CSCCathodeLCTAnalyzer clct_analyzer;
2853  clct_analyzer.setGeometry(geom_);
2854 
2855  for (auto cdetUnitIt = clcts->begin(); cdetUnitIt != clcts->end(); cdetUnitIt++) {
2856  const CSCDetId& id = (*cdetUnitIt).first;
2857  if (checkBadChambers_ && badChambers_->isInBadChamber(id)) continue;
2858  const auto& range = (*cdetUnitIt).second;
2859  for (auto digiIt = range.first;
2860  digiIt != range.second; digiIt++) {
2861 
2862  bool clct_valid = (*digiIt).isValid();
2863  if (clct_valid) {
2864  vector<CSCCathodeLayerInfo> clctInfo =
2865  clct_analyzer.getSimInfo(*digiIt, id, compdc, &allSimHits);
2866 
2867  double hitPhi = -999.0, hitEta = -999.0, deltaStrip = -999.0;
2868  int hitHS = clct_analyzer.nearestHS(clctInfo, hitPhi, hitEta);
2869  if (hitHS >= 0.) {
2870  // Key strip and key layer id.
2871  int halfstrip = (*digiIt).getKeyStrip();
2872  int strip = halfstrip/2;
2873  int distrip = halfstrip/4;
2874  int stripType = (*digiIt).getStripType();
2875 
2876  CSCDetId layerId(id.endcap(), id.station(), id.ring(),
2877  id.chamber(), key_layer);
2878  int endc = id.endcap();
2879  int stat = id.station();
2880  int csctype = getCSCType(id);
2881 
2882  // 'float strip' is in the units of 'strip', i.e., angular
2883  // widths of each strip. The counting is from 0.0 at the extreme
2884  // edge of the 'first' strip at one edge of the detector.
2885  float fstrip = -999.;
2886  if (stripType == 0) { // di-strip CLCT
2887  fstrip = strip + 1.;
2888  }
2889  else { // half-strip CLCT
2890  fstrip = strip + 0.5*(halfstrip%2) + 0.25;
2891  }
2892  double clctPhi = clct_analyzer.getStripPhi(layerId, fstrip);
2893  double deltaPhi = clctPhi - hitPhi;
2894  if (deltaPhi < -M_PI) deltaPhi += 2.*M_PI;
2895  else if (deltaPhi > M_PI) deltaPhi -= 2.*M_PI;
2896  deltaPhi *= 1000; // in mrad
2897  if (hitPhi < 0) hitPhi += 2.*M_PI;
2898  if (clctPhi < 0) clctPhi += 2.*M_PI;
2899  if (debug) LogTrace("CSCTriggerPrimitivesReader")
2900  << " clctPhi = " << clctPhi << " hitPhi = " << hitPhi
2901  << " deltaPhi = " << deltaPhi;
2902 
2903  hResolDeltaPhi->Fill(deltaPhi);
2904  if (stripType == 0) { // di-strip CLCT
2905  deltaStrip = distrip - hitHS/4;
2906  hResolDeltaDS->Fill(deltaStrip);
2907  hResolDeltaPhiDS->Fill(deltaPhi);
2908  hPhiDiffVsStripCsc[csctype][0]->Fill(distrip, deltaPhi);
2909  }
2910  else { // half-strip CLCT
2911  deltaStrip = halfstrip - hitHS;
2912  hResolDeltaHS->Fill(deltaStrip);
2913  hResolDeltaPhiHS->Fill(deltaPhi);
2914  hPhiDiffVsStripCsc[csctype][1]->Fill(halfstrip, deltaPhi);
2915  }
2916  if (debug) LogTrace("CSCTriggerPrimitivesReader")
2917  << "Half-strip: MC = " << hitHS << " rec = " << halfstrip
2918  << " pattern type = " << stripType << " delta = " << deltaStrip;
2919 
2920  hPhiRecVsSim->Fill(hitPhi, clctPhi);
2921  hPhiDiffCsc[csctype][0]->Fill(deltaPhi);
2922  hPhiDiffCsc[csctype][endc]->Fill(deltaPhi);
2923  hPhiDiffCsc[csctype][stripType+3]->Fill(deltaPhi);
2924  hClctVsPhi[stat-1]->Fill(clctPhi);
2925  hPhiDiffVsPhi[stat-1]->Fill(clctPhi, fabs(deltaPhi));
2926 
2927  // Histograms to check phi offsets for various pattern types
2928  if (stripType == 1) { // half-strips
2929  double hsperrad = getHsPerRad(csctype); // halfstrips-per-radian
2930  if((endc == 1 && (stat == 1 || stat == 2)) ||
2931  (endc == 2 && (stat == 3 || stat == 4))) {
2932  hPhiDiffPattern[(*digiIt).getPattern()]->Fill(deltaPhi/1000*hsperrad);
2933  }
2934  }
2935  }
2936  // should I comment out this "else"?
2937  //else {
2938  // edm::LogWarning("L1CSCTPEmulatorWrongInput")
2939  // << "+++ Warning in calcResolution(): no matched SimHit"
2940  // << " found! +++\n";
2941  //}
2942 
2943  // "True bend", defined as difference in phi between muon hit
2944  // positions in the first and in the sixth layers.
2945  double phi1 = -999.0, phi6 = -999.0;
2946  vector<CSCCathodeLayerInfo>::const_iterator pli;
2947  for (pli = clctInfo.begin(); pli != clctInfo.end(); pli++) {
2948  CSCDetId layerId = pli->getId();
2949  int layer = layerId.layer();
2950  if (layer == 1 || layer == 6) {
2951  // Get simHits in this layer.
2952  for (const auto& psh : allSimHits) {
2953  // Find detId where simHit is located.
2954  CSCDetId hitId = (CSCDetId)psh.detUnitId();
2955  if (hitId == layerId &&
2956  abs(psh.particleType()) == 13) { // muon hits only
2957  const CSCLayer* csclayer = geom_->layer(layerId);
2958  const auto& thisPoint = csclayer->toGlobal(psh.localPosition());
2959  double phi = thisPoint.phi();
2960  if (layer == 1) phi1 = phi;
2961  else if (layer == 6) phi6 = phi;
2962  break; // simply take the first suitable hit.
2963  }
2964  }
2965  }
2966  }
2967  if (phi1 > -99. && phi6 > -99.) {
2968  double deltaPhi = phi1 - phi6;
2969  if (deltaPhi > M_PI) deltaPhi -= 2.*M_PI;
2970  else if (deltaPhi < -M_PI) deltaPhi += 2.*M_PI;
2971  int csctype = getCSCType(id);
2972  hTrueBendCsc[csctype]->Fill(deltaPhi*1000.); // in mrad
2973  }
2974  }
2975  }
2976  }
2977 }
2978 
2980  const CSCCLCTDigiCollection* clcts,
2981  const edm::PSimHitContainer& allSimHits) {
2982 
2983  // Book histos when called for the first time.
2985 
2986  // Create list of chambers having SimHits.
2987  vector<CSCDetId> chamberIds;
2988  vector<CSCDetId>::const_iterator chamberIdIt;
2989  for (const auto& simHitIt : allSimHits) {
2990  // Find detId where simHit is located.
2991  bool sameId = false;
2992  CSCDetId hitId = (CSCDetId) simHitIt.detUnitId();
2993  // Skip chambers marked as bad (includes most of ME4/2 chambers).
2994  if (checkBadChambers_ && badChambers_->isInBadChamber(hitId)) continue;
2995  //if (hitId.ring() == 4) continue; // skip ME1/A for now.
2996  if (!plotME1A && hitId.ring() == 4) continue;
2997  for (const auto& chamberId : chamberIds) {
2998  if (chamberId.endcap() == hitId.endcap() &&
2999  chamberId.station() == hitId.station() &&
3000  chamberId.ring() == hitId.ring() &&
3001  chamberId.chamber() == hitId.chamber()) {
3002  sameId = true;
3003  break;
3004  }
3005  }
3006  if (!sameId) {
3007  CSCDetId newChamberId(hitId.endcap(), hitId.station(), hitId.ring(),
3008  hitId.chamber(), 0);
3009  chamberIds.push_back(newChamberId);
3010  }
3011  }
3012  LogTrace("CSCTriggerPrimitivesReader")
3013  << "Found SimHits in " << chamberIds.size() << " CSCs";
3014 
3015  bool used[CSCConstants::NUM_LAYERS];
3016  vector<PSimHit> simHitsV[CSCConstants::NUM_LAYERS];
3017  for (const auto& chamberId : chamberIds) {
3018  // Find out how many layers of this chamber have SimHits.
3019  int nLayers = 0;
3020  for (int ilayer = 0; ilayer < CSCConstants::NUM_LAYERS; ilayer++) {
3021  used[ilayer] = false;
3022  simHitsV[ilayer].clear();
3023  }
3024 
3025  int endcap = chamberId.endcap();
3026  int station = chamberId.station();
3027  int ring = chamberId.ring();
3028  int chamber = chamberId.chamber();
3029  for (const auto& simHitIt : allSimHits) {
3030  CSCDetId hitId = (CSCDetId) simHitIt.detUnitId();
3031  if (hitId.endcap() == endcap && hitId.station() == station &&
3032  hitId.ring() == ring && hitId.chamber() == chamber) {
3033  int layer = hitId.layer() - 1;
3034  if (!used[layer] && abs(simHitIt.particleType()) == 13) {
3035  nLayers++;
3036  used[layer] = true;
3037  simHitsV[layer].push_back(simHitIt);
3038  }
3039  }
3040  }
3041  LogTrace("CSCTriggerPrimitivesReader")
3042  << "CSC in ME" << ((endcap == 1) ? "+" : "-")
3043  << station << "/" << ring << "/" << chamber
3044  << " has muon hits in " << nLayers << " layers";
3045 
3046  // If the number of layers with hits is above threshold, look for
3047  // a presence of LCTs.
3048  if (nLayers > 3) { // Should be a parameter.
3049  // Start with the key layer and take the eta of the first hit.
3050  // Really crude; should be improved.
3051  double hitEta = -999.;
3052  for (int ilayer = 2; ilayer < CSCConstants::NUM_LAYERS; ilayer++) {
3053  vector<PSimHit> layerSimHitsV = simHitsV[ilayer];
3054  if (layerSimHitsV.size() > 0) {
3055  LocalPoint hitLP = layerSimHitsV[0].localPosition();
3056  CSCDetId layerId = (CSCDetId)(layerSimHitsV[0]).detUnitId();
3057  const CSCLayer* csclayer = geom_->layer(layerId);
3058  GlobalPoint hitGP = csclayer->toGlobal(hitLP);
3059  hitEta = hitGP.eta();
3060  break;
3061  }
3062  }
3063  if (hitEta < -3.) {
3064  edm::LogWarning("L1CSCTPEmulatorWrongValues")
3065  << "+++ Warning in calcEfficiency(): no SimHit found"
3066  << " where there must be at least " << nLayers << "! +++\n";
3067  continue;
3068  }
3069  int csctype = getCSCType(*chamberIdIt);
3070  hEfficHitsEta[station-1]->Fill(fabs(hitEta));
3071  hEfficHitsEtaCsc[csctype]->Fill(fabs(hitEta));
3072 
3073  bool isALCT = false;
3074  for (auto adetUnitIt = alcts->begin(); adetUnitIt != alcts->end();
3075  adetUnitIt++) {
3076  const CSCDetId& id = (*adetUnitIt).first;
3077  if (id == (*chamberIdIt)) {
3078  const auto& range = (*adetUnitIt).second;
3079  for (auto digiIt = range.first;
3080  digiIt != range.second; digiIt++) {
3081  if (digiIt->isValid()) {
3082  // Check the distance??
3083  LogTrace("CSCTriggerPrimitivesReader") << "ALCT was found";
3084  isALCT = true;
3085  break;
3086  }
3087  }
3088  }
3089  if (isALCT) break;
3090  }
3091  if (isALCT) {
3092  hEfficALCTEta[station-1]->Fill(fabs(hitEta));
3093  hEfficALCTEtaCsc[csctype]->Fill(fabs(hitEta));
3094  }
3095  else {
3096  LogTrace("CSCTriggerPrimitivesReader") << "ALCT was not found";
3097  }
3098 
3099  bool isCLCT = false;
3100  for (auto cdetUnitIt = clcts->begin(); cdetUnitIt != clcts->end();
3101  cdetUnitIt++) {
3102  const CSCDetId& id = (*cdetUnitIt).first;
3103  if (id == (*chamberIdIt)) {
3104  const auto& range = (*cdetUnitIt).second;
3105  for (auto digiIt = range.first;
3106  digiIt != range.second; digiIt++) {
3107  if (digiIt->isValid()) {
3108  // Check the distance??
3109  LogTrace("CSCTriggerPrimitivesReader") << "CLCT was found";
3110  isCLCT = true;
3111  break;
3112  }
3113  }
3114  }
3115  if (isCLCT) break;
3116  }
3117  if (isCLCT) {
3118  hEfficCLCTEta[station-1]->Fill(fabs(hitEta));
3119  hEfficCLCTEtaCsc[csctype]->Fill(fabs(hitEta));
3120  }
3121  else {
3122  LogTrace("CSCTriggerPrimitivesReader") << "CLCT was not found";
3123  }
3124 
3125  }
3126  }
3127 }
3128 
3130  TCanvas *c1 = new TCanvas("c1", "", 0, 0, 500, 640);
3131  string fname = resultsFileNamesPrefix_+"alcts.ps";
3132  TPostScript *ps = new TPostScript(fname.c_str(), 111);
3133 
3134  TPad *pad[MAXPAGES];
3135  for (int i_page = 0; i_page < MAXPAGES; i_page++) {
3136  pad[i_page] = new TPad("", "", .05, .05, .93, .93);
3137  }
3138 
3139  int page = 1;
3140  TText t;
3141  t.SetTextFont(32);
3142  t.SetTextSize(0.025);
3143  char pagenum[7], titl[50];
3144  TPaveLabel *title;
3145 
3146  int max_idh = plotME42 ? CSC_TYPES : CSC_TYPES-1;
3147 
3148  ps->NewPage();
3149  c1->Clear(); c1->cd(0);
3150  title = new TPaveLabel(0.1, 0.94, 0.9, 0.98, "Number of ALCTs");
3151  title->SetFillColor(10); title->Draw();
3152  sprintf(pagenum, "- %d -", page); t.DrawText(0.9, 0.02, pagenum);
3153  gStyle->SetOptStat(111110);
3154  pad[page]->Draw();
3155  pad[page]->Divide(1,3);
3156  pad[page]->cd(1); hAlctPerEvent->Draw();
3157  pad[page]->cd(2); hAlctPerChamber->Draw();
3158  for (int i = 0; i < CSC_TYPES; i++) {
3159  hAlctPerCSC->GetXaxis()->SetBinLabel(i+1, csc_type[i].c_str());
3160  }
3161  // Should be multiplied by 40/nevents to convert to MHz
3162  pad[page]->cd(3); hAlctPerCSC->Draw();
3163  page++; c1->Update();
3164 
3165  for (int endc = 0; endc < MAX_ENDCAPS; endc++) {
3166  ps->NewPage();
3167  c1->Clear(); c1->cd(0);
3168  sprintf(titl, "ALCTs per chamber, endcap %d", endc+1);
3169  title = new TPaveLabel(0.1, 0.94, 0.9, 0.98, titl);
3170  title->SetFillColor(10); title->Draw();
3171  sprintf(pagenum, "- %d -", page); t.DrawText(0.9, 0.02, pagenum);
3172  gStyle->SetOptStat(10);
3173  pad[page]->Draw();
3174  pad[page]->Divide(2,5);
3175  for (int idh = 0; idh < max_idh; idh++) {
3176  if (!plotME1A && idh == 3) continue;
3177  hAlctCsc[endc][idh]->SetMinimum(0.0);
3178  pad[page]->cd(idh+1); hAlctCsc[endc][idh]->Draw();
3179  }
3180  page++; c1->Update();
3181  }
3182 
3183  ps->NewPage();
3184  c1->Clear(); c1->cd(0);
3185  title = new TPaveLabel(0.1, 0.94, 0.9, 0.98, "ALCT quantities");
3186  title->SetFillColor(10); title->Draw();
3187  sprintf(pagenum, "- %d -", page); t.DrawText(0.9, 0.02, pagenum);
3188  gStyle->SetOptStat(111110);
3189  pad[page]->Draw();
3190  pad[page]->Divide(2,3);
3191  pad[page]->cd(1); hAlctValid->Draw();
3192  pad[page]->cd(2); hAlctQuality->Draw();
3193  pad[page]->cd(3); hAlctAccel->Draw();
3194  pad[page]->cd(4); hAlctCollis->Draw();
3195  pad[page]->cd(5); hAlctKeyGroup->Draw();
3196  pad[page]->cd(6); hAlctBXN->Draw();
3197  page++; c1->Update();
3198 
3199  ps->Close();
3200  delete c1;
3201 }
3202 
3204  TCanvas *c1 = new TCanvas("c1", "", 0, 0, 500, 640);
3205  string fname = resultsFileNamesPrefix_+"clcts.ps";
3206  TPostScript *ps = new TPostScript(fname.c_str(), 111);
3207 
3208  TPad *pad[MAXPAGES];
3209  for (int i_page = 0; i_page < MAXPAGES; i_page++) {
3210  pad[i_page] = new TPad("", "", .05, .05, .93, .93);
3211  }
3212 
3213  int page = 1;
3214  TText t;
3215  t.SetTextFont(32);
3216  t.SetTextSize(0.025);
3217  char pagenum[7], titl[50];
3218  TPaveLabel *title;
3219 
3220  ps->NewPage();
3221  c1->Clear(); c1->cd(0);
3222  title = new TPaveLabel(0.1, 0.94, 0.9, 0.98, "Number of CLCTs");
3223  title->SetFillColor(10); title->Draw();
3224  sprintf(pagenum, "- %d -", page); t.DrawText(0.9, 0.02, pagenum);
3225  gStyle->SetOptStat(111110);
3226  pad[page]->Draw();
3227  pad[page]->Divide(1,3);
3228  pad[page]->cd(1); hClctPerEvent->Draw();
3229 
3230  int max_idh = plotME42 ? CSC_TYPES : CSC_TYPES-1;
3231 
3232  edm::LogInfo("CSCTriggerPrimitivesReader") << "\n";
3233  int nbins = hClctPerChamber->GetNbinsX();
3234  for (int ibin = 1; ibin <= nbins; ibin++) {
3235  double f_bin = hClctPerChamber->GetBinContent(ibin);
3236  edm::LogInfo("CSCTriggerPrimitivesReader")
3237  << " # CLCTs/chamber: " << ibin-1 << "; events: " << f_bin << endl;
3238  }
3239 
3240  pad[page]->cd(2); hClctPerChamber->Draw();
3241  for (int i = 0; i < CSC_TYPES; i++) {
3242  hClctPerCSC->GetXaxis()->SetBinLabel(i+1, csc_type[i].c_str());
3243  }
3244  // Should be multiplied by 40/nevents to convert to MHz
3245  pad[page]->cd(3); hClctPerCSC->Draw();
3246  page++; c1->Update();
3247 
3248  for (int endc = 0; endc < MAX_ENDCAPS; endc++) {
3249  ps->NewPage();
3250  c1->Clear(); c1->cd(0);
3251  sprintf(titl, "CLCTs per chamber, endcap %d", endc+1);
3252  title = new TPaveLabel(0.1, 0.94, 0.9, 0.98, titl);
3253  title->SetFillColor(10); title->Draw();
3254  sprintf(pagenum, "- %d -", page); t.DrawText(0.9, 0.02, pagenum);
3255  gStyle->SetOptStat(10);
3256  pad[page]->Draw();
3257  pad[page]->Divide(2,5);
3258  for (int idh = 0; idh < max_idh; idh++) {
3259  if (!plotME1A && idh == 3) continue;
3260  hClctCsc[endc][idh]->SetMinimum(0.0);
3261  pad[page]->cd(idh+1); hClctCsc[endc][idh]->Draw();
3262  }
3263  page++; c1->Update();
3264  }
3265 
3266  ps->NewPage();
3267  c1->Clear(); c1->cd(0);
3268  title = new TPaveLabel(0.1, 0.94, 0.9, 0.98, "CLCT quantities");
3269  title->SetFillColor(10); title->Draw();
3270  sprintf(pagenum, "- %d -", page); t.DrawText(0.9, 0.02, pagenum);
3271  gStyle->SetOptStat(111110);
3272  pad[page]->Draw();
3273  pad[page]->Divide(2,4);
3274  pad[page]->cd(1); hClctValid->Draw();
3275  pad[page]->cd(2); hClctQuality->Draw();
3276  pad[page]->cd(3); hClctSign->Draw();
3277  hClctPattern[1]->SetTitle("CLCT pattern #");
3278  pad[page]->cd(4); hClctPattern[1]->Draw();
3279  pad[page]->cd(5); hClctCFEB->Draw();
3280  pad[page]->cd(7); hClctKeyStrip[1]->Draw();
3281  pad[page]->cd(8); hClctBXN->Draw();
3282  page++; c1->Update();
3283 
3284  ps->NewPage();
3285  c1->Clear(); c1->cd(0);
3286  title = new TPaveLabel(0.1, 0.94, 0.9, 0.98,
3287  "CLCT bend for various chamber types, halfstrips");
3288  title->SetFillColor(10); title->Draw();
3289  sprintf(pagenum, "- %d -", page); t.DrawText(0.9, 0.02, pagenum);
3290  gStyle->SetOptStat(110);
3291  pad[page]->Draw();
3292  pad[page]->Divide(2,5);
3293  for (int idh = 0; idh < max_idh; idh++) {
3294  if (!plotME1A && idh == 3) continue;
3295  pad[page]->cd(idh+1);
3296  hClctBendCsc[idh][1]->GetXaxis()->SetTitle("Pattern bend");
3297  hClctBendCsc[idh][1]->GetYaxis()->SetTitle("Number of LCTs");
3298  hClctBendCsc[idh][1]->Draw();
3299  }
3300  page++; c1->Update();
3301 
3302  ps->Close();
3303  delete c1;
3304 }
3305 
3307  TCanvas *c1 = new TCanvas("c1", "", 0, 0, 500, 640);
3308  string fname = resultsFileNamesPrefix_+"lcts_tmb.ps";
3309  TPostScript *ps = new TPostScript(fname.c_str(), 111);
3310 
3311  TPad *pad[MAXPAGES];
3312  for (int i_page = 0; i_page < MAXPAGES; i_page++) {
3313  pad[i_page] = new TPad("", "", .05, .05, .93, .93);
3314  }
3315 
3316  int page = 1;
3317  TText t;
3318  t.SetTextFont(32);
3319  t.SetTextSize(0.025);
3320  char pagenum[7], titl[50];
3321  TPaveLabel *title;
3322 
3323  int max_idh = plotME42 ? CSC_TYPES : CSC_TYPES-1;
3324 
3325  ps->NewPage();
3326  c1->Clear(); c1->cd(0);
3327  title = new TPaveLabel(0.1, 0.94, 0.9, 0.98, "Number of LCTs");
3328  title->SetFillColor(10); title->Draw();
3329  sprintf(pagenum, "- %d -", page); t.DrawText(0.9, 0.02, pagenum);
3330  gStyle->SetOptStat(111110);
3331  pad[page]->Draw();
3332  pad[page]->Divide(2,2);
3333  pad[page]->cd(1); hLctTMBPerEvent->Draw();
3334  pad[page]->cd(2); hLctTMBPerChamber->Draw();
3335  c1->Update();
3336  for (int i = 0; i < CSC_TYPES; i++) {
3337  hLctTMBPerCSC->GetXaxis()->SetBinLabel(i+1, csc_type[i].c_str());
3338  hCorrLctTMBPerCSC->GetXaxis()->SetBinLabel(i+1, csc_type[i].c_str());
3339  }
3340  // Should be multiplied by 40/nevents to convert to MHz
3341  pad[page]->cd(3); hLctTMBPerCSC->Draw();
3342  pad[page]->cd(4); hCorrLctTMBPerCSC->Draw();
3343  gStyle->SetOptStat(1110);
3344  page++; c1->Update();
3345 
3346  ps->NewPage();
3347  c1->Clear(); c1->cd(0);
3348  title = new TPaveLabel(0.1, 0.94, 0.9, 0.98, "LCT geometry");
3349  title->SetFillColor(10); title->Draw();
3350  sprintf(pagenum, "- %d -", page); t.DrawText(0.9, 0.02, pagenum);
3351  gStyle->SetOptStat(110110);
3352  pad[page]->Draw();
3353  pad[page]->Divide(2,4);
3354  pad[page]->cd(1); hLctTMBEndcap->Draw();
3355  pad[page]->cd(2); hLctTMBStation->Draw();
3356  pad[page]->cd(3); hLctTMBSector->Draw();
3357  pad[page]->cd(4); hLctTMBRing->Draw();
3358  for (int istat = 0; istat < MAX_STATIONS; istat++) {
3359  pad[page]->cd(istat+5); hLctTMBChamber[istat]->Draw();
3360  }
3361  page++; c1->Update();
3362 
3363  for (int endc = 0; endc < MAX_ENDCAPS; endc++) {
3364  ps->NewPage();
3365  c1->Clear(); c1->cd(0);
3366  sprintf(titl, "LCTs per chamber, endcap %d", endc+1);
3367  title = new TPaveLabel(0.1, 0.94, 0.9, 0.98, titl);
3368  title->SetFillColor(10); title->Draw();
3369  sprintf(pagenum, "- %d -", page); t.DrawText(0.9, 0.02, pagenum);
3370  gStyle->SetOptStat(10);
3371  pad[page]->Draw();
3372  pad[page]->Divide(2,5);
3373  for (int idh = 0; idh < max_idh; idh++) {
3374  if (!plotME1A && idh == 3) continue;
3375  hLctTMBCsc[endc][idh]->SetMinimum(0.0);
3376  pad[page]->cd(idh+1); hLctTMBCsc[endc][idh]->Draw();
3377  }
3378  page++; c1->Update();
3379  }
3380 
3381  ps->NewPage();
3382  c1->Clear(); c1->cd(0);
3383  title = new TPaveLabel(0.1, 0.94, 0.9, 0.98, "LCT quantities");
3384  title->SetFillColor(10); title->Draw();
3385  sprintf(pagenum, "- %d -", page); t.DrawText(0.9, 0.02, pagenum);
3386  gStyle->SetOptStat(110110);
3387  pad[page]->Draw();
3388  pad[page]->Divide(2,4);
3389  pad[page]->cd(1); hLctTMBValid->Draw();
3390  pad[page]->cd(2); hLctTMBQuality->Draw();
3391  pad[page]->cd(3); hLctTMBKeyGroup->Draw();
3392  pad[page]->cd(4); hLctTMBKeyStrip->Draw();
3393  pad[page]->cd(5); hLctTMBStripType->Draw();
3394  pad[page]->cd(6); hLctTMBPattern->Draw();
3395  pad[page]->cd(7); hLctTMBBend->Draw();
3396  pad[page]->cd(8); hLctTMBBXN->Draw();
3397  page++; c1->Update();
3398 
3399  ps->Close();
3400  delete c1;
3401 }
3402 
3404  TCanvas *c1 = new TCanvas("c1", "", 0, 0, 500, 640);
3405  string fname = resultsFileNamesPrefix_+"lcts_mpc.ps";
3406  TPostScript *ps = new TPostScript(fname.c_str(), 111);
3407 
3408  TPad *pad[MAXPAGES];
3409  for (int i_page = 0; i_page < MAXPAGES; i_page++) {
3410  pad[i_page] = new TPad("", "", .05, .05, .93, .93);
3411  }
3412 
3413  int page = 1;
3414  TText t;
3415  t.SetTextFont(32);
3416  t.SetTextSize(0.025);
3417  char pagenum[7];
3418  TPaveLabel *title;
3419 
3420  ps->NewPage();
3421  c1->Clear(); c1->cd(0);
3422  title = new TPaveLabel(0.1, 0.94, 0.9, 0.98, "Number of LCTs");
3423  title->SetFillColor(10); title->Draw();
3424  sprintf(pagenum, "- %d -", page); t.DrawText(0.9, 0.02, pagenum);
3425  gStyle->SetOptStat(111110);
3426  pad[page]->Draw();
3427  pad[page]->Divide(1,3);
3428  pad[page]->cd(1); hLctMPCPerEvent->Draw();
3429  for (int i = 0; i < CSC_TYPES; i++) {
3430  hLctMPCPerCSC->GetXaxis()->SetBinLabel(i+1, csc_type[i].c_str());
3431  hCorrLctMPCPerCSC->GetXaxis()->SetBinLabel(i+1, csc_type[i].c_str());
3432  }
3433  // Should be multiplied by 40/nevents to convert to MHz
3434  pad[page]->cd(2); hLctMPCPerCSC->Draw();
3435  pad[page]->cd(3); hCorrLctMPCPerCSC->Draw();
3436  page++; c1->Update();
3437 
3438  ps->NewPage();
3439  c1->Clear(); c1->cd(0);
3440  title = new TPaveLabel(0.1, 0.94, 0.9, 0.98, "LCT geometry");
3441  title->SetFillColor(10); title->Draw();
3442  sprintf(pagenum, "- %d -", page); t.DrawText(0.9, 0.02, pagenum);
3443  gStyle->SetOptStat(110110);
3444  pad[page]->Draw();
3445  pad[page]->Divide(2,4);
3446  pad[page]->cd(1); hLctMPCEndcap->Draw();
3447  pad[page]->cd(2); hLctMPCStation->Draw();
3448  pad[page]->cd(3); hLctMPCSector->Draw();
3449  pad[page]->cd(4); hLctMPCRing->Draw();
3450  for (int istat = 0; istat < MAX_STATIONS; istat++) {
3451  pad[page]->cd(istat+5); hLctMPCChamber[istat]->Draw();
3452  }
3453  page++; c1->Update();
3454 
3455  ps->NewPage();
3456  c1->Clear(); c1->cd(0);
3457  title = new TPaveLabel(0.1, 0.94, 0.9, 0.98, "LCT quantities");
3458  title->SetFillColor(10); title->Draw();
3459  sprintf(pagenum, "- %d -", page); t.DrawText(0.9, 0.02, pagenum);
3460  pad[page]->Draw();
3461  pad[page]->Divide(2,4);
3462  pad[page]->cd(1); hLctMPCValid->Draw();
3463  pad[page]->cd(2); hLctMPCQuality->Draw();
3464  pad[page]->cd(3); hLctMPCKeyGroup->Draw();
3465  pad[page]->cd(4); hLctMPCKeyStrip->Draw();
3466  pad[page]->cd(5); hLctMPCStripType->Draw();
3467  pad[page]->cd(6); hLctMPCPattern->Draw();
3468  pad[page]->cd(7); hLctMPCBend->Draw();
3469  pad[page]->cd(8); hLctMPCBXN->Draw();
3470  page++; c1->Update();
3471 
3472  ps->Close();
3473  delete c1;
3474 }
3475 
3477  TCanvas *c1 = new TCanvas("c1", "", 0, 0, 500, 640);
3478  string fname = resultsFileNamesPrefix_+"lcts_comp.ps";
3479  TPostScript *ps = new TPostScript(fname.c_str(), 111);
3480 
3481  TPad *pad[MAXPAGES];
3482  for (int i_page = 0; i_page < MAXPAGES; i_page++) {
3483  pad[i_page] = new TPad("", "", .05, .05, .93, .93);
3484  }
3485 
3486  int page = 1;
3487  TText t;
3488  t.SetTextFont(32);
3489  t.SetTextSize(0.025);
3490  char pagenum[15];
3491  TPaveLabel *title;
3492  Int_t nbins;
3493 
3494  TText teff;
3495  teff.SetTextFont(32);
3496  teff.SetTextSize(0.08);
3497  char eff[25], titl[60];
3498 
3499  int max_idh = plotME42 ? CSC_TYPES : CSC_TYPES-1;
3500 
3501  for (int endc = 0; endc < MAX_ENDCAPS; endc++) { // endcaps
3502  ps->NewPage();
3503  c1->Clear(); c1->cd(0);
3504  sprintf(titl, "ALCT firmware-emulator: match in number found, endcap %d",
3505  endc+1);
3506  title = new TPaveLabel(0.1, 0.94, 0.9, 0.98, titl);
3507  title->SetFillColor(10); title->Draw();
3508  sprintf(pagenum, "- %d -", page); t.DrawText(0.9, 0.02, pagenum);
3509  //gStyle->SetOptStat(110010);
3510  gStyle->SetOptStat(0);
3511  pad[page]->Draw();
3512  pad[page]->Divide(2,5);
3513  TH1F *hAlctFoundEffVsCsc[MAX_ENDCAPS][CSC_TYPES];
3514  for (int idh = 0; idh < max_idh; idh++) {
3515  if (!plotME1A && idh == 3) continue;
3516  hAlctFoundEffVsCsc[endc][idh] =
3517  (TH1F*)hAlctCompFoundCsc[endc][idh]->Clone();
3518  hAlctFoundEffVsCsc[endc][idh]->Divide(hAlctCompSameNCsc[endc][idh],
3519  hAlctCompFoundCsc[endc][idh],
3520  1., 1., "B");
3521  nbins = hAlctCompFoundCsc[endc][idh]->GetNbinsX();
3522  for (Int_t ibin = 1; ibin <= nbins; ibin++) {
3523  if (hAlctCompFoundCsc[endc][idh]->GetBinContent(ibin) == 0) {
3524  hAlctFoundEffVsCsc[endc][idh]->SetBinContent(ibin, -1.);
3525  hAlctFoundEffVsCsc[endc][idh]->SetBinError(ibin, 0.);
3526  }
3527  }
3528  gPad->Update(); gStyle->SetStatX(0.65);
3529  hAlctFoundEffVsCsc[endc][idh]->SetMinimum(-0.05);
3530  hAlctFoundEffVsCsc[endc][idh]->SetMaximum(1.05);
3531  hAlctFoundEffVsCsc[endc][idh]->GetXaxis()->SetTitleOffset(0.7);
3532  hAlctFoundEffVsCsc[endc][idh]->GetYaxis()->SetTitleOffset(0.8);
3533  hAlctFoundEffVsCsc[endc][idh]->GetXaxis()->SetLabelSize(0.06); // default=0.04
3534  hAlctFoundEffVsCsc[endc][idh]->GetYaxis()->SetLabelSize(0.06); // default=0.04
3535  hAlctFoundEffVsCsc[endc][idh]->GetXaxis()->SetTitleSize(0.07); // default=0.05
3536  hAlctFoundEffVsCsc[endc][idh]->GetYaxis()->SetTitleSize(0.07); // default=0.05
3537  hAlctFoundEffVsCsc[endc][idh]->GetXaxis()->SetTitle("CSC id");
3538  hAlctFoundEffVsCsc[endc][idh]->GetYaxis()->SetTitle("% of same number found");
3539  pad[page]->cd(idh+1); hAlctFoundEffVsCsc[endc][idh]->Draw("e");
3540  double numer = hAlctCompSameNCsc[endc][idh]->Integral();
3541  double denom = hAlctCompFoundCsc[endc][idh]->Integral();
3542  double ratio = 0.0, error = 0.0;
3543  if (denom > 0.) {
3544  ratio = numer/denom;
3545  error = sqrt(ratio*(1.-ratio)/denom);
3546  }
3547  sprintf(eff, "eff = (%4.1f +/- %4.1f)%%", ratio*100., error*100.);
3548  teff.DrawTextNDC(0.3, 0.5, eff);
3549  }
3550  page++; c1->Update();
3551  }
3552 
3553  for (int endc = 0; endc < MAX_ENDCAPS; endc++) { // endcaps
3554  ps->NewPage();
3555  c1->Clear(); c1->cd(0);
3556  sprintf(titl, "ALCT firmware-emulator: exact match, endcap %d", endc+1);
3557  title = new TPaveLabel(0.1, 0.94, 0.9, 0.98, titl);
3558  title->SetFillColor(10); title->Draw();
3559  sprintf(pagenum, "- %d -", page); t.DrawText(0.9, 0.02, pagenum);
3560  //gStyle->SetOptStat(110010);
3561  gStyle->SetOptStat(0);
3562  pad[page]->Draw();
3563  pad[page]->Divide(2,5);
3564  TH1F *hAlctMatchEffVsCsc[MAX_ENDCAPS][CSC_TYPES];
3565  for (int idh = 0; idh < max_idh; idh++) {
3566  if (!plotME1A && idh == 3) continue;
3567  hAlctMatchEffVsCsc[endc][idh] =
3568  (TH1F*)hAlctCompTotalCsc[endc][idh]->Clone();
3569  hAlctMatchEffVsCsc[endc][idh]->Divide(hAlctCompMatchCsc[endc][idh],
3570  hAlctCompTotalCsc[endc][idh],
3571  1., 1., "B");
3572  nbins = hAlctCompTotalCsc[endc][idh]->GetNbinsX();
3573  for (Int_t ibin = 1; ibin <= nbins; ibin++) {
3574  if (hAlctCompTotalCsc[endc][idh]->GetBinContent(ibin) == 0) {
3575  hAlctMatchEffVsCsc[endc][idh]->SetBinContent(ibin, -1.);
3576  hAlctMatchEffVsCsc[endc][idh]->SetBinError(ibin, 0.);
3577  }
3578  }
3579  gPad->Update(); gStyle->SetStatX(0.65);
3580  hAlctMatchEffVsCsc[endc][idh]->SetMinimum(-0.05);
3581  hAlctMatchEffVsCsc[endc][idh]->SetMaximum(1.05);
3582  hAlctMatchEffVsCsc[endc][idh]->GetXaxis()->SetTitleOffset(0.7);
3583  hAlctMatchEffVsCsc[endc][idh]->GetYaxis()->SetTitleOffset(0.8);
3584  hAlctMatchEffVsCsc[endc][idh]->GetXaxis()->SetLabelSize(0.06);
3585  hAlctMatchEffVsCsc[endc][idh]->GetYaxis()->SetLabelSize(0.06);
3586  hAlctMatchEffVsCsc[endc][idh]->GetXaxis()->SetTitleSize(0.07);
3587  hAlctMatchEffVsCsc[endc][idh]->GetYaxis()->SetTitleSize(0.07);
3588  hAlctMatchEffVsCsc[endc][idh]->GetXaxis()->SetTitle("CSC id");
3589  hAlctMatchEffVsCsc[endc][idh]->GetYaxis()->SetTitle("% of exact match");
3590  pad[page]->cd(idh+1); hAlctMatchEffVsCsc[endc][idh]->Draw("e");
3591  double numer = hAlctCompMatchCsc[endc][idh]->Integral();
3592  double denom = hAlctCompTotalCsc[endc][idh]->Integral();
3593  double ratio = 0.0, error = 0.0;
3594  if (denom > 0.) {
3595  ratio = numer/denom;
3596  error = sqrt(ratio*(1.-ratio)/denom);
3597  }
3598  sprintf(eff, "eff = (%4.1f +/- %4.1f)%%", ratio*100., error*100.);
3599  teff.DrawTextNDC(0.3, 0.5, eff);
3600  }
3601  page++; c1->Update();
3602  }
3603 
3604  for (int endc = 0; endc < MAX_ENDCAPS; endc++) {
3605  ps->NewPage();
3606  c1->Clear(); c1->cd(0);
3607  sprintf(titl, "CLCT firmware-emulator: match in number found, endcap %d",
3608  endc+1);
3609  title = new TPaveLabel(0.1, 0.94, 0.9, 0.98, titl);
3610  title->SetFillColor(10); title->Draw();
3611  sprintf(pagenum, "- %d -", page); t.DrawText(0.9, 0.02, pagenum);
3612  //gStyle->SetOptStat(110010);
3613  gStyle->SetOptStat(0);
3614  pad[page]->Draw();
3615  pad[page]->Divide(2,5);
3616  TH1F *hClctFoundEffVsCsc[MAX_ENDCAPS][CSC_TYPES];
3617  for (int idh = 0; idh < max_idh; idh++) {
3618  if (!plotME1A && idh == 3) continue;
3619  hClctFoundEffVsCsc[endc][idh] =
3620  (TH1F*)hClctCompFoundCsc[endc][idh]->Clone();
3621  hClctFoundEffVsCsc[endc][idh]->Divide(hClctCompSameNCsc[endc][idh],
3622  hClctCompFoundCsc[endc][idh],
3623  1., 1., "B");
3624  nbins = hClctCompFoundCsc[endc][idh]->GetNbinsX();
3625  for (Int_t ibin = 1; ibin <= nbins; ibin++) {
3626  if (hClctCompFoundCsc[endc][idh]->GetBinContent(ibin) == 0) {
3627  hClctFoundEffVsCsc[endc][idh]->SetBinContent(ibin, -1.);
3628  hClctFoundEffVsCsc[endc][idh]->SetBinError(ibin, 0.);
3629  }
3630  }
3631  gPad->Update(); gStyle->SetStatX(0.65);
3632  hClctFoundEffVsCsc[endc][idh]->SetMinimum(-0.05);
3633  hClctFoundEffVsCsc[endc][idh]->SetMaximum(1.05);
3634  hClctFoundEffVsCsc[endc][idh]->GetXaxis()->SetTitleOffset(0.7);
3635  hClctFoundEffVsCsc[endc][idh]->GetYaxis()->SetTitleOffset(0.8);
3636  hClctFoundEffVsCsc[endc][idh]->GetXaxis()->SetLabelSize(0.06);
3637  hClctFoundEffVsCsc[endc][idh]->GetYaxis()->SetLabelSize(0.06);
3638  hClctFoundEffVsCsc[endc][idh]->GetXaxis()->SetTitleSize(0.07);
3639  hClctFoundEffVsCsc[endc][idh]->GetYaxis()->SetTitleSize(0.07);
3640  hClctFoundEffVsCsc[endc][idh]->GetXaxis()->SetTitle("CSC id");
3641  hClctFoundEffVsCsc[endc][idh]->GetYaxis()->SetTitle("% of same number found");
3642  pad[page]->cd(idh+1); hClctFoundEffVsCsc[endc][idh]->Draw("e");
3643  double numer = hClctCompSameNCsc[endc][idh]->Integral();
3644  double denom = hClctCompFoundCsc[endc][idh]->Integral();
3645  double ratio = 0.0, error = 0.0;
3646  if (denom > 0.) {
3647  ratio = numer/denom;
3648  error = sqrt(ratio*(1.-ratio)/denom);
3649  }
3650  sprintf(eff, "eff = (%4.1f +/- %4.1f)%%", ratio*100., error*100.);
3651  teff.DrawTextNDC(0.3, 0.5, eff);
3652  }
3653  page++; c1->Update();
3654  }
3655 
3656  for (int endc = 0; endc < MAX_ENDCAPS; endc++) {
3657  ps->NewPage();
3658  c1->Clear(); c1->cd(0);
3659  sprintf(titl, "CLCT firmware-emulator: exact match, endcap %d", endc+1);
3660  title = new TPaveLabel(0.1, 0.94, 0.9, 0.98, titl);
3661  title->SetFillColor(10); title->Draw();
3662  sprintf(pagenum, "- %d -", page); t.DrawText(0.9, 0.02, pagenum);
3663  //gStyle->SetOptStat(110010);
3664  gStyle->SetOptStat(0);
3665  pad[page]->Draw();
3666  pad[page]->Divide(2,5);
3667  TH1F *hClctMatchEffVsCsc[MAX_ENDCAPS][CSC_TYPES];
3668  for (int idh = 0; idh < max_idh; idh++) {
3669  if (!plotME1A && idh == 3) continue;
3670  hClctMatchEffVsCsc[endc][idh] =
3671  (TH1F*)hClctCompTotalCsc[endc][idh]->Clone();
3672  hClctMatchEffVsCsc[endc][idh]->Divide(hClctCompMatchCsc[endc][idh],
3673  hClctCompTotalCsc[endc][idh],
3674  1., 1., "B");
3675  nbins = hClctCompTotalCsc[endc][idh]->GetNbinsX();
3676  for (Int_t ibin = 1; ibin <= nbins; ibin++) {
3677  if (hClctCompTotalCsc[endc][idh]->GetBinContent(ibin) == 0) {
3678  hClctMatchEffVsCsc[endc][idh]->SetBinContent(ibin, -1.);
3679  hClctMatchEffVsCsc[endc][idh]->SetBinError(ibin, 0.);
3680  }
3681  }
3682  gPad->Update(); gStyle->SetStatX(0.65);
3683  hClctMatchEffVsCsc[endc][idh]->SetMinimum(-0.05);
3684  hClctMatchEffVsCsc[endc][idh]->SetMaximum(1.05);
3685  hClctMatchEffVsCsc[endc][idh]->GetXaxis()->SetTitleOffset(0.7);
3686  hClctMatchEffVsCsc[endc][idh]->GetYaxis()->SetTitleOffset(0.8);
3687  hClctMatchEffVsCsc[endc][idh]->GetXaxis()->SetLabelSize(0.06);
3688  hClctMatchEffVsCsc[endc][idh]->GetYaxis()->SetLabelSize(0.06);
3689  hClctMatchEffVsCsc[endc][idh]->GetXaxis()->SetTitleSize(0.07);
3690  hClctMatchEffVsCsc[endc][idh]->GetYaxis()->SetTitleSize(0.07);
3691  hClctMatchEffVsCsc[endc][idh]->GetXaxis()->SetTitle("CSC id");
3692  hClctMatchEffVsCsc[endc][idh]->GetYaxis()->SetTitle("% of exact match");
3693  pad[page]->cd(idh+1); hClctMatchEffVsCsc[endc][idh]->Draw("e");
3694  double numer = hClctCompMatchCsc[endc][idh]->Integral();
3695  double denom = hClctCompTotalCsc[endc][idh]->Integral();
3696  double ratio = 0.0, error = 0.0;
3697  if (denom > 0.) {
3698  ratio = numer/denom;
3699  error = sqrt(ratio*(1.-ratio)/denom);
3700  }
3701  sprintf(eff, "eff = (%4.1f +/- %4.1f)%%", ratio*100., error*100.);
3702  teff.DrawTextNDC(0.3, 0.5, eff);
3703  }
3704  page++; c1->Update();
3705  }
3706 
3707  for (int endc = 0; endc < MAX_ENDCAPS; endc++) {
3708  ps->NewPage();
3709  c1->Clear(); c1->cd(0);
3710  sprintf(titl, "LCT firmware-emulator: match in number found, endcap %d",
3711  endc+1);
3712  title = new TPaveLabel(0.1, 0.94, 0.9, 0.98, titl);
3713  title->SetFillColor(10); title->Draw();
3714  sprintf(pagenum, "- %d -", page); t.DrawText(0.9, 0.02, pagenum);
3715  //gStyle->SetOptStat(110010);
3716  gStyle->SetOptStat(0);
3717  pad[page]->Draw();
3718  pad[page]->Divide(2,5);
3719  TH1F *hLctFoundEffVsCsc[MAX_ENDCAPS][CSC_TYPES];
3720  for (int idh = 0; idh < max_idh; idh++) {
3721  if (!plotME1A && idh == 3) continue;
3722  hLctFoundEffVsCsc[endc][idh] =
3723  (TH1F*)hLctCompFoundCsc[endc][idh]->Clone();
3724  hLctFoundEffVsCsc[endc][idh]->Divide(hLctCompSameNCsc[endc][idh],
3725  hLctCompFoundCsc[endc][idh],
3726  1., 1., "B");
3727  nbins = hLctCompFoundCsc[endc][idh]->GetNbinsX();
3728  for (Int_t ibin = 1; ibin <= nbins; ibin++) {
3729  if (hLctCompFoundCsc[endc][idh]->GetBinContent(ibin) == 0) {
3730  hLctFoundEffVsCsc[endc][idh]->SetBinContent(ibin, -1.);
3731  hLctFoundEffVsCsc[endc][idh]->SetBinError(ibin, 0.);
3732  }
3733  }
3734  gPad->Update(); gStyle->SetStatX(0.65);
3735  hLctFoundEffVsCsc[endc][idh]->SetMinimum(-0.05);
3736  hLctFoundEffVsCsc[endc][idh]->SetMaximum(1.05);
3737  hLctFoundEffVsCsc[endc][idh]->GetXaxis()->SetTitleOffset(0.7);
3738  hLctFoundEffVsCsc[endc][idh]->GetYaxis()->SetTitleOffset(0.8);
3739  hLctFoundEffVsCsc[endc][idh]->GetXaxis()->SetLabelSize(0.06);
3740  hLctFoundEffVsCsc[endc][idh]->GetYaxis()->SetLabelSize(0.06);
3741  hLctFoundEffVsCsc[endc][idh]->GetXaxis()->SetTitleSize(0.07);
3742  hLctFoundEffVsCsc[endc][idh]->GetYaxis()->SetTitleSize(0.07);
3743  hLctFoundEffVsCsc[endc][idh]->GetXaxis()->SetTitle("CSC id");
3744  hLctFoundEffVsCsc[endc][idh]->GetYaxis()->SetTitle("% of same number found");
3745  pad[page]->cd(idh+1); hLctFoundEffVsCsc[endc][idh]->Draw("e");
3746  double numer = hLctCompSameNCsc[endc][idh]->Integral();
3747  double denom = hLctCompFoundCsc[endc][idh]->Integral();
3748  double ratio = 0.0, error = 0.0;
3749  if (denom > 0.) {
3750  ratio = numer/denom;
3751  error = sqrt(ratio*(1.-ratio)/denom);
3752  }
3753  sprintf(eff, "eff = (%4.1f +/- %4.1f)%%", ratio*100., error*100.);
3754  teff.DrawTextNDC(0.3, 0.5, eff);
3755  }
3756  page++; c1->Update();
3757  }
3758 
3759  for (int endc = 0; endc < MAX_ENDCAPS; endc++) {
3760  ps->NewPage();
3761  c1->Clear(); c1->cd(0);
3762  sprintf(titl, "LCT firmware-emulator: exact match, endcap %d", endc+1);
3763  title = new TPaveLabel(0.1, 0.94, 0.9, 0.98, titl);
3764  title->SetFillColor(10); title->Draw();
3765  sprintf(pagenum, "- %d -", page); t.DrawText(0.9, 0.02, pagenum);
3766  //gStyle->SetOptStat(110010);
3767  gStyle->SetOptStat(0);
3768  pad[page]->Draw();
3769  pad[page]->Divide(2,5);
3770  TH1F *hLctMatchEffVsCsc[MAX_ENDCAPS][CSC_TYPES];
3771  for (int idh = 0; idh < max_idh; idh++) {
3772  if (!plotME1A && idh == 3) continue;
3773  hLctMatchEffVsCsc[endc][idh] =
3774  (TH1F*)hLctCompTotalCsc[endc][idh]->Clone();
3775  hLctMatchEffVsCsc[endc][idh]->Divide(hLctCompMatchCsc[endc][idh],
3776  hLctCompTotalCsc[endc][idh],
3777  1., 1., "B");
3778  nbins = hLctCompTotalCsc[endc][idh]->GetNbinsX();
3779  for (Int_t ibin = 1; ibin <= nbins; ibin++) {
3780  if (hLctCompTotalCsc[endc][idh]->GetBinContent(ibin) == 0) {
3781  hLctMatchEffVsCsc[endc][idh]->SetBinContent(ibin, -1.);
3782  hLctMatchEffVsCsc[endc][idh]->SetBinError(ibin, 0.);
3783  }
3784  }
3785  gPad->Update(); gStyle->SetStatX(0.65);
3786  hLctMatchEffVsCsc[endc][idh]->SetMinimum(-0.05);
3787  hLctMatchEffVsCsc[endc][idh]->SetMaximum(1.05);
3788  hLctMatchEffVsCsc[endc][idh]->GetXaxis()->SetTitleOffset(0.7);
3789  hLctMatchEffVsCsc[endc][idh]->GetYaxis()->SetTitleOffset(0.8);
3790  hLctMatchEffVsCsc[endc][idh]->GetXaxis()->SetLabelSize(0.06);
3791  hLctMatchEffVsCsc[endc][idh]->GetYaxis()->SetLabelSize(0.06);
3792  hLctMatchEffVsCsc[endc][idh]->GetXaxis()->SetTitleSize(0.07);
3793  hLctMatchEffVsCsc[endc][idh]->GetYaxis()->SetTitleSize(0.07);
3794  hLctMatchEffVsCsc[endc][idh]->GetXaxis()->SetTitle("CSC id");
3795  hLctMatchEffVsCsc[endc][idh]->GetYaxis()->SetTitle("% of exact match");
3796  pad[page]->cd(idh+1); hLctMatchEffVsCsc[endc][idh]->Draw("e");
3797  double numer = hLctCompMatchCsc[endc][idh]->Integral();
3798  double denom = hLctCompTotalCsc[endc][idh]->Integral();
3799  double ratio = 0.0, error = 0.0;
3800  if (denom > 0.) {
3801  ratio = numer/denom;
3802  error = sqrt(ratio*(1.-ratio)/denom);
3803  }
3804  sprintf(eff, "eff = (%4.1f +/- %4.1f)%%", ratio*100., error*100.);
3805  teff.DrawTextNDC(0.3, 0.5, eff);
3806  }
3807  page++; c1->Update();
3808  }
3809 
3810  ps->Close();
3811  delete c1;
3812 }
3813 
3815  TCanvas *c1 = new TCanvas("c1", "", 0, 0, 500, 640);
3816  string fname = resultsFileNamesPrefix_+"lcts_resol.ps";
3817  TPostScript *ps = new TPostScript(fname.c_str(), 111);
3818 
3819  TPad *pad[MAXPAGES];
3820  for (int i_page = 0; i_page < MAXPAGES; i_page++) {
3821  pad[i_page] = new TPad("", "", .05, .05, .93, .93);
3822  }
3823 
3824  int page = 1;
3825  TText t;
3826  t.SetTextFont(32);
3827  t.SetTextSize(0.025);
3828  char pagenum[7];
3829  TPaveLabel *title;
3830 
3831  int max_idh = plotME42 ? CSC_TYPES : CSC_TYPES-1;
3832 
3833  ps->NewPage();
3834  c1->Clear(); c1->cd(0);
3835  title = new TPaveLabel(0.1, 0.94, 0.9, 0.98, "ALCT resolution");
3836  title->SetFillColor(10); title->Draw();
3837  sprintf(pagenum, "- %d -", page); t.DrawText(0.9, 0.02, pagenum);
3838  gStyle->SetOptStat(111110);
3839  pad[page]->Draw();
3840  pad[page]->Divide(2,2);
3841  gStyle->SetStatX(1.00); gStyle->SetStatY(0.65);
3842  pad[page]->cd(1); hEtaRecVsSim->SetMarkerSize(0.2); hEtaRecVsSim->Draw();
3843  gPad->Update(); gStyle->SetStatX(1.00); gStyle->SetStatY(0.995);
3844  hResolDeltaWG->GetXaxis()->SetTitle("WG_{rec} - WG_{sim}");
3845  hResolDeltaWG->GetXaxis()->SetTitleOffset(1.2);
3846  hResolDeltaWG->GetYaxis()->SetTitle("Entries");
3847  hResolDeltaWG->GetYaxis()->SetTitleOffset(1.9);
3848  hResolDeltaWG->GetXaxis()->SetLabelSize(0.03);
3849  hResolDeltaWG->GetYaxis()->SetLabelSize(0.03);
3850  pad[page]->cd(3); hResolDeltaWG->Draw();
3851  hResolDeltaEta->GetXaxis()->SetNdivisions(505); // twice fewer divisions
3852  hResolDeltaEta->GetXaxis()->SetLabelSize(0.04);
3853  hResolDeltaEta->GetYaxis()->SetLabelSize(0.04);
3854  pad[page]->cd(4); hResolDeltaEta->Draw(); hResolDeltaEta->Fit("gaus","Q");
3855  page++; c1->Update();
3856 
3857  ps->NewPage();
3858  c1->Clear(); c1->cd(0);
3859  title = new TPaveLabel(0.1, 0.94, 0.9, 0.98, "#eta_rec-#eta_sim");
3860  title->SetFillColor(10); title->Draw();
3861  sprintf(pagenum, "- %d -", page); t.DrawText(0.9, 0.02, pagenum);
3862  pad[page]->Draw();
3863  pad[page]->Divide(2,5);
3864  for (int idh = 0; idh < max_idh; idh++) {
3865  if (!plotME1A && idh == 3) continue;
3866  hEtaDiffCsc[idh][0]->GetXaxis()->SetLabelSize(0.07); // default=0.04
3867  hEtaDiffCsc[idh][0]->GetYaxis()->SetLabelSize(0.07);
3868  pad[page]->cd(idh+1); hEtaDiffCsc[idh][0]->Draw();
3869  if (hEtaDiffCsc[idh][0]->GetEntries() > 1)
3870  hEtaDiffCsc[idh][0]->Fit("gaus","Q");
3871  }
3872  page++; c1->Update();
3873 
3874  ps->NewPage();
3875  c1->Clear(); c1->cd(0);
3876  title = new TPaveLabel(0.1, 0.94, 0.9, 0.98, "#eta_rec-#eta_sim, endcap1");
3877  title->SetFillColor(10); title->Draw();
3878  sprintf(pagenum, "- %d -", page); t.DrawText(0.9, 0.02, pagenum);
3879  pad[page]->Draw();
3880  pad[page]->Divide(2,5);
3881  for (int idh = 0; idh < max_idh; idh++) {
3882  if (!plotME1A && idh == 3) continue;
3883  hEtaDiffCsc[idh][1]->GetXaxis()->SetLabelSize(0.07); // default=0.04
3884  hEtaDiffCsc[idh][1]->GetYaxis()->SetLabelSize(0.07);
3885  pad[page]->cd(idh+1); hEtaDiffCsc[idh][1]->Draw();
3886  if (hEtaDiffCsc[idh][1]->GetEntries() > 1)
3887  hEtaDiffCsc[idh][1]->Fit("gaus","Q");
3888  }
3889  page++; c1->Update();
3890 
3891  ps->NewPage();
3892  c1->Clear(); c1->cd(0);
3893  title = new TPaveLabel(0.1, 0.94, 0.9, 0.98, "#eta_rec-#eta_sim, endcap2");
3894  title->SetFillColor(10); title->Draw();
3895  sprintf(pagenum, "- %d -", page); t.DrawText(0.9, 0.02, pagenum);
3896  pad[page]->Draw();
3897  pad[page]->Divide(2,5);
3898  for (int idh = 0; idh < max_idh; idh++) {
3899  if (!plotME1A && idh == 3) continue;
3900  hEtaDiffCsc[idh][2]->GetXaxis()->SetLabelSize(0.07); // default=0.04
3901  hEtaDiffCsc[idh][2]->GetYaxis()->SetLabelSize(0.07);
3902  pad[page]->cd(idh+1); hEtaDiffCsc[idh][2]->Draw();
3903  if (hEtaDiffCsc[idh][2]->GetEntries() > 1)
3904  hEtaDiffCsc[idh][2]->Fit("gaus","Q");
3905  }
3906  page++; c1->Update();
3907 
3908  ps->NewPage();
3909  c1->Clear(); c1->cd(0);
3910  title = new TPaveLabel(0.1, 0.94, 0.9, 0.98,
3911  "#LT#eta_rec-#eta_sim#GT vs #eta_rec");
3912  title->SetFillColor(10); title->Draw();
3913  sprintf(pagenum, "- %d -", page); t.DrawText(0.9, 0.02, pagenum);
3914  //gStyle->SetOptStat(0);
3915  pad[page]->Draw();
3916  pad[page]->Divide(2,2);
3917  TH1F *hMeanEtaDiffVsEta[MAX_STATIONS];
3918  for (int istation = 0; istation < MAX_STATIONS; istation++) {
3919  hMeanEtaDiffVsEta[istation] = (TH1F*)hEtaDiffVsEta[istation]->Clone();
3920  hMeanEtaDiffVsEta[istation]->Divide(hEtaDiffVsEta[istation],
3921  hAlctVsEta[istation], 1., 1.);
3922  hMeanEtaDiffVsEta[istation]->GetXaxis()->SetTitleOffset(1.2);
3923  hMeanEtaDiffVsEta[istation]->GetXaxis()->SetTitle("#eta");
3924  hMeanEtaDiffVsEta[istation]->SetMaximum(0.05);
3925  pad[page]->cd(istation+1); hMeanEtaDiffVsEta[istation]->Draw();
3926  }
3927  page++; c1->Update();
3928 
3929  c1->Clear(); c1->cd(0);
3930  title = new TPaveLabel(0.1, 0.94, 0.9, 0.98,
3931  "#eta_rec-#eta_sim vs wiregroup");
3932  title->SetFillColor(10); title->Draw();
3933  sprintf(pagenum, "- %d -", page); t.DrawText(0.9, 0.02, pagenum);
3934  pad[page]->Draw();
3935  pad[page]->Divide(2,5);
3936  for (int idh = 0; idh < max_idh; idh++) {
3937  if (!plotME1A && idh == 3) continue;
3938  pad[page]->cd(idh+1); hEtaDiffVsWireCsc[idh]->SetMarkerSize(0.2);
3939  hEtaDiffVsWireCsc[idh]->GetXaxis()->SetTitle("Wiregroup");
3940  hEtaDiffVsWireCsc[idh]->GetXaxis()->SetTitleSize(0.07);
3941  hEtaDiffVsWireCsc[idh]->GetXaxis()->SetTitleOffset(1.2);
3942  hEtaDiffVsWireCsc[idh]->GetYaxis()->SetTitle("#eta_rec-#eta_sim");
3943  hEtaDiffVsWireCsc[idh]->GetYaxis()->SetTitleSize(0.07);
3944  hEtaDiffVsWireCsc[idh]->GetXaxis()->SetLabelSize(0.07); // default=0.04
3945  hEtaDiffVsWireCsc[idh]->GetYaxis()->SetLabelSize(0.07);
3946  hEtaDiffVsWireCsc[idh]->Draw();
3947  }
3948  page++; c1->Update();
3949 
3950  ps->NewPage();
3951  c1->Clear(); c1->cd(0);
3952  title = new TPaveLabel(0.1, 0.94, 0.9, 0.98, "#phi resolution");
3953  title->SetFillColor(10); title->Draw();
3954  sprintf(pagenum, "- %d -", page); t.DrawText(0.9, 0.02, pagenum);
3955  gStyle->SetOptStat(111110);
3956  pad[page]->Draw();
3957  pad[page]->Divide(2,2);
3958  gStyle->SetStatX(1.00); gStyle->SetStatY(0.65);
3959  pad[page]->cd(1); hPhiRecVsSim->SetMarkerSize(0.2); hPhiRecVsSim->Draw();
3960  gPad->Update(); gStyle->SetStatX(1.00); gStyle->SetStatY(0.995);
3961  hResolDeltaPhi->GetXaxis()->SetLabelSize(0.04);
3962  hResolDeltaPhi->GetYaxis()->SetLabelSize(0.04);
3963  pad[page]->cd(2); hResolDeltaPhi->Draw(); hResolDeltaPhi->Fit("gaus","Q");
3964  hResolDeltaHS->GetXaxis()->SetTitle("HS_{rec} - HS_{sim}");
3965  hResolDeltaHS->GetXaxis()->SetTitleOffset(1.2);
3966  hResolDeltaHS->GetYaxis()->SetTitle("Entries");
3967  hResolDeltaHS->GetYaxis()->SetTitleOffset(1.7);
3968  hResolDeltaHS->GetXaxis()->SetLabelSize(0.03);
3969  hResolDeltaHS->GetYaxis()->SetLabelSize(0.03);
3970  pad[page]->cd(3); hResolDeltaHS->Draw();
3971  hResolDeltaDS->GetXaxis()->SetTitle("DS_{rec} - DS_{sim}");
3972  hResolDeltaDS->GetXaxis()->SetTitleOffset(1.2);
3973  hResolDeltaDS->GetYaxis()->SetTitle("Entries");
3974  hResolDeltaDS->GetYaxis()->SetTitleOffset(1.6);
3975  hResolDeltaDS->GetXaxis()->SetLabelSize(0.04);
3976  hResolDeltaDS->GetYaxis()->SetLabelSize(0.04);
3977  pad[page]->cd(4); hResolDeltaDS->Draw();
3978  page++; c1->Update();
3979 
3980  ps->NewPage();
3981  c1->Clear(); c1->cd(0);
3982  title = new TPaveLabel(0.1, 0.94, 0.9, 0.98, "#phi_rec-#phi_sim (mrad)");
3983  title->SetFillColor(10); title->Draw();
3984  sprintf(pagenum, "- %d -", page); t.DrawText(0.9, 0.02, pagenum);
3985  pad[page]->Draw();
3986  pad[page]->Divide(2,5);
3987  for (int idh = 0; idh < max_idh; idh++) {
3988  if (!plotME1A && idh == 3) continue;
3989  hPhiDiffCsc[idh][0]->GetXaxis()->SetLabelSize(0.07); // default=0.04
3990  hPhiDiffCsc[idh][0]->GetYaxis()->SetLabelSize(0.07);
3991  pad[page]->cd(idh+1); hPhiDiffCsc[idh][0]->Draw();
3992  if (hPhiDiffCsc[idh][0]->GetEntries() > 1)
3993  hPhiDiffCsc[idh][0]->Fit("gaus","Q");
3994  }
3995  page++; c1->Update();
3996 
3997  ps->NewPage();
3998  c1->Clear(); c1->cd(0);
3999  title = new TPaveLabel(0.1, 0.94, 0.9, 0.98,
4000  "#phi_rec-#phi_sim (mrad), endcap1");
4001  title->SetFillColor(10); title->Draw();
4002  sprintf(pagenum, "- %d -", page); t.DrawText(0.9, 0.02, pagenum);
4003  pad[page]->Draw();
4004  pad[page]->Divide(2,5);
4005  for (int idh = 0; idh < max_idh; idh++) {
4006  if (!plotME1A && idh == 3) continue;
4007  hPhiDiffCsc[idh][1]->GetXaxis()->SetLabelSize(0.07); // default=0.04
4008  hPhiDiffCsc[idh][1]->GetYaxis()->SetLabelSize(0.07);
4009  pad[page]->cd(idh+1); hPhiDiffCsc[idh][1]->Draw();
4010  if (hPhiDiffCsc[idh][1]->GetEntries() > 1)
4011  hPhiDiffCsc[idh][1]->Fit("gaus","Q");
4012  }
4013  page++; c1->Update();
4014 
4015  ps->NewPage();
4016  c1->Clear(); c1->cd(0);
4017  title = new TPaveLabel(0.1, 0.94, 0.9, 0.98,
4018  "#phi_rec-#phi_sim (mrad), endcap2");
4019  title->SetFillColor(10); title->Draw();
4020  sprintf(pagenum, "- %d -", page); t.DrawText(0.9, 0.02, pagenum);
4021  pad[page]->Draw();
4022  pad[page]->Divide(2,5);
4023  for (int idh = 0; idh < max_idh; idh++) {
4024  if (!plotME1A && idh == 3) continue;
4025  hPhiDiffCsc[idh][2]->GetXaxis()->SetLabelSize(0.07); // default=0.04
4026  hPhiDiffCsc[idh][2]->GetYaxis()->SetLabelSize(0.07);
4027  pad[page]->cd(idh+1); hPhiDiffCsc[idh][2]->Draw();
4028  if (hPhiDiffCsc[idh][2]->GetEntries() > 1)
4029  hPhiDiffCsc[idh][2]->Fit("gaus","Q");
4030  }
4031  page++; c1->Update();
4032 
4033  ps->NewPage();
4034  c1->Clear(); c1->cd(0);
4035  title = new TPaveLabel(0.1, 0.94, 0.9, 0.98,
4036  "#LT#phi_rec-#phi_sim#GT (mrad) vs #phi_rec");
4037  title->SetFillColor(10); title->Draw();
4038  sprintf(pagenum, "- %d -", page); t.DrawText(0.9, 0.02, pagenum);
4039  gStyle->SetOptStat(0);
4040  pad[page]->Draw();
4041  pad[page]->Divide(2,2);
4042  TH1F *hMeanPhiDiffVsPhi[MAX_STATIONS];
4043  for (int istation = 0; istation < MAX_STATIONS; istation++) {
4044  hMeanPhiDiffVsPhi[istation] = (TH1F*)hPhiDiffVsPhi[istation]->Clone();
4045  hMeanPhiDiffVsPhi[istation]->Divide(hPhiDiffVsPhi[istation],
4046  hClctVsPhi[istation], 1., 1.);
4047  hMeanPhiDiffVsPhi[istation]->GetXaxis()->SetTitleOffset(1.2);
4048  hMeanPhiDiffVsPhi[istation]->GetYaxis()->SetTitleOffset(1.7);
4049  hMeanPhiDiffVsPhi[istation]->GetXaxis()->SetTitle("#phi");
4050  hMeanPhiDiffVsPhi[istation]->GetYaxis()->SetTitle("#LT#phi_rec-#phi_sim#GT (mrad)");
4051  hMeanPhiDiffVsPhi[istation]->SetMaximum(5.);
4052  pad[page]->cd(istation+1); hMeanPhiDiffVsPhi[istation]->Draw();
4053  }
4054  page++; c1->Update();
4055 
4056  c1->Clear(); c1->cd(0);
4057  title = new TPaveLabel(0.1, 0.94, 0.9, 0.98,
4058  "#phi_rec-#phi_sim (mrad) vs halfstrip #");
4059  title->SetFillColor(10); title->Draw();
4060  sprintf(pagenum, "- %d -", page); t.DrawText(0.9, 0.02, pagenum);
4061  gStyle->SetOptStat(0);
4062  pad[page]->Draw();
4063  pad[page]->Divide(2,5);
4064  for (int idh = 0; idh < max_idh; idh++) {
4065  if (!plotME1A && idh == 3) continue;
4066  pad[page]->cd(idh+1); hPhiDiffVsStripCsc[idh][1]->SetMarkerSize(0.2);
4067  hPhiDiffVsStripCsc[idh][1]->GetXaxis()->SetTitle("Halfstrip");
4068  hPhiDiffVsStripCsc[idh][1]->GetXaxis()->SetTitleOffset(1.4);
4069  hPhiDiffVsStripCsc[idh][1]->GetYaxis()->SetTitle("#phi_rec-#phi_sim (mrad)");
4070  hPhiDiffVsStripCsc[idh][1]->GetXaxis()->SetLabelSize(0.07); // default=0.04
4071  hPhiDiffVsStripCsc[idh][1]->GetYaxis()->SetLabelSize(0.07);
4072  hPhiDiffVsStripCsc[idh][1]->Draw();
4073  }
4074  page++; c1->Update();
4075 
4076  c1->Clear(); c1->cd(0);
4077  title = new TPaveLabel(0.1, 0.94, 0.9, 0.98,
4078  "#phi_rec-#phi_sim, halfstrips only, different patterns");
4079  title->SetFillColor(10); title->Draw();
4080  sprintf(pagenum, "- %d -", page); t.DrawText(0.9, 0.02, pagenum);
4081  gStyle->SetOptStat(111110);
4082  pad[page]->Draw();
4083  pad[page]->Divide(3,3);
4084  int min_pattern, max_pattern;
4085  min_pattern = 2;
4086  max_pattern = CSCConstants::NUM_CLCT_PATTERNS;
4087  for (int idh = min_pattern; idh < max_pattern; idh++) {
4088  hPhiDiffPattern[idh]->GetXaxis()->SetTitle("Halfstrip");
4089  hPhiDiffPattern[idh]->GetXaxis()->SetTitleOffset(1.2);
4090  pad[page]->cd(idh-min_pattern+1); hPhiDiffPattern[idh]->Draw();
4091  // if (hPhiDiffPattern[idh]->GetEntries() > 1)
4092  // hPhiDiffPattern[idh]->Fit("gaus","Q");
4093  }
4094  page++; c1->Update();
4095 
4096  ps->NewPage();
4097  c1->Clear(); c1->cd(0);
4098  title = new TPaveLabel(0.1, 0.94, 0.9, 0.98,
4099  "#phi_1-#phi_6 (mrad), muon SimHits");
4100  title->SetFillColor(10); title->Draw();
4101  sprintf(pagenum, "- %d -", page); t.DrawText(0.9, 0.02, pagenum);
4102  pad[page]->Draw();
4103  pad[page]->Divide(2,5);
4104  for (int idh = 0; idh < max_idh; idh++) {
4105  if (!plotME1A && idh == 3) continue;
4106  hTrueBendCsc[idh]->GetYaxis()->SetTitle("Entries");
4107  hTrueBendCsc[idh]->GetYaxis()->SetTitleSize(0.07);
4108  hTrueBendCsc[idh]->GetXaxis()->SetLabelSize(0.07); // default=0.04
4109  hTrueBendCsc[idh]->GetYaxis()->SetLabelSize(0.07);
4110  pad[page]->cd(idh+1); hTrueBendCsc[idh]->Draw();
4111  }
4112  page++; c1->Update();
4113 
4114  ps->Close();
4115  delete c1;
4116 }
4117 
4119  TCanvas *c1 = new TCanvas("c1", "", 0, 0, 500, 700);
4120  string fname = resultsFileNamesPrefix_+"lcts_effic.ps";
4121  TPostScript *ps = new TPostScript(fname.c_str(), 111);
4122 
4123  TPad *pad[MAXPAGES];
4124  for (int i_page = 0; i_page < MAXPAGES; i_page++) {
4125  pad[i_page] = new TPad("", "", .05, .05, .93, .93);
4126  }
4127 
4128  int page = 1;
4129  TText t;
4130  t.SetTextFont(32);
4131  t.SetTextSize(0.025);
4132  char pagenum[7];
4133  TPaveLabel *title;
4134  char histtitle[60];
4135 
4136  gStyle->SetOptDate(0);
4137  gStyle->SetTitleSize(0.1, ""); // size for pad title; default is 0.02
4138 
4139  int max_idh = plotME42 ? CSC_TYPES : CSC_TYPES-1;
4140 
4141  ps->NewPage();
4142  c1->Clear(); c1->cd(0);
4143  title = new TPaveLabel(0.1, 0.94, 0.9, 0.98, "ALCT efficiency vs #eta");
4144  title->SetFillColor(10); title->Draw();
4145  sprintf(pagenum, "- %d -", page); t.DrawText(0.9, 0.02, pagenum);
4146  gStyle->SetOptStat(0);
4147  pad[page]->Draw();
4148  pad[page]->Divide(2,2);
4149  TH1F *hALCTEffVsEta[MAX_STATIONS];
4150  for (int istation = 0; istation < MAX_STATIONS; istation++) {
4151  hALCTEffVsEta[istation] = (TH1F*)hEfficHitsEta[istation]->Clone();
4152  hALCTEffVsEta[istation]->Divide(hEfficALCTEta[istation],
4153  hEfficHitsEta[istation], 1., 1., "B");
4154  hALCTEffVsEta[istation]->GetXaxis()->SetTitleOffset(1.2);
4155  hALCTEffVsEta[istation]->GetXaxis()->SetTitle("#eta");
4156  hALCTEffVsEta[istation]->SetMaximum(1.05);
4157  sprintf(histtitle, "ALCT efficiency vs #eta, station %d", istation+1);
4158  hALCTEffVsEta[istation]->SetTitle(histtitle);
4159  pad[page]->cd(istation+1); hALCTEffVsEta[istation]->Draw();
4160  }
4161  page++; c1->Update();
4162 
4163  c1->Clear(); c1->cd(0);
4164  title = new TPaveLabel(0.1, 0.94, 0.9, 0.98, "ALCT efficiency vs #eta");
4165  title->SetFillColor(10); title->Draw();
4166  sprintf(pagenum, "- %d -", page); t.DrawText(0.9, 0.02, pagenum);
4167  gStyle->SetOptStat(11111);
4168  pad[page]->Draw();
4169  pad[page]->Divide(2,5);
4170  TH1F *hALCTEffVsEtaCsc[CSC_TYPES];
4171  for (int idh = 0; idh < max_idh; idh++) {
4172  if (!plotME1A && idh == 3) continue;
4173  hALCTEffVsEtaCsc[idh] = (TH1F*)hEfficHitsEtaCsc[idh]->Clone();
4174  hALCTEffVsEtaCsc[idh]->Divide(hEfficALCTEtaCsc[idh],
4175  hEfficHitsEtaCsc[idh], 1., 1., "B");
4176  if (idh == 3 || idh == 4 || idh == 6 || idh == 8) {
4177  gPad->Update(); gStyle->SetStatX(0.43);
4178  }
4179  else {
4180  gPad->Update(); gStyle->SetStatX(1.00);
4181  }
4182  hALCTEffVsEtaCsc[idh]->GetXaxis()->SetTitle("#eta");
4183  hALCTEffVsEtaCsc[idh]->GetXaxis()->SetTitleOffset(0.8);
4184  hALCTEffVsEtaCsc[idh]->GetXaxis()->SetTitleSize(0.07); // default=0.05
4185  hALCTEffVsEtaCsc[idh]->GetXaxis()->SetLabelSize(0.10); // default=0.04
4186  hALCTEffVsEtaCsc[idh]->GetYaxis()->SetLabelSize(0.10);
4187  hALCTEffVsEtaCsc[idh]->SetLabelOffset(0.012, "XY");
4188  hALCTEffVsEtaCsc[idh]->SetMinimum(0.50);
4189  hALCTEffVsEtaCsc[idh]->SetMaximum(1.05);
4190  hALCTEffVsEtaCsc[idh]->SetTitle(csc_type[idh].c_str());
4191  hALCTEffVsEtaCsc[idh]->SetTitleSize(0.1, "");
4192  hALCTEffVsEtaCsc[idh]->SetLineWidth(2);
4193  hALCTEffVsEtaCsc[idh]->SetLineColor(4);
4194  pad[page]->cd(idh+1); gPad->SetGrid(1); hALCTEffVsEtaCsc[idh]->Draw();
4195  }
4196  page++; c1->Update();
4197 
4198  ps->NewPage();
4199  c1->Clear(); c1->cd(0);
4200  title = new TPaveLabel(0.1, 0.94, 0.9, 0.98, "CLCT efficiency vs #eta");
4201  title->SetFillColor(10); title->Draw();
4202  sprintf(pagenum, "- %d -", page); t.DrawText(0.9, 0.02, pagenum);
4203  gStyle->SetOptStat(0);
4204  pad[page]->Draw();
4205  pad[page]->Divide(2,2);
4206  TH1F *hCLCTEffVsEta[MAX_STATIONS];
4207  for (int istation = 0; istation < MAX_STATIONS; istation++) {
4208  hCLCTEffVsEta[istation] = (TH1F*)hEfficHitsEta[istation]->Clone();
4209  hCLCTEffVsEta[istation]->Divide(hEfficCLCTEta[istation],
4210  hEfficHitsEta[istation], 1., 1., "B");
4211  hCLCTEffVsEta[istation]->GetXaxis()->SetTitleOffset(1.2);
4212  hCLCTEffVsEta[istation]->GetXaxis()->SetTitle("#eta");
4213  hCLCTEffVsEta[istation]->SetMaximum(1.05);
4214  sprintf(histtitle, "CLCT efficiency vs #eta, station %d", istation+1);
4215  hCLCTEffVsEta[istation]->SetTitle(histtitle);
4216  pad[page]->cd(istation+1); hCLCTEffVsEta[istation]->Draw();
4217  }
4218  page++; c1->Update();
4219 
4220  c1->Clear(); c1->cd(0);
4221  title = new TPaveLabel(0.1, 0.94, 0.9, 0.98, "CLCT efficiency vs #eta");
4222  title->SetFillColor(10); title->Draw();
4223  sprintf(pagenum, "- %d -", page); t.DrawText(0.9, 0.02, pagenum);
4224  gStyle->SetOptStat(111110);
4225  pad[page]->Draw();
4226  pad[page]->Divide(2,5);
4227  TH1F *hCLCTEffVsEtaCsc[CSC_TYPES];
4228  for (int idh = 0; idh < max_idh; idh++) {
4229  if (!plotME1A && idh == 3) continue;
4230  hCLCTEffVsEtaCsc[idh] = (TH1F*)hEfficHitsEtaCsc[idh]->Clone();
4231  hCLCTEffVsEtaCsc[idh]->Divide(hEfficCLCTEtaCsc[idh],
4232  hEfficHitsEtaCsc[idh], 1., 1., "B");
4233  if (idh == 3 || idh == 4 || idh == 6 || idh == 8) {
4234  gPad->Update(); gStyle->SetStatX(0.43);
4235  }
4236  else {
4237  gPad->Update(); gStyle->SetStatX(1.00);
4238  }
4239  hCLCTEffVsEtaCsc[idh]->GetXaxis()->SetTitle("#eta");
4240  hCLCTEffVsEtaCsc[idh]->GetXaxis()->SetTitleOffset(0.8);
4241  hCLCTEffVsEtaCsc[idh]->GetXaxis()->SetTitleSize(0.07); // default=0.05
4242  hCLCTEffVsEtaCsc[idh]->GetXaxis()->SetLabelSize(0.10); // default=0.04
4243  hCLCTEffVsEtaCsc[idh]->GetYaxis()->SetLabelSize(0.10);
4244  hCLCTEffVsEtaCsc[idh]->SetLabelOffset(0.012, "XY");
4245  hCLCTEffVsEtaCsc[idh]->SetMinimum(0.50);
4246  hCLCTEffVsEtaCsc[idh]->SetMaximum(1.05);
4247  hCLCTEffVsEtaCsc[idh]->SetTitle(csc_type[idh].c_str());
4248  hCLCTEffVsEtaCsc[idh]->SetLineWidth(2);
4249  hCLCTEffVsEtaCsc[idh]->SetLineColor(4);
4250  pad[page]->cd(idh+1); gPad->SetGrid(1); hCLCTEffVsEtaCsc[idh]->Draw();
4251  }
4252  page++; c1->Update();
4253 
4254  ps->Close();
4255  delete c1;
4256 }
4257 
4259  TCanvas *c1 = new TCanvas("c1", "", 0, 0, 500, 640);
4260  TCanvas *c2 = new TCanvas("c2", "", 0, 0, 540, 540);
4261 
4262  TPad *pad[MAXPAGES];
4263  for (int i_page = 0; i_page < MAXPAGES; i_page++) {
4264  pad[i_page] = new TPad("", "", .07, .07, .93, .93);
4265  }
4266 
4267  int page = 1;
4268  TPaveLabel *title;
4269  gStyle->SetOptDate(0);
4270 
4271  int max_idh = plotME42 ? CSC_TYPES : CSC_TYPES-1;
4272 
4273  TPostScript *eps1 = new TPostScript("clcts.eps", 113);
4274  eps1->NewPage();
4275  c1->Clear(); c1->cd(0);
4276  title = new TPaveLabel(0.1, 0.94, 0.9, 0.98, "CLCT quantities");
4277  title->SetFillColor(10); title->Draw();
4278  pad[page]->Draw();
4279  pad[page]->Divide(2,3);
4280  pad[page]->cd(1); hClctQuality->Draw();
4281  pad[page]->cd(2); hClctSign->Draw();
4282  TH1F* hClctPatternTot = (TH1F*)hClctPattern[0]->Clone();
4283  hClctPatternTot->SetTitle("CLCT pattern #");
4284  hClctPatternTot->Add(hClctPattern[0], hClctPattern[1], 1., 1.);
4285  pad[page]->cd(3); hClctPatternTot->Draw();
4286  hClctPattern[0]->SetLineStyle(2); hClctPattern[0]->Draw("same");
4287  hClctPattern[1]->SetLineStyle(3); hClctPattern[1]->Draw("same");
4288  pad[page]->cd(4); hClctCFEB->Draw();
4289  pad[page]->cd(5); hClctStripType->Draw();
4290  TH1F* hClctKeyStripTot = (TH1F*)hClctKeyStrip[0]->Clone();
4291  hClctKeyStripTot->SetTitle("CLCT key strip #");
4292  hClctKeyStripTot->Add(hClctKeyStrip[0], hClctKeyStrip[1], 1., 1.);
4293  pad[page]->cd(6); hClctKeyStripTot->Draw();
4294  page++; c1->Update();
4295  c1->Print("asdf.png");
4296  eps1->Close();
4297 
4298  // Resolution histograms.
4299  if (bookedResolHistos) {
4300  gStyle->SetTitleSize(0.055, ""); // size for pad title; default is 0.02
4301 
4302  TPostScript *eps2 = new TPostScript("alct_deltaWG.eps", 113);
4303  eps2->NewPage();
4304  c2->Clear(); c2->cd(0);
4305  gStyle->SetOptStat(0);
4306  pad[page]->Draw();
4307  pad[page]->Divide(1,1);
4308  hResolDeltaWG->GetXaxis()->SetTitle("WG_{rec} - WG_{sim}");
4309  hResolDeltaWG->GetXaxis()->SetTitleOffset(1.2);
4310  hResolDeltaWG->GetYaxis()->SetTitle("Entries");
4311  hResolDeltaWG->GetYaxis()->SetTitleOffset(1.9);
4312  hResolDeltaWG->GetXaxis()->SetLabelSize(0.04);
4313  hResolDeltaWG->GetYaxis()->SetLabelSize(0.04);
4314  pad[page]->cd(1); hResolDeltaWG->Draw();
4315  page++; c2->Update();
4316  eps2->Close();
4317 
4318  TPostScript *eps3 = new TPostScript("clct_deltaHS.eps", 113);
4319  eps3->NewPage();
4320  c2->Clear(); c2->cd(0);
4321  pad[page]->Draw();
4322  pad[page]->Divide(1,1);
4323  hResolDeltaHS->GetXaxis()->SetTitle("HS_{rec} - HS_{sim}");
4324  hResolDeltaHS->GetXaxis()->SetTitleOffset(1.2);
4325  hResolDeltaHS->GetYaxis()->SetTitle("Entries");
4326  hResolDeltaHS->GetYaxis()->SetTitleOffset(1.7);
4327  hResolDeltaHS->GetXaxis()->SetLabelSize(0.04); // default=0.04
4328  hResolDeltaHS->GetYaxis()->SetLabelSize(0.04);
4329  pad[page]->cd(1); hResolDeltaHS->Draw();
4330  page++; c2->Update();
4331  eps3->Close();
4332 
4333  TPostScript *eps4 = new TPostScript("clct_deltaDS.eps", 113);
4334  eps4->NewPage();
4335  c2->Clear(); c2->cd(0);
4336  gStyle->SetOptStat(0);
4337  pad[page]->Draw();
4338  pad[page]->Divide(1,1);
4339  hResolDeltaDS->GetXaxis()->SetTitle("DS_{rec} - DS_{sim}");
4340  hResolDeltaDS->GetXaxis()->SetTitleOffset(1.2);
4341  hResolDeltaDS->GetYaxis()->SetTitle("Entries");
4342  hResolDeltaDS->GetYaxis()->SetTitleOffset(1.6);
4343  hResolDeltaDS->GetXaxis()->SetLabelSize(0.04); // default=0.04
4344  hResolDeltaDS->GetYaxis()->SetLabelSize(0.04);
4345  pad[page]->cd(1); hResolDeltaDS->Draw();
4346  page++; c2->Update();
4347  eps4->Close();
4348 
4349  TPostScript *eps5 = new TPostScript("clct_deltaPhi_hs.eps", 113);
4350  eps5->NewPage();
4351  c1->Clear(); c1->cd(0);
4352  title = new TPaveLabel(0.1, 0.94, 0.9, 0.98,
4353  "#phi_rec-#phi_sim (mrad), halfstrips only");
4354  title->SetFillColor(10); title->Draw();
4355  gStyle->SetTitleSize(0.1, ""); // size for pad title; default is 0.02
4356  gStyle->SetOptStat(111110);
4357  pad[page]->Draw();
4358  pad[page]->Divide(2,5);
4359  for (int idh = 0; idh < max_idh; idh++) {
4360  if (!plotME1A && idh == 3) continue;
4361  pad[page]->cd(idh+1); hPhiDiffCsc[idh][4]->Draw();
4362  //if (hPhiDiffCsc[idh][4]->GetEntries() > 1)
4363  //hPhiDiffCsc[idh][4]->Fit("gaus","Q");
4364  //hPhiDiffCsc[idh][4]->GetXaxis()->SetTitle("#phi_{rec} - #phi_{sim} (mrad)");
4365  //hPhiDiffCsc[idh][4]->GetXaxis()->SetTitleSize(0.06);
4366  //hPhiDiffCsc[idh][4]->GetXaxis()->SetTitleOffset(0.9);
4367  hPhiDiffCsc[idh][4]->GetYaxis()->SetTitle("Entries ");
4368  hPhiDiffCsc[idh][4]->GetYaxis()->SetTitleSize(0.07);
4369  hPhiDiffCsc[idh][4]->GetYaxis()->SetTitleOffset(1.0);
4370  hPhiDiffCsc[idh][4]->GetXaxis()->SetLabelSize(0.10); // default=0.04
4371  hPhiDiffCsc[idh][4]->GetYaxis()->SetLabelSize(0.10);
4372  hPhiDiffCsc[idh][4]->SetLabelOffset(0.012, "XY");
4373  }
4374  page++; c1->Update();
4375  eps5->Close();
4376  }
4377 
4378  // Efficiency histograms.
4379  if (bookedEfficHistos) {
4380  TPostScript *eps6 = new TPostScript("alct_effic.eps", 113);
4381  eps6->NewPage();
4382  c1->Clear(); c1->cd(0);
4383  title = new TPaveLabel(0.1, 0.94, 0.9, 0.98, "ALCT efficiency vs #eta");
4384  title->SetFillColor(10); title->Draw();
4385  gStyle->SetOptStat(0);
4386  pad[page]->Draw();
4387  pad[page]->Divide(2,5);
4388  TH1F *hALCTEffVsEtaCsc[CSC_TYPES];
4389  for (int idh = 0; idh < max_idh; idh++) {
4390  if (!plotME1A && idh == 3) continue;
4391  hALCTEffVsEtaCsc[idh] = (TH1F*)hEfficHitsEtaCsc[idh]->Clone();
4392  hALCTEffVsEtaCsc[idh]->Divide(hEfficALCTEtaCsc[idh],
4393  hEfficHitsEtaCsc[idh], 1., 1., "B");
4394  hALCTEffVsEtaCsc[idh]->GetXaxis()->SetTitle("#eta");
4395  hALCTEffVsEtaCsc[idh]->GetXaxis()->SetTitleOffset(0.8);
4396  hALCTEffVsEtaCsc[idh]->GetXaxis()->SetTitleSize(0.07); // default=0.05
4397  hALCTEffVsEtaCsc[idh]->GetXaxis()->SetLabelSize(0.10); // default=0.04
4398  hALCTEffVsEtaCsc[idh]->GetYaxis()->SetLabelSize(0.10);
4399  hALCTEffVsEtaCsc[idh]->SetLabelOffset(0.012, "XY");
4400  hALCTEffVsEtaCsc[idh]->SetMinimum(0.50);
4401  hALCTEffVsEtaCsc[idh]->SetMaximum(1.05);
4402  hALCTEffVsEtaCsc[idh]->SetTitle(csc_type[idh].c_str());
4403  hALCTEffVsEtaCsc[idh]->SetTitleSize(0.1, "");
4404  hALCTEffVsEtaCsc[idh]->SetLineWidth(2);
4405  hALCTEffVsEtaCsc[idh]->SetLineColor(4);
4406  hALCTEffVsEtaCsc[idh]->SetLineColor(4);
4407  pad[page]->cd(idh+1); gPad->SetGrid(1); hALCTEffVsEtaCsc[idh]->Draw();
4408  }
4409  page++; c1->Update();
4410  eps6->Close();
4411 
4412  TPostScript *eps7 = new TPostScript("clct_effic.eps", 113);
4413  eps7->NewPage();
4414  c1->Clear(); c1->cd(0);
4415  title = new TPaveLabel(0.1, 0.94, 0.9, 0.98, "CLCT efficiency vs #eta");
4416  title->SetFillColor(10); title->Draw();
4417  gStyle->SetOptStat(0);
4418  pad[page]->Draw();
4419  pad[page]->Divide(2,5);
4420  TH1F *hCLCTEffVsEtaCsc[CSC_TYPES];
4421  for (int idh = 0; idh < max_idh; idh++) {
4422  if (!plotME1A && idh == 3) continue;
4423  hCLCTEffVsEtaCsc[idh] = (TH1F*)hEfficHitsEtaCsc[idh]->Clone();
4424  hCLCTEffVsEtaCsc[idh]->Divide(hEfficCLCTEtaCsc[idh],
4425  hEfficHitsEtaCsc[idh], 1., 1., "B");
4426  hCLCTEffVsEtaCsc[idh]->GetXaxis()->SetTitle("#eta");
4427  hCLCTEffVsEtaCsc[idh]->GetXaxis()->SetTitleOffset(0.8);
4428  hCLCTEffVsEtaCsc[idh]->GetXaxis()->SetTitleSize(0.07); // default=0.05
4429  hCLCTEffVsEtaCsc[idh]->GetXaxis()->SetLabelSize(0.10); // default=0.04
4430  hCLCTEffVsEtaCsc[idh]->GetYaxis()->SetLabelSize(0.10);
4431  hCLCTEffVsEtaCsc[idh]->SetLabelOffset(0.012, "XY");
4432  hCLCTEffVsEtaCsc[idh]->SetMinimum(0.50);
4433  hCLCTEffVsEtaCsc[idh]->SetMaximum(1.05);
4434  hCLCTEffVsEtaCsc[idh]->SetTitle(csc_type[idh].c_str());
4435  hCLCTEffVsEtaCsc[idh]->SetLineWidth(2);
4436  hCLCTEffVsEtaCsc[idh]->SetLineColor(4);
4437  pad[page]->cd(idh+1); gPad->SetGrid(1); hCLCTEffVsEtaCsc[idh]->Draw();
4438  }
4439  page++; c1->Update();
4440  eps7->Close();
4441  }
4442  delete c1;
4443  delete c2;
4444 }
4445 
4447 CSCTriggerPrimitivesReader::getGlobalPosition(unsigned int rawId, int keyWg, int keyHS) const
4448 {
4449  // taken from https://github.com/cms-sw/cmssw/blob/dc9f78b6af4ad56c9342cf14041b6485a60b0691/L1Trigger/CSCTriggerPrimitives/src/CSCTriggerPrimitivesReaderGEM.cc
4450  CSCDetId cscId = CSCDetId(rawId);
4451  int ring = cscId.ring();
4452  if (cscId.station() == 1 and cscId.ring() == 1 and (lut_wg_vs_hs_me1b[keyWg][0] <0 || keyHS>=128)){
4453  ring =4;
4454  if (keyHS >= 128)
4455  keyHS = keyHS-128;
4456  }
4457 
4458  CSCDetId key_id(cscId.endcap(), cscId.station(), ring,
4460  auto cscChamber = geom_->chamber(cscId);
4461  float fractional_strip = 0.5 * (keyHS + 1) - 0.25;
4462  auto layer_geo = cscChamber->layer(CSCConstants::KEY_CLCT_LAYER)->geometry();
4463  // LCT::getKeyWG() also starts from 0
4464  float wire = layer_geo->middleWireOfGroup(keyWg + 1);
4465  LocalPoint csc_intersect = layer_geo->intersectionOfStripAndWire(fractional_strip, wire);
4466  GlobalPoint csc_gp = geom_->idToDet(key_id)->surface().toGlobal(csc_intersect);
4467  return csc_gp;
4468 
4469 }
4470 
4471 
4472 bool CSCTriggerPrimitivesReader::doesALCTCrossCLCT(CSCDetId id, int key_wg, int key_hs) const
4473 {
4474 
4475  bool isME11 = (id.station() ==1 and (id.ring()==1 or id.ring()==4));
4476  if (not isME11) return true;
4477 
4478  int theEndcap = (id.endcap() == 1)?1 : 2;
4479 
4480  if (key_hs > CSCConstants::MAX_HALF_STRIP_ME1B)
4481  {
4482  key_hs = key_hs - CSCConstants::MAX_HALF_STRIP_ME1B -1;//convert it from 128-223 -> 0-95
4483  if ( !gangedME1a )
4484  {
4485  // wrap around ME11 HS number for -z endcap
4486  if (theEndcap==2) key_hs = CSCConstants::MAX_HALF_STRIP_ME1A_UNGANGED - key_hs;
4487  if ( key_hs >= lut_wg_vs_hs_me1a[key_wg][0] &&
4488  key_hs <= lut_wg_vs_hs_me1a[key_wg][1] ) return true;
4489  return false;
4490  }
4491  else
4492  {
4493  if (theEndcap==2) key_hs = CSCConstants::MAX_HALF_STRIP_ME1A_GANGED - key_hs;
4494  if ( key_hs >= lut_wg_vs_hs_me1ag[key_wg][0] &&
4495  key_hs <= lut_wg_vs_hs_me1ag[key_wg][1] ) return true;
4496  return false;
4497  }
4498  }
4499  if ( key_hs <= CSCConstants::MAX_HALF_STRIP_ME1B)
4500  {
4501  if (theEndcap==2) key_hs = CSCConstants::MAX_HALF_STRIP_ME1B - key_hs;
4502  if ( key_hs >= lut_wg_vs_hs_me1b[key_wg][0] &&
4503  key_hs <= lut_wg_vs_hs_me1b[key_wg][1] ) return true;
4504  }
4505  return false;
4506 }
4507 
4508 
4509 
4510 
4511 // Returns chamber type (0-9) according to the station and ring number
4513  int type = -999;
4514 
4515  if (id.station() == 1) {
4516  type = (id.triggerCscId()-1)/3;
4517  if (id.ring() == 4) {
4518  type = 3;
4519  }
4520  }
4521  else { // stations 2-4
4522  type = 3 + id.ring() + 2*(id.station()-2);
4523  }
4524 
4525  assert(type >= 0 && type < CSC_TYPES);
4526  return type;
4527 }
4528 
4529 // Returns halfstrips-per-radian for different CSC types
4531  return (NCHAMBERS[idh]*MAX_HS[idh]/TWOPI);
4532 }
4533 
4535 //-------------------------------------------------
#define LogDebug(id)
RunNumber_t run() const
Definition: EventID.h:39
TH1F * hClctCompTotalCsc[MAX_ENDCAPS][CSC_TYPES]