77 DTSegmentTags_(iConfig.getParameter<edm::InputTag>(
"DTsegments")),
78 theHitsMin_(iConfig.getParameter<int>(
"HitsMin")),
79 thePruneCut_(iConfig.getParameter<double>(
"PruneCut")),
80 theTimeOffset_(iConfig.getParameter<double>(
"DTTimeOffset")),
81 theError_(iConfig.getParameter<double>(
"HitError")),
82 useSegmentT0_(iConfig.getParameter<bool>(
"UseSegmentT0")),
83 doWireCorr_(iConfig.getParameter<bool>(
"DoWireCorr")),
84 dropTheta_(iConfig.getParameter<bool>(
"DropTheta")),
85 requireBothProjections_(iConfig.getParameter<bool>(
"RequireBothProjections")),
86 debug(iConfig.getParameter<bool>(
"debug"))
116 std::cout <<
" *** Muon Timimng Extractor ***" << std::endl;
132 double totalWeightInvbeta=0;
133 double totalWeightVertex=0;
134 std::vector<TimeMeasurement> tms;
143 std::vector<const DTRecSegment4D*> range =
theMatcher->
matchDT(*muonTrack,iEvent);
146 std::cout <<
" The muon track matches " << range.size() <<
" segments." << std::endl;
150 for (std::vector<const DTRecSegment4D*>::iterator rechit = range.begin(); rechit!=range.end();++rechit) {
153 DetId id = (*rechit)->geographicalId();
156 if (
debug)
std::cout <<
"Matched DT segment in station " << station << std::endl;
159 bool bothProjections = ( ((*rechit)->hasPhi()) && ((*rechit)->hasZed()) );
170 else segm =
dynamic_cast<const DTRecSegment2D*
>((*rechit)->zSegment());
172 if(segm == 0)
continue;
179 for (std::vector<DTRecHit1D>::const_iterator hiti=hits1d.begin(); hiti!=hits1d.end(); hiti++) {
181 const GeomDet* dtcell = theTrackingGeometry->
idToDet(hiti->geographicalId());
184 std::pair< TrajectoryStateOnSurface, double> tsos;
188 double dist_straight = dtcell->
toGlobal(hiti->localPosition()).
mag();
189 if (tsos.first.isValid()) {
190 dist = tsos.second+posp.mag();
193 dist = dist_straight;
197 thisHit.
driftCell = hiti->geographicalId();
208 if (
doWireCorr_ && !bothProjections && tsos.first.isValid()) {
209 const DTLayer* layer = theDTGeom->layer(hiti->wireId());
210 float propgL = layer->
toLocal( tsos.first.globalPosition() ).
y();
211 float wirePropCorr = propgL/24.4*0.00543;
212 if (thisHit.
isLeft) wirePropCorr=-wirePropCorr;
216 tofCorr = (tofCorr/29.979)*0.00543;
217 if (thisHit.
isLeft) tofCorr=-tofCorr;
221 float slCorr = (dist_straight-dist)/29.979*0.00543;
222 if (thisHit.
isLeft) slCorr=-slCorr;
228 tms.push_back(thisHit);
233 bool modified =
false;
234 std::vector <double> dstnc, dsegm, dtraj, hitWeightVertex, hitWeightInvbeta, left;
243 hitWeightVertex.clear();
244 hitWeightInvbeta.clear();
247 std::vector <int> hit_idx;
248 totalWeightInvbeta=0;
252 for (
int sta=1;sta<5;sta++)
254 std::vector <TimeMeasurement> seg;
255 std::vector <int> seg_idx;
257 for (std::vector<TimeMeasurement>::iterator tm=tms.begin(); tm!=tms.end(); ++tm) {
258 if ((tm->station==sta) && (tm->isPhi==
phi)) {
260 seg_idx.push_back(tmpos);
265 unsigned int segsize = seg.size();
269 std::vector <double> hitxl,hitxr,hityl,hityr;
271 for (std::vector<TimeMeasurement>::iterator tm=seg.begin(); tm!=seg.end(); ++tm) {
273 DetId id = tm->driftCell;
281 hitxl.push_back(celly);
282 hityl.push_back(tm->posInLayer);
284 hitxr.push_back(celly);
285 hityr.push_back(tm->posInLayer);
289 if (!
fitT0(a,
b,hitxl,hityl,hitxr,hityr)) {
291 std::cout <<
" t0 = zero, Left hits: " << hitxl.size() <<
" Right hits: " << hitxr.size() << std::endl;
296 if ((!hitxl.size()) || (!hityl.size()))
continue;
299 for (std::vector<TimeMeasurement>::const_iterator tm=seg.begin(); tm!=seg.end(); ++tm) {
301 DetId id = tm->driftCell;
307 double segmLocalPos =
b+layerZ*
a;
308 double hitLocalPos = tm->posInLayer;
309 int hitSide = -tm->isLeft*2+1;
310 double t0_segm = (-(hitSide*segmLocalPos)+(hitSide*hitLocalPos))/0.00543+tm->timeCorr;
312 if (
debug)
std::cout <<
" Segm hit. dstnc: " << tm->distIP <<
" t0: " << t0_segm << std::endl;
314 dstnc.push_back(tm->distIP);
315 dsegm.push_back(t0_segm);
316 left.push_back(hitSide);
317 hitWeightInvbeta.push_back(((
double)seg.size()-2.)*tm->distIP*tm->distIP/((double)seg.size()*30.*30.*
theError_*
theError_));
318 hitWeightVertex.push_back(((
double)seg.size()-2.)/((double)seg.size()*
theError_*
theError_));
319 hit_idx.push_back(seg_idx.at(segidx));
321 totalWeightInvbeta+=((double)seg.size()-2.)*tm->distIP*tm->distIP/((double)seg.size()*30.*30.*
theError_*
theError_);
326 if (totalWeightInvbeta==0)
break;
330 std::cout <<
" Points for global fit: " << dstnc.size() << std::endl;
334 for (
unsigned int i=0;
i<dstnc.size();
i++)
335 invbeta+=(1.+dsegm.at(
i)/dstnc.at(
i)*30.)*hitWeightInvbeta.at(
i)/totalWeightInvbeta;
338 std::vector<TimeMeasurement>::iterator tmmax;
342 for (
unsigned int i=0;
i<dstnc.size();
i++) {
343 diff=(1.+dsegm.at(
i)/dstnc.at(
i)*30.)-invbeta;
344 diff=diff*diff*hitWeightInvbeta.at(
i);
347 tmmax=tms.begin()+hit_idx.at(
i);
352 invbetaerr=
sqrt(invbetaerr/totalWeightInvbeta);
361 std::cout <<
" Measured 1/beta: " << invbeta <<
" +/- " << invbetaerr << std::endl;
365 for (
unsigned int i=0;
i<dstnc.size();
i++) {
366 tmSequence.
dstnc.push_back(dstnc.at(
i));
367 tmSequence.
local_t0.push_back(dsegm.at(
i));
378 DTTimingExtractor::fitT0(
double &
a,
double &
b,
const std::vector<double>& xl,
const std::vector<double>& yl,
const std::vector<double>& xr,
const std::vector<double>& yr ) {
380 double sx=0,sy=0,sxy=0,sxx=0,ssx=0,ssy=0,
s=0,
ss=0;
382 for (
unsigned int i=0;
i<xl.size();
i++) {
393 for (
unsigned int i=0;
i<xr.size();
i++) {
409 a=(ssy*
s*ssx+sxy*
ss*
ss+sy*sx*
s-sy*
ss*ssx-ssy*sx*
ss-sxy*
s*
s)/delta;
410 b=(ssx*sy*ssx+sxx*ssy*
ss+sx*sxy*
s-sxx*sy*
s-ssx*sxy*
ss-sx*ssy*ssx)/delta;
411 t0_corr=(ssx*
s*sxy+sxx*
ss*sy+sx*sx*ssy-sxx*
s*ssy-sx*
ss*sxy-ssx*sx*sy)/delta;
void update(const edm::EventSetup &setup)
update the services each event
T getParameter(std::string const &) const
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.
LocalPoint toLocal(const GlobalPoint &gp) const
Conversion to the R.F. of the GeomDet.
edm::ESHandle< MagneticField > magneticField() const
get the magnetic field
const Plane & surface() const
The nominal surface of the GeomDet.
virtual const GeomDet * idToDet(DetId) const
const Surface::PositionType & position() const
The position (origin of the R.F.)
edm::ESHandle< GlobalTrackingGeometry > theTrackingGeometry
std::vector< double > weightInvbeta
virtual std::pair< TrajectoryStateOnSurface, double > propagateWithPath(const FreeTrajectoryState &, const Surface &) const final
std::vector< DTRecHit1D > specificRecHits() const
Access to specific components.
double totalWeightInvbeta
XYZVectorD XYZVector
spatial vector with cartesian internal representation
XYZPointD XYZPoint
point in space with cartesian internal representation
T const * product() const
const DTSuperLayer * superLayer() const
edm::ESHandle< GlobalTrackingGeometry > trackingGeometry() const
get the tracking geometry
std::vector< const DTRecSegment4D * > matchDT(const reco::Track &muon, const edm::Event &event)
perform the matching
DetId geographicalId() const
double t0() const
Get the segment t0 (if recomputed, 0 is returned otherwise)
int station() const
Return the station number.
std::vector< double > dstnc
const PositionType & position() const
std::vector< double > weightVertex
edm::ESHandle< Propagator > propagator(std::string propagatorName) const
get the propagator