1 #include "AliJEfficiency.h"
14 AliJEfficiency::AliJEfficiency():
19 fDataPath("$ALICE_ROOT/PWGCF/Correlations/macros/jcorran"),
32 AliJEfficiency::AliJEfficiency(const AliJEfficiency& obj) :
35 fTrackCut(obj.fTrackCut),
36 fRunTable(obj.fRunTable),
37 fDataPath(obj.fDataPath),
39 fPeriodStr(obj.fPeriodStr),
40 fMCPeriodStr(obj.fMCPeriodStr),
41 fRunNumber(obj.fRunNumber),
43 fInputRootName(obj.fInputRootName),
44 fInputRoot(obj.fInputRoot),
45 fCentBin(obj.fCentBin)
47 // copy constructor TODO: handling of pointer members
51 AliJEfficiency& AliJEfficiency::operator=(const AliJEfficiency& obj){
52 // equal sign operator TODO: content
57 TString AliJEfficiency::GetEffName() {
59 1. kNotUse : no Load, efficiency is 1 always
60 2. has fInputRootName : Load that or crash
61 3. has fName : Load fName [+runnumber] or crash
62 4. has runnumber : Find Good MC period from AliJRunTable, or crash
63 3. has period : Find Good MC period from AliJRunTable, or crash
66 if( fMode == kNotUse ) {
67 cout<<"J_WARNING : Eff Mode is \"NOTUSE\". eff is 1 !!!"<<endl;
71 //==== 1. fInputRootName
72 //==== 2. Eff-fName-fPeriod-fMCPeriod-fRunNumber-fTag.root
73 if( fInputRootName.Length() == 0 ){
75 //==== SELECT Period : fPeriod, fPeriodStr
76 // 1. Use fPeriodStr if it is
77 // 2. Use fPeriod if it is
79 if( fPeriodStr.Length() == 0 ){
80 if( fRunNumber > 0 && fPeriod < 0 ) {
81 fPeriod = fRunTable.GetRunNumberToPeriod( fRunNumber );
83 fPeriodStr = fRunTable.GetPeriodName( fPeriod );
85 //==== Select McPeriod
86 //==== 1. Use fMCPeriodStr
88 if( fMCPeriodStr.Length() == 0 ){
89 fMCPeriodStr = fRunTable.GetMCPeriod( fPeriod );
91 //==== Select fRunNumber
92 //==== MODE 1 : runnumber = 0;
93 if( fMode == kPeriod ) fRunNumber = 0;
94 else if( fRunNumber < 0 ){
95 cout<< "J_ERROR : Runumber must be >=0. Input runnumber is "<<fRunNumber<<endl;
99 fInputRootName = Form("Eff-%s-%s-%s-%d-%s.root", fName.Data(), fPeriodStr.Data(), fMCPeriodStr.Data(), int(fRunNumber), fTag.Data() );
102 return fInputRootName;
105 TString AliJEfficiency::GetEffFullName() {
107 fInputRootName = fDataPath + "/" + fInputRootName;
108 return fInputRootName;
112 bool AliJEfficiency::Load(){
113 // Load Efficiency File based on fMode
114 if( fMode == kNotUse ) {
115 cout<<"J_WARNING : Eff Mode is \"NOTUSE\". eff is 1 !!!"<<endl;
119 fInputRoot = new TFile( fInputRootName,"READ");
121 cout<< "J_ERROR : "<<fInputRootName <<" is not exist"<<endl;
125 //fEffDir[0] = (TDirectory*)fInputRoot->Get("EffRE");
126 ///fEffDir[1] = (TDirectory*)fInputRoot->Get("EffMC");
127 fEffDir[2] = (TDirectory*)fInputRoot->Get("Efficiency");
128 //iif( fEffDir[0] && fEffDir[1] && fEffDir[2] )
131 cout<< "J_ERROR : Directory EFF is not exist"<<endl;
135 fCentBin = (TAxis*)fEffDir[2]->Get("CentralityBin");
137 cout<< "J_ERROR : No CentralityBin in directory"<<endl;
143 int nCentBin = fCentBin->GetNbins();
144 for( int ivtx=0;ivtx<nVtx;ivtx++ ){
145 for( int icent=0;icent<nCentBin;icent++ ){
146 for( int icut=0;icut<fTrackCut.GetNCut();icut++ ){
147 fCorrection[ivtx][icent][icut]
148 = (TGraphErrors*) fEffDir[2]->Get(Form("gCor%02d%02d%02d", ivtx,icent,icut));
149 //cout<<"J_LOG : Eff graph - "<<Form("gCor%02d%02d%02d", ivtx,icent,icut)<<" - "<<g<<endl;
153 cout<<"J_LOG : Eff file is "<<fInputRootName<<endl;
154 cout<<"J_LOG : Eff Cent Bins are ";
155 for( int i=0;i<=nCentBin;i++ ){
156 cout<<fCentBin->GetXbins()->At(i)<<" ";
162 double AliJEfficiency::GetCorrection( double pt, int icut , double cent ) const {
163 // TODO : Function mode
164 if( fMode == kNotUse ) return 1;
165 int icent = fCentBin->FindBin( cent ) -1 ;
166 if( icent < 0 || icent > fCentBin->GetNbins()-1 ) {
167 cout<<"J_WARNING : Centrality "<<cent<<" is out of CentBinBorder"<<endl;
170 // TODO error check for icent;
172 if( ! fCorrection[ivtx][icent][icut] ) {
173 cout<<"J_WARNING : No Eff Info "<<pt<<"\t"<<icut<<"\t"<<cent<<"\t"<<icent<<endl;
176 TGraphErrors * gr = fCorrection[ivtx][icent][icut];
177 //=== TEMPERORY SETTING. IT will be removed soon.
178 if( pt > 30 ) pt = 30; // Getting eff of 30GeV for lager pt
179 double cor = gr->Eval(pt);
180 if ( cor < 0.2 ) cor = 0.2;
184 void AliJEfficiency::Write(){
185 // Write Efficiency information to root file
186 if( fMode == kNotUse ){
187 cout<<"J_LOG : Efficiency mode is \"NotUse\", nothing will be Written" <<endl;
190 cout<<"J_LOG : Efficiency Write to "<<gDirectory->GetName()<<endl;
191 TDirectory *cwd = gDirectory;
192 TDirectory *eff = gDirectory->mkdir("Efficiency");
195 int nCentBin = fCentBin->GetNbins();
196 cout<<nCentBin<<endl;
197 for( int ivtx=0;ivtx<nVtx;ivtx++ ){
198 for( int icent=0;icent<nCentBin;icent++ ){
199 for( int icut=0;icut<fTrackCut.GetNCut();icut++ ){
200 cout<<fCorrection[ivtx][icent][icut]<<endl;
201 if( !fCorrection[ivtx][icent][icut]) continue;
202 fCorrection[ivtx][icent][icut]->Write(Form("gCor%02d%02d%02d", ivtx,icent,icut));
206 fCentBin->Write("CentralityBin");