StRoot  1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
StMcEmcModuleHitCollection.cc
1 /***************************************************************************
2  *
3  * $Id $
4  *
5  * Author: Aleksei Pavlinov, May 2000
6  ***************************************************************************
7  *
8  * Description: Monte Carlo Emc Module Hit Collection class
9  *
10  ***************************************************************************
11  *
12  * $Log: StMcEmcModuleHitCollection.cc,v $
13  * Revision 2.8 2012/03/01 16:48:29 perev
14  * method Browse() added
15  *
16  * Revision 2.7 2007/12/14 20:23:50 calderon
17  * From Adam Kocoloski: fix a memory leak, hits were not deleted in destructor.
18  *
19  * Revision 2.6 2007/10/05 00:01:21 calderon
20  * Changes to include a EMC hit collection that does not care about
21  * parent tracks, so that now there are two collections. This
22  * new collection will be useful to compare all the deposited energy in a hit tower
23  * in a given event. The information about the track parentage is still
24  * kept in the original collection unchanged.
25  *
26  * Revision 2.5 2005/08/09 03:31:01 perev
27  * Cleanup
28  *
29  * Revision 2.4 2005/01/27 23:40:47 calderon
30  * Adding persistency to StMcEvent as a step for Virtual MonteCarlo.
31  *
32  * Revision 2.3 2001/05/13 21:12:10 calderon
33  * Modifications by Aleksei to the Emc Hit Collections on indexing of
34  * module numbers
35  *
36  * Revision 2.2 2000/08/30 14:52:03 calderon
37  * New changes made by Aleksei.
38  *
39  * Revision 2.1 2000/06/06 23:01:09 calderon
40  * Inital revision
41  *
42  *
43  **************************************************************************/
44 #include "TBrowser.h"
45 #include "StMcEmcModuleHitCollection.hh"
46 #include "StMcCalorimeterHit.hh"
47 
48 static const char rcsid[] = "$Id: StMcEmcModuleHitCollection.cc,v 2.8 2012/03/01 16:48:29 perev Exp $";
49 
51 
52 //_____________________________________________________________________________
54 {init(m);}
55 
56 StMcEmcModuleHitCollection::StMcEmcModuleHitCollection()
57 {init(0);}
58 
59 //_____________________________________________________________________________
60 void StMcEmcModuleHitCollection::init(const unsigned int m)
61 {
62  //
63  // m - module number
64  //
65  char name[10];
66  sprintf(name,"m%3.3i",m);
67  SetName(name);
68 }
69 
70 //_____________________________________________________________________________
71 StMcEmcModuleHitCollection::~StMcEmcModuleHitCollection()
72 {
73  int n = mHits.size();
74  for (int i=0; i<n; i++) {delete mHits[i];}
75  mHits.clear();
76 
77  n = mDetectorHits.size();
78  for (int i=0; i<n; i++) {delete mDetectorHits[i];}
79  mDetectorHits.clear();
80 }
81 
82 //_____________________________________________________________________________
83 unsigned long
84 StMcEmcModuleHitCollection::numberOfHits() const
85 {
86  return mHits.size();
87 }
88 
89 //_____________________________________________________________________________
90 unsigned long StMcEmcModuleHitCollection::numberOfDetectorHits() const
91 {
92  return mDetectorHits.size();
93 }
94 
95 //_____________________________________________________________________________
96 float StMcEmcModuleHitCollection::sum() const
97 {
98  float s = 0.0;
99  for(unsigned int i=0; i<mHits.size(); i++){
100  s += (*mHits[i]).dE();
101  }
102  return s;
103 }
104 
105 //_____________________________________________________________________________
106 const StSPtrVecMcCalorimeterHit&
107 StMcEmcModuleHitCollection::hits() const { return mHits; }
108 
109 //_____________________________________________________________________________
110 StSPtrVecMcCalorimeterHit&
111 StMcEmcModuleHitCollection::hits() { return mHits; }
112 
113 //_____________________________________________________________________________
114 const StSPtrVecMcCalorimeterHit&
115 StMcEmcModuleHitCollection::detectorHits() const { return mDetectorHits; }
116 
117 //_____________________________________________________________________________
118 StSPtrVecMcCalorimeterHit&
119 StMcEmcModuleHitCollection::detectorHits() { return mDetectorHits; }
120 
121 //_____________________________________________________________________________
122 void StMcEmcModuleHitCollection::Clear(const char*)
123 {
124  for (int i=0; i<(int)mHits.size(); i++)
125  {
126  delete mHits[i]; mHits[i] = 0;
127  }
128  for (int i=0; i<(int)mDetectorHits.size(); i++)
129  {
130  delete mDetectorHits[i]; mDetectorHits[i] = 0;
131  }
132  mHits.clear();
133  mDetectorHits.clear();
134 
135 
136 }
137 //_____________________________________________________________________________
139 {
140  // Browse this event (called by TBrowser).
141  for (int i=0; i<(int)mHits.size(); i++) {
142  TObject *obj = mHits[i]; if (!obj) continue;
143  TString ts(obj->GetName()); ts+="#"; ts+=i;
144  b->Add(obj,ts.Data());
145  }
146 }
virtual void Browse(TBrowser *b)
Browse this dataset (called by TBrowser).