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());
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){
272 DetId detId = muonRecHit->hit()->geographicalId();
282 lastUpdatedTSOS = tSOSDest;
288 chi2_loc = 9999999999.;
293 LocalPoint locHitPos = muonRecHit->localPosition();
294 LocalError locHitErr = muonRecHit->localPositionError();
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();
312 if(4!=muonRecHit->hit()->dimension()){
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;
333 DetId detId = muonRecHit->hit()->geographicalId();
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 =
622 CLHEP::Hep3Vector foot2(invP, theta, result_phi.first);
623 CLHEP::Hep3Vector foot3(invP, result_theta.first , phi);
630 CLHEP::Hep3Vector foot4(result_pInv.first, theta, phi);
631 morePoints.push_back(foot2);
632 morePoints.push_back(foot3);
633 morePoints.push_back(foot4);
637 CLHEP::Hep3Vector foot2(invP, theta, phi-deltaPhi_init);
638 CLHEP::Hep3Vector foot3(invP, theta-deltaTheta_init, phi);
639 CLHEP::Hep3Vector foot4(invP-deltaInvP_init, theta, phi);
640 morePoints.push_back(foot2);
641 morePoints.push_back(foot3);
642 morePoints.push_back(foot4);
648 std::vector <double> &quadratic_chi2){
652 double paramAtMin = -99.;
653 std::vector <double> quadratic_param(3);
660 for(
int iCol=0;iCol<3;++iCol){
665 enumerator_1(0,iCol) = quadratic_chi2.at(iCol);
670 enumerator_2(1,iCol) = quadratic_chi2.at(iCol);
675 enumerator_3(2,iCol) = quadratic_chi2.at(iCol);
677 const double mult = 5.;
684 enumerator.push_back(enumerator_1);
685 enumerator.push_back(enumerator_2);
686 enumerator.push_back(enumerator_3);
688 double determinant=0;
689 denominator.Det2(determinant);
690 if(fabs(determinant)>0.00000000001){
691 for(
int iPar=0;iPar<3;++iPar){
693 enumerator.at(iPar).Det2(d);
694 quadratic_param.at(iPar) = d/determinant;
700 if(quadratic_param.at(2)>0){
701 paramAtMin = - quadratic_param.at(1)/quadratic_param.at(2)/2;
705 paramAtMin = quadratic_var.at(1);
707 double chi2_min = quadratic_param.at(0) + quadratic_param.at(1)*paramAtMin + quadratic_param.at(2)*
pow(paramAtMin,2);
708 std::pair <double, double>
result;
709 result = std::make_pair ( paramAtMin, chi2_min);
714 unsigned int & high,
unsigned int & second_high,
unsigned int & low){
716 std::vector <double> chi2Feet_tmp = chi2Feet;
717 std::vector <double>::iterator minEl = min_element(chi2Feet.begin(), chi2Feet.end());
718 std::vector <double>::iterator maxEl = max_element(chi2Feet.begin(), chi2Feet.end());
719 high = maxEl - chi2Feet.begin();
720 low = minEl - chi2Feet.begin();
721 chi2Feet_tmp[high] = chi2Feet_tmp[low];
722 std::vector <double>::iterator second_maxEl = max_element(chi2Feet_tmp.begin(), chi2Feet_tmp.end());
723 second_high = second_maxEl - chi2Feet_tmp.begin();
729 unsigned int key_foot,
double scale ){
731 CLHEP::Hep3Vector newPosition(0.,0.,0.);
736 CLHEP::Hep3Vector centroid(0,0,0);
737 for(
unsigned int iFoot = 0; iFoot<feet.size();++iFoot){
741 centroid += feet[iFoot];
743 centroid/=(feet.size()-1);
744 CLHEP::Hep3Vector displacement = 2.*(centroid - feet[key_foot]);
745 newPosition = feet[key_foot] + scale * displacement;
750 for(
unsigned int iFoot = 0; iFoot<feet.size();++iFoot){
755 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
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
virtual SubDetector subDetector() const =0
The type of detector (PixelBarrel, PixelEndcap, TIB, TOB, TID, TEC, CSC, DT, RPCBarrel, RPCEndcap)
Sin< T >::type sin(const T &t)
TrajectoryStateOnSurface theLastButOneUpdatedTSOS
the trajectory state on the last but one available surface
Geom::Theta< T > theta() const
Trajectory::DataContainer trajectoryMeasurementsInTheSet
bool buildTrajectoryMeasurements(SeedCandidate *validSegmentsSet, Trajectory::DataContainer &finalCandidate)
from SeedCandidate to DataContainer only
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
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.
std::shared_ptr< MuonTransientTrackingRecHit > MuonRecHitPointer
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)
void pickElements(std::vector< double > &chi2Feet, unsigned int &high, unsigned int &second_high, unsigned int &low)
std::vector< ConstRecHitPointer > ConstRecHitContainer
const MuonServiceProxy * theService
TrajectoryStateOnSurface propagate(STA const &state, SUR const &surface) const
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
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)