JAPAn
Just Another Parity Analyzer
Loading...
Searching...
No Matches
QwHelicityCorrelatedFeedback.h
Go to the documentation of this file.
1/**********************************************************\
2* File: QwHelicityCorrelatedFeedback.h *
3* *
4* Author: Rakitha Beminiwattha *
5* Time-stamp: <2010-09-28> *
6\**********************************************************/
7#ifndef __QwHelicityCorrelatedFeedback__
8#define __QwHelicityCorrelatedFeedback__
9
10#include "QwHelicityPattern.h"
11
12#include "QwEPICSControl.h"
13#include "GreenMonster.h"
14#include "QwVQWK_Channel.h"
15#include "QwScaler_Channel.h"
16
17#include "QwParameterFile.h"
18#include <time.h>
19///
20/// \ingroup QwAnalysis_ADC
21///
22/// \ingroup QwAnalysis_BL
24 /******************************************************************
25 * Class: QwHelicityCorrelatedFeedback
26 *
27 *
28 ******************************************************************/
29
30 public:
32 //Currently pattern type based runningasymmetry accumulation works only with pattern size of 4
33 fFBRunningAsymmetry.resize(kHelModes,event);
35
36 fEnableBurstSum=kFALSE;
41
42
43/* fFeedbackStatus=kTRUE; */
44/* if (fEPICSCtrl.Get_FeedbackStatus()>0) */
45/* fEPICSCtrl.Set_FeedbackStatus(0); */
46/* if (fFeedbackStatus){ */
47/* fFeedbackStatus=kFALSE; */
48/* fEPICSCtrl.Set_FeedbackStatus(1.0); */
49/* } */
50
52
53 fPreviousHelPat=0;//at the beginning of the run this is non existing
54 fCurrentHelPatMode=-1;//at the beginning of the run this is non existing
55
60 fPITA_MIN_Charge_asym=1;//default value is 1ppm
61
62 //initialize setpoints to zero
63 //HA IA
64 for(Int_t i=0;i<4;i++){
66 fHAIASetpoint[i]=0;
67 }
68 //PITA
73
74
75 fTargetCharge.InitializeChannel("q_targ","derived");
76 fRunningCharge.InitializeChannel("q_targ","derived");
77 fAsymBCM7.InitializeChannel("bcm7","derived");
78 fAsymBCM8.InitializeChannel("bcm8","derived");
79
80 fChargeAsymmetry0.InitializeChannel("q_targ","derived");//this is the charge asym at the beginning of the feedback loop
81 fPreviousChargeAsymmetry.InitializeChannel("q_targ","derived");//charge asymmetry at the previous feedback loop
82 fCurrentChargeAsymmetry.InitializeChannel("q_targ","derived");//current charge asymmetry
83
84 fIAAsymmetry0.InitializeChannel("q_targ","derived");//this is the charge asymmetry of the IA at the beginning of the feedback loop
85 fPreviousIAAsymmetry.InitializeChannel("q_targ","derived");//this is the charge asymmetry of the IA at the previous feedback loop
86 fCurrentIAAsymmetry.InitializeChannel("q_targ","derived");//current charge asymmetry of the IA
87
88 fScalerChargeRunningSum.InitializeChannel("sca_bcm");
89 fScalerCharge.InitializeChannel("sca_bcm");
90
91 fTargetParameter.InitializeChannel("x_targ","derived");
92
93 fTargetXDiffRunningSum.InitializeChannel("x_targ","derived");//to access the published Target X diff
94 fTargetXPDiffRunningSum.InitializeChannel("xp_targ","derived");//to access the published Target XP diff
95 fTargetYDiffRunningSum.InitializeChannel("y_targ","derived");//to access the published Target Y diff
96 fTargetYPDiffRunningSum.InitializeChannel("yp_targ","derived");//to access the published Target YP diff
97
98 fAsymBCM78DDRunningSum.InitializeChannel("bcm78dd","derived");
99 fYieldBCM8RunningSum.InitializeChannel("q_targ","derived");
100 fAsymUSLumiSumRunningSum.InitializeChannel("uslumisum","derived");
101
102 time ( &rawtime );
103 timeinfo = localtime ( &rawtime );
104 out_file_IA = fopen("/local/scratch/qweak/Feedback_IA_log.txt", "a");
105 //out_file_IA = fopen("/dev/shm/Feedback_IA_log.txt", "a");
106
107 fprintf(out_file_IA,"%22s \n",asctime (timeinfo));
108 fprintf(out_file_IA,"Pat num. \t A_q[mode]\t IA Setpoint \t IA Previous Setpoint \n");
109 fclose(out_file_IA);
110 // out_file_PITA = fopen("Feedback_PITA_log.txt", "wt");
111
112 out_file_PITA = fopen("/local/scratch/qweak/Feedback_PITA_log.txt", "a");
113 out_file_HA_IA = fopen("/local/scratch/qweak/Feedback_HA_IA_log.txt", "a");
114 fprintf(out_file_PITA,"%22s \n",asctime (timeinfo));
115 fprintf(out_file_PITA,
116 "%10s %22s +- %16s %16s %26s %26s %26s %26s\n",
117 "Pat num.", "Charge Asym [ppm]", "Asym Error", "Correction",
118 "New PITA Setpoint[+]", "Old PITA Setpoint[+]",
119 "New PITA Setpoint[-]", "Old PITA Setpoint[-]");
120 fclose(out_file_PITA);
121
122 fprintf(out_file_HA_IA,"%22s \n",asctime (timeinfo));
123 fprintf(out_file_HA_IA,
124 "%10s %22s %16s %16s %26s %23s \n",
125 "Pat num.", "Charge Asym(ppm)", "Asym Error", "Correction",
126 "New IA Setpoint", "Old IA Setpoint");
127 fclose(out_file_HA_IA);
128
129
130
131 };
132
133
135 // if (!fFeedbackStatus){
136 // fFeedbackStatus=kFALSE;
137 fEPICSCtrl.Set_FeedbackStatus(0);
138 // }
139
140 };
141 ///inherited from QwHelicityPattern
142 void CalculateAsymmetry();
143 void ClearRunningSum();
146 void ConstructBranchAndVector(TTree *tree, TString &prefix, std::vector<Double_t> &values);
147 void FillTreeVector(std::vector<Double_t> &values) const;
148
149 /// \brief Define the configuration options
150 static void DefineOptions(QwOptions &options);
151 /// \brief Process the configuration options
152 void ProcessOptions(QwOptions &options);
153
154 /// \brief Load deltaA_q, no.of good patterns to accumulate and other neccessary feedback parameters
155 void LoadParameterFile(TString filename);
156
157 /// \brief retrieves the target charge asymmetry,asymmetry error ,asymmetry width
158 void GetTargetChargeStat();
159 /// \brief retrieves the target charge asymmetry,asymmetry error ,asymmetry width for given mode
160 void GetTargetChargeStat(Int_t mode);
161 /// \brief retrieves the target position angle parameters (X,XP,Y,YP) mean, error and width
163 /// \brief retrieves the Hall A charge asymmetry,asymmetry error ,asymmetry width for given mode
164 void GetHAChargeStat(Int_t mode);
165
166
167
168 /// \brief Feed the Hall C IA set point based on the charge asymmetry
169 void FeedIASetPoint(Int_t mode);
170
171 /// \brief Feed the Hall A IA set point based on the charge asymmetry
172 void FeedHAIASetPoint(Int_t mode);
173
174 /// \brief Feed the Hall C PITA set point based on the charge asymmetry
175 void FeedPITASetPoints();
176
177
178 /// \brief Feed the IA set point based on the charge asymmetry
179 void FeedPCPos();
180 /// \brief Feed the IA set point based on the charge asymmetry
181 void FeedPCNeg();
182
183 /// \brief Log the last IA feedback information
184 void LogParameters(Int_t mode);
185
186 /// \brief Log the last PITA feedback information
187 void LogParameters();
188
189 /// \brief Log the Pos/angle information
190 void LogPFParameters();
191
192
193
194 /// \brief Log the last Hall A IA feedback information
195 void LogHAParameters(Int_t mode);
196
197 /// \brief Set Clean=0 or 1 in the GreenMonster
198 void UpdateGMClean(Int_t state);
199
200 /// \brief Update last feedback setting into scan variables in the GreenMonster
202
203 /// \brief Initiates the PITA feedback if the charge asymmetry passed the quality cut
204 Bool_t ApplyPITAFeedback();
205 /// \brief Initiates the Hall A IA feedback if the Hall A charge asymmetry passed the quality cut
206 Bool_t ApplyHAIAFeedback();
207
208 /// \brief Initiates the IA feedback if the Hall C charge asymmetry have passed the quality cut
209 Bool_t ApplyIAFeedback(Int_t mode);
210
211 /// \brief Initiates the Helicity magnet feedback if the position differences and/or angle differences have passed the quality cut
212 Bool_t ApplyHMFeedback();
213
214
215
216 /// \brief Check to see no.of good patterns accumulated after the last feedback is greater than a set value
219 return kTRUE;
220
221 return kFALSE;
222 };
223 /// \brief Check to see no.of good patterns accumulated after the last position/angle feedback correction
226 return kTRUE;
227
228 return kFALSE;
229 };
230
231 /// \brief Check to see no.of good patterns accumulated after the last position/angle feedback correction
234 return kTRUE;
235
236 return kFALSE;
237 };
238
239
240 /// \brief Check neccessary conditions and apply IA setponts based on the charge asym for all four modes
242 /// \brief Check to see no.of good patterns accumulated after the last feedback is greater than a set value for given mode
243 Bool_t IsPatternsAccumulated(Int_t mode);
244
245 /// \brief Returns the type of the last helicity pattern based on following pattern history
246 ///1. +--+ +--+
247 ///2. +--+ -++-
248 ///3. -++- +--+
249 ///4. -++- -++-
250
252
253
254 void CalculateRunningAverage(Int_t mode);
255 void ClearRunningSum(Int_t mode);
256
257 private:
258 /// \brief Returns the charge asymmetry stats when required by feedback caluculations.
259 Double_t GetChargeAsym(){
260 return fChargeAsymmetry;
261 };
264 };
267 };
268
269 //Define separate running sums for differents helicity pattern modes
270 /// \brief The types of helicity patterns based on following pattern history
271 ///1. +--+ +--+
272 ///2. +--+ -++-
273 ///3. -++- +--+
274 ///4. -++- -++-
275
276
277 TString GetHalfWavePlateState();
278 UInt_t GetHalfWavePlate2State();
279 void CheckFeedbackStatus();
280
281 static const Int_t kHelPat1=1001;//to compare with current or previous helpat
282 static const Int_t kHelPat2=110;
283 static const Int_t kHelModes=4;//kHelModes
284
285 std::vector<QwSubsystemArrayParity> fFBRunningAsymmetry;
288
290
291 Double_t fChargeAsymmetry;//current charge asym
292 Double_t fChargeAsymmetryError;//current charge asym precision
293 Double_t fChargeAsymmetryWidth;//current charge asym width
294
295 //position/angle parameters
296 Double_t fTargetXDiff;
299
303
304 Double_t fTargetYDiff;
307
311
312 Double_t f3C12XDiff;
315
316 Double_t f3C12YDiff;
319
320 Double_t f3C12YQ;
321 Double_t f3C12YQError;
322 Double_t f3C12YQWidth;
323
324 Double_t fAsymBCM78DD;
327
328 Double_t fBCM8Yield;
329
330
334
335 Double_t fChargeAsym[kHelModes];//current charge asym
336 Double_t fChargeAsymError[kHelModes];//current charge asym precision
337 Double_t fChargeAsymWidth[kHelModes];//current charge asym width
338
339 Double_t fHAChargeAsym[kHelModes];//Hall A current charge asym
340 Double_t fHAChargeAsymError[kHelModes];//Hall A current charge asym precision
341 Double_t fHAChargeAsymWidth[kHelModes];//Hall A current charge asym width
342
343 Int_t fAccumulatePatternMax; //Hall C PITA Correction interval in units of patterns
344 Int_t fHAAccumulatePatternMax; //Hall A IA Correction interval in units of patterns
345 Int_t fPFAccumulatePatternMax; //HC Position/Angle difference Correction interval in units of patterns
346 Double_t fChargeAsymPrecision; //Charge asymmetry precision in ppm
347
348
349 //Keep a record of optimal values for IA, PC POS and NEG
350 Double_t fOptimalIA;
351 Double_t fOptimalPCP;
352 Double_t fOptimalPCN;
353 //current IA and PC values
354 Double_t fCurrentIA;
355 Double_t fCurrentPCP;
356 Double_t fCurrentPCN;
357
358 //Hall C IA Slopes for 4 modes and their errors
361
362 //Hall A IA Slopes for 4 modes and their errors
365
366 //Hall C IA setpoints for 4 modes
367 Double_t fIASetpoint[kHelModes];//New setpont calculated based on the charge asymmetry
368 Double_t fPrevIASetpoint[kHelModes];//previous setpoint
369
370 //Hall A IA setpoints for 4 modes
371 Double_t fHAIASetpoint[kHelModes];//New setpont calculated based on the charge asymmetry
372 Double_t fPrevHAIASetpoint[kHelModes];//previous setpoint
373
374 Double_t fIASetpointlow;//lower and upper limits for IA dac hardware counts
376
377 //PITA Slopes for halfwave plate IN & OUT
378 Double_t fPITASlopeIN;//IHWP1 IN IHWP2 OUT
379 Double_t fPITASlopeOUT;//IHWP1 OUT IHWP2 OUT
380 Double_t fPITASlopeOUT_IN;//IHWP1 OUT IHWP2 IN
381 Double_t fPITASlope;
382
383 //PITA setpoints for pos hel and neg hel
386 Double_t fPITASetpointPOS_t0_IN;//Initial PC positive HW setpoint
387 Double_t fPITASetpointNEG_t0_IN;//Initial PC negative HW setpoint
388 Double_t fPITASetpointPOS_t0_OUT;//Initial PC positive HW setpoint
389 Double_t fPITASetpointNEG_t0_OUT;//Initial PC negative HW setpoint
390 Bool_t fInitialCorrection;//Is true at the beginning so that t_0 correction is appiled before doing any correction
391
392
393 Double_t fPrevPITASetpointPOS;//previous setpoint
394 Double_t fPrevPITASetpointNEG;//previous setpoint
395 Double_t fPITASetpointlow;//lower and upper limits for PITA dac hardware counts
397 Double_t fPITA_MIN_Charge_asym;//Minimum charge asymmetry at which feedback correction is applied. see QwHelicityCorrelatedFeedback::FeedPITASetPoints()
398
399
400
401 /// Create an EPICS control event
404
405 //Pattern counter
406 Int_t fGoodPatternCounter;//increment the quartet number - reset after each PITA feedback operation
407 Int_t fHAGoodPatternCounter;//increment the quartet number - reset after each Hall A IA feedback operation
408 Int_t fPFGoodPatternCounter;//increment the quartet number - reset after each position/angle feedback operation
409
410 Int_t fPatternCounter;//increment the quartet number - reset after each feedback operation
411
412
413 std::vector<Int_t> fHelModeGoodPatternCounter;//count patterns for each mode seperately - reset after each feedback operation
414
415 // Keep four VQWK channels, one each for pattern history 1, 2, 3, and 4
416 // Use AddToRunningSum to add the asymmetry for the current pattern
417 // into the proper pattern history runnign sum.
418
421 QwBeamCharge fChargeAsymmetry0;//this is the charge asym at the beginning of the feedback loop
422 QwBeamCharge fPreviousChargeAsymmetry;//charge asymmetry at the previous feedback loop
423 QwBeamCharge fCurrentChargeAsymmetry;//current charge asymmetry
424
425 QwBeamCharge fIAAsymmetry0;//this is the charge asymmetry of the IA at the beginning of the feedback loop
426 QwBeamCharge fPreviousIAAsymmetry;//this is the charge asymmetry of the IA at the previous feedback loop
427 QwBeamCharge fCurrentIAAsymmetry;//current charge asymmetry of the IA
428
431
432 QwBeamCharge fTargetParameter;//to access the published postions/angles
433
434 QwBeamCharge fTargetXDiffRunningSum;//to access the published Target X diff
435 QwBeamCharge fTargetXPDiffRunningSum;//to access the published Target XP diff
436 QwBeamCharge fTargetYDiffRunningSum;//to access the published Target Y diff
437 QwBeamCharge fTargetYPDiffRunningSum;//to access the published Target YP diff
438 QwBeamCharge f3C12XDiffRunningSum;//to access the published 3c12 X diff
439 QwBeamCharge f3C12YDiffRunningSum;//to access the published 3c12 Y diff
440 QwBeamCharge f3C12YQRunningSum;//to access the published 3c12 eff. charge
441
442 QwBeamCharge fAsymBCM7;//to access bcm7 asymmetry
443 QwBeamCharge fAsymBCM8;//to access bcm8 asymmetry
444 QwBeamCharge fAsymBCM78DDRunningSum;//to accumulate bcm78 DD asymmetry
445 QwBeamCharge fYieldBCM8RunningSum;//to access bcm8 Yield
446
447 QwBeamCharge fAsymUSLumiSumRunningSum;//to accumulate US Lumi sum
448
449
450 //log file
459
462 Int_t fIHWP;
463
465 Bool_t fAutoIHWP;
466
470
471 Bool_t fPITAFB;
472 Bool_t fHAIAFB;
473 Bool_t fIAFB;
476
477
478 time_t rawtime;
479 struct tm * timeinfo;
480
481
482};
483
484#endif
Base and derived classes for scaler channel data handling.
class QwScaler_Channel< 0x00ffffff, 0 > QwSIS3801D24_Channel
Parameter file parsing and management.
Decoding and management for VQWK ADC channels (6x32-bit datawords)
class QwMollerADC_Channel QwBeamCharge
Definition QwTypes.h:321
Helicity pattern analysis and management.
Double_t GetChargeAsym()
Returns the charge asymmetry stats when required by feedback caluculations.
void LoadParameterFile(TString filename)
Load deltaA_q, no.of good patterns to accumulate and other neccessary feedback parameters.
void GetTargetPositionStat()
retrieves the target position angle parameters (X,XP,Y,YP) mean, error and width
void FeedPCNeg()
Feed the IA set point based on the charge asymmetry.
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
Bool_t IsHAPatternsAccumulated()
Check to see no.of good patterns accumulated after the last position/angle feedback correction.
void ApplyFeedbackCorrections()
Check neccessary conditions and apply IA setponts based on the charge asym for all four modes.
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.
void LogParameters()
Log the last PITA feedback information.
void ProcessOptions(QwOptions &options)
Process the configuration options.
void FillTreeVector(std::vector< Double_t > &values) const
Bool_t ApplyHMFeedback()
Initiates the Helicity magnet feedback if the position differences and/or angle differences have pass...
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.
Int_t GetLastGoodHelicityPatternType()
Returns the type of the last helicity pattern based on following pattern history.
QwEPICSControl fEPICSCtrl
Create an EPICS control event.
Bool_t IsPatternsAccumulated()
Check to see no.of good patterns accumulated after the last feedback is greater than a set value.
Bool_t ApplyHAIAFeedback()
Initiates the Hall A IA feedback if the Hall A charge asymmetry passed the quality cut.
Bool_t ApplyPITAFeedback()
Initiates the PITA feedback if the charge asymmetry passed the quality cut.
void ConstructBranchAndVector(TTree *tree, TString &prefix, std::vector< Double_t > &values)
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.
void FeedIASetPoint(Int_t mode)
Feed the Hall C IA set point based on the charge asymmetry.
TString GetHalfWavePlateState()
The types of helicity patterns based on following pattern history.
void FeedPCPos()
Feed the IA set point based on the charge asymmetry.
QwHelicityCorrelatedFeedback(QwSubsystemArrayParity &event)
void UpdateGMScanParameters()
Update last feedback setting into scan variables in the GreenMonster.
static void DefineOptions(QwOptions &options)
Define the configuration options.
std::vector< QwSubsystemArrayParity > fFBRunningAsymmetry
void CalculateAsymmetry()
inherited from QwHelicityPattern
Command-line and configuration file options processor.
Definition QwOptions.h:141
QwHelicityPattern()
Private default constructor (not implemented, will throw linker error on use)
Subsystem array container specialized for parity analysis with asymmetry calculations.