helper method to fill tree structure
authorrichterm <richterm@f7af4fe6-9843-0410-8265-dc069ae4e863>
Mon, 8 Aug 2011 06:20:51 +0000 (06:20 +0000)
committerrichterm <richterm@f7af4fe6-9843-0410-8265-dc069ae4e863>
Mon, 8 Aug 2011 06:20:51 +0000 (06:20 +0000)
HLT/BASE/AliHLTSpacePointContainer.cxx
HLT/BASE/AliHLTSpacePointContainer.h

index 9bc103b..e764f94 100644 (file)
@@ -31,6 +31,7 @@
 #include "TH2F.h"
 #include "TMath.h"
 #include "TMarker.h"
+#include "TTree.h"
 #include <memory>
 #include <algorithm>
 #include <iostream>
@@ -390,6 +391,45 @@ void AliHLTSpacePointContainer::Draw(Option_t *option)
   }  
 }
 
+TTree* AliHLTSpacePointContainer::FillTree(const char* name, const char* title)
+{
+  // create tree and fill the space point coordinates
+  TString treename=name;
+  TString treetitle=title;
+  if (treename.IsNull()) treename="spacepoints";
+  if (treetitle.IsNull()) treetitle="HLT space point coordinates";
+  std::auto_ptr<TTree> tree(new TTree(treename, treetitle));
+  if (!tree.get()) return NULL;
+
+  const unsigned dimension=5;
+  float values[dimension];
+  memset(values, 0, sizeof(values));
+  const char* names[dimension]={
+    "x", "y", "z", "charge", "alpha"
+  };
+
+  for (unsigned i=0; i<dimension; i++) {
+    TString type=names[i]; type+="/F";
+    tree->Branch(names[i], &values[i], type);
+  }
+
+  const vector<AliHLTUInt32_t>* clusterIDs=GetClusterIDs(0xffffffff);
+  for (vector<AliHLTUInt32_t>::const_iterator clusterID=clusterIDs->begin();
+       clusterID!=clusterIDs->end();
+       clusterID++) {
+    unsigned pos=0;
+    values[pos++]=GetX(*clusterID);
+    values[pos++]=GetY(*clusterID);
+    values[pos++]=GetZ(*clusterID);
+    values[pos++]=GetCharge(*clusterID);
+    values[pos++]=GetPhi(*clusterID);
+
+    tree->Fill();
+  }
+
+  return tree.release();
+}
+
 ostream& operator<<(ostream &out, const AliHLTSpacePointContainer& c)
 {
   c.Print(out);
index e39672d..6376fd4 100644 (file)
@@ -20,6 +20,7 @@
 
 class TArrayC;
 class TH1;
+class TTree;
 
 /**
  * @class AliHLTSpacePointContainer
@@ -119,6 +120,8 @@ class AliHLTSpacePointContainer : public TObject, public AliHLTLogging
 
   TH1* DrawProjection(const char* plane, const vector<AliHLTUInt32_t>& selection) const;
 
+  TTree* FillTree(const char* name, const char* title="");
+
  protected:
 
  private: