REST-for-Physics  v2.3
Rare Event Searches ToolKit for Physics
TRestGeant4Event.cxx
1
17
18#include "TRestGeant4Event.h"
19
20#include <TFrame.h>
21#include <TRestRun.h>
22#include <TRestStringHelper.h>
23#include <TRestTools.h>
24#include <TStyle.h>
25
26#include "TRestGeant4Metadata.h"
27
28using namespace std;
29
30ClassImp(TRestGeant4Event);
31
32TRestGeant4Event::TRestGeant4Event() {
33 fNVolumes = 0;
34 // TRestGeant4Event default constructor
35
36 Initialize();
37}
38
39TRestGeant4Event::~TRestGeant4Event() {
40 // TRestGeant4Event destructor
41}
42
45
46 fPrimaryParticleNames.clear();
47
48 fTracks.clear();
49
50 // ClearVolumes();
51 fXZHitGraph = nullptr;
52 fYZHitGraph = nullptr;
53 fXYHitGraph = nullptr;
54
55 fXZMultiGraph = nullptr;
56 fYZMultiGraph = nullptr;
57 fXYMultiGraph = nullptr;
58
59 fXYHisto = nullptr;
60 fYZHisto = nullptr;
61 fXZHisto = nullptr;
62
63 fXHisto = nullptr;
64 fYHisto = nullptr;
65 fZHisto = nullptr;
66
67 fPad = nullptr;
68
69 fLegend_XY = nullptr;
70 fLegend_XZ = nullptr;
71 fLegend_YZ = nullptr;
72
73 fTotalDepositedEnergy = 0;
74 fSensitiveVolumeEnergy = 0;
75
76 fMinX = 1e20;
77 fMaxX = -1e20;
78
79 fMinY = 1e20;
80 fMaxY = -1e20;
81
82 fMinZ = 1e20;
83 fMaxZ = -1e20;
84
85 fMinEnergy = 1e20;
86 fMaxEnergy = -1e20;
87}
88
89void TRestGeant4Event::AddActiveVolume(const string& volumeName) {
90 fNVolumes++;
91 fVolumeStored.push_back(1);
92 fVolumeStoredNames.push_back(volumeName);
93 fVolumeDepositedEnergy.push_back(0);
94}
95
96void TRestGeant4Event::ClearVolumes() {
97 fNVolumes = 0;
98 fVolumeStored.clear();
99 fVolumeStoredNames.clear();
100 fVolumeDepositedEnergy.clear();
101}
102
103void TRestGeant4Event::AddEnergyDepositToVolume(Int_t volID, Double_t eDep) {
104 fVolumeDepositedEnergy[volID] += eDep;
105}
106
107TVector3 TRestGeant4Event::GetMeanPositionInVolume(Int_t volID) const {
108 TVector3 pos;
109 Double_t eDep = 0;
110
111 for (unsigned int t = 0; t < GetNumberOfTracks(); t++) {
112 const auto tck = GetTrack(t);
113 if (tck.GetEnergyInVolume(volID) > 0) {
114 pos += tck.GetMeanPositionInVolume(volID) * tck.GetEnergyInVolume(volID);
115
116 eDep += tck.GetEnergyInVolume(volID);
117 }
118 }
119
120 if (eDep == 0) {
121 Double_t nan = TMath::QuietNaN();
122 return {nan, nan, nan};
123 }
124
125 pos = (1 / eDep) * pos;
126 return pos;
127}
128
136 TVector3 meanPos = this->GetMeanPositionInVolume(volID);
137
138 Double_t nan = TMath::QuietNaN();
139 if (meanPos == TVector3(nan, nan, nan)) return TVector3(nan, nan, nan);
140
141 TRestHits hitsInVolume = GetHitsInVolume(volID);
142
143 Double_t edep = 0;
144 TVector3 deviation = TVector3(0, 0, 0);
145
146 for (unsigned int n = 0; n < hitsInVolume.GetNumberOfHits(); n++) {
147 Double_t en = hitsInVolume.GetEnergy(n);
148 TVector3 diff = meanPos - hitsInVolume.GetPosition(n);
149 diff.SetXYZ(diff.X() * diff.X(), diff.Y() * diff.Y(), diff.Z() * diff.Z());
150
151 deviation = deviation + en * diff;
152
153 edep += en;
154 }
155 deviation = (1. / edep) * deviation;
156 return deviation;
157}
158
167 for (unsigned int t = 0; t < GetNumberOfTracks(); t++)
168 if (GetTrack(t).GetEnergyInVolume(volID) > 0) return GetTrack(t).GetFirstPositionInVolume(volID);
169
170 Double_t nan = TMath::QuietNaN();
171 return {nan, nan, nan};
172}
173
183TVector3 TRestGeant4Event::GetLastPositionInVolume(Int_t volID) const {
184 for (int t = GetNumberOfTracks() - 1; t >= 0; t--) {
185 if (GetTrack(t).GetEnergyInVolume(volID) > 0) {
186 return GetTrack(t).GetLastPositionInVolume(volID);
187 }
188 }
189 Double_t nan = TMath::QuietNaN();
190 return {nan, nan, nan};
191}
192
193TRestGeant4Track* TRestGeant4Event::GetTrackByID(Int_t trackID) const {
194 TRestGeant4Track* result = nullptr;
195 if (fTrackIDToTrackIndex.count(trackID) > 0) {
196 result = const_cast<TRestGeant4Track*>(&fTracks[fTrackIDToTrackIndex.at(trackID)]);
197 if (result == nullptr || result->GetTrackID() != trackID) {
198 cerr << "TRestGeant4Event::GetTrackByID - ERROR: trackIDToTrackIndex map is corrupted" << endl;
199 exit(1);
200 }
201 }
202 return result;
203}
204
210size_t TRestGeant4Event::GetNumberOfHits(Int_t volID) const {
211 size_t numberOfHits = 0;
212 for (const auto& track : fTracks) {
213 numberOfHits += track.GetNumberOfHits(volID);
214 }
215 return numberOfHits;
216}
217
224 size_t numberOfHits = 0;
225 for (const auto& track : fTracks) {
226 numberOfHits += track.GetNumberOfPhysicalHits(volID);
227 }
228 return numberOfHits;
229}
230
237 TRestHits hits;
238 for (unsigned int t = 0; t < GetNumberOfTracks(); t++) {
239 const auto& g4Hits = GetTrack(t).GetHits();
240 for (unsigned int n = 0; n < g4Hits.GetNumberOfHits(); n++) {
241 if (volID != -1 && g4Hits.GetVolumeId(n) != volID) continue;
242
243 Double_t x = g4Hits.GetX(n);
244 Double_t y = g4Hits.GetY(n);
245 Double_t z = g4Hits.GetZ(n);
246 Double_t en = g4Hits.GetEnergy(n);
247
248 hits.AddHit({x, y, z}, en);
249 }
250 }
251
252 return hits;
253}
254
255Int_t TRestGeant4Event::GetNumberOfTracksForParticle(const TString& particleName) const {
256 Int_t nTracks = 0;
257 for (const auto& track : fTracks) {
258 if (particleName.EqualTo(track.GetParticleName())) {
259 nTracks += 1;
260 }
261 }
262 return nTracks;
263}
264
265Double_t TRestGeant4Event::GetEnergyDepositedByParticle(const TString& particleName) const {
266 Double_t energy = 0;
267 for (const auto& track : fTracks) {
268 if (particleName.EqualTo(track.GetParticleName())) {
269 energy += track.GetTotalEnergy();
270 }
271 }
272 return energy;
273}
274
275void TRestGeant4Event::SetBoundaries(Double_t xMin, Double_t xMax, Double_t yMin, Double_t yMax,
276 Double_t zMin, Double_t zMax) {
277 SetBoundaries();
278
279 fMinX = xMin;
280 fMaxX = xMax;
281
282 fMinY = yMin;
283 fMaxY = yMax;
284
285 fMinZ = zMin;
286 fMaxZ = zMax;
287}
288
294 SetBoundaries();
295
296 Double_t dX = fMaxX - fMinX;
297 Double_t dY = fMaxY - fMinY;
298 Double_t dZ = fMaxZ - fMinZ;
299
300 return TMath::Sqrt(dX * dX + dY * dY + dZ * dZ);
301}
302
303void TRestGeant4Event::SetBoundaries() {
304 Double_t maxX = -1e10, minX = 1e10, maxZ = -1e10, minZ = 1e10, maxY = -1e10, minY = 1e10;
305 Double_t minEnergy = 1e10, maxEnergy = -1e10;
306
307 Int_t nTHits = 0;
308 for (unsigned int ntck = 0; ntck < this->GetNumberOfTracks(); ntck++) {
309 Int_t nHits = GetTrack(ntck).GetNumberOfHits();
310 nTHits += nHits;
311 const auto& hits = GetTrack(ntck).GetHits();
312
313 for (int nhit = 0; nhit < nHits; nhit++) {
314 Double_t x = hits.GetX(nhit);
315 Double_t y = hits.GetY(nhit);
316 Double_t z = hits.GetZ(nhit);
317
318 Double_t en = hits.GetEnergy(nhit);
319
320 if (en <= 0) continue;
321
322 if (x > maxX) maxX = x;
323 if (x < minX) minX = x;
324 if (y > maxY) maxY = y;
325 if (y < minY) minY = y;
326 if (z > maxZ) maxZ = z;
327 if (z < minZ) minZ = z;
328
329 if (en > maxEnergy) maxEnergy = en;
330 if (en < minEnergy) minEnergy = en;
331 }
332 }
333
334 fMinX = minX;
335 fMaxX = maxX;
336
337 fMinY = minY;
338 fMaxY = maxY;
339
340 fMinZ = minZ;
341 fMaxZ = maxZ;
342
343 fMaxEnergy = maxEnergy;
344 fMinEnergy = minEnergy;
345
346 fTotalHits = nTHits;
347}
348
349/* {{{ Get{XY,YZ,XZ}MultiGraph methods */
350TMultiGraph* TRestGeant4Event::GetXYMultiGraph(Int_t gridElement, vector<TString> pcsList,
351 Double_t minPointSize, Double_t maxPointSize) {
352 if (fXYHitGraph) {
353 delete[] fXYHitGraph;
354 fXYHitGraph = nullptr;
355 }
356 fXYHitGraph = new TGraph[fTotalHits];
357
358 fXYMultiGraph = new TMultiGraph();
359
360 if (fLegend_XY) {
361 delete fLegend_XY;
362 fLegend_XY = nullptr;
363 }
364
365 fLegend_XY = new TLegend(0.75, 0.75, 0.9, 0.85);
366
367 char title[256];
368 sprintf(title, "Event ID %d (XY)", this->GetID());
369 fPad->cd(gridElement)->DrawFrame(fMinX - 10, fMinY - 10, fMaxX + 10, fMaxY + 10, title);
370
371 Double_t m = 1, n = 0;
372 if (fMaxEnergy - fMinEnergy > 0) {
373 m = (maxPointSize - minPointSize) / (fMaxEnergy - fMinEnergy);
374 n = maxPointSize - m * fMaxEnergy;
375 }
376
377 for (unsigned int n = 0; n < fXYPcsMarker.size(); n++) delete fXYPcsMarker[n];
378 fXYPcsMarker.clear();
379
380 legendAdded.clear();
381 for (unsigned int p = 0; p < pcsList.size(); p++) legendAdded.push_back(0);
382
383 Int_t cnt = 0;
384 for (unsigned int ntck = 0; ntck < GetNumberOfTracks(); ntck++) {
385 const auto hits = GetTrack(ntck).GetHits();
386
387 EColor color = GetTrack(ntck).GetParticleColor();
388
389 for (unsigned int nhit = 0; nhit < hits.GetNumberOfHits(); nhit++) {
390 Double_t xPos = hits.GetX(nhit);
391 Double_t yPos = hits.GetY(nhit);
392 Double_t energy = hits.GetEnergy(nhit);
393
394 for (unsigned int p = 0; p < pcsList.size(); p++) {
395 if (GetTrack(ntck).GetProcessName(hits.GetProcess(nhit)) == pcsList[p]) {
396 TGraph* pcsGraph = new TGraph(1);
397
398 pcsGraph->SetPoint(0, xPos, yPos);
399 pcsGraph->SetMarkerColor(kBlack);
400 pcsGraph->SetMarkerSize(3);
401 pcsGraph->SetMarkerStyle(30 + p);
402
403 fXYPcsMarker.push_back(pcsGraph);
404
405 if (legendAdded[p] == 0) {
406 fLegend_XY->AddEntry(pcsGraph, GetTrack(ntck).GetProcessName(hits.GetProcess(nhit)),
407 "p");
408 legendAdded[p] = 1;
409 }
410 }
411 }
412
413 Double_t radius = m * energy + n;
414 if (fMaxEnergy - fMinEnergy <= 0) radius = 2.5;
415
416 fXYHitGraph[cnt].SetPoint(0, xPos, yPos);
417
418 fXYHitGraph[cnt].SetMarkerColor(color);
419 fXYHitGraph[cnt].SetMarkerSize(radius);
420 fXYHitGraph[cnt].SetMarkerStyle(20);
421
422 fXYMultiGraph->Add(&fXYHitGraph[cnt]);
423
424 cnt++;
425 }
426 }
427
428 fXYMultiGraph->GetXaxis()->SetTitle("X-axis (mm)");
429 fXYMultiGraph->GetXaxis()->SetTitleSize(1.25 * fXYMultiGraph->GetXaxis()->GetTitleSize());
430 fXYMultiGraph->GetXaxis()->SetTitleOffset(1.25);
431 fXYMultiGraph->GetXaxis()->SetLabelSize(1.25 * fXYMultiGraph->GetXaxis()->GetLabelSize());
432
433 fXYMultiGraph->GetYaxis()->SetTitle("Y-axis (mm)");
434 fXYMultiGraph->GetYaxis()->SetTitleSize(1.25 * fXYMultiGraph->GetYaxis()->GetTitleSize());
435 fXYMultiGraph->GetYaxis()->SetTitleOffset(1.75);
436 fXYMultiGraph->GetYaxis()->SetLabelSize(1.25 * fXYMultiGraph->GetYaxis()->GetLabelSize());
437 fPad->cd(gridElement);
438
439 return fXYMultiGraph;
440}
441
442TMultiGraph* TRestGeant4Event::GetYZMultiGraph(Int_t gridElement, vector<TString> pcsList,
443 Double_t minPointSize, Double_t maxPointSize) {
444 if (fYZHitGraph) {
445 delete[] fYZHitGraph;
446 fYZHitGraph = nullptr;
447 }
448 fYZHitGraph = new TGraph[fTotalHits];
449
450 fYZMultiGraph = new TMultiGraph();
451
452 if (fLegend_YZ) {
453 delete fLegend_YZ;
454 fLegend_YZ = nullptr;
455 }
456
457 fLegend_YZ = new TLegend(0.75, 0.75, 0.9, 0.85);
458
459 char title[256];
460 sprintf(title, "Event ID %d (YZ)", this->GetID());
461 fPad->cd(gridElement)->DrawFrame(fMinY - 10, fMinZ - 10, fMaxY + 10, fMaxZ + 10, title);
462
463 for (unsigned int n = 0; n < fYZPcsMarker.size(); n++) delete fYZPcsMarker[n];
464 fYZPcsMarker.clear();
465
466 Double_t m = 1, n = 0;
467 if (fMaxEnergy - fMinEnergy > 0) {
468 m = (maxPointSize - minPointSize) / (fMaxEnergy - fMinEnergy);
469 n = maxPointSize - m * fMaxEnergy;
470 }
471
472 legendAdded.clear();
473 for (unsigned int p = 0; p < pcsList.size(); p++) legendAdded.push_back(0);
474
475 Int_t cnt = 0;
476 for (unsigned int ntck = 0; ntck < GetNumberOfTracks(); ntck++) {
477 const auto& hits = GetTrack(ntck).GetHits();
478
479 EColor color = GetTrack(ntck).GetParticleColor();
480
481 for (unsigned int nhit = 0; nhit < hits.GetNumberOfHits(); nhit++) {
482 Double_t yPos = hits.GetY(nhit);
483 Double_t zPos = hits.GetZ(nhit);
484 Double_t energy = hits.GetEnergy(nhit);
485
486 for (unsigned int p = 0; p < pcsList.size(); p++) {
487 if (GetTrack(ntck).GetProcessName(hits.GetProcess(nhit)) == pcsList[p]) {
488 TGraph* pcsGraph = new TGraph(1);
489
490 pcsGraph->SetPoint(0, yPos, zPos);
491 pcsGraph->SetMarkerColor(kBlack);
492 pcsGraph->SetMarkerSize(3);
493 pcsGraph->SetMarkerStyle(30 + p);
494
495 fYZPcsMarker.push_back(pcsGraph);
496
497 if (legendAdded[p] == 0) {
498 fLegend_YZ->AddEntry(pcsGraph, GetTrack(ntck).GetProcessName(hits.GetProcess(nhit)),
499 "p");
500 legendAdded[p] = 1;
501 }
502 }
503 }
504
505 Double_t radius = m * energy + n;
506 if (fMaxEnergy - fMinEnergy <= 0) radius = 2.5;
507
508 fYZHitGraph[cnt].SetPoint(0, yPos, zPos);
509
510 fYZHitGraph[cnt].SetMarkerColor(color);
511 fYZHitGraph[cnt].SetMarkerSize(radius);
512 fYZHitGraph[cnt].SetMarkerStyle(20);
513
514 fYZMultiGraph->Add(&fYZHitGraph[cnt]);
515
516 cnt++;
517 }
518 }
519
520 fYZMultiGraph->GetXaxis()->SetTitle("Y-axis (mm)");
521 fYZMultiGraph->GetXaxis()->SetTitleSize(1.25 * fYZMultiGraph->GetXaxis()->GetTitleSize());
522 fYZMultiGraph->GetXaxis()->SetTitleOffset(1.25);
523 fYZMultiGraph->GetXaxis()->SetLabelSize(1.25 * fYZMultiGraph->GetXaxis()->GetLabelSize());
524
525 fYZMultiGraph->GetYaxis()->SetTitle("Z-axis (mm)");
526 fYZMultiGraph->GetYaxis()->SetTitleSize(1.25 * fYZMultiGraph->GetYaxis()->GetTitleSize());
527 fYZMultiGraph->GetYaxis()->SetTitleOffset(1.75);
528 fYZMultiGraph->GetYaxis()->SetLabelSize(1.25 * fYZMultiGraph->GetYaxis()->GetLabelSize());
529 fPad->cd(gridElement);
530
531 return fYZMultiGraph;
532}
533
534TMultiGraph* TRestGeant4Event::GetXZMultiGraph(Int_t gridElement, vector<TString> pcsList,
535 Double_t minPointSize, Double_t maxPointSize) {
536 if (fXZHitGraph) {
537 delete[] fXZHitGraph;
538 fXZHitGraph = nullptr;
539 }
540 fXZHitGraph = new TGraph[fTotalHits];
541
542 fXZMultiGraph = new TMultiGraph();
543
544 if (fLegend_XZ) {
545 delete fLegend_XZ;
546 fLegend_XZ = nullptr;
547 }
548
549 fLegend_XZ = new TLegend(0.75, 0.75, 0.9, 0.85);
550
551 char title[256];
552 sprintf(title, "Event ID %d (XZ)", this->GetID());
553 fPad->cd(gridElement)->DrawFrame(fMinX - 10, fMinZ - 10, fMaxX + 10, fMaxZ + 10, title);
554
555 for (unsigned int n = 0; n < fXZPcsMarker.size(); n++) delete fXZPcsMarker[n];
556 fXZPcsMarker.clear();
557
558 Double_t m = 1, n = 0;
559 if (fMaxEnergy - fMinEnergy > 0) {
560 m = (maxPointSize - minPointSize) / (fMaxEnergy - fMinEnergy);
561 n = maxPointSize - m * fMaxEnergy;
562 }
563
564 legendAdded.clear();
565 for (unsigned int p = 0; p < pcsList.size(); p++) legendAdded.push_back(0);
566
567 Int_t cnt = 0;
568 for (unsigned int ntck = 0; ntck < GetNumberOfTracks(); ntck++) {
569 const auto& hits = GetTrack(ntck).GetHits();
570
571 EColor color = GetTrack(ntck).GetParticleColor();
572
573 for (unsigned int nhit = 0; nhit < hits.GetNumberOfHits(); nhit++) {
574 Double_t xPos = hits.GetX(nhit);
575 Double_t zPos = hits.GetZ(nhit);
576 Double_t energy = hits.GetEnergy(nhit);
577
578 for (unsigned int p = 0; p < pcsList.size(); p++) {
579 if (GetTrack(ntck).GetProcessName(hits.GetProcess(nhit)) == pcsList[p]) {
580 TGraph* pcsGraph = new TGraph(1);
581
582 pcsGraph->SetPoint(0, xPos, zPos);
583 pcsGraph->SetMarkerColor(kBlack);
584 pcsGraph->SetMarkerSize(3);
585 pcsGraph->SetMarkerStyle(30 + p);
586
587 fXZPcsMarker.push_back(pcsGraph);
588
589 if (legendAdded[p] == 0) {
590 fLegend_XZ->AddEntry(pcsGraph, GetTrack(ntck).GetProcessName(hits.GetProcess(nhit)),
591 "p");
592 legendAdded[p] = 1;
593 }
594 }
595 }
596
597 Double_t radius = m * energy + n;
598 if (fMaxEnergy - fMinEnergy <= 0) radius = 2.5;
599
600 fXZHitGraph[cnt].SetPoint(0, xPos, zPos);
601
602 fXZHitGraph[cnt].SetMarkerColor(color);
603 fXZHitGraph[cnt].SetMarkerSize(radius);
604 fXZHitGraph[cnt].SetMarkerStyle(20);
605
606 fXZMultiGraph->Add(&fXZHitGraph[cnt]);
607
608 cnt++;
609 }
610 }
611
612 fXZMultiGraph->GetXaxis()->SetTitle("X-axis (mm)");
613 fXZMultiGraph->GetXaxis()->SetTitleOffset(1.25);
614 fXZMultiGraph->GetXaxis()->SetTitleSize(1.25 * fXZMultiGraph->GetXaxis()->GetTitleSize());
615 fXZMultiGraph->GetXaxis()->SetLabelSize(1.25 * fXZMultiGraph->GetXaxis()->GetLabelSize());
616
617 fXZMultiGraph->GetYaxis()->SetTitle("Z-axis (mm)");
618 fXZMultiGraph->GetYaxis()->SetTitleOffset(1.75);
619 fXZMultiGraph->GetYaxis()->SetTitleSize(1.25 * fXZMultiGraph->GetYaxis()->GetTitleSize());
620 fXZMultiGraph->GetYaxis()->SetLabelSize(1.25 * fXZMultiGraph->GetYaxis()->GetLabelSize());
621 fPad->cd(gridElement);
622
623 return fXZMultiGraph;
624}
625/* }}} */
626
627/* {{{ Get{XY,YZ,XZ}Histogram methods */
628TH2F* TRestGeant4Event::GetXYHistogram(Int_t gridElement, vector<TString> optList) {
629 if (fXYHisto) {
630 delete fXYHisto;
631 fXYHisto = nullptr;
632 }
633
634 Bool_t stats = false;
635 Double_t pitch = 3;
636 for (unsigned int n = 0; n < optList.size(); n++) {
637 if (optList[n].Contains("binSize=")) {
638 TString pitchStr = optList[n].Remove(0, 8);
639 pitch = stod((string)pitchStr);
640 }
641
642 if (optList[n].Contains("stats")) stats = true;
643 }
644
645 Int_t nBinsX = (fMaxX - fMinX + 20) / pitch;
646 Int_t nBinsY = (fMaxY - fMinY + 20) / pitch;
647
648 fXYHisto = new TH2F("XY", "", nBinsX, fMinX - 10, fMinX + pitch * nBinsX, nBinsY, fMinY - 10,
649 fMinY + pitch * nBinsY);
650
651 for (unsigned int ntck = 0; ntck < GetNumberOfTracks(); ntck++) {
652 const auto& hits = GetTrack(ntck).GetHits();
653
654 for (unsigned int nhit = 0; nhit < hits.GetNumberOfHits(); nhit++) {
655 Double_t xPos = hits.GetX(nhit);
656 Double_t yPos = hits.GetY(nhit);
657 Double_t energy = hits.GetEnergy(nhit);
658
659 fXYHisto->Fill(xPos, yPos, energy);
660 }
661 }
662
663 TStyle style;
664 style.SetPalette(1);
665 style.SetOptStat(1001111);
666
667 fXYHisto->SetStats(stats);
668
669 char title[256];
670 sprintf(title, "Event ID %d (XY)", this->GetID());
671 fXYHisto->SetTitle(title);
672
673 fXYHisto->GetXaxis()->SetTitle("X-axis (mm)");
674 fXYHisto->GetXaxis()->SetTitleOffset(1.25);
675 fXYHisto->GetXaxis()->SetTitleSize(1.25 * fXYHisto->GetXaxis()->GetTitleSize());
676 fXYHisto->GetXaxis()->SetLabelSize(1.25 * fXYHisto->GetXaxis()->GetLabelSize());
677
678 fXYHisto->GetYaxis()->SetTitle("Y-axis (mm)");
679 fXYHisto->GetYaxis()->SetTitleOffset(1.75);
680 fXYHisto->GetYaxis()->SetTitleSize(1.25 * fXYHisto->GetYaxis()->GetTitleSize());
681 fXYHisto->GetYaxis()->SetLabelSize(1.25 * fXYHisto->GetYaxis()->GetLabelSize());
682 fPad->cd(gridElement);
683
684 return fXYHisto;
685}
686
687TH2F* TRestGeant4Event::GetXZHistogram(Int_t gridElement, vector<TString> optList) {
688 if (fXZHisto) {
689 delete fXZHisto;
690 fXZHisto = nullptr;
691 }
692
693 Bool_t stats = false;
694 Double_t pitch = 3;
695 for (unsigned int n = 0; n < optList.size(); n++) {
696 if (optList[n].Contains("binSize=")) {
697 TString pitchStr = optList[n].Remove(0, 8);
698 pitch = stod((string)pitchStr);
699 }
700
701 if (optList[n].Contains("stats")) stats = true;
702 }
703
704 Int_t nBinsX = (fMaxX - fMinX + 20) / pitch;
705 Int_t nBinsZ = (fMaxZ - fMinZ + 20) / pitch;
706
707 fXZHisto = new TH2F("XZ", "", nBinsX, fMinX - 10, fMinX + pitch * nBinsX, nBinsZ, fMinZ - 10,
708 fMinZ + pitch * nBinsZ);
709
710 for (unsigned int ntck = 0; ntck < GetNumberOfTracks(); ntck++) {
711 const auto& hits = GetTrack(ntck).GetHits();
712
713 for (unsigned int nhit = 0; nhit < hits.GetNumberOfHits(); nhit++) {
714 Double_t xPos = hits.GetX(nhit);
715 Double_t zPos = hits.GetZ(nhit);
716 Double_t energy = hits.GetEnergy(nhit);
717
718 fXZHisto->Fill(xPos, zPos, energy);
719 }
720 }
721
722 TStyle style;
723 style.SetPalette(1);
724 style.SetOptStat(1001111);
725
726 fXZHisto->SetStats(stats);
727
728 char title[256];
729 sprintf(title, "Event ID %d (XZ)", this->GetID());
730 fXZHisto->SetTitle(title);
731
732 fXZHisto->GetXaxis()->SetTitle("X-axis (mm)");
733 fXZHisto->GetXaxis()->SetTitleOffset(1.25);
734 fXZHisto->GetXaxis()->SetTitleSize(1.25 * fXZHisto->GetXaxis()->GetTitleSize());
735 fXZHisto->GetXaxis()->SetLabelSize(1.25 * fXZHisto->GetXaxis()->GetLabelSize());
736
737 fXZHisto->GetYaxis()->SetTitle("Z-axis (mm)");
738 fXZHisto->GetYaxis()->SetTitleOffset(1.75);
739 fXZHisto->GetYaxis()->SetTitleSize(1.25 * fXZHisto->GetYaxis()->GetTitleSize());
740 fXZHisto->GetYaxis()->SetLabelSize(1.25 * fXZHisto->GetYaxis()->GetLabelSize());
741 fPad->cd(gridElement);
742
743 return fXZHisto;
744}
745
746TH2F* TRestGeant4Event::GetYZHistogram(Int_t gridElement, vector<TString> optList) {
747 if (fYZHisto) {
748 delete fYZHisto;
749 fYZHisto = nullptr;
750 }
751
752 Bool_t stats;
753 Double_t pitch = 3;
754 for (unsigned int n = 0; n < optList.size(); n++) {
755 if (optList[n].Contains("binSize=")) {
756 TString pitchStr = optList[n].Remove(0, 8);
757 pitch = stod((string)pitchStr);
758 }
759
760 if (optList[n].Contains("stats")) stats = true;
761 }
762
763 Int_t nBinsY = (fMaxY - fMinY + 20) / pitch;
764 Int_t nBinsZ = (fMaxZ - fMinZ + 20) / pitch;
765
766 fYZHisto = new TH2F("YZ", "", nBinsY, fMinY - 10, fMinY + pitch * nBinsY, nBinsZ, fMinZ - 10,
767 fMinZ + pitch * nBinsZ);
768
769 for (unsigned int ntck = 0; ntck < GetNumberOfTracks(); ntck++) {
770 const auto& hits = GetTrack(ntck).GetHits();
771
772 for (unsigned int nhit = 0; nhit < hits.GetNumberOfHits(); nhit++) {
773 Double_t yPos = hits.GetY(nhit);
774 Double_t zPos = hits.GetZ(nhit);
775 Double_t energy = hits.GetEnergy(nhit);
776
777 fYZHisto->Fill(yPos, zPos, energy);
778 }
779 }
780
781 TStyle style;
782 style.SetPalette(1);
783 style.SetOptStat(1001111); // Not Working :(
784
785 fYZHisto->SetStats(stats);
786
787 char title[256];
788 sprintf(title, "Event ID %d (YZ)", this->GetID());
789 fYZHisto->SetTitle(title);
790
791 fYZHisto->GetXaxis()->SetTitle("Y-axis (mm)");
792 fYZHisto->GetXaxis()->SetTitleOffset(1.25);
793 fYZHisto->GetXaxis()->SetTitleSize(1.25 * fYZHisto->GetXaxis()->GetTitleSize());
794 fYZHisto->GetXaxis()->SetLabelSize(1.25 * fYZHisto->GetXaxis()->GetLabelSize());
795
796 fYZHisto->GetYaxis()->SetTitle("Z-axis (mm)");
797 fYZHisto->GetYaxis()->SetTitleOffset(1.75);
798 fYZHisto->GetYaxis()->SetTitleSize(1.25 * fYZHisto->GetYaxis()->GetTitleSize());
799 fYZHisto->GetYaxis()->SetLabelSize(1.25 * fYZHisto->GetYaxis()->GetLabelSize());
800 fPad->cd(gridElement);
801
802 return fYZHisto;
803}
804/* }}} */
805
806TH1D* TRestGeant4Event::GetXHistogram(Int_t gridElement, vector<TString> optList) {
807 if (fXHisto) {
808 delete fXHisto;
809 fXHisto = nullptr;
810 }
811
812 Double_t pitch = 3;
813 Bool_t stats = false;
814 for (unsigned int n = 0; n < optList.size(); n++) {
815 if (optList[n].Contains("binSize=")) {
816 TString pitchStr = optList[n].Remove(0, 8);
817 pitch = stod((string)pitchStr);
818 }
819
820 if (optList[n].Contains("stats")) stats = true;
821 }
822
823 Int_t nBinsX = (fMaxX - fMinX + 20) / pitch;
824
825 fXHisto = new TH1D("X", "", nBinsX, fMinX - 10, fMinX + pitch * nBinsX);
826
827 for (unsigned int ntck = 0; ntck < GetNumberOfTracks(); ntck++) {
828 const auto& hits = GetTrack(ntck).GetHits();
829
830 for (unsigned int nhit = 0; nhit < hits.GetNumberOfHits(); nhit++) {
831 Double_t xPos = hits.GetX(nhit);
832 Double_t energy = hits.GetEnergy(nhit);
833
834 fXHisto->Fill(xPos, energy);
835 }
836 }
837
838 TStyle style;
839 style.SetPalette(1);
840
841 fXHisto->SetStats(stats);
842
843 char title[256];
844 sprintf(title, "Event ID %d (X)", this->GetID());
845 fXHisto->SetTitle(title);
846
847 fXHisto->GetXaxis()->SetTitle("X-axis (mm)");
848 fXHisto->GetXaxis()->SetTitleOffset(1.25);
849 fXHisto->GetXaxis()->SetTitleSize(1.25 * fXHisto->GetXaxis()->GetTitleSize());
850 fXHisto->GetXaxis()->SetLabelSize(1.25 * fXHisto->GetXaxis()->GetLabelSize());
851
852 fPad->cd(gridElement);
853
854 return fXHisto;
855}
856
857TH1D* TRestGeant4Event::GetZHistogram(Int_t gridElement, vector<TString> optList) {
858 if (fZHisto) {
859 delete fZHisto;
860 fZHisto = nullptr;
861 }
862
863 Double_t pitch = 3;
864 Bool_t stats = false;
865 for (unsigned int n = 0; n < optList.size(); n++) {
866 if (optList[n].Contains("binSize=")) {
867 TString pitchStr = optList[n].Remove(0, 8);
868 pitch = stod((string)pitchStr);
869 }
870
871 if (optList[n].Contains("stats")) stats = true;
872 }
873
874 Int_t nBinsZ = (fMaxZ - fMinZ + 20) / pitch;
875
876 fZHisto = new TH1D("Z", "", nBinsZ, fMinZ - 10, fMinZ + pitch * nBinsZ);
877
878 for (unsigned int ntck = 0; ntck < GetNumberOfTracks(); ntck++) {
879 const auto& hits = GetTrack(ntck).GetHits();
880
881 for (unsigned int nhit = 0; nhit < hits.GetNumberOfHits(); nhit++) {
882 Double_t zPos = hits.GetZ(nhit);
883 Double_t energy = hits.GetEnergy(nhit);
884
885 fZHisto->Fill(zPos, energy);
886 }
887 }
888
889 TStyle style;
890 style.SetPalette(1);
891
892 fZHisto->SetStats(stats);
893
894 char title[256];
895 sprintf(title, "Event ID %d (Z)", this->GetID());
896 fZHisto->SetTitle(title);
897
898 fZHisto->GetXaxis()->SetTitle("Z-axis (mm)");
899 fZHisto->GetXaxis()->SetTitleOffset(1.25);
900 fZHisto->GetXaxis()->SetTitleSize(1.25 * fZHisto->GetXaxis()->GetTitleSize());
901 fZHisto->GetXaxis()->SetLabelSize(1.25 * fZHisto->GetXaxis()->GetLabelSize());
902
903 fPad->cd(gridElement);
904
905 return fZHisto;
906}
907
908TH1D* TRestGeant4Event::GetYHistogram(Int_t gridElement, vector<TString> optList) {
909 if (fYHisto) {
910 delete fYHisto;
911 fYHisto = nullptr;
912 }
913
914 Double_t pitch = 3;
915 Bool_t stats = false;
916 for (unsigned int n = 0; n < optList.size(); n++) {
917 if (optList[n].Contains("binSize=")) {
918 TString pitchStr = optList[n].Remove(0, 8);
919 pitch = stod((string)pitchStr);
920 }
921
922 if (optList[n].Contains("stats")) stats = true;
923 }
924
925 Int_t nBinsY = (fMaxY - fMinY + 20) / pitch;
926
927 fYHisto = new TH1D("Y", "", nBinsY, fMinY - 10, fMinY + pitch * nBinsY);
928
929 for (unsigned int ntck = 0; ntck < GetNumberOfTracks(); ntck++) {
930 const auto& hits = GetTrack(ntck).GetHits();
931
932 for (unsigned int nhit = 0; nhit < hits.GetNumberOfHits(); nhit++) {
933 Double_t yPos = hits.GetY(nhit);
934 Double_t energy = hits.GetEnergy(nhit);
935
936 fYHisto->Fill(yPos, energy);
937 }
938 }
939
940 TStyle style;
941 style.SetPalette(1);
942
943 fYHisto->SetStats(stats);
944
945 char title[256];
946 sprintf(title, "Event ID %d (Y)", this->GetID());
947 fYHisto->SetTitle(title);
948
949 fYHisto->GetXaxis()->SetTitle("Y-axis (mm)");
950 fYHisto->GetXaxis()->SetTitleOffset(1.25);
951 fYHisto->GetXaxis()->SetTitleSize(1.25 * fYHisto->GetXaxis()->GetTitleSize());
952 fYHisto->GetXaxis()->SetLabelSize(1.25 * fYHisto->GetXaxis()->GetLabelSize());
953
954 fPad->cd(gridElement);
955
956 return fYHisto;
957}
958
1022TPad* TRestGeant4Event::DrawEvent(const TString& option, Bool_t autoBoundaries) {
1023 vector<TString> optList = Vector_cast<string, TString>(TRestTools::GetOptions((string)option));
1024
1025 if (autoBoundaries) SetBoundaries();
1026
1027 // If no option is given. This is the default
1028 if (optList.size() == 0) {
1029 optList.push_back("graphXZ");
1030 optList.push_back("graphYZ");
1031 optList.push_back("histXZ(Cont0,colz)");
1032 optList.push_back("histYZ(Cont0,colz)");
1033 }
1034
1035 for (unsigned int n = 0; n < optList.size(); n++) {
1036 if (optList[n] == "print") this->PrintEvent();
1037 }
1038
1039 optList.erase(remove(optList.begin(), optList.end(), "print"), optList.end());
1040
1041 unsigned int nPlots = optList.size();
1042
1043 RestartPad(nPlots);
1044
1045 for (unsigned int n = 0; n < nPlots; n++) {
1046 fPad->cd(n + 1);
1047
1048 string optionStr = (string)optList[n];
1049
1050 /* {{{ Retreiving drawEventType argument. The word key before we find ( or [
1051 * character. */
1052 TString drawEventType = optList[n];
1053 size_t startPos = optionStr.find("(");
1054 if (startPos == string::npos) startPos = optionStr.find("[");
1055
1056 if (startPos != string::npos) drawEventType = optList[n](0, startPos);
1057 /* }}} */
1058
1059 /* {{{ Retrieving drawOption argument. Inside normal brackets ().
1060 * We do not separate the different fields we take the full string. */
1061 string drawOption = "";
1062 size_t endPos = optionStr.find(")");
1063 if (endPos != string::npos) {
1064 TString drawOptionTmp = optList[n](startPos + 1, endPos - startPos - 1);
1065
1066 drawOption = (string)drawOptionTmp;
1067 size_t pos = 0;
1068 while ((pos = drawOption.find(",", pos)) != string::npos) {
1069 drawOption.replace(pos, 1, ":");
1070 pos = pos + 1;
1071 }
1072 }
1073 /* }}} */
1074
1075 /* {{{ Retrieving optList. Inside squared brackets [] and separated by colon
1076 * [Field1,Field2] */
1077 vector<TString> optList_2;
1078
1079 startPos = optionStr.find("[");
1080 endPos = optionStr.find("]");
1081
1082 if (endPos != string::npos) {
1083 TString tmpStr = optList[n](startPos + 1, endPos - startPos - 1);
1084 optList_2 = Vector_cast<string, TString>(Split((string)tmpStr, ","));
1085 }
1086 /* }}} */
1087
1088 if (drawEventType == "graphXZ") {
1089 GetXZMultiGraph(n + 1, optList_2)->Draw("P");
1090
1091 // Markers for physical processes have been already assigned in
1092 // GetXYMultigraph method
1093 if (fXZPcsMarker.size() > 0) fLegend_XZ->Draw("same");
1094
1095 for (unsigned int m = 0; m < fXZPcsMarker.size(); m++) fXZPcsMarker[m]->Draw("P");
1096 } else if (drawEventType == "graphYZ") {
1097 GetYZMultiGraph(n + 1, optList_2)->Draw("P");
1098
1099 if (fYZPcsMarker.size() > 0) fLegend_YZ->Draw("same");
1100
1101 for (unsigned int m = 0; m < fYZPcsMarker.size(); m++) fYZPcsMarker[m]->Draw("P");
1102 } else if (drawEventType == "graphXY") {
1103 GetXYMultiGraph(n + 1, optList_2)->Draw("P");
1104
1105 if (fXYPcsMarker.size() > 0) fLegend_XY->Draw("same");
1106
1107 for (unsigned int m = 0; m < fXYPcsMarker.size(); m++) fXYPcsMarker[m]->Draw("P");
1108 } else if (drawEventType == "histXY") {
1109 GetXYHistogram(n + 1, optList_2)->Draw((TString)drawOption);
1110 } else if (drawEventType == "histXZ") {
1111 GetXZHistogram(n + 1, optList_2)->Draw((TString)drawOption);
1112 } else if (drawEventType == "histYZ") {
1113 GetYZHistogram(n + 1, optList_2)->Draw((TString)drawOption);
1114 } else if (drawEventType == "histX") {
1115 GetXHistogram(n + 1, optList_2)->Draw((TString)drawOption);
1116 } else if (drawEventType == "histY") {
1117 GetYHistogram(n + 1, optList_2)->Draw((TString)drawOption);
1118 } else if (drawEventType == "histZ") {
1119 GetZHistogram(n + 1, optList_2)->Draw((TString)drawOption);
1120 }
1121 }
1122
1123 return fPad;
1124}
1126 cout << "Number of active volumes : " << GetNumberOfActiveVolumes() << endl;
1127 for (unsigned int i = 0; i < fVolumeStoredNames.size(); i++) {
1128 if (isVolumeStored(i)) {
1129 cout << "Active volume " << i << ":" << fVolumeStoredNames[i] << " has been stored." << endl;
1130 cout << "Total energy deposit in volume " << i << ":" << fVolumeStoredNames[i] << " : "
1131 << fVolumeDepositedEnergy[i] << " keV" << endl;
1132 } else
1133 cout << "Active volume " << i << ":" << fVolumeStoredNames[i] << " has not been stored" << endl;
1134 }
1135}
1136
1137void TRestGeant4Event::PrintEvent(int maxTracks, int maxHits) const {
1139
1140 cout << "- Total deposited energy: " << ToEnergyString(fTotalDepositedEnergy) << endl;
1141 cout << "- Sensitive detectors total energy: " << ToEnergyString(fSensitiveVolumeEnergy) << endl;
1142
1143 cout << "- Primary source position: " << VectorToString(fPrimaryPosition) << " mm" << endl;
1144
1145 for (unsigned int i = 0; i < GetNumberOfPrimaries(); i++) {
1146 const char* sourceNumberString =
1147 GetNumberOfPrimaries() <= 1 ? ""
1148 : TString::Format(" %d of %zu", i + 1, GetNumberOfPrimaries()).Data();
1149 cout << " - Source" << sourceNumberString << " primary particle: " << fPrimaryParticleNames[i]
1150 << endl;
1151 cout << " Direction: " << VectorToString(fPrimaryDirections[i]) << endl;
1152 cout << " Energy: " << ToEnergyString(fPrimaryEnergies[i]) << endl;
1153 }
1154
1155 cout << endl;
1156 cout << "Total number of tracks: " << GetNumberOfTracks() << endl;
1157
1158 int nTracks = GetNumberOfTracks();
1159 if (maxTracks > 0 && (unsigned int)maxTracks < GetNumberOfTracks()) {
1160 nTracks = min(maxTracks, int(GetNumberOfTracks()));
1161 cout << "Printing only the first " << nTracks << " tracks" << endl;
1162 }
1163
1164 for (int i = 0; i < nTracks; i++) {
1165 GetTrack(i).PrintTrack(maxHits);
1166 }
1167}
1168
1169void TRestGeant4Event::PrintEventFilterVolumes(const std::set<std::string>& volumeNames) const {
1171
1172 cout << "- Total deposited energy: " << ToEnergyString(fTotalDepositedEnergy) << endl;
1173 cout << "- Sensitive detectors total energy: " << ToEnergyString(fSensitiveVolumeEnergy) << endl;
1174
1175 cout << "- Primary source position: " << VectorToString(fPrimaryPosition) << " mm" << endl;
1176
1177 for (unsigned int i = 0; i < GetNumberOfPrimaries(); i++) {
1178 const char* sourceNumberString =
1179 GetNumberOfPrimaries() <= 1 ? ""
1180 : TString::Format(" %d of %zu", i + 1, GetNumberOfPrimaries()).Data();
1181 cout << " - Source" << sourceNumberString << " primary particle: " << fPrimaryParticleNames[i]
1182 << endl;
1183 cout << " Direction: " << VectorToString(fPrimaryDirections[i]) << endl;
1184 cout << " Energy: " << ToEnergyString(fPrimaryEnergies[i]) << endl;
1185 }
1186
1187 cout << endl;
1188 cout << "Total number of tracks: " << GetNumberOfTracks() << endl;
1189
1190 int nTracks = GetNumberOfTracks();
1191 for (int i = 0; i < nTracks; i++) {
1192 GetTrack(i).PrintTrackFilterVolumes(volumeNames);
1193 }
1194}
1195
1196Bool_t TRestGeant4Event::ContainsProcessInVolume(Int_t processID, Int_t volumeID) const {
1197 for (const auto& track : fTracks) {
1198 if (track.ContainsProcessInVolume(processID, volumeID)) {
1199 return true;
1200 }
1201 }
1202 return false;
1203}
1204
1205Bool_t TRestGeant4Event::ContainsProcessInVolume(const TString& processName, Int_t volumeID) const {
1206 const TRestGeant4Metadata* metadata = GetGeant4Metadata();
1207 if (metadata == nullptr) {
1208 return false;
1209 }
1210 const auto& processID = metadata->GetGeant4PhysicsInfo().GetProcessID(processName);
1211 for (const auto& track : fTracks) {
1212 if (track.ContainsProcessInVolume(processID, volumeID)) {
1213 return true;
1214 }
1215 }
1216 return false;
1217}
1218
1219Bool_t TRestGeant4Event::ContainsParticle(const TString& particleName) const {
1220 for (const auto& track : fTracks) {
1221 if (track.GetParticleName() == particleName) {
1222 return true;
1223 }
1224 }
1225 return false;
1226}
1227
1228Bool_t TRestGeant4Event::ContainsParticleInVolume(const TString& particleName, Int_t volumeID) const {
1229 for (const auto& track : fTracks) {
1230 if (track.GetParticleName() != particleName) {
1231 continue;
1232 }
1233 if (track.GetHits().GetNumberOfHitsInVolume(volumeID) > 0) {
1234 return true;
1235 }
1236 }
1237 return false;
1238}
1239
1240const TRestGeant4Metadata* TRestGeant4Event::GetGeant4Metadata() const {
1241 if (fRun == nullptr) {
1242 RESTError << "TRestGeant4Event::GetGeant4Metadata: fRun is nullptr" << RESTendl;
1243 return nullptr;
1244 }
1245 return dynamic_cast<TRestGeant4Metadata*>(fRun->GetMetadataClass("TRestGeant4Metadata"));
1246}
1247
1250 /*
1251 This introduces overhead to event loading, but hopefully its small enough.
1252 If this is a problem, we could rework this approach
1253 */
1254 for (auto& track : fTracks) {
1255 track.SetEvent(this);
1256 track.fHits.SetTrack(&track);
1257 track.fHits.SetEvent(this);
1258 }
1259}
1260
1261set<string> TRestGeant4Event::GetUniqueParticles() const {
1262 set<string> result;
1263 for (const auto& track : fTracks) {
1264 result.insert(track.GetParticleName().Data());
1265 }
1266 return result;
1267}
1268
1269map<string, map<string, double>> TRestGeant4Event::GetEnergyInVolumePerProcessMap() const {
1270 map<string, map<string, double>> result;
1271 for (const auto& [volume, particleProcessMap] : fEnergyInVolumePerParticlePerProcess) {
1272 for (const auto& [particle, processMap] : particleProcessMap) {
1273 for (const auto& [process, energy] : processMap) {
1274 result[volume][process] += energy;
1275 }
1276 }
1277 }
1278 return result;
1279}
1280
1281map<string, map<string, double>> TRestGeant4Event::GetEnergyInVolumePerParticleMap() const {
1282 map<string, map<string, double>> result;
1283 for (const auto& [volume, particleProcessMap] : fEnergyInVolumePerParticlePerProcess) {
1284 for (const auto& [particle, processMap] : particleProcessMap) {
1285 for (const auto& [process, energy] : processMap) {
1286 result[volume][particle] += energy;
1287 }
1288 }
1289 }
1290 return result;
1291}
1292
1293map<string, double> TRestGeant4Event::GetEnergyPerProcessMap() const {
1294 map<string, double> result;
1295 for (const auto& [volume, particleProcessMap] : fEnergyInVolumePerParticlePerProcess) {
1296 for (const auto& [particle, processMap] : particleProcessMap) {
1297 for (const auto& [process, energy] : processMap) {
1298 result[process] += energy;
1299 }
1300 }
1301 }
1302 return result;
1303}
1304
1305map<string, double> TRestGeant4Event::GetEnergyPerParticleMap() const {
1306 map<string, double> result;
1307 for (const auto& [volume, particleProcessMap] : fEnergyInVolumePerParticlePerProcess) {
1308 for (const auto& [particle, processMap] : particleProcessMap) {
1309 for (const auto& [process, energy] : processMap) {
1310 result[particle] += energy;
1311 }
1312 }
1313 }
1314 return result;
1315}
1316
1317map<string, double> TRestGeant4Event::GetEnergyInVolumeMap() const {
1318 map<string, double> result;
1319 for (const auto& [volume, particleProcessMap] : fEnergyInVolumePerParticlePerProcess) {
1320 for (const auto& [particle, processMap] : particleProcessMap) {
1321 for (const auto& [process, energy] : processMap) {
1322 result[volume] += energy;
1323 }
1324 }
1325 }
1326 return result;
1327}
1328
1329map<string, map<string, map<string, double>>> TRestGeant4Event::GetEnergyInVolumePerParticlePerProcessMap()
1330 const {
1331 return fEnergyInVolumePerParticlePerProcess;
1332}
1333
1334void TRestGeant4Event::AddEnergyInVolumeForParticleForProcess(Double_t energy, const string& volumeName,
1335 const string& particleName,
1336 const string& processName) {
1337 if (energy <= 0) {
1338 return;
1339 }
1340 fEnergyInVolumePerParticlePerProcess[volumeName][particleName][processName] += energy;
1341 fTotalDepositedEnergy += energy;
1342}
1343
1344std::pair<double, double> TRestGeant4Event::GetTimeRangeOfIonizationInVolume(const string& volumeName) const {
1345 std::pair<double, double> result = {std::numeric_limits<double>::max(),
1346 std::numeric_limits<double>::min()};
1347
1348 for (const auto& track : fTracks) {
1349 const auto& hits = track.GetHits();
1350 for (int i = 0; i < int(hits.GetNumberOfHits()); i++) {
1351 if (hits.GetVolumeName(i) == volumeName && hits.GetEnergy(i) > 0) {
1352 const double time = hits.GetTime(i);
1353 result.first = std::min(result.first, time);
1354 result.second = std::max(result.second, time);
1355 }
1356 }
1357 }
1358
1359 return result;
1360}
virtual void InitializeReferences(TRestRun *run)
Initialize dynamical references when loading the event from a root file.
Definition: TRestEvent.cxx:175
virtual void PrintEvent() const
Definition: TRestEvent.cxx:187
virtual void Initialize()=0
Definition: TRestEvent.cxx:73
An event class to store geant4 generated event information.
TVector3 GetFirstPositionInVolume(Int_t volID) const
Function to get the position (TVector3) of the first track that deposits energy in specified volume....
void InitializeReferences(TRestRun *run) override
Initialize dynamical references when loading the event from a root file.
TPad * DrawEvent(const TString &option="") override
Draw the event.
size_t GetNumberOfHits(Int_t volID=-1) const
Function that returns the total number of hits in the Geant4 event. If a specific volume is given as ...
size_t GetNumberOfPhysicalHits(Int_t volID=-1) const
Function that returns the total number of hits with energy > 0 in the Geant4 event....
Double_t GetBoundingBoxSize()
This method returns the event size as the size of the bounding box enclosing all hits.
TVector3 GetPositionDeviationInVolume(Int_t volID) const
A method that gets the standard deviation from the hits happening at a particular volumeId inside the...
void Initialize() override
void PrintActiveVolumes() const
maxTracks : number of tracks to print, 0 = all
TVector3 GetLastPositionInVolume(Int_t volID) const
Function to get the position (TVector3) of the last track that deposits energy in specified volume....
TRestHits GetHits(Int_t volID=-1) const
Function that returns all the hit depositions in the Geant4 event. If a specific volume is given as a...
The main class to store the Geant4 simulation conditions that will be used by restG4.
const TRestGeant4PhysicsInfo & GetGeant4PhysicsInfo() const
Returns an immutable reference to the physics info.
void PrintTrack(size_t maxHits=0) const
Prints the track information. N number of hits to print, 0 = all.
size_t GetNumberOfHits(Int_t volID=-1) const
Function that returns the number of hit depositions found inside the TRestGeant4Track....
It saves a 3-coordinate position and an energy for each punctual deposition.
Definition: TRestHits.h:39
void AddHit(const TVector3 &position, Double_t energy, Double_t time=0, REST_HitType type=XYZ)
Adds a new hit to the list of hits using a TVector3.
Definition: TRestHits.cxx:345
TVector3 GetPosition(int n) const
It returns the position of hit number n.
Definition: TRestHits.cxx:515
Data provider and manager in REST.
Definition: TRestRun.h:18
static std::vector< std::string > GetOptions(std::string optionsStr)
Returns all the options in an option string.
Definition: TRestTools.cxx:86
std::vector< std::string > Split(std::string in, std::string separator, bool allowBlankString=false, bool removeWhiteSpaces=false, int startPos=-1)
Split the input string according to the given separator. Returning a vector of fragments.