StRoot  1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
makeCorrelationPlot.C
1 /***************************************************************************
2  *
3  * $Id: makeCorrelationPlot.C,v 1.1 2012/01/31 09:26:18 sgliske Exp $
4  * Author: S. Gliske, Sept 2011
5  *
6  ***************************************************************************
7  *
8  * Description: Plots the correlation coefficients and covariance.
9  *
10  ***************************************************************************
11  *
12  * $Log: makeCorrelationPlot.C,v $
13  * Revision 1.1 2012/01/31 09:26:18 sgliske
14  * StFgtQaMakers moved to StFgtPool
15  *
16  * Revision 1.2 2011/09/30 19:05:32 sgliske
17  * general update
18  *
19  * Revision 1.1 2011/09/28 17:48:50 sgliske
20  * minor updates
21  *
22  *
23  **************************************************************************/
24 
25 // forward declarations
26 class StChain;
27 class StFgtCosmicMaker;
28 class StFgtEvent;
30 
31 StChain *analysisChain = 0;
32 StFgtCosmicMaker *cosmicMkr = 0;
33 StFgtQaCorrelationPlotMaker *plotterC = 0;
34 StFgtQaCorrelationPlotMaker *plotterR = 0;
35 StFgtQaCorrelationPlotMaker *plotterP = 0;
36 
37 TCanvas *can = 0;
38 
39 Int_t makeCorrelationPlot( const Char_t *filename = "testfile.sfs",
40  const Char_t *pedfilename = "testfile.Ped.txt",
41  Int_t disc = 2,
42  Int_t quad = 0,
43  const Char_t *runname = "testrun",
44  const Char_t *quadname = "013",
45  Int_t numChannelsPerBin = 8,
46  Int_t nevents = -1,
47  Int_t timeBin = 4,
48  Int_t numDiscs = 3 ){
49  LoadLibs();
50  Int_t ierr = 0;
51 
52  cout << "Constructing the chain" << endl;
53  analysisChain = new StChain("eemcAnalysisChain");
54 
55  cout << "Constructing the cosmic maker" << endl;
56  cosmicMkr = new StFgtCosmicMaker( "cosmicMaker", filename );
57  cosmicMkr->setNumDiscs( numDiscs );
58 
59  cout << "Constructing the QA makers" << endl;
60 
61  // so that don't have to rebin later
62  Int_t binFactorX = 8;
63 
64  plotterC = new StFgtQaCorrelationPlotMaker( "plotterC", "cosmicMaker", disc, quad, quadname );
65  plotterC->setTimeBin( timeBin );
66  plotterC->setToPlotVsStrip( 'c' );
67  plotterC->setBinFactors( numChannelsPerBin, 1 );
68  plotterC->setComputeCorrelations( 1 );
69  plotterC->setPedReaderFile( pedfilename );
70 
71  plotterR = new StFgtQaCorrelationPlotMaker( "plotterR", "cosmicMaker", disc, quad, quadname );
72  plotterR->setTimeBin( timeBin );
73  plotterR->setToPlotVsStrip( 'R' );
74  plotterR->setBinFactors( numChannelsPerBin, 1 );
75  plotterR->setComputeCorrelations( 1 );
76  plotterR->setPedReaderFile( pedfilename );
77 
78  plotterP = new StFgtQaCorrelationPlotMaker( "plotterP", "cosmicMaker", disc, quad, quadname );
79  plotterP->setTimeBin( timeBin );
80  plotterP->setToPlotVsStrip( 'P' );
81  plotterP->setBinFactors( numChannelsPerBin, 1 );
82  plotterP->setComputeCorrelations( 1 );
83  plotterP->setPedReaderFile( pedfilename );
84 
85  cout << "Initializing" << endl;
86  ierr = analysisChain->Init();
87  cout << "\t done initializing" << endl;
88 
89  if( ierr ){
90  cout << "Error initializing" << endl;
91  return;
92  };
93 
94  if( nevents < 0 )
95  nevents = 1<<30; // a big number
96 
97  cout << "Looping over events..." << endl;
98  for( int i=0; i<nevents && !ierr; ++i ){
99 
100  if( i%1000 == 1 )
101  cout << "event number " << i << endl;
102 
103  //cout << "clear" << endl;
104  analysisChain->Clear();
105 
106  //cout << "make" << endl;
107  ierr = analysisChain->Make();
108 
109  if( cosmicMkr->atEOF() )
110  ierr = 127;
111  };
112 
113  //
114  // Calls the ::Finish() method on all makers
115  //
116  cout << "finish" << endl;
117  analysisChain->Finish(); // bug in LOG_ makes this fail
118 
119  cout << "Making plots..." << endl;
120 
121  // now do some plotting
122  TH2F* hPlots[6] = {
123  plotterC->getCovarianceHist(),
124  plotterR->getCovarianceHist(),
125  plotterP->getCovarianceHist(),
126  plotterC->getCorrelationHist(),
127  plotterR->getCorrelationHist(),
128  plotterP->getCorrelationHist()
129  };
130 
131  gROOT->SetStyle("Plain");
132  gStyle->SetOptStat(0);
133  gStyle->SetEndErrorSize(0);
134  gStyle->SetTitleBorderSize(0);
135  gStyle->SetTitleTextColor(kRed);
136  gStyle->SetPalette(1);
137 
138  TCanvas *can = new TCanvas( "fgtCorCan", "fgtCorCan", 1800, 1200 );
139 
140  can->Divide(3,2);
141  for( Int_t i=0; i<6; ++i ){
142  can->cd(i+1);
143  gPad->SetRightMargin( 0.02 );
144  gPad->SetLeftMargin( 0.13 );
145 
146  cout << "Plot " << i << ' ' << hPlots[i] << endl;
147  if( hPlots[i] ){
148  hPlots[i]->GetYaxis()->SetTitleOffset( 1.55 );
149  //hPlots[i]->SetMaximum( 200 );
150  hPlots[i]->Draw("COLZ");
151  };
152  };
153 
154  cout << "ready to save" << endl;
155 
156  std::string fileOut = "fgtCosmic-CorPlot.";
157  fileOut += runname;
158  fileOut += ".fgt";
159  fileOut += quadname;
160  fileOut += ".eps";
161 
162  //cout << "\trunname is " << runname << endl;
163  cout << "\tsaving to '" << fileOut << "'" << endl;
164  can->Print( fileOut.data() );
165 
166  cout << "all done" << endl;
167  return;
168 };
169 
170 
171 // load the shared libraries
172 void LoadLibs() {
173  // common shared libraries
174 
175  gSystem->Load("libPhysics");
176  gSystem->Load("St_base");
177  gSystem->Load("StChain");
178  gSystem->Load("StEvent");
179  gSystem->Load("StUtilities");
180  cout << "loaded StEvent library" << endl;
181 
182  gSystem->Load("StFgtUtil");
183  gSystem->Load("StFgtRawMaker");
184  gSystem->Load("RTS");
185  gSystem->Load("StFgtPedMaker");
186  gSystem->Load("StFgtQaMakers");
187  gSystem->Load("StFgtPedPlotter");
188 };
virtual void Clear(Option_t *option="")
User defined functions.
Definition: StChain.cxx:77
virtual Int_t Finish()
Definition: StChain.cxx:85
virtual Int_t Make()
Definition: StChain.cxx:110