In the write() function a variable number of track Vectors is generated according to a Poisson distribution with random momentum uniformly distributed in phi and eta. In the read() the vectors are read back and the content analysed and some information such as number of tracks per event or the track pt distributions are displayed in a canvas.
Time for new Vector 0.204026 0.2
******************************************************************************
*Tree :t1 : Tree with new LorentzVector *
*Entries : 10000 : Total = 1854288 bytes File Size = 1667859 *
* : : Tree compression factor = 1.11 *
******************************************************************************
*Br 0 :tracks : Int_t tracks_ *
*Entries : 10000 : Total Size= 84910 bytes File Size = 24060 *
*Baskets : 4 : Basket Size= 32000 bytes Compression= 3.34 *
*............................................................................*
*Br 1 :tracks.fCoordinates.fX : Double_t fX[tracks_] *
*Entries : 10000 : Total Size= 443177 bytes File Size = 412928 *
*Baskets : 16 : Basket Size= 32000 bytes Compression= 1.07 *
*............................................................................*
*Br 2 :tracks.fCoordinates.fY : Double_t fY[tracks_] *
*Entries : 10000 : Total Size= 443177 bytes File Size = 412937 *
*Baskets : 16 : Basket Size= 32000 bytes Compression= 1.07 *
*............................................................................*
*Br 3 :tracks.fCoordinates.fZ : Double_t fZ[tracks_] *
*Entries : 10000 : Total Size= 443177 bytes File Size = 411390 *
*Baskets : 16 : Basket Size= 32000 bytes Compression= 1.08 *
*............................................................................*
*Br 4 :tracks.fCoordinates.fT : Double_t fT[tracks_] *
*Entries : 10000 : Total Size= 443177 bytes File Size = 405161 *
*Baskets : 16 : Basket Size= 32000 bytes Compression= 1.09 *
*............................................................................*
Tree Entries 10000
Time for new Vector 0.0320539 0.03
(int) 0
#include <iostream>
TFile f1(
"mathcoreLV.root",
"RECREATE");
TTree t1(
"t1",
"Tree with new LorentzVector");
std::vector<ROOT::Math::XYZTVector>
tracks;
std::vector<ROOT::Math::XYZTVector> * pTracks = &
tracks;
t1.Branch(
"tracks",
"std::vector<ROOT::Math::LorentzVector<ROOT::Math::PxPyPzE4D<double> > >",&pTracks);
double M = 0.13957;
for (
int i = 0; i <
n; ++i) {
int nPart =
R.Poisson(5);
pTracks->clear();
pTracks->reserve(nPart);
for (int j = 0; j < nPart; ++j) {
double px =
R.Gaus(0,10);
double py =
R.Gaus(0,10);
double pt = sqrt(px*px +py*py);
double eta =
R.Uniform(-3,3);
double E = sqrt( vcyl.R()*vcyl.R() + M*M);
}
}
std::cout <<
" Time for new Vector " << timer.
RealTime() <<
" " << timer.
CpuTime() << std::endl;
}
double read() {
TH1D *
h1 =
new TH1D(
"h1",
"total event energy ",100,0,1000.);
TH1D *
h2 =
new TH1D(
"h2",
"Number of track per event",21,-0.5,20.5);
TH1D *
h3 =
new TH1D(
"h3",
"Track Energy",100,0,200);
TH1D * h4 =
new TH1D(
"h4",
"Track Pt",100,0,100);
TH1D * h5 =
new TH1D(
"h5",
"Track Eta",100,-5,5);
TH1D * h6 =
new TH1D(
"h6",
"Track Cos(theta)",100,-1,1);
std::vector<ROOT::Math::LorentzVector<ROOT::Math::PxPyPzE4D<double> > > * pTracks = nullptr;
t1->SetBranchAddress(
"tracks",&pTracks);
int n = (
int)
t1->GetEntries();
std::cout <<
" Tree Entries " <<
n << std::endl;
for (
int i = 0; i <
n; ++i) {
int ntrk = pTracks->size();
for (int j = 0; j < ntrk; ++j) {
sum +=
v.x() +
v.y() +
v.z() +
v.t();
}
}
std::cout <<
" Time for new Vector " << timer.
RealTime() <<
" " << timer.
CpuTime() << std::endl;
}
int mathcoreVectorCollection() {
int nEvents = 10000;
double s1 = write(nEvents);
double s2 = read();
std::cout <<
"ERROR: Found difference in Vector when reading ( " <<
s1 <<
" != " << s2 <<
" diff = " <<
fabs(
s1-s2) <<
" ) " << std::endl;
return -1;
}
return 0;
}
return mathcoreVectorCollection();
}
#define R(a, b, c, d, e, f, g, h, i)
Class describing a generic displacement vector in 3 dimensions.
Class describing a generic LorentzVector in the 4D space-time, using the specified coordinate system ...
A ROOT file is an on-disk file, usually with extension .root, that stores objects in a file-system-li...
1-D histogram with a double per channel (see TH1 documentation)
virtual Int_t Fill(Double_t x)
Increment bin with abscissa X by 1.
void Draw(Option_t *option="") override
Draw this histogram with options.
virtual Int_t Write(const char *name=nullptr, Int_t option=0, Int_t bufsize=0)
Write this object to the current directory.
This is the base class for the ROOT Random number generators.
Double_t RealTime()
Stop the stopwatch (if it is running) and return the realtime (in seconds) passed between the start a...
void Start(Bool_t reset=kTRUE)
Start the stopwatch.
Double_t CpuTime()
Stop the stopwatch (if it is running) and return the cputime (in seconds) passed between the start an...
void Stop()
Stop the stopwatch.
A TTree represents a columnar dataset.
RVec< PromoteType< T > > cos(const RVec< T > &v)
VecExpr< UnaryOp< Fabs< T >, VecExpr< A, T, D >, T >, T, D > fabs(const VecExpr< A, T, D > &rhs)
static uint64_t sum(uint64_t i)