22 const string metname =
"Muon|RecoMuon|SETMuonSeedFinder";
37 std::vector<TrajectorySeed> &
result)
49 return (hit_1->globalPosition().mag2()<hit_2->globalPosition().mag2());
53 const sorter sortSegRadius;
57 std::vector<SETSeedFinder::MuonRecHitContainer>
60 stable_sort(cluster.begin(), cluster.end(),sortSegRadius);
64 std::vector< MuonRecHitContainer > MuonRecHitContainer_perLayer;
68 hitsInThisLayer.push_back(cluster[iHit]);
69 DetId detId = cluster[iHit]->hit()->geographicalId();
71 while(iHit<
int(cluster.size())-1){
72 DetId detId_2 = cluster[iHit+1]->hit()->geographicalId();
73 const GlobalPoint gp_nextHit = cluster[iHit+1]->globalPosition();
76 float distanceToDetector = fabs(geomDet->
surface().
localZ(gp_nextHit));
83 bool specialCase =
false;
97 if(distanceToDetector<0.001 ||
true==specialCase){
98 hitsInThisLayer.push_back(cluster[iHit+1]);
102 if(( (cluster[iHit]->
isDT() &&
103 cluster[iHit+1]->
isCSC()) ||
104 (cluster[iHit]->
isCSC() &&
105 cluster[iHit+1]->
isDT())) &&
108 fabs(cluster[iHit+1]->globalPosition().
mag() -
109 cluster[iHit]->globalPosition().
mag())<10.){
110 hitsInThisLayer.push_back(cluster[iHit+1]);
112 detId = cluster[iHit+1]->hit()->geographicalId();
113 geomDet =
theService->trackingGeometry()->idToDet( detId );
115 else if(!specialCase){
118 MuonRecHitContainer_perLayer.push_back(hitsInThisLayer);
119 hitsInThisLayer.clear();
120 hitsInThisLayer.push_back(cluster[iHit+1]);
121 detId = cluster[iHit+1]->hit()->geographicalId();
122 geomDet =
theService->trackingGeometry()->idToDet( detId );
127 MuonRecHitContainer_perLayer.push_back(hitsInThisLayer);
129 return MuonRecHitContainer_perLayer;
133 const int maximumNumberOfCombinations = 1000000;
134 unsigned nLayers = MuonRecHitContainer_perLayer.size();
140 if(MuonRecHitContainer_perLayer.size()>15){
141 MuonRecHitContainer_perLayer.resize(1);
145 std::vector <double> sizeOfLayer(nLayers);
147 double nAllCombinations = 1.;
150 sizeOfLayer.at(
i) = MuonRecHitContainer_perLayer.at(
i).size();
151 nAllCombinations*=MuonRecHitContainer_perLayer.at(
i).size();
156 while(nAllCombinations >
float(maximumNumberOfCombinations)){
158 std::vector <double>::iterator maxEl_it = max_element(sizeOfLayer.begin(),sizeOfLayer.end());
159 int maxEl = maxEl_it - sizeOfLayer.begin();
160 nAllCombinations/=MuonRecHitContainer_perLayer.at(maxEl).size();
162 MuonRecHitContainer_perLayer.erase(MuonRecHitContainer_perLayer.begin()+maxEl);
163 sizeOfLayer.erase(sizeOfLayer.begin()+maxEl);
168 std::vector<SETSeedFinder::MuonRecHitContainer>
171 std::vector <MuonRecHitContainer> allValidSets;
177 unsigned nLayers = MuonRecHitContainer_perLayer.size();
182 unsigned int iPos0 = 0;
183 std::vector <unsigned int> iLayer(12);
184 std::vector <unsigned int>
size(12);
186 size.at(iPos0) = MuonRecHitContainer_perLayer.at(iPos0).size();
187 for(iLayer[iPos0] = 0; iLayer[iPos0]<size[iPos0];++iLayer[iPos0]){
189 validSet.push_back(MuonRecHitContainer_perLayer[iPos0][iLayer[iPos0]]);
190 unsigned int iPos1 = 1;
192 size.at(iPos1) = MuonRecHitContainer_perLayer.at(iPos1).size();
193 for(iLayer[iPos1] = 0; iLayer[iPos1]<size[iPos1];++iLayer[iPos1]){
194 validSet.resize(iPos1);
195 validSet.push_back(MuonRecHitContainer_perLayer[iPos1][iLayer[iPos1]]);
196 unsigned int iPos2 = 2;
198 size.at(iPos2) = MuonRecHitContainer_perLayer.at(iPos2).size();
199 for(iLayer[iPos2] = 0; iLayer[iPos2]<size[iPos2];++iLayer[iPos2]){
200 validSet.resize(iPos2);
201 validSet.push_back(MuonRecHitContainer_perLayer[iPos2][iLayer[iPos2]]);
202 unsigned int iPos3 = 3;
204 size.at(iPos3) = MuonRecHitContainer_perLayer.at(iPos3).size();
205 for(iLayer[iPos3] = 0; iLayer[iPos3]<size[iPos3];++iLayer[iPos3]){
206 validSet.resize(iPos3);
207 validSet.push_back(MuonRecHitContainer_perLayer[iPos3][iLayer[iPos3]]);
208 unsigned int iPos4 = 4;
210 size.at(iPos4) = MuonRecHitContainer_perLayer.at(iPos4).size();
211 for(iLayer[iPos4] = 0; iLayer[iPos4]<size[iPos4];++iLayer[iPos4]){
212 validSet.resize(iPos4);
213 validSet.push_back(MuonRecHitContainer_perLayer[iPos4][iLayer[iPos4]]);
214 unsigned int iPos5 = 5;
216 size.at(iPos5) = MuonRecHitContainer_perLayer.at(iPos5).size();
217 for(iLayer[iPos5] = 0; iLayer[iPos5]<size[iPos5];++iLayer[iPos5]){
218 validSet.resize(iPos5);
219 validSet.push_back(MuonRecHitContainer_perLayer[iPos5][iLayer[iPos5]]);
220 unsigned int iPos6 = 6;
222 size.at(iPos6) = MuonRecHitContainer_perLayer.at(iPos6).size();
223 for(iLayer[iPos6] = 0; iLayer[iPos6]<size[iPos6];++iLayer[iPos6]){
224 validSet.resize(iPos6);
225 validSet.push_back(MuonRecHitContainer_perLayer[iPos6][iLayer[iPos6]]);
226 unsigned int iPos7 = 7;
228 size.at(iPos7) = MuonRecHitContainer_perLayer.at(iPos7).size();
229 for(iLayer[iPos7] = 0; iLayer[iPos7]<size[iPos7];++iLayer[iPos7]){
230 validSet.resize(iPos7);
231 validSet.push_back(MuonRecHitContainer_perLayer[iPos7][iLayer[iPos7]]);
232 unsigned int iPos8 = 8;
234 size.at(iPos8) = MuonRecHitContainer_perLayer.at(iPos8).size();
235 for(iLayer[iPos8] = 0; iLayer[iPos8]<size[iPos8];++iLayer[iPos8]){
236 validSet.resize(iPos8);
237 validSet.push_back(MuonRecHitContainer_perLayer[iPos8][iLayer[iPos8]]);
238 unsigned int iPos9 = 9;
240 size.at(iPos9) = MuonRecHitContainer_perLayer.at(iPos9).size();
241 for(iLayer[iPos9] = 0; iLayer[iPos9]<size[iPos9];++iLayer[iPos9]){
242 validSet.resize(iPos9);
243 validSet.push_back(MuonRecHitContainer_perLayer[iPos9][iLayer[iPos9]]);
244 unsigned int iPos10 = 10;
246 size.at(iPos10) = MuonRecHitContainer_perLayer.at(iPos10).size();
247 for(iLayer[iPos10] = 0; iLayer[iPos10]<size[iPos10];++iLayer[iPos10]){
248 validSet.resize(iPos10);
249 validSet.push_back(MuonRecHitContainer_perLayer[iPos10][iLayer[iPos10]]);
250 unsigned int iPos11 = 11;
252 size.at(iPos11) = MuonRecHitContainer_perLayer.at(iPos11).size();
253 for(iLayer[iPos11] = 0; iLayer[iPos11]<size[iPos11];++iLayer[iPos11]){
257 allValidSets.push_back(validSet);
263 allValidSets.push_back(validSet);
268 allValidSets.push_back(validSet);
273 allValidSets.push_back(validSet);
278 allValidSets.push_back(validSet);
283 allValidSets.push_back(validSet);
288 allValidSets.push_back(validSet);
293 allValidSets.push_back(validSet);
298 allValidSets.push_back(validSet);
303 allValidSets.push_back(validSet);
308 allValidSets.push_back(validSet);
313 allValidSets.push_back(validSet);
329 double mult = dPhi_1 * dPhi_2;
331 if(fabs(dPhi_1)<fabs(dPhi_2)){
335 if(mult>0) signMult = 1;
336 std::pair <int, int>
sign;
337 sign = make_pair (signVal, signMult);
349 for(
unsigned int iSet = 0;iSet<allValidSets.size();++iSet){
357 unsigned nHits = validSet.size();
361 std::vector <double> dPhi;
366 for(
unsigned int iHit = 1;iHit<nHits;++iHit){
367 dPhi_tmp = validSet[iHit]->globalPosition().phi() -
368 validSet[iHit-1]->globalPosition().phi();
369 dPhi.push_back(dPhi_tmp);
371 std::vector <int> pruneHit;
374 for(
unsigned int iHit = 0;iHit<nHits;++iHit){
375 double dPHI_MIN = 0.02;
379 wildCandidate =
false;
384 fabs(validSet[iHit]->globalPosition().
phi() -
385 validSet[iHit-1]->globalPosition().
phi())>dPHI_MIN ){
386 wildCandidate =
true;
394 dPhi_tmp = validSet[iHit+1]->globalPosition().phi() -
395 validSet[iHit-1]->globalPosition().phi();
398 if( 1==sign.first && 1==sign.second){
403 else if(iHit>1 && iHit<validSet.size()-1){
405 4 == validSet[1]->dimension() &&
406 pruneHit.back()!=
int(iHit-1) && pruneHit.back()!=1){
409 dPhi_tmp = validSet[iHit+1]->globalPosition().phi() -
410 validSet[iHit-1]->globalPosition().phi();
413 if( 1==sign.first && 1==sign.second){
418 dPhi_tmp = validSet[iHit+1]->globalPosition().phi() -
419 validSet[iHit]->globalPosition().phi();
421 if( 1==sign.first && 1==sign.second){
422 pruneHit_tmp = iHit-1;
429 if(pruneHit.size()>1 && pruneHit[pruneHit.size()-1]<0 && pruneHit[pruneHit.size()-2]<0){
431 if( -1==sign.first && -1==sign.second){
437 pruneHit.push_back(pruneHit_tmp);
442 for(
unsigned int iHit = 1;iHit<nHits;++iHit){
444 if(pruneHit[iHit-1]>0){
445 validSet.erase(validSet.begin()+pruneHit[iHit-1]-
count);
459 std::vector <SeedCandidate> seedCandidates_inCluster;
462 for(
unsigned int iSet = 0;iSet<allValidSets.size();++iSet){
471 CLHEP::Hep3Vector momEstimate;
478 seedCandidates_inCluster_prep.
theSet = allValidSets[iSet];
479 seedCandidates_inCluster_prep.
momentum = momEstimate;
480 seedCandidates_inCluster_prep.
charge = chargeEstimate;
481 seedCandidates_inCluster.push_back(seedCandidates_inCluster_prep);
484 return seedCandidates_inCluster;
488 CLHEP::Hep3Vector & momEstimate,
int &
charge)
const 490 int firstMeasurement = -1;
491 int lastMeasurement = -1;
501 for(
unsigned int iMeas = 0;iMeas<validSet.size();++iMeas){
503 (validSet[iMeas]->isCSC() || validSet[iMeas]->isDT())){
504 firstMeasurement = iMeas;
510 std::vector<double> momentum_estimate;
520 for(
int iMeas = validSet.size()-1;iMeas>-1;--iMeas){
522 (validSet[iMeas]->isCSC() || validSet[iMeas]->isDT()) &&
525 fabs(validSet[iMeas]->globalPosition().z())<1000.){
526 lastMeasurement = iMeas;
533 for(
unsigned int iMeas = 1;iMeas<validSet.size();++iMeas){
535 (validSet[iMeas]->isCSC() || validSet[iMeas]->isDT())){
536 lastMeasurement = iMeas;
542 if(-1==lastMeasurement && -1==firstMeasurement){
543 firstMeasurement = 0;
544 lastMeasurement = validSet.size()-1;
547 else if(-1==lastMeasurement){
548 lastMeasurement = firstMeasurement;
550 else if(-1==firstMeasurement){
551 firstMeasurement = lastMeasurement;
554 firstHit = validSet[firstMeasurement];
555 secondHit = validSet[lastMeasurement];
556 if(firstHit->isRPC() && secondHit->isRPC()){
557 momentum_estimate.push_back(300.);
558 momentum_estimate.push_back(300.);
561 if(firstHit->isRPC()){
562 firstHit = secondHit;
564 else if(secondHit->isRPC()){
565 secondHit = firstHit;
572 if(2==firstHit->dimension() && 2==secondHit->dimension()){
573 momentum_estimate.push_back(999999999.);
574 momentum_estimate.push_back(999999999.);
580 pT = fabs(momentum_estimate[0]);
588 const float pT_min = 1.99;
596 else if(pT>(-1)*pT_min ){
606 charge = momentum_estimate[0]> 0 ? 1 : -1;
611 double xHit = validSet[firstMeasurement]->globalPosition().x();
612 double yHit = validSet[firstMeasurement]->globalPosition().y();
613 double rHit = TMath::Sqrt(
pow(xHit,2) +
pow(yHit,2));
615 double thetaInner = validSet[firstMeasurement]->globalPosition().theta();
620 double rTrack = (pT /(0.3*3.8))*100.;
622 double par = -1.*(2./
charge)*(TMath::ASin(rHit/(2*rTrack)));
623 double sinPar = TMath::Sin( par );
624 double cosPar = TMath::Cos( par );
627 double sinPhiH = 1./(2.*charge*rTrack)*(xHit + ((sinPar)/(cosPar-1.))*yHit);
628 double cosPhiH = -1./(2.*charge*rTrack)*(((sinPar)/(1.-cosPar))*xHit + yHit);
633 momEstimate = CLHEP::Hep3Vector(pT*cosPhiH, pT*sinPhiH, pT/TMath::Tan(thetaInner));
635 const float minMomenum = 5.;
636 if (momEstimate.mag()<minMomenum){
637 int sign = (pT<0.) ? -1: 1;
638 pT = sign * (fabs(pT)+1);
639 CLHEP::Hep3Vector momEstimate2(pT*cosPhiH, pT*sinPhiH, pT/TMath::Tan(thetaInner));
640 momEstimate = momEstimate2;
641 if (momEstimate.mag()<minMomenum){
642 pT = sign * (fabs(pT)+1);
643 CLHEP::Hep3Vector momEstimate3(pT*cosPhiH, pT*sinPhiH, pT/TMath::Tan(thetaInner));
644 momEstimate = momEstimate3;
645 if (momEstimate.mag()<minMomenum){
646 pT = sign * (fabs(pT)+1);
647 CLHEP::Hep3Vector momEstimate4(pT*cosPhiH, pT*sinPhiH, pT/TMath::Tan(thetaInner));
648 momEstimate = momEstimate4;
660 for(
unsigned int iHit = 0;iHit < hits.size();++iHit){
661 recHitsContainer.
push_back(hits.at(iHit)->hit()->clone());
T getParameter(std::string const &) const
T mag() const
The vector magnitude. Equivalent to sqrt(vec.mag2())
CLHEP::Hep3Vector momentum
std::pair< int, int > checkAngleDeviation(double dPhi_1, double dPhi_2) const
float localZ(const GlobalPoint &gp) const
void pre_prune(MuonRecHitContainer &validSet) const
bool useSegmentsInTrajectory
TrajectorySeed makeSeed(const TrajectoryStateOnSurface &tsos, const TransientTrackingRecHit::ConstRecHitContainer &hits) const
bool isDT(GeomDetEnumerators::SubDetector m)
const Plane & surface() const
The nominal surface of the GeomDet.
std::vector< MuonRecHitContainer > sortByLayer(MuonRecHitContainer &cluster) const
void estimateMomentum(const MuonRecHitContainer &validSet, CLHEP::Hep3Vector &momentum, int &charge) const
std::shared_ptr< MuonTransientTrackingRecHit > MuonRecHitPointer
MuonTransientTrackingRecHit::MuonRecHitContainer MuonRecHitContainer
int subdetId() const
get the contents of the subdetector field (not cast into any detector's numbering enum) ...
std::vector< ConstRecHitPointer > ConstRecHitContainer
MuonSeedPtExtractor * thePtExtractor
void limitCombinatorics(std::vector< MuonRecHitContainer > &MuonRecHitContainer_perLayer)
void seeds(const MuonRecHitContainer &cluster, std::vector< TrajectorySeed > &result) override
std::vector< MuonRecHitContainer > findAllValidSets(const std::vector< MuonRecHitContainer > &MuonRecHitContainer_perLayer)
return(e1-e2)*(e1-e2)+dp *dp
MuonServiceProxy * theService
void validSetsPrePruning(std::vector< MuonRecHitContainer > &allValidSets)
bool isCSC(GeomDetEnumerators::SubDetector m)
MuonTransientTrackingRecHit::MuonRecHitContainer theSet
std::shared_ptr< MuonTransientTrackingRecHit const > ConstMuonRecHitPointer
std::vector< SeedCandidate > fillSeedCandidates(std::vector< MuonRecHitContainer > &allValidSets)
int station() const
Return the station number.
uint32_t dimension(pat::CandKinResolution::Parametrization parametrization)
Returns the number of free parameters in a parametrization (3 or 4)
SETSeedFinder(const edm::ParameterSet &pset)
Power< A, B >::type pow(const A &a, const B &b)
ParameterSet const & parameterSet(Provenance const &provenance)