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

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

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