77 theHitsMin_(iConfig.getParameter<
int>(
"HitsMin")),
78 thePruneCut_(iConfig.getParameter<double>(
"PruneCut")),
79 theTimeOffset_(iConfig.getParameter<double>(
"DTTimeOffset")),
80 theError_(iConfig.getParameter<double>(
"HitError")),
81 useSegmentT0_(iConfig.getParameter<bool>(
"UseSegmentT0")),
82 doWireCorr_(iConfig.getParameter<bool>(
"DoWireCorr")),
83 dropTheta_(iConfig.getParameter<bool>(
"DropTheta")),
84 requireBothProjections_(iConfig.getParameter<bool>(
"RequireBothProjections")),
85 debug(iConfig.getParameter<bool>(
"debug"))
88 theService = std::make_unique<MuonServiceProxy>(serviceParameters);
108 std::cout <<
" *** DT Timimng Extractor ***" << std::endl;
130 std::vector<const DTRecSegment4D*> range =
theMatcher->
matchDT(*muonTrack,iEvent);
133 std::cout <<
" The muon track matches " << range.size() <<
" segments." << std::endl;
136 std::vector<TimeMeasurement> tms;
137 for (std::vector<const DTRecSegment4D*>::iterator rechit = range.begin(); rechit!=range.end();++rechit) {
140 DetId id = (*rechit)->geographicalId();
143 if (
debug)
std::cout <<
"Matched DT segment in station " << station << std::endl;
146 bool bothProjections = ( ((*rechit)->hasPhi()) && ((*rechit)->hasZed()) );
156 segm =
dynamic_cast<const DTRecSegment2D*
>((*rechit)->phiSegment());
159 else segm =
dynamic_cast<const DTRecSegment2D*
>((*rechit)->zSegment());
161 if(segm == 0)
continue;
168 for (std::vector<DTRecHit1D>::const_iterator hiti=hits1d.begin(); hiti!=hits1d.end(); hiti++) {
170 const GeomDet* dtcell = theTrackingGeometry->
idToDet(hiti->geographicalId());
173 std::pair< TrajectoryStateOnSurface, double> tsos;
177 double dist_straight = dtcell->
toGlobal(hiti->localPosition()).
mag();
178 if (tsos.first.isValid()) {
179 dist = tsos.second+posp.mag();
182 dist = dist_straight;
186 thisHit.
driftCell = hiti->geographicalId();
197 if (
doWireCorr_ && !bothProjections && tsos.first.isValid()) {
198 const DTLayer* layer = theDTGeom->
layer(hiti->wireId());
199 float propgL = layer->
toLocal( tsos.first.globalPosition() ).
y();
200 float wirePropCorr = propgL/24.4*0.00543;
201 if (thisHit.
isLeft) wirePropCorr=-wirePropCorr;
205 tofCorr = (tofCorr/29.979)*0.00543;
206 if (thisHit.
isLeft) tofCorr=-tofCorr;
210 float slCorr = (dist_straight-dist)/29.979*0.00543;
211 if (thisHit.
isLeft) slCorr=-slCorr;
217 tms.push_back(thisHit);
222 bool modified =
false;
223 std::vector <double> dstnc, local_t0, hitWeightTimeVtx, hitWeightInvbeta, left;
224 double totalWeightInvbeta=0;
225 double totalWeightTimeVtx=0;
233 hitWeightTimeVtx.clear();
234 hitWeightInvbeta.clear();
237 std::vector <int> hit_idx;
238 totalWeightInvbeta=0;
239 totalWeightTimeVtx=0;
242 for (
int sta=1;sta<5;sta++)
244 std::vector <TimeMeasurement> seg;
245 std::vector <int> seg_idx;
247 for (std::vector<TimeMeasurement>::iterator tm=tms.begin(); tm!=tms.end(); ++tm) {
248 if ((tm->station==sta) && (tm->isPhi==
phi)) {
250 seg_idx.push_back(tmpos);
255 unsigned int segsize = seg.size();
259 std::vector <double> hitxl,hitxr,hityl,hityr;
261 for (std::vector<TimeMeasurement>::iterator tm=seg.begin(); tm!=seg.end(); ++tm) {
263 DetId id = tm->driftCell;
271 hitxl.push_back(celly);
272 hityl.push_back(tm->posInLayer);
274 hitxr.push_back(celly);
275 hityr.push_back(tm->posInLayer);
279 if (!
fitT0(a,
b,hitxl,hityl,hitxr,hityr)) {
281 std::cout <<
" t0 = zero, Left hits: " << hitxl.size() <<
" Right hits: " << hitxr.size() << std::endl;
286 if ((!hitxl.size()) || (!hityl.size()))
continue;
289 for (std::vector<TimeMeasurement>::const_iterator tm=seg.begin(); tm!=seg.end(); ++tm) {
291 DetId id = tm->driftCell;
297 double segmLocalPos =
b+layerZ*
a;
298 double hitLocalPos = tm->posInLayer;
299 int hitSide = -tm->isLeft*2+1;
300 double t0_segm = (-(hitSide*segmLocalPos)+(hitSide*hitLocalPos))/0.00543+tm->timeCorr;
302 if (
debug)
std::cout <<
" Segm hit. dstnc: " << tm->distIP <<
" t0: " << t0_segm << std::endl;
304 dstnc.push_back(tm->distIP);
305 local_t0.push_back(t0_segm);
306 left.push_back(hitSide);
307 hitWeightInvbeta.push_back(((
double)seg.size()-2.)*tm->distIP*tm->distIP/((double)seg.size()*30.*30.*
theError_*
theError_));
308 hitWeightTimeVtx.push_back(((
double)seg.size()-2.)/((double)seg.size()*
theError_*
theError_));
309 hit_idx.push_back(seg_idx.at(segidx));
311 totalWeightInvbeta+=((double)seg.size()-2.)*tm->distIP*tm->distIP/((double)seg.size()*30.*30.*
theError_*
theError_);
316 if (totalWeightInvbeta==0)
break;
320 std::cout <<
" Points for global fit: " << dstnc.size() << std::endl;
322 double invbeta=0,invbetaErr=0;
323 double timeVtx=0,timeVtxErr=0;
325 for (
unsigned int i=0;
i<dstnc.size();
i++) {
326 invbeta+=(1.+local_t0.at(
i)/dstnc.at(
i)*30.)*hitWeightInvbeta.at(
i)/totalWeightInvbeta;
327 timeVtx+=local_t0.at(
i)*hitWeightTimeVtx.at(
i)/totalWeightTimeVtx;
331 std::vector<TimeMeasurement>::iterator tmmax;
334 double diff_ibeta,diff_tvtx;
335 for (
unsigned int i=0;
i<dstnc.size();
i++) {
336 diff_ibeta=(1.+local_t0.at(
i)/dstnc.at(
i)*30.)-invbeta;
337 diff_ibeta=diff_ibeta*diff_ibeta*hitWeightInvbeta.at(
i);
338 diff_tvtx=local_t0.at(
i)-timeVtx;
339 diff_tvtx=diff_tvtx*diff_tvtx*hitWeightTimeVtx.at(
i);
340 invbetaErr+=diff_ibeta;
341 timeVtxErr+=diff_tvtx;
345 if (diff_tvtx>chimax) {
346 tmmax=tms.begin()+hit_idx.at(
i);
358 double cf = 1./(dstnc.size()-1);
359 invbetaErr=
sqrt(invbetaErr/totalWeightInvbeta*cf);
360 timeVtxErr=
sqrt(timeVtxErr/totalWeightTimeVtx*cf);
361 std::cout <<
" Measured 1/beta: " << invbeta <<
" +/- " << invbetaErr << std::endl;
362 std::cout <<
" Measured time: " << timeVtx <<
" +/- " << timeVtxErr << std::endl;
367 for (
unsigned int i=0;
i<dstnc.size();
i++) {
368 tmSequence.
dstnc.push_back(dstnc.at(
i));
369 tmSequence.
local_t0.push_back(local_t0.at(
i));
380 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 ) {
382 double sx=0,
sy=0,sxy=0,sxx=0,ssx=0,ssy=0,
s=0,ss=0;
384 for (
unsigned int i=0;
i<xl.size();
i++) {
395 for (
unsigned int i=0;
i<xr.size();
i++) {
406 double delta = ss*ss*sxx+
s*sx*sx+
s*ssx*ssx-
s*
s*sxx-2*ss*sx*ssx;
411 a=(ssy*
s*ssx+sxy*ss*ss+
sy*sx*
s-
sy*ss*ssx-ssy*sx*ss-sxy*
s*
s)/delta;
412 b=(ssx*
sy*ssx+sxx*ssy*ss+sx*sxy*
s-sxx*
sy*
s-ssx*sxy*ss-sx*ssy*ssx)/delta;
413 t0_corr=(ssx*
s*sxy+sxx*ss*
sy+sx*sx*ssy-sxx*
s*ssy-sx*ss*sxy-ssx*sx*
sy)/delta;
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.
double totalWeightTimeVtx
LocalPoint toLocal(const GlobalPoint &gp) const
Conversion to the R.F. of the GeomDet.
const Plane & surface() const
The nominal surface of the GeomDet.
const Surface::PositionType & position() const
The position (origin of the R.F.)
virtual std::pair< TrajectoryStateOnSurface, double > propagateWithPath(const FreeTrajectoryState &, const Surface &) const final
edm::ESHandle< GlobalTrackingGeometry > theTrackingGeometry
std::vector< double > weightInvbeta
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
std::vector< double > weightTimeVtx
const DTSuperLayer * superLayer() const
const GeomDet * idToDet(DetId) const override
std::vector< const DTRecSegment4D * > matchDT(const reco::Track &muon, const edm::Event &event)
perform the matching
const DTLayer * layer(const DTLayerId &id) const
Return a layer given its id.
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
T const * product() const