GSI Object Oriented Online Offline (Go4)  GO4-5.3.2
 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 f�r 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 <stdlib.h>
17 
18 #include "TH1.h"
19 #include "TFile.h"
20 #include "TSystem.h"
21 
22 extern "C" {
23  #include "s_filhe_swap.h"
24  #include "s_bufhe_swap.h"
25  #include "f_ut_utime.h"
26 }
27 
28 #include "TGo4Fitter.h"
29 #include "TGo4FitterEnvelope.h"
30 #include "TGo4AnalysisStep.h"
31 #include "TGo4StepFactory.h"
32 #include "TXXXParameter.h"
33 #include "TXXXUnpackEvent.h"
34 #include "TXXXAnlEvent.h"
35 #include "TGo4Version.h"
36 
37 #include "Go4EventServer.h"
38 
39 //***********************************************************
41  TGo4Analysis(),
42  fMbsEvent(0),
43  fRawEvent(0),
44  fCalEvent(0)
45 {
46  TGo4Log::Error("Wrong constructor TXXXAnalysis()!");
47 }
48 
49 //***********************************************************
50 // this constructor is called by go4analysis executable
51 TXXXAnalysis::TXXXAnalysis(int argc, char** argv) :
52  TGo4Analysis(argc, argv),
53  fMbsEvent(0),
54  fRawEvent(0),
55  fCalEvent(0),
56  fSize(0),
57  fEvents(0),
58  fLastEvent(0)
59 {
61  TGo4Log::Error("Go4 version mismatch");
62  exit(-1);
63  }
64 
65  TGo4Log::Info("TXXXAnalysis: Create %s", argv[0]);
66 
67  TString kind, input, out1, out2;
68 
69  // this is a way to get user-specific arguments in batch mode, like:
70  // shell> go4analysis -x -file|-transport|-stream|-random name
71  // in this case argv[0] will be analysis name (default is "Go4Analysis")
72  // argv[1] should be type of source
73  // argv[2] should be "name" of file or MBS node
74  // any kind of additional arguments can be supplied
75 
76  switch(argc){
77  case 1:
78  TGo4Log::Info("Configure with default parameters");
79  kind = "-file";
80  input = "test";
81  out1 = "Output_Calib";
82  out2 = "Output_Anl";
83  break;
84 
85  case 2: // default kind
86  TGo4Log::Info("Configure with user-specified parameters");
87  kind = "-file";
88  input = TString::Format("%s", argv[1]);
89  out1 = TString::Format("%s_Calib", argv[1]);
90  out2 = TString::Format("%s_Anl", argv[1]);
91  break;
92  case 3:
93  default:
94  TGo4Log::Info("Configure with user-specified parameters");
95  kind = TString::Format("%s", argv[1]);
96  input = TString::Format("%s", argv[2]);
97  out1 = TString::Format("%s_Calib", argv[2]);
98  out2 = TString::Format("%s_Anl", argv[2]);
99  break;
100  }
101 // Create step 1 Unpack.
102  TGo4StepFactory* factory1 = new TGo4StepFactory("UnpackFactory");
103  factory1->DefEventProcessor("UnpackProc", "TXXXUnpackProc");// object name, class name
104  factory1->DefOutputEvent("UnpackEvent", "TXXXUnpackEvent"); // object name, class name
105  TGo4AnalysisStep* step1 = new TGo4AnalysisStep("Unpack",factory1,0,0,0);
106  step1->SetErrorStopEnabled(kTRUE);
107  AddAnalysisStep(step1);
108 // These settings will be overwritten by setup.C
109  step1->SetSourceEnabled(kTRUE);
110  step1->SetStoreEnabled(kFALSE);
111  step1->SetProcessEnabled(kTRUE);
112 
113 // Create step 2 Analysis.
114  TGo4StepFactory* factory2 = new TGo4StepFactory("AnalysisFactory");
115  factory2->DefInputEvent("UnpackEvent", "TXXXUnpackEvent"); // object name, class name
116  factory2->DefEventProcessor("AnlProc", "TXXXAnlProc"); // object name, class name
117  factory2->DefOutputEvent("AnlEvent", "TXXXAnlEvent"); // object name, class name
118  TGo4AnalysisStep* step2 = new TGo4AnalysisStep("Analysis",factory2,0,0,0);
119  step2->SetErrorStopEnabled(kTRUE);
120  AddAnalysisStep(step2);
121 // These settings will be overwritten by setup.C
122  step2->SetSourceEnabled(kFALSE);
123  step2->SetStoreEnabled(kFALSE);
124  step2->SetProcessEnabled(kTRUE);
125 
126  // uncomment following line to define custom passwords for analysis server
127  // DefineServerPasswords("XXXadmin", "XXXctrl", "XXXview");
128 
130  // At this point, autosave file has not yet been read!
131  // Therefore parameter values set here will be overwritten
132  // if an autosave file is there.
133  fPar = new TXXXParameter("XXXPar1");
134  fPar->frP1 = 100;
135  fPar->frP2 = 200;
137  fPar = new TXXXParameter("XXXPar2");
138  fPar->frP1 = 1000;
139  fPar->frP2 = 2000;
141 
142  // check that file setup.C is existing in current directory
143 
144  ExecuteScript(Form("setup.C(\"%s\",\"%s\")", kind.Data(), input.Data()));
145 }
146 
147 //***********************************************************
149 {
150  TGo4Log::Info("TXXXAnalysis: Delete");
151 }
152 //***********************************************************
153 
154 //-----------------------------------------------------------
156 {
157  TGo4Log::Info("TXXXAnalysis: PreLoop");
158  Print(); // printout the step settings
159  // we update the pointers to the current event structures here:
160  fMbsEvent = dynamic_cast<TGo4MbsEvent*> (GetInputEvent("Unpack")); // of step "Unpack"
161  fRawEvent = dynamic_cast<TXXXUnpackEvent*> (GetOutputEvent("Unpack"));
162  fCalEvent = dynamic_cast<TXXXAnlEvent*> (GetOutputEvent("Analysis"));
163  fEvents=0;
164  fLastEvent=0;
165 
166 
167  // create histogram for UserEventFunc
168  // At this point, the histogram has been restored from autosave file if any.
169  fSize=(TH1D*)GetHistogram("Eventsize");
170  if(fSize==0)
171  { // no autosave read, create new and register
172  fSize = new TH1D ("Eventsize", "Event size [b]",160,1,160);
174  }
175  // we use a fitter envelope parameters to exchange fit results:
177  if(fFitEnvSize==0)
178  {
179  TGo4Fitter* fitter=new TGo4Fitter("Gaussfit", TGo4Fitter::ff_ML_Poisson, kTRUE);;
180  // add histogram to fitter, which should be fitted
181  fitter->AddH1("data1", fSize, kFALSE);
182  // create polynom of first order
183  //fitter->AddPolynomX("data1", "Pol", 1);
184  // create gaussian
185  fitter->AddGauss1("data1", "Gauss1",15,5,1000);
186  fFitEnvSize=new TGo4FitterEnvelope("sizefitter",fitter);
188  }
190  if(fFitEnvSpectrum==0)
191  {
192  TGo4Fitter* fitter=new TGo4Fitter("Multilines", TGo4Fitter::ff_ML_Poisson, kTRUE);;
193  // add histogram to fitter, which should be fitted
194  fitter->AddH1("spectrum", fSize, kFALSE);
195  // create polynom of first order
196  fitter->AddPolynomX("spectrum", "Pol", 1);
197  // create gaussian
198  fitter->AddGauss1("spectrum", "Gauss1",500,20,1000);
199  fFitEnvSpectrum=new TGo4FitterEnvelope("specfitter",fitter);
201  }
202 
203  return 0;
204 }
205 //-----------------------------------------------------------
207 {
208  TGo4Log::Info("TXXXAnalysis: PostLoop");
209  TGo4Log::Info("Last event: %d Total events: %d", fLastEvent, fEvents);
210  if(fMbsEvent)
211  {
212  // we can check some properties of last event here:
213  //fMbsEvent->PrintEvent(); // header and data content
214 
215  // fileheader structure:
217 
218  // mbs buffer header structure:
220  }
222 // Uncomment this if you want to perform a fit
223 // each time analysis stops:
225 // if(fFitEnvSize)
226 // {
227 // std::cout <<"Fitting event size..." << std::endl;
228 // TGo4Fitter* fitter=fFitEnvSize->GetFitter();
229 // if(fitter)
230 // {
231 // //std::cout <<"Fitter setting histogram and fitting..." << std::endl;
232 // fitter->SetObject("data1", fSize, kFALSE);
233 // fitter->DoActions();
234 // fitter->PrintLines();
235 // }
236 // }
238 // second fitter:
239 // if(fFitEnvSpectrum)
240 // {
241 // std::cout <<"Fitting sum spectrum..." << std::endl;
242 // TGo4Fitter* fitter=fFitEnvSpectrum->GetFitter();
243 // if(fitter)
244 // {
245 // //std::cout <<"Fitter setting histogram and fitting..." << std::endl;
246 // TH1* his=GetHistogram("Sum2");
247 // fitter->SetObject("spectrum", his, kFALSE);
248 // fitter->DoActions();
249 // fitter->PrintLines();
250 // }
251 // }
253 
254 
257 // std::cout <<"Storing parameter fPar to Unpack:" << std::endl;
258 // StoreParameter("Unpack",fPar);
259 // std::cout <<"Storing parameter fPar to Analysis:" << std::endl;
260 // StoreParameter("Analysis",fPar);
261 // if(fFitEnvSpectrum)
262 // {
263 // std::cout <<"Storing fitter"<<fFitEnvSpectrum->GetName() <<" to analysis" << std::endl;
264 // TGo4Fitter* fitter=fFitEnvSpectrum->GetFitter();
265 // StoreFitter("Analysis",fitter);
266 // }
267 //
268 // TGo4Condition* winar=GetAnalysisCondition("winconar");
269 // if(winar)
270 // {
271 // std::cout <<"Storing condition"<< winar->GetName()<<"to analysis" << std::endl;
272 // StoreCondition("Analysis",winar);
273 // }
274 // std::cout <<"Storing all conditions to unpack." << std::endl;
275 // StoreFolder("Unpack","Conditions");
277 
278  fMbsEvent = 0; // reset to avoid invalid pointer if analysis is changed in between
279  fRawEvent = 0;
280  fCalEvent = 0;
281  fEvents=0;
282  return 0;
283 }
284 
285 //-----------------------------------------------------------
287 {
289  Int_t value = 0;
290  Int_t count = 0;
291  if(fMbsEvent) value = fMbsEvent->GetDlen()/2+2; // total longwords
292  fSize->Fill(value); // fill histogram
293  fEvents++;
294  if(fEvents == 1 || IsNewInputFile()) {
295  if(fMbsEvent) {
296  count = fMbsEvent->GetCount();
297  TGo4Log::Info("First event #: %d", count);
298 
299  // mbs buffer header structure:
301  }
302  }
303  fLastEvent = count;
304  return 0;
305 }
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:225
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:132
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:347
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:149
#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:309
TGo4FitterEnvelope * fFitEnvSize
Definition: TXXXAnalysis.h:39
static void Info(const char *text,...)
Definition: TGo4Log.cxx:283
virtual ~TXXXAnalysis()
TGo4FitDataHistogram * AddH1(const char *DataName, TH1 *histo, Bool_t Owned=kFALSE, Double_t lrange=0., Double_t rrange=0.)
Definition: TGo4Fitter.cxx:126