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

beamtime/cosy-jan12/go4/TBeamMonitorProc.cxx (r4864/r3159)

Go to the documentation of this file.
00001 #include "TBeamMonitorProc.h"
00002 #include "TGo4Version.h"
00003 #if __GO4BUILDVERSION__ > 40502
00004 #include "go4iostream.h"
00005 #else
00006 #include "Riostream.h"
00007 #endif
00008 #include "TTimeStamp.h"
00009 #include "TSystem.h"
00010 #include "TROOT.h"
00011 #include "TGo4Log.h"
00012 
00013 #include "TGo4UserException.h"
00014 #include "TGo4MbsEvent.h"
00015 #include "roc/Message.h"
00016 #include "roc/Board.h"
00017 
00018 
00019 TBeamMonitorProc::TBeamMonitorProc(const char* name) :
00020 TCBMBeamtimeProc(name),
00021 fCrateInputEvent(0),
00022 fRocInputEvent(0),
00023 fEpicsInputEvent(0),
00024 fOutputEvent(0)
00025 {
00026    cout << "**** TBeamMonitorProc: Create instance " << name << endl;
00027    TString obname, obtitle;
00028 
00029    fPar = (TBeamMonitorParam*) MakeParameter("BeamMonitorPar", "TBeamMonitorParam");
00030 
00031    TString setupmacro = "set_BeamMonitorPar.C";
00032    if (!gSystem->AccessPathName(setupmacro.Data())) {
00033       TGo4Log::Info("Executing beam monitor condition setup script %s", setupmacro.Data());
00034       gROOT->ProcessLine(Form(".x %s", setupmacro.Data()));
00035 
00036    } else {
00037       TGo4Log::Info("NO beam monitor  setup script %s. Use previous values!", setupmacro.Data());
00038    }
00039 
00040    // fCh_Pb = MakeTH2('I', "BeamMonitor/Ch1_Pb", "Cherenkov - Pb", 512, 0., 4096., 512, 0., 4096., "Cherenkov1", "Pb");
00041 
00042    fPmtDiff = MakeTH1('I', "BeamMonitor/PmtDiff", "Time difference between TDC[5][2] and TDC[5][3]", 4096, -2048, +2048, "time");
00043 
00044    // following is for slow control display:
00045    //   fMotorPos = MakeTH2('I', Form("EPICS/MotorPosition"), Form("GEM Motor"),
00046    //         60, 0, 300, 60, 0, 300, "X (mm)", "Y (mm)");
00047    //   fRoluPos = MakeTH2('I', Form("EPICS/ROLUPosition"), Form("Rolu positions"),
00048    //         35, 0, 35, 35, 0, 35, "X (mm)", "Y (mm)");
00049 
00050    printf("TBeamMonitorProc Histograms created \n");
00051    fflush ( stdout);
00052 }
00053 
00054 
00055 TBeamMonitorProc::~TBeamMonitorProc()
00056 {
00057 }
00058 
00059 
00060 
00061 void TBeamMonitorProc::InitEvent(TGo4EventElement* outevnt)
00062 {
00063    // first assign input event:
00064    // since input event object is never discarded within processor lifetime,
00065    // we just search for subevent by name once to speed up processing
00066    if(fCrateInputEvent==0)
00067    {
00068       TCBMBeamtimeEvent* btevent=dynamic_cast<TCBMBeamtimeEvent*>(GetInputEvent());
00069       if(btevent)
00070       {
00071          fCrateInputEvent=dynamic_cast<TMbsCrateEvent*>(btevent->GetSubEvent("MBSCRATE"));
00072          fRocInputEvent=dynamic_cast<TRocEvent*>(btevent->GetSubEvent("ROC"));
00073          fEpicsInputEvent=dynamic_cast<TEpicsEvent*>(btevent->GetSubEvent("EPICS"));
00074       }
00075       else
00076       {
00077          fCrateInputEvent=dynamic_cast<TMbsCrateEvent*>(GetInputEvent());
00078 
00079       }
00080       if(fCrateInputEvent==0) {
00081          GO4_STOP_ANALYSIS_MESSAGE("**** TBeamMonitorProc: Fatal error: no input event TMbsCrateEvent!!! STOP GO4");
00082       }
00083       if(fRocInputEvent==0) {
00084          GO4_STOP_ANALYSIS_MESSAGE("**** TBeamMonitorProc: Fatal error: no input event TRocEvent!!! STOP GO4");
00085       }
00086       if(fEpicsInputEvent==0) {
00087          Message(2,"**** TBeamMonitorProc: could not find TEpicsEvent!"); // but do not stop...
00088       }
00089 
00090    }
00091    // then assign output event
00092    // since output event object is never discarded within processor lifetime,
00093    // we just search for subevent by name once to speed up processing
00094    if(fOutputEvent==0)
00095    {
00096       TCBMBeamtimeEvent* btevent=dynamic_cast<TCBMBeamtimeEvent*>(outevnt);
00097       if(btevent)
00098       {
00099          fOutputEvent=dynamic_cast<TBeamMonitorEvent*>(btevent->GetSubEvent("BEAM"));
00100       }
00101       else
00102       {
00103          fOutputEvent= dynamic_cast<TBeamMonitorEvent*>(outevnt);
00104       }
00105       if(fOutputEvent==0) {
00106          GO4_STOP_ANALYSIS_MESSAGE("**** TBeamMonitorProc: Fatal error: output event is not a TBeamMonitorEvent!!! STOP GO4");
00107       }
00108    }
00109 }
00110 
00111 
00112 
00113 void TBeamMonitorProc::FinalizeEvent()
00114 {
00115    if(fCrateInputEvent && fCrateInputEvent->IsValid())
00116    {
00117       fPmtDiff->Fill(fCrateInputEvent->fMtdc[5].lead[2] - fCrateInputEvent->fMtdc[5].lead[3]);
00118 
00119       // fCh_Pb->Fill(fCrateInputEvent->fData1182[1][0], fCrateInputEvent->fData1182[1][5]);
00120 
00121       // fOutputEvent->fIsPion = fPionCond->Test(fCrateInputEvent->fData1182[1][0], fCrateInputEvent->fData1182[1][5]);
00122    }
00123 
00124    if( 0 && fEpicsInputEvent && fEpicsInputEvent->IsValid()) // check if new update has been done
00125    {
00126       // TODO: put reasonable display of interesting slow control variables here
00127 
00128 
00129 
00130       // the following is example from cosy december 2010 beamtime
00131       // note access to EPICS process variables by full name here
00132       /*     int motorx = fEpicsInputEvent->GetDouble("CBM:MOTOR:GETPOSX");
00133      int motory = fEpicsInputEvent->GetDouble("CBM:MOTOR:GETPOSY");
00134      int rolu_left = fEpicsInputEvent->GetDouble("CBM:rolu:step_to_mm_L");
00135      int rolu_right = fEpicsInputEvent->GetDouble("CBM:rolu:step_to_mm_R");
00136      int rolu_up = fEpicsInputEvent->GetDouble("CBM:rolu:step_to_mm_O");
00137      int rolu_down = fEpicsInputEvent->GetDouble("CBM:rolu:step_to_mm_U");
00138 
00139      fMotorPos->SetTitle(
00140            Form("Motor position, EPICS Time:%s -",
00141                  fEpicsInputEvent->GetUpdateTimeString()));
00142      fMotorPos->Fill(motorx, motory);
00143 
00144      fRoluPos->SetTitle(
00145            Form("ROLU positions, EPICS Time:%s -",
00146                  fEpicsInputEvent->GetUpdateTimeString()));
00147      Int_t roludim = 35;
00148      Int_t middle = roludim / 2;
00149      Int_t displaywidth = 6;
00150      for (int i = 0; i < 2 * displaywidth; ++i) {
00151         fRoluPos->Fill(middle - rolu_left, middle - displaywidth + i);
00152         fRoluPos->Fill(middle + rolu_right, middle - displaywidth + i);
00153         fRoluPos->Fill(middle - displaywidth + i, middle - rolu_down);
00154         fRoluPos->Fill(middle - displaywidth + i, rolu_up + middle);
00155      }
00156        */
00157 
00158    } // end EPICS block
00159 }

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