Hall A ROOT/C++ Analyzer (podd)
Loading...
Searching...
No Matches
THaG0HelicityReader.cxx
Go to the documentation of this file.
1//*-- Author : Ole Hansen August 2006
2// Extracted from Bob Michaels' THaHelicity CVS 1.19
4//
5// THaG0HelicityReader
6//
8
10#include "THaEvData.h"
11#include "TMath.h"
12#include "TError.h"
13#include "VarDef.h"
14#include "THaAnalysisObject.h" // For LoadDB
15#include <iostream>
16
17using namespace std;
18
19//____________________________________________________________________
24
25//____________________________________________________________________
27 fPresentReading(0), fQrt(0), fGate(0), fTimestamp(0),
28 fOldT1(-1.0), fOldT2(-1.0), fOldT3(-1.0), fValidTime(false),
29 fG0Debug(0), fHaveROCs(false), fNegGate(false)
30{
31 // Default constructor
32}
33
34//____________________________________________________________________
36{
38 fTimestamp = 0.0;
39 fValidTime = false;
40}
41
42//____________________________________________________________________
44 const ROCinfo& info )
45{
46 UInt_t len = evdata.GetRocLength(info.roc);
47 if (len <= 4)
48 return -1;
49
50 UInt_t i = 0;
51 if( info.header == 0 )
52 i = info.index;
53 else {
54 for( ; i < len && evdata.GetRawData(info.roc, i) != info.header; ++i ) {}
55 i += info.index;
56 }
57 return (i < len) ? i : kMaxUInt;
58}
59
60//_____________________________________________________________________________
62 const char* prefix,
63 const TDatime& date,
64 int debug_flag )
65{
66 // Read parameters from database: ROC info (detector map), G0 delay value
67
68 static const char* const here = "THaG0HelicityReader::ReadDatabase";
69
70 FILE* file = Podd::OpenDBFile(dbfilename, date, here, "r", debug_flag);
72
73 Int_t invert_gate = 0;
75 DBRequest req[] = {
76 { "helroc", &fROCinfo[kHel], kInt, 3, false, -2 },
77 { "timeroc", &fROCinfo[kTime], kInt, 3, false, -2 },
78 { "time2roc", &fROCinfo[kROC2], kInt, 3, true, -2 },
79 { "time3roc", &fROCinfo[kROC3], kInt, 3, true, -2 },
80 { "neg_g0_gate", &invert_gate, kInt, 0, true, -2 },
81 { nullptr }
82 };
83 Int_t st = THaAnalysisObject::LoadDB( file, date, req, prefix );
84 fclose(file);
85 if( st )
87
88 // Require the helicity and time ROCs to be defined
90 // If ROC2 or ROC3 are defined in tha database, they must be valid
91 st = any_of(fROCinfo+kROC2, fROCinfo + kROC3+1, []( const ROCinfo& R ) {
92 return R.roc != kMaxUInt && !R.valid();
93 });
94
95 if( st || !fHaveROCs ) {
96 ::Error( here, "Invalid ROC data. Fix database." );
98 }
99
100 fNegGate = (invert_gate != 0);
101
103}
104
105//____________________________________________________________________
107{
108
109 // Obtain the present data from the event for G0 helicity mode.
110
111 static const char* here = "THaG0HelicityReader::ReadData";
112
113 if( !fHaveROCs ) {
114 ::Error( here, "ROC data (detector map) not properly set up." );
115 return -1;
116 }
117 UInt_t hroc = fROCinfo[kHel].roc;
118 UInt_t len = evdata.GetRocLength(hroc);
119 if (len <= 4)
120 return -1;
121
122 UInt_t ihel = FindWord( evdata, fROCinfo[kHel] );
123 if (ihel == kMaxUInt) {
124 ::Error( here , "Cannot find helicity" );
125 return -1;
126 }
127 UInt_t itime = FindWord( evdata, fROCinfo[kTime] );
128 if (itime == kMaxUInt) {
129 ::Error( here, "Cannot find timestamp" );
130 return -1;
131 }
132
133 UInt_t data = evdata.GetRawData( hroc, ihel );
134 fPresentReading = ((data & 0x10) != 0);
135 fQrt = ((data & 0x20) != 0);
136 fGate = ((data & 0x40) != 0);
137 fTimestamp = static_cast<Double_t>( evdata.GetRawData( hroc, itime) );
138
139 // Invert the gate polarity if requested
140 if( fNegGate )
141 fGate = !fGate;
142
143 // Look for redundant clock info and patch up time if it appears wrong
144
145 if( fROCinfo[kROC2].valid() && fROCinfo[kROC3].valid() ) {
146 UInt_t itime2 = FindWord( evdata, fROCinfo[kROC2] );
147 UInt_t itime3 = FindWord( evdata, fROCinfo[kROC3] );
148 if (itime2 != kMaxUInt && itime3 != kMaxUInt ) {
150 Double_t t2 = evdata.GetRawData(fROCinfo[kROC2].roc, itime2);
151 Double_t t3 = evdata.GetRawData(fROCinfo[kROC3].roc, itime3);
152 Double_t t2t1 = fOldT1 + t2 - fOldT2;
153 Double_t t3t1 = fOldT1 + t3 - fOldT3;
154 // We believe t1 unless it disagrees with t2 and t2 agrees with t3
155 if (fOldT1 >= 0.0 && TMath::Abs(t1-t2t1) > 3.0
156 && TMath::Abs(t2t1-t3t1) <= 3.0 ) {
157 if (fG0Debug >= 1)
158 ::Warning( here, "Clock 1 disagrees with 2, 3; using 2: %lf %lf %lf",
159 t1, t2t1, t3t1 );
160 fTimestamp = t2t1;
161 }
162 if (fG0Debug >= 3) {
163 cout << "Clocks: " << t1
164 << " " << t2 << "->" << t2t1
165 << " " << t3 << "->" << t3t1
166 << endl;
167 }
169 fOldT2 = t2;
170 fOldT3 = t3;
171 }
172 }
173
174 fValidTime = true;
175
176 return 0;
177}
178
179//____________________________________________________________________
int Int_t
unsigned int UInt_t
bool Bool_t
const UInt_t kMaxUInt
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 GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t WindowAttributes_t Float_t Float_t Float_t Int_t Int_t UInt_t UInt_t Rectangle_t Int_t Int_t Window_t TString Int_t GCValues_t GetPrimarySelectionOwner GetDisplay GetScreen GetColormap GetNativeEvent const char const char dpyName wid window const char font_name cursor keysym reg const char only_if_exist regb h Point_t winding char text const char depth char const char Int_t count const char ColorStruct_t color const char Pixmap_t Pixmap_t PictureAttributes_t attr const char char ret_data h unsigned char height h Atom_t Int_t ULong_t ULong_t unsigned char prop_list Atom_t Atom_t Atom_t Time_t UChar_t len
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")
UInt_t GetRawData(UInt_t crate, UInt_t slot, UInt_t hit) const
Definition THaEvData.h:288
UInt_t GetRocLength(UInt_t crate) const
Definition THaEvData.h:259
virtual Int_t ReadData(const THaEvData &evdata)
Int_t ReadDatabase(const char *dbfilename, const char *prefix, const TDatime &date, int debug_flag=0)
ROCinfo fROCinfo[kROC3+1]
static UInt_t FindWord(const THaEvData &evdata, const ROCinfo &info)
virtual void Clear(Option_t *opt="")
static const UInt_t MAXROC
Definition Decoder.h:33
constexpr Double_t R()
Double_t Abs(Double_t d)
STL namespace.
auto * t1
ClassImp(TPyArg)