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 "TCutG.h"
19 
20 #include "TGo4Log.h"
21 #include "TGo4WinCond.h"
22 #include "TGo4PolyCond.h"
23 #include "TGo4CondArray.h"
24 #include "TGo4Picture.h"
25 #include "TGo4MbsEvent.h"
26 
27 #include "TXXXEvent.h"
28 #include "TXXXControl.h"
29 
30 //***********************************************************
32 {
33  TGo4Log::Info("TXXXProc: Create instance");
34 }
35 
36 //***********************************************************
38 {
39  TGo4Log::Info("TXXXProc: Delete instance");
40 }
41 
42 //***********************************************************
43 // this one is used in standard factory
44 TXXXProc::TXXXProc(const char *name) : TGo4EventProcessor(name)
45 {
46  TGo4Log::Info("TXXXProc: Create instance %s", name);
47 
49 
50  // Parameters are created in analysis, therefore just take it out
51  fControl = (TXXXControl *) GetParameter("Control");
52 
53  // This example analysis allows for en-disabling the histogram filling.
54  // Macro histofill.C sets histogram fill status in parameter "Control".
55  // This macro histofill.C, not the auto save file, will set status.
56  ExecuteScript("histofill.C");
57  fControl->Print();
58 
59  TGo4Log::Info("TXXXProc: Produce histograms");
60  // Creation of histograms (or take them from autosave)
61  for (int i = 0; i < 8; i++) {
62  TString hname = TString::Format("Crate1/Cr1Ch%02d", i + 1);
63  TString htitle = TString::Format("Crate 1 channel %2d", i+1);
64  fCr1Ch[i] = MakeTH1('I', hname.Data(), htitle.Data(), 5000, 1., 5001.);
65  hname = TString::Format("Crate2/Cr2Ch%02d",i+1);
66  htitle = TString::Format("Crate 2 channel %2d",i+1);
67  fCr2Ch[i] = MakeTH1('I', hname.Data(), htitle.Data(), 5000, 1., 5001.);
68  }
69 
70  fCr1Ch1x2 = MakeTH2('I', "Cr1Ch1x2","Crate 1 channel 1x2", 200, 1., 5001., 200, 1., 5001.);
71  fHis1 = MakeTH1('I', "His1","Condition histogram", 5000, 1., 5001.);
72  fHis2 = MakeTH1('I', "His2","Condition histogram", 5000, 1., 5001.);
73  fHis1gate = MakeTH1('I', "His1g","Gated histogram", 5000, 1., 5001.);
74  fHis2gate = MakeTH1('I', "His2g","Gated histogram", 5000, 1., 5001.);
75 
76  TGo4Log::Info("TXXXProc: Produce conditions");
77  fconHis1 = MakeWinCond("cHis1", 100, 2000, "His1");
78  fconHis2 = MakeWinCond("cHis2", 100, 2000, "His2");
79 
80  Double_t cutpnts[3][2] = { {400, 800}, {700, 900}, {600, 1100} };
81  fPolyCon = MakePolyCond("polycon", 3, cutpnts);
82 
84  if(!fConArr) {
85  // This is example how to create condition array
86  TGo4Log::Info("TXXXProc: Create condition array");
87  Double_t xvalues[4] = { 1000, 2000, 1500, 1000 };
88  Double_t yvalues[4] = { 1000, 1000, 3000, 1000 };
89  TCutG *mycut = new TCutG("cut2", 4, xvalues, yvalues);
90  fConArr = new TGo4CondArray("polyconar",4,"TGo4PolyCond");
91  fConArr->SetValues(mycut);
92  fConArr->Disable(true); // means: condition check always returns true
93  delete mycut; // mycat has been copied into the conditions
95  } else {
96  TGo4Log::Info("TXXXProc: Restore condition array from autosave");
98  }
99  // connect histograms to conditions. will be drawn when condition is edited.
100  ((*fConArr)[0])->Enable();
101  ((*fConArr)[1])->Enable(); // 2 and 3 remain disabled
102 
103  TGo4Log::Info("TXXXProc: Produce pictures");
104  fcondSet = GetPicture("condSet");
105  if (!fcondSet) {
106  // in the upper two pads, the condition limits can be set,
107  // in the lower two pads, the resulting histograms are shown
108  fcondSet = new TGo4Picture("condSet","Set conditions");
109  fcondSet->SetDivision(2,2);
110  fcondSet->Pic(0,0)->AddObject(fHis1);
111  fcondSet->Pic(0,1)->AddObject(fHis2);
116  fcondSet->Pic(1,0)->SetFillAtt(4, 1001); // solid
117  fcondSet->Pic(1,0)->SetLineAtt(4,1,1);
118  fcondSet->Pic(1,1)->SetFillAtt(9, 1001); // solid
119  fcondSet->Pic(1,1)->SetLineAtt(9,1,1);
121  }
122 
123  fPicture = GetPicture("Picture");
124  if (!fPicture) {
125  fPicture = new TGo4Picture("Picture","Picture example");
126  fPicture->SetLinesDivision(3, 2,3,1);
127  fPicture->LPic(0,0)->AddObject(fCr1Ch[0]);
128  fPicture->LPic(0,0)->SetFillAtt(5, 3001); // pattern
129  fPicture->LPic(0,0)->SetLineAtt(5,1,1);
130  fPicture->LPic(0,1)->AddObject(fCr1Ch[1]);
131  fPicture->LPic(0,1)->SetFillAtt(4, 3001); // pattern
132  fPicture->LPic(0,1)->SetLineAtt(4,1,1);
133  fPicture->LPic(1,0)->AddObject(fCr1Ch[2]);
134  fPicture->LPic(1,0)->SetFillAtt(6, 1001); // solid
135  fPicture->LPic(1,0)->SetLineAtt(6,1,1);
136  fPicture->LPic(1,1)->AddObject(fCr1Ch[3]);
137  fPicture->LPic(1,1)->SetFillAtt(7, 1001); // solid
138  fPicture->LPic(1,1)->SetLineAtt(7,1,1);
139  fPicture->LPic(1,2)->AddObject(fCr1Ch[4]);
141  fPicture->LPic(3,0)->SetDrawOption("CONT");
143  }
144 }
145 //-----------------------------------------------------------
146 // event function
148 {
149  // called by framework from TXXXEvent to fill it
150 
151  TXXXEvent *XXXEvent = (TXXXEvent *)target;
152 
153  TGo4MbsEvent *source = (TGo4MbsEvent *)GetInputEvent();
154  if(!source) {
155  TGo4Log::Error("TXXXProc: no input event!");
156  return kFALSE;
157  }
158  if(source->GetTrigger() > 11) {
159  TGo4Log::Info("TXXXProc: Skip trigger event");
160  XXXEvent->SetValid(kFALSE); // not store
161  return kFALSE;
162  }
163  // first we fill the TXXXEvent with data from MBS source
164  // we have up to two subevents, crate 1 and 2
165  // Note that one has to loop over all subevents and select them by
166  // crate number: psubevt->GetSubcrate(),
167  // procid: psubevt->GetProcid(),
168  // and/or control: psubevt->GetControl()
169  // here we use only crate number
170 
171  source->ResetIterator();
172  while(auto psubevt = source->NextSubEvent()) { // loop over subevents
173  Int_t *pdata = psubevt->GetDataField();
174  Int_t lwords = psubevt->GetIntLen();
175  if(lwords > 8) lwords=8; // take only first 8 lwords
176 
177  if(psubevt->GetSubcrate() == 1) {
178  for(Int_t i = 0; i<lwords; i++) {
179  // Int_t index = *pdata&0xfff; // in case low word is index
180  //Float_t value = (*pdata>>16)&0xfff; // and high word is data
181  Float_t value = (Float_t)*pdata++; // otherwise longword data
182  Int_t index = i; // and index in order
183  XXXEvent->fCrate1[index] = value; // copy to output event
184  }
185  }
186  if(psubevt->GetSubcrate() == 2)
187  for(Int_t i = 0; i<lwords; i++)
188  XXXEvent->fCrate2[i] = (Float_t)*pdata++;
189  }
190 
191  // now we fill histograms from XXXEvent
192  if(fControl->fill) {
193  for(Int_t i = 0; i<8; i++) {
194  fCr1Ch[i]->Fill(XXXEvent->fCrate1[i]);
195  fCr2Ch[i]->Fill(XXXEvent->fCrate2[i]);
196  }
197  Float_t value1 = XXXEvent->fCrate1[0];
198  Float_t value2 = XXXEvent->fCrate1[1];
199  fHis1->Fill(value1); //fill histograms without gate
200  fHis2->Fill(value2);
201  if (fconHis1->Test(value1)) fHis1gate->Fill(value1); //fill histograms with gate
202  if (fconHis2->Test(value2)) fHis2gate->Fill(value2);
203  // fill Cr1Ch1x2 for three polygons:
204  if (fPolyCon->Test(value1,value2)) fCr1Ch1x2->Fill(value1,value2);
205  if(((*fConArr)[0])->Test(value1,value2)) fCr1Ch1x2->Fill(value1,value2);
206  if(((*fConArr)[1])->Test(value1,value2)) fCr1Ch1x2->Fill(value1,value2);
207  }
208  XXXEvent->SetValid(kTRUE); // to store
209  return kTRUE;
210 }
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
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
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)
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
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)