CbmRoot
Loading...
Searching...
No Matches
CbmLitMCTrackCreator.cxx
Go to the documentation of this file.
1/* Copyright (C) 2011-2020 GSI/JINR-LIT, Darmstadt/Dubna
2 SPDX-License-Identifier: GPL-3.0-only
3 Authors: Andrey Lebedev [committer], Timur Ablyazimov */
4
11
12#include "CbmDigiManager.h"
13#include "CbmHit.h"
14#include "CbmMCDataArray.h"
15#include "CbmMCDataManager.h"
16#include "CbmMCTrack.h"
17#include "CbmMatchRecoToMC.h"
18#include "CbmMuchGeoScheme.h"
19#include "CbmMuchPoint.h"
20#include "CbmMvdPoint.h"
21#include "CbmRichGeoManager.h"
22#include "CbmRichHit.h"
23#include "CbmRichHitProducer.h"
24#include "CbmRichPoint.h"
26#include "CbmStsPoint.h"
27#include "CbmStsSetup.h"
28#include "CbmTrdAddress.h"
29#include "CbmTrdPoint.h"
30#include "FairGeoNode.h"
31#include "FairMCPoint.h"
32#include "FairRootManager.h"
33#include "TClonesArray.h"
34#include "TDatabasePDG.h"
35#include "TGeoManager.h"
36
37#include <map> // for map
38#include <utility> // for make_pair, pair
39
40using std::make_pair;
41using std::map;
42using std::pair;
43
45 : fMCTracks(NULL)
46 , fMvdPoints(NULL)
47 , fStsPoints(NULL)
48 , fTrdPoints(NULL)
49 , fMuchPoints(NULL)
50 , fTofPoints(NULL)
51 , fRichPoints(NULL)
52 , fRichHits(NULL)
53 , fDigiMan(nullptr)
54 , fLitMCTracks()
55 , fMvdStationsMap()
56 , fStsStationsMap()
57 , fTrdStationsMap()
58 , fMuchStationsMap()
59 , fTauFit(NULL)
60{
62
64}
65
67
69{
70 static CbmLitMCTrackCreator instance;
71 return &instance;
72}
73
74void CbmLitMCTrackCreator::Create(Int_t eventNum)
75{
76 FillStationMaps(eventNum);
77
78
79 fLitMCTracks.clear();
80
82
84
86
88
90
92
93 AddRichHits(eventNum);
94
95 AddRingParameters(eventNum);
96
97 std::map<std::pair<Int_t, Int_t>, CbmLitMCTrack>::iterator it;
98 for (it = fLitMCTracks.begin(); it != fLitMCTracks.end(); it++) {
99 it->second.CalculateNofConsecutivePoints();
100 }
101
102 // std::cout << "CbmLitMCTrackCreator: nof MC tracks=" << fLitMCTracks.size() << std::endl;
103 // for (it = fLitMCTracks.begin(); it != fLitMCTracks.end(); it++){
104 // std::cout << (*it).first.first << "-" << (*it).first.second<< " => " << (*it).second.ToString();
105 // }
106}
107
108
110{
111 FairRootManager* ioman = FairRootManager::Instance();
112
113 CbmMCDataManager* mcManager = (CbmMCDataManager*) ioman->GetObject("MCDataManager");
114
115 if (0 == mcManager) LOG(fatal) << "CbmMatchRecoToMC::ReadAndCreateDataBranches() NULL MCDataManager.";
116
117 fMCTracks = mcManager->InitBranch("MCTrack");
118 fMvdPoints = mcManager->InitBranch("MvdPoint");
119 fStsPoints = mcManager->InitBranch("StsPoint");
120 fTrdPoints = mcManager->InitBranch("TrdPoint");
121 fMuchPoints = mcManager->InitBranch("MuchPoint");
122 fTofPoints = mcManager->InitBranch("TofPoint");
123 fRichPoints = mcManager->InitBranch("RichPoint");
124 fRichHits = (TClonesArray*) ioman->GetObject("RichHit");
126 fDigiMan->Init();
127}
128
130{
131 if (array == NULL) return;
132
133 Int_t nofPoints = array->Size(0, iEvent);
134
135 for (Int_t iPoint = 0; iPoint < nofPoints; ++iPoint) {
136 FairMCPoint* fairPoint = static_cast<FairMCPoint*>(array->Get(0, iEvent, iPoint));
137 if (NULL == fairPoint) continue;
138 CbmLitMCPoint litPoint;
139 Int_t stationId = -1;
140 if (detId == ECbmModuleId::kMvd) {
141 stationId = fMvdStationsMap[make_pair(iEvent, iPoint)];
142 MvdPointCoordinatesAndMomentumToLitMCPoint(static_cast<CbmMvdPoint*>(fairPoint), &litPoint);
143 }
144 else if (detId == ECbmModuleId::kSts) {
145 stationId = fStsStationsMap[make_pair(iEvent, iPoint)];
146 StsPointCoordinatesAndMomentumToLitMCPoint(static_cast<CbmStsPoint*>(fairPoint), &litPoint);
147 }
148 else if (detId == ECbmModuleId::kTrd) {
149 stationId = fTrdStationsMap[make_pair(iEvent, iPoint)];
150 TrdPointCoordinatesAndMomentumToLitMCPoint(static_cast<CbmTrdPoint*>(fairPoint), &litPoint);
151 }
152 else if (detId == ECbmModuleId::kMuch) {
153 stationId = fMuchStationsMap[make_pair(iEvent, iPoint)];
154 MuchPointCoordinatesAndMomentumToLitMCPoint(static_cast<CbmMuchPoint*>(fairPoint), &litPoint);
155 }
156 else if (detId == ECbmModuleId::kTof) {
157 stationId = 0;
159 }
160 else if (detId == ECbmModuleId::kRich) {
161 stationId = 0;
163 }
164 if (stationId < 0) continue;
165 FairMCPointToLitMCPoint(fairPoint, &litPoint, iEvent, iPoint, stationId);
166 if (detId != ECbmModuleId::kRich) {
167 fLitMCTracks[make_pair(iEvent, fairPoint->GetTrackID())].AddPoint(detId, litPoint);
168 }
169 else {
170 const CbmMCTrack* mcTrack = static_cast<const CbmMCTrack*>(fMCTracks->Get(0, iEvent, fairPoint->GetTrackID()));
171 fLitMCTracks[make_pair(iEvent, mcTrack->GetMotherId())].AddPoint(detId, litPoint);
172 }
173 }
174}
175
176void CbmLitMCTrackCreator::AddRichHits(Int_t /* iEvent */)
177{
178 if (NULL == fRichHits) return;
179 map<pair<Int_t, Int_t>, Int_t> nofHitsInRing;
180 Int_t nofRichHits = fRichHits->GetEntriesFast();
181 for (Int_t iHit = 0; iHit < nofRichHits; iHit++) {
182 const CbmRichHit* hit = static_cast<const CbmRichHit*>(fRichHits->At(iHit));
183 if (NULL == hit) continue;
185 for (UInt_t i = 0; i < motherIds.size(); i++) {
186 auto motherId = std::make_pair<Int_t, Int_t>(motherIds[i].GetEntry(), motherIds[i].GetIndex());
187 nofHitsInRing[motherId]++;
188 }
189 }
190
191 map<pair<Int_t, Int_t>, Int_t>::const_iterator it;
192 for (it = nofHitsInRing.begin(); it != nofHitsInRing.end(); it++) {
193 fLitMCTracks[it->first].SetNofRichHits(it->second);
194 }
195}
196
198{
199 if (NULL == fRichPoints || NULL == fMCTracks) return;
200 map<pair<Int_t, Int_t>, CbmRichRingLight> mapRings;
201
202 int nofRichPoints = fRichPoints->Size(0, iEvent);
203
204 for (int iPoint = 0; iPoint < nofRichPoints; iPoint++) {
205 CbmRichPoint* richPoint = (CbmRichPoint*) fRichPoints->Get(0, iEvent, iPoint);
206 if (NULL == richPoint) continue;
207 Int_t trackId = richPoint->GetTrackID();
208 if (trackId < 0) continue;
209 CbmMCTrack* mcTrackRich = (CbmMCTrack*) fMCTracks->Get(0, iEvent, trackId);
210 if (NULL == mcTrackRich) continue;
211 int motherIdRich = mcTrackRich->GetMotherId();
212 if (motherIdRich == -1) continue;
213 TVector3 posPoint;
214 richPoint->Position(posPoint);
215 TVector3 detPoint;
216
217 CbmRichGeoManager::GetInstance().RotatePoint(&posPoint, &detPoint);
218 CbmRichHitLight hit(detPoint.X(), detPoint.Y());
219 mapRings[make_pair(iEvent, motherIdRich)].AddHit(hit);
220 }
221
222
223 map<pair<Int_t, Int_t>, CbmRichRingLight>::const_iterator it;
224 for (it = mapRings.begin(); it != mapRings.end(); it++) {
225 CbmRichRingLight ring(it->second);
226 fTauFit->DoFit(&ring); //fLitMCTracks[it->first].SetNofRichHits(it->second);
227 fLitMCTracks[it->first].SetRingAaxis(ring.GetAaxis());
228 fLitMCTracks[it->first].SetRingBaxis(ring.GetBaxis());
229 fLitMCTracks[it->first].SetRingCenterX(ring.GetCenterX());
230 fLitMCTracks[it->first].SetRingCenterY(ring.GetCenterY());
231 //std::cout << ++i << " " << ring.GetAaxis() << " " << ring.GetBaxis() << std::endl;
232 }
233}
234
235void CbmLitMCTrackCreator::FairMCPointToLitMCPoint(const FairMCPoint* fairPoint, CbmLitMCPoint* litPoint, Int_t eventId,
236 Int_t refId, Int_t stationId)
237{
238 if (fairPoint == NULL || litPoint == NULL) return;
239 litPoint->SetRefId(refId);
240 litPoint->SetStationId(stationId);
241 const CbmMCTrack* mcTrack = static_cast<const CbmMCTrack*>(fMCTracks->Get(0, eventId, fairPoint->GetTrackID()));
242 if (mcTrack == NULL) return;
243 TParticlePDG* pdgParticle = TDatabasePDG::Instance()->GetParticle(mcTrack->GetPdgCode());
244 double charge = (pdgParticle != NULL) ? pdgParticle->Charge() : 0.;
245 Double_t q = (charge > 0) ? 1. : -1.;
246 litPoint->SetQ(q);
247}
248
250 CbmLitMCPoint* litPoint)
251{
252 if (fairPoint == NULL || litPoint == NULL) return;
253 litPoint->SetXIn(fairPoint->GetX());
254 litPoint->SetYIn(fairPoint->GetY());
255 litPoint->SetZIn(fairPoint->GetZ());
256 litPoint->SetPxIn(fairPoint->GetPx());
257 litPoint->SetPyIn(fairPoint->GetPy());
258 litPoint->SetPzIn(fairPoint->GetPz());
259 litPoint->SetXOut(fairPoint->GetX());
260 litPoint->SetYOut(fairPoint->GetY());
261 litPoint->SetZOut(fairPoint->GetZ());
262 litPoint->SetPxOut(fairPoint->GetPx());
263 litPoint->SetPyOut(fairPoint->GetPy());
264 litPoint->SetPzOut(fairPoint->GetPz());
265}
266
268 CbmLitMCPoint* litPoint)
269{
270 if (mvdPoint == NULL || litPoint == NULL) return;
271 litPoint->SetXIn(mvdPoint->GetX());
272 litPoint->SetYIn(mvdPoint->GetY());
273 litPoint->SetZIn(mvdPoint->GetZ());
274 litPoint->SetPxIn(mvdPoint->GetPx());
275 litPoint->SetPyIn(mvdPoint->GetPy());
276 litPoint->SetPzIn(mvdPoint->GetPz());
277 litPoint->SetXOut(mvdPoint->GetXOut());
278 litPoint->SetYOut(mvdPoint->GetYOut());
279 litPoint->SetZOut(mvdPoint->GetZOut());
280 litPoint->SetPxOut(mvdPoint->GetPxOut());
281 litPoint->SetPyOut(mvdPoint->GetPyOut());
282 litPoint->SetPzOut(mvdPoint->GetPzOut());
283}
284
286 CbmLitMCPoint* litPoint)
287{
288 if (stsPoint == NULL || litPoint == NULL) return;
289 litPoint->SetXIn(stsPoint->GetXIn());
290 litPoint->SetYIn(stsPoint->GetYIn());
291 litPoint->SetZIn(stsPoint->GetZIn());
292 litPoint->SetPxIn(stsPoint->GetPx());
293 litPoint->SetPyIn(stsPoint->GetPy());
294 litPoint->SetPzIn(stsPoint->GetPz());
295 litPoint->SetXOut(stsPoint->GetXOut());
296 litPoint->SetYOut(stsPoint->GetYOut());
297 litPoint->SetZOut(stsPoint->GetZOut());
298 litPoint->SetPxOut(stsPoint->GetPxOut());
299 litPoint->SetPyOut(stsPoint->GetPyOut());
300 litPoint->SetPzOut(stsPoint->GetPzOut());
301}
302
304 CbmLitMCPoint* litPoint)
305{
306 if (trdPoint == NULL || litPoint == NULL) return;
307 litPoint->SetXIn(trdPoint->GetXIn());
308 litPoint->SetYIn(trdPoint->GetYIn());
309 litPoint->SetZIn(trdPoint->GetZIn());
310 litPoint->SetPxIn(trdPoint->GetPxIn());
311 litPoint->SetPyIn(trdPoint->GetPyIn());
312 litPoint->SetPzIn(trdPoint->GetPzIn());
313 litPoint->SetXOut(trdPoint->GetXOut());
314 litPoint->SetYOut(trdPoint->GetYOut());
315 litPoint->SetZOut(trdPoint->GetZOut());
316 litPoint->SetPxOut(trdPoint->GetPxOut());
317 litPoint->SetPyOut(trdPoint->GetPyOut());
318 litPoint->SetPzOut(trdPoint->GetPzOut());
319}
320
322 CbmLitMCPoint* litPoint)
323{
324 if (muchPoint == NULL || litPoint == NULL) return;
325 litPoint->SetXIn(muchPoint->GetXIn());
326 litPoint->SetYIn(muchPoint->GetYIn());
327 litPoint->SetZIn(muchPoint->GetZIn());
328 litPoint->SetPxIn(muchPoint->GetPx());
329 litPoint->SetPyIn(muchPoint->GetPy());
330 litPoint->SetPzIn(muchPoint->GetPz());
331 litPoint->SetXOut(muchPoint->GetXOut());
332 litPoint->SetYOut(muchPoint->GetYOut());
333 litPoint->SetZOut(muchPoint->GetZOut());
334 litPoint->SetPxOut(muchPoint->GetPxOut());
335 litPoint->SetPyOut(muchPoint->GetPyOut());
336 litPoint->SetPzOut(muchPoint->GetPzOut());
337}
338
340{
341 fMvdStationsMap.clear();
342 fStsStationsMap.clear();
343 fTrdStationsMap.clear();
344 fMuchStationsMap.clear();
345
346
347 // MVD
348 if (NULL != fMvdPoints) {
349 Int_t nofMvdPoints = fMvdPoints->Size(0, iEvent);
350 for (Int_t iPoint = 0; iPoint < nofMvdPoints; iPoint++) {
351 CbmMvdPoint* point = static_cast<CbmMvdPoint*>(fMvdPoints->Get(0, iEvent, iPoint));
352 if (NULL == point) continue;
353 fMvdStationsMap[make_pair(iEvent, iPoint)] = point->GetStationNr() - 1;
354 }
355 }
356 // end MVD
357
358 // STS
359 if (NULL != fStsPoints) {
360 Int_t nofStsPoints = fStsPoints->Size(0, iEvent);
361 for (Int_t iPoint = 0; iPoint < nofStsPoints; iPoint++) {
362 const CbmStsPoint* point = static_cast<const CbmStsPoint*>(fStsPoints->Get(0, iEvent, iPoint));
363 if (NULL == point) continue;
364 UInt_t address = point->GetDetectorID();
365 Int_t stationId = CbmStsSetup::Instance()->GetStationNumber(address);
366 fStsStationsMap[make_pair(iEvent, iPoint)] = stationId;
367 }
368 }
369 // end STS
370
371 // MUCH
372 if (NULL != fMuchPoints) {
373 Int_t nofMuchPoints = fMuchPoints->Size(0, iEvent);
374 for (Int_t iPoint = 0; iPoint < nofMuchPoints; iPoint++) {
375 const FairMCPoint* point = static_cast<const FairMCPoint*>(fMuchPoints->Get(0, iEvent, iPoint));
376 if (NULL == point) continue;
377 Int_t stationId = 100 * CbmMuchGeoScheme::GetStationIndex(point->GetDetectorID())
378 + 10 * CbmMuchGeoScheme::GetLayerIndex(point->GetDetectorID())
379 + CbmMuchGeoScheme::GetLayerSideIndex(point->GetDetectorID());
380 // Int_t stationId = CbmMuchGeoScheme::Instance()->GetLayerSideNr(point->GetDetectorID());
381 fMuchStationsMap[make_pair(iEvent, iPoint)] = stationId;
382 }
383 }
384 // end MUCH
385
386 // TRD
387 if (NULL != fTrdPoints) {
388 Int_t nofTrdPoints = fTrdPoints->Size(0, iEvent);
389 for (Int_t iPoint = 0; iPoint < nofTrdPoints; iPoint++) {
390 const FairMCPoint* point = static_cast<const FairMCPoint*>(fTrdPoints->Get(0, iEvent, iPoint));
391 if (NULL == point) continue;
392 //Int_t stationId = 10 * CbmTrdAddress::GetStationNr(point->GetDetectorID()) + CbmTrdAddress::GetLayerNr(point->GetDetectorID());
393 Int_t stationId = CbmTrdAddress::GetLayerId(point->GetDetectorID());
394 fTrdStationsMap[make_pair(iEvent, iPoint)] = stationId;
395 }
396 }
397 // end TRD
398}
ECbmModuleId
Definition CbmDefs.h:39
@ kMvd
Micro-Vertex Detector.
@ kTrd
Transition Radiation Detector.
@ kTof
Time-of-flight Detector.
@ kSts
Silicon Tracking System.
@ kMuch
Muon detection system.
@ kRich
Ring-Imaging Cherenkov Detector.
Creates CbmLitMCTrack objects.
FairTask for matching RECO data to MC.
Class for producing RICH hits directly from MCPoints.
Here the ring is fitted with Taubin algorithm from A. Ayriyan, G. Ososkov, N. Chernov.
CbmDigiManager * fDigiMan
Helper class to convert unique channel ID back and forth.
InitStatus Init()
Initialisation.
static CbmDigiManager * Instance()
Static instance.
Monte-Carlo point.
void SetYOut(Double_t y)
void SetXIn(Double_t x)
void SetRefId(Int_t refId)
void SetQ(Double_t q)
void SetPxOut(Double_t px)
void SetPyIn(Double_t py)
void SetZOut(Double_t z)
void SetZIn(Double_t z)
void SetYIn(Double_t y)
void SetPzIn(Double_t pz)
void SetPzOut(Double_t pz)
void SetPyOut(Double_t py)
void SetStationId(Int_t stationId)
void SetXOut(Double_t x)
void SetPxIn(Double_t px)
Creates CbmLitMCTrack objects.
void FillStationMaps(Int_t iEvent)
Fill maps for MC points to station id.
std::map< std::pair< int, int >, int > fTrdStationsMap
void StsPointCoordinatesAndMomentumToLitMCPoint(const CbmStsPoint *stsPoint, CbmLitMCPoint *litPoint)
void FairMCPointCoordinatesAndMomentumToLitMCPoint(const FairMCPoint *fairPoint, CbmLitMCPoint *litPoint)
void MuchPointCoordinatesAndMomentumToLitMCPoint(const CbmMuchPoint *muchPoint, CbmLitMCPoint *litPoint)
void FairMCPointToLitMCPoint(const FairMCPoint *fairPoint, CbmLitMCPoint *litPoint, int eventId, int refId, int stationId)
Convert FairMCPoint to CbmLitMCPoint.
virtual ~CbmLitMCTrackCreator()
Destructor.
void AddPoints(ECbmModuleId detId, CbmMCDataArray *array, Int_t iEvent)
Add MC points from a certain detector.
std::map< std::pair< int, int >, int > fMvdStationsMap
std::map< std::pair< int, int >, CbmLitMCTrack > fLitMCTracks
void AddRichHits(Int_t iEvent)
Calculate and set number of RICH hits for MC track.
std::map< std::pair< int, int >, int > fMuchStationsMap
void Create(Int_t eventNum)
Creates array of CbmLitMCTracks for current event.
CbmRichRingFitterEllipseTau * fTauFit
std::map< std::pair< int, int >, int > fStsStationsMap
void AddRingParameters(Int_t iEvent)
Fit Rich MC points using ellipse fitter and fill ellipse parameters.
void MvdPointCoordinatesAndMomentumToLitMCPoint(const CbmMvdPoint *mvdPoint, CbmLitMCPoint *litPoint)
void ReadDataBranches()
Read data branches.
void TrdPointCoordinatesAndMomentumToLitMCPoint(const CbmTrdPoint *trdPoint, CbmLitMCPoint *litPoint)
static CbmLitMCTrackCreator * Instance()
Singleton instance.
Monte-Carlo track.
Access to a MC data branch for time-based analysis.
TObject * Get(const CbmLink *lnk)
Int_t Size(Int_t fileNumber, Int_t eventNumber)
Task class creating and managing CbmMCDataArray objects.
CbmMCDataObject * GetObject(const char *name)
CbmMCDataArray * InitBranch(const char *name)
int32_t GetMotherId() const
Definition CbmMCTrack.h:69
int32_t GetPdgCode() const
Definition CbmMCTrack.h:68
static std::vector< CbmLink > GetMcTrackMotherIdsForRichHit(CbmDigiManager *digiMan, const CbmRichHit *hit, CbmMCDataArray *richPoints, CbmMCDataArray *mcTracks)
Get CbmLinks of Mother MC Tracks for RICH hit.
static Int_t GetLayerSideIndex(Int_t address)
static Int_t GetStationIndex(Int_t address)
static Int_t GetLayerIndex(Int_t address)
double GetYOut() const
double GetZOut() const
double GetYIn() const
double GetPxOut() const
double GetPyOut() const
double GetZIn() const
double GetPzOut() const
double GetXOut() const
double GetXIn() const
double GetXOut() const
Definition CbmMvdPoint.h:67
double GetPxOut() const
Definition CbmMvdPoint.h:70
double GetPzOut() const
Definition CbmMvdPoint.h:72
int32_t GetStationNr() const
Definition CbmMvdPoint.h:75
double GetZOut() const
Definition CbmMvdPoint.h:69
double GetPyOut() const
Definition CbmMvdPoint.h:71
double GetYOut() const
Definition CbmMvdPoint.h:68
void RotatePoint(TVector3 *inPos, TVector3 *outPos, Bool_t noTilting=false)
static CbmRichGeoManager & GetInstance()
Here the ring is fitted with Taubin algorithm from A. Ayriyan, G. Ososkov, N. Chernov.
virtual void DoFit(CbmRichRingLight *ring)
Inherited from CbmRichRingFitterBase.
float GetCenterX() const
float GetAaxis() const
float GetCenterY() const
float GetBaxis() const
double GetPxOut() const
Definition CbmStsPoint.h:79
double GetZOut() const
Definition CbmStsPoint.h:78
double GetPzOut() const
Definition CbmStsPoint.h:81
double GetXOut() const
Definition CbmStsPoint.h:76
double GetYIn() const
Definition CbmStsPoint.h:74
double GetXIn() const
Definition CbmStsPoint.h:73
double GetPyOut() const
Definition CbmStsPoint.h:80
double GetZIn() const
Definition CbmStsPoint.h:75
double GetYOut() const
Definition CbmStsPoint.h:77
static CbmStsSetup * Instance()
Int_t GetStationNumber(Int_t address)
static uint32_t GetLayerId(uint32_t address)
Return layer ID from address.
double GetPzOut() const
Definition CbmTrdPoint.h:73
double GetPxIn() const
Definition CbmTrdPoint.h:74
double GetPzIn() const
Definition CbmTrdPoint.h:76
double GetYOut() const
Definition CbmTrdPoint.h:69
double GetXIn() const
Definition CbmTrdPoint.h:65
double GetZIn() const
Definition CbmTrdPoint.h:67
double GetPxOut() const
Definition CbmTrdPoint.h:71
double GetPyOut() const
Definition CbmTrdPoint.h:72
double GetXOut() const
Definition CbmTrdPoint.h:68
double GetPyIn() const
Definition CbmTrdPoint.h:75
double GetYIn() const
Definition CbmTrdPoint.h:66
double GetZOut() const
Definition CbmTrdPoint.h:70