StRoot  1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
StCtbUtility.cxx
1 #include "tables/St_g2t_ctf_hit_Table.h"
2 #include <StMessMgr.h>
3 
4 
5 #include <StTriggerData.h>
6 
7 // This needs cleanup of the mapping code
8 extern void cts_get_ctb_indexes(long, long &, long &);
9 
10 
11 
12 #include "StCtbUtility.h"
13 //==========================================================
14 //==========================================================
15 StCtbUtility::StCtbUtility() {
16 
17  mCtbEtaSeg=0.5; mCtbPhiSeg=M_PI/30; // NEVER chang this two , JB
18 
19  // parameters
20  mCtbThres_mev=1; //to reject slats with low dE for M-C data, CTB clibration: 2 MeV==5 ADC
21  mCtbThres_ch=2 ; //to reject slats with low ADC for real data
22 
23 
24 }
25 
26 
27 //==========================================================
28 //==========================================================
29 void StCtbUtility::ctb_get_slat_from_data(int slat, int tray, float & phiRad, float &eta) {
30  float phiZero1 = 72 ; // magic lines from Pablo & Herb
31  float phiZero2 = 108 ;
32  float deltaPhi = 6 ;
33  // tray=0,1
34  // slat=0,...,119
35 
36  int iz ;
37  float phi ;
38 
39  if ( tray < 60 ) {
40  phi = phiZero1 - tray * deltaPhi ;
41  iz = 0 ;
42  } else {
43  phi = phiZero2 + (tray-60) * deltaPhi ;
44  iz = 1 ;
45  }
46  if ( phi < 0. ) phi += 360 ;
47  if ( phi > 360. ) phi -= 360 ;
48 
49  phiRad=phi/180*M_PI;
50  eta=(1-2*iz)*(1+2*slat)*0.25;
51  // printf("CTB hit: slat=%d, tray=%d, phiDeg=%f/deg, eta=%f\n",slat,tray,phi,eta);
52 
53 }
54 
55 
56 
57 //==========================================================
58 //==========================================================
59 void StCtbUtility::collectCTBhitsMC(St_DataSet *gds){// M-C CTB
60  // CTB clibration: 2 MeV==5 ADC
61  // RETUN: true if GEANT table with hits exist (even if empty)
62  gMessMgr->Message("","I") <<" use GEANT CTB hits, ADC's with 2 MeV=> 5 ADC, thr/MeV="<<mCtbThres_mev<<endm;
63 
64 
65  if(gds==0) return ;
66 
67  // -------------- E X T R A C T C T B H I T S --------------------
68  //access the CTB data from GEANT
69  St_g2t_ctf_hit *g2t_ctb_hit = (St_g2t_ctf_hit *) gds->Find("g2t_ctb_hit");
70  if(g2t_ctb_hit == 0){
71  LOG_DEBUG << "No CTB Hits in MC table for this event" << endm;
72  LOG_DEBUG << "g2t_ctb_hit = " << g2t_ctb_hit << endm;
73  return ;
74  }
75 
76  g2t_ctf_hit_st *ctb_hit = NULL;
77 
78  //printf("All GEANT CTB hits=%d\n",(int)g2t_ctb_hit->GetNRows());
79 
80  if (g2t_ctb_hit->GetNRows() == 0) gMessMgr->Message("","I") <<" Empty geant/ctb data set "<<endm;
81 
82  ctb_hit = g2t_ctb_hit->GetTable();
83 
84  //assert(ctb_hit);
85  if (! ctb_hit){
86  LOG_WARN << "StCtbUtility::collectCTBhitsMC: no CTB hits" << endm;
87  return ;
88  }
89 
90  int i;
91  for (i = 0; i < g2t_ctb_hit->GetNRows(); i++,ctb_hit++){
92  float de_mev=ctb_hit->de*1000.;
93  if(de_mev>0.01) LOG_INFO<<Form("CTB Hit i=%d de/MeV=%f parent=%d\n",i,de_mev ,ctb_hit->track_p)<<endm;
94  if(de_mev <mCtbThres_mev) continue; // ignore low energy CTB slat
95 
96  long iPhi,iEta;
97  cts_get_ctb_indexes(ctb_hit->volume_id,iPhi,iEta);
98  iPhi--; iEta--; // change range to [0,N-1]
99  // printf("iPhi=%d,iEta=%d de/MeV=%f \n",(int)iPhi,(int)iEta,de_mev);
100  assert(iPhi >= 0 && iPhi<60 && iEta>=0 && iEta<4);
101  //printf("ctb_indexes , hit=%d, vol_id=%d, iPhi=%d, iEta=%d, de/MeV=%f\n",i,(int)ctb_hit->volume_id,(int)iPhi,(int)iEta );
102 
103  ctbHit curHit;
104  curHit.adc=de_mev*2.5 ;
105  curHit.phi=iPhi*mCtbPhiSeg;
106  curHit.eta=iEta*mCtbEtaSeg -0.75;
107  mCtbHits.push_back(curHit);
108 
109  }// end of loop over CTB hits
110 
111 
112  gMessMgr->Message("","I") << mCtbHits.size() << " CTB slats accepted from M-C data"<<endm;
113 
114  return ;
115 }
116 
117 
118 
119 //==========================================================
120 //==========================================================
121 void StCtbUtility::collectCTBhitsData(StTriggerData *trgD){
122  // returns true if one or more valid CTB hits are found.
123  LOG_INFO << "StCtbUtility scans real CTB hits" << endm;
124 
125  // access CTB from Akio's Maker
126 
127  if(!trgD){
128  LOG_WARN << "StCtbUtility scans: no trigData in real data" << endm;
129  return ;
130  }
131 
132  //assert(trgD);
133  for (UInt_t slat = 0; slat < 2; slat++)
134  for (UInt_t tray = 0; tray < 120; tray++) {
135  ctbHit curHit;
136  curHit.adc = trgD->ctbTraySlat(tray,slat,0);
137  if(curHit.adc<mCtbThres_ch) continue;
138  // printf("B sl=%3d tr=%3d %4f\n",slat,tray, curHit.adc );
139  ctb_get_slat_from_data(slat,tray,curHit.phi, curHit.eta);
140  mCtbHits.push_back(curHit);
141  }
142 
143 #if 0
144  // old method , run just for cross check, delete later, JB
145 
146  StTriggerDetectorCollection* trigCol = event->triggerDetectorCollection();
147  if(!trigCol){
148  LOG_WARN << "StCtbUtility scans: no trigCol in Data" << endm;
149  return ;
150  }
151 
152  StCtbTriggerDetector* ctbDet = &(trigCol->ctb());
153  for (UInt_t slat = 0; slat < ctbDet->numberOfSlats(); slat++)
154  for (UInt_t tray = 0; tray < ctbDet->numberOfTrays(); tray++) {
155  ctbHit curHit;
156  curHit.adc = ctbDet->mips(tray,slat,0);
157  if(curHit.adc<mCtbThres_ch) continue;
158  LOG_INFO<<Form("A sl=%3d tr=%3d %4f\n",slat,tray, curHit.adc )<<endm;
159  }
160 
161 #endif
162  return ;
163 }
164 
165 
166 //==========================================================
167 //==========================================================
168 void StCtbUtility::printCtb() {
169  LOG_INFO<<Form("StCtbUtility::print(),nSlat=%d\n",mCtbHits.size())<<endm;
170 
171  unsigned int ih;
172  for(ih=0;ih<mCtbHits.size();ih++) {// loop over CTB hits
173  LOG_INFO<<Form("ih=%d eta=%.3f phi/deg=%.1f adc=%.1f\n",ih
174  ,mCtbHits[ih].eta,mCtbHits[ih].phi/3.1416*180,mCtbHits[ih].adc)<<endm;
175  }
176 }
177 
float mCtbThres_mev
Definition: StCtbUtility.h:23
virtual TDataSet * Find(const char *path) const
Definition: TDataSet.cxx:362