18#ifdef __USE_DATABASE__
47 QwError <<
"QwVQWK_Channel::GetBufferOffset: Invalid module index,"
49 <<
". Must be zero or greater."
52 QwError <<
"QwVQWK_Channel::GetBufferOffset: Invalid channel index,"
67 Bool_t fEventIsGood=kTRUE;
244 <<
" cannot set the default sample size."
285 Double_t drift = 0.0;
445 Long_t localbuf[6] = {0};
452 for (Int_t i = 0; i < 4; i++) {
462 for (Int_t i = 0; i < 6; i++){
463 buffer.push_back(localbuf[i]);
516 UInt_t words_read = 0;
529 localbuf[i] = buffer[i];
530 localbuf_signed[i] =
static_cast<Int_t
>(localbuf[i]);
553 std::cerr <<
"QwVQWK_Channel::ProcessEvBuffer: Not enough words!"
575 QwWarning <<
"QwVQWK_Channel::ProcessEvent: Channel "
577 <<
" has fNumberOfSamples==0 but has valid data in the hardware sum. "
578 <<
"Flag this as an error."
609 std::cout<<
"***************************************"<<
"\n";
611 std::cout<<
"Beam Instrument Type: "<<
GetModuleType()<<
"\n"<<
"\n";
613 std::cout<<
"fPedestal= "<<
fPedestal<<
"\n";
618 std::cout<<
"fBlock_raw ";
625 std::cout<<
"fBlock ";
627 std::cout <<
" : " <<std::setprecision(8) <<
fBlock[i];
628 std::cout << std::endl;
630 std::cout <<
"fHardwareBlockSum = "<<std::setprecision(8) <<
fHardwareBlockSum << std::endl;
640 if (folder != NULL) folder->cd();
751 TString basename = prefix(0, (prefix.First(
"|") >= 0)? prefix.First(
"|"): prefix.Length()) +
GetElementName();
782 values.
push_back(
"Device_Error_Code",
'i');
796 values.
push_back(
"sequence_number",
'i');
802 std::string leaf_list = values.
LeafList();
804 if (
gQwHists.MatchDeviceParamsFromList(basename.Data())
809 if (leaf_list ==
"hw_sum/D")
810 leaf_list = basename+
"/D";
819 std::cerr <<
"QwVQWK_Channel::ConstructBranchAndVector: fTreeArrayIndex==" <<
fTreeArrayIndex
821 <<
"; values.size()==" << values.
size()
822 <<
"; list==" << leaf_list
835 std::cerr <<
"QwVQWK_Channel::ConstructBranchAndVector: fTreeArrayIndex==" <<
fTreeArrayIndex
847 if (
bDEBUG) std::cerr <<
"QwVQWK_Channel::FillTreeVector: fTreeArrayNumEntries=="
850 if (
bDEBUG) std::cerr <<
"QwVQWK_Channel::FillTreeVector: values.size()=="
852 <<
"; fTreeArrayIndex+fTreeArrayNumEntries=="
904#ifdef HAS_RNTUPLE_SUPPORT
905void QwVQWK_Channel::ConstructNTupleAndVector(std::unique_ptr<ROOT::RNTupleModel>& model, TString &prefix, std::vector<Double_t>& values, std::vector<std::shared_ptr<Double_t>> &fieldPtrs)
930 TString basename = prefix(0, (prefix.First(
"|") >= 0)? prefix.First(
"|"): prefix.Length()) +
GetElementName();
936 values.push_back(0.0);
937 auto field = model->MakeField<Double_t>(basename.Data());
938 fieldPtrs.push_back(field);
947 values.push_back(0.0);
948 fieldPtrs.push_back(model->MakeField<Double_t>((basename +
"_hw_sum").Data()));
949 values.push_back(0.0);
950 fieldPtrs.push_back(model->MakeField<Double_t>((basename +
"_hw_sum_m2").Data()));
951 values.push_back(0.0);
952 fieldPtrs.push_back(model->MakeField<Double_t>((basename +
"_hw_sum_err").Data()));
957 values.push_back(0.0);
958 fieldPtrs.push_back(model->MakeField<Double_t>((basename + Form(
"_block%d", i)).Data()));
963 values.push_back(0.0);
964 fieldPtrs.push_back(model->MakeField<Double_t>((basename +
"_num_samples").Data()));
968 values.push_back(0.0);
969 fieldPtrs.push_back(model->MakeField<Double_t>((basename +
"_Device_Error_Code").Data()));
979 values.push_back(0.0);
980 auto field = model->MakeField<Double_t>(TString::Format(
"%s_hw_sum", basename.Data()).Data());
981 fieldPtrs.push_back(field);
985 values.push_back(0.0);
986 auto field = model->MakeField<Double_t>(TString::Format(
"%s_hw_sum_raw", basename.Data()).Data());
987 fieldPtrs.push_back(field);
992 values.push_back(0.0);
993 auto field = model->MakeField<Double_t>(TString::Format(
"%s_block%d", basename.Data(), i).Data());
994 fieldPtrs.push_back(field);
1000 values.push_back(0.0);
1001 auto field = model->MakeField<Double_t>(TString::Format(
"%s_block%d_raw", basename.Data(), i).Data());
1002 fieldPtrs.push_back(field);
1007 values.push_back(0.0);
1008 auto field = model->MakeField<Double_t>(TString::Format(
"%s_num_samples", basename.Data()).Data());
1009 fieldPtrs.push_back(field);
1013 values.push_back(0.0);
1014 auto field = model->MakeField<Double_t>(TString::Format(
"%s_Device_Error_Code", basename.Data()).Data());
1015 fieldPtrs.push_back(field);
1019 values.push_back(0.0);
1020 auto field = model->MakeField<Double_t>(TString::Format(
"%s_sequence_number", basename.Data()).Data());
1021 fieldPtrs.push_back(field);
1028 std::cerr <<
"QwVQWK_Channel::ConstructNTupleAndVector: fTreeArrayIndex==" <<
fTreeArrayIndex
1030 <<
"; values.size()==" << values.size()
1035void QwVQWK_Channel::FillNTupleVector(std::vector<Double_t>& values)
const
1040 if (
bDEBUG) std::cerr <<
"QwVQWK_Channel::FillNTupleVector: fTreeArrayNumEntries=="
1043 if (
bDEBUG) std::cerr <<
"QwVQWK_Channel::FillNTupleVector: values.size()=="
1045 <<
"; fTreeArrayIndex+fTreeArrayNumEntries=="
1128 if(
this ==&value)
return *
this;
1156 if(
this == &value)
return;
1180 TString loc=
"Standard exception from QwVQWK_Channel::AssignValueFrom = "
1182 throw std::invalid_argument(loc.Data());
1192 TString loc=
"Standard exception from QwVQWK_Channel::AddValueFrom = "
1194 throw std::invalid_argument(loc.Data());
1204 TString loc=
"Standard exception from QwVQWK_Channel::SubtractValueFrom = "
1206 throw std::invalid_argument(loc.Data());
1216 TString loc=
"Standard exception from QwVQWK_Channel::MultiplyBy = "
1218 throw std::invalid_argument(loc.Data());
1228 TString loc=
"Standard exception from QwVQWK_Channel::DivideBy = "
1230 throw std::invalid_argument(loc.Data());
1316 TString loc=
"Standard exception from QwVQWK_Channel::operator+= "
1319 throw(std::invalid_argument(loc.Data()));
1330 TString loc=
"Standard exception from QwVQWK_Channel::operator-= "
1333 throw(std::invalid_argument(loc.Data()));
1344 TString loc=
"Standard exception from QwVQWK_Channel::operator*= "
1347 throw(std::invalid_argument(loc.Data()));
1358 TString loc=
"Standard exception from QwVQWK_Channel::operator/= "
1361 throw(std::invalid_argument(loc.Data()));
1405 for (Int_t i = 0; i < 4; i++) {
1408 variance = ratio * ratio *
1413 }
else if (this->
fBlock[i] == 0.0) {
1417 QwVerbose <<
"Attempting to divide by zero block in "
1425 variance = ratio * ratio *
1434 QwVerbose <<
"Attempting to divide by zero sum in "
1633 }
else if (n2 == -1) {
1641 for (Int_t i = 0; i < 4; i++) {
1645 fBlock[i] -= (M12 - M11) / n;
1648 }
else if (n == 1) {
1655 for (Int_t i = 0; i < 4; i++) {
1659 fBlock[i] -= (M12 - M11) / n;
1661 if (fabs(
fBlockM2[i]) < 10.*std::numeric_limits<double>::epsilon())
1664 }
else if (n == 0) {
1672 for (Int_t i = 0; i < 4; i++) {
1678 if (fabs(
fBlock[i]) < 10.*std::numeric_limits<double>::epsilon())
1680 if (fabs(
fBlockM2[i]) < 10.*std::numeric_limits<double>::epsilon())
1686 }
else if (n2 == 1) {
1693 for (Int_t i = 0; i < 4; i++) {
1697 fBlock[i] += (M12 - M11) / n;
1700 }
else if (n2 > 1) {
1706 for (Int_t i = 0; i < 4; i++) {
1710 fBlock[i] += n2 * (M12 - M11) / n;
1711 fBlockM2[i] += M22 + n1 * n2 * (M12 - M11) * (M12 - M11) / n;
1765 << std::setw(12) << std::left <<
GetBlockValue(0) <<
" +/- "
1767 << std::setw(12) << std::left <<
GetBlockValue(1) <<
" +/- "
1769 << std::setw(12) << std::left <<
GetBlockValue(2) <<
" +/- "
1771 << std::setw(12) << std::left <<
GetBlockValue(3) <<
" +/- "
1835 Bool_t status = kTRUE;
1844 Bool_t status = kTRUE;
1849 std::cerr <<
"QwVQWK_Channel::MatchNumberOfSamples: Channel "
1852 <<
" and was supposed to have " << numsamp
1862 Bool_t status = kFALSE;
1915 message = Form(
"%30s",
"Device name");
1916 message += Form(
"%9s",
"HW Sat");
1917 message += Form(
"%9s",
"Sample");
1918 message += Form(
"%9s",
"SW_HW");
1919 message += Form(
"%9s",
"Sequence");
1920 message += Form(
"%9s",
"SameHW");
1921 message += Form(
"%9s",
"ZeroHW");
1922 message += Form(
"%9s",
"EventCut");
1923 QwMessage <<
"---------------------------------------------------------------------------------------------" <<
QwLog::endl;
1925 QwMessage <<
"---------------------------------------------------------------------------------------------" <<
QwLog::endl;
1931 QwMessage <<
"---------------------------------------------------------------------------------------------" <<
QwLog::endl;
1949 message +=
" >>>>> No Pedestal or Gain in map file";
1978 }
else if (input == NULL && value != NULL) {
1979 TString loc=
"Standard exception from QwVQWK_Channel::ScaledAdd "
1982 throw(std::invalid_argument(loc.Data()));
1986#ifdef __USE_DATABASE__
2048 row_list.push_back(row);
2054 row_list.push_back(row);
2060 row_list.push_back(row);
2067 row_list.push_back(row);
2074 row_list.push_back(row);
2080 row_list.push_back(row);
2087 row_list.push_back(row);
Physical units and constants for Qweak analysis.
Helper functions and utilities for ROOT histogram management.
QwHistogramHelper gQwHists
Globally defined instance of the QwHistogramHelper class.
A logfile class, based on an identical class in the Hermes analyzer.
#define QwVerbose
Predefined log drain for verbose messages.
#define QwError
Predefined log drain for errors.
#define QwWarning
Predefined log drain for warnings.
#define QwMessage
Predefined log drain for regular messages.
ROOT file and tree management wrapper classes.
Decoding and management for VQWK ADC channels (6x32-bit datawords)
static const UInt_t kBeamStabilityError
static const UInt_t kErrorFlag_ZeroHW
static const UInt_t kStabilityCut
static const UInt_t kErrorFlag_EventCut_L
static const UInt_t kErrorFlag_EventCut_U
static const UInt_t kErrorFlag_SW_HW
static const UInt_t kErrorFlag_sample
static const UInt_t kPreserveError
static const UInt_t kErrorFlag_VQWK_Sat
static const UInt_t kErrorFlag_SameHW
static const UInt_t kErrorFlag_Sequence
Database interface for QwIntegrationPMT and subsystems.
std::ostream & operator<<(std::ostream &stream, const QwVQWK_Channel &channel)
A class for blinding data, adapted from G0 blinder class.
static const double pi
Angles: base unit is radian.
std::vector< TH1_ptr > fHistograms
Histograms associated with this data element.
std::vector< Double_t > fMockDriftAmplitude
Harmonic drift amplitude.
std::vector< Double_t > fMockDriftFrequency
Harmonic drift frequency.
Double_t fMockAsymmetry
Helicity asymmetry.
bool fUseExternalRandomVariable
Flag to use an externally provided normal random variable.
Double_t fMockGaussianSigma
Sigma of normal distribution.
Double_t fMockGaussianMean
Mean of normal distribution.
std::vector< Double_t > fMockDriftPhase
Harmonic drift phase.
Double_t GetRandomValue()
void SetDeviceName(TString &in)
void SetErrorCodeId(UInt_t in)
static std::ostream & endl(std::ostream &)
End of the line.
Configuration file parser with flexible tokenization and search capabilities.
Bool_t ReturnValue(const std::string keyname, T &retvalue)
A helper class to manage a vector of branch entries for ROOT trees.
size_type size() const noexcept
std::string LeafList(size_type start_index=0) const
void push_back(const std::string &name, const char type='D')
void SetValue(size_type index, Double_t val)
Int_t fADC_Same_NumEvt
Keep track of how many events with same ADC value returned.
void SubtractValueFrom(const VQwHardwareChannel *valueptr) override
Double_t fBlockError[4]
Uncertainty on the sub-block.
QwVQWK_Channel & operator=(const QwVQWK_Channel &value)
void InitializeChannel(TString name, TString datatosave) override
Initialize the fields in this object.
Double_t GetHardwareSumM2() const
void Sum(const QwVQWK_Channel &value1, const QwVQWK_Channel &value2)
void SetRawEventData() override
Bool_t MatchNumberOfSamples(size_t numsamp)
Double_t GetVQWKSaturationLimt()
UInt_t fNumberOfSamples
Number of samples read through the module.
Int_t GetRawBlockValue(size_t blocknum) const
Int_t GetRawSoftwareSum() const
static void PrintErrorCounterTail()
Int_t fSequenceNo_Prev
Keep the sequence number of the last event.
void MultiplyBy(const VQwHardwareChannel *valueptr) override
void SetHardwareSum(Double_t hwsum, UInt_t sequencenumber=0)
Bool_t MatchSequenceNumber(size_t seqnum)
void ScaledAdd(Double_t scale, const VQwHardwareChannel *value) override
UInt_t fSequenceNumber
Event sequence number for this channel.
static const Bool_t kDEBUG
Bool_t bDevice_Error_Code
VQwHardwareChannel & operator/=(const VQwHardwareChannel &input) override
void ConstructHistograms(TDirectory *folder, TString &prefix) override
Construct the histograms for this data element.
Double_t GetHardwareSumWidth() const
void SetDefaultSampleSize(size_t num_samples_map)
void ClearEventData() override
Clear the event data in this element.
void CalculateRunningAverage() override
QwVQWK_Channel & operator*=(const QwVQWK_Channel &value)
const QwVQWK_Channel operator-(const QwVQWK_Channel &value) const
void LoadChannelParameters(QwParameterFile ¶mfile) override
Int_t fHardwareBlockSum_raw
Module-based sum of the four sub-blocks as read from the module.
void ConstructBranchAndVector(TTree *tree, TString &prefix, QwRootTreeBranchVector &values) override
void AddChannelOffset(Double_t Offset)
void PrintErrorCounters() const override
report number of events failed due to HW and event cut failure
void FillHistograms() override
Fill the histograms for this data element.
Int_t ProcessEvBuffer(UInt_t *buffer, UInt_t num_words_left, UInt_t index=0) override
Decode the event data from a CODA buffer.
void AccumulateRunningSum(const QwVQWK_Channel &value, Int_t count=0, Int_t ErrorMask=0xFFFFFFF)
void ConstructBranch(TTree *tree, TString &prefix) override
Int_t fSoftwareBlockSum_raw
Sum of the data in the four sub-blocks raw.
Double_t GetHardwareSumError() const
static Int_t GetBufferOffset(Int_t moduleindex, Int_t channelindex)
Int_t fErrorCount_ZeroHW
check to see ADC returning zero
Int_t fErrorCount_sample
for sample size check
QwVQWK_Channel & operator+=(const QwVQWK_Channel &value)
void RandomizeEventData(int helicity=0.0, double time=0.0) override
Internally generate random event data.
static const Bool_t bDEBUG
debugging display purposes
Double_t GetBlockErrorValue(size_t blocknum) const
Double_t GetHardwareSum() const
UInt_t fPreviousSequenceNumber
Previous event sequence number for this channel.
size_t GetSequenceNumber() const
Double_t fHardwareBlockSumError
Uncertainty on the hardware sum.
void ProcessEvent() override
Process the event data according to pedestal and calibration factor.
void SmearByResolution(double resolution) override
static const Int_t kWordsPerChannel
Int_t fErrorCount_Sequence
sequence number check
void FillTreeVector(QwRootTreeBranchVector &values) const override
void AssignValueFrom(const VQwDataElement *valueptr) override
UInt_t fNumberOfSamples_map
Number of samples in the expected to read through the module. This value is set in the QwBeamline map...
QwVQWK_Channel & operator-=(const QwVQWK_Channel &value)
void Ratio(const QwVQWK_Channel &numer, const QwVQWK_Channel &denom)
void Difference(const QwVQWK_Channel &value1, const QwVQWK_Channel &value2)
void AddValueFrom(const VQwHardwareChannel *valueptr) override
const QwVQWK_Channel operator+(const QwVQWK_Channel &value) const
void PrintValue() const override
Print single line of value and error of this data element.
Int_t ApplyHWChecks() override
Double_t fPrev_HardwareBlockSum
Previous Module-based sum of the four sub-blocks.
void PrintInfo() const override
Print multiple lines of information about this data element.
Double_t GetAverageVolts() const
void Blind(const QwBlinder *blinder)
Blind this channel as an asymmetry.
static const Double_t kTimePerSample
static const Double_t kVQWK_VoltsPerBit
void DivideBy(const VQwHardwareChannel *valueptr) override
void Product(const QwVQWK_Channel &value1, const QwVQWK_Channel &value2)
Int_t fErrorCount_SameHW
check to see ADC returning same HW value
Double_t fBlock[4]
Array of the sub-block data.
Double_t GetValueWidth() const
void SetEventData(Double_t *block, UInt_t sequencenumber=0)
static const Int_t kMaxChannels
Bool_t ApplySingleEventCuts() override
const QwVQWK_Channel operator*(const QwVQWK_Channel &value) const
void AssignScaledValue(const QwVQWK_Channel &value, Double_t scale)
Double_t fBlockM2[4]
Second moment of the sub-block.
void IncrementErrorCounters() override
Int_t fBlock_raw[4]
Array of the sub-block data as read from the module.
void Scale(Double_t Offset) override
Double_t fHardwareBlockSum
Module-based sum of the four sub-blocks.
void EncodeEventData(std::vector< UInt_t > &buffer) override
Encode the event data into a CODA buffer.
void ArcTan(const QwVQWK_Channel &value)
Int_t fErrorCount_HWSat
check to see ADC channel is saturated
Double_t GetBlockValue(size_t blocknum) const
Int_t fErrorCount_SW_HW
HW_sum==SW_sum check.
Int_t fSequenceNo_Counter
Internal counter to keep track of the sequence number.
Int_t GetRawHardwareSum() const
Double_t fHardwareBlockSumM2
Second moment of the hardware sum.
size_t GetNumberOfSamples() const
static void PrintErrorCounterHead()
Int_t fNumEvtsWithEventCutsRejected
Counts the Event cut rejected events.
UInt_t fGoodEventCount
Number of good events accumulated in this element.
VQwDataElement()
Default constructor.
UInt_t fErrorConfigFlag
contains the global/local/stability flags
void SetSubsystemName(TString sysname)
Set the name of the inheriting subsystem name.
virtual const TString & GetElementName() const
Get the name of this element.
UInt_t fErrorFlag
This the standard error code generated for the channel that contains the global/local/stability flags...
void SetElementName(const TString &name)
Set the name of this element.
Bool_t IsNameEmpty() const
Is the name of this element empty?
TString GetSubsystemName() const
Return the name of the inheriting subsystem name.
UInt_t GetGoodEventCount() const
TString GetModuleType() const
Return the type of the beam instrument.
void SetModuleType(TString ModuleType)
set the type of the beam instrument
void SetDataToSave(TString datatosave)
Set the flag indicating if raw or derived values are in this data element.
Double_t fCalibrationFactor
void SetNumberOfSubElements(const size_t elements)
Set the number of data words in this data element.
size_t fTreeArrayNumEntries
VQwHardwareChannel & operator=(const VQwHardwareChannel &value)
Arithmetic assignment operator: Should only copy event-based data.
void SetNumberOfDataWords(const UInt_t &numwords)
Set the number of data words in this data element.
virtual void AddErrEntriesToList(std::vector< QwErrDBInterface > &)
UInt_t fNumberOfDataWords
Number of raw data words in this data element.
void SetDataToSaveByPrefix(const TString &prefix)
Set the flag indicating if raw or derived values are in this data element based on prefix.
Data blinding utilities for parity violation analysis.
const Bool_t & IsBlinderOkay() const
void ModifyThisErrorCode(UInt_t &errorcode) const
void BlindValue(Double_t &value) const
Asymmetry blinding.
static constexpr const Double_t kValue_BlinderFail