14 #include <boost/algorithm/string.hpp>
51 _histograms{
new Histos{_containers.get()}},
52 _builder{
new flatbuffers::FlatBufferBuilder{16*1024*1024}},
53 _event{
new Event{_histograms.get(), _containers.get()}} {
55 this->setSettingsHandler(*_settings);
56 _histograms->setSettingsHandler(*_settings);
57 _event->setSettingsHandler(*_settings);
58 _containers->setSettingsHandler(*_settings);
63 Hammer::~Hammer() noexcept {
68 void Hammer::initEvent(
double weight) {
70 if(
_histograms->isValidHistogram(
"Total Sum of Weights", 1)){
73 if(!
isZero(weight - 1.0)) {
74 _event->setEventBaseWeight(weight);
79 return _event->addProcess(p);
82 void Hammer::removeProcess(
size_t id) {
86 void Hammer::setEventHistogramBin(
const string& name,
const IndexList& bins) {
87 _event->setHistogramBin(name, bins);
90 void Hammer::fillEventHistogram(
const string& name,
const vector<double>& values) {
96 void Hammer::setEventBaseWeight(
double weight) {
97 if(!
isZero(weight - 1.0)) {
98 _event->setEventBaseWeight(weight);
102 bool Hammer::loadEventWeights(
IOBuffer& buffer,
bool merge) {
104 const Serial::FBEvent* buf = flatbuffers::GetRoot<Serial::FBEvent>(buffer.
start);
105 if (buf !=
nullptr) {
106 return _event->read(buf, merge);
109 MSG_ERROR(
"Invalid event record on read!");
123 bool Hammer::loadRunHeader(
IOBuffer& buffer,
bool merge) {
125 const Serial::FBHeader* buf = flatbuffers::GetRoot<Serial::FBHeader>(buffer.
start);
126 if (buf !=
nullptr) {
127 bool result =
_settings->read(buf, merge);
132 MSG_ERROR(
"Invalid header record on read!");
146 string Hammer::loadHistogramDefinition(
IOBuffer& buffer,
bool merge) {
148 const Serial::FBHistoDefinition* buf = flatbuffers::GetRoot<Serial::FBHistoDefinition>(buffer.
start);
149 if (buf !=
nullptr) {
153 MSG_ERROR(
"Invalid histogram record on read!");
159 const Serial::FBHistogram* buf = flatbuffers::GetRoot<Serial::FBHistogram>(buffer.
start);
160 if (buf !=
nullptr) {
164 MSG_ERROR(
"Invalid histogram record on read!");
168 IOBuffers Hammer::saveHistogram(
const string& name)
const {
174 for (
auto& schemeName :
_containers->schemeDefs().getFFSchemeNames()) {
175 for (
auto& eventIDs :
_histograms->getEventIDRepsForHisto(name, schemeName)) {
185 IOBuffers Hammer::saveHistogram(
const string& name,
const string& scheme)
const {
191 for(
auto& eventIDs:
_histograms->getEventIDRepsForHisto(name, scheme)) {
196 if(resultVec->size() == 1) {
197 MSG_ERROR(
"No scheme '" + scheme +
"' present for histogram '" + name +
"'. Only definition will be saved.");
209 for (
auto& schemeName :
_containers->schemeDefs().getFFSchemeNames()) {
214 if(resultVec->size() == 1) {
215 string groupId =
"[ ";
216 for(
auto& elem: eventIDs) {
218 for(
auto& elem2: elem) {
219 groupId += to_string(elem2) +
" ";
224 MSG_ERROR(
"No event ID " + groupId +
"present for histogram '" + name +
"'. Only definition will be saved.");
239 if (resultVec->size() == 1) {
240 string groupId =
"[ ";
241 for (
auto& elem : eventIDs) {
243 for (
auto& elem2 : elem) {
244 groupId += to_string(elem2) +
" ";
249 MSG_ERROR(
"No event ID " + groupId +
"/ scheme '" + scheme +
"' combination present for histogram '" + name +
250 "'. Only definition will be saved.");
260 else if(info.
scheme.size() > 0) {
271 bool Hammer::loadRates(
IOBuffer& buffer,
bool merge) {
273 const Serial::FBRates* buf = flatbuffers::GetRoot<Serial::FBRates>(buffer.
start);
274 if (buf !=
nullptr) {
278 MSG_ERROR(
"Invalid rate record on read!");
292 void Hammer::processEvent() {
293 if(
isOn(
"CalcProcesses")) {
301 void Hammer::readCards(
const string& fileDecays,
const string& fileOptions) {
306 void Hammer::saveOptionCard(
const string& fileOptions,
bool useDefault)
const {
307 _settings->saveSettings(fileOptions, useDefault);
310 void Hammer::saveHeaderCard(
const string& fileDecays)
const {
314 void Hammer::saveReferences(
const std::string& fileRefs)
const {
318 void Hammer::setOptions(
const string& options) {
322 void Hammer::setHeader(
const string& options) {
326 void Hammer::initRun() {
333 void Hammer::addTotalSumOfWeights(
const bool compress,
const bool witherrors){
339 void Hammer::addHistogram(
const string& name,
const IndexList& binSizes,
bool hasUnderOverFlow,
340 const vector<pair<double, double>>& ranges) {
341 _histograms->addHistogramDefinition(name, binSizes, hasUnderOverFlow, ranges);
344 void Hammer::addHistogram(
const string& name,
const vector<vector<double>>& binEdges,
345 bool hasUnderOverFlow) {
346 _histograms->addHistogramDefinition(name, binEdges, hasUnderOverFlow);
349 void Hammer::keepErrorsInHistogram(
const string& name,
bool value) {
353 void Hammer::collapseProcessesInHistogram(
const string& name) {
357 void Hammer::specializeWCInWeights(
const string& process,
const vector<complex<double>>& values){
358 _containers->externalData().specializeWCInWeights(process, values);
361 void Hammer::specializeWCInWeights(
const string& process,
const map<
string, complex<double>>& settings){
362 _containers->externalData().specializeWCInWeights(process, settings);
365 void Hammer::resetSpecializeWCInWeights(
const string& process){
366 _containers->externalData().resetSpecializeWCInWeights(process);
369 void Hammer::specializeWCInHistogram(
const string& name,
const string& process,
370 const vector<complex<double>>& values) {
371 auto data =
_containers->externalData().getTempWilsonCoefficients(process, values);
375 void Hammer::specializeWCInHistogram(
const string& name,
const string& process,
376 const map<
string, complex<double>>& settings) {
377 auto data =
_containers->externalData().getTempWilsonCoefficients(process, settings);
381 void Hammer::specializeFFInHistogram(
const string& name,
const string& process,
const string& group,
382 const vector<double>& values) {
383 auto data =
_containers->externalData().getTempFFEigenVectors({process, group}, values);
387 void Hammer::specializeFFInHistogram(
const string& name,
const string& process,
const string& group,
388 const map<string, double>& settings) {
389 auto data =
_containers->externalData().getTempFFEigenVectors({process, group}, settings);
393 void Hammer::resetSpecializationInHistogram(
const string& name) {
397 void Hammer::createProjectedHistogram(
const string& oldName,
const string& newName,
398 const set<uint16_t>& collapsedIndexPositions) {
399 _histograms->createProjectedHistogram(oldName, newName, collapsedIndexPositions);
403 void Hammer::removeHistogram(
const string& name) {
407 void Hammer::addFFScheme(
const string& schemeName,
const map<string, string>& schemes) {
408 _containers->schemeDefs().addFFScheme(schemeName, schemes);
411 void Hammer::setFFInputScheme(
const map<string, string>& schemes) {
412 _containers->schemeDefs().setFFInputScheme(schemes);
415 void Hammer::removeFFScheme(
const string& schemeName) {
416 _containers->schemeDefs().removeFFScheme(schemeName);
419 vector<string> Hammer::getFFSchemeNames()
const {
420 return _containers->schemeDefs().getFFSchemeNames();
423 void Hammer::includeDecay(
const vector<string>& names) {
424 _containers->processDefs().addIncludedDecay(names);
427 void Hammer::includeDecay(
const string& name) {
428 _containers->processDefs().addIncludedDecay({name});
431 void Hammer::forbidDecay(
const vector<string>& names) {
432 _containers->processDefs().addForbiddenDecay(names);
435 void Hammer::forbidDecay(
const string& name) {
436 _containers->processDefs().addForbiddenDecay({name});
439 void Hammer::addPurePSVertices(
const set<string>& vertices,
WTerm what) {
440 _containers->purePSDefs().addPurePhaseSpaceVertices(vertices, what);
443 void Hammer::clearPurePSVertices(
WTerm what) {
444 _containers->purePSDefs().clearPurePhaseSpaceVertices(what);
447 void Hammer::setUnits(
string name) {
448 _settings->changeSetting<
string>(
"Hammer",
"Units", name);
450 _mcunits = units.getUnitsRescalingToMC(name,
"GeV");
453 void Hammer::defineSettings() {
455 addSetting<bool>(
"CalcHistograms",
true);
456 addSetting<bool>(
"CalcProcesses",
true);
457 addSetting<string>(
"Units",
"GeV");
460 Log& Hammer::getLog()
const {
464 void Hammer::setWilsonCoefficients(
const string& process,
const vector<complex<double>>& values,
WTerm what) {
465 _containers->externalData().setWilsonCoefficients(process, values, what);
468 void Hammer::setWilsonCoefficients(
const string& process,
const map<
string, complex<double>>& values,
WTerm what) {
469 _containers->externalData().setWilsonCoefficients(process, values, what);
472 void Hammer::setWilsonCoefficientsLocal(
const string& process,
const vector<complex<double>>& values) {
473 _containers->externalData().setWilsonCoefficientsLocal(process, values);
476 void Hammer::setWilsonCoefficientsLocal(
const string& process,
const map<
string, complex<double>>& values) {
477 _containers->externalData().setWilsonCoefficientsLocal(process, values);
480 void Hammer::resetWilsonCoefficients(
const string& process,
WTerm what) {
481 _containers->externalData().resetWilsonCoefficients(process, what);
484 void Hammer::setFFEigenvectors(
const string& process,
const string& group,
const vector<double>& values) {
486 if(
_containers->providers().checkFFPrefixAndGroup(tmp)) {
487 _containers->externalData().setFFEigenVectors(tmp, values);
491 void Hammer::setFFEigenvectors(
const string& process,
const string& group,
const map<string, double>& settings) {
493 if(
_containers->providers().checkFFPrefixAndGroup(tmp)) {
494 _containers->externalData().setFFEigenVectors(tmp, settings);
498 void Hammer::setFFEigenvectorsLocal(
const string& process,
const string& group,
const vector<double>& values) {
500 if (
_containers->providers().checkFFPrefixAndGroup(tmp)) {
501 _containers->externalData().setFFEigenVectorsLocal(tmp, values);
505 void Hammer::setFFEigenvectorsLocal(
const string& process,
const string& group,
const map<string, double>& settings) {
507 if (
_containers->providers().checkFFPrefixAndGroup(tmp)) {
508 _containers->externalData().setFFEigenVectorsLocal(tmp, settings);
512 void Hammer::resetFFEigenvectors(
const string& process,
const string& group) {
514 if (
_containers->providers().checkFFPrefixAndGroup(tmp)) {
515 _containers->externalData().resetFFEigenVectors(tmp);
519 double Hammer::getWeight(
const string& scheme,
const vector<size_t>& processes)
const {
520 auto tempProcesses = processes;
521 if(tempProcesses.size() == 0) {
522 copy(
_event->getEventId().begin(),
_event->getEventId().end(), back_inserter(tempProcesses));
524 double result =
_event->getEventBaseWeight();
525 for(
auto elem: tempProcesses) {
527 result *=
_event->getWeight(scheme, elem);
530 MSG_ERROR(
"Weight not found: " << err.what() <<
". Skipping");
537 double Hammer::getWeight(
const string& scheme,
const vector<vector<string>>& processes)
const {
538 const auto procIdSet =
_containers->processDefs().decayStringsToProcessIds(processes);
539 const vector<HashId> processesId(procIdSet.begin(), procIdSet.end());
543 map<size_t, double> Hammer::getWeights(
const string& scheme)
const {
544 return _event->getWeights(scheme);
547 double Hammer::getRate(
const HashId& vertexid,
const string& scheme)
const {
551 double Hammer::getRate(
const PdgId& parent,
const vector<PdgId>& daughters,
const string& scheme)
const {
558 double Hammer::getRate(
const string& vertex,
const string& scheme)
const {
561 if (vertexid.size() == 1){
564 MSG_ERROR(
"Vertex string does not correspond to a (charge) unique process. ");
569 double Hammer::getDenominatorRate(
const HashId& vertexid)
const {
570 return getRate(vertexid,
"Denominator");
573 double Hammer::getDenominatorRate(
const PdgId& parent,
const vector<PdgId>& daughters)
const {
574 return getRate(parent, daughters,
"Denominator");
577 double Hammer::getDenominatorRate(
const string& vertex)
const {
578 return getRate(vertex,
"Denominator");
582 IOHistogram Hammer::getHistogram(
const string& name,
const string& scheme)
const {
590 EventUIDGroup Hammer::getHistogramEventIds(
const string& name,
const string& scheme)
const {
591 return _histograms->getHistogramEventIds(name, scheme);
594 vector<vector<double>> Hammer::getHistogramBinEdges(
const string& name)
const {
598 IndexList Hammer::getHistogramShape(
const string& name)
const {
602 bool Hammer::histogramHasUnderOverFlows(
const string& name)
const {
608 unique_ptr<TH1D> Hammer::getHistogram1D(
const string& name,
const string& scheme)
const {
612 unique_ptr<TH2D> Hammer::getHistogram2D(
const string& name,
const string& scheme)
const {
616 unique_ptr<TH3D> Hammer::getHistogram3D(
const string& name,
const string& scheme)
const {
620 EventIdGroupDict<unique_ptr<TH1D>> Hammer::getHistograms1D(
const string& name,
const string& scheme)
const {
624 EventIdGroupDict<unique_ptr<TH2D>> Hammer::getHistograms2D(
const string& name,
const string& scheme)
const {
628 EventIdGroupDict<unique_ptr<TH3D>> Hammer::getHistograms3D(
const string& name,
const string& scheme)
const {
632 void Hammer::setHistogram1D(
const string& name,
const string& scheme, TH1D& histogram)
const {
633 _histograms->setHistogram1D(name, scheme, histogram);
636 void Hammer::setHistogram2D(
const string& name,
const string& scheme, TH2D& histogram)
const {
637 _histograms->setHistogram2D(name, scheme, histogram);
640 void Hammer::setHistogram3D(
const string& name,
const string& scheme, TH3D& histogram)
const {
641 _histograms->setHistogram3D(name, scheme, histogram);
644 void Hammer::setHistograms1D(
const string& name,
const string& scheme,
646 _histograms->setHistograms1D(name, scheme, histograms);
649 void Hammer::setHistograms2D(
const string& name,
const string& scheme,
651 _histograms->setHistograms2D(name, scheme, histograms);
654 void Hammer::setHistograms3D(
const string& name,
const string& scheme,
656 _histograms->setHistograms3D(name, scheme, histograms);
PDG codes to UID functions.
std::vector< PdgId > combineDaughters(const std::vector< PdgId > &daughters, const std::vector< PdgId > &subDaughters)
combine list of codes of daughters and grandaughters (for processes which parameterise two subsequent...
std::vector< HashId > expandToValidVertexUIDs(const std::string &name, const bool &hadOnly=false) const
void collapseProcessesInHistogram(const std::string &name)
void setPath(const std::string &path)
provide the basic path for the settings defined by this class, as in "<path>:<setting>" ...
Container class for values of WC and FF vectors.
void addHistogram(const std::string &name, const std::vector< uint16_t > &binSizes, bool hasUnderOverFlow=true, const std::vector< std::pair< double, double >> &ranges={})
Adds a tensor histogram.
std::vector< BinContents > IOHistogram
Container class for storing included/forbidden process info.
std::set< EventUID > EventUIDGroup
static void resetWarningCounters()
reset the warning counters for all loggers
Hammer class for dealing with units.
Interface class for amplitudes, rates, FFs dictionary container.
Message logging routines.
Hammer base amplitude class.
Hammer settings manager class.
double getWeight(const std::string &scheme, const std::vector< size_t > &processes={}) const
Hammer histogram manager.
static Log & getLog(const std::string &name)
Get a logger with the given name.
std::unique_ptr< SettingsHandler > _settings
std::vector< IndexType > IndexList
void setEventHistogramBin(const std::string &name, const std::vector< uint16_t > &bins)
static Units & instance()
std::unique_ptr< Event > _event
UMap< EventUIDGroup, T > EventIdGroupDict
Hammer class for dealing with particle data.
Container class for pure phase space vertices definitions.
bool isZero(const std::complex< double > val)
Container class for all process related data structures.
std::unique_ptr< DictionaryManager > _containers
void keepErrorsInHistogram(const std::string &name, bool value=true)
Hammer particle data class.
Container class for Scheme Definitions.
Hammer settings manager class.
std::unique_ptr< Histos > _histograms
std::unique_ptr< flatbuffers::FlatBufferBuilder > _builder
HashId processID(PdgId parent, const std::vector< PdgId > &allDaughters)
compute a unique ID for a given process based on the PDG codes of the parent particle and the ordered...
std::set< std::set< size_t > > eventGroupId
bool isOn(const std::string &name) const
method to check a boolean setting defined by this class
Container class for process rate tensors.
Hammer available modules header.
Out-of-range error class.
Serialization related typedefs and includes.
double getRate(const HashId &id, const std::string &scheme) const
Global container class for amplitudes, rates, FFs, data.
IOBuffers saveHistogram(const std::string &name) const