00001 #include <string.h>
00002 #include <stdio.h>
00003 #include <assert.h>
00004 #include <cmath>
00005
00006 #include <math_constants.h>
00007 #include <StMessMgr.h>
00008
00009 #include "BtofHitList.h"
00010
00011 #include "StMaker.h"
00012 #include "StBTofUtil/StBTofGeometry.h"
00013 #include "StBTofUtil/StBTofTables.h"
00014 #include "StBTofCollection.h"
00015
00016
00017
00018
00019 BtofHitList::BtofHitList() :
00020
00021
00022 ScintHitList(0.,C_PI/60,60, -0.9,0.028125,64,"Btof",4,0.75) {
00023 myTable = new StBTofTables();
00024 }
00025
00026
00027
00028
00029 void
00030 BtofHitList::initRun() {
00031 LOG_DEBUG <<Form("BtofHitList::initRun() start")<<endm;
00032 ScintHitList::initRun();
00033
00034 int i,j,k;
00035 for(i=0;i<mxTray;i++)
00036 for(j=0;j<mxModule;j++)
00037 for(k=0;k<mxCell;k++)
00038 tmc2bin[i][j][k]=-1;
00039
00040
00041 StMaker*mk=(StMaker*)StMaker::GetChain()->GetMaker("GenericVertex");
00042 assert(mk);
00043 myTable->loadTables(mk);
00044
00045
00046 int nB=0; int nA=0;
00047 for(int i=0;i<mxTray;i++) {
00048 for(int j=0;j<mxModule;j++) {
00049 for(int k=0;k<mxCell;k++) {
00050 int iBin = cell2bin(i+1,j+1,k+1);
00051 tmc2bin[i][j][k]=iBin;
00052
00053 int status = 1;
00054 status = myTable->status(i+1,j+1,k+1);
00055 nB++;
00056 if( status!= 1) continue;
00057
00058 setActive(iBin);
00059 nA++;
00060 }
00061 }
00062 }
00063
00064 LOG_INFO <<" BtofHitList::initRun() done, active="<<nA<<" of "<<nB<<" BTOF channels" <<endm;
00065
00066 }
00067
00068
00069
00070 void
00071 BtofHitList::clear(){
00072 ScintHitList::clear();
00073
00074 }
00075
00076
00077
00078 BtofHitList::~BtofHitList(){
00079 if(myTable) delete myTable;
00080 }
00081
00082
00083
00084 void
00085 BtofHitList::build ( StBTofCollection *btofColl){
00086
00087 if(!btofColl || !btofColl->hitsPresent()) {
00088 LOG_INFO << " No available BTOF hits for this event ... " << endm;
00089 return;
00090 }
00091
00092 StSPtrVecBTofHit& tofHits = btofColl->tofHits();
00093
00094 for(size_t i=0;i<tofHits.size();i++) {
00095 StBTofHit *aHit = tofHits[i];
00096 if(!aHit) continue;
00097 int t = aHit->tray();
00098 int m = aHit->module();
00099 int c = aHit->cell();
00100 if(t<=0||t>mxTray||m<=0||m>mxModule||c<=0||c>mxCell) continue;
00101
00102 int iBin=tmc2bin[t-1][m-1][c-1];
00103
00104 if ( getActive(iBin)<0) continue;
00105 setFired(iBin);
00106 }
00107
00108
00109
00110
00111
00112
00113
00114
00115
00116
00117
00118
00119
00120
00121
00122
00123
00124
00125
00126
00127
00128
00129
00130
00131
00132
00133
00134
00135
00136
00137 };
00138
00139
00140 int
00141 BtofHitList::cell2bin(int tray, int module, int cell) {
00142 int iPhi = (tray-1)%60;
00143 int iEta = (tray-1)/60*mxModule + (module-1);
00144 assert( iEta>=0);
00145 assert( iPhi>=0);
00146 return iPhiEta2bin(iPhi,iEta);
00147 }
00148
00149
00150 int
00151 BtofHitList::addBtofTrack(int tray, int module, int cell) {
00152 int iBin = cell2bin(tray, module, cell);
00153 track[iBin]++;
00154 nTrack++;
00155 return iBin;
00156 }
00157
00158
00159
00160 int
00161 BtofHitList::addBtofMatch(IntVec ibinVec) {
00162 if(isMatched(ibinVec)) nMatch++;
00163 return nMatch;
00164 }
00165
00166
00167 bool
00168 BtofHitList::isMatched(IntVec ibinVec) {
00169 bool match = kFALSE;
00170 for(size_t i=0;i<ibinVec.size();i++) {
00171 int iBin = ibinVec[i];
00172 if(getActive(iBin)>0) {
00173 if(getTrack(iBin)>0&&getFired(iBin)>0) match = kTRUE;
00174 }
00175 }
00176 return match;
00177 }
00178
00179
00180 bool
00181 BtofHitList::isVetoed(IntVec ibinVec) {
00182 int nA = 0;
00183 bool veto = kTRUE;
00184 for(size_t i=0;i<ibinVec.size();i++) {
00185 int iBin = ibinVec[i];
00186 if(getActive(iBin)>0) {
00187 nA++;
00188 if(getTrack(iBin)>0&&getFired(iBin)==0) veto &= kTRUE;
00189 else veto &= kFALSE;
00190 }
00191 }
00192 if(nA==0) return kFALSE;
00193 else return veto;
00194 }
00195
00196
00197 float
00198 BtofHitList::getWeight(IntVec ibinVec) {
00199 const float Wdunno=1;
00200 int nA = 0;
00201 for(size_t i=0;i<ibinVec.size();i++) {
00202 int iBin = ibinVec[i];
00203 if(getActive(iBin)>0) nA++;
00204 }
00205 if(nA==0) return Wdunno;
00206 if(isMatched(ibinVec)) return Wmatch;
00207 if(isVetoed(ibinVec)) return Wveto;
00208 return Wdunno;
00209 }
00210
00211
00212 int
00213 BtofHitList::etaBin(float eta){
00214 if(fabs(eta)>0.9) return -1;
00215 int iEta=(int)((eta-eta0)/dEta);
00216 if(iEta<0 || iEta>=nEta) return -1;
00217 return iEta;
00218 }
00219
00220
00221
00222 float
00223 BtofHitList::bin2EtaLeft(int iEta){
00224 assert(iEta>=0);
00225 assert(iEta<nEta);
00226 float etaF= eta0+iEta*dEta ;
00227 if(etaF<-0.9) etaF=0.9;
00228 return etaF;
00229 }