/afs/hep.man.ac.uk/u/markowen/ATLAS/SFrameProof/2011EPS/topUtils/src/muon_SF_R16.h

00001 #ifndef muon_SF_R16_h
00002 #define muon_SF_R16_h
00003 
00004 /******************************************************************************
00005  * muon_SF_R16.h                                                              *
00006  *                                                                            *
00007  * Simple functions which return data/MC scale factors                        *
00008  * given a muon's (or two muons') eta and phi (defined b/w -pi and pi).       *
00009  * Also functions for corresponding uncertainties.                            *
00010  *                     .                                                      *
00011  * double mu_trigger_SF(double eta, double phi)                               * 
00012  * double mu_trigger_SF_err(double eta, double phi, bool isUp)                * 
00013  * double mu_trigger_SF_staterr(double eta, double phi)                       * 
00014  * double mu_trigger_SF_systerr(double eta, double phi, bool isUp)            * 
00015  *                                                                            * 
00016  * double mu_recoID_SF()                                                      *
00017  * double mu_recoID_SF_err()                                                  *
00018  * double mu_recoID_SF_staterr()                                              *
00019  * double mu_recoID_SF_systerr()                                              *
00020  *                                                                            *
00021  * History                                                                    *
00022  *         08 Dec 2010 -- created by S. Caughron                              *   
00023  *****************************************************************************/
00024 
00025 #include <iostream>
00026 
00027 // forward declaration of functions
00028 double mu_trigger_SF(double eta, double phi);
00029 double mu_trigger_SF_err(double eta, double phi, bool isUp);
00030 double mu_trigger_SF_staterr(double eta, double phi);
00031 double mu_trigger_SF_systerr(double eta, double phi, bool isUp);
00032 double mu_recoID_SF();
00033 double mu_recoID_SF_err();
00034 double mu_recoID_SF_staterr();
00035 double mu_recoID_SF_systerr();
00036 double check_phi_range(double phi);
00037 
00038 
00039 // For trigger scale factors
00040 double mu_trigger_SF(double eta, double phi)
00041 {
00042 
00043     double mu_eta = eta;
00044     double mu_phi = check_phi_range(phi);
00045     int etaI=-1, phiI=-1;   
00046 
00047     const double pi = acos(-1.);
00048 
00049     const double etabins[3] = {-1.05,-0.6,0.6};   // lower edges of eta bins
00050     const double etabins_P2[4] = {-0.5,-0.4,0.2,0.3};   // defines special B2P2 binning
00051 
00052     const double phibins[4] = {-pi,5*pi/16,pi/2,11*pi/16};   // lower edges of phi bins, first and last bin have same SF
00053 
00054     const double trig_SFmatrix[3][3] = {{1.0264,0.9195,0.9522},   // rows are eta, columns are phi
00055                                         {1.0089,0.6571,0.9065},
00056                                         {1.0052,0.8430,1.0458}};
00057 
00058     const double EC_eta = 1.05;
00059     const double EC_SF = 0.9875;
00060 
00061     if ( fabs(mu_eta) > EC_eta )    // only one SF in endcaps
00062 
00063         return EC_SF;       
00064 
00065     else {                          // if in barrel, look up appropriate SF 
00066         
00067         for (int i=3; i>=0; i--){    // find phi index
00068             if ( mu_phi > phibins[i] ) {
00069                 phiI = i;
00070                 break;
00071             }
00072         }
00073         for (int i=2; i>=0; i--){    // find eta index
00074             if ( mu_eta > etabins[i] ) {
00075                 etaI = i;
00076                 break;
00077             }
00078         }
00079 
00080                 if (phiI==1 && etaI == 1) {  // "B1P2" and "B2P2" regions have different binning in rel16
00081                         if ( !((mu_eta > etabins_P2[0] && mu_eta < etabins_P2[1]) || (mu_eta > etabins_P2[2] && mu_eta < etabins_P2[3])) )
00082                                 etaI = 0;
00083                 }
00084 
00085         return trig_SFmatrix[etaI][phiI % 3];   // if phiI==3, use 0 (same SF)
00086 
00087     } //else
00088 
00089     return 0;
00090 }
00091 
00092 // For trigger scale factor uncertainties. 
00093 // These are asymmetric. Passing isUp = kTRUE returns uncertainty in positive direction, kFALSE returns negative direction 
00094 // NB: For both cases, returns *magnitude* of uncertainty, i.e. always a positive number
00095 double mu_trigger_SF_err(double eta, double phi, bool isUp)
00096 {
00097 
00098     double mu_eta = eta;
00099     double mu_phi = check_phi_range(phi);
00100     double staterr, systerr, toterr;
00101 
00102     staterr = mu_trigger_SF_staterr(mu_eta,mu_phi);
00103     systerr = mu_trigger_SF_systerr(mu_eta,mu_phi,isUp);
00104 
00105     toterr = sqrt(pow(staterr,2) + pow(systerr,2));
00106 
00107     return toterr;
00108 
00109 }
00110 
00111 // For trigger scale factor statistical uncertainties. (symmetric)
00112 double mu_trigger_SF_staterr(double eta, double phi)
00113 {
00114 
00115     double mu_eta = eta;
00116     double mu_phi = check_phi_range(phi);
00117     int etaI=-1, phiI=-1;   
00118     //bool isEC = kFALSE;
00119 
00120     const double pi = acos(-1.);
00121 
00122     const double etabins[3] = {-1.05,-0.6,0.6};   // lower edges of eta bins
00123     const double etabins_P2[4] = {-0.5,-0.4,0.2,0.3};   // defines special B2P2 binning
00124 
00125     const double phibins[4] = {-pi,5*pi/16,pi/2,11*pi/16};   // lower edges of phi bins, first and last bin have same SF
00126 
00127     const double errmatrix[3][3] = {{0.0104,0.0167,0.0300},   // rows are eta, columns are phi
00128                                         {0.0056,0.0501,0.0188},
00129                                         {0.0101,0.0530,0.0288}};
00130 
00131     const double EC_eta = 1.05;
00132     const double EC_err= 0.004;
00133 
00134     if ( fabs(mu_eta) > EC_eta ) {   // only one SF in endcaps
00135 
00136                 return EC_err;
00137 
00138     } 
00139     else {                          // if in barrel, look up appropriate SF 
00140         
00141         for (int i=2; i>=0; i--){    // find eta index
00142             if ( mu_eta > etabins[i] ) {
00143                 etaI = i;
00144                 break;
00145             }
00146         }
00147 
00148         for (int i=3; i>=0; i--){    // find phi index
00149             if ( mu_phi > phibins[i] ) {
00150                 phiI = i;
00151                 break;
00152             }
00153         }
00154                 
00155                 if (phiI==1 && etaI == 1) {  // "B1P2" and "B2P2" regions have different binning in rel16
00156                         if ( !((mu_eta > etabins_P2[0] && mu_eta < etabins_P2[1]) || (mu_eta > etabins_P2[2] && mu_eta < etabins_P2[3])) )
00157                                 etaI = 0;
00158                 }
00159 
00160         return errmatrix[etaI][phiI % 3];   // if phiI==3, use 0 (same SF)
00161 
00162     } //else
00163 
00164     return 0;
00165 }
00166 
00167 // For trigger scale factor systematic uncertainties. 
00168 // These are asymmetric. Passing isUp = kTRUE returns uncertainty in positive direction, kFALSE returns negative direction 
00169 // NB: For both cases, returns *magnitude* of uncertainty, i.e. always a positive number
00170 double mu_trigger_SF_systerr(double eta, double phi, bool isUp)
00171 {
00172 
00173     double mu_eta = eta;
00174     double mu_phi = check_phi_range(phi);
00175     int etaI=-1, phiI=-1;   
00176     //bool isEC = kFALSE;
00177 
00178     const double pi = acos(-1.);
00179 
00180     const double etabins[3] = {-1.05,-0.6,0.6};   // lower edges of eta bins
00181     const double etabins_P2[4] = {-0.5,-0.4,0.2,0.3};   // defines special B2P2 binning
00182 
00183     const double phibins[4] = {-pi,5*pi/16,pi/2,11*pi/16};   // lower edges of phi bins, first and last bin have same SF
00184 
00185     const double pos_errmatrix[3][3] = {{0.003,0.007,0.002},   // rows are eta, columns are phi
00186                                         {0.001,0.010,0.000},
00187                                         {0.002,0.000,0.011}};
00188 
00189     const double neg_errmatrix[3][3] = {{0.002,0.000,0.003},   // rows are eta, columns are phi
00190                                         {0.002,0.000,0.004},
00191                                         {0.003,0.013,0.009}};
00192 
00193     const double EC_eta = 1.05;
00194     const double EC_err_up = 0.001;
00195     const double EC_err_down = 0.001;
00196 
00197     if ( fabs(mu_eta) > EC_eta ) {   // only one SF in endcaps
00198 
00199         if (isUp)
00200                 return EC_err_up;
00201         else
00202                 return EC_err_down;
00203 
00204     } 
00205     else {                          // if in barrel, look up appropriate SF 
00206         
00207         for (int i=2; i>=0; i--){    // find eta index
00208             if ( mu_eta > etabins[i] ) {
00209                 etaI = i;
00210                 break;
00211             }
00212         }
00213 
00214         for (int i=3; i>=0; i--){    // find phi index
00215             if ( mu_phi > phibins[i] ) {
00216                 phiI = i;
00217                 break;
00218             }
00219         }
00220                 
00221                 if (phiI==1 && etaI == 1) {  // "B1P2" and "B2P2" regions have different binning in rel16
00222                         if ( !((mu_eta > etabins_P2[0] && mu_eta < etabins_P2[1]) || (mu_eta > etabins_P2[2] && mu_eta < etabins_P2[3])) )
00223                                 etaI = 0;
00224                 }
00225 
00226         if (isUp)
00227                 return pos_errmatrix[etaI][phiI % 3];   // if phiI==3, use 0 (same SF)
00228         else
00229                 return neg_errmatrix[etaI][phiI % 3];   
00230 
00231     } //else
00232 
00233     return 0;
00234 }
00235 
00236 
00237 // For reco+ID scale factors
00238 double mu_recoID_SF()
00239 {
00240 
00241         const double recoID_SF = 0.999;  // in rel16, just a number
00242     return recoID_SF;
00243 
00244 }
00245 
00246 // For reco+ID scale factor total uncertainties. 
00247 double mu_recoID_SF_err()
00248 {
00249 
00250     double staterr, systerr, toterr;
00251 
00252     staterr = mu_recoID_SF_staterr();
00253     systerr = mu_recoID_SF_systerr();
00254 
00255     toterr = sqrt(pow(staterr,2) + pow(systerr,2));
00256 
00257     return toterr;
00258 
00259 }
00260 
00261 // For reco+ID scale factor statistical uncertainties (symmetric)
00262 double mu_recoID_SF_staterr()
00263 {
00264 
00265         const double SFerr = 0.002;  //in rel16, just a number
00266         return SFerr;    
00267 
00268 }
00269 
00270 // For reco+ID scale factor systematic uncertainties 
00271 double mu_recoID_SF_systerr()
00272 {
00273 
00274         const double SFerr = 0.003;
00275         return SFerr;
00276 
00277 }
00278 
00279 // Helper function to deal with possible phi ambiguity
00280 double check_phi_range(double phi)
00281 {
00282 
00283         double newphi = phi;
00284         const double pi = acos(-1.);
00285 
00286         if (newphi > pi) {
00287                 printf("<muon_SF>: WARNING: Muon phi %4.2f > pi! Using (phi-2*pi) \n", phi);
00288                 newphi -= 2*pi;
00289         }
00290         if (newphi < -pi) {
00291                 printf("<muon_SF>: WARNING: Muon phi %4.2f < -pi! Using (phi+2*pi) \n", phi);
00292                 newphi += 2*pi;
00293         }
00294 
00295         return newphi;
00296 }
00297 
00298 
00299 #endif

Generated on Thu Jun 30 11:40:04 2011 for manTreeSFrame by  doxygen 1.4.7