CbmRoot
Debug.h
Go to the documentation of this file.
1 /*
2  * To change this license header, choose License Headers in Project Properties.
3  * To change this template file, choose Tools | Templates
4  * and open the template in the editor.
5  */
6 
7 /*
8  * File: Debug.h
9  * Author: tablyaz
10  *
11  * Created on September 19, 2017, 12:40 PM
12  */
13 
14 #ifndef DEBUG_H
15 #define DEBUG_H
16 
17 #include "CbmMCDataArray.h"
18 #include "CbmMCDataManager.h"
19 #include "CbmMCTrack.h"
20 #include "CbmMatch.h"
21 #include "CbmStsDigi.h"
22 #include "CbmStsHit.h"
23 #include "CbmStsPoint.h"
24 #include "CbmTrdCluster.h"
25 #include "CbmTrdHit.h"
26 #include "CbmTrdPoint.h"
27 #include "FairRootManager.h"
28 #include "setup/CbmStsSetup.h"
29 
31  Int_t fEventNumber;
32  FairRootManager* fIoman;
34  TClonesArray* fStsHitArray;
35  TClonesArray* fStsClusterArray;
36  TClonesArray* fStsDigiArray;
38  TClonesArray* fTrdHitArray;
39  TClonesArray* fTrdClusterArray;
40  TClonesArray* fTrdDigiMatchArray;
42 
43  struct MCTrack {
44  bool isRef;
45  std::set<Int_t> stsHits[2];
46  std::set<Int_t> trdHits[4];
47 
48  MCTrack() : isRef(false) {}
49  };
50 
51  std::vector<MCTrack> fMCTracks;
52 
54  : fEventNumber(0)
55  , fIoman(0)
56  , fMCTrackArray(0)
57  , fStsHitArray(0)
58  , fStsClusterArray(0)
59  , fStsDigiArray(0)
60  , fStsPointArray(0)
61  , fTrdHitArray(0)
62  , fTrdClusterArray(0)
64  , fTrdPointArray(0)
65  , fMCTracks() {
66  fIoman = FairRootManager::Instance();
67  CbmMCDataManager* mcManager =
68  static_cast<CbmMCDataManager*>(fIoman->GetObject("MCDataManager"));
69  fMCTrackArray = mcManager->InitBranch("MCTrack");
70  fStsHitArray = static_cast<TClonesArray*>(fIoman->GetObject("StsHit"));
72  static_cast<TClonesArray*>(fIoman->GetObject("StsCluster"));
73  fStsDigiArray = static_cast<TClonesArray*>(fIoman->GetObject("StsDigi"));
74  fStsPointArray = mcManager->InitBranch("StsPoint");
75  fTrdHitArray = static_cast<TClonesArray*>(fIoman->GetObject("TrdHit"));
77  static_cast<TClonesArray*>(fIoman->GetObject("TrdCluster"));
79  static_cast<TClonesArray*>(fIoman->GetObject("TrdDigiMatch"));
80  fTrdPointArray = mcManager->InitBranch("TrdPoint");
81  }
82 
83  CbmBinnedDebug(const CbmBinnedDebug&) = delete;
85 
86  void Exec() {
87  fMCTracks.clear();
88  Int_t nofMCTracks = fMCTrackArray->Size(0, fEventNumber);
89  fMCTracks.resize(nofMCTracks);
90  Int_t nofStsHits = fStsHitArray->GetEntriesFast();
91 
92  for (Int_t i = 0; i < nofStsHits; ++i) {
93  const CbmStsHit* stsHit =
94  static_cast<const CbmStsHit*>(fStsHitArray->At(i));
95  Int_t stationNumber =
97  Int_t frontClusterInd = stsHit->GetFrontClusterId();
98  Int_t backClusterInd = stsHit->GetBackClusterId();
99  const CbmStsCluster* frontCluster = static_cast<const CbmStsCluster*>(
100  fStsClusterArray->At(frontClusterInd));
101  Int_t nofFrontDigis = frontCluster->GetNofDigis();
102 
103  for (Int_t j = 0; j < nofFrontDigis; ++j) {
104  Int_t stsDigiInd = frontCluster->GetDigi(j);
105  const CbmStsDigi* stsDigi =
106  static_cast<const CbmStsDigi*>(fStsDigiArray->At(stsDigiInd));
107  const CbmMatch* match = stsDigi->GetMatch();
108  Int_t nofLinks = match->GetNofLinks();
109 
110  for (Int_t k = 0; k < nofLinks; ++k) {
111  const CbmLink& link = match->GetLink(k);
112  Int_t eventId = link.GetEntry();
113  Int_t mcPointId = link.GetIndex();
114  const CbmStsPoint* stsPoint = static_cast<const CbmStsPoint*>(
115  fStsPointArray->Get(0, eventId, mcPointId));
116  Int_t trackId = stsPoint->GetTrackID();
117  MCTrack& mcTrack = fMCTracks[trackId];
118  mcTrack.stsHits[stationNumber].insert(i);
119  }
120  }
121 
122  const CbmStsCluster* backCluster =
123  static_cast<const CbmStsCluster*>(fStsClusterArray->At(backClusterInd));
124  Int_t nofBackDigis = backCluster->GetNofDigis();
125 
126  for (Int_t j = 0; j < nofBackDigis; ++j) {
127  Int_t stsDigiInd = backCluster->GetDigi(j);
128  const CbmStsDigi* stsDigi =
129  static_cast<const CbmStsDigi*>(fStsDigiArray->At(stsDigiInd));
130  const CbmMatch* match = stsDigi->GetMatch();
131  Int_t nofLinks = match->GetNofLinks();
132 
133  for (Int_t k = 0; k < nofLinks; ++k) {
134  const CbmLink& link = match->GetLink(k);
135  Int_t eventId = link.GetEntry();
136  Int_t mcPointId = link.GetIndex();
137  const CbmStsPoint* stsPoint = static_cast<const CbmStsPoint*>(
138  fStsPointArray->Get(0, eventId, mcPointId));
139  Int_t trackId = stsPoint->GetTrackID();
140  MCTrack& mcTrack = fMCTracks[trackId];
141  mcTrack.stsHits[stationNumber].insert(i);
142  }
143  }
144  }
145 
146  Int_t nofTrdHits = fTrdHitArray->GetEntriesFast();
147 
148  for (Int_t i = 0; i < nofTrdHits; ++i) {
149  const CbmTrdHit* trdHit =
150  static_cast<const CbmTrdHit*>(fTrdHitArray->At(i));
151  Int_t stationNumber = trdHit->GetPlaneId();
152  Int_t clusterId = trdHit->GetRefId();
153  const CbmTrdCluster* cluster =
154  static_cast<const CbmTrdCluster*>(fTrdClusterArray->At(clusterId));
155  Int_t nofDigis = cluster->GetNofDigis();
156 
157  for (Int_t j = 0; j < nofDigis; ++j) {
158  Int_t digiId = cluster->GetDigi(j);
159  const CbmMatch* match =
160  static_cast<const CbmMatch*>(fTrdDigiMatchArray->At(digiId));
161  Int_t nofLinks = match->GetNofLinks();
162 
163  for (Int_t k = 0; k < nofLinks; ++k) {
164  const CbmLink& link = match->GetLink(k);
165  Int_t eventId = link.GetEntry();
166  Int_t mcPointId = link.GetIndex();
167  const CbmTrdPoint* trdPoint = static_cast<const CbmTrdPoint*>(
168  fTrdPointArray->Get(0, eventId, mcPointId));
169  Int_t trackId = trdPoint->GetTrackID();
170  MCTrack& mcTrack = fMCTracks[trackId];
171  mcTrack.trdHits[stationNumber].insert(i);
172  }
173  }
174  }
175 
176  for (int i = 0; i < nofMCTracks; ++i) {
177  MCTrack& mcTrack = fMCTracks[i];
178  const CbmMCTrack* track =
179  static_cast<const CbmMCTrack*>(fMCTrackArray->Get(0, fEventNumber, i));
180  mcTrack.isRef = track->GetMotherId() < 0;
181 
182  if (!mcTrack.isRef) continue;
183 
184  for (int j = 0; j < 2; ++j) {
185  if (mcTrack.stsHits[j].empty()) {
186  mcTrack.isRef = false;
187  break;
188  }
189  }
190 
191  if (!mcTrack.isRef) continue;
192 
193  for (int j = 0; j < 4; ++j) {
194  if (mcTrack.trdHits[j].empty()) {
195  mcTrack.isRef = false;
196  break;
197  }
198  }
199  }
200 
201  ++fEventNumber;
202  }
203 
204  bool TrackHasHit(int stNo, Int_t trackInd, Int_t hitInd) {
205  if (stNo < 0)
206  return -1;
207  else if (stNo < 2)
208  return TrackHasHitSts(stNo, trackInd, hitInd);
209  else if (stNo < 6)
210  return TrackHasHitTrd(stNo - 2, trackInd, hitInd);
211  else
212  return -1;
213  }
214 
215  bool TrackHasHitSts(int stNo, Int_t trackInd, Int_t hitInd) {
216  return fMCTracks[trackInd].stsHits[stNo].find(hitInd)
217  != fMCTracks[trackInd].stsHits[stNo].end();
218  }
219 
220  bool TrackHasHitTrd(int stNo, Int_t trackInd, Int_t hitInd) {
221  return fMCTracks[trackInd].trdHits[stNo].find(hitInd)
222  != fMCTracks[trackInd].trdHits[stNo].end();
223  }
224 };
225 
226 #endif /* DEBUG_H */
CbmMCTrack::GetMotherId
Int_t GetMotherId() const
Definition: CbmMCTrack.h:71
CbmMatch
Definition: CbmMatch.h:22
CbmMCDataManager.h
CbmBinnedDebug::fStsPointArray
CbmMCDataArray * fStsPointArray
Definition: Debug.h:37
CbmBinnedDebug::MCTrack
Definition: Debug.h:43
CbmMatch::GetLink
const CbmLink & GetLink(Int_t i) const
Definition: CbmMatch.h:35
CbmMatch::GetNofLinks
Int_t GetNofLinks() const
Definition: CbmMatch.h:38
CbmStsCluster
Data class for STS clusters.
Definition: CbmStsCluster.h:31
CbmBinnedDebug
Definition: Debug.h:30
CbmBinnedDebug::fStsHitArray
TClonesArray * fStsHitArray
Definition: Debug.h:34
CbmBinnedDebug::fEventNumber
Int_t fEventNumber
Definition: Debug.h:31
CbmMCDataArray::Size
Int_t Size(Int_t fileNumber, Int_t eventNumber)
Definition: CbmMCDataArray.cxx:133
CbmBinnedDebug::fIoman
FairRootManager * fIoman
Definition: Debug.h:32
i
int i
Definition: L1/vectors/P4_F32vec4.h:25
CbmTrdHit
data class for a reconstructed Energy-4D measurement in the TRD
Definition: CbmTrdHit.h:35
CbmMCDataManager::InitBranch
CbmMCDataArray * InitBranch(const char *name)
Definition: CbmMCDataManager.cxx:106
CbmBinnedDebug::Exec
void Exec()
Definition: Debug.h:86
CbmStsSetup::Instance
static CbmStsSetup * Instance()
Definition: CbmStsSetup.cxx:293
CbmMCDataArray.h
CbmMCDataArray
Access to a MC data branch for time-based analysis.
Definition: CbmMCDataArray.h:35
CbmBinnedDebug::TrackHasHitSts
bool TrackHasHitSts(int stNo, Int_t trackInd, Int_t hitInd)
Definition: Debug.h:215
CbmStsHit::GetFrontClusterId
Int_t GetFrontClusterId() const
Definition: CbmStsHit.h:93
CbmHit::GetRefId
Int_t GetRefId() const
Definition: CbmHit.h:72
CbmBinnedDebug::CbmBinnedDebug
CbmBinnedDebug()
Definition: Debug.h:53
CbmStsPoint
Definition: CbmStsPoint.h:27
CbmMatch.h
CbmBinnedDebug::TrackHasHit
bool TrackHasHit(int stNo, Int_t trackInd, Int_t hitInd)
Definition: Debug.h:204
CbmBinnedDebug::fStsClusterArray
TClonesArray * fStsClusterArray
Definition: Debug.h:35
CbmBinnedDebug::fStsDigiArray
TClonesArray * fStsDigiArray
Definition: Debug.h:36
CbmCluster::GetNofDigis
Int_t GetNofDigis() const
Number of digis in cluster.
Definition: CbmCluster.h:69
CbmTrdCluster
Data Container for TRD clusters.
Definition: CbmTrdCluster.h:23
CbmBinnedDebug::fMCTracks
std::vector< MCTrack > fMCTracks
Definition: Debug.h:51
CbmStsHit
data class for a reconstructed 3-d hit in the STS
Definition: CbmStsHit.h:31
CbmStsDigi.h
CbmBinnedDebug::MCTrack::trdHits
std::set< Int_t > trdHits[4]
Definition: Debug.h:46
CbmStsSetup::GetStationNumber
Int_t GetStationNumber(Int_t address)
Definition: CbmStsSetup.cxx:187
CbmMCDataArray::Get
TObject * Get(const CbmLink *lnk)
Definition: CbmMCDataArray.h:47
CbmBinnedDebug::MCTrack::stsHits
std::set< Int_t > stsHits[2]
Definition: Debug.h:45
CbmHit::GetAddress
Int_t GetAddress() const
Definition: CbmHit.h:73
CbmBinnedDebug::fTrdClusterArray
TClonesArray * fTrdClusterArray
Definition: Debug.h:39
CbmTrdHit.h
Class for hits in TRD detector.
CbmStsDigi
Data class for a single-channel message in the STS.
Definition: CbmStsDigi.h:29
CbmBinnedDebug::MCTrack::isRef
bool isRef
Definition: Debug.h:44
CbmBinnedDebug::fTrdPointArray
CbmMCDataArray * fTrdPointArray
Definition: Debug.h:41
CbmTrdPoint
Definition: CbmTrdPoint.h:23
CbmMCDataManager
Task class creating and managing CbmMCDataArray objects.
Definition: CbmMCDataManager.h:27
CbmStsPoint.h
CbmMCTrack.h
CbmStsHit::GetBackClusterId
Int_t GetBackClusterId() const
Definition: CbmStsHit.h:69
CbmMCTrack
Definition: CbmMCTrack.h:34
CbmBinnedDebug::fTrdDigiMatchArray
TClonesArray * fTrdDigiMatchArray
Definition: Debug.h:40
CbmTrdPoint.h
CbmTrdCluster.h
Data Container for TRD clusters.
CbmBinnedDebug::TrackHasHitTrd
bool TrackHasHitTrd(int stNo, Int_t trackInd, Int_t hitInd)
Definition: Debug.h:220
CbmBinnedDebug::operator=
CbmBinnedDebug & operator=(const CbmBinnedDebug &)=delete
CbmCluster::GetDigi
Int_t GetDigi(Int_t index) const
Get digi at position index.
Definition: CbmCluster.h:76
CbmBinnedDebug::CbmBinnedDebug
CbmBinnedDebug(const CbmBinnedDebug &)=delete
CbmBinnedDebug::fMCTrackArray
CbmMCDataArray * fMCTrackArray
Definition: Debug.h:33
CbmBinnedDebug::MCTrack::MCTrack
MCTrack()
Definition: Debug.h:48
CbmBinnedDebug::fTrdHitArray
TClonesArray * fTrdHitArray
Definition: Debug.h:38
CbmStsHit.h
Data class for a reconstructed hit in the STS.
CbmTrdHit::GetPlaneId
Int_t GetPlaneId() const
Inherited from CbmBaseHit.
Definition: CbmTrdHit.h:73