StRoot  1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
StGammaTreeMaker.cxx
1 #include <TFile.h>
2 #include <TTree.h>
3 #include <TString.h>
4 #include "TObjString.h"
5 
6 #include "StMuDSTMaker/COMMON/StMuDst.h"
7 #include "StMuDSTMaker/COMMON/StMuDstMaker.h"
8 #include "StMuDSTMaker/COMMON/StMuEvent.h"
9 #include "StMuDSTMaker/COMMON/StMuPrimaryVertex.h"
10 
11 #include "StGammaEventMaker.h"
12 #include "StGammaEvent.h"
13 #include "StGammaRawMaker.h"
14 
15 #include "StGammaTreeMaker.h"
16 
17 ClassImp(StGammaTreeVersion);
18 ClassImp(StGammaTreeMaker);
19 
20 using namespace std;
21 
23 // Constructor //
25 StGammaTreeVersion::StGammaTreeVersion(const char *name, const char *title): TNamed(name, title)
26 {}
27 
29 // Destructor //
31 StGammaTreeVersion::~StGammaTreeVersion()
32 {}
33 
35 // Print version information //
37 void StGammaTreeVersion::print()
38 {
39 
40  cout << "-- List of makers --" << endl << endl;
41  for(UInt_t i = 0; i < mMakerTags.size(); i++)
42  {
43  cout << Form("[%i]: %s", (int)i, mMakerTags[i].Data()) << endl;
44  }
45 
46  cout << endl;
47  cout << "-- List of containers --" << endl << endl;
48  for (UInt_t i = 0; i < mStorageTags.size(); i++)
49  {
50  cout << Form("[%i]: %s", (int)i, mStorageTags[i].Data()) << endl;
51  }
52 
53 }
54 
56 // Constructor //
58 StGammaTreeMaker::StGammaTreeMaker(const char *name): StMaker(name)
59 {
60  mFilename="gamma_tree.root";
61  mGammaFile = 0;
62  mGammaTree = 0;
63  mGammaEvent = 0;
64  mSkipEmpty = true;
65 }
66 
68 // Destructor //
70 StGammaTreeMaker::~StGammaTreeMaker()
71 {}
72 
74 // Maker Init //
76 Int_t StGammaTreeMaker::Init()
77 {
78 
79  // Create a file if necessary
80  if(!mGammaFile) mGammaFile = new TFile(mFilename, "RECREATE");
81 
82  // Create a tree if necessary
83  if(!mGammaTree)
84  {
85  TString title = "Gamma TTree $Id: StGammaTreeMaker.cxx,v 1.12 2015/07/29 19:10:12 smirnovd Exp $ built " __DATE__ " " __TIME__;
86  mGammaTree = new TTree("gammas", title);
87  mGammaTree->SetDirectory(mGammaFile);
88  }
89 
90  // Retrieve StGammaEventMaker from the chain
91  StGammaEventMaker *mGammaEventMaker = dynamic_cast<StGammaEventMaker*>(GetMakerInheritsFrom("StGammaEventMaker"));
92  if(!mGammaEventMaker)
93  {
94  LOG_DEBUG << "Make() - No StGammaEventMaker found!" << endm;
95  return kStFatal;
96  }
97 
98  mGammaEvent = mGammaEventMaker->event();
99  mGammaTree->Branch("GammaEvent", &mGammaEvent, 32000, 99);
100  mGammaTree->BranchRef(); // Ensure that the reference table is saved
101 
102  // Generate versioning information for each type of storage container
103  mVersion.mStorageTags.push_back( TString(mGammaEvent->GetCVS()) );
104  mVersion.mStorageTags.push_back( TString(mGammaEvent->newCandidate()->GetCVS()) );
105  mVersion.mStorageTags.push_back( TString(mGammaEvent->newTower()->GetCVS()) );
106  mVersion.mStorageTags.push_back( TString(mGammaEvent->newTrack()->GetCVS()) );
107  mVersion.mStorageTags.push_back( TString(mGammaEvent->newStrip()->GetCVS()) );
108  mVersion.mStorageTags.push_back( TString(mGammaEvent->candidate(0)->smdFit().GetCVS() ) );
109 
110  // Clear the current event
111  mGammaEvent->Clear();
112 
113  assert(mGammaFile);
114  assert(mGammaTree);
115 
116  return StMaker::Init();
117 
118 }
119 
121 // Maker Clear //
123 void StGammaTreeMaker::Clear(Option_t *opts)
124 {
125  mGammaEvent->Clear();
126  StMaker::Clear(opts);
127 }
128 
130 // Maker Make //
133 {
134 
135  if( !GetDataSet("MuDst") )
136  {
137  LOG_DEBUG << "Make() - MuDst not found!" << endm;
138  return kStFatal;
139  }
140 
141  // Grabbing StGammaRawMaker was originally here,
142  // is it still necessary?
143 
144  // Store event information in the tree
145  if(mSkipEmpty)
146  {
147  if(mGammaEvent->numberOfCandidates() > 0) mGammaTree->Fill();
148  }
149  else
150  {
151  mGammaTree->Fill();
152  }
153 
154  return kStOK;
155 
156 }
157 
159 // Maker Finish //
162 {
163 
164  // Write QA information to log files AND append information
165  // to an object which we will save w/in the tree file
166 
167  TString cvstag = GetCVS();
168 
169  TIter next( GetParentChain()->GetMakeList());
170  mVersion.mMakerTags.push_back( cvstag );
171 
172  StMaker *maker;
173  while( (maker = (StMaker*)next()) )
174  {
175  cvstag = maker->GetCVS();
176  mVersion.mMakerTags.push_back(cvstag);
177  }
178 
179  LOG_QA <<" -- StGammaMaker versioning information follows --" << endm;
180  mVersion.print();
181 
182  // Save tree
183  mGammaFile->cd();
184  mVersion.Write();
185  mGammaTree->Write();
186 
187  return kStOK;
188 
189 }
virtual void Clear(Option_t *option="")
User defined functions.
Definition: StMaker.cxx:634
Int_t numberOfCandidates() const
Return number of strips.
Definition: StGammaEvent.h:63
StGammaTower * newTower()
Add a new track.
StGammaTrack * newTrack(StMuTrack *mutr=0)
Returns tower pT in eta range.
StGammaCandidate * newCandidate()
Add a new SMD strip.
void Clear(Option_t *opts="")
User defined functions.
StGammaStrip * newStrip()
Add a new postshower element.
Definition: Stypes.h:40
StGammaCandidate * candidate(Int_t i) const
Return ith strip.
Definition: StGammaEvent.h:71