GSI Object Oriented Online Offline (Go4)  GO4-6.3.0
TXXXUnpackProc.cxx
Go to the documentation of this file.
1 // $Id: TXXXUnpackProc.cxx 478 2009-10-29 12:26:09Z 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 "TXXXUnpackProc.h"
15 
16 #include "TH1.h"
17 #include "TH2.h"
18 #include "TCutG.h"
19 #include "TArrow.h"
20 #include "TLatex.h"
21 
22 #include "TGo4Log.h"
23 #include "TGo4MbsEvent.h"
24 #include "TGo4WinCond.h"
25 #include "TGo4PolyCond.h"
26 #include "TGo4CondArray.h"
27 #include "TGo4Picture.h"
28 
29 #include "TXXXParameter.h"
30 #include "TXXXUnpackEvent.h"
31 #include "TXXXCalibPar.h"
32 
33 //***********************************************************
36 {
37 }
38 //***********************************************************
39 // this one is used in TXXXUnpackFact.cxx
40 TXXXUnpackProc::TXXXUnpackProc(const char *name) :
41  TGo4EventProcessor(name)
42 {
43  TGo4Log::Info("TXXXUnpackProc: Create %s", name);
44 
46  fParam1 = (TXXXParameter *) GetParameter("XXXPar1");
47  fParam2 = (TXXXParameter *) GetParameter("XXXPar2");
48 
49  fParam1->Print();
50  fParam2->Print();
51 
52  TGo4Log::Info("TXXXProc: Produce histograms");
53 
54  for (int i = 0; i < 8; i++) {
55  fCr1Ch[i] = nullptr;
56  fCr2Ch[i] = nullptr;
57  }
58 
59  CreateRawHistograms(5000, 1., 5001.);
60  fEvCount = 0;
61 
62  fCr1Ch1x2 = MakeTH2('I', "Cr1Ch1x2","Crate 1 channel 1x2", 200, 1., 5001., 200, 1., 5001.);
63  fHis1 = MakeTH1('I', "His1","Condition histogram", 5000, 1., 5001.);
64  fHis2 = MakeTH1('I', "His2","Condition histogram", 5000, 1., 5001.);
65  fHis1gate = MakeTH1('I', "His1g","Gated histogram", 5000, 1., 5001.);
66  fHis2gate = MakeTH1('I', "His2g","Gated histogram", 5000, 1., 5001.);
67 
68  TGo4Log::Info("TXXXProc: Produce conditions");
69  fWinCon1 = MakeWinCond("wincon1", 50, 2000);
70  fWinCon2 = MakeWinCond("wincon2", 50, 70, 90, 120);
71  fconHis1 = MakeWinCond("cHis1", 100, 2000, "His1");
72  fconHis2 = MakeWinCond("cHis2", 100, 2000, "His2");
73 
74  Double_t cutpnts[3][2] = { {400, 800}, {700, 900}, {600, 1100} };
75  fPolyCon1 = MakePolyCond("polycon", 3, cutpnts);
76 
78  if (!fConArr1) {
79  fConArr1 = new TGo4CondArray("winconar",30,"TGo4WinCond");
80  fConArr1->SetValues(100,500);
81  fConArr1->Disable(true);
82  ((*fConArr1)[0])->SetValues(200,400);
83  ((*fConArr1)[1])->SetValues(700,1000);
84  ((*fConArr1)[2])->SetValues(1500,2000);
85  fConArr1->SetHistogram("Sum3");
87  } else {
89  }
90 
92  if(!fConArr2) {
93  // This is example how to create condition array
94  TGo4Log::Info("TXXXProc: Create condition");
95  Double_t xvalues[4] = { 1000, 2000, 1500, 1000 };
96  Double_t yvalues[4] = { 1000, 1000, 3000, 1000 };
97  TCutG *mycut = new TCutG("cut2", 4, xvalues, yvalues);
98  fConArr2 = new TGo4CondArray("polyconar",4,"TGo4PolyCond");
99  fConArr2->SetValues(mycut);
100  fConArr2->Disable(true); // means: condition check always returns true
101  delete mycut; // mycat has been copied into the conditions
103  } else {
104  TGo4Log::Info("TXXXProc: Restore condition from autosave");
106  }
107 
108  // connect histograms to conditions. will be drawn when condition is edited.
109  fWinCon1->Enable();
110  fWinCon2->Disable(true); // return always true
111  fWinCon2->Invert(kTRUE);
112  fWinCon1->PrintCondition(true);
113  fconHis1->PrintCondition(true);
114  fconHis2->PrintCondition(true);
115  fPolyCon1->Enable();
116  fPolyCon1->PrintCondition(true);
117  ((*fConArr2)[0])->Enable();
118  ((*fConArr2)[1])->Enable(); // 2 and 3 remain disabled
119 
120  fcondSet = GetPicture("condSet");
121  if (!fcondSet) {
122  // in the upper two pads, the condition limits can be set,
123  // in the lower two pads, the resulting histograms are shown
124  fcondSet = new TGo4Picture("condSet","Set conditions");
125  fcondSet->SetDivision(2,2);
126  fcondSet->Pic(0,0)->AddObject(fHis1);
127  fcondSet->Pic(0,1)->AddObject(fHis2);
132  fcondSet->Pic(1,0)->SetFillAtt(4, 1001); // solid
133  fcondSet->Pic(1,0)->SetLineAtt(4,1,1);
134  fcondSet->Pic(1,1)->SetFillAtt(9, 1001); // solid
135  fcondSet->Pic(1,1)->SetLineAtt(9,1,1);
136  fcondSet->Pic(0,0)->SetTitleAttr(0.05, 0.85, 0.8, 0.95);
138  }
139 
140  fPicture1 = GetPicture("Picture1");
141  if (!fPicture1) {
142  fPicture1 = new TGo4Picture("Picture1","Picture example");
143  fPicture1->SetLinesDivision(3, 2,3,1);
144  fPicture1->LPic(0,0)->AddObject(fCr1Ch[0]);
145  fPicture1->LPic(0,0)->SetFillAtt(5, 3001); // pattern
146  fPicture1->LPic(0,0)->SetLineAtt(5,1,1);
147  fPicture1->LPic(0,1)->AddObject(fCr1Ch[1]);
148  fPicture1->LPic(0,1)->SetFillAtt(4, 3001); // pattern
149  fPicture1->LPic(0,1)->SetLineAtt(4,1,1);
150  fPicture1->LPic(1,0)->AddObject(fCr1Ch[2]);
151  fPicture1->LPic(1,0)->SetFillAtt(6, 1001); // solid
152  fPicture1->LPic(1,0)->SetLineAtt(6,1,1);
153  fPicture1->LPic(1,1)->AddObject(fCr1Ch[3]);
154  fPicture1->LPic(1,1)->SetFillAtt(7, 1001); // solid
155  fPicture1->LPic(1,1)->SetLineAtt(7,1,1);
156  fPicture1->LPic(1,2)->AddObject(fCr1Ch[4]);
158  fPicture1->LPic(3,0)->SetDrawOption("CONT");
159  fPicture1->LPic(3,0)->AddSpecialObject(new TArrow(3500., 3500, 2000., 1500., 0.02));
160  fPicture1->LPic(3,0)->AddSpecialObject(new TLatex(1500, 3500, "Example of text label in the picture"));
161 // fPicture1->LPic(3,0)->AddSpecialObject(new TLine(2500., 2500, 3500., 1500.));
163  }
164 }
165 //***********************************************************
167 {
168  fWinCon1->PrintCondition(true);
169  fPolyCon1->PrintCondition(true);
170 }
171 
172 //-----------------------------------------------------------
173 void TXXXUnpackProc::CreateRawHistograms(int nbins, double xmin, double xmax)
174 {
175  for (int i = 0; i < 8; i++) {
176 
177  if (fCr1Ch[i]) {
178  RemoveHistogram(fCr1Ch[i]->GetName());
179  fCr1Ch[i] = nullptr;
180  }
181 
182  if (fCr2Ch[i]) {
183  RemoveHistogram(fCr2Ch[i]->GetName());
184  fCr2Ch[i] = nullptr;
185  }
186 
187  TString hname = TString::Format("Crate1/Cr1Ch%02d", i + 1);
188  TString htitle = TString::Format("Crate 1 channel %2d", i + 1);
189  fCr1Ch[i] = MakeTH1('I', hname.Data(), htitle.Data(), nbins, xmin, xmax);
190  hname = TString::Format("Crate2/Cr2Ch%02d", i + 1);
191  htitle = TString::Format("Crate 2 channel %2d", i + 1);
192  fCr2Ch[i] = MakeTH1('I', hname.Data(), htitle.Data(), nbins, xmin, xmax);
193  }
194 
195  // change histogram pointer, used in parameter
196  TXXXCalibPar* par = (TXXXCalibPar*) GetParameter("CaliPar");
197  if (par) par->SetCalibSpectrum(fCr1Ch[0]);
198 }
199 
200 //-----------------------------------------------------------
202 {
203  TGo4MbsEvent *inp_evt = (TGo4MbsEvent *) GetInputEvent(); // from this
204  TXXXUnpackEvent* out_evt = (TXXXUnpackEvent*) dest;
205 
206  if (!inp_evt) {
207  TGo4Log::Error("XXXUnpackProc: no input event !");
208  return kFALSE;
209  }
210 
211  fEvCount++;
212  if (fEvCount % 1000000 == 0) {
213  // this is demonstration how one can time to time recreate histogram with other ranges
214 
215  Long_t loop = (fEvCount / 1000000) % 5;
216 
217  CreateRawHistograms(5000 + loop*200, 1. - loop*100, 5001 + loop*100);
218 
219  // TGo4Log::Info("Histograms recreated");
220  }
221 
224 // s_filhe* head=inp_evt->GetMbsSourceHeader();
225 // if(head)
226 // {
227 // std::cout <<"found filhe structure:" << std::endl;
228 // std::cout <<"\tdatalen: "<<head->filhe_dlen << std::endl;
229 // std::cout <<"\tfilename_l: "<<head->filhe_file_l << std::endl;
230 // std::cout <<"\tfilename: "<<head->filhe_file << std::endl;
231 // std::cout <<"\ttype: "<<head->filhe_type << std::endl;
232 // std::cout <<"\tsubtype: "<<head->filhe_subtype << std::endl;
233 // std::cout <<"\t#commentlines: "<<head->filhe_lines << std::endl;
234 // }
235 // else
236 // {
237 // std::cout <<"zero file header" << std::endl;
238 // }
240 
243 // s_bufhe* head=inp_evt->GetMbsBufferHeader();
244 // if(head) {
245 // std::cout <<"\nfound bufhe structure:" << std::endl;
246 // std::cout <<"\tbuffernumber: "<<head->l_buf << std::endl;
247 // std::cout <<"\tdatalen: "<<head->l_dlen << std::endl;
248 // std::cout <<"\ttime lo: "<<head->l_time[0] << std::endl; // seconds since epoch 1970
249 // std::cout <<"\ttime hi: "<<head->l_time[1] << std::endl; // microseconds since time lo
250 // char sbuf[1000]; f_ut_utime(head->l_time[0], head->l_time[1], sbuf);
251 // std::cout <<"\ttimestring: " << sbuf << std::endl;
252 // std::cout <<"\ttype: "<<head->i_type << std::endl;
253 // std::cout <<"\tsubtype: "<<head->i_subtype << std::endl;
254 // }
255 // else
256 // {
257 // std::cout <<"zero buffer header" << std::endl;
258 //
259 // }
261 
262  inp_evt->ResetIterator();
263  while (auto psubevt = inp_evt->NextSubEvent()) // subevent loop
264  {
265  Int_t *pdata = psubevt->GetDataField();
266  Int_t lwords = psubevt->GetIntLen();
267  Int_t subcrate=psubevt->GetSubcrate();
268  if(subcrate<0 || subcrate> XXX_NUM_CRATES)
269  {
270  TGo4Log::Info("XXXUnpackProc: skip invalid subcrate %d", subcrate);
271  continue; // try next subevent if any
272  }
273 
274  if(lwords >= 8) lwords=8; // take only first 8 lwords
275  Int_t lastvalue = 0;
276  for(Int_t i = 0; i<lwords; ++i)
277  {
278  // Int_t index = *pdata&0xfff; // in case low word is index
279  // Int_t value = (*pdata>>16)&0xfff; // in case high word is data
280 
281 
282  // first copy data of crate and channel into corresponding module:
283  TXXXUnpackEvent& ev=*out_evt; // ref instead pointer for array syntax:
284  TXXXModule* mod=dynamic_cast<TXXXModule*>(&ev[subcrate][i]); // 2d array with composite event operator[]
285  if(mod)
286  {
287  if(*pdata != 0)
288  mod->SetData(*pdata); // zero suppressed data
289  else
290  mod->SetAux(i); // account count zero value data channel for each subevent
291 
292  mod->SetTest(*pdata); // record any data here
293  }
294  else
295  {
296  TGo4Log::Info("XXXUnpackProc: WARNING: no output event module for crate %d, channel %d", subcrate, i);
297 
298  }
299  if(*pdata != 0)
300  {
301  // process crate specific histograming here:
302  if( subcrate == 1)
303  {
304  fCr1Ch[i]->Fill((Float_t)(*pdata));
305 
306  if(i == 0) // fill first channel
307  {
308  if(fconHis1->Test((Double_t)*pdata))
309  fHis1gate->Fill((Float_t)(*pdata));
310  fHis1->Fill((Float_t)(*pdata));
311  }
312  if(i == 1)
313  {
314  if(fconHis2->Test((Double_t)*pdata))fHis2gate->Fill((Float_t)(*pdata));
315  fHis2->Fill((Float_t)(*pdata));
316  // fill Cr1Ch1x2 for three polygons:
317  if(fPolyCon1->Test(*pdata,lastvalue)) fCr1Ch1x2->Fill((Float_t)(*pdata),(Float_t)lastvalue);
318  if(((*fConArr2)[0])->Test(*pdata,lastvalue))fCr1Ch1x2->Fill((Float_t)(*pdata),(Float_t)lastvalue);
319  if(((*fConArr2)[1])->Test(*pdata,lastvalue))fCr1Ch1x2->Fill((Float_t)(*pdata),(Float_t)lastvalue);
320  }
321  lastvalue = *pdata; // save for 2d histogram
322  }
323  else if ( subcrate == 2)
324  {
325  fCr2Ch[i]->Fill((Float_t)(*pdata));
326  }
327  }
328  pdata++;
329  }// for SEW LW
330  } // while
331  out_evt->SetValid(kTRUE); // to store
332  // throwing this exception stops the event loop
333  // Note that subsequent steps are not executed!
334  // throw TGo4EventEndException(this);
335 
336  return kTRUE;
337 }
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
void Disable(Bool_t result) override
void SetData(Int_t dat)
void AddCondition(TNamed *cond=nullptr)
void SetValid(Bool_t on)
TGo4Picture * GetPicture(const char *name)
TXXXParameter * fParam2
Bool_t BuildEvent(TGo4EventElement *dest) override
static void Info(const char *text,...) GO4_PRINTF_ARGS
Definition: TGo4Log.cxx:294
Bool_t AddPicture(TGo4Picture *pic, const char *subfolder=nullptr)
TH1 * fCr2Ch[XXX_NUM_CHAN]
TH1 * fCr1Ch[XXX_NUM_CHAN]
void SetValues(Double_t low1, Double_t up1) override
TGo4CondArray * fConArr2
TGo4CondArray * fConArr1
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)
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)
virtual void Enable()
void CreateRawHistograms(int nbins, double xmin, double xmax)
void SetTest(Int_t dat)
void SetDivision(Int_t ndivy, Int_t ndivx)
TGo4Picture * fcondSet
void PrintCondition(Bool_t full=kTRUE) override
void SetHistogram(const char *name)
void Print(Option_t *opt="") const override
TXXXParameter * fParam1
virtual void Disable(Bool_t result)
TGo4Condition * GetAnalysisCondition(const char *name, const char *cond_cl=nullptr)
#define XXX_NUM_CRATES
TGo4WinCond * fconHis2
void SetLineAtt(Color_t color, Style_t style, Width_t width, Int_t index=UndefIndex)
void SetLinesDivision(Int_t numlines, const Int_t *numbers)
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
TGo4WinCond * fWinCon1
TGo4WinCond * fconHis1
TGo4Parameter * GetParameter(const char *name, const char *par_class=nullptr)
void SetFillAtt(Color_t color, Style_t style, Int_t index=UndefIndex)
TGo4WinCond * fWinCon2
Bool_t AddAnalysisCondition(TGo4Condition *con, const char *subfolder=nullptr)
TGo4PolyCond * fPolyCon1
TGo4WinCond * MakeWinCond(const char *fullname, Double_t xmin, Double_t xmax, const char *HistoName=nullptr)
void ResetIterator()
Definition: TGo4MbsEvent.h:100
TGo4Picture * fPicture1
Bool_t Test(Double_t v1) override
Definition: TGo4WinCond.cxx:86
void AddSpecialObject(TObject *obj, Option_t *drawopt=nullptr)
TGo4Picture * LPic(Int_t nline, Int_t ncol)
virtual ~TXXXUnpackProc()
void SetAux(Int_t dat)
TGo4PolyCond * MakePolyCond(const char *fullname, Int_t npoints, Double_t(*points) [2], const char *HistoName=nullptr)
void SetTitleAttr(Double_t x1, Double_t y1, Double_t x2, Double_t y2, Double_t textsize=0.)
virtual void Invert(Bool_t on)
void PrintCondition(Bool_t points=kTRUE) override
Bool_t RemoveHistogram(const char *name)