BmnRoot
Loading...
Searching...
No Matches
BmnMCTrackCreator.cxx
Go to the documentation of this file.
1
7#include "BmnMCTrackCreator.h"
8#include "FairRootManager.h"
9#include "FairRunAna.h"
10#include "FairRuntimeDb.h"
11#include "FairGeoNode.h"
12#include "FairMCPoint.h"
13#include "CbmGeoStsPar.h"
14#include "CbmStsSensor.h"
15#include "CbmStsDigiScheme.h"
16#include "CbmGeoStsPar.h"
17#include "CbmStsDigiPar.h"
18#include "CbmMCTrack.h"
19#include "CbmStsPoint.h"
20#include "CbmBaseHit.h"
21#include "TDatabasePDG.h"
22#include "TGeoManager.h"
23#include "TClonesArray.h"
24
25using namespace std;
26
27BmnMCTrackCreator::BmnMCTrackCreator(TString gem, TString sil, TString csc)
28: fMCTracks(nullptr),
29 fSilPoints(nullptr),
30 fGemPoints(nullptr),
31 fTof400Points(nullptr),
32 fTof700Points(nullptr),
33 fCscPoints(nullptr),
34 fDchPoints(nullptr),
35 fNSiliconStations(0)
36{
37 ReadDataBranches();
38 fSilDetector = new BmnSiliconStationSet(sil);
39 fGemDetector = new BmnGemStripStationSet(gem);
40 fCscDetector = new BmnCSCStationSet(csc);
41}
42
44 delete fGemDetector;
45 delete fSilDetector;
46 delete fCscDetector;
47}
48
49BmnMCTrackCreator* BmnMCTrackCreator::Instance(TString gem, TString sil, TString csc) {
50 static BmnMCTrackCreator instance(gem, sil, csc);
51 return &instance;
52}
53
55 fBmnMCTracks.clear();
56 fNSiliconStations = fSilDetector->GetNStations();
57 fNGemStations = fGemDetector->GetNStations();
58 fNCscStations = fCscDetector->GetNStations();
59 AddPoints(kSILICON, fSilPoints);
60 AddPoints(kSSD, fSsdPoints);
61 AddPoints(kGEM, fGemPoints);
62 AddPoints(kTOF1, fTof400Points);
63 AddPoints(kTOF, fTof700Points);
64 AddPoints(kCSC, fCscPoints);
65 AddPoints(kDCH, fDchPoints);
66 // printf("fSilDetector->GetNStations() = %d\n", fSilDetector->GetNStations());
67 // printf("fGemDetector->GetNStations() = %d\n", fGemDetector->GetNStations());
68
69 // std::cout << "BmnMCTrackCreator: nof MC tracks=" << fBmnMCTracks.size() << std::endl;
70 // std::map<Int_t, BmnMCTrack>::iterator it;
71 // for (it = fBmnMCTracks.begin(); it != fBmnMCTracks.end(); it++) {
72 // printf("n gem pnts = %d\n", (*it).second.GetNofPoints(kGEM));
73 // printf("n sil pnts = %d\n", (*it).second.GetNofPoints(kSILICON));
74 // //std::cout << (*it).first << " => " << (*it).second;
75 // }
76}
77
78void BmnMCTrackCreator::ReadDataBranches() {
79 FairRootManager* ioman = FairRootManager::Instance();
80 fMCTracks = (TClonesArray*) ioman->GetObject("MCTrack");
81 fSilPoints = (TClonesArray*) ioman->GetObject("SiliconPoint");
82 fSsdPoints = (TClonesArray*) ioman->GetObject("SSDPoint");
83 fGemPoints = (TClonesArray*) ioman->GetObject("StsPoint");
84 fTof400Points = (TClonesArray*) ioman->GetObject("TOF400Point");
85 fTof700Points = (TClonesArray*) ioman->GetObject("TOF700Point");
86 fCscPoints = (TClonesArray*) ioman->GetObject("CSCPoint");
87 fDchPoints = (TClonesArray*) ioman->GetObject("DCHPoint");
88}
89
90void BmnMCTrackCreator::AddPoints(DetectorId detId, const TClonesArray* array) {
91 if (!array) return;
92 Int_t nofPoints = array->GetEntriesFast();
93 for (Int_t iPoint = 0; iPoint < nofPoints; iPoint++) {
94 FairMCPoint* fairPoint = (FairMCPoint*) (array->At(iPoint));
95 BmnMCPoint bmnPoint;
96 Int_t stationId = -1;
97 if (detId == kSILICON) {
98 stationId = fSilDetector->GetPointStationOwnership(fairPoint->GetZ());
99 // printf("stSil = %d\n", stationId);
100 } else if (detId == kSSD) {
101 // BmnSSDHitProducer hp;
102 // stationId = hp.DefineStationByZ(fairPoint->GetZ(), 0);
103 } else if (detId == kGEM) {
104 stationId = fGemDetector->GetPointStationOwnership(fairPoint->GetZ()) + fNSiliconStations;
105 } else if (detId == kCSC) {
106 stationId = fCscDetector->GetPointStationOwnership(fairPoint->GetZ()) + fNSiliconStations + fNGemStations;
107 } else if (detId == kTOF1) {
108 stationId = fNSiliconStations + fNGemStations + fNCscStations + 1;
109 } else if (detId == kTOF) {
110 stationId = fNSiliconStations + fNGemStations + fNCscStations + 2;
111 } else if (detId == kDCH) {
112 stationId = fNSiliconStations + fNGemStations + fNCscStations + 3;
113 }
114
115 if (stationId < 0) continue;
116 FairMCPointCoordinatesAndMomentumToBmnMCPoint(fairPoint, &bmnPoint);
117 FairMCPointToBmnMCPoint(fairPoint, &bmnPoint, iPoint, stationId);
118 fBmnMCTracks[fairPoint->GetTrackID()].AddPoint(detId, bmnPoint);
119 }
120}
121
122void BmnMCTrackCreator::FairMCPointToBmnMCPoint(const FairMCPoint* fairPoint, BmnMCPoint* bmnPoint, Int_t refId, Int_t stationId) {
123 bmnPoint->SetRefId(refId);
124 bmnPoint->SetStationId(stationId);
125 const CbmMCTrack* mcTrack = (const CbmMCTrack*) (fMCTracks->At(fairPoint->GetTrackID()));
126 if (mcTrack == nullptr) return; //FIXME! it shouldn't happen
127 TParticlePDG* pdgParticle = TDatabasePDG::Instance()->GetParticle(mcTrack->GetPdgCode());
128 Float_t charge = (pdgParticle != nullptr) ? pdgParticle->Charge() : 0.;
129 //Float_t q = (charge > 0) ? 1. : -1.;
130 bmnPoint->SetQ(charge / 3); //Потому что, сука, кварки!
131}
132
133void BmnMCTrackCreator::FairMCPointCoordinatesAndMomentumToBmnMCPoint(const FairMCPoint* fairPoint, BmnMCPoint* bmnPoint) {
134 bmnPoint->SetXIn(fairPoint->GetX());
135 bmnPoint->SetYIn(fairPoint->GetY());
136 bmnPoint->SetZIn(fairPoint->GetZ());
137 bmnPoint->SetPxIn(fairPoint->GetPx());
138 bmnPoint->SetPyIn(fairPoint->GetPy());
139 bmnPoint->SetPzIn(fairPoint->GetPz());
140 bmnPoint->SetXOut(fairPoint->GetX());
141 bmnPoint->SetYOut(fairPoint->GetY());
142 bmnPoint->SetZOut(fairPoint->GetZ());
143 bmnPoint->SetPxOut(fairPoint->GetPx());
144 bmnPoint->SetPyOut(fairPoint->GetPy());
145 bmnPoint->SetPzOut(fairPoint->GetPz());
146}
147
DetectorId
@ kSILICON
@ kGEM
@ kTOF
@ kSSD
@ kTOF1
@ kCSC
@ kDCH
Int_t GetPointStationOwnership(Double_t zcoord)
Int_t GetPointStationOwnership(Double_t zcoord)
Monte-Carlo point.
Definition BmnMCPoint.h:21
void SetYIn(Double_t y)
Definition BmnMCPoint.h:89
void SetPyOut(Double_t py)
Definition BmnMCPoint.h:98
void SetPxOut(Double_t px)
Definition BmnMCPoint.h:97
void SetPxIn(Double_t px)
Definition BmnMCPoint.h:91
void SetStationId(Int_t stationId)
Definition BmnMCPoint.h:102
void SetYOut(Double_t y)
Definition BmnMCPoint.h:95
void SetPzOut(Double_t pz)
Definition BmnMCPoint.h:99
void SetPyIn(Double_t py)
Definition BmnMCPoint.h:92
void SetZIn(Double_t z)
Definition BmnMCPoint.h:90
void SetPzIn(Double_t pz)
Definition BmnMCPoint.h:93
void SetXIn(Double_t x)
Definition BmnMCPoint.h:88
void SetXOut(Double_t x)
Definition BmnMCPoint.h:94
void SetZOut(Double_t z)
Definition BmnMCPoint.h:96
void SetQ(Double_t q)
Definition BmnMCPoint.h:100
void SetRefId(Int_t refId)
Definition BmnMCPoint.h:101
virtual ~BmnMCTrackCreator()
Destructor.
void Create()
Creates array of BmnMCTracks for current event. Has to be executed in Exec() function of the task.
static BmnMCTrackCreator * Instance(TString gem, TString sil, TString csc)
Singleton instance.
Int_t GetPointStationOwnership(Double_t zcoord)
Int_t GetPdgCode() const
Definition CbmMCTrack.h:56
@ array
array (ordered collection of values)
STL namespace.