StRoot  1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
simpleFgtCosmicQA.C
1 /***************************************************************************
2  *
3  * $Id: simpleFgtCosmicQA.C,v 1.1 2012/01/31 09:26:18 sgliske Exp $
4  * Author: S. Gliske, Sept 2011
5  *
6  ***************************************************************************
7  *
8  * Description: Script to make the basic, raw QA plots for a single
9  * quadrant
10  *
11  ***************************************************************************
12  *
13  * $Log: simpleFgtCosmicQA.C,v $
14  * Revision 1.1 2012/01/31 09:26:18 sgliske
15  * StFgtQaMakers moved to StFgtPool
16  *
17  * Revision 1.6 2011/10/03 19:39:46 avossen
18  * compiling version of simple cluster maker, changed PushBack->pushBack energy->charge in ClusterArray and Cluster
19  *
20  * Revision 1.5 2011/09/28 17:48:50 sgliske
21  * minor updates
22  *
23  * Revision 1.4 2011/09/27 15:28:17 sgliske
24  * added common StFgtQaMaker parent
25  *
26  * Revision 1.3 2011/09/27 00:49:01 sgliske
27  * cosmic QA update
28  *
29  * Revision 1.2 2011/09/26 16:55:53 sgliske
30  * Continued work on cosmic QA plots
31  *
32  * Revision 1.1 2011/09/24 02:14:10 sgliske
33  * updated FGT cosmic QA
34  *
35  *
36  **************************************************************************/
37 
38 // forward declarations
39 class StChain;
40 class StFgtCosmicMaker;
41 class StFgtRawMaker;
42 class StFgtEvent;
44 class StFgtPedPlotter;
45 
46 StChain *analysisChain = 0;
47 StFgtCosmicMaker *cosmicMkr = 0;
48 
49 StFgtQaAdcVsChannel *adcVsChan = 0;
50 StFgtQaAdcVsChannel *adcVsR = 0;
51 StFgtQaAdcVsChannel *adcVsPhi = 0;
52 StFgtQaAdcVsChannel *adcSansPedVsChan = 0;
53 StFgtQaAdcVsChannel *adcSansPedVsR = 0;
54 StFgtQaAdcVsChannel *adcSansPedVsPhi = 0;
55 StFgtPedPlotter *pedPlotterC = 0;
56 StFgtPedPlotter *pedPlotterR = 0;
57 StFgtPedPlotter *pedPlotterP = 0;
58 
59 TCanvas *can = 0;
60 
61 Int_t simpleFgtCosmicQA( const Char_t *filename = "testfile.sfs",
62  const Char_t *pedfilename = "testfile.Ped.txt",
63  Int_t disc = 0,
64  Int_t quad = 0,
65  const Char_t *runname = "testrun",
66  const Char_t *quadname = "010",
67  Int_t nevents = 1999,
68  Int_t timeBin = 4,
69  Int_t numDiscs = 3 ){
70  LoadLibs();
71  Int_t ierr = 0;
72 
73  cout << "Constructing the ped plotter" << endl;
74  pedPlotterC = new StFgtPedPlotter;
75  pedPlotterC->setReadFromFile( pedfilename );
76  pedPlotterC->setTimeBinMask( 1<<timeBin );
77  pedPlotterC->setPlotVsStrip( 'c' );
78  pedPlotterC->setDisc( disc );
79  pedPlotterC->setQuad( quad );
80  pedPlotterC->setQuadName( quadname );
81 
82  pedPlotterR = new StFgtPedPlotter;
83  pedPlotterR->setReadFromFile( pedfilename );
84  pedPlotterR->setTimeBinMask( 1<<timeBin );
85  pedPlotterR->setPlotVsStrip( 'R' );
86  pedPlotterR->setDisc( disc );
87  pedPlotterR->setQuad( quad );
88  pedPlotterR->setQuadName( quadname );
89 
90  pedPlotterP = new StFgtPedPlotter;
91  pedPlotterP->setReadFromFile( pedfilename );
92  pedPlotterP->setTimeBinMask( 1<<timeBin );
93  pedPlotterP->setPlotVsStrip( 'P' );
94  pedPlotterP->setDisc( disc );
95  pedPlotterP->setQuad( quad );
96  pedPlotterP->setQuadName( quadname );
97 
98  cout << "making the graphs" << endl;
99  ierr = pedPlotterR->makePlots();
100  ierr &= pedPlotterP->makePlots();
101  ierr &= pedPlotterC->makePlots();
102 
103  if( ierr ){
104  return ierr;
105  };
106 
107  cout << "Constructing the chain" << endl;
108  analysisChain = new StChain("eemcAnalysisChain");
109 
110  cout << "Constructing the cosmic maker" << endl;
111  cosmicMkr = new StFgtCosmicMaker( "cosmicMaker", filename );
112  cout <<"constructing raw maker" <<endl;
113  StFgtRawMaker *rawMkr = new StFgtRawMaker();
114  cout <<"done" <<endl;
115  cosmicMkr->setNumDiscs( numDiscs );
116 
117 
118 
119 
120  cout << "Constructing the QA makers" << endl;
121 
122  Float_t sansPedYmax = 512;
123  Float_t sansPedYmin = -512;
124  Int_t sansPedYbins = (sansPedYmax-sansPedYmin)/8;
125 
126  // so that don't have to rebin later
127  Int_t binFactorXc = 8, binFactorXr = 2, binFactorXp = 4, binFactorY = 32;
128 
129  adcVsChan = new StFgtQaAdcVsChannel( "fgtQaAdc_1", "cosmicMaker", disc, quad, quadname );
130  adcVsChan->setTimeBin( timeBin );
131  adcVsChan->setFilenameBase( "" );
132  adcVsChan->setToPlotVsStrip( 'c' );
133  adcVsChan->setToSubtrPeds( 0 );
134  adcVsChan->setBinFactors( binFactorXc, binFactorY );
135 
136  adcVsR = new StFgtQaAdcVsChannel( "fgtQaAdc_2", "cosmicMaker", disc, quad, quadname );
137  adcVsR->setTimeBin( timeBin );
138  adcVsR->setFilenameBase( "" );
139  adcVsR->setToPlotVsStrip( 'R' );
140  adcVsR->setToSubtrPeds( 0 );
141  adcVsR->setBinFactors( binFactorXr, binFactorY );
142 
143  adcVsPhi = new StFgtQaAdcVsChannel( "fgtQaAdc_3", "cosmicMaker", disc, quad, quadname );
144  adcVsPhi->setTimeBin( timeBin );
145  adcVsPhi->setFilenameBase( "" );
146  adcVsPhi->setToPlotVsStrip( 'P' );
147  adcVsPhi->setToSubtrPeds( 0 );
148  adcVsPhi->setBinFactors( binFactorXp, binFactorY );
149 
150  adcSansPedVsChan = new StFgtQaAdcVsChannel( "fgtQaAdc_4", "cosmicMaker", disc, quad, quadname );
151  adcSansPedVsChan->setTimeBin( timeBin );
152  adcSansPedVsChan->setFilenameBase( "" );
153  adcSansPedVsChan->setToPlotVsStrip( 'c' );
154  adcSansPedVsChan->setToSubtrPeds( 1 );
155  adcSansPedVsChan->setPedReaderFile( pedfilename );
156  //adcSansPedVsChan->setPedThres( 3.0 );
157  adcSansPedVsChan->setYbins( sansPedYbins );
158  adcSansPedVsChan->setYrange( sansPedYmin, sansPedYmax );
159  adcSansPedVsChan->setBinFactors( binFactorXc, 1 );
160 
161  adcSansPedVsR = new StFgtQaAdcVsChannel( "fgtQaAdc_5", "cosmicMaker", disc, quad, quadname );
162  adcSansPedVsR->setTimeBin( timeBin );
163  adcSansPedVsR->setFilenameBase( "" );
164  adcSansPedVsR->setToPlotVsStrip( 'R' );
165  adcSansPedVsR->setToSubtrPeds( 1 );
166  adcSansPedVsR->setPedReaderFile( pedfilename );
167  //adcSansPedVsR->setPedThres( 3.0 );
168  adcSansPedVsR->setYbins( sansPedYbins );
169  adcSansPedVsR->setYrange( sansPedYmin, sansPedYmax );
170  adcSansPedVsR->setBinFactors( binFactorXr, 1 );
171 
172  adcSansPedVsPhi = new StFgtQaAdcVsChannel( "fgtQaAdc_6", "cosmicMaker", disc, quad, quadname );
173  adcSansPedVsPhi->setTimeBin( timeBin );
174  adcSansPedVsPhi->setFilenameBase( "" );
175  adcSansPedVsPhi->setToPlotVsStrip( 'P' );
176  adcSansPedVsPhi->setToSubtrPeds( 1 );
177  adcSansPedVsPhi->setPedReaderFile( pedfilename );
178  //adcSansPedVsPhi->setPedThres( 3.0 );
179  adcSansPedVsPhi->setYbins( sansPedYbins );
180  adcSansPedVsPhi->setYrange( sansPedYmin, sansPedYmax );
181  adcSansPedVsPhi->setBinFactors( binFactorXp, 1 );
182 
183  cout << "Initializing" << endl;
184  ierr = analysisChain->Init();
185  cout << "\t done initializing" << endl;
186 
187  if( ierr ){
188  cout << "Error initializing" << endl;
189  return;
190  };
191 
192  if( nevents < 0 )
193  nevents = 1<<30; // a big number
194 
195  cout << "Looping over events..." << endl;
196  for( int i=0; i<nevents && !ierr; ++i ){
197 
198  if( i%1000 == 1 )
199  cout << "event number " << i << endl;
200 
201  //cout << "clear" << endl;
202  analysisChain->Clear();
203 
204  //cout << "make" << endl;
205  ierr = analysisChain->Make();
206 
207  if( cosmicMkr->atEOF() )
208  ierr = 127;
209  };
210 
211  cout << "Making plots..." << endl;
212 
213  // now do some plotting
214  TH2F* hAdcVsChan = adcVsChan->getHist();
215  TH2F* hAdcVsR = adcVsR->getHist();
216  TH2F* hAdcVsPhi = adcVsPhi->getHist();
217  TH2F* hAdcSansPedVsChan = adcSansPedVsChan->getHist();
218  TH2F* hAdcSansPedVsR = adcSansPedVsR->getHist();
219  TH2F* hAdcSansPedVsPhi = adcSansPedVsPhi->getHist();
220 
221 // cout << "Hist ptrs " << hAdcVsChan << ' ' << hAdcVsR << ' ' << hAdcVsPhi << ' ' << hAdcSansPedVsChan << ' '
222 // << hAdcSansPedVsR << ' ' << hAdcSansPedVsPhi << endl;
223 
224  gROOT->SetStyle("Plain");
225  gStyle->SetOptStat(0);
226  gStyle->SetEndErrorSize(0);
227  gStyle->SetTitleBorderSize(0);
228  gStyle->SetTitleTextColor(kRed);
229 
230  Float_t maxY = pedPlotterC->getMaxY()*1.05;
231 
232  TH2F *histC = new TH2F ("histC", "", 1, 0, 1280, 1, 0, maxY );
233  TH2F *histR = new TH2F ("histR", "", 1, 10, 40, 1, 0, maxY );
234  TH2F *histP = new TH2F ("histP", "", 1, 0, 1.571, 1, 0, maxY );
235 
236  TH2F* hAdcArray[9] = { hAdcVsChan, hAdcVsR, hAdcVsPhi,
237  histC, histR, histP,
238  hAdcSansPedVsChan, hAdcSansPedVsR, hAdcSansPedVsPhi };
239 
240  TGraphErrors* grArray[3] = { 0, 0, 0 };
241  grArray[0] = pedPlotterC->getGraph( timeBin );
242  grArray[1] = pedPlotterR->getGraph( timeBin );
243  grArray[2] = pedPlotterP->getGraph( timeBin );
244 
245  gROOT->SetStyle("Plain");
246  TCanvas *can = new TCanvas( "fgtQAcan", "fgtQAcan", 1800, 1200 );
247 
248  gStyle->SetOptStat(0);
249  gStyle->SetPalette(1);
250 
251  can->Divide(3,3);
252  for( Int_t i=0; i<9; ++i ){
253  can->cd(i+1);
254  gPad->SetRightMargin( 0.02 );
255  gPad->SetLeftMargin( 0.13 );
256 
257  hAdcArray[i]->GetYaxis()->SetTitleOffset( 1.55 );
258 
259  if( i < 3 ){
260  hAdcArray[i]->SetMaximum( 200 );
261  hAdcArray[i]->Draw("COLZ");
262  } else if( i < 6 ) {
263  hAdcArray[i]->SetTitle( grArray[i-3]->GetTitle() );
264  hAdcArray[i]->Draw("H");
265  grArray[i-3]->SetLineColor( kBlue );
266  grArray[i-3]->Draw("PE same");
267  } else {
268  hAdcArray[i]->SetMaximum( 100 );
269  hAdcArray[i]->Draw("COLZ");
270  };
271  };
272 
273  cout << "ready to save" << endl;
274 
275  std::string fileOut = "simpleFgtCosmicQA.";
276  fileOut += runname;
277  fileOut += ".fgt";
278  fileOut += quadname;
279  fileOut += ".eps";
280 
281  //cout << "\trunname is " << runname << endl;
282  cout << "\tsaving to '" << fileOut << "'" << endl;
283  can->Print( fileOut.data() );
284 
285  //
286  // Calls the ::Finish() method on all makers
287  //
288  cout << "finish" << endl;
289  analysisChain->Finish(); // bug in LOG_ makes this fail
290 
291  cout << "all done" << endl;
292  return;
293 };
294 
295 
296 // load the shared libraries
297 void LoadLibs() {
298  // common shared libraries
299 
300  gSystem->Load("libPhysics");
301  gSystem->Load("St_base");
302  gSystem->Load("StChain");
303  gSystem->Load("StEvent");
304  cout << "loaded StEvent library" << endl;
305 
306  gSystem->Load("StFgtUtil");
307  gSystem->Load("StFgtRawMaker");
308  gSystem->Load("RTS");
309  gSystem->Load("StFgtPedMaker");
310  gSystem->Load("StFgtQaMakers");
311  gSystem->Load("StFgtPedPlotter");
312 };
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