StRoot  1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
fgtRawSpectraQA.C
1 /***************************************************************************
2  *
3  * $Id: fgtRawSpectraQA.C,v 1.3 2012/03/05 20:34:48 sgliske Exp $
4  * Author: S. Gliske, Jan 2011
5  *
6  ***************************************************************************
7  *
8  * Description: Make plot of raw spectra per quadrant. Requires the DB.
9  *
10  ***************************************************************************
11  *
12  * $Log: fgtRawSpectraQA.C,v $
13  * Revision 1.3 2012/03/05 20:34:48 sgliske
14  * update--still not really working
15  *
16  * Revision 1.2 2012/01/31 12:53:28 sgliske
17  * updates
18  *
19  * Revision 1.1 2012/01/31 09:26:18 sgliske
20  * StFgtQaMakers moved to StFgtPool
21  *
22  * Revision 1.3 2012/01/26 11:40:21 sgliske
23  * default to cutting short events
24  *
25  * Revision 1.2 2012/01/25 12:06:03 sgliske
26  * default number of events to read changed to -1
27  *
28  * Revision 1.1 2012/01/24 11:55:39 sgliske
29  * creation
30  *
31  *
32  **************************************************************************/
33 
34 // forward declarations
35 class StChain;
36 class StFgtDbMaker;
37 class StFgtRawDaqReader;
38 class St_db_Maker;
39 class StDbConfigNode;
40 class StDbManager;
41 class StFgtQaRawOctAdc;
42 
43 
44 StChain *analysisChain = 0;
45 St_db_Maker *dbMkr = 0;
46 StFgtDbMaker *fgtDbMkr = 0;
47 StFgtRawDaqReader *daqRdr = 0;
48 StFgtQaRawOctAdc *qaMkr = 0;
49 
50 TCanvas *can = 0;
51 
52 int fgtRawSpectraQA( const Char_t *filenameIn = "testfile.daq",
53  const Char_t *filebaseOut = "testfile.rawQA",
54  Int_t date = 20120115,
55  Int_t time = 0,
56  Float_t pedRelThres = 0, // 0 = no cut, otherwise: # of sigma above pedestal for cut
57  Int_t nevents = 2000,
58  Int_t timebin = 2,
59  UInt_t statusMask,
60  Bool_t cutShortEvents = 1 ){
61 
62  LoadLibs();
63  Int_t ierr = 0;
64 
65  //
66  // START CONSTRUCTING THE CHAIN
67  //
68 
69  cout << "Constructing the chain" << endl;
70  analysisChain = new StChain("eemcAnalysisChain");
71 
72  //
73  // THE DATABASE
74  //
75 
76  // note: DB is used to convert elec coords into geoIds in
77  // StEvent/StFgtStrip, and do determine the disc and quad given
78  // an rdo/arm/apv combination.
79 
80  cout << "Constructing St_db_Maker" << endl;
81 
82  TString dir0 = "MySQL:StarDb";
83  TString dir1 = "$STAR/StarDb";
84  St_db_Maker *dbMkr = new St_db_Maker( "dbMkr", dir0, dir1 );
85  dbMkr->SetDateTime(date,time);
86 
87  cout << "Constructing StFgtDbMaker" << endl;
88  fgtDbMkr = new StFgtDbMaker( "fgtDbMkr" );
89 
90  //
91  // NOW THE OTHER READERS AND MAKERS
92  //
93 
94  cout << "Constructing the daq reader" << endl;
95  daqRdr = new StFgtRawDaqReader( "daqReader", filenameIn, "" );
96  daqRdr->setIsCosmic( 0 );
97  daqRdr->cutShortEvents( cutShortEvents );
98 
99 // a2cMkr = new StFgtA2CMaker( "a2cMkr" );
100 // a2cMkr->setStatusMask( statusMask );
101 // a2cMkr->setAbsThres( -10000 ); // set to below -4096 to skip cut
102 // a2cMkr->setRelThres( pedRelThres ); // set to zero to skip cut
103 
104  cout << "Constructing the QA Makers" << endl;
105  qaMkr = new StFgtQaRawOctAdc( "qaMkr", 2 );
106  qaMkr->setTimeBin( 2 );
107 
108  // debug
109  analysisChain->ls(4);
110 
111  cout << "Initializing" << endl;
112  ierr = analysisChain->Init();
113 
114  if( ierr ){
115  cout << "Error initializing" << endl;
116  return;
117  };
118 
119  if( nevents < 0 )
120  nevents = 1<<30; // a big number
121 
122  cout << "max nevents = " << nevents << endl;
123  for( int i=0; i<nevents && !ierr; ++i ){
124 
125  if( i+1 % 100 == 0 )
126  cout << "\ton event number " << i << endl;
127 
128  //cout << "clear" << endl;
129  analysisChain->Clear();
130 
131  //cout << "make" << endl;
132  ierr = analysisChain->Make();
133 
134  };
135 
136  //
137  // Calls the ::Finish() method on all makers
138  //
139  cout << "finish" << endl;
140  analysisChain->Finish();
141 
142  cout << "Making plots" << endl;
143 
144  gROOT->SetStyle("Plain");
145  gStyle->SetOptStat(0);
146  gStyle->SetPalette(1);
147 
148  can = new TCanvas( "fgtRawQA", "fgtRawQA", 850, 1100);
149  can->Divide( 1, 4 );
150 
151  // open output file
152  can->Print( (std::string(filebaseOut) + ".ps[").data() );
153 
154  //std::vector< TH2F* >& hist = qaMkr->getHistVec();
155 
156  cout << "First hist at " << qaMkr->getHist(0) << endl;
157 
158  cout << "Finding max" << endl;
159 
160  // get max
161  Float_t max = 0;
162  for( Int_t idx = 0; idx < 48; ++idx ){
163  if( qaMkr->getHist(idx) )
164  if( qaMkr->getHist(idx)->GetMaximum() > max )
165  max = qaMkr->getHist(idx)->GetMaximum();
166  };
167  max = 0.9*max;
168 
169  cout << "Max is " << max << endl;
170 
171  TH2F *dummy[4];
172  const Char_t dummyNames[4][20] = { "dummy1", "dummy2", "dummy3", "dummy4" };
173 
174  Float_t xMin = qaMkr->getHist(0)->GetXaxis()->GetXmin();
175  Float_t xMax = qaMkr->getHist(0)->GetXaxis()->GetXmax();
176  Float_t yMin = qaMkr->getHist(0)->GetYaxis()->GetXmin();
177  Float_t yMax = qaMkr->getHist(0)->GetYaxis()->GetXmax();
178 
179  for( Int_t i=0; i<4; ++i )
180  dummy[i] = new TH2F( dummyNames[i], "", 5, xMin, xMax, 1, yMin, yMax );
181 
182  std::stringstream ss;
183 
184  Int_t subpad = 1;
185  idx = 0;
186  for( Int_t rdo = 1; rdo < 3; ++rdo ){
187  for( Int_t arm = 0; arm < 6; ++arm ){
188  for( Int_t startIdx = 0; startIdx < 4; ++startIdx, ++idx ){
189  for( Int_t oct = 0; oct < 1; ++oct ){
190 
191  cout << "rdo/arm/disc/oct = " << rdo << '/' << arm << '/' << startIdx << '/' << oct << endl;
192  if( qaMkr->getHist(idx)->GetEntries() > 0 ){
193  can->cd(subpad);
194  gPad->SetLeftMargin( 0.06 );
195  gPad->SetRightMargin( 0.05 );
196  gPad->SetBottomMargin( 0.11 );
197 
198  qaMkr->getHist(idx)->SetMaximum( max );
199  dummy[subpad-1]->GetXaxis()->SetTitleOffset(0.9);
200  dummy[subpad-1]->GetXaxis()->SetTitleSize(0.06);
201  dummy[subpad-1]->GetXaxis()->SetLabelSize(0.06);
202  dummy[subpad-1]->GetYaxis()->SetTitleOffset(0.55);
203  dummy[subpad-1]->GetYaxis()->SetTitleSize(0.06);
204  dummy[subpad-1]->GetYaxis()->SetLabelSize(0.06);
205 
206  gPad->SetGridx(0);
207  gPad->SetGridy(0);
208 
209  for( Int_t i = 0; i<5; ++i ){
210  ss.str("");
211  ss.clear();
212  ss << "channels in APV "; // startArray[startIdx]+i;
213  dummy[subpad-1]->GetXaxis()->SetBinLabel( i+1, ss.str().data() );
214  };
215  dummy[subpad-1]->GetXaxis()->SetNdivisions(222,0);
216  dummy[subpad-1]->SetMinimum( 0 );
217  dummy[subpad-1]->SetMaximum( max );
218  dummy[subpad-1]->SetTitle( qaMkr->getHist(idx)->GetTitle() );
219  qaMkr->getHist(idx)->SetTitle("");
220 
221  dummy[subpad-1]->GetYaxis()->SetTitle( qaMkr->getHist(idx)->GetYaxis()->GetTitle() );
222  qaMkr->getHist(idx)->GetYaxis()->SetTitle("");
223  dummy[subpad-1]->Draw("COLZ");
224 
225  qaMkr->getHist(idx)->Draw("COLZ SAME");
226 
227  gPad->Update();
228  gPad->Modified();
229 
230  TPaveText *title = (TPaveText*)(gPad->GetPrimitive("title"));
231  if( title ){
232  title->SetX1NDC( 0.045 );
233  title->SetX2NDC( 0.55 );
234  title->SetY1NDC( 0.91 ) ;
235  title->SetY2NDC( 0.999 );
236  title->SetBorderSize(0);
237  title->SetTextAlign( 12 );
238  title->SetTextColor(kBlue);
239  title->Draw();
240  };
241 
242  TPave *palette = (TPave*)(gPad->GetPrimitive("palette"));
243  if( palette ){
244  palette->SetX1NDC( 0.955 );
245  palette->SetX2NDC( 0.985 );
246  palette->Draw();
247  };
248 
249  ++subpad;
250  if( subpad == 5 ){
251  subpad = 1;
252  can->Print( (std::string(filebaseOut) + ".ps").data() );
253  };
254  };
255  };
256  };
257  };
258  };
259 
260  if( subpad != 1 )
261  can->Print( (std::string(filebaseOut) + ".ps").data() );
262  can->Print( (std::string(filebaseOut) + ".ps]").data() );
263 
264  gSystem->Exec(( std::string("ps2pdf -dAutoRotatePages=/None ") + filebaseOut + ".ps" ).data());
265 
266 
267  cerr << "\tall done" << endl;
268  return;
269 };
270 
271 
272 // load the shared libraries
273 void LoadLibs() {
274  // common shared libraries
275 
276  gSystem->Load("libPhysics");
277  gSystem->Load("St_base");
278  gSystem->Load("StChain");
279  gSystem->Load("StFgtUtil");
280  gSystem->Load("StUtilities");
281  gSystem->Load("StEvent");
282  cout << "loaded StEvent library" << endl;
283 
284  gSystem->Load("libStDb_Tables.so");
285  gSystem->Load("StDbLib.so");
286  gSystem->Load("St_db_Maker");
287  gSystem->Load("StDbBroker");
288  cout << "loaded DB libraries" << endl;
289 
290  gSystem->Load("RTS");
291  gSystem->Load("StFgtUtil");
292  gSystem->Load("StFgtDbMaker");
293  gSystem->Load("StFgtA2CMaker");
294  gSystem->Load("StFgtRawDaqReader");
295  gSystem->Load("StFgtPedMaker");
296  gSystem->Load("StFgtQaMakers");
297  cout << "loaded FGT libraries" << endl;
298 };
virtual void Clear(Option_t *option="")
User defined functions.
Definition: StChain.cxx:77
virtual Int_t Finish()
Definition: StChain.cxx:85
virtual void ls(Option_t *option="") const
Definition: TDataSet.cxx:495
virtual Int_t Make()
Definition: StChain.cxx:110