00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014 #include "TXXXAnalysis.h"
00015
00016 #include <stdlib.h>
00017
00018 #include "TH1.h"
00019 #include "TFile.h"
00020 #include "TSystem.h"
00021
00022 extern "C" {
00023 #include "s_filhe_swap.h"
00024 #include "s_bufhe_swap.h"
00025 #include "f_ut_utime.h"
00026 }
00027
00028 #include "TGo4Fitter.h"
00029 #include "TGo4FitterEnvelope.h"
00030 #include "TGo4AnalysisStep.h"
00031 #include "TGo4StepFactory.h"
00032 #include "TXXXParameter.h"
00033 #include "TXXXUnpackEvent.h"
00034 #include "TXXXAnlEvent.h"
00035 #include "TGo4Version.h"
00036
00037 #include "Go4EventServer.h"
00038
00039
00040 TXXXAnalysis::TXXXAnalysis() :
00041 TGo4Analysis(),
00042 fMbsEvent(0),
00043 fRawEvent(0),
00044 fCalEvent(0)
00045 {
00046 TGo4Log::Error("Wrong constructor TXXXAnalysis()!");
00047 }
00048
00049
00050
00051 TXXXAnalysis::TXXXAnalysis(int argc, char** argv) :
00052 TGo4Analysis(argc, argv),
00053 fMbsEvent(0),
00054 fRawEvent(0),
00055 fCalEvent(0),
00056 fSize(0),
00057 fEvents(0),
00058 fLastEvent(0)
00059 {
00060 if (!TGo4Version::CheckVersion(__GO4BUILDVERSION__)) {
00061 TGo4Log::Error("Go4 version mismatch");
00062 exit(-1);
00063 }
00064
00065 TGo4Log::Info("TXXXAnalysis: Create %s", argv[0]);
00066
00067 TString kind, input, out1, out2;
00068
00069
00070
00071
00072
00073
00074
00075
00076 switch(argc){
00077 case 1:
00078 TGo4Log::Info("Configure with default parameters");
00079 kind = "-file";
00080 input = "test";
00081 out1 = "Output_Calib";
00082 out2 = "Output_Anl";
00083 break;
00084
00085 case 2:
00086 TGo4Log::Info("Configure with user-specified parameters");
00087 kind = "-file";
00088 input = TString::Format("%s", argv[1]);
00089 out1 = TString::Format("%s_Calib", argv[1]);
00090 out2 = TString::Format("%s_Anl", argv[1]);
00091 break;
00092 case 3:
00093 default:
00094 TGo4Log::Info("Configure with user-specified parameters");
00095 kind = TString::Format("%s", argv[1]);
00096 input = TString::Format("%s", argv[2]);
00097 out1 = TString::Format("%s_Calib", argv[2]);
00098 out2 = TString::Format("%s_Anl", argv[2]);
00099 break;
00100 }
00101
00102 TGo4StepFactory* factory1 = new TGo4StepFactory("UnpackFactory");
00103 factory1->DefEventProcessor("UnpackProc", "TXXXUnpackProc");
00104 factory1->DefOutputEvent("UnpackEvent", "TXXXUnpackEvent");
00105 TGo4AnalysisStep* step1 = new TGo4AnalysisStep("Unpack",factory1,0,0,0);
00106 step1->SetErrorStopEnabled(kTRUE);
00107 AddAnalysisStep(step1);
00108
00109 step1->SetSourceEnabled(kTRUE);
00110 step1->SetStoreEnabled(kFALSE);
00111 step1->SetProcessEnabled(kTRUE);
00112
00113
00114 TGo4StepFactory* factory2 = new TGo4StepFactory("AnalysisFactory");
00115 factory2->DefInputEvent("UnpackEvent", "TXXXUnpackEvent");
00116 factory2->DefEventProcessor("AnlProc", "TXXXAnlProc");
00117 factory2->DefOutputEvent("AnlEvent", "TXXXAnlEvent");
00118 TGo4AnalysisStep* step2 = new TGo4AnalysisStep("Analysis",factory2,0,0,0);
00119 step2->SetErrorStopEnabled(kTRUE);
00120 AddAnalysisStep(step2);
00121
00122 step2->SetSourceEnabled(kFALSE);
00123 step2->SetStoreEnabled(kFALSE);
00124 step2->SetProcessEnabled(kTRUE);
00125
00126
00127
00128
00130
00131
00132
00133 fPar = new TXXXParameter("XXXPar1");
00134 fPar->frP1 = 100;
00135 fPar->frP2 = 200;
00136 AddParameter(fPar);
00137 fPar = new TXXXParameter("XXXPar2");
00138 fPar->frP1 = 1000;
00139 fPar->frP2 = 2000;
00140 AddParameter(fPar);
00141
00142
00143
00144 ExecuteScript(Form("setup.C(\"%s\",\"%s\")", kind.Data(), input.Data()));
00145 }
00146
00147
00148 TXXXAnalysis::~TXXXAnalysis()
00149 {
00150 TGo4Log::Info("TXXXAnalysis: Delete");
00151 }
00152
00153
00154
00155 Int_t TXXXAnalysis::UserPreLoop()
00156 {
00157 TGo4Log::Info("TXXXAnalysis: PreLoop");
00158 Print();
00159
00160 fMbsEvent = dynamic_cast<TGo4MbsEvent*> (GetInputEvent("Unpack"));
00161 fRawEvent = dynamic_cast<TXXXUnpackEvent*> (GetOutputEvent("Unpack"));
00162 fCalEvent = dynamic_cast<TXXXAnlEvent*> (GetOutputEvent("Analysis"));
00163 fEvents=0;
00164 fLastEvent=0;
00165
00166
00167
00168
00169 fSize=(TH1D*)GetHistogram("Eventsize");
00170 if(fSize==0)
00171 {
00172 fSize = new TH1D ("Eventsize", "Event size [b]",160,1,160);
00173 AddHistogram(fSize);
00174 }
00175
00176 fFitEnvSize=(TGo4FitterEnvelope*) GetParameter("sizefitter");
00177 if(fFitEnvSize==0)
00178 {
00179 TGo4Fitter* fitter=new TGo4Fitter("Gaussfit", TGo4Fitter::ff_ML_Poisson, kTRUE);;
00180
00181 fitter->AddH1("data1", fSize, kFALSE);
00182
00183
00184
00185 fitter->AddGauss1("data1", "Gauss1",15,5,1000);
00186 fFitEnvSize=new TGo4FitterEnvelope("sizefitter",fitter);
00187 AddParameter(fFitEnvSize);
00188 }
00189 fFitEnvSpectrum=(TGo4FitterEnvelope*) GetParameter("specfitter");
00190 if(fFitEnvSpectrum==0)
00191 {
00192 TGo4Fitter* fitter=new TGo4Fitter("Multilines", TGo4Fitter::ff_ML_Poisson, kTRUE);;
00193
00194 fitter->AddH1("spectrum", fSize, kFALSE);
00195
00196 fitter->AddPolynomX("spectrum", "Pol", 1);
00197
00198 fitter->AddGauss1("spectrum", "Gauss1",500,20,1000);
00199 fFitEnvSpectrum=new TGo4FitterEnvelope("specfitter",fitter);
00200 AddParameter(fFitEnvSpectrum);
00201 }
00202
00203 return 0;
00204 }
00205
00206 Int_t TXXXAnalysis::UserPostLoop()
00207 {
00208 TGo4Log::Info("TXXXAnalysis: PostLoop");
00209 TGo4Log::Info("Last event: %d Total events: %d", fLastEvent, fEvents);
00210 if(fMbsEvent)
00211 {
00212
00213
00214
00215
00216 fMbsEvent->PrintMbsFileHeader();
00217
00218
00219 fMbsEvent->PrintMbsBufferHeader();
00220 }
00222
00223
00225
00226
00227
00228
00229
00230
00231
00232
00233
00234
00235
00236
00238
00239
00240
00241
00242
00243
00244
00245
00246
00247
00248
00249
00250
00251
00253
00254
00257
00258
00259
00260
00261
00262
00263
00264
00265
00266
00267
00268
00269
00270
00271
00272
00273
00274
00275
00277
00278 fMbsEvent = 0;
00279 fRawEvent = 0;
00280 fCalEvent = 0;
00281 fEvents=0;
00282 return 0;
00283 }
00284
00285
00286 Int_t TXXXAnalysis::UserEventFunc()
00287 {
00289 Int_t value = 0;
00290 Int_t count = 0;
00291 if(fMbsEvent) value = fMbsEvent->GetDlen()/2+2;
00292 fSize->Fill(value);
00293 fEvents++;
00294 if(fEvents == 1 || IsNewInputFile()) {
00295 if(fMbsEvent) {
00296 count = fMbsEvent->GetCount();
00297 TGo4Log::Info("First event #: %d", count);
00298
00299
00300 fMbsEvent->PrintMbsBufferHeader();
00301 }
00302 }
00303 fLastEvent = count;
00304 return 0;
00305 }