CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
DTEfficiencyTask.cc
Go to the documentation of this file.
1 /*
2  * See header file for a description of this class.
3  *
4  * \author G. Mila - INFN Torino
5  */
6 
7 
8 #include "DTEfficiencyTask.h"
9 
10 
11 // Framework
17 
20 
21 //Geometry
24 
25 //RecHit
27 
30 
31 #include <iterator>
32 
33 using namespace edm;
34 using namespace std;
35 
36 
38 
39  debug = pset.getUntrackedParameter<bool>("debug",false);
40  // the name of the 4D rec hits collection
41  recHits4DToken_ = consumes<DTRecSegment4DCollection>(
42  edm::InputTag(pset.getParameter<string>("recHits4DLabel")));
43  // the name of the rechits collection
44  recHitToken_ = consumes<DTRecHitCollection>(
45  edm::InputTag(pset.getParameter<string>("recHitLabel")));
46 
47  parameters = pset;
48 }
49 
50 
52 }
53 
55 
56  // Get the geometry
57  context.get<MuonGeometryRecord>().get(muonGeom);
58 
59 }
60 
61 
62 void DTEfficiencyTask::bookHistograms(DQMStore::IBooker & ibooker, edm::Run const & iRun, edm::EventSetup const & context) {
63 
64  ibooker.setCurrentFolder("DT/DTEfficiencyTask");
65 
66  cout<<"[DTTestPulseTask]: booking"<<endl;
67 
68 
69  //here put the static booking loop
70 
71  // Loop over all the chambers
72  vector<const DTChamber*>::const_iterator ch_it = muonGeom->chambers().begin();
73  vector<const DTChamber*>::const_iterator ch_end = muonGeom->chambers().end();
74 
75  for (; ch_it != ch_end; ++ch_it) {
76 
77  // Loop over the SLs
78  vector<const DTSuperLayer*>::const_iterator sl_it = (*ch_it)->superLayers().begin();
79  vector<const DTSuperLayer*>::const_iterator sl_end = (*ch_it)->superLayers().end();
80 
81  for(; sl_it != sl_end; ++sl_it) {
82  DTSuperLayerId sl = (*sl_it)->id();
83  stringstream superLayer; superLayer << sl.superlayer();
84 
85  // Loop over the Ls
86  vector<const DTLayer*>::const_iterator l_it = (*sl_it)->layers().begin();
87  vector<const DTLayer*>::const_iterator l_end = (*sl_it)->layers().end();
88 
89  for(; l_it != l_end; ++l_it) {
90 
91  DTLayerId layerId = (*l_it)->id();
92  if(debug) cout << " Booking histos for L: " << layerId << endl;
93 
94  // Compose the chamber name
95  stringstream layer; layer << layerId.layer();
96  stringstream superLayer; superLayer << layerId.superlayer();
97  stringstream station; station << layerId.superlayerId().chamberId().station();
98  stringstream sector; sector << layerId.superlayerId().chamberId().sector();
99  stringstream wheel; wheel << layerId.superlayerId().chamberId().wheel();
100 
101  const int firstWire = (*l_it)->specificTopology().firstChannel();
102  const int lastWire = (*l_it)->specificTopology().lastChannel();
103 
104  string lHistoName =
105  "_W" + wheel.str() +
106  "_St" + station.str() +
107  "_Sec" + sector.str() +
108  "_SL" + superLayer.str()+
109  "_L" + layer.str();
110 
111  ibooker.setCurrentFolder("DT/DTEfficiencyTask/Wheel" + wheel.str() +
112  "/Station" + station.str() +
113  "/Sector" + sector.str() +
114  "/SuperLayer" +superLayer.str());
115 
116 
117  // Create the monitor elements
118  vector<MonitorElement *> histos;
119  // histo for hits associated to the 4D reconstructed segment
120  histos.push_back(ibooker.book1D(
121  "hEffOccupancy"+lHistoName, "4D segments recHits occupancy",lastWire-firstWire+1, firstWire-0.5, lastWire+0.5));
122  // histo for hits not associated to the segment
123  histos.push_back(ibooker.book1D(
124  "hEffUnassOccupancy"+lHistoName, "4D segments recHits and Hits not associated occupancy",
125  lastWire-firstWire+1, firstWire-0.5, lastWire+0.5));
126  // histo for cells associated to the 4D reconstructed segment
127  histos.push_back(ibooker.book1D(
128  "hRecSegmOccupancy"+lHistoName, "4D segments cells occupancy",lastWire-firstWire+1, firstWire-0.5, lastWire+0.5));
129 
130  histosPerL[layerId] = histos;
131 
132  } // layer
133  } // superlayer
134  } // chambers
135 }
136 
138 
139 
140  if(lumiSeg.id().luminosityBlock()%parameters.getUntrackedParameter<int>("ResetCycle", 3) == 0) {
141  for(map<DTLayerId, vector<MonitorElement*> > ::const_iterator histo = histosPerL.begin();
142  histo != histosPerL.end();
143  histo++) {
144  int size = (*histo).second.size();
145  for(int i=0; i<size; i++){
146  (*histo).second[i]->Reset();
147  }
148  }
149  }
150 
151 }
152 
154 
155 
156  if(debug)
157  cout << "[DTEfficiencyTask] Analyze #Run: " << event.id().run()
158  << " #Event: " << event.id().event() << endl;
159 
160 
161  // Get the 4D segment collection from the event
163  event.getByToken(recHits4DToken_, all4DSegments);
164 
165  // Get the rechit collection from the event
166  Handle<DTRecHitCollection> dtRecHits;
167  event.getByToken(recHitToken_, dtRecHits);
168 
169  // Get the DT Geometry
170  ESHandle<DTGeometry> dtGeom;
171  setup.get<MuonGeometryRecord>().get(dtGeom);
172 
173  // Loop over all chambers containing a segment
174  DTRecSegment4DCollection::id_iterator chamberId;
175  for (chamberId = all4DSegments->id_begin();
176  chamberId != all4DSegments->id_end();
177  ++chamberId) {
178 
179  // Get the chamber
180  const DTChamber* chamber = dtGeom->chamber(*chamberId);
181 
182  // Get all 1D RecHits to be used for searches of hits not associated to segments and map them by wire
183  const vector<const DTSuperLayer*> SLayers = chamber->superLayers();
184  map<DTWireId, int> wireAnd1DRecHits;
185  for(vector<const DTSuperLayer*>::const_iterator superlayer = SLayers.begin();
186  superlayer != SLayers.end();
187  superlayer++) {
188  DTRecHitCollection::range range = dtRecHits->get(DTRangeMapAccessor::layersBySuperLayer((*superlayer)->id()));
189  // Loop over the rechits of this ChamberId
190  for (DTRecHitCollection::const_iterator rechit = range.first;
191  rechit!=range.second;
192  ++rechit){
193  wireAnd1DRecHits[(*rechit).wireId()] = (*rechit).wireId().wire();
194  }
195  }
196 
197 
198  // Get the 4D segment range for the corresponding ChamerId
199  DTRecSegment4DCollection::range range = all4DSegments->get(*chamberId);
200  int nsegm = distance(range.first, range.second);
201  if(debug)
202  cout << " Chamber: " << *chamberId << " has " << nsegm
203  << " 4D segments" << endl;
204 
205 
206  // Loop over the rechits of this ChamerId
207  for (DTRecSegment4DCollection::const_iterator segment4D = range.first;
208  segment4D!=range.second;
209  ++segment4D) {
210  if(debug)
211  cout << " == RecSegment dimension: " << (*segment4D).dimension() << endl;
212 
213  // If Station != 4 skip RecHits with dimension != 4
214  // For the Station 4 consider 2D RecHits
215  if((*chamberId).station() != 4 && (*segment4D).dimension() != 4) {
216  if(debug)
217  cout << "[DTEfficiencyTask]***Warning: RecSegment dimension is not 4 but "
218  << (*segment4D).dimension() << ", skipping!" << endl;
219  continue;
220  } else if((*chamberId).station() == 4 && (*segment4D).dimension() != 2) {
221  if(debug)
222  cout << "[DTEfficiencyTask]***Warning: RecSegment dimension is not 2 but "
223  << (*segment4D).dimension() << ", skipping!" << endl;
224  continue;
225  }
226 
227  vector<DTRecHit1D> recHits1D;
228  bool rPhi = false;
229  bool rZ = false;
230 
231  // Get 1D RecHits and select only events with 7 or 8 hits in phi and 3 or 4 hits in theta (if any)
232  const DTChamberRecSegment2D* phiSeg = (*segment4D).phiSegment();
233  vector<DTRecHit1D> phiRecHits = phiSeg->specificRecHits();
234  rPhi = true;
235  if(phiRecHits.size() < 7 || phiRecHits.size() > 8 ) {
236  if(debug)
237  cout << "[DTEfficiencyTask] Phi segments has: " << phiRecHits.size()
238  << " hits, skipping" << endl; // FIXME: info output
239  continue;
240  }
241  copy(phiRecHits.begin(), phiRecHits.end(), back_inserter(recHits1D));
242  const DTSLRecSegment2D* zSeg = 0;
243  if((*segment4D).dimension() == 4) {
244  rZ = true;
245  zSeg = (*segment4D).zSegment();
246  vector<DTRecHit1D> zRecHits = zSeg->specificRecHits();
247  if(zRecHits.size() < 3 || zRecHits.size() > 4 ) {
248  if(debug)
249  cout << "[DTEfficiencyTask] Theta segments has: " << zRecHits.size()
250  << " hits, skipping" << endl; // FIXME: info output
251  continue;
252  }
253  copy(zRecHits.begin(), zRecHits.end(), back_inserter(recHits1D));
254  }
255 
256  // Skip the segment if it has more than 1 hit on the same layer
257  vector<DTWireId> wireMap;
258  for(vector<DTRecHit1D>::const_iterator recHit1D = recHits1D.begin();
259  recHit1D != recHits1D.end();
260  recHit1D++) {
261  wireMap.push_back((*recHit1D).wireId());
262  }
263 
264  bool hitsOnSameLayer = false;
265  for(vector<DTWireId>::const_iterator channelId = wireMap.begin();
266  channelId != wireMap.end(); channelId++) {
267  vector<DTWireId>::const_iterator next = channelId;
268  next++;
269  for(vector<DTWireId>::const_iterator ite = next; ite != wireMap.end(); ite++) {
270  if((*channelId).layerId() == (*ite).layerId()) {
271  hitsOnSameLayer = true;
272  }
273  }
274  }
275  if(hitsOnSameLayer) {
276  if(debug)
277  cout << "[DTEfficiencyTask] This RecHit has 2 hits on the same layer, skipping!" << endl;
278  continue;
279  }
280 
281 
282  // Select 2D segments with angle smaller than 45 deg
283  LocalVector phiDirectionInChamber = (*phiSeg).localDirection();
284  if(rPhi && fabs(phiDirectionInChamber.x()/phiDirectionInChamber.z()) > 1) {
285  if(debug) {
286  cout << " RPhi segment has angle > 45 deg, skipping! " << endl;
287  cout << " Theta = " << phiDirectionInChamber.theta() << endl;
288  }
289  continue;
290  }
291  if(rZ) {
292  LocalVector zDirectionInChamber = (*zSeg).localDirection();
293  if(fabs(zDirectionInChamber.y()/zDirectionInChamber.z()) > 1) {
294  if(debug){
295  cout << " RZ segment has angle > 45 deg, skipping! " << endl;
296  cout << " Theta = " << zDirectionInChamber.theta() << endl;
297  }
298  continue;
299  }
300  }
301 
302 
303  // Skip if the 4D segment has only 10 hits
304  if(recHits1D.size() == 10) {
305  if(debug)
306  cout << "[DTEfficiencyTask] 4D Segment with only 10 hits, skipping!" << endl;
307  continue;
308  }
309 
310 
311  // Analyse the case of 11 recHits for MB1,MB2,MB3 and of 7 recHits for MB4
312  if((rPhi && recHits1D.size() == 7) || (rZ && recHits1D.size() == 11)) {
313 
314  if(debug) {
315  if(rPhi && recHits1D.size() == 7)
316  cout << "[DTEfficiencyTask] MB4 Segment with only 7 hits!" << endl;
317  if(rZ && recHits1D.size() == 11)
318  cout << "[DTEfficiencyTask] 4D Segment with only 11 hits!" << endl;
319  }
320 
321  // Find the layer without RecHits ----------------------------------------
322  const vector<const DTSuperLayer*> SupLayers = chamber->superLayers();
323  map<DTLayerId, bool> layerMap;
324  map<DTWireId, float> wireAndPosInChamberAtLayerZ;
325  // Loop over layers and wires to fill a map
326  for(vector<const DTSuperLayer*>::const_iterator superlayer = SupLayers.begin();
327  superlayer != SupLayers.end();
328  superlayer++) {
329  const vector<const DTLayer*> Layers = (*superlayer)->layers();
330  for(vector<const DTLayer*>::const_iterator layer = Layers.begin();
331  layer != Layers.end();
332  layer++) {
333  layerMap.insert(make_pair((*layer)->id(), false));
334  const int firstWire = dtGeom->layer((*layer)->id())->specificTopology().firstChannel();
335  const int lastWire = dtGeom->layer((*layer)->id())->specificTopology().lastChannel();
336  for(int i=firstWire; i - lastWire <= 0; i++) {
337  DTWireId wireId((*layer)->id(), i);
338  float wireX = (*layer)->specificTopology().wirePosition(wireId.wire());
339  LocalPoint wirePosInLay(wireX,0,0);
340  GlobalPoint wirePosGlob = (*layer)->toGlobal(wirePosInLay);
341  LocalPoint wirePosInChamber = chamber->toLocal(wirePosGlob);
342  if((*superlayer)->id().superlayer() == 1 || (*superlayer)->id().superlayer() == 3) {
343  wireAndPosInChamberAtLayerZ.insert(make_pair(wireId, wirePosInChamber.x()));
344  } else {
345  wireAndPosInChamberAtLayerZ.insert(make_pair(wireId, wirePosInChamber.y()));
346  }
347  }
348  }
349  }
350 
351  // Loop over segment 1D RecHit
352  map<DTLayerId, int> NumWireMap;
353  for(vector<DTRecHit1D>::const_iterator recHit = recHits1D.begin();
354  recHit != recHits1D.end();
355  recHit++) {
356  layerMap[(*recHit).wireId().layerId()]= true;
357  NumWireMap[(*recHit).wireId().layerId()]= (*recHit).wireId().wire();
358  }
359 
360  DTLayerId missLayerId;
361  //Loop over the map and find the layer without hits
362  for(map<DTLayerId, bool>::const_iterator iter = layerMap.begin();
363  iter != layerMap.end(); iter++) {
364  if(!(*iter).second) missLayerId = (*iter).first;
365  }
366  if(debug)
367  cout << "[DTEfficiencyTask] Layer without recHits is: " << missLayerId << endl;
368  // -------------------------------------------------------
369 
370  const DTLayer* missLayer = chamber->layer(missLayerId);
371 
372  LocalPoint missLayerPosInChamber = chamber->toLocal(missLayer->toGlobal(LocalPoint(0,0,0)));
373 
374  // Segment position at Wire z in chamber local frame
375  LocalPoint segPosAtZLayer = (*segment4D).localPosition()
376  + (*segment4D).localDirection()*missLayerPosInChamber.z()/cos((*segment4D).localDirection().theta());
377 
378  DTWireId missWireId;
379 
380  // Find the id of the cell without hit ---------------------------------------------------
381  for(map<DTWireId, float>::const_iterator wireAndPos = wireAndPosInChamberAtLayerZ.begin();
382  wireAndPos != wireAndPosInChamberAtLayerZ.end();
383  wireAndPos++) {
384  DTWireId wireId = (*wireAndPos).first;
385  if(wireId.layerId() == missLayerId) {
386  if(missLayerId.superlayerId().superlayer() == 1 || missLayerId.superlayerId().superlayer() == 3 ) {
387  if(fabs(segPosAtZLayer.x() - (*wireAndPos).second) < 2.1)
388  missWireId = wireId;
389  } else {
390  if(fabs(segPosAtZLayer.y() - (*wireAndPos).second) < 2.1)
391  missWireId = wireId;
392  }
393  }
394  }
395  if(debug)
396  cout << "[DTEfficiencyTask] Cell without hit is: " << missWireId << endl;
397  // ----------------------------------------------------------
398 
399  bool foundUnAssRechit = false;
400 
401  // Look for unassociated hits in this cell
402  if(wireAnd1DRecHits.find(missWireId) != wireAnd1DRecHits.end()) {
403  if(debug)
404  cout << "[DTEfficiencyTask] Unassociated Hit found!" << endl;
405  foundUnAssRechit = true;
406  }
407 
408 
409  for(map<DTLayerId, bool>::const_iterator iter = layerMap.begin();
410  iter != layerMap.end(); iter++) {
411  if((*iter).second)
412  fillHistos((*iter).first, dtGeom->layer((*iter).first)->specificTopology().firstChannel(), dtGeom->layer((*iter).first)->specificTopology().lastChannel(), NumWireMap[(*iter).first]);
413  else
414  fillHistos((*iter).first, dtGeom->layer((*iter).first)->specificTopology().firstChannel(), dtGeom->layer((*iter).first)->specificTopology().lastChannel(), missWireId.wire(), foundUnAssRechit);
415  }
416 
417  } // End of the loop for segment with 7 or 11 recHits
418 
419  if((rPhi && recHits1D.size() == 8) || (rZ && recHits1D.size() == 12)) {
420  map<DTLayerId, int> NumWireMap;
421  DTLayerId LayerID;
422  for(vector<DTRecHit1D>::const_iterator recHit = recHits1D.begin();
423  recHit != recHits1D.end();
424  recHit++) {
425  LayerID = (*recHit).wireId().layerId();
426  NumWireMap[LayerID]= (*recHit).wireId().wire();
427  }
428  for(map<DTLayerId, int>::const_iterator iter = NumWireMap.begin();
429  iter != NumWireMap.end(); iter++) {
430  fillHistos((*iter).first, dtGeom->layer((*iter).first)->specificTopology().firstChannel(), dtGeom->layer((*iter).first)->specificTopology().lastChannel(), NumWireMap[(*iter).first]);
431  }
432  }
433 
434  } // End of loop over the 4D segments inside a sigle chamber
435  } // End of loop over all tha chamber with at least a 4D segment in the event
436 }
437 
438 
439 // Fill a set of histograms for a given Layer
441  int firstWire, int lastWire,
442  int numWire) {
443 
444  vector<MonitorElement *> histos = histosPerL[lId];
445  histos[0]->Fill(numWire);
446  histos[1]->Fill(numWire);
447  histos[2]->Fill(numWire);
448 }
449 
450 // Fill a set of histograms for a given Layer
452  int firstWire, int lastWire,
453  int missingWire,
454  bool unassHit) {
455 
456  vector<MonitorElement *> histos = histosPerL[lId];
457  if(unassHit)
458  histos[1]->Fill(missingWire);
459  histos[2]->Fill(missingWire);
460 }
461 
462 // Local Variables:
463 // show-trailing-whitespace: t
464 // truncate-lines: t
465 // End:
LuminosityBlockID id() const
T getParameter(std::string const &) const
T getUntrackedParameter(std::string const &, T const &) const
int i
Definition: DBlmapReader.cc:9
std::pair< const_iterator, const_iterator > range
iterator range
Definition: RangeMap.h:50
void beginLuminosityBlock(edm::LuminosityBlock const &lumiSeg, edm::EventSetup const &context)
To reset the MEs.
DTChamberId chamberId() const
Return the corresponding ChamberId.
GlobalPoint toGlobal(const Local2DPoint &lp) const
Conversion to the global R.F. from the R.F. of the GeomDet.
Definition: GeomDet.h:52
static std::pair< DTLayerId, DTSuperLayerIdComparator > layersBySuperLayer(DTSuperLayerId slId)
Access by SL objects written into a RangeMap by layer.
T y() const
Definition: PV3DBase.h:63
LocalPoint toLocal(const GlobalPoint &gp) const
Conversion to the R.F. of the GeomDet.
Definition: GeomDet.h:67
const DTLayer * layer(DTLayerId id) const
Return the layer corresponding to the given id.
Definition: DTChamber.cc:80
int layer() const
Return the layer number.
Definition: DTLayerId.h:53
DTSuperLayerId superlayerId() const
Return the corresponding SuperLayerId.
Definition: DTLayerId.h:59
void fillHistos(DTLayerId lId, int firstWire, int lastWire, int numWire)
Geom::Theta< T > theta() const
Definition: PV3DBase.h:75
const std::vector< const DTSuperLayer * > & superLayers() const
Return the superlayers in the chamber.
Definition: DTChamber.cc:60
T z() const
Definition: PV3DBase.h:64
Cos< T >::type cos(const T &t)
Definition: Cos.h:22
MonitorElement * book1D(Args &&...args)
Definition: DQMStore.h:115
How EventSelector::AcceptEvent() decides whether to accept an event for output otherwise it is excluding the probing of A single or multiple positive and the trigger will pass if any such matching triggers are PASS or EXCEPTION[A criterion thatmatches no triggers at all is detected and causes a throw.] A single negative with an expectation of appropriate bit checking in the decision and the trigger will pass if any such matching triggers are FAIL or EXCEPTION A wildcarded negative criterion that matches more than one trigger in the trigger but the state exists so we define the behavior If all triggers are the negative crieriion will lead to accepting the event(this again matches the behavior of"!*"before the partial wildcard feature was incorporated).The per-event"cost"of each negative criterion with multiple relevant triggers is about the same as!*was in the past
std::vector< DTRecHit1D > specificRecHits() const
Access to specific components.
virtual ~DTEfficiencyTask()
Destructor.
int superlayer() const
Return the superlayer number (deprecated method name)
#define debug
Definition: HDRShower.cc:19
void setCurrentFolder(const std::string &fullpath)
Definition: DQMStore.cc:273
void analyze(const edm::Event &event, const edm::EventSetup &setup)
const T & get() const
Definition: EventSetup.h:56
LuminosityBlockNumber_t luminosityBlock() const
void bookHistograms(DQMStore::IBooker &, edm::Run const &, edm::EventSetup const &) override
void dqmBeginRun(const edm::Run &, const edm::EventSetup &)
BeginRun.
DTLayerId layerId() const
Return the corresponding LayerId.
Definition: DTWireId.h:62
DTEfficiencyTask(const edm::ParameterSet &pset)
Constructor.
int sector() const
Definition: DTChamberId.h:61
tuple cout
Definition: gather_cfg.py:145
int station() const
Return the station number.
Definition: DTChamberId.h:51
int wheel() const
Return the wheel number.
Definition: DTChamberId.h:45
T x() const
Definition: PV3DBase.h:62
void setup(std::vector< TH2F > &depth, std::string name, std::string units="")
tuple size
Write out results.
Definition: Run.h:43