BmnRoot
Loading...
Searching...
No Matches
BmnDataAnalRun7.cxx
Go to the documentation of this file.
1#include "BmnDataAnalRun7.h"
2
4mAnal(nullptr), fAna(nullptr), fGeomFile(""), fNFiles(0) {
5
6 mAnal = new BmnMassSpectrumAnal(dir);
7 fAna = new FairRunAna();
8}
9
10void BmnDataAnalRun7::resetHistos() {
11 const Int_t nRes = 2;
12
13 for (Int_t iRes = 0; iRes < nRes; iRes++) {
14 for (Int_t iStat = 0; iStat < silicon->GetNStations(); iStat++)
15 for (Int_t iMod = 0; iMod < silicon->GetStation(iStat)->GetNModules(); iMod++)
16 hResSil[iRes][iStat][iMod]->Reset();
17
18 for (Int_t iStat = 0; iStat < gem->GetNStations(); iStat++)
19 for (Int_t iMod = 0; iMod < gem->GetStation(iStat)->GetNModules(); iMod++)
20 hResGem[iRes][iStat][iMod]->Reset();
21 }
22}
23
24void BmnDataAnalRun7::writeHistos(TString out) {
25 const Int_t nRes = 2;
26
27 TFile* f = new TFile(out.Data(), "recreate");
28 for (Int_t iRes = 0; iRes < nRes; iRes++) {
29 for (Int_t iStat = 0; iStat < silicon->GetNStations(); iStat++)
30 for (Int_t iMod = 0; iMod < silicon->GetStation(iStat)->GetNModules(); iMod++) {
31 DoNormalization(hResSil[iRes][iStat][iMod]);
32 hResSil[iRes][iStat][iMod]->Write();
33 }
34
35 for (Int_t iStat = 0; iStat < gem->GetNStations(); iStat++)
36 for (Int_t iMod = 0; iMod < gem->GetStation(iStat)->GetNModules(); iMod++) {
37 DoNormalization(hResGem[iRes][iStat][iMod]);
38 hResGem[iRes][iStat][iMod]->Write();
39 }
40 }
41
42 delete f;
43}
44
45void BmnDataAnalRun7::calcResiduals(TString dst) {
46 BmnEfficiency* eff = new BmnEfficiency(fAna, dst);
47
48 // Doing assignment ...
49 *(BmnEfficiency*)this = *eff;
50
51 cout << "Processing file# " << dst << endl;
52
53 for (Int_t iEvent = 0; iEvent < ((fNEvents == 0) ? dstChain->GetEntries() : fNEvents); iEvent++) {
54 dstChain->GetEntry(iEvent);
55
56 if (iEvent % 1000 == 0)
57 cout << "Event# " << iEvent << endl;
58
59 BmnVertex* Vp = (BmnVertex*) fVertices->UncheckedAt(0);
60
61 Double_t zVp = Vp->GetZ();
62 Int_t nTracks = Vp->GetNTracks();
63
64 if (TMath::Abs(zVp) > 6. || nTracks < 2)
65 continue;
66
67 // Loop over glob. tracks ...
68 for (Int_t iTrack = 0; iTrack < fGlobTracks->GetEntriesFast(); iTrack++) {
69 BmnGlobalTrack* track = (BmnGlobalTrack*) fGlobTracks->UncheckedAt(iTrack);
70
71 if (track->GetNHits() < fNHits)
72 continue;
73
74 // cout << "Track#" << endl;
75
76 vector <BmnHit> hits;
77
78 // Loop over silicon hits ...
79 if (track->GetSilTrackIndex() != -1) {
80 BmnTrack* silTrack = (BmnTrack*) fSiliconTracks->UncheckedAt(track->GetSilTrackIndex());
81
82 for (Int_t iHit = 0; iHit < silTrack->GetNHits(); iHit++) {
83 BmnHit* hit = (BmnHit*) fSiliconHits->UncheckedAt(silTrack->GetHitIndex(iHit));
84 hits.push_back(*hit);
85 }
86 }
87
88 // Loop over gem hits ...
89 if (track->GetGemTrackIndex() != -1) {
90 BmnTrack* gemTrack = (BmnTrack*) fGemTracks->UncheckedAt(track->GetGemTrackIndex());
91
92 for (Int_t iHit = 0; iHit < gemTrack->GetNHits(); iHit++) {
93 BmnHit* hit = (BmnHit*) fGemHits->UncheckedAt(gemTrack->GetHitIndex(iHit));
94 hits.push_back(*hit);
95 }
96 }
97
98 // Loop over collected track hits ...
99 for (auto it = hits.begin(); it != hits.end(); it++) {
100 BmnHit hit = *it;
101
102 Int_t stat = hit.GetStation();
103 Int_t mod = hit.GetModule();
104
105 Double_t Z = hit.GetZ();
106 TString det = (Z > 30.) ? "GEM" : "SILICON";
107
108 Double_t xOrig, yOrig = 0.;
109 doKalman(track, Z, xOrig, yOrig);
110
111 // Excluding current hit from the track connected hits ...
112 vector <BmnHit> hits0;
113
114 for (auto it1 = hits.begin(); it1 != hits.end(); it1++) {
115 if (it == it1)
116 continue;
117
118 hits0.push_back(*it1);
119 }
120
121 // Trying to update track. params and get resid. with the hit excluded at Z position of the hit excluded ...
122 Double_t xUpdated, yUpdated = 0.;
123 doKalman(track, hits0, Z, xUpdated, yUpdated);
124
125 // Filling histos ...
126 TH1F**** h = det.Contains("GEM") ? hResGem : hResSil;
127
128 h[0][stat][mod]->Fill(xOrig - xUpdated); // tr - fit
129 h[1][stat][mod]->Fill(yOrig - yUpdated);
130 }
131 }
132 }
133
134 delete eff;
135}
136
138 const Int_t nRes = 2;
139
140 hResGem = new TH1F***[nRes];
141 hResSil = new TH1F***[nRes];
142
143 for (Int_t iRes = 0; iRes < nRes; iRes++) {
144 TString res = (iRes == 0) ? TString::Format("X").Data() : TString::Format("Y").Data();
145
146 // SILICON
147 hResSil[iRes] = new TH1F**[silicon->GetNStations()];
148 for (Int_t iStat = 0; iStat < silicon->GetNStations(); iStat++) {
149 hResSil[iRes][iStat] = new TH1F*[silicon->GetStation(iStat)->GetNModules()];
150
151 for (Int_t iMod = 0; iMod < silicon->GetStation(iStat)->GetNModules(); iMod++)
152 hResSil[iRes][iStat][iMod] = new TH1F(Form("SILICON, Res %s, Stat %d, Mod %d", res.Data(), iStat, iMod),
153 Form("SILICON, Res %s, Stat %d, Mod %d", res.Data(), iStat, iMod), 200, -1., +1.);
154 }
155
156 // GEM
157 hResGem[iRes] = new TH1F**[gem->GetNStations()];
158 for (Int_t iStat = 0; iStat < gem->GetNStations(); iStat++) {
159 hResGem[iRes][iStat] = new TH1F*[gem->GetStation(iStat)->GetNModules()];
160
161 for (Int_t iMod = 0; iMod < gem->GetStation(iStat)->GetNModules(); iMod++)
162 hResGem[iRes][iStat][iMod] = new TH1F(Form("GEM, Res %s, Stat %d, Mod %d", res.Data(), iStat, iMod),
163 Form("GEM, Res %s, Stat %d, Mod %d", res.Data(), iStat, iMod), 200, -1., +1.);
164 }
165 }
166
167 // Setting inn. tracker geometry ...
168 if (fGeomFile.IsNull())
169 Fatal("BmnDataAnalRun7::doResidAnal()", "No geometry file passed!!!");
170 else
171 TGeoManager::Import(fGeomFile.Data());
172
173 vector <TString> fList;
174
175 // Processing monte Carlo if needed and passed ...
176 if (!fMcDataPath.IsNull()) {
177 resetHistos(); // Not needed but for sure since it is fast:)
178 BmnMassSpectrumAnal* mcAnal = new BmnMassSpectrumAnal(fMcDataPath);
179
180 fList = mcAnal->GetFileList();
181
182 for (auto itFile = fList.begin(); itFile != fList.end(); itFile++) {
183 if (fNFiles && distance(fList.begin(), itFile) == fNFiles)
184 break;
185
186 calcResiduals(*itFile);
187 }
188
189 writeHistos("residMc.root");
190
191 delete mcAnal;
192 }
193
194 // Setting necessary target / targets ...
195 mAnal->SetTarget(fTarget);
196
197 fList = mAnal->createFilelist();
198 if (!fNFiles)
199 fNFiles = fList.size();
200
201 // Processing data ...
202 resetHistos();
203 for (auto itFile = fList.begin(); itFile != fList.end(); itFile++) {
204 if (fNFiles && distance(fList.begin(), itFile) == fNFiles)
205 break;
206
207 calcResiduals(*itFile);
208 }
209
210 // Writing histos ...
211 writeHistos(TString::Format("residData_%s.root", fTarget.Data()));
212}
213
214void BmnDataAnalRun7::doKalman(BmnGlobalTrack* track, Double_t Z, Double_t& xOrig, Double_t& yOrig) {
215 FairTrackParam* first = track->GetParamFirst();
216 FairTrackParam* last = track->GetParamLast();
217
218 FairTrackParam par = *first;
219 BmnStatus status = fKalman->TGeoTrackPropagate(&par, Z, last->GetQp() > 0. ? 2212 : -211, nullptr, nullptr, kTRUE);
220 if (status == kBMNSUCCESS) {
221 xOrig = par.GetX();
222 yOrig = par.GetY();
223 }
224}
225
226void BmnDataAnalRun7::doKalman(BmnGlobalTrack* track, vector <BmnHit> hits, Double_t Z, Double_t& xUpdated, Double_t& yUpdated) {
227
228 FairTrackParam* first = track->GetParamFirst();
229 FairTrackParam* last = track->GetParamLast();
230
231 FairTrackParam par = *first;
232
233 // Updating track params ...
234 for (BmnHit hit : hits) {
235 BmnStatus status = fKalman->TGeoTrackPropagate(&par, hit.GetZ(), last->GetQp() > 0. ? 2212 : -211, nullptr, nullptr, kTRUE);
236 if (status == kBMNERROR)
237 continue;
238
239 Double_t chi2 = 0.;
240 fKalman->Update(&par, &hit, chi2);
241 }
242
243 // Prediction at Z of the excluded hit ...
244 if (fKalman->TGeoTrackPropagate(&par, Z, last->GetQp() > 0. ? 2212 : -211, nullptr, nullptr, kTRUE) == kBMNSUCCESS) {
245 xUpdated = par.GetX();
246 yUpdated = par.GetY();
247 }
248}
249
250void BmnDataAnalRun7::DoNormalization(TH1F* h) {
251 if (h->GetEntries() == 0)
252 return;
253
254 // Collecting all bin contents ...
255 Double_t contentAll = 0.;
256
257 for (Int_t iBin = 1; iBin < h->GetNbinsX() + 1; iBin++)
258 contentAll += h->GetBinContent(iBin);
259
260 // Normalizing histo ...
261 for (Int_t iBin = 1; iBin < h->GetNbinsX() + 1; iBin++) {
262 h->SetBinContent(iBin, h->GetBinContent(iBin) / contentAll);
263 h->SetBinError(iBin, 0.);
264 }
265
266 h->GetYaxis()->SetRangeUser(0., 1.1 * h->GetMaximum());
267}
268
float f
Definition P4_F32vec4.h:21
BmnStatus
Definition BmnEnums.h:24
@ kBMNERROR
Definition BmnEnums.h:26
@ kBMNSUCCESS
Definition BmnEnums.h:25
BmnKalmanFilter * fKalman
BmnGemStripStationSet * gem
TClonesArray * fSiliconTracks
BmnSiliconStationSet * silicon
TClonesArray * fGemTracks
TClonesArray * fVertices
TClonesArray * fGemHits
TClonesArray * fSiliconHits
TChain * dstChain
TClonesArray * fGlobTracks
BmnGemStripStation * GetStation(Int_t station_num)
Int_t GetGemTrackIndex() const
Int_t GetSilTrackIndex() const
Int_t GetModule()
Definition BmnHit.h:77
Short_t GetStation() const
Definition BmnHit.h:45
BmnStatus TGeoTrackPropagate(FairTrackParam *par, Double_t zOut, Int_t pdg, vector< Double_t > *F, Double_t *length, Bool_t isField)
BmnStatus Update(FairTrackParam *par, const BmnHit *hit, Double_t &chiSq)
vector< TString > createFilelist()
void SetTarget(TString t)
vector< TString > GetFileList()
BmnSiliconStation * GetStation(Int_t station_num)
FairTrackParam * GetParamFirst()
Definition BmnTrack.h:72
Int_t GetNHits() const
Definition BmnTrack.h:44
Int_t GetHitIndex(Int_t iHit) const
Definition BmnTrack.h:48
FairTrackParam * GetParamLast()
Definition BmnTrack.h:76
Int_t GetNTracks() const
Definition BmnVertex.h:54
Double_t GetZ() const
Definition BmnVertex.h:51