JAPAn
Just Another Parity Analyzer
Loading...
Searching...
No Matches
QwFeedback.cc File Reference

main(...) function for the qwanalysis feedback executable to set IA and/or PITA slopes More...

#include <iostream>
#include <fstream>
#include <vector>
#include <new>
#include <boost/shared_ptr.hpp>
#include "QwLog.h"
#include "QwRootFile.h"
#include "QwOptionsParity.h"
#include "QwEventBuffer.h"
#include "QwHistogramHelper.h"
#include "QwSubsystemArrayParity.h"
#include "QwHelicityCorrelatedFeedback.h"
#include "QwEventRing.h"
#include "QwEPICSEvent.h"
#include "QwHelicity.h"
#include "QwFakeHelicity.h"
#include "QwBeamLine.h"
#include "QwVQWK_Channel.h"
+ Include dependency graph for QwFeedback.cc:

Go to the source code of this file.

Functions

Int_t main (Int_t argc, Char_t *argv[])
 

Detailed Description

main(...) function for the qwanalysis feedback executable to set IA and/or PITA slopes

Definition in file QwFeedback.cc.

Function Documentation

◆ main()

Int_t main ( Int_t argc,
Char_t * argv[] )

First, fill the search paths for the parameter files; this sets a static variable within the QwParameterFile class which will be used by all instances. The "scratch" directory should be first.

Setup screen and file logging

Load the histogram parameter definitions (from parity_hists.txt) into the global histogram helper: QwHistogramHelper

Create the event buffer

Create the database connection

Start loop over all runs

Set the current event number for parameter file lookup

Create an EPICS event

Load the detectors from file

Create the helicity pattern

Create the event ring with the subsysten array

Create the running sum

Definition at line 42 of file QwFeedback.cc.

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}
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
QwLog gQwLog
Definition QwLog.cc:20
#define QwMessage
Predefined log drain for regular messages.
Definition QwLog.h:49
void DefineOptionsParity(QwOptions &options)
static void DefineOptions(QwOptions &options)
Define the configuration options.
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.
Ring buffer of subsystem snapshots for burp/stability handling.
Definition QwEventRing.h:28
Subsystem array container specialized for parity analysis with asymmetry calculations.

References QwSubsystemArrayParity::AccumulateRunningSum(), QwParameterFile::AppendToSearchPath(), QwHelicityCorrelatedFeedback::ApplyFeedbackCorrections(), QwSubsystemArrayParity::ApplySingleEventCuts(), QwHelicityCorrelatedFeedback::CalculateAsymmetry(), QwHelicityPattern::ClearEventData(), QwSubsystemArray::ClearEventData(), QwHelicityCorrelatedFeedback::ClearRunningSum(), QwEventBuffer::CloseStream(), QwHelicityCorrelatedFeedback::DefineOptions(), DefineOptionsParity(), QwLog::endl(), QwEventBuffer::FillSubsystemConfigurationData(), QwEventBuffer::FillSubsystemData(), getenv_safe_string(), QwEventBuffer::GetEventNumber(), QwEventBuffer::GetNextEvent(), QwEventBuffer::GetRunNumber(), gQwHists, gQwLog, gQwOptions, QwHelicityPattern::IsCompletePattern(), QwHelicityPattern::IsGoodAsymmetry(), QwEventBuffer::IsPhysicsEvent(), QwEventRing::IsReady(), QwEventBuffer::IsROCConfigurationEvent(), QwEPICSEvent::LoadChannelMap(), QwHelicityPattern::LoadEventData(), QwHelicityCorrelatedFeedback::LoadParameterFile(), QwEventBuffer::OpenNextStream(), QwEventRing::pop(), QwEventBuffer::PrintRunTimes(), QwSubsystemArray::ProcessEvent(), QwEventBuffer::ProcessOptions(), QwHelicityCorrelatedFeedback::ProcessOptions(), QwSubsystemArray::ProcessOptions(), QwEventRing::push(), QwMessage, QwEventBuffer::ReportRunSummary(), QwParameterFile::SetCurrentRunNumber(), and QwHelicityPattern::UpdateBlinder().

+ Here is the call graph for this function: