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