| | 478 | |
| | 479 | == Analysis with root == |
| | 480 | |
| | 481 | Here is a short example how to access the data from the root file, assuming a filename '''rootify.root''', the default tree name '''Result''' and two branches with name '''Col0''' and '''Col1''' |
| | 482 | {{{#!cpp |
| | 483 | void example() |
| | 484 | { |
| | 485 | // Create chain for the tree Result |
| | 486 | // This is just easier than using TFile/TTree |
| | 487 | TChain c("Result"); |
| | 488 | |
| | 489 | // Add the input file to the |
| | 490 | c.AddFile("rootify.root"); |
| | 491 | |
| | 492 | // Assume you want to convert Col1 from RAD to DEG |
| | 493 | c.SetAlias("col1deg", "Col1*TMath::RadToDeg()"); |
| | 494 | |
| | 495 | // Plot Col0 if Col1>PI |
| | 496 | new TCanvas; |
| | 497 | c.Draw("Col0", "Col1>TMath::Pi()"); |
| | 498 | |
| | 499 | // Plot Col1 in degree versus Col0 |
| | 500 | new TCanvas; |
| | 501 | c.Draw("Col0:col1deg", ""); |
| | 502 | } |
| | 503 | }}} |
| | 504 | |
| | 505 | or |
| | 506 | |
| | 507 | {{{#!cpp |
| | 508 | void example() |
| | 509 | { |
| | 510 | // Create chain for the tree Result |
| | 511 | // This is just easier than using TFile/TTree |
| | 512 | TChain c("Result"); |
| | 513 | |
| | 514 | // Add the input file to the |
| | 515 | c.AddFile("rootify.root"); |
| | 516 | |
| | 517 | // All columns are stores as doubles |
| | 518 | double col0, col1; |
| | 519 | |
| | 520 | // Connect the variables to the coresponding leaves |
| | 521 | c.SetBranchAddress("Col0", &col0); |
| | 522 | c.SetBranchAddress("Col1", &col1); |
| | 523 | |
| | 524 | for (int i=0; i<c.GetEntries(); i++) |
| | 525 | { |
| | 526 | // read the i-th event from the file |
| | 527 | c.GetEntry(i); |
| | 528 | |
| | 529 | cout << col0 << " " << col1 << endl; |
| | 530 | } |
| | 531 | } |
| | 532 | }}} |
| | 533 | |
| | 534 | Assuming the code is written to '''example.C''', both are executed with {{{root example.C}}}. Instead of {{{Draw()}}} also {{{Select()}}} can be used to print the data to the console. |
| | 535 | |
| | 536 | For details, please refer either to the Draw-function of TTree (e.g. https://root.cern.ch/doc/master/classTTree.html#a73450649dc6e54b5b94516c468523e45) or checkout the root user manual (https://root.cern.ch/guides/users-guide), in particular the section about '''Trees'''. |