StRoot  1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
StFgtSingleEventDisplay.cxx
1 /***************************************************************************
2  *
3  * StFgtSingleEventDisplay.cxx
4  * Author: P. Nord, Sept 2012
5  *
6  ***************************************************************************
7  *
8  * Description: Interface to display strips from the FGT within a standard
9  * STAR event display. No tracks or clusters are being drawn
10  * at this time. The Make() function stores ADC values for each
11  * time bin. Geometry and pedistal values from the database
12  * will be loaded when needed by Make()
13  * Graphics are drawn by a COIN library.
14  *
15  ***************************************************************************
16  *
17  *
18  *
19  **************************************************************************/
20 
21 #include "StFgtSingleEventDisplay.h"
22 #include "StRoot/StFgtUtil/StFgtConsts.h"
23 
24 #include <string>
25 #include <TFile.h>
26 #include <TH2F.h>
27 
28 #include "StRoot/StFgtUtil/geometry/StFgtGeom.h"
29 #include "StRoot/StFgtDbMaker/StFgtDb.h"
30 
31 #include "StRoot/StEvent/StEvent.h"
32 #include "StRoot/StEvent/StFgtCollection.h"
33 #include "StRoot/StEvent/StFgtStripCollection.h"
34 #include "StRoot/StEvent/StFgtStrip.h"
35 
36 // constructors
37 StFgtSingleEventDisplay::StFgtSingleEventDisplay( const Char_t* name, const Char_t* fname ) : StMaker( name ) {
38 };
39 
40 
41 //--------------------------------------------------
42 //--------------------------------------------------
43 //--------------------------------------------------
44 void StFgtSingleEventDisplay::readFgtStripDb(){
45 
46  double pi=2.*acos(0.);
47  double rad2deg=pi/180.;
48 
49  FgtStripDbItem *S;
50 
51  // set db pointer, if needed
52  mFgtDbMkr = static_cast< StFgtDbMaker* >( GetMakerInheritsFrom( "StFgtDbMaker" ) );
53  if( !mFgtDbMkr ){
54  LOG_FATAL << "Error finding StFgtDbMaker" << endm;
55  assert(!mFgtDbMkr);
56  };
57 
58  //cout << "Got DB"<< endl;
59  mDb = mFgtDbMkr->getDbTables();
60  //cout << "Got DB"<< endl;
61 
62 
63  int nTry=0, nMap=0;
64  Int_t geoId;
65  for (int rdo=1;rdo<=2;rdo++){// 2 RDOs numbered 1,2
66  for (int arm=0;arm<6;arm++){//6 arms numbered from 0
67  for (int apv=0;apv<=21;apv++){//24 APVs numbered 0-23 but in real life APV# 10,11,22,23 are unused so 0-19 in determining electronic Id
68  if ((apv==10)||(apv==11)) continue;
69  for (int channel=0;channel<128;channel++){//128 channels numbered from 0
70  nTry++;
71  geoId=mDb->getGeoIdFromElecCoord(rdo, arm, apv, channel);
72  if (geoId<0) continue;
73  std::string geoName=mDb->getGeoNameFromElecCoord(rdo,arm,apv,channel);
74  //cout << numFgtElect << " ";
75  S = &(stripDb[numFgtElect]);
76  S->geoId = geoId;
77  entryForGeoId[geoId] = numFgtElect++; // local lookup table
78  nMap++;
79  Double_t ordinate,lowerSpan,upperSpan;
80  StFgtGeom::decodeGeoId(S->geoId,S->disc,S->quad,S->layer,S->strip);
81  StFgtGeom::getGlobalPhysicalCoordinate(geoName,S->disc,S->quad,S->layer,ordinate, lowerSpan, upperSpan);
82 
83  if (S->layer=='P') {
84  S->phi1=S->phi2=ordinate;
85  S->r1=lowerSpan;
86  S->r2=upperSpan;
87  S->x1=S->r1*cos(S->phi1);
88  S->x2=S->r2*cos(S->phi2);
89  S->y1=S->r1*sin(S->phi1);
90  S->y2=S->r2*sin(S->phi2);
91  } else {
92  S->r1=S->r2=ordinate;
93  S->phi1=lowerSpan;
94  S->phi2=upperSpan;
95  S->phi1Deg=S->phi1/rad2deg;
96  S->phi2Deg=S->phi2/rad2deg;
97  }
98  //cout << " geoId=" << geoId << " " << geoName << " ";
99  //cout << "d=" << S->disc << " lr=" << S->layer << " ";
100  //cout << "q=" << S->quad << " sp=" << S->strip << " ";
101 
102 
103  S->ped = mDb->getPedestalFromElecCoord(rdo,arm,apv,channel);
104  S->sigPed= mDb->getPedestalSigmaFromElecCoord(rdo,arm,apv,channel);
105  S->stat = mDb->getStatusFromElecCoord(rdo,arm,apv,channel);
106  S->electId = StFgtGeom::getElectIdFromElecCoord(rdo,arm,apv,channel);
107  S->Z = StFgtGeom::getDiscZ(S->disc);
108  //cout << " r1=" << S->r1 ;
109  //cout << " r2=" << S->r2 ;
110  //cout << " x1=" << S->x1 ;
111  //cout << " x2=" << S->x2 ;
112  //cout << " y1=" << S->y1 ;
113  //cout << " y2=" << S->y2 ;
114  //cout << " p1=" << S->phi1 ;
115  //cout << " p2=" << S->phi2 ;
116  //cout << " Z=" << S->Z <<endl;
117 
118  }
119  }
120  }
121  }
122 }
123 
124 
125 // deconstructor
126 StFgtSingleEventDisplay::~StFgtSingleEventDisplay(){
127 };
128 
129 Int_t StFgtSingleEventDisplay::Init(){
130  Int_t ierr = kStOk;
131 
132  mEventNum = 0;
133 
134  return ierr;
135 };
136 
138  Int_t ierr = kStOk;
139 
140  StEvent* eventPtr = 0;
141  mFgtCollectionPtr = 0;
142 
143  if (mDb == NULL) readFgtStripDb(); // Lazy instantiation of the Db
144 
145  for(int j = 0; j < numFgtElect; j++) {
146  stripDb[j].hit = 0; // clear any previous hits
147  }
148 
149  eventPtr = (StEvent*)GetInputDS("StEvent");
150  if( !eventPtr ) {
151  LOG_ERROR << "Error getting pointer to StEvent in '" << ClassName() << "'" << endm;
152  ierr = kStErr;
153  } else {
154  mFgtCollectionPtr=eventPtr->fgtCollection();
155 
156  if( !mFgtCollectionPtr) {
157  LOG_ERROR << "Error getting pointer to StFgtCollection in '" << ClassName() << "'" << endm;
158  ierr = kStErr;
159  };
160  };
161  //printf("analysis\n");
162 
163  for( Int_t disc = 0; disc < kFgtNumDiscs; ++disc ){
164  //printf("disc = %d\n",disc);
165  StFgtStripCollection *stripCollectionPtr = 0;
166  if( !ierr ){
167  stripCollectionPtr = mFgtCollectionPtr->getStripCollection( disc );
168  };
169  //printf("stripCollectionPtr = %d\n",stripCollectionPtr);
170 
171  if( stripCollectionPtr ){
172  const StSPtrVecFgtStrip &stripVec = stripCollectionPtr->getStripVec();
173  StSPtrVecFgtStripConstIterator stripIter;
174  stripIter = stripVec.begin();
175  //printf("stripVec = %d\n",stripVec);
176 
177  for( stripIter = stripVec.begin(); stripIter != stripVec.end(); ++stripIter ){
178  //printf("stripIter = %d\n",stripIter);
179  Int_t geoId = (*stripIter)->getGeoId();
180  //printf("geoId = %d\n",geoId);
181  if(geoId < 0) continue; // strip is flagged for removal
182 
183 
184  // to store position data
185  Short_t disc, quad, strip;
186  Char_t layer;
187  StFgtGeom::decodeGeoId( geoId, disc, quad, layer, strip );
188  Int_t entry = getEntryForGeoId(geoId);
189  Short_t ped = stripDb[entry].ped;
190  Double_t pedDb=mDb->getPedestalFromGeoId(geoId);
191  Short_t statDb=mDb->getStatusFromGeoId(geoId);
192  //cout<<" Peds = "<<pedDb<<" Stats = "<<statDb<<endl;
193  Short_t sigPed = stripDb[entry].sigPed;
194 
195  //if (stripDb[entry].stat != 0) {
196  //printf("geoid %d stat %d\n", geoId, stripDb[entry].stat);
197  //}
198  //stripDb[entry].stat = stat;
199 
200  for( Int_t tb = 0; tb < kFgtNumTimeBins; ++tb ){
201  Short_t adc = (*stripIter)->getAdc(tb);
202 
203  // Note: r strips 0-279 and phi strips 0-359 are for
204  // the half of the quadrant with local coordinate phi
205  // in the range of pi/4 and pi/2. Note: phi increases
206  // for decreasing phi strip number. r strips in
207  // 400-679 and phi strips in 360-719 are for the local
208  // coordinate phi in the range 0 to pi/4. Short side
209  // is for phi strips near 720, i.e. short side has
210  // smaller local phi values than long side.
211  Bool_t octIsShort = ( layer == 'R' ? (strip > 279) : (strip > 359) );
212 
213  //Int_t bin = ( quad*2 + octIsShort )*kFgtNumTimeBins + tb;
214 
215  stripDb[entry].adc[tb] = adc;
216  //printf("geoId=%d entry=%d timebin=%d ped=%d adc=%d\n",geoId,entry,tb,ped,adc);
217 
218  if(adc > ped + 6 * sigPed) {
219  //printf("timebin = %d ped = %d adc = %d\n",tb,ped,adc);
220  stripDb[entry].hit += 1<<tb; // encode the timebin into hit
221  }
222 
223 
224  };
225  };
226 
227  };
228  };
229 
230  ++mEventNum;
231  return ierr;
232 };
233 
234 void StFgtSingleEventDisplay::drawStrip(Int_t geoId, Color_t lineColor) {
235  Short_t disc;
236  Short_t quad;
237  Char_t layer;
238  Int_t strip;
239  Double_t x1; Double_t y1;
240  Double_t x2; Double_t y2;
241  Double_t z;
242 
243 
244  Int_t entry = getEntryForGeoId(geoId);
245 
246  assert(entry >= 0); // error contition, bad geoId
247 
248  x1 = stripDb[entry].x1;
249  y1 = stripDb[entry].y1;
250  x2 = stripDb[entry].x2;
251  y2 = stripDb[entry].y2;
252  z = stripDb[entry].Z;
253 
254  disc = stripDb[entry].disc;
255  quad = stripDb[entry].quad;
256  layer = stripDb[entry].layer;
257  strip = stripDb[entry].strip;
258  Short_t ped = stripDb[entry].ped;
259  Short_t sigPed = stripDb[entry].sigPed;
260  Short_t maxAdc;
261  maxAdc = 0;
262  for (int l = 0; l < kFgtNumTimeBins-1; l++) {
263  if(stripDb[entry].adc[l] > maxAdc) {
264  maxAdc = stripDb[entry].adc[l];
265  }
266  //printf("tb %d adc %d maxAdc %d\n",l,stripDb[entry].adc[l], maxAdc);
267  }
268 
269  Char_t stripName[256];
270  sprintf(stripName,"FGT%d %d%c%c%d %d%c%d %d",geoId,disc,quad,layer,strip,ped,177/*ascii +-*/,sigPed,maxAdc);
271 
272  //lineColor = 3;
273 
274 #define NUM_SEGMENTS 10
275 
276  float xyz[NUM_SEGMENTS][3];
277 
278  //cout << " geo=" << geoId ;
279  //cout << " #=" << entry ;
280  //cout << " l=" << disc ;
281  //cout << " q=" << quad ;
282  //cout << " x1=" << x1 ;
283  //cout << " x2=" << x2 ;
284  //cout << " y1=" << y1 ;
285  //cout << " y2=" << y2 ;
286  //cout << " Z=" << z <<endl;
287 
288  if( layer=='P') { //ppppppppppppppppppppp
289  xyz[0][0] = x1;
290  xyz[0][1] = y1;
291  xyz[0][2] = z;
292  xyz[1][0] = x2;
293  xyz[1][1] = y2;
294  xyz[1][2] = z ;
295  gEventDisplay->Line(2, (float *) xyz, lineColor);
296  gEventDisplay->SetComment(stripName);
297  //printf("in drawStrip\n");
299  } // end of P-plane
300 
301 
302  if( layer=='R' ) { //RRRRRRRRRRRRRRRRRRRRRRR
303 
304  Double_t phiDiff;
305  Double_t mx1, my1, phi1, phi2, r1;
306  r1 = stripDb[entry].r1;
307  phi1 = stripDb[entry].phi1;
308  phi2 = stripDb[entry].phi2;
309  phiDiff = (phi2 - phi1)/ (NUM_SEGMENTS - 1.0);
310  for (int j = 0; j < NUM_SEGMENTS; j++) {
311 
312  mx1=r1*cos(phi1 + phiDiff*j);
313  my1=r1*sin(phi1 + phiDiff*j);
314 
315  xyz[j][0] = mx1;
316  xyz[j][1] = my1;
317  xyz[j][2] = z;
318  //printf("%d %f %f %f %f %f\n", j, x1, y1, myz, mx1, mx2);
319  }
320 
321  gEventDisplay->Line(NUM_SEGMENTS, (float*) xyz, lineColor );
322  //gEventDisplay->Line(NUM_SEGMENTS, (float*) xyz, kPrimaryTrack);
323  gEventDisplay->SetComment(stripName);
324  //printf("in drawStrip\n");
325  //gEventDisplay->SetComment(S->name);
326  //numDrawn++;
327  //printf("%d\n",numDrawn);
328 
329  } // end of R-plane
330 
331 }
332 
334  return kStOk;
335 };
336 
337 ClassImp(StFgtSingleEventDisplay);
virtual TObject * Line(int n, const double *xyz, Color_t col=Color_t(-1), Style_t sty=Style_t(-1), Size_t siz=Size_t(-1))
This is an overloaded member function, provided for convenience.
Definition: StDraw3D.cxx:807
Definition: Stypes.h:44
Definition: Stypes.h:41