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