CMS 3D CMS Logo

DTCalibValidationFromMuons.cc
Go to the documentation of this file.
1 
2 /*
3  * See header file for a description of this class.
4  *
5  * \author G. Mila - INFN Torino
6  */
7 
9 
10 // Framework
17 
18 // Geometry
21 
22 // RecHit
26 
27 #include <iterator>
28 
29 using namespace edm;
30 using namespace std;
31 
33  parameters = pset;
34 
35  // the name of the 4D segments
36  segment4DToken_ =
37  consumes<DTRecSegment4DCollection>(edm::InputTag(parameters.getUntrackedParameter<string>("segment4DLabel")));
38  // muon collection for matching 4D segments to muons
39  muonToken_ = consumes<reco::MuonCollection>(edm::InputTag(parameters.getUntrackedParameter<string>("muonLabel")));
40  // the counter of segments not used to compute residuals
41  wrongSegment = 0;
42  // the counter of segments used to compute residuals
43  rightSegment = 0;
44 
45  nevent = 0;
46 }
47 
49  // FR the following was previously in the endJob
50 
51  LogVerbatim("DTCalibValidationFromMuons") << "Segments used to compute residuals: " << rightSegment;
52  LogVerbatim("DTCalibValidationFromMuons") << "Segments not used to compute residuals: " << wrongSegment;
53 }
54 
56  // get the geometry
57  setup.get<MuonGeometryRecord>().get(dtGeom);
58 }
59 
61  ++nevent;
62  LogTrace("DTCalibValidationFromMuons") << "[DTCalibValidationFromMuons] Analyze #Run: " << event.id().run()
63  << " #Event: " << nevent;
64 
65  // RecHit mapping at Step 3 ---------------------------------
66  LogTrace("DTCalibValidationFromMuons") << " -- DTRecHit S3: begin analysis:";
67  // Get the 4D rechits from the event
69  event.getByToken(muonToken_, muonH);
70  const vector<reco::Muon> *muons = muonH.product();
71 
72  // Get the 4D rechits from the event
74  event.getByToken(segment4DToken_, segment4Ds);
75 
76  vector<const DTRecSegment4D *> selectedSegment4Ds;
77 
78  for (auto &imuon : *muons) {
79  for (const auto &ch : imuon.matches()) {
80  DetId chId(ch.id.rawId());
81  if (chId.det() != DetId::Muon)
82  continue;
83  if (chId.subdetId() != MuonSubdetId::DT)
84  continue;
85  if (imuon.pt() < 15)
86  continue;
87  if (!imuon.isGlobalMuon())
88  continue;
89 
90  int nsegs = ch.segmentMatches.size();
91  if (!nsegs)
92  continue;
93 
94  // get the DT segments that were used to construct the muon
95  DTChamberId matchId = ch.id();
96  DTRecSegment4DCollection::range segs = segment4Ds->get(matchId);
97  for (DTRecSegment4DCollection::const_iterator segment = segs.first; segment != segs.second; ++segment) {
98  LocalPoint posHit = segment->localPosition();
99  float dx = (posHit.x() ? posHit.x() - ch.x : 0);
100  float dy = (posHit.y() ? posHit.y() - ch.y : 0);
101  float dr = sqrt(dx * dx + dy * dy);
102  if (dr < 5)
103  selectedSegment4Ds.push_back(&(*segment));
104  }
105  }
106  }
107 
108  // Loop over all 4D segments
109  for (auto segment : selectedSegment4Ds) {
110  LogTrace("DTCalibValidationFromMuons") << "Anlysis on recHit at step 3";
111  compute(dtGeom.product(), *segment);
112  }
113 }
114 
115 // Compute the distance from wire (cm) of a hits in a DTRecHit1DPair
117  return fabs(hitPair.localPosition(DTEnums::Left).x() - hitPair.localPosition(DTEnums::Right).x()) / 2.;
118 }
119 
120 // Compute the distance from wire (cm) of a hits in a DTRecHit1D
122  return fabs(recHit.localPosition().x() - layer->specificTopology().wirePosition(recHit.wireId().wire()));
123 }
124 
125 // Compute the position (cm) of a hits in a DTRecHit1DPair
127  const DTRecHit1DPair &hitPair, const DTLayer *layer, const DTChamber *chamber, float segmentPos, int sl) {
128  // Get the layer and the wire position
129  GlobalPoint hitPosGlob_right = layer->toGlobal(hitPair.localPosition(DTEnums::Right));
130  LocalPoint hitPosInChamber_right = chamber->toLocal(hitPosGlob_right);
131  GlobalPoint hitPosGlob_left = layer->toGlobal(hitPair.localPosition(DTEnums::Left));
132  LocalPoint hitPosInChamber_left = chamber->toLocal(hitPosGlob_left);
133 
134  float recHitPos = -1;
135  if (sl != 2) {
136  if (fabs(hitPosInChamber_left.x() - segmentPos) < fabs(hitPosInChamber_right.x() - segmentPos))
137  recHitPos = hitPosInChamber_left.x();
138  else
139  recHitPos = hitPosInChamber_right.x();
140  } else {
141  if (fabs(hitPosInChamber_left.y() - segmentPos) < fabs(hitPosInChamber_right.y() - segmentPos))
142  recHitPos = hitPosInChamber_left.y();
143  else
144  recHitPos = hitPosInChamber_right.y();
145  }
146 
147  return recHitPos;
148 }
149 
150 // Compute the position (cm) of a hits in a DTRecHit1D
152  const DTRecHit1D &recHit, const DTLayer *layer, const DTChamber *chamber, float segmentPos, int sl) {
153  // Get the layer and the wire position
154  GlobalPoint recHitPosGlob = layer->toGlobal(recHit.localPosition());
155  LocalPoint recHitPosInChamber = chamber->toLocal(recHitPosGlob);
156 
157  float recHitPos = -1;
158  if (sl != 2)
159  recHitPos = recHitPosInChamber.x();
160  else
161  recHitPos = recHitPosInChamber.y();
162 
163  return recHitPos;
164 }
165 
166 // Compute the residuals
167 void DTCalibValidationFromMuons::compute(const DTGeometry *dtGeom, const DTRecSegment4D &segment) {
168  bool computeResidual = true;
169 
170  // Get all 1D RecHits at step 3 within the 4D segment
171  vector<DTRecHit1D> recHits1D_S3;
172 
173  // Get 1D RecHits at Step 3 and select only events with
174  // >=7 hits in phi and 4 hits in theta (if any)
175  const DTChamberRecSegment2D *phiSeg = segment.phiSegment();
176  if (phiSeg) {
177  vector<DTRecHit1D> phiRecHits = phiSeg->specificRecHits();
178  if (phiRecHits.size() < 7) {
179  LogTrace("DTCalibValidationFromMuons") << "[DTCalibValidationFromMuons] Phi segments has: " << phiRecHits.size()
180  << " hits, skipping"; // FIXME: info output
181  computeResidual = false;
182  }
183  copy(phiRecHits.begin(), phiRecHits.end(), back_inserter(recHits1D_S3));
184  }
185  if (!phiSeg) {
186  LogTrace("DTCalibValidationFromMuons") << " [DTCalibValidationFromMuons] 4D segment has no phi segment! ";
187  computeResidual = false;
188  }
189 
190  if (segment.dimension() == 4) {
191  const DTSLRecSegment2D *zSeg = segment.zSegment();
192  if (zSeg) {
193  vector<DTRecHit1D> zRecHits = zSeg->specificRecHits();
194  if (zRecHits.size() != 4) {
195  LogTrace("DTCalibValidationFromMuons") << "[DTCalibValidationFromMuons] Theta segments has: " << zRecHits.size()
196  << " hits, skipping"; // FIXME: info output
197  computeResidual = false;
198  }
199  copy(zRecHits.begin(), zRecHits.end(), back_inserter(recHits1D_S3));
200  }
201  if (!zSeg) {
202  LogTrace("DTCalibValidationFromMuons") << " [DTCalibValidationFromMuons] 4D segment has not the z segment! ";
203  computeResidual = false;
204  }
205  }
206 
207  if (!computeResidual)
208  ++wrongSegment;
209 
210  if (computeResidual) {
211  ++rightSegment;
212 
213  // Loop over 1D RecHit inside 4D segment
214  for (vector<DTRecHit1D>::const_iterator recHit1D = recHits1D_S3.begin(); recHit1D != recHits1D_S3.end();
215  ++recHit1D) {
216  const DTWireId wireId = (*recHit1D).wireId();
217 
218  // Get the layer and the wire position
219  const DTLayer *layer = dtGeom->layer(wireId);
220  float wireX = layer->specificTopology().wirePosition(wireId.wire());
221 
222  // Extrapolate the segment to the z of the wire
223  // Get wire position in chamber RF
224  // (y and z must be those of the hit to be coherent in the transf. of RF
225  // in case of rotations of the layer alignment)
226  LocalPoint wirePosInLay(wireX, (*recHit1D).localPosition().y(), (*recHit1D).localPosition().z());
227  GlobalPoint wirePosGlob = layer->toGlobal(wirePosInLay);
228  const DTChamber *chamber = dtGeom->chamber((*recHit1D).wireId().layerId().chamberId());
229  LocalPoint wirePosInChamber = chamber->toLocal(wirePosGlob);
230 
231  // Segment position at Wire z in chamber local frame
232  LocalPoint segPosAtZWire = segment.localPosition() + segment.localDirection() * wirePosInChamber.z() /
233  cos(segment.localDirection().theta());
234 
235  // Compute the distance of the segment from the wire
236  int sl = wireId.superlayer();
237  float SegmDistance = -1;
238  if (sl == 1 || sl == 3) {
239  // RPhi SL
240  SegmDistance = fabs(wirePosInChamber.x() - segPosAtZWire.x());
241  LogTrace("DTCalibValidationFromMuons") << "SegmDistance: " << SegmDistance;
242  } else if (sl == 2) {
243  // RZ SL
244  SegmDistance = fabs(segPosAtZWire.y() - wirePosInChamber.y());
245  LogTrace("DTCalibValidationFromMuons") << "SegmDistance: " << SegmDistance;
246  }
247 
248  if (SegmDistance > 2.1)
249  LogTrace("DTCalibValidationFromMuons") << " Warning: dist segment-wire: " << SegmDistance;
250 
251  // Compute the distance of the recHit from the wire
252  float recHitWireDist = recHitDistFromWire(*recHit1D, layer);
253  LogTrace("DTCalibValidationFromMuons") << "recHitWireDist: " << recHitWireDist;
254 
255  // Compute the residuals
256  float residualOnDistance = recHitWireDist - SegmDistance;
257  LogTrace("DTCalibValidationFromMuons") << "WireId: " << wireId << " ResidualOnDistance: " << residualOnDistance;
258  float residualOnPosition = -1;
259  float recHitPos = -1;
260  if (sl == 1 || sl == 3) {
261  recHitPos = recHitPosition(*recHit1D, layer, chamber, segPosAtZWire.x(), sl);
262  residualOnPosition = recHitPos - segPosAtZWire.x();
263  } else {
264  recHitPos = recHitPosition(*recHit1D, layer, chamber, segPosAtZWire.y(), sl);
265  residualOnPosition = recHitPos - segPosAtZWire.y();
266  }
267  LogTrace("DTCalibValidationFromMuons") << "WireId: " << wireId << " ResidualOnPosition: " << residualOnPosition;
268 
269  // Fill the histos
270  if (sl == 1 || sl == 3)
271  fillHistos(wireId.superlayerId(),
272  SegmDistance,
273  residualOnDistance,
274  (wirePosInChamber.x() - segPosAtZWire.x()),
275  residualOnPosition,
276  3);
277  else
278  fillHistos(wireId.superlayerId(),
279  SegmDistance,
280  residualOnDistance,
281  (wirePosInChamber.y() - segPosAtZWire.y()),
282  residualOnPosition,
283  3);
284  }
285  }
286 }
287 
289  edm::Run const &iRun,
290  edm::EventSetup const &iSetup) {
291  // FR substitute the DQMStore instance by ibooker
292  ibooker.setCurrentFolder("DT/DTCalibValidationFromMuons");
293 
294  DTSuperLayerId slId;
295 
296  // Loop over all the chambers
297  vector<const DTChamber *>::const_iterator ch_it = dtGeom->chambers().begin();
298  vector<const DTChamber *>::const_iterator ch_end = dtGeom->chambers().end();
299  for (; ch_it != ch_end; ++ch_it) {
300  vector<const DTSuperLayer *>::const_iterator sl_it = (*ch_it)->superLayers().begin();
301  vector<const DTSuperLayer *>::const_iterator sl_end = (*ch_it)->superLayers().end();
302  // Loop over the SLs
303  for (; sl_it != sl_end; ++sl_it) {
304  slId = (*sl_it)->id();
305 
306  // TODO! fix this is a leftover
307  int firstStep = 3;
308  // Loop over the 3 steps
309  for (int step = firstStep; step <= 3; ++step) {
310  LogTrace("DTCalibValidationFromMuons") << " Booking histos for SL: " << slId;
311 
312  // Compose the chamber name
313  stringstream wheel;
314  wheel << slId.wheel();
315  stringstream station;
316  station << slId.station();
317  stringstream sector;
318  sector << slId.sector();
319  stringstream superLayer;
320  superLayer << slId.superlayer();
321  // Define the step
322  stringstream Step;
323  Step << step;
324 
325  string slHistoName = "_STEP" + Step.str() + "_W" + wheel.str() + "_St" + station.str() + "_Sec" + sector.str() +
326  "_SL" + superLayer.str();
327 
328  ibooker.setCurrentFolder("DT/DTCalibValidationFromMuons/Wheel" + wheel.str() + "/Station" + station.str() +
329  "/Sector" + sector.str());
330  // Create the monitor elements
331  vector<MonitorElement *> histos;
332  // Note the order matters
333  histos.push_back(ibooker.book1D(
334  "hResDist" + slHistoName, "Residuals on the distance from wire (rec_hit - segm_extr) (cm)", 200, -0.4, 0.4));
335  histos.push_back(ibooker.book2D("hResDistVsDist" + slHistoName,
336  "Residuals on the distance (cm) from wire (rec_hit "
337  "- segm_extr) vs distance (cm)",
338  100,
339  0,
340  2.5,
341  200,
342  -0.4,
343  0.4));
344 
345  histosPerSL[make_pair(slId, step)] = histos;
346  }
347  }
348  }
349 }
350 
351 // Fill a set of histograms for a given SL
353  DTSuperLayerId slId, float distance, float residualOnDistance, float position, float residualOnPosition, int step) {
354  // FIXME: optimization of the number of searches
355  vector<MonitorElement *> histos = histosPerSL[make_pair(slId, step)];
356  histos[0]->Fill(residualOnDistance);
357  histos[1]->Fill(distance, residualOnDistance);
358 }
359 
360 // Local Variables:
361 // show-trailing-whitespace: t
362 // truncate-lines: t
363 // End:
nevent
int nevent
Definition: AMPTWrapper.h:84
DTGeometry
Definition: DTGeometry.h:28
PDWG_BPHSkim_cff.muons
muons
Definition: PDWG_BPHSkim_cff.py:47
DTSLRecSegment2D
Definition: DTSLRecSegment2D.h:15
DTSuperLayerId
Definition: DTSuperLayerId.h:12
BeamSpotPI::parameters
parameters
Definition: BeamSpotPayloadInspectorHelper.h:30
DTRecSegment4D
Definition: DTRecSegment4D.h:23
DTWireId::wire
int wire() const
Return the wire number.
Definition: DTWireId.h:42
DTRecSegment4D::dimension
int dimension() const override
Dimension (in parameter space)
Definition: DTRecSegment4D.h:79
DTRecSegment4D::localDirection
LocalVector localDirection() const override
Local direction in Chamber frame.
Definition: DTRecSegment4D.h:67
MessageLogger.h
edm::Handle::product
T const * product() const
Definition: Handle.h:70
DTCalibValidationFromMuons::DTCalibValidationFromMuons
DTCalibValidationFromMuons(const edm::ParameterSet &pset)
Constructor.
Definition: DTCalibValidationFromMuons.cc:32
filterCSVwithJSON.copy
copy
Definition: filterCSVwithJSON.py:36
ESHandle.h
DTRecHitCollection.h
step
step
Definition: StallMonitor.cc:94
PV3DBase::x
T x() const
Definition: PV3DBase.h:59
edm::Run
Definition: Run.h:45
relativeConstraints.station
station
Definition: relativeConstraints.py:67
edm
HLT enums.
Definition: AlignableModifier.h:19
PV3DBase::theta
Geom::Theta< T > theta() const
Definition: PV3DBase.h:72
DTChamber
Definition: DTChamber.h:24
DTRecHit1D
Definition: DTRecHit1D.h:25
dqm::implementation::NavigatorBase::setCurrentFolder
virtual void setCurrentFolder(std::string const &fullpath)
Definition: DQMStore.cc:32
DTCalibValidationFromMuons::compute
void compute(const DTGeometry *dtGeom, const DTRecSegment4D &segment)
Definition: DTCalibValidationFromMuons.cc:167
DQMStore.h
bookConverter.compute
def compute(min, max)
Definition: bookConverter.py:106
DTSuperLayerId::superlayer
int superlayer() const
Return the superlayer number (deprecated method name)
Definition: DTSuperLayerId.h:42
edm::Handle< reco::MuonCollection >
DTRecSegment4D::localPosition
LocalPoint localPosition() const override
Local position in Chamber frame.
Definition: DTRecSegment4D.h:61
DTRecSegment4D::zSegment
const DTSLRecSegment2D * zSegment() const
The Z segment: 0 if not zed projection available.
Definition: DTRecSegment4D.h:99
DTCalibValidationFromMuons::dqmBeginRun
void dqmBeginRun(const edm::Run &r, const edm::EventSetup &c) override
BeginRun.
Definition: DTCalibValidationFromMuons.cc:55
rpcPointValidation_cfi.recHit
recHit
Definition: rpcPointValidation_cfi.py:7
singleTopDQM_cfi.setup
setup
Definition: singleTopDQM_cfi.py:37
DTCalibValidationFromMuons.h
DTGeometry::chamber
const DTChamber * chamber(const DTChamberId &id) const
Return a DTChamber given its id.
Definition: DTGeometry.cc:90
PV3DBase::z
T z() const
Definition: PV3DBase.h:61
DetId
Definition: DetId.h:17
DTEnums::Left
Definition: DTEnums.h:15
funct::cos
Cos< T >::type cos(const T &t)
Definition: Cos.h:22
DTCalibValidationFromMuons::fillHistos
void fillHistos(DTSuperLayerId slId, float distance, float residualOnDistance, float position, float residualOnPosition, int step)
Definition: DTCalibValidationFromMuons.cc:352
DTCalibValidationFromMuons::recHitPosition
float recHitPosition(const DTRecHit1DPair &hitPair, const DTLayer *layer, const DTChamber *chamber, float segmPos, int sl)
Definition: DTCalibValidationFromMuons.cc:126
DTWireId
Definition: DTWireId.h:12
MuonSelectors.h
Service.h
mathSSE::sqrt
T sqrt(T t)
Definition: SSEVec.h:19
DTCalibValidationFromMuons::recHitDistFromWire
float recHitDistFromWire(const DTRecHit1DPair &hitPair, const DTLayer *layer)
Definition: DTCalibValidationFromMuons.cc:116
DTRecHit1DPair
Definition: DTRecHit1DPair.h:26
MuonSubdetId::DT
static constexpr int DT
Definition: MuonSubdetId.h:11
Point3DBase< float, LocalTag >
phase1PixelTopology::layer
constexpr std::array< uint8_t, layerIndexSize > layer
Definition: phase1PixelTopology.h:99
DTGeometry.h
edm::ParameterSet
Definition: ParameterSet.h:47
DTGeometry::layer
const DTLayer * layer(const DTLayerId &id) const
Return a layer given its id.
Definition: DTGeometry.cc:96
Event.h
edm::RangeMap::const_iterator
C::const_iterator const_iterator
constant access iterator type
Definition: RangeMap.h:43
edm::get
T const & get(Event const &event, InputTag const &tag) noexcept(false)
Definition: Event.h:675
position
static int position[264][3]
Definition: ReadPGInfo.cc:289
PV3DBase::y
T y() const
Definition: PV3DBase.h:60
makeMuonMisalignmentScenario.wheel
wheel
Definition: makeMuonMisalignmentScenario.py:319
DTChamberRecSegment2D
Definition: DTChamberRecSegment2D.h:31
PVValHelper::dy
Definition: PVValidationHelpers.h:50
edm::EventSetup
Definition: EventSetup.h:58
DTLayer
Definition: DTLayer.h:25
combine.histos
histos
Definition: combine.py:4
DTCalibValidationFromMuons::bookHistograms
void bookHistograms(DQMStore::IBooker &, edm::Run const &, edm::EventSetup const &) override
Definition: DTCalibValidationFromMuons.cc:288
DTCalibValidationFromMuons::~DTCalibValidationFromMuons
~DTCalibValidationFromMuons() override
Destructor.
Definition: DTCalibValidationFromMuons.cc:48
DTEnums::Right
Definition: DTEnums.h:15
DTChamberId::sector
int sector() const
Definition: DTChamberId.h:49
edm::RangeMap::range
std::pair< const_iterator, const_iterator > range
iterator range
Definition: RangeMap.h:50
std
Definition: JetResolutionObject.h:76
writedatasetfile.run
run
Definition: writedatasetfile.py:27
DTRecHit1DPair::localPosition
LocalPoint localPosition() const override
Definition: DTRecHit1DPair.cc:29
edm::LogVerbatim
Log< level::Info, true > LogVerbatim
Definition: MessageLogger.h:128
dqm::implementation::IBooker::book2D
MonitorElement * book2D(TString const &name, TString const &title, int nchX, double lowX, double highX, int nchY, double lowY, double highY, FUNC onbooking=NOOP())
Definition: DQMStore.h:177
flavorHistoryFilter_cfi.dr
dr
Definition: flavorHistoryFilter_cfi.py:37
DTLayerId::superlayerId
DTSuperLayerId superlayerId() const
Return the corresponding SuperLayerId.
Definition: DTLayerId.h:45
DTRecSegment2D::specificRecHits
std::vector< DTRecHit1D > specificRecHits() const
Access to specific components.
Definition: DTRecSegment2D.cc:104
relativeConstraints.chamber
chamber
Definition: relativeConstraints.py:53
EventSetup.h
dqm::implementation::IBooker
Definition: DQMStore.h:43
DetId::Muon
Definition: DetId.h:26
DTChamberId
Definition: DTChamberId.h:14
LogTrace
#define LogTrace(id)
Definition: MessageLogger.h:234
MuonGeometryRecord.h
event
Definition: event.py:1
edm::Event
Definition: Event.h:73
DTCalibValidationFromMuons::analyze
void analyze(const edm::Event &event, const edm::EventSetup &setup) override
Definition: DTCalibValidationFromMuons.cc:60
HLT_FULL_cff.distance
distance
Definition: HLT_FULL_cff.py:7733
DTRecSegment4D::phiSegment
const DTChamberRecSegment2D * phiSegment() const
The superPhi segment: 0 if no phi projection available.
Definition: DTRecSegment4D.h:96
MuonGeometryRecord
Definition: MuonGeometryRecord.h:34
DTChamberId::wheel
int wheel() const
Return the wheel number.
Definition: DTChamberId.h:39
edm::InputTag
Definition: InputTag.h:15
PVValHelper::dx
Definition: PVValidationHelpers.h:49
DTChamberId::station
int station() const
Return the station number.
Definition: DTChamberId.h:42
muonDTDigis_cfi.pset
pset
Definition: muonDTDigis_cfi.py:27
dqm::implementation::IBooker::book1D
MonitorElement * book1D(TString const &name, TString const &title, int const nchX, double const lowX, double const highX, FUNC onbooking=NOOP())
Definition: DQMStore.h:98
DTRecSegment4DCollection.h