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")) {
181 const int theMuonHitsOption,
192 if ((*hit)->isValid()) {
194 allRecHitsTemp.push_back((**hit).cloneForFit(*tkbuilder->geometry()->idToDet((**hit).geographicalId())));
195 else if ((*hit)->geographicalId().det() ==
DetId::Muon) {
196 if ((*hit)->geographicalId().subdetId() == 3 && !
theRPCInTheFit) {
213 const int theMuonHitsOption,
221 vector<int> stationHits(4, 0);
222 map<DetId, int> hitMap;
237 vector<Trajectory> outputTraj;
243 if (globalTraj.empty()) {
245 return vector<Trajectory>();
249 << globalTraj.front().lastMeasurement().updatedState().freeState()->parameters() << endl;
252 outputTraj.push_back(globalTraj.front());
277 DYTRecHits = dytRefit.
filter(globalTraj.front());
279 if ((DYTRecHits.size() > 1) &&
280 (DYTRecHits.front()->globalPosition().mag() > DYTRecHits.back()->globalPosition().mag()))
290 if (!outputTraj.empty()) {
292 << outputTraj.front().firstMeasurement().updatedState().globalParameters().momentum().perp()
297 return vector<Trajectory>();
306 map<DetId, int>& hitMap)
const {
312 for (ConstRecHitContainer::const_iterator imrh =
all.begin(); imrh !=
all.end(); imrh++) {
313 if ((*imrh !=
nullptr) && !(*imrh)->isValid())
319 DetId id = (*imrh)->geographicalId();
330 if ((*imrh)->dimension() > 1) {
331 std::vector<const TrackingRecHit*> hits2d = (*imrh)->recHits();
332 for (std::vector<const TrackingRecHit*>::const_iterator hit2d = hits2d.begin(); hit2d != hits2d.end();
334 if ((*hit2d)->dimension() > 1) {
335 std::vector<const TrackingRecHit*> hits1d = (*hit2d)->recHits();
336 for (std::vector<const TrackingRecHit*>::const_iterator hit1d = hits1d.begin(); hit1d != hits1d.end();
338 DetId id1 = (*hit1d)->geographicalId();
344 double rhitDistance = fabs(ir->localPosition().x() - (**hit1d).localPosition().x());
348 <<
" Distance: " << rhitDistance <<
" recHits: " << layerHits
349 <<
" SL: " << lid.superLayer() << endl;
351 if (layerHits > detRecHits)
352 detRecHits = layerHits;
359 double rhitDistance = fabs(ir->localPosition().x() - (**imrh).localPosition().x());
363 <<
" Distance: " << rhitDistance <<
" recHits: " << detRecHits << endl;
375 double rhitDistance = fabs(ir->localPosition().x() - (**imrh).localPosition().x());
379 <<
" Distance: " << rhitDistance <<
" recHits: " << detRecHits << endl;
387 if ((*imrh)->recHits().size() > 1) {
388 std::vector<const TrackingRecHit*> hits2d = (*imrh)->recHits();
389 for (std::vector<const TrackingRecHit*>::const_iterator hit2d = hits2d.begin(); hit2d != hits2d.end();
391 DetId id1 = (*hit2d)->geographicalId();
399 double rhitDistance = (ir->localPosition() - (**hit2d).localPosition()).
mag();
403 <<
" Distance: " << rhitDistance <<
" recHits: " << layerHits << endl;
405 if (layerHits > detRecHits)
406 detRecHits = layerHits;
413 double rhitDistance = (ir->localPosition() - (**imrh).localPosition()).
mag();
417 <<
" Distance: " << rhitDistance <<
" recHits: " << detRecHits << endl;
425 if ((*imrh)->recHits().size() > 1) {
426 std::vector<const TrackingRecHit*> hits2d = (*imrh)->recHits();
427 for (std::vector<const TrackingRecHit*>::const_iterator hit2d = hits2d.begin(); hit2d != hits2d.end();
429 DetId id1 = (*hit2d)->geographicalId();
437 double rhitDistance = (ir->localPosition() - (**hit2d).localPosition()).
mag();
441 <<
" Distance: " << rhitDistance <<
" recHits: " << layerHits << endl;
443 if (layerHits > detRecHits)
444 detRecHits = layerHits;
451 double rhitDistance = (ir->localPosition() - (**imrh).localPosition()).
mag();
455 <<
" Distance: " << rhitDistance <<
" recHits: " << detRecHits << endl;
463 if ((*imrh)->recHits().size() > 1) {
464 std::vector<const TrackingRecHit*> hits2d = (*imrh)->recHits();
465 for (std::vector<const TrackingRecHit*>::const_iterator hit2d = hits2d.begin(); hit2d != hits2d.end();
467 DetId id1 = (*hit2d)->geographicalId();
475 double rhitDistance = (ir->localPosition() - (**hit2d).localPosition()).
mag();
479 <<
" Distance: " << rhitDistance <<
" recHits: " << layerHits << endl;
481 if (layerHits > detRecHits)
482 detRecHits = layerHits;
489 double rhitDistance = (ir->localPosition() - (**imrh).localPosition()).
mag();
493 <<
" Distance: " << rhitDistance <<
" recHits: " << detRecHits << endl;
503 map<DetId, int>::iterator imap = hitMap.find(chamberId);
504 if (imap != hitMap.end()) {
505 if (detRecHits > imap->second)
506 imap->second = detRecHits;
508 hitMap[chamberId] = detRecHits;
512 for (map<DetId, int>::iterator imap = hitMap.begin(); imap != hitMap.end(); imap++)
513 LogTrace(
theCategory) <<
" Station " << imap->first.rawId() <<
": " << imap->second << endl;
518 if ((
all.size() > 1) && (
all.front()->globalPosition().mag() >
all.back()->globalPosition().mag())) {
533 int station_to_keep = 999;
534 vector<int> stations;
535 for (ConstRecHitContainer::const_iterator ihit =
all.begin(); ihit !=
all.end(); ++ihit) {
538 DetId id = (*ihit)->geographicalId();
539 unsigned raw_id =
id.
rawId();
540 if (!(*ihit)->isValid())
544 switch (
id.subdetId()) {
572 if (station_to_keep <= 0 || station_to_keep > 4 || stations.size() !=
all.size())
573 LogInfo(
theCategory) <<
"failed to getFirstHits (all muon hits are outliers/bad ?)! station_to_keep = "
574 << station_to_keep <<
" stations.size " << stations.size() <<
" all.size " <<
all.size();
576 for (
unsigned i = 0;
i < stations.size(); ++
i)
577 if (stations[
i] >= 0 && stations[
i] <= station_to_keep)
588 const map<DetId, int>& hitMap)
const {
590 const double globalChi2Cut = 200.0;
592 vector<TrajectoryMeasurement> muonMeasurements = traj.
measurements();
595 for (std::vector<TrajectoryMeasurement>::const_iterator im = muonMeasurements.begin(); im != muonMeasurements.end();
597 if (!(*im).recHit()->isValid())
599 if ((*im).recHit()->det()->geographicalId().det() !=
DetId::Muon) {
601 muonRecHits.push_back((*im).recHit());
612 if ((*immrh).isDT()) {
619 else if ((*immrh).isCSC()) {
626 else if ((*immrh).isGEM()) {
633 else if ((*immrh).isME0()) {
640 else if ((*immrh).isRPC()) {
648 double chi2ndf = (*im).estimate() / (*im).recHit()->dimension();
651 map<DetId, int>::const_iterator imap = hitMap.find(chamberId);
652 if (imap != hitMap.end())
656 if ((
keep || (chi2ndf <
chi2Cut)) && (chi2ndf < globalChi2Cut)) {
657 muonRecHits.push_back((*im).recHit());
660 <<
") Det: " << imap->second << endl;
665 reverse(muonRecHits.begin(), muonRecHits.end());
674 for (ConstRecHitContainer::const_iterator ir =
hits.begin(); ir !=
hits.end(); ir++) {
675 if (!(*ir)->isValid()) {
683 <<
" dimension = " << (*ir)->dimension()
684 <<
" det = " << (*ir)->det()->geographicalId().det()
685 <<
" subdet = " << (*ir)->det()->subDetector()
686 <<
" raw id = " << (*ir)->det()->geographicalId().rawId();
696 ConstRecHitContainer::const_iterator frontHit =
recHits.begin();
697 ConstRecHitContainer::const_iterator backHit =
recHits.end() - 1;
698 while (!(*frontHit)->isValid() && frontHit != backHit) {
701 while (!(*backHit)->isValid() && backHit != frontHit) {
705 double rFirst = (*frontHit)->globalPosition().mag();
706 double rLast = (*backHit)->globalPosition().mag();
710 else if (rFirst > rLast)
730 LogTrace(
theCategory) <<
"GlobalMuonRefitter::transform: " << recHitsForReFit.size() <<
" hits:";
733 if (recHitsForReFit.size() < 2)
734 return vector<Trajectory>();
739 LogTrace(
theCategory) <<
"checkRecHitsOrdering() returned " << recHitsOrder <<
", theRefitDirection is "
744 reverse(recHitsForReFit.begin(), recHitsForReFit.end());
751 unsigned int innerId;
752 bool order_swapped =
track.outermostMeasurementState().globalPosition().mag() <
753 track.innermostMeasurementState().globalPosition().mag();
761 firstTSOS =
track.innermostMeasurementState();
762 lastTSOS =
track.outermostMeasurementState();
763 inner_is_first =
true;
767 firstTSOS =
track.outermostMeasurementState();
768 lastTSOS =
track.innermostMeasurementState();
769 inner_is_first =
false;
772 LogTrace(
theCategory) <<
"firstTSOS: inner_is_first? " << inner_is_first <<
" globalPosition is "
773 << firstTSOS.globalPosition() <<
" innerId is " << innerId;
775 if (!firstTSOS.isValid()) {
777 return vector<Trajectory>();
802 (firstTSOS.globalPosition().basicVector().dot(firstTSOS.globalMomentum().basicVector()) > 0)
806 (lastTSOS.globalPosition().basicVector().dot(lastTSOS.globalMomentum().basicVector()) > 0) ?
alongMomentum
808 LogTrace(
theCategory) <<
"propDir_first " << propDir_first <<
", propdir_last " << propDir_last <<
" : they "
809 << (propDir_first == propDir_last ?
"agree" :
"disagree");
812 for (TransientTrackingRecHit::ConstRecHitContainer::const_iterator it = recHitsForReFit.begin();
813 it != recHitsForReFit.end();
815 if ((*it)->globalPosition().y() > 0)
834 LogTrace(
theCategory) <<
"y_count = " << y_count <<
"; based on geometrically-outermost TSOS, propDir is "
835 << propDir <<
": " << (propDir == propDir_ycount ?
"agrees" :
"disagrees")
836 <<
" with ycount determination";
838 if (propDir_first != propDir_last) {
840 propDir = propDir_ycount;
846 if (recHitsForReFit.front()->geographicalId() !=
DetId(innerId)) {
849 <<
" to first rechit with surface pos "
850 << recHitsForReFit.front()->det()->surface().toGlobal(
LocalPoint(0, 0, 0));
853 if (!firstTSOS.isValid()) {
855 return vector<Trajectory>();
861 <<
" p=" << firstTSOS.globalMomentum() <<
" = " << firstTSOS.globalMomentum().mag() << endl;
864 <<
" nHits= " <<
seed.nHits() <<
" tsos: " <<
seed.startingState().parameters().position()
865 <<
" p=" <<
seed.startingState().parameters().momentum() << endl;
873 return vector<Trajectory>();
884 ConstRecHitContainer::const_iterator it =
hits.begin();
885 for (; it !=
hits.end(); it++) {
886 DetId id = (*it)->geographicalId();