CbmRoot
Loading...
Searching...
No Matches
LmvmUtils.cxx
Go to the documentation of this file.
1/* Copyright (C) 2010-2021 Justus-Liebig-Universitaet Giessen, Giessen
2 SPDX-License-Identifier: GPL-3.0-only
3 Authors: Semen Lebedev [committer]*/
4
5#include "LmvmUtils.h"
6
7#include "CbmKFVertex.h"
8#include "CbmL1PFFitter.h"
9#include "CbmMCTrack.h"
10#include "CbmStsTrack.h"
12
13#include "Logger.h"
14
15#include "TClonesArray.h"
16#include "TDatabasePDG.h"
17#include "TMCProcess.h"
18#include "TRandom3.h"
19
20#include <iostream>
21
22//#include "L1Field.h"
23#include "LmvmCand.h"
24#include "LmvmDef.h"
25
26using std::string;
27using std::vector;
28
30
32{
33 CbmL1PFFitter fPFFitter;
34 vector<CbmStsTrack> stsTracks;
35 stsTracks.resize(1);
36 stsTracks[0] = *stsTrack;
37 //vector<L1FieldRegion> vField; // TODO: this line or next (think of #include "L1Field.h" in header!)
38 vector<CbmL1PFFitter::PFFieldRegion> vField;
39 vector<float> chiPrim;
40 fPFFitter.GetChiToVertex(stsTracks, vField, chiPrim, kfVertex, 3e6);
41 cand->fChi2Sts = stsTracks[0].GetChiSq() / stsTracks[0].GetNDF();
42 cand->fChi2Prim = chiPrim[0];
43 const FairTrackParam* vtxTrack = stsTracks[0].GetParamFirst();
44
45 vtxTrack->Position(cand->fPosition);
46 vtxTrack->Momentum(cand->fMomentum);
47
48 cand->fMass = TDatabasePDG::Instance()->GetParticle(11)->Mass();
49 cand->fCharge = (vtxTrack->GetQp() > 0) ? 1 : -1;
50 cand->fEnergy = sqrt(cand->fMomentum.Mag2() + cand->fMass * cand->fMass);
51 cand->fRapidity = 0.5 * TMath::Log((cand->fEnergy + cand->fMomentum.Z()) / (cand->fEnergy - cand->fMomentum.Z()));
52}
53
54void LmvmUtils::CalculateArmPodParams(LmvmCand* cand1, LmvmCand* cand2, double& alpha, double& ptt)
55{
56 alpha = ptt = 0.;
57 double spx = cand1->fMomentum.X() + cand2->fMomentum.X();
58 double spy = cand1->fMomentum.Y() + cand2->fMomentum.Y();
59 double spz = cand1->fMomentum.Z() + cand2->fMomentum.Z();
60 double sp = sqrt(spx * spx + spy * spy + spz * spz);
61
62 if (sp == 0.0) return;
63 double pn, /*pp,*/ pln, plp;
64 if (cand1->fCharge < 0.) {
65 pn = cand1->fMomentum.Mag();
66 //pp = cand2->fMomentum.Mag();
67 pln = (cand1->fMomentum.X() * spx + cand1->fMomentum.Y() * spy + cand1->fMomentum.Z() * spz) / sp;
68 plp = (cand2->fMomentum.X() * spx + cand2->fMomentum.Y() * spy + cand2->fMomentum.Z() * spz) / sp;
69 }
70 else {
71 pn = cand2->fMomentum.Mag();
72 //pp = cand1->fMomentum.Mag();
73 pln = (cand2->fMomentum.X() * spx + cand2->fMomentum.Y() * spy + cand2->fMomentum.Z() * spz) / sp;
74 plp = (cand1->fMomentum.X() * spx + cand1->fMomentum.Y() * spy + cand1->fMomentum.Z() * spz) / sp;
75 }
76 if (pn == 0.0) return;
77 double ptm = (1. - ((pln / pn) * (pln / pn)));
78 ptt = (ptm >= 0.) ? pn * sqrt(ptm) : 0;
79 alpha = (plp - pln) / (plp + pln);
80}
81
83{
84 if (IsMcSignalEl(mctrack)) return ELmvmSrc::Signal;
85 if (IsMcPi0El(mctrack, mcTracks)) return ELmvmSrc::Pi0;
86 if (IsMcGammaEl(mctrack, mcTracks)) return ELmvmSrc::Gamma;
87 if (IsMcEtaEl(mctrack, mcTracks)) return ELmvmSrc::Eta;
88 return ELmvmSrc::Bg; // all bg track wich are not pi0, gamma, eta electrons
89}
90
92{
93 if (mct != nullptr && mct->GetGeantProcessId() == kPPrimary && std::abs(mct->GetPdgCode()) == 11) return true;
94 return false;
95}
96
97bool LmvmUtils::IsMcGammaEl(const CbmMCTrack* mct, TClonesArray* mcTracks)
98{
99 if (mct == nullptr || std::abs(mct->GetPdgCode()) != 11 || mct->GetMotherId() < 0) return false;
100 CbmMCTrack* mct1 = static_cast<CbmMCTrack*>(mcTracks->At(mct->GetMotherId()));
101 if (mct1 != nullptr && mct1->GetPdgCode() == 22) return true;
102 return false;
103}
104
105bool LmvmUtils::IsMcPi0El(const CbmMCTrack* mct, TClonesArray* mcTracks)
106{
107 if (mct == nullptr || std::abs(mct->GetPdgCode()) != 11 || mct->GetMotherId() < 0) return false;
108 CbmMCTrack* mct1 = static_cast<CbmMCTrack*>(mcTracks->At(mct->GetMotherId()));
109 if (mct1 != nullptr && mct1->GetPdgCode() == 111) return true;
110 return false;
111}
112
113bool LmvmUtils::IsMcEtaEl(const CbmMCTrack* mct, TClonesArray* mcTracks)
114{
115 if (mct == nullptr || std::abs(mct->GetPdgCode()) != 11 || mct->GetMotherId() < 0) return false;
116 CbmMCTrack* mct1 = static_cast<CbmMCTrack*>(mcTracks->At(mct->GetMotherId()));
117 if (mct1 != NULL && mct1->GetPdgCode() == 221) return true;
118 return false;
119}
120
121bool LmvmUtils::IsMcPairSignal(const CbmMCTrack* mctP, const CbmMCTrack* mctM)
122{
123 return (IsMcSignalEl(mctM) && IsMcSignalEl(mctP));
124}
125
126bool LmvmUtils::IsMcPairPi0(const CbmMCTrack* mctP, const CbmMCTrack* mctM, TClonesArray* mcTracks)
127{
128 return ((mctM->GetMotherId() == mctP->GetMotherId()) && IsMcPi0El(mctM, mcTracks) && IsMcPi0El(mctP, mcTracks));
129}
130
131bool LmvmUtils::IsMcPairEta(const CbmMCTrack* mctP, const CbmMCTrack* mctM, TClonesArray* mcTracks)
132{
133 return ((mctM->GetMotherId() == mctP->GetMotherId()) && IsMcEtaEl(mctM, mcTracks) && IsMcEtaEl(mctP, mcTracks));
134}
135
136bool LmvmUtils::IsMcPairGamma(const CbmMCTrack* mctP, const CbmMCTrack* mctM, TClonesArray* mcTracks)
137{
138 return ((mctM->GetMotherId() == mctP->GetMotherId()) && IsMcGammaEl(mctM, mcTracks) && IsMcGammaEl(mctP, mcTracks));
139}
140
141bool LmvmUtils::IsMcPairBg(const CbmMCTrack* mctP, const CbmMCTrack* mctM, TClonesArray* mcTracks)
142{
143 //bool isGamma = IsMcPairGamma(mctP, mctM, mcTracks);
144 bool isEta = IsMcPairEta(mctP, mctM, mcTracks);
145 bool isPi0 = IsMcPairPi0(mctP, mctM, mcTracks);
146 //return (!isEta) && (!isGamma) && (!isPi0) && (!(IsMcSignalEl(mctP) && IsMcSignalEl(mctM))); // TODO: this line or next?
147 return (!isEta) && (!isPi0) && (!(IsMcSignalEl(mctP) && IsMcSignalEl(mctM)));
148}
149
150ELmvmSrc LmvmUtils::GetMcPairSrc(const CbmMCTrack* mctP, const CbmMCTrack* mctM, TClonesArray* mcTracks)
151{
152 if (IsMcPairSignal(mctP, mctM)) return ELmvmSrc::Signal;
153 if (IsMcPairGamma(mctP, mctM, mcTracks)) return ELmvmSrc::Gamma;
154 if (IsMcPairPi0(mctP, mctM, mcTracks)) return ELmvmSrc::Pi0;
155 if (IsMcPairEta(mctP, mctM, mcTracks)) return ELmvmSrc::Eta;
156 if (IsMcPairBg(mctP, mctM, mcTracks)) return ELmvmSrc::Bg;
157
158 return ELmvmSrc::Undefined;
159}
160
161
162bool LmvmUtils::IsMcPairSignal(const LmvmCand& candP, const LmvmCand& candM)
163{
164 return (candP.IsMcSignal() && candM.IsMcSignal());
165}
166
167bool LmvmUtils::IsMcPairPi0(const LmvmCand& candP, const LmvmCand& candM)
168{
169 return (candP.IsMcPi0() && candM.IsMcPi0() && candP.fMcMotherId == candM.fMcMotherId);
170}
171
172bool LmvmUtils::IsMcPairEta(const LmvmCand& candP, const LmvmCand& candM)
173{
174 return (candP.IsMcEta() && candM.IsMcEta() && candP.fMcMotherId == candM.fMcMotherId);
175}
176
177bool LmvmUtils::IsMcPairGamma(const LmvmCand& candP, const LmvmCand& candM)
178{
179 return (candP.IsMcGamma() && candM.IsMcGamma() && candP.fMcMotherId == candM.fMcMotherId);
180}
181
182bool LmvmUtils::IsMcPairBg(const LmvmCand& candP, const LmvmCand& candM)
183{
184 //bool isGamma = IsMcPairGamma(candP, candM);
185 bool isEta = IsMcPairEta(candP, candM);
186 bool isPi0 = IsMcPairPi0(candP, candM);
187 //return (!isEta) && (!isGamma) && (!isPi0) && (!(candP.IsMcSignal() && candM.IsMcSignal())); // TODO: this line or next?
188 return (!isEta) && (!isPi0) && (!(candP.IsMcSignal() && candM.IsMcSignal()));
189}
190
192{
193 if (IsMcPairSignal(candP, candM)) return ELmvmSrc::Signal;
194 if (IsMcPairGamma(candP, candM)) return ELmvmSrc::Gamma;
195 if (IsMcPairPi0(candP, candM)) return ELmvmSrc::Pi0;
196 if (IsMcPairEta(candP, candM)) return ELmvmSrc::Eta;
197 if (IsMcPairBg(candP, candM)) return ELmvmSrc::Bg;
198
199 return ELmvmSrc::Undefined;
200}
201
203{
204 if (candM.IsMcGamma()) {
205 if (candP.IsMcGamma() && candP.fMcMotherId != candM.fMcMotherId) return ELmvmBgPairSrc::GG;
206 if (candP.IsMcPi0()) return ELmvmBgPairSrc::GP;
207 return ELmvmBgPairSrc::GO;
208 }
209 else if (candM.IsMcPi0()) {
210 if (candP.IsMcGamma()) return ELmvmBgPairSrc::GP;
211 if (candP.IsMcPi0() && candP.fMcMotherId != candM.fMcMotherId) return ELmvmBgPairSrc::PP;
212 return ELmvmBgPairSrc::PO;
213 }
214 else {
215 if (candP.IsMcGamma()) return ELmvmBgPairSrc::GO;
216 if (candP.IsMcPi0()) return ELmvmBgPairSrc::PO;
217 return ELmvmBgPairSrc::OO;
218 }
219
221}
222
224{
225 if (cand.fStsMcTrackId == cand.fRichMcTrackId && cand.fStsMcTrackId == cand.fTrdMcTrackId
226 && cand.fStsMcTrackId == cand.fTofMcTrackId && cand.fStsMcTrackId != -1)
227 return false;
228 return true;
229}
230
232{
233 if (cand.fStsMcTrackId == -1 || cand.fRichMcTrackId == -1 || cand.fTrdMcTrackId == -1 || cand.fTofMcTrackId == -1)
234 return true;
235 return false;
236}
237
238double LmvmUtils::Distance(double x1, double y1, double x2, double y2) { return std::sqrt(Distance2(x1, y1, x2, y2)); }
239
240double LmvmUtils::Distance2(double x1, double y1, double x2, double y2)
241{
242 return (x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2);
243}
244
245void LmvmUtils::IsElectron(int globalTrackIndex, double momentum, double momentumCut, LmvmCand* cand)
246{
247 bool richEl = CbmLitGlobalElectronId::GetInstance().IsRichElectron(globalTrackIndex, momentum);
248 cand->fRichAnn = CbmLitGlobalElectronId::GetInstance().GetRichAnn(globalTrackIndex, momentum);
249
250 bool trdEl = CbmLitGlobalElectronId::GetInstance().IsTrdElectron(globalTrackIndex, momentum);
251 // Additional TRD Cut
252 //if (cand->fChi2Trd > 6.) trdEl = false;
253
254 bool tofEl = CbmLitGlobalElectronId::GetInstance().IsTofElectron(globalTrackIndex, momentum);
255 cand->fMass2 = CbmLitGlobalElectronId::GetInstance().GetTofM2(globalTrackIndex, momentum);
256 // Additional ToF Cut
257 /*if (momentum >= 0.5 && momentum <= 2.) {
258 double slope = 4.;
259 double b = 0.;
260 if (cand->fTofDist > momentum*slope + b) tofEl = false;
261 }*/
262
263 bool isMomCut = (momentumCut > 0.) ? (momentum < momentumCut) : true;
264 cand->fIsElectron = (richEl && trdEl && tofEl && isMomCut);
265}
266
267void LmvmUtils::IsRichElectron(int globalTrackIndex, double momentum, LmvmCand* cand)
268{
269 cand->fIsRichElectron = CbmLitGlobalElectronId::GetInstance().IsRichElectron(globalTrackIndex, momentum);
270}
271
272void LmvmUtils::IsTrdElectron(int globalTrackIndex, double momentum, LmvmCand* cand)
273{
274 cand->fIsTrdElectron =
275 (momentum < 1.) ? true : CbmLitGlobalElectronId::GetInstance().IsTrdElectron(globalTrackIndex, momentum);
276}
277
278void LmvmUtils::IsTofElectron(int globalTrackIndex, double momentum, LmvmCand* cand)
279{
280 cand->fIsTofElectron = CbmLitGlobalElectronId::GetInstance().IsTofElectron(globalTrackIndex, momentum);
281}
282
283void LmvmUtils::IsElectronMc(LmvmCand* cand, TClonesArray* mcTracks, double pionMisidLevel)
284{
285 // Use MC information for PID to set a required level of pion suppression
286 if (cand->fStsMcTrackId < 0 || cand->fStsMcTrackId >= mcTracks->GetEntriesFast()) { cand->fIsElectron = false; }
287 else {
288 CbmMCTrack* mcTrack = static_cast<CbmMCTrack*>(mcTracks->At(cand->fStsMcTrackId));
289 if (std::abs(mcTrack->GetPdgCode()) == 11) { cand->fIsElectron = true; }
290 else {
291 cand->fIsElectron = (gRandom->Rndm() < pionMisidLevel);
292 }
293 }
294}
295
297{
298 if (cand->fCharge == 0) return "0";
299 return (cand->fCharge > 0) ? "+" : "-";
300}
301
303{
304 if (mct->GetCharge() == 0) return "0";
305 return (mct->GetCharge() > 0) ? "+" : "-";
306}
307
308double LmvmUtils::GetMassScaleInmed(double minv) // TODO: make these more elegant and delete cout's
309{
310 int nArray = sizeof(fMinvArray);
311 double weight = -1.;
312
313 if (minv < fMinvArray[0]) return fScaleArrayInmed[0];
314 else {
315 for (int i = 1; i < nArray; i++) {
316 if (fMinvArray[i] > minv) {
317 double dy = fScaleArrayInmed[i] - fScaleArrayInmed[i - 1];
318 double dx = fMinvArray[i] - fMinvArray[i - 1];
319 double slope = dy / dx;
320 double dLeft = minv - fMinvArray[i - 1];
321 weight = fScaleArrayInmed[i - 1] + slope * dLeft;
322 return weight;
323 }
324 }
325 }
326 return weight;
327}
328
329double LmvmUtils::GetMassScaleQgp(double minv) // TODO: make these more elegant and delete cout's
330{
331 int nArray = sizeof(fMinvArray);
332 double weight = -1.;
333
334 if (minv < fMinvArray[0]) return fScaleArrayQgp[0];
335 else {
336 for (int i = 1; i < nArray; i++) {
337 if (fMinvArray[i] > minv) {
338 double dy = fScaleArrayQgp[i] - fScaleArrayQgp[i - 1];
339 double dx = fMinvArray[i] - fMinvArray[i - 1];
340 double slope = dy / dx;
341 double dLeft = minv - fMinvArray[i - 1];
342 weight = fScaleArrayQgp[i - 1] + slope * dLeft;
343 return weight;
344 }
345 }
346 }
347 return weight;
348}
Data class for STS tracks.
static vector< vector< QAMCTrack > > mcTracks
friend fvec sqrt(const fvec &a)
ELmvmSrc
Definition LmvmDef.h:23
ELmvmBgPairSrc
Definition LmvmDef.h:51
ClassImp(LmvmUtils)
void GetChiToVertex(std::vector< CbmStsTrack > &Tracks, std::vector< PFFieldRegion > &field, std::vector< float > &chiToVtx, CbmKFVertex &primVtx, float chiPrim=-1)
Bool_t IsTrdElectron(Int_t globalTrackindex, Double_t momentum)
Identify electron in RICH detector.
Double_t GetTofM2(Int_t globalTrackIndex, Double_t momentum, Double_t eventTime=1000.)
Return TOF m2 value.
Double_t GetRichAnn(Int_t globalTrackIndex, Double_t momentum)
Identify electron in RICH detector.
Bool_t IsTofElectron(Int_t globalTrackIndex, Double_t momentum, Double_t eventTime=1000.)
Identify electron in RICH detector.
Bool_t IsRichElectron(Int_t globalTrackIndex, Double_t momentum)
Identify electron in RICH detector.
static CbmLitGlobalElectronId & GetInstance()
double GetCharge() const
Charge of the associated particle.
uint32_t GetGeantProcessId() const
Definition CbmMCTrack.h:67
int32_t GetMotherId() const
Definition CbmMCTrack.h:69
int32_t GetPdgCode() const
Definition CbmMCTrack.h:68
bool IsMcPi0() const
Definition LmvmCand.h:103
bool fIsTrdElectron
Definition LmvmCand.h:67
double fChi2Sts
Definition LmvmCand.h:57
int fStsMcTrackId
Definition LmvmCand.h:72
int fCharge
Definition LmvmCand.h:55
double fEnergy
Definition LmvmCand.h:53
int fTofMcTrackId
Definition LmvmCand.h:75
bool IsMcSignal() const
Definition LmvmCand.h:102
bool fIsRichElectron
Definition LmvmCand.h:66
bool fIsTofElectron
Definition LmvmCand.h:68
double fRapidity
Definition LmvmCand.h:54
bool fIsElectron
Definition LmvmCand.h:91
bool IsMcEta() const
Definition LmvmCand.h:105
TVector3 fPosition
Definition LmvmCand.h:49
double fMass2
Definition LmvmCand.h:85
double fRichAnn
Definition LmvmCand.h:83
int fTrdMcTrackId
Definition LmvmCand.h:74
int fMcMotherId
Definition LmvmCand.h:70
double fMass
Definition LmvmCand.h:51
int fRichMcTrackId
Definition LmvmCand.h:73
bool IsMcGamma() const
Definition LmvmCand.h:104
double fChi2Prim
Definition LmvmCand.h:56
TVector3 fMomentum
Definition LmvmCand.h:50
static void IsTofElectron(int globalTrackIndex, double momentum, LmvmCand *cand)
static bool IsMcGammaEl(const CbmMCTrack *mct, TClonesArray *mcTracks)
Definition LmvmUtils.cxx:97
static double Distance(double x1, double y1, double x2, double y2)
static ELmvmSrc GetMcPairSrc(const CbmMCTrack *mctP, const CbmMCTrack *mctM, TClonesArray *mcTracks)
static void CalculateArmPodParams(LmvmCand *cand1, LmvmCand *cand2, double &alpha, double &ptt)
Definition LmvmUtils.cxx:54
static void IsElectronMc(LmvmCand *cand, TClonesArray *mcTracks, double pionMisidLevel)
static constexpr double fScaleArrayInmed[170]
Definition LmvmUtils.h:124
static double GetMassScaleQgp(double minv)
static void IsElectron(int globalTrackIndex, double momentum, double momentumCut, LmvmCand *cand)
static bool IsMcPairSignal(const CbmMCTrack *mctP, const CbmMCTrack *mctM)
static ELmvmSrc GetMcSrc(CbmMCTrack *mctrack, TClonesArray *mcTracks)
Definition LmvmUtils.cxx:82
static void IsTrdElectron(int globalTrackIndex, double momentum, LmvmCand *cand)
static bool IsMcPairEta(const CbmMCTrack *mctP, const CbmMCTrack *mctM, TClonesArray *mcTracks)
static void IsRichElectron(int globalTrackIndex, double momentum, LmvmCand *cand)
static bool IsMismatch(const LmvmCand &cand)
static constexpr double fScaleArrayQgp[170]
Definition LmvmUtils.h:145
static bool IsMcPairGamma(const CbmMCTrack *mctP, const CbmMCTrack *mctM, TClonesArray *mcTracks)
static bool IsMcPairPi0(const CbmMCTrack *mctP, const CbmMCTrack *mctM, TClonesArray *mcTracks)
static constexpr double fMinvArray[170]
Definition LmvmUtils.h:109
static bool IsGhost(const LmvmCand &cand)
static bool IsMcPairBg(const CbmMCTrack *mctP, const CbmMCTrack *mctM, TClonesArray *mcTracks)
static std::string GetChargeStr(const LmvmCand *cand)
static bool IsMcPi0El(const CbmMCTrack *mct, TClonesArray *mcTracks)
static ELmvmBgPairSrc GetBgPairSrc(const LmvmCand &candP, const LmvmCand &candM)
static double GetMassScaleInmed(double minv)
static bool IsMcSignalEl(const CbmMCTrack *mct)
Definition LmvmUtils.cxx:91
static void CalculateAndSetTrackParams(LmvmCand *cand, CbmStsTrack *stsTrack, CbmKFVertex &kfVertex)
Definition LmvmUtils.cxx:31
static bool IsMcEtaEl(const CbmMCTrack *mct, TClonesArray *mcTracks)
static double Distance2(double x1, double y1, double x2, double y2)