00001 #include <stdio.h>
00002 #include <cmath>
00003 #include <sys/types.h>
00004 #include "math_constants.h"
00005
00006 #include "tables/St_g2t_ctf_hit_Table.h"
00007 #include <StMessMgr.h>
00008
00009
00010 #include <StTriggerData.h>
00011
00012
00013 extern void cts_get_ctb_indexes(long, long &, long &);
00014
00020 #include "StCtbUtility.h"
00021
00022
00023 StCtbUtility::StCtbUtility() {
00024
00025 mCtbEtaSeg=0.5; mCtbPhiSeg=C_PI/30;
00026
00027
00028 mCtbThres_mev=1;
00029 mCtbThres_ch=2 ;
00030
00031
00032 }
00033
00034
00035
00036
00037 void StCtbUtility::ctb_get_slat_from_data(int slat, int tray, float & phiRad, float &eta) {
00038 float phiZero1 = 72 ;
00039 float phiZero2 = 108 ;
00040 float deltaPhi = 6 ;
00041
00042
00043
00044 int iz ;
00045 float phi ;
00046
00047 if ( tray < 60 ) {
00048 phi = phiZero1 - tray * deltaPhi ;
00049 iz = 0 ;
00050 } else {
00051 phi = phiZero2 + (tray-60) * deltaPhi ;
00052 iz = 1 ;
00053 }
00054 if ( phi < 0. ) phi += 360 ;
00055 if ( phi > 360. ) phi -= 360 ;
00056
00057 phiRad=phi/180*C_PI;
00058 eta=(1-2*iz)*(1+2*slat)*0.25;
00059
00060
00061 }
00062
00063
00064
00065
00066
00067 void StCtbUtility::collectCTBhitsMC(St_DataSet *gds){
00068
00069
00070 gMessMgr->Message("","I") <<" use GEANT CTB hits, ADC's with 2 MeV=> 5 ADC, thr/MeV="<<mCtbThres_mev<<endm;
00071
00072
00073 if(gds==0) return ;
00074
00075
00076
00077 St_g2t_ctf_hit *g2t_ctb_hit = (St_g2t_ctf_hit *) gds->Find("g2t_ctb_hit");
00078 if(g2t_ctb_hit == 0){
00079 LOG_DEBUG << "No CTB Hits in MC table for this event" << endm;
00080 LOG_DEBUG << "g2t_ctb_hit = " << g2t_ctb_hit << endm;
00081 return ;
00082 }
00083
00084 g2t_ctf_hit_st *ctb_hit = NULL;
00085
00086
00087
00088 if (g2t_ctb_hit->GetNRows() == 0) gMessMgr->Message("","I") <<" Empty geant/ctb data set "<<endm;
00089
00090 ctb_hit = g2t_ctb_hit->GetTable();
00091
00092
00093 if (! ctb_hit){
00094 LOG_WARN << "StCtbUtility::collectCTBhitsMC: no CTB hits" << endm;
00095 return ;
00096 }
00097
00098 int i;
00099 for (i = 0; i < g2t_ctb_hit->GetNRows(); i++,ctb_hit++){
00100 float de_mev=ctb_hit->de*1000.;
00101 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;
00102 if(de_mev <mCtbThres_mev) continue;
00103
00104 long iPhi,iEta;
00105 cts_get_ctb_indexes(ctb_hit->volume_id,iPhi,iEta);
00106 iPhi--; iEta--;
00107
00108 assert(iPhi >= 0 && iPhi<60 && iEta>=0 && iEta<4);
00109
00110
00111 ctbHit curHit;
00112 curHit.adc=de_mev*2.5 ;
00113 curHit.phi=iPhi*mCtbPhiSeg;
00114 curHit.eta=iEta*mCtbEtaSeg -0.75;
00115 mCtbHits.push_back(curHit);
00116
00117 }
00118
00119
00120 gMessMgr->Message("","I") << mCtbHits.size() << " CTB slats accepted from M-C data"<<endm;
00121
00122 return ;
00123 }
00124
00125
00126
00127
00128
00129 void StCtbUtility::collectCTBhitsData(StTriggerData *trgD){
00130
00131 LOG_INFO << "StCtbUtility scans real CTB hits" << endm;
00132
00133
00134
00135 if(!trgD){
00136 LOG_WARN << "StCtbUtility scans: no trigData in real data" << endm;
00137 return ;
00138 }
00139
00140
00141 for (UInt_t slat = 0; slat < 2; slat++)
00142 for (UInt_t tray = 0; tray < 120; tray++) {
00143 ctbHit curHit;
00144 curHit.adc = trgD->ctbTraySlat(tray,slat,0);
00145 if(curHit.adc<mCtbThres_ch) continue;
00146
00147 ctb_get_slat_from_data(slat,tray,curHit.phi, curHit.eta);
00148 mCtbHits.push_back(curHit);
00149 }
00150
00151 #if 0
00152
00153
00154 StTriggerDetectorCollection* trigCol = event->triggerDetectorCollection();
00155 if(!trigCol){
00156 LOG_WARN << "StCtbUtility scans: no trigCol in Data" << endm;
00157 return ;
00158 }
00159
00160 StCtbTriggerDetector* ctbDet = &(trigCol->ctb());
00161 for (UInt_t slat = 0; slat < ctbDet->numberOfSlats(); slat++)
00162 for (UInt_t tray = 0; tray < ctbDet->numberOfTrays(); tray++) {
00163 ctbHit curHit;
00164 curHit.adc = ctbDet->mips(tray,slat,0);
00165 if(curHit.adc<mCtbThres_ch) continue;
00166 LOG_INFO<<Form("A sl=%3d tr=%3d %4f\n",slat,tray, curHit.adc )<<endm;
00167 }
00168
00169 #endif
00170 return ;
00171 }
00172
00173
00174
00175
00176 void StCtbUtility::printCtb() {
00177 LOG_INFO<<Form("StCtbUtility::print(),nSlat=%d\n",mCtbHits.size())<<endm;
00178
00179 uint ih;
00180 for(ih=0;ih<mCtbHits.size();ih++) {
00181 LOG_INFO<<Form("ih=%d eta=%.3f phi/deg=%.1f adc=%.1f\n",ih
00182 ,mCtbHits[ih].eta,mCtbHits[ih].phi/3.1416*180,mCtbHits[ih].adc)<<endm;
00183 }
00184 }
00185