Newer
Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
/////////////////////////////////////////////////////////////////////////
#include "THcExtTarCor.h"
#include "THaVertexModule.h"
#include "THcHallCSpectrometer.h"
#include "THaTrack.h"
#include "THaTrackInfo.h"
#include "TMath.h"
#include "TVector3.h"
#include "VarDef.h"
#include <cstring>
#include <cstdio>
#include <cstdlib>
#include <iostream>
using namespace std;
//_____________________________________________________________________________
THcExtTarCor::THcExtTarCor( const char* name, const char* description,
const char* spectro, const char* vertex ) :
THaPhysicsModule(name,description), fThetaCorr(0.0), fDeltaCorr(0.0),
fSpectroName(spectro), fVertexName(vertex),
fTrackModule(NULL), fVertexModule(NULL)
{
// Normal constructor.
Clear();
}
//_____________________________________________________________________________
THcExtTarCor::~THcExtTarCor()
{
// Destructor
DefineVariables( kDelete );
}
//_____________________________________________________________________________
void THcExtTarCor::Clear( Option_t* opt )
{
// Clear all event-by-event variables.
THaPhysicsModule::Clear(opt);
TrkIfoClear();
fDeltaTh = fDeltaDp = fDeltaP = 0.0;
}
//_____________________________________________________________________________
THaAnalysisObject::EStatus THcExtTarCor::Init( const TDatime& run_time )
{
// Initialize the module.
// Locate the spectrometer apparatus named in fSpectroName and save
// pointer to it.
// Also, if given, locate the vertex module given in fVertexName
// and save pointer to it.
fTrackModule = dynamic_cast<THaTrackingModule*>
( FindModule( fSpectroName.Data(), "THaTrackingModule"));
if( !fTrackModule )
return fStatus;
fTrkIfo.SetSpectrometer( fTrackModule->GetTrackInfo()->GetSpectrometer() );
// If no vertex module given, try to get the vertex info from the
// same module as the tracks, e.g. from a spectrometer
if( fVertexName.IsNull()) fVertexName = fSpectroName;
fVertexModule = dynamic_cast<THaVertexModule*>
( FindModule( fVertexName.Data(), "THaVertexModule" ));
if( !fVertexModule )
return fStatus;
// Standard initialization. Calls this object's DefineVariables().
THaPhysicsModule::Init( run_time );
return fStatus;
}
//_____________________________________________________________________________
Int_t THcExtTarCor::DefineVariables( EMode mode )
{
// Define/delete global variables.
if( mode == kDefine && fIsSetup ) return kOK;
fIsSetup = ( mode == kDefine );
DefineVarsFromList( THaTrackingModule::GetRVarDef(), mode );
const RVarDef var2[] = {
{ "delta_p", "Size of momentum correction", "fDeltaP" },
{ "delta_dp", "Size of delta correction (%)", "fDeltaDp" },
{ "delta_xptar", "Size of xptar correction (rad)", "fDeltaTh" },
{ 0 }
};
DefineVarsFromList( var2, mode );
return 0;
}
//_____________________________________________________________________________
Int_t THcExtTarCor::Process( const THaEvData& )
{
// Calculate corrections and adjust the track parameters.
if( !IsOK() ) return -1;
THaTrackInfo* trkifo = fTrackModule->GetTrackInfo();
if( !trkifo->IsOK() ) return 2;
THcHallCSpectrometer* spectro = static_cast <THcHallCSpectrometer*>(trkifo->GetSpectrometer());
if( !spectro ) return 3;
Double_t ray[6];
spectro->LabToTransport( fVertexModule->GetVertex(),
trkifo->GetPvect(), ray );
TVector3 vertex = fVertexModule->GetVertex();
TVector3 tempp = trkifo->GetPvect();
Double_t ztarg= vertex(2);
/* Ignore junk
if( TMath::Abs(ray[0]) > 0.1 || TMath::Abs(ray[1]) > 1.0 ||
TMath::Abs(ray[2]) > 0.1 || TMath::Abs(ray[3]) > 1.0 ||
TMath::Abs(ray[5]) > 1.0 )
return 3;
*/
Int_t ntracks = spectro->GetNTracks();
if( ntracks == 0 ) return -2;
Double_t xptar;
Double_t ytar;
Double_t yptar;
Double_t delta;
Double_t p=0;
TVector3 pvect;
Double_t xtar_new=vertex[1];
TClonesArray* tracks = spectro->GetTracks();
if( !tracks ){
return -2;
}
for( Int_t i = 0; i<ntracks; i++ ) {
THaTrack* theTrack = static_cast<THaTrack*>( tracks->At(i) );
if( theTrack == spectro->GetGoldenTrack() ) {
// Calculate corrections & recalculate track parameters
Double_t x_tg = vertex[1];
spectro->CalculateTargetQuantities(theTrack,x_tg,xptar,ytar,yptar,delta);
p = spectro->GetPcentral() * ( 1.0+delta );
spectro->TransportToLab( p, xptar, yptar, pvect );
Double_t theta=spectro->GetThetaSph();
xtar_new = x_tg - xptar*ztarg*cos(theta);
// Get a second-iteration value for x_tg based on the
spectro->CalculateTargetQuantities(theTrack,xtar_new,xptar,ytar,yptar,delta);
fDeltaDp = delta*100 -theTrack->GetDp();
fDeltaP = p - theTrack->GetP();
fDeltaTh = xptar - theTrack->GetTTheta();
}
}
// Save results in our TrackInfo
fTrkIfo.Set( p, delta*100, xtar_new,100*ytar, xptar, yptar, pvect );
fDataValid = true;
return 0;
}
Int_t THcExtTarCor::ReadDatabase( const TDatime& date )
{
#ifdef WITH_DEBUG
cout << "In THcExtTarCor::ReadDatabase()" << endl;
#endif
//
// cout << " GetName() " << GetName() << endl;
return kOK;
}
//_____________________________________________________________________________
ClassImp(THcExtTarCor)