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";
130 if (par.
existsAs<
double>(
"RescaleErrorFactor")) {
182 const int theMuonHitsOption,
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) {
214 const int theMuonHitsOption,
222 vector<int> stationHits(4, 0);
223 map<DetId, int> hitMap;
238 vector<Trajectory> outputTraj;
244 if (globalTraj.empty()) {
246 return vector<Trajectory>();
250 << globalTraj.front().lastMeasurement().updatedState().freeState()->parameters() << endl;
253 outputTraj.push_back(globalTraj.front());
278 DYTRecHits = dytRefit.
filter(globalTraj.front());
280 if ((DYTRecHits.size() > 1) &&
281 (DYTRecHits.front()->globalPosition().mag() > DYTRecHits.back()->globalPosition().mag()))
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());
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());
364 <<
" Distance: " << rhitDistance <<
" recHits: " << detRecHits << endl;
376 double rhitDistance = fabs(ir->localPosition().x() - (**imrh).localPosition().x());
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();
404 <<
" Distance: " << rhitDistance <<
" recHits: " << layerHits << endl;
406 if (layerHits > detRecHits)
407 detRecHits = layerHits;
414 double rhitDistance = (ir->localPosition() - (**imrh).localPosition()).
mag();
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();
442 <<
" Distance: " << rhitDistance <<
" recHits: " << layerHits << endl;
444 if (layerHits > detRecHits)
445 detRecHits = layerHits;
452 double rhitDistance = (ir->localPosition() - (**imrh).localPosition()).
mag();
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();
480 <<
" Distance: " << rhitDistance <<
" recHits: " << layerHits << endl;
482 if (layerHits > detRecHits)
483 detRecHits = layerHits;
490 double rhitDistance = (ir->localPosition() - (**imrh).localPosition()).
mag();
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())) {
534 int station_to_keep = 999;
535 vector<int> stations;
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()) {
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)
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());
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())
657 if ((
keep || (chi2ndf <
chi2Cut)) && (chi2ndf < globalChi2Cut)) {
658 muonRecHits.push_back((*im).recHit());
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();
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;
753 bool order_swapped =
track.outermostMeasurementState().globalPosition().mag() <
754 track.innermostMeasurementState().globalPosition().mag();
762 firstTSOS =
track.innermostMeasurementState();
763 lastTSOS =
track.outermostMeasurementState();
764 inner_is_first =
true;
768 firstTSOS =
track.outermostMeasurementState();
769 lastTSOS =
track.innermostMeasurementState();
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;
865 <<
" nHits= " <<
seed.nHits() <<
" tsos: " <<
seed.startingState().parameters().position()
866 <<
" p=" <<
seed.startingState().parameters().momentum() << endl;
874 return vector<Trajectory>();
885 ConstRecHitContainer::const_iterator it =
hits.begin();
886 for (; it !=
hits.end(); it++) {
887 DetId id = (*it)->geographicalId();
DynamicTruncation::Config theDynamicTruncationConfig
EDGetTokenT< ProductType > consumes(edm::InputTag const &tag)
int station() const
Return the station number.
edm::Handle< DTRecHitCollection > theDTRecHits
constexpr int station() const
T getParameter(std::string const &) const
unsigned int tobLayer(const DetId &id) const
unsigned int pxbLayer(const DetId &id) const
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
const MuonServiceProxy * theService
RefitDirection theRefitDirection
edm::Handle< CSCSegmentCollection > CSCSegments
std::string thePropagatorName
unsigned int tidWheel(const DetId &id) const
unsigned int tecWheel(const DetId &id) const
edm::Handle< GEMRecHitCollection > theGEMRecHits
void setServices(const edm::EventSetup &)
set the services needed by the TrackTransformer
void CopyFrom(const DYTInfo &)
copy from another DYTInfo
bool existsAs(std::string const ¶meterName, bool trackiness=true) const
checks if a parameter exists as a given type
TransientTrackingRecHit::ConstRecHitContainer ConstRecHitContainer
edm::EDGetTokenT< CSCSegmentCollection > CSCSegmentsToken
Log< level::Error, false > LogError
void printHits(const ConstRecHitContainer &) const
print all RecHits of a trajectory
std::unique_ptr< TrajectoryFitter > theFitter
edm::Handle< ME0SegmentCollection > theME0RecHits
std::vector< int > theDYTthrs
DataContainer const & measurements() const
T getUntrackedParameter(std::string const &, T const &) const
edm::ESGetToken< TransientTrackingRecHitBuilder, TransientRecHitRecord > theTrackerRecHitBuilderToken
void setRecoEta(double eta)
C::const_iterator const_iterator
constant access iterator type
ME0DetId chamberId() const
Return the corresponding ChamberId (mask layers)
GlobalPoint globalPosition() const
edm::Handle< DTRecSegment4DCollection > all4DSegments
const TransientTrackingRecHitBuilder * theMuonRecHitBuilder
double theRescaleErrorFactor
const TransientTrackingRecHitBuilder * theTrackerRecHitBuilder
virtual RecHitPointer build(const TrackingRecHit *p) const =0
build a tracking rechit from an existing rechit
ConstRecHitContainer selectMuonHits(const Trajectory &, const std::map< DetId, int > &) const
select muon hits compatible with trajectory; check hits in chambers with showers
MuonTransientTrackingRecHit::MuonRecHitContainer MuonRecHitContainer
unsigned int pxfDisk(const DetId &id) const
edm::EDGetTokenT< ME0SegmentCollection > theME0RecHitToken
edm::ParameterSet theDYTthrsParameters
edm::Handle< CSCRecHit2DCollection > theCSCRecHits
int theTrackerSkipSection
edm::EDGetTokenT< DTRecHitCollection > theDTRecHitToken
edm::EDGetTokenT< CSCRecHit2DCollection > theCSCRecHitToken
unsigned int innerDetId() const
DetId of the detector on which surface the innermost state is located.
TransientTrackingRecHit::ConstRecHitContainer filter(const Trajectory &)
const BasicVectorType & basicVector() const
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
edm::InputTag theDTRecHitLabel
std::vector< ConstRecHitPointer > ConstRecHitContainer
const edm::EventSetup * theEventSetup
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)
RefitDirection checkRecHitsOrdering(const ConstRecHitContainer &) const
edm::ESGetToken< TrajectoryFitter, TrajectoryFitterRecord > theFitterToken
edm::InputTag theME0RecHitLabel
T mag() const
The vector magnitude. Equivalent to sqrt(vec.mag2())
GlobalMuonRefitter(const edm::ParameterSet &, const MuonServiceProxy *, edm::ConsumesCollector &)
constructor with Parameter Set and MuonServiceProxy
edm::EDGetTokenT< DTRecSegment4DCollection > all4DSegmentsToken
DetId geographicalId() const
constexpr uint32_t rawId() const
get the raw id
CSCDetId chamberId() const
ConstRecHitContainer getRidOfSelectStationHits(const ConstRecHitContainer &hits, const TrackerTopology *tTopo) const
unsigned int outerDetId() const
DetId of the detector on which surface the outermost state is located.
GlobalVector globalMomentum() const
reco::DYTInfo getDYTInfo()
void getFirstHits(const reco::Track &, ConstRecHitContainer &, ConstRecHitContainer &) const
get the RecHits in the tracker and the first muon chamber with hits
std::vector< Trajectory > refit(const reco::Track &globalTrack, const int theMuonHitsOption, const TrackerTopology *tTopo) const
build combined trajectory from sta Track and tracker RecHits
constexpr GEMDetId chamberId() const
virtual ~GlobalMuonRefitter()
destructor
unsigned int tibLayer(const DetId &id) const
Log< level::Warning, false > LogWarning
unsigned long long theCacheId_TRH
T dot(const Basic3DVector &rh) const
Scalar product, or "dot" product, with a vector of same type.
void setThr(const std::vector< int > &)
void setUpdateState(bool)
edm::InputTag theCSCRecHitLabel
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 ...
edm::EDGetTokenT< GEMRecHitCollection > theGEMRecHitToken