BmnRoot
Loading...
Searching...
No Matches
BmnEfficiency.h
Go to the documentation of this file.
1#ifndef BMNEFF_H
2#define BMNEFF_H 1
3
4#include <TNamed.h>
5#include <TChain.h>
6#include <TObject.h>
7#include <TClonesArray.h>
8#include <TGeoManager.h>
9#include <TH1.h>
10#include <TH2.h>
11#include <TEfficiency.h>
12#include <TCanvas.h>
13#include <TStyle.h>
14#include <TLine.h>
15
17#include <DstEventHeader.h>
18#include <BmnGlobalTrack.h>
19#include <BmnHit.h>
20#include <BmnKalmanFilter.h>
21#include <UniRun.h>
22#include <CbmVertex.h>
23#include <BmnVertex.h>
24#include "BmnNewFieldMap.h"
25
26#include <vector>
27
28using namespace std;
29
30// A class to be used as a store when calculating efficiency ...
31
32class EffStore : public TObject {
33public:
34
36 : detector(""),
37 station(-1),
38 module(-1),
39 zone(""),
40 nominator(0),
41 denominator(0)
42 {}
43
44 EffStore(TString det, Int_t stat, Int_t mod, TString z = "")
45 : detector(det),
46 station(stat),
47 module(mod),
48 zone(z),
49 nominator(0),
50 denominator(0)
51 {
52 hitPositionsAndEff.resize(0);
53 }
54
55 EffStore(TString det, Int_t stat, TString z = "")
56 : detector(det),
57 station(stat),
58 module(-1),
59 zone(z),
60 nominator(0),
61 denominator(0)
62 {
63 hitPositionsAndEff.resize(0);
64 }
65
67 nominator++;
68 }
69
71 denominator++;
72 }
73
74 void AddHitCoordinates(BmnHit* hit, Double_t eff = 1.) {
75 hitPositionsAndEff.push_back(TLorentzVector(hit->GetX(), hit->GetY(), hit->GetZ(), eff));
76 }
77
78 Double_t Efficiency() {
79 Double_t eff = 0.;
80 if (denominator != 0)
81 eff = 1. * nominator / denominator;
82
83 return eff;
84 }
85
86 TString Detector() { return detector; }
87 Int_t Station() { return station; }
88 Int_t Module() { return module; }
89 TString Zone() { return zone; }
90
91 vector <TLorentzVector> CoordinatesAndEffs() {
92 return hitPositionsAndEff;
93 }
94
95 virtual ~EffStore() {}
96
97private:
98 TString detector; // GEM or SILICON
99 Int_t station;
100 Int_t module;
101 TString zone; // big or hot (valid for GEM only!)
102
103 Int_t nominator;
104 Int_t denominator;
105
106 vector <TLorentzVector> hitPositionsAndEff;
107
108 ClassDef(EffStore, 1)
109};
110
112{
113 public:
115 : det("GEM"),
116 nGemCut(4),
117 nSilCut(2)
118 {
119 eContainers = nullptr;
120 }
121
123
124 // Move assignment
125
127 if (&input == this)
128 return *this;
129
130 det = input.det;
131 nGemCut = input.nGemCut;
132 nSilCut = input.nSilCut;
133
134 sfIndices.first = input.sfIndices.first;
135 sfIndices.second = input.sfIndices.second;
136
137 flParams.first = input.flParams.first;
138 flParams.second = input.flParams.second;
139
140 gPairMap = input.gPairMap;
141 sPairMap = input.sPairMap;
142
143 eContainers = input.eContainers;
144
145 for (auto it : input.usedStats)
146 usedStats.push_back(it);
147
148 for (auto it : input.hits)
149 hits.push_back(it);
150
151 input.hits.clear();
152 input.usedStats.clear();
153
154 if (input.eContainers)
155 input.eContainers = nullptr;
156
157 return *this;
158 }
159
160 // Detector specified, hit arrays and stats used ...
161 TString det;
162 vector <BmnHit*> hits;
163 vector <Bool_t> usedStats;
164
165 // Indices and track params ....
166 pair <Int_t, Int_t> sfIndices;
167 pair <FairTrackParam, FairTrackParam> flParams;
168
169 TClonesArray* eContainers;
170
171 // Y-ranges ...
172 map <Int_t, vector <pair <Double_t, Double_t>>> gPairMap; // stat --> corresponding set of Y-pairs
173 map <Int_t, vector <pair <Double_t, Double_t>>> sPairMap;
174
175 // hit cuts ...
176 Int_t nGemCut;
177 Int_t nSilCut;
178};
179
180class InnerTrackerParams : public TObject {
181public:
182
184
185 InnerTrackerParams(Int_t stat, Double_t xMin, Double_t xMax, Double_t yMin, Double_t yMax) :
186 fStation(stat), fModule(-1),
187 fXMin(xMin), fXMax(xMax),
188 fYMin(yMin), fYMax(yMax) {
189
190 }
191
192 InnerTrackerParams(Int_t stat, Int_t mod, Double_t xMin, Double_t xMax, Double_t yMin, Double_t yMax) :
193 fStation(stat), fModule(mod),
194 fXMin(xMin), fXMax(xMax),
195 fYMin(yMin), fYMax(yMax) {
196
197 }
198
199 InnerTrackerParams(Int_t stat, Int_t mod, Double_t x, Double_t y, Double_t z) :
200 fStation(stat), fModule(mod) {
201 hitX = x;
202 hitY = y;
203 hitZ = z;
204 }
205
207 ;
208 }
209
210 Int_t station() {
211 return fStation;
212 }
213
214 Int_t module() {
215 return fModule;
216 }
217
218 pair <Double_t, Double_t> x() {
219 return make_pair(fXMin, fXMax);
220 }
221
222 pair <Double_t, Double_t> y() {
223 return make_pair(fYMin, fYMax);
224 }
225
226 void SetZ(Double_t z) {
227 fZ = z;
228 }
229
230 Double_t z() {
231 return fZ;
232 }
233
234 TVector3 xyz() {
235 return TVector3(hitX, hitY, hitZ);
236 }
237
238protected:
239 Int_t fStation;
240 Int_t fModule;
241
242 Double_t fXMin;
243 Double_t fXMax;
244
245 Double_t fYMin;
246 Double_t fYMax;
247
248 Double_t fZ; // position of station (at given module if defined) ...
249
250 //
251 Double_t hitX;
252 Double_t hitY;
253 Double_t hitZ;
254
255 ClassDef(InnerTrackerParams, 1)
256};
257
258class EffStore2D : public EffStore {
259public:
260
262 ;
263 }
264
265 EffStore2D(TString det, Int_t stat,
266 map <Int_t, vector <pair <Double_t, Double_t>>> pairs) :
267 EffStore(det, stat),
268 hEffGem(nullptr), hEffGem1d(nullptr), hEffSil(nullptr), hEffSil1d(nullptr) {
269
270 const Int_t nQp = 2; // positive and negative ...
271
272 enum QpValue {
273 pos, neg
274 };
275
276 hEffGem = new TEfficiency*[nQp];
277 hEffSil = new TEfficiency*[nQp];
278 hEffSilXP = new TEfficiency*[nQp];
279
280 if (det.Contains("GEM")) {
281 Int_t nBinsX = 160.; // 80.; // 160;
282 Int_t nBinsY = 45;
283
284 pair <Double_t, Double_t> y = make_pair(0., 45.);
285
286 Double_t xLow = -80.;
287 Double_t xUp = +80.;
288
289 for (Int_t iQp = 0; iQp < nQp; iQp++) {
290 TString Qp = (iQp == QpValue::pos) ? "Q_{p} > 0" : "Q_{p} < 0";
291
292 hEffGem[iQp] = new TEfficiency(Form("Detector# %s, Station# %d, %s", det.Data(), stat, Qp.Data()),
293 Form("Stat %d, %s; X [cm]; Y [cm]", stat, Qp.Data()), nBinsX, xLow, xUp, nBinsY, y.first, y.second);
294 }
295
296 // Preparing 1D-efficiencies (x for different y-ranges) ...
297 if (pairs.size()) {
298 nBinsX = 20.; // 80.; // 160;
299
300 hEffGem1d = new TEfficiency**[nQp];
301
302 const Int_t nYRanges = pairs.find(stat)->second.size();
303
304 for (Int_t iQp = 0; iQp < nQp; iQp++) {
305 hEffGem1d[iQp] = new TEfficiency*[nYRanges];
306
307 TString Qp = (iQp == QpValue::pos) ? "Q_{p} > 0" : "Q_{p} < 0";
308
309 for (Int_t iRange = 0; iRange < nYRanges; iRange++) {
310 Double_t y0 = pairs.find(stat)->second.at(iRange).first;
311 Double_t y1 = pairs.find(stat)->second.at(iRange).second;
312
313 hEffGem1d[iQp][iRange] = new TEfficiency(Form("Detector# %s, Station# %d, (%G < y < %G [cm]), %s", det.Data(), stat, y0, y1, Qp.Data()),
314 Form("Stat %d, (%G < y < %G [cm]), %s; X [cm]; #varepsilon", stat, y0, y1, Qp.Data()), nBinsX, xLow, xUp);
315 }
316 }
317 }
318 } else {
319 Int_t nBinsX = 80;
320 Int_t nBinsY = 45;
321
322 TClonesArray* sil = new TClonesArray("InnerTrackerParams");
323
324 // Adding necessary information ...
325 // stat 0
326 new ((*sil) [sil->GetEntriesFast()]) InnerTrackerParams(0, -6., +6., -5., +8.);
327
328 // stat 1
329 new ((*sil) [sil->GetEntriesFast()]) InnerTrackerParams(1, -6., +6., -5., +8.);
330
331 // stat 2
332 new ((*sil) [sil->GetEntriesFast()]) InnerTrackerParams(2, -12., +12., -11., +14.);
333
334 for (Int_t iQp = 0; iQp < nQp; iQp++) {
335 TString Qp = (iQp == QpValue::pos) ? "Q_{p} > 0" : "Q_{p} < 0";
336 hEffSil[iQp] = new TEfficiency(Form("Detector# %s, Station# %d, %s", det.Data(), stat, Qp.Data()),
337 Form("Stat %d, %s; X [cm]; Y [cm]", stat, Qp.Data()),
338 nBinsX, getRanges(sil, stat)[0], getRanges(sil, stat)[1], nBinsY, getRanges(sil, stat)[2], getRanges(sil, stat)[3]);
339
340 nBinsY = 55;
341
342 hEffSilXP[iQp] = new TEfficiency(Form("Detector# %s, Station# %d (xP), %s", det.Data(), stat, Qp.Data()),
343 Form("Stat %d, %s; X [cm]; P [GeV/c]", stat, Qp.Data()),
344 nBinsX, getRanges(sil, stat)[0], getRanges(sil, stat)[1], nBinsY, 0., 5.5);
345 }
346
347 // Preparing 1D-efficiencies (x for different y-ranges) ...
348 if (pairs.size()) {
349 nBinsX = 20.; // 80.; // 160;
350
351 hEffSil1d = new TEfficiency**[nQp];
352
353 const Int_t nYRanges = pairs.find(stat)->second.size();
354
355 for (Int_t iQp = 0; iQp < nQp; iQp++) {
356 hEffSil1d[iQp] = new TEfficiency*[nYRanges];
357
358 TString Qp = (iQp == QpValue::pos) ? "Q_{p} > 0" : "Q_{p} < 0";
359
360 for (Int_t iRange = 0; iRange < nYRanges; iRange++) {
361 Double_t y0 = pairs.find(stat)->second.at(iRange).first;
362 Double_t y1 = pairs.find(stat)->second.at(iRange).second;
363
364 hEffSil1d[iQp][iRange] = new TEfficiency(Form("Detector# %s, Station# %d, (%G < y < %G [cm]), %s", det.Data(), stat, y0, y1, Qp.Data()),
365 Form("Stat %d, (%G < y < %G [cm]), %s; X [cm]; #varepsilon", stat, y0, y1, Qp.Data()),
366 nBinsX, getRanges(sil, stat)[0], getRanges(sil, stat)[1]);
367 }
368 }
369 }
370
371 delete sil;
372 }
373 }
374
375 TEfficiency* efficiency(Int_t qpBin = 0, TString hType = "", TString det = "GEM") {
376 // qpBin = 0 (positive), 1 (negative)
377 if (hType.IsNull())
378 return det.Contains("GEM") ? hEffGem[qpBin] : hEffSil[qpBin];
379 else if (det.Contains("SILICON") && !hType.IsNull())
380 return hEffSilXP[qpBin];
381 else
382 return nullptr;
383 }
384
385 TEfficiency* efficiency4range(Int_t range, Int_t qpBin = 0, TString det = "GEM") {
386 // qpBin = 0 (positive), 1 (negative)
387
388 if (det.Contains("GEM") && hEffGem1d[qpBin][range])
389 return hEffGem1d[qpBin][range];
390 else if (det.Contains("SIL") && hEffSil1d[qpBin][range])
391 return hEffSil1d[qpBin][range];
392
393 else
394 return nullptr;
395 }
396
397 virtual ~EffStore2D() {
398 // Should be implemented further ...
399 }
400
401private:
402 TEfficiency** hEffGem;
403 TEfficiency*** hEffGem1d;
404
405 TEfficiency** hEffSil; // epslion(x, y)
406 TEfficiency** hEffSilXP; // epsilon(x, P)
407 TEfficiency*** hEffSil1d; // epsilon(x) at different y-slices
408
409private:
410
411 vector <Double_t> getRanges(TClonesArray* sil, Int_t stat) {
412
413 vector <Double_t> tmp;
414
415 for (Int_t iEntry = 0; iEntry < sil->GetEntriesFast(); iEntry++) {
416 InnerTrackerParams* silEle = (InnerTrackerParams*) sil->UncheckedAt(iEntry);
417
418 if (silEle->station() == stat) {
419 tmp.push_back(silEle->x().first);
420 tmp.push_back(silEle->x().second);
421 tmp.push_back(silEle->y().first);
422 tmp.push_back(silEle->y().second);
423
424 break;
425 }
426 }
427
428 return tmp;
429 }
430
431 ClassDef(EffStore2D, 1)
432};
433
434// A class to be used as a store for calculated residuals ...
435
436class Residuals : public EffStore {
437public:
438
440 station(-1), module(-1) {
441 ;
442 }
443
444 Residuals(TString det, Int_t stat, Int_t mod) : EffStore(det, stat, mod),
445 detector(det), station(stat), module(mod) {
446 ;
447 }
448
449 virtual ~Residuals() {
450 ;
451 }
452
453 void SetXY(Double_t xR, Double_t yR) {
454 x.push_back(xR);
455 y.push_back(yR);
456 }
457
458 vector <Double_t> GetX() {
459 return x;
460 }
461
462 vector <Double_t> GetY() {
463 return y;
464 }
465
466private:
467 TString detector; // GEM or SILICON
468 Int_t station;
469 Int_t module;
470
471 vector <Double_t> x;
472 vector <Double_t> y;
473
474 ClassDef(Residuals, 1)
475};
476
477class BmnEfficiency : public TNamed
478{
479 public:
481 BmnEfficiency(FairRunAna*, BmnInnerTrackerGeometryDraw*, TString, Int_t nEvents = 0);
482 BmnEfficiency(FairRunAna*, TString, Int_t nEvents = 0);
483
484 void SetMinNHitsPerGlobTrack(Int_t nHits) {
485 fNHits = nHits;
486 }
487
488 void SetMinNHitsPerSiliconTrack(Int_t nHits) {
489 fNHitsSilicon = nHits;
490 }
491
492 void SetMinNHitsPerGemTrack(Int_t nHits) {
493 fNHitsGem = nHits;
494 }
495
496 void Efficiency(TClonesArray*, TClonesArray* effSilicon,
497 map <Int_t, vector <pair <Double_t, Double_t>>>, map <Int_t, vector <pair <Double_t, Double_t>>>);
498
499 virtual ~BmnEfficiency() {
500 if (fMagField)
501 delete fMagField;
502 if (dstChain)
503 delete dstChain;
504 if (fKalman)
505 delete fKalman;
506 }
507
508 TString GetGemZone(BmnHit*);
509
510 // Overloading = ...
511
513 // Check assignement to itself
514 if (this == &eff)
515 return *this;
516
517 dstChain = eff.dstChain;
518 fVertices = eff.fVertices;
520
523
525 fGemHits = eff.fGemHits;
526
527 fMagField = eff.fMagField;
528 fField = eff.fField;
529 fKalman = eff.fKalman;
530
531 return *this;
532 }
533
534 private:
535 Bool_t isGoodDst;
536 // Acceptance maps to be used ...
537 map <pair <Int_t, Int_t>, Double_t> fStatZ; // (stat, mod) --> Z
538 map <pair <Int_t, Int_t>, vector <Double_t>> fStatAcceptance; // (stat, mod) --> vector of boarders ...
539 Int_t fNHitsSilicon;
540 Int_t fNHitsGem;
541
542 void fillEfficiency(inputForEfficiency&& in);
543 void FillAcceptanceMaps(TClonesArray*, TClonesArray* SILs = nullptr);
544
545 inline TString GetDetector(BmnHit* hit) {
546 Double_t z = hit->GetZ();
547
548 TString det = "";
549 if (z > gem->GetStation(0)->GetZPosition() - 5.)
550 det = "GEM";
551 else
552 det = "SILICON";
553
554 return det;
555 }
556
557 inline Double_t FindZ(Int_t stat) {
558 return fStatZ.find(make_pair(stat, 0))->second;
559 }
560
561 Bool_t isVirtualHitInAcceptance(Int_t, vector <BmnHit*>, pair <FairTrackParam, FairTrackParam>, pair <Double_t, Double_t>&);
562
563 Int_t FindBin(Double_t y, Int_t stat, map <Int_t, vector <pair <Double_t, Double_t>>> pairMap) {
564 Int_t bin = -1;
565
566 for (size_t iRange = 0; iRange < pairMap.find(stat)->second.size(); iRange++) {
567 Double_t min = pairMap.find(stat)->second.at(iRange).first;
568 Double_t max = pairMap.find(stat)->second.at(iRange).second;
569
570 if (y > min && y < max) {
571 bin = iRange;
572 break;
573 }
574 }
575
576 return bin;
577 }
578
579 protected:
580 // Geometries
583
585
586 TClonesArray* fInnerHits;
587 TClonesArray* fGemHits;
588 TClonesArray* fSiliconHits;
589 TClonesArray* fGlobTracks;
590 TClonesArray* fGemTracks;
591 TClonesArray* fSiliconTracks;
592 TClonesArray* fVertices;
593
594 TChain* dstChain;
595 Int_t fNEvents;
596
597 FairField* fField;
600
601 Int_t fNHits;
602
603 ClassDef(BmnEfficiency, 1)
604};
605
606#endif
friend F32vec4 min(const F32vec4 &a, const F32vec4 &b)
Definition P4_F32vec4.h:30
friend F32vec4 max(const F32vec4 &a, const F32vec4 &b)
Definition P4_F32vec4.h:31
void SetMinNHitsPerGlobTrack(Int_t nHits)
BmnKalmanFilter * fKalman
BmnNewFieldMap * fMagField
TClonesArray * fInnerHits
void Efficiency(TClonesArray *, TClonesArray *effSilicon, map< Int_t, vector< pair< Double_t, Double_t > > >, map< Int_t, vector< pair< Double_t, Double_t > > >)
BmnGemStripStationSet * gem
TClonesArray * fSiliconTracks
BmnEfficiency & operator=(const BmnEfficiency &eff)
BmnSiliconStationSet * silicon
TClonesArray * fGemTracks
TClonesArray * fVertices
DstEventHeader * fHeader
FairField * fField
TClonesArray * fGemHits
virtual ~BmnEfficiency()
TClonesArray * fSiliconHits
void SetMinNHitsPerGemTrack(Int_t nHits)
TChain * dstChain
TString GetGemZone(BmnHit *)
void SetMinNHitsPerSiliconTrack(Int_t nHits)
TClonesArray * fGlobTracks
BmnGemStripStation * GetStation(Int_t station_num)
EffStore2D(TString det, Int_t stat, map< Int_t, vector< pair< Double_t, Double_t > > > pairs)
TEfficiency * efficiency(Int_t qpBin=0, TString hType="", TString det="GEM")
virtual ~EffStore2D()
TEfficiency * efficiency4range(Int_t range, Int_t qpBin=0, TString det="GEM")
Int_t Station()
vector< TLorentzVector > CoordinatesAndEffs()
virtual ~EffStore()
void IncreaseDenominatorByUnity()
EffStore(TString det, Int_t stat, TString z="")
Int_t Module()
Double_t Efficiency()
void AddHitCoordinates(BmnHit *hit, Double_t eff=1.)
TString Detector()
TString Zone()
void IncreaseNominatorByUnity()
EffStore(TString det, Int_t stat, Int_t mod, TString z="")
InnerTrackerParams(Int_t stat, Double_t xMin, Double_t xMax, Double_t yMin, Double_t yMax)
void SetZ(Double_t z)
pair< Double_t, Double_t > y()
pair< Double_t, Double_t > x()
InnerTrackerParams(Int_t stat, Int_t mod, Double_t x, Double_t y, Double_t z)
virtual ~InnerTrackerParams()
InnerTrackerParams(Int_t stat, Int_t mod, Double_t xMin, Double_t xMax, Double_t yMin, Double_t yMax)
vector< Double_t > GetY()
void SetXY(Double_t xR, Double_t yR)
virtual ~Residuals()
vector< Double_t > GetX()
Residuals(TString det, Int_t stat, Int_t mod)
virtual ~inputForEfficiency()
pair< Int_t, Int_t > sfIndices
inputForEfficiency & operator=(inputForEfficiency &&input)
vector< Bool_t > usedStats
pair< FairTrackParam, FairTrackParam > flParams
map< Int_t, vector< pair< Double_t, Double_t > > > gPairMap
vector< BmnHit * > hits
map< Int_t, vector< pair< Double_t, Double_t > > > sPairMap
TClonesArray * eContainers
STL namespace.