Hall C ROOT/C++ Analyzer (hcana)
THcExtTarCor.cxx
Go to the documentation of this file.
1 
9 #include "THcExtTarCor.h"
10 #include "THaVertexModule.h"
11 #include "THcHallCSpectrometer.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>
21 using namespace std;
22 
23 //_____________________________________________________________________________
24 THcExtTarCor::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 
38  DefineVariables( kDelete );
39 }
40 //_____________________________________________________________________________
42 {
43  // Clear all event-by-event variables.
44 
45  THaPhysicsModule::Clear(opt);
46  TrkIfoClear();
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 
60  DefineVarsFromList( THaTrackingModule::GetRVarDef(), mode );
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 
81  THaTrackInfo* trkifo = fTrackModule->GetTrackInfo();
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];
88  spectro->LabToTransport( fVertexModule->GetVertex(),
89  trkifo->GetPvect(), ray );
90  TVector3 vertex = fVertexModule->GetVertex();
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 
virtual Int_t DefineVariables(EMode mode=kDefine)
virtual Int_t Process(const THaEvData &)
const char Option_t
virtual void Clear(Option_t *opt="")
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.
Extended target corrections physics module.
Definition: THcExtTarCor.h:14
int Int_t
STL namespace.
Float_t delta
double cos(double)
Double_t fysieve
Definition: THcExtTarCor.h:23
REAL * vertex
virtual Int_t ReadDatabase(const TDatime &date)
THcExtTarCor(const char *name, const char *description, const char *spectro="", const char *vertex="")
Double_t fxsieve
Definition: THcExtTarCor.h:23
double Double_t
ClassImp(THcDCLookupTTDConv) THcDCLookupTTDConv
virtual ~THcExtTarCor()
TObject * At(Int_t idx) const
static const Double_t kBig
Definition: THcFormula.cxx:31
A standard Hall C spectrometer apparatus.