Документ взят из кэша поисковой машины. Адрес оригинального документа : http://acat02.sinp.msu.ru/presentations/brun/Solutions_2.doc
Дата изменения: Sat Jul 6 23:58:08 2002
Дата индексирования: Mon Oct 1 20:18:08 2012
Кодировка:


Solutions To ROOT Exercises


Session A


Question A1:

root [] f1.Derivative(2)
(Double_t)(-4.35393825829554215e-01)

Question A2:

root [] f1.Integral(0,3)
(Double_t)1.84865252799946833e+00

Question A3:

root [] f1.Eval(1.23456789)
(Double_t)7.64644644211939339e-01

Question A4:

ACP is a concatenation of several TGraph::Draw options.
. 'A': Axis are drawn around the graph
. 'C': A smooth Curve is drawn
. 'P': Idem with the current marker
Question A5:

Add or change the following lines:

.
// add two points
const Int_t n = 22;

Double_t x[n], y[n];
for (Int_t i=0;i x[i] = i*0.1;
y[i] = 10*sin(x[i]+0.2);
printf(" i %i %f %f \n",i,x[i],y[i]);
}

x[20] = 2.5;
y[20] = 6;
x[21] = 3;
y[21] = 4;
.
// Insert these lines after giving the axis a title.
// Center the title by getting the x and y axis first and
// calling the CenterTitle method of the TAxis class
gr->GetXaxis()->CenterTitle();
gr->GetYaxis()->CenterTitle();


Question A6:

At the end of the script (e.g., before drawing the TPaveText), add the
following code:

Double_t *gx = gr->GetX();
Double_t *gy = gr->GetY();
TArrow *arrow1 = new TArrow(1,-5,gx[5],gy[5],0.03,"|>");
arrow1->Draw();
TArrow *arrow2 = new TArrow(1,-5,gx[19],gy[19],0.03,"|>");
arrow2->Draw();


Question A7:

Use the context menu for the graph:

1. Right click on the graph
2. To set the line thickness and color: select the
SetLineAttributes option
3. To set the marker style and color: select the
SetMarkerAttributes option
4. To set the back ground of the canvas right click on the canvas
to bring up the context menu
5. Select SetFillAttributes and use the panel to change the color.
6. To zoom, left click and hold on the x-axis (the cursor changes
to a hand) at 0.5. Drag the cursor to the right until 3.5 and
let go.
Question A8:

1. Select the Edit from the canvas Edit menu.
2. Click on the Arrow in the Editor menu
3. Left-click in the frame at 3,0 and hold
4. Drag to 2,5 and let go.
Question A9:

You can add the following statements at the end of the script:

// fitting graph with polynomial function of degree 2 to 7
char function[8];
for (Int_t i=2;i<=7;i++) {
sprintf(function,"pol%d",i);
gr2->Fit(function,"q+");
TF1 *f1 = gr2->GetFunction(function);
f1->SetLineColor(i);
}

Question A10:

The lfits points to a TList of TObjects. TList is a polymorphic container
that may contain any object derived from TObject. The return type of the
function TList::FindObject returns the lowest common denominator TObject*.
One can find the class name of the returned object with:

TObject *object = lfits->FindObject("pol4");
object->ClassName();


Question A11:

Locate the history file: $HOME/.root_hist

Question A12:

In a named script, like in normal C++, all objects created in the stack in
the scope of the function are automatically deleted when exiting from the
function. If an object is deleted and it is in one or more pad(s), it is
automatically removed from the list of objects in the pad.





Session B

Question B1:

1. Once you have run the tutorial hsum.C, select the histogram "s2"
with the right button.
2. Select the "FitPanel"
3. In the FitPanel, select "Landau" and "Same Picture", and use the
slider to select the sub-range for s2.
Question B2:

1. Double click on hsimple.root to see the contents of the file
2. Double click on ntuple to see the contents of the ntuple
3. Double click on pz to see a histogram of pz.
These are the lines needed to do the same thing from the command line. This
assumes the hsimple.root is not yet opened.

root [] TFile f("hsimple.root");
root [] ntuple->Draw("pz");


Question B3:

1. Drag the pz box to the X box.
2. Drag the px box to the Y box.
3. Right click on the white label in the Gopt box and select
SetLabel
4. Type "prof"
5. Click on the Draw button.
These are the lines needed to do the same thing from the command line. This
assumes the hsimple.root is not yet opened.

root [] TFile f("hsimple.root");
root [] ntuple->Draw("pz:px","","prof");


Question B4:

To add the fit:

1. Right click on the graph and select the Fit Panel from the
context menu.
2. Select "pol2" and "same picture"
3. Click on Fit.
These are the lines needed to do the same thing from the command line. This
assumes the hsimple.root is not yet opened.

root [] TFile f("hsimple.root");
root [] ntuple->Draw("pz:px","","prof");
root [] htemp->Fit("pol2");


Question B5:

1. In the Tree Viewer, drag the py box to the X box.
2. Drag the pz box to the Ybox
3. Set the label in the weight box to: px*px + py*py< 20
4. Look up the draw options and set the label in the Gopt box.
Question B6:

The first line finds the global list of contours using the naming service
of gROOT. It cast it to a pointer to an array of TObjects. Each contour can
have multiple disjoint poly lines. The second line gets the list of poly
lines for the first contour. The third statement gets the first poly line
in the list of poly lines for the contour and casts them to a graph.

TObjArray *contours =
(TObjArray*)gROOT->GetListOfSpecials()->FindObject( "contours");
TList *lcontour1 = (TList*)contours->At(0);
TGraph *gc1 = (TGraph*)lcontour1->First();


Question B7:

This loop fills the poly-marker using an infinite loop generating a flat
distribution, but keeping only the points inside the cut.


while(1) {
Double_t x = -4 +8*gRandom->Rndm();
Double_t y = -4 +8*gRandom->Rndm();
if (cutg->IsInside(x,y)) {
pm->SetPoint(np,x,y);
np++;
if (np == npmax) break;
}
}



Question B8:

root [] TFile f("hsimple.root");
root [] ntuple.Draw(">>elist","pz > 10");
root [] TEventList *elist = (TEventList*)f->Get("elist");
root [] elist->Print("all"); //show the list of events
root [] elist->GetN(); //show the number of entries 148

Question B9:

To set the event list and draw px:

root [] ntuple->SetEventList(elist);
root [] ntuple->Draw("px");

The script:

{
TFile f("hsimple.root");
ntuple.Draw(">>elist","pz > 10");
TEventList *elist = (TEventList*)f->Get("elist");
elist->Print("all"); //show the list of events
elist->GetN(); //show the number of entries 148
ntuple->SetEventList(elist);
ntuple->Draw("px");
}


Question B10:

root [] htemp->GetRMS(); //shows 2.407


Question B11:

Run the tutorial h1draw.C, click on the top right pad of the canvas
containing the Lego plot. This will select this pad as being the current
pad. You can rotate the Lego using the left button. To find the current
viewing angle theta, you can type the following command:

root [] gPad->GetTheta();


see next page for B12.



Question B12:

An example of script hrandom1.C is the following:

//----------- hrandom.C
#include "TStopwatch.h"
#include "TRandom2.h"
#include "TRandom3.h"
#include "TH1.h"

void hrandom()
{
// example of a script computing the CPU time to fill an histogram
// with 3 random number generators.

const Int_t nfills = 10000000;
TStopwatch timer;

// create an histogram and evaluate the time to fill nfills time
TH1F h("h","h",100,0,1);
Int_t i;
timer.Start();
for (i=0;i Double_t fillTime = timer.CpuTime();
printf("Time for Fill = %f seconds\n",fillTime);

//using TRandom
timer.Start();
TRandom r1;
for (i=0;i printf("Time for TRandom = %f seconds\n",timer.CpuTime()-
fillTime);

//using TRandom2
timer.Start();
TRandom2 r2;
for (i=0;i printf("Time for TRandom2 = %f seconds\n",timer.CpuTime()-
fillTime);

//using TRandom3
timer.Start();
TRandom3 r3;
for (i=0;i printf("Time for TRandom3 = %f seconds\n",timer.CpuTime()-
fillTime);
}


The output of the first session should be something like:

root [0] .x hrandom1.C
Time for Fill = 17.750000 seconds
Time for TRandom = 6.050000 seconds
Time for TRandom2 = 8.370000 seconds
Time for TRandom3 = 5.290000 seconds

The output of the second session should be something like:

root [0] .x hrandom1.C++
Creating shared library /export/apps/staff/brun/root/./hrandom.so
Note: operator new() masked 1c
Note: operator delete() masked 1c
Time for Fill = 3.410000 seconds
Time for TRandom = 0.660000 seconds
Time for TRandom2 = 4.220000 seconds
Time for TRandom3 = 1.250000 seconds

Question B13:

An example of script hrandom2.C is the following:

//----------- hrandom2.C
#include "TStopwatch.h"
#include "TRandom2.h"
#include "TRandom3.h"
#include "TH1.h"

void hrandom2()
{
// example of a script computing the CPU time to fill an histogram
// with 3 random number generators.

const Int_t nfills = 10000000;
TStopwatch timer;

// create an histogram and evaluate the time to fill nfills time
// change h to be a pointer and create it on the heap
// change all operators of "h." to "h->"

TH1F * h = new TH1F("h","h",100,0,1);
Int_t i;
timer.Start();
for (i=0;iFill(0.5);
Double_t fillTime = timer.CpuTime();
printf("Time for Fill = %f seconds\n",fillTime);


//using TRandom
timer.Start();
TRandom r1;
for (i=0;iFill(r1.Rndm());
printf("Time for TRandom = %f seconds\n",timer.CpuTime()
fillTime);

//using TRandom2
timer.Start();
TRandom2 r2;
for (i=0;iFill(r2.Rndm());
printf("Time for TRandom2 = %f seconds\n",timer.CpuTime()-
fillTime);

//using TRandom3
timer.Start();
TRandom3 r3;
for (i=0;iFill(r3.Rndm());
printf("Time for TRandom3 = %f seconds\n",timer.CpuTime()-
fillTime);

// add a draw command
h->Draw();
}





Session C

Question C1:

You can run the following session:

root [] TFile f("c1.root");
root [] c1->Draw();
root [] TH1F *hdmd = (TH1F*)c1->GetPrimitive("hdmd");
root [] TF1 *f5 = hdmd->GetFunction("f5");
root [] double hint = hdmd->Integral();
root [] double fint = f5->Integral(0.139,0.170);
root [] double ratio = fint/hint
1.00072237393612740e-03


Session D

Question D1:

rootcint is called twice in the makefile (acctually in Make-Macros). It
automatically generates C++ code for an interface between CINT and the
compiled code. It creates a class dictionary of the compiled classes to
make them available to CINT. It contains the class definition (RTTI) and
the Streamer functions. You can look at the C code generated by rootcint in
atlfastCint.cxx.


Question D2:

root [] .x umain.C(7)

Question D3:

atlfast.root file with 1000 events

size = 17.3 Mbytes.

Compression factor = 3.28

It is obtained with:

root [] TFile f("atlfast.root");
root [] f.GetCompressionFactor();

Question D4:

You get 414 reconstructed electrons



Question D5:

You get 2432 reconstructed jets



Question D6:

You see the status of the object ATLFElectronMaker when it was saved in the
simulation session. You can retrieve the simulation parameters from this
object and use them in the analysis code.



Question D7:

You can show all possible inter-class relationships by clicking with the
right button on any "pave". This brings up the context menu of the TPave
class. Then select "ShowLinks".