CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
DTResolutionAnalysisTask.cc
Go to the documentation of this file.
1 
2 /*
3  * See header file for a description of this class.
4  *
5  * $Date: 2010/01/05 10:14:40 $
6  * $Revision: 1.21 $
7  * \author G. Cerminara - INFN Torino
8  */
9 
11 
12 // Framework
18 
20 
23 
24 //Geometry
27 
28 //RecHit
31 
32 
33 #include <iterator>
34 
35 using namespace edm;
36 using namespace std;
37 
39 
40  edm::LogVerbatim ("DTDQM|DTMonitorModule|DTResolutionAnalysisTask") << "[DTResolutionAnalysisTask] Constructor called!" << endl;
41 
42  // the name of the 4D rec hits collection
43  theRecHits4DLabel = pset.getParameter<string>("recHits4DLabel");
44 
45  prescaleFactor = pset.getUntrackedParameter<int>("diagnosticPrescale", 1);
46  resetCycle = pset.getUntrackedParameter<int>("ResetCycle", -1);
47  // top folder for the histograms in DQMStore
48  topHistoFolder = pset.getUntrackedParameter<string>("topHistoFolder","DT/02-Segments");
49 
50 }
51 
52 
54 
55  edm::LogVerbatim ("DTDQM|DTMonitorModule|DTResolutionAnalysisTask") << "[DTResolutionAnalysisTask] Destructor called!" << endl;
56 
57 }
58 
60 
61  // Get the DQM needed services
62  theDbe = edm::Service<DQMStore>().operator->();
63  // theDbe->setCurrentFolder("DT/02-Segments");
64 
65  // Get the DT Geometry
66  setup.get<MuonGeometryRecord>().get(dtGeom);
67 
68  // Book the histograms
69  vector<DTChamber*> chambers = dtGeom->chambers();
70  for(vector<DTChamber*>::const_iterator chamber = chambers.begin();
71  chamber != chambers.end(); ++chamber) { // Loop over all chambers
72  DTChamberId dtChId = (*chamber)->id();
73  for(int sl = 1; sl <= 3; ++sl) { // Loop over SLs
74  if(dtChId.station() == 4 && sl == 2) continue;
75  const DTSuperLayerId dtSLId(dtChId,sl);
76  bookHistos(dtSLId);
77  }
78  }
79 
80 }
81 
82 
83 
84 
86  const EventSetup& context) {
87 
88  edm::LogVerbatim ("DTDQM|DTMonitorModule|DTResolutionAnalysisTask") << "[DTResolutionTask]: Begin of LS transition"<<endl;
89 
90  if(resetCycle != -1 && lumiSeg.id().luminosityBlock() % resetCycle == 0) {
91  for(map<DTSuperLayerId, vector<MonitorElement*> > ::const_iterator histo = histosPerSL.begin();
92  histo != histosPerSL.end();
93  histo++) {
94  int size = (*histo).second.size();
95  for(int i=0; i<size; i++){
96  (*histo).second[i]->Reset();
97  }
98  }
99  }
100 }
101 
102 
104 
105  edm::LogVerbatim ("DTDQM|DTMonitorModule|DTResolutionAnalysisTask") << "[DTResolutionAnalysisTask] endjob called!"<<endl;
106 
107 }
108 
109 
110 
112 
113  edm::LogVerbatim ("DTDQM|DTMonitorModule|DTResolutionAnalysisTask") << "[DTResolutionAnalysisTask] Analyze #Run: " << event.id().run()
114  << " #Event: " << event.id().event() << endl;
115 
116 
117  // Get the 4D segment collection from the event
119  event.getByLabel(theRecHits4DLabel, all4DSegments);
120 
121  // check the validity of the collection
122  if(!all4DSegments.isValid()) return;
123 
124  // Loop over all chambers containing a segment
126  for (chamberId = all4DSegments->id_begin();
127  chamberId != all4DSegments->id_end();
128  ++chamberId) {
129  // Get the range for the corresponding ChamerId
130  DTRecSegment4DCollection::range range = all4DSegments->get(*chamberId);
131  // int nsegm = distance(range.first, range.second);
132  //edm::LogVerbatim ("DTDQM|DTMonitorModule|DTResolutionAnalysisTask") << " Chamber: " << *chamberId << " has " << nsegm
133  //<< " 4D segments" << endl;
134  // Get the chamber
135  const DTChamber* chamber = dtGeom->chamber(*chamberId);
136 
137  // Loop over the rechits of this ChamerId
138  for (DTRecSegment4DCollection::const_iterator segment4D = range.first;
139  segment4D!=range.second;
140  ++segment4D) {
141  //edm::LogVerbatim ("DTDQM|DTMonitorModule|DTResolutionAnalysisTask") << " == RecSegment dimension: " << (*segment4D).dimension() << endl;
142 
143  // If Statio != 4 skip RecHits with dimension != 4
144  // For the Station 4 consider 2D RecHits
145  if((*chamberId).station() != 4 && (*segment4D).dimension() != 4) {
146  edm::LogVerbatim ("DTDQM|DTMonitorModule|DTResolutionAnalysisTask") << "[DTResolutionAnalysisTask]***Warning: RecSegment dimension is not 4 but "
147  << (*segment4D).dimension() << "!" << endl;
148  continue;
149  } else if((*chamberId).station() == 4 && (*segment4D).dimension() != 2) {
150  edm::LogVerbatim ("DTDQM|DTMonitorModule|DTResolutionAnalysisTask") << "[DTResolutionAnalysisTask]***Warning: RecSegment dimension is not 2 but "
151  << (*segment4D).dimension() << "!" << endl;
152  continue;
153  }
154 
155 
156  // Get all 1D RecHits at step 3 within the 4D segment
157  vector<DTRecHit1D> recHits1D_S3;
158 
159 
160  // Get 1D RecHits at Step 3 and select only events with
161  // 8 hits in phi and 4 hits in theta (if any)
162 
163  if((*segment4D).hasPhi()) { // has phi component
164  const DTChamberRecSegment2D* phiSeg = (*segment4D).phiSegment();
165  vector<DTRecHit1D> phiRecHits = phiSeg->specificRecHits();
166 
167  if(phiRecHits.size() != 8) {
168  //edm::LogVerbatim ("DTDQM|DTMonitorModule|DTResolutionAnalysisTask") << "[DTResolutionAnalysisTask] Phi segments has: " << phiRecHits.size()
169  //<< " hits" << endl; // FIXME: info output
170  continue;
171  }
172  copy(phiRecHits.begin(), phiRecHits.end(), back_inserter(recHits1D_S3));
173  } else {
174  //edm::LogVerbatim ("DTDQM|DTMonitorModule|DTResolutionAnalysisTask") << "[DTResolutionAnalysisTask] 4D segment has not phi component!" << endl;
175  }
176 
177  if((*segment4D).hasZed()) {
178  const DTSLRecSegment2D* zSeg = (*segment4D).zSegment();
179  vector<DTRecHit1D> zRecHits = zSeg->specificRecHits();
180  if(zRecHits.size() != 4) {
181  //edm::LogVerbatim ("DTDQM|DTMonitorModule|DTResolutionAnalysisTask") << "[DTResolutionAnalysisTask] Theta segments has: " << zRecHits.size()
182  //<< " hits, skipping" << endl; // FIXME: info output
183  continue;
184  }
185  copy(zRecHits.begin(), zRecHits.end(), back_inserter(recHits1D_S3));
186  }
187 
188  // Loop over 1D RecHit inside 4D segment
189  for(vector<DTRecHit1D>::const_iterator recHit1D = recHits1D_S3.begin();
190  recHit1D != recHits1D_S3.end();
191  recHit1D++) {
192  const DTWireId wireId = (*recHit1D).wireId();
193 
194  // Get the layer and the wire position
195  const DTLayer* layer = chamber->superLayer(wireId.superlayerId())->layer(wireId.layerId());
196  float wireX = layer->specificTopology().wirePosition(wireId.wire());
197 
198  // Distance of the 1D rechit from the wire
199  float distRecHitToWire = fabs(wireX - (*recHit1D).localPosition().x());
200 
201  // Extrapolate the segment to the z of the wire
202 
203  // Get wire position in chamber RF
204  LocalPoint wirePosInLay(wireX,(*recHit1D).localPosition().y(),(*recHit1D).localPosition().z());
205  GlobalPoint wirePosGlob = layer->toGlobal(wirePosInLay);
206  LocalPoint wirePosInChamber = chamber->toLocal(wirePosGlob);
207 
208  // Segment position at Wire z in chamber local frame
209  LocalPoint segPosAtZWire = (*segment4D).localPosition()
210  + (*segment4D).localDirection()*wirePosInChamber.z()/cos((*segment4D).localDirection().theta());
211 
212  // Compute the distance of the segment from the wire
213  int sl = wireId.superlayer();
214 
215  double distSegmToWire = -1;
216  if(sl == 1 || sl == 3) {
217  // RPhi SL
218  distSegmToWire = fabs(wirePosInChamber.x() - segPosAtZWire.x());
219  } else if(sl == 2) {
220  // RZ SL
221  distSegmToWire = fabs(wirePosInChamber.y() - segPosAtZWire.y());
222  }
223 
224  if(distSegmToWire > 2.1)
225  edm::LogVerbatim ("DTDQM|DTMonitorModule|DTResolutionAnalysisTask") << " Warning: dist segment-wire: " << distSegmToWire << endl;
226 
227  double residual = distRecHitToWire - distSegmToWire;
228  // FIXME: Fill the histos
229  fillHistos(wireId.superlayerId(), distSegmToWire, residual);
230 
231  // edm::LogVerbatim ("DTDQM|DTMonitorModule|DTResolutionAnalysisTask") << " Dist. segment extrapolation - wire (cm): " << distSegmToWire << endl;
232  //edm::LogVerbatim ("DTDQM|DTMonitorModule|DTResolutionAnalysisTask") << " Dist. RecHit - wire (cm): " << distRecHitToWire << endl;
233  //edm::LogVerbatim ("DTDQM|DTMonitorModule|DTResolutionAnalysisTask") << " Residual (cm): " << residual << endl;
234 
235 
236  }// End of loop over 1D RecHit inside 4D segment
237  }// End of loop over the rechits of this ChamerId
238  }
239  // -----------------------------------------------------------------------------
240 }
241 
242 
243 // Book a set of histograms for a given SL
245 
246  edm::LogVerbatim ("DTDQM|DTMonitorModule|DTResolutionAnalysisTask") << " Booking histos for SL: " << slId << endl;
247 
248  // Compose the chamber name
249  stringstream wheel; wheel << slId.wheel();
250  stringstream station; station << slId.station();
251  stringstream sector; sector << slId.sector();
252  stringstream superLayer; superLayer << slId.superlayer();
253 
254 
255  string slHistoName =
256  "_W" + wheel.str() +
257  "_St" + station.str() +
258  "_Sec" + sector.str() +
259  "_SL" + superLayer.str();
260 
261  theDbe->setCurrentFolder(topHistoFolder + "/Wheel" + wheel.str() +
262  "/Sector" + sector.str() +
263  "/Station" + station.str());
264  // Create the monitor elements
265  vector<MonitorElement *> histos;
266  // Note hte order matters
267  histos.push_back(theDbe->book1D("hResDist"+slHistoName,
268  "Residuals on the distance from wire (rec_hit - segm_extr) (cm)",
269  200, -0.4, 0.4));
270  //FIXME: 2D plot removed to reduce the # of ME
271 // histos.push_back(theDbe->book2D("hResDistVsDist"+slHistoName,
272 // "Residuals on the distance (cm) from wire (rec_hit - segm_extr) vs distance (cm)",
273 // 100, 0, 2.5, 200, -0.4, 0.4));
274  histosPerSL[slId] = histos;
275 }
276 
277 
278 // Fill a set of histograms for a given SL
280  float distExtr,
281  float residual) {
282  vector<MonitorElement *> histos = histosPerSL[slId];
283  histos[0]->Fill(residual);
284  //FIXME: 2D plot removed to reduce the # of ME
285  // histos[1]->Fill(distExtr, residual);
286 
287 }
288 
289 
290 
LuminosityBlockID id() const
T getParameter(std::string const &) const
T getUntrackedParameter(std::string const &, T const &) const
float wirePosition(int wireNumber) const
Returns the x position in the layer of a given wire number.
Definition: DTTopology.cc:73
int i
Definition: DBlmapReader.cc:9
std::pair< const_iterator, const_iterator > range
iterator range
Definition: RangeMap.h:52
GlobalPoint toGlobal(const Local2DPoint &lp) const
Conversion to the global R.F. from the R.F. of the GeomDet.
Definition: GeomDet.h:49
T y() const
Definition: PV3DBase.h:57
LocalPoint toLocal(const GlobalPoint &gp) const
Conversion to the R.F. of the GeomDet.
Definition: GeomDet.h:64
identifier iterator
Definition: RangeMap.h:138
static char chambers[TOTALCHAMBERS][20]
Definition: ReadPGInfo.cc:243
tuple histo
Definition: trackerHits.py:12
DTSuperLayerId superlayerId() const
Return the corresponding SuperLayerId.
Definition: DTLayerId.h:61
dictionary map
Definition: Association.py:160
void bookHistos()
Definition: Histogram.h:33
void analyze(const edm::Event &event, const edm::EventSetup &setup)
C::const_iterator const_iterator
constant access iterator type
Definition: RangeMap.h:45
const DTTopology & specificTopology() const
Definition: DTLayer.cc:44
T z() const
Definition: PV3DBase.h:58
Cos< T >::type cos(const T &t)
Definition: Cos.h:22
tuple pset
Definition: CrabTask.py:85
void beginRun(const edm::Run &, const edm::EventSetup &)
BeginRun.
void beginLuminosityBlock(edm::LuminosityBlock const &lumiSeg, edm::EventSetup const &context)
To reset the MEs.
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
bool isValid() const
Definition: HandleBase.h:76
std::vector< DTRecHit1D > specificRecHits() const
Access to specific components.
int wire() const
Return the wire number.
Definition: DTWireId.h:58
int superlayer() const
Return the superlayer number (deprecated method name)
dictionary histos
Definition: combine.py:3
const T & get() const
Definition: EventSetup.h:55
LuminosityBlockNumber_t luminosityBlock() const
DTLayerId layerId() const
Return the corresponding LayerId.
Definition: DTWireId.h:64
int sector() const
Definition: DTChamberId.h:63
void fillHistos(DTSuperLayerId slId, float distExtr, float residual)
int station() const
Return the station number.
Definition: DTChamberId.h:53
int wheel() const
Return the wheel number.
Definition: DTChamberId.h:47
T x() const
Definition: PV3DBase.h:56
DTResolutionAnalysisTask(const edm::ParameterSet &pset)
Constructor.
void bookHistos(DTSuperLayerId slId)
virtual ~DTResolutionAnalysisTask()
Destructor.
tuple size
Write out results.
Definition: Run.h:31
const DTSuperLayer * superLayer(DTSuperLayerId id) const
Return the superlayer corresponding to the given id.
Definition: DTChamber.cc:67