Hall A ROOT/C++ Analyzer (podd)
Loading...
Searching...
No Matches
THaExtTarCor.cxx
Go to the documentation of this file.
1//*-- Author : Ole Hansen 17-Mar-03
2
4//
5// THaExtTarCor
6//
7// Calculate corrections to the reconstructed momentum and out-of-plane
8// angle that are due to a finite x position of the reaction point
9// at the target. Finite x-positions occur as the result of
10//
11// - beam position deviations and raster
12// - spectrometer misalignment
13// - targets extended along the beam (finite y_target positions)
14//
15// This module implements a simple first-order correction devised by
16// Mark Jones. It is sufficient for most applications of the Hall A HRS
17// spectrometers.
18//
19// Currently, only the Golden Track of the given spectrometer is corrected.
20// (This restriction will be dropped once all vertex modules support
21// multiple tracks.)
22// The corrected quantities are available in global variables
23// of this module:
24//
25// x: Effective x_tg found by this routine (m)
26// y: y_tg (unchanged) (m)
27// th: TRANSPORT theta at target (rad)
28// ph: TRANSPORT phi (unchanged) (rad)
29// dp: delta
30// p: absolute momentum (GeV)
31// px,py,pz: lab momentum vector components (GeV)
32// ok: data valid status flag (0/1)
33//
34// The following global variables are available:
35//
36// delta_p: Size of momentum correction (GeV)
37// delta_dp: Size of delta correction
38// delta_th: Size of theta correction (rad)
39//
41
42#include "THaExtTarCor.h"
43#include "THaVertexModule.h"
44#include "THaSpectrometer.h"
45#include "THaTrack.h"
46#include "THaTrackInfo.h"
47#include "TMath.h"
48#include "TVector3.h"
49#include "VarDef.h"
50
51using namespace std;
52using namespace Podd;
53
54//_____________________________________________________________________________
55THaExtTarCor::THaExtTarCor( const char* name, const char* description,
56 const char* spectro, const char* vertex ) :
57 THaPhysicsModule(name,description), fThetaCorr(0.0), fDeltaCorr(0.0),
58 fDeltaP(0.0), fDeltaDp(0.0), fDeltaTh(0.0),
59 fSpectroName(spectro), fVertexName(vertex),
60 fTrackModule(nullptr), fVertexModule(nullptr)
61{
62 // Normal constructor.
63
65}
66
67//_____________________________________________________________________________
69{
70 // Destructor
71
73}
74
75//_____________________________________________________________________________
77{
78 // Clear all event-by-event variables.
79
82 fDeltaTh = fDeltaDp = fDeltaP = 0.0;
83}
84
85//_____________________________________________________________________________
87{
88 // Initialize the module.
89 // Locate the spectrometer apparatus named in fSpectroName and save
90 // pointer to it.
91 // Also, if given, locate the vertex module given in fVertexName
92 // and save pointer to it.
93
94 fTrackModule = dynamic_cast<THaTrackingModule*>
95 ( FindModule( fSpectroName.Data(), "THaTrackingModule"));
96 if( !fTrackModule )
97 return fStatus;
98
100
101 // If no vertex module given, try to get the vertex info from the
102 // same module as the tracks, e.g. from a spectrometer
104
105 fVertexModule = dynamic_cast<THaVertexModule*>
106 ( FindModule( fVertexName.Data(), "THaVertexModule" ));
107 if( !fVertexModule )
108 return fStatus;
109
110 // Standard initialization. Calls this object's DefineVariables().
111 THaPhysicsModule::Init( run_time );
112
113 return fStatus;
114}
115
116//_____________________________________________________________________________
118{
119 // Define/delete global variables.
120
122 if( ret )
123 return ret;
124
125 const RVarDef var2[] = {
126 { "delta_p", "Size of momentum correction", "fDeltaP" },
127 { "delta_dp", "Size of delta correction", "fDeltaDp" },
128 { "delta_th", "Size of theta correction (rad)", "fDeltaTh" },
129 { nullptr }
130 };
131 return DefineVarsFromList( var2, mode );
132}
133
134//_____________________________________________________________________________
136{
137 // Calculate corrections and adjust the track parameters.
138
139 if( !IsOK() ) return -1;
140
142 if( !trkifo->IsOK() ) return 2;
143 THaSpectrometer* spectro = trkifo->GetSpectrometer();
144 if( !spectro ) return 3;
145
146 Double_t ray[6];
148 trkifo->GetPvect(), ray );
149 // Ignore junk
150 if( TMath::Abs(ray[0]) > 0.1 || TMath::Abs(ray[1]) > 1.0 ||
151 TMath::Abs(ray[2]) > 0.1 || TMath::Abs(ray[3]) > 1.0 ||
152 TMath::Abs(ray[5]) > 1.0 )
153 return 3;
154
155 TVector3 pvect;
156 // Calculate corrections & recalculate track parameters
157 Double_t x_tg = ray[0];
158 fDeltaTh = fThetaCorr * x_tg;
159 fDeltaDp = x_tg / fDeltaCorr;
160 Double_t theta = trkifo->GetTheta() + fDeltaTh;
161
162 Double_t dp = trkifo->GetDp() + fDeltaDp;
163 Double_t p = spectro->GetPcentral() * ( 1.0+dp );
164 fDeltaP = p - trkifo->GetP();
165 spectro->TransportToLab( p, theta, trkifo->GetPhi(), pvect );
166
167 // Get a second-iteration value for x_tg based on the
168 // corrected momentum vector
169 spectro->LabToTransport( fVertexModule->GetVertex(), pvect, ray );
170
171 // Save results in our TrackInfo
172 fTrkIfo.Set( p, dp, ray[0], trkifo->GetY(), theta, trkifo->GetPhi(), pvect );
173
174 fDataValid = true;
175 return 0;
176}
177
178//_____________________________________________________________________________
180{
181 // Query the run database for the correction coefficients.
182 // Use reasonable defaults if not found.
183 // First try tags "<prefix>.theta_corr" and "<prefix>.delta_corr", then
184 // global names "theta_corr" and "delta_corr".
185
187 if( err ) return err;
188
189 FILE* f = OpenRunDBFile( date );
190 if( !f ) return kFileError;
191
192 const Double_t DEL_COR = 5.18;
193 fThetaCorr = 0.61;
194 fDeltaCorr = DEL_COR;
195
196 TString name(fPrefix), tag("theta_corr"); name += tag;
197 Int_t st = LoadDBvalue( f, date, name.Data(), fThetaCorr );
198 if( st )
199 LoadDBvalue( f, date, tag.Data(), fThetaCorr );
200
201 name = fPrefix; tag = "delta_corr"; name += tag;
202 st = LoadDBvalue( f, date, name.Data(), fDeltaCorr );
203 if( st )
204 LoadDBvalue( f, date, tag.Data(), fDeltaCorr );
205
206 if( TMath::Abs(fDeltaCorr) < 1e-6 ) {
207 Warning(Here("ReadRunDatabase()"),
208 "delta_corr parameter from database too small (%e).\n"
209 "Using default.", fDeltaCorr );
210 fDeltaCorr = DEL_COR;
211 }
212 fclose(f);
213 return kOK;
214}
215
216//_____________________________________________________________________________
218
int Int_t
#define f(i)
#define e(i)
double Double_t
const char Option_t
winID h TVirtualViewer3D TVirtualGLPainter p
Option_t Option_t TPoint TPoint const char mode
char name[80]
virtual Int_t ReadRunDatabase(const TDatime &date)
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="")
virtual const char * Here(const char *) const
THaAnalysisObject * FindModule(const char *name, const char *classname, bool do_error=true)
virtual FILE * OpenRunDBFile(const TDatime &date)
Bool_t IsOK() const
TString fVertexName
virtual Int_t DefineVariables(EMode mode=kDefine)
THaVertexModule * fVertexModule
THaExtTarCor(const char *name, const char *description, const char *spectro="", const char *vertex="")
Double_t fDeltaP
THaTrackingModule * fTrackModule
virtual Int_t Process(const THaEvData &)
virtual void Clear(Option_t *opt="")
Double_t fDeltaTh
Double_t fDeltaDp
Double_t fDeltaCorr
virtual Int_t ReadRunDatabase(const TDatime &date)
TString fSpectroName
Double_t fThetaCorr
virtual ~THaExtTarCor()
virtual void Clear(Option_t *opt="")
Double_t GetPcentral() const
virtual void LabToTransport(const TVector3 &vertex, const TVector3 &pvect, TVector3 &tvertex, Double_t *ray) const
virtual void TransportToLab(Double_t p, Double_t th, Double_t ph, TVector3 &pvect) const
THaSpectrometer * GetSpectrometer() const
Double_t GetY() const
void SetSpectrometer(THaSpectrometer *s)
Double_t GetTheta() const
Double_t GetP() const
void Set(Double_t p, Double_t dp, Double_t x, Double_t y, Double_t th, Double_t ph, Double_t px, Double_t py, Double_t pz)
const TVector3 & GetPvect() const
Double_t GetDp() const
Double_t GetPhi() const
Bool_t IsOK() const
static const RVarDef * GetRVarDef()
THaTrackInfo * GetTrackInfo()
virtual const TVector3 & GetVertex() const
virtual void Warning(const char *method, const char *msgfmt,...) const
const char * Data() const
Bool_t IsNull() const
Double_t Abs(Double_t d)
STL namespace.
ClassImp(TPyArg)
double * vertex