CMS 3D CMS Logo

RPCNoise.cc
Go to the documentation of this file.
1 // -*- C++ -*-
2 //
3 // Package: RPCNoise
4 // Class: RPCNoise
5 //
13 //
14 // Original Author: Michael Henry Schmitt
15 // Created: Thu Oct 30 21:31:44 CET 2008
16 // $Id: RPCNoise.cc,v 1.3 2010/08/07 14:55:55 wmtan Exp $
17 //
18 //
19 // system include files
20 #include <memory>
21 #include <iostream>
22 #include <vector>
23 #include <map>
24 #include <string>
25 #include <iomanip>
26 #include <fstream>
27 #include <ctime>
28 
29 // user include files
32 
35 
37 
45 
49 
52 //#include "EventFilter/RPCRawToDigi/interface/RPCRawSynchro.h"
53 
57 
63 
66 
71 
72 #include "TVector3.h"
73 #include "TH1F.h"
74 #include "TH2F.h"
75 #include "TFile.h"
76 #include "TString.h"
77 #include "TTree.h"
78 #include "TProfile.h"
79 
80 using namespace std;
81 using namespace edm;
82 
83 //
84 // class declaration
85 //
86 
87 class RPCNoise : public edm::one::EDFilter<> {
88 public:
89  explicit RPCNoise(const edm::ParameterSet &);
90  ~RPCNoise() override;
91 
92 private:
93  void beginJob() override;
94  bool filter(edm::Event &, const edm::EventSetup &) override;
95  void endJob() override;
96 
97  // counters
100  int iRun;
101  int iEvent;
105  // control parameters
111  // histogram
113  // The root file for the histograms.
115  // histograms
116  TH1F *nWires;
117  TH1F *nStrips;
118  TH1F *nWiresH;
119  TH1F *nStripsH;
120  TH1F *nDTDigis;
121  TH1F *nDTDigisH;
122  TH1F *t0All;
123  TH1F *t0AllH;
124  TH1F *nDTDigisIn;
125  TH1F *nDTDigisInH;
126  TH1F *nDTDigisOut;
128  TH1F *fDTDigisOut;
130  TH1F *nRPCRecHits;
132  TProfile *hitsVsSerial;
133  TProfile *orbitVsSerial;
134  TProfile *hitsVsOrbit;
135  TH1F *dOrbit;
136  TH1F *RPCBX;
137  TH1F *RPCClSize;
138  TH1F *RPCBXH;
139  TH1F *RPCClSizeH;
140  TH1F *rpcStation;
141  TH1F *rpcStationH;
142  TH1F *rpcRing;
143  TH1F *rpcRingH;
144  TH1F *rpcSector;
145  TH1F *rpcSectorH;
146  TH1F *rpcLayer;
147  TH1F *rpcLayerH;
148  TProfile *rpcStationVsOrbit;
149  TProfile *rpcSectorVsOrbit;
150  TProfile *rpcRingVsOrbit;
151  TH1F *rpcCorner;
152  TH1F *rpcCornerH;
153  TProfile *rpcCornerVsOrbit;
154 };
155 
157  histogramFileName = pset.getUntrackedParameter<std::string>("histogramFileName", "histos.root");
158  fillHistograms = pset.getUntrackedParameter<bool>("fillHistograms", true);
159  nRPCHitsCut = pset.getUntrackedParameter<int>("nRPCHitsCut", 40);
160  nCSCStripsCut = pset.getUntrackedParameter<int>("nCSCStripsCut", 50);
161  nCSCWiresCut = pset.getUntrackedParameter<int>("nCSCWiresCut", 10);
162  nDTDigisCut = pset.getUntrackedParameter<int>("nDTDigisCut", 10);
163 }
165 
167  // initialize variables
168  nEventsAnalyzed = 0;
169  nEventsSelected = 0;
170  iRun = 0;
171  iEvent = 0;
172  firstOrbit = lastOrbit = thisOrbit = 0;
173 
174  if (fillHistograms) {
175  // Create the root file for the histograms
176  theHistogramFile = new TFile(histogramFileName.c_str(), "RECREATE");
177  theHistogramFile->cd();
178  // book histograms
179  nWires = new TH1F("nWires", "number of wire digis", 121, -0.5, 120.5);
180  nStrips = new TH1F("nStrips", "number of strip digis", 201, -0.5, 200.5);
181  nWiresH = new TH1F("nWiresH", "number of wire digis HIGH", 121, -0.5, 120.5);
182  nStripsH = new TH1F("nStripsH", "number of strip digis HIGH", 201, -0.5, 200.5);
183  nDTDigis = new TH1F("nDTDigis", "number of DT digis", 201, -0.5, 200.5);
184  nDTDigisH = new TH1F("nDTDigisH", "number of DT digis HIGH", 201, -0.5, 200.5);
185  nDTDigisIn = new TH1F("nDTDigisIn", "N DT digis in window", 75, 0., 150.);
186  nDTDigisInH = new TH1F("nDTDigisInH", "N DT digis in window HIGH", 75, 0., 150.);
187  nDTDigisOut = new TH1F("nDTDigisOut", "N DT digis out window", 75, 0., 150.);
188  nDTDigisOutH = new TH1F("nDTDigisOutH", "N DT digis out window HIGH", 75, 0., 150.);
189  fDTDigisOut = new TH1F("fDTDigisOut", "fraction DT digis outside window", 55, 0., 1.1);
190  fDTDigisOutH = new TH1F("fDTDigisOutH", "fraction DT digis outside window HIGH", 55, 0., 1.1);
191 
192  t0All = new TH1F("t0All", "t0", 700, 0., 7000.);
193  t0AllH = new TH1F("t0AllH", "t0 HIGH", 700, 0., 7000.);
194  RPCBX = new TH1F("RPCBX", "RPC BX", 21, -10.5, 10.5);
195  RPCBXH = new TH1F("RPCBXH", "RPC BX HIGH", 21, -10.5, 10.5);
196  RPCClSize = new TH1F("RPCClSize", "RPC cluster size", 61, -0.5, 60.5);
197  RPCClSizeH = new TH1F("RPCClSizeH", "RPC cluster size HIGH", 61, -0.5, 60.5);
198 
199  nRPCRecHits = new TH1F("nRPCRecHits", "number of RPC RecHits", 101, -0.5, 100.5);
200  nRPCRecHitsLong = new TH1F("nRPCRecHitsLong", "number of RPC RecHits", 601, -0.5, 600.5);
201  hitsVsSerial = new TProfile("hitsVsSerial", "mean RPC hits vs serial event number", 4000, 0., 40000., 0., 1000.);
202  orbitVsSerial =
203  new TProfile("orbitVsSerial", "relative orbit number vs serial event number", 4000, 0., 40000., 0., 1.e10);
204  hitsVsOrbit = new TProfile("hitsVsOrbit", "mean RPC hits vs orbit number", 3000, 0., 1200000., 0., 1000.);
205  dOrbit = new TH1F("dOrbit", "difference in orbit number", 121, -0.5, 120.5);
206 
207  rpcStation = new TH1F("rpcStation", "RPC station", 6, -0.5, 5.5);
208  rpcStationH = new TH1F("rpcStationH", "RPC station HIGH", 6, -0.5, 5.5);
209  rpcRing = new TH1F("rpcRing", "RPC ring", 9, -4.5, 4.5);
210  rpcRingH = new TH1F("rpcRingH", "RPC ring HIGH", 9, -4.5, 4.5);
211  rpcSector = new TH1F("rpcSector", "RPC sector", 15, -0.5, 14.5);
212  rpcSectorH = new TH1F("rpcSectorH", "RPC sector HIGH", 15, -0.5, 14.5);
213  rpcLayer = new TH1F("rpcLayer", "RPC layer", 4, -0.5, 3.5);
214  rpcLayerH = new TH1F("rpcLayerH", "RPC layer HIGH", 4, -0.5, 3.5);
215  rpcStationVsOrbit = new TProfile("rpcStationVsOrbit", "mean RPC station vs. Orbit", 3000, 0., 1200000., 0., 20.);
216  rpcSectorVsOrbit = new TProfile("rpcSectorVsOrbit", "mean RPC sector vs. Orbit", 3000, 0., 1200000., 0., 20.);
217  rpcRingVsOrbit = new TProfile("rpcRingVsOrbit", "mean RPC ring vs. Orbit", 3000, 0., 1200000., -20., 20.);
218  rpcCorner = new TH1F("rpcCorner", "special corner designation", 4, -0.5, 3.5);
219  rpcCornerH = new TH1F("rpcCornerH", "special corner designation HIGH", 4, -0.5, 3.5);
220  rpcCornerVsOrbit = new TProfile("rpcCornerVsOrbit", "special corner vs. Orbit", 3000, 0., 1200000., -20., 20.);
221  }
222 }
223 
225  std::cout << "\n\t===============================================================\n"
226  << "\tnumber of events analyzed = " << nEventsAnalyzed << std::endl
227  << "\tnumber of events selected = " << nEventsSelected << std::endl
228  << "\tfirst and last orbit number : " << firstOrbit << ", " << lastOrbit << ", "
229  << lastOrbit - firstOrbit << std::endl
230  << "\t===============================================================\n\n";
231 
232  if (fillHistograms) {
233  // Write the histos to file
234  printf("\n\n======= write out my histograms ====\n\n");
235  theHistogramFile->cd();
236  nWires->Write();
237  nStrips->Write();
238  nWiresH->Write();
239  nStripsH->Write();
240  nDTDigis->Write();
241  nDTDigisH->Write();
242  nDTDigisIn->Write();
243  nDTDigisInH->Write();
244  nDTDigisOut->Write();
245  nDTDigisOutH->Write();
246  fDTDigisOut->Write();
247  fDTDigisOutH->Write();
248  nRPCRecHits->Write();
249  nRPCRecHitsLong->Write();
250  hitsVsSerial->Write();
251  hitsVsOrbit->Write();
252  orbitVsSerial->Write();
253  t0All->Write();
254  t0AllH->Write();
255  RPCBX->Write();
256  RPCClSize->Write();
257  RPCBXH->Write();
258  RPCClSizeH->Write();
259  rpcStation->Write();
260  rpcStationH->Write();
261  rpcRing->Write();
262  rpcRingH->Write();
263  rpcSector->Write();
264  rpcSectorH->Write();
265  rpcLayer->Write();
266  rpcLayerH->Write();
267  dOrbit->Write();
268  rpcStationVsOrbit->Write();
269  rpcSectorVsOrbit->Write();
270  rpcRingVsOrbit->Write();
271  rpcCorner->Write();
272  rpcCornerH->Write();
273  rpcCornerVsOrbit->Write();
274  theHistogramFile->Close();
275  }
276 }
277 
279  bool selectThisEvent = false;
280 
281  // increment counter
282  nEventsAnalyzed++;
283 
284  iRun = event.id().run();
285  iEvent = event.id().event();
286 
287  bool printThisLine = (nEventsAnalyzed % 100 == 0);
288  if (printThisLine) {
289  std::cout << "======================================"
290  << " analyzed= " << nEventsAnalyzed << ", selected= " << nEventsSelected << "\trun,event: " << iRun
291  << ", " << iEvent << std::endl;
292  }
293 
294  /*
295  const edm::Timestamp jTime = event.time();
296  unsigned int sec = jTime.value() >> 32;
297  unsigned int usec = 0xFFFFFFFF & jTime.value() ;
298  double floatTime = sec + usec/(float)1000000.;
299  */
300 
301  // first event gives
302  // sec = 1225315493
303  // orbit = 202375185
304  // bx = 764
305  // mtime = 205094517
306  int bx = event.bunchCrossing();
307  int thisOrbit = event.orbitNumber();
308  long mTime = 3564 * thisOrbit + bx;
309  if (firstOrbit == 0) {
310  firstOrbit = thisOrbit;
311  lastOrbit = thisOrbit;
312  }
313  int deltaOrbit = thisOrbit - lastOrbit;
314  lastOrbit = thisOrbit;
315  int relativeOrbit = thisOrbit - firstOrbit;
316 
317  if (fillHistograms) {
318  dOrbit->Fill(deltaOrbit);
319  }
320 
321  if (nEventsAnalyzed < 200) {
322  std::cout << iEvent
323  // << "\tsec,usec: " << sec << ", " << usec
324  // << "\tfloatTime= " << std::setprecision(16) << floatTime
325  // << "\tctime: " << ctime(sec)
326  << "\torbit,bx,mTime: " << thisOrbit << "," << bx << "," << mTime << "\tdelta= " << deltaOrbit
327  << std::endl;
328  }
329 
330  // ================
331  // RPC recHits
332  // ================
334  event.getByLabel("rpcRecHits", "", rpcRecHits);
335 
336  // count the number of RPC rechits
337  int nRPC = 0;
339  for (rpcIt = rpcRecHits->begin(); rpcIt != rpcRecHits->end(); rpcIt++) {
340  // RPCDetId id = (RPCDetId)(*rpcIt).rpcId();
341  // LocalPoint rhitlocal = (*rpcIt).localPosition();
342  nRPC++;
343  }
344 
345  // loop again, this time fill histograms
346  for (rpcIt = rpcRecHits->begin(); rpcIt != rpcRecHits->end(); rpcIt++) {
347  RPCDetId id = (RPCDetId)(*rpcIt).rpcId();
348  int kRegion = id.region();
349  int kStation = id.station();
350  int kRing = id.ring();
351  int kSector = id.sector();
352  int kLayer = id.layer();
353  int bx = (*rpcIt).BunchX();
354  int clSize = (*rpcIt).clusterSize();
355  int cornerFlag = 0;
356  if ((kStation > 3) && (kSector < 3)) {
357  cornerFlag = 1;
358  if (kRing < 0)
359  cornerFlag = 2;
360  }
361  if (nEventsAnalyzed < 100) {
362  std::cout << "Region/Station/Ring/Sector/Layer: " << kRegion << " / " << kStation << " / " << kRing << " / "
363  << kSector << " / " << kLayer << "\tbx,clSize: " << bx << ", " << clSize << std::endl;
364  }
365  if (fillHistograms) {
366  RPCBX->Fill(bx);
367  RPCClSize->Fill(min((float)clSize, (float)60.));
368  rpcStation->Fill(kStation);
369  rpcRing->Fill(kRing);
370  rpcSector->Fill(kSector);
371  rpcLayer->Fill(kLayer);
372  rpcStationVsOrbit->Fill(relativeOrbit, kStation);
373  rpcSectorVsOrbit->Fill(relativeOrbit, kSector);
374  rpcRingVsOrbit->Fill(relativeOrbit, kRing);
375  rpcCorner->Fill(cornerFlag);
376  rpcCornerVsOrbit->Fill(relativeOrbit, cornerFlag);
377  if (nRPC > nRPCHitsCut) {
378  RPCBXH->Fill(bx);
379  RPCClSizeH->Fill(min((float)clSize, (float)60.));
380  rpcStationH->Fill(kStation);
381  rpcRingH->Fill(kRing);
382  rpcSectorH->Fill(kSector);
383  rpcLayerH->Fill(kLayer);
384  rpcCornerH->Fill(cornerFlag);
385  }
386  }
387  }
388 
389  // ===============
390  // CSC DIGIs
391  // ===============
394  event.getByLabel("muonCSCDigis", "MuonCSCWireDigi", wires);
395  event.getByLabel("muonCSCDigis", "MuonCSCStripDigi", strips);
396 
397  // count the number of wire digis.
398  int nW = 0;
399  for (CSCWireDigiCollection::DigiRangeIterator jW = wires->begin(); jW != wires->end(); jW++) {
400  std::vector<CSCWireDigi>::const_iterator wireIterA = (*jW).second.first;
401  std::vector<CSCWireDigi>::const_iterator lWireA = (*jW).second.second;
402  for (; wireIterA != lWireA; ++wireIterA) {
403  nW++;
404  }
405  }
406 
407  // count the number of fired strips.
408  // I am using a crude indicator of signal - this is fast and adequate for
409  // this purpose, but it would be poor for actual CSC studies.
410  int nS = 0;
411  for (CSCStripDigiCollection::DigiRangeIterator jS = strips->begin(); jS != strips->end(); jS++) {
412  std::vector<CSCStripDigi>::const_iterator stripItA = (*jS).second.first;
413  std::vector<CSCStripDigi>::const_iterator lastStripA = (*jS).second.second;
414  for (; stripItA != lastStripA; ++stripItA) {
415  std::vector<int> myADCVals = stripItA->getADCCounts();
416  int iDiff = myADCVals[4] + myADCVals[5] - myADCVals[0] - myADCVals[1];
417  if (iDiff > 30) {
418  nS++;
419  }
420  }
421  }
422 
423  // ===============
424  // DT DIGIs
425  // ===============
426  // see: CalibMuon/DTCalibration/plugins/DTT0Calibration.cc
428  event.getByLabel("muonDTDigis", dtDIGIs);
429 
430  // count the number of digis.
431  int nDT = 0;
432  int nDTin = 0;
433  int nDTout = 0;
434  for (DTDigiCollection::DigiRangeIterator jDT = dtDIGIs->begin(); jDT != dtDIGIs->end(); ++jDT) {
435  const DTDigiCollection::Range &digiRange = (*jDT).second;
436  for (DTDigiCollection::const_iterator digi = digiRange.first; digi != digiRange.second; digi++) {
437  double t0 = (*digi).countsTDC();
438  nDT++;
439  if ((t0 > 3050) && (t0 < 3700)) {
440  nDTin++;
441  } else {
442  nDTout++;
443  }
444  if (fillHistograms) {
445  t0All->Fill(t0);
446  if (nRPC > nRPCHitsCut) {
447  t0AllH->Fill(t0);
448  }
449  }
450  }
451  }
452 
453  //==============
454  // Analysis
455  //==============
456 
457  if (nEventsAnalyzed < 1000) {
458  std::cout << "\tnumber of CSC DIGIS = " << nW << ", " << nS << "\tDT DIGIS = " << nDT << "\tRPC Rechits = " << nRPC
459  << std::endl;
460  }
461 
462  if (fillHistograms) {
463  nWires->Fill(min((float)nW, (float)120.));
464  nStrips->Fill(min((float)nS, (float)200.));
465 
466  nDTDigis->Fill(min((float)nDT, (float)200.));
467  nDTDigisIn->Fill(min((float)nDTin, (float)200.));
468  nDTDigisOut->Fill(min((float)nDTout, (float)200.));
469  if (nDT > 0) {
470  float fracOut = float(nDTout) / float(nDT);
471  fDTDigisOut->Fill(fracOut);
472  }
473  nRPCRecHits->Fill(min((float)nRPC, (float)100.));
474  nRPCRecHitsLong->Fill(min((float)nRPC, (float)1000.));
475  hitsVsSerial->Fill(nEventsAnalyzed, nRPC);
476  hitsVsOrbit->Fill(relativeOrbit, nRPC);
477  orbitVsSerial->Fill(nEventsAnalyzed, relativeOrbit);
478 
479  if (nRPC > nRPCHitsCut) {
480  nWiresH->Fill(min((float)nW, (float)120.));
481  nStripsH->Fill(min((float)nS, (float)200.));
482  nDTDigisH->Fill(min((float)nDT, (float)200.));
483  nDTDigisInH->Fill(min((float)nDTin, (float)200.));
484  nDTDigisOutH->Fill(min((float)nDTout, (float)200.));
485  if (nDT > 0) {
486  float fracOut = float(nDTout) / float(nDT);
487  fDTDigisOutH->Fill(fracOut);
488  }
489  }
490  }
491 
492  // select this event for output?
493 
494  selectThisEvent = (nRPC > nRPCHitsCut) && (nW > nCSCWiresCut || nS > nCSCStripsCut) && (nDT > nDTDigisCut);
495  if (selectThisEvent) {
496  nEventsSelected++;
497  }
498 
499  return selectThisEvent;
500 }
501 
502 //define this as a plug-in
TH1F * rpcStation
Definition: RPCNoise.cc:140
TH1F * rpcCorner
Definition: RPCNoise.cc:151
int nRPCHitsCut
Definition: RPCNoise.cc:107
void beginJob() override
Definition: RPCNoise.cc:166
TH1F * t0All
Definition: RPCNoise.cc:122
TProfile * rpcStationVsOrbit
Definition: RPCNoise.cc:148
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
TH1F * t0AllH
Definition: RPCNoise.cc:123
TProfile * hitsVsSerial
Definition: RPCNoise.cc:132
int iEvent
Definition: RPCNoise.cc:101
int firstOrbit
Definition: RPCNoise.cc:102
TH1F * nStripsH
Definition: RPCNoise.cc:119
TH1F * rpcRingH
Definition: RPCNoise.cc:143
TH1F * rpcStationH
Definition: RPCNoise.cc:141
TH1F * rpcRing
Definition: RPCNoise.cc:142
TH1F * RPCBX
Definition: RPCNoise.cc:136
nStrips
1.2 is to make the matching window safely the two nearest strips 0.35 is the size of an ME0 chamber i...
void beginJob()
Definition: Breakpoints.cc:14
TH1F * fDTDigisOutH
Definition: RPCNoise.cc:129
TH1F * nRPCRecHits
Definition: RPCNoise.cc:130
TH1F * rpcLayer
Definition: RPCNoise.cc:146
TH1F * RPCClSizeH
Definition: RPCNoise.cc:139
C::const_iterator const_iterator
constant access iterator type
Definition: RangeMap.h:43
TH1F * nDTDigisH
Definition: RPCNoise.cc:121
int iEvent
Definition: GenABIO.cc:224
TProfile * rpcSectorVsOrbit
Definition: RPCNoise.cc:149
TH1F * dOrbit
Definition: RPCNoise.cc:135
TH1F * nWiresH
Definition: RPCNoise.cc:118
int iRun
Definition: RPCNoise.cc:100
TH1F * rpcCornerH
Definition: RPCNoise.cc:152
TH1F * RPCClSize
Definition: RPCNoise.cc:137
~RPCNoise() override
Definition: RPCNoise.cc:164
int nEventsAnalyzed
Definition: RPCNoise.cc:98
static const std::string kLayer("layer")
int thisOrbit
Definition: RPCNoise.cc:104
TH1F * nDTDigisOutH
Definition: RPCNoise.cc:127
TH1F * nDTDigisOut
Definition: RPCNoise.cc:126
TProfile * rpcCornerVsOrbit
Definition: RPCNoise.cc:153
TH1F * rpcSector
Definition: RPCNoise.cc:144
TH1F * nRPCRecHitsLong
Definition: RPCNoise.cc:131
int lastOrbit
Definition: RPCNoise.cc:103
int nEventsSelected
Definition: RPCNoise.cc:99
std::pair< const_iterator, const_iterator > Range
TH1F * RPCBXH
Definition: RPCNoise.cc:138
std::vector< DigiType >::const_iterator const_iterator
TFile * theHistogramFile
Definition: RPCNoise.cc:114
bool filter(edm::Event &, const edm::EventSetup &) override
Definition: RPCNoise.cc:278
int region() const
Region id: 0 for Barrel, +/-1 For +/- Endcap.
Definition: RPCDetId.h:53
TH1F * rpcLayerH
Definition: RPCNoise.cc:147
TH1F * nDTDigisIn
Definition: RPCNoise.cc:124
HLT enums.
std::string histogramFileName
Definition: RPCNoise.cc:112
TProfile * orbitVsSerial
Definition: RPCNoise.cc:133
RPCNoise(const edm::ParameterSet &)
Definition: RPCNoise.cc:156
TH1F * nWires
Definition: RPCNoise.cc:116
strips
#turn off noise in all subdetectors simHcalUnsuppressedDigis.doNoise = False mix.digitizers.hcal.doNoise = False simEcalUnsuppressedDigis.doNoise = False mix.digitizers.ecal.doNoise = False simEcalUnsuppressedDigis.doESNoise = False simSiPixelDigis.AddNoise = False mix.digitizers.pixel.AddNoise = False simSiStripDigis.Noise = False mix.digitizers.strip.AddNoise = False
Definition: DigiDM_cff.py:32
TH1F * nStrips
Definition: RPCNoise.cc:117
TProfile * rpcRingVsOrbit
Definition: RPCNoise.cc:150
int nCSCStripsCut
Definition: RPCNoise.cc:108
void endJob() override
Definition: RPCNoise.cc:224
TH1F * nDTDigis
Definition: RPCNoise.cc:120
TProfile * hitsVsOrbit
Definition: RPCNoise.cc:134
TH1F * nDTDigisInH
Definition: RPCNoise.cc:125
int nCSCWiresCut
Definition: RPCNoise.cc:109
TH1F * rpcSectorH
Definition: RPCNoise.cc:145
Definition: event.py:1
TH1F * fDTDigisOut
Definition: RPCNoise.cc:128
bool fillHistograms
Definition: RPCNoise.cc:106
int nDTDigisCut
Definition: RPCNoise.cc:110