22 const string metname =
"Muon|RecoMuon|SETMuonSeedFinder";
37 std::vector<TrajectorySeed> &
result)
47 return (hit_1->globalPosition().mag2()<hit_2->globalPosition().mag2());
54 std::vector<SETSeedFinder::MuonRecHitContainer>
61 std::vector< MuonRecHitContainer > MuonRecHitContainer_perLayer;
65 hitsInThisLayer.push_back(cluster[iHit]);
66 DetId detId = cluster[iHit]->hit()->geographicalId();
68 while(iHit<
int(cluster.size())-1){
69 DetId detId_2 = cluster[iHit+1]->hit()->geographicalId();
70 const GlobalPoint gp_nextHit = cluster[iHit+1]->globalPosition();
73 float distanceToDetector = fabs(geomDet->
surface().
localZ(gp_nextHit));
80 bool specialCase =
false;
94 if(distanceToDetector<0.001 ||
true==specialCase){
95 hitsInThisLayer.push_back(cluster[iHit+1]);
99 if(( (cluster[iHit]->isDT() &&
100 cluster[iHit+1]->isCSC()) ||
101 (cluster[iHit]->isCSC() &&
102 cluster[iHit+1]->isDT())) &&
105 fabs(cluster[iHit+1]->globalPosition().
mag() -
106 cluster[iHit]->globalPosition().
mag())<10.){
107 hitsInThisLayer.push_back(cluster[iHit+1]);
109 detId = cluster[iHit+1]->hit()->geographicalId();
110 geomDet =
theService->trackingGeometry()->idToDet( detId );
112 else if(!specialCase){
115 MuonRecHitContainer_perLayer.push_back(hitsInThisLayer);
116 hitsInThisLayer.clear();
117 hitsInThisLayer.push_back(cluster[iHit+1]);
118 detId = cluster[iHit+1]->hit()->geographicalId();
119 geomDet =
theService->trackingGeometry()->idToDet( detId );
124 MuonRecHitContainer_perLayer.push_back(hitsInThisLayer);
126 return MuonRecHitContainer_perLayer;
130 const int maximumNumberOfCombinations = 1000000;
131 unsigned nLayers = MuonRecHitContainer_perLayer.size();
137 if(MuonRecHitContainer_perLayer.size()>15){
138 MuonRecHitContainer_perLayer.resize(1);
142 std::vector <double> sizeOfLayer(nLayers);
144 double nAllCombinations = 1.;
145 for(
unsigned int i = 0;
i<nLayers;++
i ){
147 sizeOfLayer.at(
i) = MuonRecHitContainer_perLayer.at(
i).size();
148 nAllCombinations*=MuonRecHitContainer_perLayer.at(
i).size();
153 while(nAllCombinations >
float(maximumNumberOfCombinations)){
155 std::vector <double>::iterator maxEl_it = max_element(sizeOfLayer.begin(),sizeOfLayer.end());
156 int maxEl = maxEl_it - sizeOfLayer.begin();
157 nAllCombinations/=MuonRecHitContainer_perLayer.at(maxEl).size();
159 MuonRecHitContainer_perLayer.erase(MuonRecHitContainer_perLayer.begin()+maxEl);
160 sizeOfLayer.erase(sizeOfLayer.begin()+maxEl);
165 std::vector<SETSeedFinder::MuonRecHitContainer>
168 std::vector <MuonRecHitContainer> allValidSets;
174 unsigned nLayers = MuonRecHitContainer_perLayer.size();
179 unsigned int iPos0 = 0;
180 std::vector <unsigned int> iLayer(12);
181 std::vector <unsigned int>
size(12);
183 size.at(iPos0) = MuonRecHitContainer_perLayer.at(iPos0).size();
184 for(iLayer[iPos0] = 0; iLayer[iPos0]<size[iPos0];++iLayer[iPos0]){
186 validSet.push_back(MuonRecHitContainer_perLayer[iPos0][iLayer[iPos0]]);
187 unsigned int iPos1 = 1;
189 size.at(iPos1) = MuonRecHitContainer_perLayer.at(iPos1).size();
190 for(iLayer[iPos1] = 0; iLayer[iPos1]<size[iPos1];++iLayer[iPos1]){
191 validSet.resize(iPos1);
192 validSet.push_back(MuonRecHitContainer_perLayer[iPos1][iLayer[iPos1]]);
193 unsigned int iPos2 = 2;
195 size.at(iPos2) = MuonRecHitContainer_perLayer.at(iPos2).size();
196 for(iLayer[iPos2] = 0; iLayer[iPos2]<size[iPos2];++iLayer[iPos2]){
197 validSet.resize(iPos2);
198 validSet.push_back(MuonRecHitContainer_perLayer[iPos2][iLayer[iPos2]]);
199 unsigned int iPos3 = 3;
201 size.at(iPos3) = MuonRecHitContainer_perLayer.at(iPos3).size();
202 for(iLayer[iPos3] = 0; iLayer[iPos3]<size[iPos3];++iLayer[iPos3]){
203 validSet.resize(iPos3);
204 validSet.push_back(MuonRecHitContainer_perLayer[iPos3][iLayer[iPos3]]);
205 unsigned int iPos4 = 4;
207 size.at(iPos4) = MuonRecHitContainer_perLayer.at(iPos4).size();
208 for(iLayer[iPos4] = 0; iLayer[iPos4]<size[iPos4];++iLayer[iPos4]){
209 validSet.resize(iPos4);
210 validSet.push_back(MuonRecHitContainer_perLayer[iPos4][iLayer[iPos4]]);
211 unsigned int iPos5 = 5;
213 size.at(iPos5) = MuonRecHitContainer_perLayer.at(iPos5).size();
214 for(iLayer[iPos5] = 0; iLayer[iPos5]<size[iPos5];++iLayer[iPos5]){
215 validSet.resize(iPos5);
216 validSet.push_back(MuonRecHitContainer_perLayer[iPos5][iLayer[iPos5]]);
217 unsigned int iPos6 = 6;
219 size.at(iPos6) = MuonRecHitContainer_perLayer.at(iPos6).size();
220 for(iLayer[iPos6] = 0; iLayer[iPos6]<size[iPos6];++iLayer[iPos6]){
221 validSet.resize(iPos6);
222 validSet.push_back(MuonRecHitContainer_perLayer[iPos6][iLayer[iPos6]]);
223 unsigned int iPos7 = 7;
225 size.at(iPos7) = MuonRecHitContainer_perLayer.at(iPos7).size();
226 for(iLayer[iPos7] = 0; iLayer[iPos7]<size[iPos7];++iLayer[iPos7]){
227 validSet.resize(iPos7);
228 validSet.push_back(MuonRecHitContainer_perLayer[iPos7][iLayer[iPos7]]);
229 unsigned int iPos8 = 8;
231 size.at(iPos8) = MuonRecHitContainer_perLayer.at(iPos8).size();
232 for(iLayer[iPos8] = 0; iLayer[iPos8]<size[iPos8];++iLayer[iPos8]){
233 validSet.resize(iPos8);
234 validSet.push_back(MuonRecHitContainer_perLayer[iPos8][iLayer[iPos8]]);
235 unsigned int iPos9 = 9;
237 size.at(iPos9) = MuonRecHitContainer_perLayer.at(iPos9).size();
238 for(iLayer[iPos9] = 0; iLayer[iPos9]<size[iPos9];++iLayer[iPos9]){
239 validSet.resize(iPos9);
240 validSet.push_back(MuonRecHitContainer_perLayer[iPos9][iLayer[iPos9]]);
241 unsigned int iPos10 = 10;
243 size.at(iPos10) = MuonRecHitContainer_perLayer.at(iPos10).size();
244 for(iLayer[iPos10] = 0; iLayer[iPos10]<size[iPos10];++iLayer[iPos10]){
245 validSet.resize(iPos10);
246 validSet.push_back(MuonRecHitContainer_perLayer[iPos10][iLayer[iPos10]]);
247 unsigned int iPos11 = 11;
249 size.at(iPos11) = MuonRecHitContainer_perLayer.at(iPos11).size();
250 for(iLayer[iPos11] = 0; iLayer[iPos11]<size[iPos11];++iLayer[iPos11]){
254 allValidSets.push_back(validSet);
260 allValidSets.push_back(validSet);
265 allValidSets.push_back(validSet);
270 allValidSets.push_back(validSet);
275 allValidSets.push_back(validSet);
280 allValidSets.push_back(validSet);
285 allValidSets.push_back(validSet);
290 allValidSets.push_back(validSet);
295 allValidSets.push_back(validSet);
300 allValidSets.push_back(validSet);
305 allValidSets.push_back(validSet);
310 allValidSets.push_back(validSet);
326 double mult = dPhi_1 * dPhi_2;
328 if(fabs(dPhi_1)<fabs(dPhi_2)){
332 if(mult>0) signMult = 1;
333 std::pair <int, int> sign;
334 sign = make_pair (signVal, signMult);
346 for(
unsigned int iSet = 0;iSet<allValidSets.size();++iSet){
354 unsigned nHits = validSet.size();
358 std::vector <double>
dPhi;
363 for(
unsigned int iHit = 1;iHit<nHits;++iHit){
364 dPhi_tmp = validSet[iHit]->globalPosition().phi() -
365 validSet[iHit-1]->globalPosition().phi();
366 dPhi.push_back(dPhi_tmp);
368 std::vector <int> pruneHit;
371 for(
unsigned int iHit = 0;iHit<nHits;++iHit){
372 double dPHI_MIN = 0.02;
376 wildCandidate =
false;
381 fabs(validSet[iHit]->globalPosition().
phi() -
382 validSet[iHit-1]->globalPosition().
phi())>dPHI_MIN ){
383 wildCandidate =
true;
391 dPhi_tmp = validSet[iHit+1]->globalPosition().phi() -
392 validSet[iHit-1]->globalPosition().phi();
395 if( 1==sign.first && 1==sign.second){
400 else if(iHit>1 && iHit<validSet.size()-1){
402 4 == validSet[1]->dimension() &&
403 pruneHit.back()!=int(iHit-1) && pruneHit.back()!=1){
406 dPhi_tmp = validSet[iHit+1]->globalPosition().phi() -
407 validSet[iHit-1]->globalPosition().phi();
410 if( 1==sign.first && 1==sign.second){
415 dPhi_tmp = validSet[iHit+1]->globalPosition().phi() -
416 validSet[iHit]->globalPosition().phi();
418 if( 1==sign.first && 1==sign.second){
419 pruneHit_tmp = iHit-1;
426 if(pruneHit.size()>1 && pruneHit[pruneHit.size()-1]<0 && pruneHit[pruneHit.size()-2]<0){
428 if( -1==sign.first && -1==sign.second){
434 pruneHit.push_back(pruneHit_tmp);
439 for(
unsigned int iHit = 1;iHit<nHits;++iHit){
441 if(pruneHit[iHit-1]>0){
442 validSet.erase(validSet.begin()+pruneHit[iHit-1]-
count);
456 std::vector <SeedCandidate> seedCandidates_inCluster;
459 for(
unsigned int iSet = 0;iSet<allValidSets.size();++iSet){
468 CLHEP::Hep3Vector momEstimate;
475 seedCandidates_inCluster_prep.
theSet = allValidSets[iSet];
476 seedCandidates_inCluster_prep.
momentum = momEstimate;
477 seedCandidates_inCluster_prep.
charge = chargeEstimate;
478 seedCandidates_inCluster.push_back(seedCandidates_inCluster_prep);
481 return seedCandidates_inCluster;
485 CLHEP::Hep3Vector & momEstimate,
int &
charge)
const
487 int firstMeasurement = -1;
488 int lastMeasurement = -1;
498 for(
unsigned int iMeas = 0;iMeas<validSet.size();++iMeas){
500 (validSet[iMeas]->isCSC() || validSet[iMeas]->isDT())){
501 firstMeasurement = iMeas;
507 std::vector<double> momentum_estimate;
517 for(
int iMeas = validSet.size()-1;iMeas>-1;--iMeas){
519 (validSet[iMeas]->isCSC() || validSet[iMeas]->isDT()) &&
522 fabs(validSet[iMeas]->globalPosition().z())<1000.){
523 lastMeasurement = iMeas;
530 for(
unsigned int iMeas = 1;iMeas<validSet.size();++iMeas){
532 (validSet[iMeas]->isCSC() || validSet[iMeas]->isDT())){
533 lastMeasurement = iMeas;
539 if(-1==lastMeasurement && -1==firstMeasurement){
540 firstMeasurement = 0;
541 lastMeasurement = validSet.size()-1;
544 else if(-1==lastMeasurement){
545 lastMeasurement = firstMeasurement;
547 else if(-1==firstMeasurement){
548 firstMeasurement = lastMeasurement;
551 firstHit = validSet[firstMeasurement];
552 secondHit = validSet[lastMeasurement];
553 if(firstHit->isRPC() && secondHit->isRPC()){
554 momentum_estimate.push_back(300.);
555 momentum_estimate.push_back(300.);
558 if(firstHit->isRPC()){
559 firstHit = secondHit;
561 else if(secondHit->isRPC()){
562 secondHit = firstHit;
569 if(2==firstHit->dimension() && 2==secondHit->dimension()){
570 momentum_estimate.push_back(999999999.);
571 momentum_estimate.push_back(999999999.);
577 pT = fabs(momentum_estimate[0]);
585 const float pT_min = 1.99;
593 else if(pT>(-1)*pT_min ){
603 charge = momentum_estimate[0]> 0 ? 1 : -1;
608 double xHit = validSet[firstMeasurement]->globalPosition().x();
609 double yHit = validSet[firstMeasurement]->globalPosition().y();
610 double rHit = TMath::Sqrt(
pow(xHit,2) +
pow(yHit,2));
612 double thetaInner = validSet[firstMeasurement]->globalPosition().theta();
617 double rTrack = (pT /(0.3*3.8))*100.;
619 double par = -1.*(2./
charge)*(TMath::ASin(rHit/(2*rTrack)));
620 double sinPar = TMath::Sin( par );
621 double cosPar = TMath::Cos( par );
624 double sinPhiH = 1./(2.*charge*rTrack)*(xHit + ((sinPar)/(cosPar-1.))*yHit);
625 double cosPhiH = -1./(2.*charge*rTrack)*(((sinPar)/(1.-cosPar))*xHit + yHit);
630 momEstimate = CLHEP::Hep3Vector(pT*cosPhiH, pT*sinPhiH, pT/TMath::Tan(thetaInner));
632 const float minMomenum = 5.;
633 if (momEstimate.mag()<minMomenum){
634 int sign = (pT<0.) ? -1: 1;
635 pT = sign * (fabs(pT)+1);
636 CLHEP::Hep3Vector momEstimate2(pT*cosPhiH, pT*sinPhiH, pT/TMath::Tan(thetaInner));
637 momEstimate = momEstimate2;
638 if (momEstimate.mag()<minMomenum){
639 pT = sign * (fabs(pT)+1);
640 CLHEP::Hep3Vector momEstimate3(pT*cosPhiH, pT*sinPhiH, pT/TMath::Tan(thetaInner));
641 momEstimate = momEstimate3;
642 if (momEstimate.mag()<minMomenum){
643 pT = sign * (fabs(pT)+1);
644 CLHEP::Hep3Vector momEstimate4(pT*cosPhiH, pT*sinPhiH, pT/TMath::Tan(thetaInner));
645 momEstimate = momEstimate4;
657 for(
unsigned int iHit = 0;iHit < hits.size();++iHit){
658 recHitsContainer.
push_back(hits.at(iHit)->hit()->clone());
666 tsTransform.
persistentState( firstTSOS, hits.at(0)->geographicalId().rawId());
T getParameter(std::string const &) const
const std::string metname
T mag() const
The vector magnitude. Equivalent to sqrt(vec.mag2())
CLHEP::Hep3Vector momentum
bool operator()(TransientTrackingRecHit::ConstRecHitPointer hit_1, TransientTrackingRecHit::ConstRecHitPointer hit_2)
std::pair< int, int > checkAngleDeviation(double dPhi_1, double dPhi_2) const
float localZ(const GlobalPoint &gp) const
Fast access to distance from plane for a point.
void pre_prune(MuonRecHitContainer &validSet) const
bool useSegmentsInTrajectory
TrajectorySeed makeSeed(const TrajectoryStateOnSurface &tsos, const TransientTrackingRecHit::ConstRecHitContainer &hits) const
std::vector< MuonRecHitContainer > sortByLayer(MuonRecHitContainer &cluster) const
void estimateMomentum(const MuonRecHitContainer &validSet, CLHEP::Hep3Vector &momentum, int &charge) const
double dPhi(double phi1, double phi2)
std::pair< const_iterator, const_iterator > range
MuonTransientTrackingRecHit::MuonRecHitContainer MuonRecHitContainer
struct sorter sortSegRadius
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)
MuonSeedPtExtractor * thePtExtractor
std::vector< ConstRecHitPointer > ConstRecHitContainer
void limitCombinatorics(std::vector< MuonRecHitContainer > &MuonRecHitContainer_perLayer)
std::vector< MuonRecHitContainer > findAllValidSets(const std::vector< MuonRecHitContainer > &MuonRecHitContainer_perLayer)
MuonServiceProxy * theService
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)
virtual const BoundPlane & surface() const
The nominal surface of the GeomDet.
tuple size
Write out results.
Power< A, B >::type pow(const A &a, const B &b)
const double par[8 *NPar][4]