|
| 1 | + |
| 2 | +#include "StEEmcSimulatorMaker/StEEmcFastMaker.h" |
| 3 | +#include "StEEmcSimulatorMaker/StEEmcSlowMaker.h" |
| 4 | +#include "StEEmcMixerMaker.h" |
| 5 | + |
| 6 | +#include <stdlib.h> |
| 7 | +#include <string.h> |
| 8 | +#include <TFile.h> |
| 9 | + |
| 10 | +#include <Stiostream.h> |
| 11 | +#include <StMessMgr.h> |
| 12 | +#include <StEventTypes.h> |
| 13 | +#include <StEvent.h> |
| 14 | + |
| 15 | + |
| 16 | +#include "StEEmcUtil/database/EEmcDbItem.h" |
| 17 | +#include "StEEmcUtil/database/StEEmcDb.h" |
| 18 | +#include "StEEmcUtil/database/cstructs/eemcConstDB.hh" // def of status bits |
| 19 | +#include "StEEmcUtil/EEmcGeom/EEmcGeomDefs.h" |
| 20 | + |
| 21 | +#include "StDAQMaker/StDAQReader.h" |
| 22 | +#include "StEmcRawMaker/StEemcRaw.h" |
| 23 | + |
| 24 | +#include "StEmcRawMaker/StEEmcPrint.h" |
| 25 | + |
| 26 | + |
| 27 | +// ROOT dictionary generation is intentionally disabled for this class, |
| 28 | +// as it is not streamed or used in ROOT I/O. |
| 29 | +//ClassImp(StEEmcMixerMaker) |
| 30 | + |
| 31 | +//------------------------------------------------------------------- |
| 32 | +//------------------------------------------------------------------- |
| 33 | +StEEmcMixerMaker::StEEmcMixerMaker(const char *name):StMaker(name){ |
| 34 | + panicOff=false; // once activated disables Endcap embedding |
| 35 | + mEEDb = 0; |
| 36 | +} |
| 37 | + |
| 38 | +//------------------------------------------------------------------- |
| 39 | +//------------------------------------------------------------------- |
| 40 | +StEEmcMixerMaker::~StEEmcMixerMaker() { |
| 41 | + |
| 42 | +} |
| 43 | + |
| 44 | +//------------------------------------------------------------------- |
| 45 | +//------------------------------------------------------------------- |
| 46 | +Int_t StEEmcMixerMaker::Finish() { |
| 47 | + return StMaker::Finish(); |
| 48 | +} |
| 49 | + |
| 50 | +//------------------------------------------------------------------- |
| 51 | +//------------------------------------------------------------------- |
| 52 | +Int_t |
| 53 | +StEEmcMixerMaker::Init(){ |
| 54 | + mEEDb=(StEEmcDb*)GetDataSet("StEEmcDb"); |
| 55 | + if( mEEDb==0){ |
| 56 | + panicOff=true; |
| 57 | + LOG_FATAL<< "::Init()\n\n Fatal Error - Eemc_DbMaker is not in the chain,\n panicOff="<<panicOff<<endm; |
| 58 | + return kStErr; |
| 59 | + } |
| 60 | + assert(!strcmp(mEEDb->ClassName(),"StEEmcDb")); |
| 61 | + return StMaker::Init(); |
| 62 | +} |
| 63 | + |
| 64 | +//------------------------------------------------------------------- |
| 65 | +//------------------------------------------------------------------- |
| 66 | +Int_t |
| 67 | +StEEmcMixerMaker::Make(){ |
| 68 | +/* Embedding is performed in the level of StEmcCollection. |
| 69 | + Data input is daq file and MC is from EEmc fast Simulator StEEmcFastMaker. |
| 70 | +*/ |
| 71 | + |
| 72 | + LOG_INFO <<"::Make() start...."<<endm; |
| 73 | + StEvent* mEvent = (StEvent*)GetInputDS("StEvent"); |
| 74 | + if(mEvent==0) panicOff=true; |
| 75 | + StEmcCollection* ecolA =(StEmcCollection*)mEvent->emcCollection(); |
| 76 | + if(ecolA==0) { |
| 77 | + LOG_WARN<<"::Make(), raw2pixels() no emc collection, skip"<<endm; |
| 78 | + return kStErr; |
| 79 | + } |
| 80 | + |
| 81 | + if(panicOff) { |
| 82 | + LOG_FATAL<< "::Make()\n\n Fatal Error was encounter earlier, Endcap embedding disabled panicOff="<<panicOff<<endm; |
| 83 | + return kStErr; |
| 84 | + } |
| 85 | + |
| 86 | +/* |
| 87 | + Fill data from StEEMCReader to StEmcRawData first, then from raw blocks |
| 88 | + to StEmcCollection of StEvent using the mehtods copyRawData() and |
| 89 | + raw2pixels() of StEemcRaw. They are changed from private to pubilc in |
| 90 | + StEemcRaw for being used legally by StEEmcMixerMaker. Also, raw2pixels |
| 91 | + is modified to accept three parameters: raw2pixels(bool mixer, |
| 92 | + StEmcCollection*, StEvent*), allowing input of embedded StEmcCollection. |
| 93 | + If mixer=false (default) , raw2pixels builds a StEmcCollection of a StEvent |
| 94 | + from DAQ as event/ecolA is built here. If mix=true, the second input |
| 95 | + StEEmcCollection* is used to build an embedded StEvent. |
| 96 | + |
| 97 | +*/ |
| 98 | + |
| 99 | + StEEmcPrint eemcPrint; |
| 100 | + eemcPrint.setMode(15);//bits= 1:Tower, 2:Pre, 4:SmdU, 8:SmdV, 15:all |
| 101 | + |
| 102 | + LOG_DEBUG<<"::Make() -------------- print data: Ecoll-A ---- real backg eve ---------"<<endm; |
| 103 | + if(Debug()) eemcPrint.print(ecolA); |
| 104 | + |
| 105 | + |
| 106 | + /* If the second source is the EEMC simulator, |
| 107 | + it owns the StEmcCollection from simulator. |
| 108 | + */ |
| 109 | + StEmcCollection *ecolB = 0; |
| 110 | + StEEmcFastMaker *sim = (StEEmcFastMaker*)GetMakerInheritsFrom("StEEmcFastMaker"); |
| 111 | + // one can use fast simu as the source even if slow simu is used, since slow simu is set up in the overwrite mode. |
| 112 | + if(!sim) { |
| 113 | + LOG_WARN<<"::Make() No fast EEmcSimulator found, nothing to embed"<<endm; return kStWarn; } |
| 114 | + ecolB = sim->GetLocalEmcCollection(); |
| 115 | + |
| 116 | + if(!ecolB) { |
| 117 | + LOG_WARN<<"::Make() No second EmcCollection to embed"<<endm; return kStWarn; } |
| 118 | + |
| 119 | + |
| 120 | + LOG_DEBUG <<"::Make() -------------- print data: Ecoll-B ----- M-C physics probe eve -----------"<<endm; |
| 121 | + if(Debug()) eemcPrint.print(ecolB); |
| 122 | + |
| 123 | + |
| 124 | + LOG_DEBUG<<GetName() <<"::Make() -------------- print data: Ecoll-A+B ----- before mrging -----"<<endm; |
| 125 | + if(Debug()) eemcPrint.printChange(ecolA,ecolB,Form("before merging")); |
| 126 | + |
| 127 | + if(!mergeADCs(ecolA,ecolB)) return kStErr; |
| 128 | + |
| 129 | + mMixerEmcCollection = ecolA; |
| 130 | + |
| 131 | + LOG_DEBUG <<"::Make() -------------- print Ecoll-A after mixing ----------------"<<endm; |
| 132 | + if(Debug()) eemcPrint.print(ecolA); |
| 133 | + |
| 134 | + LOG_DEBUG <<"::Make() -------------- print data: Ecoll-A+B ----- after merging -----"<<endm; |
| 135 | + if(Debug()) eemcPrint.printChange(ecolA,ecolB,Form("after merging")); |
| 136 | + return kStOK; |
| 137 | +} |
| 138 | + |
| 139 | + |
| 140 | +//-------------------------------------------------------------------- |
| 141 | +//-------------------------------------------------------------------- |
| 142 | +bool |
| 143 | +StEEmcMixerMaker::mergeADCs(StEmcCollection*emccolA,StEmcCollection*emccolB){ |
| 144 | +/*! |
| 145 | +This method adds the ADCs from the the second StEmcCollection |
| 146 | +into the first StEmcCollection in event for all EEMC subdetectors |
| 147 | +*/ |
| 148 | + LOG_DEBUG <<"::Make() merging ADCs ..."<<endm; |
| 149 | + |
| 150 | +/* |
| 151 | + For EEMC, module = sector(1-12). |
| 152 | + Tower (detector-name eemc): sub(1-5), eta(1-12) |
| 153 | + Pre/Post (detector-name eprs): sub(1-15), eta(1-12) |
| 154 | + Pre1 sub(1-5), Pre2: sub(6-10), Post: sub(11-15) |
| 155 | + Smd U & V (detector-name: esmdu and esmdv): sub=1, eta=strip(1-288) |
| 156 | +*/ |
| 157 | + |
| 158 | + // output of merging: collA=collA+collB |
| 159 | + for(int det = kEndcapEmcTowerId; det<= kEndcapSmdVStripId; det++){ |
| 160 | + // Loop over all four sub detectors |
| 161 | + StDetectorId id = StDetectorId(det); |
| 162 | + StEmcDetector* detectorA=emccolA->detector(id); |
| 163 | + StEmcDetector* detectorB=emccolB->detector(id); |
| 164 | + if(!detectorA) |
| 165 | + LOG_WARN<<"detectorA not loaded"<<endm; |
| 166 | + if(!detectorB) |
| 167 | + LOG_WARN<<"detectorB not loaded"<<endm; |
| 168 | + |
| 169 | + if(!detectorA || !detectorB) continue;// nothing to mix for such layer |
| 170 | + for(int secID=1; secID<=kEEmcNumSectors; secID++){ |
| 171 | + // if(secID!=6) continue;//tmp |
| 172 | + StEmcModule* sectorA = detectorA->module(secID); |
| 173 | + StEmcModule* sectorB = detectorB->module(secID); |
| 174 | + StSPtrVecEmcRawHit& rawHitA=sectorA->hits(); |
| 175 | + StSPtrVecEmcRawHit& rawHitB=sectorB->hits(); |
| 176 | + |
| 177 | + // clone pointers to hits collection B |
| 178 | + vector<StEmcRawHit*> myHitB; |
| 179 | + for(UInt_t k2=0;k2<rawHitB.size();k2++) |
| 180 | + myHitB.push_back(rawHitB[k2]); |
| 181 | + vector<StEmcRawHit*>::iterator hitB; |
| 182 | + |
| 183 | + // printf("\nmixIn idet=%d sect=%d Nhit A=%d B=%d\n",det,secID,rawHitA.size(),myHitB.size()); |
| 184 | + |
| 185 | + /*.................... |
| 186 | + 1) merge hits for pixels present in both collections */ |
| 187 | + |
| 188 | + for(UInt_t k1=0;k1<rawHitA.size();k1++) { |
| 189 | + /* do not bother with differences between BEMC & EEMC |
| 190 | + numbering scheme, pretend it is barrel */ |
| 191 | + uint Bmod=rawHitA[k1]->module(); |
| 192 | + |
| 193 | + if((int)Bmod != secID) { |
| 194 | + LOG_FATAL << "::Make()\n\n Fatal Error "<<Bmod<<" != secID ="<<secID<<" StEvent internal consistency failed - corrupted event file, abort"<<endm; |
| 195 | + panicOff=true; |
| 196 | + return false; |
| 197 | + |
| 198 | + } |
| 199 | + |
| 200 | + // StEvent internal consistency check |
| 201 | + uint Beta=rawHitA[k1]->eta(); |
| 202 | + int Bsub=rawHitA[k1]->sub(); |
| 203 | + |
| 204 | + // erase old energy for every hit, use ADC2E-maker to get energy back |
| 205 | + rawHitA[k1]->setEnergy(-654.3210); // just in case, make more non-physical |
| 206 | + |
| 207 | + for( hitB=myHitB.begin() ; hitB< myHitB.end(); hitB++) { |
| 208 | + if( (*hitB)->module()!=Bmod) continue; |
| 209 | + if( (*hitB)->eta() !=Beta) continue; |
| 210 | + if( (*hitB)->sub() !=Bsub) continue; |
| 211 | + // ......... found match to the same element |
| 212 | + int adc=(*hitB)->adc(); |
| 213 | + |
| 214 | + myHitB.erase(hitB); // to shrink the list for next search |
| 215 | + /* Note, *hitB is now a stray pointer, do NOT use it |
| 216 | + for anything. The loop must terminate with 'break', |
| 217 | + since hitB++ makes no sense any more. |
| 218 | + |
| 219 | + It is assumed there is only one hit per pixel in |
| 220 | + collectionB and it was just found. |
| 221 | + */ |
| 222 | + hitB=(vector<StEmcRawHit*>::iterator)NULL; // siher ist siher |
| 223 | + |
| 224 | + const EEmcDbItem *x=mEEDb->StBarrelIndex2Item(det,Bmod,Beta,Bsub); |
| 225 | + if(!x) break;// DB info not avaliable, drop this secondary hit |
| 226 | + |
| 227 | + /* it is assumed GEANT energy deposit is stored |
| 228 | + in secondary collection |
| 229 | + */ |
| 230 | + int adcAdd=adc; |
| 231 | + if(adcAdd<=0) break; |
| 232 | + int adcSum=rawHitA[k1]->adc() +adcAdd; |
| 233 | + //printf("D: %d %g %d %d %s\n",rawHitA[k1]->adc(),deB,adcAdd,adcSum,x->name); |
| 234 | + rawHitA[k1]->setAdc(adcSum); |
| 235 | + break; |
| 236 | + } // loop overB |
| 237 | + |
| 238 | + } // loop overA |
| 239 | + // printf("mixMid idet=%d sect=%d Nhit A=%d B=%d\n",det,secID,rawHitA.size(),myHitB.size()); |
| 240 | + |
| 241 | + |
| 242 | + /* 2) verify no hits remain in collection B. |
| 243 | + some hits may be left for real events: |
| 244 | + * in 2004 or earlier (due to the code implementation) |
| 245 | + * in 2005+ if a crate is masked out due to any form of corruption or being OFF |
| 246 | + */ |
| 247 | + |
| 248 | + if(myHitB.size()) |
| 249 | + LOG_WARN<<Form("%s::Make() merging: %d hits in collB for sect=%d are dropped\n since those channels are not available in collA, \n a crate is probably masked out\n",GetName(), myHitB.size(),secID)<<endm; |
| 250 | + // printf("mixEnd idet=%d sect=%d Nhit A=%d B=%d\n",det,secID,rawHitA.size(),myHitB.size()); |
| 251 | + |
| 252 | + } // loop over sector |
| 253 | + } // loop over detectors |
| 254 | + |
| 255 | + return true; // all finished w/o problems |
| 256 | +} |
| 257 | + |
| 258 | + |
| 259 | + |
| 260 | +/////////////////////////////////////////////////////////////////////////// |
| 261 | +// |
| 262 | +// $Id: StEEmcMixerMaker.cxx,v 1.10 2010/01/28 14:16:46 jwebb Exp $ |
| 263 | +// $Log: StEEmcMixerMaker.cxx,v $ |
| 264 | +// Revision 1.10 2010/01/28 14:16:46 jwebb |
| 265 | +// (1) Use "Form" to get around deprecated conversion from string constant to |
| 266 | +// char * |
| 267 | +// (2) eemcPrint called on debug only. |
| 268 | +// |
| 269 | +// Revision 1.9 2009/11/23 23:44:32 ogrebeny |
| 270 | +// At Pibero's request, for the embedding infrastructure. |
| 271 | +// |
| 272 | +// Revision 1.8 2009/02/05 20:06:52 ogrebeny |
| 273 | +// Changed StEEmcDbMaker -> StEEmcDb |
| 274 | +// |
| 275 | +// Revision 1.7 2007/04/28 17:56:02 perev |
| 276 | +// Redundant StChain.h removed |
| 277 | +// |
| 278 | +// Revision 1.6 2007/03/23 03:26:23 balewski |
| 279 | +// Corretions from Victor |
| 280 | +// |
| 281 | +// Revision 1.5 2007/02/07 02:24:34 balewski |
| 282 | +// fix logic error found by Wei-Ming |
| 283 | +// |
| 284 | +// Revision 1.4 2007/01/24 21:07:03 balewski |
| 285 | +// 1) no cout or printf, only new Logger |
| 286 | +// 2) EndcapMixer: |
| 287 | +// - no assert() |
| 288 | +// - locks out on first fatal error til the end of the job |
| 289 | +// |
| 290 | +// Revision 1.3 2006/12/22 15:20:45 balewski |
| 291 | +// ignore M-C hits for crates masked for real events, as suggested by Wei-Ming |
| 292 | +// |
| 293 | +// Revision 1.2 2006/12/13 13:24:38 balewski |
| 294 | +// fix wrong header path |
| 295 | +// |
| 296 | +// Revision 1.1 2006/12/12 20:29:13 balewski |
| 297 | +// added hooks for Endcap embedding |
| 298 | +// |
| 299 | +// Revision 1.1.1.1 2005/05/31 18:53:25 wzhang |
| 300 | +// First version |
| 301 | +// |
| 302 | +// |
| 303 | +/////////////////////////////////////////////////////////////////////////// |
0 commit comments