StRoot  1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
compareVertex.C
1 #include "commonmacro/common.h"
2 #include "common/Name.cc"
3 #include "commonmacro/histutil.h"
4 
5 void compareVertex(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 = "embeddingfile",
11  float extraValue = 0)
12 {
13 
14 
15  gSystem->Load("StHiMicroEvent");
16  gSystem->Load("StHiMicroAnalysis");
17 
18  TFile* inRoot = new TFile(inName);
19  TFile* embedRoot=0;
20  if(more){
21  strcpy(name,more);
22  }
23  else if(extraValue>0){
24  // attempt to find the embed file
25  TString s=inName;
26  char* trigger = (s.Contains("central")) ? "central" :"minbias";
27  sprintf(name,"~/wrk/assoc/links/P01hi.central.HighpT_piminus_%d.hist/assoc_cut%d.hist.root",(int)extraValue,cut);
28  }
29  else{
30  cout << "Unknown embed file" << endl; return;
31  }
32  embedRoot = new TFile(name);
33 
34  cout << "--------------------------" << endl;
35  cout << "in name=" << inName << endl
36  << "ps dir=" << psDir << endl
37  << "cut=" << cut << endl
38  << "embed name=" << name << endl;
39  cout << "--------------------------" << endl;
40 
41  if(!inRoot){
42  cout << "cannot find the infile" << endl;
43  return;
44  }
45  if(!embedRoot){
46  cout << "cannot find " << more << endl;
47  }
48  TH1* h1[2]={0}; //real,embed
49 
50  h1[0]=(TH1*)inRoot.Get("h1VtxZCentCut");
51  h1[1]=(TH1*)embedRoot.Get("h1VtxZCentCut");
52  if(!h1[0] || !h1[1]) { cout << "cannot find histo" << endl; return; }
53 
54  int nrebin=10;
55  h1[0]->Rebin(nrebin); h1[1]->Rebin(nrebin);
56  TH1* ha, *hb;
57 
58  char* type[] = {"real","embed"};
59 
60  TCanvas c1("c1","c1",400,500);
61 
62  float minZ=-80,maxZ=80;
63  TText* t=new TText;
64  gStyle->SetOptStat(0);
65 
66  TLegend l(0.15,0.65,0.25,0.85);
67  l.SetFillColor(kWhite); l.SetBorderSize(0);
68  //-------------------------------------------------------------
69  int lowBin=h1[0]->GetXaxis()->FindBin(minZ);
70  int upBin =h1[1]->GetXaxis()->FindBin(maxZ-0.0001);
71 
72  // show both separately
73  sprintf(title,"vertexZ (cut %d)",cut);
74  Divide(&c1,1,2,title,inName);
75  for(int i=0; i<2; i++){
76  c1.cd(i+1); h1[i]->SetTitle(title); h1[i]->Draw();
77  PrintMeanRms(h1[i],0.7,0.8);
78  }
79  Print(&c1,psDir,"vertexZ");
80 
81  // scale them
82  sprintf(title,"vertex z scaled (cut %d)",cut);
83  Divide(&c1,1,2,title,inName);
84  c1.cd(1); ha=(TH1*)h1[0]->Clone(); hb=(TH1*)h1[1]->Clone();
85  ha->SetTitle("scaled");
86  ha->Scale(1./ha->Integral());
87  hb->Scale(1./hb->Integral());
88  ha->SetMarkerStyle(4); hb->SetMarkerStyle(8);
89  ha->Draw("p"); hb->Draw("psame");
90  l.AddEntry(ha,"real","p"); l.AddEntry(hb,"embed","p"); l.Draw();
91 
92  c1.cd(2); ha=(TH1*)h1[0]->Clone(); hb=(TH1*)h1[1]->Clone();
93  ha->SetTitle("weighted");
94  cout << "min = " << ha->GetXaxis()->GetBinLowEdge(lowBin)
95  << ",max = " << ha->GetXaxis()->GetBinUpEdge(upBin) << endl;
96 
97  double realPeak = ha->Integral(lowBin,upBin);
98  double realOut = ha->Integral()-realPeak;
99  double realFrac = realPeak/realOut;
100  double embedPeak = hb->Integral(lowBin,upBin);
101  double embedOut = hb->Integral()-hb->Integral(lowBin,upBin);
102  double embedFrac = embedPeak/embedOut;
103  double weight=realFrac/embedFrac;
104 
105  cout << "real frac="<<realFrac <<", embedFrac="<<embedFrac
106  << ", weight = " << weight << endl;
107  for(int i=lowBin;i<=upBin;i++){
108  hb->SetBinContent(i,hb->GetBinContent(i)*weight);
109  // hb->SetBinError(i,hb->GetBinError(i)*weight);
110  }
111  ha->Scale(1./ha->Integral()); hb->Scale(1./hb->Integral());
112  ha->SetMarkerStyle(4); hb->SetMarkerStyle(8);
113  ha->Draw("p"); hb->Draw("psame");
114  sprintf(name,"weight %.2f",weight); t->DrawTextNDC(0.15,0.75,name);
115 
116  Print(&c1,psDir,"vertexZScaled");
117 
118 }
119 
120 
121 
122 
123 
124 
125 
126 
127