58 #include "St_DataSetIter.h"
59 #include "St_ObjectSet.h"
60 #include "StSequence.hh"
61 #include "StSvtEmbeddingMaker.h"
62 #include "StMessMgr.h"
64 #include "StSvtClassLibrary/StSvtHybridCollection.hh"
65 #include "StSvtClassLibrary/StSvtHybridData.hh"
66 #include "StSvtClassLibrary/StSvtData.hh"
67 #include "StSvtClassLibrary/StSvtHybridPixelsD.hh"
68 #include "StSvtClassLibrary/StSvtHybridPixels.hh"
69 #include "StSvtClassLibrary/StSvtConfig.hh"
70 #include "StSvtClassLibrary/StSvtHybridPed.hh"
71 #include "StDAQMaker/StSVTReader.h"
79 #define cDefaultBckgRMS 1.8
87 mPlainSimIfNoSVT=kFALSE;
88 setBackGround(kTRUE,cDefaultBckgRMS);
89 SetPedRmsPreferences(kTRUE, kTRUE);
99 StSvtEmbeddingMaker::~StSvtEmbeddingMaker()
105 Int_t StSvtEmbeddingMaker::Init()
107 return StMaker::Init();
115 gMessMgr->Warning()<<
"StSvtEmbeddingMaker - reading individual pixel RMS values from database "<<endm;
117 if (mPedRMSColl) {gMessMgr->Warning()<<
"StSvtEmbeddingMaker: Found RMS values for individual pixels."<<endm;}
118 else {gMessMgr->Warning()<<
"StSvtEmbeddingMaker: NO RMS values for individual pixels."<<endm;}
122 gMessMgr->Warning()<<
"StSvtEmbeddingMaker - reading individual hybrid RMS values from database "<<endm;
124 if (mPedColl) {gMessMgr->Warning()<<
"StSvtEmbeddingMaker: Found RMS values for individual hybrids."<<endm;}
125 else {gMessMgr->Warning()<<
"StSvtEmbeddingMaker: NO RMS values for individual hybrids."<<endm;}
127 if ((!mPedRMSColl)&&(!mPedColl))
128 {gMessMgr->Warning()<<
"Warning: no SVT RMS information available from Chain - using default backgroung:"<<mBackGSigma<<endm;}
130 return StMaker::InitRun(runumber);
138 mRunningEmbedding=mDoEmbedding;
140 if (mDoEmbedding &&NoSvt() ){
142 if (mPlainSimIfNoSVT){
143 mRunningEmbedding=kFALSE;
148 gMessMgr->Info()<<
"SVT SlowSimulation: SKIPPING THIS EVENT - no SVT in real data!!"<<endm;
155 if (mRunningEmbedding) sprintf(st,
"EMBEDDING");
156 else sprintf(st,
"PLAIN SIMULATION");
157 gMessMgr->Info()<<
"SVT SlowSimulation is running in the state of :"<<st<<endm;
163 if (res!=
kStOk)
return res;
167 for(
int Barrel = 1;Barrel <= mSimPixelColl->getNumberOfBarrels();Barrel++) {
168 for (
int Ladder = 1;Ladder <= mSimPixelColl->getNumberOfLadders(Barrel);Ladder++) {
169 for (
int Wafer = 1;Wafer <= mSimPixelColl->getNumberOfWafers(Barrel);Wafer++) {
170 for(
int Hybrid = 1;Hybrid <= mSimPixelColl->getNumberOfHybrids();Hybrid++){
171 mCurrentIndex = mSimPixelColl->getHybridIndex(Barrel,Ladder,Wafer,Hybrid);
172 if( mCurrentIndex < 0)
continue;
176 if(!mCurrentPixelData) {
177 gMessMgr->Error()<<
"Error in StSvtEmbeddingMaker::Make(): Something is wrong, no data from simulator for hybrid index:"<<mCurrentIndex<<endm;
179 mSimPixelColl->put_at(mCurrentPixelData,mCurrentIndex);
182 if (mRunningEmbedding){
187 if (mBackGrOption) CreateBackground();
198 Int_t StSvtEmbeddingMaker::GetSvtData()
204 St_DataSet* dataSet = GetDataSet(
"StSvtPixelData");
206 LOG_FATAL <<
"BIG TROUBLE:No data from simulator to work with!!!!"<<endm;
211 if ( mSimPixelColl==NULL){
212 gMessMgr->Error()<<
"BIG TROUBLE:Data from simulator is empty!!!!"<<endm;
216 if (!mRunningEmbedding)
return kStOk;
217 dataSet = GetDataSet(
"StSvtRawData");
219 else gMessMgr->Error()<<
"No StSvtRawData in the chain"<<endm;
222 gMessMgr->Error()<<
"Note: StSvtEmbeddingMaker is set to do embbeding, but found no raw data- embedding into empty event!!!"<<endm;
231 void StSvtEmbeddingMaker::AddRawData()
241 double *adcArray=mCurrentPixelData->GetArray();
242 double offset = mCurrentPixelData->getPedOffset();
246 for (
int iAnode= 0; iAnode<realData->getAnodeList(anolist); iAnode++){
248 int Anode = anolist[iAnode];
249 realData->getSequences(Anode,numOfSeq,Sequence);
251 for (
int nSeq=0; nSeq< numOfSeq ; nSeq++){
252 unsigned char* adc=Sequence[nSeq].firstAdc;
253 int length = Sequence[nSeq].length;
254 int startTimeBin=Sequence[nSeq].startTimeBin;
256 for(
int t = 0; t<length; t++){
257 int time = startTimeBin + t;
258 unsigned char adcVal = adc[t];
261 int pixelIndex=(Anode-1)*128+time;
263 adcArray[pixelIndex]=adcArray[pixelIndex]+(double)adcVal-offset;
266 mMask[pixelIndex]=kFALSE;
272 for(
int an = 0; an < 240; an++){
273 for(
int tim = 0; tim < 128; tim++){
274 int pIndex=an*128 + tim;
275 if (adcArray[pIndex]==offset) mMask[pIndex]=kFALSE;
282 double StSvtEmbeddingMaker::MakeGaussDev(
double sigma)
285 double fac,rsq,v1,v2;
288 v1 = 2.0*((float)rand()/(float)RAND_MAX) - 1.0;
289 v2 = 2.0*((float)rand()/(float)RAND_MAX) - 1.0;
291 }
while(rsq >= 1.0 );
293 fac = sigma*::sqrt(-2.0*::log(rsq)/rsq);
302 void StSvtEmbeddingMaker::CreateBackground()
304 const double rmsScale=16.;
305 double *adcArray=mCurrentPixelData->GetArray();
312 if (pedRms == NULL) {gMessMgr->Warning()<<
"Warning: Individual pixel RMS info is empty for hybrid "<<mCurrentIndex<<
" =>have to use other method "<<endm;}
317 for(
int an = 0; an < 240; an++)
for(
int tim = 0; tim < 128; tim++){
319 int pIndex=an*128 + tim;
320 if (mMask[pIndex]) adcArray[pIndex]+=MakeGaussDev(pedRms->At(pedRms->getPixelIndex(an+1,tim))/rmsScale);
329 if (ped == NULL) {gMessMgr->Warning()<<
"Warning: hybrid RMS info is empty for hybrid "<<mCurrentIndex<<
" =>using default value "<<mBackGSigma<<endm;}
331 if (ped) backgsigma=ped->getRMS();
else backgsigma=mBackGSigma;
332 if ((backgsigma<=0.)||(backgsigma>=6.)){
333 {gMessMgr->Warning()<<
"Warnig for index "<<mCurrentIndex<<
" pedestal RMS is:"<<backgsigma<<
" => seting to default "<<mBackGSigma<<endm;}
334 backgsigma=mBackGSigma;
336 if (Debug()) {gMessMgr->Debug()<<
"for index "<<mCurrentIndex<<
" pedestal RMS is:"<< backgsigma<<endm;}
338 for(
int an = 0; an < 240; an++){
339 for(
int tim = 0; tim < 128; tim++){
340 int pIndex=an*128 + tim;
341 if (mMask[pIndex]) adcArray[pIndex]+=MakeGaussDev(backgsigma);
355 void StSvtEmbeddingMaker::SetPedRmsPreferences(Bool_t usePixelRMS, Bool_t useHybridRMS)
357 mUsePixelRMS=usePixelRMS;
358 mUseHybridRMS=useHybridRMS;
363 void StSvtEmbeddingMaker::setDoEmbedding(Bool_t doIt){
368 void StSvtEmbeddingMaker::setPlainSimEvenIfNoSVT(Bool_t doIt){
369 mPlainSimIfNoSVT= doIt;
372 void StSvtEmbeddingMaker::setBackGround(Bool_t backgr,
double backgSigma){
373 mBackGrOption = backgr;
374 mBackGSigma = backgSigma;
378 void StSvtEmbeddingMaker::ClearMask()
380 for (
int i=0;i<128*240;i++)mMask[i]=kTRUE;
384 Int_t StSvtEmbeddingMaker::NoSvt()
388 dataSet = GetDataSet(
"StDAQReader");
390 gMessMgr->Error()<<(
"BIG TROUBLE: cannot find StDAQReader in the chain and you want to run embedding")<<endm;
395 gMessMgr->Error()<<(
"BIG TROUBLE: StDAQReader is empty and you want to run embedding")<<endm;
399 if (!daqReader->SVTPresent ())
401 gMessMgr->Info()<<(
"NO SVT in DAQ")<<endm;
405 gMessMgr->Info()<<(
"SVT found in DAQ")<<endm;
411 void StSvtEmbeddingMaker::ClearOutputData()
415 for(
int Barrel = 1;Barrel <= mSimPixelColl->getNumberOfBarrels();Barrel++) {
416 for (
int Ladder = 1;Ladder <= mSimPixelColl->getNumberOfLadders(Barrel);Ladder++) {
417 for (
int Wafer = 1;Wafer <= mSimPixelColl->getNumberOfWafers(Barrel);Wafer++) {
418 for(
int Hybrid = 1;Hybrid <= mSimPixelColl->getNumberOfHybrids();Hybrid++){
420 int index = mSimPixelColl->getHybridIndex(Barrel,Ladder,Wafer,Hybrid);
421 if( index < 0)
continue;
427 mSimPixelColl->put_at(tmpPixels,index);
429 tmpPixels->setPedOffset(0);
436 LOG_ERROR <<
"StSvtEmbeddingMaker::ClearOutputData(): There is no SVT data to clear" << endm;
virtual Int_t InitRun(int runumber)
All database dependent data are read here.
This maker is resposible for embedding SVT response simulation into the SVT real data and/or creation...
virtual TObject * GetObject() const
The depricated method (left here for the sake of the backward compatibility)
StSvtEmbeddingMaker(const char *name="SvtEmbedding")