StRoot  1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
StFgtPointMaker.cxx
1 //\class StFgtPointMaker
2 //\author Anselm Vossen (avossen@indiana.edu)
3 //
4 
5 #include "StFgtPointMaker.h"
6 #include "StEventTypes.h"
7 #include "StRoot/StEvent/StEvent.h"
8 #include "StRoot/StFgtDbMaker/StFgtDbMaker.h"
9 #include "StRoot/StFgtDbMaker/StFgtDb.h"
10 #include "StarClassLibrary/StThreeVectorF.hh"
11 #include "StTpcDb/StTpcDb.h"
12 #include "TGeoManager.h"
13 
14 #include "StFgtSimplePointAlgo.h"
15 
16 void StFgtPointMaker::Clear(Option_t *opts)
17 {
18 
19 };
20 
21 Int_t StFgtPointMaker::setPointAlgo(StFgtIPointAlgo* algo)
22 {
23  mPointAlgoPtr=algo;
24  return kStOk;
25 }
26 
27 
29 {
30  Int_t ierr = kStOk;
31 
32  StEvent* eventPtr = 0;
33  eventPtr = (StEvent*)GetInputDS("StEvent");
34 
35  if( !eventPtr ) {
36  LOG_ERROR << "Error getting pointer to StEvent from '" << ClassName() << "'" << endm;
37  ierr = kStErr;
38  };
39 
40  StFgtCollection* fgtCollectionPtr = 0;
41 
42  if( eventPtr ) {
43  fgtCollectionPtr=eventPtr->fgtCollection();
44  };
45 
46  if( !fgtCollectionPtr) {
47  LOG_ERROR << "Error getting pointer to StFgtCollection from '" << ClassName() << "'" << endm;
48  ierr = kStErr;
49  }
50 
51  StThreeVectorF serr(0.01,0.01,0.1);
52  if( !ierr ){
53  StFgtPointCollection *pointCollectionPtr = fgtCollectionPtr->getPointCollection();
54 
55  if(mFakeData==0.0){
56  ierr = mPointAlgoPtr->makePoints( *fgtCollectionPtr );
57  //now points are made... setting xyz, error, detectorId, etc
58  int npoint[kFgtNumDiscs][kFgtNumQuads]; memset(npoint,0,sizeof(npoint));
59  if( !ierr ){
60  StSPtrVecFgtPoint &point = pointCollectionPtr->getPointVec();
61  for(StSPtrVecFgtPointIterator it=point.begin(); it!=point.end(); it++) {
62  int idisc=(*it)->getDisc();
63  int iquad=(*it)->getQuad();
64  float phi = (*it)->getPositionPhi();
65  float r = (*it)->getPositionR();
66  TVector3 xyz,gxyz;
67  mDb->getStarXYZ(idisc,iquad,r,phi,xyz);
68  if(gStTpcDb){
69  double local[3]={0,0,0}, global[3]={0,0,0};
70  xyz.GetXYZ(local);
71  //printf("FGT local %9.6f %9.6f %9.6f %9.6f\n",local[0],local[1],local[2],local[3]);
72  TGeoHMatrix globalMatrix = gStTpcDb->Tpc2GlobalMatrix();
73  //globalMatrix.Print();
74  globalMatrix.LocalToMaster(local,global);
75  gxyz.SetXYZ(global[0],global[1],global[2]);
76  }else{
77  static int nmess=0;
78  if(nmess<100){
79  printf("StFgtPointMaker::Make could not get gStTpcDb... global xyz is same as fgt local xyz\n");
80  nmess++;
81  }
82  gxyz=xyz;
83  }
84  //printf("FGT Globl %9.6f %9.6f %9.6f\n",gxyz.X(),gxyz.Y(),gxyz.Z());
85  StThreeVectorF sxyz(gxyz.X(),gxyz.Y(),gxyz.Z());
86  (*it)->setPosition(sxyz);
87  (*it)->setPositionError(serr);
88  //printf("FgtPoint %3d D=%1d Q=%1d R=%6.3f P=%6.3f x=%6.3f y=%6.3f z=%6.3f\n",
89  // npoint[idisc][iquad],idisc,iquad,r,phi,sxyz.x(),sxyz.y(),sxyz.z());
90  npoint[idisc][iquad]++;
91  }
92  }
93  if(mSkipEvent>0){
94  printf("FgtPoint : ");
95  int max=0;
96  for(int q=0; q<kFgtNumQuads; q++){
97  int n=0;
98  for(int d=0; d<kFgtNumDiscs; d++) {if(npoint[d][q]>0) n++;}
99  printf("Q%1d=%3d ",q,n);
100  if(max<n) max=n;
101  }
102  printf(" max=%d",max);
103  if(max<mSkipEvent) {ierr=kStSKIP; printf(" SKIPPING Event!"); }
104  printf("\n");
105  }
106  }else{ //fake FGT and TPC hits at eta=mFakeData, phi=0
107  StSPtrVecFgtPoint& pointVec = pointCollectionPtr->getPointVec();
108  int quad=0;
109  float eta=mFakeData;
110  float phi=0.0;
111  float theta=2*atan(exp(-eta));
112  for(short d=0; d<6; d++){
113  StFgtHitCollection *hitCollectionPtr = fgtCollectionPtr->getHitCollection(d);
114  StSPtrVecFgtHit &clustVec = hitCollectionPtr->getHitVec();
115  float z=StFgtGeom::getDiscZ(d);
116  float x=z*tan(theta);
117  float y=0;
118  float r=sqrt(x*x+y*y);
119  if(r<38.3){
120  printf("FakeData FGT eta=%6.3f phi=%6.3f z,x=%6.3f,%6.3f\n",eta,phi,z,x);
121  StFgtHit *phit = new StFgtHit(d*2, 11,1050,d,quad,'P',0,0.1,phi,0.1,z,0.1); clustVec.push_back(phit);
122  StFgtHit *rhit = new StFgtHit(d*2+1,11,1000,d,quad,'R',r,0.1,0 ,0.1,z,0.1); clustVec.push_back(rhit);
123  StFgtPoint *p = new StFgtPoint(phit,rhit,d,1); pointVec.push_back(p);
124  StThreeVectorF xyz(x,y,z);
125  p->setPosition(xyz);
126  p->setPositionError(serr);
127  }
128  }
129  StTpcHitCollection* tpcHits = eventPtr->tpcHitCollection();
130  if ( !tpcHits ) {
131  tpcHits = new StTpcHitCollection();
132  eventPtr->setTpcHitCollection(tpcHits);
133  }
134  float tpcr[45];
135  for(int ipad= 0;ipad< 8; ipad++){tpcr[ipad]=60.0 + 4.8*ipad;}
136  for(int ipad= 8;ipad<13; ipad++){tpcr[ipad]=60.0 + 4.8*7 + 5.2*(ipad-8);}
137  for(int ipad=13;ipad<45; ipad++){tpcr[ipad]=127.950 + 2.0*(ipad-13);}
138  for(int ipad=0; ipad<45; ipad++){
139  float r=tpcr[ipad];
140  float x=r;
141  float y=0;
142  float z=r/tan(theta);
143  if(z<210){
144  printf("FakeData TPC eta=%6.3f phi=%6.3f z,x=%6.3f,%6.3f\n",eta,phi,z,x);
145  StThreeVectorF xyz(x,y,z);
146  StThreeVectorF exyz(0.1,0.1,0.1);
147  int sector=3;
148  int row=ipad+1;
149  int hw = 1 + (sector<<4) + (row<<9);
150  StTpcHit* t=new StTpcHit(xyz,exyz,hw,10);
151  tpcHits->addHit(t);
152  }
153  }
154  }
155  }
156  return ierr;
157 }
158 
159 
160 
161 Int_t StFgtPointMaker::Init()
162 {
163 
164  Int_t ierr = kStOk;
165 
166  if( !mPointAlgoPtr ){
167  LOG_WARN << "No fgt point algorithm specified" << endm;
168  mPointAlgoPtr=new StFgtSimplePointAlgo();
170  AddObj(mPointAlgoPtr,".data",0);
171  ierr = kStOk;
172  };
173  if( !ierr )
174  ierr = mPointAlgoPtr->Init();
175 
176  StFgtDbMaker *fgtDbMkr = static_cast< StFgtDbMaker* >( GetMakerInheritsFrom( "StFgtDbMaker" ) );
177  if( !fgtDbMkr ){
178  LOG_FATAL << "StFgtDb not provided and error finding StFgtDbMaker" << endm;
179  ierr = kStFatal;
180  } else {
181  mDb = fgtDbMkr->getDbTables();
182  if( !mDb ){
183  LOG_FATAL << "StFgtDb not provided and error retrieving pointer from StFgtDbMaker '"
184  << fgtDbMkr->GetName() << endm;
185  ierr = kStFatal;
186  }
187  }
188  return ierr;
189 }
190 
191 StFgtPointMaker::StFgtPointMaker( const Char_t* name ) : StMaker(name),mPointAlgoPtr(0),mSkipEvent(0),mFakeData(0)
192 {
193  /* noop */
194 };
195 
196 StFgtPointMaker::~StFgtPointMaker()
197 {
198  /* noop */
199  if (mPointAlgoPtr){
200  LOG_INFO << "Cleaning up point Algo" << endm;
201  delete mPointAlgoPtr;
202  }
203 };
204 
205 
206 ClassImp(StFgtPointMaker);
207 
208 /*
209  * $Id: StFgtPointMaker.cxx,v 1.4 2013/04/25 11:52:31 akio Exp $
210  * $Log: StFgtPointMaker.cxx,v $
211  * Revision 1.4 2013/04/25 11:52:31 akio
212  * *** empty log message ***
213  *
214  * Revision 1.3 2013/04/04 20:24:49 akio
215  * - Filling StHit with xyz, error on xyz and detectorId
216  * - Add option to return kStSkip if max number of disc hit per quad is less than setSkipEvent (default 0)
217  * This is for expert only, and not for production. Use it with SetAttr(".Privilege",1)
218  *
219  * Revision 1.2 2013/03/13 21:31:47 jeromel
220  * Minor modif
221  *
222  * Revision 1.1 2013/03/13 20:36:28 jeromel
223  * Initial revision, Anselm Vossen
224  *
225  * Revision 1.6 2011/11/04 18:55:50 ckriley
226  * minor bug fix
227  *
228  * Revision 1.5 2011/11/01 18:48:34 sgliske
229  * Updated to correspond with StEvent containers, take 2.
230  *
231  * Revision 1.3 2011/10/28 14:41:27 sgliske
232  * Changed to get StFgtEvent from StEvent rather than another maker.
233  * Also pPointrAlgo changed to mPointerAlgoPtr to conform with STAR guidelines.
234  *
235  */
virtual void Clear(Option_t *opts="")
User defined functions.
Definition: Stypes.h:48
virtual Int_t Make()
virtual const char * GetName() const
special overload
Definition: StMaker.cxx:237
Definition: Stypes.h:44
Definition: Stypes.h:41
Represents a point in the FGT.
Definition: StFgtPoint.h:49