Hall C ROOT/C++ Analyzer (hcana)
Loading...
Searching...
No Matches
THcExtTarCor.cxx
Go to the documentation of this file.
1
9#include "THcExtTarCor.h"
10#include "THaVertexModule.h"
12#include "THaTrack.h"
13#include "THaTrackInfo.h"
14#include "TMath.h"
15#include "TVector3.h"
16#include "VarDef.h"
17#include <cstring>
18#include <cstdio>
19#include <cstdlib>
20#include <iostream>
21using namespace std;
22
23//_____________________________________________________________________________
24THcExtTarCor::THcExtTarCor( const char* name, const char* description,
25 const char* spectro, const char* vertex ) :
26 THaExtTarCor(name, description, spectro, vertex)
27{
28 // Normal constructor.
29
30 Clear();
31}
32
33//_____________________________________________________________________________
35{
36 // Destructor
37
39}
40//_____________________________________________________________________________
42{
43 // Clear all event-by-event variables.
44
47 fDeltaTh = fDeltaDp = fDeltaP = 0.0;
48 fxsieve = kBig;
49 fysieve = kBig;
50}
51
52//_____________________________________________________________________________
54{
55 // Define/delete global variables.
56
57 if( mode == kDefine && fIsSetup ) return kOK;
58 fIsSetup = ( mode == kDefine );
59
61
62 const RVarDef var2[] = {
63 { "delta_p", "Size of momentum correction", "fDeltaP" },
64 { "delta_dp", "Size of delta correction (%)", "fDeltaDp" },
65 { "delta_xptar", "Size of xptar correction (rad)", "fDeltaTh" },
66 { "xsieve", "Golden track vertical position at sieve location (cm)", "fxsieve" },
67 { "ysieve", "Golden track horizontal position at sieve location (cm) (cm)", "fysieve" },
68 { 0 }
69 };
70 DefineVarsFromList( var2, mode );
71 return 0;
72}
73
74//_____________________________________________________________________________
76{
77 // Calculate corrections and adjust the track parameters.
78
79 if( !IsOK() ) return -1;
80
82 if( !trkifo->IsOK() ) return 2;
83 THcHallCSpectrometer* spectro = static_cast <THcHallCSpectrometer*>(trkifo->GetSpectrometer());
84 if( !spectro ) return 3;
85
86
87 Double_t ray[6];
89 trkifo->GetPvect(), ray );
91 TVector3 tempp = trkifo->GetPvect();
92 Double_t ztarg= vertex(2);
93 /* Ignore junk
94 if( TMath::Abs(ray[0]) > 0.1 || TMath::Abs(ray[1]) > 1.0 ||
95 TMath::Abs(ray[2]) > 0.1 || TMath::Abs(ray[3]) > 1.0 ||
96 TMath::Abs(ray[5]) > 1.0 )
97 return 3;
98 */
99 Int_t ntracks = spectro->GetNTracks();
100 if( ntracks == 0 ) return -2;
101 Double_t xptar;
102 Double_t ytar;
103 Double_t yptar;
104 Double_t delta;
105 Double_t p=0;
106 Double_t p_before_xtar_corr;
107 Double_t delta_before_xtar_corr;
108 Double_t xptar_before_xtar_corr;
109 Double_t p_after_xtar_corr=0;
110 TVector3 pvect;
111 TVector3 pvect_final;
112 TVector3 pointing_off=spectro->GetPointingOffset();
113 Double_t xtar_new=-vertex[1];
114 TClonesArray* tracks = spectro->GetTracks();
115 if( !tracks ){
116 return -2;
117 }
118 for( Int_t i = 0; i<ntracks; i++ ) {
119 THaTrack* theTrack = static_cast<THaTrack*>( tracks->At(i) );
120 if( theTrack == spectro->GetGoldenTrack() ) {
121 delta_before_xtar_corr=theTrack->GetDp();
122 p_before_xtar_corr=theTrack->GetP();
123 xptar_before_xtar_corr=theTrack->GetTTheta();
124 // Calculate corrections & recalculate ,,,track parameters
125 Double_t xptar_save=0.,xptar_diff=10000.;
126 Double_t x_tg = -vertex[1]-pointing_off[0]; // units of cm, beam position in spectrometer coordinate system
127 spectro->CalculateTargetQuantities(theTrack,x_tg,xptar,ytar,yptar,delta);
128 xptar_save = xptar;
129 Int_t niter=0;
130 while ( xptar_diff > 2 && niter < 5) {
131 p = spectro->GetPcentral() * ( 1.0+delta );
132 spectro->TransportToLab( p, xptar, yptar, pvect );
133 Double_t theta=spectro->GetThetaSph();
134 xtar_new = x_tg - xptar*ztarg*cos(theta); //units of cm
135 spectro->CalculateTargetQuantities(theTrack,xtar_new,xptar,ytar,yptar,delta);
136 xptar_diff = abs(xptar-xptar_save)*1000;
137 xptar_save = xptar;
138 niter++;
139 }
140 theTrack->SetTarget(xtar_new, ytar*100.0, xptar, yptar);
141 theTrack->SetDp(delta*100.0); // Percent.
142 p_after_xtar_corr =spectro->GetPcentral()*(1+theTrack->GetDp()/100.0);
143 theTrack->SetMomentum(p_after_xtar_corr);
144 spectro->TransportToLab(theTrack->GetP(),theTrack->GetTTheta(),theTrack->GetTPhi(),pvect_final);
145 theTrack->SetPvect(pvect_final);
146 if (strcmp(spectro->GetName(),"H")==0) {
147 fxsieve=xtar_new+xptar*168.;
148 fysieve=ytar*100.+yptar*168.;
149 }
150 if (strcmp(spectro->GetName(),"P")==0) {
151 fxsieve=xtar_new+xptar*253.;
152 Double_t delta_per=delta*100;
153 fysieve=ytar*100+yptar*253.-(0.019+40.*.01*0.052)*delta_per+(0.00019+40*.01*.00052)*delta_per*delta_per;
154 }
155 fDeltaDp = delta_before_xtar_corr -theTrack->GetDp();
156 fDeltaP = p_before_xtar_corr - theTrack->GetP();
157 fDeltaTh = xptar_before_xtar_corr - theTrack->GetTTheta();
158 // cout << xtar_new << " " << fDeltaDp << " " << fDeltaP << " " << fDeltaTh << endl;
159 }
160 }
161 // Save results in our TrackInfo
162 //cout << spectro->GetName() << " exttarcor = " << xptar << " " << delta*100 << " " << p_after_xtar_corr << endl;
163 trkifo->Set( p_after_xtar_corr, delta*100, xtar_new,100*ytar, xptar, yptar, pvect_final );
164 fTrkIfo.Set( p_after_xtar_corr, delta*100, xtar_new,100*ytar, xptar, yptar, pvect_final );
165 fDataValid = true;
166 return 0;
167}
168
170{
171
172#ifdef WITH_DEBUG
173 cout << "In THcExtTarCor::ReadDatabase()" << endl;
174#endif
175 //
176
177 // cout << " GetName() " << GetName() << endl;
178 return kOK;
179}
180
181//_____________________________________________________________________________
183
int Int_t
const Data_t kBig
double Double_t
const char Option_t
winID h TVirtualViewer3D TVirtualGLPainter p
Option_t Option_t TPoint TPoint const char mode
ClassImp(VDC::AnalyticTTDConv) using namespace std
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="")
Bool_t IsOK() const
THaVertexModule * fVertexModule
Double_t fDeltaP
THaTrackingModule * fTrackModule
Double_t fDeltaTh
Double_t fDeltaDp
virtual void Clear(Option_t *opt="")
Double_t GetPcentral() const
THaTrack * GetGoldenTrack() const
Int_t GetNTracks() const
TClonesArray * GetTracks() const
const TVector3 & GetPointingOffset() const
virtual void TransportToLab(Double_t p, Double_t th, Double_t ph, TVector3 &pvect) const
Double_t GetThetaSph() const
void LabToTransport(const TVector3 &vertex, const TVector3 &pvect, Double_t *ray) const
THaSpectrometer * GetSpectrometer() const
const TVector3 & GetPvect() const
void Set(Double_t p, Double_t dp, Double_t x, Double_t y, Double_t th, Double_t ph, const TVector3 &pvect)
Bool_t IsOK() const
void SetPvect(const TVector3 &pvect)
Double_t GetTPhi() const
Double_t GetDp() const
void SetMomentum(Double_t p)
void SetDp(Double_t dp)
void SetTarget(Double_t x, Double_t y, Double_t theta, Double_t phi)
Double_t GetP() const
Double_t GetTTheta() const
static const RVarDef * GetRVarDef()
THaTrackInfo * GetTrackInfo()
THaTrackInfo fTrkIfo
virtual const TVector3 & GetVertex() const
Extended target corrections physics module.
virtual Int_t Process(const THaEvData &)
virtual Int_t DefineVariables(EMode mode=kDefine)
Double_t fxsieve
THcExtTarCor(const char *name, const char *description, const char *spectro="", const char *vertex="")
virtual Int_t ReadDatabase(const TDatime &date)
Double_t fysieve
virtual void Clear(Option_t *opt="")
virtual ~THcExtTarCor()
A standard Hall C spectrometer apparatus.
virtual void CalculateTargetQuantities(THaTrack *track, Double_t &gbeam_y, Double_t &xptar, Double_t &ytar, Double_t &yptar, Double_t &delta)
Transport focal plane track to target.
const char * GetName() const override
RVec< PromoteType< T > > abs(const RVec< T > &v)
RVec< PromoteType< T > > cos(const RVec< T > &v)
STL namespace.
void tracks()
double * vertex