CMS 3D CMS Logo

DTSegmentAnalysisTask.cc
Go to the documentation of this file.
1 /*
2  * See header file for a description of this class.
3  *
4  * \author G. Cerminara - INFN Torino
5  * revised by G. Mila - INFN Torino
6  */
7 
9 
10 // Framework
17 
20 
21 //Geometry
26 
29 
31 
32 #include <iterator>
33 #include <TMath.h>
34 
35 using namespace edm;
36 using namespace std;
37 
39  : nevents(0), nEventsInLS(0), hNevtPerLS(nullptr) {
40  edm::LogVerbatim("DTDQM|DTMonitorModule|DTSegmentAnalysisTask") << "[DTSegmentAnalysisTask] Constructor called!";
41 
42  // switch for detailed analysis
43  detailedAnalysis = pset.getUntrackedParameter<bool>("detailedAnalysis", false);
44  // the name of the 4D rec hits collection
45  recHits4DToken_ = consumes<DTRecSegment4DCollection>(edm::InputTag(pset.getParameter<string>("recHits4DLabel")));
46  // Get the map of noisy channels
47  checkNoisyChannels = pset.getUntrackedParameter<bool>("checkNoisyChannels", false);
48  // # of bins in the time histos
49  nTimeBins = pset.getUntrackedParameter<int>("nTimeBins", 100);
50  // # of LS per bin in the time histos
51  nLSTimeBin = pset.getUntrackedParameter<int>("nLSTimeBin", 2);
52  // switch on/off sliding bins in time histos
53  slideTimeBins = pset.getUntrackedParameter<bool>("slideTimeBins", true);
54  phiSegmCut = pset.getUntrackedParameter<double>("phiSegmCut", 30.);
55  nhitsCut = pset.getUntrackedParameter<int>("nhitsCut", 12);
56 
57  // top folder for the histograms in DQMStore
58  topHistoFolder = pset.getUntrackedParameter<string>("topHistoFolder", "DT/02-Segments");
59  // hlt DQM mode
60  hltDQMMode = pset.getUntrackedParameter<bool>("hltDQMMode", false);
61 }
62 
64  //FR moved fron endjob
65  delete hNevtPerLS;
66  edm::LogVerbatim("DTDQM|DTMonitorModule|DTSegmentAnalysisTask") << "[DTSegmentAnalysisTask] Destructor called!";
67 }
68 
70  // Get the DT Geometry
71  context.get<MuonGeometryRecord>().get(dtGeom);
72 }
73 
75  edm::Run const& iRun,
76  edm::EventSetup const& context) {
77  if (!hltDQMMode) {
78  ibooker.setCurrentFolder("DT/EventInfo/Counters");
79  nEventMonitor = ibooker.bookFloat("nProcessedEventsSegment");
80  }
81 
82  for (int wh = -2; wh <= 2; wh++) {
83  stringstream wheel;
84  wheel << wh;
85  ibooker.setCurrentFolder(topHistoFolder + "/Wheel" + wheel.str());
86  string histoName = "numberOfSegments_W" + wheel.str();
87 
88  summaryHistos[wh] = ibooker.book2D(histoName.c_str(), histoName.c_str(), 12, 1, 13, 4, 1, 5);
89  summaryHistos[wh]->setAxisTitle("Sector", 1);
90  summaryHistos[wh]->setBinLabel(1, "1", 1);
91  summaryHistos[wh]->setBinLabel(2, "2", 1);
92  summaryHistos[wh]->setBinLabel(3, "3", 1);
93  summaryHistos[wh]->setBinLabel(4, "4", 1);
94  summaryHistos[wh]->setBinLabel(5, "5", 1);
95  summaryHistos[wh]->setBinLabel(6, "6", 1);
96  summaryHistos[wh]->setBinLabel(7, "7", 1);
97  summaryHistos[wh]->setBinLabel(8, "8", 1);
98  summaryHistos[wh]->setBinLabel(9, "9", 1);
99  summaryHistos[wh]->setBinLabel(10, "10", 1);
100  summaryHistos[wh]->setBinLabel(11, "11", 1);
101  summaryHistos[wh]->setBinLabel(12, "12", 1);
102  summaryHistos[wh]->setBinLabel(1, "MB1", 2);
103  summaryHistos[wh]->setBinLabel(2, "MB2", 2);
104  summaryHistos[wh]->setBinLabel(3, "MB3", 2);
105  summaryHistos[wh]->setBinLabel(4, "MB4", 2);
106  }
107 
108  // loop over all the DT chambers & book the histos
109  const vector<const DTChamber*>& chambers = dtGeom->chambers();
110  vector<const DTChamber*>::const_iterator ch_it = chambers.begin();
111  vector<const DTChamber*>::const_iterator ch_end = chambers.end();
112  for (; ch_it != ch_end; ++ch_it) {
113  bookHistos(ibooker, (*ch_it)->id());
114  }
115 
116  // book sector time-evolution histos
117  int modeTimeHisto = 0;
118  if (!slideTimeBins)
119  modeTimeHisto = 1;
120  for (int wheel = -2; wheel != 3; ++wheel) { // loop over wheels
121  for (int sector = 1; sector <= 12; ++sector) { // loop over sectors
122 
123  stringstream wheelstr;
124  wheelstr << wheel;
125  stringstream sectorstr;
126  sectorstr << sector;
127  string sectorHistoName = "NSegmPerEvent_W" + wheelstr.str() + "_Sec" + sectorstr.str();
128  string sectorHistoTitle = "# segm. W" + wheelstr.str() + " Sect." + sectorstr.str();
129 
130  ibooker.setCurrentFolder(topHistoFolder + "/Wheel" + wheelstr.str() + "/Sector" + sectorstr.str());
131 
133  ibooker, sectorHistoName, sectorHistoTitle, nTimeBins, nLSTimeBin, slideTimeBins, modeTimeHisto);
134  }
135  }
136 
137  if (hltDQMMode)
139  else
140  ibooker.setCurrentFolder("DT/EventInfo/");
141 
142  hNevtPerLS = new DTTimeEvolutionHisto(ibooker, "NevtPerLS", "# evt.", nTimeBins, nLSTimeBin, slideTimeBins, 2);
143 }
144 
146  nevents++;
148 
149  nEventsInLS++;
150  edm::LogVerbatim("DTDQM|DTMonitorModule|DTSegmentAnalysisTask")
151  << "[DTSegmentAnalysisTask] Analyze #Run: " << event.id().run() << " #Event: " << event.id().event();
152  if (!(event.id().event() % 1000))
153  edm::LogVerbatim("DTDQM|DTMonitorModule|DTSegmentAnalysisTask")
154  << "[DTSegmentAnalysisTask] Analyze #Run: " << event.id().run() << " #Event: " << event.id().event();
155 
156  ESHandle<DTStatusFlag> statusMap;
157  if (checkNoisyChannels) {
158  setup.get<DTStatusFlagRcd>().get(statusMap);
159  }
160 
161  // -- 4D segment analysis -----------------------------------------------------
162 
163  // Get the 4D segment collection from the event
165  event.getByToken(recHits4DToken_, all4DSegments);
166 
167  if (!all4DSegments.isValid())
168  return;
169 
170  // Loop over all chambers containing a segment
172  for (chamberId = all4DSegments->id_begin(); chamberId != all4DSegments->id_end(); ++chamberId) {
173  // Get the range for the corresponding ChamerId
174  DTRecSegment4DCollection::range range = all4DSegments->get(*chamberId);
175 
176  edm::LogVerbatim("DTDQM|DTMonitorModule|DTSegmentAnalysisTask")
177  << " Chamber: " << *chamberId << " has " << distance(range.first, range.second) << " 4D segments";
178 
179  // Loop over the rechits of this ChamerId
180  for (DTRecSegment4DCollection::const_iterator segment4D = range.first; segment4D != range.second; ++segment4D) {
181  //FOR NOISY CHANNELS////////////////////////////////
182  bool segmNoisy = false;
183  if (checkNoisyChannels) {
184  if ((*segment4D).hasPhi()) {
185  const DTChamberRecSegment2D* phiSeg = (*segment4D).phiSegment();
186  vector<DTRecHit1D> phiHits = phiSeg->specificRecHits();
187  map<DTSuperLayerId, vector<DTRecHit1D> > hitsBySLMap;
188  for (vector<DTRecHit1D>::const_iterator hit = phiHits.begin(); hit != phiHits.end(); ++hit) {
189  DTWireId wireId = (*hit).wireId();
190 
191  // Check for noisy channels to skip them
192  bool isNoisy = false;
193  bool isFEMasked = false;
194  bool isTDCMasked = false;
195  bool isTrigMask = false;
196  bool isDead = false;
197  bool isNohv = false;
198  statusMap->cellStatus(wireId, isNoisy, isFEMasked, isTDCMasked, isTrigMask, isDead, isNohv);
199  if (isNoisy) {
200  edm::LogVerbatim("DTDQM|DTMonitorModule|DTSegmentAnalysisTask")
201  << "Wire: " << wireId << " is noisy, skipping!";
202  segmNoisy = true;
203  }
204  }
205  }
206 
207  if ((*segment4D).hasZed()) {
208  const DTSLRecSegment2D* zSeg = (*segment4D).zSegment(); // zSeg lives in the SL RF
209  // Check for noisy channels to skip them
210  vector<DTRecHit1D> zHits = zSeg->specificRecHits();
211  for (vector<DTRecHit1D>::const_iterator hit = zHits.begin(); hit != zHits.end(); ++hit) {
212  DTWireId wireId = (*hit).wireId();
213  bool isNoisy = false;
214  bool isFEMasked = false;
215  bool isTDCMasked = false;
216  bool isTrigMask = false;
217  bool isDead = false;
218  bool isNohv = false;
219  statusMap->cellStatus(wireId, isNoisy, isFEMasked, isTDCMasked, isTrigMask, isDead, isNohv);
220  if (isNoisy) {
221  edm::LogVerbatim("DTDQM|DTMonitorModule|DTSegmentAnalysisTask")
222  << "Wire: " << wireId << " is noisy, skipping!";
223  segmNoisy = true;
224  }
225  }
226  }
227 
228  } // end of switch on noisy channels
229  if (segmNoisy) {
230  edm::LogVerbatim("DTDQM|DTMonitorModule|DTSegmentAnalysisTask")
231  << "skipping the segment: it contains noisy cells";
232  continue;
233  }
234  //END FOR NOISY CHANNELS////////////////////////////////
235 
236  int nHits = 0;
237  if ((*segment4D).hasPhi())
238  nHits = (((*segment4D).phiSegment())->specificRecHits()).size();
239  if ((*segment4D).hasZed())
240  nHits = nHits + ((((*segment4D).zSegment())->specificRecHits()).size());
241 
242  double anglePhiSegm(0.);
243  if ((*segment4D).hasPhi()) {
244  double xdir = (*segment4D).phiSegment()->localDirection().x();
245  double zdir = (*segment4D).phiSegment()->localDirection().z();
246 
247  anglePhiSegm = atan(xdir / zdir) * 180. / TMath::Pi();
248  }
249  if (fabs(anglePhiSegm) > phiSegmCut)
250  continue;
251  // If the segment is in Wh+-2/SecX/MB1, get the DT chambers just above and check if there is a segment
252  // to validate the segment present in MB1
253  if (fabs((*chamberId).wheel()) == 2 && (*chamberId).station() == 1) {
254  bool segmOk = false;
255  int mb(2);
256  while (mb < 4) {
257  DTChamberId checkMB((*chamberId).wheel(), mb, (*chamberId).sector());
258  DTRecSegment4DCollection::range ckrange = all4DSegments->get(checkMB);
259 
260  for (DTRecSegment4DCollection::const_iterator cksegment4D = ckrange.first; cksegment4D != ckrange.second;
261  ++cksegment4D) {
262  int nHits = 0;
263  if ((*cksegment4D).hasPhi())
264  nHits = (((*cksegment4D).phiSegment())->specificRecHits()).size();
265  if ((*cksegment4D).hasZed())
266  nHits = nHits + ((((*cksegment4D).zSegment())->specificRecHits()).size());
267 
268  if (nHits >= nhitsCut)
269  segmOk = true;
270  }
271  mb++;
272  }
273 
274  if (!segmOk)
275  continue;
276  }
277  fillHistos(*chamberId, nHits, (*segment4D).chi2() / (*segment4D).degreesOfFreedom());
278  }
279  }
280 
281  // -----------------------------------------------------------------------------
282 }
283 
284 // Book a set of histograms for a give chamber
286  edm::LogVerbatim("DTDQM|DTMonitorModule|DTSegmentAnalysisTask") << " Booking histos for chamber: " << chamberId;
287 
288  // Compose the chamber name
289  stringstream wheel;
290  wheel << chamberId.wheel();
291  stringstream station;
292  station << chamberId.station();
293  stringstream sector;
294  sector << chamberId.sector();
295 
296  string chamberHistoName = "_W" + wheel.str() + "_St" + station.str() + "_Sec" + sector.str();
297 
298  ibooker.setCurrentFolder(topHistoFolder + "/Wheel" + wheel.str() + "/Sector" + sector.str() + "/Station" +
299  station.str());
300 
301  // Create the monitor elements
302  vector<MonitorElement*> histos;
303  histos.push_back(ibooker.book1D("h4DSegmNHits" + chamberHistoName, "# of hits per segment", 16, 0.5, 16.5));
304  if (detailedAnalysis) {
305  histos.push_back(ibooker.book1D("h4DChi2" + chamberHistoName, "4D Segment reduced Chi2", 20, 0, 20));
306  }
307  histosPerCh[chamberId] = histos;
308 }
309 
310 // Fill a set of histograms for a give chamber
311 void DTSegmentAnalysisTask::fillHistos(DTChamberId chamberId, int nHits, float chi2) {
312  int sector = chamberId.sector();
313  if (chamberId.sector() == 13) {
314  sector = 4;
315  } else if (chamberId.sector() == 14) {
316  sector = 10;
317  }
318 
319  summaryHistos[chamberId.wheel()]->Fill(sector, chamberId.station());
320  histoTimeEvol[chamberId.wheel()][sector]->accumulateValueTimeSlot(1);
321 
322  vector<MonitorElement*> histos = histosPerCh[chamberId];
323  histos[0]->Fill(nHits);
324  if (detailedAnalysis) {
325  histos[1]->Fill(chi2);
326  }
327 }
328 
331  // book sector time-evolution histos
332  for (int wheel = -2; wheel != 3; ++wheel) {
333  for (int sector = 1; sector <= 12; ++sector) {
334  histoTimeEvol[wheel][sector]->updateTimeSlot(lumiSeg.luminosityBlock(), nEventsInLS);
335  }
336  }
337 }
338 
340  nEventsInLS = 0;
341 }
342 
343 // Local Variables:
344 // show-trailing-whitespace: t
345 // truncate-lines: t
346 // End:
size
Write out results.
const double Pi
MonitorElement * book1D(TString const &name, TString const &title, int const nchX, double const lowX, double const highX)
Definition: DQMStore.cc:239
T getParameter(std::string const &) const
EventNumber_t event() const
Definition: EventID.h:40
void fillHistos(DTChamberId chamberId, int nHits, float chi2)
T getUntrackedParameter(std::string const &, T const &) const
const std::vector< const DTChamber * > & chambers() const
Return a vector of all Chamber.
Definition: DTGeometry.cc:84
std::pair< const_iterator, const_iterator > range
iterator range
Definition: RangeMap.h:50
MonitorElement * bookFloat(TString const &name)
Definition: DQMStore.cc:233
void setCurrentFolder(std::string const &fullpath)
Definition: DQMStore.cc:418
void analyze(const edm::Event &event, const edm::EventSetup &setup) override
#define nullptr
DTTimeEvolutionHisto * hNevtPerLS
identifier iterator
Definition: RangeMap.h:130
std::map< DTChamberId, std::vector< MonitorElement * > > histosPerCh
LuminosityBlockNumber_t luminosityBlock() const
void Fill(long long x)
void bookHistograms(DQMStore::IBooker &, edm::Run const &, edm::EventSetup const &) override
C::const_iterator const_iterator
constant access iterator type
Definition: RangeMap.h:43
void beginLuminosityBlock(edm::LuminosityBlock const &lumiSeg, edm::EventSetup const &eSetup) override
Summary.
~DTSegmentAnalysisTask() override
Destructor.
void bookHistos(DQMStore::IBooker &ibooker, DTChamberId chamberId)
edm::ESHandle< DTGeometry > dtGeom
bool isValid() const
Definition: HandleBase.h:70
std::vector< DTRecHit1D > specificRecHits() const
Access to specific components.
int cellStatus(int wheelId, int stationId, int sectorId, int slId, int layerId, int cellId, bool &noiseFlag, bool &feMask, bool &tdcMask, bool &trigMask, bool &deadFlag, bool &nohvFlag) const
get content
Definition: DTStatusFlag.h:88
void updateTimeSlot(int ls, int nEventsInLS)
histos
Definition: combine.py:4
MonitorElement * nEventMonitor
std::map< int, std::map< int, DTTimeEvolutionHisto * > > histoTimeEvol
void dqmBeginRun(const edm::Run &, const edm::EventSetup &) override
BeginRun.
edm::EventID id() const
Definition: EventBase.h:59
HLT enums.
MonitorElement * book2D(TString const &name, TString const &title, int nchX, double lowX, double highX, int nchY, double lowY, double highY)
Definition: DQMStore.cc:266
int sector() const
Definition: DTChamberId.h:49
T get() const
Definition: EventSetup.h:73
std::map< int, MonitorElement * > summaryHistos
int station() const
Return the station number.
Definition: DTChamberId.h:42
static char chambers[264][20]
Definition: ReadPGInfo.cc:243
edm::EDGetTokenT< DTRecSegment4DCollection > recHits4DToken_
int wheel() const
Return the wheel number.
Definition: DTChamberId.h:39
void endLuminosityBlock(edm::LuminosityBlock const &lumiSeg, edm::EventSetup const &eSetup) override
DTSegmentAnalysisTask(const edm::ParameterSet &pset)
Constructor.
Definition: event.py:1
Definition: Run.h:45