]> git.uio.no Git - u/mrichter/AliRoot.git/blob - PWGCF/Correlations/JCORRAN/AliJEfficiency.cxx
JCORRAN code update from DongJo
[u/mrichter/AliRoot.git] / PWGCF / Correlations / JCORRAN / AliJEfficiency.cxx
1 #include "AliJEfficiency.h"
2 #include <TSystem.h>
3 #include <iostream>
4
5 // AliJEfficiency
6 // ...
7 // ...
8 // ...
9 // ...
10 // TODO
11
12 using namespace std;
13
14 AliJEfficiency::AliJEfficiency():
15   fMode(kAuto),
16   fPeriod(-1),
17   fTrackCut(),
18   fRunTable(),
19   fDataPath("$ALICE_ROOT/PWGCF/Correlations/macros/jcorran"),
20   fName(""),
21   fPeriodStr(""),
22   fMCPeriodStr(""),
23   fRunNumber(0),
24   fTag(""),
25   fInputRootName(""),
26   fInputRoot(NULL),
27   fCentBin(0x0)
28 {
29
30 }
31
32 AliJEfficiency::AliJEfficiency(const AliJEfficiency& obj) :
33   fMode(obj.fMode),
34   fPeriod(obj.fPeriod),
35   fTrackCut(obj.fTrackCut),
36   fRunTable(obj.fRunTable),
37   fDataPath(obj.fDataPath),
38   fName(obj.fName),
39   fPeriodStr(obj.fPeriodStr),
40   fMCPeriodStr(obj.fMCPeriodStr),
41   fRunNumber(obj.fRunNumber),
42   fTag(obj.fTag),
43   fInputRootName(obj.fInputRootName),
44   fInputRoot(obj.fInputRoot),
45   fCentBin(obj.fCentBin)
46 {
47   // copy constructor TODO: handling of pointer members
48   JUNUSED(obj);
49 }
50
51 AliJEfficiency& AliJEfficiency::operator=(const AliJEfficiency& obj){
52   // equal sign operator TODO: content
53   JUNUSED(obj);
54   return *this;
55 }
56
57 TString AliJEfficiency::GetEffName() {
58   /*
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
64
65 */
66   if( fMode == kNotUse ) {
67     cout<<"J_WARNING : Eff Mode is \"NOTUSE\". eff is 1 !!!"<<endl;
68     return "";
69   }
70
71   //==== 1. fInputRootName
72   //==== 2. Eff-fName-fPeriod-fMCPeriod-fRunNumber-fTag.root
73   if( fInputRootName.Length() == 0 ){
74
75     //==== SELECT Period : fPeriod, fPeriodStr
76     // 1. Use fPeriodStr if it is
77     // 2. Use fPeriod    if it is
78     // 3. Use RunNumber
79     if( fPeriodStr.Length() == 0 ){
80       if( fRunNumber > 0  && fPeriod < 0 ) {
81         fPeriod = fRunTable.GetRunNumberToPeriod( fRunNumber );
82       }
83       fPeriodStr = fRunTable.GetPeriodName( fPeriod );
84     }
85     //==== Select McPeriod
86     //==== 1. Use fMCPeriodStr
87     //==== 2. Use fPeriod
88     if( fMCPeriodStr.Length() == 0 ){
89       fMCPeriodStr =  fRunTable.GetMCPeriod( fPeriod );
90     }
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;
96       gSystem->Exit(1);
97     }
98
99     fInputRootName = Form("Eff-%s-%s-%s-%d-%s.root", fName.Data(), fPeriodStr.Data(), fMCPeriodStr.Data(), int(fRunNumber), fTag.Data() );
100   }
101
102   return fInputRootName;
103 }
104
105 TString AliJEfficiency::GetEffFullName() {
106   GetEffName();
107   fInputRootName = fDataPath + "/" + fInputRootName;
108   return fInputRootName;
109 }
110
111
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;
116     return true;
117   }
118   GetEffFullName();
119   fInputRoot = new TFile( fInputRootName,"READ");
120   if( !fInputRoot ) {
121     cout<< "J_ERROR : "<<fInputRootName <<" is not exist"<<endl;
122     gSystem->Exit(1);
123   }
124
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] )
129   if( !fEffDir[2] )
130   {
131     cout<< "J_ERROR : Directory EFF is not exist"<<endl;
132     gSystem->Exit(1);
133   }
134
135   fCentBin = (TAxis*)fEffDir[2]->Get("CentralityBin");
136   if( !fCentBin ){
137     cout<< "J_ERROR : No CentralityBin in directory"<<endl;
138     gSystem->Exit(1);
139   }
140
141
142   int nVtx = 1;
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;
150       }
151     }
152   }
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)<<" ";
157   }
158   cout<<endl;
159   return true;
160 }
161
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;
168     return 1;
169   }
170   // TODO error check for icent;
171   int ivtx = 0;
172   if( ! fCorrection[ivtx][icent][icut] ) {
173     cout<<"J_WARNING : No Eff Info "<<pt<<"\t"<<icut<<"\t"<<cent<<"\t"<<icent<<endl;
174     return 1;
175   }
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;
181   return cor;
182 }
183
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;
188     return;
189   }
190   cout<<"J_LOG : Efficiency Write to "<<gDirectory->GetName()<<endl;
191   TDirectory *cwd = gDirectory;
192   TDirectory *eff = gDirectory->mkdir("Efficiency");
193   eff->cd();
194   int nVtx = 1;
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));
203       }
204     }
205   }
206   fCentBin->Write("CentralityBin");
207   cwd->cd();
208 }
209