StRoot  1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
StEmcDetector.cxx
1 /***************************************************************************
2  *
3  * $Id: StEmcDetector.cxx,v 2.12 2004/10/14 20:00:18 ullrich Exp $
4  *
5  * Author: Akio Ogawa, Jan 2000
6  ***************************************************************************
7  *
8  * Description:
9  *
10  ***************************************************************************
11  *
12  * $Log: StEmcDetector.cxx,v $
13  * Revision 2.12 2004/10/14 20:00:18 ullrich
14  * Added member and methods to deal with crate status flags.
15  *
16  * Revision 2.11 2004/07/20 17:07:49 perev
17  * Pavlinov corrs for TBrowser
18  *
19  * Revision 2.10 2003/10/02 22:34:05 jeromel
20  * LEAK_SCOPE patch (Alex)
21  *
22  * Revision 2.9 2003/09/12 22:00:57 jeromel
23  * Forgot the void
24  *
25  * Revision 2.8 2003/09/12 21:54:53 jeromel
26  * Zeroing
27  *
28  * Revision 2.7 2001/04/05 04:00:48 ullrich
29  * Replaced all (U)Long_t by (U)Int_t and all redundant ROOT typedefs.
30  *
31  * Revision 2.6 2000/12/08 03:39:50 ullrich
32  * Fixed warning because of signed/unsigned comparison.
33  *
34  * Revision 2.5 2000/10/26 00:02:21 ullrich
35  * Fixed various problems causing I/O failures.
36  *
37  * Revision 2.4 2000/07/28 19:49:27 akio
38  * Change in Detector Id for Endcap SMD
39  *
40  * Revision 2.3 2000/06/30 17:23:19 akio
41  * minor bug fix for return kFalse
42  *
43  * Revision 2.2 2000/05/22 19:21:53 akio
44  * Bug fix, add delta into EMcPoint, wider bits for Eta in RawHit
45  *
46  * Revision 2.1 2000/02/23 17:34:08 ullrich
47  * Initial Revision
48  *
49  **************************************************************************/
50 #include "StEmcDetector.h"
51 #include "StEmcRawHit.h"
52 #include "StEmcModule.h"
53 #include "StEmcClusterCollection.h"
54 #include <TBrowser.h>
55 
56 static const char rcsid[] = "$Id: StEmcDetector.cxx,v 2.12 2004/10/14 20:00:18 ullrich Exp $";
57 
58 ClassImp(StEmcDetector)
59 
60 StEmcDetector::StEmcDetector() { clear(); }
61 
62 StEmcDetector::StEmcDetector(StDetectorId id, unsigned int n)
63 {
64  clear();
65  mDetectorId = id;
66  mNumberOfModules = n;
67  for(int i=0; i<120;i++) {
68  mModules[i] = new StEmcModule();
69  //StEmcModule * module = new StEmcModule();
70  //this->setModule(new StEmcModule(),i);
71  }
72 }
73 
74 StEmcDetector::~StEmcDetector()
75 {
76  for(int i=0; i<120;i++) if(mModules[i]) delete mModules[i];
77  if (mClusters) delete mClusters;
78 }
79 
80 void
81 StEmcDetector::clear()
82 {
83  for(int i=0; i<120;i++) mModules[i] = 0;
84  mClusters = 0;
85  for(int i=0; i<mMaxNumberOfCrates; i++)
86  mCrateStatusFlag[i] = crateUnknown;
87 }
88 
89 
90 bool
91 StEmcDetector::addHit(StEmcRawHit* hit)
92 {
93  if (hit) {
94  unsigned int m = hit->module();
95  if (m > 0 && m <= mNumberOfModules) {
96  mModules[m-1]->hits().push_back(hit);
97  return true;
98  }
99  }
100  return false;
101 }
102 
103 StDetectorId
104 StEmcDetector::detectorId() const { return mDetectorId; }
105 
106 unsigned int
107 StEmcDetector::numberOfModules() const { return mNumberOfModules; }
108 
109 unsigned int
110 StEmcDetector::numberOfHits() const
111 {
112  unsigned int sum = 0;
113  for (unsigned int m=0;m<mNumberOfModules;m++) sum+= mModules[m]->hits().size();
114  return sum;
115 }
116 
117 void
118 StEmcDetector::printNumberOfHits() const
119 {
120  printf(" Detector %i : nhits %i\n", int(mDetectorId), numberOfHits());
121  return;
122 }
123 
124 double
125 StEmcDetector::getEnergy(const int pri) const
126 {
127  float e = 0., eM = 0.;
128  for (unsigned int m=0;m<mNumberOfModules;m++) {
129  if(mModules[m]->numberOfHits()==0) continue;
130  eM = mModules[m]->getEnergy();
131  e += eM;
132  if(pri>1) {
133  if(eM !=0 ) printf("%3i(m) : e %9.4f ", m+1, eM);
134  if(eM < 0.) printf(" !!");
135  printf("\n");
136  }
137  }
138 
139  if(pri>0) printf("det %i : energy %9.4f GeV/c \n", int(mDetectorId), e);
140 
141  return e;
142 }
143 
145 StEmcDetector::module(unsigned int i)
146 {
147  if (i > 0 && i <= mNumberOfModules) return (mModules[i-1]);
148  else return 0;
149 }
150 
151 const StEmcModule*
152 StEmcDetector::module(unsigned int i) const
153 {
154  if (i > 0 && i <= mNumberOfModules) return (mModules[i-1]);
155  else return 0;
156 }
157 
159 StEmcDetector::cluster() {return mClusters;}
160 
162 StEmcDetector::cluster() const {return mClusters;}
163 
164 StEmcCrateStatus StEmcDetector::crateStatus(int crate) const {
165  if (crate > 0 && crate <= mMaxNumberOfCrates)
166  return mCrateStatusFlag[crate-1];
167  else
168  return crateUnknown;
169 }
170 
171 void
172 StEmcDetector::setCluster(StEmcClusterCollection* val)
173 {
174  if (mClusters) delete mClusters;
175  mClusters = val;
176 }
177 
178 void
179 StEmcDetector::setModule(StEmcModule* val,int IdMod)
180 {
181  if (val) {
182  if (IdMod >= 0 && IdMod < static_cast<int>(mNumberOfModules)) {
183  if (mModules[IdMod]) delete mModules[IdMod];
184  mModules[IdMod] = val;
185  }
186  }
187 }
188 
189 void StEmcDetector::setCrateStatus(int crate, StEmcCrateStatus flag) {
190  if (crate > 0 && crate <= mMaxNumberOfCrates)
191  mCrateStatusFlag[crate-1] = flag;
192 }
193 
194 bool StEmcDetector::IsFolder() const
195 {
196  if(numberOfHits()) return true;
197  else return false;
198 }