22 const string metname =
"Muon|RecoMuon|SETMuonSeedFinder";
37 std::vector<TrajectorySeed> &
result)
52 const sorter sortSegRadius;
56 std::vector<SETSeedFinder::MuonRecHitContainer>
59 stable_sort(cluster.begin(), cluster.end(),sortSegRadius);
63 std::vector< MuonRecHitContainer > MuonRecHitContainer_perLayer;
67 hitsInThisLayer.push_back(cluster[iHit]);
68 DetId detId = cluster[iHit]->hit()->geographicalId();
70 while(iHit<
int(cluster.size())-1){
71 DetId detId_2 = cluster[iHit+1]->hit()->geographicalId();
72 const GlobalPoint gp_nextHit = cluster[iHit+1]->globalPosition();
75 float distanceToDetector = fabs(geomDet->
surface().
localZ(gp_nextHit));
82 bool specialCase =
false;
96 if(distanceToDetector<0.001 ||
true==specialCase){
97 hitsInThisLayer.push_back(cluster[iHit+1]);
101 if(( (cluster[iHit]->isDT() &&
102 cluster[iHit+1]->isCSC()) ||
103 (cluster[iHit]->isCSC() &&
104 cluster[iHit+1]->isDT())) &&
107 fabs(cluster[iHit+1]->globalPosition().
mag() -
108 cluster[iHit]->globalPosition().
mag())<10.){
109 hitsInThisLayer.push_back(cluster[iHit+1]);
111 detId = cluster[iHit+1]->hit()->geographicalId();
112 geomDet =
theService->trackingGeometry()->idToDet( detId );
114 else if(!specialCase){
117 MuonRecHitContainer_perLayer.push_back(hitsInThisLayer);
118 hitsInThisLayer.clear();
119 hitsInThisLayer.push_back(cluster[iHit+1]);
120 detId = cluster[iHit+1]->hit()->geographicalId();
121 geomDet =
theService->trackingGeometry()->idToDet( detId );
126 MuonRecHitContainer_perLayer.push_back(hitsInThisLayer);
128 return MuonRecHitContainer_perLayer;
132 const int maximumNumberOfCombinations = 1000000;
133 unsigned nLayers = MuonRecHitContainer_perLayer.size();
139 if(MuonRecHitContainer_perLayer.size()>15){
140 MuonRecHitContainer_perLayer.resize(1);
144 std::vector <double> sizeOfLayer(nLayers);
146 double nAllCombinations = 1.;
147 for(
unsigned int i = 0;
i<nLayers;++
i ){
149 sizeOfLayer.at(
i) = MuonRecHitContainer_perLayer.at(
i).size();
150 nAllCombinations*=MuonRecHitContainer_perLayer.at(
i).size();
155 while(nAllCombinations >
float(maximumNumberOfCombinations)){
157 std::vector <double>::iterator maxEl_it = max_element(sizeOfLayer.begin(),sizeOfLayer.end());
158 int maxEl = maxEl_it - sizeOfLayer.begin();
159 nAllCombinations/=MuonRecHitContainer_perLayer.at(maxEl).size();
161 MuonRecHitContainer_perLayer.erase(MuonRecHitContainer_perLayer.begin()+maxEl);
162 sizeOfLayer.erase(sizeOfLayer.begin()+maxEl);
167 std::vector<SETSeedFinder::MuonRecHitContainer>
170 std::vector <MuonRecHitContainer> allValidSets;
176 unsigned nLayers = MuonRecHitContainer_perLayer.size();
181 unsigned int iPos0 = 0;
182 std::vector <unsigned int> iLayer(12);
183 std::vector <unsigned int>
size(12);
185 size.at(iPos0) = MuonRecHitContainer_perLayer.at(iPos0).size();
186 for(iLayer[iPos0] = 0; iLayer[iPos0]<size[iPos0];++iLayer[iPos0]){
188 validSet.push_back(MuonRecHitContainer_perLayer[iPos0][iLayer[iPos0]]);
189 unsigned int iPos1 = 1;
191 size.at(iPos1) = MuonRecHitContainer_perLayer.at(iPos1).size();
192 for(iLayer[iPos1] = 0; iLayer[iPos1]<size[iPos1];++iLayer[iPos1]){
193 validSet.resize(iPos1);
194 validSet.push_back(MuonRecHitContainer_perLayer[iPos1][iLayer[iPos1]]);
195 unsigned int iPos2 = 2;
197 size.at(iPos2) = MuonRecHitContainer_perLayer.at(iPos2).size();
198 for(iLayer[iPos2] = 0; iLayer[iPos2]<size[iPos2];++iLayer[iPos2]){
199 validSet.resize(iPos2);
200 validSet.push_back(MuonRecHitContainer_perLayer[iPos2][iLayer[iPos2]]);
201 unsigned int iPos3 = 3;
203 size.at(iPos3) = MuonRecHitContainer_perLayer.at(iPos3).size();
204 for(iLayer[iPos3] = 0; iLayer[iPos3]<size[iPos3];++iLayer[iPos3]){
205 validSet.resize(iPos3);
206 validSet.push_back(MuonRecHitContainer_perLayer[iPos3][iLayer[iPos3]]);
207 unsigned int iPos4 = 4;
209 size.at(iPos4) = MuonRecHitContainer_perLayer.at(iPos4).size();
210 for(iLayer[iPos4] = 0; iLayer[iPos4]<size[iPos4];++iLayer[iPos4]){
211 validSet.resize(iPos4);
212 validSet.push_back(MuonRecHitContainer_perLayer[iPos4][iLayer[iPos4]]);
213 unsigned int iPos5 = 5;
215 size.at(iPos5) = MuonRecHitContainer_perLayer.at(iPos5).size();
216 for(iLayer[iPos5] = 0; iLayer[iPos5]<size[iPos5];++iLayer[iPos5]){
217 validSet.resize(iPos5);
218 validSet.push_back(MuonRecHitContainer_perLayer[iPos5][iLayer[iPos5]]);
219 unsigned int iPos6 = 6;
221 size.at(iPos6) = MuonRecHitContainer_perLayer.at(iPos6).size();
222 for(iLayer[iPos6] = 0; iLayer[iPos6]<size[iPos6];++iLayer[iPos6]){
223 validSet.resize(iPos6);
224 validSet.push_back(MuonRecHitContainer_perLayer[iPos6][iLayer[iPos6]]);
225 unsigned int iPos7 = 7;
227 size.at(iPos7) = MuonRecHitContainer_perLayer.at(iPos7).size();
228 for(iLayer[iPos7] = 0; iLayer[iPos7]<size[iPos7];++iLayer[iPos7]){
229 validSet.resize(iPos7);
230 validSet.push_back(MuonRecHitContainer_perLayer[iPos7][iLayer[iPos7]]);
231 unsigned int iPos8 = 8;
233 size.at(iPos8) = MuonRecHitContainer_perLayer.at(iPos8).size();
234 for(iLayer[iPos8] = 0; iLayer[iPos8]<size[iPos8];++iLayer[iPos8]){
235 validSet.resize(iPos8);
236 validSet.push_back(MuonRecHitContainer_perLayer[iPos8][iLayer[iPos8]]);
237 unsigned int iPos9 = 9;
239 size.at(iPos9) = MuonRecHitContainer_perLayer.at(iPos9).size();
240 for(iLayer[iPos9] = 0; iLayer[iPos9]<size[iPos9];++iLayer[iPos9]){
241 validSet.resize(iPos9);
242 validSet.push_back(MuonRecHitContainer_perLayer[iPos9][iLayer[iPos9]]);
243 unsigned int iPos10 = 10;
245 size.at(iPos10) = MuonRecHitContainer_perLayer.at(iPos10).size();
246 for(iLayer[iPos10] = 0; iLayer[iPos10]<size[iPos10];++iLayer[iPos10]){
247 validSet.resize(iPos10);
248 validSet.push_back(MuonRecHitContainer_perLayer[iPos10][iLayer[iPos10]]);
249 unsigned int iPos11 = 11;
251 size.at(iPos11) = MuonRecHitContainer_perLayer.at(iPos11).size();
252 for(iLayer[iPos11] = 0; iLayer[iPos11]<size[iPos11];++iLayer[iPos11]){
256 allValidSets.push_back(validSet);
262 allValidSets.push_back(validSet);
267 allValidSets.push_back(validSet);
272 allValidSets.push_back(validSet);
277 allValidSets.push_back(validSet);
282 allValidSets.push_back(validSet);
287 allValidSets.push_back(validSet);
292 allValidSets.push_back(validSet);
297 allValidSets.push_back(validSet);
302 allValidSets.push_back(validSet);
307 allValidSets.push_back(validSet);
312 allValidSets.push_back(validSet);
328 double mult = dPhi_1 * dPhi_2;
330 if(fabs(dPhi_1)<fabs(dPhi_2)){
334 if(mult>0) signMult = 1;
335 std::pair <int, int> sign;
336 sign = make_pair (signVal, signMult);
348 for(
unsigned int iSet = 0;iSet<allValidSets.size();++iSet){
356 unsigned nHits = validSet.size();
360 std::vector <double>
dPhi;
365 for(
unsigned int iHit = 1;iHit<nHits;++iHit){
366 dPhi_tmp = validSet[iHit]->globalPosition().phi() -
367 validSet[iHit-1]->globalPosition().phi();
368 dPhi.push_back(dPhi_tmp);
370 std::vector <int> pruneHit;
373 for(
unsigned int iHit = 0;iHit<nHits;++iHit){
374 double dPHI_MIN = 0.02;
378 wildCandidate =
false;
383 fabs(validSet[iHit]->globalPosition().
phi() -
384 validSet[iHit-1]->globalPosition().
phi())>dPHI_MIN ){
385 wildCandidate =
true;
393 dPhi_tmp = validSet[iHit+1]->globalPosition().phi() -
394 validSet[iHit-1]->globalPosition().phi();
397 if( 1==sign.first && 1==sign.second){
402 else if(iHit>1 && iHit<validSet.size()-1){
404 4 == validSet[1]->dimension() &&
405 pruneHit.back()!=int(iHit-1) && pruneHit.back()!=1){
408 dPhi_tmp = validSet[iHit+1]->globalPosition().phi() -
409 validSet[iHit-1]->globalPosition().phi();
412 if( 1==sign.first && 1==sign.second){
417 dPhi_tmp = validSet[iHit+1]->globalPosition().phi() -
418 validSet[iHit]->globalPosition().phi();
420 if( 1==sign.first && 1==sign.second){
421 pruneHit_tmp = iHit-1;
428 if(pruneHit.size()>1 && pruneHit[pruneHit.size()-1]<0 && pruneHit[pruneHit.size()-2]<0){
430 if( -1==sign.first && -1==sign.second){
436 pruneHit.push_back(pruneHit_tmp);
441 for(
unsigned int iHit = 1;iHit<nHits;++iHit){
443 if(pruneHit[iHit-1]>0){
444 validSet.erase(validSet.begin()+pruneHit[iHit-1]-
count);
458 std::vector <SeedCandidate> seedCandidates_inCluster;
461 for(
unsigned int iSet = 0;iSet<allValidSets.size();++iSet){
470 CLHEP::Hep3Vector momEstimate;
477 seedCandidates_inCluster_prep.
theSet = allValidSets[iSet];
478 seedCandidates_inCluster_prep.
momentum = momEstimate;
479 seedCandidates_inCluster_prep.
charge = chargeEstimate;
480 seedCandidates_inCluster.push_back(seedCandidates_inCluster_prep);
483 return seedCandidates_inCluster;
487 CLHEP::Hep3Vector & momEstimate,
int &
charge)
const
489 int firstMeasurement = -1;
490 int lastMeasurement = -1;
500 for(
unsigned int iMeas = 0;iMeas<validSet.size();++iMeas){
502 (validSet[iMeas]->isCSC() || validSet[iMeas]->isDT())){
503 firstMeasurement = iMeas;
509 std::vector<double> momentum_estimate;
519 for(
int iMeas = validSet.size()-1;iMeas>-1;--iMeas){
521 (validSet[iMeas]->isCSC() || validSet[iMeas]->isDT()) &&
524 fabs(validSet[iMeas]->globalPosition().z())<1000.){
525 lastMeasurement = iMeas;
532 for(
unsigned int iMeas = 1;iMeas<validSet.size();++iMeas){
534 (validSet[iMeas]->isCSC() || validSet[iMeas]->isDT())){
535 lastMeasurement = iMeas;
541 if(-1==lastMeasurement && -1==firstMeasurement){
542 firstMeasurement = 0;
543 lastMeasurement = validSet.size()-1;
546 else if(-1==lastMeasurement){
547 lastMeasurement = firstMeasurement;
549 else if(-1==firstMeasurement){
550 firstMeasurement = lastMeasurement;
553 firstHit = validSet[firstMeasurement];
554 secondHit = validSet[lastMeasurement];
555 if(firstHit->isRPC() && secondHit->isRPC()){
556 momentum_estimate.push_back(300.);
557 momentum_estimate.push_back(300.);
560 if(firstHit->isRPC()){
561 firstHit = secondHit;
563 else if(secondHit->isRPC()){
564 secondHit = firstHit;
571 if(2==firstHit->dimension() && 2==secondHit->dimension()){
572 momentum_estimate.push_back(999999999.);
573 momentum_estimate.push_back(999999999.);
579 pT = fabs(momentum_estimate[0]);
587 const float pT_min = 1.99;
595 else if(pT>(-1)*pT_min ){
605 charge = momentum_estimate[0]> 0 ? 1 : -1;
610 double xHit = validSet[firstMeasurement]->globalPosition().x();
611 double yHit = validSet[firstMeasurement]->globalPosition().y();
612 double rHit = TMath::Sqrt(
pow(xHit,2) +
pow(yHit,2));
614 double thetaInner = validSet[firstMeasurement]->globalPosition().theta();
619 double rTrack = (pT /(0.3*3.8))*100.;
621 double par = -1.*(2./
charge)*(TMath::ASin(rHit/(2*rTrack)));
622 double sinPar = TMath::Sin( par );
623 double cosPar = TMath::Cos( par );
626 double sinPhiH = 1./(2.*charge*rTrack)*(xHit + ((sinPar)/(cosPar-1.))*yHit);
627 double cosPhiH = -1./(2.*charge*rTrack)*(((sinPar)/(1.-cosPar))*xHit + yHit);
632 momEstimate = CLHEP::Hep3Vector(pT*cosPhiH, pT*sinPhiH, pT/TMath::Tan(thetaInner));
634 const float minMomenum = 5.;
635 if (momEstimate.mag()<minMomenum){
636 int sign = (pT<0.) ? -1: 1;
637 pT = sign * (fabs(pT)+1);
638 CLHEP::Hep3Vector momEstimate2(pT*cosPhiH, pT*sinPhiH, pT/TMath::Tan(thetaInner));
639 momEstimate = momEstimate2;
640 if (momEstimate.mag()<minMomenum){
641 pT = sign * (fabs(pT)+1);
642 CLHEP::Hep3Vector momEstimate3(pT*cosPhiH, pT*sinPhiH, pT/TMath::Tan(thetaInner));
643 momEstimate = momEstimate3;
644 if (momEstimate.mag()<minMomenum){
645 pT = sign * (fabs(pT)+1);
646 CLHEP::Hep3Vector momEstimate4(pT*cosPhiH, pT*sinPhiH, pT/TMath::Tan(thetaInner));
647 momEstimate = momEstimate4;
659 for(
unsigned int iHit = 0;iHit < hits.size();++iHit){
660 recHitsContainer.
push_back(hits.at(iHit)->hit()->clone());
T getParameter(std::string const &) const
const std::string metname
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
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
double dPhi(double phi1, double phi2)
bool operator()(TransientTrackingRecHit::ConstRecHitPointer hit_1, TransientTrackingRecHit::ConstRecHitPointer hit_2) const
MuonTransientTrackingRecHit::MuonRecHitContainer MuonRecHitContainer
int subdetId() const
get the contents of the subdetector field (not cast into any detector's numbering enum) ...
virtual void seeds(const MuonRecHitContainer &cluster, std::vector< TrajectorySeed > &result)
std::vector< ConstRecHitPointer > ConstRecHitContainer
MuonSeedPtExtractor * thePtExtractor
void limitCombinatorics(std::vector< MuonRecHitContainer > &MuonRecHitContainer_perLayer)
std::vector< MuonRecHitContainer > findAllValidSets(const std::vector< MuonRecHitContainer > &MuonRecHitContainer_perLayer)
MuonServiceProxy * theService
MuonTransientTrackingRecHit const * ConstMuonRecHitPointer
void validSetsPrePruning(std::vector< MuonRecHitContainer > &allValidSets)
MuonTransientTrackingRecHit::MuonRecHitContainer theSet
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)
tuple size
Write out results.
Power< A, B >::type pow(const A &a, const B &b)
ParameterSet const & parameterSet(Provenance const &provenance)
virtual GlobalPoint globalPosition() const