GSI Object Oriented Online Offline (Go4)  GO4-5.3.2
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
TXXXAnlProc.cxx
Go to the documentation of this file.
1 // $Id: TXXXAnlProc.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 für 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 "TXXXAnlProc.h"
15 
16 #include <math.h>
17 
18 #include "TH1.h"
19 #include "TH2.h"
20 #include "TGraph.h"
21 #include "TMultiGraph.h"
22 
23 #include "TGo4Log.h"
24 #include "TGo4WinCond.h"
25 #include "TGo4Fitter.h"
26 
27 #include "TXXXAnlEvent.h"
28 #include "TXXXUnpackEvent.h"
29 #include "TXXXParameter.h"
30 #include "TXXXCalibPar.h"
31 
32 //***********************************************************
35  fSum1(0),fSum2(0),fSum3(0),
36  fParam1(0),fParam2(0),fWinCon(0)
37 {
38 }
39 //***********************************************************
40 // this one is used in TXXXAnlFact
41 TXXXAnlProc::TXXXAnlProc(const char* name) :
42  TGo4EventProcessor(name)
43 {
44  TGo4Log::Info("TXXXAnlProc: Create %s", name);
46  fParam1 = (TXXXParameter*) GetParameter("XXXPar1");
47  fParam2 = (TXXXParameter*) GetParameter("XXXPar2");
48  fWinCon = (TGo4WinCond *) GetAnalysisCondition("wincon1");
49 
50  fSum1 = MakeTH1('I', "Sum1", "Sum over 8 channels", 5000, 1., 5001.);
51  fSum2 = MakeTH1('I', "Sum2", "Sum over 8 channels shift 1", 5000, 1., 5001.);
52  fSum3 = MakeTH1('I', "Sum3", "Sum over 8 channels shift 2", 5000, 1., 5001.);
53  fCaliSum1 = MakeTH1('I', "Sum1Calib", "Sum over 8 channels(keV)", 5000, 1., 20.);
54 
55  fFitSrc = MakeTH1('I', "FitSource","Copy of fit data", 1000, 0., 1000.);
56  fFitRes = MakeTH1('I', "FitTarget","Copy of fit result", 1000, 0., 1000.);
57 
58  fCaligraph = (TGraph*) GetObject("Calibration");
59  if (fCaligraph==0) {
60  fCaligraph = new TGraph;
61  fCaligraph->SetName("Calibration");
62  fCaligraph->SetMarkerStyle(3);
64  }
65 
66  fFitter = (TGo4Fitter*) GetObject("Fitter");
67  if (fFitter==0) {
68  fFitter = new TGo4Fitter("Fitter", TGo4Fitter::ff_chi_square, kTRUE);
69  fFitter->AddH1("data", 0, kFALSE, 100., 1000.);
70  fFitter->AddPolynomX("data", "Pol", 1);
72  }
73 
74  fCalipar = (TXXXCalibPar*) GetParameter("CaliPar");
75  if (fCalipar==0) {
76  // calibration parameter not yet existing, we set it up:
77  fCalipar = new TXXXCalibPar("CaliPar",GetHistogram("Cr1Ch01"),fCaligraph);
79  }
80 
81  fFitCounter = 0;
82 }
83 //***********************************************************
85 {
86 }
87 //***********************************************************
88 
89 //-----------------------------------------------------------
90 
92 {
94  TXXXAnlEvent* out_evt = (TXXXAnlEvent*) dest;
95 
96  out_evt->SetValid(kFALSE); // events are not stored until kTRUE is set
97  if((inp_evt==0) || !inp_evt->IsValid()) return kFALSE; // do not process unvalid event
98  out_evt->SetValid(kTRUE); // events are not stored until kTRUE is set
99  Int_t cnt(0);
100  TXXXUnpackEvent& ev=*inp_evt; // ref instead pointer for array syntax below
101  for(Int_t cr=1;cr<3;cr++) {
102  // loop over first filled crates 1 and 2
103  for(Int_t ii=0;ii<4;ii++)
104  {
105  // get first channels of each crate
106  TXXXModule* mod=dynamic_cast<TXXXModule*>( &ev[cr][ii]); // 2d array with composite event operator[]
107  if(mod==0) continue;
108  Float_t val= mod->GetData();
109  out_evt->frData[cnt] = val;
110  if(val) fCaliSum1->Fill(fCalipar->Energy(val));
111  cnt++;
112  }
113  }
114 
115  for(Int_t ii=0;ii<8;ii++)
116  if(out_evt->frData[ii]) {
117  if(fWinCon && fWinCon->Test(out_evt->frData[ii])) fSum1->Fill(out_evt->frData[ii]);
118  if (fParam1) fSum2->Fill(out_evt->frData[ii] + fParam1->frP1);
119  if (fParam2) fSum3->Fill(out_evt->frData[ii] + fParam2->frP1);
120  }
121 
122  fFitCounter++;
123 
124  if ((fFitCounter % 500000 == 0) && (fFitter!=0)) {
125  TH1* histo1 = GetHistogram("Crate1/Cr1Ch04");
126 
127  if (histo1!=0) {
128  fFitter->SetH1("data", histo1, kFALSE);
129  fFitter->DoActions();
130  // std::cout << "K = " << fFitter->GetParValue("Pol_1.Ampl") << " B = " << fFitter->GetParValue("Pol_0.Ampl") << std::endl;
131  // std::cout << "FF = " << fFitter->GetResultFF() << " NDF = " << fFitter->GetResultNDF() << std::endl;
132 
133  fFitSrc->Reset();
134  fFitSrc->SetBins(histo1->GetNbinsX(), histo1->GetXaxis()->GetXmin(), histo1->GetXaxis()->GetXmax());
135  fFitSrc->Add(histo1);
136 
137  TH1* histo2 = (TH1*) fFitter->CreateDrawObject("FitResult", "data", kTRUE);
138  fFitRes->Reset();
139  if (histo2!=0) {
140  fFitRes->SetBins(histo2->GetNbinsX(), histo2->GetXaxis()->GetXmin(), histo2->GetXaxis()->GetXmax());
141  fFitRes->Add(histo2);
142  fFitRes->SetTitle(Form("Result K=%5.3f B=%7.1f", fFitter->GetParValue("Pol_1.Ampl"), fFitter->GetParValue("Pol_0.Ampl")));
143  delete histo2;
144  }
145  }
146  }
147 
148  return kTRUE;
149 }
TH1 * fFitSrc
Definition: TXXXAnlProc.h:45
TNamed * GetObject(const char *name, const char *folder=0)
virtual Bool_t BuildEvent(TGo4EventElement *dest)
Definition: TXXXAnlProc.cxx:69
virtual ~TXXXAnlProc()
Definition: TXXXAnlProc.cxx:61
void SetValid(Bool_t on)
Bool_t IsValid() const
TGo4Fitter * fFitter
Definition: TXXXAnlProc.h:43
void AddPolynomX(const char *DataName, const char *NamePrefix, Int_t MaxOrder=1, Int_t GroupIndex=0, Double_t lrange=0., Double_t rrange=0.)
Definition: TGo4Fitter.cxx:225
TH1 * fSum3
Definition: TXXXAnlProc.h:34
TGo4Condition * GetAnalysisCondition(const char *name, const char *cond_cl=0)
TGraph * fCaligraph
Definition: TXXXAnlProc.h:36
TXXXParameter * fParam1
Definition: TXXXAnlProc.h:38
Double_t Energy(Int_t channel)
TXXXParameter * fParam2
Definition: TXXXAnlProc.h:39
TH1 * fSum2
Definition: TXXXAnlProc.h:33
TH1 * fFitRes
Definition: TXXXAnlProc.h:46
Bool_t AddParameter(TGo4Parameter *par, const char *subfolder=0)
Int_t GetData()
void DoActions(Bool_t AllowFitterChange=kFALSE, TObjArray *Actions=0)
TH1 * fSum1
Definition: TXXXAnlProc.h:32
TGo4Parameter * GetParameter(const char *name, const char *par_class=0)
TGo4EventElement * GetInputEvent()
virtual Bool_t Test(Double_t v1)
Definition: TGo4WinCond.cxx:83
Bool_t AddObject(TNamed *anything, 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)
Int_t fFitCounter
Definition: TXXXAnlProc.h:44
TObject * CreateDrawObject(const char *ObjName, const char *DataName, Bool_t IsModel=kFALSE, const char *ModelName=0)
Definition: TGo4Fitter.cxx:853
TXXXCalibPar * fCalipar
Definition: TXXXAnlProc.h:40
TGo4WinCond * fWinCon
Definition: TXXXAnlProc.h:37
TGo4FitDataHistogram * SetH1(const char *DataName, TH1 *histo, Bool_t Owned=kFALSE)
Definition: TGo4Fitter.cxx:134
TH1 * GetHistogram(const char *name)
TH1 * fCaliSum1
Definition: TXXXAnlProc.h:35
Float_t frData[XXX_NUM_CHAN]
Definition: TXXXAnlEvent.h:28
static void Info(const char *text,...)
Definition: TGo4Log.cxx:283
Double_t GetParValue(const char *ParName)
TGo4FitDataHistogram * AddH1(const char *DataName, TH1 *histo, Bool_t Owned=kFALSE, Double_t lrange=0., Double_t rrange=0.)
Definition: TGo4Fitter.cxx:126