00001 #include "commonmacro/common.h"
00002 #include "commonmacro/histutil.h"
00003 #include "common/Name.cc"
00004
00005 void compareSpectra(const char* inName=
00006 "links/P01hi.minbias.2000.hist/hianalysis_1000.hist.root",
00007 const char* psDir="ps",
00008 int cut = 1,
00009 const char* outDir="./",
00010 const char* more = "west",
00011 float extraValue = 0)
00012 {
00013 bool doScale= (extraValue>0);
00014
00015 cout << "--------------------------" << endl;
00016 cout << "in name=" << inName << endl
00017 << "ps dir=" << psDir << endl
00018 << "cut=" << cut << endl
00019 << "scale? " << (doScale ? "yes" : "no") << endl;
00020 cout << "--------------------------" << endl;
00021
00022
00023
00024 TFile* inRoot[2];
00025 inRoot[0] = new TFile(inName);
00026 inRoot[1] = new TFile(more);
00027 if(!inRoot[0] || !inRoot[1]){
00028 cout << "cannot find the infile" << endl;
00029 return;
00030 }
00031 cout << "file 2=" << more << endl;
00032
00033
00034 TString trigger[2]; trigger[0]=inName; trigger[1]=more;
00035 for(int i=0;i<2;i++){
00036 trigger[i].Remove(0,trigger[i].Last('/'));
00037
00038 }
00039
00040
00041 TString sCut = trigger[1];
00042 sCut.Remove(0,sCut.First("_")+1);
00043 sCut.Remove(sCut.First('.'),sCut.Length());
00044 sCut.ReplaceAll("cut","");
00045 cout << "cut2=" << sCut << endl;
00046
00047
00048
00049 TH1* h1[2]; TH1* ha[2]; TH1* hRatio;
00050 TGraphAsymmErrors* g[2];
00051
00052 TCanvas c1("c1","c1",400,500);
00053 float minpt=2,maxpt=6;
00054
00055
00056 const int nBin=2; const int nBase=2; const int nCharge=3;
00057 char* baseName[] = {"h1Raw","h1Corrected" };
00058 char* baseTitle[] = { "raw","corrected"};
00059 char* charge[] = { 0,"Plus","Minus"};
00060 int markerStyle[] = {4,8,2};
00061 float ratioMin=0.2,ratioMax=1.5;
00062
00063 gStyle->SetOptStat(0);
00064 gStyle->SetTitleBorderSize(0);
00065 for(int iBin=0; iBin<nBin; iBin++){
00066 for(int iCharge=0; iCharge<nCharge; iCharge++){
00067
00068 sprintf(title,"bin %d %s : %s/%s ",
00069 iBin,charge[iCharge],
00070 trigger[0].Data(),trigger[1].Data());
00071
00072
00073 c1.Clear();c1.cd(1); gPad->SetTickx(); gPad->SetTicky();
00074 gPad->SetGridx(); gPad->SetGridy();
00075
00076 for(int iBase=0; iBase<nBase; iBase++){
00077 for(int if=0; if<2; if++){
00078 setName(name,baseName[iBase],iBin,charge[iCharge]);
00079 h1[if]=(TH1*)inRoot[if]->Get(name);
00080 }
00081
00082 hRatio=(TH1*)h1[0]->Clone();
00083 ha[iBase]=hRatio;
00084 hRatio->Divide(h1[1]);
00085 SetRange(hRatio->GetXaxis(),minpt,maxpt);
00086 hRatio->SetMarkerStyle(8); SetMinMax(hRatio,ratioMin,ratioMax);
00087
00088 hRatio->SetTitle(title);
00089 hRatio->SetMarkerStyle(markerStyle[iBase]);
00090 if(doScale)
00091 hRatio->Scale(1./hRatio->GetBinContent(hRatio->GetXaxis()->GetFirst()));
00092
00093
00094
00095
00096
00097
00098
00099 if(iBase==0){
00100 hRatio->Draw("e1");
00101 hRatio->GetXaxis()->SetTitle("pT (GeV/c)");
00102
00103 }
00104 else{
00105 hRatio->Draw("e1same");
00106 }
00107
00108 }
00109
00110 if(nBase>1){
00111 TLegend* l=new TLegend(.7,.7,.85,.85); l->SetBorderSize(0);
00112 l->SetFillColor(0);
00113 l->AddEntry(ha[0],"raw","p");
00114 l->AddEntry(ha[1],"corrected","p");
00115 l->Draw();
00116 }
00117 sTitle=hRatio->GetName();
00118 sTitle.Remove(sTitle.Last('.'));
00119 sprintf(title,"_cut%dcut%s",cut,sCut.Data());
00120 sTitle += title;
00121 Print(&c1,psDir,sTitle.Data());
00122
00123 }
00124 }
00125 }
00126