39 return (hit_1->globalPosition().mag2()>hit_2->globalPosition().mag2());
42 return (fabs(hit_1->globalPosition().z())>fabs(hit_2->globalPosition().z()));
64 <<
"SETFilter destructor called"<<endl;
92 <<
"Unrecognized module type in incrementChamberCounters";
101 std::vector < SeedCandidate> & validSegmentsSet_out){
103 validSegmentsSet_out.clear();
110 bool validStep =
true;
111 std::vector <double> chi2AllCombinations(validSegmentsSet_in.size());
112 std::vector < TrajectoryStateOnSurface > lastUpdatedTSOS_Vect(validSegmentsSet_in.size());
114 for(
unsigned int iSet = 0; iSet<validSegmentsSet_in.size(); ++iSet){
117 CLHEP::Hep3Vector origin (0.,0.,0.);
120 chi2AllCombinations[iSet] =
findMinChi2(iSet, origin, validSegmentsSet_in[iSet], lastUpdatedTSOS_Vect,
121 trajectoryMeasurementsInTheSet_tmp);
124 std::vector < double >::iterator itMin = min_element(chi2AllCombinations.begin(),chi2AllCombinations.end());
126 int positionMin = itMin - chi2AllCombinations.begin();
129 validSegmentsSet_out.push_back(validSegmentsSet_in[positionMin]);
137 bool validTrajectory =
true;
140 finalCandidate.clear();
162 validTrajectory =
false;
165 return validTrajectory;
176 for(
int iMeas = measurements_segments.size() - 1; iMeas>-1;--iMeas){
179 for(
unsigned int jMeas = 0; jMeas<measurements_segments[iMeas].recHit()->transientHits().size();++jMeas){
180 if(measurements_segments[iMeas].recHit()->transientHits().at(jMeas)->transientHits().size()>1){
183 for(
unsigned int kMeas = 0;kMeas<measurements_segments[iMeas].recHit()->transientHits().at(jMeas)->transientHits().size();
185 sortedHits.push_back(
186 measurements_segments[iMeas].recHit()->transientHits().at(jMeas)->transientHits().at(kMeas));
190 sortedHits = measurements_segments[iMeas].recHit()->transientHits();
195 hitContainer.insert(hitContainer.end(),sortedHits.begin(),sortedHits.end());
199 FreeTrajectoryState ftsStart = *(measurements_segments.at(measurements_segments.size()-1).forwardPredictedState().freeState());
203 DetId detId_last = hitContainer[0]->hit()->geographicalId();
208 firstTSOS = tSOSDest;
226 for(
unsigned int iMeas = 0; iMeas<measurements_segments.size();++iMeas){
227 hitContainer.push_back(measurements_segments[iMeas].recHit());
231 for(
int iMeas = measurements_segments.size() - 1; iMeas>-1;--iMeas){
232 hitContainer.push_back(measurements_segments[iMeas].recHit());
237 firstTSOS = measurements_segments.at(0).forwardPredictedState();
243 const CLHEP::Hep3Vector& r3T,
247 bool detailedOutput){
253 trajectoryMeasurementsInTheSet.clear();
265 ftsStart.setCurvilinearError(cov);
269 double chi2_loc = 0.;
270 for(
unsigned int iMeas = 0; iMeas <muonCandidate.
theSet.size(); ++iMeas){
282 lastUpdatedTSOS = tSOSDest;
288 chi2_loc = 9999999999.;
295 const GlobalPoint globPropPos = ftsStart.position();
300 CLHEP::HepMatrix dist(1,2);
301 double chi2_intermed = -9;
303 dist(1,1) = locPropPos.
x() - locHitPos.
x();
304 dist(1,2) = locPropPos.
y() - locHitPos.
y();
305 CLHEP::HepMatrix IC(2,2);
306 IC(1,1) = locHitErr.
xx();
307 IC(2,1) = locHitErr.
xy();
308 IC(2,2) = locHitErr.
yy();
313 for(
int iE = 1;iE<3;++iE){
315 if ( fabs(IC(iE,iE)) < 0.00000001){
316 IC(iE,iE) = 62500./12.;
325 chi2_intermed =
pow(dist(1,1),2)*IC(1,1) + 2.*dist(1,1)*dist(1,2)*IC(1,2) +
pow(dist(1,2),2)*IC(2,2);
327 chi2_intermed = 9999999999.;
329 chi2_loc += chi2_intermed;
357 std::vector < TrajectoryStateOnSurface > &lastUpdatedTSOS_Vect,
364 bool detailedOutput =
false;
366 double cosTheta = muonCandidate.
momentum.cosTheta();
367 double theta = acos(cosTheta);
369 double pMag = muonCandidate.
momentum.mag();
381 double invP = 1./pMag;
388 const double reflect = 1;
389 const double expand = -0.5;
390 const double contract = 0.25;
394 std::vector <CLHEP::Hep3Vector> feet(nDim+1);
395 std::vector <double> chi2Feet(nDim+1);
396 std::vector <TrajectoryStateOnSurface*> lastUpdatedTSOS_pointer(nDim+1);
400 CLHEP::Hep3Vector foot1(invP, theta, phi);
403 trajectoryMeasurementsInTheSet, detailedOutput);
406 std::vector <CLHEP::Hep3Vector> morePoints =
408 feet[1] = morePoints[0];
409 feet[2] = morePoints[1];
410 feet[3] = morePoints[2];
413 for(
unsigned int iFoot = 1; iFoot<feet.size();++iFoot){
415 chi2Feet[iFoot] =
chi2AtSpecificStep(feet[iFoot], r3T, muonCandidate, lastUpdatedTSOS,
416 trajectoryMeasurementsInTheSet, detailedOutput);
420 unsigned int high, second_high, low;
430 trajectoryMeasurementsInTheSet, detailedOutput);
433 if(chi2Feet[high] <chi2Feet[low]){
437 trajectoryMeasurementsInTheSet, detailedOutput);
441 else if( chi2Feet[high] > chi2Feet[second_high]){
442 double worstChi2 = chi2Feet[high];
446 trajectoryMeasurementsInTheSet, detailedOutput);
449 if(chi2Feet[high] <worstChi2){
451 for(
unsigned int iFoot = 0; iFoot<feet.size();++iFoot){
453 chi2Feet[iFoot] =
chi2AtSpecificStep(feet[iFoot], r3T, muonCandidate, lastUpdatedTSOS,
454 trajectoryMeasurementsInTheSet, detailedOutput);
464 int bestFitElement = min_element(chi2Feet.begin(),chi2Feet.end()) - chi2Feet.begin();
467 detailedOutput =
true;
468 chi2Feet[bestFitElement] =
chi2AtSpecificStep(feet[bestFitElement], r3T, muonCandidate, lastUpdatedTSOS,
469 trajectoryMeasurementsInTheSet, detailedOutput);
470 minChi2 = chi2Feet[bestFitElement];
472 double pMag_updated = 1./feet[bestFitElement].x();
473 double sin_theta =
sin(feet[bestFitElement].
y());
474 double cos_theta =
cos(feet[bestFitElement].
y());
475 double sin_phi =
sin(feet[bestFitElement].
z());
476 double cos_phi =
cos(feet[bestFitElement].
z());
478 double best_pX = pMag_updated*sin_theta*cos_phi;
479 double best_pY = pMag_updated*sin_theta*sin_phi;
480 double best_pZ = pMag_updated*cos_theta;
481 CLHEP::Hep3Vector bestP(best_pX, best_pY, best_pZ);
489 lastUpdatedTSOS_Vect[iSet]= *(lastUpdatedTSOS_pointer[bestFitElement]);
498 const CLHEP::Hep3Vector& r3T,
502 bool detailedOutput){
504 double chi2 = 999999999999.;
506 double pMag_updated = 1./foot.x();
507 double sin_theta =
sin(foot.y());
508 double cos_theta =
cos(foot.y());
509 double sin_phi =
sin(foot.z());
510 double cos_phi =
cos(foot.z());
512 double pX = pMag_updated*sin_theta*cos_phi;
513 double pY = pMag_updated*sin_theta*sin_phi;
514 double pZ = pMag_updated*cos_theta;
516 muonCandidate, lastUpdatedTSOS,
517 trajectoryMeasurementsInTheSet, detailedOutput);
524 const CLHEP::Hep3Vector& r3T,
528 std::vector <CLHEP::Hep3Vector> morePoints;
529 double invP = key_foot.x();
530 double theta = key_foot.y();
531 double phi = key_foot.z();
534 double deltaPhi_init = 0.005;
535 double deltaTheta_init = 0.005;
537 double deltaInvP_init = 0.1 * invP;
541 bool optimized =
true;
548 bool detailedOutput =
false;
551 std::vector < double > pInv_init(3);
552 std::vector < double > theta_init(3);
553 std::vector < double > phi_init(3);
554 std::vector < double > chi2_init(3);
556 pInv_init[0] = invP - deltaInvP_init;
558 pInv_init[2] = invP + deltaInvP_init;
561 theta_init[0] = theta-deltaTheta_init;
562 theta_init[1] =
theta;
563 theta_init[2] = theta+deltaTheta_init;
565 phi_init[0] = phi-deltaPhi_init;
567 phi_init[2] = phi+deltaPhi_init;
569 double sin_theta_nom =
sin(theta_init[1]);
570 double cos_theta_nom =
cos(theta_init[1]);
571 double sin_phi_nom =
sin(phi_init[1]);
572 double cos_phi_nom =
cos(phi_init[1]);
573 double pMag_updated_nom = 1./pInv_init[1];
576 for(
int i=0;
i<3;++
i){
577 double pMag_updated = 1./pInv_init[
i];
578 double pX = pMag_updated*sin_theta_nom*cos_phi_nom;
579 double pY = pMag_updated*sin_theta_nom*sin_phi_nom;
580 double pZ = pMag_updated*cos_theta_nom;
582 muonCandidate, lastUpdatedTSOS,
583 trajectoryMeasurementsInTheSet, detailedOutput);
585 std::pair <double,double> result_pInv =
589 for(
int i=0;
i<3;++
i){
590 double sin_theta =
sin(theta_init[
i]);
591 double cos_theta =
cos(theta_init[i]);
592 double pX = pMag_updated_nom*sin_theta*cos_phi_nom;
593 double pY = pMag_updated_nom*sin_theta*sin_phi_nom;
594 double pZ = pMag_updated_nom*cos_theta;
596 muonCandidate, lastUpdatedTSOS,
597 trajectoryMeasurementsInTheSet, detailedOutput);
599 std::pair <double,double> result_theta =
603 for(
int i=0;
i<3;++
i){
604 double sin_phi =
sin(phi_init[
i]);
605 double cos_phi =
cos(phi_init[i]);
606 double pX = pMag_updated_nom*sin_theta_nom*cos_phi;
607 double pY = pMag_updated_nom*sin_theta_nom*sin_phi;
608 double pZ = pMag_updated_nom*cos_theta_nom;
610 muonCandidate, lastUpdatedTSOS,
611 trajectoryMeasurementsInTheSet, detailedOutput);
613 std::pair <double,double> result_phi =
616 double newPhi = result_phi.first;
617 if(fabs(newPhi - phi)<0.02){
620 CLHEP::Hep3Vector foot2(invP, theta, result_phi.first);
621 CLHEP::Hep3Vector foot3(invP, result_theta.first , phi);
622 double newInvP = result_pInv.first;
623 if(fabs(newInvP - invP)<0.001){
624 newInvP = invP + 0.001;
626 CLHEP::Hep3Vector foot4(result_pInv.first, theta, phi);
627 morePoints.push_back(foot2);
628 morePoints.push_back(foot3);
629 morePoints.push_back(foot4);
633 CLHEP::Hep3Vector foot2(invP, theta, phi-deltaPhi_init);
634 CLHEP::Hep3Vector foot3(invP, theta-deltaTheta_init, phi);
635 CLHEP::Hep3Vector foot4(invP-deltaInvP_init, theta, phi);
636 morePoints.push_back(foot2);
637 morePoints.push_back(foot3);
638 morePoints.push_back(foot4);
644 std::vector <double> &quadratic_chi2){
648 double paramAtMin = -99.;
649 std::vector <double> quadratic_param(3);
656 for(
int iCol=0;iCol<3;++iCol){
661 enumerator_1(0,iCol) = quadratic_chi2.at(iCol);
666 enumerator_2(1,iCol) = quadratic_chi2.at(iCol);
671 enumerator_3(2,iCol) = quadratic_chi2.at(iCol);
673 const double mult = 5.;
680 enumerator.push_back(enumerator_1);
681 enumerator.push_back(enumerator_2);
682 enumerator.push_back(enumerator_3);
684 double determinant=0;
685 denominator.Det2(determinant);
686 if(fabs(determinant)>0.00000000001){
687 for(
int iPar=0;iPar<3;++iPar){
689 enumerator.at(iPar).Det2(d);
690 quadratic_param.at(iPar) = d/determinant;
696 if(quadratic_param.at(2)>0){
697 paramAtMin = - quadratic_param.at(1)/quadratic_param.at(2)/2;
701 paramAtMin = quadratic_var.at(1);
703 double chi2_min = quadratic_param.at(0) + quadratic_param.at(1)*paramAtMin + quadratic_param.at(2)*
pow(paramAtMin,2);
704 std::pair <double, double>
result;
705 result = std::make_pair ( paramAtMin, chi2_min);
710 unsigned int & high,
unsigned int & second_high,
unsigned int & low){
712 std::vector <double> chi2Feet_tmp = chi2Feet;
713 std::vector <double>::iterator minEl = min_element(chi2Feet.begin(), chi2Feet.end());
714 std::vector <double>::iterator maxEl = max_element(chi2Feet.begin(), chi2Feet.end());
715 high = maxEl - chi2Feet.begin();
716 low = minEl - chi2Feet.begin();
717 chi2Feet_tmp[high] = chi2Feet_tmp[low];
718 std::vector <double>::iterator second_maxEl = max_element(chi2Feet_tmp.begin(), chi2Feet_tmp.end());
719 second_high = second_maxEl - chi2Feet_tmp.begin();
725 unsigned int key_foot,
double scale ){
727 CLHEP::Hep3Vector newPosition(0.,0.,0.);
732 CLHEP::Hep3Vector centroid(0,0,0);
733 for(
unsigned int iFoot = 0; iFoot<feet.size();++iFoot){
737 centroid += feet[iFoot];
739 centroid/=(feet.size()-1);
740 CLHEP::Hep3Vector displacement = 2.*(centroid - feet[key_foot]);
741 newPosition = feet[key_foot] + scale * displacement;
746 for(
unsigned int iFoot = 0; iFoot<feet.size();++iFoot){
751 feet[iFoot] += feet[low];
void nDimContract(std::vector< CLHEP::Hep3Vector > &feet, unsigned int low)
std::string thePropagatorName
the propagator name
bool transform(Trajectory::DataContainer &measurements_segments, TransientTrackingRecHit::ConstRecHitContainer &hitContainer, TrajectoryStateOnSurface &firstTSOS)
transforms "segment trajectory" to "rechit container"
T getParameter(std::string const &) const
T getUntrackedParameter(std::string const &, T const &) const
TrajectoryStateOnSurface theLastUpdatedTSOS
the trajectory state on the last available surface
virtual FreeTrajectoryState propagate(const FreeTrajectoryState &ftsStart, const GlobalPoint &pDest) const final
virtual int dimension() const =0
double chi2AtSpecificStep(CLHEP::Hep3Vector &foot, const CLHEP::Hep3Vector &r3T, SeedCandidate &muonCandidate, TrajectoryStateOnSurface &lastUpdatedTSOS, Trajectory::DataContainer &trajectoryMeasurementsInTheSet, bool detailedOutput)
bool transformLight(Trajectory::DataContainer &measurements_segments, TransientTrackingRecHit::ConstRecHitContainer &hitContainer, TrajectoryStateOnSurface &firstTSOS)
transforms "segment trajectory" to "segment container"
const Propagator * propagator() const
access at the propagator
ROOT::Math::SMatrix< double, N, M > type
CLHEP::Hep3Vector momentum
Sin< T >::type sin(const T &t)
TrajectoryStateOnSurface theLastButOneUpdatedTSOS
the trajectory state on the last but one available surface
virtual const TrackingRecHit * hit() const
Geom::Theta< T > theta() const
Trajectory::DataContainer trajectoryMeasurementsInTheSet
virtual SubDetector subDetector() const =0
The type of detector (PixelBarrel, PixelEndcap, TIB, TOB, TID, TEC, CSC, DT, RPCBarrel, RPCEndcap)
bool buildTrajectoryMeasurements(SeedCandidate *validSegmentsSet, Trajectory::DataContainer &finalCandidate)
from SeedCandidate to DataContainer only
virtual LocalPoint localPosition() const override
LocalPoint toLocal(const GlobalPoint &gp) const
Conversion to the R.F. of the GeomDet.
double findMinChi2(unsigned int iSet, const CLHEP::Hep3Vector &r3T, SeedCandidate &muonCandidate, std::vector< TrajectoryStateOnSurface > &lastUpdatedTSOS_Vect, Trajectory::DataContainer &trajectoryMeasurementsInTheSet)
ROOT::Math::SMatrix< double, 5, 5, ROOT::Math::MatRepSym< double, 5 > > AlgebraicSymMatrix55
virtual LocalError localPositionError() const override
const Plane & surface() const
The nominal surface of the GeomDet.
TrajectoryStateOnSurface lastUpdatedTSOS() const
the Trajectory state on the last surface of the fitting
std::vector< TrajectoryMeasurement > DataContainer
bool fwfit_SET(std::vector< SeedCandidate > &validSegmentsSet_in, std::vector< SeedCandidate > &validSegmentsSet_out)
Perform the SET inner-outward fitting.
virtual ~SETFilter()
Destructor.
std::shared_ptr< TrackingRecHit const > ConstRecHitPointer
FreeTrajectoryState const * freeState(bool withErrors=true) const
Cos< T >::type cos(const T &t)
bool useSegmentsInTrajectory
SETFilter(const edm::ParameterSet &par, const MuonServiceProxy *service)
Constructor.
bool operator()(TransientTrackingRecHit::ConstRecHitPointer hit_1, TransientTrackingRecHit::ConstRecHitPointer hit_2) const
std::vector< CLHEP::Hep3Vector > find3MoreStartingPoints(CLHEP::Hep3Vector &key_foot, const CLHEP::Hep3Vector &r3T, SeedCandidate &muonCandidate)
How EventSelector::AcceptEvent() decides whether to accept an event for output otherwise it is excluding the probing of A single or multiple positive and the trigger will pass if any such matching triggers are PASS or EXCEPTION[A criterion thatmatches no triggers at all is detected and causes a throw.] A single negative with an expectation of appropriate bit checking in the decision and the trigger will pass if any such matching triggers are FAIL or EXCEPTION A wildcarded negative criterion that matches more than one trigger in the trigger but the state exists so we define the behavior If all triggers are the negative crieriion will lead to accepting the event(this again matches the behavior of"!*"before the partial wildcard feature was incorporated).The per-event"cost"of each negative criterion with multiple relevant triggers is about the same as!*was in the past
void pickElements(std::vector< double > &chi2Feet, unsigned int &high, unsigned int &second_high, unsigned int &low)
std::vector< ConstRecHitPointer > ConstRecHitContainer
const MuonServiceProxy * theService
double findChi2(double pX, double pY, double pZ, const CLHEP::Hep3Vector &r3T, SeedCandidate &muonCandidate, TrajectoryStateOnSurface &lastUpdatedTSOS, Trajectory::DataContainer &trajectoryMeasurementsInTheSet, bool detailedOutput)
void incrementChamberCounters(const DetLayer *layer)
Increment the DT,CSC,RPC counters.
MuonTransientTrackingRecHit::MuonRecHitContainer theSet
DetId geographicalId() const
std::vector< const DetLayer * > theDetLayers
the det layer used in the reconstruction
Power< A, B >::type pow(const A &a, const B &b)
std::pair< double, double > findParabolaMinimum(std::vector< double > &quadratic_var, std::vector< double > &quadratic_chi2)
virtual void setEvent(const edm::Event &event)
Pass the Event to the algo at each event.
CLHEP::Hep3Vector reflectFoot(std::vector< CLHEP::Hep3Vector > &feet, unsigned int key_foot, double scale)