BmnRoot 26.10.0-18-g4e3414f9
Software framework of the BM@N experiment
Loading...
Searching...
No Matches
BmnHit.cxx
Go to the documentation of this file.
1
2#include "BmnHit.h"
3
4#include "FairRootManager.h"
5
6#include <TBranch.h>
7#include <TChain.h>
8#include <TClonesArray.h>
9#include <map>
10#include <string>
11
13 : FairHit()
14{
15 fUsing = kFALSE;
16 fFlag = kTRUE;
17 fIndex = -1;
18 fDetId = kREF;
19 fStation = -1;
20 fModule = -1;
21 fType = -1;
22 fLength = -1.0;
23 fResX = -1000.;
24 fResY = -1000.;
25 fCovXY = -1000.;
26 fPseudo = false;
27}
28
29BmnHit::BmnHit(Int_t detID, TVector3 pos, TVector3 dpos, Int_t index)
30 : FairHit(detID, pos, dpos, index)
31{
32 fUsing = kFALSE;
33 fFlag = kTRUE;
34 fIndex = -1;
35 fDetId = kREF;
36 fStation = -1;
37 fModule = -1;
38 fType = -1;
39 fLength = -1.0;
40 fResX = -1000.;
41 fResY = -1000.;
42 fCovXY = -1000.;
43 fPseudo = false;
44}
45
47
48// Strip cluster of the hit in the given strip layer, taken from the cluster branch of this layer
49StripCluster* BmnHit::GetCluster(const char* cluster_branch_name, StripLayerType layer)
50{
51 // a pseudo hit is reconstructed from a lower layer cluster only
52 if (layer == UpperStripLayer && fPseudo)
53 return nullptr;
54 Int_t cluster_index = (layer == LowerStripLayer) ? fLowerClusterIndex : fUpperClusterIndex;
55
56 // each branch is looked up only once for the current FairRootManager, because every GetObject call
57 // for a branch which is not in memory takes a new slot of the internal array of FairRootManager
58 static thread_local FairRootManager* cached_manager = nullptr;
59 static thread_local map<string, TClonesArray*> cluster_arrays;
60
61 FairRootManager* ioman = FairRootManager::Instance();
62 if (ioman != cached_manager) {
63 cluster_arrays.clear();
64 cached_manager = ioman;
65 }
66
67 auto it = cluster_arrays.find(cluster_branch_name);
68 if (it == cluster_arrays.end()) {
69 TClonesArray* clusters = dynamic_cast<TClonesArray*>(ioman->GetObject(cluster_branch_name));
70 // a branch of the input file activated only now does not contain the current event yet, so it is read here
71 TChain* input_chain = ioman->GetInChain();
72 if (clusters && input_chain && input_chain->GetTree()) {
73 TBranch* branch = input_chain->GetTree()->GetBranch(cluster_branch_name);
74 if (branch)
75 branch->GetEntry(input_chain->GetTree()->GetReadEntry());
76 }
77 it = cluster_arrays.emplace(cluster_branch_name, clusters).first;
78 }
79
80 TClonesArray* clusters = it->second;
81 if (!clusters || cluster_index < 0 || cluster_index >= clusters->GetEntriesFast())
82 return nullptr;
83 return static_cast<StripCluster*>(clusters->UncheckedAt(cluster_index));
84}
int Int_t
constexpr Bool_t kFALSE
constexpr Bool_t kTRUE
@ kREF
@ UpperStripLayer
@ LowerStripLayer
Int_t fIndex
Index in hits array.
Definition BmnHit.h:79
Int_t fModule
Definition BmnHit.h:84
Short_t fStation
station number.
Definition BmnHit.h:83
Double_t fResY
Definition BmnHit.h:89
Int_t fUpperClusterIndex
Definition BmnHit.h:96
Int_t fType
Definition BmnHit.h:85
Double_t fCovXY
Definition BmnHit.h:91
Double_t fResX
Definition BmnHit.h:88
Int_t fLowerClusterIndex
Definition BmnHit.h:97
StripCluster * GetCluster(const char *cluster_branch_name, StripLayerType layer)
Strip cluster of the hit in the given strip layer, taken from the cluster branch of this layer (e....
Definition BmnHit.cxx:49
Double_t fLength
Definition BmnHit.h:86
BmnHit()
Default constructor.
Definition BmnHit.cxx:12
DetectorId fDetId
Id of detector which creates hit.
Definition BmnHit.h:81
Bool_t fPseudo
Definition BmnHit.h:99
Bool_t fFlag
Is hit good or not.
Definition BmnHit.h:77
virtual ~BmnHit()
Destructor.
Definition BmnHit.cxx:46
Bool_t fUsing
Is hit used or not.
Definition BmnHit.h:75
virtual Int_t GetEntry(Long64_t entry=0, Int_t getall=0)
TTree * GetTree() const override
Int_t GetEntriesFast() const
TObject * UncheckedAt(Int_t i) const
virtual TBranch * GetBranch(const char *name)
virtual Long64_t GetReadEntry() const