Hall A ROOT/C++ Analyzer (podd)
Loading...
Searching...
No Matches
THaBPM.cxx
Go to the documentation of this file.
1
2// //
3// THaBPM //
4// //
5// Class for a BPM //
6// measuring signals from four antennas //
7// and the position at the BPM (without phase correction) //
8// works with standard ADCs (lecroy like types) //
9// is good for unrastered beam, or to get average positions //
10// //
12
13#include "THaBPM.h"
14#include "THaEvData.h"
15#include "THaDetMap.h"
16#include "VarDef.h"
17#include "VarType.h"
18#include <vector>
19#include <stdexcept>
20#include <cassert>
21
22static const Int_t NCHAN = 4;
23
24using namespace std;
25
26//_____________________________________________________________________________
27THaBPM::THaBPM( const char* name, const char* description,
28 THaApparatus* apparatus ) :
29 THaBeamDet(name,description,apparatus),
30 fRawSignal(NCHAN),fPedestals(NCHAN),fCorSignal(NCHAN),fRotPos(NCHAN/2),
31 fRot2HCSPos(NCHAN/2,NCHAN/2), fCalibRot(0)
32{
33 // Constructor
34}
35
36
37//_____________________________________________________________________________
39{
40 // ReadDatabase: if detectors cant be added to detmap
41 // or entry for bpms is missing -> kInitError
42 // otherwise -> kOk
43
44 const char* const here = "ReadDatabase";
45
46 vector<Int_t> detmap;
47 Double_t pedestals[NCHAN], rotations[NCHAN], offsets[2];
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 // Read configuration parameters
58 DBRequest config_request[] = {
59 { "detmap", &detmap, kIntV },
60 { nullptr }
61 };
62 err = LoadDB( file, date, config_request, fPrefix );
63 }
64
66 if( !err && FillDetMap(detmap, flags, here) <= 0 ) {
67 err = kInitError; // Error already printed by FillDetMap
68 }
69
70 if( !err ) {
71 memset( pedestals, 0, sizeof(pedestals) );
72 memset( rotations, 0, sizeof(rotations) );
73 memset( offsets , 0, sizeof( offsets ) );
74 DBRequest calib_request[] = {
75 { "calib_rot", &fCalibRot },
76 { "pedestals", pedestals, kDouble, NCHAN, true },
77 { "rotmatrix", rotations, kDouble, NCHAN, true },
78 { "offsets" , offsets, kDouble, 2 , true },
79 { nullptr }
80 };
81 err = LoadDB( file, date, calib_request, fPrefix );
82 }
83 fclose(file);
84 if( err )
85 return err;
86
87 fOffset(0) = offsets[0];
88 fOffset(1) = offsets[1];
89
90 fPedestals.SetElements( pedestals );
91 fRot2HCSPos(0,0) = rotations[0];
92 fRot2HCSPos(0,1) = rotations[1];
93 fRot2HCSPos(1,0) = rotations[2];
94 fRot2HCSPos(1,1) = rotations[3];
95
96 return kOK;
97}
98
99//_____________________________________________________________________________
101{
102 // Initialize global variables
103
104 // Register variables in global list
105 RVarDef vars[] = {
106 { "rawcur.1", "current in antenna 1", "GetRawSignal0()"},
107 { "rawcur.2", "current in antenna 2", "GetRawSignal1()"},
108 { "rawcur.3", "current in antenna 3", "GetRawSignal2()"},
109 { "rawcur.4", "current in antenna 4", "GetRawSignal3()"},
110 { "x", "reconstructed x-position", "fPosition.fX"},
111 { "y", "reconstructed y-position", "fPosition.fY"},
112 { "z", "reconstructed z-position", "fPosition.fZ"},
113 { "rotpos1", "position in bpm system","GetRotPosX()"},
114 { "rotpos2", "position in bpm system","GetRotPosY()"},
115 { nullptr }
116 };
117
118 return DefineVarsFromList( vars, mode );
119}
120
121//_____________________________________________________________________________
123{
124 // Destructor. Remove variables from global list.
125
127}
128
129//_____________________________________________________________________________
131{
132 // Reset per-event data.
134 fPosition.SetXYZ(0., 0., -10000.);
135 fDirection.SetXYZ(0., 0., 1.);
136 for( Int_t k = 0; k < NCHAN; ++k ) {
137 fRawSignal(k) = -1;
138 fCorSignal(k) = -1;
139 }
140 fRotPos(0) = fRotPos(1) = 0.0;
141}
142
143//_____________________________________________________________________________
145{
146 // Decode BPM
147 // loops over all modules defined in the detector map
148 // copies raw data into local variables
149 // performs pedestal subtraction
150
151 Int_t nfired = THaBeamDet::Decode(evdata);
152
153 if( nfired == NCHAN ) {
155 } else {
156 Warning(Here("Decode"), "Number of fired Channels out of range. "
157 "Setting beam position to nominal values");
158 }
159
160 return 0;
161}
162
163//_____________________________________________________________________________
164bool THaBPM::CheckHitInfo( const DigitizerHitInfo_t& hitinfo ) const
165{
166 Int_t k = hitinfo.lchan;
167 if( k >= NCHAN || fRawSignal(k) != -1 ) {
168 Warning(Here("Decode"), "Illegal detector channel %d", k);
169 return false;
170 }
171 return true;
172}
173
174//_____________________________________________________________________________
176 const DigitizerHitInfo_t& hitinfo )
177{
178 if( !CheckHitInfo(hitinfo) )
179 return nullopt;
180 return THaBeamDet::LoadData(evdata, hitinfo);
181}
182
183//_____________________________________________________________________________
185{
186 // Store 'data' from single hit in channel 'hitinfo'. Called from Decode()
187
188 Int_t k = hitinfo.lchan;
189 assert(k >= 0 && k < NCHAN && fRawSignal(k) == -1); // else bug in LoadData
190
191 fRawSignal(k) = data;
192 return 0;
193}
194
195//_____________________________________________________________________________
197{
198 // called by the beam apparatus
199 // uses the pedestal subtracted signals from the antennas
200 // to get the position in the bpm coordinate system
201 // and uses the transformation matrix defined in the database
202 // to transform it into the HCS
203 // directions are not calculated, they are always set parallel to z
204
205 for( Int_t k = 0; k < NCHAN; k += 2 ) {
206 Double_t ap = fCorSignal(k);
207 Double_t am = fCorSignal(k + 1);
208 if( ap + am != 0.0 ) {
209 fRotPos(k / 2) = fCalibRot * (ap - am) / (ap + am);
210 } else {
211 fRotPos(k / 2) = 0.0;
212 }
213 }
214 TVectorD dum(fRotPos);
215 dum *= fRot2HCSPos;
217 dum(0) + fOrigin(0) + fOffset(0),
218 dum(1) + fOrigin(1) + fOffset(1),
219 fOrigin(2)
220 );
221
222 return 0;
223}
224
#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 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)
virtual Int_t StoreHit(const DigitizerHitInfo_t &hitinfo, UInt_t data)
Definition THaBPM.cxx:184
virtual ~THaBPM()
Definition THaBPM.cxx:122
virtual Int_t Decode(const THaEvData &)
Definition THaBPM.cxx:144
virtual Int_t DefineVariables(EMode mode=kDefine)
Definition THaBPM.cxx:100
virtual Int_t Process()
Definition THaBPM.cxx:196
TVectorD fPedestals
Definition THaBPM.h:42
TVector3 fOffset
Definition THaBPM.h:46
THaBPM()
Definition THaBPM.h:19
Double_t fCalibRot
Definition THaBPM.h:50
virtual Int_t ReadDatabase(const TDatime &date)
Definition THaBPM.cxx:38
TVector3 fDirection
Definition THaBPM.h:48
TMatrixD fRot2HCSPos
Definition THaBPM.h:45
TVector3 fPosition
Definition THaBPM.h:47
TVectorD fRawSignal
Definition THaBPM.h:41
virtual void Clear(Option_t *="")
Definition THaBPM.cxx:130
TVectorD fCorSignal
Definition THaBPM.h:43
virtual OptUInt_t LoadData(const THaEvData &evdata, const DigitizerHitInfo_t &hitinfo)
Definition THaBPM.cxx:175
TVectorD fRotPos
Definition THaBPM.h:44
bool CheckHitInfo(const DigitizerHitInfo_t &hitinfo) const
Definition THaBPM.cxx:164
@ kFillLogicalChannel
Definition THaDetMap.h:96
Int_t FillDetMap(const std::vector< Int_t > &values, UInt_t flags=0, const char *here="FillDetMap")
virtual Int_t ReadGeometry(FILE *file, const TDatime &date, Bool_t required=false)
virtual OptUInt_t LoadData(const THaEvData &evdata, const DigitizerHitInfo_t &hitinfo)
virtual Int_t Decode(const THaEvData &)
void Clear(Option_t *option="") override
virtual void Warning(const char *method, const char *msgfmt,...) const
void SetXYZ(Double_t x, Double_t y, Double_t z)
void SetElements(const Element *elements)
STL namespace.
ClassImp(TPyArg)