17#ifdef __USE_DATABASE__
46 QwError <<
"QwVQWK_Channel::GetBufferOffset: Invalid module index,"
48 <<
". Must be zero or greater."
51 QwError <<
"QwVQWK_Channel::GetBufferOffset: Invalid channel index,"
66 Bool_t fEventIsGood=kTRUE;
243 <<
" cannot set the default sample size."
284 Double_t drift = 0.0;
444 Long_t localbuf[6] = {0};
451 for (Int_t i = 0; i < 4; i++) {
461 for (Int_t i = 0; i < 6; i++){
462 buffer.push_back(localbuf[i]);
515 UInt_t words_read = 0;
528 localbuf[i] = buffer[i];
529 localbuf_signed[i] =
static_cast<Int_t
>(localbuf[i]);
552 std::cerr <<
"QwVQWK_Channel::ProcessEvBuffer: Not enough words!"
574 QwWarning <<
"QwVQWK_Channel::ProcessEvent: Channel "
576 <<
" has fNumberOfSamples==0 but has valid data in the hardware sum. "
577 <<
"Flag this as an error."
608 std::cout<<
"***************************************"<<
"\n";
610 std::cout<<
"Beam Instrument Type: "<<
GetModuleType()<<
"\n"<<
"\n";
612 std::cout<<
"fPedestal= "<<
fPedestal<<
"\n";
617 std::cout<<
"fBlock_raw ";
624 std::cout<<
"fBlock ";
626 std::cout <<
" : " <<std::setprecision(8) <<
fBlock[i];
627 std::cout << std::endl;
629 std::cout <<
"fHardwareBlockSum = "<<std::setprecision(8) <<
fHardwareBlockSum << std::endl;
639 if (folder != NULL) folder->cd();
750 TString basename = prefix(0, (prefix.First(
"|") >= 0)? prefix.First(
"|"): prefix.Length()) +
GetElementName();
781 values.
push_back(
"Device_Error_Code",
'i');
795 values.
push_back(
"sequence_number",
'i');
801 std::string leaf_list = values.
LeafList();
803 if (
gQwHists.MatchDeviceParamsFromList(basename.Data())
808 if (leaf_list ==
"hw_sum/D")
809 leaf_list = basename+
"/D";
818 std::cerr <<
"QwVQWK_Channel::ConstructBranchAndVector: fTreeArrayIndex==" <<
fTreeArrayIndex
820 <<
"; values.size()==" << values.
size()
821 <<
"; list==" << leaf_list
834 std::cerr <<
"QwVQWK_Channel::ConstructBranchAndVector: fTreeArrayIndex==" <<
fTreeArrayIndex
846 if (
bDEBUG) std::cerr <<
"QwVQWK_Channel::FillTreeVector: fTreeArrayNumEntries=="
849 if (
bDEBUG) std::cerr <<
"QwVQWK_Channel::FillTreeVector: values.size()=="
851 <<
"; fTreeArrayIndex+fTreeArrayNumEntries=="
903#ifdef HAS_RNTUPLE_SUPPORT
904void QwVQWK_Channel::ConstructNTupleAndVector(std::unique_ptr<ROOT::RNTupleModel>& model, TString &prefix, std::vector<Double_t>& values, std::vector<std::shared_ptr<Double_t>> &fieldPtrs)
929 TString basename = prefix(0, (prefix.First(
"|") >= 0)? prefix.First(
"|"): prefix.Length()) +
GetElementName();
935 values.push_back(0.0);
936 auto field = model->MakeField<Double_t>(basename.Data());
937 fieldPtrs.push_back(field);
946 values.push_back(0.0);
947 fieldPtrs.push_back(model->MakeField<Double_t>((basename +
"_hw_sum").Data()));
948 values.push_back(0.0);
949 fieldPtrs.push_back(model->MakeField<Double_t>((basename +
"_hw_sum_m2").Data()));
950 values.push_back(0.0);
951 fieldPtrs.push_back(model->MakeField<Double_t>((basename +
"_hw_sum_err").Data()));
956 values.push_back(0.0);
957 fieldPtrs.push_back(model->MakeField<Double_t>((basename + Form(
"_block%d", i)).Data()));
962 values.push_back(0.0);
963 fieldPtrs.push_back(model->MakeField<Double_t>((basename +
"_num_samples").Data()));
967 values.push_back(0.0);
968 fieldPtrs.push_back(model->MakeField<Double_t>((basename +
"_Device_Error_Code").Data()));
978 values.push_back(0.0);
979 auto field = model->MakeField<Double_t>(TString::Format(
"%s_hw_sum", basename.Data()).Data());
980 fieldPtrs.push_back(field);
984 values.push_back(0.0);
985 auto field = model->MakeField<Double_t>(TString::Format(
"%s_hw_sum_raw", basename.Data()).Data());
986 fieldPtrs.push_back(field);
991 values.push_back(0.0);
992 auto field = model->MakeField<Double_t>(TString::Format(
"%s_block%d", basename.Data(), i).Data());
993 fieldPtrs.push_back(field);
999 values.push_back(0.0);
1000 auto field = model->MakeField<Double_t>(TString::Format(
"%s_block%d_raw", basename.Data(), i).Data());
1001 fieldPtrs.push_back(field);
1006 values.push_back(0.0);
1007 auto field = model->MakeField<Double_t>(TString::Format(
"%s_num_samples", basename.Data()).Data());
1008 fieldPtrs.push_back(field);
1012 values.push_back(0.0);
1013 auto field = model->MakeField<Double_t>(TString::Format(
"%s_Device_Error_Code", basename.Data()).Data());
1014 fieldPtrs.push_back(field);
1018 values.push_back(0.0);
1019 auto field = model->MakeField<Double_t>(TString::Format(
"%s_sequence_number", basename.Data()).Data());
1020 fieldPtrs.push_back(field);
1027 std::cerr <<
"QwVQWK_Channel::ConstructNTupleAndVector: fTreeArrayIndex==" <<
fTreeArrayIndex
1029 <<
"; values.size()==" << values.size()
1034void QwVQWK_Channel::FillNTupleVector(std::vector<Double_t>& values)
const
1039 if (
bDEBUG) std::cerr <<
"QwVQWK_Channel::FillNTupleVector: fTreeArrayNumEntries=="
1042 if (
bDEBUG) std::cerr <<
"QwVQWK_Channel::FillNTupleVector: values.size()=="
1044 <<
"; fTreeArrayIndex+fTreeArrayNumEntries=="
1127 if(
this ==&value)
return *
this;
1155 if(
this == &value)
return;
1179 TString loc=
"Standard exception from QwVQWK_Channel::AssignValueFrom = "
1181 throw std::invalid_argument(loc.Data());
1191 TString loc=
"Standard exception from QwVQWK_Channel::AddValueFrom = "
1193 throw std::invalid_argument(loc.Data());
1203 TString loc=
"Standard exception from QwVQWK_Channel::SubtractValueFrom = "
1205 throw std::invalid_argument(loc.Data());
1215 TString loc=
"Standard exception from QwVQWK_Channel::MultiplyBy = "
1217 throw std::invalid_argument(loc.Data());
1227 TString loc=
"Standard exception from QwVQWK_Channel::DivideBy = "
1229 throw std::invalid_argument(loc.Data());
1315 TString loc=
"Standard exception from QwVQWK_Channel::operator+= "
1318 throw(std::invalid_argument(loc.Data()));
1329 TString loc=
"Standard exception from QwVQWK_Channel::operator-= "
1332 throw(std::invalid_argument(loc.Data()));
1343 TString loc=
"Standard exception from QwVQWK_Channel::operator*= "
1346 throw(std::invalid_argument(loc.Data()));
1357 TString loc=
"Standard exception from QwVQWK_Channel::operator/= "
1360 throw(std::invalid_argument(loc.Data()));
1404 for (Int_t i = 0; i < 4; i++) {
1407 variance = ratio * ratio *
1412 }
else if (this->
fBlock[i] == 0.0) {
1416 QwVerbose <<
"Attempting to divide by zero block in "
1424 variance = ratio * ratio *
1433 QwVerbose <<
"Attempting to divide by zero sum in "
1632 }
else if (n2 == -1) {
1640 for (Int_t i = 0; i < 4; i++) {
1644 fBlock[i] -= (M12 - M11) / n;
1647 }
else if (n == 1) {
1654 for (Int_t i = 0; i < 4; i++) {
1658 fBlock[i] -= (M12 - M11) / n;
1660 if (fabs(
fBlockM2[i]) < 10.*std::numeric_limits<double>::epsilon())
1663 }
else if (n == 0) {
1671 for (Int_t i = 0; i < 4; i++) {
1677 if (fabs(
fBlock[i]) < 10.*std::numeric_limits<double>::epsilon())
1679 if (fabs(
fBlockM2[i]) < 10.*std::numeric_limits<double>::epsilon())
1685 }
else if (n2 == 1) {
1692 for (Int_t i = 0; i < 4; i++) {
1696 fBlock[i] += (M12 - M11) / n;
1699 }
else if (n2 > 1) {
1705 for (Int_t i = 0; i < 4; i++) {
1709 fBlock[i] += n2 * (M12 - M11) / n;
1710 fBlockM2[i] += M22 + n1 * n2 * (M12 - M11) * (M12 - M11) / n;
1764 << std::setw(12) << std::left <<
GetBlockValue(0) <<
" +/- "
1766 << std::setw(12) << std::left <<
GetBlockValue(1) <<
" +/- "
1768 << std::setw(12) << std::left <<
GetBlockValue(2) <<
" +/- "
1770 << std::setw(12) << std::left <<
GetBlockValue(3) <<
" +/- "
1834 Bool_t status = kTRUE;
1843 Bool_t status = kTRUE;
1848 std::cerr <<
"QwVQWK_Channel::MatchNumberOfSamples: Channel "
1851 <<
" and was supposed to have " << numsamp
1861 Bool_t status = kFALSE;
1914 message = Form(
"%30s",
"Device name");
1915 message += Form(
"%9s",
"HW Sat");
1916 message += Form(
"%9s",
"Sample");
1917 message += Form(
"%9s",
"SW_HW");
1918 message += Form(
"%9s",
"Sequence");
1919 message += Form(
"%9s",
"SameHW");
1920 message += Form(
"%9s",
"ZeroHW");
1921 message += Form(
"%9s",
"EventCut");
1922 QwMessage <<
"---------------------------------------------------------------------------------------------" <<
QwLog::endl;
1924 QwMessage <<
"---------------------------------------------------------------------------------------------" <<
QwLog::endl;
1930 QwMessage <<
"---------------------------------------------------------------------------------------------" <<
QwLog::endl;
1948 message +=
" >>>>> No Pedestal or Gain in map file";
1977 }
else if (input == NULL && value != NULL) {
1978 TString loc=
"Standard exception from QwVQWK_Channel::ScaledAdd "
1981 throw(std::invalid_argument(loc.Data()));
1985#ifdef __USE_DATABASE__
2047 row_list.push_back(row);
2053 row_list.push_back(row);
2059 row_list.push_back(row);
2066 row_list.push_back(row);
2073 row_list.push_back(row);
2079 row_list.push_back(row);
2086 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