StRoot  1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
StMuPmdCollection.cxx
1 /*****************************************************************
2  * $Id: StMuPmdCollection.cxx,v 1.7 2012/11/26 23:14:33 fisyak Exp $
3  *
4  * Class : StMuPmdCollection
5  * Author: Supriya Das & Subhasis Chattopadhyay
6  * ****************************************************************
7  *
8  * Description: This class holds the PMD clusters for MuDst
9  * ****************************************************************
10  * $Log: StMuPmdCollection.cxx,v $
11  * Revision 1.7 2012/11/26 23:14:33 fisyak
12  * Replace GetEntries() by GetEntriesFast(), fix print outs
13  *
14  * Revision 1.6 2004/10/19 01:39:35 mvl
15  * Changed for splitting on file. Added support for hits
16  *
17  * Revision 1.5 2004/08/17 17:42:30 mvl
18  * Removed warning message for empty Pmd collection + corrected some range checking
19  *
20  * Revision 1.4 2004/05/02 04:10:14 perev
21  * private => protected
22  *
23  * Revision 1.3 2004/04/09 23:03:16 jeromel
24  * Ignoring indent, commented out redundant messages (lots of them in the log file)
25  *
26  * Revision 1.2 2004/04/08 23:55:41 jeromel
27  * Extraneous message commented out
28  *
29  * Revision 1.1 2004/04/02 03:36:21 jeromel
30  * New files for PMD
31  *
32  * ****************************************************************/
33 
34 #include <assert.h>
35 #include <string.h>
36 
37 #include "StMuPmdCollection.h"
38 #include "Stiostream.h"
39 #include "StMuPmdUtil.h"
40 #include "StMuPmdCluster.h"
41 #include "StMuPmdHit.h"
42 static StMuPmdUtil util; // to ease decoding of EEMC hits
43 ClassImp(StMuPmdCollection)
44 
46 {
47  for(int i=0;i<2;i++) {
48  mPmdHits[i] = 0;
49  mPmdClusters[i] = 0;
50  }
51 }
52 
53 StMuPmdCollection::StMuPmdCollection(StMuPmdCollection& o) {
54  for ( int i=0; i<2; i++) {
55  mPmdClusters[i] = (TClonesArray*)o.mPmdClusters[i]->Clone();
56  mPmdHits[i] = (TClonesArray*)o.mPmdHits[i]->Clone();
57  }
58 }
59 
60 void StMuPmdCollection::init(int detector)
61 {
62  mPmdClusters[detector - pmd] = new TClonesArray("StMuPmdCluster",0);
63  mPmdHits[detector - pmd] = new TClonesArray("StMuPmdHit",0);
64 }
65 
66 StMuPmdCollection::~StMuPmdCollection()
67 {
68  delete mPmdClusters[0];mPmdClusters[0]=0;
69  delete mPmdClusters[1];mPmdClusters[1]=0;
70 
71 
72  delete mPmdHits[0];mPmdHits[0]=0;
73  delete mPmdHits[1];mPmdHits[1]=0;
74 }
75 
76 void StMuPmdCollection::DeleteThis()
77 {
78  for ( int i=0; i<2; i++) mPmdClusters[i]->Delete();
79  for ( int i=0; i<2; i++) mPmdHits[i]->Delete();
80 }
81 
82 void StMuPmdCollection::clear(Option_t *option)
83 {
84  mPmdClusters[0]->Delete();
85  mPmdClusters[1]->Delete();
86 
87  mPmdHits[0]->Delete();
88  mPmdHits[1]->Delete();
89  return;
90 }
91 
92 int StMuPmdCollection::getNClusters(int detector)
93 {
94  if(detector<pmd || detector>cpv) return 0;
95  TClonesArray *tca =NULL;
96  if(detector>=pmd && detector <= cpv) tca = mPmdClusters[detector-pmd];
97 
98  if (tca) {
99  //cout << "Got tca"<<endl;
100  return tca->GetEntriesFast();
101  } else {
102  //cout << "StMuPmdCollection::getNClusters No tca" << endl;
103  return 0;
104  }
105 }
106 
107 int StMuPmdCollection::getNHits(int detector)
108 {
109  if(detector<pmd || detector>cpv) return 0;
110  TClonesArray *tca =NULL;
111  if(detector>=pmd && detector <= cpv) tca = mPmdHits[detector-pmd];
112 
113  if (tca) {
114  //cout << "Got tca"<<endl;
115  return tca->GetEntriesFast();
116  } else {
117  //cout << "StMuPmdCollection::getNClusters No tca" << endl;
118  return 0;
119  }
120 }
121 
122 StMuPmdCluster* StMuPmdCollection::getCluster(int clusterId,int detector)
123 {
124  if(detector<pmd || detector>cpv) return NULL;
125  TClonesArray *tca = NULL;
126  if(detector>=pmd && detector <= cpv) tca = mPmdClusters[detector-pmd];
127  int counter = tca->GetEntriesFast();
128  if(clusterId<0 || clusterId>counter) return NULL;
129  return (StMuPmdCluster*)tca->At(clusterId);
130 }
131 
132 StMuPmdHit* StMuPmdCollection::getHit(int hitId,int detector)
133 {
134  if(detector<pmd || detector>cpv) return NULL;
135  TClonesArray *tca = NULL;
136  if(detector>=pmd && detector <= cpv) tca = mPmdHits[detector-pmd];
137  int counter = tca->GetEntriesFast();
138  if(hitId<0 || hitId>counter) return NULL;
139  return (StMuPmdHit*)tca->At(hitId);
140 }
141 void StMuPmdCollection::addCluster(int detector)
142 {
143  if(detector<pmd || detector>cpv) return;
144  TClonesArray *tca =NULL;
145  if(detector>=pmd && detector <= cpv) tca = mPmdClusters[detector-pmd];
146 
147  int counter =0;
148  if(mPmdClusters[detector -pmd] == NULL){
149  init(detector);
150  tca = mPmdClusters[detector-pmd];
151  }
152  if(tca) counter=tca->GetEntriesFast();
153  //cout << "addcluster: entry "<<counter<<" "<<detector-pmd<<endl;
154  new ((*tca)[counter]) StMuPmdCluster();
155  // cout<<"counter after2 "<<tca->GetEntriesFast()<<endl;
156  return;
157 }
158 
159 void StMuPmdCollection::addHit(int detector)
160 {
161  if(detector<pmd || detector>cpv) return;
162  TClonesArray *tca =NULL;
163  if(detector>=pmd && detector <= cpv) tca = mPmdHits[detector-pmd];
164 
165  int counter =0;
166  if(mPmdHits[detector -pmd] == NULL){
167  init(detector);
168  tca = mPmdHits[detector-pmd];
169  }
170  if(tca) counter=tca->GetEntriesFast();
171  //cout << "addcluster: entry "<<counter<<" "<<detector-pmd<<endl;
172  new ((*tca)[counter]) StMuPmdHit();
173  // cout<<"counter after2 "<<tca->GetEntriesFast()<<endl;
174  return;
175 }