Analysis Software
Documentation for sPHENIX simulation software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
AnalyzeSimpleTree.cc
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file AnalyzeSimpleTree.cc
1 #include "AnalyzeSimpleTree.h"
2 #include "MySimpleTree.h"
3 #include "MyTClonesArray.h"
4 
8 
9 #include <phool/getClass.h>
10 #include <phool/PHCompositeNode.h>
11 
12 #include <TH1.h>
13 #include <TH2.h>
14 
16 {
17  return ;
18 }
19 
20 int
22 {
24  // this makes a Fun4AllHistoManager which can be used to save your histograms easily
25  // with roots pathetic TDirectory handling and the hoops and loops Fun4All has to
26  // do to accomodate for it it's hard to save histograms on your own and it might not
27  // work reliably. But still keep local pointers to the histograms in your class instead
28  // of retrieving them from the histo manager via their name. This lookup is a string search
29  // which is extremely slow and you do not want to do this for every event
30  hm = new Fun4AllHistoManager("MYHISTOS");
32  myfloats = new TH1F("myfloats", "these are stupid floats", 201, -0.5, 200);
33  my2dfloats = new TH2F("my2dfloats", "these floats are stupid in 2d", 201, -0.5, 199.5, 201, -0.5, 199.5);
34  // this reegisters the histograms with the histo manager for later saving. It will use
35  // the names you gave to the histograms when you created them.
38  return 0;
39 }
40 
41 int
43 {
44  // Find the object on the node tree and fill some of its content into a histogram
45  MySimpleTree *mytree = findNode::getClass<MySimpleTree>(topNode, "MYSIMPLETREE");
46  myfloats->Fill(mytree->MyFloat());
47  // for TClonesArrays we need to loop over its Entries, get a pointer to the class
48  // which is stored inside it and then use that pointer to fill a histogram
49  MyTClonesArray *mycontainer = findNode::getClass<MyTClonesArray>(topNode, "MYTCARRAY");
50  for (int j = 0; j < mycontainer->Entries();j++)
51  {
52  MySimpleTree *item = mycontainer->GetItem(j);
53  my2dfloats->Fill(mytree->MyFloat(), item->MyFloat());
54  }
56 }
57 
59 {
60  hm->dumpHistos("myhistos.root");
62 }