3 #include "StEventTypes.h"
10 #include "tables/St_g2t_emc_hit_Table.h"
11 #include "tables/St_g2t_event_Table.h"
13 #include "StBFChain.h"
15 #include "EEmcMCData.h"
17 #include "StEEmcUtil/EEmcGeom/EEmcGeomDefs.h"
18 #include "StEEmcUtil/EEevent/EEeventDst.h"
19 #include "StEEmcUtil/EEevent/EEsectorDst.h"
21 #include "StMessMgr.h"
33 mEthr = kEEmcDefaultEnergyThreshold;
34 mSize = kEEmcDefaultMCHitSize;
43 mEventID = e.getEventID();
44 mLastHit = e.getLastHit();
45 mEthr = e.getEnergyThreshold();
48 mSize = e.getHitArray(mHit,mSize);
54 EEmcMCData::~EEmcMCData() {
56 if(mHit)
delete [] mHit;
64 EEmcMCData::readEventFromChain(
const StMaker *myMk)
66 St_g2t_event *g2t_event = NULL;
67 St_g2t_emc_hit *emc_hit = NULL;
68 St_g2t_emc_hit *smd_hit = NULL;
69 g2t_event_st *event_head = NULL;
72 if( (g2t_event=(St_g2t_event *) myMk->GetDataSet(
"g2t_event")) == NULL ) {
73 LOG_ERROR <<
"missing MC event header" << endm;
76 if( (event_head= g2t_event->GetTable()) == NULL ) {
77 LOG_ERROR <<
"missing MC event header table" << endm;
80 mEventID=event_head->n_event;
81 emc_hit = (St_g2t_emc_hit *) myMk->GetDataSet(
"g2t_eem_hit");
82 smd_hit = (St_g2t_emc_hit *) myMk->GetDataSet(
"g2t_esm_hit");
83 unpackGeantHits(emc_hit, smd_hit);
93 EEmcMCData::unpackGeantHits(St_g2t_emc_hit* emc_hit, St_g2t_emc_hit* smd_hit ){
96 memset(mHit,0x0,
sizeof(
struct EEmcMCHit)*mSize);
99 if( emc_hit !=NULL ) {
100 Int_t nhits = emc_hit->GetNRows();
102 Warning(
"readEventFromChain",
"no tower hits (%d)",nhits);
106 g2t_emc_hit_st *
hit = emc_hit->GetTable();
107 for(Int_t ihit=0; ihit<nhits; ihit++,hit++) {
109 Int_t ivid = hit->volume_id;
113 ivid %= kEEmcTowerHalfId;
114 Short_t phi = ivid/kEEmcTowerPhiId; ivid %= kEEmcTowerPhiId;
115 Short_t eta = ivid/kEEmcTowerEtaId; ivid %= kEEmcTowerEtaId;
116 Short_t depth = ivid/kEEmcTowerDepId; ivid %= kEEmcTowerDepId;
119 if(!ivid==0){err=1;
goto crash;};
121 ssec = (phi-1)%5 + 1;
125 if(!( 0<sec && sec<=kEEmcNumSectors )){err=2;
goto crash;};
126 if(!( 0<ssec && ssec<=kEEmcNumSubSectors)){err=3;
goto crash;};
127 if(!( 0<eta && eta<=kEEmcNumEtas)){err=4;
goto crash;};
128 if(!( 0<depth && depth<=kEEmcNumDepths)){err=5;
goto crash;};
131 case kPreShower1Depth:
132 mHit[mLastHit].detector = kEEmcMCPreShower1Id;
134 case kPreShower2Depth:
135 mHit[mLastHit].detector = kEEmcMCPreShower2Id;
139 mHit[mLastHit].detector = kEEmcMCTowerId;
141 case kPostShowerDepth:
142 mHit[mLastHit].detector = kEEmcMCPostShowerId;
145 Warning(
"readEventFromChain",
"unknown depth %d",depth);
150 mHit[mLastHit].sector = sec;
151 mHit[mLastHit].tower.ssec = ssec;
152 mHit[mLastHit].tower.eta = eta;
153 mHit[mLastHit].de = hit->de;
154 mHit[mLastHit].track_p = hit->track_p;
158 if ((mLastHit >= mSize) && !expandMemory()) {
159 LOG_ERROR <<
"failed expandMemory() for tower tails" << endm;
168 if( smd_hit != NULL ) {
169 Int_t nhits = smd_hit->GetNRows();
172 Warning(
"readEventFromChain",
"no smd hits (%d)",nhits);
175 g2t_emc_hit_st *hit = smd_hit->GetTable();
177 for(Int_t ihit=0; ihit<nhits ; ihit++,hit++) {
180 Int_t ivid = hit->volume_id;
183 Short_t half = ivid/kEEmcSmdHalfId; ivid %= kEEmcSmdHalfId;
184 Short_t phi = ivid/kEEmcSmdPhiId; ivid %= kEEmcSmdPhiId;
185 Short_t plane = ivid/kEEmcSmdPlaneId;ivid %= kEEmcSmdPlaneId;
186 Short_t strip = ivid/kEEmcSmdStripId;ivid %= kEEmcSmdStripId;
188 if(!ivid==0){err=10;
goto crash;};
196 case 1: det = kEEmcMCSmdVStripId;
break;
197 case 3: det = kEEmcMCSmdUStripId;
break;
198 default: det = kUnknownId;
break;
206 case 2: det = kEEmcMCSmdVStripId;
break;
207 case 1: det = kEEmcMCSmdUStripId;
break;
208 default: det = kUnknownId;
break;
216 case 3: det = kEEmcMCSmdVStripId;
break;
217 case 2: det = kEEmcMCSmdUStripId;
break;
218 default: det = kUnknownId;
break;
225 if(det!=kEEmcMCSmdVStripId && det!=kEEmcMCSmdUStripId ) {
226 Warning(
"readEventFromChain",
"unknown smd layer %d %d-%d-%d-%d",det,half,phi,plane,strip);
232 if(! ( 0<sec && sec <=kEEmcNumSectors )){err=12;
goto crash;};
233 if(!( 0<strip && strip<=kEEmcNumStrips )){err=13;
goto crash;};
237 mHit[mLastHit].detector = det;
238 mHit[mLastHit].sector = sec;
239 mHit[mLastHit].strip = strip;
240 mHit[mLastHit].de = hit->de;
241 mHit[mLastHit].track_p = hit->track_p;
244 if ((mLastHit >= mSize) && !expandMemory()) {
245 LOG_ERROR <<
"failed expandMemory() for SMD strips" << endm;
255 printf(
"\n\n==============================\nEEmcMCData::readEventFromChain() Fatal error while decoding .fzd hits for EEMC err=%d,\n all EEMC data erased \n=====================================\n",err);
257 memset(mHit,0x0,
sizeof(
struct EEmcMCHit)*mSize);
266 EEmcMCData::getHitArray(
EEmcMCHit *h, Int_t size)
const
269 LOG_ERROR <<
"invalid size: " << size << endm;
272 if(size<mSize) {LOG_WARN <<
"truncating to " << size <<
" hits (out of " << mSize <<
")" << endm;}
273 int n = size;
if (n > mSize) n = mSize;
279 EEmcMCData::setHitArray(
EEmcMCHit *h, Int_t size)
282 LOG_ERROR <<
"invalid size: " << size << endm;
285 if(size>mSize) {LOG_WARN <<
"truncating to " << mSize <<
" hits (out of " << size <<
")" << endm;}
286 int n = size;
if (n > mSize) n = mSize;
294 EEmcMCData::print()
const
299 printf(
"EndcapEmc MC event #%d\n",mEventID);
300 for(Int_t i=0; i<mLastHit; i++,h++) {
303 case kEEmcMCTowerId: detName =
"EndcapEmcTower ";
break;
304 case kEEmcMCPreShower1Id: detName =
"EndcapEmcPreShower1 ";
break;
305 case kEEmcMCPreShower2Id: detName =
"EndcapEmcPreShower2 ";
break;
306 case kEEmcMCPostShowerId: detName =
"EndcapEmcPostShower ";
break;
307 case kEEmcMCSmdUStripId: detName =
"EndcapEmcSmdUStrip ";
break;
308 case kEEmcMCSmdVStripId: detName =
"EndcapEmcSmdVStrip ";
break;
309 default: detName =
"EndcapEmcUnknown ";
break;
315 case kEEmcMCPreShower1Id:
316 case kEEmcMCPreShower2Id:
317 case kEEmcMCPostShowerId:
318 printf(
"%s sec=%2d sub=%c eta=%d de=%g tr_p=%d\n",detName.Data(), h->sector,h->tower.ssec-1+
'A',h->tower.eta,h->de, h->track_p);
320 case kEEmcMCSmdUStripId:
321 case kEEmcMCSmdVStripId:
322 printf(
"%s sec=%2d strip=%d de=%g tr_p=%d\n",detName.Data(), h->sector,h->strip,h->de, h->track_p);
325 LOG_WARN <<
"detectorId=" << detId <<
" is unknown" << endm;
336 EEmcMCData::expandMemory()
338 Int_t newSize = mSize + kEEmcDefaultMCHitSize;
342 if (newHit) memcpy(newHit,mHit,mSize*
sizeof(
EEmcMCHit));
346 Info(
"expandMemory",
" MCHit memory expanded from 0x%04x to 0x%04x",mSize,newSize);
357 EEmcMCData::read (
void *hit,
int size)
360 const int HitSize =
sizeof(
struct EEmcMCHit);
361 const int MaxSize = mSize * HitSize;
362 if(size>MaxSize) size=MaxSize;
363 memcpy(mHit,hit,size);
364 mLastHit =size/HitSize;
372 EEmcMCData::write (
void *hit,
int size)
374 Int_t nbytes = mLastHit *
sizeof(
struct EEmcMCHit);
375 if(size>nbytes) size=nbytes;
376 memcpy(hit,mHit,size);
387 EEeve->setType(EEeventDst::kRawMC);
388 EEeve->setID(mEventID);
391 for(Int_t i=0; i<mLastHit; i++,h++) {
399 int subSec=
'A'+h->tower.ssec-1;
400 if (EEsec)
switch( h->detector) {
402 EEsec->addTwHit(subSec,h->tower.eta,h->de);
break;
403 case kEEmcMCPreShower1Id:
404 EEsec->addPre1Hit(subSec,h->tower.eta,h->de);
break;
405 case kEEmcMCPreShower2Id:
406 EEsec->addPre2Hit(subSec,h->tower.eta,h->de);
break;
407 case kEEmcMCPostShowerId:
408 EEsec->addPostHit(subSec,h->tower.eta,h->de);
break;
409 case kEEmcMCSmdUStripId:
410 EEsec->addSmdUHit(h->strip,h->de);
break;
411 case kEEmcMCSmdVStripId:
412 EEsec->addSmdVHit(h->strip,h->de);
break;
414 LOG_ERROR <<
"invalid MC depth" << endm;