StRoot  1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
timeShape.C
1 /***************************************************************************
2  *
3  * Author: Len K. Eun, Jan 2012
4  *
5  ***************************************************************************
6  *
7  * Description: script to run StFgtTimeShapeMaker, which reads daq files to analyze the time structure
8  *
9  ***************************************************************************
10  *
11  * $Log: timeShape.C,v $
12  * Revision 1.2 2012/02/15 05:45:20 leun
13  * *** empty log message ***
14  *
15  *
16  **************************************************************************/
17 
18 // forward declarations
19 class StChain;
20 class StFgtDbMaker;
21 class StFgtRawDaqReader;
23 class St_db_Maker;
24 class StDbConfigNode;
25 class StDbManager;
26 
27 StChain *analysisChain = 0;
28 St_db_Maker *dbMkr = 0;
29 StFgtDbMaker *fgtDbMkr = 0;
30 StFgtRawDaqReader *daqRdr = 0;
31 StFgtTimeShapeMaker *tshapeMkr = 0;
32 
33 int timeShape( const Char_t *filenameIn = "st_physics_13036040_raw_5010001.daq",
34  const Char_t *filenameOut = "run13036040.5",
35  Int_t nevents = 100000,
36  Int_t isCosmic = -1,
37  Bool_t cutShortEvents = 0 ){
38 
39  LoadLibs();
40  Int_t ierr = 0;
41 
42  if( isCosmic == -1 ){
43  isCosmic = 0;
44  std::string daqFileName( filenameIn );
45  std::string::size_type pos = daqFileName.find_last_of(".");
46 
47  if( pos != std::string::npos && daqFileName.substr( pos ) == ".sfs" )
48  isCosmic = 1;
49  };
50 
51  if( isCosmic )
52  cout << "Is Cosmic" << endl;
53  else
54  cout << "Is not cosmic" << endl;
55 
56 
57  cout << "Constructing the chain" << endl;
58  analysisChain = new StChain("eemcAnalysisChain");
59 
60  std::string fgtDbMkrName = "";
61 
62  if( !isCosmic ){
63  // always cut short events if it is cosmic data
64  cutShortEvents = 1;
65 
66  cout << "Loading St_db_Maker" << endl;
67  gSystem->Load("libStDb_Tables.so");
68  gSystem->Load("StDbLib.so");
69  gSystem->Load("St_db_Maker");
70  gSystem->Load("StDbBroker");
71 
72  TString dir0 = "MySQL:StarDb";
73  TString dir1 = "$STAR/StarDb";
74  St_db_Maker *dbMkr = new St_db_Maker( "dbMkr", dir0, dir1 );
75  dbMkr->SetDateTime(20120213,150645);//2012-02-13 15:06:45 GMT, database time needs to be set manually for now.
76 
77  cout << "Loading StFgtDbMaker" << endl;
78  gSystem->Load("StFgtDbMaker");
79 
80  cout << "Constructing StFgtDbMaker" << endl;
81  fgtDbMkr = new StFgtDbMaker( "fgtDbMkr" );
82 
83  fgtDbMkrName = fgtDbMkr->GetName();
84 
85  cout << "Fgt DB Maker Name " << fgtDbMkrName << endl;
86  };
87  cout << "Constructing the daq reader" << endl;
88  daqRdr = new StFgtRawDaqReader( "daqReader", filenameIn, fgtDbMkrName.data() );
89  daqRdr->setIsCosmic( isCosmic );
90  daqRdr->cutShortEvents( cutShortEvents );
91  cout << "Fgt DB Maker Name " << fgtDbMkrName.data() << endl;
92  cout << "Constructing the Time Shape Maker" << endl;
93  tshapeMkr = new StFgtTimeShapeMaker( "FgtTimeShapeMaker", fgtDbMkrName.data() );
94  std::string outFileName( filenameOut );
95  tshapeMkr->fname=outFileName;
96  tshapeMkr->fitThresh=600;//ADC count above pedestal for fitting, typical width of the pedestal is ~35 counts.
97  tshapeMkr->plotThresh=700;//ADC count above pedestal for generating fit plots. If (plotThresh<fitThresh), plotThresh=fitThresh
98  tshapeMkr->fixTau=false;//Funtion to fix the width parameter in the fit. Not activated yet
99  tshapeMkr->Ntimebin=7;//Number of time bins in the data
100  tshapeMkr->pedSelect=1;//pedSelect = 0: time bin 0 for each event, 1: the lowest adc count for each event, 2: from database, event independent.
101 
102 
103  // debug
104  // analysisChain->ls(4);
105 
106  cout << "Initializing" << endl;
107  ierr = analysisChain->Init();
108 
109  if( ierr ){
110  cout << "Error initializing" << endl;
111  return;
112  };
113 
114  if( nevents < 0 )nevents = 1<<30; // a big number
115 
116  cout << "max nevents = " << nevents << endl;
117  for( int i=0; i<nevents && !ierr; ++i ){
118 
119  //cout << "event number " << i << endl;
120 
121  //cout << "clear" << endl;
122  analysisChain->Clear();
123 
124  //cout << "make" << endl;
125  ierr = analysisChain->Make();
126 
127  };
128 
129  //
130  // Calls the ::Finish() method on all makers
131  //
132  cout << "finish" << endl;
133  analysisChain->Finish();
134 
135  cerr << "\tall done" << endl;
136  return;
137 };
138 
139 
140 // load the shared libraries
141 void LoadLibs() {
142  // common shared libraries
143 
144  gSystem->Load("libPhysics");
145  gSystem->Load("St_base");
146  gSystem->Load("StChain");
147  gSystem->Load("StFgtUtil");
148  gSystem->Load("StUtilities");
149  gSystem->Load("StEvent");
150  cout << "loaded StEvent library" << endl;
151 
152  gSystem->Load("StFgtUtil");
153  gSystem->Load("StFgtRawMaker");
154  gSystem->Load("StFgtRawDaqReader");
155  gSystem->Load("RTS");
156  gSystem->Load("StFgtTimeShapeMaker");
157  gSystem->Load("StFgtDbMaker");
158 };
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