GSI Object Oriented Online Offline (Go4) GO4-6.4.0
Loading...
Searching...
No Matches
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
40TXXXUnpackProc::TXXXUnpackProc(const char *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
77 fConArr1 = (TGo4CondArray*)GetAnalysisCondition("winconar");
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");
86 AddAnalysisCondition(fConArr1);
87 } else {
88 fConArr1->ResetCounts();
89 }
90
91 fConArr2 = (TGo4CondArray*)GetAnalysisCondition("polyconar");
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
102 AddAnalysisCondition(fConArr2);
103 } else {
104 TGo4Log::Info("TXXXProc: Restore condition from autosave");
105 fConArr2->ResetCounts();
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);
128 fcondSet->Pic(0,0)->AddCondition(fconHis1);
129 fcondSet->Pic(0,1)->AddCondition(fconHis2);
130 fcondSet->Pic(1,0)->AddObject(fHis1gate);
131 fcondSet->Pic(1,1)->AddObject(fHis2gate);
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);
137 AddPicture(fcondSet);
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]);
157 fPicture1->LPic(3,0)->AddObject(fCr1Ch1x2);
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.));
162 AddPicture(fPicture1);
163 }
164}
165//***********************************************************
167{
168 fWinCon1->PrintCondition(true);
169 fPolyCon1->PrintCondition(true);
170}
171
172//-----------------------------------------------------------
173void 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 auto inp_evt = static_cast<TGo4MbsEvent *>(GetInputEvent()); // from this
204 auto out_evt = static_cast<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}
#define XXX_NUM_CRATES
Array of conditions.
The abstract base class for the data elements of which the unpacked events (or detector structure dat...
Abstract event processor.
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)
Create one dimensional histogram of specified type.
TGo4Parameter * GetParameter(const char *name, const char *par_class=nullptr)
Get parameter from go4 framework.
TGo4EventElement * GetInputEvent()
Access to external raw event which is set as association member.
Bool_t RemoveHistogram(const char *name)
UnRegister histogram from go4 framework and delete it.
static void Info(const char *text,...) GO4_PRINTF_ARGS
User shortcut for message with prio 1.
Definition TGo4Log.cxx:294
static void Error(const char *text,...) GO4_PRINTF_ARGS
User shortcut for message with prio 3.
Definition TGo4Log.cxx:320
Wrapper for the standard gsi event structure as delivered from mbs.
Picture cconfiguration in Go4.
Definition TGo4Picture.h:40
void SetCalibSpectrum(TH1 *h1)
Reset reference to calibration spectrum in fitter.
void SetAux(Int_t dat)
void SetData(Int_t dat)
void SetTest(Int_t dat)
TGo4WinCond * fconHis1
TGo4WinCond * fconHis2
TGo4WinCond * fWinCon1
Bool_t BuildEvent(TGo4EventElement *dest) override
Fill the destination event dest.
TH1 * fCr1Ch[XXX_NUM_CHAN]
void CreateRawHistograms(int nbins, double xmin, double xmax)
TGo4PolyCond * fPolyCon1
TH1 * fCr2Ch[XXX_NUM_CHAN]
TGo4CondArray * fConArr2
virtual ~TXXXUnpackProc()