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

beamtime/cern-oct12/go4/TBeamMonitorProc.cxx (r4864/r3724)

Go to the documentation of this file.
00001 #include "TBeamMonitorProc.h"
00002 #include "TTimeStamp.h"
00003 #include "TSystem.h"
00004 #include "TROOT.h"
00005 #include "TObjString.h"
00006 #include "TGo4Analysis.h"
00007 #include "TGo4MbsFileParameter.h"
00008 #include "TGo4Log.h"
00009 
00010 #include "TGo4UserException.h"
00011 #include "TGo4MbsEvent.h"
00012 #include "roc/Message.h"
00013 #include "roc/Board.h"
00014 #include <fstream>
00015 
00016 TBeamMonitorProc::TBeamMonitorProc() :
00017    TCBMBeamtimeProc(),
00018    fCrateInputEvent(0),
00019    fRocInputEvent(0),
00020    fEpicsInputEvent(0),
00021    fOutputEvent(0)
00022 {
00023 }
00024 
00025 
00026 TBeamMonitorProc::TBeamMonitorProc(const char* name) :
00027    TCBMBeamtimeProc(name),
00028    fCrateInputEvent(0),
00029    fRocInputEvent(0),
00030    fEpicsInputEvent(0),
00031    fOutputEvent(0)
00032 {
00033    TGo4Log::Info("TBeamMonitorProc: Create instance %s", name);
00034    TString obname, obtitle;
00035 
00036    fPar = (TBeamMonitorParam*) MakeParameter("BeamMonitorPar", "TBeamMonitorParam");
00037 
00038    ExecuteScript("set_BeamMonitorPar.C");
00039 
00040    fCh_Pb = MakeTH2('I', "BeamMonitor/Ch1_Pb", "Cherenkov - Pb", 512, 0., 4096., 512, 0., 4096., "Cherenkov1", "Pb");
00041    fCh2_Pb = MakeTH2('I', "BeamMonitor/Ch2_Pb", "Cherenkov2 - Pb", 512, 0., 4096., 512, 0., 4096., "Cherenkov2", "Pb");
00042    fCh1_Ch2 = MakeTH2('I', "BeamMonitor/Ch1_Ch2", "Cherenkov1 - Cherenkov2", 512, 0., 4096., 512, 0., 4096., "Cherenkov1", "Cherenkov2");
00043 
00044    fS1_Pb = MakeTH2('I', "BeamMonitor/S1_Pb", "1182  S1_Pb", 512, 0., 4096., 512, 0., 4096., "S1", "Pb");
00045    fS1_S2 = MakeTH2('I', "BeamMonitor/S1_S2", "1182  S1_S2", 512, 0., 4096., 512, 0., 4096., "S1", "S2");
00046 
00047    TGo4Log::Info("TBeamMonitorProc: histograms created");
00048 
00049    Double_t pion_pnts[3][2] = { {713, 1198}, {815, 826}, {614, 704} };
00050    fPionCond = MakePolyCond("PionCond", 3, pion_pnts);
00051 
00052    Double_t electron_pnts[4][2] = { {834, 1644}, {819, 2041}, {1083, 2102}, {1091, 1704} };
00053    fElectronCond = MakePolyCond("ElectronCond", 4, electron_pnts);
00054 
00055    Double_t muon_pnts[4][2] = { {834, 644}, {819, 1041}, {1083, 1102}, {1091, 704} };
00056    fMuonCond = MakePolyCond("MuonCond", 4, muon_pnts);
00057 
00058    TString path;
00059    if (fPar->UseSettingsTable) {
00060       // first find out name of current event input
00061       TGo4AnalysisStep* firststep = TGo4Analysis::Instance()->GetAnalysisStepNum(0);
00062       if (dynamic_cast<TGo4MbsFileParameter*>(firststep->GetEventSource())) {
00063          TGo4Log::Info("Found name of event source %s", firststep->GetEventSourceName());
00064          // get path to macro from run settings:
00065          //path=GetSetupPath(TString("Be_run2410013")); // test
00066          path = fPar->FindPidForRun(firststep->GetEventSourceName());
00067       } else {
00068          TGo4Log::Info("Eventsource is not a file, ignore setup table!");
00069       }
00070    }
00071 
00072    if (!path.IsNull()) {
00073 
00074       // try several locations of setup macro
00075       TString setupmacro = TString("conditions/") + path;
00076       if (gSystem->AccessPathName(setupmacro.Data())) {
00077          setupmacro = TString("../conditions/") + path;
00078          if (gSystem->AccessPathName(setupmacro.Data())) {
00079             const char* rocsys = gSystem->Getenv("ROCSYS");
00080             if (rocsys!=0)
00081                setupmacro = TString(rocsys) + "/beamtime/cern-oct11/go4/conditions/" + path;
00082          }
00083       }
00084 
00085       if (ExecuteScript(setupmacro.Data()) < 0) {
00086          TGo4Log::Info("NO PID condition setup script %s. Use previous values!", setupmacro.Data());
00087          path.Clear();
00088       }
00089    }
00090 
00091    if (path.IsNull()) {
00092       // old method - via setup script in current directory
00093       ExecuteScript("set_PionCond.C");
00094 
00095       ExecuteScript("set_ElectronCond.C");
00096 
00097       ExecuteScript("set_MyonCond.C");
00098    }
00099 
00100    if (fPar->Cher1ForMuon)
00101       fMuonCond->SetHistogram(fCh_Pb->GetName());
00102    else
00103       fMuonCond->SetHistogram(fCh2_Pb->GetName());
00104 
00105    if (fPar->Cher1ForPion)
00106       fPionCond->SetHistogram(fCh_Pb->GetName());
00107    else
00108       fPionCond->SetHistogram(fCh2_Pb->GetName());
00109 
00110    if (fPar->Cher1ForElectron)
00111       fElectronCond->SetHistogram(fCh_Pb->GetName());
00112    else
00113       fElectronCond->SetHistogram(fCh2_Pb->GetName());
00114 
00115    TGo4Log::Info("TBeamMonitorProc: conditions created");
00116 }
00117 
00118 TBeamMonitorProc::~TBeamMonitorProc()
00119 {
00120 }
00121 
00122 
00123 
00124 void TBeamMonitorProc::InitEvent(TGo4EventElement* outevnt)
00125 {
00126    // first assign input event:
00127    // since input event object is never discarded within processor lifetime,
00128    // we just search for subevent by name once to speed up processing
00129    if(fCrateInputEvent==0)
00130    {
00131       TCBMBeamtimeEvent* btevent=dynamic_cast<TCBMBeamtimeEvent*>(GetInputEvent());
00132       if(btevent)
00133       {
00134          fCrateInputEvent=dynamic_cast<TMbsCrateEvent*>(btevent->GetSubEvent("MBSCRATE"));
00135          fRocInputEvent=dynamic_cast<TRocEvent*>(btevent->GetSubEvent("ROC"));
00136          fEpicsInputEvent=dynamic_cast<TEpicsEvent*>(btevent->GetSubEvent("EPICS"));
00137       }
00138       else
00139       {
00140          fCrateInputEvent=dynamic_cast<TMbsCrateEvent*>(GetInputEvent());
00141 
00142       }
00143       if(fCrateInputEvent==0) {
00144          GO4_STOP_ANALYSIS_MESSAGE("**** TBeamMonitorProc: Fatal error: no input event TMbsCrateEvent!!! STOP GO4");
00145       }
00146       if(fRocInputEvent==0) {
00147          GO4_STOP_ANALYSIS_MESSAGE("**** TBeamMonitorProc: Fatal error: no input event TRocEvent!!! STOP GO4");
00148       }
00149       if(fEpicsInputEvent==0) {
00150          Message(2,"**** TBeamMonitorProc: could not find TEpicsEvent!"); // but do not stop...
00151       }
00152 
00153    }
00154    // then assign output event
00155    // since output event object is never discarded within processor lifetime,
00156    // we just search for subevent by name once to speed up processing
00157    if(fOutputEvent==0)
00158    {
00159       TCBMBeamtimeEvent* btevent=dynamic_cast<TCBMBeamtimeEvent*>(outevnt);
00160       if(btevent)
00161       {
00162          fOutputEvent=dynamic_cast<TBeamMonitorEvent*>(btevent->GetSubEvent("BEAM"));
00163       }
00164       else
00165       {
00166          fOutputEvent= dynamic_cast<TBeamMonitorEvent*>(outevnt);
00167       }
00168       if(fOutputEvent==0) {
00169          GO4_STOP_ANALYSIS_MESSAGE("**** TBeamMonitorProc: Fatal error: output event is not a TBeamMonitorEvent!!! STOP GO4");
00170       }
00171    }
00172 }
00173 
00174 
00175 
00176 void TBeamMonitorProc::FinalizeEvent()
00177 {
00178    if(fCrateInputEvent && fCrateInputEvent->IsValid())
00179    {
00180 
00181       if (fCrateInputEvent->IsPulser()) {
00182 
00183          fOutputEvent->fIsPulser = kTRUE;
00184 
00185       } else {
00186 
00187          double cher1 = fCrateInputEvent->fData1182[1][0];
00188          double cher2 = fCrateInputEvent->fData1182[0][0];
00189          double pb = fCrateInputEvent->fData1182[1][1];
00190          double s1 = fCrateInputEvent->fData1182[0][5];
00191          double s2 = fCrateInputEvent->fData1182[0][6];
00192 
00193          fCh_Pb->Fill(cher1, pb);
00194          fCh2_Pb->Fill(cher2, pb);
00195          fCh1_Ch2->Fill(cher1, cher2);
00196 
00197          if (fPar->Cher1ForElectron)
00198             fOutputEvent->fIsElectron = fElectronCond->Test(cher1, pb);
00199          else
00200             fOutputEvent->fIsElectron = fElectronCond->Test(cher2, pb);
00201 
00202          if (!fOutputEvent->fIsElectron) {
00203             if (fPar->Cher1ForMuon)
00204                fOutputEvent->fIsMuon = fMuonCond->Test(cher1, pb);
00205             else
00206                fOutputEvent->fIsMuon = fMuonCond->Test(cher2, pb);
00207          }
00208 
00209          if (!fOutputEvent->fIsElectron && !fOutputEvent->fIsMuon) {
00210             if (fPar->Cher1ForPion)
00211                fOutputEvent->fIsPion = fPionCond->Test(cher1, pb);
00212             else
00213                fOutputEvent->fIsPion = fPionCond->Test(cher2, pb);
00214          }
00215 
00216          fS1_Pb->Fill(s1, pb);
00217          fS1_S2->Fill(s1, s2);
00218       }
00219    }
00220 
00221    // the following is example from cosy december 2010 beamtime
00222    // note access to EPICS process variables by full name here
00223 
00224 
00225    /*
00226   if(fEpicsInputEvent && fEpicsInputEvent->IsValid()) // check if new update has been done
00227    {
00228      // TODO: put reasonable display of interesting slow control variables here
00229 
00230 
00231      int motorx = fEpicsInputEvent->GetDouble("CBM:MOTOR:GETPOSX");
00232      int motory = fEpicsInputEvent->GetDouble("CBM:MOTOR:GETPOSY");
00233      int rolu_left = fEpicsInputEvent->GetDouble("CBM:rolu:step_to_mm_L");
00234      int rolu_right = fEpicsInputEvent->GetDouble("CBM:rolu:step_to_mm_R");
00235      int rolu_up = fEpicsInputEvent->GetDouble("CBM:rolu:step_to_mm_O");
00236      int rolu_down = fEpicsInputEvent->GetDouble("CBM:rolu:step_to_mm_U");
00237 
00238      fMotorPos->SetTitle(
00239            Form("Motor position, EPICS Time:%s -",
00240                  fEpicsInputEvent->GetUpdateTimeString()));
00241      fMotorPos->Fill(motorx, motory);
00242 
00243      fRoluPos->SetTitle(
00244            Form("ROLU positions, EPICS Time:%s -",
00245                  fEpicsInputEvent->GetUpdateTimeString()));
00246      Int_t roludim = 35;
00247      Int_t middle = roludim / 2;
00248      Int_t displaywidth = 6;
00249      for (int i = 0; i < 2 * displaywidth; ++i) {
00250         fRoluPos->Fill(middle - rolu_left, middle - displaywidth + i);
00251         fRoluPos->Fill(middle + rolu_right, middle - displaywidth + i);
00252         fRoluPos->Fill(middle - displaywidth + i, middle - rolu_down);
00253         fRoluPos->Fill(middle - displaywidth + i, rolu_up + middle);
00254      }
00255 
00256    } // end EPICS block
00257    */
00258 }

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