Hall C ROOT/C++ Analyzer (hcana)
THcHelicityReader.cxx
Go to the documentation of this file.
1 
13 #include "THcHelicityReader.h"
14 #include "THaEvData.h"
15 #include "THcGlobals.h"
16 #include "THcParmList.h"
17 #include "TMath.h"
18 #include "TError.h"
19 #include "VarDef.h"
20 #include "THaAnalysisObject.h" // For LoadDB
21 #include <iostream>
22 #include <vector>
23 #include "TH1F.h"
24 
25 using namespace std;
26 
27 //____________________________________________________________________
29  : fTITime(0), fTITime_last(0), fTITime_rollovers(0),
30  fHaveROCs(kFALSE)
31 {
32  // Default constructor
33 
34 }
35 //____________________________________________________________________
37 {
38  // Destructor
39 
40  // Histograms will be deleted by ROOT
41  // for( Int_t i = 0; i < NHISTR; ++i ) {
42  // delete fHistoR[i];
43  // }
44 }
45 
46 //____________________________________________________________________
48 {
49 
51 
52 }
53 
54 //_____________________________________________________________________________
55 Int_t THcHelicityReader::ReadDatabase( const char* /*dbfilename*/,
56  const char* /*prefix*/,
57  const TDatime& /*date*/,
58  int /*debug_flag*/ )
59 {
60 
61  // Eventually get these from the parameter file
62 
63  // SHMS settings see https://logbooks.jlab.org/entry/3614445
64  cout << "THcHelicityReader: Helicity information from ROC 2 (SHMS)" << endl;
65  SetROCinfo(kHel,2,14,9);
66  SetROCinfo(kHelm,2,14,8);
67  SetROCinfo(kMPS,2,14,10);
68  SetROCinfo(kQrt,2,14,7); // Starting about run 5818
69  SetROCinfo(kTime,2,21,2);
70 
71  fADCThreshold = 8000;
72 
73  DBRequest list[] = {
74  {"helicity_adcthreshold",&fADCThreshold, kInt, 0, 1},
75  {0}
76  };
77 
78  gHcParms->LoadParmValues(list, "");
79 
80  return THaAnalysisObject::kOK;
81 }
82 
83 //_____________________________________________________________________________
85 {
86  // static const char* const here = "THcHelicityReader::Begin";
87  // cout<<here<<endl;
88 
89  fTITime_last = 0;
90  fTITime = 0;
92 
93  return;
94 }
95 //____________________________________________________________________
97 {
98  // static const char* const here = "THcHelicityReader::End";
99  // cout<<here<<endl;
100 
101  return;
102 }
103 //____________________________________________________________________
105 {
106  // Obtain the present data from the event for QWEAK helicity mode.
107 
108  static const char* here = "THcHelicityReader::ReadData";
109 
110  // std::cout<<" kHel, kTime, kRing="<< kHel<<" "<<kTime<<" "<<kRing<<endl;
111  // for (int jk=0; jk<3; jk++)
112  // {
113  // std::cout<<" which="<<jk
114  // <<" roc="<<fROCinfo[jk].roc
115  // <<" header="<<fROCinfo[jk].header
116  // <<" index="<<fROCinfo[jk].index
117  // <<endl;
118  // }
119 
120  // std::cout<<" fHaveROCs="<<fHaveROCs<<endl;
121  if( !fHaveROCs ) {
122  ::Error( here, "ROC data (detector map) not properly set up." );
123  return -1;
124  }
125 
126  // Check if ROC info is correct
127 
128  if(!evdata.GetModule(fROCinfo[kTime].roc, fROCinfo[kTime].slot)) {
129  cout << "THcHelicityReader: ROC 2 not found" << endl;
130  cout << "Changing to ROC 1 (HMS)" << endl;
131  SetROCinfo(kHel,1,18,9);
132  SetROCinfo(kHelm,1,18,8);
133  SetROCinfo(kMPS,1,18,10);
134  SetROCinfo(kQrt,1,18,7);
135  SetROCinfo(kTime,1,21,2);
136  }
137 
138  // Get the TI Data
139  // Int_t fTIType = evData.GetData(fTICrate, fTISlot, 0, 0);
140  // Int_t fTIEvNum = evData.GetData(fTICrate, fTISlot, 1, 0);
141  UInt_t titime = (UInt_t) evdata.GetData(fROCinfo[kTime].roc,
142  fROCinfo[kTime].slot,
143  fROCinfo[kTime].index, 0);
144  // Check again if ROC info is correct
145  if(titime == 0 && fTITime_last==0) {
146  cout << "THcHelicityReader: ROC 2 not found" << endl;
147  cout << "Changing to ROC 1 (HMS)" << endl;
148  SetROCinfo(kHel,1,18,9);
149  SetROCinfo(kHelm,1,18,8);
150  SetROCinfo(kMPS,1,18,10);
151  SetROCinfo(kQrt,1,18,7);
152  SetROCinfo(kTime,1,21,2);
153  titime = (UInt_t) evdata.GetData(fROCinfo[kTime].roc,
154  fROCinfo[kTime].slot,
155  fROCinfo[kTime].index, 0);
156  }
157  //cout << fTITime_last << " " << titime << endl;
158  if(titime < fTITime_last) {
160  }
161  fTITime = titime + fTITime_rollovers*4294967296;
162  fTITime_last = titime;
163 
164  const_cast<THaEvData&>(evdata).SetEvTime(fTITime);
165 
166  // Get the helicity control signals. These are from the pedestals
167  // acquired by FADC channels.
168 
169  Int_t helpraw = evdata.GetData(Decoder::kPulsePedestal,
170  fROCinfo[kHel].roc,
171  fROCinfo[kHel].slot,
172  fROCinfo[kHel].index, 0);
173  Int_t helmraw = evdata.GetData(Decoder::kPulsePedestal,
174  fROCinfo[kHelm].roc,
175  fROCinfo[kHelm].slot,
176  fROCinfo[kHelm].index, 0);
177  Int_t mpsraw = evdata.GetData(Decoder::kPulsePedestal,
178  fROCinfo[kMPS].roc,
179  fROCinfo[kMPS].slot,
180  fROCinfo[kMPS].index, 0);
181  Int_t qrtraw = evdata.GetData(Decoder::kPulsePedestal,
182  fROCinfo[kQrt].roc,
183  fROCinfo[kQrt].slot,
184  fROCinfo[kQrt].index, 0);
185 
186  fIsQrt = qrtraw > fADCThreshold;
187  fIsMPS = mpsraw > fADCThreshold;
188  fIsHelp = helpraw > fADCThreshold;
189  fIsHelm = helmraw > fADCThreshold;
190 
191  return 0;
192 }
193 
194 //TODO: this should not be needed once LoadDB can fill fROCinfo directly
195 //____________________________________________________________________
197  Int_t slot, Int_t index )
198 {
199 
200  // Define source and offset of data. Normally called by ReadDatabase
201  // of the detector that is a THcHelicityReader.
202  //
203  // "which" is one of { kHel, kKelm, kQrt, kTime }.
204  // You must define at least the kHel and kTime ROCs.
205  // Returns <0 if parameter error, 0 if success
206 
207  if( which<kHel || which>=kCount )
208  return -1;
209  if( roc <= 0 || roc > 255 )
210  return -2;
211 
212  fROCinfo[which].roc = roc;
213  fROCinfo[which].slot = slot;
214  fROCinfo[which].index = index;
215 
216  cout << "SetROCInfo: " << which << " " << fROCinfo[which].roc << " " << fROCinfo[which].slot <<
217  " " << fROCinfo[which].index << endl;
218  fHaveROCs = (fROCinfo[kHel].roc > 0 && fROCinfo[kTime].roc > 0 && fROCinfo[kMPS].roc);
219 
220  return 0;
221 }
222 
223 //____________________________________________________________________
225 
virtual Decoder::Module * GetModule(UInt_t roc, UInt_t slot) const
virtual void Clear(Option_t *opt="")
const char Option_t
Int_t ReadDatabase(const char *dbfilename, const char *prefix, const TDatime &date, int debug_flag=0)
int Int_t
STL namespace.
virtual Int_t ReadData(const THaEvData &evdata)
Int_t SetROCinfo(EROC which, Int_t roc, Int_t slot, Int_t index)
ROCinfo fROCinfo[kCount]
unsigned int UInt_t
UInt_t GetData(UInt_t crate, UInt_t slot, UInt_t chan, UInt_t hit) const
tuple list
Definition: SConscript.py:9
const Bool_t kFALSE
Int_t LoadParmValues(const DBRequest *list, const char *prefix="")
Retrieve parameter values from the parameter cache.
ClassImp(THcDCLookupTTDConv) THcDCLookupTTDConv
R__EXTERN class THcParmList * gHcParms
Definition: THcGlobals.h:11
Extract helicity information from FADC250 modules.