-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathEnergyLoss.C
82 lines (74 loc) · 2.66 KB
/
EnergyLoss.C
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
#include "../include/Object.hh"
#include <TFile.h>
#include <TTree.h>
#include <TClonesArray.h>
#include <TH1F.h>
#include <TCanvas.h>
#include <TLegend.h>
#include <TStyle.h>
#include <iostream>
#include <filesystem>
using namespace std;
namespace fs = std::filesystem;
void EnergyLoss(const char *path = "../build/tree/latest.root", const char *outpath = NULL)
{
TFile *file = TFile::Open(path);
auto tree = (TTree *)file->Get("tree");
TClonesArray *Tracks = NULL;
Double_t EnergyDeposit, NonIonizingEnergyDeposit;
tree->SetBranchAddress("Tracks", &Tracks);
tree->SetBranchAddress("EnergyDeposit", &EnergyDeposit);
tree->SetBranchAddress("NonIonizingEnergyDeposit", &NonIonizingEnergyDeposit);
gStyle->SetHistLineWidth(2);
TH1F *Ionization = new TH1F("Ionization", "", 40, 0, 40);
TH1F *Radiation = new TH1F("Radiation", "", 40, 0, 40);
TH1F *Edep = new TH1F("EnergyDeposit", "", 40, 0, 40);
TH1F *NonIonEdep = new TH1F("NonIonizingEnergyDeposit", "", 40, 0, 40);
for(Long64_t i = 0; tree->GetEntry(i); ++i) {
Double_t ionization = 0.0, radiation = 0.0;
Int_t nTrack = Tracks->GetEntries();
if(nTrack == 0) continue;
for(Int_t iTrack = 1; iTrack < nTrack; ++iTrack) {
auto track = (Track *)Tracks->UncheckedAt(iTrack);
if(track->Mother != 1) continue; // Consider only primary ionization/radiation.
switch(track->Pid) {
case 11: ionization += track->E - 0.51099895; break;
case 22: radiation += track->E; break;
default: cerr << "WARNING: Unexpected PDG ID " << track->Pid << endl;
}
}
Ionization->Fill(ionization);
Radiation->Fill(radiation);
Edep->Fill(EnergyDeposit);
NonIonEdep->Fill(NonIonizingEnergyDeposit);
}
TCanvas *canvas = new TCanvas;
canvas->SetTopMargin(0.05);
canvas->SetBottomMargin(0.08);
canvas->SetLeftMargin(0.12);
canvas->SetRightMargin(0.03);
Double_t maximum = max(Ionization->GetMaximum(), Radiation->GetMaximum());
maximum = max(maximum, Edep->GetMaximum());
maximum = max(maximum, NonIonEdep->GetMaximum());
Ionization->SetMaximum(maximum * 1.1);
Ionization->SetStats(0);
Ionization->SetLineColor(2);
Ionization->SetXTitle("Energy loss [MeV]");
Ionization->SetYTitle("Events");
Ionization->Draw();
Radiation->SetLineColor(3);
Radiation->Draw("Same");
Edep->SetLineColor(4);
Edep->Draw("Same");
NonIonEdep->SetLineColor(5);
NonIonEdep->Draw("Same");
TLegend *legend = canvas->BuildLegend(0.75, 0.78, 0.95, 0.93);
legend->Draw();
canvas->SaveAs(outpath ? : fs::path(path).filename().replace_extension("pdf").c_str());
delete canvas;
delete Ionization;
delete Radiation;
delete Edep;
delete NonIonEdep;
file->Close();
}