StRoot  1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
selectAllM6.C
1 void selectAllM6(const char* infile, char* outputdir = "./", int rescaleNev=0){
2  // extracts files for cutbin mode 6 (z-vertex binning)
3  // reads infile, writes final00.root to final09.root in outputdir
4 
5  cout << " selectAllM6, input: " << infile << "\tout dir: " << outputdir << endl;
6  gSystem->Load("StEStructPoolSupport.so");
7  StEStructHAdd adder;
8  TFile * tf=new TFile(infile);
9 
10  if(!tf){
11  cout<<"error opening file "<<endl;
12  return ;
13  };
14 
15  int narray[1];
16  int num=1;
17 
18 
19  if(rescaleNev) {
20  TH1D* hns = (TH1D*)tf->Get("NEventsSame");
21  int nevs = hns->GetEntries();
22  TH1D* hnm = (TH1D*)tf->Get("NEventsMixed");
23  int nevm = hnm->GetEntries();
24  cout << infile << " has " << nevs << " sibling events and " << nevm << " mixed events." << endl;
25 
26  TH1D* hcb = (TH1D*)tf->Get("hcb");
27  if(!hcb) { cout << "error loading hcb" << endl; return;}
28  TH1D* hcbs = (TH1D*)hcb->Clone("hcbs");
29  TH1D* hcbm = (TH1D*)hcb->Clone("hcbm");
30  hcbs->Scale( nevs / hcbs->Integral() );
31  hcbm->Scale( nevm / hcbm->Integral() );
32 
33  cout << "Targets " << endl;
34  for(int i=0; i<10; i++) cout << hcbs->GetBinContent(i+1) << "\t" << hcbm->GetBinContent(i+1) << endl;
35  cout << "Totals:\t" << hcbs->Integral() << "\t" << hcbm->Integral() << endl;
36 
37  /*c1 = new TCanvas("sm6","sm6",600,300);
38  c1->Divide(2,1);
39  c1->cd(1); hcbs->Draw();
40  c1->cd(2); hcbm->Draw();
41  */
42  }
43 
44  TString fname;
45  for(int i=0; i<10; i++) {
46  narray[0] = i;
47  fname=outputdir; fname+="final0"; fname+=i; fname+=".root";
48  cout << "writing " << fname << endl;
49  adder.addCuts(fname,tf,narray,num);
50 
51  if(rescaleNev) {
52  tfout = new TFile(fname,"UPDATE");
53  TH1D* hs = (TH1D*)tfout->Get("NEventsSame");
54  hs->SetEntries( hcbs->GetBinContent(i+1) );
55  hs->Write();
56  TH1D* hm = (TH1D*)tfout->Get("NEventsMixed");
57  hm->SetEntries( hcbm->GetBinContent(i+1) );
58  hm->Write();
59  tfout->Close();
60  }
61 
62  }
63 
64 
65 };
66 
67