]> git.uio.no Git - u/mrichter/AliRoot.git/blob - PWGCF/Correlations/JCORRAN/AliJEfficiency.cxx
Merge branch 'feature-movesplit'
[u/mrichter/AliRoot.git] / PWGCF / Correlations / JCORRAN / AliJEfficiency.cxx
1 #include "AliJEfficiency.h"
2 #include <TSystem.h>
3 #include <iostream>
4 #include <TGrid.h>
5
6 // AliJEfficiency
7 // ...
8 // ...
9 // ...
10 // ...
11 // TODO
12
13 using namespace std;
14
15 AliJEfficiency::AliJEfficiency():
16   fMode(kAuto),
17   fPeriod(-1),
18   fTrackCut(),
19   fRunTable(),
20   fDataPath(""),
21   fName(""),
22   fPeriodStr(""),
23   fMCPeriodStr(""),
24   fRunNumber(0),
25   fTag(""),
26   fInputRootName(""),
27   fInputRoot(NULL),
28   fCentBin(0x0)
29 {
30
31 }
32
33 AliJEfficiency::AliJEfficiency(const AliJEfficiency& obj) :
34   fMode(obj.fMode),
35   fPeriod(obj.fPeriod),
36   fTrackCut(obj.fTrackCut),
37   fRunTable(obj.fRunTable),
38   fDataPath(obj.fDataPath),
39   fName(obj.fName),
40   fPeriodStr(obj.fPeriodStr),
41   fMCPeriodStr(obj.fMCPeriodStr),
42   fRunNumber(obj.fRunNumber),
43   fTag(obj.fTag),
44   fInputRootName(obj.fInputRootName),
45   fInputRoot(obj.fInputRoot),
46   fCentBin(obj.fCentBin)
47 {
48   // copy constructor TODO: handling of pointer members
49   JUNUSED(obj);
50 }
51
52 AliJEfficiency& AliJEfficiency::operator=(const AliJEfficiency& obj){
53   // equal sign operator TODO: content
54   JUNUSED(obj);
55   return *this;
56 }
57
58 TString AliJEfficiency::GetEffName() {
59   /*
60      1. kNotUse : no Load, efficiency is 1 always
61      2. has fInputRootName : Load that or crash
62      3. has fName : Load fName [+runnumber] or crash
63      4. has runnumber : Find Good MC period from AliJRunTable, or crash
64      3. has period : Find Good MC period from AliJRunTable, or crash
65
66 */
67   if( fMode == kNotUse ) {
68     cout<<"J_WARNING : Eff Mode is \"NOTUSE\". eff is 1 !!!"<<endl;
69     return "";
70   }
71
72   //==== 1. fInputRootName
73   //==== 2. Eff-fName-fPeriod-fMCPeriod-fRunNumber-fTag.root
74   if( fInputRootName.Length() == 0 ){
75
76     //==== SELECT Period : fPeriod, fPeriodStr
77     // 1. Use fPeriodStr if it is
78     // 2. Use fPeriod    if it is
79     // 3. Use RunNumber
80     if( fPeriodStr.Length() == 0 ){
81       if( fRunNumber > 0  && fPeriod < 0 ) {
82         fPeriod = fRunTable.GetRunNumberToPeriod( fRunNumber );
83       }
84       fPeriodStr = fRunTable.GetPeriodName( fPeriod );
85     }
86     //==== Select McPeriod
87     //==== 1. Use fMCPeriodStr
88     //==== 2. Use fPeriod
89     if( fMCPeriodStr.Length() == 0 ){
90       fMCPeriodStr =  fRunTable.GetMCPeriod( fPeriod );
91     }
92     //==== Select fRunNumber
93     //==== MODE 1 : runnumber = 0;
94     if( fMode == kPeriod ) fRunNumber = 0;
95     else if( fRunNumber < 0 ){
96       cout<< "J_ERROR : Runumber must be >=0. Input runnumber is "<<fRunNumber<<endl;
97       gSystem->Exit(1);
98     }
99
100     fInputRootName = Form("Eff-%s-%s-%s-%d-%s.root", fName.Data(), fPeriodStr.Data(), fMCPeriodStr.Data(), int(fRunNumber), fTag.Data() );
101   }
102
103   return fInputRootName;
104 }
105
106 TString AliJEfficiency::GetEffFullName() {
107   GetEffName();
108   fInputRootName = fDataPath + "/" + fInputRootName;
109   return fInputRootName;
110 }
111
112
113 bool AliJEfficiency::Load(){
114   // Load Efficiency File based on fMode
115   if( fMode == kNotUse ) {
116     cout<<"J_WARNING : Eff Mode is \"NOTUSE\". eff is 1 !!!"<<endl;
117     return true;
118   }
119   GetEffFullName();
120   if (TString(fInputRootName).BeginsWith("alien:"))  TGrid::Connect("alien:");
121   fInputRoot = TFile::Open( fInputRootName);
122   //fInputRoot = new TFile( fInputRootName,"READ");
123   if( !fInputRoot ) {
124           cout<< "J_ERROR : "<<fInputRootName <<" is not exist"<<endl;
125           gSystem->Exit(1);
126   }
127
128   //fEffDir[0] = (TDirectory*)fInputRoot->Get("EffRE");
129   ///fEffDir[1] = (TDirectory*)fInputRoot->Get("EffMC");
130   fEffDir[2] = (TDirectory*)fInputRoot->Get("Efficiency");
131   //iif( fEffDir[0] && fEffDir[1] && fEffDir[2] )
132   if( !fEffDir[2] )
133   {
134           cout<< "J_ERROR : Directory EFF is not exist"<<endl;
135           gSystem->Exit(1);
136   }
137
138   fCentBin = (TAxis*)fEffDir[2]->Get("CentralityBin");
139   if( !fCentBin ){
140           cout<< "J_ERROR : No CentralityBin in directory"<<endl;
141           gSystem->Exit(1);
142   }
143
144
145   int nVtx = 1;
146   int nCentBin = fCentBin->GetNbins();
147   for( int ivtx=0;ivtx<nVtx;ivtx++ ){
148           for( int icent=0;icent<nCentBin;icent++ ){
149                   for( int icut=0;icut<fTrackCut.GetNCut();icut++ ){
150                           fCorrection[ivtx][icent][icut] 
151                                   = (TGraphErrors*) fEffDir[2]->Get(Form("gCor%02d%02d%02d", ivtx,icent,icut));
152                           //cout<<"J_LOG : Eff graph - "<<Form("gCor%02d%02d%02d", ivtx,icent,icut)<<" - "<<g<<endl;
153                   }
154           }
155   }
156   cout<<"J_LOG : Eff file is "<<fInputRootName<<endl;
157   cout<<"J_LOG : Eff Cent Bins are ";
158   for( int i=0;i<=nCentBin;i++ ){
159           cout<<fCentBin->GetXbins()->At(i)<<" ";
160   }
161   cout<<endl;
162   return true;
163 }
164
165 double AliJEfficiency::GetCorrection( double pt, int icut , double cent ) const {
166         // TODO : Function mode
167         if( fMode == kNotUse ) return 1;
168         int icent = fCentBin->FindBin( cent ) -1 ;
169         if( icent < 0 || icent > fCentBin->GetNbins()-1 ) {
170                 cout<<"J_WARNING : Centrality "<<cent<<" is out of CentBinBorder"<<endl;
171                 return 1;
172         }
173         // TODO error check for icent;
174         int ivtx = 0;
175         if( ! fCorrection[ivtx][icent][icut] ) {
176                 cout<<"J_WARNING : No Eff Info "<<pt<<"\t"<<icut<<"\t"<<cent<<"\t"<<icent<<endl;
177                 return 1;
178         }
179         TGraphErrors * gr = fCorrection[ivtx][icent][icut];
180         //=== TEMPERORY SETTING. IT will be removed soon.
181         if( pt > 30 ) pt = 30; // Getting eff of 30GeV for lager pt
182         double cor = gr->Eval(pt);
183         if ( cor < 0.2 ) cor = 0.2;
184         return cor;
185 }
186
187 void AliJEfficiency::Write(){
188         // Write Efficiency information to root file 
189         if( fMode == kNotUse ){
190                 cout<<"J_LOG : Efficiency mode is \"NotUse\", nothing will be Written" <<endl;
191                 return;
192         }
193         cout<<"J_LOG : Efficiency Write to "<<gDirectory->GetName()<<endl;
194         TDirectory *cwd = gDirectory;
195         TDirectory *eff = gDirectory->mkdir("Efficiency");
196         eff->cd();
197         int nVtx = 1;
198         int nCentBin = fCentBin->GetNbins();
199         cout<<nCentBin<<endl;
200         for( int ivtx=0;ivtx<nVtx;ivtx++ ){
201                 for( int icent=0;icent<nCentBin;icent++ ){
202                         for( int icut=0;icut<fTrackCut.GetNCut();icut++ ){
203                                 cout<<fCorrection[ivtx][icent][icut]<<endl;
204                                 if( !fCorrection[ivtx][icent][icut]) continue;
205                                 fCorrection[ivtx][icent][icut]->Write(Form("gCor%02d%02d%02d", ivtx,icent,icut));
206                         }
207                 }
208         }
209         fCentBin->Write("CentralityBin");
210         cwd->cd();
211 }
212