mathcoreVectorFloatIO.C: Macro illustrating automatic dictionary generation and I/O with Lorentz Vectors of floats
//
// Macro illustrating automatic dictionary generation and I/O with Lorentz Vectors of floats
// The dictionary for LorentzVector of float is not in the libMathCore, therefore
// is generated when parsed the file with CINT.
//
// To run this macro you must do
//
// root[0]: .L mathcoreVectorFloatIO.C+
// root[1]: runIt();
//Author: Lorenzo Moneta
#include "TRandom.h"
#include "TStopwatch.h"
#include "TSystem.h"
#include "TFile.h"
#include "TTree.h"
#include "TH1D.h"
#include "TCanvas.h"
#include <iostream>
#include "TLorentzVector.h"
#include "Math/Vector4D.h"
#ifdef __MAKECINT__
#pragma link C++ class ROOT::Math::PxPyPzE4D<float>+;
#pragma link C++ class ROOT::Math::LorentzVector<ROOT::Math::PxPyPzE4D<float> >+;
#pragma link C++ typedef ROOT::Math::XYZTVectorF;
#endif
using namespace ROOT::Math;
void write(int n) {
TRandom R;
TStopwatch timer;
TFile f1("mathcoreVectorIO_F.root","RECREATE");
// create tree
TTree t1("t1","Tree with new Float LorentzVector");
XYZTVectorF *v1 = new XYZTVectorF();
t1.Branch("LV branch","ROOT::Math::XYZTVectorF",&v1);
timer.Start();
for (int i = 0; i < n; ++i) {
double Px = R.Gaus(0,10);
double Py = R.Gaus(0,10);
double Pz = R.Gaus(0,10);
double E = R.Gaus(100,10);
//CylindricalEta4D<double> & c = v1->Coordinates();
//c.SetValues(Px,pY,pZ,E);
v1->SetCoordinates(Px,Py,Pz,E);
t1.Fill();
}
f1.Write();
timer.Stop();
std::cout << " Time for new Float Vector " << timer.RealTime() << " " << timer.CpuTime() << std::endl;
t1.Print();
}
void read() {
TRandom R;
TStopwatch timer;
TFile f1("mathcoreVectorIO_F.root");
// create tree
TTree *t1 = (TTree*)f1.Get("t1");
XYZTVectorF *v1 = 0;
t1->SetBranchAddress("LV branch",&v1);
timer.Start();
int n = (int) t1->GetEntries();
std::cout << " Tree Entries " << n << std::endl;
double etot=0;
for (int i = 0; i < n; ++i) {
t1->GetEntry(i);
etot += v1->E();
}
timer.Stop();
std::cout << " Time for new Float Vector " << timer.RealTime() << " " << timer.CpuTime() << std::endl;
std::cout << " E average" << n<< " " << etot << " " << etot/double(n) << endl;
}
void runIt() {
#if defined(__CINT__) && !defined(__MAKECINT__)
gSystem->Load("libMathCore");
gSystem->Load("libPhysics");
using namespace ROOT::Math;
cout << "This tutorial can run only using ACliC, you must run it by doing: " << endl;
cout << "\t .L tutorials/math/mathcoreVectorFloatIO.C+" << endl;
cout << "\t runIt()" << endl;
#endif
int nEvents = 100000;
write(nEvents);
read();
}
void mathcoreVectorFloatIO() {
#if defined(__CINT__) && !defined(__MAKECINT__)
gSystem->Load("libMathCore");
gSystem->Load("libPhysics");
using namespace ROOT::Math;
cout << "This tutorial can run only using ACliC, you must run it by doing: " << endl;
cout << "\t .L tutorials/math/mathcoreVectorFloatIO.C+" << endl;
cout << "\t runIt()" << endl;
#endif
}
mathcoreVectorFloatIO.C:1 mathcoreVectorFloatIO.C:2 mathcoreVectorFloatIO.C:3 mathcoreVectorFloatIO.C:4 mathcoreVectorFloatIO.C:5 mathcoreVectorFloatIO.C:6 mathcoreVectorFloatIO.C:7 mathcoreVectorFloatIO.C:8 mathcoreVectorFloatIO.C:9 mathcoreVectorFloatIO.C:10 mathcoreVectorFloatIO.C:11 mathcoreVectorFloatIO.C:12 mathcoreVectorFloatIO.C:13 mathcoreVectorFloatIO.C:14 mathcoreVectorFloatIO.C:15 mathcoreVectorFloatIO.C:16 mathcoreVectorFloatIO.C:17 mathcoreVectorFloatIO.C:18 mathcoreVectorFloatIO.C:19 mathcoreVectorFloatIO.C:20 mathcoreVectorFloatIO.C:21 mathcoreVectorFloatIO.C:22 mathcoreVectorFloatIO.C:23 mathcoreVectorFloatIO.C:24 mathcoreVectorFloatIO.C:25 mathcoreVectorFloatIO.C:26 mathcoreVectorFloatIO.C:27 mathcoreVectorFloatIO.C:28 mathcoreVectorFloatIO.C:29 mathcoreVectorFloatIO.C:30 mathcoreVectorFloatIO.C:31 mathcoreVectorFloatIO.C:32 mathcoreVectorFloatIO.C:33 mathcoreVectorFloatIO.C:34 mathcoreVectorFloatIO.C:35 mathcoreVectorFloatIO.C:36 mathcoreVectorFloatIO.C:37 mathcoreVectorFloatIO.C:38 mathcoreVectorFloatIO.C:39 mathcoreVectorFloatIO.C:40 mathcoreVectorFloatIO.C:41 mathcoreVectorFloatIO.C:42 mathcoreVectorFloatIO.C:43 mathcoreVectorFloatIO.C:44 mathcoreVectorFloatIO.C:45 mathcoreVectorFloatIO.C:46 mathcoreVectorFloatIO.C:47 mathcoreVectorFloatIO.C:48 mathcoreVectorFloatIO.C:49 mathcoreVectorFloatIO.C:50 mathcoreVectorFloatIO.C:51 mathcoreVectorFloatIO.C:52 mathcoreVectorFloatIO.C:53 mathcoreVectorFloatIO.C:54 mathcoreVectorFloatIO.C:55 mathcoreVectorFloatIO.C:56 mathcoreVectorFloatIO.C:57 mathcoreVectorFloatIO.C:58 mathcoreVectorFloatIO.C:59 mathcoreVectorFloatIO.C:60 mathcoreVectorFloatIO.C:61 mathcoreVectorFloatIO.C:62 mathcoreVectorFloatIO.C:63 mathcoreVectorFloatIO.C:64 mathcoreVectorFloatIO.C:65 mathcoreVectorFloatIO.C:66 mathcoreVectorFloatIO.C:67 mathcoreVectorFloatIO.C:68 mathcoreVectorFloatIO.C:69 mathcoreVectorFloatIO.C:70 mathcoreVectorFloatIO.C:71 mathcoreVectorFloatIO.C:72 mathcoreVectorFloatIO.C:73 mathcoreVectorFloatIO.C:74 mathcoreVectorFloatIO.C:75 mathcoreVectorFloatIO.C:76 mathcoreVectorFloatIO.C:77 mathcoreVectorFloatIO.C:78 mathcoreVectorFloatIO.C:79 mathcoreVectorFloatIO.C:80 mathcoreVectorFloatIO.C:81 mathcoreVectorFloatIO.C:82 mathcoreVectorFloatIO.C:83 mathcoreVectorFloatIO.C:84 mathcoreVectorFloatIO.C:85 mathcoreVectorFloatIO.C:86 mathcoreVectorFloatIO.C:87 mathcoreVectorFloatIO.C:88 mathcoreVectorFloatIO.C:89 mathcoreVectorFloatIO.C:90 mathcoreVectorFloatIO.C:91 mathcoreVectorFloatIO.C:92 mathcoreVectorFloatIO.C:93 mathcoreVectorFloatIO.C:94 mathcoreVectorFloatIO.C:95 mathcoreVectorFloatIO.C:96 mathcoreVectorFloatIO.C:97 mathcoreVectorFloatIO.C:98 mathcoreVectorFloatIO.C:99 mathcoreVectorFloatIO.C:100 mathcoreVectorFloatIO.C:101 mathcoreVectorFloatIO.C:102 mathcoreVectorFloatIO.C:103 mathcoreVectorFloatIO.C:104 mathcoreVectorFloatIO.C:105 mathcoreVectorFloatIO.C:106 mathcoreVectorFloatIO.C:107 mathcoreVectorFloatIO.C:108 mathcoreVectorFloatIO.C:109 mathcoreVectorFloatIO.C:110 mathcoreVectorFloatIO.C:111 mathcoreVectorFloatIO.C:112 mathcoreVectorFloatIO.C:113 mathcoreVectorFloatIO.C:114 mathcoreVectorFloatIO.C:115 mathcoreVectorFloatIO.C:116 mathcoreVectorFloatIO.C:117 mathcoreVectorFloatIO.C:118 mathcoreVectorFloatIO.C:119 mathcoreVectorFloatIO.C:120 mathcoreVectorFloatIO.C:121 mathcoreVectorFloatIO.C:122 mathcoreVectorFloatIO.C:123 mathcoreVectorFloatIO.C:124 mathcoreVectorFloatIO.C:125 mathcoreVectorFloatIO.C:126 mathcoreVectorFloatIO.C:127 mathcoreVectorFloatIO.C:128 mathcoreVectorFloatIO.C:129 mathcoreVectorFloatIO.C:130 mathcoreVectorFloatIO.C:131 mathcoreVectorFloatIO.C:132 mathcoreVectorFloatIO.C:133 mathcoreVectorFloatIO.C:134 mathcoreVectorFloatIO.C:135 mathcoreVectorFloatIO.C:136 mathcoreVectorFloatIO.C:137 mathcoreVectorFloatIO.C:138 mathcoreVectorFloatIO.C:139 mathcoreVectorFloatIO.C:140 mathcoreVectorFloatIO.C:141 mathcoreVectorFloatIO.C:142 mathcoreVectorFloatIO.C:143 mathcoreVectorFloatIO.C:144 mathcoreVectorFloatIO.C:145 mathcoreVectorFloatIO.C:146 mathcoreVectorFloatIO.C:147 mathcoreVectorFloatIO.C:148 mathcoreVectorFloatIO.C:149 mathcoreVectorFloatIO.C:150