53 #include "CLHEP/Units/GlobalPhysicalConstants.h" 54 #include "CLHEP/Units/GlobalSystemOfUnits.h" 62 template<
class TrackCollection>
70 template <
class H,
class T>
92 if (!recHits.empty()){
97 auto rFirst = first.
mag2();
98 auto rLast = last.
mag2();
102 LogDebug(
"TrackExtenderWithMTD") <<
"Impossible to determine the rechits order" <<endl;
109 string dumpLayer(
const DetLayer* layer)
const;
116 static constexpr char betaOrigTrkName[] =
"generalTrackBeta";
117 static constexpr char t0OrigTrkName[] =
"generalTrackt0";
118 static constexpr char sigmat0OrigTrkName[] =
"generalTracksigmat0";
119 static constexpr char pathLengthOrigTrkName[] =
"generalTrackPathLength";
120 static constexpr char tmtdOrigTrkName[] =
"generalTracktmtd";
121 static constexpr char sigmatmtdOrigTrkName[] =
"generalTracksigmatmtd";
137 template<
class TrackCollection>
142 updateTraj_(iConfig.getParameter<
bool>(
"updateTrackTrajectory")),
143 updateExtra_(iConfig.getParameter<
bool>(
"updateTrackExtra")),
144 updatePattern_(iConfig.getParameter<
bool>(
"updateTrackHitPattern")),
145 mtdRecHitBuilder_(iConfig.getParameter<
std::
string>(
"MTDRecHitBuilder")),
146 propagator_(iConfig.getParameter<
std::
string>(
"Propagator")),
147 transientTrackBuilder_(iConfig.getParameter<
std::
string>(
"TransientTrackBuilder")) {
155 produces<edm::ValueMap<float> >(
tmtdName);
165 produces<edm::OwnVector<TrackingRecHit>>();
166 produces<reco::TrackExtraCollection>();
167 produces<TrackCollection>();
170 template<
class TrackCollection>
176 desc.
add<
bool>(
"updateTrackTrajectory",
true);
177 desc.
add<
bool>(
"updateTrackExtra",
true);
178 desc.
add<
bool>(
"updateTrackHitPattern",
true);
179 desc.
add<
std::string>(
"TransientTrackBuilder",
"TransientTrackBuilder");
181 desc.
add<
std::string>(
"Propagator",
"PropagatorWithMaterialForMTD");
184 "KFFitterForRefitInsideOut",
185 "KFSmootherForRefitInsideOut",
186 "PropagatorWithMaterialForMTD",
194 descriptions.
add(
"trackExtenderWithMTDBase", desc);
197 template<
class TrackCollection>
198 template <
class H,
class T>
200 auto out = std::make_unique<edm::ValueMap<T>>();
202 filler.insert(handle, vec.begin(), vec.end());
207 template<
class TrackCollection>
236 auto output = std::make_unique<TrackCollection>();
237 auto extras = std::make_unique<reco::TrackExtraCollection>();
238 auto outhits = std::make_unique<edm::OwnVector<TrackingRecHit>>();
240 std::vector<float> pathLengthsRaw;
241 std::vector<float> tmtdRaw;
242 std::vector<float> sigmatmtdRaw;
243 std::vector<float> pOrigTrkRaw;
244 std::vector<float> betaOrigTrkRaw;
245 std::vector<float> t0OrigTrkRaw;
246 std::vector<float> sigmat0OrigTrkRaw;
247 std::vector<float> pathLengthsOrigTrkRaw;
248 std::vector<float> tmtdOrigTrkRaw;
249 std::vector<float> sigmatmtdOrigTrkRaw;
253 const auto&
tracks = *tracksH;
257 const auto&
hits = *hitsH;
261 const auto& bs = *bsH;
263 std::vector<unsigned> track_indices;
273 mtdthits.insert(mtdthits.end(),btlhits.begin(),btlhits.end());
278 mtdthits.insert(mtdthits.end(),etlhits.begin(),etlhits.end());
282 thits.insert(thits.end(),mtdthits.begin(),mtdthits.end());
285 mtdthits.insert(mtdthits.end(),thits.begin(),thits.end());
286 thits.swap(mtdthits);
288 const auto& trajwithmtd =
theTransformer->transform(ttrack,thits);
289 float pMap = 0.f, betaMap = 0.f, t0Map = 0.f, sigmat0Map = -1.f, pathLengthMap = -1.f, tmtdMap = 0.f, sigmatmtdMap = -1.f;
291 for(
const auto& trj : trajwithmtd ) {
292 const auto& thetrj = (
updateTraj_ ? trj : trajs.front());
293 float pathLength = 0.f, tmtd = 0.f, sigmatmtd = -1.f;
295 prop.
product(), !mtdthits.empty(),pathLength,tmtd,sigmatmtd);
296 if( result.
ndof() >= 0 ) {
300 size_t hitsstart = outhits->size();
302 t2t(trj,*outhits,trajParams,chi2s);
304 t2t(thetrj,*outhits,trajParams,chi2s);
306 size_t hitsend = outhits->size();
308 extras->back().setHits(hitsRefProd,hitsstart,hitsend-hitsstart);
309 extras->back().setTrajParams(trajParams,chi2s);
311 output->push_back(result);
312 pathLengthsRaw.push_back(pathLength);
313 tmtdRaw.push_back(tmtd);
314 sigmatmtdRaw.push_back(sigmatmtd);
315 pathLengthMap = pathLength;
317 sigmatmtdMap = sigmatmtd;
318 auto& backtrack =
output->back();
319 pMap = backtrack.p();
320 betaMap = backtrack.beta();
321 t0Map = backtrack.t0();
322 sigmat0Map = std::copysign(
std::sqrt(
std::abs(backtrack.covt0t0())),backtrack.covt0t0());
325 for(
unsigned ihit = hitsstart; ihit < hitsend; ++ihit) {
326 backtrack.appendHitPattern((*outhits)[ihit],ttopo);
330 pOrigTrkRaw.push_back(pMap);
331 betaOrigTrkRaw.push_back(betaMap);
332 t0OrigTrkRaw.push_back(t0Map);
333 sigmat0OrigTrkRaw.push_back(sigmat0Map);
334 pathLengthsOrigTrkRaw.push_back(pathLengthMap);
335 tmtdOrigTrkRaw.push_back(tmtdMap);
336 sigmatmtdOrigTrkRaw.push_back(sigmatmtdMap);
357 bool cmp_for_detset(
const unsigned one,
const unsigned two) {
return one < two; };
364 pair<bool, TrajectoryStateOnSurface>
comp = layer->
compatible(tsos,*prop,theEstimator);
366 vector<DetLayer::DetWithState> compDets = layer->
compatibleDets(tsos,*prop,theEstimator);
367 if (!compDets.empty()) {
370 for(
const auto& detWithState : compDets ) {
371 auto range = hits.
equal_range(detWithState.first->geographicalId(),cmp_for_detset);
372 for(
auto detitr = range.first; detitr != range.second; ++detitr ) {
373 for(
auto itr = detitr->begin(); itr != detitr->end(); ++itr ) {
374 auto est = theEstimator.
estimate(detWithState.second,*itr);
375 if( est.first && est.second < best_chi2 ) {
377 best_chi2 = est.second;
384 output.push_back(hitbuilder.
build(best));
390 template<
class TrackCollection>
402 for (
const DetLayer* ilay : layers) {
410 template<
class TrackCollection>
423 for (
const DetLayer* ilay : layers) {
425 const double diskZ = disk.position().z();
438 template<
class TrackCollection>
446 float& pathLengthOut,
448 float& sigmatmtdOut)
const {
455 edm::LogError(
"CannotPropagateToBeamLine")<<
"the state on the closest measurement isnot valid. skipping track.";
463 constexpr double c_cm_ns = CLHEP::c_light*CLHEP::ns/CLHEP::cm;
483 double covt0t0 = -1.;
484 pathLengthOut = -1.f;
488 double covbetabeta = -1.;
493 bool validpropagation =
true;
494 double pathlength = 0.;
495 double pathlength1 = 0.;
496 double pathlength2 = 0.;
499 double layerpathlength =
std::abs(propresult.second);
500 if (layerpathlength==0.) {
501 validpropagation =
false;
503 pathlength1 += layerpathlength;
507 double thiterror = -1.;
508 bool validmtd =
false;
514 pathlength2 = propresult2.second;
515 if (pathlength2 == 0.) {
516 validpropagation =
false;
518 pathlength = pathlength1 + pathlength2;
520 thit = mtdhit->
time();
532 pathlength2 = propresult2.second;
533 if (pathlength2 == 0.) {
534 validpropagation =
false;
536 pathlength = pathlength1 + pathlength2;
538 thit = mtdhit->
time();
546 if (validmtd && validpropagation) {
547 double magp2 = p.mag2();
549 double gammasq_pi = 1. + magp2*m_pi_inv2;
550 double beta_pi =
std::sqrt(1.-1./gammasq_pi);
551 double dt_pi = pathlength/beta_pi*c_inv;
553 double gammasq_p = 1. + magp2*m_p_inv2;
554 double beta_p =
std::sqrt(1.-1./gammasq_p);
555 double dt_p = pathlength/beta_p*c_inv;
557 double dterror = dt_p - dt_pi;
558 double betaerror = beta_p - beta_pi;
560 pathLengthOut = pathlength;
562 sigmatmtdOut = thiterror;
564 covt0t0 = thiterror*thiterror + dterror*dterror;
566 covbetabeta = betaerror*betaerror;
578 template<
class TrackCollection>
581 static const string metname =
"TrackExtenderWithMTD";
591 unsigned int innerId=0, outerId=0;
605 LogTrace(metname)<<
"oppositeToMomentum";
613 else LogError(metname)<<
"Wrong propagation direction!";
624 <<
"The Global Muon outerMostMeasurementState is not compatible with the recHit detector!" 625 <<
" Setting outerMost postition to recHit position if recHit isValid: " << outerRecHit->isValid();
626 LogTrace(metname)<<
"From " << outerTSOSPos <<
" to " << hitPos;
650 template<
class TrackCollection>
659 if ( (bc = dynamic_cast<const BoundCylinder*>(sur)) ) {
660 output <<
" Cylinder of radius: " << bc->radius() << endl;
662 else if ( (bd = dynamic_cast<const BoundDisk*>(sur)) ) {
663 output <<
" Disk at: " << bd->position().z() << endl;
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
double z0() const
z coordinate
TrackExtenderWithMTDT< reco::TrackCollection > TrackExtenderWithMTD
OrphanHandle< PROD > put(std::unique_ptr< PROD > product)
Put a new product.
std::vector< LayerSetAndLayers > layers(const SeedingLayerSetsHits &sets)
ConstRecHitPointer const & recHit() const
Range equal_range(id_type i, CMP cmp, bool update=false) const
reco::TrackExtra buildTrackExtra(const Trajectory &trajectory) const
bool getByToken(EDGetToken token, Handle< PROD > &result) const
const std::string metname
edm::EDGetTokenT< reco::BeamSpot > bsToken_
std::unique_ptr< MeasurementEstimator > theEstimator
TrackExtenderWithMTDT(const ParameterSet &pset)
const CurvilinearTrajectoryError & curvilinearError() const
static char sigmat0OrigTrkName[]
Global3DPoint GlobalPoint
reco::TransientTrack build(const reco::Track *p) const
string dumpLayer(const DetLayer *layer) const
const bool updatePattern_
edm::View< TrackType > InputCollection
GlobalPoint globalPosition() const
LocalPoint toLocal(const GlobalPoint &gp) const
Conversion to the R.F. of the GeomDet.
ConstRecHitContainer recHits() const
const Bounds & bounds() const
edm::ESHandle< GlobalTrackingGeometry > gtg
const std::vector< const DetLayer * > & allBTLLayers() const
return the BTL DetLayers (barrel), inside-out
TrackCharge charge() const
reco::Track buildTrack(const reco::Track &, const Trajectory &, const Trajectory &, const reco::BeamSpot &, const MagneticField *field, const Propagator *prop, bool hasMTD, float &pathLength, float &tmtdOut, float &sigmatmtdOut) const
TrajectoryMeasurement const & closestMeasurement(GlobalPoint) const
const Plane & surface() const
The nominal surface of the GeomDet.
const CurvilinearTrajectoryError & curvilinearError() const
virtual std::vector< DetWithState > compatibleDets(const TrajectoryStateOnSurface &startingState, const Propagator &prop, const MeasurementEstimator &est) const
edm::EDGetTokenT< MTDTrackingDetSetVector > hitsToken_
static char sigmatmtdOrigTrkName[]
static char pOrigTrkName[]
PropagationDirection const & direction() const
TrackAlgorithm algo() const
DataContainer const & measurements() const
virtual bool inside(const Local3DPoint &) const =0
Determine if the point is inside the bounds.
const SurfaceType & surface() const
#define DEFINE_FWK_MODULE(type)
Container::value_type value_type
static char betaOrigTrkName[]
const std::vector< const DetLayer * > & allETLLayers() const
return the ETL DetLayers (endcap), -Z to +Z
const std::string mtdRecHitBuilder_
edm::ESHandle< TransientTrackingRecHitBuilder > hitbuilder
double ndof() const
number of degrees of freedom of the fit
TrajectoryMeasurement const & lastMeasurement() const
FreeTrajectoryState const * freeState(bool withErrors=true) const
GlobalVector momentum() const
RefitDirection::GeometricalDirection checkRecHitsOrdering(TransientTrackingRecHit::ConstRecHitContainer const &recHits) const
virtual std::pair< TrajectoryStateOnSurface, double > propagateWithPath(const FreeTrajectoryState &, const Surface &) const final
Abs< T >::type abs(const T &t)
virtual const BoundSurface & surface() const =0
The surface of the GeometricSearchDet.
const std::string propagator_
static char pathLengthName[]
static char tmtdOrigTrkName[]
ParameterDescriptionBase * add(U const &iLabel, T const &value)
edm::RefToBase< TrajectorySeed > seedRef(void) const
static char sigmatmtdName[]
virtual std::pair< bool, TrajectoryStateOnSurface > compatible(const TrajectoryStateOnSurface &ts, const Propagator &, const MeasurementEstimator &) const =0
GlobalVector momentum() const
RefProd< PROD > getRefBeforePut()
virtual RecHitPointer build(const TrackingRecHit *p) const =0
build a tracking rechit from an existing rechit
FTS const & trackStateAtPCA() const
GlobalPoint position() const
std::vector< ConstRecHitPointer > ConstRecHitContainer
const std::string transientTrackBuilder_
GlobalPoint position() const
int ndof(bool bon=true) const
std::vector< TrackExtra > TrackExtraCollection
collection of TrackExtra objects
TrajectoryMeasurement const & firstMeasurement() const
ConstRecHitContainer RecHitContainer
TransientTrackingRecHit::ConstRecHitContainer tryBTLLayers(const TrackType &, const MTDTrackingDetSetVector &, const MTDDetLayerGeometry *, const MagneticField *field, const Propagator *prop) const
static char pathLengthOrigTrkName[]
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
edm::ESHandle< Propagator > prop
const GlobalTrajectoryParameters & globalParameters() const
ParameterSet const & getParameterSet(std::string const &) const
XYZVectorD XYZVector
spatial vector with cartesian internal representation
TransientTrackingRecHit::ConstRecHitContainer tryETLLayers(const TrackType &, const MTDTrackingDetSetVector &, const MTDDetLayerGeometry *, const MagneticField *field, const Propagator *prop) const
edm::ESHandle< TransientTrackBuilder > builder
XYZPointD XYZPoint
point in space with cartesian internal representation
A 2D TrackerRecHit with time and time error information.
void add(std::string const &label, ParameterSetDescription const &psetDescription)
TrackingRecHit::ConstRecHitPointer ConstRecHitPointer
std::unique_ptr< TrackTransformer > theTransformer
static char t0OrigTrkName[]
static int position[264][3]
const GeomDet * idToDet(DetId) const override
double y0() const
y coordinate
virtual HitReturnType estimate(const TrajectoryStateOnSurface &ts, const TrackingRecHit &hit) const =0
TrajectoryStateOnSurface const & updatedState() const
TrackCollection::value_type TrackType
T const * product() const
void produce(edm::Event &ev, const edm::EventSetup &es) final
edm::EDGetTokenT< InputCollection > tracksToken_
void fillValueMap(edm::Event &iEvent, const H &handle, const std::vector< T > &vec, const std::string &name) const
double x0() const
x coordinate