3#include <BmnFHCalEvent.h>
4#include <BmnHodoEvent.h>
12 : fRootFilePath(rootFilePath)
18 for (
auto& entry : fPDF) {
24 if (fBmnEventCentrality)
25 delete fBmnEventCentrality;
31 fpFairRootMgr = FairRootManager::Instance();
34 for (
auto& pdf : fPDF) {
44 std::string feature =
"FHCalEvent";
47 LOG(error) <<
"CentralityClusterizer::Init(): Failed to initialize Branch " << feature
48 <<
" ! Task will be deactivated.";
54 std::string feature =
"HodoEvent";
57 LOG(error) <<
"CentralityClusterizer::Init(): Failed to initialize Branch " << feature
58 <<
" ! Task will be deactivated.";
66 fpFairRootMgr->RegisterAny(
"EventCentrality", fBmnEventCentrality, kTRUE);
67 LOG(debug) <<
"CentralityClusterizer Reconstructor ready";
71void CentralityClusterizer::LoadHistograms()
74 std::string dir = getenv(
"VMCWORKDIR");
75 std::string path = dir +
"/parameters/centrality/";
77 fPdfFile =
new TFile((path + fRootFilePath).c_str(),
"READONLY");
78 TIter nextkey(fPdfFile->GetListOfKeys());
80 while ((key = (TKey*)nextkey())) {
82 TClass* cl = gROOT->GetClass(key->GetClassName());
83 if (!cl->InheritsFrom(
"TH1"))
86 std::string keyName(key->GetName());
88 if (std::regex_search(keyName, matches, fPattern) && matches.size() == 2) {
89 int cluster_id = std::stoi(matches[1]);
92 TH2F* hist = (TH2F*)fPdfFile->Get(keyName.c_str());
94 fPDF[cluster_id] = hist;
95 LOG(debug) << Form(
"CentralityClusterizer::LoadHistograms(): %s cluster %d entries %.0f",
96 keyName.c_str(), cluster_id, fPDF[cluster_id]->GetEntries());
99 if (cluster_id + 1 > fNumClusters)
100 fNumClusters = cluster_id + 1;
102 LOG(error) <<
"CentralityClusterizer::LoadHistograms(): Failed to retrieve histogram " << keyName;
107 LOG(error) <<
"CentralityClusterizer::LoadHistograms(): " << keyName <<
" No match found.";
116 LOG(debug2) <<
"Exec of CentralityClusterizer";
120 fBmnEventCentrality->
Reset();
122 float x = ((
BmnFHCalEvent*)fpFairRootMgr->GetObject(
"FHCalEvent"))->GetTotalEnergy();
123 float y = ((
BmnHodoEvent*)fpFairRootMgr->GetObject(
"HodoEvent"))->GetTotalSignal();
125 std::vector<float> prob(fNumClusters);
126 for (
auto& pdf : fPDF) {
127 auto cluster_id = pdf.first;
128 TH2F* hist = pdf.second;
130 LOG(error) <<
"CentralityClusterizer::Exec(): Failed to get histogram " << cluster_id;
135 if (x < hist->GetXaxis()->GetXmin() || x > hist->GetXaxis()->GetXmax() || y < hist->GetYaxis()->GetXmin()
136 || y > hist->GetYaxis()->GetXmax())
141 float probability = hist->Interpolate(x, y);
142 LOG(debug2) << Form(
"CentralityClusterizer::Exec(): value fhcal %.3f value_hodo %.3f cluster %d prob %.3f", x,
143 y, cluster_id, probability);
144 prob.at(cluster_id) = probability;
147 for (
int cluster_id = 0; cluster_id < fNumClusters; ++cluster_id) {
150 LOG(debug2) << Form(
"CentralityClusterizer::Exec(): class %d prob %.3f", fBmnEventCentrality->
GetClass(),
154 if (fBmnEventCentrality->
GetProbability() < std::numeric_limits<float>::epsilon()) {
155 fBmnEventCentrality->
Reset();
156 TVector2 this_event(x, y);
157 float min_distance = std::numeric_limits<float>::max();
159 for (
auto& pdf : fPDF) {
160 auto cluster_id = pdf.first;
161 TH2F* hist = pdf.second;
163 LOG(error) <<
"CentralityClusterizer::Exec(): Failed to get histogram " << cluster_id;
167 TVector2 centroid(hist->GetMean(1), hist->GetMean(2));
168 float distance = (this_event - centroid).Mod();
169 if (distance < min_distance) {
170 min_distance = distance;
171 candida = cluster_id;
178 fworkTime += sw.RealTime();
186 resultTree->Branch(
"EventCentrality", &fBmnEventCentrality);
192 printf(
"Work time of CentralityClusterizer: %4.2f sec.\n", fworkTime);
void SetCentrality(int cluster_id, float probability, BmnCentralityClass::Method method)
float GetProbability() const
Class for Bmn FHCal data container in event.
Class for Bmn Hodo data container in event.
CentralityClusterizer(const std::string &rootFilePath)
virtual ~CentralityClusterizer()
virtual void OnlineWrite(const std::unique_ptr< TTree > &resultTree)
Write task resul to tree.
virtual void Exec(Option_t *opt)
virtual InitStatus Init()