Skip to content

Instantly share code, notes, and snippets.

@musinsky musinsky/README.md
Last active Nov 21, 2016

Embed
What would you like to do?
ROOT Tips Tricks

ROOT Tips Tricks

// Author: Jan Musinsky
// 14/10/2014
#include <TMath.h>
void float_double()
{
Float_t fmin = TMath::Limits<Float_t>::Min();
Float_t fmax = TMath::Limits<Float_t>::Max();
Float_t feps = TMath::Limits<Float_t>::Epsilon();
Double_t dmin = TMath::Limits<Double_t>::Min();
Double_t dmax = TMath::Limits<Double_t>::Max();
Double_t deps = TMath::Limits<Double_t>::Epsilon();
Float_t f1 = 1234567890123456789012345.1234567890123456789012345;
Float_t f2 = 1234567890123456789012345.0;
Float_t f3 = 0.1234567890123456789012345;
Float_t fi = 1234567890123456789012345;
Double_t d1 = 1234567890123456789012345.1234567890123456789012345;
Double_t d2 = 1234567890123456789012345.0;
Double_t d3 = 0.1234567890123456789012345;
Double_t di = 1234567890123456789012345;
printf("float min = %g\n", fmin);
printf("float max = %g\n", fmax);
printf("double min = %g\n", dmin);
printf("double max = %g\n", dmax);
printf("float epsilon = %.60f => %g\n", feps, feps);
printf("double epsilon = %.60f => %g\n", deps, deps);
printf("\n\n");
printf("number 1234567890123456789012345.1234567890123456789012345\n");
printf("as float %f => %g\n", f1, f1);
printf("as double %f => %g\n", d1, d1);
printf("\n");
printf("number 1234567890123456789012345.0\n");
printf("as float %f => %g\n", f2, f2);
printf("as double %f => %g\n", d2, d2);
printf("\n");
printf("number 0.1234567890123456789012345\n");
printf("as float %.60f => %g\n", f3, f3);
printf("as double %.60f => %g\n", d3, d3);
printf("\n");
printf("number 1234567890123456789012345 (no decimal)\n");
printf("as float %f => %g\n", fi, fi);
printf("as double %f => %g\n", di, di);
Float_t fbig = 9.123e+22;
Double_t dbig = 9.123e+22;
printf("\n");
printf("number 9.123e+22\n");
printf("as float %f => %g\n", fbig, fbig);
printf("as double %f => %g\n", dbig, dbig);
Float_t fbig2 = 9.123e+40;
Double_t dbig2 = 9.123e+40;
printf("\n");
printf("number 9.123e+40\n");
printf("as float %f => %g\n", fbig2, fbig2);
printf("as double %f => %g\n", dbig2, dbig2);
Float_t fsmall = 9.123e-10;
Double_t dsmall = 9.123e-10;
printf("\n");
printf("number 9.123e-10\n");
printf("as float %.60f => %g\n", fsmall, fsmall);
printf("as double %.60f => %g\n", dsmall, dsmall);
Float_t fsmall2 = 9.123e-50;
Double_t dsmall2 = 9.123e-50;
printf("\n");
printf("number 9.123e-50\n");
printf("as float %.60f => %g\n", fsmall2, fsmall2);
printf("as double %.60f => %g\n", dsmall2, dsmall2);
}
// 2016-11-21
{
Int_t delay = 500;
TGraph *g = new TGraph(100);
g->SetMarkerStyle(8);
g->Draw("AP");
gPad->SetGridx();
gPad->Modified();
gPad->Update();
TDatime dt;
gStyle->SetTimeOffset(dt.Convert());
for (Int_t i = 0; i < g->GetN(); i++) {
dt.Set();
g->SetPoint(i, dt.Convert() - gStyle->GetTimeOffset(), i%5);
Printf("%f", dt.Convert() - gStyle->GetTimeOffset());
g->GetXaxis()->SetTimeDisplay(1);
g->GetXaxis()->SetTimeFormat("%H:%M:%S");
g->GetXaxis()->SetNdivisions(407);
gPad->Modified();
gPad->Update();
gSystem->Sleep(delay);
}
}
// How to write a Tree in one process and view it from another process
// https://root.cern.ch/root/html/TTree.html#TTree:AutoSave
// https://root.cern.ch/phpBB3/viewtopic.php?f=3&t=19051
// root.cern.ch/files/fw.C
#include "TFile.h"
#include "TH1F.h"
#include "TPad.h"
void writer()
{
TFile *f = new TFile("test.root", "RECREATE");
TH1F *h = new TH1F("h", "h", 100, -3., 3.);
f->Write(0, TObject::kWriteDelete); // ??? WHY ???
Int_t count = 0;
while(kTRUE) {
printf("Loop %d\r", count++);
fflush(stdout);
h->FillRandom("gaus", 100);
h->Write(0, TObject::kWriteDelete);
f->SaveSelf();
sleep(1);
}
}
void reading(TFile *f, const char *name = "h")
{
f->ReadKeys();
delete f->FindObject(name);
TH1F *h; f->GetObject(name, h);
h->Draw();
gPad->Update();
gPad->Modified();
}
// []$ root
// root [0] .L rw.C+
// root [1] writer()
// []$ root
// root [0] .L rw.C+
// root [1] TFile *f = TFile::Open("test.root", "READ");
// root [2] while(kTRUE) { reading(f); gSystem->Sleep(1000); }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.