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

beamtime/gsi-aug12/hd/go4/ROOTFORMAT/TRootConverterProc.cxx (r4864/r3215)

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 #ifdef ROOTCONV_WITHHODO
00027 fHodoInputEvent(0),
00028 #endif
00029 #ifdef ROOTCONV_WITHGET4
00030 fRpcInputEvent(0),
00031 #endif
00032 fVftxInputEvent(0),
00033 fCrateInputEvent(0),
00034 fTriglogInputEvent(0),
00035 fEpicsInputEvent(0),
00036 fOutputEvent(0),
00037 cleanTree(0)
00038 {
00039    TGo4Log::Info("**** TRootConverterProc: Create instance %s", name);
00040 
00041 #if defined(ROOTCONV_WITHGET4) || defined(ROOTCONV_WITHHODO)
00042    fRocPar = (TRocParam*) GetParameter("RocPar");
00043    cout << "ROCPAR = " << fRocPar << endl;
00044    
00045    if (fRocPar->numRocs > 0) fNumRocs = (UInt_t) fRocPar->numRocs;
00046 #endif
00047 
00048 #ifdef ROOTCONV_WITHGET4
00049    fRpcPar = (TRPCParam*) GetParameter("RPCPar");
00050    cout << "RPCPAR = " << fRpcPar << endl;
00051 #endif
00052 
00053    fRootConvPar = (TRootConverterParam*) MakeParameter("RootConvPar", "TRootConverterParam");
00054    cout << "RootConvPar = " << fRootConvPar << endl;
00055 
00056 
00057    // ROC general variables
00058    uNbEvents = 0;
00059    
00060 #ifdef ROOTCONV_WITHHODO
00061    if(1 == fRootConvPar->uHodoDebugHisto)
00062    {
00063       TString path = GetName();
00064       path += "/";
00065       path += GetName();
00066 
00067       // Booking histograms
00068       hNbClustersPerEventHodoscope = MakeTH1('I', path+"_NbClustersPerEventHodoscope","Nb hosdoscope clusters per event",
00069             16,-0.5,15.5);
00070 
00071       hHitXvsMilliSecondsInSpill = MakeTH2('I', path+"_HitPosXVsTimeMilSecInSpill",
00072             "Hodoscope hit position versus time in Spill; Time in spill [ms]; X [mm]; Counts [mm]",
00073             8000,-50, 79950, 32,-14.5,15.5 );
00074       hHitYvsMilliSecondsInSpill = MakeTH2('I', path+"_HitPosYVsTimeMilSecInSpill",
00075             "Hodoscope hit position versus time in Spill; Time in spill [ms]; Y [mm]; Counts [mm]",
00076             8000,-50, 79950, 32,-14.5,15.5 );
00077       // No MakeTH3 function in go4, so do same operations by hand
00078       // => Need to check if loaded from autosave and create by ourselves
00079       path = GetName();
00080       path += "/";
00081       TString sName = GetName();
00082       hHit2DvsSeconds        = (TH3*)GetHistogram( path+ sName +"_HitPosVsTimeSec" );
00083       if( 0 == hHit2DvsSeconds )
00084       {
00085          hHit2DvsSeconds        = new TH3I( sName +"_HitPosVsTimeSec",
00086                                  "Hodoscope hit position versus time; Time [s]; X [mm]; Y [mm]",
00087                                  1000,-0.5, 1999.5, 32,-14.5,15.5, 32,-14.5,15.5 );
00088          AddHistogram( hHit2DvsSeconds, path );
00089       }
00090       hHit2DvsSecondsInSpill        = (TH3*)GetHistogram( path + sName +"_HitPosVsTimeSecInSpill" );
00091       if( 0 == hHit2DvsSecondsInSpill )
00092       {
00093          hHit2DvsSecondsInSpill = new TH3I( sName +"_HitPosVsTimeSecInSpill",
00094                                  "Hodoscope hit position versus time in Spill; Time in spill [s]; X [mm]; Y [mm]",
00095                                  80,-0.5, 79.5, 32,-14.5,15.5, 32,-14.5,15.5 );
00096          AddHistogram( hHit2DvsSecondsInSpill, path );
00097       }
00098       hHit2DvsMilliSecondsInSpill        = (TH3*)GetHistogram( path + sName +"_HitPosVsTimeMilSecInSpill" );
00099       if( 0 == hHit2DvsMilliSecondsInSpill )
00100       {
00101          hHit2DvsMilliSecondsInSpill = new TH3I( sName +"_HitPosVsTimeMilSecInSpill",
00102                                  "Hodoscope hit position versus time in Spill; Time in spill [ms]; X [mm]; Y [mm]",
00103                                  8000,-50, 79950, 32,-14.5,15.5, 32,-14.5,15.5 );
00104          AddHistogram( hHit2DvsMilliSecondsInSpill, path );
00105       }
00106       // For hodoscope hits map
00107       uFirstMbsTime = 0;
00108       uSpillStartMbsTime = 0;
00109       uLastMbsTime = 0;
00110 
00111       uFirstMbsTimeMs = 0;
00112       uSpillStartMbsTimeMs = 0;
00113    } // if(1 == fRootConvPar->uHodoDebugHisto)
00114 #endif
00115 
00116    //~ TString path = GetName();
00117    //~ path += "/";
00118    //~ path += GetName();
00119    if( 1 == fRootConvPar->uSlowControlInTree )
00120    {
00121       hTimeEpicsUpdates = MakeTH1('I', "RootConv/RC_TimeEpicsUpdate","Timing of epics updates; Time [s]",
00122             7200, 0, 7200);
00123    } // if( 1 == fRootConvPar->uSlowControlInTree )
00124    uEpicsTimeOrigin = 0;
00125       
00126    //printf("RPC Histograms created \n");
00127    fflush ( stdout);
00128 }
00129 
00130 TRootConverterProc::~TRootConverterProc()
00131 {
00132 //   TGo4Log::Info("Proc  %p", this);
00133    if( (1 == fRootConvPar->uCleanOuputEnable || 1 == fRootConvPar->uRootDisplay)
00134          && 0 != cleanTree )
00135       {
00136           if( 1 == fRootConvPar->uRootDisplay )
00137              TGo4Analysis::Instance()->RemoveTree(cleanTree);
00138           if( 1 == fRootConvPar->uCleanOuputEnable )
00139           {
00140              fRootOut->Write("",TObject::kOverwrite);
00141              //~ gDirectory->Cd(sOutputFilename);
00142 //~ 
00143              //~ cleanTree->SetDirectory(gDirectory);
00144              //~ cleanTree->Write(0,TObject::kOverwrite); // to avoid double trees in file: cf http://root.cern.ch/root/roottalk/roottalk01/0842.html
00145              //~ gDirectory->Cd(oldDir->GetPath());
00146              fRootOut->Close();
00147           } // if( 1 == fRootConvPar->uCleanOuputEnable )
00148 
00149           if( 0 == fRootConvPar->uCleanOuputEnable )
00150              delete cleanTree;
00151              
00152 #ifdef ROOTCONV_WITHGET4
00153           if( 1 == fRootConvPar->uAddGet4DataInTree )
00154           {
00155              for( UInt_t uChannelTemp = 0; uChannelTemp < fRocPar->uNbFeets*8; uChannelTemp++)
00156              {
00157                 (*vuHitNumber)[uChannelTemp]  = 0;
00158                 (*vuTime)[uChannelTemp].clear();
00159                 (*vuEpochTime)[uChannelTemp].clear();
00160                 (*viTot)[uChannelTemp].clear();
00161              }
00162 
00163              delete vuHitNumber;
00164              delete vuTime;
00165              delete vuEpochTime;
00166              delete viTot;
00167           } // if( 1 == fRootConvPar->uAddGet4DataInTree )
00168 #endif
00169 
00170           if( 1 == fRootConvPar->uSlowControlInTree )
00171           {
00172              vdPositiveHvI.clear();
00173              vdPositiveHvU.clear();
00174              vdNegativeHvI.clear();
00175              vdNegativeHvU.clear();
00176           }
00177 
00178 //          if( 1 == fRootConvPar->uCleanOuputEnable )
00179 //             delete fRootOut;
00180       }
00181 
00182    cout << "**** TRootConverterProc: Delete instance " << endl;
00183 }
00184 //***********************************************************
00185 
00186 void TRootConverterProc::InitEvent(TGo4EventElement* outevnt)
00187 {
00188    // first assign input event:
00189    // since input event object is never discarded within processor lifetime,
00190    // we just search for subevent by name once to speed up processing
00191 #ifdef ROOTCONV_WITHGET4
00192    if( 0==fRpcInputEvent && 1 == fRootConvPar->uAddGet4DataInTree )
00193    {
00194       TCBMBeamtimeEvent* btevent=dynamic_cast<TCBMBeamtimeEvent*>(GetInputEvent());
00195       if(btevent)
00196       {
00197          fRpcInputEvent=dynamic_cast<TRPCEvent*>(btevent->GetSubEvent("RPC"));
00198       }
00199       if(fRpcInputEvent==0 ) {
00200          GO4_STOP_ANALYSIS_MESSAGE("**** TRootConverterProc: Fatal error: input event has no TRPCEvent!!! STOP GO4");
00201       }
00202    }
00203 #endif
00204 #ifdef ROOTCONV_WITHHODO
00205    if( 0==fHodoInputEvent && 1 == fRootConvPar->uHodoInputInTree )
00206    {
00207       TCBMBeamtimeEvent* btevent=dynamic_cast<TCBMBeamtimeEvent*>(GetInputEvent());
00208       if(btevent)
00209       {
00210          fHodoInputEvent=dynamic_cast<TFiberHodEvent*>(btevent->GetSubEvent("Hodo1"));
00211       }
00212       if( 0==fHodoInputEvent ) {
00213          GO4_STOP_ANALYSIS_MESSAGE("**** TRootConverterProc: Fatal error: input event has no TFiberHodEvent!!! STOP GO4");
00214       }
00215    }
00216 #endif
00217    if( 0 ==fVftxInputEvent && 1 == fRootConvPar->uVftxInTree)
00218    {
00219       TCBMBeamtimeEvent* btevent=dynamic_cast<TCBMBeamtimeEvent*>(GetInputEvent());
00220       if(btevent)
00221       {
00222          fVftxInputEvent=dynamic_cast<TVftxEvent*>(btevent->GetSubEvent("VFTX"));
00223       }
00224 
00225       if(fVftxInputEvent==0) {
00226          GO4_STOP_ANALYSIS_MESSAGE("**** TRootConverterProc: Fatal error: input event is/has not a TVftxEvent!!! STOP GO4");
00227       }
00228    } // if( 0 == fVftxInputEvent && 1 == fRootConvPar->uVftxInTree)
00229 
00230    // Optional: if triggered mode and tree, look for the VME crate data
00231    // since input event object is never discarded within processor lifetime,
00232    // we just search for subevent by name once to speed up processing
00233 #if defined(ROOTCONV_WITHGET4) || defined(ROOTCONV_WITHHODO)
00234    if( kFALSE == fRocPar->noTrigger && ( 1 == fRootConvPar->uCleanOuputEnable || 1 == fRootConvPar->uRootDisplay) )
00235 #else
00236    if( 1 == fRootConvPar->uCleanOuputEnable || 1 == fRootConvPar->uRootDisplay )
00237 #endif
00238    {
00239       TCBMBeamtimeEvent* btevent=dynamic_cast<TCBMBeamtimeEvent*>(GetInputEvent("Detector"));
00240       if(fCrateInputEvent==0)
00241       {
00242          if(btevent)
00243          {
00244             fCrateInputEvent=dynamic_cast<TMbsCrateEvent*>(btevent->GetSubEvent("MBSCRATE"));
00245          }
00246 
00247          if(fCrateInputEvent==0) {
00248             GO4_STOP_ANALYSIS_MESSAGE("**** TRootConverterProc: Fatal error: input event is/has not a TMbsCrateEvent!!! STOP GO4");
00249          }
00250       } // if(fCrateInputEvent==0)
00251       if( 1 == fRootConvPar->uTriglogInputInTree )
00252       {
00253          if(fTriglogInputEvent==0)
00254          {
00255             if(btevent)
00256             {
00257                fTriglogInputEvent=dynamic_cast<TTriglogEvent*>(btevent->GetSubEvent("TRIGLOG"));
00258             }
00259 
00260             if(fTriglogInputEvent==0) {
00261                GO4_STOP_ANALYSIS_MESSAGE("**** TRootConverterProc: Fatal error: input event is/has not a TTriglogEvent!!! STOP GO4");
00262             }
00263          } // if(fTriglogInputEvent==0)
00264       } // if( 1 == fRootConvPar->uTriglogInputInTree )
00265       if( 1 == fRootConvPar->uSlowControlInTree )
00266       {
00267          if(fEpicsInputEvent==0)
00268          {
00269             if(btevent)
00270             {
00271                fEpicsInputEvent=dynamic_cast<TEpicsEvent*>(btevent->GetSubEvent("EPICS"));
00272             }
00273 
00274             if(fEpicsInputEvent==0) {
00275                GO4_STOP_ANALYSIS_MESSAGE("**** TRootConverterProc: Fatal error: input event is/has not a TEpicsEvent!!! STOP GO4");
00276             }
00277          } // if(fEpicsInputEvent==0)
00278       } // if( 1 == fRootConvPar->uSlowControlInTree )
00279    } // if( kFALSE == fRocPar->noTrigger && ( 1 == fRootConvPar->uCleanOuputEnable || 1 == fRootConvPar->uRootDisplay) )
00280       else if( 1 == fRootConvPar->uSlowControlInTree )
00281       {
00282          TCBMBeamtimeEvent* btevent=dynamic_cast<TCBMBeamtimeEvent*>(GetInputEvent("Detector"));
00283          if(fEpicsInputEvent==0)
00284          {
00285             if(btevent)
00286             {
00287                fEpicsInputEvent=dynamic_cast<TEpicsEvent*>(btevent->GetSubEvent("EPICS"));
00288             }
00289 
00290             if(fEpicsInputEvent==0) {
00291                GO4_STOP_ANALYSIS_MESSAGE("**** TRootConverterProc: Fatal error: input event is/has not a TEpicsEvent!!! STOP GO4");
00292             }
00293          } // if(fEpicsInputEvent==0)
00294       } //  else if( 1 == fRootConvPar->uSlowControlInTree )
00295 
00296    // then assign output event
00297    // since output event object is never discarded within processor lifetime,
00298    // we just search for subevent by name once to speed up processing
00299    if(fOutputEvent==0)
00300    {
00301       TCBMBeamtimeEvent* btevent=dynamic_cast<TCBMBeamtimeEvent*>(outevnt);
00302       if(btevent)
00303       {
00304          fOutputEvent=dynamic_cast<TRootConverterEvent*>(btevent->GetSubEvent("ROOTFORMAT"));
00305       }
00306       else
00307       {
00308 
00309             fOutputEvent= dynamic_cast<TRootConverterEvent*>(outevnt);
00310       }
00311       if(fOutputEvent==0) {
00312       GO4_STOP_ANALYSIS_MESSAGE("**** TRootConverterProc: Fatal error: output event is not a TRootConverterEvent!!! STOP GO4");
00313       }
00314 
00315    }
00316 
00317    // Prepare root tree and tree output file
00318    if( 1 == fRootConvPar->uCleanOuputEnable || 1 == fRootConvPar->uRootDisplay)
00319    {
00320       if( 0 == cleanTree)
00321       {
00322          TGo4Log::Info("**** TRootConverter: Create tree ");
00323 
00324          if( 1 == fRootConvPar->uCleanOuputEnable )
00325          {
00326             oldDir = gDirectory;
00327 
00328             sOutputFilename = fRootConvPar->sOutputFilename;
00329             fRootOut= new TFile(sOutputFilename, "RECREATE", "TTree file from GET4 and CAEN v1290", 9);
00330             sOutputFilename += ":/";
00331             if (fRootOut->IsZombie()) {
00332                cout << "Error opening file for TTree output in TRootConverter" << endl;
00333             }
00334 
00335             gDirectory->Cd(sOutputFilename);
00336          }
00337 
00338          if( 0 == TGo4Analysis::Instance()->GetTree( "GsiAug12" ) )
00339          {
00340             cleanTree = new TTree("GsiAug12", "GSI August 2012 data");
00341             TGo4Log::Info("Output Tree created in %s", gDirectory->GetPath());
00342          } // if( 0 == TGo4Analysis::Instance()->GetTree( "GsiAug12" ) )
00343             else
00344             {
00345                cleanTree = TGo4Analysis::Instance()->GetTree( "GsiAug12" );
00346                TGo4Log::Info("Output Tree recovered from Go4");
00347             } // else of if( 0 == TGo4Analysis::Instance()->GetTree( "GsiAug12" ) )
00348 
00349          // To prevent having multiple trees when opening the file with Go4 -> Not right solution
00350 //         cleanTree->SetAutoFlush(0);
00351 
00352          // Data from CAEN v1290 & Lecroy QDC VME boards (triggered)
00353 #if defined(ROOTCONV_WITHGET4) || defined(ROOTCONV_WITHHODO)
00354          if( kFALSE == fRocPar->noTrigger )
00355 #endif
00356          {
00357             if( -1 != fRootConvPar->iReferenceTdc && -1 != fRootConvPar->iReferenceChannel1 && 1 == fRootConvPar->uAddGet4DataInTree )
00358             {
00359                cleanTree->Branch("CaenRef1_Leading",
00360                                  &((fCrateInputEvent->fMtdc[fRootConvPar->iReferenceTdc]).lead[fRootConvPar->iReferenceChannel1]),
00361                                  "CaenRef1_Leading/I" );
00362                cleanTree->Branch("CaenRef1_Trailing",
00363                                  &((fCrateInputEvent->fMtdc[fRootConvPar->iReferenceTdc]).trail[fRootConvPar->iReferenceChannel1]),
00364                                  "CaenRef1_Trailing/I" );
00365             } // if( -1 != fRootConvPar->iReferenceTdc && -1 != fRootConvPar->iReferenceChannel && 1 == fRootConvPar->uAddGet4DataInTree )
00366             if( -1 != fRootConvPar->iReferenceTdc && -1 != fRootConvPar->iReferenceChannel2 && 1 == fRootConvPar->uAddGet4DataInTree )
00367             {
00368                cleanTree->Branch("CaenRef2_Leading",
00369                                  &((fCrateInputEvent->fMtdc[fRootConvPar->iReferenceTdc]).lead[fRootConvPar->iReferenceChannel2]),
00370                                  "CaenRef2_Leading/I" );
00371                cleanTree->Branch("CaenRef2_Trailing",
00372                                  &((fCrateInputEvent->fMtdc[fRootConvPar->iReferenceTdc]).trail[fRootConvPar->iReferenceChannel2]),
00373                                  "CaenRef2_Trailing/I" );
00374             } // if( -1 != fRootConvPar->iReferenceTdc && -1 != fRootConvPar->iReferenceChannel && 1 == fRootConvPar->uAddGet4DataInTree )
00375             
00376             if( 1 == fRootConvPar->uCaenMode )
00377             {
00378                for( Int_t iCaenBoard = 0; iCaenBoard<MAX_1290; iCaenBoard ++)
00379                   if( 1 == fRootConvPar->uGeneralCaenTdcEnabled[iCaenBoard])
00380                   {
00381                      cleanTree->Branch(Form("Caen%d_TriggerTime", iCaenBoard),  
00382                                        &( (fCrateInputEvent->fMtdc[iCaenBoard]).extended_trigger_time ),
00383                                        Form("Caen%d_TriggerTime/I", iCaenBoard )  );
00384                                        
00385                      // The multiple hits array for CAEN v1290 now also include first hit
00386                      // => either add to tree the first hit or add to tree only the multiple hit array
00387                      if( 1 == fRootConvPar->uCaenMulti )
00388                      {
00389                cleanTree->Branch(Form("Caen%d_Leading_NbHit", iCaenBoard), 
00390                                  (fCrateInputEvent->fMtdc[iCaenBoard]).hit_lead,
00391                                  Form("Caen%d_Leading_NbHit[%u]/I", iCaenBoard, T1290Data::NumChan ) );
00392                cleanTree->Branch(Form("Caen%d_Trailing_NbHit", iCaenBoard), 
00393                                  (fCrateInputEvent->fMtdc[iCaenBoard]).hit_trail,
00394                                  Form("Caen%d_Trailing_NbHit[%u]/I", iCaenBoard, T1290Data::NumChan ) );
00395                cleanTree->Branch(Form("Caen%d_Leading_multi", iCaenBoard),  
00396                                  (fCrateInputEvent->fMtdc[iCaenBoard]).lead_multi,
00397                                  Form("Caen%d_Leading_multi[%u][%u]/I", iCaenBoard, T1290Data::NumChan, T1290Data::MaxHits )  );
00398                cleanTree->Branch(Form("Caen%d_Trailing_multi", iCaenBoard), 
00399                                  (fCrateInputEvent->fMtdc[iCaenBoard]).trail_multi,
00400                                  Form("Caen%d_Trailing_multi[%u][%u]/I", iCaenBoard, T1290Data::NumChan, T1290Data::MaxHits ) );
00401                      } // if( 1 == fRootConvPar->uCaenMulti )
00402                         else
00403                         {
00404                      cleanTree->Branch(Form("Caen%d_Leading", iCaenBoard),  
00405                                        (fCrateInputEvent->fMtdc[iCaenBoard]).lead,
00406                                        Form("Caen%d_Leading[%u]/I", iCaenBoard, T1290Data::NumChan )  );
00407                      cleanTree->Branch(Form("Caen%d_Trailing", iCaenBoard), 
00408                                        (fCrateInputEvent->fMtdc[iCaenBoard]).trail,
00409                                        Form("Caen%d_Trailing[%u]/I", iCaenBoard, T1290Data::NumChan ) );
00410                         } // else of if( 1 == fRootConvPar->uCaenMulti )
00411                   } // if( 1 == fRootConvPar->uGeneralCaenTdcEnabled[iCaenBoard])
00412             } // if( 1 == fRootConvPar->uCaenMode )
00413             
00414             if( -1 != fRootConvPar->iPmtTdc && 0 == fRootConvPar->uCaenMode)
00415             {
00416                cleanTree->Branch("PmtTdc_Leading",  (fCrateInputEvent->fMtdc[fRootConvPar->iPmtTdc]).lead,
00417                                  Form("PmtTdc_Leading[%u]/I", T1290Data::NumChan )  );
00418                cleanTree->Branch("PmtTdc_Trailing", (fCrateInputEvent->fMtdc[fRootConvPar->iPmtTdc]).trail,
00419                                  Form("PmtTdc_Trailing[%u]/I", T1290Data::NumChan ) );
00420                cleanTree->Branch("PmtTdc_Leading_NbHit", (fCrateInputEvent->fMtdc[fRootConvPar->iPmtTdc]).hit_lead,
00421                                     Form("PmtTdc_Leading_NbHit[%u]/I", T1290Data::NumChan ) );
00422                cleanTree->Branch("PmtTdc_Trailing_NbHit", (fCrateInputEvent->fMtdc[fRootConvPar->iPmtTdc]).hit_trail,
00423                                  Form("PmtTdc_Trailing_NbHit[%u]/I", T1290Data::NumChan ) );
00424                cleanTree->Branch("PmtTdc_Leading_multi",  (fCrateInputEvent->fMtdc[fRootConvPar->iPmtTdc]).lead_multi,
00425                                  Form("PmtTdc_Leading_multi[%u][%u]/I", T1290Data::NumChan, T1290Data::MaxHits )  );
00426                cleanTree->Branch("PmtTdc_Trailing_multi", (fCrateInputEvent->fMtdc[fRootConvPar->iPmtTdc]).trail_multi,
00427                                  Form("PmtTdc_Trailing_multi[%u][%u]/I", T1290Data::NumChan, T1290Data::MaxHits ) );
00428             } // if( -1 != fRootConvPar->iPmtTdc )
00429             if( -1 != fRootConvPar->iRpcTdcLeading && -1 != fRootConvPar->iRpcTdcTrailing && 0 == fRootConvPar->uCaenMode )
00430             {
00431                cleanTree->Branch("CaenRpc_Leading",  (fCrateInputEvent->fMtdc[fRootConvPar->iRpcTdcLeading]).lead,
00432                                  Form("CaenRpc_Leading[%u]/I", T1290Data::NumChan )  );
00433                cleanTree->Branch("CaenRpc_Trailing", (fCrateInputEvent->fMtdc[fRootConvPar->iRpcTdcTrailing]).trail,
00434                                  Form("CaenRpc_Trailing[%u]/I", T1290Data::NumChan ) );
00435                cleanTree->Branch("CaenRpc_Leading_NbHit", (fCrateInputEvent->fMtdc[fRootConvPar->iRpcTdcLeading]).hit_lead,
00436                                     Form("CaenRpc_Leading_NbHit[%u]/I", T1290Data::NumChan ) );
00437                cleanTree->Branch("CaenRpc_Trailing_NbHit", (fCrateInputEvent->fMtdc[fRootConvPar->iRpcTdcTrailing]).hit_trail,
00438                                  Form("CaenRpc_Trailing_NbHit[%u]/I", T1290Data::NumChan ) );
00439                cleanTree->Branch("CaenRpc_Leading_multi",  (fCrateInputEvent->fMtdc[fRootConvPar->iRpcTdcLeading]).lead_multi,
00440                                  Form("CaenRpc_Leading_multi[%u][%u]/I", T1290Data::NumChan, T1290Data::MaxHits )  );
00441                cleanTree->Branch("CaenRpc_Trailing_multi", (fCrateInputEvent->fMtdc[fRootConvPar->iRpcTdcTrailing]).trail_multi,
00442                                  Form("CaenRpc_Trailing_multi[%u][%u]/I", T1290Data::NumChan, T1290Data::MaxHits ) );
00443             } // if( -1 != fRootConvPar->iRpcTdcLeading && -1 != fRootConvPar->iRpcTdcTrailing && 0 == fRootConvPar->uCaenMode )
00444             
00445             if( -1 != fRootConvPar->iPmtQdc )
00446             {
00447                cleanTree->Branch("PmtQdc", fCrateInputEvent->fData1182[fRootConvPar->iPmtQdc], Form("PmtQdc[%u]/s", NUM_1182_CH ) );
00448             } // if( -1 != fRootConvPar->iPmtQdc )
00449 
00450             if( 1 == fRootConvPar->uTriglogInputInTree)
00451             {
00452                cleanTree->Branch("TriglogSyncNb",  &(fTriglogInputEvent->fVulomSyncNumber),
00453                                  "TriglogSyncNb/i"  );
00454                cleanTree->Branch("TriglogPattern",  &(fTriglogInputEvent->fVulomTriggerPattern),
00455                                  "TriglogPattern/i"  );
00456                cleanTree->Branch("TriglogTimeSec",  &(fTriglogInputEvent->fMbsTimeSecs),
00457                                  "TriglogTimeSec/i"  );
00458                cleanTree->Branch("TriglogTimeMilsec",  &(fTriglogInputEvent->fMbsTimeMillisec),
00459                                  "TriglogTimeMilsec/i"  );
00460                cleanTree->Branch("TriglogScalers1",  (fTriglogInputEvent->fVulomScaler[0]),
00461                                  Form("TriglogScalers1[%u]/i", N_SCALERS_CH )  );
00462                cleanTree->Branch("TriglogScalers2",  (fTriglogInputEvent->fVulomScaler[1]),
00463                                  Form("TriglogScalers2[%u]/i", N_SCALERS_CH )  );
00464                cleanTree->Branch("TriglogScalers3",  (fTriglogInputEvent->fVulomScaler[2]),
00465                                  Form("TriglogScalers3[%u]/i", N_SCALERS_CH )  );
00466             } // if( 1 == fRootConvPar->uTriglogInputInTree)
00467             if( 1 == fRootConvPar->uVftxInTree)
00468             {
00469                for( Int_t iVftxBoard = 0; iVftxBoard<MAX_FPGA_TDC; iVftxBoard ++)
00470                   if( 1 == fRootConvPar->uVftxEnabled[iVftxBoard])
00471                   {
00472                      TString sBrNameTrigg  = Form("Vftx%dTriggerTime", iVftxBoard);
00473                      TString sBrNameMulti  = Form("Vftx%dMultiplicity", iVftxBoard);
00474                      TString sBrNameFineT  = Form("Vftx%dFineTime", iVftxBoard);
00475                      TString sBrNameCoarT  = Form("Vftx%dCoarseTime", iVftxBoard);
00476                      TString sBrNameFutuB  = Form("Vftx%dFutureBit", iVftxBoard);
00477                      TString sBrNameTimeC  = Form("Vftx%dTimeCorr", iVftxBoard);
00478                      TString sBrNameFtCorr = Form("Vftx%dFineTimeCorr", iVftxBoard);
00479 
00480                cleanTree->Branch( sBrNameTrigg,  &((fVftxInputEvent->fVftxBoards[iVftxBoard]).iTriggerTime),
00481                                   sBrNameTrigg + "/I" );
00482                cleanTree->Branch( sBrNameMulti,  ((fVftxInputEvent->fVftxBoards[iVftxBoard]).iMultiplicity),
00483                                   sBrNameMulti + Form("[%u]/I", FPGA_TDC_NBCHAN )  );
00484                      if( 1 == fRootConvPar->uVftxFullDataMode )
00485                      {
00486                cleanTree->Branch( sBrNameFineT,  ((fVftxInputEvent->fVftxBoards[iVftxBoard]).iFineTime),
00487                                   sBrNameFineT + Form("[%u][%u]/I", FPGA_TDC_NBCHAN, TVftxBoardData::MaxMult )  );
00488                cleanTree->Branch( sBrNameCoarT,  ((fVftxInputEvent->fVftxBoards[iVftxBoard]).iCoarseTime),
00489                                   sBrNameCoarT + Form("[%u][%u]/I", FPGA_TDC_NBCHAN, TVftxBoardData::MaxMult )  );
00490                cleanTree->Branch( sBrNameFutuB,  ((fVftxInputEvent->fVftxBoards[iVftxBoard]).uFutureBit),
00491                                   sBrNameFutuB + Form("[%u][%u]/i", FPGA_TDC_NBCHAN, TVftxBoardData::MaxMult )  );
00492                cleanTree->Branch( sBrNameFtCorr,  ((fVftxInputEvent->fVftxBoards[iVftxBoard]).dFineTimeCorr),
00493                                   sBrNameFtCorr + Form("[%u][%u]/D", FPGA_TDC_NBCHAN, TVftxBoardData::MaxMult )  );
00494                      } //if( 1 == fRootConvPar->uVftxFullDataMode )
00495 
00496                cleanTree->Branch( sBrNameTimeC,  ((fVftxInputEvent->fVftxBoards[iVftxBoard]).dTimeCorr),
00497                                   sBrNameTimeC + Form("[%u][%u]/D", FPGA_TDC_NBCHAN, TVftxBoardData::MaxMult )  );
00498                   } // if( 1 == fRootConvPar->uVftxEnabled[iVftxBoard])
00499             } // if( 1 == fRootConvPar->uVftxInTree)
00500             if( 1 == fRootConvPar->uScalOrMuInTree)
00501             {
00502                cleanTree->Branch("ScalOrMuScalers",  (fCrateInputEvent->fScalOrMu).uScaler,
00503                                  Form("ScalOrMuScalers[%u]/i", SCALORMU_NB_SCAL )  );
00504             } // if( 1 == fRootConvPar->uVftxInTree)
00505          } // if( kFALSE == fRocPar->noTrigger )
00506          
00507 #ifdef ROOTCONV_WITHHODO
00508          if( 1 == fRootConvPar->uHodoInputInTree )
00509          {
00510             cleanTree->Branch("HodoscopeX",  &(hitHodoscope.X),"HodoscopeX/D");
00511             cleanTree->Branch("HodoscopeY",  &(hitHodoscope.Y),"HodoscopeY/D");
00512          } // if( 1 == fRootConvPar->uHodoInputInTree )
00513 #endif
00514 
00515          if( 1 == fRootConvPar->uSlowControlInTree )
00516          {
00517             uSlowControlUpdateTime = 0;
00518             cleanTree->Branch( "TimeEpicsUpdate", &(uSlowControlUpdateTime),
00519                                "TimeEpicsUpdate/i"  );
00520             vdPositiveHvI.clear();
00521             vdPositiveHvU.clear();
00522             vdNegativeHvI.clear();
00523             vdNegativeHvU.clear();
00524             vdPositiveHvI.resize(fRootConvPar->uNbSlowControlChan);
00525             vdPositiveHvU.resize(fRootConvPar->uNbSlowControlChan);
00526             vdNegativeHvI.resize(fRootConvPar->uNbSlowControlChan);
00527             vdNegativeHvU.resize(fRootConvPar->uNbSlowControlChan);
00528             for( UInt_t uChannelHV = 0; uChannelHV < fRootConvPar->uNbSlowControlChan; uChannelHV++)
00529             {
00530                cleanTree->Branch( fRootConvPar->sScOutputNamePosI[uChannelHV], &(vdPositiveHvI.at(uChannelHV)),
00531                                  fRootConvPar->sScOutputNamePosI[uChannelHV] + Form("/D" )  );
00532                cleanTree->Branch( fRootConvPar->sScOutputNamePosU[uChannelHV], &(vdPositiveHvU.at(uChannelHV)),
00533                                  fRootConvPar->sScOutputNamePosU[uChannelHV] + Form("/D" )  );
00534                cleanTree->Branch( fRootConvPar->sScOutputNameNegI[uChannelHV], &(vdNegativeHvI.at(uChannelHV)),
00535                                  fRootConvPar->sScOutputNameNegI[uChannelHV] + Form("/D" )  );
00536                cleanTree->Branch( fRootConvPar->sScOutputNameNegU[uChannelHV], &(vdNegativeHvU.at(uChannelHV)),
00537                                  fRootConvPar->sScOutputNameNegU[uChannelHV] + Form("/D" )  );
00538                vdPositiveHvI.at(uChannelHV) = 0;
00539                vdPositiveHvU.at(uChannelHV) = 0;
00540                vdNegativeHvI.at(uChannelHV) = 0;
00541                vdNegativeHvU.at(uChannelHV) = 0;
00542             } // for( UInt_t uChannelHV = 0; uChannelHV < fRootConvPar->uNbSlowControlChan; uChannelHV++)
00543          } // if( 1 == fRootConvPar->uSlowControlInTree )
00544 
00545 #ifdef ROOTCONV_WITHGET4
00546          if( 1 == fRootConvPar->uAddGet4DataInTree )
00547          {
00548             // Data from Get4-Roc
00549             vuHitNumber = new std::vector< UInt_t >;
00550             vuHitNumber->resize( fRocPar->uNbFeets*8 );
00551 
00552             vuTime      = new std::vector< std::vector< UInt_t > >;
00553             vuEpochTime = new std::vector< std::vector< UInt_t > >;
00554             viTot       = new std::vector< std::vector<  Int_t > >;
00555 
00556             vuTime->resize(      fRocPar->uNbFeets*8 );
00557             vuEpochTime->resize( fRocPar->uNbFeets*8 );
00558             viTot->resize(       fRocPar->uNbFeets*8 );
00559 
00560             for( UInt_t uChannelTemp = 0; uChannelTemp < fRocPar->uNbFeets*8; uChannelTemp++)
00561             {
00562                (*vuHitNumber)[uChannelTemp]  = 0;
00563                (*vuTime)[uChannelTemp].clear();
00564                (*vuEpochTime)[uChannelTemp].clear();
00565                (*viTot)[uChannelTemp].clear();
00566             }
00567 
00568             cleanTree->Bronch( "vuHitNumber",     "std::vector< UInt_t >",   &vuHitNumber );
00569             cleanTree->Bronch( "get4_time",       "std::vector< std::vector< UInt_t > >", &(vuTime) );
00570             cleanTree->Bronch( "get4_epoch_time", "std::vector< std::vector< UInt_t > >", &(vuEpochTime) );
00571             cleanTree->Bronch( "get4_tot",        "std::vector< std::vector<  Int_t > >", &(viTot) );
00572          }
00573 #endif
00574 
00575          cleanTree->SetDirectory(gDirectory);
00576 
00577          if( 1 == fRootConvPar->uRootDisplay && 0 == TGo4Analysis::Instance()->GetTree( "GsiAug12" ))
00578          {
00579             TGo4Analysis::Instance()->AddTree(cleanTree );
00580             TGo4Log::Info("Root Tree registered in Go4: %p", TGo4Analysis::Instance()->GetTree( "GsiAug12" ) );
00581          }
00582       } // if( 0 == cleanTree)
00583    } // if( 1 == fRootConvPar->uCleanOuputEnable || 1 == fRootConvPar->uRootDisplay)
00584 }
00585 
00586 
00587 void TRootConverterProc::FinalizeEvent()
00588 {
00589    if( 0 == fRootConvPar->uCleanOuputEnable && 0 == fRootConvPar->uRootDisplay)
00590          return;
00591    if( 0 == fRootConvPar->uCleanOuputEnable && 1 == fRootConvPar->uRootDisplay &&
00592        fRootConvPar->uEventsUntilReset <= cleanTree->GetEntries())
00593       cleanTree->Reset("");
00594         //if(!fRpcInputEvent->IsValid() &&  1 == fRootConvPar->uAddGet4DataInTree) return; // skip incomplete rpc events from second step
00595    if(!fCrateInputEvent->IsValid() ) return; // skip incomplete mbs events from first step
00596    if( 1 == fRootConvPar->uTriglogInputInTree )
00597       if( !fTriglogInputEvent->IsValid() )
00598          return; // skip incomplete triglog events from first step
00599    if( 1 == fRootConvPar->uVftxInTree )
00600       if( !fVftxInputEvent->IsValid() )
00601          cout<<"Invalid VFTX event! event "<<uNbEvents<<endl;
00602 
00603    //Fill FEET rocs data:
00604 #ifdef ROOTCONV_WITHGET4
00605    Bool_t bTestAllValid = kTRUE;
00606    if( (1 == fRootConvPar->uCleanOuputEnable || 1 == fRootConvPar->uRootDisplay) && 1 == fRootConvPar->uAddGet4DataInTree )
00607    {
00608       if( kFALSE == FillHitsFromRoc( ) )
00609       {
00610          bTestAllValid = kFALSE;
00611 
00612          for( UInt_t uChannelTemp = 0; uChannelTemp < fRocPar->uNbFeets*8; uChannelTemp++)
00613          {
00614             (*vuHitNumber)[uChannelTemp]  = 0;
00615             (*vuTime)[uChannelTemp].clear();
00616             (*vuEpochTime)[uChannelTemp].clear();
00617             (*viTot)[uChannelTemp].clear();
00618          } // for( UInt_t uChannelTemp = 0; uChannelTemp < fRocPar->uNbFeets*8; uChannelTemp++)
00619       } // if( kFALSE == FillHitsFromRoc( ) )
00620    } //  if( (1 == fRootConvPar->uCleanOuputEnable || 1 == fRootConvPar->uRootDisplay) && 1 == fRootConvPar->uAddGet4DataInTree )
00621 #endif
00622 
00623 
00624    uNbEvents++;
00625 
00626    // Fill the tree
00627    if( ( 1 == fRootConvPar->uCleanOuputEnable || 1 == fRootConvPar->uRootDisplay) )
00628    {
00629 #ifdef ROOTCONV_WITHHODO
00630       if( 1 == fRootConvPar->uHodoInputInTree )
00631       {
00632          if( 1 == fRootConvPar->uHodoDebugHisto)
00633             hNbClustersPerEventHodoscope->Fill( fHodoInputEvent->NumHits() );
00634 
00635          if( 0 < fHodoInputEvent->NumHits() )
00636          {
00637             hitHodoscope = fHodoInputEvent->Hit(0);
00638             if( 1 == fRootConvPar->uTriglogInputInTree && 1 == fRootConvPar->uHodoDebugHisto )
00639             {
00640                if( 0 == uFirstMbsTime)
00641                {
00642                   uFirstMbsTime = fTriglogInputEvent->fMbsTimeSecs;
00643                   uSpillStartMbsTime = fTriglogInputEvent->fMbsTimeSecs- uFirstMbsTime;
00644                   uLastMbsTime = fTriglogInputEvent->fMbsTimeSecs;
00645 
00646                   uFirstMbsTimeMs = fTriglogInputEvent->fMbsTimeMillisec;
00647                   uSpillStartMbsTimeMs = fTriglogInputEvent->fMbsTimeMillisec- uFirstMbsTimeMs;
00648                }
00649 
00650                hHit2DvsSeconds->Fill( fTriglogInputEvent->fMbsTimeSecs - uFirstMbsTime,
00651                      fHodoInputEvent->Hit(0).X, fHodoInputEvent->Hit(0).Y);
00652 
00653                if( 20 < fTriglogInputEvent->fMbsTimeSecs - uLastMbsTime )
00654                {
00655                   uSpillStartMbsTime = fTriglogInputEvent->fMbsTimeSecs - uFirstMbsTime;
00656                   uSpillStartMbsTimeMs = fTriglogInputEvent->fMbsTimeMillisec - uFirstMbsTimeMs;
00657                }
00658 
00659                hHit2DvsSecondsInSpill->Fill(
00660                      fTriglogInputEvent->fMbsTimeSecs - uFirstMbsTime - uSpillStartMbsTime,
00661                      fHodoInputEvent->Hit(0).X, fHodoInputEvent->Hit(0).Y);
00662 
00663                hHit2DvsMilliSecondsInSpill->Fill(
00664                      (fTriglogInputEvent->fMbsTimeSecs - uFirstMbsTime - uSpillStartMbsTime)*1000 +
00665                      fTriglogInputEvent->fMbsTimeMillisec - uFirstMbsTimeMs - uSpillStartMbsTimeMs,
00666                      fHodoInputEvent->Hit(0).X, fHodoInputEvent->Hit(0).Y);
00667 
00668                hHitXvsMilliSecondsInSpill->Fill(
00669                      (fTriglogInputEvent->fMbsTimeSecs - uFirstMbsTime - uSpillStartMbsTime)*1000 +
00670                      fTriglogInputEvent->fMbsTimeMillisec - uFirstMbsTimeMs - uSpillStartMbsTimeMs,
00671                      fHodoInputEvent->Hit(0).X );
00672                hHitYvsMilliSecondsInSpill->Fill(
00673                      (fTriglogInputEvent->fMbsTimeSecs - uFirstMbsTime - uSpillStartMbsTime)*1000 +
00674                      fTriglogInputEvent->fMbsTimeMillisec - uFirstMbsTimeMs - uSpillStartMbsTimeMs,
00675                      fHodoInputEvent->Hit(0).Y );
00676 
00677                uLastMbsTime  = fTriglogInputEvent->fMbsTimeSecs;
00678 
00679             } // if( 1 == fRootConvPar->uTriglogInputInTree && 1 == fRootConvPar->uHodoDebugHisto )
00680          } // if( 0 < fHodoInputEvent->NumHits() )
00681       } // if( 1 == fRootConvPar->uHodoInputInTree )
00682 #endif
00683       if( 1 == fRootConvPar->uSlowControlInTree )
00684       {
00685          if( kTRUE == fEpicsInputEvent->IsValid() )
00686          {
00687             TString sVariableName = "";
00688             if( 0 == uEpicsTimeOrigin )
00689                uEpicsTimeOrigin = fEpicsInputEvent->fUTimeSeconds;
00690             hTimeEpicsUpdates->Fill( (fEpicsInputEvent->fUTimeSeconds )% 1000);
00691             uSlowControlUpdateTime = fEpicsInputEvent->fUTimeSeconds;
00692             for(UInt_t uEpicsVariableIndex = 0; uEpicsVariableIndex < fEpicsInputEvent->GetNumDoubles(); uEpicsVariableIndex++ )
00693             {
00694                sVariableName = fEpicsInputEvent->GetDoubleName( uEpicsVariableIndex );
00695                for( UInt_t uChannelHV = 0; uChannelHV < fRootConvPar->uNbSlowControlChan; uChannelHV++)
00696                {
00697                   if( sVariableName == fRootConvPar->sScInputNamePosI[uChannelHV])
00698                   {
00699                      vdPositiveHvI.at(uChannelHV) = fEpicsInputEvent->GetDouble(uEpicsVariableIndex);
00700                      break;
00701                   }
00702                   if( sVariableName == fRootConvPar->sScInputNamePosU[uChannelHV])
00703                   {
00704                      vdPositiveHvU.at(uChannelHV) = fEpicsInputEvent->GetDouble(uEpicsVariableIndex);
00705                      break;
00706                   }
00707                   if( sVariableName == fRootConvPar->sScInputNameNegI[uChannelHV])
00708                   {
00709                      vdNegativeHvI.at(uChannelHV) = fEpicsInputEvent->GetDouble(uEpicsVariableIndex);
00710                      break;
00711                   }
00712                   if( sVariableName == fRootConvPar->sScInputNameNegU[uChannelHV])
00713                   {
00714                      vdNegativeHvU.at(uChannelHV) = fEpicsInputEvent->GetDouble(uEpicsVariableIndex);
00715                      break;
00716                   }
00717                } //  for( UInt_t uChannelHV = 0; uChannelHV < fRootConvPar->uNbSlowControlChan; uChannelHV++)
00718             } // for(UInt_t uEpicsVariableIndex = 0; uEpicsVariableIndex < fEpicsInputEvent->GetNumDoubles(); uEpicsVariableIndex++ )
00719          } // if( kTRUE == fEpicsInputEvent->IsValid() )
00720       } // if( 1 == fRootConvPar->uSlowControlInTree )
00721 
00722       cleanTree->Fill();
00723 #ifdef ROOTCONV_WITHGET4
00724       if( 1 == fRootConvPar->uAddGet4DataInTree )
00725       {
00726          for( UInt_t uChannelTemp = 0; uChannelTemp < fRocPar->uNbFeets*8; uChannelTemp++)
00727          {
00728             (*vuHitNumber)[uChannelTemp]  = 0;
00729             (*vuTime)[uChannelTemp].clear();
00730             (*vuEpochTime)[uChannelTemp].clear();
00731             (*viTot)[uChannelTemp].clear();
00732          } // for( UInt_t uChannelTemp = 0; uChannelTemp < fRocPar->uNbFeets*8; uChannelTemp++)
00733       } // if( 1 == fRootConvPar->uAddGet4DataInTree )
00734 #endif
00735    } // if( ( 1 == fRootConvPar->uCleanOuputEnable || 1 == fRootConvPar->uRootDisplay) )
00736 
00737    fOutputEvent->SetValid(kTRUE);
00738 }
00739 
00740 #ifdef ROOTCONV_WITHGET4
00741 Bool_t TRootConverterProc::FillHitsFromRoc()
00742 {
00743    TGet4HitUnpacked hitTemp;
00744    
00745    if(!fRpcInputEvent->IsValid())
00746       return kFALSE;
00747 
00748    for( Int_t iHitIndex = 0; iHitIndex < (Int_t)((fRpcInputEvent->fUnpackedHits).size()); iHitIndex ++)
00749    {
00750       hitTemp = (fRpcInputEvent->fUnpackedHits).at(iHitIndex);
00751       // Fill root tree
00752       UInt_t uFullChan = hitTemp.GetFullChan();
00753       (*vuHitNumber)[uFullChan] ++;
00754       (*vuTime)[uFullChan].push_back( hitTemp.GetTsLeading() );
00755       (*vuEpochTime)[uFullChan].push_back( hitTemp.GetEpochLeading() );
00756       (*viTot)[uFullChan].push_back( hitTemp.GetRawTOT() );
00757    }
00758 
00759    return kTRUE;
00760 }
00761 #endif

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