FairShip
Loading...
Searching...
No Matches
test_split_set.cxx File Reference
#include <TClonesArray.h>
#include <TFile.h>
#include <TTree.h>
#include <cstdio>
#include <iostream>
#include <memory>
#include "ShipMCTrack.h"
Include dependency graph for test_split_set.cxx:

Go to the source code of this file.

Functions

int main (int argc, char **argv)

Function Documentation

◆ main()

int main ( int argc,
char ** argv )

Definition at line 31 of file test_split_set.cxx.

31 {
32 ShipMCTrack plain;
33 Check(plain.GetSplitSet() == -1, "default split set");
34 Check(plain.GetSplitRole() == ShipMCTrack::kNotSplit, "default split role");
35 Check(!plain.IsSplitDecay() && !plain.IsSplitSurvivor(), "default flags");
36
37 ShipMCTrack clone(321, 0, 0., 0., 50., 50.002, 0., 0., 10., 0.3, 0, 0, 7,
38 0.25);
39 Check(clone.GetSplitSet() == -1, "standard constructor split set");
40 clone.SetSplitSet(3, ShipMCTrack::kSplitDecay, 0.5);
41 Check(clone.IsSplitDecay() && !clone.IsSplitSurvivor(), "decay role");
42 const ShipMCTrack copy(clone);
43 Check(copy.GetSplitSet() == 3 && copy.IsSplitDecay() &&
44 copy.GetSplitWeight() == 0.5,
45 "copy keeps split set");
46
47 // Round trip through a file.
48 const char* fname = "test_split_set.root";
49 {
50 TFile f(fname, "RECREATE");
51 ShipMCTrack survivor(clone);
52 survivor.SetSplitSet(3, ShipMCTrack::kSplitSurvivor, 0.5);
53 f.WriteObject(&clone, "clone");
54 f.WriteObject(&survivor, "survivor");
55 }
56 {
57 TFile f(fname);
58 std::unique_ptr<ShipMCTrack> c(f.Get<ShipMCTrack>("clone"));
59 std::unique_ptr<ShipMCTrack> s(f.Get<ShipMCTrack>("survivor"));
60 Check(c && c->GetSplitSet() == 3 && c->IsSplitDecay() &&
61 c->GetSplitWeight() == 0.5,
62 "read back clone");
63 Check(s && s->GetSplitSet() == 3 && s->IsSplitSurvivor(),
64 "read back survivor");
65 }
66 std::remove(fname);
67
68 // A file written before the split set existed (ShipMCTrack version 9).
69 if (argc > 1) {
70 TFile f(argv[1]);
71 auto* tree = f.Get<TTree>("cbmsim");
72 Check(tree != nullptr, "old file has cbmsim");
73 if (tree) {
74 // This file predates the move to std::vector: MCTrack is a TClonesArray.
75 TClonesArray* tracks = nullptr;
76 tree->SetBranchAddress("MCTrack", &tracks);
77 Long64_t n = 0;
78 bool allUnsplit = true;
79 for (Long64_t i = 0; i < tree->GetEntries(); ++i) {
80 tree->GetEntry(i);
81 for (Int_t j = 0; tracks && j < tracks->GetEntriesFast(); ++j) {
82 const auto* t = dynamic_cast<const ShipMCTrack*>(tracks->At(j));
83 if (!t) continue;
84 ++n;
85 allUnsplit &= t->GetSplitSet() == -1 &&
86 t->GetSplitRole() == ShipMCTrack::kNotSplit;
87 }
88 }
89 Check(n > 0, "old file has tracks");
90 Check(allUnsplit, "old tracks read back as not split");
91 tree->ResetBranchAddresses();
92 delete tracks;
93 }
94 }
95
96 if (failures) {
97 std::cerr << failures << " check(s) failed" << std::endl;
98 return 1;
99 }
100 return 0;
101}
Bool_t IsSplitDecay() const
Bool_t IsSplitSurvivor() const
Int_t GetSplitRole() const
@ kSplitDecay
a clone standing for one decay of the split track
Definition ShipMCTrack.h:34
@ kNotSplit
not part of a split set
Definition ShipMCTrack.h:32
@ kSplitSurvivor
the split track itself, or its continuation
Definition ShipMCTrack.h:33
Int_t GetSplitSet() const
int i
Definition ShipAna.py:108
c
Definition hnl.py:116