StRoot  1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
StFmsPoint.cxx
1 /***************************************************************************
2  *
3  * $Id: StFmsPoint.cxx,v 2.8 2017/11/20 20:01:49 smirnovd Exp $
4  *
5  * Author: Thomas Burton, Yuxi Pan, 2014
6  ***************************************************************************
7  *
8  * Description: Implementation of StFmsPoint, the StEvent FMS
9  * photon structure
10  *
11  ***************************************************************************
12  *
13  * $Log: StFmsPoint.cxx,v $
14  * Revision 2.8 2017/11/20 20:01:49 smirnovd
15  * Remove StRoot/ from included header prefix
16  *
17  * Revision 2.7 2016/06/07 15:51:34 akio
18  * Making code better based on Coverity reports
19  *
20  * Revision 2.6 2015/09/14 16:59:22 ullrich
21  * Added comments and modified print out.
22  *
23  * Revision 2.5 2015/09/01 21:01:47 ullrich
24  * Minor changes to format of print statments and \nchange to naming of data member.
25  *
26  * Revision 2.4 2015/09/01 18:29:01 ullrich
27  * Changes due to adding StFpsSlat and interconnection between slats and points.
28  *
29  * Revision 2.3 2015/08/26 16:51:25 ullrich
30  * Fixed bug in cluster() and added print out fct and operator.
31  *
32  * Revision 2.2 2015/08/19 19:22:34 ullrich
33  * Major update (PID) by Akio.
34  *
35  *
36  ***************************************************************************/
37 #include "StFmsPoint.h"
38 #include "St_base/StMessMgr.h"
39 #include "TMath.h"
40 
41 static const char rcsid[] = "$Id: StFmsPoint.cxx,v 2.8 2017/11/20 20:01:49 smirnovd Exp $";
42 
43 StFmsPoint::StFmsPoint()
44 : mDetectorId(0), mEnergy(-1.0), mX(-99.0), mY(-99.0),
45 mId(-1), mParentClusterId(-1), mNParentClusterPhotons(-1), mCluster(0)
46 {
47  resetFps();
48 }
49 
50 StFmsPoint::~StFmsPoint() { /* no op */ }
51 
52 int StFmsPoint::fpsNCandidate(int layer) {
53  if (layer>=1 && layer<=kFpsNLayer) {
54  return mFpsNCandidate[layer-1];
55  }
56  return 0;
57 }
58 
59 float StFmsPoint::fpsMip(int layer, int candidate) {
60  if(layer<1 || layer>kFpsNLayer) return -1;
61  if(candidate>=0 && candidate<kFpsNCandidate) return mFpsMip[layer-1][candidate]; //return mip for a candidate
62  if(candidate>=kFpsNCandidate && candidate<=kFpsNCandidate+2){ // candidate=kFpsNCandidate return 1+2
63  float sum=0.0; // candidate=kFpsNCandidate+1 return 1+2+3
64  for(int i=0; i<candidate-kFpsNCandidate+2; i++){ // candidate=kFpsNCandidate+2 return 1+2+3+4
65  if(i==0 && mFpsMip[layer-1][i]==-9.0) return -9.0; // if closest one has bad status, return bad.
66  if(mFpsMip[layer-1][i]>0.0) sum+=mFpsMip[layer-1][i];
67  }
68  return sum;
69  }
70  return -1;
71 }
72 
73 int StFmsPoint::fpsSlatId(int layer, int candidate) {
74  if (layer>=1 && layer<=kFpsNLayer && candidate>=0 && candidate<mFpsNCandidate[layer-1]){
75  return mFpsSlatId[layer-1][candidate];
76  }
77  return -1;
78 }
79 
80 float StFmsPoint::fpsDistance(int layer, int candidate) {
81  if (layer>=1 && layer<=kFpsNLayer && candidate>=0 && candidate<mFpsNCandidate[layer-1]){
82  return mFpsDistance[layer-1][candidate];
83  }
84  return 999.0;
85 }
86 
87 void StFmsPoint::setFps(int layer, float mip, int slatid, float d) {
88  if (layer>=1 && layer<=kFpsNLayer){
89  int n=mFpsNCandidate[layer-1];
90  if (n>=kFpsNCandidate) {
91  LOG_WARN << Form("StFmsPoint::setFps() too many FPS slats associcated with a point in layer=%d (slatid=%d distance=%6.2f mip=%6.2f) n=%d/%d"
92  ,layer,slatid,d,mip,n,kFpsNCandidate) <<endm;
93  return;
94  }
95  mFpsMip[layer-1][n] = mip;
96  mFpsSlatId[layer-1][n] = slatid;
97  mFpsDistance[layer-1][n] = d;
98  mFpsNCandidate[layer-1]++;
99  }
100  orderFpsCandidates(layer);
101 }
102 
103 void StFmsPoint::resetFps() {
104  mFpsPid = 0;
105  for(int l=0; l<kFpsNLayer; l++){
106  mFpsNCandidate[l]=0;
107  for(int c=0; c<kFpsNCandidate; c++){
108  mFpsMip[l][c] = -2.0;
109  mFpsSlatId[l][c] = -1;
110  mFpsDistance[l][c] = 999.0;
111  }
112  }
113 }
114 
115 void StFmsPoint::orderFpsCandidates(int layer) { //order candidates by distance
116  int l1=0, l2=kFpsNLayer;
117  if(layer>0) {l1=layer-1; l2=layer;}
118  for(int l=l1; l<l2; l++){
119  int n=mFpsNCandidate[l];
120  if(n<2) continue;
121  int index[kFpsNCandidate];
122  TMath::Sort(n,mFpsDistance[l],index,false); //flase=increasing order
123  for(int i=0; i<n-1; i++) { //swap contents based on index
124  int j=index[i];
125  if(j!=i){
126  float mip = mFpsMip[l][i];
127  int slatid = mFpsSlatId[l][i];
128  float d = mFpsDistance[l][i];
129  mFpsMip[l][i] = mFpsMip[l][j];
130  mFpsSlatId[l][i] = mFpsSlatId[l][j];
131  mFpsDistance[l][i] = mFpsDistance[l][j];
132  mFpsMip[l][j] = mip;
133  mFpsSlatId[l][j] = slatid;
134  mFpsDistance[l][j] = d;
135  for(int k=i+i; k<n; k++){ // swap index as well
136  if(index[k]==i) {
137  index[k]=j;
138  index[i]=i;
139  break;
140  }
141  }
142  }
143  }
144  }
145 }
146 
147 void StFmsPoint::print(int opt) {
148  cout << Form("StFmsPoint: Id=%4d Det=%2d ParentId=%3d loc=%6.1f %6.1f xyz=%6.1f %6.1f %6.1f E=%7.2f ET=%6.2f FPS=",
149  id(), detectorId(), parentClusterId(),
150  x(), y(), XYZ().x(), XYZ().y(), XYZ().z(), energy(), fourMomentum().perp());
151  for(int i=1; i<=kFpsNLayer; i++) {
152  //int mip=fpsMip(i,kFpsNCandidate);
153  float mip=fpsMip(i,0);
154  if(mip<0.0) {cout << "?";}
155  else if(mip>9.0) {cout << "9";}
156  else {cout << Form("%1d",int(mip+0.5));}
157  }
158  cout << Form(" PID=%2d(%s) ",fpsPid(),pidName(fpsPid()));
159  for(int l=1; l<=kFpsNLayer; l++){
160  for(int j=0; j<fpsNCandidate(l); j++){
161  int slatid=fpsSlatId(l,j);
162  int mip=int(fpsMip(l,j)+0.5);
163  int slat=slatid%21+1;
164  int layer=(slatid/21)%3+1;
165  int quad=(slatid/21/3)+1;
166  cout << Form(" Q%1dL%1dS%02d=%2d ",quad,layer,slat,mip);
167  }
168  }
169  cout << endl;
170 }