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