StRoot  1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
makeFgtPedAndStat.C
1 /***************************************************************************
2  *
3  * $Id: makeFgtPedAndStat.C,v 1.1 2013/02/10 14:51:29 akio Exp $
4  * Author: S. Gliske, Sept 2011
5  *
6  ***************************************************************************
7  *
8  * Description: Compute peds and status from DAQ or cosmic data file.
9  * Output QA plots if desired.
10  *
11  ***************************************************************************
12  *
13  * $Log: makeFgtPedAndStat.C,v $
14  * Revision 1.1 2013/02/10 14:51:29 akio
15  * *** empty log message ***
16  *
17  * Revision 1.6 2012/11/12 23:22:56 rfatemi
18  * *** empty log message ***
19  *
20  * Revision 1.5 2012/02/29 15:38:39 sgliske
21  * fixed bug in lynx query: ?r -> ?r=
22  *
23  * Revision 1.4 2012/02/06 04:17:19 balewski
24  * *** empty log message ***
25  *
26  * Revision 1.3 2012/02/02 14:57:46 avossen
27  * fixed chain
28  *
29  * Revision 1.2 2012/02/02 14:14:12 sgliske
30  * Need to load RawDaqReader lib, not RawMaker
31  * Also, fixed bug in using the runnumber for accessing online.star.bnl.gov
32  * Also, now only check RunLog if run number is nonzero
33  *
34  * Revision 1.1 2012/01/31 08:56:43 sgliske
35  * moved StFgtStatusMaker/macro/makeFgtPedAndStat.C to
36  * StFgtPool/StFgtQaMakers/macro/
37  *
38  * Revision 1.7 2012/01/30 17:04:23 sgliske
39  * remove automatic guess of cosmic or
40  * not based on file extension
41  *
42  * Revision 1.6 2012/01/28 13:51:47 balewski
43  * cleaned up printout
44  *
45  * Revision 1.5 2012/01/27 14:09:43 balewski
46  * switch to new consts
47  *
48  * Revision 1.4 2012/01/25 12:26:45 sgliske
49  * cosmetic change
50  *
51  * Revision 1.3 2012/01/25 12:25:24 sgliske
52  * many updates, including outputting an info file
53  *
54  * Revision 1.2 2012/01/17 23:28:25 sgliske
55  * update to use the DB
56  *
57  * Revision 1.1 2012/01/17 20:11:31 sgliske
58  * creation
59  *
60  *
61  **************************************************************************/
62 
63 #include <TSystem.h>
64 
65 // forward declarations
66 class StChain;
67 class StFgtDbMaker;
68 class StFgtRawDaqReader;
70 class StFgtStatusMaker;
71 class StFgtPedStatQA;
72 class St_db_Maker;
73 class StDbConfigNode;
74 class StDbManager;
75 
76 StChain *analysisChain = 0;
77 St_db_Maker *dbMkr = 0;
78 StFgtDbMaker *fgtDbMkr = 0;
79 StFgtRawDaqReader *daqRdr = 0;
80 StFgtRobustPedMaker *pedMkr = 0;
81 StFgtStatusMaker *statMkr = 0;
82 StFgtPedStatQA *qaMkr = 0;
83 
84 int makeFgtPedAndStat(const Char_t *filenameIn ="inputfile",
85  const Char_t *filenameOutbase ="13025001",
86  Int_t runnumber = 13025001,
87  Int_t nevents = 2000,
88  Short_t timeBinMask = 0x0,
89  Short_t timeBin = 0,
90  Bool_t doOutputTxt = 1,
91  Bool_t doOutputPdf = 1,
92  Bool_t doOutputRoot = 1,
93  Bool_t isCosmic = 0,
94  Bool_t cutShortEvents = 1 ){
95 
96  LoadLibs();
97  Int_t ierr = 0;
98 
99  if( isCosmic )
100  cout << "Is Cosmic" << endl;
101  else
102  cout << "Is not cosmic" << endl;
103 
104  //
105  // COMPUTE FILENAMES
106  //
107 
108  std::string base(filenameOutbase), pedFile, statFile, txtFile, pdfFile, rootFile, logFile;
109  pedFile = base + ".FGT-ped-DB.dat";
110  statFile = base + ".FGT-stat-DB.dat";
111  if( doOutputTxt )
112  txtFile = base + ".FGT-ped-stat.txt";
113  if( doOutputPdf )
114  pdfFile = base + ".FGT-ped-stat.ps";
115  if( doOutputRoot )
116  rootFile = base + ".FGT-ped-stat.root";
117  logFile = base + ".FGT-ped-stat-info.txt";
118 
119 
120  //
121  // START CONSTRUCTING THE CHAIN
122  //
123 
124  cout << "Constructing the chain" << endl;
125  analysisChain = new StChain("eemcAnalysisChain");
126 
127  std::string fgtDbMkrName = "";
128 
129  if( !isCosmic ){
130  // always cut short events if it is cosmic data
131  cutShortEvents = 1;
132 
133  cout << "Loading St_db_Maker" << endl;
134  gSystem->Load("libStDb_Tables.so");
135  gSystem->Load("StDbLib.so");
136  gSystem->Load("St_db_Maker");
137  gSystem->Load("StDbBroker");
138 
139  TString dir0 = "MySQL:StarDb";
140  TString dir1 = "$STAR/StarDb";
141  St_db_Maker *dbMkr = new St_db_Maker( "dbMkr", dir0, dir1 );
142  dbMkr->SetDateTime(20121127,000000);
143 
144  fgtDbMkr = new StFgtDbMaker( "fgtDbMkr" );
145  fgtDbMkrName = fgtDbMkr->GetName();
146  };
147 
148  //
149  // NOW THE OTHER READERS AND MAKERS
150  //
151 
152  cout << "Constructing the daq reader" << endl;
153  daqRdr = new StFgtRawDaqReader( "daqReader", filenameIn, fgtDbMkrName.data() );
154  daqRdr->setIsCosmic( isCosmic );
155  daqRdr->cutShortEvents( cutShortEvents );
156 
157  cout << "Constructing the Ped Maker" << endl;
158  pedMkr = new StFgtRobustPedMaker( "FgtPedMaker" );
159  pedMkr->setToSaveToFile( pedFile.data() );
160  pedMkr->setTimeBinMask( timeBinMask );
161  pedMkr->setFgtDbMkrName( fgtDbMkrName );
162  pedMkr->setNumBins( 4200 );
163  pedMkr->setMaxAdc( 4200 );
164  pedMkr->setNumSmooth( 0 );
165 
166  cout << "Constructing the Status Maker" << endl;
167  statMkr = new StFgtStatusMaker( "FgtStatusMaker", "FgtPedMaker" );
168  statMkr->setToSaveToFile( statFile.data() );
169  statMkr->setTimeBin( timeBin );
170  statMkr->setMaxDeadPerApv(128);
171 
172  cout << "Constructing the QA Maker" << endl;
173  qaMkr = new StFgtPedStatQA( "FgtPedStatQA", "FgtPedMaker", "FgtStatusMaker" );
174  qaMkr->setSaveTxtFile( txtFile.data() );
175  qaMkr->setSaveRootFile( rootFile.data() );
176  qaMkr->setSavePdfFile( pdfFile.data() );
177  qaMkr->setTimeBin( timeBin );
178 
179  // debug
180  // analysisChain->ls(4);
181 
182  cout << "Initializing" << endl;
183  ierr = analysisChain->Init();
184 
185  if( ierr ){
186  cout << "Error initializing" << endl;
187  return;
188  };
189 
190  if( nevents < 0 )
191  nevents = 1<<30; // a big number
192 
193  cout << "max nevents = " << nevents << endl;
194  for( int i=0; i<nevents && !ierr; ++i ){
195 
196  if( i+1 % 100 == 1 )
197  cout << "\ton event number " << i << endl;
198 
199  //cout << "clear" << endl;
200  analysisChain->Clear();
201 
202  //cout << "make" << endl;
203  ierr = analysisChain->Make();
204 
205  };
206 
207  fgtDbMkr->printFgtDumpCSV1("fgtMapDump.csv");
208  //
209  // Calls the ::Finish() method on all makers
210  //
211  cout << "finish" << endl;
212  analysisChain->Finish();
213 
214  // Now write a status table
215 
216  std::ofstream fout( logFile.data() );
217  if( fout ){
218  fout << "Log file generated by 'makeFgtPedAndStat' for run number " << runnumber << endl << endl;
219  fout << "CVS Ids: "<< endl;
220  fout << "\t$Id: makeFgtPedAndStat.C,v 1.1 2013/02/10 14:51:29 akio Exp $" << endl;
221  if( fgtDbMkr )
222  fout << "\t" << fgtDbMkr->GetCVS() << endl;
223  fout << "\t" << daqRdr->GetCVS() << endl;
224  fout << "\t" << pedMkr->GetCVS() << endl;
225  fout << "\t" << statMkr->GetCVS() << endl;
226  fout << "\t" << qaMkr->GetCVS() << endl << endl;
227 
228  TDatime d;
229  fout << "This file was generated " << d.AsString() << endl << endl;
230  fout << "The following options were used in this macro " << endl;
231  fout << "\tfilenameIn = " << filenameIn << endl;
232  fout << "\tfilenameOutbase = " << filenameOutbase << endl;
233  fout << "\trunnumber = " << runnumber << endl;
234  fout << "\tnevents = " << nevents << endl;
235  fout << "\ttimeBinMask = " << timeBinMask << endl;
236  fout << "\ttimeBin = " << timeBin << endl;
237  fout << "\tdoOutputTxt = " << doOutputTxt << endl;
238  fout << "\tdoOutputPdf = " << doOutputPdf << endl;
239  fout << "\tdoOutputRoot = " << doOutputRoot << endl;
240  fout << "\tisCosmic = " << isCosmic << endl;
241  fout << "\tcutShortEvents = " << cutShortEvents << endl << endl;
242 
243  if( runnumber ){
244  std::stringstream ss;
245  fout << "Times given in the run log are " << endl;
246  ss << "lynx -dump 'http://online.star.bnl.gov/RunLogRun12/index.php?r=" << runnumber << "' | grep GMT";
247  FILE *f = gSystem->OpenPipe(ss.str().data(),"r");
248  Char_t c;
249  while((c=fgetc(f))!=EOF)
250  fout << c;
251  };
252  };
253  fout.close();
254 
255  // convert ps to pdf
256  if( doOutputPdf ){
257  cout << "converting ps to pdf" << endl;
258  gSystem->Exec(( std::string("ps2pdf -dAutoRotatePages=/None ") + pdfFile ).data());
259  };
260 
261  cerr << "\tall done" << endl;
262  return;
263 };
264 
265 
266 // load the shared libraries
267 void LoadLibs() {
268  // common shared libraries
269 
270  gSystem->Load("libPhysics");
271  gSystem->Load("St_base");
272  gSystem->Load("StChain");
273  gSystem->Load("StFgtUtil");
274  gSystem->Load("StUtilities");
275  gSystem->Load("StEvent");
276  cout << "loaded StEvent library" << endl;
277 
278  gSystem->Load("RTS");
279  gSystem->Load("StFgtUtil");
280  gSystem->Load("StFgtDbMaker");
281  gSystem->Load("StFgtRawDaqReader");
282  gSystem->Load("StFgtPedMaker");
283  gSystem->Load("StFgtStatusMaker");
284  gSystem->Load("StFgtQaMakers");
285 
286 
287 
288 };
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
virtual const char * GetName() const
special overload
Definition: StMaker.cxx:237