00001
00002
00003
00004
00005 #include <Stiostream.h>
00006 #include <math.h>
00007
00008 #include "StEventTypes.h"
00009 #include "StEvent.h"
00010 #include <TTree.h>
00011
00012 #include "St2eemcFeeRawMaker.h"
00013
00014 #include "StEEmcUtil/database/StEEmcDb.h"
00015 #include "StEEmcUtil/database/EEmcDbItem.h"
00016 #include "EEfeeRaw/EEfeeDataBlock.h"
00017 #include "EEfeeRaw/EEfeeRawEvent.h"
00018 #include "EEfeeRaw/EEmcEventHeader.h"
00019 #include "EEfeeRaw/EEname2Index.h"
00020
00021
00022 ClassImp(St2eemcFeeRawMaker)
00023
00024
00025 St2eemcFeeRawMaker::St2eemcFeeRawMaker(const char *name):StMaker(name){
00026 moutTTree=0;
00027 meeDb=0;
00028 meveTT=new EEfeeRawEvent();
00029 mrunTT=new EEmcEventHeader();
00030 mNFeeCrate=6;
00031 }
00032
00033
00034 St2eemcFeeRawMaker::~St2eemcFeeRawMaker(){
00035
00036
00037 delete mrunTT;
00038 delete meveTT;
00039 delete [] mcrateData;
00040 }
00041
00042
00043
00044
00045
00046
00047 Int_t St2eemcFeeRawMaker::Init(){
00048 meeDb = (StEEmcDb*)this->GetDataSet("StEEmcDb");
00049 assert(moutTTree);
00050 assert(meeDb);
00051 assert(meveTT);
00052 assert(mrunTT);
00053 assert(mNFeeCrate>0);
00054 mcrateData=new EEfeeDataBlock[mNFeeCrate];
00055
00056
00057
00058
00059 moutTTree->Branch("head","EEmcEventHeader",&mrunTT,16000,99);
00060
00061
00062 moutTTree->Branch("evt","EEfeeRawEvent",&meveTT,16000,99);
00063
00064
00065
00066 return StMaker::Init();
00067 }
00068
00069
00070
00071
00072
00073
00074 Int_t St2eemcFeeRawMaker::InitRun (int runNumber){
00075
00076 StEvent* mEvent = (StEvent*)GetInputDS("StEvent");
00077 assert(mEvent);
00078 LOG_INFO<<Form("\n%s accessing StEvent ID=%d\n",GetName(),mEvent->id())<<endm;
00079 LOG_INFO<<Form("StEvent time=%d, ID=%d, runID=%d\n",(int)mEvent->time(),(int)mEvent->id(),(int)mEvent->runId())<<endm;
00080
00081 mrunTT->setTimeStamp(this->GetDBTime().Convert());
00082 mrunTT->setProcessingTime(time(0));
00083 char text[200];
00084 sprintf(text," M-C event file, run=%d , created by %s",mEvent->runId(),GetName());
00085 mrunTT->setComment(text);
00086 mrunTT->print();
00087
00088 LOG_INFO<<Form("\n%s::InitRun(%d) list DB content \n",GetName(),runNumber)<<endm;
00089
00090 return kStOK;
00091 }
00092
00093
00094
00095
00096
00097 Int_t St2eemcFeeRawMaker::Make(){
00098
00099 StEvent* mEvent = (StEvent*)GetInputDS("StEvent");
00100 assert(mEvent);
00101 LOG_INFO<<Form("\n%s accesing StEvent ID=%d\n",GetName(),mEvent->id())<<endm;
00102
00103 StEmcCollection* emcCollection = mEvent->emcCollection();
00104
00105
00106
00107 StEmcDetector* twE = emcCollection->detector(kEndcapEmcTowerId);
00108 if(!twE) {
00109 LOG_WARN<<"No EEMC twE hits, skip event"<<endm;
00110 return kStOK;
00111 }
00112
00113
00114
00115
00116
00117
00118 int nDrop=0;
00119 int icr;
00120 UShort_t head[4];
00121
00122 UChar_t token=(int)mEvent->id()%256;
00123 for(icr=0;icr<mNFeeCrate;icr++) {
00124 int crateID=icr+1;
00125 mcrateData[icr].clear();
00126
00127 int j;
00128 for(j=0;j<2;j++) head[j]=((0xa+j)<<8) +crateID;
00129 head[2]= token;
00130 head[3]=(UChar_t)crateID;
00131
00132 mcrateData[icr].setHead(head);
00133 }
00134
00135
00136
00137 int i;
00138 LOG_INFO<<Form("%s:: E_EMC Tower HITS ... %d\n",GetName(),twE->numberOfModules())<<endm;
00139 for ( i = 0; i < (int)twE->numberOfModules(); i++) {
00140
00141 StEmcModule* stmod = twE->module(i);
00142 if(stmod==0) continue;
00143 StSPtrVecEmcRawHit& emcTowerHits = stmod->hits();
00144 LOG_INFO<<Form("bbb i=%d %d\n",i,emcTowerHits.size())<<endm;
00145
00146 uint j;
00147 for ( j = 0; j < emcTowerHits.size(); j++) {
00148 int adc= emcTowerHits[j]->adc();
00149 int sec= emcTowerHits[j]->module()+1;
00150 int sub= emcTowerHits[j]->sub()+'A';
00151 int eta= emcTowerHits[j]->eta()+1;
00152 float energy=emcTowerHits[j]->energy();
00153
00154 const EEmcDbItem *dbItem=meeDb->getT(sec,sub,eta);
00155 assert(dbItem);
00156
00157 int chan=dbItem->chan;
00158 int slot=dbItem->crate;
00159
00160
00161
00162 LOG_INFO<<Form("j=%d, sec=%d, sub=%c, eta=%d rawAdc=%d energy =%g -->crate/chan=%d/%d\n",j,sec,sub,eta,adc,energy,slot,chan)<<endm;
00163
00164
00165
00166 if(adc<=0) continue;
00167 if(chan<0 || slot<0) { nDrop++; continue;}
00168 icr=slot-1;
00169 assert(icr>=0);
00170 assert(icr<mNFeeCrate);
00171 mcrateData[icr].setData(chan,adc);
00172 }
00173 }
00174
00175
00176 meveTT->clear();
00177 meveTT->setID(mEvent->id());
00178 int n1=0;
00179 for(icr=0;icr<mNFeeCrate;icr++) {
00180 if(mcrateData[icr].getNData(0)<=0) continue;
00181
00182 LOG_INFO<<Form("SS crateID=%d, Npositive=%d\n",icr+1,mcrateData[icr].getNData(0))<<endm;
00183
00184 meveTT->addFeeDataBlock(mcrateData+icr);
00185 n1++;
00186 }
00187
00188
00189
00190 moutTTree->Fill();
00191
00192
00193 LOG_INFO<<Form("%s:: stored TTree with %d=%d data blocks, ID=%d \n",GetName(),n1,meveTT->block->GetEntries(),meveTT->getID())<<endm;
00194
00195
00196 return kStOK;
00197 }
00198
00199
00200
00201
00202
00203
00204
00205
00206
00207
00208
00209
00210
00211
00212
00213
00214
00215
00216
00217
00218
00219
00220
00221
00222
00223
00224
00225
00226
00227
00228
00229
00230
00231
00232
00233
00234
00235
00236
00237
00238
00239
00240
00241
00242
00243
00244
00245
00246
00247
00248
00249
00250
00251
00252
00253
00254
00255
00256