GSI Object Oriented Online Offline (Go4)  GO4-6.1.4
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
TXXXAnalysis.cxx
Go to the documentation of this file.
1 // $Id: TXXXAnalysis.cxx 487 2009-11-03 17:06:10Z goofy $
2 //-----------------------------------------------------------------------
3 // The GSI Online Offline Object Oriented (Go4) Project
4 // Experiment Data Processing at EE department, GSI
5 //-----------------------------------------------------------------------
6 // Copyright (C) 2000- GSI Helmholtzzentrum fuer Schwerionenforschung GmbH
7 // Planckstr. 1, 64291 Darmstadt, Germany
8 // Contact: http://go4.gsi.de
9 //-----------------------------------------------------------------------
10 // This software can be used under the license agreements as stated
11 // in Go4License.txt file which is part of the distribution.
12 //-----------------------------------------------------------------------
13 
14 #include "TXXXAnalysis.h"
15 
16 #include "TH1.h"
17 
18 #include "TGo4Fitter.h"
19 #include "TGo4FitterEnvelope.h"
20 #include "TGo4AnalysisStep.h"
21 #include "TGo4StepFactory.h"
22 #include "TXXXParameter.h"
23 #include "TXXXUnpackEvent.h"
24 #include "TXXXAnlEvent.h"
25 #include "TGo4Version.h"
26 
27 //***********************************************************
29  TGo4Analysis(),
30  fMbsEvent(0),
31  fRawEvent(0),
32  fCalEvent(0)
33 {
34  TGo4Log::Error("Wrong constructor TXXXAnalysis()!");
35 }
36 
37 //***********************************************************
38 // this constructor is called by go4analysis executable
39 TXXXAnalysis::TXXXAnalysis(int argc, char** argv) :
40  TGo4Analysis(argc, argv),
41  fMbsEvent(0),
42  fRawEvent(0),
43  fCalEvent(0),
44  fSize(0),
45  fEvents(0),
46  fLastEvent(0)
47 {
49  TGo4Log::Error("Go4 version mismatch");
50  exit(-1);
51  }
52 
53  TGo4Log::Info("TXXXAnalysis: Create %s", argv[0]);
54 
55  TString kind, input, out1, out2;
56 
57  // this is a way to get user-specific arguments in batch mode, like:
58  // shell> go4analysis -x -file|-transport|-stream|-random name
59  // in this case argv[0] will be analysis name (default is "Go4Analysis")
60  // argv[1] should be type of source
61  // argv[2] should be "name" of file or MBS node
62  // any kind of additional arguments can be supplied
63 
64  switch(argc){
65  case 1:
66  TGo4Log::Info("Configure with default parameters");
67  kind = "-file";
68  input = "test";
69  out1 = "Output_Calib";
70  out2 = "Output_Anl";
71  break;
72 
73  case 2: // default kind
74  TGo4Log::Info("Configure with user-specified parameters");
75  kind = "-file";
76  input = TString::Format("%s", argv[1]);
77  out1 = TString::Format("%s_Calib", argv[1]);
78  out2 = TString::Format("%s_Anl", argv[1]);
79  break;
80  case 3:
81  default:
82  TGo4Log::Info("Configure with user-specified parameters");
83  kind = TString::Format("%s", argv[1]);
84  input = TString::Format("%s", argv[2]);
85  out1 = TString::Format("%s_Calib", argv[2]);
86  out2 = TString::Format("%s_Anl", argv[2]);
87  break;
88  }
89 // Create step 1 Unpack.
90  TGo4StepFactory* factory1 = new TGo4StepFactory("UnpackFactory");
91  factory1->DefEventProcessor("UnpackProc", "TXXXUnpackProc");// object name, class name
92  factory1->DefOutputEvent("UnpackEvent", "TXXXUnpackEvent"); // object name, class name
93  TGo4AnalysisStep* step1 = new TGo4AnalysisStep("Unpack",factory1,0,0,0);
94  step1->SetErrorStopEnabled(kTRUE);
95  AddAnalysisStep(step1);
96 // These settings will be overwritten by setup.C
97  step1->SetSourceEnabled(kTRUE);
98  step1->SetStoreEnabled(kFALSE);
99  step1->SetProcessEnabled(kTRUE);
100 
101 // Create step 2 Analysis.
102  TGo4StepFactory* factory2 = new TGo4StepFactory("AnalysisFactory");
103  factory2->DefInputEvent("UnpackEvent", "TXXXUnpackEvent"); // object name, class name
104  factory2->DefEventProcessor("AnlProc", "TXXXAnlProc"); // object name, class name
105  factory2->DefOutputEvent("AnlEvent", "TXXXAnlEvent"); // object name, class name
106  TGo4AnalysisStep* step2 = new TGo4AnalysisStep("Analysis",factory2,0,0,0);
107  step2->SetErrorStopEnabled(kTRUE);
108  AddAnalysisStep(step2);
109 // These settings will be overwritten by setup.C
110  step2->SetSourceEnabled(kFALSE);
111  step2->SetStoreEnabled(kFALSE);
112  step2->SetProcessEnabled(kTRUE);
113 
114  // uncomment following line to define custom passwords for analysis server
115  // DefineServerPasswords("XXXadmin", "XXXctrl", "XXXview");
116 
118  // At this point, autosave file has not yet been read!
119  // Therefore parameter values set here will be overwritten
120  // if an autosave file is there.
121  fPar = new TXXXParameter("XXXPar1");
122  fPar->frP1 = 100;
123  fPar->frP2 = 200;
125  fPar = new TXXXParameter("XXXPar2");
126  fPar->frP1 = 1000;
127  fPar->frP2 = 2000;
129 
130  // check that file setup.C is existing in current directory
131 
132  ExecuteScript(Form("setup.C(\"%s\",\"%s\")", kind.Data(), input.Data()));
133 }
134 
135 //***********************************************************
137 {
138  TGo4Log::Info("TXXXAnalysis: Delete");
139 }
140 //***********************************************************
141 
142 //-----------------------------------------------------------
144 {
145  TGo4Log::Info("TXXXAnalysis: PreLoop");
146  Print(); // printout the step settings
147  // we update the pointers to the current event structures here:
148  fMbsEvent = dynamic_cast<TGo4MbsEvent*> (GetInputEvent("Unpack")); // of step "Unpack"
149  fRawEvent = dynamic_cast<TXXXUnpackEvent*> (GetOutputEvent("Unpack"));
150  fCalEvent = dynamic_cast<TXXXAnlEvent*> (GetOutputEvent("Analysis"));
151  fEvents=0;
152  fLastEvent=0;
153 
154 
155  // create histogram for UserEventFunc
156  // At this point, the histogram has been restored from autosave file if any.
157  fSize=(TH1D*)GetHistogram("Eventsize");
158  if(fSize==0)
159  { // no autosave read, create new and register
160  fSize = new TH1D ("Eventsize", "Event size [b]",160,1,160);
162  }
163  // we use a fitter envelope parameters to exchange fit results:
165  if(fFitEnvSize==0)
166  {
167  TGo4Fitter* fitter=new TGo4Fitter("Gaussfit", TGo4Fitter::ff_ML_Poisson, kTRUE);
168  // add histogram to fitter, which should be fitted
169  fitter->AddH1("data1", fSize, kFALSE);
170  // create polynom of first order
171  //fitter->AddPolynomX("data1", "Pol", 1);
172  // create gaussian
173  fitter->AddGauss1("data1", "Gauss1",15,5,1000);
174  fFitEnvSize=new TGo4FitterEnvelope("sizefitter",fitter);
176  }
178  if(fFitEnvSpectrum==0)
179  {
180  TGo4Fitter* fitter=new TGo4Fitter("Multilines", TGo4Fitter::ff_ML_Poisson, kTRUE);
181  // add histogram to fitter, which should be fitted
182  fitter->AddH1("spectrum", fSize, kFALSE);
183  // create polynom of first order
184  fitter->AddPolynomX("spectrum", "Pol", 1);
185  // create gaussian
186  fitter->AddGauss1("spectrum", "Gauss1",500,20,1000);
187  fFitEnvSpectrum=new TGo4FitterEnvelope("specfitter",fitter);
189  }
190 
191  return 0;
192 }
193 //-----------------------------------------------------------
195 {
196  TGo4Log::Info("TXXXAnalysis: PostLoop");
197  TGo4Log::Info("Last event: %d Total events: %d", fLastEvent, fEvents);
198  if(fMbsEvent)
199  {
200  // we can check some properties of last event here:
201  //fMbsEvent->PrintEvent(); // header and data content
202 
203  // fileheader structure:
205 
206  // mbs buffer header structure:
208  }
210 // Uncomment this if you want to perform a fit
211 // each time analysis stops:
213 // if(fFitEnvSize)
214 // {
215 // std::cout <<"Fitting event size..." << std::endl;
216 // TGo4Fitter* fitter=fFitEnvSize->GetFitter();
217 // if(fitter)
218 // {
219 // //std::cout <<"Fitter setting histogram and fitting..." << std::endl;
220 // fitter->SetObject("data1", fSize, kFALSE);
221 // fitter->DoActions();
222 // fitter->PrintLines();
223 // }
224 // }
226 // second fitter:
227 // if(fFitEnvSpectrum)
228 // {
229 // std::cout <<"Fitting sum spectrum..." << std::endl;
230 // TGo4Fitter* fitter=fFitEnvSpectrum->GetFitter();
231 // if(fitter)
232 // {
233 // //std::cout <<"Fitter setting histogram and fitting..." << std::endl;
234 // TH1* his=GetHistogram("Sum2");
235 // fitter->SetObject("spectrum", his, kFALSE);
236 // fitter->DoActions();
237 // fitter->PrintLines();
238 // }
239 // }
241 
242 
245 // std::cout <<"Storing parameter fPar to Unpack:" << std::endl;
246 // StoreParameter("Unpack",fPar);
247 // std::cout <<"Storing parameter fPar to Analysis:" << std::endl;
248 // StoreParameter("Analysis",fPar);
249 // if(fFitEnvSpectrum)
250 // {
251 // std::cout <<"Storing fitter"<<fFitEnvSpectrum->GetName() <<" to analysis" << std::endl;
252 // TGo4Fitter* fitter=fFitEnvSpectrum->GetFitter();
253 // StoreFitter("Analysis",fitter);
254 // }
255 //
256 // TGo4Condition* winar=GetAnalysisCondition("winconar");
257 // if(winar)
258 // {
259 // std::cout <<"Storing condition"<< winar->GetName()<<"to analysis" << std::endl;
260 // StoreCondition("Analysis",winar);
261 // }
262 // std::cout <<"Storing all conditions to unpack." << std::endl;
263 // StoreFolder("Unpack","Conditions");
265 
266  fMbsEvent = 0; // reset to avoid invalid pointer if analysis is changed in between
267  fRawEvent = 0;
268  fCalEvent = 0;
269  fEvents=0;
270  return 0;
271 }
272 
273 //-----------------------------------------------------------
275 {
277  Int_t value = 0;
278  Int_t count = 0;
279  if(fMbsEvent) value = fMbsEvent->GetDlen()/2+2; // total longwords
280  fSize->Fill(value); // fill histogram
281  fEvents++;
282  if(fEvents == 1 || IsNewInputFile()) {
283  if(fMbsEvent) {
284  count = fMbsEvent->GetCount();
285  TGo4Log::Info("First event #: %d", count);
286 
287  // mbs buffer header structure:
289  }
290  }
291  fLastEvent = count;
292  return 0;
293 }
TGo4FitterEnvelope * fFitEnvSpectrum
Definition: TXXXAnalysis.h:40
Int_t fLastEvent
Definition: TXXXAnalysis.h:34
Bool_t AddParameter(TGo4Parameter *par, const char *subfolder=0)
static Bool_t CheckVersion(Int_t version)
Definition: TGo4Version.cxx:42
TGo4MbsEvent * fMbsEvent
Definition: TXXXAnalysis.h:31
virtual Int_t UserPreLoop()
void DefEventProcessor(const char *Pname, const char *Pclass)
TXXXAnlEvent * fCalEvent
Definition: TXXXAnalysis.h:37
void AddPolynomX(const char *DataName, const char *NamePrefix, Int_t MaxOrder=1, Int_t GroupIndex=0, Double_t lrange=0., Double_t rrange=0.)
Definition: TGo4Fitter.cxx:223
friend class TGo4AnalysisStep
TH1D * fSize
Definition: TXXXAnalysis.h:39
TGo4EventElement * GetOutputEvent()
virtual Int_t UserEventFunc()
Bool_t AddHistogram(TH1 *his, const char *subfolder=0, Bool_t replace=kTRUE)
Bool_t IsNewInputFile() const
void SetSourceEnabled(Bool_t on=kTRUE)
Int_t GetDlen() const
Definition: TGo4MbsEvent.h:135
TH1 * GetHistogram(const char *name)
TGo4EventElement * GetInputEvent(const char *stepname)
TGo4FitModelGauss1 * AddGauss1(const char *DataName, const char *ModelName, Double_t iPosition, Double_t iWidth, Double_t iAmpl=1., Int_t Axis=0)
Definition: TGo4Fitter.cxx:345
TGo4Parameter * GetParameter(const char *name, const char *parameter_class=0)
Long_t ExecuteScript(const char *script_name)
void DefOutputEvent(const char *Oname, const char *Oclass)
TXXXParameter * fPar
Definition: TXXXAnalysis.h:38
Int_t GetCount() const
Definition: TGo4MbsEvent.h:152
#define __GO4BUILDVERSION__
Definition: TGo4Version.h:24
void SetStoreEnabled(Bool_t on=kTRUE)
void PrintMbsFileHeader()
virtual void Print(Option_t *opt="") const
void PrintMbsBufferHeader()
virtual Int_t UserPostLoop()
void SetProcessEnabled(Bool_t on=kTRUE)
Bool_t AddAnalysisStep(TGo4AnalysisStep *next)
void SetErrorStopEnabled(Bool_t on)
void DefInputEvent(const char *Iname, const char *Iclass)
TXXXUnpackEvent * fRawEvent
Definition: TXXXAnalysis.h:36
static void Error(const char *text,...)
Definition: TGo4Log.cxx:313
TGo4FitterEnvelope * fFitEnvSize
Definition: TXXXAnalysis.h:39
static void Info(const char *text,...)
Definition: TGo4Log.cxx:287
virtual ~TXXXAnalysis()
TGo4FitDataHistogram * AddH1(const char *DataName, TH1 *histo, Bool_t Owned=kFALSE, Double_t lrange=0., Double_t rrange=0.)
Definition: TGo4Fitter.cxx:124