12 #include "Cintex/Cintex.h" 13 #include "Reflex/Reflex.h" 42 #define DEFVECTOR4D(TYPE) \ 43 typedef TYPE AVector4D; \ 44 const std::string vector4d_type = #TYPE ; 46 #define DEFVECTOR3D(TYPE) \ 47 typedef TYPE AVector3D; \ 48 const std::string vector3d_type = #TYPE ; 50 #define DEFPOINT3D(TYPE) \ 51 typedef TYPE APoint3D; \ 52 const std::string point3d_type = #TYPE ; 57 const double tol = 1.0E-6;
71 template<
class Vector>
106 v.
SetXYZT(x[0],x[1],x[2],x[3]);
113 v.
SetXYZT(x[0],x[1],x[2],x[3]);
117 template <
class Vector>
129 for (
int i = 0; i <
n; ++i) {
133 p[3] = R.
Gaus(100,10);
142 std::cout <<
" Time for Random gen " << timer.
RealTime() <<
" " << timer.
CpuTime() << std::endl;
143 int pr = std::cout.precision(18); std::cout <<
"Average : " << sav << std::endl; std::cout.precision(pr);
152 template<
class Vector>
153 double write(
int n,
const std::string & file_name,
const std::string & vector_type,
int compress = 0) {
159 std::cout <<
"writing a tree with " << vector_type << std::endl;
161 std::string fname = file_name +
".root";
162 TFile f1(fname.c_str(),
"RECREATE",
"",compress);
165 std::string tree_name=
"Tree with" + vector_type;
166 TTree t1(
"t1",tree_name.c_str());
168 Vector *v1 =
new Vector();
169 std::cout <<
"typeID written : " <<
typeid(*v1).name() << std::endl;
171 t1.Branch(
"Vector branch",vector_type.c_str(),&v1);
176 for (
int i = 0; i <
n; ++i) {
180 p[3] = R.
Gaus(100,10);
196 std::cout <<
" Time for Writing " << file_name <<
"\t: " << timer.
RealTime() <<
" " << timer.
CpuTime() << std::endl;
197 int pr = std::cout.precision(18); std::cout <<
"Average : " << sav << std::endl; std::cout.precision(pr);
208 template<
class Vector>
209 double read(
const std::string & file_name) {
213 std::string fname = file_name +
".root";
217 std::cout <<
" Error opening file " << file_name << std::endl;
228 std::cout <<
"reading typeID : " <<
typeid(*v1).name() << std::endl;
234 std::cout <<
" Tree Entries " << n << std::endl;
236 for (
int i = 0; i <
n; ++i) {
247 std::cout <<
" Time for Reading " << file_name <<
"\t: " << timer.
RealTime() <<
" " << timer.
CpuTime() << std::endl;
248 int pr = std::cout.precision(18); std::cout <<
"Average : " << sav << std::endl; std::cout.precision(pr);
254 template<
class TrackType>
255 double writeTrack(
int n,
const std::string & file_name,
int compress = 0) {
258 std::cout <<
" Test writing .." << file_name <<
" .....\n";
259 std::cout <<
"**************************************************\n";
267 std::string fname = file_name +
".root";
268 TFile f1(fname.c_str(),
"RECREATE",
"",compress);
271 std::string tree_name=
"Tree with TrackD";
272 TTree t1(
"t1",tree_name.c_str());
274 TrackType *track =
new TrackType();
275 std::cout <<
"typeID written : " <<
typeid(*track).name() << std::endl;
280 t1.Branch(
"Vector branch",&track);
286 typedef typename TrackType::VectorType V;
287 typedef typename TrackType::PointType
P;
289 for (
int i = 0; i <
n; ++i) {
296 track->Set( V(q),
P(p) );
310 std::cout <<
" Time for Writing " << file_name <<
"\t: " << timer.
RealTime() <<
" " << timer.
CpuTime() << std::endl;
311 int pr = std::cout.precision(18); std::cout <<
"Average : " << sav << std::endl; std::cout.precision(pr);
323 std::cout << w1 <<
" r " << r1 << std::endl;
326 std::cout <<
"\nERROR: Differeces found when reading " << std::endl;
327 int pr = std::cout.precision(18); std::cout << w1 <<
" != " << r1 << std::endl; std::cout.precision(pr);
331 std::cout <<
"\n*********************************************************************************************\n";
332 std::cout <<
"Test :\t " << type <<
"\t\t";
334 std::cout <<
"OK" << std::endl;
336 std::cout <<
"FAILED" << std::endl;
337 std::cout <<
"********************************************************************************************\n\n";
361 std::cout <<
"Use Reflex dictionary " << std::endl;
366 ROOT::Cintex::Cintex::SetDebug(1);
367 ROOT::Cintex::Cintex::Enable();
375 std::cerr <<
"Failing to Load Reflex dictionaries " << std::endl;
379 #endif // endif on using reflex 390 fname =
"lorentzvector";
392 w1 = 98.995527276968474;
396 w1 = write<AVector4D>(
nEvents,fname,vector4d_type);
398 r1 = read<AVector4D>(fname);
401 fname =
"displacementvector";
403 w1 = 17.3281570633214095;
407 w1 = write<AVector3D>(
nEvents,fname,vector3d_type);
409 r1 = read<AVector3D>(fname);
412 fname =
"positionvector";
416 w1 = write<APoint3D>(
nEvents,fname,point3d_type);
418 r1 = read<APoint3D>(fname);
433 w1 = writeTrack<TrackD>(
nEvents,fname);
435 r1 = read<TrackD>(fname);
448 w1 = writeTrack<TrackD32>(
nEvents,fname);
450 r1 = read<TrackD32>(fname);
463 w1 = writeTrack<VecTrackD>(
nEvents,fname);
465 r1 = read<VecTrackD>(fname);
477 w1 = writeTrack<ClusterD>(
nEvents,fname);
479 r1 = read<ClusterD>(fname);
487 bool readOnly =
false;
488 if (argc > 1) readOnly =
true;
492 std::cerr <<
"testVectorIO:\t FAILED ! " << std::endl;
494 std::cerr <<
"testVectorIO:\t OK ! " << std::endl;
virtual Int_t Write(const char *name=0, Int_t option=0, Int_t bufsize=0)
Write this object to the current directory.
double read(const std::string &file_name)
reading
Class describing a generic LorentzVector in the 4D space-time, using the specified coordinate system ...
virtual void Print(Option_t *option="") const
Dump this text with its attributes.
Random number generator class based on M.
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.
DisplacementVector3D< CoordSystem, Tag > & SetXYZ(Scalar a, Scalar b, Scalar c)
set the values of the vector from the cartesian components (x,y,z) (if the vector is held in polar or...
double write(int n, const std::string &file_name, const std::string &vector_type, int compress=0)
writing
virtual Double_t Gaus(Double_t mean=0, Double_t sigma=1)
Samples a random number from the standard Normal (Gaussian) Distribution with the given mean and sigm...
A ROOT file is a suite of consecutive data records (TKey instances) with a well defined format...
Class describing a generic position vector (point) in 3 dimensions.
virtual Int_t GetEntry(Long64_t entry=0, Int_t getall=0)
Read all branches of entry and return total number of bytes read.
virtual int Load(const char *module, const char *entry="", Bool_t system=kFALSE)
Load a shared library.
Double_t CpuTime()
Stop the stopwatch (if it is running) and return the cputime (in seconds) passed between the start an...
double writeTrack(int n, const std::string &file_name, int compress=0)
LorentzVector< CoordSystem > & SetXYZT(Scalar xx, Scalar yy, Scalar zz, Scalar tt)
set the values of the vector from the cartesian components (x,y,z,t) (if the vector is held in anothe...
void Stop()
Stop the stopwatch.
virtual Int_t SetBranchAddress(const char *bname, void *add, TBranch **ptr=0)
Change branch address, dealing with clone trees properly.
void SetXYZ(Double_t x, Double_t y, Double_t z)
int testVectorIO(bool readOnly=false)
TVector3 is a general three vector class, which can be used for the description of different vectors ...
Class describing a generic displacement vector in 3 dimensions.
VecExpr< UnaryOp< Fabs< T >, VecExpr< A, T, D >, T >, T, D > fabs(const VecExpr< A, T, D > &rhs)
TLorentzVector is a general four-vector class, which can be used either for the description of positi...
R__EXTERN TSystem * gSystem
void SetXYZT(Double_t x, Double_t y, Double_t z, Double_t t)
int testResult(double w1, double r1, const std::string &type)
unsigned int r1[N_CITIES]
virtual Long64_t GetEntries() const
#define DEFVECTOR4D(TYPE)
PositionVector3D< CoordSystem, Tag > & SetXYZ(Scalar a, Scalar b, Scalar c)
set the values of the vector from the cartesian components (x,y,z) (if the vector is held in polar or...
int main(int argc, char **)
#define DEFVECTOR3D(TYPE)
void setValues(ROOT::Math::DisplacementVector3D< U > &v, const double x[])
A TTree object has a header with a name and a title.
double getMag2(const Vector &v)