StRoot  1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
fgtCosmicQA.C
1 // forward declarations
2 class StChain;
3 class StFgtCosmicMaker;
4 class StFgtEvent;
6 class StFgtPedPlotter;
7 class StFgtCorAdcMaker;
9 
10 StChain *analysisChain = 0;
11 StFgtCosmicMaker *cosmicMkr = 0;
12 StFgtCorAdcMaker *adcCorrector = 0;
13 StFgtQaAdcVsChannel *adcVsChan = 0;
14 StFgtQaAdcVsChannel *adcSansPedVsChan = 0;
15 StFgtQaAdcVsChannel *adcSansPedVsR1 = 0;
16 StFgtQaAdcVsChannel *adcSansPedVsR2 = 0;
17 StFgtQaAdcVsChannel *adcSansPedVsPhi = 0;
18 StFgtPedPlotter *pedPlotter = 0;
19 StFgtQaCorrelationPlotMaker *cPlotterC = 0;
20 StFgtQaCorrelationPlotMaker *cPlotterR1 = 0;
21 StFgtQaCorrelationPlotMaker *cPlotterR2 = 0;
22 StFgtQaCorrelationPlotMaker *cPlotterP = 0;
23 
24 TCanvas *can1 = 0;
25 TCanvas *can2 = 0;
26 TCanvas *can3 = 0;
27 
28 Int_t fgtCosmicQA( const Char_t *filename = "testfile.sfs",
29  const Char_t *pedfilename = "testfile.Ped.txt",
30  Int_t disc = 0,
31  Int_t quad = 0,
32  const Char_t *runname = "testrun",
33  const Char_t *quadname = "010",
34  Int_t nevents = -1,
35  Int_t timeBin = 4,
36  Bool_t cutShortEvents = 1,
37  Bool_t skipCor = 0 ){
38  LoadLibs();
39  Int_t ierr = 0;
40 
41  // hardcoded options
42  Int_t numDiscs = 3;
43  Float_t sansPedYmax = 1024;
44  Float_t sansPedYmin = -512;
45  Int_t sansPedYbins = (sansPedYmax-sansPedYmin)/8;
46 
47  // so that don't have to rebin later
48  Int_t binFactorXc = 8, binFactorXr = 2, binFactorXp = 4, binFactorY = 32;
49  Int_t numChannelsPerCorBin = 1;
50 
51  // canvas size
52  Int_t canWidth = 850, canHeight = 1100;
53 
54  Short_t timeBinMask = (1<<timeBin);
55 
56  cout << "Constructing the ped plotter" << endl;
57  pedPlotter = new StFgtPedPlotter;
58  pedPlotter->setReadFromFile( pedfilename );
59  pedPlotter->setTimeBinMask( 1<<timeBin );
60  pedPlotter->setPlotVsStrip( 'c' );
61  pedPlotter->setDisc( disc );
62  pedPlotter->setQuad( quad );
63  pedPlotter->setQuadName( quadname );
64  pedPlotter->setPlotStDev( 1 );
65 
66  cout << "making the ped. st. dev. plots" << endl;
67  ierr = pedPlotter->makePlots();
68  cout << "\tdone" << endl;
69 
70  if( ierr ){
71  cerr << "\tError making pedistal st. dev. plot" << endl;
72  return;
73  }
74 
75  const TGraph* gr = pedPlotter->getGraph( timeBin );
76  if( !gr ){
77  cerr << "\tError making pedistal st. dev. plot" << endl;
78  return;
79  }
80 
81  cout << "Constructing the chain" << endl;
82  analysisChain = new StChain("eemcAnalysisChain");
83 
84  cout << "Constructing the cosmic maker" << endl;
85  cosmicMkr = new StFgtCosmicMaker( "cosmicMaker", filename );
86  cosmicMkr->setNumDiscs( numDiscs );
87 
88  cout << "Constructing the QA makers" << endl;
89 
90  adcVsChan = new StFgtQaAdcVsChannel( "fgtQaAdc_1", "cosmicMaker", disc, quad, quadname );
91  adcVsChan->setTimeBin( timeBin );
92  adcVsChan->setFilenameBase( "" );
93  adcVsChan->setToPlotVsStrip( 'c' );
94  adcVsChan->setToSubtrPeds( 0 );
95  adcVsChan->setBinFactors( binFactorXc, binFactorY );
96 
97  if( !skipCor ){
98  cPlotterC = new StFgtQaCorrelationPlotMaker( "cPlotter", "cosmicMaker", disc, quad, quadname );
99  cPlotterC->setTimeBin( timeBin );
100  cPlotterC->setToPlotVsStrip( 'c' );
101  cPlotterC->setBinFactors( numChannelsPerCorBin, 1 );
102  cPlotterC->setComputeCorrelations( 1 );
103  cPlotterC->setPedReaderFile( "" );
104 
105  cPlotterR1 = new StFgtQaCorrelationPlotMaker( "cPlotterR1", "cosmicMaker", disc, quad, quadname );
106  cPlotterR1->setTimeBin( timeBin );
107  cPlotterR1->setToPlotVsStrip( 'r' );
108  cPlotterR1->setBinFactors( numChannelsPerCorBin, 1 );
109  cPlotterR1->setComputeCorrelations( 1 );
110  cPlotterR1->setPedReaderFile( "" );
111 
112  cPlotterR2 = new StFgtQaCorrelationPlotMaker( "cPlotterR2", "cosmicMaker", disc, quad, quadname );
113  cPlotterR2->setTimeBin( timeBin );
114  cPlotterR2->setToPlotVsStrip( 'R1' );
115  cPlotterR2->setBinFactors( numChannelsPerCorBin, 1 );
116  cPlotterR2->setComputeCorrelations( 1 );
117  cPlotterR2->setPedReaderFile( "" );
118 
119  cPlotterP = new StFgtQaCorrelationPlotMaker( "cPlotterP", "cosmicMaker", disc, quad, quadname );
120  cPlotterP->setTimeBin( timeBin );
121  cPlotterP->setToPlotVsStrip( 'P' );
122  cPlotterP->setBinFactors( numChannelsPerCorBin, 1 );
123  cPlotterP->setComputeCorrelations( 1 );
124  cPlotterP->setPedReaderFile( "" );
125  };
126 
127  adcCorrector = new StFgtCorAdcMaker( "adcCorrector", "cosmicMaker" );
128  adcCorrector->setPedReaderFile( pedfilename );
129  adcCorrector->setTimeBinMask( timeBinMask );
130  adcCorrector->setAbsThres( -10000 ); // set below -4096 to skip cut
131  adcCorrector->setRelThres( 0 ); // set to zero to skip cut
132  adcCorrector->doSubtrPeds( 1 );
133  adcCorrector->doRemoveOtherTimeBins( 1 );
134 
135  adcSansPedVsChan = new StFgtQaAdcVsChannel( "fgtQaAdc_3", "cosmicMaker", disc, quad, quadname );
136  adcSansPedVsChan->setTimeBin( timeBin );
137  adcSansPedVsChan->setFilenameBase( "" );
138  adcSansPedVsChan->setToPlotVsStrip( 'c' );
139  adcSansPedVsChan->setToSubtrPeds( 0 );
140  adcSansPedVsChan->setYbins( sansPedYbins );
141  adcSansPedVsChan->setYrange( sansPedYmin, sansPedYmax );
142  adcSansPedVsChan->setBinFactors( binFactorXc, 1 );
143 
144  adcSansPedVsR1 = new StFgtQaAdcVsChannel( "fgtQaAdc_4", "cosmicMaker", disc, quad, quadname );
145  adcSansPedVsR1->setTimeBin( timeBin );
146  adcSansPedVsR1->setFilenameBase( "" );
147  adcSansPedVsR1->setToPlotVsStrip( 'r' );
148  adcSansPedVsR1->setToSubtrPeds( 0 );
149  adcSansPedVsR1->setYbins( sansPedYbins );
150  adcSansPedVsR1->setYrange( sansPedYmin, sansPedYmax );
151  adcSansPedVsR1->setBinFactors( binFactorXr, 1 );
152 
153  adcSansPedVsR2 = new StFgtQaAdcVsChannel( "fgtQaAdc_5", "cosmicMaker", disc, quad, quadname );
154  adcSansPedVsR2->setTimeBin( timeBin );
155  adcSansPedVsR2->setFilenameBase( "" );
156  adcSansPedVsR2->setToPlotVsStrip( 'R' );
157  adcSansPedVsR2->setToSubtrPeds( 0 );
158  adcSansPedVsR2->setYbins( sansPedYbins );
159  adcSansPedVsR2->setYrange( sansPedYmin, sansPedYmax );
160  adcSansPedVsR2->setBinFactors( binFactorXr, 1 );
161 
162  adcSansPedVsPhi = new StFgtQaAdcVsChannel( "fgtQaAdc_6", "cosmicMaker", disc, quad, quadname );
163  adcSansPedVsPhi->setTimeBin( timeBin );
164  adcSansPedVsPhi->setFilenameBase( "" );
165  adcSansPedVsPhi->setToPlotVsStrip( 'P' );
166  adcSansPedVsPhi->setToSubtrPeds( 0 );
167  adcSansPedVsPhi->setYbins( sansPedYbins );
168  adcSansPedVsPhi->setYrange( sansPedYmin, sansPedYmax );
169  adcSansPedVsPhi->setBinFactors( binFactorXp, 1 );
170 
171  cout << "Initializing" << endl;
172  ierr = analysisChain->Init();
173  cout << "\t done initializing" << endl;
174 
175  if( ierr ){
176  cout << "Error initializing" << endl;
177  return;
178  };
179 
180  if( nevents < 0 )
181  nevents = 1<<30; // a big number
182 
183  cout << "Looping over events..." << endl;
184  for( int i=0; i<nevents && !ierr; ++i ){
185 
186  if( i%1000 == 1 )
187  cout << "event number " << i << endl;
188 
189  //cout << "clear" << endl;
190  analysisChain->Clear();
191 
192  //cout << "make" << endl;
193  ierr = analysisChain->Make();
194 
195  };
196 
197  //
198  // Calls the ::Finish() method on all makers
199  //
200  cout << "finish" << endl;
201  analysisChain->Finish();
202 
203  cout << "Making plots..." << endl;
204 
205  // now do some plotting
206  TH2F* hAdcVsChan = adcVsChan->getHist();
207  TH2F* hAdcSansPedVsChan = adcSansPedVsChan->getHist();
208  TH2F* hAdcSansPedVsR1 = adcSansPedVsR1->getHist();
209  TH2F* hAdcSansPedVsR2 = adcSansPedVsR2->getHist();
210  TH2F* hAdcSansPedVsPhi = adcSansPedVsPhi->getHist();
211 
212 // cout << "Hist ptrs " << hAdcVsChan << ' ' << hAdcVsR << ' ' << hAdcVsPhi << ' ' << hAdcSansPedVsChan << ' '
213 // << hAdcSansPedVsR << ' ' << hAdcSansPedVsPhi << endl;
214 
215  gROOT->SetStyle("Plain");
216  gStyle->SetOptStat(0);
217  gStyle->SetEndErrorSize(0);
218  gStyle->SetTitleBorderSize(0);
219  gStyle->SetTitleTextColor(kRed);
220  gStyle->SetPalette(1);
221 
222  //Float_t maxY = pedPlotter->getMaxY()*1.05;
223  TH2F *histC = new TH2F ("histC", "", 1, 0, 1280, 1, 0, 200 );
224 
225  gROOT->SetStyle("Plain");
226  TCanvas *can1 = new TCanvas( "fgtQAcan1", "fgtQAcan1", canWidth, canHeight );
227 
228  can1->Divide(1,4);
229  gPad->SetGridx(0);
230 
231  // top row
232  can1->cd(1);
233  gPad->SetGridx(0);
234  hAdcVsChan->SetMaximum( 200 );
235  hAdcVsChan->Draw("COLZ");
236 
237  can1->cd(2);
238  gPad->SetGridx(0);
239  histC->SetTitle( gr->GetTitle() );
240  histC->Draw( "H" );
241  gr->SetMarkerColor( kBlue );
242  gr->SetMarkerSize( 0.4 );
243  gr->SetMarkerStyle( 20 );
244  gr->Draw("PE same");
245 
246  can1->cd(3);
247  gPad->SetGridx(0);
248  hAdcSansPedVsChan->SetMaximum( 100 );
249  hAdcSansPedVsChan->Draw("COLZ");
250 
251  can1->cd(4);
252  gPad->SetGridx(0);
253  TPad *pad = gPad;
254  pad->Divide(3,1);
255 
256  pad->cd(1);
257  gPad->SetGridx(0);
258  hAdcSansPedVsR1->SetMaximum( 100 );
259  hAdcSansPedVsR1->Draw("COLZ");
260 
261  pad->cd(2);
262  gPad->SetGridx(0);
263  hAdcSansPedVsR2->SetMaximum( 100 );
264  hAdcSansPedVsR2->Draw("COLZ");
265 
266  pad->cd(3);
267  gPad->SetGridx(0);
268  hAdcSansPedVsPhi->SetMaximum( 100 );
269  hAdcSansPedVsPhi->Draw("COLZ");
270 
271 // gPad->SetRightMargin( 0.02 );
272 // gPad->SetLeftMargin( 0.13 );
273 // hAdcArray[i]->GetYaxis()->SetTitleOffset( 1.55 );
274 
275  if( !skipCor ){
276  TCanvas *can2 = new TCanvas( "fgtQAcan2", "fgtQAcan2", canWidth, canWidth );
277  TH2F* corHist = cPlotterC->getCorrelationHist();
278 
279  gPad->SetGridx(0);
280  gPad->SetGridy(0);
281  if( corHist ){
282  corHist->SetMaximum( 1 );
283  corHist->SetMinimum( -1 );
284  corHist->Draw("COLZ");
285  };
286  };
287 
288  if( !skipCor ){
289  TCanvas *can3 = new TCanvas( "fgtQAcan3", "fgtQAcan3", canWidth, canHeight );
290  can3->Divide(1,2);
291 
292  TH2F* corHistR1 = cPlotterR1->getCorrelationHist();
293  TH2F* corHistR2 = cPlotterR2->getCorrelationHist();
294  TH2F* corHistP = cPlotterP->getCorrelationHist();
295  can3->cd(1);
296 
297  TVirtualPad *pad = gPad;
298  pad->Divide(1,2);
299 
300  pad->cd(1);
301  gPad->SetGridx(0);
302  gPad->SetGridy(0);
303 
304  if( corHistR1 ){
305  corHistR1->SetMaximum( 1 );
306  corHistR1->SetMinimum( -1 );
307  corHistR1->Draw("COLZ");
308  };
309 
310  pad->cd(2);
311  gPad->SetGridx(0);
312  gPad->SetGridy(0);
313 
314  if( corHistR2 ){
315  corHistR2->SetMaximum( 1 );
316  corHistR2->SetMinimum( -1 );
317  corHistR2->Draw("COLZ");
318  };
319 
320  can3->cd(2);
321  gPad->SetGridx(0);
322  gPad->SetGridy(0);
323 
324  if( corHistP ){
325  corHistP->SetMaximum( 1 );
326  corHistP->SetMinimum( -1 );
327  corHistP->Draw("COLZ");
328  };
329  };
330 
331 
332  cout << "ready to save" << endl;
333 
334  std::string fileOut1 = "fgtCosmicQA.page-1.";
335  std::string fileOut2 = "fgtCosmicQA.page-2.";
336  std::string fileOut3 = "fgtCosmicQA.page-3.";
337 
338  std::string tail = runname;
339  tail += ".fgt";
340  tail += quadname;
341  tail += ".pdf";
342 
343  //cout << "\trunname is " << runname << endl;
344  cout << "\tsaving to '" << tail << "'" << endl;
345  can1->Print( (fileOut1+tail).data() );
346  if( !skipCor ){
347  can2->Print( (fileOut2+tail).data() );
348  can3->Print( (fileOut3+tail).data() );
349  };
350 
351  cout << "all done" << endl;
352  return;
353 };
354 
355 
356 // load the shared libraries
357 void LoadLibs() {
358  // common shared libraries
359 
360  gSystem->Load("libPhysics");
361  gSystem->Load("St_base");
362  gSystem->Load("StChain");
363  gSystem->Load("StEvent");
364  gSystem->Load("StUtilities");
365  cout << "loaded StEvent library" << endl;
366 
367  gSystem->Load("StFgtUtil");
368  gSystem->Load("StFgtRawMaker");
369  gSystem->Load("RTS");
370  gSystem->Load("StFgtPedMaker");
371  gSystem->Load("StFgtQaMakers");
372  gSystem->Load("StFgtPedPlotter");
373  gSystem->Load("StFgtCorAdcMaker");
374 
375 };
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