CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_5_3_10_patch2/src/RecoTracker/RoadSearchHelixMaker/src/Dcxprobab.cc

Go to the documentation of this file.
00001 //babar #include "BaBar/BaBar.hh"
00002 //babar #include <math.h>
00003 //babar #include "DcxReco/Dcxprobab.hh"
00004 #include <cmath>
00005 #include "RecoTracker/RoadSearchHelixMaker/interface/Dcxprobab.hh"
00006 extern float Dcxprobab(int& ndof, float& chisq){
00007 
00008   //constants
00009   static float srtopi=2.0/sqrt(2.0*M_PI);
00010   static float upl=100.0;
00011 
00012   float prob=0.0;
00013   if(ndof<=0) {return prob;}
00014   if(chisq<0.0) {return prob;}
00015   if(ndof<=60) {
00016     //full treatment
00017     if(chisq>upl) {return prob;}
00018     float sum=exp(-0.5*chisq);
00019     float term=sum;
00020 
00021     int m=ndof/2;
00022     if(2*m==ndof){
00023       if(m==1){return sum;}
00024       for(int i=2; i<=m;i++){
00025         term=0.5*term*chisq/(i-1);
00026         sum+=term;
00027       }//(int i=2; i<=m)
00028       return sum;
00029       //even
00030 
00031     }else{
00032       //odd
00033       float srty=sqrt(chisq);
00034       float temp=srty/M_SQRT2;
00035       prob=erfc(temp);
00036       if(ndof==1) {return prob;}
00037       if(ndof==3) {return (srtopi*srty*sum+prob);}
00038       m=m-1;
00039       for(int i=1; i<=m; i++){
00040         term=term*chisq/(2*i+1);
00041         sum+=term;
00042       }//(int i=1; i<=m; i++)
00043       return (srtopi*srty*sum+prob);
00044 
00045     }//(2*m==ndof)
00046 
00047   }else{
00048     //asymtotic Gaussian approx
00049     float srty=sqrt(chisq)-sqrt(ndof-0.5);
00050     if(srty<12.0) {prob=0.5*erfc(srty);};
00051     return prob;
00052 
00053   }//ndof<30
00054 
00055   // cannot reach following line; warning on OSF; so comment it out
00056   // return prob;
00057 }//endof Dcxprobab