diff --git a/EventFiltering/CMakeLists.txt b/EventFiltering/CMakeLists.txt index 4f5ab9ed153..31cd58f40ed 100644 --- a/EventFiltering/CMakeLists.txt +++ b/EventFiltering/CMakeLists.txt @@ -108,10 +108,10 @@ o2physics_add_dpl_workflow(lf-f1proton-filter COMPONENT_NAME Analysis) o2physics_add_library(EventFilteringUtils - SOURCES Zorro.cxx - INSTALL_HEADERS ZorroHelper.h + SOURCES Zorro.cxx ZorroSummary.cxx + INSTALL_HEADERS ZorroHelper.h ZorroSummary.h PUBLIC_LINK_LIBRARIES O2::Framework O2Physics::AnalysisCore Arrow::arrow_shared) o2physics_target_root_dictionary(EventFilteringUtils - HEADERS ZorroHelper.h + HEADERS ZorroHelper.h ZorroSummary.h LINKDEF EventFilteringUtilsLinkDef.h) \ No newline at end of file diff --git a/EventFiltering/EventFilteringUtilsLinkDef.h b/EventFiltering/EventFilteringUtilsLinkDef.h index 61def8978aa..3f029b8aa9a 100644 --- a/EventFiltering/EventFilteringUtilsLinkDef.h +++ b/EventFiltering/EventFilteringUtilsLinkDef.h @@ -14,4 +14,5 @@ #pragma link off all functions; #pragma link C++ class ZorroHelper + ; +#pragma link C++ class ZorroSummary + ; #pragma link C++ class std::vector < ZorroHelper> + ; diff --git a/EventFiltering/Zorro.cxx b/EventFiltering/Zorro.cxx index a5c2a51133a..027861009d3 100644 --- a/EventFiltering/Zorro.cxx +++ b/EventFiltering/Zorro.cxx @@ -135,6 +135,13 @@ std::vector Zorro::initCCDB(o2::ccdb::BasicCCDBManager* ccdb, int runNumber for (size_t i{0}; i < mTOIs.size(); ++i) { LOGF(info, ">>> %s : %i", mTOIs[i].data(), mTOIidx[i]); } + mZorroSummary.setupTOIs(mTOIs.size(), tois); + std::vector toiCounters(mTOIs.size(), 0.); + for (size_t i{0}; i < mTOIs.size(); ++i) { + toiCounters[i] = mSelections->GetBinContent(mTOIidx[i] + 2); + } + mZorroSummary.setupRun(runNumber, mInspectedTVX->GetBinContent(1), toiCounters); + return mTOIidx; } @@ -174,6 +181,7 @@ bool Zorro::isSelected(uint64_t bcGlobalId, uint64_t tolerance) { uint64_t lastSelectedIdx = mLastSelectedIdx; fetch(bcGlobalId, tolerance); + bool retVal{false}; for (size_t i{0}; i < mTOIidx.size(); ++i) { if (mTOIidx[i] < 0) { continue; @@ -181,11 +189,12 @@ bool Zorro::isSelected(uint64_t bcGlobalId, uint64_t tolerance) mTOIcounts[i] += (lastSelectedIdx != mLastSelectedIdx); /// Avoid double counting if (mAnalysedTriggersOfInterest && lastSelectedIdx != mLastSelectedIdx) { mAnalysedTriggersOfInterest->Fill(i); + mZorroSummary.increaseTOIcounter(mRunNumber, i); } - return true; + retVal = true; } } - return false; + return retVal; } std::vector Zorro::getTriggerOfInterestResults(uint64_t bcGlobalId, uint64_t tolerance) diff --git a/EventFiltering/Zorro.h b/EventFiltering/Zorro.h index 2e5012da64f..5043eec232c 100644 --- a/EventFiltering/Zorro.h +++ b/EventFiltering/Zorro.h @@ -23,6 +23,7 @@ #include "CommonDataFormat/IRFrame.h" #include "Framework/HistogramRegistry.h" #include "ZorroHelper.h" +#include "ZorroSummary.h" namespace o2 { @@ -55,7 +56,11 @@ class Zorro void setBaseCCDBPath(std::string path) { mBaseCCDBPath = path; } void setBCtolerance(int tolerance) { mBCtolerance = tolerance; } + ZorroSummary* getZorroSummary() { return &mZorroSummary; } + private: + ZorroSummary mZorroSummary{"ZorroSummary", "ZorroSummary"}; + std::string mBaseCCDBPath = "Users/m/mpuccio/EventFiltering/OTS/"; int mRunNumber = 0; TH1* mAnalysedTriggers; /// Accounting for all triggers in the current run diff --git a/EventFiltering/ZorroSummary.cxx b/EventFiltering/ZorroSummary.cxx new file mode 100644 index 00000000000..ee241f49108 --- /dev/null +++ b/EventFiltering/ZorroSummary.cxx @@ -0,0 +1,69 @@ +// Copyright 2019-2020 CERN and copyright holders of ALICE O2. +// See https://alice-o2.web.cern.ch/copyright for details of the copyright holders. +// All rights not expressly granted are reserved. +// +// This software is distributed under the terms of the GNU General Public +// License v3 (GPL Version 3), copied verbatim in the file "COPYING". +// +// In applying this license CERN does not waive the privileges and immunities +// granted to it by virtue of its status as an Intergovernmental Organization +// or submit itself to any jurisdiction. + +#include "ZorroSummary.h" + +#include "TCollection.h" + +void ZorroSummary::Copy(TObject& c) const +{ + static_cast(c) = *this; +} + +Long64_t ZorroSummary::Merge(TCollection* list) +{ + if (!list) { + return 0; + } + int n = 1; + if (list->IsEmpty()) { + return n; + } + + for (auto* obj : *list) { + auto* entry = dynamic_cast(obj); + if (!entry || entry->getTOInames() != mTOInames) { + continue; + } + n++; + auto& analysedToiCounters = entry->getAnalysedTOIcounters(); + for (const auto& [runNumber, currentAnalysedToiCounters] : analysedToiCounters) { + if (mAnalysedTOIcounters.find(runNumber) == mAnalysedTOIcounters.end()) { + mAnalysedTOIcounters[runNumber] = currentAnalysedToiCounters; + mTVXcounters[runNumber] = entry->getTVXcounters().at(runNumber); + mTOIcounters[runNumber] = entry->getTOIcounters().at(runNumber); + } else { + auto& thisCounters = mAnalysedTOIcounters[runNumber]; + for (size_t i = 0; i < thisCounters.size(); ++i) { + thisCounters[i] += currentAnalysedToiCounters[i]; + } + } + } + } + return n; +} + +double ZorroSummary::getNormalisationFactor(int toiId) const +{ + double totalTOI{0.}, totalTVX{0.}; + ULong64_t totalAnalysedTOI{0}; + for (const auto& [runNumber, toiCounters] : mTOIcounters) { + totalTOI += toiCounters.at(toiId); + } + for (const auto& [runNumber, tvxCounters] : mTVXcounters) { + totalTVX += tvxCounters; + } + for (const auto& [runNumber, analysedTOIcounters] : mAnalysedTOIcounters) { + totalAnalysedTOI += analysedTOIcounters.at(toiId); + } + + return totalTVX * totalAnalysedTOI / totalTOI; +} \ No newline at end of file diff --git a/EventFiltering/ZorroSummary.h b/EventFiltering/ZorroSummary.h new file mode 100644 index 00000000000..b4d401adba4 --- /dev/null +++ b/EventFiltering/ZorroSummary.h @@ -0,0 +1,76 @@ +// Copyright 2019-2020 CERN and copyright holders of ALICE O2. +// See https://alice-o2.web.cern.ch/copyright for details of the copyright holders. +// All rights not expressly granted are reserved. +// +// This software is distributed under the terms of the GNU General Public +// License v3 (GPL Version 3), copied verbatim in the file "COPYING". +// +// In applying this license CERN does not waive the privileges and immunities +// granted to it by virtue of its status as an Intergovernmental Organization +// or submit itself to any jurisdiction. +// + +#ifndef EVENTFILTERING_ZORROSUMMARY_H_ +#define EVENTFILTERING_ZORROSUMMARY_H_ + +#include + +#include +#include +#include + +class ZorroSummary : public TNamed +{ + public: + ZorroSummary() = default; + ZorroSummary(const char* name, const char* objTitle) : TNamed(name, objTitle) {} + virtual ~ZorroSummary() = default; // NOLINT: Making this override breaks compilation for unknown reason + virtual void Copy(TObject& c) const; // NOLINT: Making this override breaks compilation for unknown reason + virtual Long64_t Merge(TCollection* list); + + void setupTOIs(int ntois, const std::string& toinames) + { + mNtois = ntois; + mTOInames = toinames; + } + void setupRun(int runNumber, double tvxCountes, const std::vector& toiCounters) + { + if (mRunNumber == runNumber) { + return; + } + mRunNumber = runNumber; + mTVXcounters[runNumber] = tvxCountes; + mTOIcounters[runNumber] = toiCounters; + if (mAnalysedTOIcounters.find(runNumber) == mAnalysedTOIcounters.end()) { + mAnalysedTOIcounters[runNumber] = std::vector(mNtois, 0ull); + } + mCurrentAnalysedTOIcounters = &mAnalysedTOIcounters[runNumber]; + } + double getNormalisationFactor(int toiId) const; + void increaseTOIcounter(int runNumber, int toiId) + { + if (runNumber != mRunNumber) { + return; + } + mCurrentAnalysedTOIcounters->at(toiId)++; + } + + std::string getTOInames() const { return mTOInames; } + const auto& getTOIcounters() const { return mTOIcounters; } + const auto& getTVXcounters() const { return mTVXcounters; } + const auto& getAnalysedTOIcounters() const { return mAnalysedTOIcounters; } + + private: + int mRunNumber = 0; //! Run currently being analysed + std::vector* mCurrentAnalysedTOIcounters = nullptr; //! Analysed TOI counters for the current run + + int mNtois = 0; + std::string mTOInames; + std::unordered_map> mAnalysedTOIcounters; + std::unordered_map> mTOIcounters; + std::unordered_map mTVXcounters; + + ClassDef(ZorroSummary, 1); +}; + +#endif // EVENTFILTERING_ZORROSUMMARY_H_ \ No newline at end of file diff --git a/PWGLF/TableProducer/Nuspex/nucleiSpectra.cxx b/PWGLF/TableProducer/Nuspex/nucleiSpectra.cxx index 9dae9bf2e1c..1e8fdfd22cd 100644 --- a/PWGLF/TableProducer/Nuspex/nucleiSpectra.cxx +++ b/PWGLF/TableProducer/Nuspex/nucleiSpectra.cxx @@ -45,6 +45,7 @@ #include "DetectorsBase/Propagator.h" #include "EventFiltering/Zorro.h" +#include "EventFiltering/ZorroSummary.h" #include "Framework/AnalysisDataModel.h" #include "Framework/AnalysisTask.h" @@ -232,6 +233,7 @@ struct nucleiSpectra { Produces nucleiTableFlow; Service ccdb; Zorro zorro; + OutputObj zorroSummary{"zorroSummary"}; TrackTuner trackTunerObj; Configurable cfgCompensatePIDinTracking{"cfgCompensatePIDinTracking", false, "If true, divide tpcInnerParam by the electric charge"}; @@ -370,6 +372,7 @@ struct nucleiSpectra { void init(o2::framework::InitContext&) { + zorroSummary.setObject(zorro.getZorroSummary()); ccdb->setURL(cfgCCDBurl); ccdb->setCaching(true); ccdb->setLocalObjectValidityChecking();