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