GSI Object Oriented Online Offline (Go4)  GO4-6.3.0
TXXXProc.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 "TXXXProc.h"
15 
16 #include "TH1.h"
17 #include "TH2.h"
18 #include "TProfile.h"
19 #include "TProfile2D.h"
20 #include "TCutG.h"
21 
22 #include "TGo4Log.h"
23 #include "TGo4WinCond.h"
24 #include "TGo4PolyCond.h"
25 #include "TGo4CondArray.h"
26 #include "TGo4Picture.h"
27 #include "TGo4MbsEvent.h"
28 
29 #include "TXXXControl.h"
30 #include "TXXXEvent.h"
31 
32 //***********************************************************
34 {
35  TGo4Log::Info("TXXXProc: Create instance");
36 }
37 
38 //***********************************************************
40 {
41  TGo4Log::Info("TXXXProc: Delete instance");
42 }
43 
44 //***********************************************************
45 // this one is used in standard factory
46 TXXXProc::TXXXProc(const char *name) : TGo4EventProcessor(name)
47 {
48  TGo4Log::Info("TXXXProc: Create instance %s", name);
49 
51 
52  // Parameters are created in analysis, therefore just take it out
53  fControl = (TXXXControl *) GetParameter("Control");
54 
55  // This example analysis allows for en-disabling the histogram filling.
56  // Macro histofill.C sets histogram fill status in parameter "Control".
57  // This macro histofill.C, not the auto save file, will set status.
58  ExecuteScript("histofill.C");
59  fControl->Print();
60 
61  TGo4Log::Info("TXXXProc: Produce histograms");
62  // Creation of histograms (or take them from autosave)
63  for (int i = 0; i < 8; i++) {
64  TString hname = TString::Format("Crate1/Cr1Ch%02d", i + 1);
65  TString htitle = TString::Format("Crate 1 channel %2d", i+1);
66  fCr1Ch[i] = MakeTH1('I', hname.Data(), htitle.Data(), 5000, 1., 5001.);
67  hname = TString::Format("Crate2/Cr2Ch%02d",i+1);
68  htitle = TString::Format("Crate 2 channel %2d",i+1);
69  fCr2Ch[i] = MakeTH1('I', hname.Data(), htitle.Data(), 5000, 1., 5001.);
70  }
71 
72  fCr1Ch1x2 = MakeTH2('I', "Cr1Ch1x2","Crate 1 channel 1x2", 200, 1., 5001., 200, 1., 5001.);
73  fHis1 = MakeTH1('I', "His1","Condition histogram", 5000, 1., 5001.);
74  fHis2 = MakeTH1('I', "His2","Condition histogram", 5000, 1., 5001.);
75  fHis1gate = MakeTH1('I', "His1g","Gated histogram", 5000, 1., 5001.);
76  fHis2gate = MakeTH1('I', "His2g","Gated histogram", 5000, 1., 5001.);
77 
78  TGo4Log::Info("TXXXProc: Produce conditions");
79  fconHis1 = MakeWinCond("cHis1", 100, 2000, "His1");
80  fconHis2 = MakeWinCond("cHis2", 100, 2000, "His2");
81 
82  Double_t cutpnts[3][2] = { {400, 800}, {700, 900}, {600, 1100} };
83  fPolyCon = MakePolyCond("polycon", 3, cutpnts);
84 
86  if(!fConArr) {
87  // This is example how to create condition array
88  TGo4Log::Info("TXXXProc: Create condition array");
89  Double_t xvalues[4] = { 1000, 2000, 1500, 1000 };
90  Double_t yvalues[4] = { 1000, 1000, 3000, 1000 };
91  TCutG *mycut = new TCutG("cut2", 4, xvalues, yvalues);
92  fConArr = new TGo4CondArray("polyconar",4,"TGo4PolyCond");
93  fConArr->SetValues(mycut);
94  fConArr->Disable(true); // means: condition check always returns true
95  delete mycut; // mycat has been copied into the conditions
97  } else {
98  TGo4Log::Info("TXXXProc: Restore condition array from autosave");
100  }
101  // connect histograms to conditions. will be drawn when condition is edited.
102  ((*fConArr)[0])->Enable();
103  ((*fConArr)[1])->Enable(); // 2 and 3 remain disabled
104 
105  TGo4Log::Info("TXXXProc: Produce pictures");
106  fcondSet = GetPicture("condSet");
107  if (!fcondSet) {
108  // in the upper two pads, the condition limits can be set,
109  // in the lower two pads, the resulting histograms are shown
110  fcondSet = new TGo4Picture("condSet","Set conditions");
111  fcondSet->SetDivision(2,2);
112  fcondSet->Pic(0,0)->AddObject(fHis1);
113  fcondSet->Pic(0,1)->AddObject(fHis2);
118  fcondSet->Pic(1,0)->SetFillAtt(4, 1001); // solid
119  fcondSet->Pic(1,0)->SetLineAtt(4,1,1);
120  fcondSet->Pic(1,1)->SetFillAtt(9, 1001); // solid
121  fcondSet->Pic(1,1)->SetLineAtt(9,1,1);
123  }
124 
125  fPicture = GetPicture("Picture");
126  if (!fPicture) {
127  fPicture = new TGo4Picture("Picture","Picture example");
128  fPicture->SetLinesDivision(3, 2,3,1);
129  fPicture->LPic(0,0)->AddObject(fCr1Ch[0]);
130  fPicture->LPic(0,0)->SetFillAtt(5, 3001); // pattern
131  fPicture->LPic(0,0)->SetLineAtt(5,1,1);
132  fPicture->LPic(0,1)->AddObject(fCr1Ch[1]);
133  fPicture->LPic(0,1)->SetFillAtt(4, 3001); // pattern
134  fPicture->LPic(0,1)->SetLineAtt(4,1,1);
135  fPicture->LPic(1,0)->AddObject(fCr1Ch[2]);
136  fPicture->LPic(1,0)->SetFillAtt(6, 1001); // solid
137  fPicture->LPic(1,0)->SetLineAtt(6,1,1);
138  fPicture->LPic(1,1)->AddObject(fCr1Ch[3]);
139  fPicture->LPic(1,1)->SetFillAtt(7, 1001); // solid
140  fPicture->LPic(1,1)->SetLineAtt(7,1,1);
141  fPicture->LPic(1,2)->AddObject(fCr1Ch[4]);
143  fPicture->LPic(3,0)->SetDrawOption("CONT");
145  }
146 
147  fProfile = dynamic_cast<TProfile *>(GetObject("profile"));
148  if (!fProfile) {
149  fProfile = new TProfile("profile","Example of TProfile usage", 5000, 1., 5001., 1., 5001.);
150  fProfile->SetDirectory(nullptr);
152  }
153 
154  fProfile2D = dynamic_cast<TProfile2D *>(GetObject("profile2d"));
155  if (!fProfile2D) {
156  fProfile2D = new TProfile2D("profile2d","Example of TProfile2D usage", 200, 1., 5001., 200, 1., 5001., 1., 5001.);
157  fProfile2D->SetDirectory(nullptr);
159  }
160 }
161 //-----------------------------------------------------------
162 // event function
164 {
165  // called by framework from TXXXEvent to fill it
166 
167  TXXXEvent *XXXEvent = (TXXXEvent *) target;
168 
169  TGo4MbsEvent *source = (TGo4MbsEvent *) GetInputEvent();
170  if(!source) {
171  TGo4Log::Error("TXXXProc: no input event!");
172  return kFALSE;
173  }
174  if(source->GetTrigger() > 11) {
175  TGo4Log::Info("TXXXProc: Skip trigger event");
176  XXXEvent->SetValid(kFALSE); // not store
177  return kFALSE;
178  }
179  // first we fill the TXXXEvent with data from MBS source
180  // we have up to two subevents, crate 1 and 2
181  // Note that one has to loop over all subevents and select them by
182  // crate number: psubevt->GetSubcrate(),
183  // procid: psubevt->GetProcid(),
184  // and/or control: psubevt->GetControl()
185  // here we use only crate number
186 
187  source->ResetIterator();
188  while(auto psubevt = source->NextSubEvent()) { // loop over subevents
189  Int_t *pdata = psubevt->GetDataField();
190  Int_t lwords = psubevt->GetIntLen();
191  if(lwords > 8) lwords=8; // take only first 8 lwords
192 
193  if(psubevt->GetSubcrate() == 1) {
194  for(Int_t i = 0; i<lwords; i++) {
195  // Int_t index = *pdata&0xfff; // in case low word is index
196  //Float_t value = (*pdata>>16)&0xfff; // and high word is data
197  Float_t value = (Float_t)*pdata++; // otherwise longword data
198  Int_t index = i; // and index in order
199  XXXEvent->fCrate1[index] = value; // copy to output event
200  }
201  }
202  if(psubevt->GetSubcrate() == 2)
203  for(Int_t i = 0; i<lwords; i++)
204  XXXEvent->fCrate2[i] = (Float_t)*pdata++;
205  }
206 
207  // now we fill histograms from XXXEvent
208  if(fControl->fill) {
209  for(Int_t i = 0; i<8; i++) {
210  fCr1Ch[i]->Fill(XXXEvent->fCrate1[i]);
211  fCr2Ch[i]->Fill(XXXEvent->fCrate2[i]);
212  }
213  Float_t value1 = XXXEvent->fCrate1[0];
214  Float_t value2 = XXXEvent->fCrate1[1];
215  Float_t value3 = XXXEvent->fCrate1[3];
216  fHis1->Fill(value1); //fill histograms without gate
217  fHis2->Fill(value2);
218 
219  fProfile->Fill(value1, value2, 1);
220  fProfile2D->Fill(value1, value2, value3, 1);
221 
222  if (fconHis1->Test(value1)) fHis1gate->Fill(value1); //fill histograms with gate
223  if (fconHis2->Test(value2)) fHis2gate->Fill(value2);
224  // fill Cr1Ch1x2 for three polygons:
225  if (fPolyCon->Test(value1,value2)) fCr1Ch1x2->Fill(value1,value2);
226  if(((*fConArr)[0])->Test(value1,value2)) fCr1Ch1x2->Fill(value1,value2);
227  if(((*fConArr)[1])->Test(value1,value2)) fCr1Ch1x2->Fill(value1,value2);
228  }
229  XXXEvent->SetValid(kTRUE); // to store
230  return kTRUE;
231 }
TH1 * MakeTH1(char type, const char *fullname, const char *title, Int_t nbinsx, Double_t xlow, Double_t xup, const char *xtitle=nullptr, const char *ytitle=nullptr)
void ResetCounts() override
Long64_t ExecuteScript(const char *script_name)
void Disable(Bool_t result) override
Bool_t fill
Definition: TXXXControl.h:23
TXXXProc()
Definition: TXXXProc.cxx:33
TNamed * GetObject(const char *name, const char *folder=nullptr)
void AddCondition(TNamed *cond=nullptr)
void SetValid(Bool_t on)
TGo4Picture * GetPicture(const char *name)
static void Info(const char *text,...) GO4_PRINTF_ARGS
Definition: TGo4Log.cxx:294
TH1 * fHis2
Definition: TXXXProc.h:37
Bool_t AddPicture(TGo4Picture *pic, const char *subfolder=nullptr)
void SetValues(Double_t low1, Double_t up1) override
TProfile2D * fProfile2D
Definition: TXXXProc.h:47
TGo4Picture * fPicture
Definition: TXXXProc.h:44
Bool_t BuildEvent(TGo4EventElement *target) override
Definition: TXXXProc.cxx:163
TH2 * MakeTH2(char type, const char *fullname, const char *title, Int_t nbinsx, Double_t xlow, Double_t xup, Int_t nbinsy, Double_t ylow, Double_t yup, const char *xtitle=nullptr, const char *ytitle=nullptr, const char *ztitle=nullptr)
TGo4Picture * fcondSet
Definition: TXXXProc.h:45
TXXXControl * fControl
Definition: TXXXProc.h:43
TH1 * fHis1
Definition: TXXXProc.h:35
void AddObject(TObject *obj, Option_t *DrawOption=nullptr)
Bool_t Test(Double_t x, Double_t y) override
TGo4Picture * Pic(Int_t posy, Int_t posx)
TGo4MbsSubEvent * NextSubEvent(Bool_t all=kFALSE)
void SetDivision(Int_t ndivy, Int_t ndivx)
TH1 * fHis2gate
Definition: TXXXProc.h:38
TGo4WinCond * fconHis2
Definition: TXXXProc.h:40
TGo4CondArray * fConArr
Definition: TXXXProc.h:42
void Print(Option_t *opt="") const override
virtual ~TXXXProc()
Definition: TXXXProc.cxx:39
TGo4Condition * GetAnalysisCondition(const char *name, const char *cond_cl=nullptr)
TProfile * fProfile
Definition: TXXXProc.h:46
void SetLineAtt(Color_t color, Style_t style, Width_t width, Int_t index=UndefIndex)
Float_t fCrate1[8]
Definition: TXXXEvent.h:28
void SetLinesDivision(Int_t numlines, const Int_t *numbers)
TH1 * fCr2Ch[8]
Definition: TXXXProc.h:33
TGo4PolyCond * fPolyCon
Definition: TXXXProc.h:41
static void Error(const char *text,...) GO4_PRINTF_ARGS
Definition: TGo4Log.cxx:320
TGo4EventElement * GetInputEvent()
void SetDrawOption(Option_t *option="") override
Definition: TGo4Picture.h:138
TGo4Parameter * GetParameter(const char *name, const char *par_class=nullptr)
TH1 * fCr1Ch[8]
Definition: TXXXProc.h:32
void SetFillAtt(Color_t color, Style_t style, Int_t index=UndefIndex)
Bool_t AddAnalysisCondition(TGo4Condition *con, const char *subfolder=nullptr)
TH2 * fCr1Ch1x2
Definition: TXXXProc.h:34
TGo4WinCond * MakeWinCond(const char *fullname, Double_t xmin, Double_t xmax, const char *HistoName=nullptr)
void ResetIterator()
Definition: TGo4MbsEvent.h:100
Bool_t Test(Double_t v1) override
Definition: TGo4WinCond.cxx:86
TGo4WinCond * fconHis1
Definition: TXXXProc.h:39
Bool_t AddObject(TNamed *anything, const char *subfolder=nullptr)
Float_t fCrate2[8]
Definition: TXXXEvent.h:29
TGo4Picture * LPic(Int_t nline, Int_t ncol)
TH1 * fHis1gate
Definition: TXXXProc.h:36
Short_t GetTrigger() const
Definition: TGo4MbsEvent.h:148
TGo4PolyCond * MakePolyCond(const char *fullname, Int_t npoints, Double_t(*points) [2], const char *HistoName=nullptr)