CbmRoot
Loading...
Searching...
No Matches
CbmTaskTrdHitFinder.cxx
Go to the documentation of this file.
1/* Copyright (C) 2010-2021 GSI Helmholtzzentrum fuer Schwerionenforschung, Darmstadt
2 SPDX-License-Identifier: GPL-3.0-only
3 Authors: Florian Uhlig [committer], Pascal Raisig, Alexandru Bercuci */
4
6
7#include "CbmDigiManager.h"
8
9#include <FairRootManager.h>
10#include <FairRunAna.h>
11#include <FairRuntimeDb.h>
12#include <Logger.h>
13
14// C++ Classes and includes
15#include "compat/Filesystem.h"
16#include "yaml/Yaml.h"
17
18#include <TStopwatch.h>
19#include <TVector3.h>
20
21#include <cmath>
22#include <iomanip>
23#include <iostream>
24
25using std::fixed;
26using std::left;
27using std::right;
28using std::setprecision;
29using std::setw;
30using std::stringstream;
31
32//_____________________________________________________________________
33CbmTaskTrdHitFinder::CbmTaskTrdHitFinder() : FairTask("TrdClusterFinder", 1) {}
34
35// ---- Destructor ----------------------------------------------------
37{
38 if (fClusters) {
39 fClusters->clear();
40 delete fClusters;
41 }
42 if (fHits) {
43 fHits->clear();
44 delete fHits;
45 }
46}
47
48//_____________________________________________________________________
50{
51 // FairRuntimeDb* rtdb = FairRunAna::Instance()->GetRuntimeDb();
52}
53
54//_____________________________________________________________________
56{
58 if (!CbmDigiManager::Instance()->IsPresent(ECbmModuleId::kTrd)) LOG(fatal) << GetName() << "Missing Trd digi branch.";
59
60 fClusters = new std::vector<CbmTrdCluster>();
61 FairRootManager* ioman = FairRootManager::Instance();
62 ioman->RegisterAny("TrdCluster", fClusters, true);
63
64 fHits = new std::vector<CbmTrdHit>();
65 ioman->RegisterAny("TrdHit", fHits, true);
66
67 // Read hitfinder parameters and initialize algo
68 fAlgo = std::make_unique<cbm::algo::trd::Hitfind>(
71
72 return kSUCCESS;
73}
74
75//_____________________________________________________________________
76void CbmTaskTrdHitFinder::Exec(Option_t* /*option*/)
77{
78 fClusters->clear();
79 fHits->clear();
80
81 TStopwatch timerTs;
82 timerTs.Start();
83
84 std::vector<CbmTrdDigi> digiVec;
85
86 for (int32_t iDigi = 0; iDigi < CbmDigiManager::Instance()->GetNofDigis(ECbmModuleId::kTrd); iDigi++) {
87 const CbmTrdDigi* tDigi = CbmDigiManager::Instance()->Get<CbmTrdDigi>(iDigi);
88 digiVec.push_back(CbmTrdDigi(*tDigi));
89 }
90
91 auto [hits, monitor] = (*fAlgo)(digiVec);
92 AddHits(hits.Data());
93
94 timerTs.Stop();
95 fProcessTime += timerTs.RealTime();
96
97 stringstream logOut;
98 logOut << setw(20) << left << GetName() << " [";
99 logOut << fixed << setw(8) << setprecision(1) << right << timerTs.RealTime() * 1000. << " ms] ";
100 logOut << "TS " << fNrTs;
101 LOG(info) << logOut.str();
102}
103
104
105//_____________________________________________________________________
106void CbmTaskTrdHitFinder::AddHits(gsl::span<cbm::algo::trd::Hit> hits)
107{
108 for (auto& hit : hits) {
109 TVector3 pos(hit.X(), hit.Y(), hit.Z());
110 TVector3 dpos(hit.Dx(), hit.Dy(), hit.Dz());
111
112 CbmTrdHit& hitSave =
113 fHits->emplace_back(hit.Address(), pos, dpos, hit.Dxy(), hit.GetRefId(), hit.GetELoss(), hit.Time(),
114 hit.TimeError()); // TODO implement copy constructor
115 hitSave.SetOverFlow(hit.HasOverFlow());
116 hitSave.SetRowCross(hit.IsRowCross());
117 hitSave.SetClassType(hit.GetClassType());
118 hitSave.SetMaxType(hit.GetMaxType());
119 }
120}
121
122
123//_____________________________________________________________________
125{
126 std::cout << std::endl;
127 LOG(info) << "=====================================";
128 LOG(info) << GetName() << ": Finish run";
129 LOG(info) << GetName() << ": Run summary ";
130 LOG(info) << GetName() << ": Processing time : " << std::fixed << std::setprecision(3) << fProcessTime;
131 LOG(info) << GetName() << ": Nr of events : " << fNrEvents;
132 LOG(info) << GetName() << ": Nr of input digis : " << fNrDigis;
133 LOG(info) << GetName() << ": Nr of produced clusters : " << fNrClusters;
134 LOG(info) << GetName() << ": Nr of clusters / event : " << std::fixed << std::setprecision(2)
135 << (fNrEvents > 0 ? fNrClusters / (Double_t) fNrEvents : 0);
136 LOG(info) << GetName() << ": Nr of digis / cluster : " << std::fixed << std::setprecision(2)
137 << (fNrClusters > 0 ? fNrDigis / (Double_t) fNrClusters : 0);
138 LOG(info) << "=====================================";
139
140 LOG(info) << GetName() << ": Nr of events : " << fNrEvents;
141 LOG(info) << GetName() << ": Nr of input clusters : " << fNrClusters;
142 LOG(info) << GetName() << ": Nr of produced hits : " << fNrHits;
143 LOG(info) << GetName() << ": Nr of hits / event : " << std::fixed << std::setprecision(2)
144 << (fNrEvents > 0 ? fNrHits / (Double_t) fNrEvents : 0);
145 LOG(info) << GetName() << ": Nr of hits / clusters: " << std::fixed << std::setprecision(2)
146 << (fNrClusters > 0 ? fNrHits / (Double_t) fNrClusters : 0);
147 LOG(info) << "=====================================";
148 std::cout << std::endl;
149}
150
ClassImp(CbmConverterManager)
@ kTrd
Transition Radiation Detector.
TVector3 dpos
static vector< vector< QAHit > > hits
static Int_t GetNofDigis(ECbmModuleId systemId)
InitStatus Init()
Initialisation.
const Digi * Get(Int_t index) const
Get a digi object.
static CbmDigiManager * Instance()
Static instance.
UInt_t fNrClusters
Number of produced clusters.
virtual void SetParContainers()
std::vector< CbmTrdHit > * fHits
Output array of CbmTrdHit.
~CbmTaskTrdHitFinder()
Default destructor.
std::unique_ptr< cbm::algo::trd::Hitfind > fAlgo
Hit finding algorithm.
virtual InitStatus Init()
std::vector< CbmTrdCluster > * fClusters
void AddHits(gsl::span< cbm::algo::trd::Hit > hits)
CbmTaskTrdHitFinder()
Default constructor.
Float_t fProcessTime
Total processing time [RealTime].
virtual void Exec(Option_t *option)
Executed task.
UInt_t fNrHits
Number of produced hits.
UInt_t fNrEvents
Number of processed events (without CbmEvent corresponds to nr of exec calls)
UInt_t fNrTs
Number of processed time slices.
UInt_t fNrDigis
Number of digis as input for the hit production.
data class for a reconstructed Energy-4D measurement in the TRD
Definition CbmTrdHit.h:40
void SetClassType(bool set=true)
Type of pad layout used in reconstruction R[0], T[1].
Definition CbmTrdHit.h:93
void SetOverFlow(bool set=true)
Mark overflow in one or more digits which define the hit.
Definition CbmTrdHit.h:89
void SetMaxType(bool set=true)
Extra bool definition for the hit (e.g. the type of maximum for triangular pads).
Definition CbmTrdHit.h:95
void SetRowCross(bool set=true)
Mark hit reconstructed between pad rows.
Definition CbmTrdHit.h:91
T ReadFromFile(fs::path path)
Definition Yaml.h:51