StRoot  1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
StEStructSigAnal.cxx
1 
2 #include "StEStructSigAnal.h"
3 #include "StEStructSigAnal.h"
4 
5 #include "TH2F.h"
6 #include "TFile.h"
7 
8 
9 ClassImp(StEStructSigAnal)
10 
11 //--------------------------------------------------------------------------
12 StEStructSigAnal::StEStructSigAnal( const char *inputFile, const char *prefix ) {
13  printf("Creating StEStructSigAnal object.\n");
14  mInputFile = strdup( inputFile );
15  mpreFix = strdup( prefix );
16  initArrays();
17 }
18 //--------------------------------------------------------------------------
19 StEStructSigAnal::~StEStructSigAnal() {
20  free( mInputFile );
21  free( mpreFix );
22  deleteArrays();
23 }
24 //--------------------------------------------------------------------------
25 void StEStructSigAnal::newFile( char *inputFile ) {
26  if (mInputFile) {
27  free( mInputFile );
28  }
29  if (mInFile) {
30  delete mInFile;
31  }
32  mInputFile = strdup( inputFile );
33  mInFile = new TFile( mInputFile );
34  normalizeCounters();
35 }
36 //--------------------------------------------------------------------------
37 void StEStructSigAnal::closeFile() {
38  if (mInputFile) {
39  free( mInputFile );
40  }
41  if (mInFile) {
42  delete mInFile;
43  }
44  mInputFile = 0;
45  mInFile = 0;
46 }
47 //--------------------------------------------------------------------------
48 void StEStructSigAnal::getLimits() {
49  // get number of eta and phi bins from histogram called "nBins".
50  TH2F *hnBins = (TH2F *) gDirectory->Get("nBins");
51  mNPhiBins = hnBins->GetNbinsX();
52  mNEtaBins = hnBins->GetNbinsY();
53  // get number of files. This assumes one bin for largest scale.
54  mNFiles = hnBins->GetBinContent(mNPhiBins,mNEtaBins);
55  // get minimum and maximum eta values from histogram called "EtaLimits".
56  TH1F *hEtaLimits = (TH1F *) gDirectory->Get("EtaLimits");
57  mEtaMin = hEtaLimits->GetBinContent(1) / mNFiles;
58  mEtaMax = hEtaLimits->GetBinContent(2) / mNFiles;
59 }
60 void StEStructSigAnal::normalizeCounters() {
61  getLimits();
62  TH2F *hnBins = (TH2F *) gDirectory->Get("nBins");
63  hnBins->Scale( 1.0/mNFiles );
64  TH2F *hoffset = (TH2F *) gDirectory->Get("offset");
65  hoffset->Scale( 1.0/mNFiles );
66  TH2F *hfUnique = (TH2F *) gDirectory->Get("fUnique");
67  hfUnique->Scale( 1.0/mNFiles );
68 }
69 //--------------------------------------------------------------------------
70 void StEStructSigAnal::fillHistograms() {
71  for (int i=0;i<mnSigmas;i++) {
72  mSigma[i]->fillHistograms();
73  }
74 }
75 void StEStructSigAnal::writeHistograms(TFile* sig) {
76 
77  sig->cd();
78  for (int i=0;i<mnSigmas;i++) {
79  mSigma[i]->writeHistograms();
80  }
81 }
82 //--------------------------------------------------------------------------
83 void StEStructSigAnal::initArrays() {
84 
85  // There should be a more clever way to extract the pt/centrality keys,
86  // but I can't come up with one quickly.
87  // Assume we have fewer than 20 centrality bins, fewer then 10 pt
88  // bins and fewer than 10 centrality bins for every pt bin.
89  // Every Pt bin has same number of centrality bins.
90  char hist[1024];
91 
92  mInFile = new TFile( mInputFile );
93  normalizeCounters();
94 printf("Scanning for centrality bins.\n");
95  mnCents = 0;
96  for (int i=0;i<100;i++) {
97  sprintf( hist, "NSum%i_0", i );
98  if (gDirectory->Get(hist)) {
99  mnCents++;
100  }
101  }
102 printf("Found %i centrality bins. \n", mnCents);
103  mnPts = 0;
104  for (int i=0;i<100;i++) {
105  sprintf( hist, "%sNSum0_%i_0", mpreFix, i );
106  if (gDirectory->Get(hist)) {
107  mnPts++;
108  }
109  }
110 printf("Found %i Pt bins. \n", mnPts);
111  mnPtCents = 0;
112  for (int i=0;i<100;i++) {
113  sprintf( hist, "%sNSum%i_0_0", mpreFix, i );
114  if (gDirectory->Get(hist)) {
115  mnPtCents++;
116  }
117  }
118 printf("Found %i Pt centrality bins. \n", mnPtCents);
119 
120  // Want our histograms to stay around when we close mInputFile and
121  // open a new one.
122  delete mInFile;
123 
124  mnSigmas = mnCents + mnPts*mnPtCents;
125  mSigma = new StEStructSigmas*[mnSigmas];
126  char key[1024];
127  for (int i=0;i<mnCents;i++) {
128  sprintf(key,"%i",i);
129  mSigma[i] = new StEStructSigmas(key,mNPhiBins,mNEtaBins,mEtaMin,mEtaMax);
130  }
131  int index = mnCents;
132  for (int i=0;i<mnPtCents;i++) {
133  for (int j=0;j<mnPts;j++) {
134  sprintf(key,"%i_%i",i,j);
135  mSigma[index] = new StEStructSigmas(key,mNPhiBins,mNEtaBins,
136  mEtaMin,mEtaMax,mpreFix);
137  index++;
138  }
139  }
140  mInFile = new TFile( mInputFile );
141  normalizeCounters();
142 }
143 //--------------------------------------------------------------------------
144 void StEStructSigAnal::deleteArrays() {
145  for (int i=0;i<mnSigmas;i++) {
146  delete mSigma[i];
147  }
148 }