1 #include "AliJEfficiency.h"
15 AliJEfficiency::AliJEfficiency():
33 AliJEfficiency::AliJEfficiency(const AliJEfficiency& obj) :
36 fTrackCut(obj.fTrackCut),
37 fRunTable(obj.fRunTable),
38 fDataPath(obj.fDataPath),
40 fPeriodStr(obj.fPeriodStr),
41 fMCPeriodStr(obj.fMCPeriodStr),
42 fRunNumber(obj.fRunNumber),
44 fInputRootName(obj.fInputRootName),
45 fInputRoot(obj.fInputRoot),
46 fCentBin(obj.fCentBin)
48 // copy constructor TODO: handling of pointer members
52 AliJEfficiency& AliJEfficiency::operator=(const AliJEfficiency& obj){
53 // equal sign operator TODO: content
58 TString AliJEfficiency::GetEffName() {
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
67 if( fMode == kNotUse ) {
68 cout<<"J_WARNING : Eff Mode is \"NOTUSE\". eff is 1 !!!"<<endl;
72 //==== 1. fInputRootName
73 //==== 2. Eff-fName-fPeriod-fMCPeriod-fRunNumber-fTag.root
74 if( fInputRootName.Length() == 0 ){
76 //==== SELECT Period : fPeriod, fPeriodStr
77 // 1. Use fPeriodStr if it is
78 // 2. Use fPeriod if it is
80 if( fPeriodStr.Length() == 0 ){
81 if( fRunNumber > 0 && fPeriod < 0 ) {
82 fPeriod = fRunTable.GetRunNumberToPeriod( fRunNumber );
84 fPeriodStr = fRunTable.GetPeriodName( fPeriod );
86 //==== Select McPeriod
87 //==== 1. Use fMCPeriodStr
89 if( fMCPeriodStr.Length() == 0 ){
90 fMCPeriodStr = fRunTable.GetMCPeriod( fPeriod );
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;
100 fInputRootName = Form("Eff-%s-%s-%s-%d-%s.root", fName.Data(), fPeriodStr.Data(), fMCPeriodStr.Data(), int(fRunNumber), fTag.Data() );
103 return fInputRootName;
106 TString AliJEfficiency::GetEffFullName() {
108 fInputRootName = fDataPath + "/" + fInputRootName;
109 return fInputRootName;
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;
120 if (TString(fInputRootName).BeginsWith("alien:")) TGrid::Connect("alien:");
121 fInputRoot = TFile::Open( fInputRootName);
122 //fInputRoot = new TFile( fInputRootName,"READ");
124 cout<< "J_ERROR : "<<fInputRootName <<" is not exist"<<endl;
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] )
134 cout<< "J_ERROR : Directory EFF is not exist"<<endl;
138 fCentBin = (TAxis*)fEffDir[2]->Get("CentralityBin");
140 cout<< "J_ERROR : No CentralityBin in directory"<<endl;
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;
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)<<" ";
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;
173 // TODO error check for icent;
175 if( ! fCorrection[ivtx][icent][icut] ) {
176 cout<<"J_WARNING : No Eff Info "<<pt<<"\t"<<icut<<"\t"<<cent<<"\t"<<icent<<endl;
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;
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;
193 cout<<"J_LOG : Efficiency Write to "<<gDirectory->GetName()<<endl;
194 TDirectory *cwd = gDirectory;
195 TDirectory *eff = gDirectory->mkdir("Efficiency");
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));
209 fCentBin->Write("CentralityBin");