JAPAn
Just Another Parity Analyzer
Loading...
Searching...
No Matches
QwHelicityCorrelatedFeedback.cc
Go to the documentation of this file.
1/**********************************************************\
2* File: QwHelicityCorrelatedFeedback.cc *
3* *
4* Author:Author: Rakitha Beminiwattha *
5* Time-stamp:Time-stamp: <2010-09-28> *
6\**********************************************************/
7
9#include "TSystem.h"
10
11/*****************************************************************/
12
13
14/**
15 * Defines configuration options using QwOptions functionality.
16 * @param options Options object
17 */
19{
20
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");
23 //options.AddOptions("Helicity Correlated Feedback")("Half-wave-plate-OUT", po::value<bool>()->default_value(true)->zero_tokens(),"Half wave plate OUT");
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");
27
28};
29
30/*****************************************************************/
32{
34
35 fHalfWaveRevert = options.GetValue<bool>("Half-wave-plate-revert");
36 fHalfWavePlateStatus = GetHalfWavePlateState();//read the IHWP for the first time when the feedback is starting.
37 fAutoIHWP = options.GetValue<bool>("Auto-IHWP-Flip");
38
39
40
41 printf("NOTICE \n QwFeedback got the half-wave plate status %s\n", fHalfWavePlateStatus.Data());
42
43 if(fHalfWavePlateStatus.Contains("IN")) {
44 if(fHalfWaveRevert) fHalfWaveIN = false;
45 else fHalfWaveIN = true;
47 }
48 else {
50 else fHalfWaveIN = false;
52 }
53
55
56 if (fHalfWaveIN)
57 printf("NOTICE \n Half-wave-plate-IN\n");
58 else
59 printf("NOTICE \n Half-wave-plate-OUT\n");
60
62 printf("NOTICE \n Half-wave-plate-2 is IN \n");
63 else if (GetHalfWavePlate2State()==0)
64 printf("NOTICE \n Half-wave-plate-2 is OUT \n");
65
66
67
68
69 fPITAFB = options.GetValue<bool>("PITA-Feedback");
70 fHAIAFB = options.GetValue<bool>("HA-IA-Feedback");
71 fIAFB = options.GetValue<bool>("IA-Feedback");
72
73 if (fPITAFB)
74 printf("NOTICE \n PITA-Feedback is running.\n");
75 else
76 printf("NOTICE \n PITA-Feedback is not running.\n");
77 if (fIAFB)
78 printf("NOTICE \n IA-Feedback is running.\n");
79 else
80 printf("NOTICE \n IA-Feedback is not running.\n");
81 if (fHAIAFB)
82 printf("NOTICE \n Hall A IA-Feedback is running.\n");
83 else
84 printf("NOTICE \n Hall A IA-Feedback is not running.\n");
85
86 if (!fPITAFB && !fIAFB && !fHAIAFB){//no correction applied.
87 fEPICSCtrl.Set_FeedbackStatus(0);
88 exit(1);
89 }
90
91 if (fAutoIHWP){
92 printf("NOTICE \n AUTO IHWP Flip is ON \n");
93 //exit(1);
94 }else{
95 printf("NOTICE \n AUTO IHWP Flip is OFF \n");
96 //exit(1);
97 }
98 //exit(1);
99};
100
101/*****************************************************************/
103 char buffer [10];
104 TString prev_IHWP_State;
105
106 QwParameterFile mapstr(filename.Data()); //Open the file
107 TString varname, varvalue;
108 UInt_t value;
109 Double_t dvalue;
110 fIASetpointlow=11000;
111 fIASetpointup=40000;
112 while (mapstr.ReadNextLine()){
113 mapstr.TrimComment('#'); // Remove everything after a '!' character.
114 mapstr.TrimWhitespace(); // Get rid of leading and trailing spaces.
115 if (mapstr.LineIsEmpty()) continue;
116
117 if (mapstr.HasVariablePair("=",varname,varvalue)){
118 //Decode it.
119 varname.ToLower();
120 if (varname=="patterns"){
121 value = QwParameterFile::GetUInt(varvalue);
123 }
124 else if (varname=="haf_patterns"){
125 value = QwParameterFile::GetUInt(varvalue);
127 }else if(varname=="pf_patterns"){
128 value = QwParameterFile::GetUInt(varvalue);
130 }else if (varname=="deltaaq"){
131 dvalue = atof(varvalue.Data());
133 }
134 else if (varname=="optimalia"){
135 dvalue = atof(varvalue.Data());
136 fOptimalIA = dvalue;
137 }
138 else if (varname=="optimalpcp"){
139 dvalue = atof(varvalue.Data());
140 fOptimalPCP = dvalue;
141 }
142 else if (varname=="optimalpcn"){
143 dvalue = atof(varvalue.Data());
144 fOptimalPCN = dvalue;
145 }
146 else if (varname=="a0"){
147 dvalue = atof(varvalue.Data());
148 fIASlopeA[0] = dvalue;
149 }
150 else if (varname=="deltaa0"){
151 dvalue = atof(varvalue.Data());
152 fDelta_IASlopeA[0] = dvalue;
153 }
154 else if (varname=="a1"){
155 dvalue = atof(varvalue.Data());
156 fIASlopeA[1] = dvalue;
157 }
158 else if (varname=="deltaa1"){
159 dvalue = atof(varvalue.Data());
160 fDelta_IASlopeA[1] = dvalue;
161 }
162 else if (varname=="a2"){
163 dvalue = atof(varvalue.Data());
164 fIASlopeA[2] = dvalue;
165 }
166 else if (varname=="deltaa2"){
167 dvalue = atof(varvalue.Data());
168 fDelta_IASlopeA[2] = dvalue;
169 }
170 else if (varname=="a3"){
171 dvalue = atof(varvalue.Data());
172 fIASlopeA[3] = dvalue;
173 }
174 else if (varname=="deltaa3"){
175 dvalue = atof(varvalue.Data());
176 fDelta_IASlopeA[3] = dvalue;
177 }
178 else if (varname=="haa0"){
179 dvalue = atof(varvalue.Data());
180 fHAIASlopeA[0] = dvalue;
181 }
182 else if (varname=="haa1"){
183 dvalue = atof(varvalue.Data());
184 fHAIASlopeA[1] = dvalue;
185 }
186 else if (varname=="haa2"){
187 dvalue = atof(varvalue.Data());
188 fHAIASlopeA[2] = dvalue;
189 }
190 else if (varname=="haa3"){
191 dvalue = atof(varvalue.Data());
192 fHAIASlopeA[3] = dvalue;
193 }
194 else if (varname=="ia_low"){
195 dvalue = atof(varvalue.Data());
196 if (dvalue>0)
197 fIASetpointlow = dvalue;
198 }
199 else if (varname=="ia_up"){
200 dvalue = atof(varvalue.Data());
201 if (dvalue>0)
202 fIASetpointup = dvalue;
203 }
204 else if (varname=="pitaslope_in"){//IHWP1 IN IHWP2 OUT
205 dvalue = atof(varvalue.Data());
206 fPITASlopeIN = dvalue;
207 }
208 else if (varname=="pitaslope_out"){//IHWP1 OUT IHWP2 OUT
209 dvalue = atof(varvalue.Data());
210 fPITASlopeOUT = dvalue;
211 }
212 else if (varname=="pitaslope_out_in"){//IHWP1 OUT IHWP2 IN
213 dvalue = atof(varvalue.Data());
214 fPITASlopeOUT_IN = dvalue;
215 }
216 else if (varname=="pc_pos_t0_in"){
217 dvalue = atof(varvalue.Data());
218 fPITASetpointPOS_t0_IN = dvalue;
219 }
220 else if (varname=="pc_neg_t0_in"){
221 dvalue = atof(varvalue.Data());
222 fPITASetpointNEG_t0_IN = dvalue;
223 }
224 else if (varname=="pc_pos_t0_out"){
225 dvalue = atof(varvalue.Data());
227 }
228 else if (varname=="pc_neg_t0_out"){
229 dvalue = atof(varvalue.Data());
231 }
232 else if (varname=="pc_up"){
233 dvalue = atof(varvalue.Data());
234 if (dvalue>0)
235 fPITASetpointup = dvalue;
236 }
237 else if (varname=="pc_low"){
238 dvalue = atof(varvalue.Data());
239 if (dvalue>0)
240 fPITASetpointlow = dvalue;
241 }else if (varname=="min_charge_asym"){
242 dvalue = atof(varvalue.Data());
243 if (dvalue>0)
244 fPITA_MIN_Charge_asym = dvalue;
245 } else if (varname=="damping"){
246 dvalue = atof(varvalue.Data());
247 if (dvalue>0)
248 fFeedbackDamping=kTRUE;
249 else
250 fFeedbackDamping=kFALSE;
251 }
252
253
254
255 }
256 }
257
258 //Read the last know good PC set points
259 out_file_PC_IN_pos = fopen("/local/scratch/qweak/Last_good_PC_pos_IN", "r");//Open in read mode
260 out_file_PC_IN_neg = fopen("/local/scratch/qweak/Last_good_PC_neg_IN", "r");//Open in read mode
261 out_file_PC_OUT_pos = fopen("/local/scratch/qweak/Last_good_PC_pos_OUT", "r");//Open in read mode
262 out_file_PC_OUT_neg = fopen("/local/scratch/qweak/Last_good_PC_neg_OUT", "r");//Open in read mode
263
265 UInt_t tmp;
266 fscanf(out_file_PC_IN_pos,"%d",&tmp);
268 fscanf(out_file_PC_IN_neg,"%d",&tmp);
270 fscanf(out_file_PC_OUT_pos,"%d",&tmp);
272 fscanf(out_file_PC_OUT_neg,"%d",&tmp);
274 fclose(out_file_PC_IN_pos);
275 fclose(out_file_PC_IN_neg);
276 fclose(out_file_PC_OUT_pos);
277 fclose(out_file_PC_OUT_neg);
278
279 }
280
281
282
283 QwMessage<<"Hall C patternMax = "<<fAccumulatePatternMax<<" Hall C patternMax = "<<fHAAccumulatePatternMax<<" deltaAq "<<fChargeAsymPrecision<<"ppm"<<QwLog::endl;
284 //QwMessage<<"Optimal values - IA ["<<fOptimalIA<<"] PC+["<<fOptimalPCP<<"] PC-["<<fOptimalPCN<<"]"<<QwLog::endl;
285 QwMessage<<"IA DAC counts limits "<<fIASetpointlow<<" to "<< fIASetpointup <<QwLog::endl;
286 for (Int_t i=0;i<kHelModes;i++)
287 QwMessage<<"Slope A["<<i<<"] "<<fIASlopeA[i]<<"+-"<<fDelta_IASlopeA[i]<<QwLog::endl;
288 QwMessage<<"PITA slopes: H-wave IN "<<fPITASlopeIN<<" H-wave OUT "<<fPITASlopeOUT<<" H-wave OUT IHWP2 IN"<<fPITASlopeOUT_IN<<QwLog::endl;
289 QwMessage<<"PC dac limits "<<fPITASetpointlow<<" to "<<fPITASetpointup<<QwLog::endl;
290
291 fInitialCorrection=kFALSE;
292 QwMessage<<"t_0 corrections for IN +["<<fPITASetpointPOS_t0_IN<<"] -["<<fPITASetpointNEG_t0_IN<<"]"<<QwLog::endl;
293 QwMessage<<"t_0 corrections for OUT +["<<fPITASetpointPOS_t0_OUT<<"] -["<<fPITASetpointNEG_t0_OUT<<"]"<<QwLog::endl;
294
295 if (fAutoIHWP){
296 IHWP_State = fopen("/local/scratch/qweak/Feedback_IHWP.txt", "r");//Open in read mode to get the previous IHWP state
297 if (IHWP_State!=NULL){
298 fgets(buffer , 10 ,IHWP_State);//read the previous IHWP mode
299 //printf("NOTICE \n %s \n",buffer);
300 prev_IHWP_State=buffer;
301 if (prev_IHWP_State.Contains("IN") || prev_IHWP_State.Contains("OUT")){
302 if (prev_IHWP_State.Contains("IN"))
304 else
306 if (fHalfWavePlateStatus.IsNull())//EPICS IHWP state is missing
307 fHalfWavePlateStatus=prev_IHWP_State;//in case EPICS IHWP state is not existing set the previous run IHWP state
308 }
309 }
310 else
311 prev_IHWP_State="";
312
313 if (!prev_IHWP_State.Contains("IN") && !prev_IHWP_State.Contains("OUT") ){//first time the file created
314 if (IHWP_State!=NULL)
315 fclose(IHWP_State);
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());
318 if (IHWP_State!=NULL){
319 fprintf(IHWP_State,"%s",fHalfWavePlateStatus.Data());
320 fclose(IHWP_State);
321 }
322 }
323 else{
324 if (fDefaultHalfWavePlateStatus!=fPreviousHalfWavePlateStatus){//at the begging of the feedback, if the current IHWP is not the same as last known good IHWP state then reset the PC values
325 printf("NOTICE \n Half-wave plate status has changed from %s to %s \n",prev_IHWP_State.Data(),fHalfWavePlateStatus.Data());
326 if (fHalfWaveIN){
328 fEPICSCtrl.Set_Pockels_Cell_plus(fPITASetpointPOS_t0_IN);
329 fEPICSCtrl.Set_Pockels_Cell_minus(fPITASetpointNEG_t0_IN);
330 }
331 } else{
333 fEPICSCtrl.Set_Pockels_Cell_plus(fPITASetpointPOS_t0_OUT);
334 fEPICSCtrl.Set_Pockels_Cell_minus(fPITASetpointNEG_t0_OUT);
335 }
336 }
337 }
338 printf("NOTICE \n previous half-wave plate status %s\n",prev_IHWP_State.Data());
339 if (IHWP_State!=NULL)
340 fclose(IHWP_State);
341 IHWP_State = fopen("/local/scratch/qweak/Feedback_IHWP.txt", "w");
342 printf("NOTICE \n Updating new IHWP %s \n",fHalfWavePlateStatus.Data());
343 if (IHWP_State!=NULL){
344 fprintf(IHWP_State,"%s",fHalfWavePlateStatus.Data());
345 fclose(IHWP_State);
346 }
347
348 }
349 }
350
351};
352
353
354/*****************************************************************/
356 //calculate the new setpoint
357 fEPICSCtrl.Get_HallCIA(mode,fPrevIASetpoint[mode]);
358 if (fIASlopeA[mode]!=0)
359 fIASetpoint[mode]=fPrevIASetpoint[mode] - fChargeAsym[mode]/fIASlopeA[mode];
360 else
361 fIASetpoint[mode]=fPrevIASetpoint[mode];
362
363 if (fIASetpoint[mode]>fIASetpointup)
365 else if (fIASetpoint[mode]<fIASetpointlow)
367
368 QwMessage<<"FeedIASetPoint("<<mode<<") "<<fChargeAsym[mode]<<"+/-"<<fChargeAsymError[mode]<<" new set point "<<fIASetpoint[mode]<<QwLog::endl;
369 //send the new IA setpoint
370
371 fEPICSCtrl.Set_HallCIA(mode,fIASetpoint[mode]);
372
373 //updating the standard asymmetry statistics
374 //commented out - rakithab 01-06-2011
375 //GetTargetChargeStat();
376 //fEPICSCtrl.Set_ChargeAsymmetry(fChargeAsymmetry,fChargeAsymmetryError,fChargeAsymmetryWidth);//updates the epics values
377
378 //Greenmonster stuffs
379 //fScanCtrl.SCNSetValue(1,0);
380 //fScanCtrl.SCNSetValue(2,0);
381 //fScanCtrl.CheckScan();
382 //fScanCtrl.PrintScanInfo();
383 //fScanCtrl.Close();
384};
385
386/*****************************************************************/
388 //calculate the new setpoint
389
390 fEPICSCtrl.Get_HallAIA(mode,fPrevHAIASetpoint[mode]);
391 if (fIASlopeA[mode]!=0){
392
393 if (fHalfWaveIN)
394 fHAIASetpoint[mode]=fPrevHAIASetpoint[mode] - fHAChargeAsym[mode]/fHAIASlopeA[0];//IHWP IN slope is stored at fHAIASlopeA[0]
395 else
396 fHAIASetpoint[mode]=fPrevHAIASetpoint[mode] - fHAChargeAsym[mode]/fHAIASlopeA[1];//IHWP OUT slope is stored at fHAIASlopeA[1]
397
398 } else
400
401 if ((fHAIASetpoint[mode]>fIASetpointup) || (fHAIASetpoint[mode]<fIASetpointlow)){//if correction is out-of bound no correction applied
402 QwMessage<<"Hall A FeedIASetPoint out-of-bounds "<<fHAChargeAsym[mode]<<" +/- "<<fHAChargeAsymError[mode]<<" new set point[+] "<<fHAIASetpoint[mode]<<" aborting correction for this time! "<<QwLog::endl;
403 return;
404 }
405
406 QwMessage<<"FeedIASetPoint("<<mode<<") "<<fHAChargeAsym[mode]<<"+/-"<<fHAChargeAsymError[mode]<<" new set point "<<fHAIASetpoint[mode]<<QwLog::endl;
407 //send the new IA setpoint
408
409 for (Int_t i=0;i<4;i++)
410 fEPICSCtrl.Set_HallAIA(i,fHAIASetpoint[mode]);//do the same correction to 4 DACs
411
412 fScalerChargeRunningSum.ClearEventData();//reset the running sums
413};
414
415
416/*****************************************************************/
418
419
420 //calculate the new setpoint
421 if (fHalfWaveIN)
423 else{
424 if (GetHalfWavePlate2State()==0)//IHWP2==OUT or No IHWP2 anymore
426 else
427 fPITASlope=fPITASlopeOUT_IN;//IHWP2==IN
428 }
429
430
431
432 fEPICSCtrl.Get_Pockels_Cell_plus(fPrevPITASetpointPOS);
433 fEPICSCtrl.Get_Pockels_Cell_minus(fPrevPITASetpointNEG);
434
435 if (fPITASlope!=0) {
436 Double_t correction = fChargeAsymmetry/fPITASlope;
437 //damp the correction when charge asymmetry is close to zero
438 if (fFeedbackDamping){
439 if (TMath::Abs(fChargeAsymmetry)<0.01)//ppm
440 correction*=0.01;
441 else if (TMath::Abs(fChargeAsymmetry)<0.1)//ppm
442 correction*=0.1;
443 else if (TMath::Abs(fChargeAsymmetry)<1)//ppm
444 correction*=0.25;
445 else if (TMath::Abs(fChargeAsymmetry)<2)//ppm
446 correction*=0.5;
447 else if (TMath::Abs(fChargeAsymmetry)<5)//ppm
448 correction*=0.75;
449 }
450
453
454
455 } else {
458 }
459
460
461
462
464 QwMessage<<"FeedPITASetPoint out-of-bounds "<<fChargeAsymmetry<<" +/- "<<fChargeAsymmetryError<<" new set point[+] "<<fPITASetpointPOS<<" [-] "<<fPITASetpointNEG<<" aborting correction for this time! "<<QwLog::endl;
465 return;//do nothing but can we reset to t_0 correction and start all over???????
466 }
467
468 QwMessage<<"FeedPITASetPoint "<<" "<<fChargeAsymmetry<<" +/- "<<fChargeAsymmetryError<<" new set point[+] "<<fPITASetpointPOS<<" [-] "<<fPITASetpointNEG<<QwLog::endl;
469
470 //send the new PITA setpoint
471 fEPICSCtrl.Set_Pockels_Cell_plus(fPITASetpointPOS);
472 fEPICSCtrl.Set_Pockels_Cell_minus(fPITASetpointNEG);
473
474 /*
475 if (fFeedbackStatus){
476 fFeedbackStatus=kFALSE;
477 fEPICSCtrl.Set_FeedbackStatus(2.0);//Setting to 2 seems to be not updating. Check back later
478 }
479 */
480
481 //Greenmonster stuffs are commented out - rakithab
482 //fScanCtrl.SCNSetValue(1,0);
483 //fScanCtrl.SCNSetValue(2,0);
484 //fScanCtrl.CheckScan();
485 //fScanCtrl.PrintScanInfo();
486 //fScanCtrl.Close();
487 ClearRunningSum();//reset the running sum only if PITA correction applied, the object fRunningAsymmetry is solely dedicated to PITA feedback
488};
489
490/*****************************************************************/
493/*****************************************************************/
496
497/*****************************************************************/
499 out_file_IA = fopen("/local/scratch/qweak/Feedback_IA_log.txt", "a");
500 // fprintf(out_file," Feedback at %d current A_q[%d]:%5.8f+/-%5.8f IA Setpoint:%5.3f IA Previous Setpoint:%5.3f\n",fQuartetNumber,mode,fChargeAsym[mode],fChargeAsymError[mode],fIASetpoint[mode],fPrevIASetpoint[mode]);
501 fprintf(out_file_IA," %10.0d A_q[%1.0d] %20.4f +/- %20.4f %20.2f %20.2f\n",fQuartetNumber,mode,fChargeAsym[mode],fChargeAsymError[mode],fIASetpoint[mode],fPrevIASetpoint[mode]);
502 fclose(out_file_IA);
503};
504
505/*****************************************************************/
507 fEPICSCtrl.Set_ChargeAsymmetry(fChargeAsymmetry,fChargeAsymmetryError,fChargeAsymmetryWidth);//updates the epics values
508 fEPICSCtrl.Set_BCM78DDAsymmetry(fAsymBCM78DD,fAsymBCM78DDError,fAsymBCM78DDWidth);//update BCM78DD
509 fEPICSCtrl.Set_BCM8Yield(fBCM8Yield);//Update BCM8 Yield
510 fEPICSCtrl.Set_USLumiSumAsymmetry(fAsymBCMUSLumiSum,fAsymBCMUSLumiSumError,fAsymBCMUSLumiSumWidth);//update the EPICS
511 out_file_PITA = fopen("/local/scratch/qweak/Feedback_PITA_log.txt", "a");
512 // out_file_PITA = fopen("/dev/shm/Feedback_PITA_log.txt", "a");
514 fclose(out_file_PITA);
515
516 if(TMath::Abs(fChargeAsymmetry)<5){
517 //These files save the last good PC hw count value for IHWP IN and OUT
518 if (fHalfWaveIN){
519 if (GetHalfWavePlate2State()==0){//IHWP2==OUT or No IHWP2 anymore
520 out_file_PC_IN_pos = fopen("/local/scratch/qweak/Last_good_PC_pos_IN", "w");//Open in write mode
521 out_file_PC_IN_neg = fopen("/local/scratch/qweak/Last_good_PC_neg_IN", "w");//Open in write mode
522 fprintf(out_file_PC_IN_pos,"%5.0f \n",fPrevPITASetpointPOS);
523 fprintf(out_file_PC_IN_neg,"%5.0f \n",fPrevPITASetpointNEG);
524 fclose(out_file_PC_IN_pos);
525 fclose(out_file_PC_IN_neg);
526 }else{//IHWP2==IN
527 out_file_PC_IN_pos = fopen("/local/scratch/qweak/Last_good_PC_pos_IN_IHWP2_IN", "w");//Open in write mode
528 out_file_PC_IN_neg = fopen("/local/scratch/qweak/Last_good_PC_neg_IN_IHWP2_IN", "w");//Open in write mode
529 fprintf(out_file_PC_IN_pos,"%5.0f \n",fPrevPITASetpointPOS);
530 fprintf(out_file_PC_IN_neg,"%5.0f \n",fPrevPITASetpointNEG);
531 fclose(out_file_PC_IN_pos);
532 fclose(out_file_PC_IN_neg);
533 }
534 }else{
535 if (GetHalfWavePlate2State()==0){//IHWP2==OUT or No IHWP2 anymore
536 out_file_PC_OUT_pos = fopen("/local/scratch/qweak/Last_good_PC_pos_OUT", "w");//Open in write mode
537 out_file_PC_OUT_neg = fopen("/local/scratch/qweak/Last_good_PC_neg_OUT", "w");//Open in write mode
538 fprintf(out_file_PC_OUT_pos,"%5.0f \n",fPrevPITASetpointPOS);
539 fprintf(out_file_PC_OUT_neg,"%5.0f \n",fPrevPITASetpointNEG);
540 fclose(out_file_PC_OUT_pos);
541 fclose(out_file_PC_OUT_neg);
542 }else{//IHWP2==IN
543 out_file_PC_OUT_pos = fopen("/local/scratch/qweak/Last_good_PC_pos_OUT_IHWP2_IN", "w");//Open in write mode
544 out_file_PC_OUT_neg = fopen("/local/scratch/qweak/Last_good_PC_neg_OUT_IHWP2_IN", "w");//Open in write mode
545 fprintf(out_file_PC_OUT_pos,"%5.0f \n",fPrevPITASetpointPOS);
546 fprintf(out_file_PC_OUT_neg,"%5.0f \n",fPrevPITASetpointNEG);
547 fclose(out_file_PC_OUT_pos);
548 fclose(out_file_PC_OUT_neg);
549 }
550 }
551 }
552
553};
554
555/*****************************************************************/
560
561/*****************************************************************/
563 fEPICSCtrl.Set_HAChargeAsymmetry(fHAChargeAsym[mode],fHAChargeAsymError[mode],fHAChargeAsymWidth[mode]);//updates the epics values
564 out_file_HA_IA = fopen("/local/scratch/qweak/Feedback_HA_IA_log.txt", "a");
565 //fQuartetNumber only available when we have good stable Hall C beam
566 fprintf(out_file_HA_IA," %10.0d %20.2f %15.2f %15.0f %20.0f %20.0f \n",fQuartetNumber,fHAChargeAsym[mode],fHAChargeAsymError[mode],TMath::Abs(fHAIASetpoint[mode]-fPrevHAIASetpoint[mode]),fHAIASetpoint[mode],fPrevHAIASetpoint[mode]);
567 fclose(out_file_HA_IA);
568
569};
570
571
572/*****************************************************************/
574 //fScanCtrl.Open();
575
576 if (state==0)
577 fScanCtrl.SCNSetStatus(SCN_INT_NOT);
578 if (state)
579 fScanCtrl.SCNSetStatus(SCN_INT_CLN);
580 fScanCtrl.CheckScan();
581 fScanCtrl.PrintScanInfo();
582 fScanCtrl.Close();
583
584};
585/*****************************************************************/
588
589/*****************************************************************/
591 Bool_t status=kFALSE;
592 GetTargetChargeStat();//call the calculate running sum routine and access the q_targ published value
593 if (fChargeAsymmetry==-1 && fChargeAsymmetryError == -1 && fChargeAsymmetryWidth==-1){//target asymmetry not published or accesible
594 QwError<<"target asymmetry not published or accesible"<<QwLog::endl;
595 status=kFALSE;
596 }
597 fChargeAsymmetryError=fChargeAsymmetryError*1e+6;//converts to ppm
598 fChargeAsymmetry=fChargeAsymmetry*1e+6;//converts to ppm
599 fChargeAsymmetryWidth=fChargeAsymmetryWidth*1e+6;//converts to ppm
601 QwError<<"Charge Asymmetry precision has not reached. Current value "<<fChargeAsymmetryError<<" Expected "<<fChargeAsymPrecision<<QwLog::endl;
602 status=kFALSE;
604 }
605 else{
606 QwError<<"Charge Asymmetry precision, Current value "<<fChargeAsymmetryError<<" Expected "<<fChargeAsymPrecision<<QwLog::endl;
607 //UpdateGMClean(0);//set to not clean - Diabled the cfsocket comm-rakithab 11-27-2011
608 FeedPITASetPoints();//set the new PITA values
609 LogParameters();//Log PITA setting after feedback
610 //UpdateGMClean(1);//set back to clean
611 status=kTRUE;
612 fGoodPatternCounter=0;//Reset after each feedback operation
613 }
614
615
616 return status;
617};
618
619/*****************************************************************/
621 Bool_t status=kFALSE;
622
624 if (fHAChargeAsym[0]==-1 && fHAChargeAsymError[0] == -1 && fHAChargeAsymWidth[0]==-1){//target asymmetry not published or accesible
625 QwError<<"Hall A asymmetry not published or accesible"<<QwLog::endl;
626 }else{
627 fHAChargeAsymError[0]=fHAChargeAsymError[0]*1.0e+6;//converts to ppm
628 fHAChargeAsym[0]=fHAChargeAsym[0]*1e+6;//converts to ppm
629 fHAChargeAsymWidth[0]=fHAChargeAsymWidth[0]*1e+6;//converts to ppm
631 QwError<<"Hall A Charge Asymmetry precision has not reached. Current value "<<fHAChargeAsymError[0]<<" Expected "<<fChargeAsymPrecision<<QwLog::endl;
632 QwError<<"--------------------------------------------------------------------------------------------------------------------------------"<<QwLog::endl;
634 }else{
635 //QwError<<"Hall A Charge Asymmetry precision, Current value "<<fHAChargeAsymError[0]<<" Expected "<<fChargeAsymPrecision<<QwLog::endl;
636 if (fHAIAFB){
637 //UpdateGMClean(0);//set to not clean - Diabled the cfsocket comm-rakithab 11-27-2011
639 //UpdateGMClean(1);//set back to clean
640 //fHAGoodPatternCounter=0;
641 }
643 LogHAParameters(0);
644 }
645 }
646
647 return status;
648};
649
650/*****************************************************************/
652 Bool_t HCstatus=kFALSE;
653
654 if (mode<0 || mode>3){
655 QwError << " Could not get external value setting parameters to q_targ" <<QwLog::endl;
656 return kFALSE;
657 }
658 QwMessage<<"ApplyIAFeedback["<<mode<<"]\n";
659
661
662 if (fChargeAsym[mode]==-1 && fChargeAsymError[mode] == -1 && fChargeAsymWidth[mode]==-1){//target asymmetry not published or accesible
663 QwError<<"target asymmetry not published or accesible"<<QwLog::endl;
664 HCstatus=kFALSE;
665 }else{
666 fChargeAsymError[mode]=fChargeAsymError[mode]*1e+6;//converts to ppm
667 fChargeAsym[mode]=fChargeAsym[mode]*1e+6;//converts to ppm
668 fChargeAsymWidth[mode]=fChargeAsymWidth[mode]*1e+6;//converts to ppm
670 QwError<<"Charge Asymmetry["<<mode<<"] precision not reached current value "<<fChargeAsymError[mode]<<" Expected "<<fChargeAsymPrecision<<QwLog::endl;
671 QwError<<"--------------------------------------------------------------------------------------------------------------------------------"<<QwLog::endl;
672 HCstatus=kFALSE;
674 }else
675 HCstatus=kTRUE;
676 }
677
678
679 if (HCstatus && fIAFB){
680 QwError<<"Charge Asymmetry["<<mode<<"] precision current value "<<fChargeAsymError[mode]<<" Expected "<<fChargeAsymPrecision<<QwLog::endl;
681 //UpdateGMClean(0);//set to not clean - Diabled the cfsocket comm-rakithab 11-27-2011
682 FeedIASetPoint(mode);
683 LogParameters(mode);
684 //UpdateGMClean(1);//set back to clean
687 }
688
689
690 return HCstatus;
691};
692
694 GetTargetPositionStat();//read running averages for target
695
696 //for now the targer paremeters are simply published
698 fPFGoodPatternCounter=0;//reset good pattern counter
699 fTargetXDiffRunningSum.ClearEventData();//reset the running sums
700 fTargetXPDiffRunningSum.ClearEventData();//reset the running sums
701 fTargetYDiffRunningSum.ClearEventData();//reset the running sums
702 fTargetYPDiffRunningSum.ClearEventData();//reset the running sums
703 f3C12XDiffRunningSum.ClearEventData();//reset the running sums
704 f3C12YDiffRunningSum.ClearEventData();//reset the running sums
705 f3C12YQRunningSum.ClearEventData();//reset the running sums
706
707
708 return kTRUE;
709};
710
711
712/*****************************************************************/
714 //Position Feedback
716 QwMessage<<"Initiating Position Feedback"<<QwLog::endl;
718 }
719 //End Position Feedback
720
721 //Hall C IA feedback
722 if (fIAFB){
723 for (Int_t i=0;i<kHelModes;i++){
724 if (IsPatternsAccumulated(i)){
725 QwMessage<<"IsPatternsAccumulated for Hall C IA "<<QwLog::endl;
726 ApplyIAFeedback(i);//Hall C IA is not set up properly
727 }
728 }
729 }
730 //Hall A IA feedback, the condition fHAIAFB is checked inside the IsHAPatternsAccumulated() routine. This is done to report charge Aq even HA feedback is disabled.
732 QwMessage<<"Initiating Hall A IA Feedback"<<QwLog::endl;
734 }
735 //End IA feedback
736
737 //PITA feedback
738 if (fPITAFB){
741 if(fHalfWavePlateStatus.Contains("IN")) {
742 if(fHalfWaveRevert) fHalfWaveIN = false;
743 else fHalfWaveIN = true;
744 }
745 else {
746 if(fHalfWaveRevert) fHalfWaveIN = true;
747 else fHalfWaveIN = false;
748 }
749
751
752 if (fHalfWaveIN)
753 printf("NOTICE \n Half-wave-plate-IN\n");
754 else
755 printf("NOTICE \n Half-wave-plate-OUT\n");
756
757 //Check to see the IHWP has changed if we are running is Auto IHWP mode
758 if (fAutoIHWP){
759 if((fDefaultHalfWavePlateStatus==1 && fHalfWaveOUT) || (fDefaultHalfWavePlateStatus==0 && fHalfWaveIN)){ //IHWP at the start of the feedback is different from current value
760 if (fHalfWaveOUT){
761 fDefaultHalfWavePlateStatus=0;//update the defalut IHWP state to OUT
763 fEPICSCtrl.Set_Pockels_Cell_plus(fPITASetpointPOS_t0_OUT);
764 fEPICSCtrl.Set_Pockels_Cell_minus(fPITASetpointNEG_t0_OUT);
765 }
766 }
767 else{
768 fDefaultHalfWavePlateStatus=1;//update the defalut IHWP state to IN
770 fEPICSCtrl.Set_Pockels_Cell_plus(fPITASetpointPOS_t0_IN);
771 fEPICSCtrl.Set_Pockels_Cell_minus(fPITASetpointNEG_t0_IN);
772 }
773 }
774 fGoodPatternCounter=0;//Reset after each feedback operation
775 ClearRunningSum();//Then reset the running sum
776
777 //Update the new IHWP state in the text file
778 if (IHWP_State!=NULL)
779 fclose(IHWP_State);
780 IHWP_State = fopen("/local/scratch/qweak/Feedback_IHWP.txt", "w");
781 printf("NOTICE \n Updating new IHWP %s \n",fHalfWavePlateStatus.Data());
782 if (IHWP_State!=NULL){
783 fprintf(IHWP_State,"%s",fHalfWavePlateStatus.Data());
784 fclose(IHWP_State);
785 }
786
787 return;//and start the correction loop all over
788 }
789
790 }
791
792 ApplyPITAFeedback();//PITA corrections initiate here
793 }
794 }
795 //End PITA feedback
796
797 return;
798
799};
800
801/*****************************************************************/
804 //QwMessage<<"fHelModeGoodPatternCounter["<<mode<<"]\n";
805 return kTRUE;
806 }
807
808 return kFALSE;
809};
810/*****************************************************************/
814/*****************************************************************/
815
816//*****************************************************************
817/**
818 * Calculate asymmetries for the current pattern.
819 */
821{
822
823 Bool_t localdebug=kFALSE;
824
825 if(localdebug) std::cout<<"Entering QwHelicityPattern::CalculateAsymmetry \n";
826
827 Int_t plushel = 1;
828 Int_t minushel = 0;
829 Int_t checkhel = 0;
830 Bool_t firstplushel=kTRUE;
831 Bool_t firstminushel=kTRUE;
832
833 fPositiveHelicitySum.ClearEventData();
834 fNegativeHelicitySum.ClearEventData();
835
836 if (fIgnoreHelicity){
837 // Don't check to see if we have equal numbers of even and odd helicity states in this pattern.
838 // Build an asymmetry with even-parity phases as "+" and odd-parity phases as "-"
839 for (size_t i = 0; i < (size_t) fPatternSize; i++) {
840 Int_t localhel = 1;
841 for (size_t j = 0; j < (size_t) fPatternSize/2; j++) {
842 localhel ^= ((i >> j)&0x1);
843 }
844 if (localhel == plushel) {
845 if (firstplushel) {
847 firstplushel = kFALSE;
848 } else {
850 }
851 } else if (localhel == minushel) {
852 if (firstminushel) {
854 firstminushel = kFALSE;
855 } else {
857 }
858 }
859 }
860 } else {
861 //
863 for (size_t i = 0; i < (size_t) fPatternSize; i++) {
864 if (fHelicity[i] == plushel) {
865 if (fPatternSize==4){//currently works only for pattern size of 4
866 switch(i){
867 case 0:
868 //fCurrentHelPat+=1;
869 fCurrentHelPat+=1000;
870 break;
871 case 1:
872 //fCurrentHelPat+=10;
873 fCurrentHelPat+=100;
874 break;
875 case 2:
876 //fCurrentHelPat+=100;
877 fCurrentHelPat+=10;
878 break;
879 case 3:
880 //fCurrentHelPat+=1000;
882 break;
883 }
884 }
885
886 if (localdebug)
887 std::cout<<"QwHelicityPattern::CalculateAsymmetry:: here filling fPositiveHelicitySum \n";
888 if (firstplushel) {
889 if (localdebug) std::cout<<"QwHelicityPattern::CalculateAsymmetry:: with = \n";
891 firstplushel = kFALSE;
892 } else {
893 if (localdebug) std::cout<<"QwHelicityPattern::CalculateAsymmetry:: with += \n";
895 }
896 checkhel += 1;
897 } else if (fHelicity[i] == minushel) {
898 if (localdebug) std::cout<<"QwHelicityPattern::CalculateAsymmetry:: here filling fNegativeHelicitySum \n";
899 if (firstminushel) {
900 if (localdebug) std::cout<<"QwHelicityPattern::CalculateAsymmetry:: with = \n";
902 firstminushel = kFALSE;
903 } else {
904 if (localdebug) std::cout<<"QwHelicityPattern::CalculateAsymmetry:: with += \n";
906 }
907 checkhel -= 1;
908 } else {
909 QwError<< "QwHelicityPattern::CalculateAsymmetry =="
910 << "Helicity should be "<<plushel<<" or "<<minushel<<" but is"<< fHelicity[i]
911 << "; Asymmetry computation aborted!"<<QwLog::endl;
913 i = fPatternSize;
914 checkhel = -9999;
915 // This is an unknown helicity event.
916 }
917
918 }
919
920 }
921
922 if (checkhel == -9999) {
923 //do nothing the asymmetry computation has been aborted earlier in this function
924 fPatternIsGood = kFALSE;
925 } else if (checkhel!=0) {
926 fPatternIsGood = kFALSE;
927 // there is a different number of plus and minus helicity window.
928 QwError<<" QwHelicityPattern::CalculateAsymmetry == \n"
929 <<" you do not have the same number of positive and negative \n"
930 <<" impossible to compute assymetry \n"
931 <<" dropping every thing -- pattern number ="<<fCurrentPatternNumber<<QwLog::endl;
932 } else {
933 // This is a good pattern.
934 // Calculate the asymmetry.
935
936 //Now set the HelPatMode
937 if (fPreviousHelPat){
946 else
947 fCurrentHelPatMode=-1;//error
948 }
949 //save the current pattern size to previouspat
950 if (localdebug)
951 QwMessage<<"QwHelicityPattern::CalculateAsymmetry current helpat is "<<fCurrentHelPat<<" Prev pat "<<fPreviousHelPat<<" Mode "<<fCurrentHelPatMode<<" \n";
953
954 fPatternIsGood = kTRUE;
956 //std::cout<<" quartet count ="<<fQuartetNumber<<"\n";
957
959 fYield.Scale(1.0/fPatternSize);
961 fDifference.Scale(1.0/fPatternSize);
962 if (! fIgnoreHelicity){
963 // Only blind the difference if we're using the real helicity.
965 }
967
968 if (fAsymmetry.GetEventcutErrorFlag()==0){//good pattern
969 //fPatternIsGood = kTRUE;
970 fGoodPatternCounter++;//increment the quartet number - reset after each PITA feedback operation
971 fQuartetNumber++;//Then increment the quartet number - continously count
972 }
973
974 /*
975 With additional two asymmetry calculations
976 Don't blind them!
977
978 quartet pattern + - - +
979 1 2 3 4
980 fAsymmetry = (1+4)-(2+3)/(1+2+3+4)
981 fAsymmetry1 = (1+2)-(3+4)/(1+2+3+4)
982 fAsymmetry2 = (1+3)-(2+4)/(1+2+3+4)
983 */
985 // fAsymmetry1: (first 1/2 pattern - second 1/2 pattern)/fYield
986 fPositiveHelicitySum.ClearEventData();
987 fNegativeHelicitySum.ClearEventData();
990 if (fPatternSize/2 > 1){
991 for (size_t i = 1; i < (size_t) fPatternSize/2 ; i++){
994 }
995 }
996 fAlternateDiff.ClearEventData();
998 // Do not blind this helicity-uncorrelated difference.
1000 // fAsymmetry2: (even events - odd events)/fYield
1001 // Only build fAsymmetry2 if fPatternSize>2.
1002 if (fPatternSize > 2) {
1003 fPositiveHelicitySum.ClearEventData();
1004 fNegativeHelicitySum.ClearEventData();
1007 if (fPatternSize/2 > 1){
1008 for (size_t i = 1; i < (size_t) fPatternSize/2 ; i++){
1009 fPositiveHelicitySum += fEvents.at(2*i);
1010 fNegativeHelicitySum += fEvents.at(2*i + 1);
1011 }
1012 }
1013 fAlternateDiff.ClearEventData();
1015 // Do not blind this helicity-uncorrelated difference.
1017 }
1018 }
1019
1020 // Accumulate the burst and running sums
1021 if (fEnableBurstSum) AccumulateBurstSum();
1022 if (fEnableRunningSum) {
1024 }
1025
1026 if (localdebug) QwDebug << " pattern number =" << fQuartetNumber << QwLog::endl;
1027 }
1028
1029 return;
1030};
1031
1032
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;
1041
1042
1043
1044
1046
1047 if(fAsymmetry.RequestExternalValue("sca_bcm", &fScalerCharge)){
1048 //fScalerChargeRunningSum.PrintValue();
1049 //fScalerChargeRunningSum.AccumulateRunningSum(fScalerCharge);
1050 if (fScalerCharge.GetEventcutErrorFlag()==0 && fAsymmetry.GetEventcutErrorFlag()==0){
1051 fScalerChargeRunningSum.AccumulateRunningSum(fScalerCharge);
1052 fHAGoodPatternCounter++;//update the good HA asymmetry counter
1053 }
1054 }else{
1055 QwError << " Could not get external value setting parameters to sca_bcm" <<QwLog::endl;
1056 fHAIAFB=kFALSE;
1057 }
1058
1059 if(fAsymmetry.RequestExternalValue("x_targ", &fTargetParameter)){
1060 if (fTargetParameter.GetEventcutErrorFlag()==0 && fAsymmetry.GetEventcutErrorFlag()==0){
1061 fTargetXDiffRunningSum.AccumulateRunningSum(fTargetParameter);
1062 bXDiff=kTRUE;
1063 }
1064 }
1065
1066 if(fAsymmetry.RequestExternalValue("xp_targ", &fTargetParameter)){
1067 if (fTargetParameter.GetEventcutErrorFlag()==0 && fAsymmetry.GetEventcutErrorFlag()==0){
1068 fTargetXPDiffRunningSum.AccumulateRunningSum(fTargetParameter);
1069 bXPDiff=kTRUE;
1070 }
1071 }
1072
1073 if(fAsymmetry.RequestExternalValue("y_targ", &fTargetParameter)){
1074 if (fTargetParameter.GetEventcutErrorFlag()==0 && fAsymmetry.GetEventcutErrorFlag()==0){
1075 fTargetYDiffRunningSum.AccumulateRunningSum(fTargetParameter);
1076 bYDiff=kTRUE;
1077 }
1078 }
1079
1080 if(fAsymmetry.RequestExternalValue("yp_targ", &fTargetParameter)){
1081 if (fTargetParameter.GetEventcutErrorFlag()==0 && fAsymmetry.GetEventcutErrorFlag()==0){
1082 fTargetYPDiffRunningSum.AccumulateRunningSum(fTargetParameter);
1083 bYPDiff=kTRUE;
1084 }
1085 }
1086
1087 if(fAsymmetry.RequestExternalValue("3c12x", &fTargetParameter)){
1088 if (fTargetParameter.GetEventcutErrorFlag()==0 && fAsymmetry.GetEventcutErrorFlag()==0){
1089 f3C12XDiffRunningSum.AccumulateRunningSum(fTargetParameter);
1090 b3C12XDiff=kTRUE;
1091 }
1092 }
1093
1094 if(fAsymmetry.RequestExternalValue("3c12y", &fTargetParameter)){
1095 if (fTargetParameter.GetEventcutErrorFlag()==0 && fAsymmetry.GetEventcutErrorFlag()==0){
1096 f3C12YDiffRunningSum.AccumulateRunningSum(fTargetParameter);
1097 b3C12YDiff=kTRUE;
1098 }
1099 }
1100
1101 if(fAsymmetry.RequestExternalValue("bcm7", &fAsymBCM7) && fAsymmetry.RequestExternalValue("bcm8", &fAsymBCM8)){
1102 if (fAsymBCM7.GetEventcutErrorFlag()==0 && fAsymBCM8.GetEventcutErrorFlag()==0 && fAsymmetry.GetEventcutErrorFlag()==0){
1103 fAsymBCM78DDRunningSum.AccumulateRunningSum((fAsymBCM7-fAsymBCM8));
1104 }
1105 }
1106
1107 if(fAsymmetry.RequestExternalValue("uslumisum", &fTargetCharge)){
1108 if (fAsymmetry.GetEventcutErrorFlag()==0 && fTargetCharge.GetEventcutErrorFlag()==0){
1109 fAsymUSLumiSumRunningSum.AccumulateRunningSum(fTargetCharge);
1110 }
1111 }
1112 if(fYield.RequestExternalValue("3c12efc", &fTargetParameter)){
1113 if (fTargetParameter.GetEventcutErrorFlag()==0 && fYield.GetEventcutErrorFlag()==0){
1114 f3C12YQRunningSum.AccumulateRunningSum(fTargetParameter);
1115 b3C12YQ=kTRUE;
1116 }
1117 }
1118 if(fYield.RequestExternalValue("bcm8", &fTargetCharge)){
1119 if (fTargetCharge.GetEventcutErrorFlag()==0 && fYield.GetEventcutErrorFlag()==0){
1120 fYieldBCM8RunningSum.AccumulateRunningSum(fTargetCharge);
1121 }
1122 }
1123
1124
1125
1126
1127
1128
1129
1130
1131 if (bXDiff && bXPDiff && bYDiff && bYPDiff && b3C12YQ)//if all parameters are good
1132 fPFGoodPatternCounter++;//update the good position/angle asymmetry counter
1133
1134
1135
1136
1137
1138
1139 switch(fCurrentHelPatMode){
1140 case 0:
1141 fFBRunningAsymmetry[0].AccumulateRunningSum(fAsymmetry);
1143 break;
1144 case 1:
1145 fFBRunningAsymmetry[1].AccumulateRunningSum(fAsymmetry);
1147 break;
1148 case 2:
1149 fFBRunningAsymmetry[2].AccumulateRunningSum(fAsymmetry);
1151 break;
1152 case 3:
1153 fFBRunningAsymmetry[3].AccumulateRunningSum(fAsymmetry);
1155 break;
1156 }
1157
1158
1159};
1160
1161
1162
1166
1168 fFBRunningAsymmetry[mode].CalculateRunningAverage();
1169};
1170
1171
1172//*****************************************************************
1173/**
1174/// \brief retrieves the target charge asymmetry,asymmetry error ,asymmetry width
1175*/
1177 fRunningAsymmetry.CalculateRunningAverage();
1178
1179 if (fRunningAsymmetry.RequestExternalValue("q_targ",&fTargetCharge)){
1180 QwMessage<<"Reading published charge value stats"<<QwLog::endl;
1181 fTargetCharge.PrintInfo();
1183 fChargeAsymmetryError=fTargetCharge.GetValueError();
1184 fChargeAsymmetryWidth=fTargetCharge.GetValueWidth();
1185
1186 //calculate mean BCM78DD asymmetry and bcm8 yield and update parameters to be publised in EPICS
1187 fAsymBCM78DDRunningSum.CalculateRunningAverage();
1188 fYieldBCM8RunningSum.CalculateRunningAverage();
1189
1191
1192 fAsymBCM78DD=fAsymBCM78DDRunningSum.GetValue()*1.0e+6;
1193 fAsymBCM78DDError=fAsymBCM78DDRunningSum.GetValueError()*1.0e+6;
1194 fAsymBCM78DDWidth=fAsymBCM78DDRunningSum.GetValueWidth()*1.0e+6;
1195
1196 //calculate mean USLumi Sum asymmetry and update parameters to be publised in EPICS
1197 fAsymUSLumiSumRunningSum.CalculateRunningAverage();
1199 fAsymBCMUSLumiSumError=fAsymUSLumiSumRunningSum.GetValueError()*1.0e+6;
1200 fAsymBCMUSLumiSumWidth=fAsymUSLumiSumRunningSum.GetValueWidth()*1.0e+6;
1201 return ;
1202 }
1203 QwError << " Could not get external value setting parameters to q_targ" <<QwLog::endl;
1207
1208 fBCM8Yield=0;
1209 fAsymBCM78DD=0;
1212
1216 return;
1217};
1218
1219//*****************************************************************
1220/**
1221/// \brief retrieves the target charge asymmetry,asymmetry error ,asymmetry width
1222*/
1224 if (!fIAFB){
1225 fChargeAsym[mode]=-1;
1226 fChargeAsymError[mode]=-1;
1227 fChargeAsymWidth[mode]=-1;
1228 }
1229
1230 if (mode<0 || mode>3){
1231 QwError << " Could not get external value setting parameters to q_targ" <<QwLog::endl;
1232 return;
1233 }
1234 /*
1235 fFBRunningAsymmetry[mode].CalculateRunningAverage();
1236 if (fFBRunningAsymmetry[mode].RequestExternalValue("q_targ",&fTargetCharge)){
1237 QwMessage<<"Reading published charge value stats"<<QwLog::endl;
1238 fTargetCharge.PrintInfo();
1239 fChargeAsym[mode]=fTargetCharge.GetHardwareSum();
1240 fChargeAsymError[mode]=fTargetCharge.GetHardwareSumError();
1241 fChargeAsymWidth[mode]=fTargetCharge.GetHardwareSumWidth();
1242 return ;
1243 }
1244 */
1245 //QwError << " Could not get external value setting parameters to q_targ" <<QwLog::endl;
1246 fChargeAsym[mode]=-1;
1247 fChargeAsymError[mode]=-1;
1248 fChargeAsymWidth[mode]=-1;
1249
1250 return;
1251};
1252
1253//*****************************************************************
1255 //compute the running averages
1256 fTargetXDiffRunningSum.CalculateRunningAverage();
1257 fTargetXPDiffRunningSum.CalculateRunningAverage();
1258 fTargetYDiffRunningSum.CalculateRunningAverage();
1259 fTargetYPDiffRunningSum.CalculateRunningAverage();
1260 f3C12XDiffRunningSum.CalculateRunningAverage();
1261 f3C12YDiffRunningSum.CalculateRunningAverage();
1262 f3C12YQRunningSum.CalculateRunningAverage();
1263
1264
1265 //Update X stats
1266 fTargetXDiff=fTargetXDiffRunningSum.GetValue()*1.0e+3;
1267 fTargetXDiffError=fTargetXDiffRunningSum.GetValueError()*1.0e+3;
1268 fTargetXDiffWidth=fTargetXDiffRunningSum.GetValueWidth()*1.0e+3;
1269
1270 //Update XP stats in nrad
1271 fTargetXPDiff=fTargetXPDiffRunningSum.GetValue()*1.0e+9;
1272 fTargetXPDiffError=fTargetXPDiffRunningSum.GetValueError()*1.0e+9;
1273 fTargetXPDiffWidth=fTargetXPDiffRunningSum.GetValueWidth()*1.0e+9;
1274
1275 //Update Y stats
1276 fTargetYDiff=fTargetYDiffRunningSum.GetValue()*1.0e+3;
1277 fTargetYDiffError=fTargetYDiffRunningSum.GetValueError()*1.0e+3;
1278 fTargetYDiffWidth=fTargetYDiffRunningSum.GetValueWidth()*1.0e+3;
1279
1280 //Update YP stats in nrad
1281 fTargetYPDiff=fTargetYPDiffRunningSum.GetValue()*1.0e+9;
1282 fTargetYPDiffError=fTargetYPDiffRunningSum.GetValueError()*1.0e+9;
1283 fTargetYPDiffWidth=fTargetYPDiffRunningSum.GetValueWidth()*1.0e+9;
1284
1285
1286 //Update 3c12X stats
1287 f3C12XDiff=f3C12XDiffRunningSum.GetValue()*1.0e+3;
1288 f3C12XDiffError=f3C12XDiffRunningSum.GetValueError()*1.0e+3;
1289 f3C12XDiffWidth=f3C12XDiffRunningSum.GetValueWidth()*1.0e+3;
1290
1291 //Update 3c12Y stats
1292 f3C12YDiff=f3C12YDiffRunningSum.GetValue()*1.0e+3;
1293 f3C12YDiffError=f3C12YDiffRunningSum.GetValueError()*1.0e+3;
1294 f3C12YDiffWidth=f3C12YDiffRunningSum.GetValueWidth()*1.0e+3;
1295
1296 //Update 3c12YQ stats
1297 f3C12YQ=f3C12YQRunningSum.GetValue();
1298 f3C12YQError=f3C12YQRunningSum.GetValueError();
1299 f3C12YQWidth=f3C12YQRunningSum.GetValueWidth();
1300
1301
1302
1303
1304
1305 /*
1306 fTargetXDiffRunningSum.PrintInfo();
1307 fTargetXPDiffRunningSum.PrintInfo();
1308 fTargetYDiffRunningSum.PrintInfo();
1309 fTargetYPDiffRunningSum.PrintInfo();
1310 */
1311
1312 return;
1313
1314}
1315
1316//*****************************************************************
1317/**
1318/// \brief retrieves the Hall A charge asymmetry,asymmetry error ,asymmetry width
1319*/
1321 if (mode<0 || mode>3){
1322 QwError << " Hall A Mode is out of bound " << mode <<" mode<0 || mode>3 "<<QwLog::endl;
1323 return;
1324 }
1325 fScalerChargeRunningSum.CalculateRunningAverage();
1326 QwError<<"Reading published Hall A charge value stats "<<QwLog::endl;
1327 fScalerChargeRunningSum.PrintValue();
1328 fHAChargeAsym[mode]=fScalerChargeRunningSum.GetValue();
1329 fHAChargeAsymError[mode]=fScalerChargeRunningSum.GetValueError();
1330 fHAChargeAsymWidth[mode]=fScalerChargeRunningSum.GetValueWidth();
1331 QwError<<" Scaler asym "<<fHAChargeAsym[mode]<<" error "<<fHAChargeAsymError[mode]<<" width "<<fHAChargeAsymWidth[mode]<<QwLog::endl;
1332 return ;
1333};
1334
1335//*****************************************************************
1336/**
1337 * Clear the running sums of yield, difference and asymmetry.
1338 * Also clear the running burst sums if enabled.
1339 */
1341{
1342 QwHelicityPattern::ClearRunningSum();
1343 //Clean bcm8 yield and bcm78 DD running sums
1344 fAsymBCM78DDRunningSum.ClearEventData();
1345 fYieldBCM8RunningSum.ClearEventData();
1346 //clear US lumi running sum
1347 fAsymUSLumiSumRunningSum.ClearEventData();
1348}
1349
1351{
1352 fFBRunningAsymmetry[mode].ClearEventData();
1353};
1354
1355void QwHelicityCorrelatedFeedback::ConstructBranchAndVector(TTree *tree, TString &prefix, std::vector<Double_t> &values){
1357};
1358
1359void QwHelicityCorrelatedFeedback::FillTreeVector(std::vector<Double_t> &values) const{
1361};
1362
1363
1365{
1366 TString plate_status = gSystem->GetFromPipe("caget -t -w 0.1 IGL1I00DI24_24M");
1367 return plate_status;
1368};
1369
1371 TString ihwp2_value = gSystem->GetFromPipe("caget -tf0 -w 0.1 IGL1I00DIOFLRD");
1372 UInt_t ihwp2 =ihwp2_value.Atoi();
1373
1374 if (ihwp2>10000)
1375 return 1;//13056=IN
1376 else
1377 return 0; //8960=OUT
1378};
1379
1381{
1382 Double_t old_status = 0.0;
1383 old_status = fEPICSCtrl.Get_FeedbackStatus();
1384 if(old_status == 1.0) {
1385 // EPIC says, feedback is on, but we start it now.
1386 // qwfeedback was killed by "kill -9 option" or was ended improperly.
1387 fEPICSCtrl.Set_FeedbackStatus(0.0);
1388 fFeedbackStatus=kFALSE;
1389 gSystem->Sleep(4000); // wait 4 secs
1390 }
1391 fEPICSCtrl.Set_FeedbackStatus(1.0);
1392 fFeedbackStatus=kTRUE;
1393}
#define SCN_INT_NOT
#define SCN_INT_CLN
#define QwError
Predefined log drain for errors.
Definition QwLog.h:39
#define QwMessage
Predefined log drain for regular messages.
Definition QwLog.h:49
#define QwDebug
Predefined log drain for debugging output.
Definition QwLog.h:59
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.
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
static std::ostream & endl(std::ostream &)
End of the line.
Definition QwLog.cc:297
Command-line and configuration file options processor.
Definition QwOptions.h:141
T GetValue(const std::string &key)
Get a templated value.
Definition QwOptions.h:236
po::options_description_easy_init AddOptions(const std::string &blockname="Specialized options")
Add an option to a named block or create new block.
Definition QwOptions.h:170
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
void ConstructBranchAndVector(TTree *tree, TString &prefix, QwRootTreeBranchVector &values)
QwSubsystemArrayParity fNegativeHelicitySum
QwSubsystemArrayParity fDifference
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