• Main Page
  • Related Pages
  • Namespaces
  • Data Structures
  • Files
  • File List
  • Globals

beamtime/tof-tdctest/go4/ROOTCONV/TRootConverterProc.cxx (r4864/r4613)

Go to the documentation of this file.
00001 /* Generated by Together */
00002 
00003 #include "TRootConverterProc.h"
00004 #include "TCBMBeamtimeEvent.h"
00005 #include "TGo4Version.h"
00006 #if __GO4BUILDVERSION__ > 40502
00007    #include "go4iostream.h"
00008 #else
00009    #include "Riostream.h"
00010 #endif
00011 #include "TGo4UserException.h"
00012 #include "TGo4MbsEvent.h"
00013 
00014 #include "TH1.h"
00015 #include "TH2.h"
00016 #include "TH3.h"
00017 #include "TProfile.h"
00018 
00019 #include "TGo4Analysis.h"
00020 
00021 #include <algorithm>
00022 
00023 //***********************************************************
00024 TRootConverterProc::TRootConverterProc(const char* name) :
00025 TCBMBeamtimeProc(name),
00026 fGet4v1InputEvent(0),
00027 fCrateInputEvent(0),
00028 fTriglogInputEvent(0),
00029 fEpicsInputEvent(0),
00030 fVftxInputEvent(0),
00031 //fPadRpcInputEvent(0),
00032 fScalOrMu1InputEvent(0),
00033 fScalOrMu2InputEvent(0),
00034 fMatchingInputEvent(0),
00035 #ifdef ROOTCONV_WITHHODO
00036 fHodoInputEvent(0),
00037 #endif
00038 fOutputEvent(0),
00039 cleanTree(0)
00040 {
00041    TGo4Log::Info("**** TRootConverterProc: Create instance %s", name);
00042 
00043    for( UInt_t uRpcIndex = 0; uRpcIndex < NB_RPC; uRpcIndex++ )
00044       fRpcInputEvent[uRpcIndex] = 0;
00045    for( UInt_t uPlasticIndex = 0; uPlasticIndex < NB_PLASTICS; uPlasticIndex++ )
00046       fPlasticsInputEvent[uPlasticIndex] = 0;
00047 
00048 #if defined(ROOTCONV_WITHHODO)
00049    fRocPar = (TRocParam*) GetParameter("RocPar");
00050    cout << "ROCPAR = " << fRocPar << endl;
00051    
00052    if (fRocPar->numRocs > 0) fNumRocs = (UInt_t) fRocPar->numRocs;
00053 #endif
00054 
00055 
00056    fRootConvPar = (TRootConverterParam*) MakeParameter("RootConvPar", "TRootConverterParam");
00057    cout << "RootConvPar = " << fRootConvPar << endl;
00058 
00059    fParAnalysis = (TGsiAug12Param*) GetParameter("GsiAug12Par");
00060 
00061    if( kTRUE == fParAnalysis->bWithGet4 )
00062    {
00063       fGet4v1Par = (TGet4v1Param*) GetParameter("Get4v1Par");
00064       if( 0 == fGet4v1Par )
00065          fGet4v1Par = (TGet4v1Param*) MakeParameter("Get4v1Par", "TGet4v1Param");
00066    } // if( kTRUE == fParAnalysis->bWithGet4 )
00067 
00068    // Initialize detector parameter pointers to 0
00069    for( UInt_t uRpcIndex = 0; uRpcIndex < NB_RPC; uRpcIndex++ )
00070       fParRpc[uRpcIndex] = 0;
00071    for( UInt_t uPlasticIndex = 0; uPlasticIndex < NB_PLASTICS; uPlasticIndex++ )
00072       fParPlastics[uPlasticIndex] = 0;
00073 
00074    // ROC general variables
00075    uNbEvents = 0;
00076    
00077 #ifdef ROOTCONV_WITHHODO
00078    if(1 == fRootConvPar->uHodoDebugHisto)
00079    {
00080       TString path = GetName();
00081       path += "/";
00082       path += GetName();
00083 
00084       // Booking histograms
00085       hNbClustersPerEventHodoscope = MakeTH1('I', path+"_NbClustersPerEventHodoscope","Nb hosdoscope clusters per event",
00086             16,-0.5,15.5);
00087 
00088       hHitXvsMilliSecondsInSpill = MakeTH2('I', path+"_HitPosXVsTimeMilSecInSpill",
00089             "Hodoscope hit position versus time in Spill; Time in spill [ms]; X [mm]; Counts [mm]",
00090             8000,-50, 79950, 32,-14.5,15.5 );
00091       hHitYvsMilliSecondsInSpill = MakeTH2('I', path+"_HitPosYVsTimeMilSecInSpill",
00092             "Hodoscope hit position versus time in Spill; Time in spill [ms]; Y [mm]; Counts [mm]",
00093             8000,-50, 79950, 32,-14.5,15.5 );
00094       // No MakeTH3 function in go4, so do same operations by hand
00095       // => Need to check if loaded from autosave and create by ourselves
00096       path = GetName();
00097       path += "/";
00098       TString sName = GetName();
00099       hHit2DvsSeconds        = (TH3*)GetHistogram( path+ sName +"_HitPosVsTimeSec" );
00100       if( 0 == hHit2DvsSeconds )
00101       {
00102          hHit2DvsSeconds        = new TH3I( sName +"_HitPosVsTimeSec",
00103                                  "Hodoscope hit position versus time; Time [s]; X [mm]; Y [mm]",
00104                                  1000,-0.5, 1999.5, 32,-14.5,15.5, 32,-14.5,15.5 );
00105          AddHistogram( hHit2DvsSeconds, path );
00106       }
00107       hHit2DvsSecondsInSpill        = (TH3*)GetHistogram( path + sName +"_HitPosVsTimeSecInSpill" );
00108       if( 0 == hHit2DvsSecondsInSpill )
00109       {
00110          hHit2DvsSecondsInSpill = new TH3I( sName +"_HitPosVsTimeSecInSpill",
00111                                  "Hodoscope hit position versus time in Spill; Time in spill [s]; X [mm]; Y [mm]",
00112                                  80,-0.5, 79.5, 32,-14.5,15.5, 32,-14.5,15.5 );
00113          AddHistogram( hHit2DvsSecondsInSpill, path );
00114       }
00115       hHit2DvsMilliSecondsInSpill        = (TH3*)GetHistogram( path + sName +"_HitPosVsTimeMilSecInSpill" );
00116       if( 0 == hHit2DvsMilliSecondsInSpill )
00117       {
00118          hHit2DvsMilliSecondsInSpill = new TH3I( sName +"_HitPosVsTimeMilSecInSpill",
00119                                  "Hodoscope hit position versus time in Spill; Time in spill [ms]; X [mm]; Y [mm]",
00120                                  8000,-50, 79950, 32,-14.5,15.5, 32,-14.5,15.5 );
00121          AddHistogram( hHit2DvsMilliSecondsInSpill, path );
00122       }
00123       // For hodoscope hits map
00124       uFirstMbsTime = 0;
00125       uSpillStartMbsTime = 0;
00126       uLastMbsTime = 0;
00127 
00128       uFirstMbsTimeMs = 0;
00129       uSpillStartMbsTimeMs = 0;
00130    } // if(1 == fRootConvPar->uHodoDebugHisto)
00131 #endif
00132 
00133    //~ TString path = GetName();
00134    //~ path += "/";
00135    //~ path += GetName();
00136    if( 1 == fRootConvPar->uSlowControlInTree && kTRUE == fParAnalysis->bWithEpics )
00137    {
00138       hTimeEpicsUpdates = MakeTH1('I', "RootConv/RC_TimeEpicsUpdate","Timing of epics updates; Time [s]",
00139             7200, 0, 7200);
00140    } // if( 1 == fRootConvPar->uSlowControlInTree && kTRUE == fParAnalysis->bWithEpics )
00141    uEpicsTimeOrigin = 0;
00142       
00143    //printf("RPC Histograms created \n");
00144    fflush ( stdout);
00145 }
00146 
00147 TRootConverterProc::~TRootConverterProc()
00148 {
00149 //   TGo4Log::Info("Proc  %p", this);
00150    if( (1 == fRootConvPar->uCleanOuputEnable || 1 == fRootConvPar->uRootDisplay)
00151          && 0 != cleanTree )
00152       {
00153           if( 1 == fRootConvPar->uRootDisplay )
00154              TGo4Analysis::Instance()->RemoveTree(cleanTree);
00155           if( 1 == fRootConvPar->uCleanOuputEnable )
00156           {
00157              fRootOut->Write("",TObject::kOverwrite);
00158              //~ gDirectory->Cd(sOutputFilename);
00159 //~ 
00160              //~ cleanTree->SetDirectory(gDirectory);
00161              //~ cleanTree->Write(0,TObject::kOverwrite); // to avoid double trees in file: cf http://root.cern.ch/root/roottalk/roottalk01/0842.html
00162              //~ gDirectory->Cd(oldDir->GetPath());
00163              fRootOut->Close();
00164           } // if( 1 == fRootConvPar->uCleanOuputEnable )
00165 
00166           if( 0 == fRootConvPar->uCleanOuputEnable )
00167              delete cleanTree;
00168 
00169           if( 1 == fRootConvPar->uSlowControlInTree && kTRUE == fParAnalysis->bWithEpics )
00170           {
00171              vdPositiveHvI.clear();
00172              vdPositiveHvU.clear();
00173              vdNegativeHvI.clear();
00174              vdNegativeHvU.clear();
00175           }
00176 
00177 //          if( 1 == fRootConvPar->uCleanOuputEnable )
00178 //             delete fRootOut;
00179       }
00180 
00181    cout << "**** TRootConverterProc: Delete instance " << endl;
00182 }
00183 //***********************************************************
00184 
00185 void TRootConverterProc::InitEvent(TGo4EventElement* outevnt)
00186 {
00187    // first assign input event:
00188    // since input event object is never discarded within processor lifetime,
00189    // we just search for subevent by name once to speed up processing
00190 #ifdef ROOTCONV_WITHHODO
00191    if( 0==fHodoInputEvent && 1 == fRootConvPar->uHodoInputInTree )
00192    {
00193       TCBMBeamtimeEvent* btevent=dynamic_cast<TCBMBeamtimeEvent*>(GetInputEvent("Detector"));
00194       if(btevent)
00195       {
00196          fHodoInputEvent=dynamic_cast<TFiberHodEvent*>(btevent->GetSubEvent("Hodo1"));
00197       }
00198       if( 0==fHodoInputEvent ) {
00199          GO4_STOP_ANALYSIS_MESSAGE("**** TRootConverterProc: Fatal error: input event has no TFiberHodEvent!!! STOP GO4");
00200       }
00201    }
00202 #endif
00203 
00204    // Optional: if triggered mode and tree, look for the VME crate data
00205    // since input event object is never discarded within processor lifetime,
00206    // we just search for subevent by name once to speed up processing
00207 #if defined(ROOTCONV_WITHHODO)
00208    if( kFALSE == fRocPar->noTrigger && ( 1 == fRootConvPar->uCleanOuputEnable || 1 == fRootConvPar->uRootDisplay) )
00209 #else
00210    if( 1 == fRootConvPar->uCleanOuputEnable || 1 == fRootConvPar->uRootDisplay )
00211 #endif
00212    {
00213       TCBMBeamtimeEvent* btevent=dynamic_cast<TCBMBeamtimeEvent*>(GetOutputEvent("Unpack"));
00214       if(btevent)
00215       {
00216          if( 1 == fRootConvPar->uGet4InTree && fGet4v1InputEvent==0 && kTRUE == fParAnalysis->bWithGet4 )
00217          {
00218             fGet4v1InputEvent=dynamic_cast<TGet4v1Event*>(btevent->GetSubEvent("ROCGET4V10"));
00219 
00220             if(fGet4v1InputEvent==0) {
00221                GO4_STOP_ANALYSIS_MESSAGE("**** TRootConverterProc: Fatal error: Unpack Output event is/has not a TGet4v1Event!!! STOP GO4");
00222             }
00223          } // if( 1 == fRootConvPar->uGet4InTree && fGet4v1InputEvent==0 && kTRUE == fParAnalysis->bWithGet4 )
00224          if(( (1 == fRootConvPar->uCaenInTree && kTRUE == fParAnalysis->bWithMbs ) || 1 == fRootConvPar->uTriglogInputInTree)
00225              && fCrateInputEvent==0)
00226          {
00227             fCrateInputEvent=dynamic_cast<TMbsCrateEvent*>(btevent->GetSubEvent("MBSCRATE"));
00228 
00229             if(fCrateInputEvent==0) {
00230                GO4_STOP_ANALYSIS_MESSAGE("**** TRootConverterProc: Fatal error: Unpack Output  event is/has not a TMbsCrateEvent!!! STOP GO4");
00231             }
00232          } // if( ( (1 == fRootConvPar->uCaenInTree && kTRUE == fParAnalysis->bWithMbs ) || 1 == fRootConvPar->uTriglogInputInTree) && fCrateInputEvent==0)
00233          if( 0 == fTriglogInputEvent && kTRUE == fParAnalysis->bWithTriglog )
00234          {
00235                fTriglogInputEvent=dynamic_cast<TTriglogEvent*>(btevent->GetSubEvent("TRIGLOG"));
00236 
00237             if(fTriglogInputEvent==0) {
00238                GO4_STOP_ANALYSIS_MESSAGE("**** TRootConverterProc: Fatal error: Unpack Output  event is/has not a TTriglogEvent!!! STOP GO4");
00239             }
00240          } // if( 0 == fTriglogInputEvent && kTRUE == fParAnalysis->bWithTriglog )
00241          if( 0 == fEpicsInputEvent && 1 == fRootConvPar->uSlowControlInTree && kTRUE == fParAnalysis->bWithEpics )
00242          {
00243                fEpicsInputEvent=dynamic_cast<TEpicsEvent*>(btevent->GetSubEvent("EPICS"));
00244 
00245             if(fEpicsInputEvent==0) {
00246                GO4_STOP_ANALYSIS_MESSAGE("**** TRootConverterProc: Fatal error: Unpack Output  event is/has not a TEpicsEvent!!! STOP GO4");
00247             }
00248          } // if( 0 == fEpicsInputEvent && 1 == fRootConvPar->uSlowControlInTree && kTRUE == fParAnalysis->bWithEpics )
00249       } // if(btevent)
00250          else if( ( 1 == fRootConvPar->uCaenInTree && kTRUE == fParAnalysis->bWithMbs ) ||
00251                    ( 1 == fRootConvPar->uTriglogInputInTree && kTRUE == fParAnalysis->bWithTriglog ) ||
00252                    ( 1 == fRootConvPar->uSlowControlInTree && kTRUE == fParAnalysis->bWithEpics ) )
00253             GO4_STOP_ANALYSIS_MESSAGE("**** TRootConverterProc: Fatal error: Unpack Output event not found!!! STOP GO4");
00254 
00255       btevent=dynamic_cast<TCBMBeamtimeEvent*>(GetOutputEvent("Calibration"));
00256       if(btevent)
00257       {
00258          if( 0 ==fVftxInputEvent && 1 == fRootConvPar->uVftxInTree && kTRUE == fParAnalysis->bWithVftxCalib )
00259          {
00260                fVftxInputEvent=dynamic_cast<TVftxEvent*>(btevent->GetSubEvent("VFTX"));
00261 
00262             if(fVftxInputEvent==0) {
00263                GO4_STOP_ANALYSIS_MESSAGE("**** TRootConverterProc: Fatal error: Calibration Output event is/has not a TVftxEvent!!! STOP GO4");
00264             }
00265          } // if( 0 == fVftxInputEvent && 1 == fRootConvPar->uVftxInTree && kTRUE == fParAnalysis->bWithVftxCalib )
00266       } // if(btevent)
00267          else if( 1 == fRootConvPar->uVftxInTree && kTRUE == fParAnalysis->bWithVftxCalib )
00268             GO4_STOP_ANALYSIS_MESSAGE("**** TRootConverterProc: Fatal error: Calibration Output event not found!!! STOP GO4");
00269 
00270       // Param need to be done!!!!
00271       btevent=dynamic_cast<TCBMBeamtimeEvent*>(GetOutputEvent("Detector"));
00272       if(btevent)
00273       {
00274          if( 1 == fRootConvPar->uRpcInTree )
00275             for( UInt_t uRpcIndex = 0; uRpcIndex < fParAnalysis->uNbRpc; uRpcIndex++ )
00276             {
00277                if( 1 == fRootConvPar->uRpcEnabled[uRpcIndex] )
00278                {
00279                   if( 0 == fParRpc[uRpcIndex])
00280                   {
00281                      fParRpc[uRpcIndex] = (TRpcParam*) GetParameter( Form("RpcPar_%02d", uRpcIndex));
00282                      if( 0 == fParRpc[uRpcIndex])
00283                      {
00284                         fRootConvPar->uRpcEnabled[uRpcIndex] = 0;
00285                         cout<<"Parameter for Rpc"<<uRpcIndex<<" not found => Disabled in Event output"<<endl;
00286                         continue; // Jump this RPC as disabled anyway
00287                      } // if( 0 == fParRpc[uRpcIndex])
00288                      if( 0 == fParRpc[uRpcIndex]->uNbStrips )
00289                      {
00290                         fRootConvPar->uRpcEnabled[uRpcIndex] = 0;
00291                         cout<<"Rpc"<<uRpcIndex<<" empty (uNbStrips = 0) => Disabled in Event output"<<endl;
00292                         continue; // Jump this RPC as disabled anyway
00293                      } // if( 0 == fParRpc[uRpcIndex]->uNbStrips )
00294                   } // if( 0 == fParRpc[uRpcIndex])
00295 
00296                   if( 0 == fRpcInputEvent[uRpcIndex] )
00297                   {
00298                      fRpcInputEvent[uRpcIndex]  =dynamic_cast<TRpcEvent*>( btevent->GetSubEvent(
00299                            Form("RPC_%02d", uRpcIndex) ) );
00300 
00301                      if( fRpcInputEvent[uRpcIndex] ==0) {
00302                         GO4_STOP_ANALYSIS_MESSAGE("**** TRootConverterProc: Fatal error: Detector Output event is/has not a TRpcEvent for Rpc %02d!!! STOP GO4",
00303                               uRpcIndex);
00304                      }
00305                   } // if(  0 == fRpcInputEvent[uRpcIndex] )
00306                } // if( 1 == fRootConvPar->uRpcEnabled[uRpcIndex] )
00307             } // for( UInt_t uRpcIndex = 0; uRpcIndex < fParAnalysis->uNbRpc; uRpcIndex++ )
00308 
00309          /* Plastics */
00310          if( ( 1 == fRootConvPar->uPlasticsInTree  ) )
00311             for( UInt_t uPlasticIndex = 0; uPlasticIndex < fParAnalysis->uNbPlastics; uPlasticIndex++ )
00312             {
00313                if( 1 == fRootConvPar->uPlasticsEnabled[uPlasticIndex] )
00314                {
00315                   if( 0 == fParPlastics[uPlasticIndex] )
00316                   {
00317                      fParPlastics[uPlasticIndex] = (TPlasticsParam*) GetParameter( Form("PlasticsPar_%02d", uPlasticIndex));
00318                      if( 0 == fParPlastics[uPlasticIndex])
00319                      {
00320                         fRootConvPar->uPlasticsEnabled[uPlasticIndex] = 0;
00321                         cout<<"Parameter for Plastics"<<uPlasticIndex<<" not found => Disabled in Event output"<<endl;
00322                         continue; // Jump this PLASTICS as disabled anyway
00323                      } // if( 0 == fParPlastics[uPlasticIndex])
00324                      if( 0 == fParPlastics[uPlasticIndex]->uNbPlastics )
00325                      {
00326                         fRootConvPar->uPlasticsEnabled[uPlasticIndex] = 0;
00327                         cout<<"Plastics"<<uPlasticIndex<<" empty (uNbPlastics = 0) => Disabled in Event output"<<endl;
00328                         continue; // Jump this PLASTICS as disabled anyway
00329                      } // if( 0 == fParPlastics[uPlasticIndex]->uNbPlastics )
00330                   } // if( 0 == fParPlastics[uPlasticIndex] )
00331                   if( 0 == fPlasticsInputEvent[uPlasticIndex] )
00332                   {
00333                      fPlasticsInputEvent[uPlasticIndex] =dynamic_cast<TPlasticsEvent*>(btevent->GetSubEvent(
00334                            Form("PLASTICS_%02d", uPlasticIndex) ) );
00335 
00336                      if( fPlasticsInputEvent[uPlasticIndex]==0) {
00337                         GO4_STOP_ANALYSIS_MESSAGE("**** TRootConverterProc: Fatal error: Detector Output event is/has not a TPlasticsEvent for Plastics %02d!!! STOP GO4",
00338                               uPlasticIndex);
00339                      }
00340                   } // if( 0 == fPlasticsInputEvent[uPlasticIndex] )
00341                } // if( ( 1 == fRootConvPar->uPlasticsEnabled[uPlasticIndex] && 0 == fPlasticsInputEvent[uPlasticIndex] ) )
00342             } // for( UInt_t uPlasticIndex = 0; uPlasticIndex < fParAnalysis->uNbPlastics; uPlasticIndex++ )
00343 
00344          /* Pad Rpc */
00345          /*
00346          if( ( 1 == fRootConvPar->uPadRpcInTree && fPadRpcInputEvent ==0 ) )
00347          {
00348             fPadRpcInputEvent =dynamic_cast<TPadRpcEvent*>(btevent->GetSubEvent("PADRPC"));
00349 
00350             if( fPadRpcInputEvent==0) {
00351                GO4_STOP_ANALYSIS_MESSAGE("**** TRootConverterProc: Fatal error: Detector Output event is/has not a TPadRpcEvent for Pad Rpc!!! STOP GO4");
00352             }
00353          } // if( ( 1 == fRootConvPar->uPadRpcInTree && fPadRpcInputEvent ==0 ) )
00354 */
00355          if( 0 == fScalOrMu1InputEvent && 1 == fRootConvPar->uScalOrMuInTree && kTRUE == fParAnalysis->bWithScalersRate )
00356          {
00357             fScalOrMu1InputEvent=dynamic_cast<TScalersEvent*>(btevent->GetSubEvent("SCALERS"));
00358 
00359             if(fScalOrMu1InputEvent==0) {
00360                GO4_STOP_ANALYSIS_MESSAGE("**** TRootConverterProc: Fatal error: Detector Output event is/has not a TScalersEvent!!! STOP GO4");
00361             }
00362          } // if( 0 == fScalOrMu1InputEvent && 1 == fRootConvPar->uScalOrMuInTree && kTRUE == fParAnalysis->bWithScalersRate )
00363          if( 0 == fScalOrMu2InputEvent && 1 == fRootConvPar->uScalOrMu2InTree )
00364          {
00365             fScalOrMu2InputEvent=dynamic_cast<TScalersEvent*>(btevent->GetSubEvent("SCALERS2"));
00366 
00367             if(fScalOrMu2InputEvent==0) {
00368                GO4_STOP_ANALYSIS_MESSAGE("**** TRootConverterProc: Fatal error: Detector Output event is/has not a TScalersEvent!!! STOP GO4");
00369             }
00370          } // if( 0 == fScalOrMu2InputEvent && 1 == fRootConvPar->uScalOrMu2InTree )
00371       } // if(btevent)
00372          else if( 1 == fRootConvPar->uRpcInTree ||
00373                    1 == fRootConvPar->uPlasticsInTree ||
00374                    1 == fRootConvPar->uPadRpcInTree ||
00375                    1 == fRootConvPar->uScalOrMuInTree ||
00376                    1 == fRootConvPar->uScalOrMu2InTree )
00377             GO4_STOP_ANALYSIS_MESSAGE("**** TRootConverterProc: Fatal error: Detector Output event not found!!! STOP GO4");
00378 
00379       if( 1 == fRootConvPar->uMatchingInTree && kTRUE == fParAnalysis->bWithMatching)
00380       {
00381          if(fMatchingInputEvent==0)
00382          {
00383             TCBMBeamtimeEvent* btevent=dynamic_cast<TCBMBeamtimeEvent*>(GetInputEvent());
00384             if(btevent)
00385             {
00386                fMatchingInputEvent=dynamic_cast<TMatchingEvent*>(btevent->GetSubEvent("MATCHING"));
00387             }
00388 
00389             if(fMatchingInputEvent==0) {
00390                GO4_STOP_ANALYSIS_MESSAGE("**** TRootConverterProc: Fatal error: input event is/has not a TMatchingEvent!!! STOP GO4");
00391             }
00392          } // if(fMatchingInputEvent==0)
00393       } // if( 1 == fRootConvPar->uMatchingInTree && kTRUE == fParAnalysis->bWithMatching )
00394 
00395    } // if( kFALSE == fRocPar->noTrigger && ( 1 == fRootConvPar->uCleanOuputEnable || 1 == fRootConvPar->uRootDisplay) )
00396       else if( 1 == fRootConvPar->uSlowControlInTree && kTRUE == fParAnalysis->bWithEpics )
00397       {
00398 //         TCBMBeamtimeEvent* btevent=dynamic_cast<TCBMBeamtimeEvent*>(GetInputEvent("Calibration"));
00399          TCBMBeamtimeEvent* btevent=dynamic_cast<TCBMBeamtimeEvent*>(GetOutputEvent("Unpack"));
00400          if(fEpicsInputEvent==0)
00401          {
00402             if(btevent)
00403             {
00404                fEpicsInputEvent=dynamic_cast<TEpicsEvent*>(btevent->GetSubEvent("EPICS"));
00405             }
00406 
00407             if(fEpicsInputEvent==0) {
00408                GO4_STOP_ANALYSIS_MESSAGE("**** TRootConverterProc: Fatal error: input event is/has not a TEpicsEvent!!! STOP GO4");
00409             }
00410          } // if(fEpicsInputEvent==0)
00411       } //  else if( 1 == fRootConvPar->uSlowControlInTree && kTRUE == fParAnalysis->bWithEpics  )
00412 
00413    // then assign output event
00414    // since output event object is never discarded within processor lifetime,
00415    // we just search for subevent by name once to speed up processing
00416    if(fOutputEvent==0)
00417    {
00418       TCBMBeamtimeEvent* btevent=dynamic_cast<TCBMBeamtimeEvent*>(outevnt);
00419       if(btevent)
00420       {
00421          fOutputEvent=dynamic_cast<TRootConverterEvent*>(btevent->GetSubEvent("ROOTCONV"));
00422       }
00423       else
00424       {
00425 
00426             fOutputEvent= dynamic_cast<TRootConverterEvent*>(outevnt);
00427       }
00428       if(fOutputEvent==0) {
00429       GO4_STOP_ANALYSIS_MESSAGE("**** TRootConverterProc: Fatal error: output event is not a TRootConverterEvent!!! STOP GO4");
00430       }
00431 
00432    }
00433 
00434    // Prepare root tree and tree output file
00435    if( 1 == fRootConvPar->uCleanOuputEnable || 1 == fRootConvPar->uRootDisplay)
00436    {
00437       if( 0 == cleanTree)
00438       {
00439          TGo4Log::Info("**** TRootConverter: Create tree ");
00440 
00441          if( 1 == fRootConvPar->uCleanOuputEnable )
00442          {
00443             oldDir = gDirectory;
00444 
00445             sOutputFilename = fRootConvPar->sOutputFilename;
00446             fRootOut= new TFile(sOutputFilename, "RECREATE", "TTree file from GET4 and CAEN v1290", 9);
00447             sOutputFilename += ":/";
00448             if (fRootOut->IsZombie()) {
00449                cout << "Error opening file for TTree output in TRootConverter" << endl;
00450             }
00451 
00452             gDirectory->Cd(sOutputFilename);
00453          }
00454 
00455          if( 0 == TGo4Analysis::Instance()->GetTree( "GsiAug12" ) )
00456          {
00457             cleanTree = new TTree("GsiAug12", "GSI August 2012 data");
00458             TGo4Log::Info("Output Tree created in %s", gDirectory->GetPath());
00459          } // if( 0 == TGo4Analysis::Instance()->GetTree( "GsiAug12" ) )
00460             else
00461             {
00462                cleanTree = TGo4Analysis::Instance()->GetTree( "GsiAug12" );
00463                TGo4Log::Info("Output Tree recovered from Go4");
00464             } // else of if( 0 == TGo4Analysis::Instance()->GetTree( "GsiAug12" ) )
00465 
00466          // To prevent having multiple trees when opening the file with Go4 -> Not right solution
00467 //         cleanTree->SetAutoFlush(0);
00468 
00469          // Data from CAEN v1290 & Lecroy QDC VME boards (triggered)
00470 #if defined(ROOTCONV_WITHHODO)
00471          if( kFALSE == fRocPar->noTrigger )
00472 #endif
00473          {
00474             if( -1 != fRootConvPar->iReferenceTdc && -1 != fRootConvPar->iReferenceChannel1 && 1 == fRootConvPar->uCaenInTree
00475                   && kTRUE == fParAnalysis->bWithMbs )
00476             {
00477                cleanTree->Branch("CaenRef1_Leading",
00478                                  &((fCrateInputEvent->fMtdc[fRootConvPar->iReferenceTdc]).lead[fRootConvPar->iReferenceChannel1]),
00479                                  "CaenRef1_Leading/I" );
00480                cleanTree->Branch("CaenRef1_Trailing",
00481                                  &((fCrateInputEvent->fMtdc[fRootConvPar->iReferenceTdc]).trail[fRootConvPar->iReferenceChannel1]),
00482                                  "CaenRef1_Trailing/I" );
00483             } // if( -1 != fRootConvPar->iReferenceTdc && -1 != fRootConvPar->iReferenceChannel && 1 == fRootConvPar->uCaenInTree && kTRUE == fParAnalysis->bWithMbs )
00484             if( -1 != fRootConvPar->iReferenceTdc && -1 != fRootConvPar->iReferenceChannel2 && 1 == fRootConvPar->uCaenInTree
00485                   && kTRUE == fParAnalysis->bWithMbs )
00486             {
00487                cleanTree->Branch("CaenRef2_Leading",
00488                                  &((fCrateInputEvent->fMtdc[fRootConvPar->iReferenceTdc]).lead[fRootConvPar->iReferenceChannel2]),
00489                                  "CaenRef2_Leading/I" );
00490                cleanTree->Branch("CaenRef2_Trailing",
00491                                  &((fCrateInputEvent->fMtdc[fRootConvPar->iReferenceTdc]).trail[fRootConvPar->iReferenceChannel2]),
00492                                  "CaenRef2_Trailing/I" );
00493             } // if( -1 != fRootConvPar->iReferenceTdc && -1 != fRootConvPar->iReferenceChannel && 1 == fRootConvPar->uCaenInTree && kTRUE == fParAnalysis->bWithMbs )
00494             
00495             if( 1 == fRootConvPar->uCaenMode )
00496             {
00497                for( Int_t iCaenBoard = 0; iCaenBoard<MAX_1290; iCaenBoard ++)
00498                   if( 1 == fRootConvPar->uGeneralCaenTdcEnabled[iCaenBoard])
00499                   {
00500                      cleanTree->Branch(Form("Caen%d_TriggerTime", iCaenBoard),  
00501                                        &( (fCrateInputEvent->fMtdc[iCaenBoard]).extended_trigger_time ),
00502                                        Form("Caen%d_TriggerTime/I", iCaenBoard )  );
00503                                        
00504                      // The multiple hits array for CAEN v1290 now also include first hit
00505                      // => either add to tree the first hit or add to tree only the multiple hit array
00506                      if( 1 == fRootConvPar->uCaenMulti )
00507                      {
00508                cleanTree->Branch(Form("Caen%d_Leading_NbHit", iCaenBoard), 
00509                                  (fCrateInputEvent->fMtdc[iCaenBoard]).hit_lead,
00510                                  Form("Caen%d_Leading_NbHit[%u]/I", iCaenBoard, T1290Data::NumChan ) );
00511                cleanTree->Branch(Form("Caen%d_Trailing_NbHit", iCaenBoard), 
00512                                  (fCrateInputEvent->fMtdc[iCaenBoard]).hit_trail,
00513                                  Form("Caen%d_Trailing_NbHit[%u]/I", iCaenBoard, T1290Data::NumChan ) );
00514                cleanTree->Branch(Form("Caen%d_Leading_multi", iCaenBoard),  
00515                                  (fCrateInputEvent->fMtdc[iCaenBoard]).lead_multi,
00516                                  Form("Caen%d_Leading_multi[%u][%u]/I", iCaenBoard, T1290Data::NumChan, T1290Data::MaxHits )  );
00517                cleanTree->Branch(Form("Caen%d_Trailing_multi", iCaenBoard), 
00518                                  (fCrateInputEvent->fMtdc[iCaenBoard]).trail_multi,
00519                                  Form("Caen%d_Trailing_multi[%u][%u]/I", iCaenBoard, T1290Data::NumChan, T1290Data::MaxHits ) );
00520                      } // if( 1 == fRootConvPar->uCaenMulti )
00521                         else
00522                         {
00523                      cleanTree->Branch(Form("Caen%d_Leading", iCaenBoard),  
00524                                        (fCrateInputEvent->fMtdc[iCaenBoard]).lead,
00525                                        Form("Caen%d_Leading[%u]/I", iCaenBoard, T1290Data::NumChan )  );
00526                      cleanTree->Branch(Form("Caen%d_Trailing", iCaenBoard), 
00527                                        (fCrateInputEvent->fMtdc[iCaenBoard]).trail,
00528                                        Form("Caen%d_Trailing[%u]/I", iCaenBoard, T1290Data::NumChan ) );
00529                         } // else of if( 1 == fRootConvPar->uCaenMulti )
00530                   } // if( 1 == fRootConvPar->uGeneralCaenTdcEnabled[iCaenBoard])
00531             } // if( 1 == fRootConvPar->uCaenMode )
00532             
00533             if( -1 != fRootConvPar->iPmtTdc && 0 == fRootConvPar->uCaenMode)
00534             {
00535                cleanTree->Branch("PmtTdc_Leading",  (fCrateInputEvent->fMtdc[fRootConvPar->iPmtTdc]).lead,
00536                                  Form("PmtTdc_Leading[%u]/I", T1290Data::NumChan )  );
00537                cleanTree->Branch("PmtTdc_Trailing", (fCrateInputEvent->fMtdc[fRootConvPar->iPmtTdc]).trail,
00538                                  Form("PmtTdc_Trailing[%u]/I", T1290Data::NumChan ) );
00539                cleanTree->Branch("PmtTdc_Leading_NbHit", (fCrateInputEvent->fMtdc[fRootConvPar->iPmtTdc]).hit_lead,
00540                                     Form("PmtTdc_Leading_NbHit[%u]/I", T1290Data::NumChan ) );
00541                cleanTree->Branch("PmtTdc_Trailing_NbHit", (fCrateInputEvent->fMtdc[fRootConvPar->iPmtTdc]).hit_trail,
00542                                  Form("PmtTdc_Trailing_NbHit[%u]/I", T1290Data::NumChan ) );
00543                cleanTree->Branch("PmtTdc_Leading_multi",  (fCrateInputEvent->fMtdc[fRootConvPar->iPmtTdc]).lead_multi,
00544                                  Form("PmtTdc_Leading_multi[%u][%u]/I", T1290Data::NumChan, T1290Data::MaxHits )  );
00545                cleanTree->Branch("PmtTdc_Trailing_multi", (fCrateInputEvent->fMtdc[fRootConvPar->iPmtTdc]).trail_multi,
00546                                  Form("PmtTdc_Trailing_multi[%u][%u]/I", T1290Data::NumChan, T1290Data::MaxHits ) );
00547             } // if( -1 != fRootConvPar->iPmtTdc )
00548             if( -1 != fRootConvPar->iRpcTdcLeading && -1 != fRootConvPar->iRpcTdcTrailing && 0 == fRootConvPar->uCaenMode )
00549             {
00550                cleanTree->Branch("CaenRpc_Leading",  (fCrateInputEvent->fMtdc[fRootConvPar->iRpcTdcLeading]).lead,
00551                                  Form("CaenRpc_Leading[%u]/I", T1290Data::NumChan )  );
00552                cleanTree->Branch("CaenRpc_Trailing", (fCrateInputEvent->fMtdc[fRootConvPar->iRpcTdcTrailing]).trail,
00553                                  Form("CaenRpc_Trailing[%u]/I", T1290Data::NumChan ) );
00554                cleanTree->Branch("CaenRpc_Leading_NbHit", (fCrateInputEvent->fMtdc[fRootConvPar->iRpcTdcLeading]).hit_lead,
00555                                     Form("CaenRpc_Leading_NbHit[%u]/I", T1290Data::NumChan ) );
00556                cleanTree->Branch("CaenRpc_Trailing_NbHit", (fCrateInputEvent->fMtdc[fRootConvPar->iRpcTdcTrailing]).hit_trail,
00557                                  Form("CaenRpc_Trailing_NbHit[%u]/I", T1290Data::NumChan ) );
00558                cleanTree->Branch("CaenRpc_Leading_multi",  (fCrateInputEvent->fMtdc[fRootConvPar->iRpcTdcLeading]).lead_multi,
00559                                  Form("CaenRpc_Leading_multi[%u][%u]/I", T1290Data::NumChan, T1290Data::MaxHits )  );
00560                cleanTree->Branch("CaenRpc_Trailing_multi", (fCrateInputEvent->fMtdc[fRootConvPar->iRpcTdcTrailing]).trail_multi,
00561                                  Form("CaenRpc_Trailing_multi[%u][%u]/I", T1290Data::NumChan, T1290Data::MaxHits ) );
00562             } // if( -1 != fRootConvPar->iRpcTdcLeading && -1 != fRootConvPar->iRpcTdcTrailing && 0 == fRootConvPar->uCaenMode )
00563             
00564             if( -1 != fRootConvPar->iPmtQdc )
00565             {
00566                cleanTree->Branch("PmtQdc", fCrateInputEvent->fData1182[fRootConvPar->iPmtQdc], Form("PmtQdc[%u]/s", NUM_1182_CH ) );
00567             } // if( -1 != fRootConvPar->iPmtQdc )
00568 
00569             if( 1 == fRootConvPar->uTriglogInputInTree && kTRUE == fParAnalysis->bWithTriglog )
00570             {
00571                cleanTree->Branch("TriglogSyncNb",  &(fTriglogInputEvent->fVulomSyncNumber),
00572                                  "TriglogSyncNb/i"  );
00573                cleanTree->Branch("TriglogPattern",  &(fTriglogInputEvent->fVulomTriggerPattern),
00574                                  "TriglogPattern/i"  );
00575                cleanTree->Branch("TriglogInputPattern",  &(fCrateInputEvent->fTriglogInputPattern),
00576                                  "TriglogInputPattern/i"  );
00577                cleanTree->Branch("TriglogTimeSec",  &(fTriglogInputEvent->fMbsTimeSecs),
00578                                  "TriglogTimeSec/i"  );
00579                cleanTree->Branch("TriglogTimeMilsec",  &(fTriglogInputEvent->fMbsTimeMillisec),
00580                                  "TriglogTimeMilsec/i"  );
00581                cleanTree->Branch("TriglogScalers1",  (fTriglogInputEvent->fVulomScaler[0]),
00582                                  Form("TriglogScalers1[%u]/i", N_SCALERS_CH )  );
00583                cleanTree->Branch("TriglogScalers2",  (fTriglogInputEvent->fVulomScaler[1]),
00584                                  Form("TriglogScalers2[%u]/i", N_SCALERS_CH )  );
00585                cleanTree->Branch("TriglogScalers3",  (fTriglogInputEvent->fVulomScaler[2]),
00586                                  Form("TriglogScalers3[%u]/i", N_SCALERS_CH )  );
00587             } // if( 1 == fRootConvPar->uTriglogInputInTree && kTRUE == fParAnalysis->bWithTriglog )
00588             if( 1 == fRootConvPar->uGet4InTree && kTRUE == fParAnalysis->bWithGet4 )
00589             {
00590                if( 1 == fRootConvPar->uMultiEventsAllowed)
00591                {
00592                   cleanTree->Branch("Get4v1Event",      "TGet4v1Event", &fGet4v1InputEvent);
00593                } // if( 1 == fRootConvPar->uMultiEventsAllowed)
00594                   else
00595                   {
00596                      for( Int_t iGet4Board = 0; iGet4Board<MAX_GET4; iGet4Board ++)
00597                         if( 1 == fRootConvPar->uGet4Enabled[iGet4Board])
00598                         {
00599                            // No multi event support !!!!!
00600                            /*
00601                            cleanTree->Branch( Form("Get4%d", iGet4Board), "Get4v1Tdc",
00602                                  &((fGet4v1InputEvent->fEvents[0]).fGet4Boards[iGet4Board] ));
00603                                  */
00604                            cleanTree->Branch( Form("Get4_%d", iGet4Board), "Get4v1Tdc", &( fGet4Board[iGet4Board] ) );
00605                         }
00606                   } // else of if( 1 == fRootConvPar->uMultiEventsAllowed)
00607             }
00608             if( 1 == fRootConvPar->uVftxInTree && kTRUE == fParAnalysis->bWithVftxCalib )
00609             {
00610                for( Int_t iVftxBoard = 0; iVftxBoard<MAX_FPGA_TDC; iVftxBoard ++)
00611                   if( 1 == fRootConvPar->uVftxEnabled[iVftxBoard])
00612                   {
00613                      if( 1 == fRootConvPar->uVftxFullBoardData )
00614                      {
00615                         cleanTree->Branch( Form("Vftx%02dData", iVftxBoard), "TVftxBoardData",
00616                                              &(fVftxInputEvent->fVftxBoards[iVftxBoard]) );
00617                      }
00618                         else
00619                         {
00620                            TString sBrNameTrigg  = Form("Vftx%dTriggerTime", iVftxBoard);
00621                            TString sBrNameMulti  = Form("Vftx%dMultiplicity", iVftxBoard);
00622                            TString sBrNameFineT  = Form("Vftx%dFineTime", iVftxBoard);
00623                            TString sBrNameCoarT  = Form("Vftx%dCoarseTime", iVftxBoard);
00624                            TString sBrNameFutuB  = Form("Vftx%dFutureBit", iVftxBoard);
00625                            TString sBrNameTimeC  = Form("Vftx%dTimeCorr", iVftxBoard);
00626                            TString sBrNameFtCorr = Form("Vftx%dFineTimeCorr", iVftxBoard);
00627 
00628                cleanTree->Branch( sBrNameTrigg,  &((fVftxInputEvent->fVftxBoards[iVftxBoard]).iTriggerTime),
00629                                   sBrNameTrigg + "/I" );
00630                cleanTree->Branch( sBrNameMulti,  ((fVftxInputEvent->fVftxBoards[iVftxBoard]).iMultiplicity),
00631                                   sBrNameMulti + Form("[%u]/I", FPGA_TDC_NBCHAN )  );
00632                            if( 1 == fRootConvPar->uVftxFullDataMode )
00633                            {
00634                cleanTree->Branch( sBrNameFineT,  ((fVftxInputEvent->fVftxBoards[iVftxBoard]).iFineTime),
00635                                   sBrNameFineT + Form("[%u][%u]/I", FPGA_TDC_NBCHAN, TVftxBoardData::MaxMult )  );
00636                cleanTree->Branch( sBrNameCoarT,  ((fVftxInputEvent->fVftxBoards[iVftxBoard]).iCoarseTime),
00637                                   sBrNameCoarT + Form("[%u][%u]/I", FPGA_TDC_NBCHAN, TVftxBoardData::MaxMult )  );
00638                cleanTree->Branch( sBrNameFutuB,  ((fVftxInputEvent->fVftxBoards[iVftxBoard]).uFutureBit),
00639                                   sBrNameFutuB + Form("[%u][%u]/i", FPGA_TDC_NBCHAN, TVftxBoardData::MaxMult )  );
00640                cleanTree->Branch( sBrNameFtCorr,  ((fVftxInputEvent->fVftxBoards[iVftxBoard]).dFineTimeCorr),
00641                                   sBrNameFtCorr + Form("[%u][%u]/D", FPGA_TDC_NBCHAN, TVftxBoardData::MaxMult )  );
00642                            } //if( 1 == fRootConvPar->uVftxFullDataMode )
00643 
00644                cleanTree->Branch( sBrNameTimeC,  ((fVftxInputEvent->fVftxBoards[iVftxBoard]).dTimeCorr),
00645                                   sBrNameTimeC + Form("[%u][%u]/D", FPGA_TDC_NBCHAN, TVftxBoardData::MaxMult )  );
00646                         } // else of if( 1 == fRootConvPar->uVftxFullBoardData )
00647                   } // if( 1 == fRootConvPar->uVftxEnabled[iVftxBoard])
00648             } // if( 1 == fRootConvPar->uVftxInTree && kTRUE == fParAnalysis->bWithVftxCalib )
00649             if( 1 == fRootConvPar->uScalOrMuInTree && kTRUE == fParAnalysis->bWithScalersRate )
00650             {
00651                cleanTree->Branch("ScalOrMuScalers",  (fCrateInputEvent->fScalOrMu).uScaler,
00652                                  Form("ScalOrMuScalers[%u]/i", SCALORMU_NB_SCAL )  );
00653             } // if( 1 == fRootConvPar->uScalOrMuInTree && kTRUE == fParAnalysis->bWithScalersRate )
00654             if( 1 == fRootConvPar->uRpcInTree )
00655             {
00656                if( 1 == fRootConvPar->uMultiEventsAllowed)
00657                {
00658                   for( UInt_t uRpcIndex = 0; uRpcIndex < fParAnalysis->uNbRpc; uRpcIndex++ )
00659                      if( 1 == fRootConvPar->uRpcEnabled[uRpcIndex] )
00660                      {
00661                         cleanTree->Branch( Form("Rpc%02dEvent", uRpcIndex), "TRpcEvent",
00662                               &(fRpcInputEvent[uRpcIndex]) );
00663                      }
00664                } // if( 1 == fRootConvPar->uMultiEventsAllowed)
00665                   else for( UInt_t uRpcIndex = 0; uRpcIndex < fParAnalysis->uNbRpc; uRpcIndex++ )
00666                      if( 1 == fRootConvPar->uRpcEnabled[uRpcIndex] )
00667                      {
00668                         /*
00669                         cleanTree->Branch( Form("Rpc%02dEvent", uRpcIndex),  "Rpc_Event",
00670                               &(fRpcInputEvent[uRpcIndex]->fEvents[0]) );
00671                               */
00672                         cleanTree->Branch( Form("Rpc%02dEvent", uRpcIndex),  "Rpc_Event",
00673                               &( fRpcSingleEvent[uRpcIndex] ) );
00674                      } // if( 1 == fRootConvPar->uRpcEnabled[uRpcIndex] )
00675             } // if( 1 == fRootConvPar->uRpcInTree )
00676             if( 1 == fRootConvPar->uPlasticsInTree )
00677             {
00678                if( 1 == fRootConvPar->uMultiEventsAllowed)
00679                {
00680                   for( UInt_t uPlasticIndex = 0; uPlasticIndex < fParAnalysis->uNbPlastics; uPlasticIndex++ )
00681                      if( 1 == fRootConvPar->uPlasticsEnabled[uPlasticIndex] )
00682                      {
00683                         cleanTree->Branch( Form("Plastics%02dEvent", uPlasticIndex), "TPlasticsEvent",
00684                               &(fPlasticsInputEvent[uPlasticIndex]) );
00685                      }
00686                } // if( 1 == fRootConvPar->uMultiEventsAllowed)
00687                   else for( UInt_t uPlasticIndex = 0; uPlasticIndex < fParAnalysis->uNbPlastics; uPlasticIndex++ )
00688                      if( 1 == fRootConvPar->uPlasticsEnabled[uPlasticIndex] )
00689                      {
00690                         /*
00691                         cleanTree->Branch( Form("Plastics%02dEvent", uPlasticIndex),     "Plastics_Event",
00692                               &(fPlasticsInputEvent[uPlasticIndex]->fEvents[0]) );
00693                               */
00694                         cleanTree->Branch( Form("Plastics%02dEvent", uPlasticIndex),     "Plastics_Event",
00695                               &( fPlasticsSingleEvent[uPlasticIndex] ) );
00696                      } // if( 1 == fRootConvPar->uRpcEnabled[uRpcIndex] )
00697             } // if( 1 == fRootConvPar->uRpcInTree )
00698             /*
00699             if( 1 == fRootConvPar->uPadRpcInTree)
00700             {
00701                cleanTree->Branch("PadRpcEvent",     "TPadRpcEvent", &fPadRpcInputEvent);
00702             }
00703             */
00704             if( 1 == fRootConvPar->uScalOrMuInTree && kTRUE == fParAnalysis->bWithScalersRate )
00705             {
00706 //               cleanTree->Branch("ScalOrMu1Event",  "TScalersEvent", &fScalOrMu1InputEvent);
00707                cleanTree->Branch("ScalOrMu1Event",  "Scalers_Event", &(fScalOrMu1InputEvent->fEvent) );
00708             } // if( 1 == fRootConvPar->uScalOrMuInTree && kTRUE == fParAnalysis->bWithScalersRate )
00709             if( 1 == fRootConvPar->uScalOrMu2InTree)
00710             {
00711 //               cleanTree->Branch("ScalOrMu2Event",  "TScalersEvent", &fScalOrMu2InputEvent);
00712                cleanTree->Branch("ScalOrMu2Event",  "Scalers_Event", &(fScalOrMu2InputEvent->fEvent) );
00713             }
00714 
00715             if( 1 == fRootConvPar->uMatchingInTree && kTRUE == fParAnalysis->bWithMatching)
00716             {
00717                cleanTree->Branch("MatchingEvent",  "TMatchingEvent", &fMatchingInputEvent);
00718             } // if( 1 == fRootConvPar->uMatchingInTree && kTRUE == fParAnalysis->bWithMatching)
00719          } // if( kFALSE == fRocPar->noTrigger )
00720          
00721 #ifdef ROOTCONV_WITHHODO
00722          if( 1 == fRootConvPar->uHodoInputInTree )
00723          {
00724             cleanTree->Branch("HodoscopeX",  &(hitHodoscope.X),"HodoscopeX/D");
00725             cleanTree->Branch("HodoscopeY",  &(hitHodoscope.Y),"HodoscopeY/D");
00726          } // if( 1 == fRootConvPar->uHodoInputInTree )
00727 #endif
00728 
00729          if( 1 == fRootConvPar->uSlowControlInTree && kTRUE == fParAnalysis->bWithEpics )
00730          {
00731             uSlowControlUpdateTime = 0;
00732             cleanTree->Branch( "TimeEpicsUpdate", &(uSlowControlUpdateTime),
00733                                "TimeEpicsUpdate/i"  );
00734             vdPositiveHvI.clear();
00735             vdPositiveHvU.clear();
00736             vdNegativeHvI.clear();
00737             vdNegativeHvU.clear();
00738             vdPositiveHvI.resize(fRootConvPar->uNbSlowControlChan);
00739             vdPositiveHvU.resize(fRootConvPar->uNbSlowControlChan);
00740             vdNegativeHvI.resize(fRootConvPar->uNbSlowControlChan);
00741             vdNegativeHvU.resize(fRootConvPar->uNbSlowControlChan);
00742             for( UInt_t uChannelHV = 0; uChannelHV < fRootConvPar->uNbSlowControlChan; uChannelHV++)
00743             {
00744                cleanTree->Branch( fRootConvPar->sScOutputNamePosI[uChannelHV], &(vdPositiveHvI.at(uChannelHV)),
00745                                  fRootConvPar->sScOutputNamePosI[uChannelHV] + Form("/D" )  );
00746                cleanTree->Branch( fRootConvPar->sScOutputNamePosU[uChannelHV], &(vdPositiveHvU.at(uChannelHV)),
00747                                  fRootConvPar->sScOutputNamePosU[uChannelHV] + Form("/D" )  );
00748                cleanTree->Branch( fRootConvPar->sScOutputNameNegI[uChannelHV], &(vdNegativeHvI.at(uChannelHV)),
00749                                  fRootConvPar->sScOutputNameNegI[uChannelHV] + Form("/D" )  );
00750                cleanTree->Branch( fRootConvPar->sScOutputNameNegU[uChannelHV], &(vdNegativeHvU.at(uChannelHV)),
00751                                  fRootConvPar->sScOutputNameNegU[uChannelHV] + Form("/D" )  );
00752                vdPositiveHvI.at(uChannelHV) = 0;
00753                vdPositiveHvU.at(uChannelHV) = 0;
00754                vdNegativeHvI.at(uChannelHV) = 0;
00755                vdNegativeHvU.at(uChannelHV) = 0;
00756             } // for( UInt_t uChannelHV = 0; uChannelHV < fRootConvPar->uNbSlowControlChan; uChannelHV++)
00757          } // if( 1 == fRootConvPar->uSlowControlInTree && kTRUE == fParAnalysis->bWithEpics )
00758 
00759          cleanTree->SetDirectory(gDirectory);
00760 
00761          if( 1 == fRootConvPar->uRootDisplay && 0 == TGo4Analysis::Instance()->GetTree( "GsiAug12" ))
00762          {
00763             TGo4Analysis::Instance()->AddTree(cleanTree );
00764             TGo4Log::Info("Root Tree registered in Go4: %p", TGo4Analysis::Instance()->GetTree( "GsiAug12" ) );
00765          }
00766       } // if( 0 == cleanTree)
00767    } // if( 1 == fRootConvPar->uCleanOuputEnable || 1 == fRootConvPar->uRootDisplay)
00768 }
00769 
00770 
00771 void TRootConverterProc::FinalizeEvent()
00772 {
00773    if( 0 == fRootConvPar->uCleanOuputEnable && 0 == fRootConvPar->uRootDisplay)
00774          return;
00775    if( 0 == fRootConvPar->uCleanOuputEnable && 1 == fRootConvPar->uRootDisplay &&
00776        fRootConvPar->uEventsUntilReset <= cleanTree->GetEntries())
00777       cleanTree->Reset("");
00778 
00779    if( -1 < fParAnalysis->iTriggerRejection && kTRUE == fParAnalysis->bWithTriglog)
00780       if( 1 == ((fTriglogInputEvent->fVulomTriggerPattern>>fParAnalysis->iTriggerRejection)&0x1 )  )
00781       {
00782           // The trigger Rejection is active and we have rejected trigger
00783          return;
00784       }
00785 
00786    if( (1 == fRootConvPar->uCaenInTree && kTRUE == fParAnalysis->bWithMbs ) || 1 == fRootConvPar->uTriglogInputInTree )
00787       if(!fCrateInputEvent->IsValid() )
00788          return; // skip incomplete mbs events from first step
00789    if( 1 == fRootConvPar->uTriglogInputInTree && kTRUE == fParAnalysis->bWithTriglog )
00790       if( !fTriglogInputEvent->IsValid() )
00791          return; // skip incomplete triglog events from first step
00792    if( 1 == fRootConvPar->uVftxInTree && kTRUE == fParAnalysis->bWithVftxCalib )
00793       if( !fVftxInputEvent->IsValid() )
00794          cout<<"Invalid VFTX event! event "<<uNbEvents<<endl;
00795 
00796    uNbEvents++;
00797 
00798    // Fill the tree
00799    if( ( 1 == fRootConvPar->uCleanOuputEnable || 1 == fRootConvPar->uRootDisplay) )
00800    {
00801       if( 1 == fRootConvPar->uRpcInTree )
00802       {
00803          if( 0 == fRootConvPar->uMultiEventsAllowed )
00804          {
00805             for( UInt_t uRpcIndex = 0; uRpcIndex < fParAnalysis->uNbRpc; uRpcIndex++ )
00806                if( 1 == fRootConvPar->uRpcEnabled[uRpcIndex] )
00807                {
00808                   fRpcSingleEvent[uRpcIndex].Clear();
00809                   fRpcSingleEvent[uRpcIndex] = fRpcInputEvent[uRpcIndex]->fEvents[0];
00810                } // if( 1 == fRootConvPar->uRpcEnabled[uRpcIndex] )
00811          } // if( 0 == fRootConvPar->uMultiEventsAllowed )
00812       } // if( 1 == fRootConvPar->uRpcInTree )
00813 
00814       if( 1 == fRootConvPar->uPlasticsInTree )
00815       {
00816          if( 0 == fRootConvPar->uMultiEventsAllowed )
00817          {
00818             for( UInt_t uPlasticIndex = 0; uPlasticIndex < fParAnalysis->uNbPlastics; uPlasticIndex++ )
00819                if( 1 == fRootConvPar->uPlasticsEnabled[uPlasticIndex] )
00820                {
00821                   fPlasticsSingleEvent[uPlasticIndex].Clear();
00822                   fPlasticsSingleEvent[uPlasticIndex] = fPlasticsInputEvent[uPlasticIndex]->fEvents[0];
00823                } // if( 1 == fRootConvPar->uPlasticsEnabled[uPlasticIndex] )
00824          } // if( 0 == fRootConvPar->uMultiEventsAllowed )
00825       } // if( 1 == fRootConvPar->uPlasticsInTree )
00826 
00827       if( 1 == fRootConvPar->uGet4InTree && kTRUE == fParAnalysis->bWithGet4 )
00828       {
00829          if( 0 == fRootConvPar->uMultiEventsAllowed )
00830          {
00831             if( 0 < (fGet4v1InputEvent->fEvents).size())
00832             {
00833                for( Int_t iGet4Board = 0; iGet4Board<MAX_GET4; iGet4Board ++)
00834                   if( 1 == fRootConvPar->uGet4Enabled[iGet4Board])
00835                   {
00836                      fGet4Board[iGet4Board].Clear();
00837                      fGet4Board[iGet4Board] = (fGet4v1InputEvent->fEvents[0]).fGet4Boards[iGet4Board];
00838                   } // if( 1 == fRootConvPar->uGet4Enabled[iGet4Board])
00839             } // if( 0 < (fGet4v1InputEvent->fEvents).size())
00840             else for( Int_t iGet4Board = 0; iGet4Board<MAX_GET4; iGet4Board ++)
00841                if( 1 == fRootConvPar->uGet4Enabled[iGet4Board])
00842                   fGet4Board[iGet4Board].Clear();
00843          } // if( 0 == fRootConvPar->uMultiEventsAllowed )
00844       } // if( 1 == fRootConvPar->uGet4InTree && kTRUE == fParAnalysis->bWithGet4 )
00845 #ifdef ROOTCONV_WITHHODO
00846       if( 1 == fRootConvPar->uHodoInputInTree )
00847       {
00848          if( 1 == fRootConvPar->uHodoDebugHisto)
00849             hNbClustersPerEventHodoscope->Fill( fHodoInputEvent->NumHits() );
00850 
00851          if( 0 < fHodoInputEvent->NumHits() )
00852          {
00853             hitHodoscope = fHodoInputEvent->Hit(0);
00854             if( 1 == fRootConvPar->uTriglogInputInTree && 1 == fRootConvPar->uHodoDebugHisto
00855                   && kTRUE == fParAnalysis->bWithTriglog )
00856             {
00857                if( 0 == uFirstMbsTime)
00858                {
00859                   uFirstMbsTime = fTriglogInputEvent->fMbsTimeSecs;
00860                   uSpillStartMbsTime = fTriglogInputEvent->fMbsTimeSecs- uFirstMbsTime;
00861                   uLastMbsTime = fTriglogInputEvent->fMbsTimeSecs;
00862 
00863                   uFirstMbsTimeMs = fTriglogInputEvent->fMbsTimeMillisec;
00864                   uSpillStartMbsTimeMs = fTriglogInputEvent->fMbsTimeMillisec- uFirstMbsTimeMs;
00865                }
00866 
00867                hHit2DvsSeconds->Fill( fTriglogInputEvent->fMbsTimeSecs - uFirstMbsTime,
00868                      fHodoInputEvent->Hit(0).X, fHodoInputEvent->Hit(0).Y);
00869 
00870                if( 20 < fTriglogInputEvent->fMbsTimeSecs - uLastMbsTime )
00871                {
00872                   uSpillStartMbsTime = fTriglogInputEvent->fMbsTimeSecs - uFirstMbsTime;
00873                   uSpillStartMbsTimeMs = fTriglogInputEvent->fMbsTimeMillisec - uFirstMbsTimeMs;
00874                }
00875 
00876                hHit2DvsSecondsInSpill->Fill(
00877                      fTriglogInputEvent->fMbsTimeSecs - uFirstMbsTime - uSpillStartMbsTime,
00878                      fHodoInputEvent->Hit(0).X, fHodoInputEvent->Hit(0).Y);
00879 
00880                hHit2DvsMilliSecondsInSpill->Fill(
00881                      (fTriglogInputEvent->fMbsTimeSecs - uFirstMbsTime - uSpillStartMbsTime)*1000 +
00882                      fTriglogInputEvent->fMbsTimeMillisec - uFirstMbsTimeMs - uSpillStartMbsTimeMs,
00883                      fHodoInputEvent->Hit(0).X, fHodoInputEvent->Hit(0).Y);
00884 
00885                hHitXvsMilliSecondsInSpill->Fill(
00886                      (fTriglogInputEvent->fMbsTimeSecs - uFirstMbsTime - uSpillStartMbsTime)*1000 +
00887                      fTriglogInputEvent->fMbsTimeMillisec - uFirstMbsTimeMs - uSpillStartMbsTimeMs,
00888                      fHodoInputEvent->Hit(0).X );
00889                hHitYvsMilliSecondsInSpill->Fill(
00890                      (fTriglogInputEvent->fMbsTimeSecs - uFirstMbsTime - uSpillStartMbsTime)*1000 +
00891                      fTriglogInputEvent->fMbsTimeMillisec - uFirstMbsTimeMs - uSpillStartMbsTimeMs,
00892                      fHodoInputEvent->Hit(0).Y );
00893 
00894                uLastMbsTime  = fTriglogInputEvent->fMbsTimeSecs;
00895 
00896             } // if( 1 == fRootConvPar->uTriglogInputInTree && 1 == fRootConvPar->uHodoDebugHisto && kTRUE == fParAnalysis->bWithTriglog )
00897          } // if( 0 < fHodoInputEvent->NumHits() )
00898       } // if( 1 == fRootConvPar->uHodoInputInTree )
00899 #endif
00900       if( 1 == fRootConvPar->uSlowControlInTree && kTRUE == fParAnalysis->bWithEpics )
00901       {
00902          if( kTRUE == fEpicsInputEvent->IsValid() )
00903          {
00904             TString sVariableName = "";
00905             if( 0 == uEpicsTimeOrigin )
00906                uEpicsTimeOrigin = fEpicsInputEvent->fUTimeSeconds;
00907             hTimeEpicsUpdates->Fill( (fEpicsInputEvent->fUTimeSeconds )% 1000);
00908             uSlowControlUpdateTime = fEpicsInputEvent->fUTimeSeconds;
00909             for(UInt_t uEpicsVariableIndex = 0; uEpicsVariableIndex < fEpicsInputEvent->GetNumDoubles(); uEpicsVariableIndex++ )
00910             {
00911                sVariableName = fEpicsInputEvent->GetDoubleName( uEpicsVariableIndex );
00912                for( UInt_t uChannelHV = 0; uChannelHV < fRootConvPar->uNbSlowControlChan; uChannelHV++)
00913                {
00914                   if( sVariableName == fRootConvPar->sScInputNamePosI[uChannelHV])
00915                   {
00916                      vdPositiveHvI.at(uChannelHV) = fEpicsInputEvent->GetDouble(uEpicsVariableIndex);
00917                      break;
00918                   }
00919                   if( sVariableName == fRootConvPar->sScInputNamePosU[uChannelHV])
00920                   {
00921                      vdPositiveHvU.at(uChannelHV) = fEpicsInputEvent->GetDouble(uEpicsVariableIndex);
00922                      break;
00923                   }
00924                   if( sVariableName == fRootConvPar->sScInputNameNegI[uChannelHV])
00925                   {
00926                      vdNegativeHvI.at(uChannelHV) = fEpicsInputEvent->GetDouble(uEpicsVariableIndex);
00927                      break;
00928                   }
00929                   if( sVariableName == fRootConvPar->sScInputNameNegU[uChannelHV])
00930                   {
00931                      vdNegativeHvU.at(uChannelHV) = fEpicsInputEvent->GetDouble(uEpicsVariableIndex);
00932                      break;
00933                   }
00934                } //  for( UInt_t uChannelHV = 0; uChannelHV < fRootConvPar->uNbSlowControlChan; uChannelHV++)
00935             } // for(UInt_t uEpicsVariableIndex = 0; uEpicsVariableIndex < fEpicsInputEvent->GetNumDoubles(); uEpicsVariableIndex++ )
00936          } // if( kTRUE == fEpicsInputEvent->IsValid() )
00937       } // if( 1 == fRootConvPar->uSlowControlInTree && kTRUE == fParAnalysis->bWithEpics )
00938 
00939       cleanTree->Fill();
00940 
00941       // Case: RAW DATA mode and GET4 enabled => only GET4 data possible!
00942       // => Multi-event by definition
00943       if( kTRUE == fParAnalysis->bWithGet4 )
00944          if( kTRUE == fGet4v1Par->bRawDataMode )
00945          {
00946             for( UInt_t uGet4EventIndex = 1; uGet4EventIndex < (fGet4v1InputEvent->fEvents).size(); uGet4EventIndex++ )
00947             {
00948                uNbEvents++;
00949                for( Int_t iGet4Board = 0; iGet4Board<MAX_GET4; iGet4Board ++)
00950                   if( 1 == fRootConvPar->uGet4Enabled[iGet4Board])
00951                   {
00952                      fGet4Board[iGet4Board].Clear();
00953                      fGet4Board[iGet4Board] = (fGet4v1InputEvent->fEvents[uGet4EventIndex]).fGet4Boards[iGet4Board];
00954                   } // if( 1 == fRootConvPar->uGet4Enabled[iGet4Board])
00955                for( UInt_t uRpcIndex = 0; uRpcIndex < fParAnalysis->uNbRpc; uRpcIndex++ )
00956                   if( 1 == fRootConvPar->uRpcEnabled[uRpcIndex] )
00957                   {
00958                      fRpcSingleEvent[uRpcIndex].Clear();
00959                      fRpcSingleEvent[uRpcIndex] = fRpcInputEvent[uRpcIndex]->fEvents[uGet4EventIndex];
00960                   } // if( 1 == fRootConvPar->uRpcEnabled[uRpcIndex] )
00961 
00962                for( UInt_t uPlasticIndex = 0; uPlasticIndex < fParAnalysis->uNbPlastics; uPlasticIndex++ )
00963                   if( 1 == fRootConvPar->uPlasticsEnabled[uPlasticIndex] )
00964                   {
00965                      fPlasticsSingleEvent[uPlasticIndex].Clear();
00966                      fPlasticsSingleEvent[uPlasticIndex] = fPlasticsInputEvent[uPlasticIndex]->fEvents[uGet4EventIndex];
00967                   } // if( 1 == fRootConvPar->uPlasticsEnabled[uPlasticIndex] )
00968 
00969                cleanTree->Fill();
00970             } // for( Int_t iGet4EventIndex = 1; iGet4EventIndex < (fGet4v1InputEvent->fEvents).size(); iGet4EventIndex++ )
00971          } // if( kTRUE == fParAnalysis->bWithGet4 ) && if( kTRUE == fGet4v1Par->bRawDataMode )
00972    } // if( ( 1 == fRootConvPar->uCleanOuputEnable || 1 == fRootConvPar->uRootDisplay) )
00973 
00974    fOutputEvent->SetValid(kTRUE);
00975 }

Generated on Tue Dec 10 2013 04:52:18 for ROCsoft by  doxygen 1.7.1