Hall A ROOT/C++ Analyzer (podd)
Loading...
Searching...
No Matches
THaADCHelicity.cxx
Go to the documentation of this file.
1//*-- Author : Robert Michaels Sept 2002
2// Updated by Vincent Sulkosky Jan 2006
3// More updates by Richard Holmes, Feb 2006
4// Changed into an implementation of THaHelicityDet, Ole Hansen, Aug 2006
6//
7// THaADCHelicity
8//
9// Helicity of the beam - from a single ADC.
10// +1 = plus, -1 = minus, 0 = unknown
11//
13
14#include "THaADCHelicity.h"
15#include "THaEvData.h"
16#include "VarDef.h"
17#include <iostream>
18#include <vector>
19
20using namespace std;
21
22static const Double_t kDefaultThreshold = 4000.0;
23
24//____________________________________________________________________
25THaADCHelicity::THaADCHelicity( const char* name, const char* description,
26 THaApparatus* app ) :
27 THaHelicityDet( name, description, app ),
28 fADC_hdata(kBig), fADC_Gate(kBig), fADC_Hel(kUnknown),
29 fThreshold(kDefaultThreshold), fIgnoreGate(false),
30 fInvertGate(false), fNchan(0)
31{
32 // Constructor
33}
34
35//____________________________________________________________________
40
41//_____________________________________________________________________________
43{
44 // Initialize global variables
45
47 if( ret )
48 return ret;
49
50 const RVarDef var[] = {
51 { "adc", "Helicity ADC raw data", "fADC_hdata" },
52 { "gate_adc", "Gate ADC raw data", "fADC_Gate" },
53 { "adc_hel", "Beam helicity from ADC", "fADC_Hel" },
54 { nullptr }
55 };
56 return DefineVarsFromList( var, mode );
57}
58
59
60//____________________________________________________________________
62{
63
64 static const char* const here = "ReadDatabase";
65
67 if( err )
68 return err;
69
70 FILE* file = OpenFile( date );
71 if( !file ) return kFileError;
72
73 vector<Int_t> heldef, gatedef;
75 Int_t ignore_gate = -1, invert_gate = 0;
76 const DBRequest request[] = {
77 { "helchan", &heldef, kIntV, 0, false, -2 },
78 { "gatechan", &gatedef, kIntV, 0, true, -2 },
79 { "threshold", &fThreshold, kDouble, 0, true, -2 },
80 { "ignore_gate", &ignore_gate, kInt, 0, true, -2 },
81 { "invert_gate", &invert_gate, kInt, 0, true, -2 },
82 { nullptr }
83 };
84 // Database keys are prefixed with this detector's name, not apparatus.name
85 err = LoadDB( file, date, request, fPrefix );
86 fclose(file);
87 if( err )
88 return kInitError;
89
90 if( heldef.size() != 3 ) {
91 Error( Here(here), "Incorrect definition of helicity data channel. Must be "
92 "exactly 3 numbers (roc,slot,chan), found %u. Fix database.",
93 static_cast<unsigned int>(heldef.size()) );
94 return kInitError;
95 }
96 // Missing gate channel implies ignoring gate unless explicitly set
97 if( gatedef.empty() ) {
98 if( ignore_gate < 0 )
99 fIgnoreGate = true;
100 else {
101 Error( Here(here), "Missing gate data channel definition gatechan. "
102 "Fix database." );
103 return kInitError;
104 }
105 }
106 if( !gatedef.empty() && gatedef.size() != 3 ) {
107 Error( Here(here), "Incorrect definition of gate data channel. Must be "
108 "exactly 3 numbers (roc,slot,chan), found %u. Fix database.",
109 static_cast<unsigned int>(gatedef.size()) );
110 return kInitError;
111 }
112
113 fIgnoreGate = (ignore_gate > 0);
114 // If ignoring gate and no gate channel given, decode only one
115 fNchan = (fIgnoreGate && gatedef.empty()) ? 1 : 2;
116
117 try {
118 fAddr[0] = heldef;
119 if( !gatedef.empty() )
120 fAddr[1] = gatedef;
121 }
122 catch( const std::out_of_range& e) {
123 Error( Here(here), "%s. Fix database.", e.what() );
124 return kInitError;
125 }
126 fInvertGate = (invert_gate != 0);
127
128 fIsInit = true;
129 return kOK;
130}
131
132//____________________________________________________________________
134{
135 // Clear the event data
136
139 fADC_Gate = kBig;
141}
142
143//____________________________________________________________________
145{
146 // Decode Helicity data.
147 // Return 1 if helicity was assigned, 0 if not, -1 if error.
148
149 // Only the first two channels defined in the detector map are used
150 // here, regardless of how they are defined (consecutive channels
151 // in same module or otherwise). ReadDatabase guarantees that two channels
152 // are present and warns about extra channels.
153
154 if( !fIsInit )
155 return -1;
156
157 Int_t ret = 0;
158 bool gate_high = false;
159
160 for( UInt_t i = 0; i < fNchan; ++i ) {
161 UInt_t roc = fAddr[i].roc, slot = fAddr[i].slot, chan = fAddr[i].chan;
162 if ( !evdata.GetNumHits( roc, slot, chan ))
163 continue;
164
165 auto data = static_cast<Double_t>(evdata.GetData( roc, slot, chan, 0 ));
166
167 if (fDebug >= 3) {
168 cout << "crate "<<roc<<" slot "<<slot<<" chan "
169 <<chan<<" data "<<data<<" ";
170 if (data > fThreshold)
171 cout << " above cut !";
172 cout << endl;
173 }
174
175 // Assign gate and helicity bit data. The first data channel is
176 // the helicity bit, the second, the gate.
177 switch(i) {
178 case 0:
179 fADC_hdata = data;
180 break;
181 case 1:
182 fADC_Gate = data;
183 gate_high = fInvertGate ? (data < fThreshold) : (data >= fThreshold);
184 break;
185 default:
186 break;
187 }
188 }
189
190 // Logic: if gate==0 helicity remains unknown. If gate==1
191 // (or we are ignoring the gate) then helicity is determined by
192 // the helicity bit.
193 if( gate_high || fIgnoreGate ) {
195 ret = 1;
196 }
197
198 // fHelicity may be reassigned by derived classes, so we must keep the ADC
199 // result separately. But within this class, the two are the same.
200 if( fSign >= 0 )
202 else
203 fHelicity = ( fADC_Hel == kPlus ) ? kMinus : kPlus;
204
205 if (fDebug >= 3) {
206 cout << "ADC helicity info "<<endl
207 << "Gate "<<fADC_Gate<<" helic. bit "<<fADC_hdata
208 << " ADC helicity "<<fADC_Hel
209 << " resulting helicity"<<fHelicity<<endl;
210 }
211
212 return ret;
213}
214
215
217
#define kOK
Definition BdataLoc.cxx:40
#define kInitError
Definition BdataLoc.cxx:41
int Int_t
unsigned int UInt_t
const Data_t kBig
Definition DataType.h:15
uint32_t chan
#define e(i)
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 Double_t kDefaultThreshold
static const char *const here
Definition THaVar.cxx:64
kUnknown
Double_t fThreshold
virtual Int_t DefineVariables(EMode mode=kDefine)
virtual ~THaADCHelicity()
Double_t fADC_hdata
virtual Int_t ReadDatabase(const TDatime &date)
ChanDef_t fAddr[2]
virtual Int_t Decode(const THaEvData &evdata)
virtual void Clear(Option_t *opt="")
EHelicity fADC_Hel
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)
UInt_t GetNumHits(UInt_t crate, UInt_t slot, UInt_t chan) const
Definition THaEvData.h:264
UInt_t GetData(UInt_t crate, UInt_t slot, UInt_t chan, UInt_t hit) const
Definition THaEvData.h:273
virtual void Clear(Option_t *opt="")
virtual Int_t ReadDatabase(const TDatime &date)
EHelicity fHelicity
virtual Int_t DefineVariables(EMode mode=kDefine)
virtual void Error(const char *method, const char *msgfmt,...) const
STL namespace.
ClassImp(TPyArg)