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
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
00080
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
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
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
00156
00157
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!");
00180 }
00181
00182 }
00183
00184
00185
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
00251
00252
00253
00254
00255
00256
00257
00258
00259
00260
00261
00262
00263
00264
00265
00266
00267
00268
00269
00270
00271
00272
00273
00274
00275
00276
00277
00278
00279
00280
00281
00282
00283
00284
00285
00286
00287 }