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 
3 /*
4  * See header file for a description of this class.
5  *
6  * \author G. Mila - INFN Torino
7  */
8 
9 
10 #include "DTEfficiencyTask.h"
11 
12 
13 // Framework
19 
22 
23 //Geometry
26 
27 //RecHit
29 
32 
33 #include <iterator>
34 
35 using namespace edm;
36 using namespace std;
37 
38 
40 
41  debug = pset.getUntrackedParameter<bool>("debug",false);
42  // the name of the 4D rec hits collection
43  recHits4DToken_ = consumes<DTRecSegment4DCollection>(
44  edm::InputTag(pset.getParameter<string>("recHits4DLabel")));
45  // the name of the rechits collection
46  recHitToken_ = consumes<DTRecHitCollection>(
47  edm::InputTag(pset.getParameter<string>("recHitLabel")));
48 
49  // Get the DQM needed services
50  theDbe = edm::Service<DQMStore>().operator->();
51  theDbe->setCurrentFolder("DT/DTEfficiencyTask");
52 
53  parameters = pset;
54 }
55 
56 
58 }
59 
60 
62 }
63 
64 
66 
67 
68  if(lumiSeg.id().luminosityBlock()%parameters.getUntrackedParameter<int>("ResetCycle", 3) == 0) {
69  for(map<DTLayerId, vector<MonitorElement*> > ::const_iterator histo = histosPerL.begin();
70  histo != histosPerL.end();
71  histo++) {
72  int size = (*histo).second.size();
73  for(int i=0; i<size; i++){
74  (*histo).second[i]->Reset();
75  }
76  }
77  }
78 
79 }
80 
81 
83  theDbe->rmdir("DT/DTEfficiencyTask");
84 }
85 
86 
88 
89 
90  if(debug)
91  cout << "[DTEfficiencyTask] Analyze #Run: " << event.id().run()
92  << " #Event: " << event.id().event() << endl;
93 
94 
95  // Get the 4D segment collection from the event
97  event.getByToken(recHits4DToken_, all4DSegments);
98 
99  // Get the rechit collection from the event
100  Handle<DTRecHitCollection> dtRecHits;
101  event.getByToken(recHitToken_, dtRecHits);
102 
103  // Get the DT Geometry
104  ESHandle<DTGeometry> dtGeom;
105  setup.get<MuonGeometryRecord>().get(dtGeom);
106 
107  // Loop over all chambers containing a segment
108  DTRecSegment4DCollection::id_iterator chamberId;
109  for (chamberId = all4DSegments->id_begin();
110  chamberId != all4DSegments->id_end();
111  ++chamberId) {
112 
113  // Get the chamber
114  const DTChamber* chamber = dtGeom->chamber(*chamberId);
115 
116  // Get all 1D RecHits to be used for searches of hits not associated to segments and map them by wire
117  const vector<const DTSuperLayer*> SLayers = chamber->superLayers();
118  map<DTWireId, int> wireAnd1DRecHits;
119  for(vector<const DTSuperLayer*>::const_iterator superlayer = SLayers.begin();
120  superlayer != SLayers.end();
121  superlayer++) {
122  DTRecHitCollection::range range = dtRecHits->get(DTRangeMapAccessor::layersBySuperLayer((*superlayer)->id()));
123  // Loop over the rechits of this ChamberId
124  for (DTRecHitCollection::const_iterator rechit = range.first;
125  rechit!=range.second;
126  ++rechit){
127  wireAnd1DRecHits[(*rechit).wireId()] = (*rechit).wireId().wire();
128  }
129  }
130 
131 
132  // Get the 4D segment range for the corresponding ChamerId
133  DTRecSegment4DCollection::range range = all4DSegments->get(*chamberId);
134  int nsegm = distance(range.first, range.second);
135  if(debug)
136  cout << " Chamber: " << *chamberId << " has " << nsegm
137  << " 4D segments" << endl;
138 
139 
140  // Loop over the rechits of this ChamerId
141  for (DTRecSegment4DCollection::const_iterator segment4D = range.first;
142  segment4D!=range.second;
143  ++segment4D) {
144  if(debug)
145  cout << " == RecSegment dimension: " << (*segment4D).dimension() << endl;
146 
147  // If Statio != 4 skip RecHits with dimension != 4
148  // For the Station 4 consider 2D RecHits
149  if((*chamberId).station() != 4 && (*segment4D).dimension() != 4) {
150  if(debug)
151  cout << "[DTEfficiencyTask]***Warning: RecSegment dimension is not 4 but "
152  << (*segment4D).dimension() << ", skipping!" << endl;
153  continue;
154  } else if((*chamberId).station() == 4 && (*segment4D).dimension() != 2) {
155  if(debug)
156  cout << "[DTEfficiencyTask]***Warning: RecSegment dimension is not 2 but "
157  << (*segment4D).dimension() << ", skipping!" << endl;
158  continue;
159  }
160 
161  vector<DTRecHit1D> recHits1D;
162  bool rPhi = false;
163  bool rZ = false;
164 
165  // Get 1D RecHits and select only events with 7 or 8 hits in phi and 3 or 4 hits in theta (if any)
166  const DTChamberRecSegment2D* phiSeg = (*segment4D).phiSegment();
167  vector<DTRecHit1D> phiRecHits = phiSeg->specificRecHits();
168  rPhi = true;
169  if(phiRecHits.size() < 7 || phiRecHits.size() > 8 ) {
170  if(debug)
171  cout << "[DTEfficiencyTask] Phi segments has: " << phiRecHits.size()
172  << " hits, skipping" << endl; // FIXME: info output
173  continue;
174  }
175  copy(phiRecHits.begin(), phiRecHits.end(), back_inserter(recHits1D));
176  const DTSLRecSegment2D* zSeg = 0;
177  if((*segment4D).dimension() == 4) {
178  rZ = true;
179  zSeg = (*segment4D).zSegment();
180  vector<DTRecHit1D> zRecHits = zSeg->specificRecHits();
181  if(zRecHits.size() < 3 || zRecHits.size() > 4 ) {
182  if(debug)
183  cout << "[DTEfficiencyTask] Theta segments has: " << zRecHits.size()
184  << " hits, skipping" << endl; // FIXME: info output
185  continue;
186  }
187  copy(zRecHits.begin(), zRecHits.end(), back_inserter(recHits1D));
188  }
189 
190  // Skip the segment if it has more than 1 hit on the same layer
191  vector<DTWireId> wireMap;
192  for(vector<DTRecHit1D>::const_iterator recHit1D = recHits1D.begin();
193  recHit1D != recHits1D.end();
194  recHit1D++) {
195  wireMap.push_back((*recHit1D).wireId());
196  }
197 
198  bool hitsOnSameLayer = false;
199  for(vector<DTWireId>::const_iterator channelId = wireMap.begin();
200  channelId != wireMap.end(); channelId++) {
201  vector<DTWireId>::const_iterator next = channelId;
202  next++;
203  for(vector<DTWireId>::const_iterator ite = next; ite != wireMap.end(); ite++) {
204  if((*channelId).layerId() == (*ite).layerId()) {
205  hitsOnSameLayer = true;
206  }
207  }
208  }
209  if(hitsOnSameLayer) {
210  if(debug)
211  cout << "[DTEfficiencyTask] This RecHit has 2 hits on the same layer, skipping!" << endl;
212  continue;
213  }
214 
215 
216  // Select 2D segments with angle smaller than 45 deg
217  LocalVector phiDirectionInChamber = (*phiSeg).localDirection();
218  if(rPhi && fabs(phiDirectionInChamber.x()/phiDirectionInChamber.z()) > 1) {
219  if(debug) {
220  cout << " RPhi segment has angle > 45 deg, skipping! " << endl;
221  cout << " Theta = " << phiDirectionInChamber.theta() << endl;
222  }
223  continue;
224  }
225  if(rZ) {
226  LocalVector zDirectionInChamber = (*zSeg).localDirection();
227  if(fabs(zDirectionInChamber.y()/zDirectionInChamber.z()) > 1) {
228  if(debug){
229  cout << " RZ segment has angle > 45 deg, skipping! " << endl;
230  cout << " Theta = " << zDirectionInChamber.theta() << endl;
231  }
232  continue;
233  }
234  }
235 
236 
237  // Skip if the 4D segment has only 10 hits
238  if(recHits1D.size() == 10) {
239  if(debug)
240  cout << "[DTEfficiencyTask] 4D Segment with only 10 hits, skipping!" << endl;
241  continue;
242  }
243 
244 
245  // Analyse the case of 11 recHits for MB1,MB2,MB3 and of 7 recHits for MB4
246  if((rPhi && recHits1D.size() == 7) || (rZ && recHits1D.size() == 11)) {
247 
248  if(debug) {
249  if(rPhi && recHits1D.size() == 7)
250  cout << "[DTEfficiencyTask] MB4 Segment with only 7 hits!" << endl;
251  if(rZ && recHits1D.size() == 11)
252  cout << "[DTEfficiencyTask] 4D Segment with only 11 hits!" << endl;
253  }
254 
255  // Find the layer without RecHits ----------------------------------------
256  const vector<const DTSuperLayer*> SupLayers = chamber->superLayers();
257  map<DTLayerId, bool> layerMap;
258  map<DTWireId, float> wireAndPosInChamberAtLayerZ;
259  // Loop over layers and wires to fill a map
260  for(vector<const DTSuperLayer*>::const_iterator superlayer = SupLayers.begin();
261  superlayer != SupLayers.end();
262  superlayer++) {
263  const vector<const DTLayer*> Layers = (*superlayer)->layers();
264  for(vector<const DTLayer*>::const_iterator layer = Layers.begin();
265  layer != Layers.end();
266  layer++) {
267  layerMap.insert(make_pair((*layer)->id(), false));
268  const int firstWire = dtGeom->layer((*layer)->id())->specificTopology().firstChannel();
269  const int lastWire = dtGeom->layer((*layer)->id())->specificTopology().lastChannel();
270  for(int i=firstWire; i - lastWire <= 0; i++) {
271  DTWireId wireId((*layer)->id(), i);
272  float wireX = (*layer)->specificTopology().wirePosition(wireId.wire());
273  LocalPoint wirePosInLay(wireX,0,0);
274  GlobalPoint wirePosGlob = (*layer)->toGlobal(wirePosInLay);
275  LocalPoint wirePosInChamber = chamber->toLocal(wirePosGlob);
276  if((*superlayer)->id().superlayer() == 1 || (*superlayer)->id().superlayer() == 3) {
277  wireAndPosInChamberAtLayerZ.insert(make_pair(wireId, wirePosInChamber.x()));
278  } else {
279  wireAndPosInChamberAtLayerZ.insert(make_pair(wireId, wirePosInChamber.y()));
280  }
281  }
282  }
283  }
284 
285  // Loop over segment 1D RecHit
286  map<DTLayerId, int> NumWireMap;
287  for(vector<DTRecHit1D>::const_iterator recHit = recHits1D.begin();
288  recHit != recHits1D.end();
289  recHit++) {
290  layerMap[(*recHit).wireId().layerId()]= true;
291  NumWireMap[(*recHit).wireId().layerId()]= (*recHit).wireId().wire();
292  }
293 
294  DTLayerId missLayerId;
295  //Loop over the map and find the layer without hits
296  for(map<DTLayerId, bool>::const_iterator iter = layerMap.begin();
297  iter != layerMap.end(); iter++) {
298  if(!(*iter).second) missLayerId = (*iter).first;
299  }
300  if(debug)
301  cout << "[DTEfficiencyTask] Layer without recHits is: " << missLayerId << endl;
302  // -------------------------------------------------------
303 
304 
305 
306  const DTLayer* missLayer = chamber->layer(missLayerId);
307 
308  LocalPoint missLayerPosInChamber = chamber->toLocal(missLayer->toGlobal(LocalPoint(0,0,0)));
309 
310  // Segment position at Wire z in chamber local frame
311  LocalPoint segPosAtZLayer = (*segment4D).localPosition()
312  + (*segment4D).localDirection()*missLayerPosInChamber.z()/cos((*segment4D).localDirection().theta());
313 
314  DTWireId missWireId;
315 
316  // Find the id of the cell without hit ---------------------------------------------------
317  for(map<DTWireId, float>::const_iterator wireAndPos = wireAndPosInChamberAtLayerZ.begin();
318  wireAndPos != wireAndPosInChamberAtLayerZ.end();
319  wireAndPos++) {
320  DTWireId wireId = (*wireAndPos).first;
321  if(wireId.layerId() == missLayerId) {
322  if(missLayerId.superlayerId().superlayer() == 1 || missLayerId.superlayerId().superlayer() == 3 ) {
323  if(fabs(segPosAtZLayer.x() - (*wireAndPos).second) < 2.1)
324  missWireId = wireId;
325  } else {
326  if(fabs(segPosAtZLayer.y() - (*wireAndPos).second) < 2.1)
327  missWireId = wireId;
328  }
329  }
330  }
331  if(debug)
332  cout << "[DTEfficiencyTask] Cell without hit is: " << missWireId << endl;
333  // ----------------------------------------------------------
334 
335 
336  bool foundUnAssRechit = false;
337 
338  // Look for unassociated hits in this cell
339  if(wireAnd1DRecHits.find(missWireId) != wireAnd1DRecHits.end()) {
340  if(debug)
341  cout << "[DTEfficiencyTask] Unassociated Hit found!" << endl;
342  foundUnAssRechit = true;
343  }
344 
345 
346  for(map<DTLayerId, bool>::const_iterator iter = layerMap.begin();
347  iter != layerMap.end(); iter++) {
348  if((*iter).second)
349  fillHistos((*iter).first, dtGeom->layer((*iter).first)->specificTopology().firstChannel(), dtGeom->layer((*iter).first)->specificTopology().lastChannel(), NumWireMap[(*iter).first]);
350  else
351  fillHistos((*iter).first, dtGeom->layer((*iter).first)->specificTopology().firstChannel(), dtGeom->layer((*iter).first)->specificTopology().lastChannel(), missWireId.wire(), foundUnAssRechit);
352  }
353 
354  } // End of the loop for segment with 7 or 11 recHits
355 
356  if((rPhi && recHits1D.size() == 8) || (rZ && recHits1D.size() == 12)) {
357  map<DTLayerId, int> NumWireMap;
358  DTLayerId LayerID;
359  for(vector<DTRecHit1D>::const_iterator recHit = recHits1D.begin();
360  recHit != recHits1D.end();
361  recHit++) {
362  LayerID = (*recHit).wireId().layerId();
363  NumWireMap[LayerID]= (*recHit).wireId().wire();
364  }
365  for(map<DTLayerId, int>::const_iterator iter = NumWireMap.begin();
366  iter != NumWireMap.end(); iter++) {
367  fillHistos((*iter).first, dtGeom->layer((*iter).first)->specificTopology().firstChannel(), dtGeom->layer((*iter).first)->specificTopology().lastChannel(), NumWireMap[(*iter).first]);
368  }
369  }
370 
371  } // End of loop over the 4D segments inside a sigle chamber
372  } // End of loop over all tha chamber with at least a 4D segment in the event
373 }
374 
375 
376 // Book a set of histograms for a given Layer
377 void DTEfficiencyTask::bookHistos(DTLayerId lId, int firstWire, int lastWire) {
378  if(debug)
379  cout << " Booking histos for L: " << lId << endl;
380 
381  // Compose the chamber name
382  stringstream wheel; wheel << lId.superlayerId().chamberId().wheel();
383  stringstream station; station << lId.superlayerId().chamberId().station();
384  stringstream sector; sector << lId.superlayerId().chamberId().sector();
385  stringstream superLayer; superLayer << lId.superlayerId().superlayer();
386  stringstream layer; layer << lId.layer();
387 
388  string lHistoName =
389  "_W" + wheel.str() +
390  "_St" + station.str() +
391  "_Sec" + sector.str() +
392  "_SL" + superLayer.str()+
393  "_L" + layer.str();
394 
395  theDbe->setCurrentFolder("DT/DTEfficiencyTask/Wheel" + wheel.str() +
396  "/Station" + station.str() +
397  "/Sector" + sector.str() +
398  "/SuperLayer" +superLayer.str());
399  // Create the monitor elements
400  vector<MonitorElement *> histos;
401  // histo for hits associated to the 4D reconstructed segment
402  histos.push_back(theDbe->book1D("hEffOccupancy"+lHistoName, "4D segments recHits occupancy",lastWire-firstWire+1, firstWire-0.5, lastWire+0.5));
403  // histo for hits not associated to the segment
404  histos.push_back(theDbe->book1D("hEffUnassOccupancy"+lHistoName, "4D segments recHits and Hits not associated occupancy",lastWire-firstWire+1, firstWire-0.5, lastWire+0.5));
405  // histo for cells associated to the 4D reconstructed segment
406  histos.push_back(theDbe->book1D("hRecSegmOccupancy"+lHistoName, "4D segments cells occupancy",lastWire-firstWire+1, firstWire-0.5, lastWire+0.5));
407 
408  histosPerL[lId] = histos;
409 }
410 
411 
412 // Fill a set of histograms for a given Layer
414  int firstWire, int lastWire,
415  int numWire) {
416  if(histosPerL.find(lId) == histosPerL.end()){
417  bookHistos(lId, firstWire, lastWire);
418  }
419  vector<MonitorElement *> histos = histosPerL[lId];
420  histos[0]->Fill(numWire);
421  histos[1]->Fill(numWire);
422  histos[2]->Fill(numWire);
423 }
424 
425 // Fill a set of histograms for a given Layer
427  int firstWire, int lastWire,
428  int missingWire,
429  bool unassHit) {
430  if(histosPerL.find(lId) == histosPerL.end()){
431  bookHistos(lId, firstWire, lastWire);
432  }
433  vector<MonitorElement *> histos = histosPerL[lId];
434  if(unassHit)
435  histos[1]->Fill(missingWire);
436  histos[2]->Fill(missingWire);
437 }
438 
439 // Local Variables:
440 // show-trailing-whitespace: t
441 // truncate-lines: t
442 // End:
LuminosityBlockID id() const
T getParameter(std::string const &) const
T getUntrackedParameter(std::string const &, T const &) const
int i
Definition: DBlmapReader.cc:9
dictionary parameters
Definition: Parameters.py:2
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:47
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:62
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)
void bookHistos()
Definition: Histogram.h:33
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
void beginJob()
BeginJob.
T z() const
Definition: PV3DBase.h:64
Cos< T >::type cos(const T &t)
Definition: Cos.h:22
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
void bookHistos(DTLayerId lId, int fisrtWire, int lastWire)
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 analyze(const edm::Event &event, const edm::EventSetup &setup)
const T & get() const
Definition: EventSetup.h:55
LuminosityBlockNumber_t luminosityBlock() const
void endJob()
Endjob.
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:121
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.