BmnRoot 26.10.0-18-g4e3414f9
Software framework of the BM@N experiment
Loading...
Searching...
No Matches
readSim.C
Go to the documentation of this file.
1// @(#)bmnroot/macro/howTo:$Id$
2////////////////////////////////////////////////////////////////////////////////
3// //
4// readSim.C //
5// //
6// An example how to read simulated data (MC) from bmnsim.root //
7// //
8////////////////////////////////////////////////////////////////////////////////
9#include <fairlogger/Logger.h>
10
11int readSim(TString simFilePath = "")
12{
13 if (simFilePath == "") {
14 LOG(error) << "Simulation file not specified!";
15 return -1;
16 }
17
18 // check SIM file exists
19 if (!BmnFunctionSet::CheckFileExist(simFilePath, 1))
20 return -2;
21
22 // open SIM file with 'bmndata' tree
23 TChain* dataChain = new TChain("bmndata");
24 dataChain->Add(simFilePath.Data());
25 LOG(info) << "Event Number = " << dataChain->GetEntries();
26
27 /** assign TClonesArrays to SIM tree branches **/
28 // assign event header class to the MC event header
29 FairMCEventHeader* event_header = nullptr;
30 dataChain->SetBranchAddress("MCEventHeader.", &event_header);
31 if (event_header == nullptr) {
32 LOG(error) << "'MCEventHeader.' branch was not found, please, check the structure of the file, exiting...";
33 return -3;
34 }
35
36 // assign TClonesArray to the branch with MC tracks
37 TClonesArray* mcTracks = nullptr;
38 dataChain->SetBranchAddress("MCTrack", &mcTracks);
39 if (mcTracks == nullptr) {
40 LOG(error) << "'MCTrack' branch was not found, please, check the structure of the file, exiting...";
41 return -4;
42 }
43
44 // assign TClonesArrays to branches with track points in the detectors
45 TClonesArray* stsPoints = nullptr;
46 dataChain->SetBranchAddress("StsPoint", &stsPoints);
47 if (stsPoints == nullptr) {
48 LOG(error) << "'StsPoint' branch was not found, please, check the structure of the file, exiting...";
49 return -5;
50 }
51 // and other necessary track points in a similar way...
52
53 // assign TClonesArrays to branches with detector digits
54 TClonesArray* siliconDigits = nullptr;
55 dataChain->SetBranchAddress("BmnSiliconDigit", &siliconDigits);
56 if (siliconDigits == nullptr) {
57 LOG(error) << "'BmnSiliconDigit' branch was not found, please, check the structure of the file, exiting...";
58 return -6;
59 }
60 // and other necessary detector digits in a similar way...
61
62 // event loop
63 for (Int_t iEvent = 0; iEvent < dataChain->GetEntries(); iEvent++) {
64 LOG(info) << "Event# " << iEvent;
65
66 // next event
67 dataChain->GetEntry(iEvent);
68
69 // read MC Event Header
70 if (event_header) {
71 cout << "|||||||||||| MC EVENT SUMMARY ||||||||||||||||||||||" << endl;
72 cout << "||\t\t\t\t\t\t ||" << setprecision(3) << endl;
73 cout << "|| Event number: " << event_header->GetEventID() << "\t\t\t ||" << endl;
74 cout << "|| Vertex (x:y:z): " << event_header->GetX() << ":" << event_header->GetY() << ":"
75 << event_header->GetZ() << " cm\t ||" << endl;
76 cout << "|| Impact parameter: " << event_header->GetB() << " fm\t\t\t ||" << endl;
77 cout << "|| Beam tilt (x:y): " << event_header->GetRotX() << "" << event_header->GetRotY()
78 << " rad\t\t ||" << endl;
79 cout << "|| Event plane: " << event_header->GetRotZ() << " rad\t\t\t ||" << endl;
80 cout << "|| input tracks: " << event_header->GetNPrim() << "\t\t\t ||" << endl;
81 cout << "||\t\t\t\t\t\t ||" << endl;
82 cout << "||||||||||||||||||||||||||||||||||||||||||||||||||||" << endl;
83 }
84
85 // read MC Tracks
86 for (Int_t iTrack = 0; iTrack < mcTracks->GetEntriesFast(); iTrack++) {
87 CbmMCTrack* mcTrack = (CbmMCTrack*)mcTracks->UncheckedAt(iTrack);
88
89 // Get MC track data
90 cout << endl;
91 Int_t MotherId = mcTrack->GetMotherId();
92 LOG(info) << "MC Track " << iTrack << ": mother track ID = " << MotherId;
93 TVector3 Vertex;
94 mcTrack->GetStartVertex(Vertex);
95 LOG(info) << "MC Track " << iTrack << ": vertex = " << Vertex.X() << ":" << Vertex.Y() << ":" << Vertex.Z();
96 TVector3 Ptot;
97 mcTrack->GetMomentum(Ptot);
98 LOG(info) << "MC Track " << iTrack << ": momentum = " << Ptot.X() << ":" << Ptot.Y() << ":" << Ptot.Z();
99 // TParticle* P = (TParticle*) tr->GetParticle();
100 LOG(info) << "MC Track " << iTrack << ": particle PDG code = " << mcTrack->GetPdgCode();
101 TParticlePDG* fParticlePDG = TDatabasePDG::Instance()->GetParticle(mcTrack->GetPdgCode());
102 Float_t charge = (fParticlePDG != nullptr) ? fParticlePDG->Charge() : 0., mass = -1, ene = -1;
103 if (fParticlePDG)
104 mass = fParticlePDG->Mass();
105 if (mass >= 0)
106 ene = TMath::Sqrt(mass * mass + Ptot.Mag2());
107
108 // Put here your code ...
109 // See $VMCWORKDIR/base/data/CbmMCTrack.h to get more ...
110
111 // Get STS points and select ones belonging the current track
112 for (Int_t iPoint = 0; iPoint < stsPoints->GetEntriesFast(); iPoint++) {
113 CbmStsPoint* stsPoint = (CbmStsPoint*)stsPoints->UncheckedAt(iPoint);
114
115 Int_t TrackID = stsPoint->GetTrackID();
116 if (TrackID != iTrack)
117 continue;
118
119 // Put here your code ...
120 // See $VMCWORKDIR/base/cbm/CbmStsPoint.h to get more ...
121 }
122
123 // Get silicon digits and select ones belonging the current track
124 for (Int_t iDigit = 0; iDigit < siliconDigits->GetEntriesFast(); iDigit++) {
125 BmnStripDigit* siliconDigit = (BmnStripDigit*)siliconDigits->UncheckedAt(iDigit); // BmnSiliconDigit
126 if (siliconDigit->IsGoodDigit()) {
127 Int_t stationNumber = siliconDigit->GetStation();
128 Int_t moduleNumber = siliconDigit->GetModule();
129 Int_t layerNumber = siliconDigit->GetStripLayer();
130 Int_t stripNumber = siliconDigit->GetStripNumber();
131 Double_t signalNumber = siliconDigit->GetStripNumber();
132 }
133
134 // Put here your code ...
135 // See $VMCWORKDIR/detectos/silicon/BmnSiliconDigit.h and $VMCWORKDIR/base/data/BmnStripDigit.h to get
136 // more ...
137 }
138 }
139 }
140
141 return true;
142}
int Int_t
float Float_t
double Double_t
static int CheckFileExist(TString &fileName, int iVerbose=0, EAccessMode mode=kFileExists)
Class BmnStripDigit Base class for strip detector digits.
Bool_t IsGoodDigit()
Int_t GetStripNumber()
Int_t GetStripLayer()
Int_t GetStation()
Int_t GetModule()
CbmMCTrack.h.
Definition CbmMCTrack.h:26
void GetMomentum(TVector3 &momentum) const
Definition CbmMCTrack.h:139
Int_t GetMotherId() const
Definition CbmMCTrack.h:57
void GetStartVertex(TVector3 &vertex) const
Definition CbmMCTrack.h:149
Int_t GetPdgCode() const
Accessors.
Definition CbmMCTrack.h:56
Int_t SetBranchAddress(const char *bname, T **add, TBranch **ptr=nullptr)
virtual Int_t Add(const char *name, Long64_t nentries=TTree::kMaxEntries)
Long64_t GetEntries() const override
Int_t GetEntry(Long64_t entry=0, Int_t getall=0) override
static TDatabasePDG * Instance()
TParticlePDG * GetParticle(const char *name) const
Int_t GetEntriesFast() const
TObject * UncheckedAt(Int_t i) const
Double_t Charge() const
Double_t Mass() const
Double_t Z() const
Double_t Y() const
Double_t Mag2() const
Double_t X() const
int readSim(TString simFilePath="")
Definition readSim.C:11
Double_t Sqrt(Double_t x)