StRoot  1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
QMRatio.C
1 #include "commonmacro/common.h"
2 #include "commonmacro/histutil.h"
3 #include "common/Name.cc"
4 
5 void QMRatio(const char* inName=
6  "links/P01hi.minbias.2000.hist/hianalysis_1000.hist.root",
7  const char* psDir="ps",
8  int cut = 1,
9  const char* outDir="./",
10  char* more = "west",
11  float extraValue = 0)
12 {
13  bool doScale=(extraValue>0);
14 
15  cout << "--------------------------" << endl;
16  cout << "in name=" << inName << endl
17  << "ps dir=" << psDir << endl
18  << "cut=" << cut << endl
19  << "scale? " << (doScale ? "yes" : "no") << endl;
20  cout << "--------------------------" << endl;
21 
22  char qm[100]; strcpy(qm,"finish_central_cut1_QM.hist.root");
23  more=qm;
24 
25  TFile* inRoot[2];
26  inRoot[0] = new TFile(inName);
27  inRoot[1] = new TFile(more); // second
28  if(!inRoot[0] || !inRoot[1]){
29  cout << "cannot find the infile" << endl;
30  return;
31  }
32  cout << "file 2=" << more << endl;
33 
34  // deduce whether file name
35  TString trigger[2]; trigger[0]=inName; trigger[1]="QM";
36  trigger[0].Remove(0,trigger[0].Last('/'));
37 
38  TH1* h1[2]; TH1* ha[2]; TH1* hRatio;
39  TGraphAsymmErrors* g[2];
40 
41  TCanvas c1("c1","c1",400,500);
42  float minpt=2,maxpt=6;
43  //---------------------------------------------------
44  // histogram ratios
45  const int nBin=2; const int nBase=2; const int nCharge=3;
46  char* baseName[] = {"h1Raw","h1Corrected" };
47  char* baseTitle[] = { "raw","corrected"};
48  char* charge[] = { 0,"Plus","Minus"};
49  int markerStyle[] = {4,8,2};
50  char* oldcharge[] = {0,"plus","minus"};
51 
52  gStyle->SetOptStat(0);
53  gStyle->SetTitleBorderSize(0);
54  for(int iCharge=0; iCharge<nCharge; iCharge++){
55 
56  sprintf(title,"%s : %s/%s ",
57  charge[iCharge],
58  trigger[0].Data(),trigger[1].Data());
59  //Divide(&c1,1,1,title,inName);
60 
61  c1.Clear();c1.cd(1); gPad->SetTickx(); gPad->SetTicky();
62  gPad->SetGridx(); gPad->SetGridy();
63 
64  for(int iBase=0; iBase<nBase; iBase++){ //raw,corrected,etc
65  setName(name,baseName[iBase],0,charge[iCharge]); // bin0
66  h1[0]=(TH1*)inRoot[0]->Get(name);
67  if(iBase==0){
68  setName(name,baseName[iBase],1,oldcharge[iCharge]); // bin1
69  }
70  else{
71  setName(name,baseName[iBase],1,3,oldcharge[iCharge]);
72  }
73  // cout << name << endl;
74  h1[1]=(TH1*)inRoot[1]->Get(name);
75  if(!h1[1])return;
76 
77  hRatio=(TH1*)h1[0]->Clone();
78  ha[iBase]=hRatio; // save info for Tlegend
79  hRatio->Divide(h1[1]);
80  SetRange(hRatio->GetXaxis(),minpt,maxpt);
81  hRatio->SetMarkerStyle(8); SetMinMax(hRatio,0.5,1.5);
82  // scale it
83  hRatio->SetTitle(title); //cout << h1[0]->GetTitle() << endl;
84  hRatio->SetMarkerStyle(markerStyle[iBase]);
85  if(doScale)
86  hRatio->Scale(1./hRatio->GetBinContent(hRatio->GetXaxis()->GetFirst()));
87  /*
88  for(int k=hRatio->GetXaxis()->GetFirst();
89  k<=hRatio->GetXaxis()->GetLast();k++){
90  cout << "\t" << hRatio->GetBinCenter(k)
91  << "\t" << hRatio->GetBinContent(k) << endl;
92  }
93  */
94  if(iBase==0){
95  hRatio->Draw("e1");
96  hRatio->GetXaxis()->SetTitle("pT (GeV/c)");
97  //sTitle = h1[0]->GetName(); sTitle += "Ratio";
98  }
99  else{
100  hRatio->Draw("e1same");
101  }
102 
103  } // base
104  //DrawLine(h1[0]);
105  if(nBase>1){
106  TLegend* l=new TLegend(.2,.7,.3,.80); l->SetBorderSize(0);
107  l->SetFillColor(0);
108  l->AddEntry(ha[0],"raw","p");
109  l->AddEntry(ha[1],"corrected","p");
110  l->Draw();
111  }
112  sTitle=hRatio->GetName();
113  sTitle.Remove(sTitle.Last('.')); //c1.Update();
114  Print(&c1,psDir,sTitle.Data());
115 
116  }
117 
118 }
119