Skip to content
Snippets Groups Projects
Commit 76bbcc81 authored by Stephen A. Wood's avatar Stephen A. Wood Committed by Mark K Jones
Browse files

Improve THcHelicity

  Previously the helicity code was not always setting the actual
  helicity.  It would then just use the helicity from the last event.
  This was almost always OK.  With this change, the helicity (T.helicity.hel)
  should be always defined.
  It is now sufficient to use just this variable when sorting events into
  plus and minus helicity.  The helicity value will be zero if the event
  occured during the settle period, or if the helicity decoder has not
  got enough data to have a seed.
parent 0e0eb28f
No related branches found
No related tags found
No related merge requests found
...@@ -73,6 +73,9 @@ THaAnalysisObject::EStatus THcHelicity::Init(const TDatime& date) { ...@@ -73,6 +73,9 @@ THaAnalysisObject::EStatus THcHelicity::Init(const TDatime& date) {
return fStatus; return fStatus;
} }
fEvNumCheck = 0;
fDisabled = kFALSE;
fStatus = kOK; fStatus = kOK;
return fStatus; return fStatus;
} }
...@@ -140,6 +143,9 @@ Int_t THcHelicity::ReadDatabase( const TDatime& date ) ...@@ -140,6 +143,9 @@ Int_t THcHelicity::ReadDatabase( const TDatime& date )
// Initialize mode to find quartets and then seed // Initialize mode to find quartets and then seed
} }
cout << "Helicity decoder initialized with frequency of " << fFreq
<< " Hz and reporting delay of " << fHelDelay << " cycles." << endl;
return kOK; return kOK;
} }
...@@ -256,11 +262,32 @@ Int_t THcHelicity::Decode( const THaEvData& evdata ) ...@@ -256,11 +262,32 @@ Int_t THcHelicity::Decode( const THaEvData& evdata )
fActualHelicity = fIsMPS?kUnknown:fReportedHelicity; fActualHelicity = fIsMPS?kUnknown:fReportedHelicity;
return 0; return 0;
} }
Long64_t lastlastmpstime = fLastMPSTime;
if(fDisabled) {
fActualHelicity = kUnknown;
return 0;
}
fEvNumCheck++;
Int_t evnum = evdata.GetEvNum();
if(fEvNumCheck!=evnum) {
cout << "THcHelicity: Missed " << evnum-fEvNumCheck << " events at event " << evnum << endl;
cout << " Disabling helicity decoding for rest of run." << endl;
cout << " Make sure \"RawDecode_master in cuts file accepts all physics events." <<endl;
fDisabled = kTRUE;
fActualHelicity = kUnknown;
return 0;
}
fActualHelicity = -10.0;
if(fFirstEvProcessed) { // Normal processing if(fFirstEvProcessed) { // Normal processing
// cout << evnum << " " << fNCycle << " " << fIsMPS << " " << fFoundMPS << " " << fTITime << " "
// << fLastMPSTime << " " << fNBits << endl;
Int_t missed = 0; Int_t missed = 0;
// Double_t elapsed_time = (fTITime - fFirstEvTime)/250000000.0; // Double_t elapsed_time = (fTITime - fFirstEvTime)/250000000.0;
if(fIsMPS) { if(fIsMPS) {
fActualHelicity = kUnknown;
fPredictedHelicity = kUnknown;
if(fFoundMPS) { if(fFoundMPS) {
missed = TMath::Nint(fTITime/fTIPeriod-fLastMPSTime/fTIPeriod); missed = TMath::Nint(fTITime/fTIPeriod-fLastMPSTime/fTIPeriod);
if(missed < 1) { // was <=1 if(missed < 1) { // was <=1
...@@ -292,12 +319,6 @@ Int_t THcHelicity::Decode( const THaEvData& evdata ) ...@@ -292,12 +319,6 @@ Int_t THcHelicity::Decode( const THaEvData& evdata )
} }
int quartetphase = (newNCycle-fFirstCycle)%4; int quartetphase = (newNCycle-fFirstCycle)%4;
// cout << " " << fNCycle << " " << newNCycle << " " << fFirstCycle << " " << quartets_missed << " " << quartetphase << endl; // cout << " " << fNCycle << " " << newNCycle << " " << fFirstCycle << " " << quartets_missed << " " << quartetphase << endl;
fQuartetStartHelicity = (fRingSeed_actual&1)?kPlus:kMinus;
fQuartetStartPredictedHelicity = (fRingSeed_reported&1)?kPlus:kMinus;
fActualHelicity = (quartetphase==0||quartetphase==3)?
fQuartetStartHelicity:-fQuartetStartHelicity;
fPredictedHelicity = (quartetphase==0||quartetphase==3)?
fQuartetStartPredictedHelicity:-fQuartetStartPredictedHelicity;
// cout << "Cycles " << fNCycle << " " << newNCycle << " " << fFirstCycle // cout << "Cycles " << fNCycle << " " << newNCycle << " " << fFirstCycle
// << " skipped " << quartets_missed << " quartets" << endl; // << " skipped " << quartets_missed << " quartets" << endl;
fNCycle = newNCycle; fNCycle = newNCycle;
...@@ -305,6 +326,13 @@ Int_t THcHelicity::Decode( const THaEvData& evdata ) ...@@ -305,6 +326,13 @@ Int_t THcHelicity::Decode( const THaEvData& evdata )
// reported helicity. So we don't fail quartet testing. // reported helicity. So we don't fail quartet testing.
// But only do this if we are calibrated. // But only do this if we are calibrated.
if(fNBits >= fMAXBIT) { if(fNBits >= fMAXBIT) {
fQuartetStartHelicity = (fRingSeed_actual&1)?kPlus:kMinus;
fQuartetStartPredictedHelicity = (fRingSeed_reported&1)?kPlus:kMinus;
fActualHelicity = (quartetphase==0||quartetphase==3)?
fQuartetStartHelicity:-fQuartetStartHelicity;
fPredictedHelicity = (quartetphase==0||quartetphase==3)?
fQuartetStartPredictedHelicity:-fQuartetStartPredictedHelicity;
if (((fNCycle - fFirstCycle)%2)==1) { if (((fNCycle - fFirstCycle)%2)==1) {
fQuartet[0] = fReportedHelicity; fQuartet[0] = fReportedHelicity;
fQuartet[1] = fQuartet[2] = -fQuartet[0]; fQuartet[1] = fQuartet[2] = -fQuartet[0];
...@@ -313,6 +341,7 @@ Int_t THcHelicity::Decode( const THaEvData& evdata ) ...@@ -313,6 +341,7 @@ Int_t THcHelicity::Decode( const THaEvData& evdata )
fQuartet[2] = -fQuartet[1]; fQuartet[2] = -fQuartet[1];
} }
} else { } else {
fActualHelicity = kUnknown;
fQuartet[0] = fReportedHelicity; fQuartet[0] = fReportedHelicity;
fQuartet[1] = 0; fQuartet[1] = 0;
} }
...@@ -320,6 +349,18 @@ Int_t THcHelicity::Decode( const THaEvData& evdata ) ...@@ -320,6 +349,18 @@ Int_t THcHelicity::Decode( const THaEvData& evdata )
fLastMPSTime += missed*fTIPeriod; fLastMPSTime += missed*fTIPeriod;
fIsNewCycle = kTRUE; fIsNewCycle = kTRUE;
fLastReportedHelicity = fReportedHelicity; fLastReportedHelicity = fReportedHelicity;
} else { // No missed periods. Get helicities from rings
if(fNBits>=fMAXBIT) {
int quartetphase = (fNCycle-fFirstCycle)%4;
fQuartetStartHelicity = (fRingSeed_actual&1)?kPlus:kMinus;
fQuartetStartPredictedHelicity = (fRingSeed_reported&1)?kPlus:kMinus;
fActualHelicity = (quartetphase==0||quartetphase==3)?
fQuartetStartHelicity:-fQuartetStartHelicity;
fPredictedHelicity = (quartetphase==0||quartetphase==3)?
fQuartetStartPredictedHelicity:-fQuartetStartPredictedHelicity;
} else {
fActualHelicity = 0;
}
} }
if(fIsNewCycle) { if(fIsNewCycle) {
fQuartet[3]=fQuartet[2]; fQuartet[2]=fQuartet[1]; fQuartet[1]=fQuartet[0]; fQuartet[3]=fQuartet[2]; fQuartet[2]=fQuartet[1]; fQuartet[1]=fQuartet[0];
...@@ -361,6 +402,8 @@ Int_t THcHelicity::Decode( const THaEvData& evdata ) ...@@ -361,6 +402,8 @@ Int_t THcHelicity::Decode( const THaEvData& evdata )
// << fPredictedHelicity << " " << fActualHelicity << endl; // << fPredictedHelicity << " " << fActualHelicity << endl;
} }
// Ignore until a MPS Is found // Ignore until a MPS Is found
} else { // No MPS found yet
fActualHelicity = kUnknown;
} }
} else { } else {
cout << "Initializing" << endl; cout << "Initializing" << endl;
...@@ -377,10 +420,17 @@ Int_t THcHelicity::Decode( const THaEvData& evdata ) ...@@ -377,10 +420,17 @@ Int_t THcHelicity::Decode( const THaEvData& evdata )
fIsNewCycle = kFALSE; fIsNewCycle = kFALSE;
fNBits = 0; fNBits = 0;
} }
// cout << setprecision(9) << "HEL " << fTITime/250000000.0 << " " << fNCycle << "(" << (fNCycle-fFirstCycle)%4 << "): "
// << fMPS << " " << fReportedHelicity << " " // Some sanity checks
// << fPredictedHelicity << " " << fActualHelicity << " " << lastlastmpstime/250000000.0 << endl; if(fActualHelicity < -5) {
// bitset<32>(v) cout << "Actual Helicity never got defined" << endl;
}
if(fNBits < fMAXBIT) {
if(fActualHelicity == -1 || fActualHelicity == 1) {
cout << "Helicity of " << fActualHelicity << " reported prematurely at cycle " << fNCycle << endl;
}
}
fLastActualHelicity = fActualHelicity;
return 0; return 0;
} }
......
...@@ -94,6 +94,9 @@ protected: ...@@ -94,6 +94,9 @@ protected:
Double_t fErrorCode; Double_t fErrorCode;
Int_t fEvtype; // Current CODA event type Int_t fEvtype; // Current CODA event type
Int_t fLastActualHelicity;
Int_t fEvNumCheck;
Bool_t fDisabled;
static const Int_t NHIST = 2; static const Int_t NHIST = 2;
TH1F* fHisto[NHIST]; TH1F* fHisto[NHIST];
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment