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