GSI Object Oriented Online Offline (Go4)  GO4-6.1.4
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
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  fParam1->PrintParameter(0,0);
49 
50  fParam2->PrintParameter(0,0);
51 
52  TGo4Log::Info("TXXXProc: Produce histograms");
53 
54  for(int i=0;i<8;i++) {
55  fCr1Ch[i] = 0;
56  fCr2Ch[i] = 0;
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==0) {
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==0) {
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==0) {
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 == 0) {
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 //-----------------------------------------------------------
174 void TXXXUnpackProc::CreateRawHistograms(int nbins, double xmin, double xmax)
175 {
176  //std::cout <<"TXXXUnpackProc::CreateRawHistograms" << std::endl;
177  for(int i=0;i<8;i++) {
178 
179  if (fCr1Ch[i]!=0) {
180  RemoveHistogram(fCr1Ch[i]->GetName());
181  fCr1Ch[i] = 0;
182  }
183 
184  if (fCr2Ch[i]!=0) {
185  RemoveHistogram(fCr2Ch[i]->GetName());
186  fCr2Ch[i] = 0;
187  }
188 
189  fCr1Ch[i] = MakeTH1('I', Form("Crate1/Cr1Ch%02d",i+1), Form("Crate 1 channel %2d",i+1), nbins, xmin, xmax);
190  fCr2Ch[i] = MakeTH1('I', Form("Crate2/Cr2Ch%02d",i+1), Form("Crate 2 channel %2d",i+1), nbins, xmin, xmax);
191  }
192 
193  // change histogram pointer, used in parameter
194  TXXXCalibPar* par = (TXXXCalibPar*) GetParameter("CaliPar");
195  if (par!=0) par->SetCalibSpectrum(fCr1Ch[0]);
196 
197 
198 }
199 
200 //-----------------------------------------------------------
202 {
203  TGo4MbsEvent* inp_evt = (TGo4MbsEvent* ) GetInputEvent(); // from this
204  TXXXUnpackEvent* out_evt = (TXXXUnpackEvent*) dest;
205 
206  if (inp_evt==0) {
207  TGo4Log::Error("XXXUnpackProc: no input event !");
208  return kFALSE;
209  }
210 
211 
212  fEvCount++;
213  if (fEvCount % 1000000 == 0) {
214  // this is demonstration how one can time to time recreate histogram with other ranges
215 
216  Long_t loop = (fEvCount / 1000000) % 5;
217 
218  CreateRawHistograms(5000 + loop*200, 1. - loop*100, 5001 + loop*100);
219 
220  // TGo4Log::Info("Histograms recreated");
221  }
222 
225 // s_filhe* head=inp_evt->GetMbsSourceHeader();
226 // if(head)
227 // {
228 // std::cout <<"found filhe structure:" << std::endl;
229 // std::cout <<"\tdatalen: "<<head->filhe_dlen << std::endl;
230 // std::cout <<"\tfilename_l: "<<head->filhe_file_l << std::endl;
231 // std::cout <<"\tfilename: "<<head->filhe_file << std::endl;
232 // std::cout <<"\ttype: "<<head->filhe_type << std::endl;
233 // std::cout <<"\tsubtype: "<<head->filhe_subtype << std::endl;
234 // std::cout <<"\t#commentlines: "<<head->filhe_lines << std::endl;
235 // }
236 // else
237 // {
238 // std::cout <<"zero file header" << std::endl;
239 // }
241 
244 // s_bufhe* head=inp_evt->GetMbsBufferHeader();
245 // if(head) {
246 // std::cout <<"\nfound bufhe structure:" << std::endl;
247 // std::cout <<"\tbuffernumber: "<<head->l_buf << std::endl;
248 // std::cout <<"\tdatalen: "<<head->l_dlen << std::endl;
249 // std::cout <<"\ttime lo: "<<head->l_time[0] << std::endl; // seconds since epoch 1970
250 // std::cout <<"\ttime hi: "<<head->l_time[1] << std::endl; // microseconds since time lo
251 // char sbuf[1000]; f_ut_utime(head->l_time[0], head->l_time[1], sbuf);
252 // std::cout <<"\ttimestring: " << sbuf << std::endl;
253 // std::cout <<"\ttype: "<<head->i_type << std::endl;
254 // std::cout <<"\tsubtype: "<<head->i_subtype << std::endl;
255 // }
256 // else
257 // {
258 // std::cout <<"zero buffer header" << std::endl;
259 //
260 // }
262 
263 
264  inp_evt->ResetIterator();
265  TGo4MbsSubEvent* psubevt(0);
266  while ((psubevt = inp_evt->NextSubEvent()) != 0) // subevent loop
267  {
268  Int_t* pdata = psubevt->GetDataField();
269  Int_t lwords = psubevt->GetIntLen();
270  Int_t subcrate=psubevt->GetSubcrate();
271  if(subcrate<0 || subcrate> XXX_NUM_CRATES)
272  {
273  TGo4Log::Info("XXXUnpackProc: skip invalid subcrate %d", subcrate);
274  continue; // try next subevent if any
275  }
276 
277  if(lwords >= 8) lwords=8; // take only first 8 lwords
278  Int_t lastvalue = 0;
279  for(Int_t i = 0; i<lwords; ++i)
280  {
281  // Int_t index = *pdata&0xfff; // in case low word is index
282  // Int_t value = (*pdata>>16)&0xfff; // in case high word is data
283 
284 
285  // first copy data of crate and channel into corresponding module:
286  TXXXUnpackEvent& ev=*out_evt; // ref instead pointer for array syntax:
287  TXXXModule* mod=dynamic_cast<TXXXModule*>(&ev[subcrate][i]); // 2d array with composite event operator[]
288  if(mod)
289  {
290  if(*pdata != 0)
291  mod->SetData(*pdata); // zero suppressed data
292  else
293  mod->SetAux(i); // account count zero value data channel for each subevent
294 
295  mod->SetTest(*pdata); // record any data here
296  }
297  else
298  {
299  TGo4Log::Info("XXXUnpackProc: WARNING: no output event module for crate %d, channel %d", subcrate, i);
300 
301  }
302  if(*pdata != 0)
303  {
304  // process crate specific histograming here:
305  if( subcrate == 1)
306  {
307  fCr1Ch[i]->Fill((Float_t)(*pdata));
308 
309  if(i == 0) // fill first channel
310  {
311  if(fconHis1->Test((Double_t)*pdata))
312  fHis1gate->Fill((Float_t)(*pdata));
313  fHis1->Fill((Float_t)(*pdata));
314  }
315  if(i == 1)
316  {
317  if(fconHis2->Test((Double_t)*pdata))fHis2gate->Fill((Float_t)(*pdata));
318  fHis2->Fill((Float_t)(*pdata));
319  // fill Cr1Ch1x2 for three polygons:
320  if(fPolyCon1->Test(*pdata,lastvalue)) fCr1Ch1x2->Fill((Float_t)(*pdata),(Float_t)lastvalue);
321  if(((*fConArr2)[0])->Test(*pdata,lastvalue))fCr1Ch1x2->Fill((Float_t)(*pdata),(Float_t)lastvalue);
322  if(((*fConArr2)[1])->Test(*pdata,lastvalue))fCr1Ch1x2->Fill((Float_t)(*pdata),(Float_t)lastvalue);
323  }
324  lastvalue = *pdata; // save for 2d histogram
325  }
326  else if ( subcrate == 2)
327  {
328  fCr2Ch[i]->Fill((Float_t)(*pdata));
329  }
330  }
331  pdata++;
332  }// for SEW LW
333  } // while
334  out_evt->SetValid(kTRUE); // to store
335  // throwing this exception stops the event loop
336  // Note that subsequent steps are not executed!
337  // throw TGo4EventEndException(this);
338 
339  return kTRUE;
340 }
virtual void PrintCondition(Bool_t points=kTRUE)
void SetData(Int_t dat)
void SetValid(Bool_t on)
TGo4Picture * GetPicture(const char *name)
virtual void PrintCondition(Bool_t full=kTRUE)
TXXXParameter * fParam2
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 * fCr2Ch[XXX_NUM_CHAN]
TH1 * fCr1Ch[XXX_NUM_CHAN]
TGo4WinCond * MakeWinCond(const char *fullname, Double_t xmin, Double_t xmax, const char *HistoName=0)
TGo4CondArray * fConArr2
TGo4CondArray * fConArr1
virtual Int_t PrintParameter(Text_t *buffer=0, Int_t buflen=0)
TGo4Condition * GetAnalysisCondition(const char *name, const char *cond_cl=0)
GO4 ConditionPainter prototype Test
Definition: go4canvas.js:355
TGo4PolyCond * MakePolyCond(const char *fullname, Int_t npoints, Double_t(*points)[2], const char *HistoName=0)
virtual Bool_t BuildEvent(TGo4EventElement *dest)
virtual void SetValues(Double_t low1, Double_t up1)
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)
void AddObject(TObject *obj, Option_t *DrawOption=0)
virtual void Disable(Bool_t result)
TGo4Picture * fcondSet
void SetCalibSpectrum(TH1 *h1)
void SetHistogram(const char *name)
TXXXParameter * fParam1
virtual void Disable(Bool_t result)
#define XXX_NUM_CRATES
void AddCondition(TNamed *cond=0)
TGo4WinCond * fconHis2
void SetLineAtt(Color_t color, Style_t style, Width_t width, Int_t index=UndefIndex)
TGo4Parameter * GetParameter(const char *name, const char *par_class=0)
void SetLinesDivision(Int_t numlines, const Int_t *numbers)
TGo4EventElement * GetInputEvent()
TGo4WinCond * fWinCon1
TGo4WinCond * fconHis1
Bool_t AddAnalysisCondition(TGo4Condition *con, const char *subfolder=0)
virtual Bool_t Test(Double_t v1)
Definition: TGo4WinCond.cxx:86
void SetFillAtt(Color_t color, Style_t style, Int_t index=UndefIndex)
TGo4WinCond * fWinCon2
Bool_t AddPicture(TGo4Picture *pic, const char *subfolder=0)
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)
TGo4PolyCond * fPolyCon1
void ResetIterator()
Definition: TGo4MbsEvent.h:101
TGo4Picture * fPicture1
void AddSpecialObject(TObject *obj, Option_t *drawopt=0)
virtual void SetDrawOption(Option_t *option="")
Definition: TGo4Picture.h:139
TGo4Picture * LPic(Int_t nline, Int_t ncol)
static void Error(const char *text,...)
Definition: TGo4Log.cxx:313
static void Info(const char *text,...)
Definition: TGo4Log.cxx:287
virtual ~TXXXUnpackProc()
virtual void ResetCounts()
void SetAux(Int_t dat)
void SetTitleAttr(Double_t x1, Double_t y1, Double_t x2, Double_t y2, Double_t textsize=0.)
virtual void Invert(Bool_t on)
Bool_t RemoveHistogram(const char *name)