StRoot  1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
divideSpectra.C
1 #include "commonmacro/common.h"
2 #include "commonmacro/histutil.h"
3 #include "common/Name.cc"
4 
5 void divideSpectra(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  cout << "--------------------------" << endl;
14  cout << "in name=" << inName << endl
15  << "ps dir=" << psDir << endl
16  << "cut=" << cut << endl;
17  cout << "--------------------------" << endl;
18 
19 
20 
21  TFile* inRoot;
22  inRoot = new TFile(inName);
23  if(!inRoot){
24  cout << "cannot find the infile" << endl;
25  return;
26  }
27 
28  TH1* h1[2];
29  TGraphAsymmErrors* g[2];
30 
31  TCanvas c1("c1","c1",400,500);
32  float minpt=2,maxpt=6;
33 
34  const int nCharge=1;
35  char* charge[] = { 0,"Plus","Minus"};
36  const int nBin=1; // different binning
37  float ratioMin=0.2,ratioMax=1.5;
38  float ptMin=2,ptMax=6;
39 
40  char name1[100],name2[100];
41 
42  int nPair=2;
43  char* namePair[][2]={
44  {"h1Raw","h1EffCorrected"},
45  {"h1Corrected","h1EffCorrected"}
46  };
47  int nx=1,ny=2;
48 
49  gStyle->SetOptStat(0); gStyle->SetTitleBorderSize(0);
50  gStyle->SetPadTickY(1); gStyle->SetPadTickX(1);
51  //---------------------------------------------------
52 
53 
54  // raw/efficiency corrected
55 
56  c1.Clear();
57 
58  for(int ib=0; ib<nBin; ib++){ // loop over binning
59  for(int ic=0; ic<nCharge; ic++){ // loop over charge type
60 
61  sprintf(title,"spectra ratios (binning %d, cut %d)",cut);
62  Divide(&c1,nx,ny,title,inName);
63 
64  for(int ip=0; ip<nPair; ip++){ // loop over pairs of hists
65  c1.cd(ip+1); gPad->SetGridx(); gPad->SetGridy();
66  setName(name1,namePair[ip][0],ib,charge[ic]);
67  cout << name1 << "\t";
68  h1[0]=(TH1*)inRoot->Get(name1);
69  setName(name2,namePair[ip][1],ib,charge[ic]);
70  cout << name2 << endl;
71  h1[1]=(TH1*)inRoot->Get(name2);
72 
73  sprintf(title,"%s / %s",name1,name2);
74  cout << h1[0]->GetBinContent(5)
75  << "\t" << h1[1]->GetBinContent(5) << endl;
76 
77  h1[0]->Divide(h1[1]);
78  h1[0]->SetTitle(title);
79  h1[0]->Draw("e");
80  // SetMinMax(h1[0],ratioMin,ratioMax);
81  h1[0]->SetAxisRange(ptMin,ptMax-.00001);
82 
83  h1[0]->SetMinimum(); h1[0]->SetMaximum(1.2);
84  } //ip
85 
86  if(ic==0)
87  sprintf(title,"bin%d.divideSpectra",ib);
88  else
89  sprintf(title,"bin%d.%s.divideSpectra",ib,ic);
90  Print(&c1,psDir,title);
91  } // ic
92  } // ib
93 }