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