ROOT logo
//Christine Nattrass, University of Tennessee at Knoxville
//This macro is for calculating the correction for the pT cut-off and its systematic error
//Uses the output of AliAnalysisTaskHadEt
//This is not actually what gets used in the correction class AliAnalysisHadEtCorrections - that is done in the macro GetCorrections.C - but this is useful for making plots and playing around with different options

float mean=0;
float highbound=0;
float lowbound=0;
float syserr = 0;

TH1D *GetHisto(float ptcut = 0.15, char *name, char *filename, float etacut){
  TFile *file = new TFile(filename);
  TList *list = file->FindObject("out2");
  //TH2F *allhad = ((TH2F*) out2->FindObject("EtSimulatedAllHadron"))->Clone("allhad");
  TH2F *allhad = ((TH2F*) out2->FindObject("EtSimulatedChargedHadron"))->Clone("allhad");
  TH2F *ptlow = ((TH2F*) out2->FindObject("EtSimulatedChargedHadronAssumingNoPt"))->Clone("ptlow");
  TH2F *pthigh;
  if(ptcut>0.14){//TPC cut off
    (TH2F*)pthigh =(TH2F*) ((TH2F*) out2->FindObject("EtSimulatedChargedHadronAssumingPtTPCCut"))->Clone("pthigh");
  }
  else{
    (TH2F*)pthigh =(TH2F*) ((TH2F*) out2->FindObject("EtSimulatedChargedHadronAssumingPtITSCut"))->Clone("pthigh");
  }

  int lowbin = allhad->GetXaxis()->FindBin(0.0);//make sure we don't accidentally get the wrong bin
  int highbin = allhad->GetXaxis()->FindBin(ptcut);
  int nbins = allhad->GetXaxis()->GetNbins();
  cout<<"Projecting from "<<allhad->GetXaxis()->GetBinLowEdge(lowbin)<<" to "<<allhad->GetXaxis()->GetBinLowEdge(highbin+1)<<endl;
  cout<<"Projecting from "<<allhad->GetXaxis()->GetBinLowEdge(lowbin)<<" to "<<allhad->GetXaxis()->GetBinLowEdge(nbins)<<endl;

  //allhad->Sumw2();


  TH1D *numerator = allhad->ProjectionY("name",lowbin,highbin);
  TH1D *denominator = allhad->ProjectionY("denominator",lowbin,nbins);
  TH1D *numeratorLow = ptlow->ProjectionY("nameLow",lowbin,highbin);
  TH1D *denominatorLow = allhad->ProjectionY("denominatorLow",highbin,nbins);
  denominatorLow->Add(ptlow);
  TH1D *numeratorHigh = pthigh->ProjectionY("nameHigh",lowbin,highbin);
  TH1D *denominatorHigh = allhad->ProjectionY("denominatorHigh",highbin,nbins);
  denominatorHigh->Add(pthigh);

  numerator->Divide(denominator);
  numeratorLow->Divide(denominatorLow);
  numeratorHigh->Divide(denominatorHigh);

  TF1 *funcLow = new TF1("funcLow","[0]",-.7,.7);
  funcLow->SetParameter(0,0.01);
  numeratorLow->Fit(funcLow);
  TF1 *func = new TF1("func","[0]",-.7,.7);
  func->SetParameter(0,0.02);
  numerator->Fit(func);
  TF1 *funcHigh = new TF1("funcHigh","[0]",-.7,.7);
  funcHigh->SetParameter(0,0.02);
  numeratorHigh->Fit(funcHigh);

  mean = 1.0-func->GetParameter(0);
  lowbound = 1.0-funcHigh->GetParameter(0);
  highbound = 1.0-funcLow->GetParameter(0);
  cout<<"fpTcut = "<<mean<<","<<lowbound<<","<<highbound<<endl;
  cout<<"1/fpTcut = "<<1.0/mean<<","<<1.0/lowbound<<","<<1.0/highbound<<endl;
  //cout<<"fpTcut = "<<mean<<"-"<<mean-lowbound<<"+"<<highbound-mean<<endl;
  syserr = highbound-mean;
  if(mean-lowbound>syserr) syserr = mean-lowbound;
  cout<<Form("%2.4f^{+%2.4f}_{-%2.4f}",mean,highbound-mean,mean-lowbound)<<endl;
  cout<<"latex here ";
  cout<<Form("%2.4f \\pm %2.4f",mean,syserr)<<endl;
  cout<<"1/fpTcut = "<<1.0/mean<<"+"<<1.0/lowbound-1.0/mean<<"-"<<1.0/mean-1.0/highbound<<endl;
  numerator->SetYTitle("E_{T}^{had, p_{T}<cut-off}/E_{T}^{had, all p_{T}}");
  numerator->GetYaxis()->SetTitleOffset(1.);
  numerator->GetYaxis()->SetTitleSize(0.08);
  numerator->GetYaxis()->SetLabelSize(0.05);
  numerator->GetXaxis()->SetTitleSize(0.08);
  numerator->GetXaxis()->SetLabelSize(0.05);
  numerator->GetXaxis()->SetTitleOffset(.6);
  //numerator->Rebin(2);
  //numerator->Scale(0.5);
  //numerator->Draw("e");
  return numerator;

}
void CorrPtCut(char *prodname = "LHC10d4 PYTHIA D6T 7 TeV p+p", char *shortprodname = "LHC10d4", char *filename="Et.ESD.new.sim.LHC10d4.pp.merged.root"){

  gStyle->SetOptTitle(0);
  gStyle->SetOptStat(0);
  gStyle->SetOptFit(0);
  TCanvas *c = new TCanvas("c","c",500,400);
  c->SetTopMargin(0.04);
  c->SetRightMargin(0.04);
  c->SetLeftMargin(0.181452);
  c->SetBottomMargin(0.134409);
  c->SetBorderSize(0);
  c->SetFillColor(0);
  c->SetFillColor(0);
  c->SetBorderMode(0);
  c->SetFrameFillColor(0);
  c->SetFrameBorderMode(0);
  float etacut = 0.7;
  cout<<"Pt cut = 150 MeV/c"<<endl;
  TH1D *High = GetHisto(0.15-.001,"High",filename,etacut);
  float tpcHigh=highbound;
  float tpcLow=lowbound;
  float tpcsyserr = syserr;
  float tpcmean = mean;
  float x1 = High->GetXaxis()->GetBinLowEdge(1);
  //TBox *tpcBox = new TBox(-x1*.99,1.0-tpcLow,x1*.99,1.0-tpcHigh);
  TBox *tpcBox = new TBox(-x1*.99,1.0-(mean-syserr),x1*.99,1.0-(mean+syserr));
  tpcBox->SetFillColor(5);
  tpcBox->SetLineColor(0);
  tpcBox->SetFillStyle(1001);
  cout<<"Pt cut = 100 MeV/c"<<endl;
  TH1D *Low = GetHisto(0.1-.001,"Low",filename,etacut);
  float itsHigh=highbound;
  float itsLow=lowbound;
  float itssyserr = syserr;
  float itsmean = mean;

  cout<<Form("dataset & %2.4f \\pm %2.4f &  %2.4f \\pm %2.4f \\",itsmean,itssyserr,tpcmean,tpcsyserr)<<endl;
  float x = Low->GetXaxis()->GetBinLowEdge(1);
  //TBox *itsBox = new TBox(-x*.99,1.0-itsLow,x*.99,1.0-itsHigh);
  TBox *itsBox = new TBox(-x1*.99,1.0-(mean-syserr),x1*.99,1.0-(mean+syserr));
  itsBox->SetFillColor(5);
  itsBox->SetLineColor(0);
  itsBox->SetFillStyle(1001);
  cout<<"Pt cut = 50 MeV/c"<<endl;
  TH1D *Lowest = GetHisto(0.05-.001,"Lowest",filename,etacut);
  TF1 *funcLow = new TF1("funcLow","[0]",-.7,.7);
  funcLow->SetParameter(0,0.01);
  Low->Fit(funcLow);
  TF1 *funcHigh = new TF1("funcHigh","[0]",-.7,.7);
  funcHigh->SetParameter(0,0.02);
  High->Fit(funcLow);
  High->SetMaximum(0.06);
  High->SetMinimum(0.0);
  High->SetMarkerColor(2);
  Low->SetMarkerColor(4);
  High->SetLineColor(2);
  Low->SetLineColor(4);
  High->SetMinimum(0.0);
  High->SetMarkerStyle(20);
  Low->SetMarkerStyle(21);
  Lowest->SetMarkerStyle(22);
  High->Draw();
  tpcBox->Draw("f");
  High->Draw("same");
  itsBox->Draw("f");
  //return;
  Low->Draw("same");
  //Lowest->Draw("same");
  TLatex *tex = new TLatex(-0.723444,0.0373593+0.019,prodname);
  tex->SetTextSize(0.0537634);
  tex->Draw();
  TLegend *leg = new TLegend(0.217742,0.696237,0.477823,0.873656);
  leg->AddEntry(High,"p_{T} cut-off = 0.15 GeV/c");
  leg->AddEntry(Low,"p_{T} cut-off = 0.1 GeV/c");
  //leg->AddEntry(Lowest,"p_{T} cut-off = 0.05 GeV/c");
  leg->SetFillStyle(0);
  leg->SetFillColor(0);
  leg->SetBorderSize(0);
  leg->SetTextSize(0.0537634);
  leg->Draw();
  c->SaveAs(Form("pics/%s/fptcut.eps",shortprodname));
  c->SaveAs(Form("pics/%s/fptcut.png",shortprodname));
  c->SaveAs(Form("pics/%s/fptcut.pdf",shortprodname));
}
 CorrPtCut.C:1
 CorrPtCut.C:2
 CorrPtCut.C:3
 CorrPtCut.C:4
 CorrPtCut.C:5
 CorrPtCut.C:6
 CorrPtCut.C:7
 CorrPtCut.C:8
 CorrPtCut.C:9
 CorrPtCut.C:10
 CorrPtCut.C:11
 CorrPtCut.C:12
 CorrPtCut.C:13
 CorrPtCut.C:14
 CorrPtCut.C:15
 CorrPtCut.C:16
 CorrPtCut.C:17
 CorrPtCut.C:18
 CorrPtCut.C:19
 CorrPtCut.C:20
 CorrPtCut.C:21
 CorrPtCut.C:22
 CorrPtCut.C:23
 CorrPtCut.C:24
 CorrPtCut.C:25
 CorrPtCut.C:26
 CorrPtCut.C:27
 CorrPtCut.C:28
 CorrPtCut.C:29
 CorrPtCut.C:30
 CorrPtCut.C:31
 CorrPtCut.C:32
 CorrPtCut.C:33
 CorrPtCut.C:34
 CorrPtCut.C:35
 CorrPtCut.C:36
 CorrPtCut.C:37
 CorrPtCut.C:38
 CorrPtCut.C:39
 CorrPtCut.C:40
 CorrPtCut.C:41
 CorrPtCut.C:42
 CorrPtCut.C:43
 CorrPtCut.C:44
 CorrPtCut.C:45
 CorrPtCut.C:46
 CorrPtCut.C:47
 CorrPtCut.C:48
 CorrPtCut.C:49
 CorrPtCut.C:50
 CorrPtCut.C:51
 CorrPtCut.C:52
 CorrPtCut.C:53
 CorrPtCut.C:54
 CorrPtCut.C:55
 CorrPtCut.C:56
 CorrPtCut.C:57
 CorrPtCut.C:58
 CorrPtCut.C:59
 CorrPtCut.C:60
 CorrPtCut.C:61
 CorrPtCut.C:62
 CorrPtCut.C:63
 CorrPtCut.C:64
 CorrPtCut.C:65
 CorrPtCut.C:66
 CorrPtCut.C:67
 CorrPtCut.C:68
 CorrPtCut.C:69
 CorrPtCut.C:70
 CorrPtCut.C:71
 CorrPtCut.C:72
 CorrPtCut.C:73
 CorrPtCut.C:74
 CorrPtCut.C:75
 CorrPtCut.C:76
 CorrPtCut.C:77
 CorrPtCut.C:78
 CorrPtCut.C:79
 CorrPtCut.C:80
 CorrPtCut.C:81
 CorrPtCut.C:82
 CorrPtCut.C:83
 CorrPtCut.C:84
 CorrPtCut.C:85
 CorrPtCut.C:86
 CorrPtCut.C:87
 CorrPtCut.C:88
 CorrPtCut.C:89
 CorrPtCut.C:90
 CorrPtCut.C:91
 CorrPtCut.C:92
 CorrPtCut.C:93
 CorrPtCut.C:94
 CorrPtCut.C:95
 CorrPtCut.C:96
 CorrPtCut.C:97
 CorrPtCut.C:98
 CorrPtCut.C:99
 CorrPtCut.C:100
 CorrPtCut.C:101
 CorrPtCut.C:102
 CorrPtCut.C:103
 CorrPtCut.C:104
 CorrPtCut.C:105
 CorrPtCut.C:106
 CorrPtCut.C:107
 CorrPtCut.C:108
 CorrPtCut.C:109
 CorrPtCut.C:110
 CorrPtCut.C:111
 CorrPtCut.C:112
 CorrPtCut.C:113
 CorrPtCut.C:114
 CorrPtCut.C:115
 CorrPtCut.C:116
 CorrPtCut.C:117
 CorrPtCut.C:118
 CorrPtCut.C:119
 CorrPtCut.C:120
 CorrPtCut.C:121
 CorrPtCut.C:122
 CorrPtCut.C:123
 CorrPtCut.C:124
 CorrPtCut.C:125
 CorrPtCut.C:126
 CorrPtCut.C:127
 CorrPtCut.C:128
 CorrPtCut.C:129
 CorrPtCut.C:130
 CorrPtCut.C:131
 CorrPtCut.C:132
 CorrPtCut.C:133
 CorrPtCut.C:134
 CorrPtCut.C:135
 CorrPtCut.C:136
 CorrPtCut.C:137
 CorrPtCut.C:138
 CorrPtCut.C:139
 CorrPtCut.C:140
 CorrPtCut.C:141
 CorrPtCut.C:142
 CorrPtCut.C:143
 CorrPtCut.C:144
 CorrPtCut.C:145
 CorrPtCut.C:146
 CorrPtCut.C:147
 CorrPtCut.C:148
 CorrPtCut.C:149
 CorrPtCut.C:150
 CorrPtCut.C:151
 CorrPtCut.C:152
 CorrPtCut.C:153
 CorrPtCut.C:154
 CorrPtCut.C:155
 CorrPtCut.C:156
 CorrPtCut.C:157
 CorrPtCut.C:158
 CorrPtCut.C:159
 CorrPtCut.C:160
 CorrPtCut.C:161
 CorrPtCut.C:162
 CorrPtCut.C:163
 CorrPtCut.C:164
 CorrPtCut.C:165
 CorrPtCut.C:166