CMS 3D CMS Logo

List of all members | Classes | Public Member Functions | Private Attributes
CSCTimingExtractor Class Reference

#include <RecoMuon/MuonIdentification/src/CSCTimingExtractor.cc>

Classes

class  TimeMeasurement
 

Public Member Functions

 CSCTimingExtractor (const edm::ParameterSet &, MuonSegmentMatcher *segMatcher)
 Constructor. More...
 
void fillTiming (TimeMeasurementSequence &tmSequence, const std::vector< const CSCSegment * > &segments, reco::TrackRef muonTrack, const edm::Event &iEvent, const edm::EventSetup &iSetup)
 
void fillTiming (TimeMeasurementSequence &tmSequence, reco::TrackRef muonTrack, const edm::Event &iEvent, const edm::EventSetup &iSetup)
 
 ~CSCTimingExtractor ()
 Destructor. More...
 

Private Attributes

edm::InputTag CSCSegmentTags_
 
bool debug
 
unsigned int theHitsMin_
 
MuonSegmentMatchertheMatcher
 
double thePruneCut_
 
std::unique_ptr< MuonServiceProxytheService
 
double theStripError_
 
double theStripTimeOffset_
 
double theWireError_
 
double theWireTimeOffset_
 
bool UseStripTime
 
bool UseWireTime
 

Detailed Description

Extracts timing information associated to a muon track

Description: Produce timing information for a muon track using CSC hits from segments used to build the track

Definition at line 54 of file CSCTimingExtractor.h.

Constructor & Destructor Documentation

CSCTimingExtractor::CSCTimingExtractor ( const edm::ParameterSet iConfig,
MuonSegmentMatcher segMatcher 
)

Constructor.

Definition at line 69 of file CSCTimingExtractor.cc.

References edm::ParameterSet::getParameter(), theMatcher, and theService.

70  :
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 {
80  edm::ParameterSet serviceParameters = iConfig.getParameter<edm::ParameterSet>("ServiceParameters");
81  theService = std::make_unique<MuonServiceProxy>(serviceParameters);
82  theMatcher = segMatcher;
83 }
T getParameter(std::string const &) const
std::unique_ptr< MuonServiceProxy > theService
MuonSegmentMatcher * theMatcher
CSCTimingExtractor::~CSCTimingExtractor ( )

Destructor.

Definition at line 86 of file CSCTimingExtractor.cc.

87 {
88 }

Member Function Documentation

void CSCTimingExtractor::fillTiming ( TimeMeasurementSequence tmSequence,
const std::vector< const CSCSegment * > &  segments,
reco::TrackRef  muonTrack,
const edm::Event iEvent,
const edm::EventSetup iSetup 
)

Definition at line 95 of file CSCTimingExtractor.cc.

References gather_cfg::cout, debug, CSCTimingExtractor::TimeMeasurement::distIP, TimeMeasurementSequence::dstnc, edm::EventSetup::get(), mps_fire::i, GlobalTrackingGeometry::idToDet(), TimeMeasurementSequence::local_t0, mag(), edm::ESHandle< T >::product(), Propagator::propagateWithPath(), PhotonConversionTrajectorySeedProducerFromQuadruplets_cfi::propagator, mathSSE::sqrt(), GeomDet::surface(), thePruneCut_, theService, theStripError_, theStripTimeOffset_, MuonServiceProxy::theTrackingGeometry, theWireError_, theWireTimeOffset_, CSCTimingExtractor::TimeMeasurement::timeCorr, GeomDet::toGlobal(), TimeMeasurementSequence::totalWeightInvbeta, TimeMeasurementSequence::totalWeightTimeVtx, UseStripTime, UseWireTime, TimeMeasurementSequence::weightInvbeta, CSCTimingExtractor::TimeMeasurement::weightInvbeta, TimeMeasurementSequence::weightTimeVtx, and CSCTimingExtractor::TimeMeasurement::weightTimeVtx.

Referenced by fillTiming().

99 {
100  theService->update(iSetup);
101 
102  const GlobalTrackingGeometry *theTrackingGeometry = &*theService->trackingGeometry();
103 
104  // get the propagator
106  iSetup.get<TrackingComponentsRecord>().get("SteppingHelixPropagatorAny", propagator);
107  const Propagator *propag = propagator.product();
108 
109  math::XYZPoint pos=muonTrack->innerPosition();
110  math::XYZVector mom=muonTrack->innerMomentum();
111  if (sqrt(muonTrack->innerPosition().mag2()) > sqrt(muonTrack->outerPosition().mag2())){
112  pos=muonTrack->outerPosition();
113  mom=-1*muonTrack->outerMomentum();
114  }
115  GlobalPoint posp(pos.x(), pos.y(), pos.z());
116  GlobalVector momv(mom.x(), mom.y(), mom.z());
117  FreeTrajectoryState muonFTS(posp, momv, (TrackCharge)muonTrack->charge(), theService->magneticField().product());
118 
119  // create a collection on TimeMeasurements for the track
120  std::vector<TimeMeasurement> tms;
121  for (const auto& rechit : segments) {
122 
123  // Create the ChamberId
124  DetId id = rechit->geographicalId();
125  CSCDetId chamberId(id.rawId());
126  // int station = chamberId.station();
127 
128  if (rechit->specificRecHits().empty()) continue;
129 
130  const std::vector<CSCRecHit2D>& hits2d(rechit->specificRecHits());
131 
132  // store all the hits from the segment
133  for (const auto& hiti : hits2d) {
134 
135  const GeomDet* cscDet = theTrackingGeometry->idToDet(hiti.geographicalId());
136  TimeMeasurement thisHit;
137 
138  std::pair< TrajectoryStateOnSurface, double> tsos;
139  tsos=propag->propagateWithPath(muonFTS,cscDet->surface());
140 
141  double dist;
142  if (tsos.first.isValid()) dist = tsos.second+posp.mag();
143  else dist = cscDet->toGlobal(hiti.localPosition()).mag();
144 
145  thisHit.distIP = dist;
146  if (UseStripTime) {
147  thisHit.weightInvbeta = dist*dist/(theStripError_*theStripError_*30.*30.);
148  thisHit.weightTimeVtx = 1./(theStripError_*theStripError_);
149  thisHit.timeCorr = hiti.tpeak()-theStripTimeOffset_;
150  tms.push_back(thisHit);
151  }
152 
153  if (UseWireTime) {
154  thisHit.weightInvbeta = dist*dist/(theWireError_*theWireError_*30.*30.);
155  thisHit.weightTimeVtx = 1./(theWireError_*theWireError_);
156  thisHit.timeCorr = hiti.wireTime()-theWireTimeOffset_;
157  tms.push_back(thisHit);
158  }
159 
160 // std::cout << " CSC Hit. Dist= " << dist << " Time= " << thisHit.timeCorr
161 // << " invBeta= " << (1.+thisHit.timeCorr/dist*30.) << std::endl;
162  }
163 
164  } // rechit
165 
166  bool modified = false;
167  std::vector <double> dstnc, local_t0, hitWeightInvbeta, hitWeightTimeVtx;
168  double totalWeightInvbeta=0;
169  double totalWeightTimeVtx=0;
170 
171  // Now loop over the measurements, calculate 1/beta and cut away outliers
172  do {
173 
174  modified = false;
175  dstnc.clear();
176  local_t0.clear();
177  hitWeightInvbeta.clear();
178  hitWeightTimeVtx.clear();
179 
180  totalWeightInvbeta=0;
181  totalWeightTimeVtx=0;
182 
183  for (auto& tm : tms) {
184  dstnc.push_back(tm.distIP);
185  local_t0.push_back(tm.timeCorr);
186  hitWeightInvbeta.push_back(tm.weightInvbeta);
187  hitWeightTimeVtx.push_back(tm.weightTimeVtx);
188  totalWeightInvbeta+=tm.weightInvbeta;
189  totalWeightTimeVtx+=tm.weightTimeVtx;
190  }
191 
192  if (totalWeightInvbeta==0) break;
193 
194  // calculate the value and error of 1/beta and timeVtx from the complete set of 1D hits
195  if (debug)
196  std::cout << " Points for global fit: " << dstnc.size() << std::endl;
197 
198  double invbeta=0,invbetaErr=0;
199  double timeVtx=0,timeVtxErr=0;
200 
201  for (unsigned int i=0;i<dstnc.size();i++) {
202  invbeta+=(1.+local_t0.at(i)/dstnc.at(i)*30.)*hitWeightInvbeta.at(i)/totalWeightInvbeta;
203  timeVtx+=local_t0.at(i)*hitWeightTimeVtx.at(i)/totalWeightTimeVtx;
204  }
205 
206  double chimax=0.;
207  std::vector<TimeMeasurement>::iterator tmmax;
208 
209  // Calculate the inv beta and time at vertex dispersion
210  double diff_ibeta,diff_tvtx;
211  for (unsigned int i=0;i<dstnc.size();i++) {
212  diff_ibeta=(1.+local_t0.at(i)/dstnc.at(i)*30.)-invbeta;
213  diff_ibeta=diff_ibeta*diff_ibeta*hitWeightInvbeta.at(i);
214  diff_tvtx=local_t0.at(i)-timeVtx;
215  diff_tvtx=diff_tvtx*diff_tvtx*hitWeightTimeVtx.at(i);
216  invbetaErr+=diff_ibeta;
217  timeVtxErr+=diff_tvtx;
218 
219  // decide if we cut away time at vertex outliers or inverse beta outliers
220  // currently not configurable.
221  if (diff_tvtx>chimax) {
222  tmmax=tms.begin()+i;
223  chimax=diff_tvtx;
224  }
225  }
226 
227  // cut away the outliers
228  if (chimax>thePruneCut_) {
229  tms.erase(tmmax);
230  modified=true;
231  }
232 
233  if (debug) {
234  double cf = 1./(dstnc.size()-1);
235  invbetaErr=sqrt(invbetaErr/totalWeightInvbeta*cf);
236  timeVtxErr=sqrt(timeVtxErr/totalWeightTimeVtx*cf);
237  std::cout << " Measured 1/beta: " << invbeta << " +/- " << invbetaErr << std::endl;
238  std::cout << " Measured time: " << timeVtx << " +/- " << timeVtxErr << std::endl;
239  }
240 
241  } while (modified);
242 
243  for (unsigned int i=0;i<dstnc.size();i++) {
244  tmSequence.dstnc.push_back(dstnc.at(i));
245  tmSequence.local_t0.push_back(local_t0.at(i));
246  tmSequence.weightInvbeta.push_back(hitWeightInvbeta.at(i));
247  tmSequence.weightTimeVtx.push_back(hitWeightTimeVtx.at(i));
248  }
249 
250  tmSequence.totalWeightInvbeta=totalWeightInvbeta;
251  tmSequence.totalWeightTimeVtx=totalWeightTimeVtx;
252 }
std::vector< double > local_t0
T mag() const
The vector magnitude. Equivalent to sqrt(vec.mag2())
GlobalPoint toGlobal(const Local2DPoint &lp) const
Conversion to the global R.F. from the R.F. of the GeomDet.
Definition: GeomDet.h:54
const Plane & surface() const
The nominal surface of the GeomDet.
Definition: GeomDet.h:42
std::unique_ptr< MuonServiceProxy > theService
int TrackCharge
Definition: TrackCharge.h:4
T sqrt(T t)
Definition: SSEVec.h:18
virtual std::pair< TrajectoryStateOnSurface, double > propagateWithPath(const FreeTrajectoryState &, const Surface &) const final
Definition: Propagator.cc:15
std::vector< double > weightInvbeta
Definition: DetId.h:18
XYZVectorD XYZVector
spatial vector with cartesian internal representation
Definition: Vector3D.h:30
XYZPointD XYZPoint
point in space with cartesian internal representation
Definition: Point3D.h:12
std::vector< double > weightTimeVtx
T get() const
Definition: EventSetup.h:68
const GeomDet * idToDet(DetId) const override
std::vector< double > dstnc
T const * product() const
Definition: ESHandle.h:84
void CSCTimingExtractor::fillTiming ( TimeMeasurementSequence tmSequence,
reco::TrackRef  muonTrack,
const edm::Event iEvent,
const edm::EventSetup iSetup 
)

Definition at line 257 of file CSCTimingExtractor.cc.

References gather_cfg::cout, debug, fillTiming(), MuonSegmentMatcher::matchCSC(), and theMatcher.

259 {
260 
261  if (debug)
262  std::cout << " *** CSC Timimng Extractor ***" << std::endl;
263 
264  // get the CSC segments that were used to construct the muon
265  std::vector<const CSCSegment*> range = theMatcher->matchCSC(*muonTrack,iEvent);
266 
267  fillTiming(tmSequence, range, muonTrack, iEvent, iSetup);
268 }
std::vector< const CSCSegment * > matchCSC(const reco::Track &muon, const edm::Event &event)
void fillTiming(TimeMeasurementSequence &tmSequence, const std::vector< const CSCSegment * > &segments, reco::TrackRef muonTrack, const edm::Event &iEvent, const edm::EventSetup &iSetup)
MuonSegmentMatcher * theMatcher

Member Data Documentation

edm::InputTag CSCTimingExtractor::CSCSegmentTags_
private

Definition at line 82 of file CSCTimingExtractor.h.

bool CSCTimingExtractor::debug
private
unsigned int CSCTimingExtractor::theHitsMin_
private

Definition at line 83 of file CSCTimingExtractor.h.

MuonSegmentMatcher* CSCTimingExtractor::theMatcher
private

Definition at line 94 of file CSCTimingExtractor.h.

Referenced by CSCTimingExtractor(), and fillTiming().

double CSCTimingExtractor::thePruneCut_
private

Definition at line 84 of file CSCTimingExtractor.h.

Referenced by fillTiming().

std::unique_ptr<MuonServiceProxy> CSCTimingExtractor::theService
private

Definition at line 93 of file CSCTimingExtractor.h.

Referenced by CSCTimingExtractor(), and fillTiming().

double CSCTimingExtractor::theStripError_
private

Definition at line 87 of file CSCTimingExtractor.h.

Referenced by fillTiming().

double CSCTimingExtractor::theStripTimeOffset_
private

Definition at line 85 of file CSCTimingExtractor.h.

Referenced by fillTiming().

double CSCTimingExtractor::theWireError_
private

Definition at line 88 of file CSCTimingExtractor.h.

Referenced by fillTiming().

double CSCTimingExtractor::theWireTimeOffset_
private

Definition at line 86 of file CSCTimingExtractor.h.

Referenced by fillTiming().

bool CSCTimingExtractor::UseStripTime
private

Definition at line 90 of file CSCTimingExtractor.h.

Referenced by fillTiming().

bool CSCTimingExtractor::UseWireTime
private

Definition at line 89 of file CSCTimingExtractor.h.

Referenced by fillTiming().