BmnRoot
Loading...
Searching...
No Matches
BmnRealisticMc.cxx
Go to the documentation of this file.
1#include "BmnRealisticMc.h"
2
4 : fSilHitsArray(nullptr)
5 , fGemHitsArray(nullptr)
6 , fGemHitsArrayFiltered(nullptr)
7 , fSilHitsArrayFiltered(nullptr)
8 , fEff(nullptr)
9{
10 fEff = new BmnEfficiency(); // test writing. Speed obtained looks suitable for working:)
11}
12
14{
15
16 if (fVerbose > 1)
17 cout << "======================== RealisticMc init started ====================" << endl;
18
19 // Get ROOT Manager
20 FairRootManager* ioman = FairRootManager::Instance();
21 if (!ioman)
22 Fatal("Init", "FairRootManager is not instantiated");
23
24 fGemHitsArray = (TClonesArray*)ioman->GetObject("BmnGemStripHit"); // in
25 fSilHitsArray = (TClonesArray*)ioman->GetObject("BmnSiliconHit"); // in
26
27 fGemHitsArrayFiltered = new TClonesArray("BmnGemStripHit");
28 ioman->Register("BmnGemStripHitFiltered", "BmnGemStripHitFiltered_", fGemHitsArrayFiltered, kFALSE);
29
30 fSilHitsArrayFiltered = new TClonesArray("BmnSiliconHit");
31 ioman->Register("BmnSiliconHitFiltered", "BmnSiliconHitFiltered_", fSilHitsArrayFiltered, kFALSE);
32
33 return kSUCCESS;
34}
35
36void BmnRealisticMc::Exec(Option_t* option)
37{
38 fGemHitsArrayFiltered->Delete();
39 fSilHitsArrayFiltered->Delete();
40
41 doHitSelection(fGemHitsArray, fGemHitsArrayFiltered);
42 doHitSelection(fSilHitsArray, fSilHitsArrayFiltered);
43}
44
46
47void BmnRealisticMc::doHitSelection(TClonesArray* hitsArray, TClonesArray* hitsArrayFiltered)
48{
49 // Define detector we are processing (GEM or SILICON) ...
50 Bool_t isGem = kFALSE, isSilicon = kFALSE;
51
52 TString className = TString(hitsArray->GetClass()->GetName());
53 TString detector = (className.Contains("BmnGemStripHit")) ? "GEM"
54 : className.Contains("BmnSiliconHit") ? "SILICON"
55 : "";
56
57 if (detector.IsNull())
58 return;
59
60 if (detector.Contains("GEM"))
61 isGem = kTRUE;
62 else
63 isSilicon = kTRUE;
64
65 // Collecting unique X'-digit indices ...
66 set<Int_t> digiIndices;
67
68 for (Int_t iHit = 0; iHit < hitsArray->GetEntriesFast(); iHit++) {
69 BmnHit* hit = (BmnHit*)hitsArray->UncheckedAt(iHit);
70 Int_t idx =
71 hit->GetDigitNumberMatch().GetLink(0).GetIndex(); // Link to the corresponding index of X'-digit ...
72 digiIndices.insert(idx);
73 }
74
75 // Trying to sort hits according to the indices of X'-digits ...
76 map<Int_t, vector<BmnHit>> hitMap;
77
78 for (auto idx : digiIndices) {
79 vector<BmnHit> hitVector;
80 hitMap[idx] = hitVector;
81 }
82
83 // Loop over GEM hits once more ...
84 for (Int_t iHit = 0; iHit < hitsArray->GetEntriesFast(); iHit++) {
85 BmnHit* hit = (BmnHit*)hitsArray->UncheckedAt(iHit);
86
87 // Getting link to X'-digit of the hit ...
88 BmnMatch digiMatch = hit->GetDigitNumberMatch();
89 Int_t idx = digiMatch.GetLink(0).GetIndex(); // Link to the corresponding index of X'-digit ...
90
91 hitMap.find(idx)->second.push_back(*(BmnHit*)hit);
92 }
93
94 // Looking for hits with the known X'-digit index ...
95 for (auto it : hitMap) {
96
97 // Generating prob. value for the digit ...
98 Double_t probDigiValue = gRandom->Rndm();
99
100 TString zone = "";
101 BmnHit* hit = nullptr;
102
103 Int_t counter = 0;
104
105 Bool_t isSkipped = kFALSE;
106
107 if (isGem) {
108 do {
109 // Getting hit and GEM zone ...
110 Int_t hitIdx = it.second.at(Int_t(it.second.size() * gRandom->Rndm())).GetIndex();
111 hit = (BmnHit*)hitsArray->UncheckedAt(hitIdx);
112 zone = fEff->GetGemZone(hit);
113
114 counter++;
115
116 if (counter > 2. * it.second.size()) {
117 isSkipped = kTRUE;
118 break;
119 }
120 } while (zone == "");
121 } else if (isSilicon) {
122 Int_t hitIdx = it.second.at(Int_t(it.second.size() * gRandom->Rndm())).GetIndex();
123 hit = (BmnHit*)hitsArray->UncheckedAt(hitIdx);
124 }
125
126 if (isSkipped)
127 continue;
128
129 // Generating prob. value for the hit ...
131
132 probs->SetDetector(detector);
133 probs->SetStation(hit->GetStation());
134 probs->SetModule(hit->GetModule());
135
136 if (isGem)
137 probs->SetZone(zone);
138
139 Double_t probHitValue = probs->GetProbability();
140
141 delete probs;
142
143 Bool_t isExcluded = (probDigiValue > probHitValue) ? kTRUE : kFALSE;
144 // Mark hits to be excluded ...
145 if (isExcluded) {
146 for (BmnHit hit0 : it.second) {
147 BmnHit* hitWithSetType = (BmnHit*)hitsArray->UncheckedAt(hit0.GetIndex());
148 hitWithSetType->SetType(1000);
149 }
150 } // Write survived hits ...
151 else
152 {
153 for (BmnHit hit0 : it.second) {
154 if (isGem) {
155 BmnGemStripHit* hitWithSetType = (BmnGemStripHit*)hitsArray->UncheckedAt(hit0.GetIndex());
156 new ((*hitsArrayFiltered)[hitsArrayFiltered->GetEntriesFast()]) BmnGemStripHit(*hitWithSetType);
157 } else {
158 BmnSiliconHit* hitWithSetType = (BmnSiliconHit*)hitsArray->UncheckedAt(hit0.GetIndex());
159 new ((*hitsArrayFiltered)[hitsArrayFiltered->GetEntriesFast()]) BmnSiliconHit(*hitWithSetType);
160 }
161 }
162 }
163 }
164}
TString GetGemZone(BmnHit *)
Int_t GetIndex() const
Definition BmnHit.h:37
Int_t GetModule()
Definition BmnHit.h:77
void SetType(Int_t type)
Definition BmnHit.h:81
BmnMatch GetDigitNumberMatch()
Definition BmnHit.h:117
Short_t GetStation() const
Definition BmnHit.h:45
const BmnLink & GetLink(Int_t i) const
Definition BmnMatch.h:37
virtual void Finish()
virtual void Exec(Option_t *option)
virtual InitStatus Init()