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