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")),
94 string refitDirectionName = par.
getParameter<
string>(
"RefitDirection");
96 if (refitDirectionName ==
"insideOut")
98 else if (refitDirectionName ==
"outsideIn")
102 <<
"Wrong refit direction chosen in TrackTransformer ParameterSet"
104 <<
"Possible choices are:"
106 <<
"RefitDirection = insideOut or RefitDirection = outsideIn";
129 if (par.
existsAs<
double>(
"RescaleErrorFactor")) {
183 const int theMuonHitsOption,
194 if ((*hit)->isValid()) {
196 allRecHitsTemp.push_back((**hit).cloneForFit(*tkbuilder->geometry()->idToDet((**hit).geographicalId())));
197 else if ((*hit)->geographicalId().det() ==
DetId::Muon) {
198 if ((*hit)->geographicalId().subdetId() == 3 && !
theRPCInTheFit) {
215 const int theMuonHitsOption,
223 vector<int> stationHits(4, 0);
224 map<DetId, int> hitMap;
239 vector<Trajectory> outputTraj;
245 if (globalTraj.empty()) {
247 return vector<Trajectory>();
251 << globalTraj.front().lastMeasurement().updatedState().freeState()->parameters() << endl;
254 outputTraj.push_back(globalTraj.front());
279 DYTRecHits = dytRefit.
filter(globalTraj.front());
281 if ((DYTRecHits.size() > 1) &&
282 (DYTRecHits.front()->globalPosition().mag() > DYTRecHits.back()->globalPosition().mag()))
292 if (!outputTraj.empty()) {
294 << outputTraj.front().firstMeasurement().updatedState().globalParameters().momentum().perp()
299 return vector<Trajectory>();
308 map<DetId, int>& hitMap)
const {
314 for (ConstRecHitContainer::const_iterator imrh =
all.begin(); imrh !=
all.end(); imrh++) {
315 if ((*imrh !=
nullptr) && !(*imrh)->isValid())
321 DetId id = (*imrh)->geographicalId();
332 if ((*imrh)->dimension() > 1) {
333 std::vector<const TrackingRecHit*> hits2d = (*imrh)->recHits();
334 for (std::vector<const TrackingRecHit*>::const_iterator hit2d = hits2d.begin(); hit2d != hits2d.end();
336 if ((*hit2d)->dimension() > 1) {
337 std::vector<const TrackingRecHit*> hits1d = (*hit2d)->recHits();
338 for (std::vector<const TrackingRecHit*>::const_iterator hit1d = hits1d.begin(); hit1d != hits1d.end();
340 DetId id1 = (*hit1d)->geographicalId();
346 double rhitDistance = fabs(ir->localPosition().x() - (**hit1d).localPosition().x());
350 <<
" Distance: " << rhitDistance <<
" recHits: " << layerHits
351 <<
" SL: " << lid.superLayer() << endl;
353 if (layerHits > detRecHits)
354 detRecHits = layerHits;
361 double rhitDistance = fabs(ir->localPosition().x() - (**imrh).localPosition().x());
365 <<
" Distance: " << rhitDistance <<
" recHits: " << detRecHits << endl;
377 double rhitDistance = fabs(ir->localPosition().x() - (**imrh).localPosition().x());
381 <<
" Distance: " << rhitDistance <<
" recHits: " << detRecHits << endl;
389 if ((*imrh)->recHits().size() > 1) {
390 std::vector<const TrackingRecHit*> hits2d = (*imrh)->recHits();
391 for (std::vector<const TrackingRecHit*>::const_iterator hit2d = hits2d.begin(); hit2d != hits2d.end();
393 DetId id1 = (*hit2d)->geographicalId();
401 double rhitDistance = (ir->localPosition() - (**hit2d).localPosition()).
mag();
405 <<
" Distance: " << rhitDistance <<
" recHits: " << layerHits << endl;
407 if (layerHits > detRecHits)
408 detRecHits = layerHits;
415 double rhitDistance = (ir->localPosition() - (**imrh).localPosition()).
mag();
419 <<
" Distance: " << rhitDistance <<
" recHits: " << detRecHits << endl;
427 if ((*imrh)->recHits().size() > 1) {
428 std::vector<const TrackingRecHit*> hits2d = (*imrh)->recHits();
429 for (std::vector<const TrackingRecHit*>::const_iterator hit2d = hits2d.begin(); hit2d != hits2d.end();
431 DetId id1 = (*hit2d)->geographicalId();
439 double rhitDistance = (ir->localPosition() - (**hit2d).localPosition()).
mag();
443 <<
" Distance: " << rhitDistance <<
" recHits: " << layerHits << endl;
445 if (layerHits > detRecHits)
446 detRecHits = layerHits;
453 double rhitDistance = (ir->localPosition() - (**imrh).localPosition()).
mag();
457 <<
" Distance: " << rhitDistance <<
" recHits: " << detRecHits << endl;
465 if ((*imrh)->recHits().size() > 1) {
466 std::vector<const TrackingRecHit*> hits2d = (*imrh)->recHits();
467 for (std::vector<const TrackingRecHit*>::const_iterator hit2d = hits2d.begin(); hit2d != hits2d.end();
469 DetId id1 = (*hit2d)->geographicalId();
477 double rhitDistance = (ir->localPosition() - (**hit2d).localPosition()).
mag();
481 <<
" Distance: " << rhitDistance <<
" recHits: " << layerHits << endl;
483 if (layerHits > detRecHits)
484 detRecHits = layerHits;
491 double rhitDistance = (ir->localPosition() - (**imrh).localPosition()).
mag();
495 <<
" Distance: " << rhitDistance <<
" recHits: " << detRecHits << endl;
505 map<DetId, int>::iterator imap = hitMap.find(chamberId);
506 if (imap != hitMap.end()) {
507 if (detRecHits > imap->second)
508 imap->second = detRecHits;
510 hitMap[chamberId] = detRecHits;
514 for (map<DetId, int>::iterator imap = hitMap.begin(); imap != hitMap.end(); imap++)
515 LogTrace(
theCategory) <<
" Station " << imap->first.rawId() <<
": " << imap->second << endl;
520 if ((
all.size() > 1) && (
all.front()->globalPosition().mag() >
all.back()->globalPosition().mag())) {
535 int station_to_keep = 999;
536 vector<int> stations;
537 for (ConstRecHitContainer::const_iterator ihit =
all.begin(); ihit !=
all.end(); ++ihit) {
540 DetId id = (*ihit)->geographicalId();
541 unsigned raw_id =
id.
rawId();
542 if (!(*ihit)->isValid())
546 switch (
id.subdetId()) {
574 if (station_to_keep <= 0 || station_to_keep > 4 || stations.size() !=
all.size())
575 LogInfo(
theCategory) <<
"failed to getFirstHits (all muon hits are outliers/bad ?)! station_to_keep = "
576 << station_to_keep <<
" stations.size " << stations.size() <<
" all.size " <<
all.size();
578 for (
unsigned i = 0;
i < stations.size(); ++
i)
579 if (stations[
i] >= 0 && stations[
i] <= station_to_keep)
590 const map<DetId, int>& hitMap)
const {
592 const double globalChi2Cut = 200.0;
594 vector<TrajectoryMeasurement> muonMeasurements = traj.
measurements();
597 for (std::vector<TrajectoryMeasurement>::const_iterator im = muonMeasurements.begin(); im != muonMeasurements.end();
599 if (!(*im).recHit()->isValid())
601 if ((*im).recHit()->det()->geographicalId().det() !=
DetId::Muon) {
603 muonRecHits.push_back((*im).recHit());
614 if ((*immrh).isDT()) {
621 else if ((*immrh).isCSC()) {
628 else if ((*immrh).isGEM()) {
635 else if ((*immrh).isME0()) {
642 else if ((*immrh).isRPC()) {
650 double chi2ndf = (*im).estimate() / (*im).recHit()->dimension();
653 map<DetId, int>::const_iterator imap = hitMap.find(chamberId);
654 if (imap != hitMap.end())
658 if ((
keep || (chi2ndf <
chi2Cut)) && (chi2ndf < globalChi2Cut)) {
659 muonRecHits.push_back((*im).recHit());
662 <<
") Det: " << imap->second << endl;
667 reverse(muonRecHits.begin(), muonRecHits.end());
676 for (ConstRecHitContainer::const_iterator ir =
hits.begin(); ir !=
hits.end(); ir++) {
677 if (!(*ir)->isValid()) {
685 <<
" dimension = " << (*ir)->dimension()
686 <<
" det = " << (*ir)->det()->geographicalId().det()
687 <<
" subdet = " << (*ir)->det()->subDetector()
688 <<
" raw id = " << (*ir)->det()->geographicalId().rawId();
698 ConstRecHitContainer::const_iterator frontHit =
recHits.begin();
699 ConstRecHitContainer::const_iterator backHit =
recHits.end() - 1;
700 while (!(*frontHit)->isValid() && frontHit != backHit) {
703 while (!(*backHit)->isValid() && backHit != frontHit) {
707 double rFirst = (*frontHit)->globalPosition().mag();
708 double rLast = (*backHit)->globalPosition().mag();
712 else if (rFirst > rLast)
732 LogTrace(
theCategory) <<
"GlobalMuonRefitter::transform: " << recHitsForReFit.size() <<
" hits:";
735 if (recHitsForReFit.size() < 2)
736 return vector<Trajectory>();
741 LogTrace(
theCategory) <<
"checkRecHitsOrdering() returned " << recHitsOrder <<
", theRefitDirection is "
746 reverse(recHitsForReFit.begin(), recHitsForReFit.end());
753 unsigned int innerId;
754 bool order_swapped =
track.outermostMeasurementState().globalPosition().mag() <
755 track.innermostMeasurementState().globalPosition().mag();
763 firstTSOS =
track.innermostMeasurementState();
764 lastTSOS =
track.outermostMeasurementState();
765 inner_is_first =
true;
769 firstTSOS =
track.outermostMeasurementState();
770 lastTSOS =
track.innermostMeasurementState();
771 inner_is_first =
false;
774 LogTrace(
theCategory) <<
"firstTSOS: inner_is_first? " << inner_is_first <<
" globalPosition is "
775 << firstTSOS.globalPosition() <<
" innerId is " << innerId;
777 if (!firstTSOS.isValid()) {
779 return vector<Trajectory>();
804 (firstTSOS.globalPosition().basicVector().dot(firstTSOS.globalMomentum().basicVector()) > 0)
808 (lastTSOS.globalPosition().basicVector().dot(lastTSOS.globalMomentum().basicVector()) > 0) ?
alongMomentum
810 LogTrace(
theCategory) <<
"propDir_first " << propDir_first <<
", propdir_last " << propDir_last <<
" : they "
811 << (propDir_first == propDir_last ?
"agree" :
"disagree");
814 for (TransientTrackingRecHit::ConstRecHitContainer::const_iterator it = recHitsForReFit.begin();
815 it != recHitsForReFit.end();
817 if ((*it)->globalPosition().y() > 0)
836 LogTrace(
theCategory) <<
"y_count = " << y_count <<
"; based on geometrically-outermost TSOS, propDir is "
837 << propDir <<
": " << (propDir == propDir_ycount ?
"agrees" :
"disagrees")
838 <<
" with ycount determination";
840 if (propDir_first != propDir_last) {
842 propDir = propDir_ycount;
848 if (recHitsForReFit.front()->geographicalId() !=
DetId(innerId)) {
851 <<
" to first rechit with surface pos "
852 << recHitsForReFit.front()->det()->surface().toGlobal(
LocalPoint(0, 0, 0));
855 if (!firstTSOS.isValid()) {
857 return vector<Trajectory>();
863 <<
" p=" << firstTSOS.globalMomentum() <<
" = " << firstTSOS.globalMomentum().mag() << endl;
866 <<
" nHits= " <<
seed.nHits() <<
" tsos: " <<
seed.startingState().parameters().position()
867 <<
" p=" <<
seed.startingState().parameters().momentum() << endl;
875 return vector<Trajectory>();
886 ConstRecHitContainer::const_iterator it =
hits.begin();
887 for (; it !=
hits.end(); it++) {
888 DetId id = (*it)->geographicalId();