In this example, we are mapping a class to one of the Geant3 common blocks /gctrak/. In the real life, this common will be filled by Geant3 at each step and only the Tree Fill function should be called. The example emulates the Geant3 step routines.
Note that since IO is involved, ACLiC has to be invoked to create the dictionary of class Gctrak.
public:
Gctrak() {
lmec = nullptr;
namec = nullptr;
}
};
{
enum Evect {kX, kY, kZ, kPX, kPY, kPZ, kPP};
vout[kPP] = vect[kPP];
Float_t f3 = step * tsint * vect[kPZ];
Float_t f6 = tet * cos1t * vect[kPZ];
vout[kX] = vect[kX] + (
f1*vect[kPX] - f2*vect[kPY]);
vout[kY] = vect[kY] + (
f1*vect[kPY] + f2*vect[kPX]);
vout[kZ] = vect[kZ] + (
f1*vect[kPZ] + f3);
vout[kPX] = vect[kPX] + (f4*vect[kPX] - f5*vect[kPY]);
vout[kPY] = vect[kPY] + (f4*vect[kPY] + f5*vect[kPX]);
vout[kPZ] = vect[kPZ] + (f4*vect[kPZ] + f6);
}
void tree106_write()
{
TFile f(
"tree106.root",
"recreate");
TTree t2(
"t2",
"a Tree with data from a fake Geant3");
auto gstep = new Gctrak;
t2.Branch("track", &gstep, 8000, 1);
gstep->lmec =
new Int_t[MAXMEC];
gstep->namec =
new Int_t[MAXMEC];
gstep->step = 0.1;
gstep->destep = 0;
gstep->nmec = 0;
gstep->pid = 0;
for (
Int_t i=0;i <10000; i++) {
if (newParticle) {
charge = 1;
charge = -1;
gstep->pid += 1;
gstep->vect[0] = 0;
gstep->vect[1] = 0;
gstep->vect[2] = 0;
gstep->vect[3] = px / p;
gstep->vect[4] = py / p;
gstep->vect[5] = pz / p;
gstep->vect[6] = p*charge;
gstep->gekin = gstep->getot - mass;
}
t2.Fill();
helixStep(gstep->step, gstep->vect, vout);
gstep->destep = gstep->step*
gRandom->Gaus(0.0002, 0.00001);
gstep->gekin -= gstep->destep;
gstep->getot = gstep->gekin + mass;
gstep->vect[6] = charge *
TMath::Sqrt(gstep->getot * gstep->getot - mass * mass);
gstep->vect[0] = vout[0];
gstep->vect[1] = vout[1];
gstep->vect[2] = vout[2];
gstep->vect[3] = vout[3];
gstep->vect[4] = vout[4];
gstep->vect[5] = vout[5];
gstep->namec[
l] =
l + 100;
}
if (gstep->gekin < 0.001)
}
t2.Write();
}
void tree106_read()
{
auto t2 =
f->Get<
TTree>(
"t2");
Gctrak *gstep = nullptr;
auto b_destep = t2->GetBranch("destep");
auto hdestep =
new TH1F(
"hdestep",
"destep in Mev", 100, 1
e-5, 3
e-5);
b_destep->GetEntry(i);
hdestep->Fill(gstep->destep);
}
hdestep->SetFillColor(45);
hdestep->Fit("gaus");
t2->SetMarkerColor(
kRed);
t2->Draw("vect[0]:vect[1]:vect[2]");
return;
gPad->GetViewer3D(
"ogl");
}
void tree106_tree()
{
tree106_write();
tree106_read();
}
int Int_t
Signed integer 4 bytes (int).
bool Bool_t
Boolean (0=false, 1=true) (bool).
long long Long64_t
Portable signed long integer 8 bytes.
float Float_t
Float 4 bytes (float).
#define ClassDefOverride(name, id)
A file, usually with extension .root, that stores data and code in the form of serialized objects in ...
static TFile * Open(const char *name, Option_t *option="", const char *ftitle="", Int_t compress=ROOT::RCompressionSetting::EDefaults::kUseCompiledDefault, Int_t netopt=0)
Create / open a file.
1-D histogram with a float per channel (see TH1 documentation)
Mother of all ROOT objects.
A TTree represents a columnar dataset.
virtual Int_t SetBranchAddress(const char *bname, void *add, TBranch **ptr, TClass *realClass, EDataType datatype, bool isptr, bool suppressMissingBranchError)
Double_t Sqrt(Double_t x)
Returns the square root of x.
Short_t Abs(Short_t d)
Returns the absolute value of parameter Short_t d.