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