78 : theCosmicFlag(par.getParameter<bool>(
"PropDirForCosmics")),
79 theDTRecHitLabel(par.getParameter<
InputTag>(
"DTRecSegmentLabel")),
80 theCSCRecHitLabel(par.getParameter<
InputTag>(
"CSCRecSegmentLabel")),
81 theGEMRecHitLabel(par.getParameter<
InputTag>(
"GEMRecHitLabel")),
82 theME0RecHitLabel(par.getParameter<
InputTag>(
"ME0RecHitLabel")),
84 theDynamicTruncationConfig(iC) {
95 string refitDirectionName = par.
getParameter<
string>(
"RefitDirection");
97 if (refitDirectionName ==
"insideOut")
99 else if (refitDirectionName ==
"outsideIn")
103 <<
"Wrong refit direction chosen in TrackTransformer ParameterSet"
105 <<
"Possible choices are:"
107 <<
"RefitDirection = insideOut or RefitDirection = outsideIn";
126 if (theDYTParThrsMode)
130 if (par.
existsAs<
double>(
"RescaleErrorFactor")) {
182 const int theMuonHitsOption,
184 LogTrace(
theCategory) <<
" *** GlobalMuonRefitter *** option " << theMuonHitsOption << endl;
193 if ((*hit)->isValid()) {
195 allRecHitsTemp.push_back((**hit).cloneForFit(*tkbuilder->geometry()->idToDet((**hit).geographicalId())));
196 else if ((*hit)->geographicalId().det() ==
DetId::Muon) {
197 if ((*hit)->geographicalId().subdetId() == 3 && !
theRPCInTheFit) {
204 vector<Trajectory> refitted =
refit(globalTrack,
track, allRecHitsTemp, theMuonHitsOption, tTopo);
214 const int theMuonHitsOption,
222 vector<int> stationHits(4, 0);
223 map<DetId, int> hitMap;
230 LogTrace(
theCategory) <<
" *** GlobalMuonRefitter *** option " << theMuonHitsOption << endl;
238 vector<Trajectory> outputTraj;
240 if ((theMuonHitsOption == 1) || (theMuonHitsOption == 3) || (theMuonHitsOption == 4)) {
242 vector<Trajectory> globalTraj =
transform(globalTrack, track, allRecHits);
244 if (globalTraj.empty()) {
246 return vector<Trajectory>();
250 << globalTraj.front().lastMeasurement().updatedState().freeState()->parameters() << endl;
252 if (theMuonHitsOption == 1)
253 outputTraj.push_back(globalTraj.front());
255 if (theMuonHitsOption == 3) {
259 outputTraj =
transform(globalTrack, track, selectedRecHits);
262 if (theMuonHitsOption == 4) {
278 DYTRecHits = dytRefit.
filter(globalTraj.front());
280 if ((DYTRecHits.size() > 1) &&
281 (DYTRecHits.front()->globalPosition().mag() > DYTRecHits.back()->globalPosition().mag()))
283 outputTraj =
transform(globalTrack, track, DYTRecHits);
286 }
else if (theMuonHitsOption == 2) {
288 outputTraj =
transform(globalTrack, track, fmsRecHits);
291 if (!outputTraj.empty()) {
293 << outputTraj.front().firstMeasurement().updatedState().globalParameters().momentum().perp()
298 return vector<Trajectory>();
307 map<DetId, int>& hitMap)
const {
313 for (ConstRecHitContainer::const_iterator imrh = all.begin(); imrh != all.end(); imrh++) {
314 if ((*imrh !=
nullptr) && !(*imrh)->isValid())
320 DetId id = (*imrh)->geographicalId();
331 if ((*imrh)->dimension() > 1) {
332 std::vector<const TrackingRecHit*> hits2d = (*imrh)->recHits();
333 for (std::vector<const TrackingRecHit*>::const_iterator hit2d = hits2d.begin(); hit2d != hits2d.end();
335 if ((*hit2d)->dimension() > 1) {
336 std::vector<const TrackingRecHit*> hits1d = (*hit2d)->recHits();
337 for (std::vector<const TrackingRecHit*>::const_iterator hit1d = hits1d.begin(); hit1d != hits1d.end();
339 DetId id1 = (*hit1d)->geographicalId();
345 double rhitDistance = fabs(ir->localPosition().x() - (**hit1d).localPosition().x());
346 if (rhitDistance < coneSize)
349 <<
" Distance: " << rhitDistance <<
" recHits: " << layerHits
350 <<
" SL: " << lid.superLayer() << endl;
352 if (layerHits > detRecHits)
353 detRecHits = layerHits;
360 double rhitDistance = fabs(ir->localPosition().x() - (**imrh).localPosition().x());
361 if (rhitDistance < coneSize)
364 <<
" Distance: " << rhitDistance <<
" recHits: " << detRecHits << endl;
376 double rhitDistance = fabs(ir->localPosition().x() - (**imrh).localPosition().x());
377 if (rhitDistance < coneSize)
380 <<
" Distance: " << rhitDistance <<
" recHits: " << detRecHits << endl;
388 if ((*imrh)->recHits().size() > 1) {
389 std::vector<const TrackingRecHit*> hits2d = (*imrh)->recHits();
390 for (std::vector<const TrackingRecHit*>::const_iterator hit2d = hits2d.begin(); hit2d != hits2d.end();
392 DetId id1 = (*hit2d)->geographicalId();
400 double rhitDistance = (ir->localPosition() - (**hit2d).localPosition()).
mag();
401 if (rhitDistance < coneSize)
404 <<
" Distance: " << rhitDistance <<
" recHits: " << layerHits << endl;
406 if (layerHits > detRecHits)
407 detRecHits = layerHits;
414 double rhitDistance = (ir->localPosition() - (**imrh).localPosition()).
mag();
415 if (rhitDistance < coneSize)
418 <<
" Distance: " << rhitDistance <<
" recHits: " << detRecHits << endl;
426 if ((*imrh)->recHits().size() > 1) {
427 std::vector<const TrackingRecHit*> hits2d = (*imrh)->recHits();
428 for (std::vector<const TrackingRecHit*>::const_iterator hit2d = hits2d.begin(); hit2d != hits2d.end();
430 DetId id1 = (*hit2d)->geographicalId();
438 double rhitDistance = (ir->localPosition() - (**hit2d).localPosition()).
mag();
439 if (rhitDistance < coneSize)
442 <<
" Distance: " << rhitDistance <<
" recHits: " << layerHits << endl;
444 if (layerHits > detRecHits)
445 detRecHits = layerHits;
452 double rhitDistance = (ir->localPosition() - (**imrh).localPosition()).
mag();
453 if (rhitDistance < coneSize)
456 <<
" Distance: " << rhitDistance <<
" recHits: " << detRecHits << endl;
464 if ((*imrh)->recHits().size() > 1) {
465 std::vector<const TrackingRecHit*> hits2d = (*imrh)->recHits();
466 for (std::vector<const TrackingRecHit*>::const_iterator hit2d = hits2d.begin(); hit2d != hits2d.end();
468 DetId id1 = (*hit2d)->geographicalId();
476 double rhitDistance = (ir->localPosition() - (**hit2d).localPosition()).
mag();
477 if (rhitDistance < coneSize)
480 <<
" Distance: " << rhitDistance <<
" recHits: " << layerHits << endl;
482 if (layerHits > detRecHits)
483 detRecHits = layerHits;
490 double rhitDistance = (ir->localPosition() - (**imrh).localPosition()).
mag();
491 if (rhitDistance < coneSize)
494 <<
" Distance: " << rhitDistance <<
" recHits: " << detRecHits << endl;
504 map<DetId, int>::iterator imap = hitMap.find(chamberId);
505 if (imap != hitMap.end()) {
506 if (detRecHits > imap->second)
507 imap->second = detRecHits;
509 hitMap[chamberId] = detRecHits;
513 for (map<DetId, int>::iterator imap = hitMap.begin(); imap != hitMap.end(); imap++)
514 LogTrace(
theCategory) <<
" Station " << imap->first.rawId() <<
": " << imap->second << endl;
519 if ((all.size() > 1) && (all.front()->globalPosition().mag() > all.back()->globalPosition().mag())) {
531 LogTrace(
theCategory) <<
" GlobalMuonRefitter::getFirstHits\nall rechits length:" << all.size() << endl;
534 int station_to_keep = 999;
536 for (ConstRecHitContainer::const_iterator ihit = all.begin(); ihit != all.end(); ++ihit) {
539 DetId id = (*ihit)->geographicalId();
540 unsigned raw_id =
id.
rawId();
541 if (!(*ihit)->isValid())
545 switch (
id.subdetId()) {
550 station =
CSCDetId(raw_id).station();
559 station =
RPCDetId(raw_id).station();
566 if (use_it && station > 0 && station < station_to_keep)
568 stations.push_back(station);
569 LogTrace(
theCategory) <<
"rawId: " << raw_id <<
" station = " << station <<
" station_to_keep is now "
573 if (station_to_keep <= 0 || station_to_keep > 4 || stations.size() != all.size())
574 LogInfo(
theCategory) <<
"failed to getFirstHits (all muon hits are outliers/bad ?)! station_to_keep = "
575 << station_to_keep <<
" stations.size " << stations.size() <<
" all.size " << all.size();
577 for (
unsigned i = 0;
i < stations.size(); ++
i)
578 if (stations[
i] >= 0 && stations[
i] <= station_to_keep)
579 first.push_back(all[
i]);
589 const map<DetId, int>& hitMap)
const {
591 const double globalChi2Cut = 200.0;
593 vector<TrajectoryMeasurement> muonMeasurements = traj.
measurements();
596 for (std::vector<TrajectoryMeasurement>::const_iterator im = muonMeasurements.begin(); im != muonMeasurements.end();
598 if (!(*im).recHit()->isValid())
600 if ((*im).recHit()->det()->geographicalId().det() !=
DetId::Muon) {
602 muonRecHits.push_back((*im).recHit());
610 double chi2Cut = 0.0;
613 if ((*immrh).isDT()) {
620 else if ((*immrh).isCSC()) {
627 else if ((*immrh).isGEM()) {
634 else if ((*immrh).isME0()) {
641 else if ((*immrh).isRPC()) {
649 double chi2ndf = (*im).estimate() / (*im).recHit()->dimension();
652 map<DetId, int>::const_iterator imap = hitMap.find(chamberId);
653 if (imap != hitMap.end())
654 if (imap->second > threshold)
657 if ((keep || (chi2ndf < chi2Cut)) && (chi2ndf < globalChi2Cut)) {
658 muonRecHits.push_back((*im).recHit());
660 LogTrace(
theCategory) <<
"Skip hit: " <<
id.rawId() <<
" chi2=" << chi2ndf <<
" ( threshold: " << chi2Cut
661 <<
") Det: " << imap->second << endl;
666 reverse(muonRecHits.begin(), muonRecHits.end());
675 for (ConstRecHitContainer::const_iterator ir = hits.begin(); ir != hits.end(); ir++) {
676 if (!(*ir)->isValid()) {
684 <<
" dimension = " << (*ir)->dimension()
685 <<
" det = " << (*ir)->det()->geographicalId().det()
686 <<
" subdet = " << (*ir)->det()->subDetector()
687 <<
" raw id = " << (*ir)->det()->geographicalId().rawId();
696 if (!recHits.empty()) {
697 ConstRecHitContainer::const_iterator frontHit = recHits.begin();
698 ConstRecHitContainer::const_iterator backHit = recHits.end() - 1;
699 while (!(*frontHit)->isValid() && frontHit != backHit) {
702 while (!(*backHit)->isValid() && backHit != frontHit) {
706 double rFirst = (*frontHit)->globalPosition().mag();
707 double rLast = (*backHit)->globalPosition().mag();
711 else if (rFirst > rLast)
731 LogTrace(
theCategory) <<
"GlobalMuonRefitter::transform: " << recHitsForReFit.size() <<
" hits:";
734 if (recHitsForReFit.size() < 2)
735 return vector<Trajectory>();
740 LogTrace(
theCategory) <<
"checkRecHitsOrdering() returned " << recHitsOrder <<
", theRefitDirection is "
745 reverse(recHitsForReFit.begin(), recHitsForReFit.end());
752 unsigned int innerId;
764 inner_is_first =
true;
770 inner_is_first =
false;
773 LogTrace(
theCategory) <<
"firstTSOS: inner_is_first? " << inner_is_first <<
" globalPosition is "
774 << firstTSOS.globalPosition() <<
" innerId is " << innerId;
776 if (!firstTSOS.isValid()) {
778 return vector<Trajectory>();
803 (firstTSOS.globalPosition().basicVector().dot(firstTSOS.globalMomentum().basicVector()) > 0)
807 (lastTSOS.globalPosition().basicVector().dot(lastTSOS.globalMomentum().basicVector()) > 0) ?
alongMomentum
809 LogTrace(
theCategory) <<
"propDir_first " << propDir_first <<
", propdir_last " << propDir_last <<
" : they "
810 << (propDir_first == propDir_last ?
"agree" :
"disagree");
813 for (TransientTrackingRecHit::ConstRecHitContainer::const_iterator it = recHitsForReFit.begin();
814 it != recHitsForReFit.end();
816 if ((*it)->globalPosition().y() > 0)
835 LogTrace(
theCategory) <<
"y_count = " << y_count <<
"; based on geometrically-outermost TSOS, propDir is "
836 << propDir <<
": " << (propDir == propDir_ycount ?
"agrees" :
"disagrees")
837 <<
" with ycount determination";
839 if (propDir_first != propDir_last) {
841 propDir = propDir_ycount;
847 if (recHitsForReFit.front()->geographicalId() !=
DetId(innerId)) {
850 <<
" to first rechit with surface pos "
851 << recHitsForReFit.front()->det()->surface().toGlobal(
LocalPoint(0, 0, 0));
854 if (!firstTSOS.isValid()) {
856 return vector<Trajectory>();
862 <<
" p=" << firstTSOS.globalMomentum() <<
" = " << firstTSOS.globalMomentum().mag() << endl;
872 if (trajectories.empty()) {
874 return vector<Trajectory>();
885 ConstRecHitContainer::const_iterator it = hits.begin();
886 for (; it != hits.end(); it++) {
887 DetId id = (*it)->geographicalId();
949 results.push_back(*it);
DynamicTruncation::Config theDynamicTruncationConfig
double p() const
momentum vector magnitude
EDGetTokenT< ProductType > consumes(edm::InputTag const &tag)
void printHits(const ConstRecHitContainer &) const
print all RecHits of a trajectory
T getUntrackedParameter(std::string const &, T const &) const
edm::Handle< DTRecHitCollection > theDTRecHits
void setProd(const edm::Handle< DTRecSegment4DCollection > &DTSegProd, const edm::Handle< CSCSegmentCollection > &CSCSegProd)
edm::ESGetToken< TransientTrackingRecHitBuilder, TransientRecHitRecord > theMuonRecHitBuilderToken
std::pair< const_iterator, const_iterator > range
iterator range
Point3DBase< Scalar, LocalTag > LocalPoint
bool existsAs(std::string const ¶meterName, bool trackiness=true) const
checks if a parameter exists as a given type
const MuonServiceProxy * theService
unsigned int tibLayer(const DetId &id) const
RefitDirection theRefitDirection
edm::Handle< CSCSegmentCollection > CSCSegments
ME0DetId chamberId() const
Return the corresponding ChamberId (mask layers)
std::string thePropagatorName
LocalPoint position() const
Local x and y position coordinates.
T mag() const
The vector magnitude. Equivalent to sqrt(vec.mag2())
unsigned int pxfDisk(const DetId &id) const
constexpr uint32_t rawId() const
get the raw id
edm::Handle< GEMRecHitCollection > theGEMRecHits
GlobalPoint globalPosition() const
void setServices(const edm::EventSetup &)
set the services needed by the TrackTransformer
unsigned int tidWheel(const DetId &id) const
void CopyFrom(const DYTInfo &)
copy from another DYTInfo
TransientTrackingRecHit::ConstRecHitContainer ConstRecHitContainer
edm::EDGetTokenT< CSCSegmentCollection > CSCSegmentsToken
Log< level::Error, false > LogError
std::unique_ptr< TrajectoryFitter > theFitter
edm::Handle< ME0SegmentCollection > theME0RecHits
void checkMuonHits(const reco::Track &, ConstRecHitContainer &, std::map< DetId, int > &) const
check muon RecHits, calculate chamber occupancy and select hits to be used in the final fit ...
TrajectoryStateOnSurface innermostMeasurementState() const
constexpr std::array< uint8_t, layerIndexSize > layer
std::vector< int > theDYTthrs
void getFirstHits(const reco::Track &, ConstRecHitContainer &, ConstRecHitContainer &) const
get the RecHits in the tracker and the first muon chamber with hits
bool getData(T &iHolder) const
edm::ESGetToken< TransientTrackingRecHitBuilder, TransientRecHitRecord > theTrackerRecHitBuilderToken
void setRecoEta(double eta)
C::const_iterator const_iterator
constant access iterator type
DataContainer const & measurements() const
double eta() const
pseudorapidity of momentum vector
edm::Handle< DTRecSegment4DCollection > all4DSegments
const TransientTrackingRecHitBuilder * theMuonRecHitBuilder
ConstRecHitContainer selectMuonHits(const Trajectory &, const std::map< DetId, int > &) const
select muon hits compatible with trajectory; check hits in chambers with showers
ConstRecHitContainer getRidOfSelectStationHits(const ConstRecHitContainer &hits, const TrackerTopology *tTopo) const
double theRescaleErrorFactor
const TransientTrackingRecHitBuilder * theTrackerRecHitBuilder
virtual RecHitPointer build(const TrackingRecHit *p) const =0
build a tracking rechit from an existing rechit
double pt() const
track transverse momentum
MuonTransientTrackingRecHit::MuonRecHitContainer MuonRecHitContainer
unsigned int outerDetId() const
DetId of the detector on which surface the outermost state is located.
edm::EDGetTokenT< ME0SegmentCollection > theME0RecHitToken
CSCDetId chamberId() const
edm::ParameterSet theDYTthrsParameters
edm::Handle< CSCRecHit2DCollection > theCSCRecHits
constexpr GEMDetId chamberId() const
int theTrackerSkipSection
RefitDirection checkRecHitsOrdering(const ConstRecHitContainer &) const
LocalVector momentum() const
Momentum vector in the local frame.
edm::EDGetTokenT< DTRecHitCollection > theDTRecHitToken
edm::EDGetTokenT< CSCRecHit2DCollection > theCSCRecHitToken
TrajectoryStateOnSurface outermostMeasurementState() const
TransientTrackingRecHit::ConstRecHitContainer filter(const Trajectory &)
edm::InputTag theDTRecHitLabel
std::vector< ConstRecHitPointer > ConstRecHitContainer
const edm::EventSetup * theEventSetup
unsigned int pxbLayer(const DetId &id) const
edm::InputTag theGEMRecHitLabel
Log< level::Info, false > LogInfo
virtual void setEvent(const edm::Event &)
pass the Event to the algo at each event
void setThrsMap(const edm::ParameterSet &)
void setParThrsMode(bool dytParThrsMode)
edm::ESGetToken< TrajectoryFitter, TrajectoryFitterRecord > theFitterToken
edm::InputTag theME0RecHitLabel
PTrajectoryStateOnDet const & startingState() const
GlobalMuonRefitter(const edm::ParameterSet &, const MuonServiceProxy *, edm::ConsumesCollector &)
constructor with Parameter Set and MuonServiceProxy
edm::EDGetTokenT< DTRecSegment4DCollection > all4DSegmentsToken
T getParameter(std::string const &) const
constexpr int station() const
reco::DYTInfo getDYTInfo()
unsigned int nHits() const
GlobalVector globalMomentum() const
virtual ~GlobalMuonRefitter()
destructor
DetId geographicalId() const
Log< level::Warning, false > LogWarning
unsigned long long theCacheId_TRH
int station() const
Return the station number.
const BasicVectorType & basicVector() const
unsigned int tecWheel(const DetId &id) const
unsigned int innerDetId() const
DetId of the detector on which surface the innermost state is located.
void setThr(const std::vector< int > &)
std::vector< Trajectory > refit(const reco::Track &globalTrack, const int theMuonHitsOption, const TrackerTopology *tTopo) const
build combined trajectory from sta Track and tracker RecHits
const LocalTrajectoryParameters & parameters() const
void setUpdateState(bool)
unsigned int tobLayer(const DetId &id) const
edm::InputTag theCSCRecHitLabel
edm::EDGetTokenT< GEMRecHitCollection > theGEMRecHitToken
std::vector< Trajectory > transform(const reco::Track &newTrack, const reco::TransientTrack track, const TransientTrackingRecHit::ConstRecHitContainer &recHitsForReFit) const
refit the track with a new set of RecHits
T dot(const Basic3DVector &rh) const
Scalar product, or "dot" product, with a vector of same type.