72 Double_t asym_diff_err,
73 Double_t asym_diff_width,
74 TString asym_diff_unit
109if (type.Contains(
"yield")&& !(dd||da)){
112if (type.Contains(
"asy")&& !(dd||da)){
115if (type.Contains(
"double")&& (dd||da)) {
135 if (type.Contains(
"yield")){
156 else if(type.Contains(
"asymmetry")) {
172 else if(type.Contains(
"difference")) {
231 std::string default_param_file =
"prompt_summary.map";
240 }
catch (
const std::exception& e) {
242 QwMessage <<
"QwPromptSummary: Could not load from " << default_param_file
243 <<
", using default elements: " << e.what() <<
QwLog::endl;
255 }
catch (
const std::exception& e) {
256 QwError <<
"QwPromptSummary::LoadElementsFromParameterFile: Unable to open parameter file: "
257 << parameter_file <<
" - " << e.what() <<
QwLog::endl;
266 QwMessage <<
"QwPromptSummary::LoadElementsFromParameterFile: Loading prompt summary elements" <<
QwLog::endl;
276 std::unique_ptr<QwParameterFile> section;
277 std::string section_name;
282 if (section_name ==
"prompt_summary_elements" || section_name ==
"elements") {
284 while (section->ReadNextLine()) {
285 section->TrimWhitespace();
286 section->TrimComment();
287 if (section->LineIsEmpty())
continue;
289 std::string line = section->GetLine();
295 std::string element_name, element_type;
296 if (section->HasVariablePair(
"=", element_name, element_type)) {
299 element_name.erase(0, element_name.find_first_not_of(
" \t\r\n"));
300 element_name.erase(element_name.find_last_not_of(
" \t\r\n") + 1);
301 element_type.erase(0, element_type.find_first_not_of(
" \t\r\n"));
302 element_type.erase(element_type.find_last_not_of(
" \t\r\n") + 1);
305 QwMessage <<
"Adding element: " << element_name <<
" (type: " << element_type <<
")" <<
QwLog::endl;
310 element_type =
"single";
318 if (!element_name.empty()) {
332 TString name = in->
GetName(); name.ToLower();
351 std::cout <<
"System " << an_element->
GetName()
352 <<
" QwPromptSummary::GetElementByName address at " << an_element << std::endl;
357 <<
" QwPromptSummary::GetElementByName not found" << std::endl;
371 out =
"======= BEGIN ======= \n";
383 out =
"==================================================\n";
393 Double_t goodEvents = 0.0;
394 TString referenceElementName =
"N/A";
401 QwError <<
"Warning: No reference element found in QwPromptSummary. Setting goodEvents=0." <<
QwLog::endl;
405 out +=
"Start Time: "+start_time+
"\nEnd Time: "+end_time+
"\n";
406 out += Form(
"Number of events processed: %i\n",nEvents);
407 out += Form(
"Number of events in good multiplicity patterns: %3.0f\n", goodEvents);
408 out += Form(
"Percentage of good events: %3.1f %%\n", goodEvents/nEvents*100);
409 out += Form(
"Good events reference: %s (first element from parameter file)\n", referenceElementName.Data());
410 out +=
"=========================================================================\n";
411 out +=
"Yield Units: bcm(uA), cavq(uA), bpm(mm), sam(mV/uA)\n";
412 out +=
"Asymmetry/Difference Units: bcm(ppm), cavq(ppm), bpm(um), sam(ppm)\n";
414 out +=
"=========================================================================\n";
427 Double_t yield_width,
430 Double_t asym_diff_err,
431 Double_t asym_diff_width,
432 TString asym_diff_unit
439 an_element->
FillData(yield, yield_err, yield_width, yield_unit, asym_diff, asym_diff_err, asym_diff_width, asym_diff_unit);
444 <<
"QwPromptSummary::FillDataInElement : No Element with the name "
456 Double_t yield_error,
457 Double_t yield_width,
471 <<
"QwPromptSummary::FillYieldToElement : No Element with the name "
482 Double_t asym_diff_err,
483 Double_t asym_diff_width,
484 TString asym_diff_unit
497 <<
"QwPromptSummary::FillYieldToElement : No Element with the name "
518 if(one_element && two_element ) {
526 Double_t error_diff = 0.0;
527 Double_t width_diff = 0.0;
531 Double_t a_err = 0.0;
532 Double_t b_err = 0.0;
533 Double_t a_wit = 0.0;
534 Double_t b_wit = 0.0;
537 if(type.Contains(
"yield")) {
538 a = one_element -> GetYield();
539 b = two_element -> GetYield();
540 a_err = one_element -> GetYieldError();
541 b_err = two_element -> GetYieldError();
542 a_wit = one_element -> GetYieldWidth();
543 b_wit = two_element -> GetYieldWidth();
546 error_diff = TMath::Sqrt(a_err*a_err + b_err*b_err);
547 width_diff = a_wit - b_wit;
549 an_element -> SetYield(diff);
550 an_element -> SetYieldError(error_diff);
551 an_element -> SetYieldWidth(width_diff);
554 a = one_element -> GetAsymmetry();
555 b = two_element -> GetAsymmetry();
556 a_err = one_element -> GetAsymmetryError();
557 b_err = two_element -> GetAsymmetryError();
558 a_wit = one_element -> GetAsymmetryWidth();
559 b_wit = two_element -> GetAsymmetryWidth();
562 error_diff = TMath::Sqrt(a_err*a_err + b_err*b_err);
563 width_diff = a_wit - b_wit;
565 an_element -> SetAsymmetry(diff);
566 an_element -> SetAsymmetryError(error_diff);
567 an_element -> SetAsymmetryWidth(width_diff);
576 <<
"QwPromptSummary::FillYieldToElement : No Element with the name "
577 << name1 +
"-" + name2
586 <<
"QwPromptSummary::FillDoubleDifference: No Elements with the name "
587 << name1 <<
" and " << name2
596 printf(
"-----------------------\n");
597 TString filename =
gQwOptions.GetValue<std::string>(
"rootfiles");
598 filename+=Form(
"/summary_%d.txt",
fRunNumber);
599 TString header= this->
PrintCSVHeader(nEvents, start_time, end_time);
600 std::ofstream output;
601 output.open(filename.Data());
602 output<< header.Data();
604 TString secheader=
"=========================================================================\n";
605 secheader+=Form(
"%40s \n",
"Yields");
606 secheader+=
"=========================================================================\n" ;
607 output << secheader.Data() ;
611 output << i->second->GetCSVSummary(
"yield") ;
615 secheader=
"=========================================================================\n";
616 secheader+=Form(
"%50s\n",
"Asymmetries/Differences");
617 secheader+=
"=========================================================================\n";
618 output << secheader.Data();
622 output << j->second->GetCSVSummary(
"asymmetry");
627 secheader=
"=========================================================================\n";
628 secheader+=Form(
"%55s\n",
"Combined Differences/Averages");
629 secheader+=
"=========================================================================\n";
630 output << secheader.Data();
634 output << j->second->GetCSVSummary(
"double");
637 output<<
"=========================================================================\n";
638 output<< Form(
"%45s\n",
" End of Summary");
639 output<<
"=========================================================================\n";
#define QwVerbose
Predefined log drain for verbose messages.
#define QwError
Predefined log drain for errors.
#define QwMessage
Predefined log drain for regular messages.
#define QwDebug
Predefined log drain for debugging output.
Prompt summary data management.
static const double uA
Beam current: base unit is microamp.
static const double mV_uA
Signal volts per microamp.
static const double mm
Length units: base unit is mm.
static std::ostream & endl(std::ostream &)
End of the line.
Configuration file parser with flexible tokenization and search capabilities.
std::unique_ptr< QwParameterFile > ReadSectionPreamble()
Rewinds to the start and read until it finds next section header.
std::unique_ptr< QwParameterFile > ReadNextSection(std::string &secname, const bool keep_header=false)
void SetYield(const Double_t in)
void SetDifference(const Double_t in)
~PromptSummaryElement() override
void SetYieldWidth(const Double_t in)
void SetAsymmetryWidth(const Double_t in)
TString GetCSVSummary(TString type)
void SetYieldError(const Double_t in)
void SetAsymmetry(const Double_t in)
void SetDifferenceUnit(const TString in)
void Set(TString type, const Double_t a, const Double_t a_err, const Double_t a_width)
void SetAsymmetryUnit(const TString in)
void SetDifferenceError(const Double_t in)
void SetAsymmetryError(const Double_t in)
void FillData(Double_t yield, Double_t yield_err, Double_t yield_width, TString yield_unit, Double_t asym_diff, Double_t asym_diff_err, Double_t asym_diff_width, TString asym_diff_unit)
void SetDifferenceWidth(const Double_t in)
void SetYieldUnit(const TString in)
void FillDataInElement(TString name, Double_t yield, Double_t yield_err, Double_t yield_width, TString yield_unit, Double_t asym_diff, Double_t asym_diff_err, Double_t asym_diff_width, TString asym_diff_unit)
virtual ~QwPromptSummary()
TString PrintTextSummaryTailer()
PromptSummaryElement * fReferenceElement
void AddElement(PromptSummaryElement *in)
TString PrintTextSummaryHeader()
void FillDoubleDifference(TString type, TString name1, TString name2)
void LoadElementsFromParameterFile(const std::string ¶meter_file)
PromptSummaryElement * GetElementByName(TString name)
TString PrintCSVHeader(Int_t nEvents, TString start_time, TString end_time)
void FillYieldToElement(TString name, Double_t yield, Double_t yield_error, Double_t yield_width, TString yield_unit)
void FillAsymDiffToElement(TString name, Double_t asym_diff, Double_t asym_diff_err, Double_t asym_diff_width, TString asym_diff_unit)
void PrintCSV(Int_t nEvents, TString start_time, TString end_time)
std::map< TString, PromptSummaryElement * > fElementList