StRoot  1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
StPhmdDetector.cxx
1 /********************************************************************
2  *
3  * $Id: StPhmdDetector.cxx,v 2.4 2007/10/25 19:38:47 ullrich Exp $
4  *
5  * Author: Subhasis Chattopadhyay, Dec 2002
6  ********************************************************************
7  *
8  * Description: Base class for PMD detector
9  *
10  ********************************************************************
11  *
12  * $Log: StPhmdDetector.cxx,v $
13  * Revision 2.4 2007/10/25 19:38:47 ullrich
14  * Added missing const version of method cluster().
15  *
16  * Revision 2.3 2007/10/25 19:24:14 ullrich
17  * Added missing const version of method module().
18  *
19  * Revision 2.2 2003/11/07 18:33:03 perev
20  * Zeroing in constructor added
21  *
22  * Revision 2.1 2002/12/20 22:33:00 ullrich
23  * Initial Revision.
24  *
25  ********************************************************************/
26 #include "StPhmdDetector.h"
27 #include "StPhmdHit.h"
28 #include "StPhmdModule.h"
29 #include "StPhmdClusterCollection.h"
30 
31 
32 ClassImp(StPhmdDetector)
33 
35 {
36  mDetectorId = kUnknownId;
37  memset(mModulesNHit,0,sizeof(mModulesNHit));
38  memset(mModules ,0,sizeof(mModules ));
39  mClusters = 0;
40 }
41 
42 StPhmdDetector::StPhmdDetector(StDetectorId id)
43 {
44  mDetectorId = id;
45  memset(mModulesNHit,0,sizeof(mModulesNHit));
46  memset(mModules ,0,sizeof(mModules ));
47  mClusters = 0;
48  for (int i=0; i<mMaxModules; i++)
49  this->setModule(new StPhmdModule(), i);
50 }
51 
52 StPhmdDetector::~StPhmdDetector()
53 {
54  for (int i=0; i<mMaxModules; i++) delete mModules[i];
55  memset(mModules ,0,sizeof(mModules ));
56  delete mClusters; mClusters = 0;
57 }
58 
59 bool
60 StPhmdDetector::addHit(StPhmdHit* hit)
61 {
62  if (hit) {
63  unsigned int m = static_cast<unsigned int>(hit->module());
64  if (m <= mMaxModules) {
65  mModules[m]->hits().push_back(hit);
66  mModulesNHit[m]++;
67  return true;
68  }
69  }
70  return false;
71 }
72 
73 int
74 StPhmdDetector::moduleHits(unsigned int i)
75 {
76  if (i <= mMaxModules)
77  return mModulesNHit[i];
78  else
79  return 0;
80 }
81 
82 unsigned int
83 StPhmdDetector::numberOfModules() const { return mMaxModules; }
84 
85 unsigned int
86 StPhmdDetector::numberOfHits() const
87 {
88  unsigned int sum = 0;
89  return sum;
90 }
91 
93 StPhmdDetector::module(unsigned int i)
94 {
95  if (i < mMaxModules)
96  return (mModules[i]);
97  else
98  return 0;
99 }
100 
101 const StPhmdModule*
102 StPhmdDetector::module(unsigned int i) const
103 {
104  if (i < mMaxModules)
105  return (mModules[i]);
106  else
107  return 0;
108 }
109 
110 void
111 StPhmdDetector::setModule(StPhmdModule* val, unsigned int IdMod)
112 {
113  if (val) {
114  if (IdMod < mMaxModules) {
115  if (mModules[IdMod]) delete mModules[IdMod];
116  mModules[IdMod] = val;
117  }
118  }
119 }
120 
122 StPhmdDetector::cluster() {return mClusters;}
123 
125 StPhmdDetector::cluster() const {return mClusters;}
126 
127 void
128 StPhmdDetector::setCluster(StPhmdClusterCollection* val)
129 {
130  if (mClusters) delete mClusters;
131  mClusters = val;
132 }
133 
134 ostream& operator<<(ostream& os, const StPhmdHit& h)
135 {
136  os << "super=" << h.superModule();
137  os << "\tsubDetector=" << h.subDetector();
138  os << "\trow=" << h.row();
139  os << "\tcolumn=" << h.column();
140  os << "\tedep=" << h.energy();
141  return os;
142 }