CMS 3D CMS Logo

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