JAPAn
Just Another Parity Analyzer
Loading...
Searching...
No Matches
QwHelicityPattern.h
Go to the documentation of this file.
1/*!
2 * \file QwHelicityPattern.h
3 * \brief Helicity pattern analysis and management
4 * \author P. M. King
5 * \date 2007-05-08
6 */
7
8#pragma once
9
10// System headers
11#include <vector>
12#include <iostream>
13#include <fstream>
14
15// ROOT headers
16#include <TTree.h>
17#ifdef HAS_RNTUPLE_SUPPORT
18#include "ROOT/RNTupleModel.hxx"
19#include "ROOT/RField.hxx"
20#endif // HAS_RNTUPLE_SUPPORT
21
22// Qweak headers
24#include "QwEPICSEvent.h"
25#include "QwBlinder.h"
26
27// Forward declarations
28class QwHelicity;
29
30///
31/// \ingroup QwAnalysis_ADC
32///
33/// \ingroup QwAnalysis_BL
34/**
35 * \class QwHelicityPattern
36 * \ingroup QwAnalysis_BL
37 * \brief Manages yields/differences/asymmetries for helicity patterns
38 *
39 * Aggregates per-window subsystem arrays into pairs and patterns, supports
40 * burst and running sums, and integrates with the blinder strategy.
41 */
43 /******************************************************************
44 * Class: QwHelicityPattern
45 *
46 *
47 ******************************************************************/
48 private:
49 /// Private default constructor (not implemented, will throw linker error on use)
51 public:
52 /// Constructor with subsystem array
53 QwHelicityPattern(QwSubsystemArrayParity &event, const TString &run = "0");
54 /// \brief Copy constructor by reference
56 /// Virtual destructor
57 virtual ~QwHelicityPattern() { };
58
59 /// \brief Define the configuration options
60 static void DefineOptions(QwOptions &options);
61 /// \brief Process the configuration options
62 void ProcessOptions(QwOptions &options);
63
65 Bool_t HasDataLoaded() const { return fIsDataLoaded; };
66
67 Bool_t PairAsymmetryIsGood();
68 Bool_t NextPairIsComplete();
71 fPairYield.ClearEventData();
72 fPairDifference.ClearEventData();
73 fPairAsymmetry.ClearEventData();
74 }
75
76 Bool_t IsCompletePattern() const;
77
78 void PrintIndexMapFile(Int_t runNum){
80 // Print a text map file to max_burst_index.####.conf
81 Int_t maxBurst = 0;
82 if (fBurstCounter==0) {
83 // It's a single burst run anyway
84 maxBurst = 0;
85 }
86 else {
87 // It's a multi burst run and we want to merge the final two bursts
88 maxBurst = fBurstCounter-1;
89 }
90 QwWarning << "Printing max_burst_index." << runNum << ".conf file with " << maxBurst << " max burst number" << QwLog::endl;
91 std::ofstream output;
92 output.open(Form("max_burst_index.%d.conf",runNum));
93 output<< "max-burst-index=" << maxBurst << std::endl; // Print the current index before incrementing further, this will be the max index and the next pass will overflow this one instead of having another
94 output.close();
95 }
96 }
97
98 Bool_t IsEndOfBurst(){
99 // Is this the end of a burst? And is this not the final burst?
101 }
102
103 void CalculateAsymmetry();
104 void GetTargetChargeStat(Double_t & asym, Double_t & error, Double_t & width);//retrieves the target charge asymmetry,asymmetry error ,asymmetry width
105
106 /// Enable/disable alternate asymmetry calculation
107 void EnableAlternateAsymmetry(const Bool_t flag = kTRUE) { fEnableAlternateAsym = flag; };
108 /// Disable alternate asymmetry calculation
110 /// Status of alternate asymmetry calculation flag
112
113 /// Enable/disable burst sum calculation
114 void EnableBurstSum(const Bool_t flag = kTRUE) { fEnableBurstSum = flag; };
115 /// Disable burst sum calculation
116 void DisableBurstSum() { fEnableBurstSum = kFALSE; };
117 /// Status of burst sum calculation flag
118 Bool_t IsBurstSumEnabled() { return fEnableBurstSum; };
119
120 /// Enable/disable running sum calculation
121 void EnableRunningSum(const Bool_t flag = kTRUE) { fEnableRunningSum = flag; };
122 /// Disable running sum calculation
124 /// Status of running sum calculation flag
126
127 /// Enable/disable storing pattern differences
128 void EnableDifference(const Bool_t flag = kTRUE) { fEnableDifference = flag; };
129 /// Disable storing pattern differences
131 /// Status of storing pattern differences flag
133
134 /// Enable/disable storing pair differences
135 void EnablePairs(const Bool_t flag = kTRUE) { fEnablePairs = flag; };
136 /// Disable storing pair differences
137 void DisablePairs() { fEnablePairs = kFALSE; };
138 /// Status of storing pair differences flag
139 Bool_t IsPairsEnabled() { return fEnablePairs; };
140
141#ifdef __USE_DATABASE__
142 /// Update the blinder status with new external information
143 void UpdateBlinder(QwParityDB* db){
144 fBlinder.Update(db);
145 };
146#endif
147 /// Update the blinder status using a random number generator
149 fBlinder.Update();
150 };
151 /// Update the blinder status with new external information
152 void UpdateBlinder(const QwSubsystemArrayParity& detectors) {
153 fBlinder.Update(detectors);
154 };
155 /// Update the blinder status with new external information
156 void UpdateBlinder(const QwEPICSEvent& epics) {
157 fBlinder.Update(epics);
158 };
159
160 // wish these could be const references, but ConstructBranchAndVector messes with object
164
165 // wish these could be const references, but ConstructBranchAndVector messes with object
169
170 void AccumulateRunningSum(QwHelicityPattern &entry, Int_t count=0, Int_t ErrorMask=0xFFFFFFF);
172
174
175 void PrintValue() const;
176
177 void ConstructObjects(){ConstructObjects((TDirectory*)NULL);};
178 void ConstructObjects(TDirectory *folder);
179
180 void ConstructHistograms(){ConstructHistograms((TDirectory*)NULL);};
181 void ConstructHistograms(TDirectory *folder);
182 void FillHistograms();
183
184 void ConstructBranchAndVector(TTree *tree, TString &prefix, QwRootTreeBranchVector &values);
185 void ConstructBranch(TTree *tree, TString &prefix);
186 void ConstructBranch(TTree *tree, TString &prefix, QwParameterFile &trim_tree);
187 void FillTreeVector(QwRootTreeBranchVector &values) const;
188
189#ifdef HAS_RNTUPLE_SUPPORT
190 // RNTuple methods
191 void ConstructNTupleAndVector(std::unique_ptr<ROOT::RNTupleModel>& model, TString& prefix, std::vector<Double_t>& values, std::vector<std::shared_ptr<Double_t>>& fieldPtrs);
192 void FillNTupleVector(std::vector<Double_t>& values) const;
193#endif // HAS_RNTUPLE_SUPPORT
194
195#ifdef __USE_DATABASE__
196 void FillDB(QwParityDB *db);
197 void FillErrDB(QwParityDB *db);
198#endif
199
201
202 Bool_t IsGoodAsymmetry();
203 UInt_t GetEventcutErrorFlag() const {
204 return fAsymmetry.GetEventcutErrorFlag();
205 };
206 const UInt_t* GetEventcutErrorFlagPointer() const {
207 return fAsymmetry.GetEventcutErrorFlagPointer();
208 };
209
210 Bool_t HasBurstData(){return fGoodPatterns>0;};
214 }
215 // Else we just park here and don't try to increment any more. This is a parameter from command line or map file
216 }
217 Short_t GetBurstCounter() const {return fBurstCounter;}
218 void ClearEventData();
219
220 void Print() const;
221
222 protected:
223
224 std::vector<QwSubsystemArrayParity> fEvents;
225 std::vector<Bool_t> fEventLoaded;
226 std::vector<Int_t> fHelicity;// this is here up to when we code the Helicity decoding routine
227 std::vector<Int_t> fEventNumber;
231
232 // Blinding strategy
234
235 /// This indicates if the subsystem arrays are missing the helicity object.
236 /// It is updated once during initialization and once when processing the first event
238 /// This is true if any of the helicity objects of this pattern have indicated that
239 /// we should ignore the helicity. It is updated every event and reset by ClearEventData.
241
242 // Yield and asymmetry of a single helicity pattern
246 // Alternate asymmetry calculations
250
251 // Yield and asymmetry of a single helicity pair
256
257 // Burst sum/difference of the yield and asymmetry
266
267 // Running sum/average of the yield and asymmetry
270
275
279
280 size_t fNextPair;
282
284
285 TString run_label;
286
287 // Flag to indicate that the pattern contains data
289 void SetDataLoaded(Bool_t flag) { fIsDataLoaded = flag; };
290
291 friend class QwDataHandlerArray;
292};
#define QwWarning
Predefined log drain for warnings.
Definition QwLog.h:44
EPICS data event handling and storage.
Subsystem array container for parity analysis with asymmetry calculations.
A class for blinding data, adapted from G0 blinder class.
EPICS slow controls data management.
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
Configuration file parser with flexible tokenization and search capabilities.
A helper class to manage a vector of branch entries for ROOT trees.
Definition QwRootFile.h:53
Data blinding utilities for parity violation analysis.
Definition QwBlinder.h:57
void Update()
Update the status using a random number.
Definition QwBlinder.cc:276
Subsystem for helicity state management and pattern recognition.
Definition QwHelicity.h:52
Manages yields/differences/asymmetries for helicity patterns.
QwSubsystemArrayParity fAlternateDiff
Bool_t IsPairsEnabled()
Status of storing pair differences flag.
QwSubsystemArrayParity & GetPairYield()
void EnableAlternateAsymmetry(const Bool_t flag=kTRUE)
Enable/disable alternate asymmetry calculation.
void DisableRunningSum()
Disable running sum calculation.
void ConstructBranchAndVector(TTree *tree, TString &prefix, QwRootTreeBranchVector &values)
void EnablePairs(const Bool_t flag=kTRUE)
Enable/disable storing pair differences.
QwSubsystemArrayParity & GetDifference()
void DisablePairs()
Disable storing pair differences.
void ConstructBranch(TTree *tree, TString &prefix)
QwSubsystemArrayParity fNegativeHelicitySum
void GetTargetChargeStat(Double_t &asym, Double_t &error, Double_t &width)
QwSubsystemArrayParity fPairDifference
QwSubsystemArrayParity & GetYield()
std::vector< Bool_t > fEventLoaded
QwHelicityPattern()
Private default constructor (not implemented, will throw linker error on use)
static void DefineOptions(QwOptions &options)
Define the configuration options.
QwSubsystemArrayParity fDifference
UInt_t GetEventcutErrorFlag() const
Bool_t IsRunningSumEnabled()
Status of running sum calculation flag.
QwSubsystemArrayParity fPairYield
void UpdateBlinder()
Update the blinder status using a random number generator.
void DisableAlternateAsymmetry()
Disable alternate asymmetry calculation.
std::vector< QwSubsystemArrayParity > fEvents
void ProcessOptions(QwOptions &options)
Process the configuration options.
Bool_t IsBurstSumEnabled()
Status of burst sum calculation flag.
Bool_t IsCompletePattern() const
void DisableBurstSum()
Disable burst sum calculation.
std::vector< Int_t > fHelicity
void AccumulatePairRunningSum(QwHelicityPattern &entry)
QwSubsystemArrayParity & GetPairAsymmetry()
void EnableBurstSum(const Bool_t flag=kTRUE)
Enable/disable burst sum calculation.
std::vector< Int_t > fEventNumber
Short_t GetBurstCounter() const
Bool_t IsAlternateAsymEnabled()
Status of alternate asymmetry calculation flag.
virtual ~QwHelicityPattern()
Virtual destructor.
void UpdateBlinder(const QwEPICSEvent &epics)
Update the blinder status with new external information.
QwSubsystemArrayParity & GetPairDifference()
friend class QwDataHandlerArray
void SetDataLoaded(Bool_t flag)
void WritePromptSummary(QwPromptSummary *ps)
QwSubsystemArrayParity fAsymmetry1
Bool_t IsDifferenceEnabled()
Status of storing pattern differences flag.
void FillTreeVector(QwRootTreeBranchVector &values) const
void UpdateBlinder(const QwSubsystemArrayParity &detectors)
Update the blinder status with new external information.
void EnableRunningSum(const Bool_t flag=kTRUE)
Enable/disable running sum calculation.
QwSubsystemArrayParity fPositiveHelicitySum
void PrintIndexMapFile(Int_t runNum)
void LoadEventData(QwSubsystemArrayParity &event)
void AccumulateRunningSum(QwHelicityPattern &entry, Int_t count=0, Int_t ErrorMask=0xFFFFFFF)
void DisableDifference()
Disable storing pattern differences.
QwSubsystemArrayParity fYield
QwSubsystemArrayParity & GetAsymmetry()
QwSubsystemArrayParity fAsymmetry
Bool_t HasDataLoaded() const
QwSubsystemArrayParity fPairAsymmetry
void EnableDifference(const Bool_t flag=kTRUE)
Enable/disable storing pattern differences.
const UInt_t * GetEventcutErrorFlagPointer() const
QwSubsystemArrayParity fAsymmetry2
Subsystem array container specialized for parity analysis with asymmetry calculations.