Hall A ROOT/C++ Analyzer (podd)
Loading...
Searching...
No Matches
THaEpicsEbeam.cxx
Go to the documentation of this file.
1//*-- Author : Ole Hansen 07-May-2004
2
4//
5// THaEpicsEbeam
6//
7// A physics module that provides beam energy/momentum based on
8// EPCIS information
9//
11
12#include "THaEpicsEbeam.h"
13#include "VarDef.h"
14#include "THaEvData.h"
15#include "TMath.h"
16
17//_____________________________________________________________________________
18THaEpicsEbeam::THaEpicsEbeam( const char* name, const char* description,
19 const char* beam, const char* epics_var,
20 Double_t scale_factor ) :
21 THaPhysicsModule( name,description ), fEcorr(0.0), fEpicsIsMomentum(false),
22 fScaleFactor(scale_factor), fBeamName(beam), fEpicsVar(epics_var),
23 fBeamModule(nullptr)
24{
25 // Constructor.
26}
27
28
29//_____________________________________________________________________________
31{
32 // Destructor
33
35}
36
37//_____________________________________________________________________________
39{
40 // Clear all event-by-event variables.
41
44 fEcorr = 0.0;
45}
46
47//_____________________________________________________________________________
49{
50 // Initialize the module.
51
52 fBeamModule = dynamic_cast<THaBeamModule*>
53 ( FindModule( fBeamName.Data(), "THaBeamModule"));
54 if( !fBeamModule )
55 return fStatus;
56
57 //this is done by THaBeamInfo::operator= in Process
58 // fBeamIfo.SetBeam( fBeamModule->GetBeamInfo()->GetBeam() );
59
60 return THaPhysicsModule::Init(run_time);
61}
62
63//_____________________________________________________________________________
65{
66 // Initialize global variables
67
68 RVarDef vars[] = {
69 { "ecorr", "Beam energy correction (output-input) (GeV)", "fEcorr" },
70 { nullptr }
71 };
72 return DefineVarsFromList( vars, mode );
73}
74
75//_____________________________________________________________________________
77{
78 // Obtain actual beam energy from EPICS (if available) and
79 // calculate new beam parameters
80
81 if( !IsOK() ) return -1;
82
84 if( !input->IsOK() ) return 2;
85
86 // Copy the input beam info
87 fBeamIfo = *input;
88
89 // Obtain current beam energy (or momentum) from EPICS
90 // If requested EPICS variable not loaded, do nothing
91 if( evdata.IsLoadedEpics(fEpicsVar) ) {
93 // the scale factor must convert the EPICS value to GeV
94 e *= fScaleFactor;
96 Double_t p;
97 if( fEpicsIsMomentum ) {
98 p = e;
99 e = TMath::Sqrt(p*p+m*m);
100 } else {
101 p = TMath::Sqrt( TMath::Max(e*e-m*m,0.0) );
102 }
103 fBeamIfo.SetP(p);
104 fEcorr = e - input->GetE();
105 }
106
107 fDataValid = true;
108 return 0;
109}
110
111//_____________________________________________________________________________
112void THaEpicsEbeam::SetBeam( const char* name )
113{
114 // Set the name of the module providing the beam input data
115 if( !IsInit())
116 fBeamName = name;
117 else
118 PrintInitError("SetBeam");
119}
120
121//_____________________________________________________________________________
122void THaEpicsEbeam::SetEpicsVar( const char* name )
123{
124 // Set the name of the EPICS variable to use for corrections
125 if( !IsInit())
126 fEpicsVar = name;
127 else
128 PrintInitError("SetEpicsVar");
129}
130
131//_____________________________________________________________________________
133{
134 // If mode=true, interpret EPICS data as momentum rather than energy
135 if( !IsInit())
137 else
138 PrintInitError("SetEpicsIsMomentum");
139}
140
141//_____________________________________________________________________________
143{
144 // If mode=true, interpret EPICS data as momentum rather than energy
145 if( !IsInit())
146 fScaleFactor = factor;
147 else
148 PrintInitError("SetEpicsIsMomentum");
149}
150
151//_____________________________________________________________________________
153
154
int Int_t
#define e(i)
bool Bool_t
double Double_t
const char Option_t
winID h TVirtualViewer3D TVirtualGLPainter p
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void input
Option_t Option_t TPoint TPoint const char mode
char name[80]
static Int_t DefineVarsFromList(const void *list, EType type, EMode mode, const char *def_prefix, const TObject *obj, const char *prefix, const char *here, const char *comment_subst="")
THaAnalysisObject * FindModule(const char *name, const char *classname, bool do_error=true)
Bool_t IsOK() const
Bool_t IsInit() const
Double_t GetM() const
void SetP(Double_t p)
Definition THaBeamInfo.h:61
THaBeamInfo * GetBeamInfo()
THaBeamInfo fBeamIfo
void BeamIfoClear()
THaEpicsEbeam(const char *name, const char *description, const char *beam, const char *epics_var, Double_t scale_factor=1.0)
void SetEpicsIsMomentum(Bool_t mode=true)
virtual Int_t DefineVariables(EMode mode=kDefine)
TString fEpicsVar
virtual void Clear(Option_t *opt="")
virtual ~THaEpicsEbeam()
void SetBeam(const char *beam)
TString fBeamName
Bool_t fEpicsIsMomentum
void SetScaleFactor(Double_t fact)
virtual Int_t Process(const THaEvData &)
Double_t fEcorr
THaBeamModule * fBeamModule
void SetEpicsVar(const char *epics_var)
Double_t fScaleFactor
virtual Bool_t IsLoadedEpics(const char *) const
Definition THaEvData.h:122
virtual double GetEpicsData(const char *tag, UInt_t event=0) const
Definition THaEvData.h:406
void PrintInitError(const char *here)
virtual void Clear(Option_t *opt="")
const char * Data() const
Double_t Sqrt(Double_t x)
Double_t Max(Double_t a, Double_t b)
TMarker m
ClassImp(TPyArg)