00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016 #include "TXXXAnalysis.h"
00017
00018 #include "Riostream.h"
00019 #include <time.h>
00020
00021 #include "TH1.h"
00022 #include "TFile.h"
00023
00024 #include "s_filhe_swap.h"
00025 #include "s_bufhe_swap.h"
00026 #include "TGo4Fitter.h"
00027 #include "TGo4FitterEnvelope.h"
00028 #include "TGo4AnalysisStep.h"
00029 #include "TXXXUnpackFact.h"
00030 #include "TXXXAnlFact.h"
00031 #include "TXXXParameter.h"
00032 #include "TXXXUnpackEvent.h"
00033 #include "TXXXAnlEvent.h"
00034
00035 #include "Go4EventServer.h"
00036
00037
00038
00039 TXXXAnalysis::TXXXAnalysis()
00040 : fUserFile(0),fMbsEvent(0),fRawEvent(0),fCalEvent(0)
00041 {
00042 cout << "Wrong constructor TXXXAnalysis()!" << endl;
00043 }
00044
00045
00046 TXXXAnalysis::TXXXAnalysis(Text_t * input, Int_t type, Int_t port, Text_t * out1, Text_t * out2, Bool_t enable1, Bool_t enable2)
00047 : fUserFile(0),
00048 fMbsEvent(0),
00049 fRawEvent(0),
00050 fCalEvent(0),
00051 fSize(0),
00052 fEvents(0),
00053 fLastEvent(0)
00054 {
00055
00056
00057
00058 cout << "**** TXXXAnalysis: Create" << endl;
00059
00060
00061
00062
00063
00064 TGo4MbsFileParameter* mbsfile;
00065 TGo4MbsTransportParameter* mbstrans;
00066 TGo4MbsStreamParameter* mbsstream;
00067 TGo4RevServParameter* mbsrev;
00068 TGo4MbsEventServerParameter* mbsevent;
00069 TGo4MbsRandomParameter* mbsrandom;
00070 TGo4FileStoreParameter* store1;
00071 TXXXUnpackFact* factory1;
00072 TGo4AnalysisStep* step1;
00073 TGo4FileSourceParameter* source2;
00074 TGo4FileStoreParameter* store2;
00075 TXXXAnlFact* factory2;
00076 TGo4AnalysisStep* step2;
00077
00078 factory1 = new TXXXUnpackFact("UnpackFactory");
00079 store1 = new TGo4FileStoreParameter(out1);
00080 switch (type){
00081 case GO4EV_MBS_FILE:
00082 mbsfile = new TGo4MbsFileParameter(input);
00083 step1 = new TGo4AnalysisStep("Unpack",factory1,mbsfile,store1,0);
00084 cout << "**** Unpack: Create file input " << input << endl;
00085 break;
00086 case GO4EV_MBS_STREAM:
00087 mbsstream = new TGo4MbsStreamParameter(input);
00088 step1 = new TGo4AnalysisStep("Unpack",factory1,mbsstream,store1,0);
00089 cout << "**** Unpack: Create stream input " << input << endl;
00090 break;
00091 case GO4EV_MBS_TRANSPORT:
00092 mbstrans = new TGo4MbsTransportParameter(input);
00093 step1 = new TGo4AnalysisStep("Unpack",factory1,mbstrans,store1,0);
00094 cout << "**** Unpack: Create transport input " << input << endl;
00095 break;
00096 case GO4EV_MBS_REVSERV:
00097 mbsrev = new TGo4RevServParameter(input);
00098 mbsrev->SetPort(port);
00099 step1 = new TGo4AnalysisStep("Unpack",factory1,mbsrev,store1,0);
00100 cout << "**** Unpack: Create remote event server input " << input << " port " << port <<endl;
00101 break;
00102 case GO4EV_MBS_EVENTSERVER:
00103 mbsevent = new TGo4MbsEventServerParameter(input);
00104 step1 = new TGo4AnalysisStep("Unpack",factory1,mbsevent,store1,0);
00105 cout << "**** Unpack: Create mbs event server input " << input << endl;
00106 break;
00107 case GO4EV_MBS_RANDOM:
00108 mbsrandom = new TGo4MbsRandomParameter(input);
00109 step1 = new TGo4AnalysisStep("Unpack",factory1,mbsrandom,store1,0);
00110 cout << "**** Unpack: Create mbs random input " << input << endl;
00111 break;
00112 default:
00113 step1 = 0;
00114 break;
00115 }
00116 AddAnalysisStep(step1);
00117
00118 store1->SetOverwriteMode(kTRUE);
00119 step1->SetSourceEnabled(kTRUE);
00120 step1->SetStoreEnabled(enable1);
00121 step1->SetProcessEnabled(kTRUE);
00122 step1->SetErrorStopEnabled(kTRUE);
00123
00124
00125
00126
00127 factory2 = new TXXXAnlFact("AnalysisFactory");
00128 source2 = new TGo4FileSourceParameter(out1);
00129 store2 = new TGo4FileStoreParameter(out2);
00130 step2 = new TGo4AnalysisStep("Analysis",factory2,source2,store2,0);
00131 store2->SetOverwriteMode(kTRUE);
00132 step2->SetSourceEnabled(kFALSE);
00133 step2->SetStoreEnabled(enable2);
00134 step2->SetProcessEnabled(kTRUE);
00135 step2->SetErrorStopEnabled(kTRUE);
00136 AddAnalysisStep(step2);
00137
00138
00140
00141
00142
00143 fPar = new TXXXParameter("XXXPar1");
00144 fPar->frP1 = 100;
00145 fPar->frP2 = 200;
00146 AddParameter(fPar);
00147 fPar = new TXXXParameter("XXXPar2");
00148 fPar->frP1 = 1000;
00149 fPar->frP2 = 2000;
00150 AddParameter(fPar);
00151
00152
00153 }
00154
00155
00156 TXXXAnalysis::~TXXXAnalysis()
00157 {
00158 cout << "**** TXXXAnalysis: Delete" << endl;
00159 }
00160
00161
00162
00163 Int_t TXXXAnalysis::UserPreLoop()
00164 {
00165 cout << "**** TXXXAnalysis: PreLoop" << endl;
00166
00167 fMbsEvent = dynamic_cast<TGo4MbsEvent*> (GetInputEvent("Unpack"));
00168 fRawEvent = dynamic_cast<TXXXUnpackEvent*> (GetOutputEvent("Unpack"));
00169 fCalEvent = dynamic_cast<TXXXAnlEvent*> (GetOutputEvent("Analysis"));
00170 fEvents=0;
00171 fLastEvent=0;
00172
00173
00174
00175
00176
00177 fSize=(TH1D*)GetHistogram("Eventsize");
00178 if(fSize==0)
00179 {
00180 fSize = new TH1D ("Eventsize", "Event size [b]",160,1,160);
00181 AddHistogram(fSize);
00182 }
00183
00184 fFitEnvSize=(TGo4FitterEnvelope*) GetParameter("sizefitter");
00185 if(fFitEnvSize==0)
00186 {
00187 TGo4Fitter* fitter=new TGo4Fitter("Gaussfit", TGo4Fitter::ff_ML_Poisson, kTRUE);;
00188
00189 fitter->AddH1("data1", fSize, kFALSE);
00190
00191
00192
00193 fitter->AddGauss1("data1", "Gauss1",15,5,1000);
00194 fFitEnvSize=new TGo4FitterEnvelope("sizefitter",fitter);
00195 AddParameter(fFitEnvSize);
00196 }
00197 fFitEnvSpectrum=(TGo4FitterEnvelope*) GetParameter("specfitter");
00198 if(fFitEnvSpectrum==0)
00199 {
00200 TGo4Fitter* fitter=new TGo4Fitter("Multilines", TGo4Fitter::ff_ML_Poisson, kTRUE);;
00201
00202 fitter->AddH1("spectrum", fSize, kFALSE);
00203
00204 fitter->AddPolynomX("spectrum", "Pol", 1);
00205
00206 fitter->AddGauss1("spectrum", "Gauss1",500,20,1000);
00207 fFitEnvSpectrum=new TGo4FitterEnvelope("specfitter",fitter);
00208 AddParameter(fFitEnvSpectrum);
00209 }
00210
00211 return 0;
00212 }
00213
00214 Int_t TXXXAnalysis::UserPostLoop()
00215 {
00216 cout << "**** TXXXAnalysis: PostLoop" << endl;
00217 cout << "Last event: " << fLastEvent << " Total events: " << fEvents << endl;
00218 if(fMbsEvent)
00219 {
00220
00221
00222
00223
00224 s_filhe* fileheader=fMbsEvent->GetMbsSourceHeader();
00225 if(fileheader)
00226 {
00227 cout <<"\nInput file was: "<<fileheader->filhe_file << endl;
00228 cout <<"Tapelabel:\t" << fileheader->filhe_label<<endl;
00229 cout <<"UserName:\t" << fileheader->filhe_user<<endl;
00230 cout <<"RunID:\t" << fileheader->filhe_run<<endl;
00231 cout <<"\tExplanation: "<<fileheader->filhe_exp <<endl;
00232 cout <<"\tComments: "<<endl;
00233 Int_t numlines=fileheader->filhe_lines;
00234 for(Int_t i=0; i<numlines;++i)
00235 {
00236 cout<<"\t\t"<<fileheader->s_strings[i].string << endl;
00237 }
00238 }
00239
00240
00241 s_bufhe* bufheader=fMbsEvent->GetMbsBufferHeader();
00242 if(bufheader)
00243 {
00244 cout <<"Last Buffer:"<<endl;
00245 cout <<"\tNumber: "<<bufheader->l_buf << endl;
00246 void* timptr=&(bufheader->l_time[0]);
00247 cout <<"\tTime: "<<ctime((const time_t*) timptr);
00248 cout << "\t\t\t + "<<bufheader->l_time[1] << " µs"<<endl;
00249 }
00250
00251
00252 }
00253
00255
00256
00258
00259
00260
00261
00262
00263
00264
00265
00266
00267
00268
00269
00271
00272
00273
00274
00275
00276
00277
00278
00279
00280
00281
00282
00283
00284
00286
00287
00290
00291
00292
00293
00294
00295
00296
00297
00298
00299
00300
00301
00302
00303
00304
00305
00306
00307
00308
00310
00311 fMbsEvent = 0;
00312 fRawEvent = 0;
00313 fCalEvent = 0;
00314 fEvents=0;
00315 return 0;
00316 }
00317
00318
00319 Int_t TXXXAnalysis::UserEventFunc()
00320 {
00322 Int_t value = 0;
00323 Int_t count = 0;
00324 if(fMbsEvent) value = fMbsEvent->GetDlen()/2+2;
00325 fSize->Fill(value);
00326 fEvents++;
00327 if(fEvents == 1 || IsNewInputFile()) {
00328 if(fMbsEvent) {
00329 count=fMbsEvent->GetCount();
00330 cout << "\nFirst event #: " << count << endl;
00331 s_bufhe* bufheader=fMbsEvent->GetMbsBufferHeader();
00332 if(bufheader) {
00333 cout <<"First Buffer:"<<endl;
00334 cout <<"\tNumber: "<<bufheader->l_buf << endl;
00335 void* timptr=&(bufheader->l_time[0]);
00336 cout <<"\tTime: "<<ctime((const time_t*) timptr);
00337 cout << "\t\t\t + "<<bufheader->l_time[1] << " µs"<<endl;
00338 }
00339 }
00340 SetNewInputFile(kFALSE);
00341 }
00342 fLastEvent = count;
00343 return 0;
00344 }
00345
00346