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