StRoot  1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
combineRatios.C
1 void combineRatios(char* dir, char* OutFilename, int num, int startnum = 0) {
2  // Author: Michael Daugherity
3 
4  // combineRatios uses Support class to create charge-type correlations seperately for several input
5  // files, then combines them as a pair-weighted average. The output file consists of 16 histograms
6  // with names such as CIDEtaDPhi. This version does *not* do the necessary chi^2 minimization for YtYt.
7 
8  // Calling: reads dir/final0(startnum).root to dir/final0(startnum+num-1).root
9  // example: combineRatios(".","comb.root",10) reads final00.root to final09.root in current directory
10 
11 
12  const int MAX=45;
13  if(num>MAX) {
14  cout << "OVERFLOW, increase MAX!!!" << endl;
15  return;
16  }
17 
18  TFile* tf[MAX];
19  TString filename;
20 
21  for(int i=0; i<num; i++) {
22  filename=dir; filename+="/"; filename+="final0"; filename+=i+startnum; filename+=".root";
23  cout << "Loading "<< filename.Data() << endl;
24  tf[i] = new TFile(filename.Data());
25  }
26 
27  TH2D** plots[MAX];
28  StEStructSupport ehelp(tf[0],0);
29 
30  tfout = new TFile(OutFilename,"RECREATE");
31  const char* plotnames[] = {"DEtaDPhi","YtYt","EtaEta","PhiPhi"}; // Correlations to make
32  const int NUMPLOTS = 4;
33 
34  TString name;
35  double npairs[4][MAX+1]; // [0] = LS, [1] = US, [2] = CI, [3] = CD;
36  const char* pairnames[] = {"SibppNDEtaDPhi","SibmmNDEtaDPhi","SibpmNDEtaDPhi","SibmpNDEtaDPhi"};
37  double npairsCS[4]; // pair counts for pp,mm,pm,mm
38  TH2D* htemp;
39 
40 
41  for(int plot=0; plot<NUMPLOTS; plot++) {
42  name=plotnames[plot];
43 
44  for(i=0; i<num; i++) { // fill plots[] with correlations
45  ehelp.setTFile(tf[i]);
46 
47  //plots[i] = (TH2D**)ehelp.buildChargeTypeRFunctions(name);
48  plots[i] = (TH2D**)ehelp.buildNChargeTypes(name);
49 
50  if(plot==0) { // only fill pairs counts once
51  for(int j=0; j<4; j++) { // get pair counts for norm
52  htemp = (TH2D*)tf[i]->Get(pairnames[j]);
53  if (!htemp) {
54  cout << "ERROR reading " << pairnames[j] << endl;
55  return;
56  }
57  npairsCS[j] = htemp->Integral();
58  //cout << npairsCS[j] << "\t";
59  }
60  npairs[0][i] = npairsCS[0] + npairsCS[1]; // LS = pp + mm
61  npairs[1][i] = npairsCS[2] + npairsCS[3]; // US = pm + mp
62  npairs[2][i] = npairs[0][i] + npairs[1][i];// CI = LS + US
63  npairs[3][i] = npairs[2][i]; // CD = CI;
64  if(i==0) { for(j=0; j<4; j++) npairs[j][MAX] = 0;}
65  for(j=0; j<4; j++) npairs[j][MAX] += npairs[j][i];
66  }
67  }
68 
69  for (int type=0; type<4; type++) {
70  plots[0][type]->Scale(npairs[type][0]);
71  TH2D* hout = (TH2D*)plots[0][type]->Clone();
72  for(i=1; i<num; i++) {
73  plots[i][type]->Scale(npairs[type][i]);
74  hout->Add(plots[i][type]);
75  }
76  hout->Scale(1.0/npairs[type][MAX]);
77  tfout->cd();
78  cout << "Writing " << hout->GetName() << endl;
79  hout->Write();
80  }
81  }
82 
83  /*
84  cout << "Pair Counts: LS, US, CI/CD" << endl;
85  for(i=0; i<num; i++) {
86  for(j=0; j<4; j++) cout << npairs[j][i] << "\t";
87  cout << endl;
88  }
89  cout << "Totals" << endl;
90  for(j=0; j<4; j++) cout << npairs[j][MAX] << "\t";
91  cout << endl;
92  */
93 
94  //tfout->ls();
95  tfout->Close();
96 
97 }
98 
99 
100 
101