StRoot  1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
dirtyBack.C
1 #include "commonmacro/common.h"
2 #include "common/Name.cc"
3 #include "commonmacro/histutil.h"
4 
5 void dirtyBack(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 = 1)
12 {
13  cout << "--------------------------" << endl;
14  cout << "in name=" << inName << endl
15  << "ps dir=" << psDir << endl
16  << "cut=" << cut << endl;
17  cout << "--------------------------" << endl;
18 
19  inRoot = new TFile(inName);
20 
21  gSystem->Load("StHiMicroAnalysis");
22  if(!inRoot){
23  cout << "cannot find the infile" << endl;
24  return;
25  }
26  // deduce the output dir and name
27  TString outName=outDir;
28  sprintf(name,"/background_cut%d.hist.root",cut);
29  outName+=name;
30 
31  TFile* outRoot=new TFile(outName.Data(),"RECREATE");
32  double badBkgFrac[]={.56,.70,.70,.80,.80};
33  double sigBkgOverBadBkg[] = {6.5,3.9,1.4,.5,.2};
34  int npt=5;
35  float ptary[]={1.5,2,3,4,5,6};
36 
37  //----------------------------------------
38 
39  TH2* h2=(TH2*)inRoot->Get("Minus.h2SDcaGlPtPr");
40 
41  TH1D* hBack=new TH1D("h1BackGround","h1BackGround",
42  5,ptary);
43  int lowBin,upBin;
44  for(int ipt=0;ipt<npt;ipt++){
45  TH1* h1=(TH2*)HistSlice(h2,"","",0,ptary[ipt],ptary[ipt+1],"x");
46  lowBin=h1->FindBin(-3);
47  upBin=h1->FindBin(-1.99999);
48  double badAll=h1->Integral(lowBin,upBin);
49  double sigBkg=badAll*badBkgFrac[ipt]*sigBkgOverBadBkg[ipt];
50  lowBin=h1->FindBin(Cut::mSDcaGl[0]);
51  upBin=h1->FindBin(Cut::mSDcaGl[1]-.00001);
52  double sig=h1->Integral(lowBin,upBin);
53  double bkgFrac = sigBkg/sig;
54  cout << h1->GetTitle() " : " << bkgFrac << endl;
55  hBack->SetBinContent(ipt+1,bkgFrac);
56  }
57  cout << "writing " << outName << endl;
58  outRoot->Write();
59 }