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