Hall A ROOT/C++ Analyzer (podd)
Loading...
Searching...
No Matches
THaRaster.cxx
Go to the documentation of this file.
1
2// //
3// THaRaster //
4// //
5// Class for a beam raster device //
6// measuring two magnet currents //
7// which are proportional to the horizontal/vertical beam displacement //
8// the two planes are assumed to be decoupled //
9// there is no phase shift between the current and the actual beam position //
10// //
12
13#include "THaRaster.h"
14#include "TMath.h"
15
16using namespace std;
17
18static constexpr Int_t NPOS = 3;
19static constexpr Int_t NBPM = 2;
20static constexpr Int_t NCHAN = 2*NBPM;
21
22//_____________________________________________________________________________
23THaRaster::THaRaster( const char* name, const char* description,
24 THaApparatus* apparatus )
25 : THaBeamDet(name,description,apparatus), fRawPos(NBPM), fRawSlope(NBPM),
26 fRasterFreq(NBPM), fSlopePedestal(NBPM), fRasterPedestal(NBPM),
27 fNfired(0)
28{
29 // Constructor
33}
34
35
36//_____________________________________________________________________________
38{
39 // ReadDatabase: if detectors cant be added to detmap
40 // or entry for bpms is missing -> kInitError
41 // otherwise -> kOk
42
43 const char* const here = "ReadDatabase";
44 vector<Int_t> detmap;
45 Double_t zpos[NPOS];
46 Double_t freq[NBPM], rped[NBPM], sped[NBPM];
47 Double_t raw2posA[NBPM*NPOS], raw2posB[NBPM*NPOS], raw2posT[NBPM*NPOS];
48
49 FILE* file = OpenFile( date );
50 if( !file )
51 return kInitError;
52
53 // fOrigin.SetXYZ(0,0,0);
54 //Int_t err = ReadGeometry( file, date );
55
56// if( !err ) {
57 memset(zpos, 0, sizeof(zpos));
58 // Read configuration parameters
59 DBRequest config_request[] = {
60 {"detmap", &detmap, kIntV},
61 {"zpos", zpos, kDouble, NPOS, true},
62 {nullptr}
63 };
64 Int_t err = LoadDB(file, date, config_request, fPrefix);
65// }
66
67 // Fill the detector map. It must specify NBPM(=2) channels for the x/y
68 // position readouts. Another NBPM(=2) channels for the x/y raw slopes are
69 // optional. These channels must be defined in exactly this order.
70 // Although the existing database format includes the logical channel number,
71 // which would in principle allow a different order, its value was ignored in
72 // the original code and replaced with the order in which modules are listed
73 // in the database. It is unclear why the number was first introduced and then
74 // extra code was written to support ignoring it. Bizarre.
75 // To maintain compatibility with existing databases, we ignore the logical
76 // channel number altogether here. Alternatively, we could use it, but then
77 // many old databases would become invalid, causing confusion and errors.
79 if( !err && FillDetMap(detmap, flags, here) <= 0 ) {
80 err = kInitError; // Error already printed by FillDetMap
81 }
82 if( !err ) {
83 UInt_t nchan = fDetMap->GetTotNumChan();
84 if( nchan != NBPM && nchan != NCHAN ) {
85 Error(Here(here), "Incorrect number of channels = %u defined in "
86 "detector map. Must be either %u or %u. Fix database.",
87 nchan, NBPM, NCHAN);
88 err = kInitError;
89 } else if( fDebug > 0 && nchan == NBPM ) {
90 Warning( Here(here), "Only %u channels defined in detector map. Raster "
91 "slope information will not be available", nchan);
92 }
93 }
94
95 if( !err ) {
96 fPosOff[0].SetZ( zpos[0] );
97 fPosOff[1].SetZ( zpos[1] );
98 fPosOff[2].SetZ( zpos[2] );
99
100 memset( rped, 0, sizeof(rped) );
101 memset( sped, 0, sizeof(sped) );
102
103 DBRequest calib_request[] = {
104 { "freqs", freq, kDouble, NBPM },
105 { "rast_peds", rped, kDouble, NBPM, true },
106 { "slope_peds", sped, kDouble, NBPM, true },
107 { "raw2posA", raw2posA, kDouble, NBPM*NPOS },
108 { "raw2posB", raw2posB, kDouble, NBPM*NPOS },
109 { "raw2posT", raw2posT, kDouble, NBPM*NPOS },
110 { nullptr }
111 };
112 err = LoadDB( file, date, calib_request, fPrefix );
113 }
114 fclose(file);
115 if( err )
116 return err;
117
118 fRasterFreq.SetElements( freq );
121
122 fPosOff[0].SetX( raw2posA[0]);
123 fPosOff[0].SetY( raw2posA[1]);
124 fRaw2Pos[0](0,0) = raw2posA[2];
125 fRaw2Pos[0](1,1) = raw2posA[3];
126 fRaw2Pos[0](0,1) = raw2posA[4];
127 fRaw2Pos[0](1,0) = raw2posA[5];
128
129 fPosOff[1].SetX( raw2posB[0]);
130 fPosOff[1].SetY( raw2posB[1]);
131 fRaw2Pos[1](0,0) = raw2posB[2];
132 fRaw2Pos[1](1,1) = raw2posB[3];
133 fRaw2Pos[1](0,1) = raw2posB[4];
134 fRaw2Pos[1](1,0) = raw2posB[5];
135
136 fPosOff[2].SetX( raw2posT[0]);
137 fPosOff[2].SetY( raw2posT[1]);
138 fRaw2Pos[2](0,0) = raw2posT[2];
139 fRaw2Pos[2](1,1) = raw2posT[3];
140 fRaw2Pos[2](0,1) = raw2posT[4];
141 fRaw2Pos[2](1,0) = raw2posT[5];
142
143 return kOK;
144}
145
146//_____________________________________________________________________________
148{
149 // Initialize global variables and lookup table for decoder
150
151 // Register variables in global list
152
153 RVarDef vars[] = {
154 { "rawcur.x", "current in horizontal raster", "GetRawPosX()" },
155 { "rawcur.y", "current in vertical raster", "GetRawPosY()"},
156 { "rawslope.x", "derivative of current in horizontal raster", "GetRawSlopeX()" },
157 { "rawslope.y", "derivative of current in vertical raster", "GetRawSlopeY()"},
158 { "bpma.x", "reconstructed x-position at 1st bpm", "GetPosBPMAX()"},
159 { "bpma.y", "reconstructed y-position at 1st bpm", "GetPosBPMAY()"},
160 { "bpma.z", "reconstructed z-position at 1st bpm", "GetPosBPMAZ()"},
161 { "bpmb.x", "reconstructed x-position at 2nd bpm", "GetPosBPMBX()"},
162 { "bpmb.y", "reconstructed y-position at 2nd bpm", "GetPosBPMBY()"},
163 { "bpmb.z", "reconstructed z-position at 2nd bpm", "GetPosBPMBZ()"},
164 { "target.x", "reconstructed x-position at nom. interaction point", "GetPosTarX()"},
165 { "target.y", "reconstructed y-position at nom. interaction point", "GetPosTarY()"},
166 { "target.z", "reconstructed z-position at nom. interaction point", "GetPosTarZ()"},
167 { "target.dir.x", "reconstructed x-component of beam direction", "fDirection.fX"},
168 { "target.dir.y", "reconstructed y-component of beam direction", "fDirection.fY"},
169 { "target.dir.z", "reconstructed z-component of beam direction", "fDirection.fZ"},
170 { nullptr }
171 };
172
173 return DefineVarsFromList( vars, mode );
174}
175
176//_____________________________________________________________________________
178{
179 // Destructor. Remove variables from global list.
180
182}
183
184//_____________________________________________________________________________
186{
187 // Reset per-event data.
189 fRawPos(0)=-1;
190 fRawPos(1)=-1;
191 fRawSlope(0)=-1;
192 fRawSlope(1)=-1;
193 fPosition[0].SetXYZ(0.,0.,-10000.);
194 fPosition[1].SetXYZ(0.,0.,-10000.);
195 fPosition[2].SetXYZ(0.,0.,-10000.);
196 fDirection.SetXYZ(0.,0.,1.);
197 fNfired=0;
198}
199
200//_____________________________________________________________________________
202{
203 // Decode Raster
204 // loops over all modules defined in the detector map
205 // copies raw data into local variables
206 // pedestal subtraction is not foreseen for the raster
207
208 fNfired += THaBeamDet::Decode(evdata);
209
210 if( fNfired != NBPM && fNfired != NCHAN ) {
211 Warning(Here("Decode"), "Unexpected number of fired channels = %d."
212 "Setting beam position to nominal values.", fNfired);
213 Clear();
214 }
215 return 0;
216}
217
218//_____________________________________________________________________________
219bool THaRaster::CheckHitInfo( const DigitizerHitInfo_t& hitinfo ) const
220{
221 Int_t k = hitinfo.lchan;
222 if( k < 0 || k >= NCHAN ) {
223 Warning(Here("Decode"), "Illegal detector channel %d", k);
224 return false;
225 }
226 return true;
227}
228
229//_____________________________________________________________________________
231 const DigitizerHitInfo_t& hitinfo )
232{
233 if( !CheckHitInfo(hitinfo) )
234 return nullopt;
235 return THaBeamDet::LoadData(evdata, hitinfo);
236}
237
238//_____________________________________________________________________________
240{
241 // Store 'data' from single hit in channel 'hitinfo'. Called from Decode()
242
243 Int_t k = hitinfo.lchan;
244 assert(k >= 0 && k < NCHAN); // else bug in LoadData
245
246 if( k < NBPM )
247 fRawPos(k) = data;
248 else
249 fRawSlope(k-NBPM) = data;
250
251 return 0;
252}
253
254//_____________________________________________________________________________
256{
257 for( Int_t i = 0; i < NPOS; i++ ) {
258
259 // fPosition[i] = fRaw2Pos[i]*fRawPos+fPosOff[i] ;
260 // this is how i wish it would look like,
261 // but unluckily multiplications between tmatrix and tvector
262 // are not defined, as well as adding a tvector and a tvector3
263 // so i have to do it by hand instead ):
264
265 TVectorD dum(fRawPos);
266 dum *= fRaw2Pos[i];
267 fPosition[i].SetXYZ(dum(0) + fPosOff[i](0),
268 dum(1) + fPosOff[i](1),
269 dum(2) + fPosOff[i](2));
270
271 }
272
274
275 return 0;
276}
277
278
281
#define kOK
Definition BdataLoc.cxx:40
#define kInitError
Definition BdataLoc.cxx:41
int Int_t
unsigned int UInt_t
double Double_t
const char Option_t
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void data
Option_t Option_t TPoint TPoint const char mode
char name[80]
static const Int_t NCHAN
Definition THaBPM.cxx:22
static constexpr Int_t NCHAN
Definition THaRaster.cxx:20
static constexpr Int_t NBPM
Definition THaRaster.cxx:19
static constexpr Int_t NPOS
Definition THaRaster.cxx:18
static const char *const here
Definition THaVar.cxx:64
static Int_t LoadDB(FILE *file, const TDatime &date, const DBRequest *request, const char *prefix, Int_t search=0, const char *here="THaAnalysisObject::LoadDB")
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
virtual FILE * OpenFile(const TDatime &date)
@ kSkipLogicalChannel
Definition THaDetMap.h:95
UInt_t GetTotNumChan() const
Int_t FillDetMap(const std::vector< Int_t > &values, UInt_t flags=0, const char *here="FillDetMap")
THaDetMap * fDetMap
virtual OptUInt_t LoadData(const THaEvData &evdata, const DigitizerHitInfo_t &hitinfo)
virtual Int_t Decode(const THaEvData &)
virtual void Clear(Option_t *="")
TVectorD fSlopePedestal
Definition THaRaster.h:70
Int_t fNfired
Definition THaRaster.h:73
TVectorD fRasterPedestal
Definition THaRaster.h:71
virtual ~THaRaster()
bool CheckHitInfo(const DigitizerHitInfo_t &hitinfo) const
TVector3 fPosOff[3]
Definition THaRaster.h:67
virtual Int_t Decode(const THaEvData &)
TVectorD fRawSlope
Definition THaRaster.h:61
TVectorD fRasterFreq
Definition THaRaster.h:69
virtual Int_t DefineVariables(EMode mode=kDefine)
TVector3 fPosition[3]
Definition THaRaster.h:63
TVectorD fRawPos
Definition THaRaster.h:60
virtual Int_t StoreHit(const DigitizerHitInfo_t &hitinfo, UInt_t data)
virtual Int_t ReadDatabase(const TDatime &date)
Definition THaRaster.cxx:37
virtual OptUInt_t LoadData(const THaEvData &evdata, const DigitizerHitInfo_t &hitinfo)
TMatrixD fRaw2Pos[3]
Definition THaRaster.h:66
virtual Int_t Process()
TVector3 fDirection
Definition THaRaster.h:64
THaRaster(const char *name, const char *description="", THaApparatus *a=nullptr)
Definition THaRaster.cxx:23
TMatrixTBase< Element > & ResizeTo(const TMatrixT< Element > &m)
void Clear(Option_t *option="") override
virtual void Warning(const char *method, const char *msgfmt,...) const
virtual void Error(const char *method, const char *msgfmt,...) const
void SetY(Double_t)
void SetXYZ(Double_t x, Double_t y, Double_t z)
void SetX(Double_t)
void SetZ(Double_t)
void SetElements(const Element *elements)
STL namespace.
ClassImp(TPyArg)