GSI Object Oriented Online Offline (Go4)  GO4-6.1.2
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
TXXXProc.cxx
Go to the documentation of this file.
1 // $Id: TXXXProc.cxx 997 2013-07-17 14:50: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 "TXXXProc.h"
15 
16 #include "TH1.h"
17 #include "TH2.h"
18 
19 #include "TGo4Log.h"
20 #include "TGo4MbsEvent.h"
21 #include "TGo4WinCond.h"
22 #include "TGo4PolyCond.h"
23 #include "TGo4Picture.h"
24 
25 //***********************************************************
28  fHandle()
29 {
30 }
31 
32 //***********************************************************
34 {
35  TGo4Log::Info("TXXXProc: Delete instance");
36 }
37 
38 //***********************************************************
39 // this one is used in standard factory
40 TXXXProc::TXXXProc(const char* name) :
41  TGo4EventProcessor(name),
42  fHandle()
43 {
44  TGo4Log::Info("TXXXProc: Create instance");
45 
46  for(int i=0;i<8;i++) {
47  fCr1Ch[i] = MakeTH1('I', Form("Crate1/Cr1Ch%02d",i+1), Form("Crate 1 channel %2d",i+1), 5000, 1., 5001.);
48  fCr2Ch[i] = MakeTH1('I', Form("Crate2/Cr2Ch%02d",i+1), Form("Crate 2 channel %2d",i+1), 5000, 1., 5001.);
49  }
50 
51  fCr1Ch1x2 = MakeTH2('I', "Cr1Ch1x2","Crate 1 channel 1x2", 200, 1., 5001., 200, 1., 5001.);
52  fHis1 = MakeTH1('I', "His1","Condition histogram", 5000, 1., 5001.);
53  fHis2 = MakeTH1('I', "His2","Condition histogram", 5000, 1., 5001.);
54  fHis1gate = MakeTH1('I', "His1g","Gated histogram", 5000, 1., 5001.);
55  fHis2gate = MakeTH1('I', "His2g","Gated histogram", 5000, 1., 5001.);
56  fHis3 = MakeTH1('I', "His3","Singular histogram", 20000, 0.999, 1.001);
57 
58  fconHis1 = MakeWinCond("cHis1", 100,2000, "His1");
59  fconHis2 = MakeWinCond("cHis2", 100,2000, "His2");
60 
61  Double_t cutpnts[3][2] = { {400, 800}, {700, 900}, {600, 1100} };
62  fPolyCon = MakePolyCond("polycon", 3, cutpnts);
63 
64  fcondSet = GetPicture("condSet");
65  if (fcondSet==0) {
66  // in the upper two pads, the condition limits can be set,
67  // in the lower two pads, the resulting histograms are shown
68  fcondSet = new TGo4Picture("condSet","Set conditions");
69  fcondSet->SetDivision(2,2);
70  fcondSet->Pic(0,0)->AddObject(fHis1);
71  fcondSet->Pic(0,1)->AddObject(fHis2);
76 
77  fcondSet->Pic(1,0)->SetFillAtt(4, 1001); // solid
78  fcondSet->Pic(1,0)->SetLineAtt(4,1,1);
79  fcondSet->Pic(1,1)->SetFillAtt(9, 1001); // solid
80  fcondSet->Pic(1,1)->SetLineAtt(9,1,1);
82  }
83 
84  const char* mbsnode = "x86l-9";
85 
86  fHandle = mbs::MonitorHandle::Connect(mbsnode);
87  if (!fHandle.null())
88  printf("Connect to MBS node %s\n", mbsnode);
89  else
90  printf("Fail to connect to MBS node %s\n", mbsnode);
91 
92 
93 /*
94  // this is example of creating canvas, which can be observed in the gui" << std::endl;
95  TCanvas* mycan = new TCanvas("TestCanvas","Does this work?", 3);
96  std::cout << "Did Creating canvas " << std::endl;
97  mycan->Divide(2,2);
98  mycan->cd(1);
99  fHis1->Draw();
100  mycan->cd(2);
101  fHis2->Draw();
102  AddCanvas(mycan);
103 
104 */
105 }
106 
107 //-----------------------------------------------------------
108 // event function
110 { // called by framework. We dont fill any output event here at all
111 
112  if ((GetInputEvent()==0) || (GetInputEvent()->IsA() != TGo4MbsEvent::Class())) {
113  std::cout << "TXXXProc: no input MBS event found!" << std::endl;
114  return kFALSE;
115  }
116 
118 
119  if(evnt->GetTrigger() > 11) {
120  std::cout << "**** TXXXProc: Skip trigger event" << std::endl;
121  return kFALSE;
122  }
123  // first we fill the arrays fCrate1,2 with data from MBS source
124  // we have up to two subevents, crate 1 and 2
125  // Note that one has to loop over all subevents and select them by
126  // crate number: psubevt->GetSubcrate(),
127  // procid: psubevt->GetProcid(),
128  // and/or control: psubevt->GetControl()
129  // here we use only crate number
130 
131  Float_t Crate1[8];
132  Float_t Crate2[8];
133  for(Int_t i = 0; i<8; i++) {
134  Crate1[i] = 0.;
135  Crate2[i] = 0.;
136  }
137 
138 
139  // uncomment this lines to update histogram on the gui periodically without activating monitoring
140  //static int cnt =0;
141  // if ((cnt++ % 100000) == 0) SendObjectToGUI(fHis1);
142 
143  evnt->ResetIterator();
144  TGo4MbsSubEvent *psubevt(0);
145  while((psubevt = evnt->NextSubEvent()) != 0) { // loop over subevents
146  Int_t * pdata = psubevt->GetDataField();
147  Int_t lwords = psubevt->GetIntLen();
148  if(lwords > 8) lwords = 8; // take only first 8 lwords
149 
150  if(psubevt->GetSubcrate() == 1)
151  for(Int_t i = 0; i<lwords; i++)
152  Crate1[i] = (Float_t)*pdata++;
153 
154  if(psubevt->GetSubcrate() == 2)
155  for(Int_t i = 0; i<lwords; i++)
156  Crate2[i] = (Float_t)*pdata++;
157  }
158 
159  // now we fill histograms from the arrays
160  for(Int_t i = 0; i<8; i++) {
161  fCr1Ch[i]->Fill(Crate1[i]);
162  fCr2Ch[i]->Fill(Crate2[i]);
163  }
164  Float_t value1 = Crate1[0];
165  Float_t value2 = Crate1[1];
166  fHis1->Fill(value1); // fill histograms without gate
167  fHis2->Fill(value2);
168  if(fconHis1->Test(value1))fHis1gate->Fill(value1); //fill histograms with gate
169  if(fconHis2->Test(value2))fHis2gate->Fill(value2);
170  if(fPolyCon->Test(value1,value2)) fCr1Ch1x2->Fill(value1,value2);
171  fHis3->Fill(1.);
172  return kTRUE;
173 }
TXXXProc()
Definition: TXXXProc.cxx:31
Bool_t BuildEvent(TGo4EventElement *target)
Definition: TXXXProc.cxx:141
TGo4Picture * GetPicture(const char *name)
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 * fHis2
Definition: TXXXProc.h:35
TGo4WinCond * MakeWinCond(const char *fullname, Double_t xmin, Double_t xmax, const char *HistoName=0)
TGo4Picture * fcondSet
Definition: TXXXProc.h:43
TGo4PolyCond * MakePolyCond(const char *fullname, Int_t npoints, Double_t(*points)[2], const char *HistoName=0)
TH1 * fHis1
Definition: TXXXProc.h:33
mbs::MonitorHandle fHandle
Definition: TXXXProc.h:27
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:36
void AddObject(TObject *obj, Option_t *DrawOption=0)
TGo4WinCond * fconHis2
Definition: TXXXProc.h:38
virtual ~TXXXProc()
Definition: TXXXProc.cxx:36
void AddCondition(TNamed *cond=0)
void SetLineAtt(Color_t color, Style_t style, Width_t width, Int_t index=UndefIndex)
TH1 * fCr2Ch[8]
Definition: TXXXProc.h:31
TGo4PolyCond * fPolyCon
Definition: TXXXProc.h:39
TGo4EventElement * GetInputEvent()
virtual Bool_t Test(Double_t v1)
Definition: TGo4WinCond.cxx:86
TH1 * fCr1Ch[8]
Definition: TXXXProc.h:30
void SetFillAtt(Color_t color, Style_t style, Int_t index=UndefIndex)
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)
Short_t GetTrigger() const
Definition: TGo4MbsEvent.h:146
TH2 * fCr1Ch1x2
Definition: TXXXProc.h:32
void ResetIterator()
Definition: TGo4MbsEvent.h:98
TGo4WinCond * fconHis1
Definition: TXXXProc.h:37
TH1 * fHis1gate
Definition: TXXXProc.h:34
static void Info(const char *text,...)
Definition: TGo4Log.cxx:287
TH1 * fHis3
Definition: TXXXProc.h:45