Hall A ROOT/C++ Analyzer (podd)
Loading...
Searching...
No Matches
THaAvgVertex.cxx
Go to the documentation of this file.
1//*-- Author : Ole Hansen 13-Mar-03
2
4//
5// THaAvgVertex
6//
7// Calculate the average of the reaction points of the Golden Track from
8// two separate spectrometers. Requires that the standard track-beam
9// vertex information of each of the two Golden Tracks has been calculated,
10// for example using the THaReactionPoint module.
11//
13
14#include "THaAvgVertex.h"
15#include "TMath.h"
16#include <vector>
17
18using namespace std;
19
21
22//_____________________________________________________________________________
23THaAvgVertex::THaAvgVertex( const char* name, const char* description,
24 const char* spectro1, const char* spectro2 ) :
25 THaPhysicsModule(name,description),
26 fName1(spectro1), fName2(spectro2), fSpectro1(nullptr), fSpectro2(nullptr)
27{
28 // Normal constructor.
29
30 Clear();
31}
32
33//_____________________________________________________________________________
35{
36 // Destructor
37
39}
40
41//_____________________________________________________________________________
43{
44 // Clear all internal variables.
45
48 // fZerror = 0.0;
49}
50
51//_____________________________________________________________________________
53{
54 // Define/delete standard variables for a spectrometer (tracks etc.)
55 // Can be overridden or extended by derived (actual) apparatuses
56
58}
59
60//_____________________________________________________________________________
62{
63 // Initialize the module.
64 // Locate the spectrometer apparatus named in fSpectroName and save
65 // pointer to it.
66
67 // Standard initialization. Calls this object's DefineVariables().
68 if( THaPhysicsModule::Init( run_time ) != kOK )
69 return fStatus;
70
71 fSpectro1 = dynamic_cast<THaVertexModule*>
72 ( FindModule( fName1.Data(), "THaVertexModule"));
73 if( !fSpectro1 )
74 return fStatus;
75
76 fSpectro2 = dynamic_cast<THaVertexModule*>
77 ( FindModule( fName2.Data(), "THaVertexModule"));
78
79 return fStatus;
80}
81
82//_____________________________________________________________________________
84{
85 // Calculate the average vertex coordinates and uncertainties.
86
87 // consider two tracks
88 const vector<const THaVertexModule*> tracks{fSpectro1, fSpectro2};
89
90 if( !IsOK() ) return -1;
91
92 // Compute the weighted average of the vertex positions.
93 // Use the uncertainty in each vertex z as the weight for each vertex.
94 fVertex.SetXYZ( 0.0, 0.0, 0.0 );
95 Double_t sigsum = 0.0;
96 for( const auto* trk : tracks ) {
97 if( !trk->HasVertex() ) return 1;
98 Double_t sigma = trk->GetVertexError()(2);
99 Double_t sig2 = sigma*sigma;
100 if( sig2 > 0.0 ) {
101 sigsum += 1.0/sig2;
102 for( Int_t i=0; i<3; i++ ) {
103 Double_t x = trk->GetVertex()(i);
104 fVertex(i) += x/sig2;
105 }
106 }
107 }
108 if( sigsum > 0.0 ) {
109 fVertex *= 1.0/sigsum;
110 // requires beam info to get x/y uncertainties right
111 // fZerror = 1.0/TMath::Sqrt(sigsum);
112 }
113 fVertexOK = true;
114
115 return 0;
116}
117
int Int_t
double Double_t
const char Option_t
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
virtual Int_t DefineVariables(EMode mode=kDefine)
THaVertexModule * fSpectro2
TString fName1
virtual ~THaAvgVertex()
THaVertexModule * fSpectro1
virtual void Clear(Option_t *opt="")
TString fName2
virtual Int_t Process(const THaEvData &)
THaAvgVertex(const char *name, const char *description, const char *spectro1="", const char *spectro2="")
virtual void Clear(Option_t *opt="")
virtual void VertexClear()
static const RVarDef * GetRVarDef()
const char * Data() const
void SetXYZ(Double_t x, Double_t y, Double_t z)
const Double_t sigma
Double_t x[n]
STL namespace.
ClassImp(TPyArg)
void tracks()