StRoot  1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
StMcEmcHitCollection.cc
1 /***************************************************************************
2  *
3  * $Id $
4  *
5  * Author: Aleksei Pavlinov, May 2000
6  ***************************************************************************
7  *
8  * Description: Monte Carlo Emc Hit Collection class
9  *
10  ***************************************************************************
11  *
12  * $Log: StMcEmcHitCollection.cc,v $
13  * Revision 2.12 2009/08/25 20:57:54 fine
14  * fix the compilation issues under SL5_64_bits gcc 4.3.2
15  *
16  * Revision 2.11 2007/10/05 00:01:20 calderon
17  * Changes to include a EMC hit collection that does not care about
18  * parent tracks, so that now there are two collections. This
19  * new collection will be useful to compare all the deposited energy in a hit tower
20  * in a given event. The information about the track parentage is still
21  * kept in the original collection unchanged.
22  *
23  * Revision 2.10 2007/03/29 15:34:11 fisyak
24  * comment out print out
25  *
26  * Revision 2.9 2005/11/22 21:44:51 fisyak
27  * Add compress Print for McEvent, add Ssd collections
28  *
29  * Revision 2.8 2005/09/28 21:30:14 fisyak
30  * Persistent StMcEvent
31  *
32  * Revision 2.7 2005/08/09 03:30:30 perev
33  * Cleanup
34  *
35  * Revision 2.6 2005/06/28 18:44:11 fine
36  * fix assert
37  *
38  * Revision 2.5 2005/06/28 18:06:41 fine
39  * Remove the redundant data-member StMcEmcModuleHitCollection mModules[mNumberOfModules] causing the crash duw double destruction of one and the same object
40  *
41  * Revision 2.4 2005/01/27 23:40:47 calderon
42  * Adding persistency to StMcEvent as a step for Virtual MonteCarlo.
43  *
44  * Revision 2.3 2001/05/13 21:12:10 calderon
45  * Modifications by Aleksei to the Emc Hit Collections on indexing of
46  * module numbers
47  *
48  * Revision 2.2 2000/08/30 14:52:02 calderon
49  * New changes made by Aleksei.
50  *
51  * Revision 2.1 2000/06/06 23:01:09 calderon
52  * Inital revision
53  *
54  *
55  **************************************************************************/
56 #include "StMcEmcHitCollection.hh"
57 #include "StMcEmcModuleHitCollection.hh"
58 #include "StMcCalorimeterHit.hh"
59 #include "StMcTrack.hh"
60 #include "StParticleDefinition.hh"
61 #include "StMessMgr.h"
62 #include "TObjectSet.h"
63 #include "TDataSetIter.h"
64 #include <cassert>
65 
66 static const char rcsid[] = "$Id ";
67 
68 ClassImp(StMcEmcHitCollection);
69 
70 StMcEmcHitCollection::StMcEmcHitCollection():TDataSet("emcHits",0,kTRUE) { MakeHitCollection(); }
71 
72 StMcEmcHitCollection::StMcEmcHitCollection(char* name):TDataSet(name,0,kTRUE) {MakeHitCollection();}
73 StMcEmcHitCollection::StMcEmcHitCollection(const char* name):TDataSet(name,0,kTRUE) { MakeHitCollection();}
74 
75 void
76 StMcEmcHitCollection::MakeHitCollection()
77 {
79  TObjArray *modules = GetObjArray();
80  assert(modules);
81  // Create the dummy modules collection
82  for (int i=0; i < mNumberOfModules; i++)
83  Add(new StMcEmcModuleHitCollection());
84 }
85 StMcEmcHitCollection::~StMcEmcHitCollection()
86 { /* noop */ }
87 
88 StMcEmcHitCollection::EAddHit
89 StMcEmcHitCollection::addHit(StMcCalorimeterHit* hit)
90 {
91  if(!hit) { LOG_ERROR << "tried to add a NULL hit to StMcEmcHitCollection" << endm; }
92 
93  unsigned int m = hit->module();
94  unsigned int i = m-1;
95 
96  if(m<=mNumberOfModules && m>=1) {
97  StMcCalorimeterHit *detectorHit = new StMcCalorimeterHit(hit->module(), hit->eta(), hit->sub(), hit->dE());
98  for(unsigned int ih=0; ih<thisModule(i).numberOfDetectorHits(); ih++) {
99  if((*thisModule(i).detectorHits()[ih]) == (*detectorHit)) {
100  (*thisModule(i).detectorHits()[ih]) += (*detectorHit);
101  delete detectorHit; detectorHit = NULL;
102  break;
103  }
104  }
105  if(detectorHit) { // hit on a new element
106  thisModule(i).detectorHits().push_back(detectorHit);
107  }
108  }
109 
110  if (m<=mNumberOfModules && m>=1) {
111  if(thisModule(i).numberOfHits() == 0) {
112  thisModule(i)(m); // Set name
113  thisModule(i).hits().push_back(hit); // New hit(first)
114  return kNew;
115  }
116  else {
117  for(unsigned int ih=0; ih<thisModule(i).numberOfHits(); ih++){
118  if((*thisModule(i).hits()[ih]) == (*hit)) { // Hits from the same particle
119  (*thisModule(i).hits()[ih]) += (*hit);
120  return kAdd;
121  }
122  }
123  thisModule(i).hits().push_back(hit); // New hit
124  return kNew;
125  }
126  }
127  else {
128  Warning("addHit","Wrong hit: module=%d but mNumberOfModules=%d",m,mNumberOfModules);
129  return kErr; // Bad number of module
130  }
131 }
132 
133 unsigned long
134 StMcEmcHitCollection::numberOfHits() const
135 {
136  unsigned long sum = 0;
137  for (int i=0; i<mNumberOfModules; i++) {
138  sum += thisModule(i).hits().size();
139  }
140  return sum;
141 }
142 
143 float
144 StMcEmcHitCollection::sum() const
145 {
146  float s = 0.0;
147  unsigned int i, m;
148  for(i=0; i < mNumberOfModules; i++){
149  m = i + 1;
150  s += module(m)->sum();
151  }
152  return s;
153 }
154 
156 StMcEmcHitCollection::module(unsigned int m)
157 {
158 // m - module number; i-index number; i = m - 1; // 10-may-2001
159  TObjArray &modules = *GetObjArray();
160  unsigned int i = m - 1;
161  if (i>=0 && i < mNumberOfModules)
162  return (StMcEmcModuleHitCollection *)modules[i];
163  else
164  return 0;
165 }
166 
168 StMcEmcHitCollection::module(unsigned int m) const
169 {
170  TObjArray &modules = *GetObjArray();
171  unsigned int i = m - 1;
172  if (i>=0 && i < mNumberOfModules)
173  return (StMcEmcModuleHitCollection *)modules[i];
174  else
175  return 0;
176 }
177 
178 void
180 {
181  TDataSet::Browse(b);
182  print();
183 }
184 
185 void StMcEmcHitCollection::print() {/* cout << *this << endl; */}
186 //________________________________________________________________________________
187 ostream& operator<<(ostream& os, const StMcEmcHitCollection &emcColl) {
188  os<<"-----------\n"<<emcColl.GetName()<<" has "<<emcColl.numberOfHits()<<" hits in "
189  <<emcColl.GetListSize()<<" modules. Deposit Energy "<<emcColl.sum()<<" GeV \n-----------\n";
190  unsigned int i, m;
191  for (i=0; i<emcColl.numberOfModules(); i++) {
192  m = i + 1;
193  const StSPtrVecMcCalorimeterHit& hits = emcColl.thisModule(i).hits();
194  int nh = hits.size();
195  if (nh > 0) {
196  os<<" " <<emcColl.module(m)->GetName()<<" #hits "<<nh<<" Dep.Energy " <<
197  emcColl.module(m)->sum()<< endl;
198  os << *(emcColl.module(m)->hits())[0];
199  os << "Parent track of this Hit" << endl;
200  StMcTrack *track = (emcColl.module(m)->hits())[0]->parentTrack();
201  if (track) os << *track << endl;
202  }
203  }
204  return os;
205 }
206 //________________________________________________________________________________
207 void StMcEmcHitCollection::Print(Option_t *option) const {
208  TString Option(option);
209  if (Option.Contains("all",TString::kIgnoreCase)) {
210  cout<<"-----------\n"<<GetName()<<" has "<<numberOfHits()<<" hits in "
211  <<GetListSize()<<" modules. Deposit Energy "<<sum()<<" GeV \n-----------\n";
212  unsigned int i, m;
213  for (i=0; i<numberOfModules(); i++) {
214  m = i + 1;
215  const StSPtrVecMcCalorimeterHit& hits = thisModule(i).hits();
216  int nh = hits.size();
217  if (nh > 0) {
218  cout<<" " <<module(m)->GetName()<<" #hits "<<nh<<" Dep.Energy " <<
219  module(m)->sum()<< endl;
220  for (int j = 0; j < nh; j++) {
221  StMcCalorimeterHit *hit = module(m)->hits()[j];
222  cout << *hit;
223  if ( hit->parentTrack()) {
224  cout << " key " << hit->parentTrack()->key();
225  }
226  cout << endl;
227  }
228  }
229  }
230  } else cout << *this;
231 }
virtual void Browse(TBrowser *b)
Browse this dataset (called by TBrowser).
Definition: TDataSet.cxx:297
Monte Carlo Track class All information on a simulated track is stored in this class: kinematics...
Definition: StMcTrack.hh:144
virtual void Browse(TBrowser *b)
Browse this dataset (called by TBrowser).
void MakeCollection()
Create the internal container at once if any.
Definition: TDataSet.cxx:221