Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members

TXXXAnalysis.cxx

Go to the documentation of this file.
00001 //-------------------------------------------------------------
00002 //        Go4 Release Package v3.04-01 (build 30401)
00003 //                      28-November-2008
00004 //---------------------------------------------------------------
00005 //   The GSI Online Offline Object Oriented (Go4) Project
00006 //   Experiment Data Processing at EE department, GSI
00007 //---------------------------------------------------------------
00008 //
00009 //Copyright (C) 2000- Gesellschaft f. Schwerionenforschung, GSI
00010 //                    Planckstr. 1, 64291 Darmstadt, Germany
00011 //Contact:            http://go4.gsi.de
00012 //----------------------------------------------------------------
00013 //This software can be used under the license agreements as stated
00014 //in Go4License.txt file which is part of the distribution.
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 // this constructor is used
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 // input: input file name (*.lmd)
00056 // out1:  output file name of first analysis step  (*.root)
00057 // out2:  output file name of second analysis step (*.root)
00058   cout << "**** TXXXAnalysis: Create" << endl;
00059 
00060 // the step definitions can be changed in the GUI
00061 // first step definitions:
00062 // the name of the step can be used later to get event objects
00063 // all these parameter objects will be used for the different MBS inputs
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); // overwrite file
00119   step1->SetSourceEnabled(kTRUE);
00120   step1->SetStoreEnabled(enable1);
00121   step1->SetProcessEnabled(kTRUE);
00122   step1->SetErrorStopEnabled(kTRUE);
00123 
00124 // second step definitions:
00125 // If source is enabled, take output file from step 1 as input.
00126 // otherwise we use output event from step 1 (set in factory)
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);  // disable file input (output file of step 1)
00133   step2->SetStoreEnabled(enable2);
00134   step2->SetProcessEnabled(kTRUE);
00135   step2->SetErrorStopEnabled(kTRUE);
00136   AddAnalysisStep(step2);
00137 
00138 
00140   // At this point, autosave file has not yet been read!
00141   // Therefore parameter values set here will be overwritten
00142   // if an autosave file is there.
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    // we update the pointers to the current event structures here:
00167    fMbsEvent = dynamic_cast<TGo4MbsEvent*>    (GetInputEvent("Unpack"));   // of step "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    // create histogram for UserEventFunc
00176    // At this point, the histogram has been restored from autosave file if any.
00177   fSize=(TH1D*)GetHistogram("Eventsize");
00178   if(fSize==0)
00179     { // no autosave read, create new and register
00180       fSize = new TH1D ("Eventsize", "Event size [b]",160,1,160);
00181       AddHistogram(fSize);
00182     }
00183   // we use a fitter envelope parameters to exchange fit results:
00184   fFitEnvSize=(TGo4FitterEnvelope*) GetParameter("sizefitter");
00185   if(fFitEnvSize==0)
00186    {
00187      TGo4Fitter* fitter=new TGo4Fitter("Gaussfit", TGo4Fitter::ff_ML_Poisson, kTRUE);;
00188       // add histogram to fitter, which should be fitted
00189       fitter->AddH1("data1", fSize, kFALSE);
00190       // create polynom of first order
00191       //fitter->AddPolynomX("data1", "Pol", 1);
00192       // create gaussian
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       // add histogram to fitter, which should be fitted
00202       fitter->AddH1("spectrum", fSize, kFALSE);
00203       // create polynom of first order
00204       fitter->AddPolynomX("spectrum", "Pol", 1);
00205       // create gaussian
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       // we can check some properties of last event here:
00221       //fMbsEvent->PrintEvent(); // header and data content
00222 
00223       // fileheader structure:
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       // mbs buffer header structure:
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]); // satisfy compiler warning
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 // Uncomment this if you want to perform a fit
00256 // each time analysis stops:
00258 //  if(fFitEnvSize)
00259 //     {
00260 //         cout <<"Fitting event size..." << endl;
00261 //         TGo4Fitter* fitter=fFitEnvSize->GetFitter();
00262 //         if(fitter)
00263 //         {
00264 //            //cout <<"Fitter setting histogram and fitting..." << endl;
00265 //            fitter->SetObject("data1", fSize, kFALSE);
00266 //            fitter->DoActions();
00267 //            fitter->PrintLines();
00268 //         }
00269 //     }
00271 // second fitter:
00272 //   if(fFitEnvSpectrum)
00273 //     {
00274 //         cout <<"Fitting sum spectrum..." << endl;
00275 //         TGo4Fitter* fitter=fFitEnvSpectrum->GetFitter();
00276 //         if(fitter)
00277 //         {
00278 //            //cout <<"Fitter setting histogram and fitting..." << endl;
00279 //            TH1* his=GetHistogram("Sum2");
00280 //            fitter->SetObject("spectrum", his, kFALSE);
00281 //            fitter->DoActions();
00282 //            fitter->PrintLines();
00283 //         }
00284 //     }
00286 
00287 
00290 //   cout <<"Storing parameter fPar to Unpack:" << endl;
00291 //   StoreParameter("Unpack",fPar);
00292 //   cout <<"Storing parameter fPar to Analysis:" << endl;
00293 //   StoreParameter("Analysis",fPar);
00294 //   if(fFitEnvSpectrum)
00295 //     {
00296 //         cout <<"Storing fitter"<<fFitEnvSpectrum->GetName() <<" to analysis" << endl;
00297 //         TGo4Fitter* fitter=fFitEnvSpectrum->GetFitter();
00298 //         StoreFitter("Analysis",fitter);
00299 //     }
00300 //
00301 //   TGo4Condition* winar=GetAnalysisCondition("winconar");
00302 //   if(winar)
00303 //      {
00304 //         cout <<"Storing condition"<< winar->GetName()<<"to analysis" << endl;
00305 //         StoreCondition("Analysis",winar);
00306 //      }
00307 //   cout <<"Storing all conditions to unpack." << endl;
00308 //   StoreFolder("Unpack","Conditions");
00310 
00311    fMbsEvent = 0; // reset to avoid invalid pointer if analysis is changed in between
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; // total longwords
00325    fSize->Fill(value); // fill histogram
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]); // satisfy compiler warning
00336             cout <<"\tTime: "<<ctime((const time_t*) timptr);
00337             cout << "\t\t\t + "<<bufheader->l_time[1] << " µs"<<endl;
00338          }
00339       }
00340       SetNewInputFile(kFALSE); // we have to reset the newfile flag
00341    }
00342    fLastEvent = count;
00343    return 0;
00344 }
00345 
00346 //----------------------------END OF GO4 SOURCE FILE ---------------------

Generated on Fri Nov 28 12:59:09 2008 for Go4-v3.04-1 by  doxygen 1.4.2