18 #include "THaApparatus.h"
33 THaHelicityDet( name, description, app ),
34 fnQrt(-1), fHelDelay(8), fMAXBIT(30)
45 : fnQrt(-1), fHelDelay(8), fMAXBIT(30)
76 EStatus status = THaDetector::Init(date);
109 string kwPrefix = string(GetApparatus()->
GetName()) +
"_" + name;
110 std::transform(kwPrefix.begin(), kwPrefix.end(), kwPrefix.begin(), ::tolower);
118 cout <<
"In THcHelicity::ReadDatabase" << endl;
137 fFreq = 120.0007547169;
142 {
"helicity_delay", &
fHelDelay, kInt, 0, 1},
143 {
"helicity_freq", &
fFreq, kDouble, 0, 1},
172 cout <<
"Helicity decoder initialized with frequency of " <<
fFreq
173 <<
" Hz and reporting delay of " <<
fHelDelay <<
" cycles." << endl;
182 THaDetector::MakePrefix();
189 cout <<
"Called THcHelicity::DefineVariables with mode == "
192 if( mode == kDefine && fIsSetup )
return kOK;
193 fIsSetup = ( mode == kDefine );
196 THaHelicityDet::DefineVariables( mode );
198 const RVarDef var[] = {
199 {
"nqrt",
"position of cycle in quartet",
"fnQrt" },
200 {
"hel",
"actual helicity for event",
"fActualHelicity" },
201 {
"helrep",
"reported helicity for event",
"fReportedHelicity" },
202 {
"helpred",
"predicted reported helicity for event",
"fPredictedHelicity" },
203 {
"mps",
"In MPS blanking period",
"fMPS"},
204 {
"pcheck",
"Period check",
"fPeriodCheck"},
205 {
"cycle",
"Helicity Cycle",
"fCycle"},
206 {
"qrt",
"Last cycle of quartet",
"fQrt"},
209 cout <<
"Calling THcHelicity DefineVarsFromList" << endl;
210 return DefineVarsFromList( var, mode );
217 cout<<
" ++++++ THcHelicity::Print ++++++\n";
219 cout<<
" +++++++++++++++++++++++++++++++++++++\n";
265 THaHelicityDet::Clear(opt);
291 Error( Here(
"THcHelicity::Decode"),
"Error decoding helicity data." );
304 for(
Int_t i=0;i<nhelev;i++) {
312 for(nbehind=0;nbehind<4;nbehind++) {
315 cout <<
"Scaler seed behind " << nbehind
316 <<
" quartets" << endl;
318 cout <<
"Scaler Seed " << bitset<32>(
fScalerSeed) << endl;
325 cout <<
"Scaler seed does not match" << endl;
327 cout <<
"Scaler Seed " << bitset<32>(
fScalerSeed) << endl;
349 cout <<
"THcHelicity: Missed " << evnum-
fEvNumCheck <<
" events at event " << evnum << endl;
350 cout <<
" Disabling helicity decoding for rest of run." << endl;
351 cout <<
" Make sure \"RawDecode_master in cuts file accepts all physics events." <<endl;
410 for(
Int_t i=0;i<quartets_missed;i++) {
470 cout <<
"QRT Problem resetting" << endl;
490 cout <<
"Phase found from QRT signal" << endl;
513 cout <<
"Quartet potentially found, starting at cycle " <<
fFirstCycle
521 cout <<
"Lost quartet sync at cycle " <<
fNCycle << endl;
528 cout <<
"Searching for first of a quartet at cycle " <<
" " <<
fFirstCycle
559 cout <<
"Initializing" << endl;
576 cout <<
"Actual Helicity never got defined" << endl;
599 cout <<
"------------- HELICITY DECODING ----------------------" << endl;
600 cout <<
"Actual helicity reversal frequency differs from \"helicity_freq\" value" << endl;
601 cout <<
"If there are helicity decoding errors beyond the start of the run, " << endl;
602 streamsize ss = cout.precision();
605 cout <<
"If that still gives helicity errors, try " << 0.9999999*
fRecommendedFreq << endl;
607 cout <<
"------------------------------------------------------" << endl;
619 THaHelicityDet::SetDebug( level );
628 fnQrt = quartetphase;
633 cout <<
"fNBits = 0, missedcycles=" << missedcycles <<
651 cout <<
"Start calibrating at cycle " << cyclecount << endl;
673 cout <<
"Seed at cycle " <<
fFirstCycle <<
" should be " << hex << backseed << dec << endl;
685 cout <<
" -- Getting seed from scalers -- " << endl;
687 cout <<
"Scaler Seed " << bitset<32>(scalerseed) << endl;
691 fRingSeed_actual =
RanBit30(fRingSeed_actual);
701 if(quartetphase == 0) {
734 UInt_t bit7 = (ranseed & 0x00000040) != 0;
735 UInt_t bit28 = (ranseed & 0x08000000) != 0;
736 UInt_t bit29 = (ranseed & 0x10000000) != 0;
737 UInt_t bit30 = (ranseed & 0x20000000) != 0;
739 UInt_t newbit = (bit30 ^ bit29 ^ bit28 ^ bit7) & 0x1;
744 std::cerr<<
"ranseed must be greater than zero!"<<
"\n";
748 ranseed = ( (ranseed<<1) | newbit ) & 0x3FFFFFFF;
752 cout<<
"THcHelicity::RanBit30, newbit="<<newbit<<
"\n";
763 Int_t seed = currentseed;
764 for(
Int_t i=0;i<30;i++) {
765 UInt_t bit1 = (seed & 0x00000001) != 0;
766 UInt_t bit8 = (seed & 0x00000080) != 0;
767 UInt_t bit29 = (seed & 0x10000000) != 0;
768 UInt_t bit30 = (seed & 0x20000000) != 0;
770 UInt_t newbit30 = (bit30 ^ bit29 ^ bit8 ^ bit1) & 0x1;
771 seed = (seed >> 1) | (newbit30<<29);
774 Int_t bits = currentseed;
776 for(
Int_t i=0;i<30;i++) {
780 val = ((bits & (1<<(i)))!=0) ^ ((bits & (1<<(i+29)))!=0);
782 val = ((bits & (1<<(i)))!=0) ^ ((seed & (1<<(i-1)))!=0);
785 val = ((bits & (1<<(1-i)))!=0) ^ val;
787 val = ((seed & (1<<(i-2)))!=0) ^ val;
790 val = ((bits & (1<<(i-22)))!=0) ^ val;
792 val = ((seed & (1<<(i-23)))!=0) ^ val;
std::string GetName(const std::string &scope_name)
Int_t fRingSeed_reported_initial
virtual void Clear(Option_t *opt="")
THcHelicityScaler * fglHelicityScaler
Int_t ReadDatabase(const char *dbfilename, const char *prefix, const TDatime &date, int debug_flag=0)
virtual EStatus Init(const TDatime &date)
Event handler for Hall C helicity scalers.
virtual Int_t * GetHelicityHistoryP()
virtual Bool_t IsSeedGood()
virtual void SetHelicityScaler(THcHelicityScaler *f)
virtual Int_t ReadData(const THaEvData &evdata)
virtual Int_t ReadDatabase(const TDatime &date)
virtual void Clear(Option_t *opt="")
virtual Int_t DefineVariables(EMode mode=kDefine)
Determine the beam helicity for the current event.
void Error(const char *location, const char *msgfmt,...)
virtual void SetDebug(Int_t level)
virtual Int_t GetNcycles()
Int_t RanBit30(Int_t ranseed)
Double_t fPeriodCheckOffset
void Setup(const char *name, const char *description)
virtual Int_t GetReportedSeed()
Int_t fLastActualHelicity
Int_t LoadParmValues(const DBRequest *list, const char *prefix="")
Retrieve parameter values from the parameter cache.
void SetErrorCode(Int_t error)
void LoadHelicity(Int_t reportedhelicity, Int_t cyclecount, Int_t missedcycles)
ClassImp(THcDCLookupTTDConv) THcDCLookupTTDConv
Int_t GetSeed30(Int_t currentseed)
Int_t fQuartetStartPredictedHelicity
virtual void MakePrefix()
Int_t fHelperQuartetHistory
Int_t fQuartetStartHelicity
R__EXTERN class THcParmList * gHcParms
Int_t fLastReportedHelicity
virtual Int_t Decode(const THaEvData &evdata)
void PrintEvent(Int_t evtnum)
Double_t fRecommendedFreq
virtual Int_t GetNevents()