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 DT Geometry
63  setup.get<MuonGeometryRecord>().get(dtGeom);
64 
65 }
66 
68  edm::Run const & iRun,
69  edm::EventSetup const & /* iSetup */) {
70 
71  // Book the histograms
72  vector<const DTChamber*> chambers = dtGeom->chambers();
73  for(vector<const 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(ibooker,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 
106 
107  edm::LogVerbatim ("DTDQM|DTMonitorModule|DTResolutionAnalysisTask") << "[DTResolutionAnalysisTask] Analyze #Run: " << event.id().run()
108  << " #Event: " << event.id().event() << endl;
109 
110 
111  // Get the 4D segment collection from the event
113  event.getByToken(recHits4DToken_, all4DSegments);
114 
115  // check the validity of the collection
116  if(!all4DSegments.isValid()) return;
117 
118  // Loop over all chambers containing a segment
119  DTRecSegment4DCollection::id_iterator chamberId;
120  for (chamberId = all4DSegments->id_begin();
121  chamberId != all4DSegments->id_end();
122  ++chamberId) {
123  // Get the range for the corresponding ChamerId
124  DTRecSegment4DCollection::range range = all4DSegments->get(*chamberId);
125 
126  // Get the chamber
127  const DTChamber* chamber = dtGeom->chamber(*chamberId);
128 
129  // Loop over the rechits of this ChamerId
130  for (DTRecSegment4DCollection::const_iterator segment4D = range.first;
131  segment4D!=range.second;
132  ++segment4D) {
133 
134  // If Statio != 4 skip RecHits with dimension != 4
135  // For the Station 4 consider 2D RecHits
136  if((*chamberId).station() != 4 && (*segment4D).dimension() != 4) {
137  edm::LogVerbatim ("DTDQM|DTMonitorModule|DTResolutionAnalysisTask") << "[DTResolutionAnalysisTask]***Warning: RecSegment dimension is not 4 but "
138  << (*segment4D).dimension() << "!" << endl;
139  continue;
140  } else if((*chamberId).station() == 4 && (*segment4D).dimension() != 2) {
141  edm::LogVerbatim ("DTDQM|DTMonitorModule|DTResolutionAnalysisTask") << "[DTResolutionAnalysisTask]***Warning: RecSegment dimension is not 2 but "
142  << (*segment4D).dimension() << "!" << endl;
143  continue;
144  }
145 
146 
147  // Get all 1D RecHits at step 3 within the 4D segment
148  vector<DTRecHit1D> recHits1D_S3;
149 
150 
151  // Get 1D RecHits at Step 3 and select only events with
152  // 8 hits in phi and 4 hits in theta (if any)
153 
154  if((*segment4D).hasPhi()) { // has phi component
155  const DTChamberRecSegment2D* phiSeg = (*segment4D).phiSegment();
156  vector<DTRecHit1D> phiRecHits = phiSeg->specificRecHits();
157 
158  if(phiRecHits.size() < thePhiHitsCut) {
159  continue;
160  }
161  copy(phiRecHits.begin(), phiRecHits.end(), back_inserter(recHits1D_S3));
162  } else {
163 
164  }
165 
166  if((*segment4D).hasZed()) {
167  const DTSLRecSegment2D* zSeg = (*segment4D).zSegment();
168  vector<DTRecHit1D> zRecHits = zSeg->specificRecHits();
169  if(zRecHits.size() < theZHitsCut) {
170 
171  continue;
172  }
173  copy(zRecHits.begin(), zRecHits.end(), back_inserter(recHits1D_S3));
174  }
175 
176  // Loop over 1D RecHit inside 4D segment
177  for(vector<DTRecHit1D>::const_iterator recHit1D = recHits1D_S3.begin();
178  recHit1D != recHits1D_S3.end();
179  recHit1D++) {
180  const DTWireId wireId = (*recHit1D).wireId();
181 
182  // Get the layer and the wire position
183  const DTLayer* layer = chamber->superLayer(wireId.superlayerId())->layer(wireId.layerId());
184  float wireX = layer->specificTopology().wirePosition(wireId.wire());
185 
186  // Distance of the 1D rechit from the wire
187  float distRecHitToWire = fabs(wireX - (*recHit1D).localPosition().x());
188 
189  // Extrapolate the segment to the z of the wire
190 
191  // Get wire position in chamber RF
192  LocalPoint wirePosInLay(wireX,(*recHit1D).localPosition().y(),(*recHit1D).localPosition().z());
193  GlobalPoint wirePosGlob = layer->toGlobal(wirePosInLay);
194  LocalPoint wirePosInChamber = chamber->toLocal(wirePosGlob);
195 
196  // Segment position at Wire z in chamber local frame
197  LocalPoint segPosAtZWire = (*segment4D).localPosition()
198  + (*segment4D).localDirection()*wirePosInChamber.z()/cos((*segment4D).localDirection().theta());
199 
200  // Compute the distance of the segment from the wire
201  int sl = wireId.superlayer();
202 
203  double distSegmToWire = -1;
204  if(sl == 1 || sl == 3) {
205  // RPhi SL
206  distSegmToWire = fabs(wirePosInChamber.x() - segPosAtZWire.x());
207  } else if(sl == 2) {
208  // RZ SL
209  distSegmToWire = fabs(wirePosInChamber.y() - segPosAtZWire.y());
210  }
211 
212  if(distSegmToWire > 2.1)
213  edm::LogVerbatim ("DTDQM|DTMonitorModule|DTResolutionAnalysisTask") << " Warning: dist segment-wire: " << distSegmToWire << endl;
214 
215  double residual = distRecHitToWire - distSegmToWire;
216  // FIXME: Fill the histos
217  fillHistos(wireId.superlayerId(), distSegmToWire, residual);
218 
219  }// End of loop over 1D RecHit inside 4D segment
220  }// End of loop over the rechits of this ChamerId
221  }
222  // -----------------------------------------------------------------------------
223 }
224 
225 
226 // Book a set of histograms for a given SL
228 
229  edm::LogVerbatim ("DTDQM|DTMonitorModule|DTResolutionAnalysisTask") << " Booking histos for SL: " << slId << endl;
230 
231  // Compose the chamber name
232  stringstream wheel; wheel << slId.wheel();
233  stringstream station; station << slId.station();
234  stringstream sector; sector << slId.sector();
235  stringstream superLayer; superLayer << slId.superlayer();
236 
237 
238  string slHistoName =
239  "_W" + wheel.str() +
240  "_St" + station.str() +
241  "_Sec" + sector.str() +
242  "_SL" + superLayer.str();
243 
244  ibooker.setCurrentFolder(topHistoFolder + "/Wheel" + wheel.str() +
245  "/Sector" + sector.str() +
246  "/Station" + station.str());
247  // Create the monitor elements
248  vector<MonitorElement *> histos;
249  // Note the order matters
250  histos.push_back(ibooker.book1D("hResDist"+slHistoName,
251  "Residuals on the distance from wire (rec_hit - segm_extr) (cm)",
252  200, -0.4, 0.4));
253  histosPerSL[slId] = histos;
254 }
255 
256 
257 // Fill a set of histograms for a given SL
259  float distExtr,
260  float residual) {
261  vector<MonitorElement *> histos = histosPerSL[slId];
262  histos[0]->Fill(residual);
263 }
264 
265 // Local Variables:
266 // show-trailing-whitespace: t
267 // truncate-lines: t
268 // 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
void dqmBeginRun(const edm::Run &, const edm::EventSetup &)
BeginRun.
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:52
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
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
MonitorElement * book1D(Args &&...args)
Definition: DQMStore.h:115
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:75
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)
void setCurrentFolder(const std::string &fullpath)
Definition: DQMStore.cc:274
void bookHistograms(DQMStore::IBooker &, edm::Run const &, edm::EventSetup const &) override
BookHistograms.
const T & get() const
Definition: EventSetup.h:55
LuminosityBlockNumber_t luminosityBlock() const
DTLayerId layerId() const
Return the corresponding LayerId.
Definition: DTWireId.h:62
void bookHistos(DQMStore::IBooker &ibooker, DTSuperLayerId slId)
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 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