StRoot  1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
spectraRatio.C
1 #include "commonmacro/common.h"
2 #include "commonmacro/histutil.h"
3 #include "common/Name.cc"
4 
5 void compareSpectra(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  const 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 
23 
24  TFile* inRoot[2];
25  inRoot[0] = new TFile(inName);
26  inRoot[1] = new TFile(more); // second
27  if(!inRoot[0] || !inRoot[1]){
28  cout << "cannot find the infile" << endl;
29  return;
30  }
31  cout << "file 2=" << more << endl;
32 
33  // deduce whether file name
34  TString trigger[2]; trigger[0]=inName; trigger[1]=more;
35  for(int i=0;i<2;i++){
36  trigger[i].Remove(0,trigger[i].Last('/'));
37  // cout << "file " << i+1 << " " << trigger[i] << endl;
38  }
39 
40  // deduce cut of 2nd file
41  TString sCut = trigger[1];
42  sCut.Remove(0,sCut.First("_")+1);
43  sCut.Remove(sCut.First('.'),sCut.Length());
44  sCut.ReplaceAll("cut","");
45  cout << "cut2=" << sCut << endl;
46 
47 
48 
49  TH1* h1[2]; TH1* ha[2]; TH1* hRatio;
50  TGraphAsymmErrors* g[2];
51 
52  TCanvas c1("c1","c1",400,500);
53  float minpt=2,maxpt=6;
54  //---------------------------------------------------
55  // histogram ratios
56  const int nBin=2; const int nBase=2; const int nCharge=3;
57  char* baseName[] = {"h1Raw","h1Corrected" };
58  char* baseTitle[] = { "raw","corrected"};
59  char* charge[] = { 0,"Plus","Minus"};
60  int markerStyle[] = {4,8,2};
61  float ratioMin=0.2,ratioMax=1.5;
62 
63  gStyle->SetOptStat(0);
64  gStyle->SetTitleBorderSize(0);
65  for(int iBin=0; iBin<nBin; iBin++){ // loop over binning
66  for(int iCharge=0; iCharge<nCharge; iCharge++){ // loop over charge
67 
68  sprintf(title,"bin %d %s : %s/%s ",
69  iBin,charge[iCharge],
70  trigger[0].Data(),trigger[1].Data());
71  //Divide(&c1,1,1,title,inName);
72 
73  c1.Clear();c1.cd(1); gPad->SetTickx(); gPad->SetTicky();
74  gPad->SetGridx(); gPad->SetGridy();
75 
76  for(int iBase=0; iBase<nBase; iBase++){ //raw,corrected,etc
77  for(int if=0; if<2; if++){ // different files
78  setName(name,baseName[iBase],iBin,charge[iCharge]);
79  h1[if]=(TH1*)inRoot[if]->Get(name);
80  }
81 
82  hRatio=(TH1*)h1[0]->Clone();
83  ha[iBase]=hRatio; // save info for Tlegend
84  hRatio->Divide(h1[1]);
85  SetRange(hRatio->GetXaxis(),minpt,maxpt);
86  hRatio->SetMarkerStyle(8); SetMinMax(hRatio,ratioMin,ratioMax);
87  // scale it
88  hRatio->SetTitle(title); //cout << h1[0]->GetTitle() << endl;
89  hRatio->SetMarkerStyle(markerStyle[iBase]);
90  if(doScale)
91  hRatio->Scale(1./hRatio->GetBinContent(hRatio->GetXaxis()->GetFirst()));
92  /*
93  for(int k=hRatio->GetXaxis()->GetFirst();
94  k<=hRatio->GetXaxis()->GetLast();k++){
95  cout << "\t" << hRatio->GetBinCenter(k)
96  << "\t" << hRatio->GetBinContent(k) << endl;
97  }
98  */
99  if(iBase==0){
100  hRatio->Draw("e1");
101  hRatio->GetXaxis()->SetTitle("pT (GeV/c)");
102  //sTitle = h1[0]->GetName(); sTitle += "Ratio";
103  }
104  else{
105  hRatio->Draw("e1same");
106  }
107 
108  } // base
109  //DrawLine(h1[0]);
110  if(nBase>1){
111  TLegend* l=new TLegend(.7,.7,.85,.85); l->SetBorderSize(0);
112  l->SetFillColor(0);
113  l->AddEntry(ha[0],"raw","p");
114  l->AddEntry(ha[1],"corrected","p");
115  l->Draw();
116  }
117  sTitle=hRatio->GetName();
118  sTitle.Remove(sTitle.Last('.')); //c1.Update();
119  sprintf(title,"_cut%dcut%s",cut,sCut.Data());
120  sTitle += title;
121  Print(&c1,psDir,sTitle.Data());
122 
123  }
124  }
125 }
126