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
16 
19 
20 //Geometry
24 
26 
27 #include <iterator>
28 #include "TMath.h"
29 
30 using namespace edm;
31 using namespace std;
32 
34  : muonGeomToken_(esConsumes<edm::Transition::BeginRun>()), statusMapToken_(esConsumes()), nevents(0) {
35  edm::LogVerbatim("DTDQM|DTMonitorModule|DTSegmentAnalysisTask") << "[DTSegmentAnalysisTask] Constructor called!";
36 
37  // switch for detailed analysis
38  detailedAnalysis = pset.getUntrackedParameter<bool>("detailedAnalysis", false);
39  // the name of the 4D rec hits collection
41  consumes<DTRecSegment4DCollection>(edm::InputTag(pset.getUntrackedParameter<string>("recHits4DLabel")));
42  // Get the map of noisy channels
43  checkNoisyChannels = pset.getUntrackedParameter<bool>("checkNoisyChannels", false);
44  phiSegmCut = pset.getUntrackedParameter<double>("phiSegmCut", 30.);
45  nhitsCut = pset.getUntrackedParameter<int>("nhitsCut", 12);
46 
47  // top folder for the histograms in DQMStore
48  topHistoFolder = pset.getUntrackedParameter<string>("topHistoFolder", "DT/02-Segments");
49  // hlt DQM mode
50  hltDQMMode = pset.getUntrackedParameter<bool>("hltDQMMode", false);
51 }
52 
54  //FR moved fron endjob
55  edm::LogVerbatim("DTDQM|DTMonitorModule|DTSegmentAnalysisTask") << "[DTSegmentAnalysisTask] Destructor called!";
56 }
57 
59  // Get the DT Geometry
60  dtGeom = &context.getData(muonGeomToken_);
61 }
62 
64  edm::Run const& iRun,
65  edm::EventSetup const& context) {
66  if (!hltDQMMode) {
67  ibooker.setCurrentFolder("DT/EventInfo/Counters");
68  nEventMonitor = ibooker.bookFloat("nProcessedEventsSegment");
69  }
70 
71  for (int wh = -2; wh <= 2; wh++) {
72  stringstream wheel;
73  wheel << wh;
74  ibooker.setCurrentFolder(topHistoFolder + "/Wheel" + wheel.str());
75  string histoName = "numberOfSegments_W" + wheel.str();
76 
77  summaryHistos[wh] = ibooker.book2D(histoName.c_str(), histoName.c_str(), 12, 1, 13, 4, 1, 5);
78  summaryHistos[wh]->setAxisTitle("Sector", 1);
79  summaryHistos[wh]->setBinLabel(1, "1", 1);
80  summaryHistos[wh]->setBinLabel(2, "2", 1);
81  summaryHistos[wh]->setBinLabel(3, "3", 1);
82  summaryHistos[wh]->setBinLabel(4, "4", 1);
83  summaryHistos[wh]->setBinLabel(5, "5", 1);
84  summaryHistos[wh]->setBinLabel(6, "6", 1);
85  summaryHistos[wh]->setBinLabel(7, "7", 1);
86  summaryHistos[wh]->setBinLabel(8, "8", 1);
87  summaryHistos[wh]->setBinLabel(9, "9", 1);
88  summaryHistos[wh]->setBinLabel(10, "10", 1);
89  summaryHistos[wh]->setBinLabel(11, "11", 1);
90  summaryHistos[wh]->setBinLabel(12, "12", 1);
91  summaryHistos[wh]->setBinLabel(1, "MB1", 2);
92  summaryHistos[wh]->setBinLabel(2, "MB2", 2);
93  summaryHistos[wh]->setBinLabel(3, "MB3", 2);
94  summaryHistos[wh]->setBinLabel(4, "MB4", 2);
95  }
96 
97  // loop over all the DT chambers & book the histos
98  const vector<const DTChamber*>& chambers = dtGeom->chambers();
99  vector<const DTChamber*>::const_iterator ch_it = chambers.begin();
100  vector<const DTChamber*>::const_iterator ch_end = chambers.end();
101  for (; ch_it != ch_end; ++ch_it) {
102  bookHistos(ibooker, (*ch_it)->id());
103  }
104 }
105 
107  nevents++;
109 
110  edm::LogVerbatim("DTDQM|DTMonitorModule|DTSegmentAnalysisTask")
111  << "[DTSegmentAnalysisTask] Analyze #Run: " << event.id().run() << " #Event: " << event.id().event();
112  if (!(event.id().event() % 1000))
113  edm::LogVerbatim("DTDQM|DTMonitorModule|DTSegmentAnalysisTask")
114  << "[DTSegmentAnalysisTask] Analyze #Run: " << event.id().run() << " #Event: " << event.id().event();
115 
116  if (checkNoisyChannels) {
117  statusMap = &setup.getData(statusMapToken_);
118  }
119 
120  // -- 4D segment analysis -----------------------------------------------------
121 
122  // Get the 4D segment collection from the event
124  event.getByToken(recHits4DToken_, all4DSegments);
125 
126  if (!all4DSegments.isValid())
127  return;
128 
129  // Loop over all chambers containing a segment
131  for (chamberId = all4DSegments->id_begin(); chamberId != all4DSegments->id_end(); ++chamberId) {
132  // Get the range for the corresponding ChamerId
133  DTRecSegment4DCollection::range range = all4DSegments->get(*chamberId);
134 
135  edm::LogVerbatim("DTDQM|DTMonitorModule|DTSegmentAnalysisTask")
136  << " Chamber: " << *chamberId << " has " << distance(range.first, range.second) << " 4D segments";
137 
138  // Loop over the rechits of this ChamerId
139  for (DTRecSegment4DCollection::const_iterator segment4D = range.first; segment4D != range.second; ++segment4D) {
140  //FOR NOISY CHANNELS////////////////////////////////
141  bool segmNoisy = false;
142  if (checkNoisyChannels) {
143  if ((*segment4D).hasPhi()) {
144  const DTChamberRecSegment2D* phiSeg = (*segment4D).phiSegment();
145  vector<DTRecHit1D> phiHits = phiSeg->specificRecHits();
146  map<DTSuperLayerId, vector<DTRecHit1D> > hitsBySLMap;
147  for (vector<DTRecHit1D>::const_iterator hit = phiHits.begin(); hit != phiHits.end(); ++hit) {
148  DTWireId wireId = (*hit).wireId();
149 
150  // Check for noisy channels to skip them
151  bool isNoisy = false;
152  bool isFEMasked = false;
153  bool isTDCMasked = false;
154  bool isTrigMask = false;
155  bool isDead = false;
156  bool isNohv = false;
157  statusMap->cellStatus(wireId, isNoisy, isFEMasked, isTDCMasked, isTrigMask, isDead, isNohv);
158  if (isNoisy) {
159  edm::LogVerbatim("DTDQM|DTMonitorModule|DTSegmentAnalysisTask")
160  << "Wire: " << wireId << " is noisy, skipping!";
161  segmNoisy = true;
162  }
163  }
164  }
165 
166  if ((*segment4D).hasZed()) {
167  const DTSLRecSegment2D* zSeg = (*segment4D).zSegment(); // zSeg lives in the SL RF
168  // Check for noisy channels to skip them
169  vector<DTRecHit1D> zHits = zSeg->specificRecHits();
170  for (vector<DTRecHit1D>::const_iterator hit = zHits.begin(); hit != zHits.end(); ++hit) {
171  DTWireId wireId = (*hit).wireId();
172  bool isNoisy = false;
173  bool isFEMasked = false;
174  bool isTDCMasked = false;
175  bool isTrigMask = false;
176  bool isDead = false;
177  bool isNohv = false;
178  statusMap->cellStatus(wireId, isNoisy, isFEMasked, isTDCMasked, isTrigMask, isDead, isNohv);
179  if (isNoisy) {
180  edm::LogVerbatim("DTDQM|DTMonitorModule|DTSegmentAnalysisTask")
181  << "Wire: " << wireId << " is noisy, skipping!";
182  segmNoisy = true;
183  }
184  }
185  }
186 
187  } // end of switch on noisy channels
188  if (segmNoisy) {
189  edm::LogVerbatim("DTDQM|DTMonitorModule|DTSegmentAnalysisTask")
190  << "skipping the segment: it contains noisy cells";
191  continue;
192  }
193  //END FOR NOISY CHANNELS////////////////////////////////
194 
195  int nHits = 0;
196  if ((*segment4D).hasPhi())
197  nHits = (((*segment4D).phiSegment())->specificRecHits()).size();
198  if ((*segment4D).hasZed())
199  nHits = nHits + ((((*segment4D).zSegment())->specificRecHits()).size());
200 
201  double anglePhiSegm(0.);
202  if ((*segment4D).hasPhi()) {
203  double xdir = (*segment4D).phiSegment()->localDirection().x();
204  double zdir = (*segment4D).phiSegment()->localDirection().z();
205 
206  anglePhiSegm = atan(xdir / zdir) * 180. / TMath::Pi();
207  }
208  if (fabs(anglePhiSegm) > phiSegmCut)
209  continue;
210  // If the segment is in Wh+-2/SecX/MB1, get the DT chambers just above and check if there is a segment
211  // to validate the segment present in MB1
212  if (fabs((*chamberId).wheel()) == 2 && (*chamberId).station() == 1) {
213  bool segmOk = false;
214  int mb(2);
215  while (mb < 4) {
216  DTChamberId checkMB((*chamberId).wheel(), mb, (*chamberId).sector());
217  DTRecSegment4DCollection::range ckrange = all4DSegments->get(checkMB);
218 
219  for (DTRecSegment4DCollection::const_iterator cksegment4D = ckrange.first; cksegment4D != ckrange.second;
220  ++cksegment4D) {
221  int nHits = 0;
222  if ((*cksegment4D).hasPhi())
223  nHits = (((*cksegment4D).phiSegment())->specificRecHits()).size();
224  if ((*cksegment4D).hasZed())
225  nHits = nHits + ((((*cksegment4D).zSegment())->specificRecHits()).size());
226 
227  if (nHits >= nhitsCut)
228  segmOk = true;
229  }
230  mb++;
231  }
232 
233  if (!segmOk)
234  continue;
235  }
236  fillHistos(*chamberId, nHits, (*segment4D).chi2() / (*segment4D).degreesOfFreedom());
237  }
238  }
239 
240  // -----------------------------------------------------------------------------
241 }
242 
243 // Book a set of histograms for a give chamber
245  edm::LogVerbatim("DTDQM|DTMonitorModule|DTSegmentAnalysisTask") << " Booking histos for chamber: " << chamberId;
246 
247  // Compose the chamber name
248  stringstream wheel;
249  wheel << chamberId.wheel();
250  stringstream station;
251  station << chamberId.station();
252  stringstream sector;
253  sector << chamberId.sector();
254 
255  string chamberHistoName = "_W" + wheel.str() + "_St" + station.str() + "_Sec" + sector.str();
256 
257  ibooker.setCurrentFolder(topHistoFolder + "/Wheel" + wheel.str() + "/Sector" + sector.str() + "/Station" +
258  station.str());
259 
260  // Create the monitor elements
261  vector<MonitorElement*> histos;
262  histos.push_back(ibooker.book1D("h4DSegmNHits" + chamberHistoName, "# of hits per segment", 16, 0.5, 16.5));
263  if (detailedAnalysis) {
264  histos.push_back(ibooker.book1D("h4DChi2" + chamberHistoName, "4D Segment reduced Chi2", 20, 0, 20));
265  }
266  histosPerCh[chamberId] = histos;
267 }
268 
269 // Fill a set of histograms for a give chamber
271  int sector = chamberId.sector();
272  if (chamberId.sector() == 13) {
273  sector = 4;
274  } else if (chamberId.sector() == 14) {
275  sector = 10;
276  }
277 
278  summaryHistos[chamberId.wheel()]->Fill(sector, chamberId.station());
279 
280  vector<MonitorElement*> histos = histosPerCh[chamberId];
281  histos[0]->Fill(nHits);
282  if (detailedAnalysis) {
283  histos[1]->Fill(chi2);
284  }
285 }
286 
287 // Local Variables:
288 // show-trailing-whitespace: t
289 // truncate-lines: t
290 // End:
size
Write out results.
const double Pi
Log< level::Info, true > LogVerbatim
int station() const
Return the station number.
Definition: DTChamberId.h:45
void fillHistos(DTChamberId chamberId, int nHits, float chi2)
ESGetTokenH3DDVariant esConsumes(std::string const &Record, edm::ConsumesCollector &)
Definition: DeDxTools.cc:283
MonitorElement * bookFloat(TString const &name, FUNC onbooking=NOOP())
Definition: DQMStore.h:80
std::pair< const_iterator, const_iterator > range
iterator range
Definition: RangeMap.h:50
const DTGeometry * dtGeom
virtual void setCurrentFolder(std::string const &fullpath)
Definition: DQMStore.cc:36
void analyze(const edm::Event &event, const edm::EventSetup &setup) override
identifier iterator
Definition: RangeMap.h:130
edm::ESGetToken< DTStatusFlag, DTStatusFlagRcd > statusMapToken_
edm::ESGetToken< DTGeometry, MuonGeometryRecord > muonGeomToken_
std::map< DTChamberId, std::vector< MonitorElement * > > histosPerCh
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
~DTSegmentAnalysisTask() override
Destructor.
void bookHistos(DQMStore::IBooker &ibooker, DTChamberId chamberId)
Transition
Definition: Transition.h:12
const DTStatusFlag * statusMap
std::vector< DTRecHit1D > specificRecHits() const
Access to specific components.
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
bool isValid() const
Definition: HandleBase.h:70
histos
Definition: combine.py:4
MonitorElement * nEventMonitor
void dqmBeginRun(const edm::Run &, const edm::EventSetup &) override
BeginRun.
int wheel() const
Return the wheel number.
Definition: DTChamberId.h:42
HLT enums.
int sector() const
Definition: DTChamberId.h:52
std::map< int, MonitorElement * > summaryHistos
const std::vector< const DTChamber * > & chambers() const
Return a vector of all Chamber.
Definition: DTGeometry.cc:84
MonitorElement * book1D(TString const &name, TString const &title, int const nchX, double const lowX, double const highX, FUNC onbooking=NOOP())
Definition: DQMStore.h:98
TupleMultiplicity< TrackerTraits > const *__restrict__ uint32_t nHits
static char chambers[264][20]
Definition: ReadPGInfo.cc:243
edm::EDGetTokenT< DTRecSegment4DCollection > recHits4DToken_
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:90
DTSegmentAnalysisTask(const edm::ParameterSet &pset)
Constructor.
Definition: event.py:1
Definition: Run.h:45