BmnRoot 26.10.0-18-g4e3414f9
Software framework of the BM@N experiment
Loading...
Searching...
No Matches
CbmStsMatchHits.cxx
Go to the documentation of this file.
1//* $Id: */
2
3// -------------------------------------------------------------------------
4// ----- CbmStsMatchHits source file -----
5// ----- Created 01/07/2008 by R. Karabowicz -----
6// -------------------------------------------------------------------------
7
8// --- Includes from ROOT
9#include "TClonesArray.h"
10
11// --- Includes from base
12#include "FairRootManager.h"
13#include "FairRunAna.h"
14#include "FairRuntimeDb.h"
15
16// --- Includes from STS
17#include "BmnSiliconPoint.h" //AZ-280322
18#include "CbmGeoStsPar.h"
19#include "CbmStsCluster.h"
20#include "CbmStsDigi.h"
21#include "CbmStsDigiMatch.h"
22#include "CbmStsDigiPar.h"
23#include "CbmStsDigiScheme.h"
24#include "CbmStsHit.h"
25#include "CbmStsMatchHits.h"
26#include "CbmStsPoint.h"
27#include "CbmStsSector.h"
28#include "CbmStsSensor.h" //AZ
29#include "CbmStsStation.h"
30#include "FairGeoNode.h"
31#include "FairGeoPassivePar.h"
32#include "FairGeoVector.h"
33#include "TGeoManager.h" //AZ
34#include "TMath.h"
35
36#include <iomanip>
37#include <iostream>
38#include <map>
39
40using std::cout;
41using std::endl;
42using std::fixed;
43using std::flush;
44using std::left;
45using std::map;
46using std::right;
47using std::setprecision;
48using std::setw;
49
50// ----- Default constructor -------------------------------------------
52 : FairTask("STSMatchHits", 1)
53 , fGeoPar(NULL)
54 , fDigiPar(NULL)
55 , fDigiScheme(NULL)
56 , fPoints(NULL)
57 , fPointsSi(nullptr)
58 , // AZ-280322
59 fDigis(NULL)
60 , fDigiMatches(NULL)
61 , fHits(NULL)
62 , fTimer()
63 , fNEvents(0)
65 , fTime(0.)
66 , fNHits(0.)
67 , fNMatched(0.)
68 , fNDistant(0.)
69 , fNBackgrd(0.)
70 , fPassGeo(NULL)
71 , fTargetPos(0., 0., 0.)
72 , fNStations(0)
74 , fCandMap()
75 , fIter()
76{
77 // AZ fDigiScheme = new CbmStsDigiScheme();
79}
80// -------------------------------------------------------------------------
81
82// ----- Standard constructor ------------------------------------------
84 : FairTask("STSMatchHits", iVerbose)
85 , fGeoPar(NULL)
86 , fDigiPar(NULL)
87 , fDigiScheme(NULL)
88 , fPoints(NULL)
89 , fPointsSi(nullptr)
90 , // AZ-280322
91 fDigis(NULL)
92 , fDigiMatches(NULL)
93 , fHits(NULL)
94 , fTimer()
95 , fNEvents(0)
97 , fTime(0.)
98 , fNHits(0.)
99 , fNMatched(0.)
100 , fNDistant(0.)
101 , fNBackgrd(0.)
102 , fPassGeo(NULL)
103 , fTargetPos(0., 0., 0.)
104 , fNStations(0)
106 , fCandMap()
107 , fIter()
108{
109 // AZ fDigiScheme = new CbmStsDigiScheme();
111}
112// -------------------------------------------------------------------------
113
114// ----- Constructor with name -----------------------------------------
115CbmStsMatchHits::CbmStsMatchHits(const char* name, Int_t iVerbose)
116 : FairTask(name, iVerbose)
117 , fGeoPar(NULL)
118 , fDigiPar(NULL)
119 , fDigiScheme(NULL)
120 , fPoints(NULL)
121 , fPointsSi(nullptr)
122 , // AZ-280322
123 fDigis(NULL)
124 , fDigiMatches(NULL)
125 , fHits(NULL)
126 , fTimer()
127 , fNEvents(0)
128 , fNEventsFailed(0)
129 , fTime(0.)
130 , fNHits(0.)
131 , fNMatched(0.)
132 , fNDistant(0.)
133 , fNBackgrd(0.)
134 , fPassGeo(NULL)
135 , fTargetPos(0., 0., 0.)
136 , fNStations(0)
138 , fCandMap()
139 , fIter()
140{
141 // AZ fDigiScheme = new CbmStsDigiScheme();
143}
144// -------------------------------------------------------------------------
145
146// ----- Destructor ----------------------------------------------------
148{
149 if (fPassGeo)
150 delete fPassGeo;
151 if (fGeoPar)
152 delete fGeoPar;
153 if (fDigiPar)
154 delete fDigiPar;
155 // AZ if ( fDigiScheme ) delete fDigiScheme;
156}
157// -------------------------------------------------------------------------
158
159// ----- Public method Exec --------------------------------------------
161{
162
163 if (fRealistic) {
164 ExecReal(opt);
165 return;
166 }
167
168 // Timer
169 fTimer.Start();
170 Bool_t warn = kFALSE;
171
172 // Counters
173 Int_t nHits = fHits->GetEntriesFast();
174 Int_t nNoDigi = 0;
175 Int_t nBackgrd = 0;
176 Int_t nDistant = 0;
177 Int_t nMatched = 0;
178
179 // Loop over all StsHits
180 for (Int_t iHit = 0; iHit < nHits; iHit++) {
181 CbmStsHit* hit = (CbmStsHit*)fHits->At(iHit);
182 if (!hit) {
183 cout << "-W- " << GetName() << "::Exec: Empty hit at index " << iHit << endl;
184 warn = kTRUE;
185 continue;
186 }
187
188 // Determine sector type and channel numbers
189 Int_t iStation = hit->GetStationNr();
190 Int_t iSector = hit->GetSectorNr();
191 CbmStsStation* station = fDigiScheme->GetStationByNr(iStation);
192 CbmStsSector* sector = fDigiScheme->GetSector(iStation, iSector);
193 Int_t iType = sector->GetType();
194 CbmStsDigiMatch* dMatchF = NULL;
195 CbmStsDigiMatch* dMatchB = NULL;
196
197 // Hit coordinates and errors
198 Double_t xH = hit->GetX();
199 Double_t yH = hit->GetY();
200 Double_t dX = hit->GetDx();
201 Double_t dY = hit->GetDy();
202
203 // Get front side DigiMatch corresponding to hit
204 Int_t iMatchF = (Int_t)hit->GetDigi(0);
205 if (iMatchF >= 0)
206 dMatchF = (CbmStsDigiMatch*)fDigiMatches->At(iMatchF);
207 if (!dMatchF) {
208 cout << "-E- " << GetName() << "::Exec: "
209 << "No DigiMatchF for hit " << iHit << endl;
210 hit->SetRefIndex(-1);
211 nNoDigi++;
212 warn = kTRUE;
213 continue;
214 }
215
216 // Get back side DigiMatch of hit (for strip sensors only)
217 if (iType != 1) {
218 Int_t iMatchB = (Int_t)hit->GetDigi(1);
219 if (iMatchB >= 0)
220 dMatchB = (CbmStsDigiMatch*)fDigiMatches->At(iMatchB);
221 if (!dMatchB) {
222 cout << "-E- " << GetName() << "::Exec: "
223 << "No DigiMatchB for hit " << iHit << endl;
224 hit->SetRefIndex(-1);
225 nNoDigi++;
226 warn = kTRUE;
227 continue;
228 }
229 }
230
231 // Map candidate points to distance to hit
232 fCandMap.clear();
233 Int_t nPointsF = 0;
234 Int_t nPointsB = 0;
235
236 if (iType == 1) {
237 // Case pixel: Candidates are all points of the digi.
238 for (Int_t jMatchF = 0; jMatchF < 3; jMatchF++) {
239 Int_t iPointF = dMatchF->GetRefIndex(jMatchF);
240 if (iPointF < 0)
241 continue;
242 nPointsF++;
243 // Calculate distance to hit
244 CbmStsPoint* point = (CbmStsPoint*)fPoints->At(iPointF);
245 if (!point) {
246 cout << "-E- " << GetName() << "::Exec: "
247 << "No StsPoint (" << iPointF << ") for pixel hit " << iHit << endl;
248 warn = kTRUE;
249 continue;
250 }
251 // point coordinates in station midplane
252 Double_t xP = point->GetX(station->GetZ());
253 Double_t yP = point->GetY(station->GetZ());
254 Double_t dist = TMath::Sqrt((xP - xH) * (xP - xH) + (yP - yH) * (yP - yH));
255 // cout << "candidate dist = " << dist << endl;
256 fCandMap[dist] = iPointF;
257 } // front digi loop
258 } // pixel sensor
259
260 else if (iType == 2 || iType == 3)
261 {
262 // Case strip: Candidates are points corresponding to front
263 // and back side digis
264 for (Int_t jMatchF = 0; jMatchF < 3; jMatchF++) {
265 Int_t iPointF = dMatchF->GetRefIndex(jMatchF);
266 if (iPointF < 0)
267 continue;
268 // cout << " got pointf index = " << iPointF << endl;
269 nPointsF++;
270 for (Int_t iMatchB = 0; iMatchB < 3; iMatchB++) {
271 Int_t iPointB = dMatchB->GetRefIndex(iMatchB);
272 if (iPointB < 0)
273 continue;
274 // cout << " got pointb index = " << iPointB << endl;
275 if (iMatchF == 0)
276 nPointsB++;
277 if (iPointB != iPointF)
278 continue; // chance combination
279 // Calculate distance to hit
280 CbmStsPoint* point = (CbmStsPoint*)fPoints->At(iPointF);
281 if (!point) {
282 cout << "-E- " << GetName() << "::Exec: "
283 << "No StsPoint (" << iPointF << ") for strip hit " << iHit << endl;
284 warn = kTRUE;
285 continue;
286 }
287 // point coordinates in station midplane
288 Double_t xP = point->GetX(station->GetZ());
289 Double_t yP = point->GetY(station->GetZ());
290 Double_t dist = TMath::Sqrt((xP - xH) * (xP - xH) + (yP - yH) * (yP - yH));
291 fCandMap[dist] = iPointF;
292 } // back digi loop
293 } // front digi loop
294 } // strip sensor
295
296 else
297 {
298 // Unknown sensor type
299 cout << "-E- " << GetName() << "::Exec: Unknwon sensor type " << iType << endl;
300 Fatal("Exec", "Unknwon sensor type");
301 }
302
303 if (fVerbose > 1)
304 cout << "-I- " << GetName() << ": Hit " << iHit << ", type " << iType << ", points " << nPointsF << " / "
305 << nPointsB << ", candidates " << fCandMap.size();
306
307 // Check for at least one candidate point. Else background hit.
308 // This can happen for noise digis or for fake combinations
309 // of strip digis.
310 if (fCandMap.empty()) {
311 hit->SetRefIndex(-1);
312 if (fVerbose > 1)
313 cout << ", background " << endl;
314 nBackgrd++;
315 continue;
316 }
317
318 // Select closest point from candidates.
319 Double_t distMin = 999999.;
320 Int_t iPoint = -1;
321 for (fIter = fCandMap.begin(); fIter != fCandMap.end(); fIter++) {
322 if ((*fIter).first < distMin) {
323 distMin = (*fIter).first;
324 iPoint = (*fIter).second;
325 }
326 }
327 if (iPoint < 0) {
328 cout << "-E- " << GetName() << "::Exec: "
329 << "No closest point found in candidate map!" << endl;
330 Fatal("Exec", "No closest point");
331 }
332 CbmStsPoint* point = (CbmStsPoint*)fPoints->At(iPoint);
333 if (fVerbose > 1)
334 cout << ", matched to " << iPoint << ", distance " << distMin << " cm";
335
336 // Check whether closest point is more than 5 sigma away from hit.
337 // This should not happen in case of pixel or strip OSU sensors,
338 // but can happen for strip GSI sensors due to multiple
339 // crossings of front and back side strips.
340 Double_t xP = point->GetX(station->GetZ());
341 Double_t yP = point->GetY(station->GetZ());
342 if (TMath::Abs(xP - xH) > 5. * dX || TMath::Abs(yP - yH) > 5. * dY) {
343 hit->SetRefIndex(-2);
344 nDistant++;
345 if (fVerbose > 1)
346 cout << ", distant" << endl;
347 if (iType == 1 || iType == 2) {
348 cout << "-W- " << fName << "::Exec: "
349 << "Distant hit in pixel / strip MSU station" << endl;
350 cout << "Hit " << iHit << " coordinates " << xH << ", " << yH << endl;
351 cout << "Matched point " << iPoint << ", distance " << distMin << endl;
352 cout << "Distance y " << TMath::Abs(xP - xH) << " Error " << dX << endl;
353 cout << "Distance y " << TMath::Abs(yP - yH) << " Error " << dY << endl;
354 }
355
356 continue;
357 }
358
359 // Match closest StsPoint to hit
360 hit->SetRefIndex(iPoint);
361 nMatched++;
362 if (fVerbose > 1)
363 cout << ", good match" << endl;
364
365 // Check whether hit and point are in the same station.
366 // Else something has really gone wrong.
367 if (TMath::Abs(hit->GetZ() - point->GetZ()) > 1.) {
368 cout << "-E- " << GetName() << "::Exec: Hit " << iHit << " is at z = " << hit->GetZ()
369 << " cm, but matched point " << iPoint << " is at z = " << point->GetZ() << "cm " << endl;
370 Fatal("Exec", "Different stations for hit and point");
371 }
372
373 } // Loop over StsHits
374
375 // Event statistics
376 fTimer.Stop();
377 if (warn)
378 cout << "- ";
379 else
380 cout << "+ ";
381 cout << setw(15) << left << fName << ": " << setprecision(4) << setw(8) << fixed << right << fTimer.RealTime()
382 << " s, hits " << nHits << ", matched " << nMatched << ", distant " << nDistant << ", background " << setw(6)
383 << nBackgrd << endl;
384
385 // Run statistics
386 if (warn)
388 else {
389 fNEvents++;
390 fTime += fTimer.RealTime();
391 fNHits += Double_t(nHits);
392 fNMatched += Double_t(nMatched);
393 fNDistant += Double_t(nDistant);
394 fNBackgrd += Double_t(nBackgrd);
395 }
396}
397
398// -------------------------------------------------------------------------
399
400// ----- Public method ExecReal --------------------------------------------
401// AZ
403{
404
405 // Timer
406 fTimer.Start();
407 Bool_t warn = kFALSE;
408
409 // Counters
410 Int_t nHits = fHits->GetEntriesFast();
411 // Int_t nNoDigi = 0;
412 Int_t nBackgrd = 0;
413 Int_t nDistant = 0;
414 Int_t nMatched = 0;
415
416 Int_t nofStsHits = fHits->GetEntriesFast();
417 Int_t nofStsPoints = fPoints->GetEntriesFast();
418 int nofSiPoints = 0; // AZ-280322
419 if (fPointsSi)
420 nofSiPoints = fPointsSi->GetEntriesFast(); // AZ-280322
421 // cout << "there are " << nofStsPoints << " points and " << nofStsHits << " hits." << endl;
422 Int_t hitStationLimits[2][100];
423
424 // Workaround. TODO.
425 // fNStations = 8;
426 fNStations = 20; // AZ
427
428 for (Int_t ist = 0; ist < fNStations; ist++) {
429 hitStationLimits[0][ist] = -1;
430 hitStationLimits[1][ist] = -1;
431 }
432
433 // check for limits of hit indices on different stations...
434 for (Int_t ihit = 0; ihit < nofStsHits; ihit++) {
435 CbmStsHit* stsHit = (CbmStsHit*)fHits->At(ihit);
436 stsHit->SetRefIndex(-1);
437 if (hitStationLimits[0][stsHit->GetStationNr() - 1] == -1)
438 hitStationLimits[0][stsHit->GetStationNr() - 1] = ihit;
439 CbmStsHit* stsHitBack = (CbmStsHit*)fHits->At(nofStsHits - ihit - 1);
440 if (hitStationLimits[1][stsHitBack->GetStationNr() - 1] == -1) {
441 hitStationLimits[1][stsHitBack->GetStationNr() - 1] = nofStsHits - ihit;
442 }
443 }
444 // for ( Int_t istat = 0 ; istat < fNStations ; istat++ )
445 // cout << "station " << istat << " hits from " << hitStationLimits[0][istat] << " to " <<
446 // hitStationLimits[1][istat] << endl;
447
448 int nTotPoints = nofSiPoints + nofStsPoints; // AZ-280322
449 CbmStsPoint* stsPoint = nullptr; // AZ-280322
450
451 // AZ-280322 for ( Int_t ipnt = 0 ; ipnt < nofStsPoints ; ipnt++ ) {
452 for (Int_t iii = 0; iii < nTotPoints; iii++) { // AZ-280322
453 // AZ-280322 CbmStsPoint *stsPoint = (CbmStsPoint*)fPoints->At(ipnt);
454 int ipnt = (iii < nofSiPoints) ? iii : iii - nofSiPoints;
455 if (iii < nofSiPoints)
456 stsPoint = (CbmStsPoint*)fPointsSi->At(ipnt); // AZ-280322
457 else
458 stsPoint = (CbmStsPoint*)fPoints->At(ipnt); // AZ-280322
459
460 // This is a workaround. Has to be worked out when new digi scheme is implemented. TODO.
461 // AZ Double_t zPoint = stsPoint->GetZIn();
462 // AZ Int_t stationNr = TMath::Nint((zPoint-30.)/10.);
463 // AZ - Get station number
464 Double_t xin = stsPoint->GetXIn();
465 Double_t yin = stsPoint->GetYIn();
466 Double_t zin = stsPoint->GetZIn();
467 gGeoManager->FindNode(xin, yin, zin);
468 TGeoNode* curNode = gGeoManager->GetCurrentNode();
469 CbmStsSensor* sensor = NULL;
470 // if ( fDigiScheme->IsNewGeometry() ) {
471 TString curPath = fDigiScheme->GetCurrentPath();
472 sensor = fDigiScheme->GetSensorByName(curPath);
473 if (!sensor) {
474 // AZ - 160920: Check one level above (for double-sensor modules)
475 gGeoManager->CdUp();
476 curPath = fDigiScheme->GetCurrentPath();
477 sensor = fDigiScheme->GetSensorByName(curPath);
478 //
479 if (!sensor) {
480 std::cerr << "-E- " << fName << "::ExecReal:: sensor " << curNode->GetName()
481 << " not found in digi scheme!" << endl;
482 continue;
483 }
484 }
485 Int_t stationNr = sensor->GetStationNr() - 1;
486 //}
487 // AZ
488
489 // This does not work with new geometries since the StsGeoPar are not filled.
490 // Int_t stationNr = fStationNrFromMcId[stsPoint->GetDetectorID()]];
491
492 Int_t startHit = hitStationLimits[0][stationNr];
493 Int_t finalHit = hitStationLimits[1][stationNr];
494
495 if (startHit == -1 && finalHit == -1)
496 continue;
497 if (startHit < 0 || finalHit < 0 || startHit > fHits->GetEntriesFast() || finalHit > fHits->GetEntriesFast())
498 continue;
499
500 Int_t NofMatched = 0;
501 // AZ Double_t GoodHit[100];
502 // AZ Int_t GoodHitIndex[nofStsHits];
503 Double_t GoodHit[50000];
504 Int_t GoodHitIndex[50000];
505 for (Int_t ihit = startHit; ihit < finalHit; ihit++) {
506 CbmStsHit* stsHit = (CbmStsHit*)fHits->At(ihit);
507 if (NULL == stsHit) {
508 std::cout << "CbmStsMatchHits::ExecReal: CbmStsHit NULL pointer: ihit=" << ihit << " "
509 << "startHit=" << startHit << " finalHit=" << finalHit << std::endl;
510 continue;
511 }
512
513 // Check one side
514 Int_t iL = 0, nMatch = 0;
515 FairLink link = stsHit->GetLink(iL);
516 CbmStsCluster* stsCluster = dynamic_cast<CbmStsCluster*>(fClusters->UncheckedAt(link.GetIndex()));
517 Int_t nLinks2 = stsCluster->GetNLinks();
518 for (Int_t iL2 = 0; iL2 < nLinks2; ++iL2) {
519 FairLink link2 = stsCluster->GetLink(iL2);
520 // CbmStsDigi *stsDigi = dynamic_cast<CbmStsDigi*> (fDigis->UncheckedAt(link2.GetIndex()));
521 CbmStsDigiMatch* stsDigiMatch =
522 dynamic_cast<CbmStsDigiMatch*>(fDigiMatches->UncheckedAt(link2.GetIndex()));
523 // const Int_t nLinks3 = stsDigi->GetNLinks();
524 const Int_t nLinks3 = 3;
525 for (Int_t iL3 = 0; iL3 < nLinks3; ++iL3) {
526 // FairLink link3 = stsDigi->GetLink(iL3);
527 // Int_t stsPointId = link3.GetIndex();
528 Int_t stsPointId = stsDigiMatch->GetRefIndex(iL3);
529 if (stsPointId == ipnt) {
530 ++nMatch;
531 break;
532 } else if (stsPointId < 0)
533 break;
534 } // for mcPoint
535 if (nMatch)
536 break;
537 } // for digi
538
539 // Check the other side
540 iL = 1;
541 link = stsHit->GetLink(iL);
542 stsCluster = dynamic_cast<CbmStsCluster*>(fClusters->UncheckedAt(link.GetIndex()));
543 nLinks2 = stsCluster->GetNLinks();
544 for (Int_t iL2 = 0; iL2 < nLinks2; ++iL2) {
545 FairLink link2 = stsCluster->GetLink(iL2);
546 // CbmStsDigi *stsDigi = dynamic_cast<CbmStsDigi*> (fDigis->UncheckedAt(link2.GetIndex()));
547 CbmStsDigiMatch* stsDigiMatch =
548 dynamic_cast<CbmStsDigiMatch*>(fDigiMatches->UncheckedAt(link2.GetIndex()));
549 // const Int_t nLinks3 = stsDigi->GetNLinks();
550 const Int_t nLinks3 = 3;
551 for (Int_t iL3 = 0; iL3 < nLinks3; ++iL3) {
552 // FairLink link3 = stsDigi->GetLink(iL3);
553 // Int_t stsPointId = link3.GetIndex();
554 Int_t stsPointId = stsDigiMatch->GetRefIndex(iL3);
555 if (stsPointId == ipnt) {
556 ++nMatch;
557 break;
558 } else if (stsPointId < 0)
559 break;
560 } // for mcPoint
561 if (nMatch == 2)
562 break;
563 } // for digi
564
565 if (nMatch == 2) {
566 Double_t xH = stsHit->GetX();
567 Double_t yH = stsHit->GetY();
568 // AZ-280322 Double_t xP = stsPoint->GetX(stsHit->GetZ());
569 // AZ-280322 Double_t yP = stsPoint->GetY(stsHit->GetZ());
570 Double_t xP = stsPoint->GetXIn(); // AZ-280322
571 Double_t yP = stsPoint->GetYIn(); // AZ-280322
572 Double_t dist = TMath::Sqrt((xP - xH) * (xP - xH) + (yP - yH) * (yP - yH));
573 nMatched++;
574 NofMatched++;
575 GoodHitIndex[NofMatched] = ihit;
576 GoodHit[NofMatched] = dist;
577 }
578
579 } // for ( Int_t ihit = startHit ; ihit < finalHit ;
580
581 Int_t k = NofMatched;
582 if (NofMatched > 1) {
583 for (Int_t i = NofMatched - 1; i > 0; i--) {
584 if (GoodHit[i] < GoodHit[k])
585 k = i;
586 }
587 }
588 if (NofMatched > 0) {
589 CbmStsHit* stsHit = (CbmStsHit*)fHits->At(GoodHitIndex[k]);
590 stsHit->SetRefIndex(ipnt);
591 }
592 } // for ( Int_t iii = 0 ; iii < nTotPoints ;
593
594 // Event statistics
595 fTimer.Stop();
596 if (warn)
597 cout << "- ";
598 else
599 cout << "+ ";
600 cout << setw(15) << left << fName << ": " << setprecision(4) << setw(8) << fixed << right << fTimer.RealTime()
601 << " s, hits " << nHits << ", matched " << nMatched << ", distant " << nDistant << ", background " << setw(6)
602 << nBackgrd << endl;
603
604 // Run statistics
605 if (warn)
607 else {
608 fNEvents++;
609 fTime += fTimer.RealTime();
610 fNHits += Double_t(nHits);
611 fNMatched += Double_t(nMatched);
612 fNDistant += Double_t(nDistant);
613 fNBackgrd += Double_t(nBackgrd);
614 }
615}
616// -------------------------------------------------------------------------
617
618// ----- Public method ExecReal --------------------------------------------
619/*
620void CbmStsMatchHits::ExecReal(Option_t* opt) {
621
622 // Timer
623 fTimer.Start();
624 Bool_t warn = kFALSE;
625
626 // Counters
627 Int_t nHits = fHits->GetEntriesFast();
628 Int_t nNoDigi = 0;
629 Int_t nBackgrd = 0;
630 Int_t nDistant = 0;
631 Int_t nMatched = 0;
632
633 Int_t nofStsHits = fHits->GetEntriesFast();
634 Int_t nofStsPoints = fPoints->GetEntriesFast();
635 //cout << "there are " << nofStsPoints << " points and " << nofStsHits << " hits." << endl;
636 Int_t hitStationLimits[2][100];
637
638 // Workaround. TODO.
639 fNStations = 8;
640
641 for ( Int_t ist = 0 ; ist < fNStations ; ist++ ) {
642 hitStationLimits[0][ist] = -1;
643 hitStationLimits[1][ist] = -1;
644 }
645
646 // check for limits of hit indices on different stations...
647 for ( Int_t ihit = 0 ; ihit < nofStsHits ; ihit++ ) {
648 CbmStsHit *stsHit = (CbmStsHit*)fHits->At(ihit);
649 stsHit->SetRefIndex(-1);
650 if ( hitStationLimits[0][stsHit->GetStationNr()-1] == -1 )
651 hitStationLimits[0][stsHit->GetStationNr()-1] = ihit;
652 CbmStsHit *stsHitBack = (CbmStsHit*)fHits->At(nofStsHits-ihit-1);
653 if ( hitStationLimits[1][stsHitBack->GetStationNr()-1] == -1 ) {
654 hitStationLimits[1][stsHitBack->GetStationNr()-1] = nofStsHits-ihit;
655 }
656 }
657 //for ( Int_t istat = 0 ; istat < fNStations ; istat++ )
658 // cout << "station " << istat << " hits from " << hitStationLimits[0][istat] << " to " <<
659hitStationLimits[1][istat] << endl;
660
661 for ( Int_t ipnt = 0 ; ipnt < nofStsPoints ; ipnt++ ) {
662 CbmStsPoint *stsPoint = (CbmStsPoint*)fPoints->At(ipnt);
663
664 // This is a workaround. Has to be worked out when new digi scheme is implemented. TODO.
665 Double_t zPoint = stsPoint->GetZIn();
666 Int_t stationNr = TMath::Nint((zPoint-30.)/10.);
667
668 // This does not work with new geometries since the StsGeoPar are not filled.
669 // Int_t stationNr = fStationNrFromMcId[stsPoint->GetDetectorID()]];
670
671 Int_t startHit = hitStationLimits[0][stationNr];
672 Int_t finalHit = hitStationLimits[1][stationNr];
673
674 if ( startHit == -1 && finalHit == -1 ) continue;
675 if ( startHit < 0 || finalHit < 0 || startHit > fHits->GetEntriesFast() || finalHit > fHits->GetEntriesFast())
676continue;
677
678
679 Int_t NofMatched = 0;
680 Double_t GoodHit[100];
681 Int_t GoodHitIndex[nofStsHits];
682 for ( Int_t ihit = startHit ; ihit < finalHit ; ihit++ ) {
683 CbmStsHit *stsHit= (CbmStsHit*)fHits->At(ihit);
684 if (NULL == stsHit) {
685 std::cout << "CbmStsMatchHits::ExecReal: CbmStsHit NULL pointer: ihit=" << ihit
686 << " " << "startHit=" << startHit << " finalHit=" << finalHit << std::endl;
687 continue;
688 }
689 Double_t xH = stsHit->GetX();
690 Double_t yH = stsHit->GetY();
691 Double_t xP = stsPoint->GetX(stsHit->GetZ());
692 Double_t yP = stsPoint->GetY(stsHit->GetZ());
693 if ( ( TMath::Abs(stsHit->GetX()-stsPoint->GetX(stsHit->GetZ())) < .01 ) &&
694 ( TMath::Abs(stsHit->GetY()-stsPoint->GetY(stsHit->GetZ())) < .04 ) ) {
695 Double_t dist = TMath::Sqrt( (xP-xH)*(xP-xH) + (yP-yH)*(yP-yH) );
696 // cout << "matching "
697 // << "X: " << stsHit->GetX() << " - " << stsPoint->GetX(stsHit->GetZ())
698 // << "Y: " << stsHit->GetY() << " - " << stsPoint->GetY(stsHit->GetZ()) << endl;
699// cout << "candidate dist = " << dist << endl;
700
701 // cout << "setting ref index = " << stsHit->GetRefIndex() << " (max sts pnt = " << nofStsPoints << ")" << endl;
702 nMatched++;
703 NofMatched++;
704 GoodHitIndex[NofMatched]=ihit;
705 GoodHit[NofMatched]=dist;
706// cout <<" NofMatched = "<<NofMatched<<" dist = "<<dist<<flush;
707 }
708
709 }
710
711 Int_t k=NofMatched;
712 if (NofMatched>1){
713 for (Int_t i=NofMatched-1; i>0; i--) {
714
715 if (GoodHit[i]<GoodHit[k]) {
716 k=i;
717 }
718 }
719 }
720 if (NofMatched>0) {
721 CbmStsHit *stsHit= (CbmStsHit*)fHits->At(GoodHitIndex[k]);
722 stsHit->SetRefIndex(ipnt);
723 }
724 }
725
726 // Event statistics
727 fTimer.Stop();
728 if ( warn ) cout << "- ";
729 else cout << "+ ";
730 cout << setw(15) << left << fName << ": " << setprecision(4) << setw(8)
731 << fixed << right << fTimer.RealTime()
732 << " s, hits " << nHits << ", matched " << nMatched << ", distant "
733 << nDistant << ", background " << setw(6) << nBackgrd << endl;
734
735 // Run statistics
736 if ( warn) fNEventsFailed++;
737 else {
738 fNEvents++;
739 fTime += fTimer.RealTime();
740 fNHits += Double_t(nHits);
741 fNMatched += Double_t(nMatched);
742 fNDistant += Double_t(nDistant);
743 fNBackgrd += Double_t(nBackgrd);
744 }
745
746}
747*/
748// -------------------------------------------------------------------------
749
750// ----- Private method SetParContainers -------------------------------
752{
753
754 // Get run and runtime database
755 FairRunAna* run = FairRunAna::Instance();
756 if (!run)
757 Fatal("SetParContainers", "No analysis run");
758 FairRuntimeDb* db = run->GetRuntimeDb();
759 if (!db)
760 Fatal("SetParContainers", "No runtime database");
761
762 // Get STS geometry and digitisation parameter container
763 fPassGeo = (FairGeoPassivePar*)db->getContainer("FairGeoPassivePar");
764 fGeoPar = (CbmGeoStsPar*)db->getContainer("CbmGeoStsPar");
765 fDigiPar = (CbmStsDigiPar*)db->getContainer("CbmStsDigiPar");
766}
767// -------------------------------------------------------------------------
768
769// ----- Private method Init -------------------------------------------
771{
772
773 // Reset counters
776
777 // Get input arrays
778 FairRootManager* ioman = FairRootManager::Instance();
779 if (!ioman)
780 Fatal("Init", "No FairRootManager");
781 fPoints = (TClonesArray*)ioman->GetObject("StsPoint");
782 if (!fPoints) {
783 // cout << "-E- " << GetName() << "::Init: No STSPoint array!" << endl;
784 return kERROR;
785 }
786 fPointsSi = (TClonesArray*)ioman->GetObject("SiliconPoint"); // AZ-289322
787 fDigis = (TClonesArray*)ioman->GetObject("StsDigi");
788 if (!fDigis) {
789 cout << "-E- " << GetName() << "::Init: No StsDigi array!" << endl;
790 return kERROR;
791 }
792 fDigiMatches = (TClonesArray*)ioman->GetObject("StsDigiMatch");
793 if (!fDigiMatches) {
794 cout << "-E- " << GetName() << "::Init: No StsDigiMatch array!" << endl;
795 return kERROR;
796 }
797 fHits = (TClonesArray*)ioman->GetObject("StsHit");
798 if (!fHits) {
799 cout << "-E- " << GetName() << "::Init: No StsHit array!" << endl;
800 return kERROR;
801 }
802 // AZ
803 fClusters = (TClonesArray*)ioman->GetObject("StsCluster");
804 if (!fClusters) {
805 cout << "-E- " << GetName() << "::Init: No StsCluster array!" << endl;
806 return kERROR;
807 }
808 // AZ
809
810 InitStatus geoStatus = GetGeometry();
811 if (geoStatus != kSUCCESS) {
812 cout << "-E- " << GetName() << "::Init: Error in reading geometry!" << endl;
813 return geoStatus;
814 }
815
816 // Build digitisation scheme
817
818 if (fDigiScheme->Init(fGeoPar, fDigiPar)) {
819
820 if (fVerbose == 1 || fVerbose == 2)
821 fDigiScheme->Print(kFALSE);
822 else if (fVerbose > 2)
823 fDigiScheme->Print(kTRUE);
824 cout << "-I- " << fName << "::Init: "
825 << "STS digitisation scheme succesfully initialised" << endl;
826 cout << " Stations: " << fDigiScheme->GetNStations() << ", Sectors: " << fDigiScheme->GetNSectors()
827 << ", Channels: " << fDigiScheme->GetNChannels() << endl;
828 return kSUCCESS;
829 }
830
831 return kERROR;
832}
833// -------------------------------------------------------------------------
834
835// ----- Private method ReInit -----------------------------------------
837{
838
839 // Clear digitisation scheme
840 fDigiScheme->Clear();
841
842 // Build new digitisation scheme
843 if (fDigiScheme->Init(fGeoPar, fDigiPar))
844 return kSUCCESS;
845
846 InitStatus geoStatus = GetGeometry();
847 if (geoStatus != kSUCCESS) {
848 cout << "-E- " << GetName() << "::Init: Error in reading geometry!" << endl;
849 return geoStatus;
850 }
851
852 return kERROR;
853}
854// -------------------------------------------------------------------------
855
856// ----- Private method GetGeometry ------------------------------------
858{
859 cout << "-W- " << endl;
860 // Get target geometry
861 if (!fPassGeo) {
862 cout << "-W- " << GetName() << "::GetGeometry: No passive geometry!" << endl;
863 fTargetPos.SetXYZ(0., 0., 0.);
864 return kERROR;
865 }
866 TObjArray* passNodes = fPassGeo->GetGeoPassiveNodes();
867 if (!passNodes) {
868 cout << "-W- " << GetName() << "::GetGeometry: No passive node array" << endl;
869 fTargetPos.SetXYZ(0., 0., 0.);
870 return kERROR;
871 }
872 /* FairGeoNode* target = (FairGeoNode*) passNodes->FindObject("targ");
873 if ( ! target ) {
874 cout << "-E- " << GetName() << "::GetGeometry: No target node"
875 << endl;
876 fTargetPos.SetXYZ(0., 0., 0.);
877 return kERROR;
878 }
879 FairGeoVector targetPos = target->getLabTransform()->getTranslation();
880 FairGeoVector centerPos = target->getCenterPosition().getTranslation();
881 Double_t targetX = targetPos.X() + centerPos.X();
882 Double_t targetY = targetPos.Y() + centerPos.Y();
883 Double_t targetZ = targetPos.Z() + centerPos.Z();
884 fTargetPos.SetXYZ(targetX, targetY, targetZ);*/
885
886 // Get STS geometry
887 if (!fGeoPar) {
888 cout << "-W- " << GetName() << "::GetGeometry: No passive geometry!" << endl;
889 fNStations = 0;
890 return kERROR;
891 }
892 TObjArray* stsNodes = fGeoPar->GetGeoSensitiveNodes();
893 if (!stsNodes) {
894 cout << "-E- " << GetName() << "::GetGeometry: No STS node array" << endl;
895 fNStations = 0;
896 return kERROR;
897 }
898 Int_t tempNofStations = stsNodes->GetEntries();
899 cout << "Nodes in STS: " << tempNofStations << endl;
900
901 cout << "There are " << tempNofStations << " nodes" << (tempNofStations > 10 ? "!!!" : "") << endl;
902
903 TString geoNodeName;
904 fNStations = 0;
905 TString stationNames[1000];
906 for (Int_t ist = 0; ist < tempNofStations; ist++) {
907 FairGeoNode* stsNode = (FairGeoNode*)stsNodes->At(ist);
908 if (!stsNode) {
909 cout << "-W- CbmStsDigiScheme::Init: station#" << ist << " not found among sensitive nodes " << endl;
910 continue;
911 }
912 geoNodeName = stsNode->getName();
913 // TArrayD* params = stsNode->getParameters();
914
915 Bool_t stationKnown = kFALSE;
916 // check if the node belongs to some station, save the MCId and outer radius
917 for (Int_t ikst = 0; ikst < fNStations; ikst++)
918 if (geoNodeName.Contains(stationNames[ikst])) {
919 fStationNrFromMcId[stsNode->getMCid()] = ikst;
920 stationKnown = kTRUE;
921 }
922
923 if (stationKnown)
924 continue;
925
926 // if not known, register it and save MCId
927 fStationNrFromMcId[stsNode->getMCid()] = fNStations;
928
929 // it will work only if the node name is organized as:
930 // for station name is "stsstationXX", where XX is the station number (f.e. XX=07 for station number 7)
931 // for sector name is "stsstationXXanythingHereToDistinguishDifferentSectors"
932 geoNodeName.Remove(12, geoNodeName.Length() - 12);
933 stationNames[fNStations] = geoNodeName.Data();
934 fNStations++;
935
936 cout << "station #" << fNStations << " has MCID = " << stsNode->getMCid() << " and name " << stsNode->GetName()
937 << endl;
938
939 // fStationsMCId[fNStations] = stsNode->getMCid(); // not used
940 }
941 cout << "There are " << fNStations << " stations" << endl;
942
943 return kSUCCESS;
944}
945// -------------------------------------------------------------------------
946
947// ----- Private method Finish -----------------------------------------
949{
950
951 cout << endl;
952 cout << "============================================================" << endl;
953 cout << "===== " << GetName() << ": Run summary " << endl;
954 cout << "===== " << endl;
955 cout << "===== Good events : " << setw(6) << fNEvents << endl;
956 cout << "===== Failed events : " << setw(6) << fNEventsFailed << endl;
957 cout << "===== Average time : " << setprecision(4) << setw(8) << right << fTime / Double_t(fNEvents) << " s"
958 << endl;
959 cout << "===== " << endl;
960 cout << "===== Hits per event : " << fixed << setprecision(0) << fNHits / Double_t(fNEvents) << endl;
961 cout << setprecision(2);
962 cout << "===== Matched hits : " << fixed << setw(6) << right << fNMatched / fNHits * 100. << " %" << endl;
963 cout << "===== Distant hits : " << fixed << setw(6) << right << fNDistant / fNHits * 100. << " %" << endl;
964 cout << "===== Background hits : " << fixed << setw(6) << right << fNBackgrd / fNHits * 100. << " % " << endl;
965 cout << "============================================================" << endl;
966}
967// -------------------------------------------------------------------------
vector< Double_t > dist(vector< Double_t > qp, Double_t mu)
Definition BmnMath.cxx:869
int i
Definition P4_F32vec4.h:22
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,...)
R__EXTERN TGeoManager * gGeoManager
CbmStsCluster.h.
CbmStsDigiMatch.h.
Int_t GetRefIndex(Int_t i=0) const
Accessor to StsPoint indizes.
static CbmStsDigiScheme * Instance(int version=1)
virtual Int_t GetStationNr() const
Definition CbmStsHit.h:67
Int_t GetSectorNr() const
Definition CbmStsHit.h:68
Int_t GetDigi(Int_t iSide) const
Int_t fNEvents
Timer.
map< Double_t, Int_t >::iterator fIter
Int_t fNEventsFailed
Number of events with success.
virtual void SetParContainers()
Get parameter containers.
TClonesArray * fClusters
Array of CbmStsHit.
TClonesArray * fDigiMatches
Array of CbmStsDigi.
virtual ~CbmStsMatchHits()
Destructor.
TClonesArray * fDigis
Array of BmnSiliconPoint AZ-280322.
TClonesArray * fPointsSi
Array of CbmStsPoint.
virtual void Finish()
Run summary.
InitStatus GetGeometry()
TClonesArray * fHits
Array of CbmStsDigiMatch.
FairGeoPassivePar * fPassGeo
Total number of background hits.
virtual void Exec(Option_t *opt)
Execution.
CbmStsMatchHits()
Default constructor.
Double_t fNDistant
Total number of matched hits.
CbmStsDigiScheme * fDigiScheme
Digitisation parameter container.
CbmStsDigiPar * fDigiPar
Geometry parameter container.
Double_t fNMatched
Total number of hits.
Double_t fNHits
Total real time used for good events.
CbmGeoStsPar * fGeoPar
virtual void ExecReal(Option_t *opt)
Double_t fNBackgrd
Total number of displaced hits.
TClonesArray * fPoints
Digitisation scheme.
Int_t fStationNrFromMcId[10000]
Double_t fTime
Number of events with failure.
map< Double_t, Int_t > fCandMap
Map from candidate point to distance to hit.
virtual InitStatus Init()
Intialisation.
virtual InitStatus ReInit()
Reinitialisation.
Double_t GetY(Double_t z) const
Double_t GetX(Double_t z) const
Point coordinates at given z from linear extrapolation.
Double_t GetXIn() const
Accessors.
Definition CbmStsPoint.h:64
Double_t GetZIn() const
Definition CbmStsPoint.h:66
Double_t GetYIn() const
Definition CbmStsPoint.h:65
Int_t GetType() const
Int_t GetStationNr() const
Double_t GetZ(Int_t it=0)
const char * GetName() const override
Int_t GetEntries() const override
TObject * At(Int_t idx) const override
const char * Data() const
Double_t Sqrt(Double_t x)
Double_t Abs(Double_t d)