StFms  0.0.0
FMS software in the STAR framework
StMuFmsUtil.cxx
Go to the documentation of this file.
1 /***************************************************************************
2  *
3  * $Id: StMuFmsUtil.cxx,v 1.1 2010/01/25 03:57:39 tone421 Exp $
4  *
5  * Author: Jingguo Ma, Jan 2010
6  ***************************************************************************
7  *
8  * Description: FMS Util to convert between StEvent and MuDst
9  *
10  ***************************************************************************
11  *
12  * $Log: StMuFmsUtil.cxx,v $
13  * Revision 1.1 2010/01/25 03:57:39 tone421
14  * Added FMS and Roman pot arrays
15  *
16  **************************************************************************/
17 #include "StEvent/StFmsCluster.h"
23 #include "StEvent/StEvent.h"
24 #include "St_base/StMessMgr.h"
25 #include "StEvent/StEventTypes.h"
26 
27 #include <algorithm> // For std::find
28 #include <iterator> // For std::distance
29 
30 #include "TCollection.h" // For TIter
31 #include "TRefArray.h"
32 #include "TVector3.h"
33 
35 
36 namespace {
37 /*
38  Return the index of an element in an StPtrVec-like array.
39 
40  The element should be of the pointer type in the StPtrVec.
41  Return -1 if the element cannot be located in the array.
42  See StEvent/StArray.h for the definition of St[S]PtrVec arrays.
43  */
44 template<class StPtrVec, class Element>
45 int findElementIndex(const StPtrVec& array, const Element* element) {
46  // This typedef is equivalent to an iterator to an Element in the StPtrVec,
47  // as defined in StArray.h. The StPtrVec definition does not include a
48  // template iterator typedef itself, but this the same as what
49  // StPtrVec::const_iterator would do.
50  typedef Element* const * ElementConstIter;
51  // Find where the element is in the array
52  ElementConstIter location = std::find(array.begin(), array.end(), element);
53  // Ensure the desired element actually is in the array, as the behaviour
54  // of std::distance is undefined otherwise.
55  // Return -1 if the element isn't in the array, otherwise return its index
56  if (location == array.end()) { // Not in the array
57  return -1;
58  } else {
59  return std::distance(array.begin(), location);
60  } // if
61 }
62 } // namespace
63 
65 {
66 }
68 {
69 }
70 
72 {
73  if(!fmscol) return NULL;
75  fillMuFms(muFms,fmscol);
76  return muFms;
77 }
78 
80 {
81  if(!muFms) return NULL;
82 
84  fillFms(fms,muFms);
85  return fms;
86 }
87 
89 {
90  if(!fmscol) return;
91  if(!muFms) return;
92  // Do hits and points before clusters, so that the hit and point lists are
93  // populated before we try to set hit- and photon-in-cluster information
94  // during the cluster loop
95  fillMuFmsHits(muFms, fmscol);
96  fillMuFmsPoints(muFms, fmscol);
97  fillMuFmsClusters(muFms, fmscol);
98  // Now we need to go back and set parent cluster of each point, now that the
99  // cluster list in StMuFmsCollection is populated (as these are the clusters
100  // we reference).
101  setMuFmsPointParentClusters(muFms, fmscol);
102 }
103 
105 {
106  if(!muFms) return;
107  if(!fmscol) return;
108  fillFmsHits(fmscol, muFms);
109  fillFmsPoints(fmscol, muFms);
110  fillFmsClusters(fmscol, muFms);
111  // Now we need to go back and set parent cluster of each point, now that the
112  // cluster list in StFmsCollection is populated (as these are the clusters
113  // we reference).
114  setFmsPointParentClusters(fmscol, muFms);
115 }
116 
118  StFmsCollection* fmscol) {
119  StSPtrVecFmsHit vecHit = fmscol->hits();
120  for(unsigned int i=0; i<fmscol->numberOfHits(); i++){
121  unsigned short detId = vecHit[i]->detectorId();
122  unsigned short ch = vecHit[i]->channel();
123  unsigned short crate = vecHit[i]->qtCrate();
124  unsigned short slot = vecHit[i]->qtSlot();
125  unsigned short qtch = vecHit[i]->qtChannel();
126  unsigned short adc = vecHit[i]->adc();
127  unsigned short tdc = vecHit[i]->tdc();
128  float ene = vecHit[i]->energy();
129  muFms->addHit();
130  StMuFmsHit* muFmsHit = muFms->getHit(i);
131  muFmsHit->setDetectorId(detId);
132  muFmsHit->setChannel(ch);
133  muFmsHit->setQtCrate(crate);
134  muFmsHit->setQtSlot(slot);
135  muFmsHit->setQtChannel(qtch);
136  muFmsHit->setAdc(adc);
137  muFmsHit->setTdc(tdc);
138  muFmsHit->setEnergy(ene);
139  }
140 }
141 
143  StFmsCollection* fmscol) {
144  // Fill clusters
145  for (unsigned i(0); i < fmscol->numberOfClusters(); ++i) {
146  const StFmsCluster* cluster = fmscol->clusters()[i];
147  muFms->addCluster(); // Expand StMuFmsCollection cluster array by 1
148  StMuFmsCluster* muCluster = muFms->getCluster(i);
149  muCluster->setDetectorId(cluster->detectorId());
150  muCluster->setCategory(cluster->category());
151  muCluster->setEnergy(cluster->energy());
152  muCluster->setX(cluster->x());
153  muCluster->setY(cluster->y());
154  // Propagate hits-in-cluster information
155  // Remember, clusters don't *own* hits, they just reference them.
156  // For each StFmsHit in the cluster, find the index of that hit in the main
157  // StFmsCollection hit array. Then add the StMuFmsHit (from the main
158  // StMuFmsCollection hit array) at the same index to the StMuFmsCluster.
159  StPtrVecFmsHitConstIterator hit; // Iterate over StFmsHits
160  for (hit = cluster->hits().begin(); hit != cluster->hits().end(); ++hit) {
161  const int index = findElementIndex(fmscol->hits(), *hit);
162  if (index != -1) {
163  muCluster->hits()->Add(muFms->getHit(index));
164  } // if
165  } // for
166  // Do the same procedure for photon-in-cluster information
167  StPtrVecFmsPointConstIterator p;
168  for (p = cluster->points().begin(); p != cluster->points().end(); ++p) {
169  const int index = findElementIndex(fmscol->points(), *p);
170  if (index != -1) {
171  muCluster->photons()->Add(muFms->getPoint(index));
172  } // if
173  } // for
174  } // for
175 }
176 
178  StFmsCollection* fmscol) {
179  for (unsigned i(0); i < fmscol->numberOfPoints(); ++i) {
180  const StFmsPoint* point = fmscol->points()[i];
181  StMuFmsPoint* muPoint = muFms->addPoint();
182  if (point && muPoint) {
183  muPoint->set(*point);
184  } // if
185  } // for
186 }
187 
189  StFmsCollection* fmscol) {
190  for (unsigned i(0); i < muFms->numberOfPoints(); ++i) {
191  // Points and clusters in the StMuFmsCollection and StFmsCollection are in
192  // the same order, so we get the corresponding objects just by index
193  const StFmsPoint* point = fmscol->points().at(i);
194  if (!point) {
195  continue;
196  } // if
197  // Find the index of the point's parent cluster in the main cluster list
198  const int index = findElementIndex(fmscol->clusters(), point->cluster());
199  // If we found it, set the StMuFmsPoint's parent cluster to be the
200  // corresponding cluster in the StMuFmsCollection
201  if (index != -1) {
202  StMuFmsPoint* muPoint = muFms->getPoint(i);
203  if (muPoint) {
204  muPoint->setCluster(muFms->getCluster(index));
205  } // if
206  } // if
207  } // for
208 }
209 
211  StMuFmsCollection* muFms) {
212  // Using TIter to iterate is safe in the case of hits being NULL
213  TIter next(muFms->getHitArray());
214  StMuFmsHit* muHit(NULL);
215  while ((muHit = static_cast<StMuFmsHit*>(next()))) {
216  fmscol->addHit(new StFmsHit);
217  StFmsHit* hit = fmscol->hits().back();
218  hit->setDetectorId(muHit->detectorId());
219  hit->setChannel(muHit->channel());
220  hit->setQtCrate(muHit->qtCrate());
221  hit->setQtSlot(muHit->qtSlot());
222  hit->setQtChannel(muHit->qtChannel());
223  hit->setAdc(muHit->adc());
224  hit->setTdc(muHit->tdc());
225  hit->setEnergy(muHit->energy());
226  } // while
227 }
228 
230  StMuFmsCollection* muFms) {
231  // Using TIter to iterate is safe in the case of clusters being NULL
232  TIter next(muFms->getClusterArray());
233  StMuFmsCluster* muCluster(NULL);
234  while ((muCluster = static_cast<StMuFmsCluster*>(next()))) {
235  // Create an StFmsCluster from this StMuFmsCluster
236  fmscol->addCluster(new StFmsCluster);
237  StFmsCluster* cluster = fmscol->clusters().back();
238  cluster->setDetectorId(muCluster->detectorId());
239  cluster->setCategory(muCluster->category());
240  cluster->setNTowers(muCluster->hits()->GetEntries());
241  cluster->setNPhotons(muCluster->photons()->GetEntries());
242  cluster->setEnergy(muCluster->energy());
243  cluster->setX(muCluster->x());
244  cluster->setY(muCluster->y());
245  // StMuFmsCluster does not store all the information in StFmsCluster, so
246  // sigmaMin, sigmaMax, chi2Ndf1Photon, chi2Ndf2Photon and id will not be
247  // filled
250  } // while
251 }
252 
254  StMuFmsCollection* muFms) {
255  // Using TIter to iterate is safe in the case of points being NULL
256  TIter next(muFms->getPointArray());
257  StMuFmsPoint* muPoint(NULL);
258  while ((muPoint = static_cast<StMuFmsPoint*>(next()))) {
259  // Create an StFmsPoint from this StMuFmsPoint
260  fmscol->addPoint(new StFmsPoint);
261  StFmsPoint* point = fmscol->points().back();
262  point->setDetectorId(muPoint->detectorId());
263  point->setEnergy(muPoint->energy());
264  point->setX(muPoint->x());
265  point->setY(muPoint->y());
266  } // while
267 }
268 
270  StMuFmsCollection* muFms) {
271  // Points and clusters in the StMuFmsCollection and StFmsCollection are in
272  // the same order, so we get the corresponding objects just by index
273  for (unsigned i(0); i < muFms->numberOfClusters(); ++i) {
274  const StMuFmsPoint* muPoint = muFms->getPoint(i);
275  if (!muPoint) {
276  continue;
277  } // if
278  const int index = muFms->getClusterArray()->IndexOf(muPoint->cluster());
279  if (index != -1) {
280  StFmsPoint* point = fmscol->points().at(i);
281  if (point) {
282  point->setCluster(fmscol->clusters().at(index));
283  } // if
284  } // if
285  } // for
286 }
TClonesArray * getHitArray()
TRefArray * photons()
void setX(Float_t x0)
Definition: StFmsCluster.h:85
void setY(Float_t ypos)
Definition: StFmsPoint.h:60
void setCluster(StMuFmsCluster *cluster)
Float_t x() const
Definition: StFmsCluster.h:59
void fillFmsPoints(StFmsCollection *, StMuFmsCollection *)
void setY(float y)
Declaration of StMuFmsPoint, the MuDST FMS "point" class.
StFmsCollection * getFms(StMuFmsCollection *)
Definition: StMuFmsUtil.cxx:79
void setEnergy(float energy)
void setMuFmsPointParentClusters(StMuFmsCollection *, StFmsCollection *)
unsigned int numberOfPoints() const
void fillFms(StFmsCollection *, StMuFmsCollection *)
StMuFmsCluster * cluster()
unsigned int numberOfClusters() const
void fillFmsClusters(StFmsCollection *, StMuFmsCollection *)
void setCluster(StFmsCluster *cluster)
Definition: StFmsPoint.h:64
void addPoint(StFmsPoint *)
void setX(Float_t xpos)
Definition: StFmsPoint.h:58
void setY(Float_t y0)
Definition: StFmsCluster.h:87
unsigned int numberOfHits() const
void setAdc(unsigned short)
TRefArray * hits()
Declaration of StFmsCluster, a group of adjacent FMS hits.
unsigned int numberOfClusters() const
UShort_t detectorId() const
Definition: StFmsCluster.h:49
void setQtChannel(unsigned short)
void setQtCrate(unsigned short)
void fillMuFmsClusters(StMuFmsCollection *, StFmsCollection *)
void setTdc(unsigned short)
void setCategory(UShort_t category)
StMuFmsPoint * addPoint()
StMuFmsCluster * getCluster(int index)
void fillMuFmsHits(StMuFmsCollection *, StFmsCollection *)
void setDetectorId(UShort_t detector)
Definition: StFmsPoint.h:54
void addHit(StFmsHit *)
StMuFmsCollection * getMuFms(StFmsCollection *)
Definition: StMuFmsUtil.cxx:71
StSPtrVecFmsPoint & points()
Bool_t setNPhotons(Int_t nPhoton)
void addCluster(StFmsCluster *)
StPtrVecFmsPoint & points()
Definition: StFmsCluster.h:105
void set(const StFmsPoint &)
void setEnergy(Float_t energy)
Definition: StFmsPoint.h:56
void setQtSlot(unsigned short)
void setDetectorId(UShort_t detector)
Definition: StFmsCluster.h:75
StSPtrVecFmsHit & hits()
Declaration of StMuFmsCluster, the MuDST FMS cluster class.
StPtrVecFmsHit & hits()
Definition: StFmsCluster.h:101
void setEnergy(float)
void setEnergy(Float_t energy)
Definition: StFmsCluster.h:83
void setDetectorId(UShort_t detector)
void fillFmsHits(StFmsCollection *, StMuFmsCollection *)
Float_t y() const
Definition: StFmsCluster.h:61
void setNTowers(Int_t numbTower)
Definition: StFmsCluster.h:79
void setChannel(unsigned short)
ClassImp(StMuFmsUtil) namespace
Definition: StMuFmsUtil.cxx:34
unsigned int numberOfPoints() const
void fillMuFmsPoints(StMuFmsCollection *, StFmsCollection *)
void setDetectorId(unsigned short)
void setFmsPointParentClusters(StFmsCollection *, StMuFmsCollection *)
StMuFmsPoint * getPoint(int index)
StSPtrVecFmsCluster & clusters()
Int_t category() const
Definition: StFmsCluster.h:51
TClonesArray * getClusterArray()
void fillMuFms(StMuFmsCollection *, StFmsCollection *)
Definition: StMuFmsUtil.cxx:88
StMuFmsHit * getHit(int hitId)
StFmsCluster * cluster()
Definition: StFmsPoint.h:44
TClonesArray * getPointArray()
void setCategory(Int_t catag)
Definition: StFmsCluster.h:77
Float_t energy() const
Definition: StFmsCluster.h:57
void setX(float x)