root tutorial parte 3. void randomgaus(){ double_t x, y; th2d *h2 = new th2d(“h2”,”uniform...

16
ROOT Tutorial Parte 3

Upload: concettina-palma

Post on 02-May-2015

213 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: ROOT Tutorial Parte 3. void randomGaus(){ Double_t x, y; TH2D *h2 = new TH2D(“h2”,”Uniform Distribution”, 100,0,10,100,0,10); for(Int_t i=0; i < 100000;

ROOT Tutorial Parte 3

Page 2: ROOT Tutorial Parte 3. void randomGaus(){ Double_t x, y; TH2D *h2 = new TH2D(“h2”,”Uniform Distribution”, 100,0,10,100,0,10); for(Int_t i=0; i < 100000;

void randomGaus(){Double_t x, y;TH2D *h2 = new TH2D(“h2”,”Uniform Distribution”, 100,0,10,100,0,10);for(Int_t i=0; i < 100000; i++){

x = gRandom->Uniform(0,10);y = gRandom->Gaus(5,1);h2->Fill(x,y);

}gStyle->SetPalette(1);h2->Draw();}

Esempio: distribuzione uniforme in x, gaussiana in y

h2->Draw(“lego”);

h2->Draw(“colz”);

Page 3: ROOT Tutorial Parte 3. void randomGaus(){ Double_t x, y; TH2D *h2 = new TH2D(“h2”,”Uniform Distribution”, 100,0,10,100,0,10); for(Int_t i=0; i < 100000;

Esempio: distribuzione uniforme nello spazio

Estrazione uniforme (,)?

void sfera(){ Int_t raggio=1; Double_t teta, phi; TH3D *hsemisfera = new TH3D("hsemisfera","hsemisfera",200,-1,1,200,-1,1,100,0,1); for(Int_t i=0; i<10000; i++){ teta = gRandom->Uniform(0,TMath::Pi()/2); //semisfera

// teta = gRandom->Uniform(0,TMath::Pi()); // sfera phi = gRandom->Uniform(0,2*TMath::Pi()); Double_t x = raggio * TMath::Cos(phi)*TMath::Sin(teta); Double_t y = raggio * TMath::Sin(phi)*TMath::Sin(teta); Double_t z = raggio * TMath::Cos(teta); hsemisfera->Fill(x,y,z); } hsemisfera->Draw(); }

Page 4: ROOT Tutorial Parte 3. void randomGaus(){ Double_t x, y; TH2D *h2 = new TH2D(“h2”,”Uniform Distribution”, 100,0,10,100,0,10); for(Int_t i=0; i < 100000;

Estrazione uniforme in e in sin()

void sfera2(){ Int_t raggio=1; Double_t teta, phi; TH3D *hsemisfera = new TH3D("hsemisfera","hsemisfera",200,-1,1,200,-1,1,100,0,1); for(Int_t i=0; i<10000; i++){ teta = TMath::ACos(gRandom->Uniform(0,1)); //Semisfera

//teta = TMath::ACos(-1 + 2*gRandom->Uniform(0,1)); //Sfera phi = gRandom->Uniform(0,2*TMath::Pi());

Double_t x = raggio * TMath::Cos(phi)*TMath::Sin(teta); Double_t y = raggio * TMath::Sin(phi)*TMath::Sin(teta); Double_t z = raggio * TMath::Cos(teta); hsemisfera->Fill(x,y,z); } hsemisfera->Draw(); }

Page 5: ROOT Tutorial Parte 3. void randomGaus(){ Double_t x, y; TH2D *h2 = new TH2D(“h2”,”Uniform Distribution”, 100,0,10,100,0,10); for(Int_t i=0; i < 100000;

ROOT Files

Si tratta di file salvati in un formato leggibile da ROOT. Può contenere vari tipi di oggetti.

Esempio: TFile f(“esempio.root","recreate");h0->Write();f.Close();

TFile f("demo.root");TBrowser browser;

Per creare un file ROOT e salvare un istogramma

Per aprire un file ROOT e vederne il contenuto

Opzioni: NEW, CREATE, RECREATE, UPDATE, READ

Page 6: ROOT Tutorial Parte 3. void randomGaus(){ Double_t x, y; TH2D *h2 = new TH2D(“h2”,”Uniform Distribution”, 100,0,10,100,0,10); for(Int_t i=0; i < 100000;

Tree ROOT

Ogni esperimento di fisica nucleare produce in genere degli eventi, definiti da una serie ordinata di variabili.

Esempio: 2 rivelatori in coincidenza, con le seguenti informazioni: energia depositata in ciascuno dei due e tempo di volo tra i due: E1, E2, T Struttura dell’evento:

N.Evento E1 E2 T

1 2.35 3.46 5.61

2 3.43 4.21 5.66

3 …………………………….

4 ………………………

Il programma di acquisizione dati scriverà in un file, evento per evento, questa serie ordinata di numeri, per la loro successiva analisi

I Tree di ROOT permettono di conservare facilmente queste strutture dati e consentono un’analisi multiparametrica

Page 7: ROOT Tutorial Parte 3. void randomGaus(){ Double_t x, y; TH2D *h2 = new TH2D(“h2”,”Uniform Distribution”, 100,0,10,100,0,10); for(Int_t i=0; i < 100000;

Creare un oggetto TTree

TTree *tree = new TTree(“tree","A ROOT tree");

Aggiungere i Branches

Double_t var;tree->Branch(“var",&var,”var/D”);

Riempire il tree

tree->Fill();

Scrivere un tree in un file

tree->Write();

Creare e riempire un Tree

Page 8: ROOT Tutorial Parte 3. void randomGaus(){ Double_t x, y; TH2D *h2 = new TH2D(“h2”,”Uniform Distribution”, 100,0,10,100,0,10); for(Int_t i=0; i < 100000;

Esempio

void createtree(){ //Output ROOT file TFile *f = new TFile("esempiotree.root","RECREATE"); //Output tree TTree *myTree = new TTree("myTree","a ROOT tree"); Int_t evno; Float_t var1, var2, var3; myTree->Branch("evno",&evno,"evno/I"); myTree->Branch("var1",&var1,"var1/F"); myTree->Branch("var2",&var2,"var2/F"); myTree->Branch("var3",&var3,"var3/F"); for(Int_t i=0; i<1000; i++){ evno = i; var1 = gRandom->Uniform(); var2 = gRandom->Exp(1); var3 = gRandom->Gaus(0,1); myTree->Fill(); } myTree->Write(); f->Close(); }

Page 9: ROOT Tutorial Parte 3. void randomGaus(){ Double_t x, y; TH2D *h2 = new TH2D(“h2”,”Uniform Distribution”, 100,0,10,100,0,10); for(Int_t i=0; i < 100000;

root[ ]> myTree- >Scan()root[ ]> myTree- >Print()root[ ]> myTree- >Draw(“var3”) 1Droot[ ]> myTree- >Draw(“var1:var2”) 2Droot[ ]> myTree- >Draw(“var1:var2”, “”, “lego2”) 2D con opzioniroot[ ]> myTree- >Draw(“var1:var2”, “evno<500”, “lego”) 2D con taglioroot[ ]> myTree- >Draw(“var1:var2:var3”) 3Droot[ ]> myTree- >Fit(“gaus”, “var3”) Fitroot[ ]> myTree- >Fit(“gaus”, “var3”, “cut”) Fit con taglio

Alcuni metodi utili per l’analisi di un Tree (interattivamente)

Leggere un tree da un file ROOT

void readtree(){ TFile *f = new TFile("esempiotree.root"); TTree *tree = (TTree*)f->Get("myTree");

Int_t evno; Float_t var1, var2, var3; tree->SetBranchAddress("evno",&evno); tree->SetBranchAddress("var1",&var1); tree->SetBranchAddress("var2",&var2); tree->SetBranchAddress("var3",&var3); tree->Draw("var3","evno<500");}

Page 10: ROOT Tutorial Parte 3. void randomGaus(){ Double_t x, y; TH2D *h2 = new TH2D(“h2”,”Uniform Distribution”, 100,0,10,100,0,10); for(Int_t i=0; i < 100000;

Un esempio di analisi su dati simulati

Diverse particelle (p, π, K in una certa proporzione)

Rivelatore costituito da 3 rivelatori sottili e da un rivelatore spesso in silicio

Output: Un file di Root con 50000 eventi simulati che contengono:

N.evento, Tipo di particella, Impulso, E1, E2, E3, Etot

Esercitazione: Costruire gli spettri dell’energia depositata in ciascuno dei rivelatori

Page 11: ROOT Tutorial Parte 3. void randomGaus(){ Double_t x, y; TH2D *h2 = new TH2D(“h2”,”Uniform Distribution”, 100,0,10,100,0,10); for(Int_t i=0; i < 100000;

Contenuto del Tree (file “deltae.root”)

Kpart=8 (pioni), 11 (kaoni), 14 (protoni)

Page 12: ROOT Tutorial Parte 3. void randomGaus(){ Double_t x, y; TH2D *h2 = new TH2D(“h2”,”Uniform Distribution”, 100,0,10,100,0,10); for(Int_t i=0; i < 100000;
Page 13: ROOT Tutorial Parte 3. void randomGaus(){ Double_t x, y; TH2D *h2 = new TH2D(“h2”,”Uniform Distribution”, 100,0,10,100,0,10); for(Int_t i=0; i < 100000;

Leggere il file deltae.root

void deltae(){

TFile *f = new TFile("deltae.root"); TTree *tree = (TTree*)f->Get("tree");

Int_t iev, kpart; Double_t pmod, e1, e2, e3, etot; tree->SetBranchAddress("iev",&iev); tree->SetBranchAddress("kpart",&kpart); tree->SetBranchAddress("pmod",&pmod); tree->SetBranchAddress("e1",&e1); tree->SetBranchAddress("e2",&e2); tree->SetBranchAddress("e3",&e3); tree->SetBranchAddress("etot",&etot);

Page 14: ROOT Tutorial Parte 3. void randomGaus(){ Double_t x, y; TH2D *h2 = new TH2D(“h2”,”Uniform Distribution”, 100,0,10,100,0,10); for(Int_t i=0; i < 100000;

Un esempio di analisi su dati simulati

Esercitazioni:

1 Costruire gli spettri dell’energia depositata in ciascuno dei rivelatori

2 Costruire gli spettri selezionando le particelle incidenti

3 Costruire dei plot bidimensionali Ej-Etot per j=1, 2, 3 (matrici DeltaE-E)

4 Studiare l’effetto dell’impulso delle particelle incidenti

5 Studiare l’effetto dell’inclinazione della traccia

Page 15: ROOT Tutorial Parte 3. void randomGaus(){ Double_t x, y; TH2D *h2 = new TH2D(“h2”,”Uniform Distribution”, 100,0,10,100,0,10); for(Int_t i=0; i < 100000;

…Tree->Draw(“e1”);

}

Costruire gli spettri dell’energia depositata in ciascuno dei rivelatori

…Tree->Draw(“e1”, “kpart==14”);

}

Costruire gli spettri selezionando le particelle incidenti

Costruire dei plot bidimensionali

…Tree->Draw(“e1:etot”); //OppureTH2D *h2 = new TH2D("h2","deltaE-E",300,0,150,50,0,2.5); for(Int_t i = 0; i < tree->GetEntries(); i++){

tree->GetEntry(i); h2->Fill(etot,e1);

} gStyle->SetPalette(1); h2->Draw("colz");}

Page 16: ROOT Tutorial Parte 3. void randomGaus(){ Double_t x, y; TH2D *h2 = new TH2D(“h2”,”Uniform Distribution”, 100,0,10,100,0,10); for(Int_t i=0; i < 100000;

Studiare l’effetto dell’inclinazione della traccia Tree->Draw(“etot”,”kpart==8”)

deltae.root deltae_cono.root

Studiare l’effetto dell’impulso Tree->Draw(“e1:etot”,”kpart==11&&pmod<0.4”)