Go to the documentation of this file.00001
00002
00003
00004
00005
00011
00012
00013
00014
00015
00016
00017
00018 #include "RecoMuon/MuonIdentification/interface/CSCTimingExtractor.h"
00019
00020
00021
00022 #include "FWCore/Framework/interface/Frameworkfwd.h"
00023 #include "FWCore/Framework/interface/EDProducer.h"
00024
00025 #include "FWCore/Framework/interface/Event.h"
00026 #include "FWCore/Framework/interface/MakerMacros.h"
00027
00028 #include "FWCore/ParameterSet/interface/ParameterSet.h"
00029
00030 #include "RecoMuon/TrackingTools/interface/MuonServiceProxy.h"
00031
00032 #include "Geometry/Records/interface/MuonGeometryRecord.h"
00033 #include "DataFormats/MuonDetId/interface/MuonSubdetId.h"
00034
00035 #include "Geometry/Records/interface/GlobalTrackingGeometryRecord.h"
00036 #include "Geometry/CommonDetUnit/interface/GlobalTrackingGeometry.h"
00037 #include "TrackingTools/Records/interface/TrackingComponentsRecord.h"
00038
00039 #include "DataFormats/MuonReco/interface/Muon.h"
00040 #include "DataFormats/MuonReco/interface/MuonFwd.h"
00041 #include "DataFormats/CSCRecHit/interface/CSCSegment.h"
00042 #include "DataFormats/MuonDetId/interface/CSCDetId.h"
00043 #include "DataFormats/CSCRecHit/interface/CSCRecHit2D.h"
00044 #include "DataFormats/TrackingRecHit/interface/TrackingRecHitFwd.h"
00045 #include "RecoMuon/TransientTrackingRecHit/interface/MuonTransientTrackingRecHit.h"
00046
00047 #include "DataFormats/TrackReco/interface/Track.h"
00048 #include "DataFormats/TrackReco/interface/TrackFwd.h"
00049 #include "DataFormats/TrackReco/interface/TrackExtra.h"
00050 #include "DataFormats/TrackReco/interface/TrackExtraFwd.h"
00051
00052
00053
00054 #include <memory>
00055 #include <vector>
00056 #include <string>
00057 #include <iostream>
00058
00059 namespace edm {
00060 class ParameterSet;
00061 class EventSetup;
00062 class InputTag;
00063 }
00064
00065 class MuonServiceProxy;
00066
00067
00068
00069
00070 CSCTimingExtractor::CSCTimingExtractor(const edm::ParameterSet& iConfig)
00071 :
00072 CSCSegmentTags_(iConfig.getParameter<edm::InputTag>("CSCsegments")),
00073 thePruneCut_(iConfig.getParameter<double>("PruneCut")),
00074 theTimeOffset_(iConfig.getParameter<double>("CSCTimeOffset")),
00075 debug(iConfig.getParameter<bool>("debug"))
00076 {
00077 edm::ParameterSet serviceParameters = iConfig.getParameter<edm::ParameterSet>("ServiceParameters");
00078 theService = new MuonServiceProxy(serviceParameters);
00079
00080 edm::ParameterSet matchParameters = iConfig.getParameter<edm::ParameterSet>("MatchParameters");
00081
00082 theMatcher = new MuonSegmentMatcher(matchParameters, theService);
00083 }
00084
00085
00086 CSCTimingExtractor::~CSCTimingExtractor()
00087 {
00088 if (theService) delete theService;
00089 if (theMatcher) delete theMatcher;
00090 }
00091
00092
00093
00094
00095
00096
00097
00098 void
00099 CSCTimingExtractor::fillTiming(TimeMeasurementSequence &tmSequence, reco::TrackRef muonTrack, const edm::Event& iEvent, const edm::EventSetup& iSetup)
00100 {
00101
00102 if (debug)
00103 std::cout << " *** CSC Timimng Extractor ***" << std::endl;
00104
00105 theService->update(iSetup);
00106
00107 const GlobalTrackingGeometry *theTrackingGeometry = &*theService->trackingGeometry();
00108
00109 edm::ESHandle<Propagator> propagator;
00110 iSetup.get<TrackingComponentsRecord>().get("SteppingHelixPropagatorAny", propagator);
00111 const Propagator *propag = propagator.product();
00112
00113 double invbeta=0;
00114 double invbetaerr=0;
00115 int totalWeight=0;
00116 std::vector<TimeMeasurement> tms;
00117
00118 math::XYZPoint pos=muonTrack->innerPosition();
00119 math::XYZVector mom=muonTrack->innerMomentum();
00120 GlobalPoint posp(pos.x(), pos.y(), pos.z());
00121 GlobalVector momv(mom.x(), mom.y(), mom.z());
00122 FreeTrajectoryState muonFTS(posp, momv, (TrackCharge)muonTrack->charge(), theService->magneticField().product());
00123
00124
00125 std::vector<const CSCSegment*> range = theMatcher->matchCSC(*muonTrack,iEvent);
00126
00127
00128 for (std::vector<const CSCSegment*>::iterator rechit = range.begin(); rechit!=range.end();++rechit) {
00129
00130
00131 DetId id = (*rechit)->geographicalId();
00132 CSCDetId chamberId(id.rawId());
00133 int station = chamberId.station();
00134
00135 if (!(*rechit)->specificRecHits().size()) continue;
00136
00137 const std::vector<CSCRecHit2D> hits2d = (*rechit)->specificRecHits();
00138
00139
00140 for (std::vector<CSCRecHit2D>::const_iterator hiti=hits2d.begin(); hiti!=hits2d.end(); hiti++) {
00141
00142 const GeomDet* cscDet = theTrackingGeometry->idToDet(hiti->geographicalId());
00143 TimeMeasurement thisHit;
00144
00145 std::pair< TrajectoryStateOnSurface, double> tsos;
00146 tsos=propag->propagateWithPath(muonFTS,cscDet->surface());
00147
00148 double dist;
00149 if (tsos.first.isValid()) dist = tsos.second+posp.mag();
00150 else dist = cscDet->toGlobal(hiti->localPosition()).mag();
00151
00152 thisHit.distIP = dist;
00153 thisHit.station = station;
00154 thisHit.timeCorr = hiti->tpeak()+theTimeOffset_;
00155 tms.push_back(thisHit);
00156
00157
00158
00159 }
00160
00161 }
00162
00163 bool modified = false;
00164 std::vector <double> dstnc, dsegm, dtraj, hitWeight;
00165
00166
00167 do {
00168
00169 modified = false;
00170 dstnc.clear();
00171 dsegm.clear();
00172 dtraj.clear();
00173 hitWeight.clear();
00174
00175 totalWeight=0;
00176
00177 for (std::vector<TimeMeasurement>::iterator tm=tms.begin(); tm!=tms.end(); ++tm) {
00178 dstnc.push_back(tm->distIP);
00179 dsegm.push_back(tm->timeCorr);
00180 hitWeight.push_back(1.);
00181 totalWeight++;
00182 }
00183
00184 if (totalWeight==0) break;
00185
00186
00187 if (debug)
00188 std::cout << " Points for global fit: " << dstnc.size() << std::endl;
00189
00190
00191 invbeta=0;
00192 for (unsigned int i=0;i<dstnc.size();i++)
00193 invbeta+=(1.+dsegm.at(i)/dstnc.at(i)*30.)*hitWeight.at(i)/totalWeight;
00194
00195 double chimax=0.;
00196 std::vector<TimeMeasurement>::iterator tmmax;
00197
00198
00199 double diff;
00200 for (unsigned int i=0;i<dstnc.size();i++) {
00201 diff=(1.+dsegm.at(i)/dstnc.at(i)*30.)-invbeta;
00202 diff=diff*diff*hitWeight.at(i);
00203 invbetaerr+=diff;
00204 if (diff/totalWeight>chimax) {
00205 tmmax=tms.begin()+i;
00206 chimax=diff;
00207 }
00208 }
00209
00210 invbetaerr=sqrt(invbetaerr/totalWeight);
00211
00212
00213 if (chimax>thePruneCut_) {
00214 tms.erase(tmmax);
00215 modified=true;
00216 }
00217
00218 if (debug)
00219 std::cout << " Measured 1/beta: " << invbeta << " +/- " << invbetaerr << std::endl;
00220
00221 } while (modified);
00222
00223
00224
00225 for (unsigned int i=0;i<dstnc.size();i++) {
00226 tmSequence.dstnc.push_back(dstnc.at(i));
00227 tmSequence.local_t0.push_back(dsegm.at(i));
00228 tmSequence.weight.push_back(hitWeight.at(i));
00229 }
00230
00231 tmSequence.totalWeight=totalWeight;
00232
00233 }
00234
00235
00236