JAPAn
Just Another Parity Analyzer
Loading...
Searching...
No Matches
QwFeedback.cc
Go to the documentation of this file.
1
2/*------------------------------------------------------------------------*//*!
3
4 \file QwFeedback.cc
5
6 \brief main(...) function for the qwanalysis feedback executable to set IA and/or PITA slopes
7
8*//*-------------------------------------------------------------------------*/
9
10// System headers
11#include <iostream>
12#include <fstream>
13#include <vector>
14#include <new>
15
16// Boost headers
17#include <boost/shared_ptr.hpp>
18
19// Qweak headers
20#include "QwLog.h"
21#include "QwRootFile.h"
22#include "QwOptionsParity.h"
23#include "QwEventBuffer.h"
24#include "QwHistogramHelper.h"
27#include "QwEventRing.h"
28#include "QwEPICSEvent.h"
29//#include "QwEPICSControl.h"
30//#include "GreenMonster.h"
31
32// Qweak subsystems
33// (for correct dependency generation)
34#include "QwHelicity.h"
35#include "QwFakeHelicity.h"
36#include "QwBeamLine.h"
37#include "QwVQWK_Channel.h"
38
39
40
41
42Int_t main(Int_t argc, Char_t* argv[])
43{
44 /// First, fill the search paths for the parameter files; this sets a
45 /// static variable within the QwParameterFile class which will be used by
46 /// all instances.
47 /// The "scratch" directory should be first.
48 //QwParameterFile::AppendToSearchPath(getenv_safe_string("QW_PRMINPUT"));
49 QwParameterFile::AppendToSearchPath(getenv_safe_string("QWANALYSIS") + "/Extensions/QwFeedback/prminput");
50 //QwParameterFile::AppendToSearchPath(getenv_safe_string("QWANALYSIS") + "/Parity/prminput");
51 //QwParameterFile::AppendToSearchPath(getenv_safe_string("QWANALYSIS") + "/Analysis/prminput");
52
53
54 // Then set the command line arguments and the configuration filename,
55 // and we define the options that can be used in them (using QwOptions).
56 gQwOptions.SetCommandLine(argc, argv);
57 gQwOptions.AddConfigFile("qwfeedback.conf");
58 //gQwOptions.ListConfigFiles();
59 //gQwOptions.AddConfigFile("qweak_mysql.conf");
60 // Define the command line options
63 //Load command line options for the histogram/tree helper class
64 gQwHists.ProcessOptions(gQwOptions);
65 /// Setup screen and file logging
66 gQwLog.ProcessOptions(&gQwOptions);
67
68 /// Load the histogram parameter definitions (from parity_hists.txt) into the global
69 /// histogram helper: QwHistogramHelper
70 //gQwHists.LoadHistParamsFromFile("qweak_parity_hists.in");
71 //gQwHists.LoadTreeParamsFromFile("Qweak_Tree_Trim_List.in");
72
73
74 /// Create the event buffer
75 QwEventBuffer eventbuffer;
76 eventbuffer.ProcessOptions(gQwOptions);
77
78
79
80 /// Create the database connection
81 // QwDatabase database(gQwOptions);
82
83
84 /// Start loop over all runs
85 // QwRootFile* rootfile = 0;
86
87
88 /*
89 /// Create an EPICS control event
90 QwEPICSControl fEPICSCtrl;
91 GreenMonster fScanCtrl;
92 // Let's clear the values for the scan data & set "not clean".
93 fScanCtrl.Open();
94 fScanCtrl.SCNSetStatus(SCN_INT_NOT);
95 fScanCtrl.SCNSetValue(1,0);
96 fScanCtrl.SCNSetValue(2,0);
97 fScanCtrl.CheckScan();
98 fScanCtrl.PrintScanInfo();
99 fScanCtrl.Close();
100
101 fEPICSCtrl.Print_Qasym_Ctrls();
102 */
103
104 // Loop over all runs
105 while (eventbuffer.OpenNextStream() == CODA_OK){
106 // Begin processing for the first run.
107
108 /// Set the current event number for parameter file lookup
110
111
112 /// Create an EPICS event
113 QwEPICSEvent epicsevent;
114 epicsevent.LoadChannelMap("EpicsTable.map");
115
116 /// Load the detectors from file
118 detectors.ProcessOptions(gQwOptions);
119
120 /// Create the helicity pattern
121 QwHelicityCorrelatedFeedback helicitypattern(detectors);
122 helicitypattern.ProcessOptions(gQwOptions);
123 helicitypattern.LoadParameterFile("qweak_fb_prm.in");
124 /*
125 helicitypattern.UpdateGMClean(0);
126 helicitypattern.FeedIASetPoint(0);
127 helicitypattern.UpdateGMClean(1);
128 */
129
130 /// Create the event ring with the subsysten array
131 QwEventRing eventring(gQwOptions,detectors);
132
133 /// Create the running sum
134 QwSubsystemArrayParity runningsum(detectors);
135
136
137 Int_t failed_events_counts = 0; // count failed total events
138
139
140 // Clear the single-event running sum at the beginning of the runlet
141 runningsum.ClearEventData();
142 helicitypattern.ClearRunningSum();
143 // Clear the running sum of the burst values at the beginning of the runlet
144 helicitypattern.ClearBurstSum();
145
146
147
148
149 // Loop over events in this CODA file
150 while (eventbuffer.GetNextEvent() == CODA_OK) {
151
152 if (eventbuffer.GetEventNumber()%1000)
153 std::cout<<std::flush;
154
155 // First, do processing of non-physics events...
156 if (eventbuffer.IsROCConfigurationEvent()){
157 // Send ROC configuration event data to the subsystem objects.
158 eventbuffer.FillSubsystemConfigurationData(detectors);
159 }
160
161 // Dump out of the loop when we see the end event.
162 if (eventbuffer.GetEndEventCount()>0){
163 QwMessage << "Number of events processed at end of run: " << eventbuffer.GetEventNumber() << std::endl;
164 break;
165 }
166
167 // Now, if this is not a physics event, go back and get a new event.
168 if (!eventbuffer.IsPhysicsEvent()) continue;
169
170
171 // Fill the subsystem objects with their respective data for this event.
172 eventbuffer.FillSubsystemData(detectors);
173
174 // Process the subsystem data
175 detectors.ProcessEvent();
176
177 // The event pass the event cut constraints
178 if (detectors.ApplySingleEventCuts()) {
179
180 // Accumulate the running sum to calculate the event based running average
181 runningsum.AccumulateRunningSum(detectors);
182
183// // Fill the histograms
184// rootfile->FillHistograms(detectors);
185
186// // Fill the tree branches
187// rootfile->FillTreeBranches(detectors);
188// rootfile->FillTree("Mps_Tree");
189
190 // Add event to the ring
191 eventring.push(detectors);
192
193 // Check to see ring is ready
194 if (eventring.IsReady()) {
195
196 // Load the event into the helicity pattern
197 helicitypattern.LoadEventData(eventring.pop());
198
199 // Calculate helicity pattern asymmetry
200 if (helicitypattern.IsCompletePattern()) {
201
202 // Update the blinder if conditions have changed
203 helicitypattern.UpdateBlinder(detectors);
204
205 // Calculate the asymmetry
206 helicitypattern.CalculateAsymmetry();
207 if (helicitypattern.IsGoodAsymmetry()) {
208 helicitypattern.ApplyFeedbackCorrections();//apply IA feedback
209 // Clear the data
210 helicitypattern.ClearEventData();
211 }
212
213 } // helicitypattern.IsCompletePattern()
214
215 } // eventring.IsReady()
216
217
218 // Failed single event cuts
219 } else {
220 failed_events_counts++;
221 }
222
223
224
225
226 } // end of loop over events
227
228 QwMessage << "Number of events processed at end of run: "
229 << eventbuffer.GetEventNumber() << std::endl;
230
231
232
233 // Close event buffer stream
234 eventbuffer.CloseStream();
235
236
237
238 // Print the event cut error summery for each subsystem
239 // detectors.GetEventcutErrorCounters();
240
241
242 // Read from the datebase
243 // database.SetupOneRun(eventbuffer);
244
245 // Each sussystem has its own Connect() and Disconnect() functions.
246 // if (database.AllowsWriteAccess()) {
247 // helicitypattern.FillDB(&database);
248 // epicsevent.FillDB(&database);
249 // }
250
251
252 QwMessage << "Total events failed " << failed_events_counts << QwLog::endl;
253
254 // Report run summary
255 eventbuffer.ReportRunSummary();
256 eventbuffer.PrintRunTimes();
257
258 } //end of run loop
259
260
261 QwMessage << "I have done everything I can do..." << QwLog::endl;
262
263 return 0;
264}
Int_t main(Int_t argc, Char_t *argv[])
Definition QwFeedback.cc:42
Helper functions and utilities for ROOT histogram management.
QwHistogramHelper gQwHists
Globally defined instance of the QwHistogramHelper class.
const std::string getenv_safe_string(const char *name)
Definition QwOptions.h:43
#define gQwOptions
Definition QwOptions.h:31
A logfile class, based on an identical class in the Hermes analyzer.
QwLog gQwLog
Definition QwLog.cc:20
#define QwMessage
Predefined log drain for regular messages.
Definition QwLog.h:49
ROOT file and tree management wrapper classes.
EPICS data event handling and storage.
Decoding and management for VQWK ADC channels (6x32-bit datawords)
Event buffer management for reading and processing CODA data.
Helicity state management and pattern recognition.
Subsystem array container for parity analysis with asymmetry calculations.
Event ring buffer for burp detection and stability monitoring.
Beamline subsystem containing BPMs, BCMs, and other beam monitoring devices.
Fake helicity generator using pregenerated random seeds.
Load the options for the parity subsystems.
void DefineOptionsParity(QwOptions &options)
void LoadParameterFile(TString filename)
Load deltaA_q, no.of good patterns to accumulate and other neccessary feedback parameters.
void ApplyFeedbackCorrections()
Check neccessary conditions and apply IA setponts based on the charge asym for all four modes.
void ProcessOptions(QwOptions &options)
Process the configuration options.
static void DefineOptions(QwOptions &options)
Define the configuration options.
void CalculateAsymmetry()
inherited from QwHelicityPattern
EPICS slow controls data management.
Int_t LoadChannelMap(TString mapfile)
Event buffer management for reading and processing CODA data.
Int_t GetEventNumber()
void ReportRunSummary()
Int_t CloseStream()
Closes a currently open event stream.
Int_t OpenNextStream()
Opens the event stream (file or ET) based on the internal flags.
void ProcessOptions(QwOptions &options)
Sets internal flags based on the QwOptions.
Bool_t FillSubsystemData(QwSubsystemArray &subsystems)
Int_t GetRunNumber() const
Return CODA file run number.
Bool_t IsROCConfigurationEvent()
Bool_t IsPhysicsEvent()
Bool_t FillSubsystemConfigurationData(QwSubsystemArray &subsystems)
static std::ostream & endl(std::ostream &)
End of the line.
Definition QwLog.cc:297
static void AppendToSearchPath(const TString &searchdir)
Add a directory to the search path.
static void SetCurrentRunNumber(const UInt_t runnumber)
Set the current run number for looking up the appropriate parameter file.
void ProcessEvent()
Process the decoded data in this event.
void ProcessOptions(QwOptions &options)
Process configuration options (default behavior)
Ring buffer of subsystem snapshots for burp/stability handling.
Definition QwEventRing.h:28
QwSubsystemArrayParity & pop()
Return the last subsystem in the ring.
void push(QwSubsystemArrayParity &event)
Add the subsystem to the ring.
Bool_t IsReady()
Return the read status of the ring.
void UpdateBlinder()
Update the blinder status using a random number generator.
Bool_t IsCompletePattern() const
void LoadEventData(QwSubsystemArrayParity &event)
Subsystem array container specialized for parity analysis with asymmetry calculations.
void AccumulateRunningSum(const QwSubsystemArrayParity &value, Int_t count=0, Int_t ErrorMask=0xFFFFFFF)
Update the running sums for devices accumulated for the global error non-zero events/patterns.
Bool_t ApplySingleEventCuts()
Apply the single event cuts.