12#include "ROOT/RNTupleModel.hxx"
13#include "ROOT/RField.hxx"
16#ifdef __USE_DATABASE__
37 Bool_t localdebug = kFALSE;
51 std::cout<<
" Wire ["<<i<<
"]="<<
fWire[i].GetElementName()<<
"\n";
84 Bool_t localdebug = kFALSE;
91 fEffectiveCharge.InitializeChannel(subsystem,
"QwBPMStripline", name+
"WS",
"derived");
92 fEllipticity.InitializeChannel(subsystem,
"QwBPMStripline", name+
"Elli",
"derived");
95 fWire[i].InitializeChannel(subsystem,
"QwBPMStripline", name+
subelement[i],
"raw");
97 std::cout<<
" Wire ["<<i<<
"]="<<
fWire[i].GetElementName()<<
"\n";
133 Bool_t eventokay=kTRUE;
135 UInt_t deviceerror=0;
136 for(Short_t i=0;i<4;i++)
138 deviceerror|=
fWire[i].ApplyHWChecks();
139 eventokay &= (deviceerror & 0x0);
157 fRelPos[i].IncrementErrorCounters();
158 fAbsPos[i].IncrementErrorCounters();
172 fRelPos[i].PrintErrorCounters();
173 fAbsPos[i].PrintErrorCounters();
186 error|=
fRelPos[i].GetEventcutErrorFlag();
187 error|=
fAbsPos[i].GetEventcutErrorFlag();
202 error1 |=
fWire[i].GetErrorCode();
203 error2 |=
fWire[i].GetEventcutErrorFlag();
206 fRelPos[i].UpdateErrorFlag(error1);
207 fAbsPos[i].UpdateErrorFlag(error1);
208 error2|=
fRelPos[i].GetEventcutErrorFlag();
209 error2|=
fAbsPos[i].GetEventcutErrorFlag();
227 Bool_t burpstatus = kFALSE;
229 if(
typeid(*ev_error)==
typeid(*
this)) {
234 burpstatus |=
fWire[i].CheckForBurpFail(&(value_bpm->
fWire[i]));
237 burpstatus |=
fRelPos[i].CheckForBurpFail(&(value_bpm->
fRelPos[i]));
238 burpstatus |=
fAbsPos[i].CheckForBurpFail(&(value_bpm->
fAbsPos[i]));
244 TString loc=
"Standard exception from QwBPMStripline::CheckForBurpFail :"+
247 throw std::invalid_argument(loc.Data());
249 }
catch (std::exception& e) {
250 std::cerr<< e.what()<<std::endl;
260 if(
typeid(*ev_error)==
typeid(*
this)) {
265 fWire[i].UpdateErrorFlag(value_bpm->
fWire[i]);
275 TString loc=
"Standard exception from QwBPMStripline::UpdateErrorFlag :"+
278 throw std::invalid_argument(loc.Data());
280 }
catch (std::exception& e) {
281 std::cerr<< e.what()<<std::endl;
292 UInt_t element_error_code[2];
300 if (
bDEBUG) std::cout<<
" Abs X event cut failed ";
326 if (
bDEBUG) std::cout<<
" Rel X event cut failed ";
336 if (
bDEBUG) std::cout<<
" Abs X event cut failed ";
349 if (
bDEBUG) std::cout<<
"EffectiveCharge event cut failed ";
361 }
else if (ch_name==
"xm"){
363 }
else if (ch_name==
"yp"){
365 }
else if (ch_name==
"ym"){
367 }
else if (ch_name==
"relx"){
369 }
else if (ch_name==
"rely"){
371 }
else if (ch_name==
"absx" || ch_name==
"x" ){
373 }
else if (ch_name==
"absy" || ch_name==
"y"){
375 }
else if (ch_name==
"effectivecharge" || ch_name==
"charge"){
377 }
else if (ch_name==
"ellipticity" || ch_name==
"elli"){
380 TString loc=
"QwBPMStripline::GetSubelementByName for"
382 + ch_name +
", which is an unrecognized subelement name.";
383 throw std::invalid_argument(loc.Data());
404 QwError<<
"***************************inside QwBPStripline "<<
typeid(
this).name()<<
QwLog::endl;
405 fWire[0].SetSingleEventCuts(errorflag,minX,maxX,stability,burplevel);
407 }
else if (ch_name==
"xm"){
409 fWire[1].SetSingleEventCuts(errorflag,minX,maxX,stability,burplevel);
411 }
else if (ch_name==
"yp"){
413 fWire[2].SetSingleEventCuts(errorflag,minX,maxX,stability,burplevel);
415 }
else if (ch_name==
"ym"){
417 fWire[3].SetSingleEventCuts(errorflag,minX,maxX,stability,burplevel);
419 }
else if (ch_name==
"relx"){
421 fRelPos[0].SetSingleEventCuts(errorflag,minX,maxX,stability,burplevel);
423 }
else if (ch_name==
"rely"){
425 fRelPos[1].SetSingleEventCuts(errorflag,minX,maxX,stability,burplevel);
427 }
else if (ch_name==
"absx"){
430 fAbsPos[0].SetSingleEventCuts(errorflag,minX,maxX,stability,burplevel);
432 }
else if (ch_name==
"absy"){
434 fAbsPos[1].SetSingleEventCuts(errorflag,minX,maxX,stability,burplevel);
436 }
else if (ch_name==
"effectivecharge"){
438 fEffectiveCharge.SetSingleEventCuts(errorflag,minX,maxX,stability,burplevel);
440 }
else if (ch_name==
"ellipticity"){
442 fEllipticity.SetSingleEventCuts(errorflag,minX,maxX,stability,burplevel);
450 Bool_t localdebug = kFALSE;
451 static T numer(
"numerator",
"derived"), denom(
"denominator",
"derived");
452 static T tmp1(
"tmp1",
"derived"), tmp2(
"tmp2",
"derived");
453 static T tmp3(
"tmp3",
"derived"), tmp4(
"tmp4",
"derived");
454 static T tmp5(
"tmp3",
"derived");
455 static T rawpos[2] = {T(
"rawpos_0",
"derived"),T(
"rawpos_1",
"derived")};
470 fWire[i].ProcessEvent();
512 rawpos[i].Ratio(numer,denom);
519 std::cout<<
" hw Wire["<<i*2<<
"]="<<
fWire[i*2].GetValue()<<
" ";
520 std::cout<<
" hw relative gain * Wire["<<i*2+1<<
"]="<<
fWire[i*2+1].GetValue()<<
"\n";
522 std::cout<<
" hw numerator= "<<numer.GetValue()<<
" ";
523 std::cout<<
" hw denominator= "<<denom.GetValue()<<
"\n";
533 fRelPos[i].Difference(tmp1,tmp2);
558 tmp5.Difference(tmp3,tmp4);
559 tmp5.Scale(-1.0*0.250014);
571 fWire[index].ProcessEvBuffer(buffer,word_position_in_buffer);
576 "QwBPMStripline::ProcessEvBuffer(): attempt to fill in raw data for a wire that doesn't exist \n";
578 return word_position_in_buffer;
586 for (Short_t i = 0; i < 2; i++) {
613 for (i = 0; i < 2; i++) {
626 if(subindex<4&&subindex>-1)
627 thisname=
fWire[subindex].GetElementName();
629 std::cerr<<
"QwBPMStripline::GetSubElementName for "<<
640 for(Short_t i=0;i<4;i++)
if(subname==
subelement[i])localindex=i;
643 std::cerr <<
"QwBPMStripline::GetSubElementIndex is unable to associate the string -"
644 <<subname<<
"- to any index"<<std::endl;
679 for(i=0;i<4;i++) this->
fWire[i]=value.
fWire[i];
704 for(i=0;i<4;i++) this->
fWire[i]+=value.
fWire[i];
728 for(i=0;i<4;i++) this->
fWire[i]-=value.
fWire[i];
776 for (i = 0; i < 4; i++){
777 fWire[i].CalculateRunningAverage();
780 for (i = 0; i < 2; i++){
781 fRelPos[i].CalculateRunningAverage();
782 fAbsPos[i].CalculateRunningAverage();
799 for (i = 0; i < 4; i++){
800 fWire[i].AccumulateRunningSum(value.
fWire[i], count, ErrorMask);
802 for (i = 0; i < 2; i++){
803 fRelPos[i].AccumulateRunningSum(value.
fRelPos[i], count, ErrorMask);
804 fAbsPos[i].AccumulateRunningSum(value.
fAbsPos[i], count, ErrorMask);
817 for (i = 0; i < 4; i++){
818 fWire[i].DeaccumulateRunningSum(value.
fWire[i], ErrorMask);
820 for (i = 0; i < 2; i++){
837 TString thisprefix=prefix;
839 if(prefix.Contains(
"asym_"))
840 thisprefix.ReplaceAll(
"asym_",
"diff_");
847 fRelPos[i].ConstructHistograms(folder, thisprefix);
848 fAbsPos[i].ConstructHistograms(folder, thisprefix);
883 TString thisprefix=prefix;
884 if(prefix.Contains(
"asym_"))
885 thisprefix.ReplaceAll(
"asym_",
"diff_");
890 fEllipticity.ConstructBranchAndVector(tree,prefix,values);
898 fAbsPos[i].ConstructBranchAndVector(tree,thisprefix,values);
912 TString thisprefix=prefix;
913 if(prefix.Contains(
"asym_"))
914 thisprefix.ReplaceAll(
"asym_",
"diff_");
927 fAbsPos[i].ConstructBranch(tree,thisprefix);
949 devicename.ToLower();
954 if (modulelist.
HasValue(devicename)){
955 TString thisprefix=prefix;
956 if(prefix.Contains(
"asym_"))
957 thisprefix.ReplaceAll(
"asym_",
"diff_");
970 fAbsPos[i].ConstructBranch(tree,thisprefix);
998 fAbsPos[i].FillTreeVector(values);
1004#ifdef HAS_RNTUPLE_SUPPORT
1008 if (GetElementName()==
""){
1012 TString thisprefix=prefix;
1013 if(prefix.Contains(
"asym_"))
1014 thisprefix.ReplaceAll(
"asym_",
"diff_");
1016 this->SetRootSaveStatus(prefix);
1018 fEffectiveCharge.ConstructNTupleAndVector(model, prefix, values, fieldPtrs);
1019 fEllipticity.ConstructNTupleAndVector(model, prefix, values, fieldPtrs);
1022 for(i=0;i<4;i++) fWire[i].ConstructNTupleAndVector(model, thisprefix, values, fieldPtrs);
1024 for(i=kXAxis;i<kNumAxes;i++) {
1027 fAbsPos[i].ConstructNTupleAndVector(model, thisprefix, values, fieldPtrs);
1035 if (GetElementName()==
"") {
1039 fEffectiveCharge.FillNTupleVector(values);
1040 fEllipticity.FillNTupleVector(values);
1043 for(i=0;i<4;i++) fWire[i].FillNTupleVector(values);
1045 for(i=kXAxis;i<kNumAxes;i++){
1048 fAbsPos[i].FillNTupleVector(values);
1061 fRelPos[i].SetEventCutMode(bcuts);
1062 fAbsPos[i].SetEventCutMode(bcuts);
1092#ifdef __USE_DATABASE__
1096 std::vector <QwDBInterface> row_list;
1099 for(
size_t i=0;i<2;i++) {
1100 fRelPos[i].AddEntriesToList(row_list);
1101 fAbsPos[i].AddEntriesToList(row_list);
1103 fEffectiveCharge.AddEntriesToList(row_list);
1104 fEllipticity.AddEntriesToList(row_list);
1112 std::vector <QwErrDBInterface> row_list;
1115 for(
size_t i=0;i<2;i++) {
1116 fRelPos[i].AddErrEntriesToList(row_list);
1117 fAbsPos[i].AddErrEntriesToList(row_list);
1119 fEffectiveCharge.AddErrEntriesToList(row_list);
1120 fEllipticity.AddErrEntriesToList(row_list);
1139 for(
int i = 0; i < 4; i++){
1185 static T numer(
"numerator",
"derived"), denom(
"denominator",
"derived");
1186 static T tmp1(
"tmp1",
"derived"), tmp2(
"tmp2",
"derived");
1187 static T rawpos[2] = {T(
"rawpos_0",
"derived"),T(
"rawpos_1",
"derived")};
1191 fAbsPos[i].RandomizeEventData(helicity, time);
1204 Double_t xres=0.0, yres=0.0;
1206 if (paramfile.
GetLine().find(
"resolution")!=std::string::npos){
1235 fAbsPos[i].SetMockDataAsDiff();
1236 fAbsPos[i].LoadMockDataParameters(paramfile);
1261 static T numer(
"numerator",
"derived"), denom(
"denominator",
"derived");
1262 static T tmp1(
"tmp1",
"derived"), tmp2(
"tmp2",
"derived");
1263 static T rawpos[2] = {T(
"rawpos_0",
"derived"),T(
"rawpos_1",
"derived")};
1264 int helicity = 0;
double time = 0.0;
1266 numer.CopyParameters(&
fAbsPos[0]);
1267 denom.CopyParameters(&
fAbsPos[0]);
1268 tmp1.CopyParameters(&
fAbsPos[0]);
1269 tmp2.CopyParameters(&
fAbsPos[0]);
1270 rawpos[0].CopyParameters(&
fAbsPos[0]);
1271 rawpos[1].CopyParameters(&
fAbsPos[0]);
1287 rawpos[i].Sum(tmp1,tmp2);
1289 rawpos[i].Difference(tmp1,tmp2);
1294 numer.AssignScaledValue(rawpos[i],1.0);
1296 denom.AssignScaledValue(rawpos[i],-1.0);
1298 tmp2.SetRandomEventParameters(5.0, 0.005);
1300 tmp2.RandomizeEventData(helicity, time);
1301 tmp1.Ratio(numer,denom);
1302 if (tmp1.GetValue()<1.0){
1303 fWire[i*2+1].AssignScaledValue(tmp2, 1.0);
1304 fWire[i*2].Product(tmp1, tmp2);
1306 fWire[i*2].AssignScaledValue(tmp2, 1.0);
1307 fWire[i*2+1].Ratio(tmp2, tmp1);
1314 fWire[i*2].SetRawEventData();
1315 fWire[i*2+1].SetRawEventData();
1337 for (Short_t i=0; i<2; i++){
1363 fWire[j].SetPedestal(value);
1370 fWire[j].SetCalibrationFactor(value);
Base and derived classes for scaler channel data handling.
#define QwError
Predefined log drain for errors.
#define QwMessage
Predefined log drain for regular messages.
Decoding and management for Moller ADC channels (6x32-bit datawords)
Decoding and management for VQWK ADC channels (6x32-bit datawords)
static const UInt_t kBPMErrorFlag
static const UInt_t kInvalidSubelementIndex
Database interface for QwIntegrationPMT and subsystems.
Stripline beam position monitor implementation.
static std::ostream & endl(std::ostream &)
End of the line.
Configuration file parser with flexible tokenization and search capabilities.
T GetTypedNextToken()
Get next token into specific type.
Bool_t HasValue(TString &vname)
std::string GetNextToken(const std::string &separatorchars)
Get next token as a string.
A helper class to manage a vector of branch entries for ROOT trees.
VQwDataElement()
Default constructor.
TString fElementName
Name of this data element.
virtual const TString & GetElementName() const
Get the name of this element.
void SetModuleType(TString ModuleType)
set the type of the beam instrument
Abstract base for concrete hardware channels implementing dual-operator pattern.
Templated concrete stripline beam position monitor implementation.
void SetSubElementCalibrationFactor(Int_t j, Double_t value) override
void AccumulateRunningSum(const QwBPMStripline &value, Int_t count=0, Int_t ErrorMask=0xFFFFFFF)
Bool_t ApplyHWChecks()
Apply hardware checks across all wires and derived channels.
void LoadMockDataParameters(QwParameterFile ¶mfile) override
void PrintInfo() const override
Print multiple lines of information about this data element.
VQwBPM & operator=(const VQwBPM &value) override
Int_t ProcessEvBuffer(UInt_t *buffer, UInt_t word_position_in_buffer, UInt_t indexnumber) override
Process the CODA event buffer for this element.
void ProcessEvent() override
void CalculateRunningAverage() override
void SetEventCutMode(Int_t bcuts) override
void RandomizeEventData(int helicity=0, double time=0.0) override
UInt_t UpdateErrorFlag() override
Update and return the aggregated event-cut error flag.
UInt_t GetEventcutErrorFlag() override
Aggregate and return the event-cut error flag for this BPM.
std::array< T, 2 > fAbsPos
void SetRandomEventParameters(Double_t meanX, Double_t sigmaX, Double_t meanY, Double_t sigmaY) override
void ApplyResolutionSmearing() override
VQwHardwareChannel * GetSubelementByName(TString ch_name) override
static UInt_t GetSubElementIndex(TString subname)
VQwBPM & operator-=(const VQwBPM &value) override
void GetAbsolutePosition() override
void Scale(Double_t factor) override
void SetEventData(Double_t *block, UInt_t sequencenumber)
void WritePromptSummary(QwPromptSummary *ps, TString type)
static const TString subelement[4]
std::vector< T > fBPMElementList
Bool_t ApplySingleEventCuts() override
void ConstructBranch(TTree *tree, TString &prefix) override
void ConstructHistograms(TDirectory *folder, TString &prefix) override
Construct the histograms for this data element.
void EncodeEventData(std::vector< UInt_t > &buffer) override
VQwBPM & operator+=(const VQwBPM &value) override
void InitializeChannel(TString name)
Initialize this BPM stripline with a detector name.
void Ratio(VQwBPM &numer, VQwBPM &denom) override
void SetSingleEventCuts(TString ch_name, UInt_t errorflag, Double_t minX, Double_t maxX, Double_t stability, Double_t burplevel)
void FillHistograms() override
Fill the histograms for this data element.
void ConstructBranchAndVector(TTree *tree, TString &prefix, QwRootTreeBranchVector &values) override
void SetDefaultSampleSize(Int_t sample_size) override
void FillTreeVector(QwRootTreeBranchVector &values) const override
Bool_t CheckForBurpFail(const VQwDataElement *ev_error) override
Check for burp failures against another BPM of the same type.
void PrintValue() const override
Print single line of value and error of this data element.
void IncrementErrorCounters() override
Increment error counters for all internal channels.
TString GetSubElementName(Int_t subindex) override
void SetSubElementPedestal(Int_t j, Double_t value) override
void DeaccumulateRunningSum(VQwBPM &value, Int_t ErrorMask=0xFFFFFFF) override
void PrintErrorCounters() const override
Print error counters for all internal channels.
void ClearEventData() override
Clear event-scoped data in all channels of this BPM.
void FillRawEventData() override
std::array< T, 2 > fRelPos
Double_t fPositionCenter[3]
Double_t fQwStriplineCalibration
void SetRootSaveStatus(TString &prefix)
static const TString kAxisLabel[2]
virtual void SetResolution(Double_t resolutionX, Double_t resolutionY)
Double_t fRelativeGains[2]
void InitializeChannel(TString name)
Initialize common BPM state and set the element name.
static const Bool_t bDEBUG
virtual VQwBPM & operator=(const VQwBPM &value)=0