La présentation est en train de télécharger. S'il vous plaît, attendez

La présentation est en train de télécharger. S'il vous plaît, attendez

Python + ROOT = pyROOT ● Manipulation des I/O ● Manipulation des strings ● Pas besoin de s'embêter avec les '.', ou '→', ou d'utiliser des 'new'.. ● Les.

Présentations similaires


Présentation au sujet: "Python + ROOT = pyROOT ● Manipulation des I/O ● Manipulation des strings ● Pas besoin de s'embêter avec les '.', ou '→', ou d'utiliser des 'new'.. ● Les."— Transcription de la présentation:

1 Python + ROOT = pyROOT ● Manipulation des I/O ● Manipulation des strings ● Pas besoin de s'embêter avec les '.', ou '→', ou d'utiliser des 'new'.. ● Les Tcollections ou Ttrees sont plus faciles à manipuler dans Python. ● Complétion et rappel des commandes avec iPython ● Python Shall Not Crash. Period. ● Plus lent que CINT (ou c++ compilé) notamment dans les boucles ● Pas de pointeurs (c'est grave?) ● Compatibilité entre les librairies si on n'a pas compilé ROOT depuis le source.

2 Comment faire marcher pyROOT D'abord s'assurer que Python puisse voir ROOT: export PYTHONPATH=$ROOTSYS/lib:$PYTHONPATH (bash) setenv PYTHONPATH $ROOTSYS/lib:$PYTHONPATH (csh) Puis s'assurer que ROOT puisse voir Python: export LD_LIBRARY_PATH=$ROOTSYS/lib:$PYTHONDIR/lib:$LD_LIBRARY_PATH Puis tester si ROOT ou ses modules sont importables: #!/bin/env python # importer EXPLICITEMENT les modules ROOT utilisées from ROOT import gROOT, TCanvas, TF1 gROOT.Reset() c1 = TCanvas('c1', 'Example de Formule', 200, 10, 700, 500)

3 Je prefere personnellement l'approche suivante, utile quand on importe plusieurs modules: #!/bin/env python # importer ROOT import ROOT ROOT.gROOT.Reset() c1 = ROOT.TCanvas('c1', 'Exemple de Formule', 200, 10, 700, 500) # fabriquer la fonction func1 = ROOT.TF1('func1', 'abs(sin(x)/x)', 0, 10) c1.SetGridx() c1.SetGridy() # dessiner la fonction func1.Draw() c1.Update() Beaucoup de scripts marchent 'clefs en main' dans $ROOTSYS/tutorials/pyroot Lisez puis utilisez fillrandom.py puis fit1.py

4 Le fichier flare.qdp contient 5 colonnes numériques, il faut ignorer les 3 premières lignes et plotter 4 colonnes (intensité versus énergie) # energie, resolution energie, intensité, erreur intensité, dummy import ROOT import array myfile= open('file.qdp','r') lines= myfile.readlines() print lines ilen= len(lines) print ilen v_ener= [array.array('f',ilen*[0]),array.array('f',ilen*[0]) ] v_flux= [ array.array('f',ilen*[0],array.array('f',ilen*[0]) ] print v_ener print v_ener[0] Lire un fichier texte en colonnes

5 i= 0 for line in lines[3:]: words= string.split(line) row= map(float,words) v_ener[0][i]= row[0]*1000 v_ener[1][i]= row[1]*1000 v_flux[0][i]= row[2]/6.25e8 v_flux[1][i]= row[3]/6.25e8 i= i+1 tgr= ROOT.TGraphErrors( ilen,v_ener[0],v_flux[0],v_ener[1],v_flux[1] ) mgr=ROOT.TH2F('mgr','myplot',1000,2,1e3,500,1e-13,1e-8) mgr.SetXTitle('Energy [eV]') mgr.SetYTitle('#nuF_{#nu} [erg cm^{-2} s^{-1}]') mgr.Draw() tgr.SetLineColor(30) tgr.SetMarkerStyle(20) tgr.SetMarkerColor(30) tgr.SetUniqueID(1) tgr.Draw('pz') #ecrire tgr dans un fichier.root

6 Lire un fichier format CSV Beaucoup de d'outils permettent un 'dump' des bases de données dans des formats divers (csv,txt,html,xls..). Le comma separated values (csv) peut être facilement lu dans python grâce à import csv Exemple sur le fichier tevcatable.csv

7 import array import ROOT import sys,string import math import csv a_date,a_num = array.array('f'),array.array('f') names= [] f_h = csv.reader(open("tevcatable.csv"),delimiter=',', quotechar='|') for row in f_h: print row[0],row[4] a_date.append(string.atof(row[4][6:])+( string.atof(row[4][0:2])/12.) ) a_num.append( len(a_date) ) names.append(ROOT.TText(string.atof(row[4][6:])+( string.atof(row[4][0:2])/12.)+0.2,len(a_date),row[0])) hh1= ROOT.TH2F('hh1','',100,1991,2012,100,0,35) hh1.SetXTitle('Année de découverte') hh1.SetYTitle('Nombre de sources') tg1= ROOT.TGraph(len(a_num),a_date,a_num) tg1.SetMarkerStyle(20) hh1.Draw() tg1.Draw('pzl') for i in xrange(len(names)): names[i].SetTextSize(0.02) names[i].Draw()

8 Extraire les points du graphe.root myfile= ROOT.TFile("myfile.root") c1= myfile.Get("c1") c1_1= c1.GetPrimitive("c1_1") c1_1.cd() tg= c1_1.GetPrimitive("Graph"); x = tg.GetX() y = tg.GetY() ex= tg.GetEX() ey= tg.GetEY()

9 Quelques sites utiles ● http://wlav.home.cern.ch/wlav/pyroot Le site de Wim Lavrijsen (très dispo quand on a lu la FAQ) http://wlav.home.cern.ch/wlav/pyroot ● http://root.cern.ch/drupal/content/how-use-use- python-pyroot-interpreter ● http://www.scipy.org/SciPy http://www.scipy.org/SciPy ● http://polywww.in2p3.fr/~berrie/PAWtopyROOT. html


Télécharger ppt "Python + ROOT = pyROOT ● Manipulation des I/O ● Manipulation des strings ● Pas besoin de s'embêter avec les '.', ou '→', ou d'utiliser des 'new'.. ● Les."

Présentations similaires


Annonces Google