Main Page | Modules | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members | Related Pages

Zfluk.cxx

Go to the documentation of this file.
00001 // $Author: zarko $ 
00002 //
00003 // $Revision: 1.10 $
00004 // 
00005 // $Name:  $
00006 //
00007 // $Id: Zfluk.cxx,v 1.10 2007/03/03 21:27:05 zarko Exp $
00008 //
00009 // $Log: Zfluk.cxx,v $
00010 // Revision 1.10  2007/03/03 21:27:05  zarko
00011 // Version used for PiMinus fits.
00012 //
00013 // Revision 1.9  2007/02/14 22:58:07  zarko
00014 // In this version of zfluk GetWeight(ptype,pt,pz) returns a weight using
00015 // 16 parameters (6 for pi+, 6 for K+, 2 for pi- and 2 for K-)
00016 //
00017 // Revision 1.8  2006/11/10 19:13:17  zarko
00018 // Changed the way kaon weights are calculated so that K/pi ratio is
00019 // preserved. Added K0L reweighting based on K+ and K- weights.
00020 // To get these weights use SetParameters(vector<double>) and
00021 // GetWeight(ptype, pT, pz) functions.
00022 //
00023 // Revision 1.7  2006/10/03 16:00:56  zarko
00024 // Updated code to reweight numus and numubars
00025 //
00026 // Revision 1.6  2006/06/02 04:37:53  zarko
00027 // Use arrays instead of histograms in GetPTshift to speed up the code.
00028 //
00029 // Revision 1.5  2006/04/14 02:37:31  zarko
00030 // Zfluk now looks into SRT_PUBLIC_CONTEXT if the data cannot be found in SRT_PRIVATE_CONTEXT
00031 //
00032 // Revision 1.4  2006/03/13 23:58:32  zarko
00033 // Updated SKZP parameterization. Now using 7 parameters.
00034 // One for kaons and 6 to parameterize pt-xf weights.
00035 //
00036 // Revision 1.3  2006/02/21 00:04:24  zarko
00037 // Modified Files:
00038 //      Zfluk.cxx Zfluk.h
00039 //
00040 // Added function GetPTshift(par). This uses the fluka05ptxf.root file that should
00041 // be in MCReweight/data. This function returns shift in mean pT for a given set
00042 // of parameters, for a parameterization that was set with UseParameterization.
00043 //
00044 // Revision 1.2  2006/01/30 20:57:56  zarko
00045 // Removed one parameter from SKZP (par[2])
00046 // Redefined par[3] (low pT) and par[4] (kaons) in SKZP,
00047 // and par[5] (kaons) in TV, so that they are just numbers.
00048 // They are not multiplicative factors of sigma distortions any more.
00049 //
00050 //
00051 
00052 #include "MCReweight/Zfluk.h"
00053 #include "MessageService/MsgService.h"
00054 
00055 #include <string>
00056 #include <iostream>
00057 #include <cmath>
00058 #include <cstdlib>
00059 #include <cassert>
00060 #include "TFile.h"
00061 #include "TH2F.h"
00062 #include "TSystem.h"
00063 ClassImp(Zfluk)
00064 
00065 CVSID("$Id: Zfluk.cxx,v 1.10 2007/03/03 21:27:05 zarko Exp $");
00066 
00067 Zfluk::Zfluk(const char* dir) 
00068   :fPar(0)
00069 { 
00070   whichParameterization=0; //by default using SKZP parameterization
00071 
00072   // topDir is where the fluka05 pt-xf histogram file is
00073   std::string topDir=dir; // user may set location of input data
00074   if(topDir=="") { // by default, this code looks in a standard place
00075     topDir="MCReweight/data";
00076     std::string base="";
00077     base=getenv("SRT_PRIVATE_CONTEXT");
00078     if (base!="" && base!=".")
00079       {
00080         // check if directory exists in SRT_PRIVATE_CONTEXT
00081         std::string path = base + "/" + topDir;
00082         void *dir_ptr = gSystem -> OpenDirectory(path.c_str());
00083         if(!dir_ptr) base=getenv("SRT_PUBLIC_CONTEXT"); // if it doesn't exist then use SRT_PUBLIC_CONTEXT
00084       }
00085     else base=getenv("SRT_PUBLIC_CONTEXT");
00086     
00087     if(base=="") {
00088       MSG("MCReweight",Msg::kFatal)<<"No SRT_PUBLIC_CONTEXT set"<<std::endl;
00089       assert(false);
00090     }
00091     topDir = base+ "/" + topDir;
00092   }
00093 
00094   MSG("Zfluk",Msg::kDebug) <<"Zfluk reading data from: "<<topDir<<std::endl;
00095   std::string fileName =topDir+"/fluka05ptxf.root";
00096 
00097   TFile* hFile=new TFile(fileName.c_str());
00098   
00099   fPlist.push_back(kPiPlus);
00100   fPlist.push_back(kPiMinus);
00101   fPlist.push_back(kKPlus);
00102   fPlist.push_back(kKMinus);
00103   fPlist.push_back(kK0L);
00104   
00105   for (std::vector<ParticleType_t>::iterator itPlist=fPlist.begin();itPlist!=fPlist.end(); itPlist++)
00106     {
00107       TH2F* hist=dynamic_cast <TH2F*> (hFile->Get(Form("hF05ptxf%s",GetParticleName(*itPlist).c_str()))->Clone());
00108       hist->SetDirectory(0);
00109       TH2F* hist2=dynamic_cast <TH2F*> (hist->Clone(Form("hWeightedPTXF%s",GetParticleName(*itPlist).c_str())));
00110       hist2->SetDirectory(0);
00111       hist2->SetTitle(Form("%s weighted pt-pz",GetParticleName(*itPlist).c_str()));
00112       fWeightHist[*itPlist]=dynamic_cast<TH2F*> (hist->Clone(Form("hWeight%s",GetParticleName(*itPlist).c_str())));
00113 
00114       fWeightHist[*itPlist]->Divide(hist2);
00115       fWeightHist[*itPlist]->SetDirectory(0);
00116 
00117       std::pair<Zfluk::ParticleType_t, TH2F* > p(*itPlist, hist);
00118       std::pair<Zfluk::ParticleType_t, TH2F* > p2(*itPlist, hist2);
00119       fPTXF.insert(p);
00120       fWeightedPTXF.insert(p2);
00121 
00122       fPTXF[*itPlist]->SetDirectory(0);
00123       fWeightedPTXF[*itPlist]->SetDirectory(0);
00124 
00125       fMeanPT[*itPlist]=fPTXF[*itPlist]->ProjectionY()->GetMean()*1000.;
00126       fWeightedMeanPT[*itPlist]=fWeightedPTXF[*itPlist]->ProjectionY()->GetMean()*1000.;
00127             
00128       double N=fPTXF[*itPlist]->ProjectionY()->GetSumOfWeights();
00129       double wN=fWeightedPTXF[*itPlist]->ProjectionY()->GetSumOfWeights();
00130 
00131       fN[*itPlist]=N;
00132       fNWeighted[*itPlist]=wN;
00133     }
00134   hFile->Close();
00135   delete hFile;
00136   hFile=0;
00137 }
00138 
00139 Zfluk::~Zfluk() {
00140 }
00141 
00142 double Zfluk::GetWeight(int ptype, double pT, double pz, double* par)
00143 {
00144   //this was used for PRL (par was an array of 7 parameters
00145   std::vector<double> parVec;
00146   int npar=0;
00147 
00148   if (whichParameterization==0) npar=7;
00149   else npar=6;
00150   
00151   for (int i=0;i<npar;i++) parVec.push_back(par[i]);
00152   //need 16 parameters to call GetWeight(ptype,pT,pz,parVec)
00153   // fill rest of the parameters so that weights for pi- and K- are 1
00154   for (int i=7;i<16;i++) parVec.push_back(double((i-1)%2));
00155   return GetWeight(ptype,pT,pz,parVec);
00156 }
00157 
00158 double Zfluk::GetWeight(int tpType, double pT, double tpz, std::vector<double> par)
00159 {
00160   double xF;
00161   double weight=1.;
00162   if (tpz<0.) return weight;
00163   double A,B,C;
00164   double Ap,Bp,Cp;
00165   xF=tpz/120.;
00166 
00167   // This is SKZP parameterization
00168   if (whichParameterization==0)
00169     {
00170       if (tpType==211||tpType==8)
00171         {
00172           //Calculate weight for pions
00173           if (pT>=0.05)
00174             {
00175               // calculate the A, B and C in SKZP parameterization
00176               // A, B and C are best fit to Fluka 05
00177               
00178               A=-0.00761*pow((1.-xF),4.045)*(1.+9620.*xF)*pow(xF,-2.975);
00179               B=0.05465*pow((1.-xF),2.675)*(1.+69590.*xF)*pow(xF,-3.144);
00180               
00181               if (xF<0.22){
00182                 C=-7.058/pow(xF,-0.1419)+9.188;
00183               }
00184               else{
00185                 C = (3.008/exp((xF-0.1984)*3.577)) + 2.616*xF+0.1225;
00186               }
00187               // scale/skew A, B and C
00188               Ap=(par[0]+par[1]*xF)*A;
00189               Bp=(par[2]+par[3]*xF)*B;
00190               Cp=(par[4]+par[5]*xF)*C;
00191               
00192               weight=(Ap+Bp*pT)/(A+B*pT)*exp(-(Cp-C)*pow(pT,3./2.));
00193             }
00194           else weight=GetWeight(tpType,0.051,tpz,par);  // for low pT
00195         }
00196       else if (tpType==321||tpType==11)
00197         {
00198           //for kaons
00199           weight=par[6]+par[7]*xF;
00200         }
00201       else if (tpType==-211||tpType==9)
00202         {
00203           // calculate the A, B and C in SKZP parameterization
00204           // A, B and C are best fit to Fluka 05
00205           if (pT>=0.05)
00206             {
00207               A=-0.006327*pow((1.-xF),5.734)*(1.+13660.*xF)*pow(xF,-2.898);
00208               B=0.04605*pow((1.-xF),3.291)*(1.+58610.*xF)*pow(xF,-3.209);
00209               
00210               if (xF<0.22){
00211                 C=-16.02/pow(xF,-0.06456)+17.61;
00212               }
00213               else{
00214                 C = (2.963/exp((xF-0.1774)*2.265)) + 1.732*xF+0.03925;
00215               }
00216               
00217               // scale/skew A, B and C
00218               Ap=(par[8]+par[9]*xF)*A;
00219               Bp=(par[10]+par[11]*xF)*B;
00220               Cp=(par[12]+par[13]*xF)*C;
00221               
00222               weight=(Ap+Bp*pT)/(A+B*pT)*exp(-(Cp-C)*pow(pT,3./2.));
00223             }
00224           else weight=GetWeight(tpType,0.051,tpz,par);  // for low pT
00225           
00226         }
00227       else if (tpType==-321||tpType==12)
00228         {
00229           //for kaons
00230           weight=par[14]+par[15]*xF;
00231         }
00232     }
00233   else if (whichParameterization==1)
00234     {
00235       // This is TV parameterization
00236       if (tpType==211||tpType==8){
00237  
00238         weight=par[0]*(1.+par[1]*pT)/(1.+par[2]*pT)*
00239                exp(-par[3]*tpz*pow(pT,par[4]));
00240  
00241       }
00242       else if (tpType==321||tpType==11) {
00243         weight=par[5];
00244       }
00245       
00246     }
00247   else
00248     {
00249       MSG("MCReweight",Msg::kError) << "Please select one of the two hadron production"<<std::endl;
00250       MSG("MCReweight",Msg::kError) << " parameterizations (SKZP (default) or TV)"<<std::endl;
00251       return 0.;;
00252     }
00253   return weight;
00254 }
00255 
00256 double Zfluk::GetWeight(int ptype, double pT, double pz)
00257 {
00258   double weight=1.;
00259 
00260   if (fPar.size()==0) 
00261     {
00262       MAXMSG("MCReweight",Msg::kWarning,10)
00263         <<"You need to set the parameters before calling "
00264         <<"Zfluk::GetWeight (use SetParameters(vector<double>))"<<std::endl
00265         <<"Returning weight = "<<weight<<std::endl;
00266       return weight;
00267     }
00268 
00269   double xF=pz/120.;
00270   double A,B,C;
00271   double Ap,Bp,Cp;
00272   Zfluk::ParticleType_t eptype=GetParticleEnum(ptype);
00273 
00274   // This is SKZP parameterization
00275   if (xF>1.||xF<0.) return weight;
00276   if (pT>1.||pT<0.) return weight;
00277 
00278   if (eptype==kPiPlus)
00279     {
00280       //Calculate weight for pions
00281       if (pT>=0.03)
00282         {
00283           // calculate the A, B and C in SKZP parameterization
00284           // A, B and C are best fit to Fluka 05
00285           
00286           A=-0.00761*pow((1.-xF),4.045)*(1.+9620.*xF)*pow(xF,-2.975);
00287           B=0.05465*pow((1.-xF),2.675)*(1.+69590.*xF)*pow(xF,-3.144);
00288           
00289           if (xF<0.22){
00290             C=-7.058/pow(xF,-0.1419)+9.188;
00291           }
00292           else{
00293             C = (3.008/exp((xF-0.1984)*3.577)) + 2.616*xF+0.1225;
00294           }
00295           
00296           // scale/skew A, B and C
00297           Ap=(fPar[0]+fPar[1]*xF)*A;
00298           Bp=(fPar[2]+fPar[3]*xF)*B;
00299           Cp=(fPar[4]+fPar[5]*xF)*C;
00300             
00301           weight=(Ap+Bp*pT)/(A+B*pT)*exp(-(Cp-C)*pow(pT,3./2.));
00302         }
00303       else weight=GetWeight(ptype,0.031,pz);  // for low pT
00304     }
00305   else if (eptype==kKPlus)
00306     {
00307       if (pT>=0.05)
00308         {
00309           // calculate the A, B and C in SKZP parameterization
00310           // A, B and C are best fit to Fluka 05
00311           
00312           A=-0.005187*pow((1.-xF),4.119)*(1.+2170.*xF)*pow(xF,-2.767);
00313           B=0.4918*pow((1.-xF),2.672)*(1.+1373.*xF)*pow(xF,-2.927);
00314           
00315           if (xF<0.22){
00316             C=-16.10/pow(xF,-0.04582)+17.92;
00317           }
00318           else{
00319             C = (6.905/exp((xF+0.163)*6.718)) - 0.4257*xF + 2.486;
00320           }
00321           
00322           // scale/skew A, B and C
00323           Ap=(fPar[6]+fPar[7]*xF)*A;
00324           Bp=(fPar[8]+fPar[9]*xF)*B;
00325           Cp=(fPar[10]+fPar[11]*xF)*C;
00326 
00327           weight=(Ap+Bp*pT)/(A+B*pT)*exp(-(Cp-C)*pow(pT,3./2.));
00328         }
00329       else 
00330         weight=GetWeight(ptype,0.051,pz);  // for low pT
00331     }
00332   else if (eptype==kPiMinus)
00333     {
00334       weight=GetWeight(kPiPlus,pT,pz);
00335       if ( pz > 4. ) weight *= ( fPar[12] + fPar[13] * xF );
00336     }
00337   else if (eptype==kKMinus)
00338     {
00339       weight=GetWeight(kKPlus,pT,pz)*(fPar[14]+fPar[15]*xF);
00340     }
00341   else if (eptype==kK0L)
00342     {
00343       //N(K0L) approximately given with (N(K+)+3*N(K-))/4
00344       weight= ((fNWeighted[kKPlus]+3.*fNWeighted[kKMinus])
00345                /(fN[kKPlus]+3.*fN[kKMinus]));
00346     }
00347   if (weight>10.) weight=10.;
00348   return weight;
00349 }
00350 
00351 void Zfluk::RecalculateWeights()
00352 {
00353   
00354   for (std::vector<ParticleType_t>::iterator itPlist=fPlist.begin();
00355        itPlist!=fPlist.end(); itPlist++)
00356     {
00357       double xf,pt;
00358       double meanpt(0.);
00359       double sum(0.);
00360       for (int i=0;i<fPTXF[*itPlist]->GetNbinsX()+1;i++)
00361         {
00362           for (int j=0;j<fPTXF[*itPlist]->GetNbinsY()+1;j++)
00363             {
00364               xf=fPTXF[*itPlist]->GetXaxis()->GetBinCenter(i);
00365               pt=fPTXF[*itPlist]->GetYaxis()->GetBinCenter(j);
00366               fWeightedPTXF[*itPlist]
00367                 ->SetBinContent(i,j,(fPTXF[*itPlist]->GetBinContent(i,j)
00368                                      *GetWeight(*itPlist,pt,xf)));
00369               fWeightHist[*itPlist]->SetBinContent(i,j,GetWeight(*itPlist,pt,xf));
00370               meanpt+=fWeightedPTXF[*itPlist]->GetBinContent(i,j)*pt;
00371               sum+=fWeightedPTXF[*itPlist]->GetBinContent(i,j);
00372             }
00373         }
00374       meanpt/=sum;
00375       fWeightedMeanPT[*itPlist]=meanpt*1000.; //GeV to MeV
00376       fNWeighted[*itPlist]=sum;
00377       meanpt=0.;
00378       sum=0.;
00379     }
00380 }
00381 
00382 double Zfluk::GetPTshift(int ptype, double pz_low, double pz_up)
00383 {
00384   //returns the pT shift for ptype particle due to reweighting in xf slice
00385   //given by pz_low and pz_up
00386   //this function returns correct ptshift only if the parameters were set using SetParameters
00387 
00388   Zfluk::ParticleType_t eptype=GetParticleEnum(ptype);
00389 
00390   if (fPTXF.find(eptype)==fPTXF.end())
00391     {
00392       return 0.;
00393     }
00394   if (pz_low==0.&&pz_up==120.) return fWeightedMeanPT[eptype]-fMeanPT[eptype];
00395  
00396   int xlow=int(pz_low+1.);
00397   int xup=int(pz_up+1.);
00398  
00399   double pt;
00400   double meanpt(0.);
00401   double sum(0.);
00402   for (int i=xlow;i<xup;i++)
00403     {
00404       for (int j=1;j<51;j++)
00405         {
00406           pt=0.02*j-0.01;
00407           meanpt+=fWeightedPTXF[eptype]->GetBinContent(i,j)*pt;
00408           sum+=fWeightedPTXF[eptype]->GetBinContent(i,j);
00409         }
00410     }
00411   meanpt/=sum;
00412   meanpt*=1000.;  //GeV to MeV
00413 
00414   return meanpt-fMeanPT[eptype];
00415 
00416 }
00417 double Zfluk::GetNFrac(int ptype, double pz_low, double pz_up, double pt_low, double pt_up)
00418 {
00419   //returns the fractional change in number of particles due to reweighting in xf-pt region 
00420   //given by pz_low, pz_up and pt_low, pt_up
00421   
00422   Zfluk::ParticleType_t eptype=GetParticleEnum(ptype);
00423   if (fPTXF.find(eptype)==fPTXF.end())
00424     {
00425       return 1.;
00426     }
00427   int xlow=int(pz_low+1.);
00428   int xup=int(pz_up+1.);
00429   int ylow=int(50.*pt_low+1.);
00430   int yup=int(50.*pt_up+1.);
00431   
00432   double wsum(0.);
00433   double sum(0.);
00434   for (int i=xlow;i<xup;i++)
00435     {
00436       for (int j=ylow;j<yup;j++)
00437         {
00438           sum+=fPTXF[eptype]->GetBinContent(i,j);
00439           wsum+=fWeightedPTXF[eptype]->GetBinContent(i,j);
00440         }
00441     }
00442 
00443   return wsum/sum;
00444 }
00445 
00446 std::string Zfluk::GetParticleName(Zfluk::ParticleType_t ptype)
00447 {
00448 switch (ptype)
00449    {
00450    case kPiPlus:          return "PiPlus";    break;
00451    case kPiMinus:         return "PiMinus";   break;
00452    case kKPlus:           return "KPlus";     break;
00453    case kKMinus:          return "KMinus";    break;
00454    case kK0L:             return "K0L";       break;
00455    case kUnknown:         return "Unknown";   break;
00456    default:               return "Unknown";   break;
00457    }
00458  
00459    return "Unknown";
00460 }
00461 
00462 Zfluk::ParticleType_t Zfluk::GetParticleEnum(int ptype)
00463 {
00464   switch (ptype)
00465     {
00466     case 8   :       return kPiPlus;      break;
00467     case 211 :       return kPiPlus;      break;    
00468     case 9   :       return kPiMinus;     break;
00469     case -211:       return kPiMinus;     break;
00470     case 11  :       return kKPlus;       break;
00471     case 321 :       return kKPlus;       break;
00472     case 12  :       return kKMinus;      break;
00473     case -321:       return kKMinus;      break;
00474     case 10  :       return kK0L;         break;
00475     case 130 :       return kK0L;         break;
00476     default:         return kUnknown;     break;
00477     }
00478   return kUnknown;
00479 
00480 }

Generated on Thu Nov 1 11:53:49 2007 for loon by  doxygen 1.3.9.1