test
CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
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 
20 // user include files
23 
26 
28 
30 
33 
37 
45 
50 
51 
52 // system include files
53 #include <memory>
54 #include <vector>
55 #include <string>
56 #include <iostream>
57 
58 namespace edm {
59  class ParameterSet;
60  class EventSetup;
61  class InputTag;
62 }
63 
64 class MuonServiceProxy;
65 
66 //
67 // constructors and destructor
68 //
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 = new MuonServiceProxy(serviceParameters);
82 
83  edm::ParameterSet matchParameters = iConfig.getParameter<edm::ParameterSet>("MatchParameters");
84 
85  theMatcher = new MuonSegmentMatcher(matchParameters, iC);
86 }
87 
88 
90 {
91  if (theService) delete theService;
92  if (theMatcher) delete theMatcher;
93 }
94 
95 
96 //
97 // member functions
98 //
99 
100 // ------------ method called to produce the data ------------
101 void
103 {
104 
105  if (debug)
106  std::cout << " *** CSC Timimng Extractor ***" << std::endl;
107 
108  theService->update(iSetup);
109 
111 
113  iSetup.get<TrackingComponentsRecord>().get("SteppingHelixPropagatorAny", propagator);
114  const Propagator *propag = propagator.product();
115 
116  double invbeta=0;
117  double invbetaerr=0;
118  double totalWeightInvbeta=0;
119  double totalWeightVertex=0;
120  std::vector<TimeMeasurement> tms;
121 
122  math::XYZPoint pos=muonTrack->innerPosition();
123  math::XYZVector mom=muonTrack->innerMomentum();
124 
125  if (sqrt(muonTrack->innerPosition().mag2()) > sqrt(muonTrack->outerPosition().mag2())){
126  pos=muonTrack->outerPosition();
127  mom=-1*muonTrack->outerMomentum();
128  }
129 
130  GlobalPoint posp(pos.x(), pos.y(), pos.z());
131  GlobalVector momv(mom.x(), mom.y(), mom.z());
132  FreeTrajectoryState muonFTS(posp, momv, (TrackCharge)muonTrack->charge(), theService->magneticField().product());
133 
134  // get the CSC segments that were used to construct the muon
135  std::vector<const CSCSegment*> range = theMatcher->matchCSC(*muonTrack,iEvent);
136 
137  // create a collection on TimeMeasurements for the track
138  for (std::vector<const CSCSegment*>::iterator rechit = range.begin(); rechit!=range.end();++rechit) {
139 
140  // Create the ChamberId
141  DetId id = (*rechit)->geographicalId();
142  CSCDetId chamberId(id.rawId());
143  // int station = chamberId.station();
144 
145  if (!(*rechit)->specificRecHits().size()) continue;
146 
147  const std::vector<CSCRecHit2D> hits2d = (*rechit)->specificRecHits();
148 
149  // store all the hits from the segment
150  for (std::vector<CSCRecHit2D>::const_iterator hiti=hits2d.begin(); hiti!=hits2d.end(); hiti++) {
151 
152  const GeomDet* cscDet = theTrackingGeometry->idToDet(hiti->geographicalId());
153  TimeMeasurement thisHit;
154 
155  std::pair< TrajectoryStateOnSurface, double> tsos;
156  tsos=propag->propagateWithPath(muonFTS,cscDet->surface());
157 
158  double dist;
159  if (tsos.first.isValid()) dist = tsos.second+posp.mag();
160  else dist = cscDet->toGlobal(hiti->localPosition()).mag();
161 
162  thisHit.distIP = dist;
163  if (UseStripTime) {
164  thisHit.weightInvbeta = dist*dist/(theStripError_*theStripError_*30.*30.);
166  thisHit.timeCorr = hiti->tpeak()-theStripTimeOffset_;
167  tms.push_back(thisHit);
168  }
169 
170  if (UseWireTime) {
171  thisHit.weightInvbeta = dist*dist/(theWireError_*theWireError_*30.*30.);
173  thisHit.timeCorr = hiti->wireTime()-theWireTimeOffset_;
174  tms.push_back(thisHit);
175  }
176 
177 
178 // std::cout << " CSC Hit. Dist= " << dist << " Time= " << thisHit.timeCorr
179 // << " invBeta= " << (1.+thisHit.timeCorr/dist*30.) << std::endl;
180  }
181 
182  } // rechit
183 
184  bool modified = false;
185  std::vector <double> dstnc, dsegm, dtraj, hitWeightInvbeta, hitWeightVertex;
186 
187  // Now loop over the measurements, calculate 1/beta and cut away outliers
188  do {
189 
190  modified = false;
191  dstnc.clear();
192  dsegm.clear();
193  dtraj.clear();
194  hitWeightInvbeta.clear();
195  hitWeightVertex.clear();
196 
197  totalWeightInvbeta=0;
198  totalWeightVertex=0;
199 
200  for (std::vector<TimeMeasurement>::iterator tm=tms.begin(); tm!=tms.end(); ++tm) {
201  dstnc.push_back(tm->distIP);
202  dsegm.push_back(tm->timeCorr);
203  hitWeightInvbeta.push_back(tm->weightInvbeta);
204  hitWeightVertex.push_back(tm->weightVertex);
205  totalWeightInvbeta+=tm->weightInvbeta;
206  totalWeightVertex+=tm->weightVertex;
207  }
208 
209  if (totalWeightInvbeta==0) break;
210 
211  // calculate the value and error of 1/beta from the complete set of 1D hits
212  if (debug)
213  std::cout << " Points for global fit: " << dstnc.size() << std::endl;
214 
215  // inverse beta - weighted average of the contributions from individual hits
216  invbeta=0;
217  for (unsigned int i=0;i<dstnc.size();i++)
218  invbeta+=(1.+dsegm.at(i)/dstnc.at(i)*30.)*hitWeightInvbeta.at(i)/totalWeightInvbeta;
219 
220  double chimax=0.;
221  std::vector<TimeMeasurement>::iterator tmmax;
222 
223  // the dispersion of inverse beta
224  double diff;
225  for (unsigned int i=0;i<dstnc.size();i++) {
226  diff=(1.+dsegm.at(i)/dstnc.at(i)*30.)-invbeta;
227  diff=diff*diff*hitWeightInvbeta.at(i);
228  invbetaerr+=diff;
229  if (diff>chimax) {
230  tmmax=tms.begin()+i;
231  chimax=diff;
232  }
233  }
234 
235  invbetaerr=sqrt(invbetaerr/totalWeightInvbeta);
236 
237  // cut away the outliers
238  if (chimax>thePruneCut_) {
239  tms.erase(tmmax);
240  modified=true;
241  }
242 
243  if (debug)
244  std::cout << " Measured 1/beta: " << invbeta << " +/- " << invbetaerr << std::endl;
245 
246  } while (modified);
247 
248  // std::cout << " *** FINAL Measured 1/beta: " << invbeta << " +/- " << invbetaerr << std::endl;
249 
250  for (unsigned int i=0;i<dstnc.size();i++) {
251  tmSequence.dstnc.push_back(dstnc.at(i));
252  tmSequence.local_t0.push_back(dsegm.at(i));
253  tmSequence.weightInvbeta.push_back(hitWeightInvbeta.at(i));
254  tmSequence.weightVertex.push_back(hitWeightVertex.at(i));
255  }
256 
257  tmSequence.totalWeightInvbeta=totalWeightInvbeta;
258  tmSequence.totalWeightVertex=totalWeightVertex;
259 
260 }
261 
262 //define this as a plug-in
263 //DEFINE_FWK_MODULE(CSCTimingExtractor);
void update(const edm::EventSetup &setup)
update the services each event
T getParameter(std::string const &) const
int i
Definition: DBlmapReader.cc:9
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:52
std::vector< const CSCSegment * > matchCSC(const reco::Track &muon, const edm::Event &event)
edm::ESHandle< MagneticField > magneticField() const
get the magnetic field
const Plane & surface() const
The nominal surface of the GeomDet.
Definition: GeomDet.h:40
int TrackCharge
Definition: TrackCharge.h:4
virtual const GeomDet * idToDet(DetId) const
int iEvent
Definition: GenABIO.cc:230
MuonSegmentMatcher * theMatcher
T sqrt(T t)
Definition: SSEVec.h:48
CSCTimingExtractor(const edm::ParameterSet &, edm::ConsumesCollector &iC)
Constructor.
edm::ESHandle< GlobalTrackingGeometry > theTrackingGeometry
std::vector< double > weightInvbeta
virtual std::pair< TrajectoryStateOnSurface, double > propagateWithPath(const FreeTrajectoryState &, const Surface &) const final
Definition: Propagator.cc:15
Definition: DetId.h:18
#define debug
Definition: HDRShower.cc:19
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
const T & get() const
Definition: EventSetup.h:56
T const * product() const
Definition: ESHandle.h:86
void fillTiming(TimeMeasurementSequence &tmSequence, reco::TrackRef muonTrack, const edm::Event &iEvent, const edm::EventSetup &iSetup)
edm::ESHandle< GlobalTrackingGeometry > trackingGeometry() const
get the tracking geometry
MuonServiceProxy * theService
tuple cout
Definition: gather_cfg.py:121
std::vector< double > dstnc
std::vector< double > weightVertex
~CSCTimingExtractor()
Destructor.