CMS 3D CMS Logo

/data/doxygen/doxygen-1.7.3/gen/CMSSW_4_2_8/src/RecoHI/HiMuonAlgos/src/HICMeasurementEstimator.cc

Go to the documentation of this file.
00001 #include "TrackingTools/TrajectoryState/interface/TrajectoryStateOnSurface.h"
00002 #include "RecoHI/HiMuonAlgos/interface/HICMeasurementEstimator.h"
00003 #include "TrackingTools/PatternTools/interface/MeasurementExtractor.h"
00004 #include "DataFormats/GeometrySurface/interface/BoundPlane.h"
00005 using namespace edm;
00006 using namespace std;
00007 using namespace cms;
00008 
00009 //#define DEBUG
00010 
00011 std::pair<bool,double> 
00012 HICMeasurementEstimator::estimate(const TrajectoryStateOnSurface& tsos,
00013                                    const TransientTrackingRecHit& aRecHit) const {
00014     std::pair<bool,double> flag(false,0.);
00015     if(!tsos.isValid()) {
00016 #ifdef DEBUG
00017           std::cout<<" HICMeasurementEstimator::estimate::trajectory is not valid "<<std::endl;
00018 #endif
00019     return flag;
00020     }
00021 
00022     switch (aRecHit.dimension()) {
00023         case 1: return estimate<1>(tsos,aRecHit);
00024         case 2: return estimate<2>(tsos,aRecHit);
00025         case 3: return estimate<3>(tsos,aRecHit);
00026         case 4: return estimate<4>(tsos,aRecHit);
00027         case 5: return estimate<5>(tsos,aRecHit);
00028     }
00029     throw cms::Exception("RecHit of invalid size (not 1,2,3,4,5)");
00030 }
00031 
00032 template <unsigned int D> std::pair<bool,double> 
00033 HICMeasurementEstimator::estimate(const TrajectoryStateOnSurface& tsos,
00034                                    const TransientTrackingRecHit& aRecHit) const {
00035   typedef typename AlgebraicROOTObject<D>::Vector Vec;
00036   typedef typename AlgebraicROOTObject<D>::SymMatrix Mat;
00037   double est = 0.;
00038 // If RecHit is not valid   
00039   if(!(aRecHit.isValid())) {
00040 #ifdef DEBUG
00041          std::cout<<" Measurement estimator::RecHit is invalid "<<std::endl; 
00042 #endif
00043    return HitReturnType(false,est); 
00044    }
00045 // Check windows
00046 
00047   double dphi = fabs(tsos.freeTrajectoryState()->parameters().position().phi() - aRecHit.globalPosition().phi() - thePhiBoundMean);
00048   double dz = fabs( tsos.freeTrajectoryState()->parameters().position().z() - aRecHit.globalPosition().z() - theZBoundMean );
00049   double dr = fabs( tsos.freeTrajectoryState()->parameters().position().perp() - aRecHit.globalPosition().perp() - theZBoundMean );
00050 #ifdef DEBUG
00051   std::cout<<" Momentum "<<tsos.freeTrajectoryState()->parameters().momentum().perp()<<" "<<tsos.freeTrajectoryState()->parameters().momentum().z()<<std::endl;
00052   std::cout<<" RecHit position r "<<aRecHit.globalPosition().perp()<<" phi "<<aRecHit.globalPosition().phi()<<" "<<aRecHit.globalPosition().z()<<std::endl;
00053   std::cout<<" Predicted position "<<tsos.freeTrajectoryState()->parameters().position().perp()<<" "<<tsos.freeTrajectoryState()->parameters().position().phi()<<
00054   " "<<tsos.freeTrajectoryState()->parameters().position().z()<<std::endl;
00055   std::cout<<" HICMeasurementEstimator::phi "<<dphi<<" "<<thePhiBound<<std::endl;
00056   std::cout<<" HICMeasurementEstimator::z "<<dz<<" "<<theZBound<<std::endl;
00057   std::cout<<" HICMeasurementEstimator::z "<<dr<<" "<<theZBound<<std::endl;
00058 #endif
00059   if( dphi > thePhiBound ) {
00060 #ifdef DEBUG
00061     std::cout<<" HICMeasurementEstimator::phi::failed "<<std::endl;
00062 #endif
00063     return HitReturnType(false,est);
00064   }
00065   if( dz > theZBound ) {
00066 #ifdef DEBUG
00067     std::cout<<" HICMeasurementEstimator::z::failed "<<std::endl;
00068 #endif
00069     return HitReturnType(false,est);
00070   }
00071   if( dr > theZBound ) {
00072 #ifdef DEBUG
00073     std::cout<<" HICMeasurementEstimator::r::failed "<<std::endl;
00074 #endif
00075     return HitReturnType(false,est);
00076   }
00077 
00078     
00079   MeasurementExtractor me(tsos);
00080   Vec r = asSVector<D>(aRecHit.parameters()) - me.measuredParameters<D>(aRecHit);
00081   Mat R = asSMatrix<D>(aRecHit.parametersError()) + me.measuredError<D>(aRecHit);
00082   //int ierr = ! R.Invert(); // if (ierr != 0) throw exception; // 
00083   R.Invert();
00084   est = ROOT::Math::Similarity(r, R);
00085   
00086     if( est > theChi2Cut )
00087     {
00088 #ifdef DEBUG
00089     std::cout<<" HICMeasurementEstimator::chi2::failed "<<est<<" "<<theChi2Cut<<std::endl;
00090 #endif
00091     
00092       return HitReturnType(false,est);
00093     }
00094   
00095   return HitReturnType(true,est);
00096 }
00097 
00098 bool HICMeasurementEstimator::estimate( const TrajectoryStateOnSurface& ts, 
00099                                         const BoundPlane& plane) const
00100 {
00101 
00102 //  cout<<" start estimate plane "<<endl;
00103   double pi = 4.*atan(1.);
00104   double twopi = 2.*pi;
00105   float theZError = plane.bounds().length() + 4.;
00106   float thePhiError = 2.*plane.bounds().width()/plane.position().perp(); 
00107 // Change 02.07.08
00108 //  float thePhiError = 4.*plane.bounds().width()/plane.position().perp();
00109 
00110 #ifdef DEBUG  
00111   cout<<" ======================================================================================== ";
00112   cout<<" Estimate detector::   tsos      :     detector   :   Error "<<endl;
00113   cout<<" R                 "<<ts.globalPosition().perp()<<" "<<plane.position().perp()<<" "<<theZError<<endl;
00114   cout<<" Phi               "<<ts.globalPosition().phi()<<" "<<plane.position().phi()<<" "<<thePhiError<<endl;
00115   cout<<" Z                 "<<ts.globalPosition().z()<<" "<<plane.position().z()<<" "<<theZError<<endl;
00116 #endif
00117 
00118   bool flag = false;
00119   if(fabs(ts.globalPosition().perp()-plane.position().perp())<theZError){
00120    if(fabs(ts.globalPosition().z()-plane.position().z())<theZError){
00121    float phi1 = ts.globalPosition().phi();
00122    float phi2 = plane.position().phi();
00123    if(phi1<0.) phi1 = twopi+phi1;
00124    if(phi2<0.) phi2 = twopi+phi2;
00125    float dfi = fabs(phi1-phi2);
00126    if(dfi>pi) dfi = twopi-dfi;
00127       if(dfi<thePhiError) flag = true;
00128    }
00129   }
00130 #ifdef DEBUG
00131     cout<<" Estimate = "<<flag<<endl;
00132 #endif
00133 
00134   return flag;
00135   
00136 }
00137 
00138 vector<double> HICMeasurementEstimator::setCuts(Trajectory& traj, const DetLayer* b)
00139 {
00140      vector<double> theCuts;
00141      const DetLayer* a = traj.data().back().layer();
00142      const DetLayer* first = traj.data().front().layer();
00143 //     const DetLayer* last = traj.data().front().layer();
00144      thePhiWinMean = 0.;
00145      theZWinMean = 0.;
00146      thePhiWin = 0.;
00147      theZWin = 0.;
00148      theNewCut = 11.; // change 5->10 03.07.2008 //10-11 23.06.09
00149      theNewCutB = 5.;
00150      
00151      thePhiWinMeanB = 0.002;
00152      theZWinMeanB = 0.;
00153      thePhiWinB = 0.008;
00154      theZWinB = 17.;
00155           
00156      theZCutMean = 0.;
00157      thePhiCutMean = 0.;
00158      thePhiCut = 0.;
00159      theZCut = 0.;
00160      
00161      theLayer = b;
00162      theLastLayer = a;
00163 
00164      
00165      theTrajectorySize = traj.data().size();
00166      
00167      
00168      if( theBarrel.size() == 0 || theForward.size() == 0 )
00169      {
00170 #ifdef DEBUG
00171        cout<<" HICMeasurementEstimator::setCuts:: no datector map "<<endl;
00172 #endif
00173         return theCuts;
00174      }
00175      
00176      if( a->location() == GeomDetEnumerators::barrel )
00177      {
00178        if( first->location() == GeomDetEnumerators::barrel ) 
00179        {
00180         thePhiWin = (*theHICConst).phiwinbar[(*theBarrel.find(first)).second][(*theBarrel.find(a)).second][(*theBarrel.find(b)).second];
00181         theZWin = (*theHICConst).zwinbar[(*theBarrel.find(first)).second][(*theBarrel.find(a)).second][(*theBarrel.find(b)).second];
00182         thePhiCut = (*theHICConst).phicutbar[(*theBarrel.find(first)).second][(*theBarrel.find(theLastLayer)).second][(*theBarrel.find(b)).second];
00183         theZCut = (*theHICConst).zcutbar[(*theBarrel.find(first)).second][(*theBarrel.find(theLastLayer)).second][(*theBarrel.find(b)).second];
00184 //        cout<<" Barrel first -Barrel cuts::layers "<<(*theBarrel.find(first)).second<<" "<<(*theBarrel.find(a)).second<<" "<<(*theBarrel.find(b)).second<<endl; 
00185 //        cout<<" Barrel first -Barrel cuts "<< thePhiWin<<" "<<theZWin <<" "<<thePhiCut <<" "<<theZCut<<endl;
00186        }
00187          else
00188          {
00189           if(first->surface().position().z() > 0. )
00190           {
00191           thePhiWin = (*theHICConst).phiwinfbb[(*theForward.find(first)).second][(*theBarrel.find(a)).second][(*theBarrel.find(b)).second];
00192           theZWin = (*theHICConst).zwinfbb[(*theForward.find(first)).second][(*theBarrel.find(a)).second][(*theBarrel.find(b)).second];
00193           thePhiCut = (*theHICConst).phicutfbb[(*theForward.find(first)).second][(*theBarrel.find(theLastLayer)).second][(*theBarrel.find(b)).second];
00194           theZCut = (*theHICConst).zcutfbb[(*theForward.find(first)).second][(*theBarrel.find(theLastLayer)).second][(*theBarrel.find(b)).second];
00195 //          cout<<" Endcap first positive -Barrel cuts::layers "<<(*theForward.find(first)).second<<" "<<(*theBarrel.find(a)).second<<" "<<(*theBarrel.find(b)).second<<endl;       
00196 //          cout<<" Endcap first positive -Barrel cuts "<< thePhiWin<<" "<<theZWin <<" "<<thePhiCut <<" "<<theZCut<<endl;
00197           } else {
00198           thePhiWin = (*theHICConst).phiwinfbb[(*theBackward.find(first)).second][(*theBarrel.find(a)).second][(*theBarrel.find(b)).second];
00199           theZWin = (*theHICConst).zwinfbb[(*theBackward.find(first)).second][(*theBarrel.find(a)).second][(*theBarrel.find(b)).second];
00200           thePhiCut = (*theHICConst).phicutfbb[(*theBackward.find(first)).second][(*theBarrel.find(theLastLayer)).second][(*theBarrel.find(b)).second];
00201           theZCut = (*theHICConst).zcutfbb[(*theBackward.find(first)).second][(*theBarrel.find(theLastLayer)).second][(*theBarrel.find(b)).second];
00202 //          cout<<" Endcap first negative -Barrel cuts::layers "<<(*theBackward.find(first)).second<<" "<<(*theBarrel.find(a)).second<<" "<<(*theBarrel.find(b)).second<<endl;
00203 //          cout<<" Endcap first negative -Barrel cuts "<< thePhiWin<<" "<<theZWin <<" "<<thePhiCut <<" "<<theZCut<<endl;
00204          }
00205          } //
00206 
00207 
00208         theCuts.push_back(thePhiWin); theCuts.push_back(theZWin);
00209         theCuts.push_back(thePhiCut); theCuts.push_back(theZCut);
00210 
00211         return theCuts;
00212      }
00213      if( a->location() == GeomDetEnumerators::endcap && b->location() == GeomDetEnumerators::endcap)
00214      {
00215         if( a->surface().position().z() > 0. )
00216         {
00217         thePhiWin = (*theHICConst).phiwinfrw[(*theForward.find(first)).second][(*theForward.find(a)).second][(*theForward.find(b)).second];
00218         theZWin = (*theHICConst).zwinfrw[(*theForward.find(first)).second][(*theForward.find(a)).second][(*theForward.find(b)).second];
00219         thePhiCut = (*theHICConst).phicutfrw[(*theForward.find(first)).second][(*theForward.find(theLastLayer)).second][(*theForward.find(b)).second];
00220         theZCut = (*theHICConst).zcutfrw[(*theForward.find(first)).second][(*theForward.find(theLastLayer)).second][(*theForward.find(b)).second];
00221         }
00222           else
00223           {
00224            thePhiWin = (*theHICConst).phiwinfrw[(*theBackward.find(first)).second][(*theBackward.find(a)).second][(*theBackward.find(b)).second];
00225            theZWin = (*theHICConst).zwinfrw[(*theBackward.find(first)).second][(*theBackward.find(a)).second][(*theBackward.find(b)).second];
00226            thePhiCut = (*theHICConst).phicutfrw[(*theBackward.find(first)).second][(*theBackward.find(theLastLayer)).second][(*theBackward.find(b)).second];
00227            theZCut = (*theHICConst).zcutfrw[(*theBackward.find(first)).second][(*theBackward.find(theLastLayer)).second][(*theBackward.find(b)).second];
00228           }
00229         
00230         if( theLowMult == 1 )
00231         {
00232         if( b->subDetector() == GeomDetEnumerators::PixelEndcap ) theNewCut = 20.;
00233         if( traj.measurements().size() == 1 ) theNewCut = 20.; 
00234         theNewCutB = 30.;
00235         }
00236         
00237         thePhiWinMeanB = 0.004;
00238         thePhiWinB = 0.05;
00239 
00240 
00241         theCuts.push_back(thePhiWin); theCuts.push_back(theZWin);
00242         theCuts.push_back(thePhiCut); theCuts.push_back(theZCut);
00243         
00244         return theCuts;
00245      }
00246      if( a->location() == GeomDetEnumerators::endcap && b->location() == GeomDetEnumerators::barrel )
00247      {
00248        
00249        if( a->surface().position().z() > 0. )
00250        {
00251         thePhiWin = (*theHICConst).phiwinbfrw[(*theForward.find(first)).second][(*theForward.find(a)).second][(*theBarrel.find(b)).second];
00252         theZWin = (*theHICConst).zwinbfrw[(*theForward.find(first)).second][(*theForward.find(a)).second][(*theBarrel.find(b)).second];
00253         thePhiCut = (*theHICConst).phicutbfrw[(*theForward.find(first)).second][(*theForward.find(theLastLayer)).second][(*theBarrel.find(b)).second];
00254         theZCut = (*theHICConst).zcutbfrw[(*theForward.find(first)).second][(*theForward.find(theLastLayer)).second][(*theBarrel.find(b)).second];
00255        }
00256           else
00257           {
00258             thePhiWin = (*theHICConst).phiwinbfrw[(*theBackward.find(first)).second][(*theBackward.find(a)).second][(*theBarrel.find(b)).second];
00259             theZWin = (*theHICConst).zwinbfrw[(*theBackward.find(first)).second][(*theBackward.find(a)).second][(*theBarrel.find(b)).second];
00260             thePhiCut = (*theHICConst).phicutbfrw[(*theBackward.find(first)).second][(*theBackward.find(theLastLayer)).second][(*theBarrel.find(b)).second];
00261             theZCut = (*theHICConst).zcutbfrw[(*theBackward.find(first)).second][(*theBackward.find(theLastLayer)).second][(*theBarrel.find(b)).second];
00262           }     
00263         
00264         if( b->subDetector() ==  GeomDetEnumerators::PixelBarrel) theNewCut = 20.;
00265 
00266         thePhiWinMeanB = 0.004;
00267         thePhiWinB = 0.016;
00268 
00269         theCuts.push_back(thePhiWin); theCuts.push_back(theZWin);
00270         theCuts.push_back(thePhiCut); theCuts.push_back(theZCut);
00271         
00272         return theCuts;
00273      }
00274 //     cout<<" HICMeasurementEstimator::setCuts::Error: unknown detector layer "<<endl;
00275      return theCuts;
00276 }
00277 
00278 void HICMeasurementEstimator::chooseCuts(int& i)
00279 {
00280 
00281       theChi2Cut = theNewCut;
00282 //      cout<<" Choose Chi2Cut "<<theChi2Cut<<endl;
00283       
00284    if( i == 1 )
00285    {
00286       thePhiBound = thePhiWin;
00287       theZBound = theZWin;
00288       thePhiBoundMean = thePhiWinMean;
00289       theZBoundMean = theZWinMean;
00290 //      cout<<" HICMeasurementEstimator::chooseCuts  "<<i<<" "<<thePhiBound<<" "<<theZBound<<endl;
00291    } 
00292       if( i == 2 )
00293    {
00294       thePhiBound = thePhiWinB;
00295       theZBound = theZWinB;
00296       thePhiBoundMean = thePhiWinMean;
00297       theZBoundMean = theZWinMean;
00298 //      cout<<" HICMeasurementEstimator::chooseCuts  "<<i<<" "<<thePhiBound<<" "<<theZBound<<endl;
00299    }  
00300       if( i == 3 )
00301    {
00302       thePhiBound = thePhiCut;
00303       theZBound = theZCut;
00304       thePhiBoundMean = thePhiCutMean;
00305       theZBoundMean = theZCutMean;
00306 //      cout<<" HICMeasurementEstimator::chooseCuts  "<<i<<" "<<thePhiBound<<" "<<theZBound<<endl;
00307    }
00308      
00309    theCutType = i;
00310 }
00311 
00312 int HICMeasurementEstimator::getDetectorCode(const DetLayer* a)
00313 {
00314      int layer = 0;
00315      if( a->location() == GeomDetEnumerators::barrel ) 
00316      {
00317            layer = (*theBarrel.find(a)).second;
00318      }     
00319      if( a->location() == GeomDetEnumerators::endcap ) 
00320      {
00321            if( a->surface().position().z() > 0. ) { layer = 100+(*theForward.find(a)).second;}
00322            if( a->surface().position().z() < 0. ) { layer = -100-(*theBackward.find(a)).second;}           
00323      }
00324      return layer;
00325 }
00326 
00327 void HICMeasurementEstimator::setHICDetMap()
00328 {
00329 
00330 #ifdef DEBUG
00331   std::cout<<" Set Detector Map... "<<std::endl;
00332 #endif
00333   
00334   int ila=0;
00335   for ( std::vector<BarrelDetLayer*>::const_iterator ilayer = bl.begin(); ilayer != bl.end(); ilayer++)
00336   {
00337      theBarrel[(*ilayer)]=ila;
00338      ila++;
00339   }
00340 //
00341 // The same for forward part.
00342 //
00343 
00344    int ilf1 = 0; 
00345    int ilf2 = 0;
00346    for ( vector<ForwardDetLayer*>::const_iterator ilayer = fpos.begin(); 
00347                                                     ilayer != fpos.end(); ilayer++)
00348    {
00349                 theForward[(*ilayer)] = ilf1;
00350                 ilf1++;
00351    }
00352    for ( vector<ForwardDetLayer*>::const_iterator ilayer = fneg.begin(); 
00353                                                     ilayer != fneg.end(); ilayer++)
00354    {
00355 #ifdef DEBUG
00356             cout<<" HICDetectorMap::negative layers "<<(**ilayer).position().z()<<" "<<ilf2<<endl;
00357 #endif
00358                    theBackward[(*ilayer)] = ilf2;
00359                    ilf2++;
00360    }
00361 
00362 }