CbmRoot
Loading...
Searching...
No Matches
CbmRecoQaTask.h
Go to the documentation of this file.
1/* Copyright (C) 2024-2026 Hulubei National Institute of Physics and Nuclear Engineering - Horia Hulubei, Bucharest
2 SPDX-License-Identifier: GPL-3.0-only
3 Authors: Alexandru Bercuci [committer], Omveer Singh */
4
5#ifndef CBMRECOQATASK_H
6#define CBMRECOQATASK_H 1
7
8#include "CbmKfTrackFitter.h"
9#include "CbmTrack.h"
10
11#include <FairTask.h>
12
13#include <TDirectoryFile.h>
14#include <TGeoNode.h>
15
16#include <bitset>
17#include <map>
18#include <vector>
19
20class FairMCPoint;
21class CbmCluster;
22class CbmEvent;
23class CbmHit;
25class CbmMCDataArray;
26class CbmTimeSlice;
27class TClonesArray;
28class TH1;
29class TVector3;
30class CbmRecoQaTask : public FairTask {
31 public:
54 enum class eViewType : int
55 {
59 };
60
61#define kNtrkProjections 6
103
105 public:
108
109 static int GetPlaneId(const Node& node) { return node.userReferences[3]; }
110 static void SetPlaneId(Node& node, int planeId) { node.userReferences[3] = planeId; }
111 void SetPlaneId(size_t inode, int planeId) { SetPlaneId(fNodes[inode], planeId); }
112 };
113
114 // Generic view definition
115 struct Detector;
116 struct View {
117 friend struct Detector;
118 friend class CbmRecoQaTask;
119
120 View() = default;
121 View(const char* n, const char* p, std::vector<int> set) : name(n), path(p), fSelector(set) { ; }
122 virtual ~View() = default;
123 bool SetProjection(eProjectionType prj, float range, const char* unit);
124 template<class Hit>
125 bool HasAddress(const CbmHit* h, double& x, double& y, double& dx, double& dy) const;
126 template<class Hit>
127 bool Load(const CbmHit* h, const FairMCPoint* point, const CbmEvent* ev);
135 bool Load(const Trajectory::Node* n, const FairMCPoint* point, const int dinfo = 0xab00);
136 bool Load(TVector3* p, TVector3* pe = nullptr);
137 std::string ToString() const;
138 static std::string ToString(eProjectionType prj);
139 void SetSetup(CbmRecoQaTask::eSetup setup) { fSetup = setup; }
141
142 std::string name = "";
143 std::string path = "";
144 double size[3] = {0.};
145 double pos[3] = {0.};
146 std::vector<int> fSelector = {};
147 std::map<eProjectionType, std::tuple<int, float, TH1*>> fProjection =
148 {};
149
151 int fMult = 0;
154
155 protected:
156 bool AddProjection(eProjectionType prj, float range = -1, const char* unit = "cm");
157 bool HasDebug() const;
162 bool Init(const char* dname, bool mc = false);
165 uint Register(TDirectoryFile* f);
171 std::string makeTrange(const int scale, float& range);
172 std::string makeYrange(const int scale, float& range);
174 1); // Stand-alone detection set to which QA is applied
175 }; // QA View definition
176
177 // Detector unit definition
178 struct Detector {
179 struct Data {
180 Data() = default;
181 Data(ECbmDataType i, const char* n) : id(i), name(n) { ; }
183 std::string name = "nn";
184 }; // Identifier of data to be monitored
185
187 virtual ~Detector() = default;
188 View* AddView(const char* n, const char* p, std::vector<int> set, bool debug = false);
189 View* GetView(const char* n);
190 View* FindView(double x, double y, double z);
195 bool Init(TDirectoryFile* f, bool mc = false);
196 void Print() const;
197
200 std::vector<View> fViews = {};
201
203 1); // QA representation of a detector unit
204 }; // Detection system agregate
205
212 static constexpr size_t projSz = 4;
213 static constexpr size_t stsSz = 3;
214 static constexpr size_t tofSz = 3;
215 static constexpr size_t trdSz = 7;
216 struct TrackFilter;
217 struct TopoFilter {
218 friend struct TrackFilter;
220 virtual ~TopoFilter() = default;
221 template<ECbmModuleId d>
222 bool Accept(const CbmHit* h, const CbmCluster* c0 = nullptr, const CbmCluster* c1 = nullptr) const;
223
224 protected:
225 std::vector<std::vector<int>> fAccept = {};
226 std::vector<std::vector<int>> fReject =
227 {};
228 std::vector<std::array<float, projSz>> fRef = {};
229 ClassDef(CbmRecoQaTask::TopoFilter, 1); // Topological cuts for hits/track
230 };
231
232 struct TrackFilter {
234 virtual ~TrackFilter() = default;
235 bool Accept(const CbmGlobalTrack* ptr, const CbmRecoQaTask* lnk) const;
237 bool AddCondAccept(std::vector<int> cuts) { return AddTopoCut(cuts, 'a'); }
238 bool AddCondReject(std::vector<int> cuts) { return AddTopoCut(cuts, 'r'); }
240 const std::vector<std::vector<int>>& GetAcceptCuts() const { return fHitsFilter.fAccept; }
241 const std::vector<std::vector<int>>& GetRejectCuts() const { return fHitsFilter.fReject; }
242 const std::vector<std::array<float, projSz>>& GetProjCuts() const { return fProjFilter.fRef; }
244 {
245 if (!fHitsFilter.fAccept.size() && !fHitsFilter.fReject.size()) return nullptr;
246 return &fHitsFilter;
247 }
248
250 bool SetProjFilter(std::vector<float> cuts);
251 void SetMinHits(int n) { fNminHits = n; }
252 std::string ToString() const;
253
255
256 private:
263 bool AddTopoCut(std::vector<int> cuts, const char opt);
264
265 int fNminHits = 0;
268 ClassDef(CbmRecoQaTask::TrackFilter, 1); // Track cut implementation
269 }; // TrackFilter definition
270
271 struct EventFilter {
280 enum class eEventDef : int
281 {
283 };
285 virtual ~EventFilter() = default;
286 bool Accept(const CbmEvent* ptr, const CbmRecoQaTask* lnk);
287 bool SetFilter(std::vector<float> cuts);
288 std::string ToString() const;
289
291
292 private:
293 // track multiplicity cut definition
294 int fMinTrack = 0;
295 int fMaxTrack = 0;
296 // hit multiplicity cut definition
298
300 void HelpMess() const;
301
302 ClassDef(CbmRecoQaTask::EventFilter, 1); // Event cut implementation
303 }; // EventFilter definition
304
305
306 public:
308 virtual ~CbmRecoQaTask() { ; }
309
312 void Activate(ECbmModuleId det, bool set = true);
313 virtual Detector* AddDetector(ECbmModuleId did);
314 virtual EventFilter* AddEventFilter(EventFilter::eEventCut cut);
315 virtual TrackFilter* AddTrackFilter(ECbmModuleId cut);
316 virtual Detector* GetDetector(ECbmModuleId did);
322 template<ECbmModuleId d>
323 static size_t GetHitDetectorId(const CbmHit* h, std::vector<int>& sel);
330 template<class Data>
331 const Data* GetData(ECbmModuleId did, int id) const;
333 virtual InitStatus Init();
335 virtual void Exec(Option_t* option);
336
337 virtual void Finish();
338
339 // /** \brief Define the set of extra z positions where the track should be
340 // * projected in the x-y plane */
341 // void SetProjections(std::vector<double> vzpj);
343 TString GetGeoTagForDetector(const TString& detector);
344 std::vector<TString> GetPath(TGeoNode* node, TString, TString activeNodeName, int depth = 0,
345 const TString& path = "");
346 void UseMC(bool set = true)
347 {
348 if (set) fuRecoConfig.set(kUseMC);
349 }
350
351 protected:
352 static std::bitset<kRecoQaNConfigs> fuRecoConfig;
353 bool IsActive(eRecoConfig feature) { return fuRecoConfig.test(feature); }
354
355 private:
358
360 template<ECbmModuleId d>
361 int GetDebugInfo(const CbmHit* h);
366 virtual bool FilterEvent(const CbmEvent* ptr) const;
371 bool FilterHit(const CbmHit* h, ECbmModuleId d) const;
378 virtual bool FilterTrack(const CbmGlobalTrack* ptr) const;
384 virtual bool FilterTrack(const Trajectory* ptr) const;
386 int GetNviews(eViewType type) const;
388 void InitMcbm22();
389 void InitMcbm24();
390 void InitMcbm25();
391 void InitDefault();
393 template<class Data>
394 std::map<ECbmModuleId, TClonesArray*> MapDataList(std::string& s) const;
395
397 TClonesArray* fGTracks = nullptr;
398 std::map<ECbmModuleId, TClonesArray*> fTracks = {};
399 TClonesArray* fTrackMatches = nullptr;
400 TClonesArray* fEvents = nullptr;
402 std::map<ECbmModuleId, TClonesArray*> fHits = {};
403 std::map<ECbmModuleId, TClonesArray*> fClusters = {};
404 std::map<ECbmModuleId, CbmMCDataArray*> fPoints = {};
405 std::map<ECbmModuleId, TClonesArray*> fHitMatch = {};
406 std::vector<EventFilter> fFilterEv = {};
407 std::vector<TrackFilter> fFilterTrk = {};
409 TDirectoryFile fOutFolder = {"RecoQA", "CA track driven reco QA"};
411 std::map<ECbmModuleId, Detector> fDetQa = {};
412 std::map<const char*, View> fViews = {};
413 std::vector<TVector3> fPrjPlanes = {};
414
415 ClassDef(CbmRecoQaTask, 1); // Reconstruction QA analyzed from CA perspective
416};
417
418#endif // CBMRECOQATASK_H
ECbmDataType
Enumerator for CBM data types.
Definition CbmDefs.h:122
ECbmModuleId
Enumerator for module Identifiers.
Definition CbmDefs.h:45
@ kNotExist
If not found.
Definition CbmDefs.h:68
Base class for cluster objects.
Definition CbmCluster.h:30
Class characterising one event by a collection of links (indices) to data objects,...
Definition CbmEvent.h:34
Access to a MC data branch for time-based analysis.
Task class creating and managing CbmMCDataArray objects.
void SetPlaneId(size_t inode, int planeId)
static void SetPlaneId(Node &node, int planeId)
static int GetPlaneId(const Node &node)
int GetDebugInfo(const CbmHit *h)
Detector specific extra info.
CbmMCDataManager * cbm_mc_manager
static constexpr size_t stsSz
static constexpr size_t projSz
Define the identifiers of the sensors from each tracking layer of the setup to be considered in the p...
std::vector< TVector3 > fPrjPlanes
list of QA views
void UseMC(bool set=true)
ClassDef(CbmRecoQaTask, 1)
local storage for the z positions of track projection planes
std::map< ECbmModuleId, TClonesArray * > MapDataList(std::string &s) const
link the right data list for the data type (Hit, Tracks, Clusters)
std::map< ECbmModuleId, TClonesArray * > fHitMatch
mc points
int GetNviews(eViewType type) const
count views types registered with the task
virtual EventFilter * AddEventFilter(EventFilter::eEventCut cut)
virtual Detector * GetDetector(ECbmModuleId did)
std::map< ECbmModuleId, CbmMCDataArray * > fPoints
reconstructed Clusters
CbmRecoQaTask & operator=(const CbmRecoQaTask &)
CbmRecoQaTask(const CbmRecoQaTask &)
TClonesArray * fGTracks
TClonesArray * fEvents
MC info for the global tracks.
static std::bitset< kRecoQaNConfigs > fuRecoConfig
virtual bool FilterTrack(const CbmGlobalTrack *ptr) const
Filter tracks based on cuts. The cuts describe track composition (type of detector hit attached) and ...
std::map< ECbmModuleId, Detector > fDetQa
void Activate(ECbmModuleId det, bool set=true)
Explcitely Activate/Deactivate detector for tracking. If set to false, the detector is QAed but it is...
virtual void Exec(Option_t *option)
Executed task.
std::map< ECbmModuleId, TClonesArray * > fHits
Time slice info.
std::vector< EventFilter > fFilterEv
reconstructed hits
std::vector< TrackFilter > fFilterTrk
static size_t GetHitDetectorId(const CbmHit *h, std::vector< int > &sel)
Retrieve detector specific hit to sensor identification array.
@ kXdXT
X to TRK residuals w.r.t MC points.
@ kPVxsx
y-z projection of the primary vertex:
@ kPVyz
x-z projection of the primary vertex:
@ kDebug1
debug slot for detectors
@ kXYh
Time to EV residuals as function of coordinate in view.
@ kPVxy
Residual distribution T:
@ kResidualX
Pull distribution Y:
@ kDmult
X-Y hit coorelation in local view.
@ kXYt3
X-Y track projections on a random plane (value 2)
@ kXYt5
X-Y track projections on a random plane (value 4)
@ kXYhMC
local view MC point multiplicity
@ kYpY
X to TRK pulls as function of local X in view.
@ kXYt1
X-Y track projections on a random plane (value 0)
@ kYdYMC
Y to TRK residuals as function of local Y in view.
@ kResidualY
Residual distribution X: (x_RC - x_MC) in cm.
@ kPVzsz
y-sy projection of the primary vertex:
@ kPullX
X-Y MC point coorelation in local view (using HitMatch)
@ kResidualTX
Residual distribution Y:
@ kDebug0
X-Y track projections on a random plane (value 5)
@ kXYt0
z-sz projection of the primary vertex:
@ kPVysy
x-sx projection of the primary vertex:
@ kXYt2
X-Y track projections on a random plane (value 1)
@ kResidualTY
Residual distribution T:
@ kXdX
X-Y track projections on detection unit.
@ kPullY
Pull distribution X: (RC - MC) / dx_RC.
@ kXYp
X-Y hit coorelation in track filtered data.
@ kPVmult
y-z projection of the primary vertex:
@ kYdY
TRK errors in X direction as function of local X.
@ kYdYT
Y to TRK residuals w.r.t MC points.
@ kXdXMC
X to TRK residuals as function of local X in view.
@ kWdT
TRK errors in Y direction as function of local Y.
@ kPVxz
x-y projection of the primary vertex:
@ kXYt4
X-Y track projections on a random plane (value 3)
@ kDmultMC
local view hit multiplicity
@ kChdT
Y to TRK pulls as function of local Y in view.
CbmKfTrackFitter fFitter
CbmTimeSlice * fTimeSlice
reconstructed events
@ kTrdHits
has STS hits (StsHit branch)
@ kMuchHits
has Rich hits (RichHit branch)
@ kUseMC
has Much hits (MuchHit branch)
@ kRichHits
has ToF hits (TofHit branch)
@ kRecoQaNConfigs
use ToF hits in track refit
@ kUseSts
use MC even if available
@ kStsHits
has tracks reconstructed (GlobalTrack branch)
@ kUseTof
use TRD hits in track refit
@ kRecoTracks
has events reconstructed (CbmEvent branch)
@ kUseTrd
use STS hits in track refit
@ kTofHits
has TRD` hits (TrdHit branch)
std::map< ECbmModuleId, TClonesArray * > fClusters
reconstructed hits
void SetSetupClass(CbmRecoQaTask::eSetup setup)
Define the set of extra z positions where the track should be projected in the x-y plane.
virtual InitStatus Init()
Perform initialization of data sources and projections.
std::map< ECbmModuleId, TClonesArray * > fTracks
reconstructed global tracks / event
bool FilterHit(const CbmHit *h, ECbmModuleId d) const
Filter hit based on internal properties (for the originating sensor \call FilterView())
virtual TrackFilter * AddTrackFilter(ECbmModuleId cut)
TString GetGeoTagForDetector(const TString &detector)
std::vector< TString > GetPath(TGeoNode *node, TString, TString activeNodeName, int depth=0, const TString &path="")
@ kPV
set of track projection views
static constexpr size_t trdSz
virtual ~CbmRecoQaTask()
static constexpr size_t tofSz
std::map< const char *, View > fViews
list of detector QA
TClonesArray * fTrackMatches
reconstructed global tracks / event
virtual Detector * AddDetector(ECbmModuleId did)
const Data * GetData(ECbmModuleId did, int id) const
Retrieve detector specific data type (Track, Hit, Match) by index.
TDirectoryFile fOutFolder
virtual void Finish()
void InitMcbm22()
build QA plots for particular setups
bool IsActive(eRecoConfig feature)
virtual bool FilterEvent(const CbmEvent *ptr) const
Filter events for QA use (e.g. event multiplicity)
Data class with information on a STS local track.
Bookkeeping of time-slice content.
Class to handle QA-objects in the online reconstruction.
Definition QaData.h:27
Data(ECbmDataType i, const char *n)
View * GetView(const char *n)
Detector(ECbmModuleId did=ECbmModuleId::kNotExist)
View * FindView(double x, double y, double z)
std::vector< View > fViews
virtual ~Detector()=default
ClassDef(CbmRecoQaTask::Detector, 1)
View * AddView(const char *n, const char *p, std::vector< int > set, bool debug=false)
void HelpMess() const
max no of hits/ev for the systems [STS TRD ToF]
std::string ToString() const
int fMultHit[(int) eEventDef::kNofDetHit]
ClassDef(CbmRecoQaTask::EventFilter, 1)
virtual ~EventFilter()=default
bool SetFilter(std::vector< float > cuts)
bool Accept(const CbmEvent *ptr, const CbmRecoQaTask *lnk)
EventFilter(eEventCut typ=eEventCut::kNone)
@ kNone
cut on vertex definition
@ kVertex
cut on trigger conditions
@ kMultHit
cut on track multiplicity
@ kTrigger
cut on hit multiplicity
std::vector< std::vector< int > > fAccept
std::vector< std::vector< int > > fReject
bool Accept(const CbmHit *h, const CbmCluster *c0=nullptr, const CbmCluster *c1=nullptr) const
ClassDef(CbmRecoQaTask::TopoFilter, 1)
list of geo identifiers for each track projection selection
std::vector< std::array< float, projSz > > fRef
list of specific sensors identifiers for each tracking layer of the setup
virtual ~TopoFilter()=default
bool AddCondAccept(std::vector< int > cuts)
Define hit conditions for the analysis. User wrappers.
TrackFilter(ECbmModuleId d=ECbmModuleId::kNotExist)
virtual ~TrackFilter()=default
std::string ToString() const
bool AddTopoCut(std::vector< int > cuts, const char opt)
Define hit conditions for the analysis.
bool AddCondReject(std::vector< int > cuts)
TopoFilter fHitsFilter
definition of min number of hits/track
const std::vector< std::vector< int > > & GetRejectCuts() const
const std::vector< std::vector< int > > & GetAcceptCuts() const
Accessors for the underlying topological cuts definitions.
bool Accept(const CbmGlobalTrack *ptr, const CbmRecoQaTask *lnk) const
bool SetProjFilter(std::vector< float > cuts)
Define geometrical conditions for track acceptance in the analysis.
const TopoFilter * GetHitsFilter() const
const std::vector< std::array< float, projSz > > & GetProjCuts() const
TopoFilter fProjFilter
definition of hits/track topology according to detection unit
ClassDef(CbmRecoQaTask::TrackFilter, 1)
bool AddProjection(eProjectionType prj, float range=-1, const char *unit="cm")
virtual ~View()=default
std::string path
name describing the module
std::string makeYrange(const int scale, float &range)
bool Load(const CbmHit *h, const FairMCPoint *point, const CbmEvent *ev)
std::vector< int > fSelector
detection element center x0 y0 z0
friend class CbmRecoQaTask
ClassDef(CbmRecoQaTask::View, 1)
View(const char *n, const char *p, std::vector< int > set)
void SetSetup(CbmRecoQaTask::eSetup setup)
uint Register(TDirectoryFile *f)
build directory structure for all projections of current view.
void SetType(CbmRecoQaTask::eViewType type)
std::string makeTrange(const int scale, float &range)
helper functions to estimate the representation (y) axis
double pos[3]
detection element geometrical dx dy dz dimmensions
bool HasAddress(const CbmHit *h, double &x, double &y, double &dx, double &dy) const
std::map< eProjectionType, std::tuple< int, float, TH1 * > > fProjection
defining subset of the address set for this view
friend struct Detector
eSetup fSetup
multiplicity between 2 reset signals
double size[3]
path to the geo volume describing the module
bool SetProjection(eProjectionType prj, float range, const char *unit)
std::string ToString() const