00001 #include "mEmcGeaMakeCalibTower.h"
00002
00003 #include <cassert>
00004 #include <cmath>
00005 #include <iostream>
00006
00007 #include "dEmcEventWrapper.h"
00008 #include "dEmcGeometryWrapper.h"
00009 #include "dEmcRawDataWrapper.h"
00010
00011 #include "EmcIndexer.h"
00012 #include "emcTowerContainer.h"
00013 #include "emcTowerContent.h"
00014
00015 #include "mEmcGeometryModule.h"
00016
00017 #include "emcNodeHelper.h"
00018
00019 #include "VtxOut.h"
00020 #include "PHPoint.h"
00021 #include "gsl/gsl_const_mks.h"
00022
00040 using namespace std;
00041
00042 namespace {
00043
00044 PHBoolean message(const char* msg)
00045 {
00046 cerr << "mEmcGeaMakeCalibTower::process_event : cannot find "
00047 << msg << endl;
00048 return False;
00049 }
00050 }
00051
00052
00053 mEmcGeaMakeCalibTower::mEmcGeaMakeCalibTower()
00054 {
00055 name = "mEmcGeaMakeCalibTower";
00056 }
00057
00058
00059 mEmcGeaMakeCalibTower::~mEmcGeaMakeCalibTower()
00060 {}
00061
00062
00063 PHBoolean
00064 mEmcGeaMakeCalibTower::event(PHCompositeNode* top)
00065 {
00066 emcNodeHelper nh;
00067
00068 dEmcGeometryWrapper* dEmcGeometry =
00069 nh.getTable<dEmcGeometryWrapper>("dEmcGeometry",top);
00070
00071 if (!dEmcGeometry)
00072 {
00073 return message("dEmcGeometry");
00074 }
00075
00076 dEmcRawDataWrapper* dEmcRawData =
00077 nh.getTable<dEmcRawDataWrapper>("dEmcRawData",top);
00078
00079 if (!dEmcRawData)
00080 {
00081 return message("dEmcRawData");
00082 }
00083
00084 dEmcEventWrapper* dEmcEvent =
00085 nh.getTable<dEmcEventWrapper>("dEmcEvent",top);
00086
00087 if (!dEmcEvent)
00088 {
00089 return message("dEmcEvent");
00090 }
00091
00092 emcTowerContainer* towers =
00093 nh.getObject<emcTowerContainer>("emcTowerContainer",top);
00094
00095 if (!towers)
00096 {
00097 return message("emcTowerContainer");
00098 }
00099
00100 VtxOut* vtxout = nh.getObject<VtxOut>("VtxOut",top);
00101 if (!vtxout)
00102 {
00103 return message("VtxOut");
00104 }
00105
00106 PHNodeIterator it(top);
00107 PHIODataNode<TObject>* geometryNode = static_cast<PHIODataNode<TObject>*>(it.findFirst("PHIODataNode","mEmcGeometry"));
00108 if (!geometryNode)
00109 {
00110 return message("mEmcGeometry Node");
00111 }
00112 mEmcGeometryModule* mEmcGeometry =
00113 static_cast<mEmcGeometryModule*>(geometryNode->getData());
00114 if (!mEmcGeometry)
00115 {
00116 return message("mEmcGeometry");
00117 }
00118
00119 const float mult_lothr = 0.005;
00120 const float mult_hithr = 0.020;
00121 float mult_lo, mult_hi;
00122
00123 float sectore[8];
00124 float sectoret[8];
00125 float tote, totet;
00126
00127 static int l_first = 1;
00128 static float torad = M_PI / 180.0;
00129
00130 const float r_tdc_convfac = 0.05;
00131
00132 static float emc_geom[8][96][48][8];
00133
00134
00135
00136
00137
00138
00139 if ( l_first == 1 )
00140 {
00141 for ( size_t i = 0; i < dEmcGeometry->RowCount(); ++i )
00142 {
00143 short iz = dEmcGeometry->get_ind(0,i);
00144 short iy = dEmcGeometry->get_ind(1,i);
00145 short i1;
00146
00147 if (dEmcGeometry->get_arm(i) == 0)
00148 {
00149 i1 = dEmcGeometry->get_sector(i);
00150 }
00151 else
00152 {
00153 i1 = 7 - dEmcGeometry->get_sector(i);
00154 }
00155
00156 emc_geom[0][iz][iy][i1] = dEmcGeometry->get_nomxyz(0,i);
00157 emc_geom[1][iz][iy][i1] = dEmcGeometry->get_nomxyz(1,i);
00158 emc_geom[2][iz][iy][i1] = dEmcGeometry->get_nomxyz(2,i);
00159 emc_geom[3][iz][iy][i1] = dEmcGeometry->get_nomtheta(i);
00160 emc_geom[4][iz][iy][i1] = dEmcGeometry->get_nomphi(i);
00161 emc_geom[5][iz][iy][i1] = dEmcGeometry->get_nomdist(i);
00162 emc_geom[6][iz][iy][i1] = dEmcGeometry->get_nomflash(i);
00163 float d_work1 = dEmcGeometry->get_nomtheta(i);
00164 d_work1 = torad * d_work1;
00165 float d_work = sin(d_work1);
00166 emc_geom[7][iz][iy][i1] = d_work;
00167
00168 }
00169 l_first = 0;
00170 }
00171
00172
00173 if ( dEmcRawData->MaxRowCount() == 0 )
00174 {
00175 return False;
00176 }
00177
00178
00179
00180 for ( size_t i = 0; i < 8 ; i++)
00181 {
00182 sectore[i] = 0.0;
00183 sectoret[i] = 0.0;
00184 }
00185
00186
00187 mult_lo = 0. ;
00188 mult_hi = 0. ;
00189 tote = 0.0;
00190 totet = 0.0;
00191
00192 towers->Reset();
00193
00194 static const double c = GSL_CONST_MKS_SPEED_OF_LIGHT*1E-7;
00195 static const float crazy_big = GSL_CONST_MKS_DAY;
00196
00197 for ( size_t i = 0; i < dEmcRawData->RowCount(); ++i )
00198 {
00199 emcTowerContent* t_i = towers->addTower(i);
00200 assert(t_i!=0);
00201
00202
00203 float e_lo = dEmcRawData->get_adclopost(i)-dEmcRawData->get_adclopre(i);
00204
00205 float e_hi = dEmcRawData->get_adchipost(i)-dEmcRawData->get_adchipre(i) ;
00206
00207 e_lo = e_lo * 0.001 ;
00208 e_hi = e_hi * 0.008 ;
00209
00210
00211
00212
00213 float tof = dEmcRawData->get_tdc(i) * r_tdc_convfac;
00214
00215
00216
00217 if (e_lo < 0.0)
00218 {
00219 e_lo = - e_lo;
00220 }
00221 if (e_hi < 0.0)
00222 {
00223 e_hi = - e_hi;
00224 }
00225
00226
00227 float e = (e_lo > e_hi) ? e_lo : e_hi;
00228
00229
00230 if (e > mult_lothr)
00231 {
00232 mult_lo = mult_lo + 1.0 ;
00233 }
00234 if (e > mult_hithr)
00235 {
00236 mult_hi = mult_hi + 1.0 ;
00237 }
00238
00239 int fem;
00240 int channel;
00241 int towerid = EmcIndexer::TowerID(dEmcRawData->get_swkey(i));
00242 EmcIndexer::PXPXSM144CH(towerid,fem,channel);
00243 int arm,sector,iy,iz;
00244 EmcIndexer::TowerLocation(towerid,arm,sector,iy,iz);
00245 int i1;
00246
00247 if ( arm == 0 )
00248 {
00249 i1 = sector;
00250 }
00251 else
00252 {
00253 i1 = 7 - sector;
00254 }
00255
00256 t_i->SetID(fem,channel);
00257
00258
00259 if (tof > 0.0 && tof < 16.0)
00260 {
00261 tof = 0.0;
00262 }
00263
00264
00265 float x,y,z;
00266 int is = mEmcGeometry->emcOfflineToEmc(arm,sector);
00267 mEmcGeometry->GetTowerPosGlobal(is,iz,iy,x,y,z);
00268 PHPoint towerpos(x,y,z);
00269 PHPoint vertex(0,0,0);
00270
00271 if ( vtxout->isValid() )
00272 {
00273 vertex = vtxout->get_Vertex();
00274 }
00275
00276 float distance = towerpos.distanceToPoint(vertex);
00277 assert(distance>0);
00278 float tshift = distance/c;
00279
00280 if ( tof < 1E-9 )
00281 {
00282 t_i->SetCalibrated(e,crazy_big);
00283 }
00284 else
00285 {
00286 t_i->SetCalibrated(e,tof-tshift);
00287 }
00288
00289 totet = totet + emc_geom[7][iz][iy][i1] * e;
00290
00291
00292
00293 sectore[i1] = sectore[i1] + e ;
00294 sectoret[i1] = sectoret[i1] + emc_geom[7][iz][iy][i1] * e ;
00295 tote = tote + e;
00296 }
00297
00298
00299
00300
00301
00302
00303
00304
00305
00306
00307
00308 dEmcEvent->set_twrmultlo(0,mult_lo);
00309 dEmcEvent->set_twrmulthi(0,mult_hi);
00310 dEmcEvent->set_tote(0,tote);
00311 dEmcEvent->set_totet(0,totet);
00312
00313 return True;
00314 }