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