CbmRoot
Simple/LxEff.cxx
Go to the documentation of this file.
1 #include "Lx.h"
2 #ifdef MAKE_EFF_CALC
3 //#include <cmath>
4 #include <iostream>
5 
6 using namespace std;
7 
9  static Int_t referenceMCTracks = 0;
10  static Int_t reconstructedRefTracks = 0;
11  bool hasPositiveSignalMuon = false;
12  bool hasNegativeSignalMuon = false;
13  hasSignalInEvent = false;
14 
15  for (vector<LxMCTrack>::iterator i = MCTracks.begin(); i != MCTracks.end();
16  ++i) {
17  LxMCTrack& mcTrack = *i;
18  Int_t pdgCode = mcTrack.pdg;
19  map<LxTrack*, Int_t>
20  recoTracks; // Mapped value is the number of common points in MC and reconstructed tracks.
21  memset(mcTrack.hitsOnStations, 0, sizeof(mcTrack.hitsOnStations));
22  bool isSignal = true;
23  //list<LxPoint*> mcTrackHits[LXSTATIONS][LXLAYERS];
24  bool mcTrackMCPoints[LXSTATIONS][LXLAYERS];
25  memset(mcTrackMCPoints, 0, sizeof(mcTrackMCPoints));
26 
27  for (vector<LxMCPoint*>::iterator j = mcTrack.Points.begin();
28  j != mcTrack.Points.end();
29  ++j) {
30  LxMCPoint* pMCPoint = *j;
31  mcTrackMCPoints[pMCPoint->stationNumber][pMCPoint->layerNumber] = true;
32 
33  for (list<LxPoint*>::iterator k = pMCPoint->lxPoints.begin();
34  k != pMCPoint->lxPoints.end();
35  ++k) {
36  LxPoint* point = *k;
37  mcTrack.hitsOnStations[point->layer->station->stationNumber]
38  [point->layer->layerNumber] = true;
39  //mcTrackHits[point->layer->station->stationNumber][point->layer->layerNumber].push_back(point);
40  LxTrack* track = point->track;
41 
42  if (0 == track) continue;
43 
44  if (track->matched) continue;
45 
46  if (track->clone) continue;
47 
48  map<LxTrack*, int>::iterator l = recoTracks.find(track);
49 
50  if (l != recoTracks.end())
51  ++(l->second);
52  else
53  recoTracks[track] = 1;
54  } // for (list<LxPoint*>::iterator k = pMCPoint->lxPoints.begin(); k != pMCPoint->lxPoints.end(); ++k)
55  } // for (vector<LxMCPoint*>::iterator j = mcTrack.Points.begin(); j != mcTrack.Points.end(); ++j)
56 
57  bool enoughHits = true;
58  bool enoughMCPoints = true;
59  mcTrack.stationsWithHits = 0;
60  mcTrack.layersWithHits = 0;
61  Int_t mcpCount = 0;
62 
63  for (Int_t j = 0; j < LXSTATIONS; ++j) {
64  Int_t hitsOnSt = 0;
65  Int_t mcpOnSt = 0;
66 
67  for (Int_t k = 0; k < LXLAYERS; ++k) {
68  if (mcTrack.hitsOnStations[j][k]) {
69  ++hitsOnSt;
70  ++mcTrack.layersWithHits;
71  }
72 
73  if (mcTrackMCPoints[j][k]) {
74  ++mcpOnSt;
75  ++mcpCount;
76  }
77  } // for (Int_t k = 0; k < LXLAYERS; ++k)
78 
79  if (hitsOnSt < LXLAYERS) {
80  if (j < caSpace.stationsInAlgo) enoughHits = false;
81  } else
82  ++mcTrack.stationsWithHits;
83 
84  if (j < caSpace.stationsInAlgo && mcpOnSt < LXLAYERS)
85  enoughMCPoints = false;
86  } // for (Int_t j = 0; j < LXSTATIONS; ++j)
87 
88  scaltype pt2 = mcTrack.px * mcTrack.px + mcTrack.py * mcTrack.py;
89 
90  if (!enoughMCPoints || mcTrack.mother_ID >= 0
91  || (pdgCode != 13 && pdgCode != -13)
92  || (pPtCut && (mcTrack.p < 3.0 || pt2 < 1.0)))
93  isSignal = false;
94  else
95  ++referenceMCTracks;
96 
97  if (!isSignal) continue;
98 
99  if (-13 == pdgCode)
100  hasPositiveSignalMuon = true;
101  else
102  hasNegativeSignalMuon = true;
103 
104  LxTrack* matchTrack = 0;
105  Int_t matchedPoints = 0;
106 
107  for (map<LxTrack*, Int_t>::iterator j = recoTracks.begin();
108  j != recoTracks.end();
109  ++j) {
110  if (0 == matchTrack
111  || matchedPoints < j->second + j->first->restoredPoints) {
112  matchTrack = j->first;
113  matchedPoints = j->second + j->first->restoredPoints;
114  }
115  }
116 
117  if (0 == matchTrack) continue;
118 
119  if (matchedPoints < mcpCount * 0.7) continue;
120 
121  ++reconstructedRefTracks;
122  } // for (vector<LxMCTrack>::iterator i = MCTracks.begin(); i != MCTracks.end(); ++i)
123 
124  if (hasPositiveSignalMuon && hasNegativeSignalMuon) {
125  hasSignalInEvent = true;
126  ++signalCounter;
127  }
128 
129  Double_t result = 100 * reconstructedRefTracks;
130  result /= referenceMCTracks;
131  cout << "LxFinder::MatchMCToReco(): efficiency = " << result << "% ("
132  << reconstructedRefTracks << "/" << referenceMCTracks << ")" << endl;
133 } // void LxFinder::MatchMCToReco()
134 
136  static Int_t recoTracksCount = 0;
137  static Int_t matchedTracksCount = 0;
138  LxTrack* signalMuPlus = 0;
139  LxTrack* signalMuMinus = 0;
140  list<LxTrack*> bgrMuPlusTracks;
141  list<LxTrack*> bgrMuMinusTracks;
142 
143  for (list<LxTrack*>::iterator i = caSpace.tracks.begin();
144  i != caSpace.tracks.end();
145  ++i) {
146  LxTrack* recoTrack = *i;
147 
148  if (recoTrack->clone) continue;
149 
150  ++recoTracksCount;
151 
152  map<LxMCTrack*, Int_t> mcTracks;
153 
154  for (Int_t j = 0; j < LXSTATIONS * LXLAYERS; ++j) {
155  LxPoint* recoPoint = recoTrack->points[j];
156 
157  if (0 == recoPoint) continue;
158 
159  for (list<LxMCPoint*>::iterator k = recoPoint->mcPoints.begin();
160  k != recoPoint->mcPoints.end();
161  ++k) {
162  LxMCPoint* mcPoint = *k;
163  LxMCTrack* mcTrack = mcPoint->track;
164 
165  if (0 == mcTrack) continue;
166 
167  map<LxMCTrack*, Int_t>::iterator mcIter = mcTracks.find(mcTrack);
168 
169  if (mcIter == mcTracks.end())
170  mcTracks[mcTrack] = 1;
171  else
172  ++(mcIter->second);
173  }
174  } // for (Int_t j = 0; j < LXSTATIONS * LXLAYERS; ++j)
175 
176  LxMCTrack* bestMatch = 0;
177  Int_t matchedPoints = 0;
178 
179  for (map<LxMCTrack*, Int_t>::iterator j = mcTracks.begin();
180  j != mcTracks.end();
181  ++j) {
182  if (0 == bestMatch || j->second > matchedPoints) {
183  bestMatch = j->first;
184  matchedPoints = j->second;
185  }
186  }
187 
188  if (0 == bestMatch) continue;
189 
190  Int_t recoPoints = 0;
191 
192  for (Int_t j = 0; j < LXSTATIONS * LXLAYERS; ++j) {
193  LxPoint* recoPoint = recoTrack->points[j];
194 
195  if (0 != recoPoint) ++recoPoints;
196  }
197 
198  if (matchedPoints < 0.7 * recoPoints) continue;
199 
200  ++matchedTracksCount;
201 
202  LxRay* ray0 = recoTrack->rays[0];
203  LxPoint* point0 = ray0->end;
204  scaltype x0 = point0->x - point0->z * ray0->tx;
205  scaltype y0 = point0->y - point0->z * ray0->ty;
206 
207  if (0 != bestMatch && bestMatch->mother_ID < 0
208  && (-13 == bestMatch->pdg || 13 == bestMatch->pdg)) {
209  signalXAtZ0->Fill(x0);
210  signalYAtZ0->Fill(y0);
211 
212  if (-13 == bestMatch->pdg)
213  signalMuPlus = recoTrack;
214  else
215  signalMuMinus = recoTrack;
216  } else {
217  bgrXAtZ0->Fill(x0);
218  bgrYAtZ0->Fill(y0);
219  scaltype charge = ray0->tx - point0->x / point0->z;
220 
221  if (charge > 0)
222  bgrMuPlusTracks.push_back(recoTrack);
223  else if (charge < 0)
224  bgrMuMinusTracks.push_back(recoTrack);
225  }
226  } // for (list<LxTrack*>::iterator i = caSpace.tracks.begin(); i != caSpace.tracks.end(); ++i)
227 
228  Double_t result = 100 * matchedTracksCount;
229  result /= recoTracksCount;
230  cout << "LxFinder::MatchRecoToMC(): efficiency = " << result << "% ("
231  << matchedTracksCount << "/" << recoTracksCount << ")" << endl;
232 
233  if (0 != signalMuPlus && 0 != signalMuMinus) {
234  scaltype x1 = signalMuPlus->rays[0]->end->x;
235  scaltype y1 = signalMuPlus->rays[0]->end->y;
236  scaltype z1 = signalMuPlus->rays[0]->end->z;
237  scaltype x2 = signalMuMinus->rays[0]->end->x;
238  scaltype y2 = signalMuMinus->rays[0]->end->y;
239  scaltype z2 = signalMuMinus->rays[0]->end->z;
240  scaltype deltaX = x1 - x2;
241  scaltype deltaY = y1 - y2;
242  scaltype deltaZ = z1 - z2;
243  scaltype d = sqrt(deltaX * deltaX + deltaY * deltaY);
244  signalInterTracksDistanceOn1st->Fill(d);
245  scaltype aSq = x1 * x1 + y1 * y1 + z1 * z1;
246  scaltype a = sqrt(aSq);
247  scaltype bSq = x2 * x2 + y2 * y2 + z2 * z2;
248  scaltype b = sqrt(bSq);
249  scaltype cSq = deltaX * deltaX + deltaY * deltaY + deltaZ * deltaZ;
250  scaltype cosC = (aSq + bSq - cSq) / (2 * a * b);
251  scaltype C = acos(cosC);
252  C *= 180;
253  C /= 3.14159265;
254  signalInterTracksAngle->Fill(C);
255  signalInterTrackCorrDA->Fill(d, C);
256  } // if (0 != signalMuPlus && 0 != signalMuMinus)
257 
258  scaltype bgrMuDistSq = 0;
259  scaltype bgrMuAngle = 0;
260 
261  for (list<LxTrack*>::iterator i = bgrMuPlusTracks.begin();
262  i != bgrMuPlusTracks.end();
263  ++i) {
264  LxTrack* mupt = *i;
265  scaltype x1 = mupt->rays[0]->end->x;
266  scaltype y1 = mupt->rays[0]->end->y;
267  scaltype z1 = mupt->rays[0]->end->z;
268 
269  for (list<LxTrack*>::iterator j = bgrMuMinusTracks.begin();
270  j != bgrMuMinusTracks.end();
271  ++j) {
272  LxTrack* mumt = *j;
273  scaltype x2 = mumt->rays[0]->end->x;
274  scaltype y2 = mumt->rays[0]->end->y;
275  scaltype z2 = mumt->rays[0]->end->z;
276  scaltype deltaX = x1 - x2;
277  scaltype deltaY = y1 - y2;
278  scaltype deltaZ = z1 - z2;
279  scaltype dSq = deltaX * deltaX + deltaY * deltaY;
280 
281  if (dSq > bgrMuDistSq) bgrMuDistSq = dSq;
282 
283  scaltype aSq = x1 * x1 + y1 * y1 + z1 * z1;
284  scaltype a = sqrt(aSq);
285  scaltype bSq = x2 * x2 + y2 * y2 + z2 * z2;
286  scaltype b = sqrt(bSq);
287  scaltype cSq = deltaX * deltaX + deltaY * deltaY + deltaZ * deltaZ;
288  scaltype cosC = (aSq + bSq - cSq) / (2 * a * b);
289  scaltype C = acos(cosC);
290  C *= 180;
291  C /= 3.14159265;
292 
293  if (C > bgrMuAngle) bgrMuAngle = C;
294  } // for (list<LxTrack*>::iterator j = bgrMuMinusTracks.begin(); j != bgrMuMinusTracks.end(); ++j)
295  } // for (list<LxTrack*>::iterator i = bgrMuPlusTracks.begin(); i != bgrMuPlusTracks.end(); ++i)
296 
297  if (bgrMuDistSq > 0) bgrInterTracksDistanceOn1st->Fill(sqrt(bgrMuDistSq));
298 
299  if (bgrMuAngle > 0) bgrInterTracksAngle->Fill(bgrMuAngle);
300 
301  if (bgrMuDistSq > 0 && bgrMuAngle > 0)
302  bgrInterTrackCorrDA->Fill(sqrt(bgrMuDistSq), bgrMuAngle);
303 } // void LxFinder::MatchRecoToMC()
304 
305 #endif //MAKE_EFF_CALC
LxTrack
Definition: LxCA.h:268
LxMCPoint
Definition: Simple/LxMC.h:16
LxMCTrack::stationsWithHits
Int_t stationsWithHits
Definition: Simple/LxMC.h:37
LxSpace::stationsInAlgo
Int_t stationsInAlgo
Definition: LxCA.h:333
LxPoint::track
LxTrack * track
Definition: LxCA.h:58
scaltype
#define scaltype
Definition: CbmGlobalTrackingDefs.h:17
memset
void memset(T *dest, T i, size_t num)
Definition: L1Grid.cxx:21
LxMCTrack::pdg
Int_t pdg
Definition: Simple/LxMC.h:30
sqrt
friend F32vec4 sqrt(const F32vec4 &a)
Definition: L1/vectors/P4_F32vec4.h:41
LxMCTrack::layersWithHits
Int_t layersWithHits
Definition: Simple/LxMC.h:38
LxSpace::tracks
std::list< LxTrack * > tracks
Definition: LxCA.h:326
i
int i
Definition: L1/vectors/P4_F32vec4.h:25
LxMCTrack::p
scaltype p
Definition: Simple/LxMC.h:28
LxTrack::rays
LxRay * rays[LXSTATIONS - 1]
Definition: LxCA.h:281
acos
friend F32vec4 acos(const F32vec4 &a)
Definition: L1/vectors/P4_F32vec4.h:138
LxMCTrack::Points
std::vector< LxMCPoint * > Points
Definition: Simple/LxMC.h:31
LxMCPoint::layerNumber
Int_t layerNumber
Definition: Simple/LxMC.h:18
LXLAYERS
#define LXLAYERS
Definition: Simple/LxSettings.h:8
caSpace
LxSpace caSpace
Definition: riplet/Lx.cxx:72
LxPoint::y
scaltype y
Definition: LxCA.h:53
LxStation::stationNumber
int stationNumber
Definition: LxCA.h:206
LxPoint
Definition: LxCA.h:52
LxMCPoint::lxPoints
std::list< LxPoint * > lxPoints
Definition: Simple/LxMC.h:19
z2
Double_t z2[nSects2]
Definition: pipe_v16a_mvdsts100.h:11
LxMCPoint::stationNumber
Int_t stationNumber
Definition: Simple/LxMC.h:18
LxRay::ty
scaltype ty
Definition: LxCA.h:116
d
double d
Definition: P4_F64vec2.h:24
mcTracks
static vector< vector< QAMCTrack > > mcTracks
Definition: CbmTofHitFinderTBQA.cxx:112
LxTrack::matched
bool matched
Definition: LxCA.h:275
LxRay::tx
scaltype tx
Definition: LxCA.h:116
LxPoint::z
scaltype z
Definition: LxCA.h:53
Lx.h
LxMCPoint::track
LxMCTrack * track
Definition: Simple/LxMC.h:22
LxMCTrack::px
scaltype px
Definition: Simple/LxMC.h:28
LxPoint::mcPoints
std::list< LxMCPoint * > mcPoints
Definition: LxCA.h:63
LxLayer::layerNumber
int layerNumber
Definition: LxCA.h:155
LxFinder::MatchRecoToMC
void MatchRecoToMC()
Definition: Simple/LxEff.cxx:135
LxRay::end
LxPoint * end
Definition: LxCA.h:119
LxMCTrack::hitsOnStations
bool hitsOnStations[LXSTATIONS][LXLAYERS]
Definition: Simple/LxMC.h:39
LxTrack::points
LxPoint * points[LXSTATIONS *LXLAYERS]
Definition: LxCA.h:282
LxTrack::clone
bool clone
Definition: LxCA.h:292
LxTrack::restoredPoints
int restoredPoints
Definition: LxCA.h:288
pPtCut
bool pPtCut
Definition: riplet/Lx.cxx:61
LxMCTrack
Definition: Simple/LxMC.h:27
z1
Double_t z1[nSects1]
Definition: pipe_v16a_mvdsts100.h:6
LxPoint::layer
LxLayer * layer
Definition: LxCA.h:60
LxFinder::MatchMCToReco
void MatchMCToReco()
Definition: Simple/LxEff.cxx:8
LXSTATIONS
#define LXSTATIONS
Definition: Simple/LxSettings.h:9
LxLayer::station
LxStation * station
Definition: LxCA.h:154
LxPoint::x
scaltype x
Definition: LxCA.h:53
LxMCTrack::mother_ID
Int_t mother_ID
Definition: Simple/LxMC.h:29
LxMCTrack::py
scaltype py
Definition: Simple/LxMC.h:28
LxRay
Definition: LxCA.h:115
MCTracks
std::vector< LxMCTrack > MCTracks
Definition: riplet/Lx.cxx:65