21 options.
AddOptions(
"Helicity Correlated Feedback")(
"Auto-IHWP-Flip", po::value<bool>()->default_value(
false)->zero_tokens(),
"Set Half wave plate IN. The default is Half wave plate OUT");
22 options.
AddOptions(
"Helicity Correlated Feedback")(
"Half-wave-plate-revert", po::value<bool>()->default_value(
false)->zero_tokens(),
"Revert half-wave plate status. The default is determined via EPIC");
24 options.
AddOptions(
"Helicity Correlated Feedback")(
"PITA-Feedback", po::value<bool>()->default_value(
false)->zero_tokens(),
"Run the PITA charge feedback");
25 options.
AddOptions(
"Helicity Correlated Feedback")(
"IA-Feedback", po::value<bool>()->default_value(
false)->zero_tokens(),
"Run the IA charge feedback");
26 options.
AddOptions(
"Helicity Correlated Feedback")(
"HA-IA-Feedback", po::value<bool>()->default_value(
false)->zero_tokens(),
"Run the Hall A IA charge feedback");
57 printf(
"NOTICE \n Half-wave-plate-IN\n");
59 printf(
"NOTICE \n Half-wave-plate-OUT\n");
62 printf(
"NOTICE \n Half-wave-plate-2 is IN \n");
64 printf(
"NOTICE \n Half-wave-plate-2 is OUT \n");
74 printf(
"NOTICE \n PITA-Feedback is running.\n");
76 printf(
"NOTICE \n PITA-Feedback is not running.\n");
78 printf(
"NOTICE \n IA-Feedback is running.\n");
80 printf(
"NOTICE \n IA-Feedback is not running.\n");
82 printf(
"NOTICE \n Hall A IA-Feedback is running.\n");
84 printf(
"NOTICE \n Hall A IA-Feedback is not running.\n");
92 printf(
"NOTICE \n AUTO IHWP Flip is ON \n");
95 printf(
"NOTICE \n AUTO IHWP Flip is OFF \n");
104 TString prev_IHWP_State;
107 TString varname, varvalue;
120 if (varname==
"patterns"){
124 else if (varname==
"haf_patterns"){
127 }
else if(varname==
"pf_patterns"){
130 }
else if (varname==
"deltaaq"){
131 dvalue = atof(varvalue.Data());
134 else if (varname==
"optimalia"){
135 dvalue = atof(varvalue.Data());
138 else if (varname==
"optimalpcp"){
139 dvalue = atof(varvalue.Data());
142 else if (varname==
"optimalpcn"){
143 dvalue = atof(varvalue.Data());
146 else if (varname==
"a0"){
147 dvalue = atof(varvalue.Data());
150 else if (varname==
"deltaa0"){
151 dvalue = atof(varvalue.Data());
154 else if (varname==
"a1"){
155 dvalue = atof(varvalue.Data());
158 else if (varname==
"deltaa1"){
159 dvalue = atof(varvalue.Data());
162 else if (varname==
"a2"){
163 dvalue = atof(varvalue.Data());
166 else if (varname==
"deltaa2"){
167 dvalue = atof(varvalue.Data());
170 else if (varname==
"a3"){
171 dvalue = atof(varvalue.Data());
174 else if (varname==
"deltaa3"){
175 dvalue = atof(varvalue.Data());
178 else if (varname==
"haa0"){
179 dvalue = atof(varvalue.Data());
182 else if (varname==
"haa1"){
183 dvalue = atof(varvalue.Data());
186 else if (varname==
"haa2"){
187 dvalue = atof(varvalue.Data());
190 else if (varname==
"haa3"){
191 dvalue = atof(varvalue.Data());
194 else if (varname==
"ia_low"){
195 dvalue = atof(varvalue.Data());
199 else if (varname==
"ia_up"){
200 dvalue = atof(varvalue.Data());
204 else if (varname==
"pitaslope_in"){
205 dvalue = atof(varvalue.Data());
208 else if (varname==
"pitaslope_out"){
209 dvalue = atof(varvalue.Data());
212 else if (varname==
"pitaslope_out_in"){
213 dvalue = atof(varvalue.Data());
216 else if (varname==
"pc_pos_t0_in"){
217 dvalue = atof(varvalue.Data());
220 else if (varname==
"pc_neg_t0_in"){
221 dvalue = atof(varvalue.Data());
224 else if (varname==
"pc_pos_t0_out"){
225 dvalue = atof(varvalue.Data());
228 else if (varname==
"pc_neg_t0_out"){
229 dvalue = atof(varvalue.Data());
232 else if (varname==
"pc_up"){
233 dvalue = atof(varvalue.Data());
237 else if (varname==
"pc_low"){
238 dvalue = atof(varvalue.Data());
241 }
else if (varname==
"min_charge_asym"){
242 dvalue = atof(varvalue.Data());
245 }
else if (varname==
"damping"){
246 dvalue = atof(varvalue.Data());
296 IHWP_State = fopen(
"/local/scratch/qweak/Feedback_IHWP.txt",
"r");
300 prev_IHWP_State=buffer;
301 if (prev_IHWP_State.Contains(
"IN") || prev_IHWP_State.Contains(
"OUT")){
302 if (prev_IHWP_State.Contains(
"IN"))
313 if (!prev_IHWP_State.Contains(
"IN") && !prev_IHWP_State.Contains(
"OUT") ){
316 IHWP_State = fopen(
"/local/scratch/qweak/Feedback_IHWP.txt",
"w");
317 printf(
"NOTICE \n previous half-wave plate status not found. Writing current IHWP state %s \n",
fHalfWavePlateStatus.Data());
325 printf(
"NOTICE \n Half-wave plate status has changed from %s to %s \n",prev_IHWP_State.Data(),
fHalfWavePlateStatus.Data());
338 printf(
"NOTICE \n previous half-wave plate status %s\n",prev_IHWP_State.Data());
341 IHWP_State = fopen(
"/local/scratch/qweak/Feedback_IHWP.txt",
"w");
409 for (Int_t i=0;i<4;i++)
499 out_file_IA = fopen(
"/local/scratch/qweak/Feedback_IA_log.txt",
"a");
511 out_file_PITA = fopen(
"/local/scratch/qweak/Feedback_PITA_log.txt",
"a");
557 fEPICSCtrl.Set_TargetHCDiffereces(
fTargetXDiff,
fTargetXDiffError,
fTargetXDiffWidth,
fTargetXPDiff,
fTargetXPDiffError,
fTargetXPDiffWidth,
fTargetYDiff,
fTargetYDiffError,
fTargetYDiffWidth,
fTargetYPDiff,
fTargetYPDiffError,
fTargetYPDiffWidth);
564 out_file_HA_IA = fopen(
"/local/scratch/qweak/Feedback_HA_IA_log.txt",
"a");
591 Bool_t status=kFALSE;
621 Bool_t status=kFALSE;
632 QwError<<
"--------------------------------------------------------------------------------------------------------------------------------"<<
QwLog::endl;
652 Bool_t HCstatus=kFALSE;
654 if (mode<0 || mode>3){
655 QwError <<
" Could not get external value setting parameters to q_targ" <<
QwLog::endl;
658 QwMessage<<
"ApplyIAFeedback["<<mode<<
"]\n";
671 QwError<<
"--------------------------------------------------------------------------------------------------------------------------------"<<
QwLog::endl;
679 if (HCstatus &&
fIAFB){
753 printf(
"NOTICE \n Half-wave-plate-IN\n");
755 printf(
"NOTICE \n Half-wave-plate-OUT\n");
780 IHWP_State = fopen(
"/local/scratch/qweak/Feedback_IHWP.txt",
"w");
823 Bool_t localdebug=kFALSE;
825 if(localdebug) std::cout<<
"Entering QwHelicityPattern::CalculateAsymmetry \n";
830 Bool_t firstplushel=kTRUE;
831 Bool_t firstminushel=kTRUE;
842 localhel ^= ((i >> j)&0x1);
844 if (localhel == plushel) {
847 firstplushel = kFALSE;
851 }
else if (localhel == minushel) {
854 firstminushel = kFALSE;
887 std::cout<<
"QwHelicityPattern::CalculateAsymmetry:: here filling fPositiveHelicitySum \n";
889 if (localdebug) std::cout<<
"QwHelicityPattern::CalculateAsymmetry:: with = \n";
891 firstplushel = kFALSE;
893 if (localdebug) std::cout<<
"QwHelicityPattern::CalculateAsymmetry:: with += \n";
898 if (localdebug) std::cout<<
"QwHelicityPattern::CalculateAsymmetry:: here filling fNegativeHelicitySum \n";
900 if (localdebug) std::cout<<
"QwHelicityPattern::CalculateAsymmetry:: with = \n";
902 firstminushel = kFALSE;
904 if (localdebug) std::cout<<
"QwHelicityPattern::CalculateAsymmetry:: with += \n";
909 QwError<<
"QwHelicityPattern::CalculateAsymmetry =="
910 <<
"Helicity should be "<<plushel<<
" or "<<minushel<<
" but is"<<
fHelicity[i]
911 <<
"; Asymmetry computation aborted!"<<
QwLog::endl;
922 if (checkhel == -9999) {
925 }
else if (checkhel!=0) {
928 QwError<<
" QwHelicityPattern::CalculateAsymmetry == \n"
929 <<
" you do not have the same number of positive and negative \n"
930 <<
" impossible to compute assymetry \n"
1034 Bool_t bXDiff=kFALSE;
1035 Bool_t bXPDiff=kFALSE;
1036 Bool_t bYDiff=kFALSE;
1037 Bool_t bYPDiff=kFALSE;
1038 Bool_t b3C12XDiff=kFALSE;
1039 Bool_t b3C12YDiff=kFALSE;
1040 Bool_t b3C12YQ=kFALSE;
1055 QwError <<
" Could not get external value setting parameters to sca_bcm" <<
QwLog::endl;
1131 if (bXDiff && bXPDiff && bYDiff && bYPDiff && b3C12YQ)
1177 fRunningAsymmetry.CalculateRunningAverage();
1179 if (fRunningAsymmetry.RequestExternalValue(
"q_targ",&
fTargetCharge)){
1203 QwError <<
" Could not get external value setting parameters to q_targ" <<
QwLog::endl;
1230 if (mode<0 || mode>3){
1231 QwError <<
" Could not get external value setting parameters to q_targ" <<
QwLog::endl;
1321 if (mode<0 || mode>3){
1322 QwError <<
" Hall A Mode is out of bound " << mode <<
" mode<0 || mode>3 "<<
QwLog::endl;
1342 QwHelicityPattern::ClearRunningSum();
1366 TString plate_status = gSystem->GetFromPipe(
"caget -t -w 0.1 IGL1I00DI24_24M");
1367 return plate_status;
1371 TString ihwp2_value = gSystem->GetFromPipe(
"caget -tf0 -w 0.1 IGL1I00DIOFLRD");
1372 UInt_t ihwp2 =ihwp2_value.Atoi();
1382 Double_t old_status = 0.0;
1383 old_status =
fEPICSCtrl.Get_FeedbackStatus();
1384 if(old_status == 1.0) {
1389 gSystem->Sleep(4000);
#define QwError
Predefined log drain for errors.
#define QwMessage
Predefined log drain for regular messages.
#define QwDebug
Predefined log drain for debugging output.
QwBeamCharge fTargetCharge
QwBeamCharge fYieldBCM8RunningSum
void LoadParameterFile(TString filename)
Load deltaA_q, no.of good patterns to accumulate and other neccessary feedback parameters.
Double_t fPITA_MIN_Charge_asym
void GetTargetPositionStat()
retrieves the target position angle parameters (X,XP,Y,YP) mean, error and width
Bool_t fInitialCorrection
Int_t fHAAccumulatePatternMax
void FeedPCNeg()
Feed the IA set point based on the charge asymmetry.
Double_t fTargetYPDiffError
Double_t fTargetXPDiffWidth
Double_t fPrevHAIASetpoint[kHelModes]
Double_t fTargetYDiffWidth
void FeedPITASetPoints()
Feed the Hall C PITA set point based on the charge asymmetry.
void GetTargetChargeStat()
retrieves the target charge asymmetry,asymmetry error ,asymmetry width
Double_t fPITASetpointPOS_t0_IN
Bool_t IsHAPatternsAccumulated()
Check to see no.of good patterns accumulated after the last position/angle feedback correction.
Double_t fPrevIASetpoint[kHelModes]
QwBeamCharge fTargetXPDiffRunningSum
void ApplyFeedbackCorrections()
Check neccessary conditions and apply IA setponts based on the charge asym for all four modes.
Double_t fAsymBCMUSLumiSumWidth
void UpdateGMClean(Int_t state)
Set Clean=0 or 1 in the GreenMonster.
Bool_t ApplyIAFeedback(Int_t mode)
Initiates the IA feedback if the Hall C charge asymmetry have passed the quality cut.
Double_t fTargetYPDiffWidth
Double_t fIASetpoint[kHelModes]
Double_t fChargeAsymmetry
QwBeamCharge f3C12YQRunningSum
QwBeamCharge f3C12XDiffRunningSum
void LogParameters()
Log the last PITA feedback information.
Int_t fAccumulatePatternMax
void ProcessOptions(QwOptions &options)
Process the configuration options.
Double_t fPrevPITASetpointPOS
Double_t fChargeAsymWidth[kHelModes]
Double_t fDelta_IASlopeA[kHelModes]
void FillTreeVector(std::vector< Double_t > &values) const
Double_t fIASlopeA[kHelModes]
Bool_t ApplyHMFeedback()
Initiates the Helicity magnet feedback if the position differences and/or angle differences have pass...
QwBeamCharge fTargetYDiffRunningSum
void FeedHAIASetPoint(Int_t mode)
Feed the Hall A IA set point based on the charge asymmetry.
void GetHAChargeStat(Int_t mode)
retrieves the Hall A charge asymmetry,asymmetry error ,asymmetry width for given mode
void LogPFParameters()
Log the Pos/angle information.
Double_t fPITASetpointNEG
Double_t fPITASetpointNEG_t0_OUT
Double_t fAsymBCM78DDWidth
Double_t fPITASetpointPOS
Int_t GetLastGoodHelicityPatternType()
Returns the type of the last helicity pattern based on following pattern history.
void CheckFeedbackStatus()
QwEPICSControl fEPICSCtrl
Create an EPICS control event.
UInt_t GetHalfWavePlate2State()
static const Int_t kHelPat1
UInt_t fPreviousHalfWavePlateStatus
void CalculateRunningAverage()
QwBeamCharge fTargetYPDiffRunningSum
FILE * out_file_PC_IN_neg
Bool_t IsPatternsAccumulated()
Check to see no.of good patterns accumulated after the last feedback is greater than a set value.
FILE * out_file_PC_OUT_neg
QwBeamCharge fTargetParameter
Bool_t ApplyHAIAFeedback()
Initiates the Hall A IA feedback if the Hall A charge asymmetry passed the quality cut.
QwBeamCharge fAsymBCM78DDRunningSum
Double_t fPITASetpointNEG_t0_IN
Bool_t ApplyPITAFeedback()
Initiates the PITA feedback if the charge asymmetry passed the quality cut.
Double_t fAsymBCMUSLumiSumError
Int_t fHAGoodPatternCounter
Double_t fHAChargeAsym[kHelModes]
static const Int_t kHelPat2
Int_t fPFAccumulatePatternMax
Double_t fHAIASlopeA[kHelModes]
Double_t fTargetXPDiffError
Double_t fChargeAsymmetryWidth
void ConstructBranchAndVector(TTree *tree, TString &prefix, std::vector< Double_t > &values)
Double_t fPITASetpointPOS_t0_OUT
Double_t fAsymBCMUSLumiSum
Bool_t IsPFPatternsAccumulated()
Check to see no.of good patterns accumulated after the last position/angle feedback correction.
void LogHAParameters(Int_t mode)
Log the last Hall A IA feedback information.
QwBeamCharge fTargetXDiffRunningSum
void FeedIASetPoint(Int_t mode)
Feed the Hall C IA set point based on the charge asymmetry.
QwSIS3801D24_Channel fScalerCharge
QwBeamCharge fAsymUSLumiSumRunningSum
TString fHalfWavePlateStatus
UInt_t fDefaultHalfWavePlateStatus
QwBeamCharge f3C12YDiffRunningSum
TString GetHalfWavePlateState()
The types of helicity patterns based on following pattern history.
Double_t fChargeAsym[kHelModes]
void FeedPCPos()
Feed the IA set point based on the charge asymmetry.
void AccumulateRunningSum()
Int_t fPFGoodPatternCounter
void UpdateGMScanParameters()
Update last feedback setting into scan variables in the GreenMonster.
FILE * out_file_PC_OUT_pos
Double_t fTargetXDiffWidth
Double_t fTargetYDiffError
Int_t fGoodPatternCounter
static const Int_t kHelModes
Double_t fChargeAsymPrecision
Double_t fPITASlopeOUT_IN
Double_t fPITASetpointlow
Double_t fPrevPITASetpointNEG
Double_t fChargeAsymmetryError
Double_t fTargetXDiffError
Double_t fHAChargeAsymWidth[kHelModes]
static void DefineOptions(QwOptions &options)
Define the configuration options.
FILE * out_file_PC_IN_pos
Double_t fHAIASetpoint[kHelModes]
std::vector< QwSubsystemArrayParity > fFBRunningAsymmetry
Double_t fChargeAsymError[kHelModes]
Double_t fHAChargeAsymError[kHelModes]
void CalculateAsymmetry()
inherited from QwHelicityPattern
std::vector< Int_t > fHelModeGoodPatternCounter
Double_t fAsymBCM78DDError
QwSIS3801D24_Channel fScalerChargeRunningSum
static std::ostream & endl(std::ostream &)
End of the line.
Command-line and configuration file options processor.
T GetValue(const std::string &key)
Get a templated value.
po::options_description_easy_init AddOptions(const std::string &blockname="Specialized options")
Add an option to a named block or create new block.
Configuration file parser with flexible tokenization and search capabilities.
void TrimWhitespace(TString::EStripType head_tail=TString::kBoth)
Bool_t HasVariablePair(const std::string &separatorchars, std::string &varname, std::string &varvalue)
void TrimComment(const char commentchar)
static UInt_t GetUInt(const TString &varvalue)
QwSubsystemArrayParity fAlternateDiff
Bool_t fEnableAlternateAsym
void ConstructBranchAndVector(TTree *tree, TString &prefix, QwRootTreeBranchVector &values)
QwSubsystemArrayParity fNegativeHelicitySum
QwSubsystemArrayParity fDifference
Int_t fCurrentPatternNumber
std::vector< QwSubsystemArrayParity > fEvents
void ProcessOptions(QwOptions &options)
Process the configuration options.
std::vector< Int_t > fHelicity
QwSubsystemArrayParity fAsymmetry1
void FillTreeVector(QwRootTreeBranchVector &values) const
QwSubsystemArrayParity fPositiveHelicitySum
void AccumulateRunningSum(QwHelicityPattern &entry, Int_t count=0, Int_t ErrorMask=0xFFFFFFF)
QwSubsystemArrayParity fYield
QwSubsystemArrayParity fAsymmetry
QwSubsystemArrayParity fAsymmetry2
void CalculateRunningAverage()