Back to home page

sPhenix code displayed by LXR

 
 

    


File indexing completed on 2025-08-05 08:21:37

0001 #include "AnalyzeSimpleTree.h"
0002 #include "MySimpleTree.h"
0003 #include "MyTClonesArray.h"
0004 
0005 #include <fun4all/Fun4AllServer.h>
0006 #include <fun4all/Fun4AllHistoManager.h>
0007 #include <fun4all/Fun4AllReturnCodes.h>
0008 
0009 #include <phool/getClass.h>
0010 #include <phool/PHCompositeNode.h>
0011 
0012 #include <TH1.h>
0013 #include <TH2.h>
0014 
0015 AnalyzeSimpleTree::AnalyzeSimpleTree(const std::string &name): SubsysReco(name)
0016 {
0017   return ;
0018 }
0019 
0020 int
0021 AnalyzeSimpleTree::Init(PHCompositeNode * /*topNode*/)
0022 {
0023   Fun4AllServer *se = Fun4AllServer::instance();
0024   // this makes a Fun4AllHistoManager which can be used to save your histograms easily
0025   // with roots pathetic TDirectory handling and the hoops and loops Fun4All has to
0026   // do to accomodate for it it's hard to save histograms on your own and it might not
0027   // work reliably. But still keep local pointers to the histograms in your class instead
0028   // of retrieving them from the histo manager via their name. This lookup is a string search
0029   // which is extremely slow and you do not want to do this for every event
0030   hm = new Fun4AllHistoManager("MYHISTOS");
0031   se->registerHistoManager(hm);
0032   myfloats = new TH1F("myfloats", "these are stupid floats", 201, -0.5, 200);
0033   my2dfloats = new TH2F("my2dfloats", "these floats are stupid in 2d", 201, -0.5, 199.5, 201, -0.5, 199.5);
0034   // this reegisters the histograms with the histo manager for later saving. It will use
0035   // the names you gave to the histograms when you created them.
0036   hm->registerHisto(myfloats);
0037   hm->registerHisto(my2dfloats);
0038   return 0;
0039 }
0040 
0041 int
0042 AnalyzeSimpleTree::process_event(PHCompositeNode *topNode)
0043 {
0044   // Find the object on the node tree and fill some of its content into a histogram
0045   MySimpleTree *mytree = findNode::getClass<MySimpleTree>(topNode, "MYSIMPLETREE");
0046   myfloats->Fill(mytree->MyFloat());
0047   // for TClonesArrays we need to loop over its Entries, get a pointer to the class
0048   // which is stored inside it and then use that pointer to fill a histogram
0049   MyTClonesArray *mycontainer = findNode::getClass<MyTClonesArray>(topNode, "MYTCARRAY");
0050   for (int j = 0; j < mycontainer->Entries();j++)
0051     {
0052       MySimpleTree *item = mycontainer->GetItem(j);
0053       my2dfloats->Fill(mytree->MyFloat(), item->MyFloat());
0054     }
0055   return Fun4AllReturnCodes::EVENT_OK;
0056 }
0057 
0058 int AnalyzeSimpleTree::End(PHCompositeNode * /*topNode*/)
0059 {
0060   hm->dumpHistos("myhistos.root");
0061   return  Fun4AllReturnCodes::EVENT_OK;
0062 }