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
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
00065
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
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
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
00127
00128
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!");
00151 }
00152
00153 }
00154
00155
00156
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
00222
00223
00224
00225
00226
00227
00228
00229
00230
00231
00232
00233
00234
00235
00236
00237
00238
00239
00240
00241
00242
00243
00244
00245
00246
00247
00248
00249
00250
00251
00252
00253
00254
00255
00256
00257
00258 }