ROOT logo
#include "MethodsP.h"

const Double_t kMean=0.135 ; //Approximate peak position to facilitate error estimate
Int_t effcor=0; //correct on efficiency

Double_t PeakPosition(Double_t pt){
  //Fit to the measured peak position
  return 4.99292e-003*exp(-pt*9.32300e-001)+1.34944e-001 ;
}
Double_t PeakWidth(Double_t pt){
  //fit to the measured peak width
  Double_t a=0.0068 ;
  Double_t b=0.0025 ;
  Double_t c=0.000319 ;
  return TMath::Sqrt(a*a+b*b/pt/pt+c*c*pt*pt) ;
}
 
Double_t CB(Double_t * x, Double_t * par){
  //Parameterization of Real/Mixed ratio
  Double_t m=par[1] ;
  Double_t s=par[2] ;
  Double_t dx=(x[0]-m)/s ;
  return par[0]*exp(-dx*dx/2.)+par[3] + par[4]*(x[0]-kMean) ;
}
Double_t CB2(Double_t * x, Double_t * par){
  //Another parameterization of Real/Mixed ratio
  Double_t m=par[1] ;
  Double_t s=par[2] ;
  Double_t dx=(x[0]-m)/s ;
  return par[0]*exp(-dx*dx/2.)+par[3]+par[4]*(x[0]-kMean) + par[5]*(x[0]-kMean)*(x[0]-kMean);
}
Double_t CBs(Double_t * x, Double_t * par){
  //Parameterizatin of signal
  Double_t m=par[1] ;
  Double_t s=par[2] ;
  Double_t dx=(x[0]-m)/s ;
  return par[0]*exp(-dx*dx/2.) ;
}
Double_t BG1(Double_t * x, Double_t * par){
  //Normalizatino of Mixed
  return par[0] ;
}
Double_t BG2(Double_t * x, Double_t * par){
  //Another normalization of  Mixed
  return par[0]+par[1]*(x[0]-kMean) ;
}

void Photon(Int_t cen=0,Int_t side=0){
//side = 1 - VOC, side = 0 - V0A
//side = 2 - TPC 3 sub method, 3 - TPC 2 sub method

  gStyle->SetOptFit(1);

  char kind[15], w[25];
  sprintf(w,""); //Weight: no weight - "NW", with weight - ""

  char PID[25] ;
  sprintf(PID,"Both2core") ;

  char key[55];
  char kind[15],kind2[15] ; //Reaction plane
  char d[15]; //detector
  sprintf(kind,"") ; //"" for real
  sprintf(kind2,"") ; //"" for mixed

  if(side==1)sprintf(d,"V0C");
  else if(side==0)sprintf(d,"V0A");
  else sprintf(d,"TPC");

  TH2F *h2DR, *h2DM;
  h2DR = GetRealMixed(cen,w,d,kind,kind2,PID,1);
  h2DM = GetRealMixed(cen,w,d,kind,kind2,PID,0);

  TH1F * hCen = GetCen() ;
  TH2F * hCenPHOS = GetCenPHOS() ;

  //  sprintf(kind,"") ; //"" for all
  const Int_t nphi=5;
  Double_t xphi[6];
  for(Int_t i=0;i<=nphi;i++)xphi[i]=TMath::PiOver2()*i/nphi ;

  //Read resolution
  TFile * f = new TFile(inname) ;

  TH2F * hcos2AC = (TH2F*)f->Get("cos2V0AC");
  TH2F * hcos2FAC= (TH2F*)f->Get("cos2FAC");
  Double_t resAC = GetCos(hcos2AC,cen);
  resAC=resAC ;

  hcos2AC = (TH2F*)f->Get("cos2V0ATPC");
  Double_t resAT = GetCos(hcos2AC,cen);
  resAT=resAT ;

  hcos2AC = (TH2F*)f->Get("cos2V0CTPC");
  Double_t resCT = GetCos(hcos2AC,cen);
  resCT=resCT ;

  hcos2AC = (TH2F*)f->Get("cos2AC");
  Double_t resT = GetRes(hcos2AC,cen);

  //side = 1 - VOC, side = 0 - V0A
  //side = 2 - TPC 3 sub method, 3 - TPC 2 sub method

  Double_t res=1;
  if(side==1) res = TMath::Sqrt(resAC*resCT/resAT);
  else if(side==0)res = TMath::Sqrt(resAC*resAT/resCT);
  else if(side==2)res = TMath::Sqrt(resAT*resCT/resAC);
  else res = resT;

//  res=1./res ;

  cout<<"res = "<< res <<endl;

//now to the v2 calculation
  
  TH1D * v2A1s= new TH1D("v2 with 2nd harmonic fit","v_{2} 1",nbin,xa) ;
  TH1D * v2A2s= new TH1D("v2 with 4rd harmonic fit","v_{2} 2",nbin,xa) ;
  TH1D * v2Asys= new TH1D("v2 sys","v_{2} sys",nbin,xa) ;
  TH1D * v2Astat= new TH1D("v2 stat","v_{2} stat",nbin,xa) ;

  char key2[155];

  Int_t col[4]={kRed,kBlue,kGreen+3,kMagenta} ;
  Int_t sym[4]={20,21,24,25} ;

  //  TF1 * fit = new TF1("fit","[0]*(1+2.*[1]*cos(2*(x-[2])))",0.,5.) ;
  TF1 * v2fit4 = new TF1("v2fit","[0]*(1+2.*[1]*cos(2.*x)+2.*[2]*cos(4.*x) )",0.,5.) ;
  v2fit->SetLineColor(2) ;
  TF1 * v2fit2 = new TF1("v2fit","[0]*(1+2.*[1]*cos(2.*x) )",0.,5.) ;
  TCanvas * c = new TCanvas("fit","fit") ;
  c->Divide(4,3);

  
  for(Int_t i=1;i<=nbin;i++){
//    h3DR->GetYaxis()->SetRangeUser(xa[i-1],xa[i]) ;
//    Double_t pt=(xa[i]+xa[i-1])/2. ;    
    sprintf(key2,"dNdPhi_%d",i);    
    Int_t iMin=h2DR->GetXaxis()->FindBin(xa[i-1]+0.0001) ;
    Int_t iMax=h2DR->GetXaxis()->FindBin(xa[i]-0.0001) ;

    TH1D * hdNdPhi = (TH1D*)h2DR->ProjectionY(key2,iMin,iMax);
    hdNdPhi->Sumw2();
    c->cd(i);

    hdNdPhi->SetXTitle("#Delta#phi (rad)") ;
    hdNdPhi->SetYTitle("dN/d#phi (a.u.)") ;
    hdNdPhi->SetTitle(Form("pT: %f-%f",xa[i-1],xa[i]));
    hdNdPhi->SetMarkerStyle(sym[0]) ;
    hdNdPhi->SetMarkerColor(col[0]) ;
    
    v2fit2->SetLineStyle(1) ;
    v2fit2->SetLineColor(col[0]) ;
    v2fit2->SetParameters(hdNdPhi->GetBinContent(5),0.1) ;
    hdNdPhi->Fit(v2fit2,"Qi") ;

    v2A1s->SetBinContent(i,v2fit2->GetParameter(1)) ;
    v2A1s->SetBinError(i,v2fit2->GetParError(1)) ;

    sprintf(key2,"dNdPhi2_%d",i);
    TH1D * hdNdPhi2 = hdNdPhi->Clone(key2);

    v2fit4->SetLineStyle(2) ;
    v2fit4->SetLineColor(col[1]) ;
    v2fit4->SetParameters(hdNdPhi2->GetBinContent(5),0.1) ;
    hdNdPhi2->Fit(v2fit4,"Qi") ;

    v2A2s->SetBinContent(i,v2fit4->GetParameter(1)) ;
    v2A2s->SetBinError(i,v2fit4->GetParError(1)) ;

   
    hdNdPhi->Draw() ;
    hdNdPhi2->Draw("same") ;
  }

  TH1D *effcorrect = v2A1s->Clone("effcorrect");
  TH1D *effcorrect2 = v2A1s->Clone("effcorrect2");

  Double_t eff=0, err=0;
  if(strcmp(PID,"Both2core")==0){
        if(cen==0) {eff=.05; err=.04;}
        if(cen==1) {eff=.02; err=.04;}
        if(cen==2) {eff=.02; err=.03;}
        if(cen==3) {eff=.01; err=.02;}
        if(cen==4) {eff=.004; err=.02;}
        if(cen==5) {eff=.004; err=.02;}
        if(cen==10) {eff=.03; err=.02;}
        if(cen==11) {eff=.01; err=.02;}
        if(cen==20) {eff=.02; err=.02;}
        if(cen==21) {eff=.03; err=.02;}

        eff=eff*2.*TMath::Pi()/5./sin(2.*TMath::Pi()/5.)/4.;
        err=err*2.*TMath::Pi()/5./sin(2.*TMath::Pi()/5.)/4.;

cout<<"res: T="<<resT<<", resolution="<<res<<endl;

        eff=eff*res/resT;
        err=err*res/resT;
        cout<<"Pi0 efficiency correction before resolution correction: "<<eff<<"+-"<<err<<endl;
  }

  Double_t x[100],y[100],ex[100],ey[100] ;

  for(Int_t i=0;i<effcorrect->GetNbinsX();i++){
        effcorrect->SetBinContent(i,eff);
        effcorrect->SetBinError(i,err);
        effcorrect2->SetBinContent(i,eff);
        effcorrect2->SetBinError(i,0);
  }

//  v2A1s->Scale(res) ;
//  v2A2s->Scale(res) ;
  
  v2A1s->SetMarkerStyle(sym[0]) ;
  v2A1s->SetMarkerColor(col[0]) ;
  v2A2s->SetMarkerStyle(sym[1]) ;
  v2A2s->SetMarkerColor(col[1]) ;

  TCanvas * c2 = new TCanvas("v2","v2") ;

  char bname[255];

  char cname[255];
  if(cen==0)sprintf(cname,"0-5%%");
  if(cen==1)sprintf(cname,"5-10%%");
  if(cen==2)sprintf(cname,"10-20%%");
  if(cen==3)sprintf(cname,"20-30%%");
  if(cen==4)sprintf(cname,"30-40%%");
  if(cen==5)sprintf(cname,"40-50%%");
  if(cen==10)sprintf(cname,"0-10%%");
  if(cen==11)sprintf(cname,"20-40%%");

  sprintf(bname,"v^{#gamma}_{2}{EP} for centrality %s, EP %s", cname, d);

  TH1D * box = new TH1D("box",bname,100,0.,20.) ;
  box->SetMinimum(-0.1) ;
  box->SetMaximum(0.4) ;
  box->SetXTitle("p_{t}^{#gamma} (GeV/c)") ;
  box->SetYTitle("v_{2}") ;
  box->Draw() ;
  v2A1s->Draw("same") ;
  v2A2s->Draw("same") ;
    
  TLegend * l = new TLegend(0.6,0.7,0.9,0.9) ;
  l->AddEntry(v2A1s,"Fit v2","p") ;
  l->AddEntry(v2A2s,"Fit v2+v4","p") ;

  l->Draw() ;

  for(Int_t i=1; i<=v2A1s->GetNbinsX() ;i++){
    Double_t mean=
      v2A1s->GetBinContent(i)/v2A1s->GetBinError(i)/v2A1s->GetBinError(i)
      +v2A2s->GetBinContent(i)/v2A2s->GetBinError(i)/v2A2s->GetBinError(i);
    Double_t weight=
       1./v2A1s->GetBinError(i)/v2A1s->GetBinError(i)
      +1./v2A2s->GetBinError(i)/v2A2s->GetBinError(i);

     Double_t statErr = TMath::Min(v2A1s->GetBinError(i),v2A2s->GetBinError(i));

    mean/=weight ;
    Double_t rms = (v2A1s->GetBinContent(i)-mean)*(v2A1s->GetBinContent(i)-mean)
/v2A1s->GetBinError(i)/v2A1s->GetBinError(i) + (v2A2s->GetBinContent(i)-mean)*(v2A2s->GetBinContent(i)-mean)/v2A2s->GetBinError(i)/v2A2s->GetBinError(i);
    rms/=weight;   

    v2Astat->SetBinContent(i,mean) ;
    v2Astat->SetBinError(i,statErr) ;
    v2Asys->SetBinContent(i,mean) ;
    v2Asys->SetBinError(i,TMath::Sqrt(rms)) ;

  }

  if(effcor){
        v2Astat->Add(effcorrect2);
        v2Asys->Add(effcorrect);
  }

  v2Asys->Scale(1/res) ;
  v2Astat->Scale(1/res) ;

  TCanvas * c5 = new TCanvas("v2_res","v2 res") ;

  v2Asys->SetFillStyle(1001) ;
  v2Asys->SetFillColor(kYellow) ;
 
  v2Astat->SetMarkerColor(kOrange+7) ;
  v2Astat->SetMarkerStyle(20) ;
  v2Astat->SetLineColor(kOrange+7) ;

  v2Asys->SetXTitle("p_{t} (GeV/c)") ;
  v2Asys->SetYTitle("v_{2}") ;

  box->Draw() ;
  v2Asys->Draw("sameE1") ;
  //  v2Fsys->Draw("E2same") ;
  v2Astat->Draw("same") ;
  //  v2Fstat->Draw("same") ;

  TFile fout("v2_photons.root","update");
  char nname[100];

  sprintf(nname,"v2sys_m1_%s_%s_%d_%d",w,PID,cen,side) ;
  v2Asys->SetName(nname) ;
  sprintf(nname,"v2stat_m1_%s_%s_%d_%d",w,PID,cen,side) ;
  v2Astat->SetName(nname) ;


/*  sprintf(nname,"v2sys_%s_%s_%d",kind,PID,cen) ;
  v2Asys->SetName(nname) ;
  sprintf(nname,"v2stat_%s_%s_%d",kind,PID,cen) ;
  v2Astat->SetName(nname) ;
*/

  v2Asys->Write(0,TObject::kOverwrite) ;
  v2Astat->Write(0,TObject::kOverwrite) ;
  fout.Close() ;
}


//-----------------------------------------------------------------------------
PPRstyle()
{

  //////////////////////////////////////////////////////////////////////
  //
  // ROOT style macro for the TRD TDR
  //
  //////////////////////////////////////////////////////////////////////

  gStyle->SetPalette(1);
  gStyle->SetCanvasBorderMode(-1);
  gStyle->SetCanvasBorderSize(1);
  gStyle->SetCanvasColor(10);

  gStyle->SetFrameFillColor(10);
  gStyle->SetFrameBorderSize(1);
  gStyle->SetFrameBorderMode(-1);
  gStyle->SetFrameLineWidth(1.2);
  gStyle->SetFrameLineColor(1);

  gStyle->SetHistFillColor(0);
  gStyle->SetHistLineWidth(1);
  gStyle->SetHistLineColor(1);

  gStyle->SetPadColor(10);
  gStyle->SetPadBorderSize(1);
  gStyle->SetPadBorderMode(-1);

  gStyle->SetStatColor(10);
  gStyle->SetTitleColor(kBlack,"X");
  gStyle->SetTitleColor(kBlack,"Y");

  gStyle->SetLabelSize(0.04,"X");
  gStyle->SetLabelSize(0.04,"Y");
  gStyle->SetLabelSize(0.04,"Z");
  gStyle->SetTitleSize(0.04,"X");
  gStyle->SetTitleSize(0.04,"Y");
  gStyle->SetTitleSize(0.04,"Z");
  gStyle->SetTitleFont(42,"X");
  gStyle->SetTitleFont(42,"Y");
  gStyle->SetTitleFont(42,"X");
  gStyle->SetLabelFont(42,"X");
  gStyle->SetLabelFont(42,"Y");
  gStyle->SetLabelFont(42,"Z");
  gStyle->SetStatFont(42);

  gStyle->SetTitleOffset(1.0,"X");
  gStyle->SetTitleOffset(1.4,"Y");

  gStyle->SetFillColor(kWhite);
  gStyle->SetTitleFillColor(kWhite);

  gStyle->SetOptDate(0);
  gStyle->SetOptTitle(1);
  gStyle->SetOptStat(0);
  gStyle->SetOptFit(0);

}

 Photon.C:1
 Photon.C:2
 Photon.C:3
 Photon.C:4
 Photon.C:5
 Photon.C:6
 Photon.C:7
 Photon.C:8
 Photon.C:9
 Photon.C:10
 Photon.C:11
 Photon.C:12
 Photon.C:13
 Photon.C:14
 Photon.C:15
 Photon.C:16
 Photon.C:17
 Photon.C:18
 Photon.C:19
 Photon.C:20
 Photon.C:21
 Photon.C:22
 Photon.C:23
 Photon.C:24
 Photon.C:25
 Photon.C:26
 Photon.C:27
 Photon.C:28
 Photon.C:29
 Photon.C:30
 Photon.C:31
 Photon.C:32
 Photon.C:33
 Photon.C:34
 Photon.C:35
 Photon.C:36
 Photon.C:37
 Photon.C:38
 Photon.C:39
 Photon.C:40
 Photon.C:41
 Photon.C:42
 Photon.C:43
 Photon.C:44
 Photon.C:45
 Photon.C:46
 Photon.C:47
 Photon.C:48
 Photon.C:49
 Photon.C:50
 Photon.C:51
 Photon.C:52
 Photon.C:53
 Photon.C:54
 Photon.C:55
 Photon.C:56
 Photon.C:57
 Photon.C:58
 Photon.C:59
 Photon.C:60
 Photon.C:61
 Photon.C:62
 Photon.C:63
 Photon.C:64
 Photon.C:65
 Photon.C:66
 Photon.C:67
 Photon.C:68
 Photon.C:69
 Photon.C:70
 Photon.C:71
 Photon.C:72
 Photon.C:73
 Photon.C:74
 Photon.C:75
 Photon.C:76
 Photon.C:77
 Photon.C:78
 Photon.C:79
 Photon.C:80
 Photon.C:81
 Photon.C:82
 Photon.C:83
 Photon.C:84
 Photon.C:85
 Photon.C:86
 Photon.C:87
 Photon.C:88
 Photon.C:89
 Photon.C:90
 Photon.C:91
 Photon.C:92
 Photon.C:93
 Photon.C:94
 Photon.C:95
 Photon.C:96
 Photon.C:97
 Photon.C:98
 Photon.C:99
 Photon.C:100
 Photon.C:101
 Photon.C:102
 Photon.C:103
 Photon.C:104
 Photon.C:105
 Photon.C:106
 Photon.C:107
 Photon.C:108
 Photon.C:109
 Photon.C:110
 Photon.C:111
 Photon.C:112
 Photon.C:113
 Photon.C:114
 Photon.C:115
 Photon.C:116
 Photon.C:117
 Photon.C:118
 Photon.C:119
 Photon.C:120
 Photon.C:121
 Photon.C:122
 Photon.C:123
 Photon.C:124
 Photon.C:125
 Photon.C:126
 Photon.C:127
 Photon.C:128
 Photon.C:129
 Photon.C:130
 Photon.C:131
 Photon.C:132
 Photon.C:133
 Photon.C:134
 Photon.C:135
 Photon.C:136
 Photon.C:137
 Photon.C:138
 Photon.C:139
 Photon.C:140
 Photon.C:141
 Photon.C:142
 Photon.C:143
 Photon.C:144
 Photon.C:145
 Photon.C:146
 Photon.C:147
 Photon.C:148
 Photon.C:149
 Photon.C:150
 Photon.C:151
 Photon.C:152
 Photon.C:153
 Photon.C:154
 Photon.C:155
 Photon.C:156
 Photon.C:157
 Photon.C:158
 Photon.C:159
 Photon.C:160
 Photon.C:161
 Photon.C:162
 Photon.C:163
 Photon.C:164
 Photon.C:165
 Photon.C:166
 Photon.C:167
 Photon.C:168
 Photon.C:169
 Photon.C:170
 Photon.C:171
 Photon.C:172
 Photon.C:173
 Photon.C:174
 Photon.C:175
 Photon.C:176
 Photon.C:177
 Photon.C:178
 Photon.C:179
 Photon.C:180
 Photon.C:181
 Photon.C:182
 Photon.C:183
 Photon.C:184
 Photon.C:185
 Photon.C:186
 Photon.C:187
 Photon.C:188
 Photon.C:189
 Photon.C:190
 Photon.C:191
 Photon.C:192
 Photon.C:193
 Photon.C:194
 Photon.C:195
 Photon.C:196
 Photon.C:197
 Photon.C:198
 Photon.C:199
 Photon.C:200
 Photon.C:201
 Photon.C:202
 Photon.C:203
 Photon.C:204
 Photon.C:205
 Photon.C:206
 Photon.C:207
 Photon.C:208
 Photon.C:209
 Photon.C:210
 Photon.C:211
 Photon.C:212
 Photon.C:213
 Photon.C:214
 Photon.C:215
 Photon.C:216
 Photon.C:217
 Photon.C:218
 Photon.C:219
 Photon.C:220
 Photon.C:221
 Photon.C:222
 Photon.C:223
 Photon.C:224
 Photon.C:225
 Photon.C:226
 Photon.C:227
 Photon.C:228
 Photon.C:229
 Photon.C:230
 Photon.C:231
 Photon.C:232
 Photon.C:233
 Photon.C:234
 Photon.C:235
 Photon.C:236
 Photon.C:237
 Photon.C:238
 Photon.C:239
 Photon.C:240
 Photon.C:241
 Photon.C:242
 Photon.C:243
 Photon.C:244
 Photon.C:245
 Photon.C:246
 Photon.C:247
 Photon.C:248
 Photon.C:249
 Photon.C:250
 Photon.C:251
 Photon.C:252
 Photon.C:253
 Photon.C:254
 Photon.C:255
 Photon.C:256
 Photon.C:257
 Photon.C:258
 Photon.C:259
 Photon.C:260
 Photon.C:261
 Photon.C:262
 Photon.C:263
 Photon.C:264
 Photon.C:265
 Photon.C:266
 Photon.C:267
 Photon.C:268
 Photon.C:269
 Photon.C:270
 Photon.C:271
 Photon.C:272
 Photon.C:273
 Photon.C:274
 Photon.C:275
 Photon.C:276
 Photon.C:277
 Photon.C:278
 Photon.C:279
 Photon.C:280
 Photon.C:281
 Photon.C:282
 Photon.C:283
 Photon.C:284
 Photon.C:285
 Photon.C:286
 Photon.C:287
 Photon.C:288
 Photon.C:289
 Photon.C:290
 Photon.C:291
 Photon.C:292
 Photon.C:293
 Photon.C:294
 Photon.C:295
 Photon.C:296
 Photon.C:297
 Photon.C:298
 Photon.C:299
 Photon.C:300
 Photon.C:301
 Photon.C:302
 Photon.C:303
 Photon.C:304
 Photon.C:305
 Photon.C:306
 Photon.C:307
 Photon.C:308
 Photon.C:309
 Photon.C:310
 Photon.C:311
 Photon.C:312
 Photon.C:313
 Photon.C:314
 Photon.C:315
 Photon.C:316
 Photon.C:317
 Photon.C:318
 Photon.C:319
 Photon.C:320
 Photon.C:321
 Photon.C:322
 Photon.C:323
 Photon.C:324
 Photon.C:325
 Photon.C:326
 Photon.C:327
 Photon.C:328
 Photon.C:329
 Photon.C:330
 Photon.C:331
 Photon.C:332
 Photon.C:333
 Photon.C:334
 Photon.C:335
 Photon.C:336
 Photon.C:337
 Photon.C:338
 Photon.C:339
 Photon.C:340
 Photon.C:341
 Photon.C:342
 Photon.C:343
 Photon.C:344
 Photon.C:345
 Photon.C:346
 Photon.C:347
 Photon.C:348
 Photon.C:349
 Photon.C:350
 Photon.C:351
 Photon.C:352
 Photon.C:353
 Photon.C:354
 Photon.C:355
 Photon.C:356
 Photon.C:357
 Photon.C:358
 Photon.C:359
 Photon.C:360
 Photon.C:361
 Photon.C:362
 Photon.C:363
 Photon.C:364
 Photon.C:365
 Photon.C:366
 Photon.C:367
 Photon.C:368
 Photon.C:369
 Photon.C:370
 Photon.C:371
 Photon.C:372
 Photon.C:373
 Photon.C:374
 Photon.C:375
 Photon.C:376
 Photon.C:377
 Photon.C:378