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);
102 const std::vector<const DTRecSegment4D*> &segments,
107 std::cout <<
" *** DT Timimng Extractor ***" << std::endl;
129 std::vector<TimeMeasurement> tms;
130 for (
const auto& rechit : segments ) {
133 DetId id = rechit->geographicalId();
136 if (
debug)
std::cout <<
"Matched DT segment in station " << station << std::endl;
139 bool bothProjections = ( (rechit->hasPhi()) && (rechit->hasZed()) );
152 else segm =
dynamic_cast<const DTRecSegment2D*
>(rechit->zSegment());
154 if(segm ==
nullptr)
continue;
161 for (
const auto& hiti : hits1d) {
163 const GeomDet* dtcell = theTrackingGeometry->
idToDet(hiti.geographicalId());
166 std::pair< TrajectoryStateOnSurface, double> tsos;
170 double dist_straight = dtcell->
toGlobal(hiti.localPosition()).
mag();
171 if (tsos.first.isValid()) {
172 dist = tsos.second+posp.mag();
175 dist = dist_straight;
179 thisHit.
driftCell = hiti.geographicalId();
190 if (
doWireCorr_ && !bothProjections && tsos.first.isValid()) {
192 float propgL = layer->
toLocal( tsos.first.globalPosition() ).
y();
193 float wirePropCorr = propgL/24.4*0.00543;
194 if (thisHit.
isLeft) wirePropCorr=-wirePropCorr;
198 tofCorr = (tofCorr/29.979)*0.00543;
199 if (thisHit.
isLeft) tofCorr=-tofCorr;
203 float slCorr = (dist_straight-dist)/29.979*0.00543;
204 if (thisHit.
isLeft) slCorr=-slCorr;
210 tms.push_back(thisHit);
215 bool modified =
false;
216 std::vector <double> dstnc, local_t0, hitWeightTimeVtx, hitWeightInvbeta, left;
217 double totalWeightInvbeta=0;
218 double totalWeightTimeVtx=0;
226 hitWeightTimeVtx.clear();
227 hitWeightInvbeta.clear();
230 std::vector <int> hit_idx;
231 totalWeightInvbeta=0;
232 totalWeightTimeVtx=0;
235 for (
int sta=1;sta<5;sta++)
237 std::vector <TimeMeasurement> seg;
238 std::vector <int> seg_idx;
240 for (
auto& tm : tms) {
241 if ((tm.station==sta) && (tm.isPhi==
phi)) {
243 seg_idx.push_back(tmpos);
248 unsigned int segsize = seg.size();
252 std::vector <double> hitxl,hitxr,hityl,hityr;
254 for (
auto& tm : seg) {
256 DetId id = tm.driftCell;
264 hitxl.push_back(celly);
265 hityl.push_back(tm.posInLayer);
267 hitxr.push_back(celly);
268 hityr.push_back(tm.posInLayer);
272 if (!
fitT0(a,
b,hitxl,hityl,hitxr,hityr)) {
274 std::cout <<
" t0 = zero, Left hits: " << hitxl.size() <<
" Right hits: " << hitxr.size() << std::endl;
279 if ((hitxl.empty()) || (hityl.empty()))
continue;
282 for (
const auto& tm : seg) {
284 DetId id = tm.driftCell;
290 double segmLocalPos =
b+layerZ*
a;
291 double hitLocalPos = tm.posInLayer;
292 int hitSide = -tm.isLeft*2+1;
293 double t0_segm = (-(hitSide*segmLocalPos)+(hitSide*hitLocalPos))/0.00543+tm.timeCorr;
295 if (
debug)
std::cout <<
" Segm hit. dstnc: " << tm.distIP <<
" t0: " << t0_segm << std::endl;
297 dstnc.push_back(tm.distIP);
298 local_t0.push_back(t0_segm);
299 left.push_back(hitSide);
300 hitWeightInvbeta.push_back(((
double)seg.size()-2.)*tm.distIP*tm.distIP/((double)seg.size()*30.*30.*
theError_*
theError_));
301 hitWeightTimeVtx.push_back(((
double)seg.size()-2.)/((double)seg.size()*
theError_*
theError_));
302 hit_idx.push_back(seg_idx.at(segidx));
304 totalWeightInvbeta+=((double)seg.size()-2.)*tm.distIP*tm.distIP/((double)seg.size()*30.*30.*
theError_*
theError_);
309 if (totalWeightInvbeta==0)
break;
313 std::cout <<
" Points for global fit: " << dstnc.size() << std::endl;
315 double invbeta=0,invbetaErr=0;
316 double timeVtx=0,timeVtxErr=0;
318 for (
unsigned int i=0;
i<dstnc.size();
i++) {
319 invbeta+=(1.+local_t0.at(
i)/dstnc.at(
i)*30.)*hitWeightInvbeta.at(
i)/totalWeightInvbeta;
320 timeVtx+=local_t0.at(
i)*hitWeightTimeVtx.at(
i)/totalWeightTimeVtx;
324 std::vector<TimeMeasurement>::iterator tmmax;
327 double diff_ibeta,diff_tvtx;
328 for (
unsigned int i=0;
i<dstnc.size();
i++) {
329 diff_ibeta=(1.+local_t0.at(
i)/dstnc.at(
i)*30.)-invbeta;
330 diff_ibeta=diff_ibeta*diff_ibeta*hitWeightInvbeta.at(
i);
331 diff_tvtx=local_t0.at(
i)-timeVtx;
332 diff_tvtx=diff_tvtx*diff_tvtx*hitWeightTimeVtx.at(
i);
333 invbetaErr+=diff_ibeta;
334 timeVtxErr+=diff_tvtx;
338 if (diff_tvtx>chimax) {
339 tmmax=tms.begin()+hit_idx.at(
i);
351 double cf = 1./(dstnc.size()-1);
352 invbetaErr=
sqrt(invbetaErr/totalWeightInvbeta*cf);
353 timeVtxErr=
sqrt(timeVtxErr/totalWeightTimeVtx*cf);
354 std::cout <<
" Measured 1/beta: " << invbeta <<
" +/- " << invbetaErr << std::endl;
355 std::cout <<
" Measured time: " << timeVtx <<
" +/- " << timeVtxErr << std::endl;
360 for (
unsigned int i=0;
i<dstnc.size();
i++) {
361 tmSequence.
dstnc.push_back(dstnc.at(
i));
362 tmSequence.
local_t0.push_back(local_t0.at(
i));
377 std::vector<const DTRecSegment4D*> range =
theMatcher->
matchDT(*muonTrack,iEvent);
380 std::cout <<
" The muon track matches " << range.size() <<
" segments." << std::endl;
381 fillTiming(tmSequence,range,muonTrack,iEvent,iSetup);
385 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 ) {
387 double sx=0,
sy=0,sxy=0,sxx=0,ssx=0,ssy=0,
s=0,ss=0;
389 for (
unsigned int i=0;
i<xl.size();
i++) {
400 for (
unsigned int i=0;
i<xr.size();
i++) {
411 double delta = ss*ss*sxx+
s*sx*sx+
s*ssx*ssx-
s*
s*sxx-2*ss*sx*ssx;
416 a=(ssy*
s*ssx+sxy*ss*ss+
sy*sx*
s-
sy*ss*ssx-ssy*sx*ss-sxy*
s*
s)/delta;
417 b=(ssx*
sy*ssx+sxx*ssy*ss+sx*sxy*
s-sxx*
sy*
s-ssx*sxy*ss-sx*ssy*ssx)/delta;
418 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