GSI Object Oriented Online Offline (Go4)  GO4-6.1.4
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
TXXXProc.cxx
Go to the documentation of this file.
1 // $Id: TXXXProc.cxx 3298 2021-07-29 08:06:41Z linev $
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");
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  fCr1Ch[i] = MakeTH1('I', Form("Crate1/Cr1Ch%02d",i+1), Form("Crate 1 channel %2d",i+1), 5000, 1., 5001.);
65  fCr2Ch[i] = MakeTH1('I', Form("Crate2/Cr2Ch%02d",i+1), Form("Crate 2 channel %2d",i+1), 5000, 1., 5001.);
66  }
67 
68  fCr1Ch1x2 = MakeTH2('I', "Cr1Ch1x2","Crate 1 channel 1x2", 200, 1., 5001., 200, 1., 5001.);
69  fHis1 = MakeTH1('I', "His1","Condition histogram", 5000, 1., 5001.);
70  fHis2 = MakeTH1('I', "His2","Condition histogram", 5000, 1., 5001.);
71  fHis1gate = MakeTH1('I', "His1g","Gated histogram", 5000, 1., 5001.);
72  fHis2gate = MakeTH1('I', "His2g","Gated histogram", 5000, 1., 5001.);
73 
74  TGo4Log::Info("TXXXProc: Produce conditions");
75  fconHis1 = MakeWinCond("cHis1", 100, 2000, "His1");
76  fconHis2 = MakeWinCond("cHis2", 100, 2000, "His2");
77 
78  Double_t cutpnts[3][2] = { {400, 800}, {700, 900}, {600, 1100} };
79  fPolyCon = MakePolyCond("polycon", 3, cutpnts);
80 
82  if(fConArr==0) {
83  // This is example how to create condition array
84  TGo4Log::Info("TXXXProc: Create condition array");
85  Double_t xvalues[4] = { 1000, 2000, 1500, 1000 };
86  Double_t yvalues[4] = { 1000, 1000, 3000, 1000 };
87  TCutG* mycut = new TCutG("cut2", 4, xvalues, yvalues);
88  fConArr = new TGo4CondArray("polyconar",4,"TGo4PolyCond");
89  fConArr->SetValues(mycut);
90  fConArr->Disable(true); // means: condition check always returns true
91  delete mycut; // mycat has been copied into the conditions
93  } else {
94  TGo4Log::Info("TXXXProc: Restore condition array from autosave");
96  }
97  // connect histograms to conditions. will be drawn when condition is edited.
98  ((*fConArr)[0])->Enable();
99  ((*fConArr)[1])->Enable(); // 2 and 3 remain disabled
100 
101  TGo4Log::Info("TXXXProc: Produce pictures");
102  fcondSet = GetPicture("condSet");
103  if (fcondSet==0) {
104  // in the upper two pads, the condition limits can be set,
105  // in the lower two pads, the resulting histograms are shown
106  fcondSet = new TGo4Picture("condSet","Set conditions");
107  fcondSet->SetDivision(2,2);
108  fcondSet->Pic(0,0)->AddObject(fHis1);
109  fcondSet->Pic(0,1)->AddObject(fHis2);
114  fcondSet->Pic(1,0)->SetFillAtt(4, 1001); // solid
115  fcondSet->Pic(1,0)->SetLineAtt(4,1,1);
116  fcondSet->Pic(1,1)->SetFillAtt(9, 1001); // solid
117  fcondSet->Pic(1,1)->SetLineAtt(9,1,1);
119  }
120 
121  fPicture = GetPicture("Picture");
122  if (fPicture == 0) {
123  fPicture = new TGo4Picture("Picture","Picture example");
124  fPicture->SetLinesDivision(3, 2,3,1);
125  fPicture->LPic(0,0)->AddObject(fCr1Ch[0]);
126  fPicture->LPic(0,0)->SetFillAtt(5, 3001); // pattern
127  fPicture->LPic(0,0)->SetLineAtt(5,1,1);
128  fPicture->LPic(0,1)->AddObject(fCr1Ch[1]);
129  fPicture->LPic(0,1)->SetFillAtt(4, 3001); // pattern
130  fPicture->LPic(0,1)->SetLineAtt(4,1,1);
131  fPicture->LPic(1,0)->AddObject(fCr1Ch[2]);
132  fPicture->LPic(1,0)->SetFillAtt(6, 1001); // solid
133  fPicture->LPic(1,0)->SetLineAtt(6,1,1);
134  fPicture->LPic(1,1)->AddObject(fCr1Ch[3]);
135  fPicture->LPic(1,1)->SetFillAtt(7, 1001); // solid
136  fPicture->LPic(1,1)->SetLineAtt(7,1,1);
137  fPicture->LPic(1,2)->AddObject(fCr1Ch[4]);
139  fPicture->LPic(3,0)->SetDrawOption("CONT");
141  }
142 
143  fProfile = dynamic_cast<TProfile*>(GetObject("profile"));
144  if (!fProfile) {
145  fProfile = new TProfile("profile","Example of TProfile usage", 5000, 1., 5001., 1., 5001.);
146  fProfile->SetDirectory(0);
148  }
149 
150  fProfile2D = dynamic_cast<TProfile2D*>(GetObject("profile2d"));
151  if (!fProfile2D) {
152  fProfile2D = new TProfile2D("profile2d","Example of TProfile2D usage", 200, 1., 5001., 200, 1., 5001., 1., 5001.);
153  fProfile2D->SetDirectory(0);
155  }
156 }
157 //-----------------------------------------------------------
158 // event function
160 {
161  // called by framework from TXXXEvent to fill it
162 
163  TXXXEvent* XXXEvent = (TXXXEvent*) target;
164 
165  TGo4MbsEvent* source = (TGo4MbsEvent*) GetInputEvent();
166  if(source == 0) {
167  TGo4Log::Error("TXXXProc: no input event!");
168  return kFALSE;
169  }
170  if(source->GetTrigger() > 11) {
171  TGo4Log::Info("TXXXProc: Skip trigger event");
172  XXXEvent->SetValid(kFALSE); // not store
173  return kFALSE;
174  }
175  // first we fill the TXXXEvent with data from MBS source
176  // we have up to two subevents, crate 1 and 2
177  // Note that one has to loop over all subevents and select them by
178  // crate number: psubevt->GetSubcrate(),
179  // procid: psubevt->GetProcid(),
180  // and/or control: psubevt->GetControl()
181  // here we use only crate number
182 
183  source->ResetIterator();
184  TGo4MbsSubEvent* psubevt(0);
185  while((psubevt = source->NextSubEvent()) != 0) { // loop over subevents
186  Int_t *pdata = psubevt->GetDataField();
187  Int_t lwords = psubevt->GetIntLen();
188  if(lwords > 8) lwords=8; // take only first 8 lwords
189 
190  if(psubevt->GetSubcrate() == 1) {
191  for(Int_t i = 0; i<lwords; i++) {
192  // Int_t index = *pdata&0xfff; // in case low word is index
193  //Float_t value = (*pdata>>16)&0xfff; // and high word is data
194  Float_t value = (Float_t)*pdata++; // otherwise longword data
195  Int_t index = i; // and index in order
196  XXXEvent->fCrate1[index] = value; // copy to output event
197  }
198  }
199  if(psubevt->GetSubcrate() == 2)
200  for(Int_t i = 0; i<lwords; i++)
201  XXXEvent->fCrate2[i] = (Float_t)*pdata++;
202  }
203 
204  // now we fill histograms from XXXEvent
205  if(fControl->fill) {
206  for(Int_t i = 0; i<8; i++) {
207  fCr1Ch[i]->Fill(XXXEvent->fCrate1[i]);
208  fCr2Ch[i]->Fill(XXXEvent->fCrate2[i]);
209  }
210  Float_t value1 = XXXEvent->fCrate1[0];
211  Float_t value2 = XXXEvent->fCrate1[1];
212  Float_t value3 = XXXEvent->fCrate1[3];
213  fHis1->Fill(value1); //fill histograms without gate
214  fHis2->Fill(value2);
215 
216  fProfile->Fill(value1, value2, 1);
217  fProfile2D->Fill(value1, value2, value3, 1);
218 
219  if (fconHis1->Test(value1)) fHis1gate->Fill(value1); //fill histograms with gate
220  if (fconHis2->Test(value2)) fHis2gate->Fill(value2);
221  // fill Cr1Ch1x2 for three polygons:
222  if (fPolyCon->Test(value1,value2)) fCr1Ch1x2->Fill(value1,value2);
223  if(((*fConArr)[0])->Test(value1,value2)) fCr1Ch1x2->Fill(value1,value2);
224  if(((*fConArr)[1])->Test(value1,value2)) fCr1Ch1x2->Fill(value1,value2);
225  }
226  XXXEvent->SetValid(kTRUE); // to store
227  return kTRUE;
228 }
TNamed * GetObject(const char *name, const char *folder=0)
Bool_t fill
Definition: TXXXControl.h:23
TXXXProc()
Definition: TXXXProc.cxx:33
void SetValid(Bool_t on)
Bool_t BuildEvent(TGo4EventElement *target)
Definition: TXXXProc.cxx:159
TGo4Picture * GetPicture(const char *name)
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=0, const char *ytitle=0, const char *ztitle=0)
virtual Bool_t Test(Double_t x, Double_t y)
TH1 * fHis2
Definition: TXXXProc.h:37
TGo4WinCond * MakeWinCond(const char *fullname, Double_t xmin, Double_t xmax, const char *HistoName=0)
TProfile2D * fProfile2D
Definition: TXXXProc.h:47
TGo4Picture * fPicture
Definition: TXXXProc.h:44
TGo4Picture * fcondSet
Definition: TXXXProc.h:45
virtual Int_t PrintParameter(Text_t *buffer=0, Int_t buflen=0)
TGo4Condition * GetAnalysisCondition(const char *name, const char *cond_cl=0)
TXXXControl * fControl
Definition: TXXXProc.h:43
GO4 ConditionPainter prototype Test
Definition: go4canvas.js:355
TGo4PolyCond * MakePolyCond(const char *fullname, Int_t npoints, Double_t(*points)[2], const char *HistoName=0)
TH1 * fHis1
Definition: TXXXProc.h:35
virtual void SetValues(Double_t low1, Double_t up1)
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
void AddObject(TObject *obj, Option_t *DrawOption=0)
virtual void Disable(Bool_t result)
TGo4WinCond * fconHis2
Definition: TXXXProc.h:40
TGo4CondArray * fConArr
Definition: TXXXProc.h:42
Int_t * GetDataField()
virtual ~TXXXProc()
Definition: TXXXProc.cxx:39
Long_t ExecuteScript(const char *script_name)
TProfile * fProfile
Definition: TXXXProc.h:46
void AddCondition(TNamed *cond=0)
void SetLineAtt(Color_t color, Style_t style, Width_t width, Int_t index=UndefIndex)
Float_t fCrate1[8]
Definition: TXXXEvent.h:28
TGo4Parameter * GetParameter(const char *name, const char *par_class=0)
void SetLinesDivision(Int_t numlines, const Int_t *numbers)
TH1 * fCr2Ch[8]
Definition: TXXXProc.h:33
TGo4PolyCond * fPolyCon
Definition: TXXXProc.h:41
TGo4EventElement * GetInputEvent()
Bool_t AddAnalysisCondition(TGo4Condition *con, const char *subfolder=0)
virtual Bool_t Test(Double_t v1)
Definition: TGo4WinCond.cxx:86
TH1 * fCr1Ch[8]
Definition: TXXXProc.h:32
void SetFillAtt(Color_t color, Style_t style, Int_t index=UndefIndex)
Bool_t AddPicture(TGo4Picture *pic, const char *subfolder=0)
Bool_t AddObject(TNamed *anything, const char *subfolder=0)
Int_t GetIntLen() const
TH1 * MakeTH1(char type, const char *fullname, const char *title, Int_t nbinsx, Double_t xlow, Double_t xup, const char *xtitle=0, const char *ytitle=0)
Char_t GetSubcrate() const
Short_t GetTrigger() const
Definition: TGo4MbsEvent.h:149
TH2 * fCr1Ch1x2
Definition: TXXXProc.h:34
void ResetIterator()
Definition: TGo4MbsEvent.h:101
TGo4WinCond * fconHis1
Definition: TXXXProc.h:39
Float_t fCrate2[8]
Definition: TXXXEvent.h:29
virtual void SetDrawOption(Option_t *option="")
Definition: TGo4Picture.h:139
TGo4Picture * LPic(Int_t nline, Int_t ncol)
TH1 * fHis1gate
Definition: TXXXProc.h:36
static void Error(const char *text,...)
Definition: TGo4Log.cxx:313
static void Info(const char *text,...)
Definition: TGo4Log.cxx:287
virtual void ResetCounts()