20#ifdef __USE_DATABASE__
66 QwError <<
"QwADC18_Channel::GetBufferOffset: Invalid module index,"
68 <<
". Must be zero or greater."
70 }
else if (channelindex<-1 || channelindex>
kMaxChannels){
71 QwError <<
"QwADC18_Channel::GetBufferOffset: Invalid channel index,"
76 if (channelindex == -1) {
228 <<
" cannot set the default sample size."
251 Double_t drift = 0.0;
304 localbuf[0] |=
mask31x & (0 << 31);
307 UInt_t exp_dtype = 1;
324 buffer.push_back(localbuf[i]);
330 return ((rawd &
mask31x) != 0);
336 UInt_t act_dtype = (rawd &
mask2422x) >> 22;
338 UInt_t act_chan = (act_dtype != 4) ?
340 UInt_t act_dvalue = (rawd &
mask2625x) >> 25;
341 UInt_t act_snum = (act_dtype == 1 || act_dtype == 2) ?
345 UInt_t value_raw = 0;
348 static UInt_t prev_dvalue = act_dvalue;
349 if (act_dvalue != prev_dvalue) {
350 QwError <<
"QwADC18_Channel::ProcessEvBuffer: Number of samples changed " << act_dvalue <<
" " << prev_dvalue <<
QwLog::endl;
354 if (rawd &
mask21x) value_raw = -((~value_raw & 0x1fffffff) + 1);
364 if (act_dvalue != 0) {
365 QwError <<
"QwADC18_Channel::ProcessEvBuffer: Divider value non-zero 0x" << std::hex << rawd << std::dec <<
QwLog::endl;
371 if (act_dvalue != 0) {
372 QwError <<
"QwADC18_Channel::ProcessEvBuffer: Divider value non-zero 0x" << std::hex << rawd << std::dec <<
QwLog::endl;
378 QwError <<
"QwADC18_Channel::ProcessEvBuffer: Unknown data type 0x" << std::hex << rawd << std::dec <<
QwLog::endl;
386 Bool_t debug =
false;
392 for (
size_t i = 0; i < num_words_left; i++) {
393 QwOut <<
"0x" << std::setfill(
'0') << std::setw(8) << buffer[i] <<
" ";
399 UInt_t words_read = 0;
411 QwOut <<
" : header " << std::hex;
413 for (
size_t i = 0; i < n && i < num_words_left; i++) {
414 QwOut <<
"0x" << std::setfill(
'0') << std::setw(8) << buffer[i] <<
" ";
422 return num_words_left;
436 QwOut <<
" : channel " << std::hex;
438 for (
size_t i = 0; i < n && i < num_words_left; i++) {
439 QwOut <<
"0x" << std::setfill(
'0') << std::setw(8) << buffer[i] <<
" ";
447 return num_words_left;
476 QwWarning <<
"QwADC18_Channel::ProcessEvent: Channel "
478 <<
" has fNumberOfSamples == 0 but has valid data in the value filed."
479 <<
"Flag this as an error."
514 if (folder != NULL) folder->cd();
520 if (prefix == TString(
"asym_")
521 || prefix == TString(
"diff_")
522 || prefix == TString(
"yield_"))
525 TString basename, fullname;
580 TString basename = prefix(0, (prefix.First(
"|") >= 0)? prefix.First(
"|"): prefix.Length()) +
GetElementName();
589 values.
push_back(
"Device_Error_Code",
'i');
598 if (
gQwHists.MatchDeviceParamsFromList(basename.Data()))
609 tree->Branch(basename, &
fValue, basename+
"/D");
618 static bool warned =
false;
620 QwError <<
"QwADC18_Channel::FillTreeVector: fTreeArrayNumEntries=="
626 QwError <<
"QwADC18_Channel::FillTreeVector: values.size()=="
628 <<
"; fTreeArrayIndex+fTreeArrayNumEntries=="
649#ifdef HAS_RNTUPLE_SUPPORT
650void QwADC18_Channel::ConstructNTupleAndVector(std::unique_ptr<ROOT::RNTupleModel>& model, TString& prefix, std::vector<Double_t>& values, std::vector<std::shared_ptr<Double_t>>& fieldPtrs)
658 TString basename = prefix(0, (prefix.First(
"|") >= 0)? prefix.First(
"|"): prefix.Length()) +
GetElementName();
662 size_t numElements = 2;
667 size_t oldSize = values.size();
668 values.resize(oldSize + numElements, 0.0);
669 fieldPtrs.reserve(fieldPtrs.size() + numElements);
672 fieldPtrs.push_back(model->MakeField<Double_t>(basename.Data()));
675 fieldPtrs.push_back(model->MakeField<Double_t>((basename +
"_m2").Data()));
676 fieldPtrs.push_back(model->MakeField<Double_t>((basename +
"_err").Data()));
680 fieldPtrs.push_back(model->MakeField<Double_t>((basename +
"_Device_Error_Code").Data()));
683 fieldPtrs.push_back(model->MakeField<Double_t>((basename +
"_raw").Data()));
684 fieldPtrs.push_back(model->MakeField<Double_t>((basename +
"_diff").Data()));
685 fieldPtrs.push_back(model->MakeField<Double_t>((basename +
"_peak").Data()));
686 fieldPtrs.push_back(model->MakeField<Double_t>((basename +
"_base").Data()));
693void QwADC18_Channel::FillNTupleVector(std::vector<Double_t>& values)
const
698 QwError <<
"QwADC18_Channel::FillNTupleVector: fTreeArrayNumEntries=="
701 static bool warned =
false;
703 QwError <<
"QwADC18_Channel::FillNTupleVector: fTreeArrayNumEntries=="
709 QwError <<
"QwADC18_Channel::FillNTupleVector: values.size()=="
711 <<
"; fTreeArrayIndex+fTreeArrayNumEntries=="
717 values[index++] = this->
fValue;
736 if (
this == &value)
return *
this;
754 if(
this == &value)
return;
772 TString loc=
"Standard exception from QwADC18_Channel::AssignValueFrom = "
774 throw std::invalid_argument(loc.Data());
784 TString loc=
"Standard exception from QwADC18_Channel::AddValueFrom = "
786 throw std::invalid_argument(loc.Data());
796 TString loc=
"Standard exception from QwADC18_Channel::SubtractValueFrom = "
798 throw std::invalid_argument(loc.Data());
808 TString loc=
"Standard exception from QwADC18_Channel::MultiplyBy = "
810 throw std::invalid_argument(loc.Data());
820 TString loc=
"Standard exception from QwADC18_Channel::DivideBy = "
822 throw std::invalid_argument(loc.Data());
888 TString loc=
"Standard exception from QwADC18_Channel::operator+= "
891 throw(std::invalid_argument(loc.Data()));
903 TString loc=
"Standard exception from QwADC18_Channel::operator-= "
906 throw(std::invalid_argument(loc.Data()));
918 TString loc=
"Standard exception from QwADC18_Channel::operator*= "
921 throw(std::invalid_argument(loc.Data()));
933 TString loc=
"Standard exception from QwADC18_Channel::operator/= "
936 throw(std::invalid_argument(loc.Data()));
984 variance = ratio * ratio *
989 }
else if (this->
fValue == 0.0) {
993 QwVerbose <<
"Attempting to divide by zero in "
1138 Double_t M12 = value.
fValue;
1143 }
else if (n2 == 1) {
1146 fValue += (M12 - M11) / n;
1148 }
else if (n2 > 1) {
1151 fValue += n2 * (M12 - M11) / n;
1152 fValueM2 += M22 + n1 * n2 * (M12 - M11) * (M12 - M11) / n;
1182 << std::setw(12) << std::left <<
GetValue() <<
" +/- "
1230 Bool_t status = kTRUE;
1239 Bool_t status = kTRUE;
1244 QwError <<
"QwADC18_Channel::MatchNumberOfSamples: Channel "
1247 <<
" and was supposed to have " << numsamp
1257 Bool_t status = kFALSE;
1310 message = Form(
"%30s",
"Device name");
1311 message += Form(
"%9s",
"HW Sat");
1312 message += Form(
"%9s",
"Sample");
1313 message += Form(
"%9s",
"SW_HW");
1314 message += Form(
"%9s",
"Sequence");
1315 message += Form(
"%9s",
"SameHW");
1316 message += Form(
"%9s",
"ZeroHW");
1317 message += Form(
"%9s",
"EventCut");
1318 QwMessage <<
"---------------------------------------------------------------------------------------------" <<
QwLog::endl;
1320 QwMessage <<
"---------------------------------------------------------------------------------------------" <<
QwLog::endl;
1325 QwMessage <<
"---------------------------------------------------------------------------------------------" <<
QwLog::endl;
1342 message +=
" >>>>> No Pedestal or Gain in map file";
1369 }
else if (input == NULL && value != NULL) {
1370 TString loc=
"Standard exception from QwADC18_Channel::ScaledAdd "
1373 throw(std::invalid_argument(loc.Data()));
1377#ifdef __USE_DATABASE__
1436 row_list.push_back(row);
1442 row_list.push_back(row);
1448 row_list.push_back(row);
1455 row_list.push_back(row);
1462 row_list.push_back(row);
1468 row_list.push_back(row);
1475 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 QwOut
Predefined log drain for explicit output.
#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.
static const UInt_t kErrorFlag_ZeroHW
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_SameHW
static const UInt_t kErrorFlag_Sequence
Database interface for QwIntegrationPMT and subsystems.
std::ostream & operator<<(std::ostream &stream, const QwADC18_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()
static const Int_t kFooterWordsPerModule
static const Int_t kMaxChannels
Double_t GetValue(size_t element) const override
static const Int_t kHeaderWordsPerBank
UInt_t fNumberOfSamples
Number of samples read through the module.
static const Int_t kHeaderWordsPerModule
static const Bool_t kDEBUG
Double_t GetValueError() const
Int_t fErrorCount_HWSat
check to see ADC channel is saturated
void PrintInfo() const override
Print multiple lines of information about this data element.
QwADC18_Channel & operator*=(const QwADC18_Channel &value)
static const Double_t kADC18_VoltsPerBit
void AddValueFrom(const VQwHardwareChannel *valueptr) override
Int_t ApplyHWChecks() override
Int_t fErrorCount_SW_HW
HW_sum==SW_sum check.
void RandomizeEventData(int helicity=0.0, double time=0.0) override
Internally generate random event data.
void ProcessEvent() override
Process the event data according to pedestal and calibration factor.
static void PrintErrorCounterHead()
static const UInt_t mask3029x
static const Int_t kFooterWordsPerBank
const QwADC18_Channel operator+(const QwADC18_Channel &value) const
Int_t fSequenceNo_Counter
Internal counter to keep track of the sequence number.
Int_t fErrorCount_SameHW
check to see ADC returning same HW value
void FillHistograms() override
Fill the histograms for this data element.
void Product(const QwADC18_Channel &value1, const QwADC18_Channel &value2)
void SubtractValueFrom(const VQwHardwareChannel *valueptr) override
Int_t fErrorCount_sample
for sample size check
Int_t fSequenceNo_Prev
Keep the sequence number of the last event.
void ArcTan(const QwADC18_Channel &value)
void Sum(const QwADC18_Channel &value1, const QwADC18_Channel &value2)
void ConstructHistograms(TDirectory *folder, TString &prefix) override
Construct the histograms for this data element.
void Scale(Double_t Offset) override
void CalculateRunningAverage() override
size_t GetSequenceNumber() const
void Difference(const QwADC18_Channel &value1, const QwADC18_Channel &value2)
void PrintValue() const override
Print single line of value and error of this data element.
void FillTreeVector(QwRootTreeBranchVector &values) const override
Int_t fErrorCount_ZeroHW
check to see ADC returning zero
void ConstructBranch(TTree *tree, TString &prefix) override
static const UInt_t mask2422x
void AddChannelOffset(Double_t Offset)
void PrintErrorCounters() const override
report number of events failed due to HW and event cut failure
void AccumulateRunningSum(const QwADC18_Channel &value, Int_t count=0, Int_t ErrorMask=0xFFFFFFF)
static const UInt_t mask2625x
void Ratio(const QwADC18_Channel &numer, const QwADC18_Channel &denom)
static const UInt_t mask170x
Int_t fADC_Same_NumEvt
Keep track of how many events with same ADC value returned.
void SetRawEventData() override
void ClearEventData() override
Clear the event data in this element.
void ScaledAdd(Double_t scale, const VQwHardwareChannel *value) override
void AssignScaledValue(const QwADC18_Channel &value, Double_t scale)
const QwADC18_Channel operator-(const QwADC18_Channel &value) const
QwADC18_Channel & operator=(const QwADC18_Channel &value)
Bool_t MatchNumberOfSamples(size_t numsamp)
static const Bool_t bDEBUG
debugging display purposes
QwADC18_Channel * fRunningSum
Pointer to the running sum for this channel.
void SmearByResolution(double resolution) override
void ConstructBranchAndVector(TTree *tree, TString &prefix, QwRootTreeBranchVector &values) override
void SetEventData(Double_t value)
void LoadChannelParameters(QwParameterFile ¶mfile) override
UInt_t fPreviousSequenceNumber
Previous event sequence number for this channel.
Int_t fNumEvtsWithEventCutsRejected
Counts the Event cut rejected events.
QwADC18_Channel & operator-=(const QwADC18_Channel &value)
static const UInt_t mask200x
static const UInt_t mask31x
VQwHardwareChannel & operator/=(const VQwHardwareChannel &input) override
Double_t GetAverageVolts() const
void IncrementErrorCounters() override
void Blind(const QwBlinder *blinder)
Blind this channel as an asymmetry.
static const Double_t kTimePerSample
void MultiplyBy(const VQwHardwareChannel *valueptr) override
Bool_t ApplySingleEventCuts() override
QwADC18_Channel & operator+=(const QwADC18_Channel &value)
Double_t GetValueWidth() const
static const UInt_t mask2118x
static Int_t GetBufferOffset(Int_t moduleindex, Int_t channelindex)
Bool_t IsHeaderWord(UInt_t word) const
Decode the event data from a CODA buffer.
void InitializeChannel(TString name, TString datatosave) override
Initialize the fields in this object.
static void PrintErrorCounterTail()
Double_t GetValue() const
static const UInt_t mask21x
static const Int_t kDataWordsPerChannel
Bool_t MatchSequenceNumber(size_t seqnum)
UInt_t fNumberOfSamples_map
Number of samples in the expected to read through the module. This value is set in the QwBeamline map...
size_t GetNumberOfSamples() const
Int_t GetRawValue() const
void AssignValueFrom(const VQwDataElement *valueptr) override
Int_t fErrorCount_Sequence
sequence number check
Int_t ProcessEvBuffer(UInt_t *buffer, UInt_t num_words_left, UInt_t index=0) override
Process the CODA event buffer for this element.
void EncodeEventData(std::vector< UInt_t > &buffer) override
Encode the event data into a CODA buffer.
void DivideBy(const VQwHardwareChannel *valueptr) override
void SetDefaultSampleSize(size_t num_samples_map)
const QwADC18_Channel operator*(const QwADC18_Channel &value) const
static const UInt_t mask150x
Int_t ProcessDataWord(UInt_t word)
UInt_t fSequenceNumber
Event sequence number for this channel.
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)
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.
TString fElementName
Name of this data element.
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.
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