// // Example of I/O of a mathcore Lorentz Vectors in a Tree and comparison with a TLorentzVector // A ROOT tree is written and read in both using either a XYZTVector or /// a TLorentzVector. // // To execute the macro type in: // // root[0]: .x mathcoreVectorIO.C //Author: Lorenzo Moneta #include "TRandom2.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" using namespace ROOT::Math; void write(int n) { TRandom2 R; TStopwatch timer; R.SetSeed(1); timer.Start(); double s = 0; for (int i = 0; i < n; ++i) { s += R.Gaus(0,10); s += R.Gaus(0,10); s += R.Gaus(0,10); s += R.Gaus(100,10); } timer.Stop(); std::cout << s/double(n) << std::endl; std::cout << " Time for Random gen " << timer.RealTime() << " " << timer.CpuTime() << std::endl; TFile f1("mathcoreVectorIO_1.root","RECREATE"); // create tree TTree t1("t1","Tree with new LorentzVector"); XYZTVector *v1 = new XYZTVector(); t1.Branch("LV branch","ROOT::Math::XYZTVector",&v1); R.SetSeed(1); 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 Vector " << timer.RealTime() << " " << timer.CpuTime() << std::endl; t1.Print(); // create tree with old LV TFile f2("mathcoreVectorIO_2.root","RECREATE"); TTree t2("t2","Tree with TLorentzVector"); TLorentzVector * v2 = new TLorentzVector(); TLorentzVector::Class()->IgnoreTObjectStreamer(); TVector3::Class()->IgnoreTObjectStreamer(); t2.Branch("TLV branch","TLorentzVector",&v2,16000,2); R.SetSeed(1); 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); v2->SetPxPyPzE(Px,Py,Pz,E); t2.Fill(); } f2.Write(); timer.Stop(); std::cout << " Time for old Vector " << timer.RealTime() << " " << timer.CpuTime() << endl; t2.Print(); } void read() { TRandom R; TStopwatch timer; TFile f1("mathcoreVectorIO_1.root"); // create tree TTree *t1 = (TTree*)f1.Get("t1"); XYZTVector *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->Px(); etot += v1->Py(); etot += v1->Pz(); etot += v1->E(); } timer.Stop(); std::cout << " Time for new Vector " << timer.RealTime() << " " << timer.CpuTime() << std::endl; std::cout << " TOT average : n = " << n << "\t " << etot/double(n) << endl; // create tree with old LV TFile f2("mathcoreVectorIO_2.root"); TTree *t2 = (TTree*)f2.Get("t2"); TLorentzVector * v2 = 0; t2->SetBranchAddress("TLV branch",&v2); timer.Start(); n = (int) t2->GetEntries(); std::cout << " Tree Entries " << n << std::endl; etot = 0; for (int i = 0; i < n; ++i) { t2->GetEntry(i); etot += v2->Px(); etot += v2->Py(); etot += v2->Pz(); etot += v2->E(); } timer.Stop(); std::cout << " Time for old Vector " << timer.RealTime() << " " << timer.CpuTime() << endl; std::cout << " TOT average:\t" << etot/double(n) << endl; } void mathcoreVectorIO() { #if defined(__CINT__) && !defined(__MAKECINT__) gSystem->Load("libMathCore"); gSystem->Load("libPhysics"); // in CINT need to do that after having loading the library using namespace ROOT::Math; cout << "This tutorial can run only using ACliC, compiling it by doing: " << endl; cout << "\t .x tutorials/math/mathcoreVectorCollection.C+" << endl; //gROOT->ProcessLine(".x tutorials/math/mathcoreVectorCollection.C+"); return; #endif int nEvents = 100000; write(nEvents); read(); } mathcoreVectorIO.C:1 mathcoreVectorIO.C:2 mathcoreVectorIO.C:3 mathcoreVectorIO.C:4 mathcoreVectorIO.C:5 mathcoreVectorIO.C:6 mathcoreVectorIO.C:7 mathcoreVectorIO.C:8 mathcoreVectorIO.C:9 mathcoreVectorIO.C:10 mathcoreVectorIO.C:11 mathcoreVectorIO.C:12 mathcoreVectorIO.C:13 mathcoreVectorIO.C:14 mathcoreVectorIO.C:15 mathcoreVectorIO.C:16 mathcoreVectorIO.C:17 mathcoreVectorIO.C:18 mathcoreVectorIO.C:19 mathcoreVectorIO.C:20 mathcoreVectorIO.C:21 mathcoreVectorIO.C:22 mathcoreVectorIO.C:23 mathcoreVectorIO.C:24 mathcoreVectorIO.C:25 mathcoreVectorIO.C:26 mathcoreVectorIO.C:27 mathcoreVectorIO.C:28 mathcoreVectorIO.C:29 mathcoreVectorIO.C:30 mathcoreVectorIO.C:31 mathcoreVectorIO.C:32 mathcoreVectorIO.C:33 mathcoreVectorIO.C:34 mathcoreVectorIO.C:35 mathcoreVectorIO.C:36 mathcoreVectorIO.C:37 mathcoreVectorIO.C:38 mathcoreVectorIO.C:39 mathcoreVectorIO.C:40 mathcoreVectorIO.C:41 mathcoreVectorIO.C:42 mathcoreVectorIO.C:43 mathcoreVectorIO.C:44 mathcoreVectorIO.C:45 mathcoreVectorIO.C:46 mathcoreVectorIO.C:47 mathcoreVectorIO.C:48 mathcoreVectorIO.C:49 mathcoreVectorIO.C:50 mathcoreVectorIO.C:51 mathcoreVectorIO.C:52 mathcoreVectorIO.C:53 mathcoreVectorIO.C:54 mathcoreVectorIO.C:55 mathcoreVectorIO.C:56 mathcoreVectorIO.C:57 mathcoreVectorIO.C:58 mathcoreVectorIO.C:59 mathcoreVectorIO.C:60 mathcoreVectorIO.C:61 mathcoreVectorIO.C:62 mathcoreVectorIO.C:63 mathcoreVectorIO.C:64 mathcoreVectorIO.C:65 mathcoreVectorIO.C:66 mathcoreVectorIO.C:67 mathcoreVectorIO.C:68 mathcoreVectorIO.C:69 mathcoreVectorIO.C:70 mathcoreVectorIO.C:71 mathcoreVectorIO.C:72 mathcoreVectorIO.C:73 mathcoreVectorIO.C:74 mathcoreVectorIO.C:75 mathcoreVectorIO.C:76 mathcoreVectorIO.C:77 mathcoreVectorIO.C:78 mathcoreVectorIO.C:79 mathcoreVectorIO.C:80 mathcoreVectorIO.C:81 mathcoreVectorIO.C:82 mathcoreVectorIO.C:83 mathcoreVectorIO.C:84 mathcoreVectorIO.C:85 mathcoreVectorIO.C:86 mathcoreVectorIO.C:87 mathcoreVectorIO.C:88 mathcoreVectorIO.C:89 mathcoreVectorIO.C:90 mathcoreVectorIO.C:91 mathcoreVectorIO.C:92 mathcoreVectorIO.C:93 mathcoreVectorIO.C:94 mathcoreVectorIO.C:95 mathcoreVectorIO.C:96 mathcoreVectorIO.C:97 mathcoreVectorIO.C:98 mathcoreVectorIO.C:99 mathcoreVectorIO.C:100 mathcoreVectorIO.C:101 mathcoreVectorIO.C:102 mathcoreVectorIO.C:103 mathcoreVectorIO.C:104 mathcoreVectorIO.C:105 mathcoreVectorIO.C:106 mathcoreVectorIO.C:107 mathcoreVectorIO.C:108 mathcoreVectorIO.C:109 mathcoreVectorIO.C:110 mathcoreVectorIO.C:111 mathcoreVectorIO.C:112 mathcoreVectorIO.C:113 mathcoreVectorIO.C:114 mathcoreVectorIO.C:115 mathcoreVectorIO.C:116 mathcoreVectorIO.C:117 mathcoreVectorIO.C:118 mathcoreVectorIO.C:119 mathcoreVectorIO.C:120 mathcoreVectorIO.C:121 mathcoreVectorIO.C:122 mathcoreVectorIO.C:123 mathcoreVectorIO.C:124 mathcoreVectorIO.C:125 mathcoreVectorIO.C:126 mathcoreVectorIO.C:127 mathcoreVectorIO.C:128 mathcoreVectorIO.C:129 mathcoreVectorIO.C:130 mathcoreVectorIO.C:131 mathcoreVectorIO.C:132 mathcoreVectorIO.C:133 mathcoreVectorIO.C:134 mathcoreVectorIO.C:135 mathcoreVectorIO.C:136 mathcoreVectorIO.C:137 mathcoreVectorIO.C:138 mathcoreVectorIO.C:139 mathcoreVectorIO.C:140 mathcoreVectorIO.C:141 mathcoreVectorIO.C:142 mathcoreVectorIO.C:143 mathcoreVectorIO.C:144 mathcoreVectorIO.C:145 mathcoreVectorIO.C:146 mathcoreVectorIO.C:147 mathcoreVectorIO.C:148 mathcoreVectorIO.C:149 mathcoreVectorIO.C:150 mathcoreVectorIO.C:151 mathcoreVectorIO.C:152 mathcoreVectorIO.C:153 mathcoreVectorIO.C:154 mathcoreVectorIO.C:155 mathcoreVectorIO.C:156 mathcoreVectorIO.C:157 mathcoreVectorIO.C:158 mathcoreVectorIO.C:159 mathcoreVectorIO.C:160 mathcoreVectorIO.C:161 mathcoreVectorIO.C:162 mathcoreVectorIO.C:163 mathcoreVectorIO.C:164 mathcoreVectorIO.C:165 mathcoreVectorIO.C:166 mathcoreVectorIO.C:167 mathcoreVectorIO.C:168 mathcoreVectorIO.C:169 mathcoreVectorIO.C:170 mathcoreVectorIO.C:171 mathcoreVectorIO.C:172 mathcoreVectorIO.C:173 mathcoreVectorIO.C:174 mathcoreVectorIO.C:175 mathcoreVectorIO.C:176 mathcoreVectorIO.C:177 mathcoreVectorIO.C:178 mathcoreVectorIO.C:179 mathcoreVectorIO.C:180 mathcoreVectorIO.C:181 mathcoreVectorIO.C:182 mathcoreVectorIO.C:183 mathcoreVectorIO.C:184 mathcoreVectorIO.C:185 mathcoreVectorIO.C:186 mathcoreVectorIO.C:187 mathcoreVectorIO.C:188 mathcoreVectorIO.C:189 mathcoreVectorIO.C:190 mathcoreVectorIO.C:191 mathcoreVectorIO.C:192 mathcoreVectorIO.C:193 mathcoreVectorIO.C:194 mathcoreVectorIO.C:195 mathcoreVectorIO.C:196 mathcoreVectorIO.C:197 mathcoreVectorIO.C:198 mathcoreVectorIO.C:199 |
|