CbmRoot
Loading...
Searching...
No Matches
CbmMatchEvents.cxx
Go to the documentation of this file.
1/* Copyright (C) 2020-2021 Physikalisches Institut, Eberhard Karls Universität Tuebingen, Tuebingen
2 SPDX-License-Identifier: GPL-3.0-only
3 Authors: Viktor Klochkov [committer] */
4
5#include "CbmMatchEvents.h"
6
7#include "CbmEvent.h"
8#include "CbmMCDataManager.h"
9#include "CbmTrackMatchNew.h"
10
11#include <FairRootManager.h>
12#include <Logger.h>
13
14#include "TClonesArray.h"
15
16#include "AnalysisTree/TaskManager.hpp"
17
18//ClassImp(CbmMatchEvents);
19
21{
22 auto* ioman = FairRootManager::Instance();
23 cbm_sts_match_ = (TClonesArray*) ioman->GetObject("StsTrackMatch");
24}
25
27{
28 if (!event) { throw std::runtime_error("No event to match"); }
29
30 LOG(info) << "Event: " << event->GetNumber() << " t_start = " << event->GetStartTime()
31 << " t_end = " << event->GetEndTime() << " Msts = " << event->GetNofStsTracks();
32
33 count_map_.clear();
34
35 const int n_sts_tracks = event->GetNofStsTracks();
36 for (short i_track = 0; i_track < n_sts_tracks; ++i_track) {
37 const auto track_index = event->GetStsTrackIndex(i_track);
38
39 auto* match = (CbmTrackMatchNew*) cbm_sts_match_->At(track_index);
40 if (match->GetNofLinks() == 0) { continue; }
41
42 const auto& link = match->GetMatchedLink();
43 auto file = link.GetFile();
44 auto entry = link.GetEntry();
45
46 count_map_[{file, entry}]++;
47 }
48 // TODO remove later if not needed
49 // using pair_type = decltype(count_map_)::value_type;
50 // auto matched_event = std::max_element(count_map_.begin(), count_map_.end(),
51 // [](const pair_type& a, const pair_type& b) -> bool{ return a.second < b.second; } );
52
53 auto match_event = new CbmMatch();
54
55 int i {0};
56 for (const auto& match : count_map_) {
57 auto weight = float(match.second) / n_sts_tracks;
58 match_event->AddLink(weight, i++, match.first.entry, match.first.file);
59 LOG(info) << " matched to " << match.first.entry << " " << match.second << " weight = " << weight;
60 }
61
62 if (match_event->GetNofLinks() > 0) event->SetMatch(match_event);
63}
Class characterising one event by a collection of links (indices) to data objects,...
Definition CbmEvent.h:34
std::map< EventId, int > count_map_
TClonesArray * cbm_sts_match_
non-owning pointer
void ProcessData(CbmEvent *event) final
void Init() final