GSI Object Oriented Online Offline (Go4)  GO4-6.3.0
TYYYAnalysis.cxx
Go to the documentation of this file.
1 // $Id$
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 "TYYYAnalysis.h"
15 
16 #include "TCanvas.h"
17 #include "TH1.h"
18 
19 #include "TGo4AnalysisStep.h"
20 #include "TGo4Version.h"
21 
22 #include "TYYYUnpackEvent.h"
23 #include "TYYYParameter.h"
24 #include "TYYYRawEvent.h"
25 #include "TGo4StepFactory.h"
26 
27 //***********************************************************
29  TGo4Analysis()
30 {
31  TGo4Log::Error("Wrong constructor TYYYAnalysis()!");
32 }
33 
34 //***********************************************************
35 // this constructor is used
36 TYYYAnalysis::TYYYAnalysis(int argc, char **argv) :
37  TGo4Analysis(argc, argv)
38 {
40  TGo4Log::Error("Go4 version mismatch");
41  exit(-1);
42  }
43 
44  TGo4Log::Info("Create TYYYAnalysis %s", GetName());
45 
46  // the step definitions can be changed in the GUI
47  // first step definitions:
48  // the name of the step can be used later to get event objects
49  TGo4StepFactory* factory1 = new TGo4StepFactory("Unpack-factory");
50 
51  factory1->DefUserEventSource("TYYYEventSource"); // class name of user event source
52  factory1->DefInputEvent("RawEvent","TYYYRawEvent"); // object name, class name
53  factory1->DefEventProcessor("UnpackProc", "TYYYUnpackProc");// object name, class name
54  factory1->DefOutputEvent("UnpackEvent", "TYYYUnpackEvent"); // object name, class name
55 
56  TGo4UserSourceParameter* source1 = new TGo4UserSourceParameter("befoil50.scf");
57  TString parname = TString::Format("%sOutput", argv[0]);
58  TGo4FileStoreParameter* store1 = new TGo4FileStoreParameter(parname.Data());
59  store1->SetOverwriteMode(kTRUE);
60  TGo4AnalysisStep * step1 = new TGo4AnalysisStep("Unpack", factory1, source1, store1, nullptr);
61 
62  step1->SetSourceEnabled(kTRUE);
63  step1->SetStoreEnabled(kFALSE); // disable output
64  step1->SetProcessEnabled(kTRUE);
65  step1->SetErrorStopEnabled(kTRUE);
66  AddAnalysisStep(step1);
67 
68  // uncomment following line to define custom passwords for analysis server
69  // DefineServerPasswords("YYYadmin", "YYYctrl", "YYYview");
70 
72  // At this point, autosave file has not yet been read!
73  // Therefore parameter values set here will be overwritten
74  // if an autosave file is there.
75  fPar = new TYYYParameter("YYYPar1");
76  fPar->frP1 = 100;
77  fPar->frP2 = 200;
79 
80  if (!GetCanvas("TestCanvas")) {
81  TCanvas *mycan = new TCanvas("TestCanvas","Does this work?");
82  mycan->Divide(2,2);
83  AddCanvas(mycan);
84  }
85 }
86 
87 //***********************************************************
89 {
90  TGo4Log::Info("TYYYAnalysis: Delete");
91 }
92 
93 //-----------------------------------------------------------
95 {
96  TGo4Log::Info("TYYYAnalysis: PreLoop");
97  // we update the pointers to the current event structures here:
98  fRawEvent = dynamic_cast<TYYYRawEvent*> (GetInputEvent("Unpack")); // of step "Unpack"
99  fUnpackEvent = dynamic_cast<TYYYUnpackEvent*> (GetOutputEvent("Unpack"));
100  fEvents = 0;
101 
102  // create histogram for UserEventFunc
103  // At this point, the histogram has been restored from autosave file if any.
104  fSize = (TH1D*)GetHistogram("Eventsize");
105  if(!fSize) {
106  // no autosave read, create new and register
107  fSize = new TH1D ("Eventsize", "Read columns",160,1,160);
109  }
110  ClearObjects("Histograms"); // reset all histograms to 0 before run
111  // name specifies folder to clear
112  return 0;
113 }
114 
115 //-----------------------------------------------------------
117 {
118  TGo4Log::Info("TYYYAnalysis: PostLoop");
119  TGo4Log::Info("Total events: %d", fEvents);
120  TCanvas *can = GetCanvas("TestCanvas");
121  if(can) {
122  TH1 *hx = GetHistogram("Xfinal");
123  TH1 *hy = GetHistogram("Yfinal");
124  TH1 *hvx = GetHistogram("Vxfinal");
125  TH1 *hvy = GetHistogram("Vyfinal");
126  can->cd(1);
127  if(hx) hx->Draw();
128  can->cd(2);
129  if(hy) hy->Draw();
130  can->cd(3);
131  if(hvx) hvx->Draw();
132  can->cd(4);
133  if(hvy) hvy->Draw();
134  }
135 
136  fUnpackEvent = nullptr; // reset to avoid invalid pointer if analysis is changed in between
137  fRawEvent = nullptr;
138  fEvents = 0;
139  return 0;
140 }
141 
142 //-----------------------------------------------------------
144 {
146  Int_t value = 0;
147  if(fRawEvent) value = fRawEvent->GetColumns();
148  fSize->Fill(value); // fill histogram
149  fEvents++;
150  return 0;
151 }
Int_t UserEventFunc() override
const char * GetName() const override
static Bool_t CheckVersion(Int_t version)
Definition: TGo4Version.cxx:42
static void Info(const char *text,...) GO4_PRINTF_ARGS
Definition: TGo4Log.cxx:294
void DefUserEventSource(const char *Sclass)
void DefEventProcessor(const char *Pname, const char *Pclass)
friend class TGo4AnalysisStep
TYYYRawEvent * fRawEvent
Definition: TYYYAnalysis.h:33
Int_t GetColumns() const
Definition: TYYYRawEvent.h:44
void SetSourceEnabled(Bool_t on=kTRUE)
virtual ~TYYYAnalysis()
Int_t UserPreLoop() override
void SetOverwriteMode(Bool_t over=kTRUE)
TH1 * GetHistogram(const char *name)
TCanvas * GetCanvas(const char *name)
TH1D * fSize
Definition: TYYYAnalysis.h:35
Int_t UserPostLoop() override
void DefOutputEvent(const char *Oname, const char *Oclass)
Bool_t ClearObjects(const char *name)
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)
Bool_t AddCanvas(TCanvas *can, const char *subfolder=nullptr)
TGo4EventElement * GetOutputEvent() const
static void Error(const char *text,...) GO4_PRINTF_ARGS
Definition: TGo4Log.cxx:320
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)
TYYYUnpackEvent * fUnpackEvent
Definition: TYYYAnalysis.h:34
void DefInputEvent(const char *Iname, const char *Iclass)
TYYYParameter * fPar
Definition: TYYYAnalysis.h:36