BmnRoot 26.10.0-18-g4e3414f9
Software framework of the BM@N experiment
Loading...
Searching...
No Matches
CbmStsIdealMatchHits.cxx
Go to the documentation of this file.
1//* $Id: */
2
3// -------------------------------------------------------------------------
4// ----- CbmStsIdealMatchHits source file -----
5// ----- Created 27/11/06 by V. Friese -----
6// -------------------------------------------------------------------------
7#include <iomanip>
8#include <iostream>
9
10// --- Includes from ROOT
11#include "TClonesArray.h"
12
13// --- Includes from base
14#include "FairRootManager.h"
15#include "FairRunAna.h"
16#include "FairRuntimeDb.h"
17
18// --- Includes from STS
19#include "CbmGeoStsPar.h"
20#include "CbmStsDigiMatch.h"
21#include "CbmStsDigiPar.h"
22#include "CbmStsDigiScheme.h"
23#include "CbmStsHit.h"
25#include "CbmStsPoint.h"
26#include "CbmStsSector.h"
27#include "CbmStsStation.h"
28#include "TMath.h"
29
30using std::cout;
31using std::endl;
32using std::fixed;
33using std::left;
34using std::right;
35using std::setprecision;
36using std::setw;
37
38// ----- Default constructor -------------------------------------------
40 : FairTask("STSMatchHits", 1)
41 , fGeoPar(NULL)
42 , fDigiPar(NULL)
43 , fPoints(NULL)
44 , fDigis(NULL)
45 , fDigiMatches(NULL)
46 , fHits(NULL)
47 , fDigiScheme(NULL)
48 , fTimer()
49 , fNEvents(0)
51 , fTime(0.)
52 , fNHits(0.)
53 , fNMatched(0.)
54 , fNDistant(0.)
55 , fNBackgrd(0.)
56 , fCandMap()
57 , fIter()
58{
60}
61// -------------------------------------------------------------------------
62
63// ----- Standard constructor ------------------------------------------
65 : FairTask("STSMatchHits", iVerbose)
66 , fGeoPar(NULL)
67 , fDigiPar(NULL)
68 , fPoints(NULL)
69 , fDigis(NULL)
70 , fDigiMatches(NULL)
71 , fHits(NULL)
72 , fDigiScheme(NULL)
73 , fTimer()
74 , fNEvents(0)
76 , fTime(0.)
77 , fNHits(0.)
78 , fNMatched(0.)
79 , fNDistant(0.)
80 , fNBackgrd(0.)
81 , fCandMap()
82 , fIter()
83{
85}
86// -------------------------------------------------------------------------
87
88// ----- Constructor with name -----------------------------------------
90 : FairTask(name, iVerbose)
91 , fGeoPar(NULL)
92 , fDigiPar(NULL)
93 , fPoints(NULL)
94 , fDigis(NULL)
95 , fDigiMatches(NULL)
96 , fHits(NULL)
97 , fDigiScheme(NULL)
98 , fTimer()
99 , fNEvents(0)
100 , fNEventsFailed(0)
101 , fTime(0.)
102 , fNHits(0.)
103 , fNMatched(0.)
104 , fNDistant(0.)
105 , fNBackgrd(0.)
106 , fCandMap()
107 , fIter()
108{
110}
111// -------------------------------------------------------------------------
112
113// ----- Destructor ----------------------------------------------------
115{
116 if (fGeoPar)
117 delete fGeoPar;
118 if (fDigiPar)
119 delete fDigiPar;
120 if (fDigiScheme)
121 delete fDigiScheme;
122}
123// -------------------------------------------------------------------------
124
125// ----- Public method Exec --------------------------------------------
127{
128
129 // Timer
130 fTimer.Start();
131 Bool_t warn = kFALSE;
132
133 // Counters
134 Int_t nHits = fHits->GetEntriesFast();
135 Int_t nNoDigi = 0;
136 Int_t nBackgrd = 0;
137 Int_t nDistant = 0;
138 Int_t nMatched = 0;
139
140 // Loop over all StsHits
141 for (Int_t iHit = 0; iHit < nHits; iHit++) {
142 CbmStsHit* hit = (CbmStsHit*)fHits->At(iHit);
143 if (!hit) {
144 cout << "-W- " << GetName() << "::Exec: Empty hit at index " << iHit << endl;
145 warn = kTRUE;
146 continue;
147 }
148
149 // Determine sector type and channel numbers
150 Int_t iStation = hit->GetStationNr();
151 Int_t iSector = hit->GetSectorNr();
152 CbmStsStation* station = fDigiScheme->GetStationByNr(iStation);
153 CbmStsSector* sector = fDigiScheme->GetSector(iStation, iSector);
154 Int_t iType = sector->GetType();
155 CbmStsDigiMatch* dMatchF = NULL;
156 CbmStsDigiMatch* dMatchB = NULL;
157
158 // Hit coordinates and errors
159 Double_t xH = hit->GetX();
160 Double_t yH = hit->GetY();
161 Double_t dX = hit->GetDx();
162 Double_t dY = hit->GetDy();
163
164 // Get front side DigiMatch corresponding to hit
165 Int_t iMatchF = hit->GetDigi(0);
166 if (iMatchF >= 0)
167 dMatchF = (CbmStsDigiMatch*)fDigiMatches->At(iMatchF);
168 if (!dMatchF) {
169 cout << "-E- " << GetName() << "::Exec: "
170 << "No DigiMatchF for hit " << iHit << endl;
171 hit->SetRefIndex(-1);
172 nNoDigi++;
173 warn = kTRUE;
174 continue;
175 }
176
177 // Get back side DigiMatch of hit (for strip sensors only)
178 if (iType != 1) {
179 Int_t iMatchB = hit->GetDigi(1);
180 if (iMatchB >= 0)
181 dMatchB = (CbmStsDigiMatch*)fDigiMatches->At(iMatchB);
182 if (!dMatchB) {
183 cout << "-E- " << GetName() << "::Exec: "
184 << "No DigiMatchB for hit " << iHit << endl;
185 hit->SetRefIndex(-1);
186 nNoDigi++;
187 warn = kTRUE;
188 continue;
189 }
190 }
191
192 // Map candidate points to distance to hit
193 fCandMap.clear();
194 Int_t nPointsF = 0;
195 Int_t nPointsB = 0;
196
197 if (iType == 1) {
198 // Case pixel: Candidates are all points of the digi.
199 for (Int_t jMatchF = 0; jMatchF < 3; jMatchF++) {
200 Int_t iPointF = dMatchF->GetRefIndex(jMatchF);
201 if (iPointF < 0)
202 continue;
203 nPointsF++;
204 // Calculate distance to hit
205 CbmStsPoint* point = (CbmStsPoint*)fPoints->At(iPointF);
206 if (!point) {
207 cout << "-E- " << GetName() << "::Exec: "
208 << "No StsPoint (" << iPointF << ") for pixel hit " << iHit << endl;
209 warn = kTRUE;
210 continue;
211 }
212 // point coordinates in station midplane
213 Double_t xP = point->GetX(station->GetZ());
214 Double_t yP = point->GetY(station->GetZ());
215 Double_t dist = TMath::Sqrt((xP - xH) * (xP - xH) + (yP - yH) * (yP - yH));
216 fCandMap[dist] = iPointF;
217 } // front digi loop
218 } // pixel sensor
219
220 else if (iType == 2 || iType == 3)
221 {
222 // Case strip: Candidates are points corresponding to front
223 // and back side digis
224 for (Int_t jMatchF = 0; jMatchF < 3; jMatchF++) {
225 Int_t iPointF = dMatchF->GetRefIndex(jMatchF);
226 if (iPointF < 0)
227 continue;
228 nPointsF++;
229 for (Int_t jMatchB = 0; jMatchB < 3; jMatchB++) {
230 Int_t iPointB = dMatchB->GetRefIndex(jMatchB);
231 if (iPointB < 0)
232 continue;
233 if (jMatchF == 0)
234 nPointsB++;
235 if (iPointB != iPointF)
236 continue; // chance combination
237 // Calculate distance to hit
238 CbmStsPoint* point = (CbmStsPoint*)fPoints->At(iPointF);
239 if (!point) {
240 cout << "-E- " << GetName() << "::Exec: "
241 << "No StsPoint (" << iPointF << ") for strip hit " << iHit << endl;
242 warn = kTRUE;
243 continue;
244 }
245 // point coordinates in station midplane
246 Double_t xP = point->GetX(station->GetZ());
247 Double_t yP = point->GetY(station->GetZ());
248 Double_t dist = TMath::Sqrt((xP - xH) * (xP - xH) + (yP - yH) * (yP - yH));
249 fCandMap[dist] = iPointF;
250 } // back digi loop
251 } // front digi loop
252 } // strip sensor
253
254 else
255 {
256 // Unknown sensor type
257 cout << "-E- " << GetName() << "::Exec: Unknwon sensor type " << iType << endl;
258 Fatal("Exec", "Unknwon sensor type");
259 }
260
261 if (fVerbose > 1)
262 cout << "-I- " << GetName() << ": Hit " << iHit << ", type " << iType << ", points " << nPointsF << " / "
263 << nPointsB << ", candidates " << fCandMap.size();
264
265 // Check for at least one candidate point. Else background hit.
266 // This can happen for noise digis or for fake combinations
267 // of strip digis.
268 if (fCandMap.empty()) {
269 hit->SetRefIndex(-1);
270 if (fVerbose > 1)
271 cout << ", background " << endl;
272 nBackgrd++;
273 continue;
274 }
275
276 // Select closest point from candidates.
277 Double_t distMin = 999999.;
278 Int_t iPoint = -1;
279 for (fIter = fCandMap.begin(); fIter != fCandMap.end(); fIter++) {
280 if ((*fIter).first < distMin) {
281 distMin = (*fIter).first;
282 iPoint = (*fIter).second;
283 }
284 }
285 if (iPoint < 0) {
286 cout << "-E- " << GetName() << "::Exec: "
287 << "No closest point found in candidate map!" << endl;
288 Fatal("Exec", "No closest point");
289 }
290 CbmStsPoint* point = (CbmStsPoint*)fPoints->At(iPoint);
291 if (fVerbose > 1)
292 cout << ", matched to " << iPoint << ", distance " << distMin << " cm";
293
294 // Check whether closest point is more than 5 sigma away from hit.
295 // This should not happen in case of pixel or strip OSU sensors,
296 // but can happen for strip GSI sensors due to multiple
297 // crossings of front and back side strips.
298 Double_t xP = point->GetX(station->GetZ());
299 Double_t yP = point->GetY(station->GetZ());
300 if (TMath::Abs(xP - xH) > 5. * dX || TMath::Abs(yP - yH) > 5. * dY) {
301 hit->SetRefIndex(-2);
302 nDistant++;
303 if (fVerbose > 1)
304 cout << ", distant" << endl;
305 if (iType == 1 || iType == 2) {
306 cout << "-W- " << fName << "::Exec: "
307 << "Distant hit in pixel / strip MSU station" << endl;
308 cout << "Hit " << iHit << " coordinates " << xH << ", " << yH << endl;
309 cout << "Matched point " << iPoint << ", distance " << distMin << endl;
310 cout << "Distance y " << TMath::Abs(xP - xH) << " Error " << dX << endl;
311 cout << "Distance y " << TMath::Abs(yP - yH) << " Error " << dY << endl;
312 }
313
314 continue;
315 }
316
317 // Match closest StsPoint to hit
318 hit->SetRefIndex(iPoint);
319 nMatched++;
320 if (fVerbose > 1)
321 cout << ", good match" << endl;
322
323 // Check whether hit and point are in the same station.
324 // Else something has really gone wrong.
325 if (TMath::Abs(hit->GetZ() - point->GetZ()) > 1.) {
326 cout << "-E- " << GetName() << "::Exec: Hit " << iHit << " is at z = " << hit->GetZ()
327 << " cm, but matched point " << iPoint << " is at z = " << point->GetZ() << "cm " << endl;
328 Fatal("Exec", "Different stations for hit and point");
329 }
330
331 } // Loop over StsHits
332
333 // Event statistics
334 fTimer.Stop();
335 if (fVerbose) {
336 if (warn)
337 cout << "- ";
338 else
339 cout << "+ ";
340 cout << setw(15) << left << fName << ": " << setprecision(4) << setw(8) << fixed << right << fTimer.RealTime()
341 << " s, hits " << nHits << ", matched " << nMatched << ", distant " << nDistant << ", background "
342 << setw(6) << nBackgrd << endl;
343 }
344
345 // Run statistics
346 if (warn)
348 else {
349 fNEvents++;
350 fTime += fTimer.RealTime();
351 fNHits += Double_t(nHits);
352 fNMatched += Double_t(nMatched);
353 fNDistant += Double_t(nDistant);
354 fNBackgrd += Double_t(nBackgrd);
355 }
356}
357// -------------------------------------------------------------------------
358
359// ----- Private method SetParContainers -------------------------------
361{
362
363 // Get run and runtime database
364 FairRunAna* run = FairRunAna::Instance();
365 if (!run)
366 Fatal("SetParContainers", "No analysis run");
367 FairRuntimeDb* db = run->GetRuntimeDb();
368 if (!db)
369 Fatal("SetParContainers", "No runtime database");
370
371 // Get STS geometry and digitisation parameter container
372 fGeoPar = (CbmGeoStsPar*)db->getContainer("CbmGeoStsPar");
373 fDigiPar = (CbmStsDigiPar*)db->getContainer("CbmStsDigiPar");
374}
375// -------------------------------------------------------------------------
376
377// ----- Private method Init -------------------------------------------
379{
380
381 // Reset counters
384
385 // Get input arrays
386 FairRootManager* ioman = FairRootManager::Instance();
387 if (!ioman)
388 Fatal("Init", "No FairRootManager");
389 fPoints = (TClonesArray*)ioman->GetObject("StsPoint");
390 if (!fPoints) {
391 // cout << "-E- " << GetName() << "::Init: No STSPoint array!" << endl;
392 return kERROR;
393 }
394 fDigis = (TClonesArray*)ioman->GetObject("StsDigi");
395 if (!fDigis) {
396 cout << "-E- " << GetName() << "::Init: No StsDigi array!" << endl;
397 return kERROR;
398 }
399 fDigiMatches = (TClonesArray*)ioman->GetObject("StsDigiMatch");
400 if (!fDigiMatches) {
401 cout << "-E- " << GetName() << "::Init: No StsDigiMatch array!" << endl;
402 return kERROR;
403 }
404 fHits = (TClonesArray*)ioman->GetObject("StsHit");
405 if (!fHits) {
406 cout << "-E- " << GetName() << "::Init: No StsHit array!" << endl;
407 return kERROR;
408 }
409
410 // Build digitisation scheme
411 if (fDigiScheme->Init(fGeoPar, fDigiPar)) {
412 if (fVerbose == 1 || fVerbose == 2)
413 fDigiScheme->Print(kFALSE);
414 else if (fVerbose > 2)
415 fDigiScheme->Print(kTRUE);
416 cout << "-I- " << fName << "::Init: "
417 << "STS digitisation scheme succesfully initialised" << endl;
418 cout << " Stations: " << fDigiScheme->GetNStations() << ", Sectors: " << fDigiScheme->GetNSectors()
419 << ", Channels: " << fDigiScheme->GetNChannels() << endl;
420 return kSUCCESS;
421 }
422
423 return kERROR;
424}
425// -------------------------------------------------------------------------
426
427// ----- Private method ReInit -----------------------------------------
429{
430
431 // Clear digitisation scheme
432 fDigiScheme->Clear();
433
434 // Build new digitisation scheme
435 if (fDigiScheme->Init(fGeoPar, fDigiPar))
436 return kSUCCESS;
437
438 return kERROR;
439}
440// -------------------------------------------------------------------------
441
442// ----- Private method Finish -----------------------------------------
444{
445
446 cout << endl;
447 cout << "============================================================" << endl;
448 cout << "===== " << GetName() << ": Run summary " << endl;
449 cout << "===== " << endl;
450 cout << "===== Good events : " << setw(6) << fNEvents << endl;
451 cout << "===== Failed events : " << setw(6) << fNEventsFailed << endl;
452 cout << "===== Average time : " << setprecision(4) << setw(8) << right << fTime / Double_t(fNEvents) << " s"
453 << endl;
454 cout << "===== " << endl;
455 cout << "===== Hits per event : " << fixed << setprecision(0) << fNHits / Double_t(fNEvents) << endl;
456 cout << setprecision(2);
457 cout << "===== Matched hits : " << fixed << setw(6) << right << fNMatched / fNHits * 100. << " %" << endl;
458 cout << "===== Distant hits : " << fixed << setw(6) << right << fNDistant / fNHits * 100. << " %" << endl;
459 cout << "===== Background hits : " << fixed << setw(6) << right << fNBackgrd / fNHits * 100. << " % " << endl;
460 cout << "============================================================" << endl;
461}
462// -------------------------------------------------------------------------
vector< Double_t > dist(vector< Double_t > qp, Double_t mu)
Definition BmnMath.cxx:869
bool Bool_t
int Int_t
constexpr Bool_t kFALSE
double Double_t
constexpr Bool_t kTRUE
const char Option_t
void Fatal(const char *location, const char *msgfmt,...)
CbmStsDigiMatch.h.
Int_t GetRefIndex(Int_t i=0) const
Accessor to StsPoint indizes.
virtual Int_t GetStationNr() const
Definition CbmStsHit.h:67
Int_t GetSectorNr() const
Definition CbmStsHit.h:68
Int_t GetDigi(Int_t iSide) const
virtual void Finish()
Run summary.
CbmStsDigiScheme * fDigiScheme
Digitisation parameter container.
TClonesArray * fPoints
Digitisation scheme.
std::map< Double_t, Int_t > fCandMap
Total number of background hits.
virtual void Exec(Option_t *opt)
Execution.
TClonesArray * fDigiMatches
Array of CbmStsDigi.
TStopwatch fTimer
Array of CbmStsHit.
virtual ~CbmStsIdealMatchHits()
Destructor.
virtual void SetParContainers()
Get parameter containers.
Double_t fNBackgrd
Total number of displaced hits.
CbmStsDigiPar * fDigiPar
Geometry parameter container.
Double_t fTime
Number of events with failure.
virtual InitStatus ReInit()
Reinitialisation.
TClonesArray * fDigis
Array of CbmStsPoint.
Int_t fNEventsFailed
Number of events with success.
std::map< Double_t, Int_t >::iterator fIter
TClonesArray * fHits
Array of CbmStsDigiMatch.
CbmStsIdealMatchHits()
Default constructor.
virtual InitStatus Init()
Intialisation.
Double_t fNMatched
Total number of hits.
Double_t fNHits
Total real time used for good events.
Double_t fNDistant
Total number of matched hits.
Double_t GetY(Double_t z) const
Double_t GetX(Double_t z) const
Point coordinates at given z from linear extrapolation.
Int_t GetType() const
Double_t GetZ(Int_t it=0)
Double_t Sqrt(Double_t x)
Double_t Abs(Double_t d)