CMS 3D CMS Logo

CSCTimingExtractor.cc
Go to the documentation of this file.
1 // -*- C++ -*-
2 //
3 // Package: MuonIdentification
4 // Class: CSCTimingExtractor
5 //
11 //
12 // Original Author: Traczyk Piotr
13 // Created: Thu Oct 11 15:01:28 CEST 2007
14 //
15 //
16 
18 
19 // user include files
23 
26 
28 
30 
33 
37 
45 
50 
51 // system include files
52 #include <memory>
53 #include <vector>
54 #include <string>
55 #include <iostream>
56 
57 namespace edm {
58  class ParameterSet;
59  class EventSetup;
60  class InputTag;
61 } // namespace edm
62 
63 class MuonServiceProxy;
64 
65 //
66 // constructors and destructor
67 //
69  MuonSegmentMatcher* segMatcher,
71  : thePruneCut_(iConfig.getParameter<double>("PruneCut")),
72  theStripTimeOffset_(iConfig.getParameter<double>("CSCStripTimeOffset")),
73  theWireTimeOffset_(iConfig.getParameter<double>("CSCWireTimeOffset")),
74  theStripError_(iConfig.getParameter<double>("CSCStripError")),
75  theWireError_(iConfig.getParameter<double>("CSCWireError")),
76  UseWireTime(iConfig.getParameter<bool>("UseWireTime")),
77  UseStripTime(iConfig.getParameter<bool>("UseStripTime")),
78  debug(iConfig.getParameter<bool>("debug")) {
79  edm::ParameterSet serviceParameters = iConfig.getParameter<edm::ParameterSet>("ServiceParameters");
80  theService = std::make_unique<MuonServiceProxy>(serviceParameters, edm::ConsumesCollector(iC));
81  theMatcher = segMatcher;
82 }
83 
85 
86 //
87 // member functions
88 //
89 
91  const std::vector<const CSCSegment*>& segments,
92  reco::TrackRef muonTrack,
93  const edm::Event& iEvent,
94  const edm::EventSetup& iSetup) {
95  theService->update(iSetup);
96 
97  const GlobalTrackingGeometry* theTrackingGeometry = &*theService->trackingGeometry();
98 
99  // get the propagator
101  iSetup.get<TrackingComponentsRecord>().get("SteppingHelixPropagatorAny", propagator);
102  const Propagator* propag = propagator.product();
103 
104  math::XYZPoint pos = muonTrack->innerPosition();
105  math::XYZVector mom = muonTrack->innerMomentum();
106  if (sqrt(muonTrack->innerPosition().mag2()) > sqrt(muonTrack->outerPosition().mag2())) {
107  pos = muonTrack->outerPosition();
108  mom = -1 * muonTrack->outerMomentum();
109  }
110  GlobalPoint posp(pos.x(), pos.y(), pos.z());
111  GlobalVector momv(mom.x(), mom.y(), mom.z());
112  FreeTrajectoryState muonFTS(posp, momv, (TrackCharge)muonTrack->charge(), theService->magneticField().product());
113 
114  // create a collection on TimeMeasurements for the track
115  std::vector<TimeMeasurement> tms;
116  for (const auto& rechit : segments) {
117  // Create the ChamberId
118  DetId id = rechit->geographicalId();
119  CSCDetId chamberId(id.rawId());
120  // int station = chamberId.station();
121 
122  if (rechit->specificRecHits().empty())
123  continue;
124 
125  const std::vector<CSCRecHit2D>& hits2d(rechit->specificRecHits());
126 
127  // store all the hits from the segment
128  for (const auto& hiti : hits2d) {
129  const GeomDet* cscDet = theTrackingGeometry->idToDet(hiti.geographicalId());
130  TimeMeasurement thisHit;
131 
132  std::pair<TrajectoryStateOnSurface, double> tsos;
133  tsos = propag->propagateWithPath(muonFTS, cscDet->surface());
134 
135  double dist;
136  if (tsos.first.isValid())
137  dist = tsos.second + posp.mag();
138  else
139  dist = cscDet->toGlobal(hiti.localPosition()).mag();
140 
141  thisHit.distIP = dist;
142  if (UseStripTime) {
143  thisHit.weightInvbeta = dist * dist / (theStripError_ * theStripError_ * 30. * 30.);
144  thisHit.weightTimeVtx = 1. / (theStripError_ * theStripError_);
145  thisHit.timeCorr = hiti.tpeak() - theStripTimeOffset_;
146  tms.push_back(thisHit);
147  }
148 
149  if (UseWireTime) {
150  thisHit.weightInvbeta = dist * dist / (theWireError_ * theWireError_ * 30. * 30.);
151  thisHit.weightTimeVtx = 1. / (theWireError_ * theWireError_);
152  thisHit.timeCorr = hiti.wireTime() - theWireTimeOffset_;
153  tms.push_back(thisHit);
154  }
155 
156  // std::cout << " CSC Hit. Dist= " << dist << " Time= " << thisHit.timeCorr
157  // << " invBeta= " << (1.+thisHit.timeCorr/dist*30.) << std::endl;
158  }
159 
160  } // rechit
161 
162  bool modified = false;
163  std::vector<double> dstnc, local_t0, hitWeightInvbeta, hitWeightTimeVtx;
164  double totalWeightInvbeta = 0;
165  double totalWeightTimeVtx = 0;
166 
167  // Now loop over the measurements, calculate 1/beta and cut away outliers
168  do {
169  modified = false;
170  dstnc.clear();
171  local_t0.clear();
172  hitWeightInvbeta.clear();
173  hitWeightTimeVtx.clear();
174 
175  totalWeightInvbeta = 0;
176  totalWeightTimeVtx = 0;
177 
178  for (auto& tm : tms) {
179  dstnc.push_back(tm.distIP);
180  local_t0.push_back(tm.timeCorr);
181  hitWeightInvbeta.push_back(tm.weightInvbeta);
182  hitWeightTimeVtx.push_back(tm.weightTimeVtx);
183  totalWeightInvbeta += tm.weightInvbeta;
184  totalWeightTimeVtx += tm.weightTimeVtx;
185  }
186 
187  if (totalWeightInvbeta == 0)
188  break;
189 
190  // calculate the value and error of 1/beta and timeVtx from the complete set of 1D hits
191  if (debug)
192  std::cout << " Points for global fit: " << dstnc.size() << std::endl;
193 
194  double invbeta = 0, invbetaErr = 0;
195  double timeVtx = 0, timeVtxErr = 0;
196 
197  for (unsigned int i = 0; i < dstnc.size(); i++) {
198  invbeta += (1. + local_t0.at(i) / dstnc.at(i) * 30.) * hitWeightInvbeta.at(i) / totalWeightInvbeta;
199  timeVtx += local_t0.at(i) * hitWeightTimeVtx.at(i) / totalWeightTimeVtx;
200  }
201 
202  double chimax = 0.;
203  std::vector<TimeMeasurement>::iterator tmmax;
204 
205  // Calculate the inv beta and time at vertex dispersion
206  double diff_ibeta, diff_tvtx;
207  for (unsigned int i = 0; i < dstnc.size(); i++) {
208  diff_ibeta = (1. + local_t0.at(i) / dstnc.at(i) * 30.) - invbeta;
209  diff_ibeta = diff_ibeta * diff_ibeta * hitWeightInvbeta.at(i);
210  diff_tvtx = local_t0.at(i) - timeVtx;
211  diff_tvtx = diff_tvtx * diff_tvtx * hitWeightTimeVtx.at(i);
212  invbetaErr += diff_ibeta;
213  timeVtxErr += diff_tvtx;
214 
215  // decide if we cut away time at vertex outliers or inverse beta outliers
216  // currently not configurable.
217  if (diff_tvtx > chimax) {
218  tmmax = tms.begin() + i;
219  chimax = diff_tvtx;
220  }
221  }
222 
223  // cut away the outliers
224  if (chimax > thePruneCut_) {
225  tms.erase(tmmax);
226  modified = true;
227  }
228 
229  if (debug) {
230  double cf = 1. / (dstnc.size() - 1);
231  invbetaErr = sqrt(invbetaErr / totalWeightInvbeta * cf);
232  timeVtxErr = sqrt(timeVtxErr / totalWeightTimeVtx * cf);
233  std::cout << " Measured 1/beta: " << invbeta << " +/- " << invbetaErr << std::endl;
234  std::cout << " Measured time: " << timeVtx << " +/- " << timeVtxErr << std::endl;
235  }
236 
237  } while (modified);
238 
239  for (unsigned int i = 0; i < dstnc.size(); i++) {
240  tmSequence.dstnc.push_back(dstnc.at(i));
241  tmSequence.local_t0.push_back(local_t0.at(i));
242  tmSequence.weightInvbeta.push_back(hitWeightInvbeta.at(i));
243  tmSequence.weightTimeVtx.push_back(hitWeightTimeVtx.at(i));
244  }
245 
246  tmSequence.totalWeightInvbeta = totalWeightInvbeta;
247  tmSequence.totalWeightTimeVtx = totalWeightTimeVtx;
248 }
249 
250 // ------------ method called to produce the data ------------
252  reco::TrackRef muonTrack,
253  const edm::Event& iEvent,
254  const edm::EventSetup& iSetup) {
255  if (debug)
256  std::cout << " *** CSC Timimng Extractor ***" << std::endl;
257 
258  // get the CSC segments that were used to construct the muon
259  std::vector<const CSCSegment*> range = theMatcher->matchCSC(*muonTrack, iEvent);
260 
261  fillTiming(tmSequence, range, muonTrack, iEvent, iSetup);
262 }
263 
264 //define this as a plug-in
265 //DEFINE_FWK_MODULE(CSCTimingExtractor);
Vector3DBase
Definition: Vector3DBase.h:8
TrackExtra.h
FastTimerService_cff.range
range
Definition: FastTimerService_cff.py:34
electrons_cff.bool
bool
Definition: electrons_cff.py:366
mps_fire.i
i
Definition: mps_fire.py:428
Muon.h
TrackExtraFwd.h
TrackCharge
int TrackCharge
Definition: TrackCharge.h:4
GeomDet
Definition: GeomDet.h:27
EDProducer.h
edm
HLT enums.
Definition: AlignableModifier.h:19
HLT_FULL_cff.UseStripTime
UseStripTime
Definition: HLT_FULL_cff.py:11559
CSCTimingExtractor::TimeMeasurement::weightInvbeta
float weightInvbeta
Definition: CSCTimingExtractor.h:68
gather_cfg.cout
cout
Definition: gather_cfg.py:144
pos
Definition: PixelAliasList.h:18
HLT_FULL_cff.InputTag
InputTag
Definition: HLT_FULL_cff.py:89285
TrackingRecHitFwd.h
CSCTimingExtractor::fillTiming
void fillTiming(TimeMeasurementSequence &tmSequence, const std::vector< const CSCSegment * > &segments, reco::TrackRef muonTrack, const edm::Event &iEvent, const edm::EventSetup &iSetup)
Definition: CSCTimingExtractor.cc:90
MuonTransientTrackingRecHit.h
CSCTimingExtractor::thePruneCut_
double thePruneCut_
Definition: CSCTimingExtractor.h:84
CSCDetId.h
edm::Ref< TrackCollection >
TimeMeasurementSequence::local_t0
std::vector< double > local_t0
Definition: TimeMeasurementSequence.h:18
MuonSegmentMatcher::matchCSC
std::vector< const CSCSegment * > matchCSC(const reco::Track &muon, const edm::Event &event)
Definition: MuonSegmentMatcher.cc:237
Propagator
Definition: Propagator.h:44
DetId
Definition: DetId.h:17
GeomDet::surface
const Plane & surface() const
The nominal surface of the GeomDet.
Definition: GeomDet.h:37
MakerMacros.h
CSCTimingExtractor::theStripTimeOffset_
double theStripTimeOffset_
Definition: CSCTimingExtractor.h:85
CSCTimingExtractor::CSCTimingExtractor
CSCTimingExtractor(const edm::ParameterSet &, MuonSegmentMatcher *segMatcher, edm::ConsumesCollector &)
Constructor.
Definition: CSCTimingExtractor.cc:68
debug
#define debug
Definition: HDRShower.cc:19
Track.h
TimeMeasurementSequence::totalWeightTimeVtx
double totalWeightTimeVtx
Definition: TimeMeasurementSequence.h:23
edm::EventSetup::get
T get() const
Definition: EventSetup.h:87
TrackFwd.h
TrackCandidateProducer_cfi.propagator
propagator
Definition: TrackCandidateProducer_cfi.py:17
GlobalTrackingGeometry
Definition: GlobalTrackingGeometry.h:20
CSCTimingExtractor::UseWireTime
bool UseWireTime
Definition: CSCTimingExtractor.h:89
CSCTimingExtractor::theWireError_
double theWireError_
Definition: CSCTimingExtractor.h:88
MuonFwd.h
HLT_FULL_cff.UseWireTime
UseWireTime
Definition: HLT_FULL_cff.py:11561
mathSSE::sqrt
T sqrt(T t)
Definition: SSEVec.h:19
edm::ESHandle< Propagator >
Point3DBase< float, GlobalTag >
CSCTimingExtractor::TimeMeasurement::distIP
float distIP
Definition: CSCTimingExtractor.h:64
GlobalTrackingGeometryRecord.h
CSCTimingExtractor::~CSCTimingExtractor
~CSCTimingExtractor()
Destructor.
Definition: CSCTimingExtractor.cc:84
GeomDet::toGlobal
GlobalPoint toGlobal(const Local2DPoint &lp) const
Conversion to the global R.F. from the R.F. of the GeomDet.
Definition: GeomDet.h:49
edm::ParameterSet
Definition: ParameterSet.h:47
math::XYZPoint
XYZPointD XYZPoint
point in space with cartesian internal representation
Definition: Point3D.h:12
Event.h
ParameterSet
Definition: Functions.h:16
TimeMeasurementSequence::totalWeightInvbeta
double totalWeightInvbeta
Definition: TimeMeasurementSequence.h:22
CSCTimingExtractor::theStripError_
double theStripError_
Definition: CSCTimingExtractor.h:87
CSCDetId
Definition: CSCDetId.h:26
math::XYZVector
XYZVectorD XYZVector
spatial vector with cartesian internal representation
Definition: Vector3D.h:31
iEvent
int iEvent
Definition: GenABIO.cc:224
CSCTimingExtractor::TimeMeasurement
Definition: CSCTimingExtractor.h:62
TimeMeasurementSequence::weightTimeVtx
std::vector< double > weightTimeVtx
Definition: TimeMeasurementSequence.h:19
edm::EventSetup
Definition: EventSetup.h:58
TimeMeasurementSequence::weightInvbeta
std::vector< double > weightInvbeta
Definition: TimeMeasurementSequence.h:20
get
#define get
MuonSubdetId.h
CSCTimingExtractor::UseStripTime
bool UseStripTime
Definition: CSCTimingExtractor.h:90
mag
T mag() const
The vector magnitude. Equivalent to sqrt(vec.mag2())
Definition: Basic3DVectorLD.h:127
CSCTimingExtractor.h
FreeTrajectoryState
Definition: FreeTrajectoryState.h:27
Frameworkfwd.h
TrackingComponentsRecord.h
GlobalTrackingGeometry::idToDet
const GeomDet * idToDet(DetId) const override
Definition: GlobalTrackingGeometry.cc:44
MuonServiceProxy.h
CSCTimingExtractor::TimeMeasurement::weightTimeVtx
float weightTimeVtx
Definition: CSCTimingExtractor.h:67
edm::ParameterSet::getParameter
T getParameter(std::string const &) const
Definition: ParameterSet.h:303
Propagator::propagateWithPath
virtual std::pair< TrajectoryStateOnSurface, double > propagateWithPath(const FreeTrajectoryState &, const Surface &) const final
Definition: Propagator.cc:10
CSCTimingExtractor::debug
bool debug
Definition: CSCTimingExtractor.h:91
CSCSegment.h
MuonServiceProxy::theTrackingGeometry
edm::ESHandle< GlobalTrackingGeometry > theTrackingGeometry
Definition: MuonServiceProxy.h:93
CSCRecHit2D.h
ConsumesCollector.h
EventSetup
ParameterSet.h
MuonServiceProxy
Definition: MuonServiceProxy.h:38
MuonGeometryRecord.h
GlobalTrackingGeometry.h
CSCTimingExtractor::TimeMeasurement::timeCorr
float timeCorr
Definition: CSCTimingExtractor.h:65
edm::Event
Definition: Event.h:73
MuonSegmentMatcher
Definition: MuonSegmentMatcher.h:29
TimeMeasurementSequence::dstnc
std::vector< double > dstnc
Definition: TimeMeasurementSequence.h:17
edm::ConsumesCollector
Definition: ConsumesCollector.h:45
CSCTimingExtractor::theService
std::unique_ptr< MuonServiceProxy > theService
Definition: CSCTimingExtractor.h:93
CSCTimingExtractor::theWireTimeOffset_
double theWireTimeOffset_
Definition: CSCTimingExtractor.h:86
CSCTimingExtractor::theMatcher
MuonSegmentMatcher * theMatcher
Definition: CSCTimingExtractor.h:94
TimeMeasurementSequence
Definition: TimeMeasurementSequence.h:15
TrackingComponentsRecord
Definition: TrackingComponentsRecord.h:12