00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014 #include "TXXXAnlProc.h"
00015
00016 #include <math.h>
00017
00018 #include "TH1.h"
00019 #include "TH2.h"
00020 #include "TGraph.h"
00021 #include "TMultiGraph.h"
00022
00023 #include "TGo4Log.h"
00024 #include "TGo4WinCond.h"
00025 #include "TGo4Fitter.h"
00026
00027 #include "TXXXAnlEvent.h"
00028 #include "TXXXUnpackEvent.h"
00029 #include "TXXXParameter.h"
00030 #include "TXXXCalibPar.h"
00031
00032
00033 TXXXAnlProc::TXXXAnlProc() :
00034 TGo4EventProcessor(),
00035 fSum1(0),fSum2(0),fSum3(0),
00036 fParam1(0),fParam2(0),fWinCon(0)
00037 {
00038 }
00039
00040
00041 TXXXAnlProc::TXXXAnlProc(const char* name) :
00042 TGo4EventProcessor(name)
00043 {
00044 TGo4Log::Info("TXXXAnlProc: Create %s", name);
00046 fParam1 = (TXXXParameter*) GetParameter("XXXPar1");
00047 fParam2 = (TXXXParameter*) GetParameter("XXXPar2");
00048 fWinCon = (TGo4WinCond *) GetAnalysisCondition("wincon1");
00049
00050 fSum1 = MakeTH1('I', "Sum1", "Sum over 8 channels", 5000, 1., 5001.);
00051 fSum2 = MakeTH1('I', "Sum2", "Sum over 8 channels shift 1", 5000, 1., 5001.);
00052 fSum3 = MakeTH1('I', "Sum3", "Sum over 8 channels shift 2", 5000, 1., 5001.);
00053 fCaliSum1 = MakeTH1('I', "Sum1Calib", "Sum over 8 channels(keV)", 5000, 1., 20.);
00054
00055 fFitSrc = MakeTH1('I', "FitSource","Copy of fit data", 1000, 0., 1000.);
00056 fFitRes = MakeTH1('I', "FitTarget","Copy of fit result", 1000, 0., 1000.);
00057
00058 fCaligraph = (TGraph*) GetObject("Calibration");
00059 if (fCaligraph==0) {
00060 fCaligraph=new TGraph;
00061 fCaligraph->SetName("Calibration");
00062 fCaligraph->SetMarkerStyle(3);
00063 AddObject(fCaligraph);
00064 }
00065
00066 fFitter = (TGo4Fitter*)GetObject("Fitter");
00067 if (fFitter==0) {
00068 fFitter = new TGo4Fitter("Fitter", TGo4Fitter::ff_chi_square, kTRUE);
00069 fFitter->AddH1("data", 0, kFALSE, 100., 1000.);
00070 fFitter->AddPolynomX("data", "Pol", 1);
00071 AddObject(fFitter);
00072 }
00073
00074 fCalipar = (TXXXCalibPar*) GetParameter("CaliPar");
00075 if (fCalipar==0) {
00076
00077 fCalipar=new TXXXCalibPar("CaliPar",GetHistogram("Cr1Ch01"),fCaligraph);
00078 AddParameter(fCalipar);
00079 }
00080
00081 fFitCounter = 0;
00082 }
00083
00084 TXXXAnlProc::~TXXXAnlProc()
00085 {
00086 }
00087
00088
00089
00090
00091 Bool_t TXXXAnlProc::BuildEvent(TGo4EventElement* dest)
00092 {
00093 TXXXUnpackEvent* inp_evt = (TXXXUnpackEvent*) GetInputEvent();
00094 TXXXAnlEvent* out_evt = (TXXXAnlEvent*) dest;
00095
00096 out_evt->SetValid(kFALSE);
00097 if((inp_evt==0) || !inp_evt->IsValid()) return kFALSE;
00098 out_evt->SetValid(kTRUE);
00099 Int_t cnt(0);
00100 TXXXUnpackEvent& ev=*inp_evt;
00101 for(Int_t cr=1;cr<3;cr++)
00102 {
00103
00104 for(Int_t ii=0;ii<4;ii++)
00105 {
00106
00107 TXXXModule* mod=dynamic_cast<TXXXModule*>( &ev[cr][ii]);
00108 if(mod==0) continue;
00109 Float_t val= mod->GetData();
00110 out_evt->frData[cnt] = val;
00111 if(val) fCaliSum1->Fill(fCalipar->Energy(val));
00112 cnt++;
00113 }
00114 }
00115
00116
00117
00118 for(Int_t ii=0;ii<8;ii++)
00119 if(out_evt->frData[ii]) {
00120 if(fWinCon && fWinCon->Test(out_evt->frData[ii])) fSum1->Fill(out_evt->frData[ii]);
00121 if (fParam1) fSum2->Fill(out_evt->frData[ii] + fParam1->frP1);
00122 if (fParam2) fSum3->Fill(out_evt->frData[ii] + fParam2->frP1);
00123 }
00124
00125 fFitCounter++;
00126
00127 if ((fFitCounter % 500000 == 0) && (fFitter!=0)) {
00128 TH1* histo1 = GetHistogram("Crate1/Cr1Ch04");
00129
00130 if (histo1!=0) {
00131 fFitter->SetH1("data", histo1, kFALSE);
00132 fFitter->DoActions();
00133
00134
00135
00136 fFitSrc->Reset();
00137 fFitSrc->SetBins(histo1->GetNbinsX(), histo1->GetXaxis()->GetXmin(), histo1->GetXaxis()->GetXmax());
00138 fFitSrc->Add(histo1);
00139
00140 TH1* histo2 = (TH1*) fFitter->CreateDrawObject("FitResult", "data", kTRUE);
00141 fFitRes->Reset();
00142 if (histo2!=0) {
00143 fFitRes->SetBins(histo2->GetNbinsX(), histo2->GetXaxis()->GetXmin(), histo2->GetXaxis()->GetXmax());
00144 fFitRes->Add(histo2);
00145 fFitRes->SetTitle(Form("Result K=%5.3f B=%7.1f", fFitter->GetParValue("Pol_1.Ampl"), fFitter->GetParValue("Pol_0.Ampl")));
00146 delete histo2;
00147 }
00148 }
00149 }
00150
00151 return kTRUE;
00152 }