00001 #include <string.h>
00002 #include <stdio.h>
00003 #include <assert.h>
00004 #include <cmath>
00005 #include <math_constants.h>
00006
00007 #include <StMessMgr.h>
00008
00009 #include <tables/St_g2t_ctf_hit_Table.h>
00010 #include <StTriggerData.h>
00011
00012
00013 #include "CtbHitList.h"
00014
00015
00016 extern void cts_get_ctb_indexes(long, long &, long &);
00017
00018
00019
00020
00021
00022
00023
00024
00025 CtbHitList::CtbHitList() :
00026 ScintHitList(-C_PI/60.,C_PI/30,60, -1.,0.5,4,"Ctb",2.,0.5){
00027
00028 mCtbThres_mev=1;
00029 mCtbThres_ch=2 ;
00030 geantE=new float [nBin];
00031 }
00032
00033
00034
00035
00036 void
00037 CtbHitList::initRun(float fac){
00038 const float mCtbEtaSeg=0.5, mCtbPhiSeg=C_PI/30;
00039 gMessMgr->Message("","I") <<" CtbHitList::initRun(), gain change factor="<<fac<<endm;
00040 mCtbThres_mev*=fac;
00041 mCtbThres_ch=(int) (fac*mCtbThres_ch);
00042
00043 gMessMgr->Message("","I")
00044 <<" CtbHitList::initRun() CtbThres_Ch (real)="<<mCtbThres_ch
00045 <<" or CtbThres_MeV (M-C)="<<mCtbThres_mev
00046 <<endm;
00047
00048 ScintHitList::initRun();
00049 int i;
00050 for(i=0;i<nBin;i++){
00051
00052 if(i==40 || i==50 ||i==100 || i==110) continue;
00053 setActive(i);
00054 }
00055
00056
00057 long iPhi1,iEta1;
00058
00059 for(iPhi1=1;iPhi1<mxPhi1;iPhi1++)
00060 for(iEta1=1;iEta1<mxEta1;iEta1++)
00061 mcId2bin[iPhi1][iEta1]=-1;
00062
00063 for(iPhi1=1;iPhi1<mxPhi1;iPhi1++)
00064 for(iEta1=1;iEta1<mxEta1;iEta1++) {
00065 int iPhi0=iPhi1-1;
00066 int iEta0=iEta1-1;
00067 int iBin0=iPhiEta2bin(iPhi0,iEta0);
00068 float phi=iPhi0*mCtbPhiSeg;
00069 float eta=iEta0*mCtbEtaSeg -0.75;
00070 int iEta=etaBin(eta);
00071 int iPhi=phiBin(phi);
00072 if(iEta<0) continue;
00073 assert( iEta<nEta);
00074 assert( iPhi>=0);
00075 int iBin=iPhiEta2bin(iPhi,iEta);
00076 assert(iBin==iBin0);
00077
00078 mcId2bin[iPhi1][iEta1]=iBin;
00079 }
00080
00081
00082 int slat, tray;
00083 for (slat = 0; slat < mxSlat; slat++)
00084 for ( tray = 0; tray < mxTray; tray++) {
00085 float phi,eta;
00086 ctb_get_slat_from_data(slat,tray,phi,eta);
00087 int iEta=etaBin(eta);
00088 int iPhi=phiBin(phi);
00089 if(iEta<0) continue;
00090 assert( iEta<nEta);
00091 assert( iPhi>=0);
00092 int iBin=iPhiEta2bin(iPhi,iEta);
00093 realId2bin[slat][tray]=iBin;
00094 }
00095
00096 }
00097
00098
00099
00100 void
00101 CtbHitList::clear(){
00102 ScintHitList::clear();
00103 memset(geantE,0,nBin*sizeof(float));
00104 }
00105
00106
00107
00108 CtbHitList::~CtbHitList(){
00109 delete [] geantE ;
00110 }
00111
00112
00113
00114
00115 int
00116 CtbHitList::etaBin(float eta){
00117 if(eta<eta0) return -1;
00118 int iEta=(int)((eta-eta0)/dEta);
00119 if( iEta>=nEta) return -1;
00120
00121 return iEta;
00122 }
00123
00124
00125
00126 float
00127 CtbHitList::bin2EtaLeft(int iEta){
00128 assert(iEta>=0);
00129 assert(iEta<nEta);
00130 float etaF= eta0+iEta*dEta ;
00131 return etaF;
00132 }
00133
00134
00135
00136 void
00137 CtbHitList::buildFromMC(TDataSet *gds) {
00138
00139
00140 gMessMgr->Message("","I") <<" CtbHitList::buildFromMC thr/MeV="<<mCtbThres_mev<<endm;
00141
00142 if(gds==0) return ;
00143
00144
00145
00146 St_g2t_ctf_hit *g2t_ctb_hit = (St_g2t_ctf_hit *) gds->Find("g2t_ctb_hit");
00147 if(g2t_ctb_hit == 0){
00148 LOG_DEBUG << "CtbHitList::buildMC() No CTB Hits in MC table for this event" << endm;
00149 LOG_DEBUG << "g2t_ctb_hit = " << g2t_ctb_hit << endm;
00150 return ;
00151 }
00152
00153 g2t_ctf_hit_st *ctb_hit = NULL;
00154
00155
00156
00157 if (g2t_ctb_hit->GetNRows() == 0) gMessMgr->Message("","I") <<" CtbHitList::buildMC() Empty geant/ctb data set "<<endm;
00158
00159 ctb_hit = g2t_ctb_hit->GetTable();
00160
00161
00162 if (! ctb_hit){
00163 LOG_WARN << "CtbHitList::buildMC() no CTB hits" << endm;
00164 return ;
00165 }
00166
00167 int i;
00168 for (i = 0; i < g2t_ctb_hit->GetNRows(); i++,ctb_hit++){
00169 float de_mev=ctb_hit->de*1000.;
00170
00171 long iPhi1,iEta1;
00172 cts_get_ctb_indexes(ctb_hit->volume_id,iPhi1,iEta1);
00173
00174
00175
00176
00177 int iBin=mcId2bin[iPhi1][iEta1];
00178 geantE[iBin]+=de_mev;
00179 }
00180
00181 for(i=0;i<nBin;i++){
00182 if ( getActive(i)<0) continue;
00183 if( geantE[i]<mCtbThres_mev) continue;
00184 setFired(i);
00185 }
00186
00187 }
00188
00189
00190
00191
00192 void
00193 CtbHitList::buildFromData(StTriggerData *trgD){
00194
00195 LOG_INFO << " CtbHitList::buildFromData CtbThres_Ch thres="<<mCtbThres_ch << endm;
00196
00197
00198
00199 if(!trgD){
00200 LOG_WARN << "CtbHitList::buildFromData: no trigData in real data" << endm;
00201 return ;
00202 }
00203 int slat, tray;
00204 for ( slat = 0; slat < mxSlat; slat++)
00205 for ( tray = 0; tray < mxTray; tray++) {
00206 float adc = trgD->ctbTraySlat(tray,slat,0);
00207 if(adc<mCtbThres_ch) continue;
00208 int iBin=realId2bin[slat][tray];
00209
00210 if ( getActive(iBin)<0) continue;
00211 setFired(iBin);
00212 }
00213 #if 0
00214
00215
00216 StTriggerDetectorCollection* trigCol = event->triggerDetectorCollection();
00217 if(!trigCol){
00218 LOG_WARN << "StCtbUtility scans: no trigCol in Data" << endm;
00219 return ;
00220 }
00221
00222 StCtbTriggerDetector* ctbDet = &(trigCol->ctb());
00223 for (UInt_t slat = 0; slat < ctbDet->numberOfSlats(); slat++)
00224 for (UInt_t tray = 0; tray < ctbDet->numberOfTrays(); tray++) {
00225 ctbHit curHit;
00226 curHit.adc = ctbDet->mips(tray,slat,0);
00227 if(curHit.adc<mCtbThres_ch) continue;
00228
00229 }
00230
00231 #endif
00232 return ;
00233 }
00234
00235
00236
00237
00238 void
00239 CtbHitList::ctb_get_slat_from_data(int slat, int tray, float & phiRad, float &eta) {
00240 float phiZero1 = 72 ;
00241 float phiZero2 = 108 ;
00242 float deltaPhi = 6 ;
00243
00244
00245
00246 int iz ;
00247 float phi ;
00248
00249 if ( tray < 60 ) {
00250 phi = phiZero1 - tray * deltaPhi ;
00251 iz = 0 ;
00252 } else {
00253 phi = phiZero2 + (tray-60) * deltaPhi ;
00254 iz = 1 ;
00255 }
00256 if ( phi < 0. ) phi += 360 ;
00257 if ( phi > 360. ) phi -= 360 ;
00258
00259 phiRad=phi/180*C_PI;
00260 eta=(1-2*iz)*(1+2*slat)*0.25;
00261
00262
00263 }
00264
00265