ECCE @ EIC 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 
15 using namespace std;
16 
18 {
19  return ;
20 }
21 
22 int
24 {
26  // this makes a Fun4AllHistoManager which can be used to save your histograms easily
27  // with roots pathetic TDirectory handling and the hoops and loops Fun4All has to
28  // do to accomodate for it it's hard to save histograms on your own and it might not
29  // work reliably. But still keep local pointers to the histograms in your class instead
30  // of retrieving them from the histo manager via their name. This lookup is a string search
31  // which is extremely slow and you do not want to do this for every event
32  hm = new Fun4AllHistoManager("MYHISTOS");
34  myfloats = new TH1F("myfloats", "these are stupid floats", 201, -0.5, 200);
35  my2dfloats = new TH2F("my2dfloats", "these floats are stupid in 2d", 201, -0.5, 199.5, 201, -0.5, 199.5);
36  // this reegisters the histograms with the histo manager for later saving. It will use
37  // the names you gave to the histograms when you created them.
40  return 0;
41 }
42 
43 int
45 {
46  // Find the object on the node tree and fill some of its content into a histogram
47  MySimpleTree *mytree = findNode::getClass<MySimpleTree>(topNode, "MYSIMPLETREE");
48  myfloats->Fill(mytree->MyFloat());
49  // for TClonesArrays we need to loop over its Entries, get a pointer to the class
50  // which is stored inside it and then use that pointer to fill a histogram
51  MyTClonesArray *mycontainer = findNode::getClass<MyTClonesArray>(topNode, "MYTCARRAY");
52  for (int j = 0; j < mycontainer->Entries();j++)
53  {
54  MySimpleTree *item = mycontainer->GetItem(j);
55  my2dfloats->Fill(mytree->MyFloat(), item->MyFloat());
56  }
58 }