CMS 3D CMS Logo

DTNoiseTask.cc
Go to the documentation of this file.
1 
2 /*
3  * See header file for a description of this class.
4  *
5  * \authors G. Mila , G. Cerminara - INFN Torino
6  */
7 
8 #include "DTNoiseTask.h"
9 
10 // Framework
15 
17 
18 // Geometry
22 
23 // Digi
27 
28 // Database
30 
31 #include <sstream>
32 #include <string>
33 
34 using namespace edm;
35 using namespace std;
36 
38  : evtNumber(0),
39  muonGeomToken_(esConsumes<edm::Transition::BeginRun>()),
40  tTrigMapToken_(esConsumes<edm::Transition::BeginRun>()) {
41  LogVerbatim("DTNoiseTask") << "[DTNoiseTask]: Constructor" << endl;
42 
43  //switch for timeBox booking
44  doTimeBoxHistos = ps.getUntrackedParameter<bool>("doTbHistos", false);
45 
46  // The label to retrieve the digis
47  dtDigiToken_ = consumes<DTDigiCollection>(ps.getUntrackedParameter<InputTag>("dtDigiLabel"));
48 
49  // the name of the 4D rec hits collection
51  consumes<DTRecSegment4DCollection>(edm::InputTag(ps.getUntrackedParameter<string>("recHits4DLabel")));
52 
53  // switch for segment veto
54  doSegmentVeto = ps.getUntrackedParameter<bool>("doSegmentVeto", false);
55 
56  // safe margin (ns) between ttrig and beginning of counting area
57  safeMargin = ps.getUntrackedParameter<double>("safeMargin", 200.);
58 }
59 
61 
64  evtNumber++;
66 
67  if (evtNumber % 1000 == 0)
68  LogVerbatim("DTNoiseTask") << "[DTNoiseTask]: Analyzing evt number :" << evtNumber << endl;
69 
70  // map of the chambers with at least 1 segment
71  std::map<DTChamberId, int> segmentsChId;
72 
73  // Get the 4D segment collection from the event
75  if (doSegmentVeto) {
76  e.getByToken(recHits4DToken_, all4DSegments);
77 
78  // Loop over all chambers containing a segment and look for the number of segments
80  for (chamberId = all4DSegments->id_begin(); chamberId != all4DSegments->id_end(); ++chamberId) {
81  segmentsChId[*chamberId] = 1;
82  }
83  }
84 
85  // Get the digis from the event
87  e.getByToken(dtDigiToken_, dtdigis);
88 
89  // LOOP OVER ALL THE DIGIS OF THE EVENT
91  for (dtLayerId_It = dtdigis->begin(); dtLayerId_It != dtdigis->end(); ++dtLayerId_It) {
92  for (DTDigiCollection::const_iterator digiIt = ((*dtLayerId_It).second).first;
93  digiIt != ((*dtLayerId_It).second).second;
94  ++digiIt) {
95  //Check the TDC trigger width
96  int tdcTime = (*digiIt).countsTDC();
97  double upperLimit = tTrigStMap[(*dtLayerId_It).first.superlayerId().chamberId()] - safeMargin;
98  if (doTimeBoxHistos)
99  tbHistos[(*dtLayerId_It).first.superlayerId()]->Fill(tdcTime);
100  if (tdcTime > upperLimit)
101  continue;
102 
103  //Check the chamber has no 4D segments (optional)
104  if (doSegmentVeto && segmentsChId.find((*dtLayerId_It).first.superlayerId().chamberId()) != segmentsChId.end())
105  continue;
106 
107  // fill the occupancy histo
108  // FIXME: needs to be optimized: no need to rescale the histo for each digi
109  TH2F* noise_root = noiseHistos[(*dtLayerId_It).first.superlayerId().chamberId()]->getTH2F();
110  double normalization = 0;
111  if (mapEvt.find((*dtLayerId_It).first.superlayerId().chamberId()) != mapEvt.end()) {
112  LogVerbatim("DTNoiseTask") << " Last fill: # of events: "
113  << mapEvt[(*dtLayerId_It).first.superlayerId().chamberId()] << endl;
114  normalization = 1e-9 * upperLimit * mapEvt[(*dtLayerId_It).first.superlayerId().chamberId()];
115  // revert back to # of entries
116  noise_root->Scale(normalization);
117  }
118  int yBin = (*dtLayerId_It).first.layer() + (4 * ((*dtLayerId_It).first.superlayerId().superlayer() - 1));
119  noise_root->Fill((*digiIt).wire(), yBin);
120  // normalize the occupancy histo
121  mapEvt[(*dtLayerId_It).first.superlayerId().chamberId()] = evtNumber;
122  LogVerbatim("DTNoiseTask") << (*dtLayerId_It).first << " wire: " << (*digiIt).wire()
123  << " # counts: " << noise_root->GetBinContent((*digiIt).wire(), yBin)
124  << " Time interval: " << upperLimit << " # of events: " << evtNumber << endl;
125  ;
126  normalization = double(1e-9 * upperLimit * mapEvt[(*dtLayerId_It).first.superlayerId().chamberId()]);
127  // update the rate
128  noise_root->Scale(1. / normalization);
129  LogVerbatim("DTNoiseTask") << " noise rate: " << noise_root->GetBinContent((*digiIt).wire(), yBin) << endl;
130  }
131  }
132 }
133 
135  // set the folder
136  stringstream wheel;
137  wheel << chId.wheel();
138  stringstream station;
139  station << chId.station();
140  stringstream sector;
141  sector << chId.sector();
142 
143  ibooker.setCurrentFolder("DT/05-Noise/Wheel" + wheel.str() +
144  // "/Station" + station.str() +
145  "/Sector" + sector.str());
146 
147  // Build the histo name
148  string histoName = string("NoiseRate") + "_W" + wheel.str() + "_St" + station.str() + "_Sec" + sector.str();
149 
150  LogVerbatim("DTNoiseTask") << "[DTNoiseTask]: booking chamber histo:" << endl;
151  LogVerbatim("DTNoiseTask") << " folder "
152  << "DT/05-Noise/Wheel" + wheel.str() +
153  // "/Station" + station.str() +
154  "/Sector" + sector.str() + "/"
155  << endl;
156  LogVerbatim("DTNoiseTask") << " histoName " << histoName << endl;
157 
158  // Get the chamber from the geometry
159  int nWires_max = 0;
160  const DTChamber* dtchamber = dtGeom->chamber(chId);
161  const vector<const DTSuperLayer*>& superlayers = dtchamber->superLayers();
162 
163  // Loop over layers and find the max # of wires
164  for (vector<const DTSuperLayer*>::const_iterator sl = superlayers.begin(); sl != superlayers.end();
165  ++sl) { // loop over SLs
166  vector<const DTLayer*> layers = (*sl)->layers();
167  for (vector<const DTLayer*>::const_iterator lay = layers.begin(); lay != layers.end(); ++lay) { // loop over layers
168  int nWires = (*lay)->specificTopology().channels();
169  if (nWires > nWires_max)
170  nWires_max = nWires;
171  }
172  }
173 
174  noiseHistos[chId] =
175  ibooker.book2D(histoName, "Noise rate (Hz) per channel", nWires_max, 1, nWires_max + 1, 12, 1, 13);
176  noiseHistos[chId]->setAxisTitle("wire number", 1);
177  noiseHistos[chId]->setBinLabel(1, "SL1-L1", 2);
178  noiseHistos[chId]->setBinLabel(2, "SL1-L2", 2);
179  noiseHistos[chId]->setBinLabel(3, "SL1-L3", 2);
180  noiseHistos[chId]->setBinLabel(4, "SL1-L4", 2);
181  noiseHistos[chId]->setBinLabel(5, "SL2-L1", 2);
182  noiseHistos[chId]->setBinLabel(6, "SL2-L2", 2);
183  noiseHistos[chId]->setBinLabel(7, "SL2-L3", 2);
184  noiseHistos[chId]->setBinLabel(8, "SL2-L4", 2);
185  noiseHistos[chId]->setBinLabel(9, "SL3-L1", 2);
186  noiseHistos[chId]->setBinLabel(10, "SL3-L2", 2);
187  noiseHistos[chId]->setBinLabel(11, "SL3-L3", 2);
188  noiseHistos[chId]->setBinLabel(12, "SL3-L4", 2);
189 }
190 
192  // set the folder
193  stringstream wheel;
194  wheel << slId.chamberId().wheel();
195  stringstream station;
196  station << slId.chamberId().station();
197  stringstream sector;
198  sector << slId.chamberId().sector();
199  stringstream superlayer;
200  superlayer << slId.superlayer();
201 
202  ibooker.setCurrentFolder("DT/05-Noise/Wheel" + wheel.str() + "/Station" + station.str() + "/Sector" + sector.str());
203 
204  // Build the histo name
205  string histoName =
206  string("TimeBox") + "_W" + wheel.str() + "_St" + station.str() + "_Sec" + sector.str() + "_SL" + superlayer.str();
207 
208  LogVerbatim("DTNoiseTask") << "[DTNoiseTask]: booking SL histo:" << endl;
209  LogVerbatim("DTNoiseTask") << " folder "
210  << "DT/05-Noise/Wheel" + wheel.str() + "/Station" + station.str() + "/Sector" +
211  sector.str() + "/"
212  << endl;
213  LogVerbatim("DTNoiseTask") << " histoName " << histoName << endl;
214 
215  tbHistos[slId] = ibooker.book1D(histoName, "Time Box (TDC counts)", 1000, 0, 6000);
216 }
217 
219  LogVerbatim("DTNoiseTask") << "[DTNoiseTask]: Begin of run" << endl;
220 
221  // tTrig Map
222  tTrigMap = &setup.getData(tTrigMapToken_);
223 
224  // get the geometry
225  dtGeom = &setup.getData(muonGeomToken_);
226 }
227 
229  ibooker.setCurrentFolder("DT/EventInfo/Counters");
230  nEventMonitor = ibooker.bookFloat("nProcessedEventsNoise");
231 
232  // Loop over all the chambers
233  vector<const DTChamber*>::const_iterator ch_it = dtGeom->chambers().begin();
234  vector<const DTChamber*>::const_iterator ch_end = dtGeom->chambers().end();
235  for (; ch_it != ch_end; ++ch_it) {
236  DTChamberId chId = (*ch_it)->id();
237  // histo booking
238  bookHistos(ibooker, chId);
239  vector<const DTSuperLayer*>::const_iterator sl_it = (*ch_it)->superLayers().begin();
240  vector<const DTSuperLayer*>::const_iterator sl_end = (*ch_it)->superLayers().end();
241  // Loop over the SLs
242  for (; sl_it != sl_end; ++sl_it) {
243  DTSuperLayerId slId = (*sl_it)->id();
244  if (doTimeBoxHistos)
245  bookHistos(ibooker, slId);
246  float tTrig, tTrigRMS, kFactor;
247  tTrigMap->get(slId, tTrig, tTrigRMS, kFactor, DTTimeUnits::ns);
248  // tTrig mapping per station
249  // check that the ttrig is the lowest of the 3 SLs
250  if (tTrigStMap.find(chId) == tTrigStMap.end() ||
251  (tTrigStMap.find(chId) != tTrigStMap.end() && tTrig < tTrigStMap[chId]))
252  tTrigStMap[chId] = tTrig;
253  }
254  }
255 }
256 
258  LogVerbatim("DTNoiseTask") << "[DTNoiseTask]: End LS, update rates in all histos" << endl;
259 
260  // update the rate of all histos (usefull for histos with few entries: they are not updated very often
261  for (map<DTChamberId, MonitorElement*>::const_iterator meAndChamber = noiseHistos.begin();
262  meAndChamber != noiseHistos.end();
263  ++meAndChamber) {
264  DTChamberId chId = (*meAndChamber).first;
265  TH2F* noise_root = (*meAndChamber).second->getTH2F();
266  double upperLimit = tTrigStMap[chId] - safeMargin;
267 
268  double normalization = 0;
269  if (mapEvt.find(chId) != mapEvt.end()) {
270  LogVerbatim("DTNoiseTask") << " Ch: " << chId << " Last fill: # of events: " << mapEvt[chId] << endl;
271  normalization = 1e-9 * upperLimit * mapEvt[chId];
272  // revert back to # of entries
273  noise_root->Scale(normalization);
274  }
275  //check that event analyzed != 0 might happen oline
276  if (evtNumber) {
277  // set the # of events analyzed until this update
278  LogVerbatim("DTNoiseTask") << " Update for events: " << evtNumber << endl;
279  mapEvt[chId] = evtNumber;
280  // update the rate
281  normalization = double(1e-9 * upperLimit * evtNumber);
282  noise_root->Scale(1. / normalization);
283  }
284  }
285 }
286 
287 // Local Variables:
288 // show-trailing-whitespace: t
289 // truncate-lines: t
290 // End:
Log< level::Info, true > LogVerbatim
int station() const
Return the station number.
Definition: DTChamberId.h:42
std::map< DTChamberId, int > mapEvt
Definition: DTNoiseTask.h:86
ESGetTokenH3DDVariant esConsumes(std::string const &Record, edm::ConsumesCollector &)
Definition: DeDxTools.cc:283
MonitorElement * bookFloat(TString const &name, FUNC onbooking=NOOP())
Definition: DQMStore.h:80
virtual void setCurrentFolder(std::string const &fullpath)
Definition: DQMStore.cc:36
identifier iterator
Definition: RangeMap.h:130
MonitorElement * nEventMonitor
Definition: DTNoiseTask.h:91
bool doSegmentVeto
Definition: DTNoiseTask.h:72
void dqmBeginRun(const edm::Run &, const edm::EventSetup &) override
Definition: DTNoiseTask.cc:218
T getUntrackedParameter(std::string const &, T const &) const
void Fill(long long x)
U second(std::pair< T, U > const &p)
DTChamberId chamberId() const
Return the corresponding ChamberId.
void analyze(const edm::Event &e, const edm::EventSetup &c) override
Analyze.
Definition: DTNoiseTask.cc:63
edm::EDGetTokenT< DTRecSegment4DCollection > recHits4DToken_
Definition: DTNoiseTask.h:70
void endLuminosityBlock(const edm::LuminosityBlock &lumiSeg, const edm::EventSetup &setup) override
Definition: DTNoiseTask.cc:257
Transition
Definition: Transition.h:12
edm::EDGetTokenT< DTDigiCollection > dtDigiToken_
Definition: DTNoiseTask.h:64
double safeMargin
Definition: DTNoiseTask.h:94
const std::vector< const DTSuperLayer * > & superLayers() const
Return the superlayers in the chamber.
Definition: DTChamber.cc:51
void bookHistograms(DQMStore::IBooker &, edm::Run const &, edm::EventSetup const &) override
Definition: DTNoiseTask.cc:228
std::map< DTSuperLayerId, MonitorElement * > tbHistos
Definition: DTNoiseTask.h:89
void bookHistos(DQMStore::IBooker &, DTChamberId chId)
Definition: DTNoiseTask.cc:134
int superlayer() const
Return the superlayer number (deprecated method name)
std::map< DTChamberId, double > tTrigStMap
Definition: DTNoiseTask.h:80
MonitorElement * book2D(TString const &name, TString const &title, int nchX, double lowX, double highX, int nchY, double lowY, double highY, FUNC onbooking=NOOP())
Definition: DQMStore.h:212
const DTGeometry * dtGeom
Definition: DTNoiseTask.h:75
std::vector< DigiType >::const_iterator const_iterator
int get(int wheelId, int stationId, int sectorId, int slId, float &tTrig, float &tTrms, float &kFact, DTTimeUnits::type unit) const
get content
Definition: DTTtrig.cc:59
edm::ESGetToken< DTTtrig, DTTtrigRcd > tTrigMapToken_
Definition: DTNoiseTask.h:76
int wheel() const
Return the wheel number.
Definition: DTChamberId.h:39
HLT enums.
int sector() const
Definition: DTChamberId.h:49
DTNoiseTask(const edm::ParameterSet &ps)
Constructor.
Definition: DTNoiseTask.cc:37
bool doTimeBoxHistos
Definition: DTNoiseTask.h:68
std::map< DTChamberId, MonitorElement * > noiseHistos
Definition: DTNoiseTask.h:83
const std::vector< const DTChamber * > & chambers() const
Return a vector of all Chamber.
Definition: DTGeometry.cc:84
const DTTtrig * tTrigMap
Definition: DTNoiseTask.h:77
MonitorElement * book1D(TString const &name, TString const &title, int const nchX, double const lowX, double const highX, FUNC onbooking=NOOP())
Definition: DQMStore.h:98
const DTChamber * chamber(const DTChamberId &id) const
Return a DTChamber given its id.
Definition: DTGeometry.cc:90
edm::ESGetToken< DTGeometry, MuonGeometryRecord > muonGeomToken_
Definition: DTNoiseTask.h:74
Definition: Run.h:45
~DTNoiseTask() override
Destructor.
Definition: DTNoiseTask.cc:60