Introduzione all'utilizzo di ROOTpiano/courses/pdffile/lezione_root_vme.pdf · [1] Convert the...

Post on 22-Mar-2020

4 views 0 download

Transcript of Introduzione all'utilizzo di ROOTpiano/courses/pdffile/lezione_root_vme.pdf · [1] Convert the...

Introduzione all'utilizzo di ROOT

Stefano Piano

maggio/giugno 2007

Lezioni del corso di Laboratorio di Acquisizione e Controllo Dati

Premessa: software in fisica

✵ Simulazione (eventi fisici, rivelatore);

✵ (Controllo remoto, Controlli lenti);

✵ Acquisizione dei dati (protocolli,...);

✵ Memorizzazione dei dati (formato, supporti,...);

✵ Analisi dei dati (ricostruzione eventi,...);

✵ Riduzione dei dati (spettri, sezioni d'urto,masse invarianti, vite medie,...);

✵ Presentazione dei risultati (istogrammi, grafici,...).

Premessa: software dedicati

✵ Pacchetti software dedicati all'acquisizione dei dati (MIDAS, LabView), alla simulazione del rivelatore e della fisica (GEANT3/4, FLUKA, PYTHIA), all'analisi dei dati (YBOS, FIDARC), alla riduzione e presentazione dei dati (Physica, PAW) -> Necessita' di interfacce di comunicazione

✵ YBOS, FIDARC, PAW e GEANT, ad esempio, sono scritti in Fortran, MIDAS in C -> Parlano lingue diverse!

Cos'e' ROOT?

ROOT offre un contesto di programmazione adatto a tutte le necessita' dello sviluppatore

Un Framework fornisce “utilities” e servizi

ROOT's Services/Utilities

Histogramming and Fitting Graphics (2D, 3D) I/O to file or socket: specialized for histograms,

Ntuples (Trees) Collection Classes and Run Time Type

Identification User Interface

GUI: Browsers, Panels, Tree Viewer Command Line interface: C++ interpreter CINT Script Processor (C++ compiled ⇔ C++ interpreted)

Com'e' strutturato ROOT

Programmazione orientata agli oggetti (C++);

ROOT permette di gestire (acquisire, memorizzare, analizzare) grandi quantita'di dati (dell'ordine delle migliaia di Tbytes) in modo efficiente;

Filosofia "Open system" -> ROOT puo' essere esteso tramite link a librerie esterne;

Interprete CINT C++ permette di utilizzare C++ come scripting language -> flessibilita'.

Com'e' strutturato ROOT

*.h...

cintmakecintnewproofdproofservrmkdependrootroot.exerootcintroot-configrootd

bin

$ROOTSYS

libCint.solibCore.solibEG.so*libEGPythia.so*libEGPythia6.solibEGVenus.solibGpad.solibGraf.solibGraf3d.solibGui.solibGX11.so*libGX11TTF.solibHist.solibHistPainter.solibHtml.solibMatrix.solibMinuit.solibNew.solibPhysics.solibPostscript.solibProof.so*libRFIO.so*libRGL.solibRint.so*libThread.solibTree.solibTreePlayer.solibTreeViewer.so*libttf.solibX3d.solibXpm.a

Aclock.cxxAclock.hEvent.cxxEvent.hEventLinkDef.hHello.cxxHello.hMainEvent.cxxMakefileMakefile.inMakefile.win32READMETestVectors.cxxTetris.cxxTetris.heventa.cxxeventb.cxxeventload.cxxguitest.cxxhsimple.cxxhworld.cxxminexam.cxxstress.cxxtcollbm.cxxtcollex.cxxtest2html.cxxtstring.cxxvlazy.cxxvmatrix.cxxvvector.cxx

lib testtutorials include

* OptionalInstallation

EditorBar.CIfit.Canalyze.Carchi.Carrow.Cbasic.Cbasic.datbasic3d.Cbenchmarks.Ccanvas.Cclasscat.Ccleanup.Ccompile.Ccopytree.Ccopytree2.Cdemos.Cdemoshelp.Cdialogs.Cdirs.Cellipse.Ceval.Cevent.Cexec1.Cexec2.Cfeynman.Cfildir.Cfile.Cfillrandom.Cfirst.Cfit1.Cfit1_C.C

fitslicesy.Cformula1.Cframework.Cgames.Cgaxis.Cgeometry.Cgerrors.Cgerrors2.Cgraph.Ch1draw.Chadd.Chclient.Chcons.Chprod.Chserv.Chserv2.Chsimple.Chsum.ChsumTimer.Chtmlex.Cio.Clatex.Clatex2.Clatex3.Cmanyaxis.Cmultifit.Cmyfit.Cna49.Cna49geomfile.Cna49view.Cna49visible.C

ntuple1.Coldbenchmarks.Cpdg.datpsexam.Cpstable.Crootalias.Crootenv.Crootlogoff.Crootlogon.Crootmarks.Cruncatalog.sqlrunzdemo.Csecond.Cshapes.Cshared.Csplines.Csqlcreatedb.Csqlfilldb.Csqlselect.Cstaff.Cstaff.datsurfaces.Ctcl.Ctestrandom.Ctornado.Ctree.Ctwo.Cxyslider.CxysliderAction.Czdemo.C

Evoluzione verso OO

Programmazione non strutturata

Programmazione procedurale

Programmazione modulare Programmazione orientata agli oggetti

Concetti di “Object Oriented”

Membri: una relazione del tipo: la classe “ha un”

Ereditarietà: una relazione del tipo la classe “è un”

Classe: la descrizione di una “cosa” nel sistema Oggetto: l’istanza di una classe Metodi: le funzioni di una classe

Event

TrackSegment Vertex

Momentum MassSquare InterceptAtVert

HAS AHAS AHAS A

HAS A HAS AHAS A

TObject

IS A

Esempio: AliRoot

Links

http://root.cern.chhttp://root.cern.ch/root/Tutorials.htmlhttp://root.cern.ch/root/Howto.html

http://root.cern.ch/root/Reference.html

/home/stefano/root/2007/Users_Guide_5_14_TwoInOne.pdf

Preparazione ambiente di lavoro

1) Apro un terminale sul computer linux: xterm, kterm2) Lancio un editor per modificare il .bash_profile: emacs .bash_profileexport ROOTSYS=/usr/local/rootexport LD_LIBRARY_PATH=$LD_LIBRARY_PATH:$ROOTSYS/libexport PATH=$PATH:$ROOTSYS/bin3) Riapro un terminale e controllo con: echo $ROOTSYS echo $LD_LIBRARY_PATH echo $PATH che vi siano tutte le variabili d’ambiente !!!4) Lancio nel terminale il comando “root” controllo le mie variabili d’ambiente con

root[] gEnv->Print()

Tre Interfacce Utente

• GUI:windows, buttons, menus

• Root Command line:CINT (C++ interpreter)

• Macros, applications, libraries (C++ compiler and interpreter)

Hello World

1) Inizio una sessione di root dal prompt unix prompt> root

2) Dichiaro l'oggetto "hello" di classe "TPaveLabel" root> TPaveLabel hello(0.2,0.4,0.8,0.8,"Hello World");

3) Utilizzo il metodo "Draw" della classe "TPaveLabel" root> hello.Draw();

Grafica in ROOT

{ gROOT->Reset(); c1 = new Tcanvas("c1","The ROOT Framework",200,10,700,500); c1->Range(0,0,19,12); // TPavesText rootf(0.4,0.6,18,2.3,20,"tr"); rootf.AddText("ROOT Framework"); rootf.SetFillColor(42); rootf.Draw(); // TPavesText eventg(0.99,2.66,3.29,5.67,4,"tr"); eventg.SetFillColor(38); eventg.AddText("Event"); eventg.AddText("Generators"); eventg.Draw(); // TPavesText simul(3.62,2.71,6.15,7.96,7,"tr"); simul.SetFillColor(41); simul.AddText("Detector"); simul.AddText("Simulation"); simul.Draw(); // ... /// c1->Update();} Macro framework.C in $ROOTSYS/tutorials

C++ Basics for ROOT USERS

Variables, Arithmetic and Assignment Expressions, Simple Output

root [0] Int_t a;

root [1] a = 3 * 5;

root [2] cout << a << endl;

[0] Declare a variable a of type Int_t

[1] Compute 3*5 and set the value of variable a to the result

[2] Print the value of variable a to the terminal. cout is the name of the

standard output stream (in our case the terminal). The operator <<

passes the value of variable a converted to a string to cout. After that

the endline character endl is passed to cout to enforce the output.

C++ Basics for ROOT USERS

C++ Fundamental Types

*C++ type* *Size (bytes)* *ROOT types* *Size (bytes)* *FORTRAN*

(unsigned)char 1 (U)Char_t 1 CHARACTER*1

(unsigned)short (int) 2 (U)Short_t 2 INTEGER*2

(unsigned)int 2 or 4 (U)Int_t 4 INTEGER*4

(unsigned)long (int) 4 or 8 (U)Long_t 8 INTEGER*8

float 4 Float_t 4 REAL*4

double 8 (>=4) Double_t 8 REAL*8

long double 16 (>= double) REAL*16

see http://root.cern.ch/root/html/ListOfTypes.html for a complete list

C++ Basics for ROOT USERS

Variables, Arithmetic and Assignment Expressions, Simple Output

root [0] Int_t a;

root [1] a = 3 * 5;

root [2] cout << a << endl;

[0] Declare a variable a of type Int_t

[1] Compute 3*5 and set the value of variable a to the result

[2] Print the value of variable a to the terminal. cout is the name of the

standard output stream (in our case the terminal). The operator <<

passes the value of variable a converted to a string to cout. After that

the endline character endl is passed to cout to enforce the output.

C++ Basics for ROOT USERS

Example:root [0] Int_t a;root [1] a = 5.1;root [2] cout << "a = " << a << endl;a = 5root [3] Double_t b;root [4] b = 5.1;root [5] cout << "b = " << b << endl;b = 5.1[1] Convert the floating point value 5.1 to integer and set the value of ato the result[2] Send first the string "a = ", second the value of a, third the endlinecharacter to cout[3] Declare a floating point variable b;[4] Set b to 5.1

C++ Basics for ROOT USERS

Arithmetic and Assignment Operators*C++* *Purpose* *FORTRAN*x++ Postincrement ++x Preincrement x-- Postdecrement --x Predecrement +x Unary plus +X-x Unary minus -Xx*y Multiply X*Yx/y Divide X/Yx%y Modulus MOD(X,Y)x+y Add X+Yx-y Subtract X-Ypow(x,y) or TMath::Power(x,y) Exp. X**Y (FORTRAN and CINT)x = y Assignment X = Yx += y Updating assignment X = X+Yx -= ,*= ,/=,%=,…,Y X=X-Y,X=X*Y,...

C++ Basics for ROOT USERS

With the exception of the increment/decrement and the updating assignment

operators the arithmetic is pretty much like in Fortran

Preincrement/decrement means 1. add/subtract one 2. use the variable

Postincrement/decrement means 1. use the variable 2. add/subtract one

try:

int i;

i = 0;

cout << i++ << endl;

cout << i << end;

cout << ++i << endl; Updating assignment i=i+x; could be written

C++ Basics for ROOT USERS

Functions

root [0] Double_t x=1.3, y;

root [1] y = TMath::Erfc(x)

(Double_t)6.59920503287388940e-02

root [2] TMath::Sin(TMath::Pi())

(Double_t)1.22464679914735320e-16

[0] Declare floating point variables x and y, initialize x to 1.3

[1] Set y to the result of the function TMath::Erfc(x). There is no

semicolon, therefore print the result to the terminal

[2] Compute the value of sin(pi), no semicolon, output to terminal

C++ Basics for ROOT USERS

Loop

root [0] Int_t sum = 0;

root [1] for(Int_t i=0; i<10; i++) sum +=i;

root [2] sum

(Int_t)45

[1] The classical counting loop

init_expression: declare i and initialize it to zero

cont_expression: continue if i is less than 10

incr_expression: increment i by one

C++ Basics for ROOT USERS

The for loop is semantically equivalent to:

init_expression;

while (cont_expression) {

statement

incr_expression;

}

All expressions in the for loop are optional, i.e

for(;;) { statements }

is an endless loop. It could be ended by a break statement.

C++ Basics for ROOT USERS

Control Statements (IF)

if (result >= 75) {

printf("Passed: Grade A\n");

} else if (result >= 60) {

printf("Passed: Grade B\n");

} else if (result >= 45) {

printf("Passed: Grade C\n");

} else {

printf("Failed\n");

}

C++ Basics for ROOT USERS

Control Statements (SWITCH)

estimate(number)

int number;

{ switch(number) {

case 0 :

printf("None\n");

break;

case 1 :

printf("One\n");

break;

default :

printf("Many\n");

break;

}

}

C++ Basics for ROOT USERS

Logical Values and Operators, Relational Operators

*C++* *ROOT extension* *Purpose* *FORTRAN*

false or 0 kFALSE False value .FALSE.

true or nonzero kTRUE True value .TRUE.

!x Logical negation .NOT.X

x && y Logical and X .AND. Y

x || y Logical or X .OR. Y

x < y Less than X. LT. Y

x <= y Less than or equal X. LE. Y

x > y Greater than X. GT. Y

x >= y Greater than or equal X .GE. Y

x == y Equal X. EQ. Y

x != y Not equal X. NE. Y

C++ Basics for ROOT USERS

VECTORS AND MATRIX (and pointers ...)

Int_t test[10];

test[0] = 0; ...; test[9] = 0;

Int_t test[10] = {0};

Double_t matrtest[10][3];

test ? Int_t * test; ==> test is equal to &test[0];

Int_t prova; Int_t * puntprova;

puntprova = & prova;

* puntprova = 10 ;

cout << prova << endl ;

Istogrammi I

{ gROOT->Reset();

c1 = new Tcanvas("c1","The HSUM example",200,10,600,400); c1->SetGrid();

gBenchmark->Start("hsum");

// Create some histograms. total = new TH1F("total","This is the total distribution",100,-

4,4); main = new TH1F("main","Main contributor",100,-4,4); s1 = new TH1F("s1","This is the first signal",100,-4,4); s2 = new TH1F("s2","This is the second signal",100,-4,4); total->Sumw2(); total->SetMarkerStyle(21); total->SetMarkerSize(0.7); main->SetFillColor(16); s1->SetFillColor(42); s2->SetFillColor(46); TSlider *slider = 0;

// Fill histograms randomly gRandom->SetSeed(); const Int_t kUPDATE = 500; Float_t xs1, xs2, xmain;

for ( Int_t i=0; i<10000; i++) { xmain = gRandom->Gaus(-1,1.5); xs1 = gRandom->Gaus(-0.5,0.5); xs2 = gRandom->Landau(1,0.15);

main->Fill(xmain); s1->Fill(xs1,0.3); s2->Fill(xs2,0.2); total->Fill(xmain); total->Fill(xs1,0.3); total->Fill(xs2,0.2); if (i && (i%kUPDATE) == 0) { if (i == kUPDATE) { total->Draw("e1p"); main->Draw("same"); s1->Draw("same"); s2->Draw("same"); c1->Update(); slider = new TSlider("slider", "test",4.2,0,4.6,total->GetMaximum(),38); slider->SetFillColor(46); } if (slider) slider->SetRange(0,Float_t(i)/10000.); c1->Modified(); c1->Update(); } } slider->SetRange(0,1); total->Draw("sameaxis"); // to redraw axis hidden // by the fill area c1->Modified(); gBenchmark->Show("hsum");}

Macro hsum.C in /home/stefano/root/2006/

Istogrammi II

Funzioni e Formule

{ // gROOT->Reset(); c1 = new TCanvas("c1","Example with

Formula",200,10,700,500); // // Create a one dimensional function and draw

it // fun1 = new TF1("fun1","abs(sin(x)/x)",0,10); c1->SetGridx(); c1->SetGridy(); fun1->Draw(); c1->Update(); // // Before leaving this demo, we print the

list // of objects known to ROOT // if (gObjectTable) gObjectTable->Print();}

Macro /home/stefano/root/2006/formula1.C

Funzioni, Formule e Istogrammi

{ // … // A function (any dimension) or a formula

may reference // an already defined formula // form1 = new

TFormula("form1","abs(sin(x)/x)"); sqroot = new TF1("sqroot","x*gaus(0) +

[3]*form1",0,10); sqroot->SetParameters(10,4,1,20); pad1->SetGridx(); pad1->SetGridy(); pad1->GetFrame()->SetFillColor(42); pad1->GetFrame()->SetBorderMode(-1); pad1->GetFrame()->SetBorderSize(5); sqroot->SetLineColor(4); sqroot->SetLineWidth(6); sqroot->Draw(); lfunction = new TPaveLabel(5,39,9.8,46,"The

sqroot function"); lfunction->SetFillColor(41); lfunction->Draw(); c1->Update();

Macro /home/stefano/root/2006/fillrandom.C

// // Create a one dimensional histogram (one float per bin) // and fill it following the distribution in function sqroot. // pad2->cd(); pad2->GetFrame()->SetFillColor(42); pad2->GetFrame()->SetBorderMode(-1); pad2->GetFrame()->SetBorderSize(5); h1f = new TH1F("h1f","Test random numbers",200,0,10); h1f->SetFillColor(45); h1f->FillRandom("sqroot",10000); h1f->Draw(); c1->Update(); // // Open a ROOT file and save the formula, function and histogram // TFile myfile("fillrandom.root","RECREATE"); form1->Write(); sqroot->Write(); h1f->Write(); myfile.Close(); gBenchmark->Show("fillrandom");}

Funzioni, Formule e Istogrammi

Macro /home/stefano/root/2006/fillrandom.C

Funzioni, Istogrammi e Fit

Macro /home/stefano/root/2006/multifit.C

Funzioni, Istogrammi e Fit

Macro /home/stefano/root/2006/multifit.C

Funzioni, Istogrammi e Fit

Macro /home/stefano/root/2006/multifit.C

Funzioni, Istogrammi e Fit

Macro /home/stefano/root/2006/multifit.C

{//… h = new TH1F("h","Example of several fits in subranges",np,85,134); h->SetMaximum(7);

for (int i=0;i<np;i++) { h->SetBinContent(i+1,x[i]); }

Double_t par[9]; g1 = new TF1("g1","gaus",85,95); g2 = new TF1("g2","gaus",98,108); g3 = new TF1("g3","gaus",110,121); total = new TF1("total","gaus(0)+gaus(3)+gaus(6)",85,125); total->SetLineColor(2); h->Fit(g1,"R"); h->Fit(g2,"R+"); h->Fit(g3,"R+"); g1->GetParameters(&par[0]); g2->GetParameters(&par[3]); g3->GetParameters(&par[6]); total->SetParameters(par); h->Fit(total,"R+");}

Lettura dati (ascii ) in C++

#include "Riostream.h"

// …

ifstream in;

in.open("run_1.dat");

Float_t a1,a2,a3, a4, t1,t2,t3, t4;

Int_t nlines = 0;

while (1) {

in >> a1 >> a2 >> a3 >> a4 >> t1 >> t2 >> t3 >> t4 ;

if (!in.good()) break;

if (nlines < 5) cout << a1 << a2 << a3 << a4 << t1 << t2 << t3 << t4 << endl;

h1->Fill(a1);

ntuple->Fill(a1,a2,a3,a4,t1,t2,t3,t4);

nlines++;

}

cout << " found “<< nlines << “ points” << endl;

in.close(); // ... ...

Macro /home/stefano/root/2006/basic.C

Riduzione dati: Ntupla

in.open(“run_1.dat”);

Float_t a1,a2,a3, a4, t1,t2,t3, t4; Int_t nlines = 0; TFile *f = new TFile(“run_1.root”,”RECREATE”); TH1F *h1 = new TH1F(“h1”,”ADC1 distribution”,255,-0.5,254.5); TNtuple *ntuple = new TNtuple(“ntuple”,”data from ascii file”,“adc1:adc2:adc3:adc4:tdc1:tdc2:tdc3:tdc4”);

while (1) { in >> a1 >> a2 >> a3 >> a4 >> t1 >> t2 >> t3 >> t4 ; if (!in.good()) break; if (nlines < 5) cout << “ adc1 “ << a1 << “ adc2 “ << a2 << “ adc3 “ << a3 << “ adc4 “ << a4 << “ tdc1 “ << t1 << “ tdc2 “ << t2 << “ tdc3 “ << t3 << “ tdc4 “ << endl; h1->Fill(a1); ntuple->Fill(a1,a2,a3,a4,t1,t2,t3,t4); nlines++; } cout << “ found “ << nlines << “ points “ << endl; in.close(); f->Write();

Macro /home/stefano/root/2006/basic.C

Ntupla: Visualizzazione e Selezione

ntuple->Draw("adc1"); GetAnswer();

// Display a scatter plot of two columns (adc1 vs adc2) pad2->cd(); ntuple->Draw("adc1:adc2"); GetAnswer();

// Display a 3D scatter plot of 3 columns pad3->cd(); ntuple->Draw("tdc2:tdc1:tdc3"); GetAnswer();

// Display adc1 and superimpose both a different selection and adc2 pad4->cd(); ntuple->Draw("adc1"); ntuple->Draw("adc1","adc2<100","same"); ntuple->Draw("adc2","","same"); GetAnswer();

Macro /home/stefano/root/2006/basic.C

Display:

Esercizio: Selezioni

✵ Aprire il run_1.root

✵ Disegnare lo scatter plot adc1 vs adc2

✵ Disegnare lo scatter plot adc1 vs adc2 con le seguenti selezioni :

✵ 100 < adc1 < 200

✵ 100 < adc2 < 200

✵ 100 < adc1 < 200 and 100 < adc2 < 200

Profile e Fit

ntuple->Draw("adc1"); GetAnswer(); // Display a scatter plot of two columns (adc1 vs adc2) pad2->cd(); ntuple->Draw("adc1:adc2"); GetAnswer(); // Display a 3D scatter plot of 3 columns pad3->cd(); ntuple->Draw("tdc2:tdc1:tdc3"); GetAnswer(); // Display adc1 and superimpose both a different selection and adc2 pad4->cd(); ntuple->Draw("adc1"); ntuple->Draw("adc1","adc2<100","same"); ntuple->Draw("adc2","","same"); GetAnswer();

Macro /home/stefano/root/2006/basic.C

Profile e Fit

Scatter plot

Profile

Fit

Esercizio: Vita Media

Se risoluzione sperimentale = 0 ⇒ P = A e –t/τ

Se si normalizza la distribuzione (0,+∞) ⇒ P = 1/τ e –t/τ

Se risoluzione sperimentale ≠ 0 ed è gaussiana scriviamo la funzione di risoluzione R come : ⇒ R = 1/√(2πσ2) e –(t-m)^2 / 2σ^2

La densità di probabilità è calcolata come convoluzione tra la distribuzione esponenziale e la distribuzione gaussiana che rappresenta la funzione di risoluzione R: ⇒ F = P ⊗ RF(t) = ∫0

+∞ 1/τ e –t’/τ 1/√(2πσ2) e –(t-t’)^2 / 2σ^2 dt’ F(t) = 1/2τ Exp((σ2 – 2 t τ)/( 2 τ2)) ( 1 + Erf( (t τ - σ2) /(√(2 σ2) τ )))

Esercizio: Vita Media

Macro /home/stefano/root/2006/meanlife.C

F(t) = 1/2τ Exp((σ2 – 2 t τ)/( 2 τ2)) ( 1 + Erf( (t τ - σ2) /(√(2 σ2) τ )))

scritta “a la root” :

Double_t TimeConv(Double_t *x, Double_t *par) { return (par[0]/(2*par[1]))*TMath::Exp((par[2]*par[2] – 2*par[1]*x[0])/(2*par[1]*par[1]))*(1+TMath::Erf((par[1]*x[0] – par[2]*par[2])/(TMath::Sqrt(2*par[2]*par[2])*par[1])));}

Esercizio: Vita Media

for (Int_t i=0; i < counts; i++){ time0 = gRandom->Exp(0.100); time1 = gRandom->Exp(0.200); time2 = gRandom->Exp(0.300); // meas0 = gRandom->Gaus(time0,resol); meas1 = gRandom->Gaus(time1,resol); meas2 = gRandom->Gaus(time2,resol); // h1f->Fill(meas0); h2f->Fill(meas1); h3f->Fill(meas2);}

Macro /home/stefano/root/2006/meanlife.C

Esercizio: Vita Media

TF1 *fgausexp = new TF1("fgausexp",TimeConv,-2,3,3);fgausexp->SetNpx(500);fgausexp->SetLineWidth(4);fgausexp->SetLineColor(kRed);fgausexp->SetParameters(100.,0.2,0.4);fgausexp->SetParNames("signal","tau","sigma");// … // …h1f->Fit("fgausexp","L");

Macro /home/stefano/root/2006/meanlife.C

Esercizio: Vita Media

Macro /home/stefano/root/2006/meanlife.C

Links

http://root.cern.chhttp://root.cern.ch/root/Tutorials.htmlhttp://root.cern.ch/root/Howto.html

http://root.cern.ch/root/Reference.html

/home/stefano/root/2007/Users_Guide_5_14_TwoInOne.pdf

Introduzione a VME

Stefano Piano

maggio/giugno 2007

Lezioni del corso di Laboratorio di Acquisizione e Controllo Dati

(Laboratorio di Fisica N. e S. I)

VMEbus

VMEbus is a computer architecture VME = Versa Module Eurocard – 1980Bus is a generic term describing a computer data

path

Bus usage was developed from a computing point of view ⇒ completely memory mapped scheme

Every device can be viewed as an address, or block of addresses

Addresses and data are not multiplexed

Crate and Module

The system is modular (Eurocard standard)

VME: card cages (21 slots) and card (160x216mm

160x100mm)

Cards capable of data path widths 8, 16, 24, 32 bitAddressing range between 16, 24, 32 bit

VME boards have P1 connector, larger cards P2 connector (and JAUX…)

Pinout: P1 P2

VMEbusMaster/Slave architecture - Asynchronous

systemInterrupt scheme

The bus allows multiple mastersA resource manager is required to handle the

interrupts

Typical transfer: an arbitration cycle (to gain bus control)an address cycle (to select register)actual data cycle

Read, Write, Modify, Block transfers

Arbitration bus

A module controlling the bus will drive the bus busy line (BBSY) low (IN USE)

If not low (NOT IN USE) the arbiter module will sample the bus request (BR0-BR3) looking for pending action (priority)

The arbiter module generates the first grant signal and this is passed to modules of increasing slot number (BG0IN-BG3IN, BG0OUT-BG3OUT)

Data Transfer bus

The data bus (D00-D31) holds the actual data during a transfer

The address of the register is presented on the address bus (A01-A31)

The address modifier lines (AM00-AM05) indicate the length of the address, the kind of data cycle and master identifier

The address strobe (AS) is used to signal the presence of a valid address

The data strobes (DS0,DS1) are used by the master module to signal valid data and the size word to be transferred

WRITE line is used to distinguish between read and write operations

The data transfer acknowledge (DTACK) is used by the slave module to signal the completion of a transfer

Errors in transfer are signaled using the bus error line (BERR)

DMA: DS-DTACK

Driver and Library

VME Card’s Hardware

User’s application

User’s application

Library USER LEVELDirect calls

Driver

User’s driver

User’s driver

KERNEL LEVELIO CTL calls

Out-going

In-going

VME and Labview

VXI is an extension of the VMEbus architecture, automatically detect and configure VXI instruments: RESMAN

VME does not use this same device detection and configuration scheme: T&M Explorer

VISA is a standard (high-level) I/O Application Programming Interface (API) that calls into system-level drivers

VISA gives you interface independence

VME and Labview 1

VME and Labview 2

VME and Labview

Vi IN

Vi OUT

Sistema Binario ed Esadecimale

Sistema Decimale237 = 2 * 10^2 + 3 * 10^1 + 7 * 10^0Conversione Base 2 Base 1011010010 = 1*2^7 + 1*2^6 + 0*2^5 + 0*2^4 + 0*2^3 + 0*2^2 + 1*2^1

+ 0*2^0 = 210Conversione Base 10 Base 2145 |72 | 1 ( cifra - significativa )36 | 018 | 09 | 04 | 12 | 01 | 00 | 1 (cifra + significativa )

145 in base 10 equivale a 10010001 in base 2con N cifre binarie possiamo rappresentare tutti i numeri da 0 fino a 2^N-1

DEC 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15HEX 0 1 2 3 4 5 6 7 8 9 A B C D E FHex Bin

0 00001 00012 00103 00114 01005 01016 01107 01118 10009 1001A 1010B 1011C 1100D 1101E 1110F 1111

Conversione Base 16 Base 2:Il numero esadecimale 3F5 corrispondeal 0011 1111 0101

Conversione Base 2 Base 16:

10 0101 1101 0101 0010

0010 20101 51101 D 10 2

100101110101010010 equivale al numero 2D52

Operatori Bit a Bit

Gli operatori Bit a Bit lavorano sulla rappresentazione binaria dei dati

1 BYTE = 8 bit - WORD = 2 BYTE = 16 bit - DWORD = 2 WORD = 32 bit

0 1 0 0 0 1 1 1 1 0 0 0 0 1 1 1 0 1 1 1 0 1 0 0 0 1 1 1 1 0 0 0|| | | | |||+- bit 31 | | | bit 0 -+|| | | | |+-- BYTE 3 -----+--- BYTE 2 ----+--- BYTE 1 ----+-- BYTE 0 -----+| | |+----------- WORD 1 ------------+----------- WORD 0 ------------+| |+--------------------------- DWORD -----------------------------+

Ci sono 6 Operatori Bit a Bit:& AND operator| OR operator^ XOR operator~ Ones Complement (Bitwise Not)>> Right Shift operator<< Left Shift operator

Operatori Bit a Bit

AND 1 & 1 == 1 1 & 0 == 0 0 & 1 == 0 0 & 0 == 0

00110010 & 00010000 ---------- 00010000

OR 1 | 1 == 1 1 | 0 == 1 0 | 1 == 1 0 | 0 == 0

00110010 | 00000100 ---------- 00110110

XOR 1 ^ 1 == 0 1 ^ 0 == 1 0 ^ 1 == 1 0 ^ 0 == 0

00110010 ^ 00011000 ---------- 00101010

Bitwise NOT ~ 1 == 0~ 0 == 1

~ 00000011 ---------- 11111100

RIGHT SHIFT

00001100 << 2 (decimale)---------- 00110000

LEFT SHIFT 00001100 >> 2 (decimale)---------- 00000011

LEFT AND RIGHT SHIFT

00001111 >> 2 (decimale)---------- 00000011 << 2 (decimale)---------- 00001100

VME and Camac

CBD 8210: Camac Branch Driver

000

0 = 24-bit or 1 = 16-bit 01

F Code (Camac funct)06 – 02

A Addr (Camac sub-addr)10 – 07

N Addr (Camac station)15 – 11

Crate Addr (1-7)18 – 16

Branch Addr (0-7)21 – 19

0 22

1 23

ValueBit

VME ADDRESS A24: 0x800000 - 0x87FFFF

VME and Camac

Camac Function Set

9

9

9

8

8

9

8

A

27

26

24

16

0

26

26

F

Test I30

Generate I30

Remove I30

Load SNR30

Read GL30

Generate C28

Generate Z28

N

Selection of CBD 8210 Internal Register

0

CR

0

A

0

F

CSR (Read/Write) 16 bit29

N

Time-Out Flag of last Camac Cycle13

Status of X during the last Camac Cycle 14

Status of Q during the last Camac Cycle15

ValueBit