18 #include "St_DataSetIter.h"
19 #include "St_ObjectSet.h"
20 #include "StSsdEmbeddingMaker.h"
21 #include "StMessMgr.h"
23 #include "tables/St_sls_strip_Table.h"
24 #include "tables/St_spa_strip_Table.h"
25 #include "StSsdDbMaker/StSsdDbMaker.h"
26 #include "StSsdUtil/StSsdBarrel.hh"
27 #include "StDAQMaker/StDAQReader.h"
28 #include "StDAQMaker/StSSDReader.h"
29 #include "StSsdSimulationMaker/St_spa_Maker.h"
30 #include "StSsdPointMaker/StSsdPointMaker.h"
39 mPlainSimIfNoSSD = kFALSE;
45 StSsdEmbeddingMaker::~StSsdEmbeddingMaker()
49 Int_t StSsdEmbeddingMaker::Init()
52 hStripsSimu =
new TH1F(
"hStripsSimu",
"Log_{10} of the number of strip after dAQ cut in simulation",100,0,10);
53 hStripsReal =
new TH1F(
"hStripsReal",
"Log_{10} of the number of strip after dAQ cut in real data",100,0,10);
54 hStripsCommon =
new TH1F(
"hStripsCommon",
"number of strips in common from real file and simu file",1000,0,1000);
56 return StMaker::Init();
62 assert(StSsdBarrel::Instance());
63 TDataSet *ssdparams = GetInputDB(
"Geometry/ssd");
65 LOG_ERROR <<
"No access to Geometry/ssd parameters" << endm;
69 m_dimensions = (St_ssdDimensions *)local(
"ssdDimensions");
70 ssdDimensions_st *dimensions = m_dimensions->GetTable();
71 setSsdParameters(dimensions);
77 LOG_INFO<<
"##################################"<<endm;
78 LOG_INFO<<
"#### START OF SSD EMBEDDING ####"<<endm;
81 mRunningEmbedding=mDoEmbedding;
83 if (mDoEmbedding && NoSsd() ){
85 if (mPlainSimIfNoSSD){
86 mRunningEmbedding=kFALSE;
90 LOG_INFO <<
"SSD SlowSimulation: SKIPPING THIS EVENT - no SSD in real data!!"<<endm;
96 if (res!=
kStOk)
return res;
99 if (mRunningEmbedding) sprintf(st,
"EMBEDDING");
100 else sprintf(st,
"PLAIN SIMULATION");
101 LOG_INFO<<
"SSD SlowSimulation is running in the state of :"<<st<<endm;
102 if (mRunningEmbedding){
104 Int_t SIZEREAL = mSsdrealData->GetNRows();
105 Int_t SIZESIMU = mSsdSimuData->GetNRows();
106 LOG_INFO <<
"#### NUMBER OF STRIPS (SIMU) : "<<SIZESIMU <<
" ####"<<endm;
107 LOG_INFO <<
"#### NUMBER OF STRIPS (REAL) : "<<SIZEREAL <<
" ####"<<endm;
108 if(Debug())CheckTables();
109 Int_t numberofstrips_in_common = AddRawData();
110 LOG_INFO <<
"#### MERGE SIMU+REAL : "<<numberofstrips_in_common <<
"####" << endm;
111 if (IAttr(
".histos")){
112 if(SIZESIMU>0){hStripsSimu->Fill(TMath::Log10(SIZESIMU));}
113 if(SIZEREAL>0){hStripsReal->Fill(TMath::Log10(SIZEREAL));}
114 hStripsCommon->Fill(numberofstrips_in_common);
120 Int_t StSsdEmbeddingMaker::GetSsdData()
123 if(!mRunningEmbedding)
return kStOk;
124 mSsdSimuData = (St_spa_strip*)GetDataSet(
"SsdSimuData");
126 if (!mSsdSimuData || mSsdSimuData->GetNRows()==0){
127 LOG_ERROR <<
"GetSsdData : no simu input (fired strip for the SSD)"<<endm;
130 if(mSsdSimuData) LOG_INFO <<
"Numbers of strips (simu) = " << mSsdSimuData->GetNRows()<< endm;
132 mSsdrealData = (St_spa_strip*)GetDataSet(
"SsdRealData");
133 if (!mSsdrealData || mSsdrealData->GetNRows()==0){
134 LOG_ERROR <<
"GetSsdData : no real input (fired strip for the SSD)"<<endm;
137 if(mSsdrealData) LOG_INFO <<
"Numbers of strips (real) = " << mSsdrealData->GetNRows()<< endm;
141 Int_t StSsdEmbeddingMaker::AddRawData(){
142 mSsdSimuReal =
new St_spa_strip(
"spa_strip",50000);
143 AddData(mSsdSimuReal);
144 spa_strip_st out_strip ;
148 Int_t nStripSimu = 0;
150 spa_strip_st *strip_simu = mSsdSimuData->GetTable();
154 Int_t nStripReal = 0;
156 spa_strip_st *strip_real = mSsdrealData->GetTable();
157 Int_t currRecord = 0;
158 Int_t currRecordSimu = 0;
159 Int_t currRecordReal = 0;
160 Int_t currRecordCommon = 0;
161 Int_t IdCommon[mSsdSimuData->GetNRows()];
162 for(Int_t ll=0;ll<mSsdSimuData->GetNRows();ll++) IdCommon[ll]=0;
163 for (Int_t i = 0 ; i < mSsdrealData->GetNRows(); i++)
165 nStripReal = (int)(strip_real[i].id_strip/100000.);
166 idWafReal = strip_real[i].id_strip-10000*((int)(strip_real[i].id_strip/10000.));
167 iWafReal = idWaferToWafer(idWafReal);
168 iLadReal = (int)(idWafReal - mSsdLayer*1000 - (iWafReal+1)*100 - 1);
169 iSideReal = (strip_real[i].id_strip - nStripReal*100000 - idWafReal)/10000;
171 for (Int_t j = 0 ; j < mSsdSimuData->GetNRows(); j++)
173 nStripSimu = (int)(strip_simu[j].id_strip/100000.);
174 idWafSimu = strip_simu[j].id_strip-10000*((int)(strip_simu[j].id_strip/10000.));
175 iWafSimu = idWaferToWafer(idWafSimu);
176 iLadSimu = (int)(idWafSimu - mSsdLayer*1000 - (iWafSimu+1)*100 - 1);
177 iSideSimu = (strip_simu[j].id_strip - nStripSimu*100000 - idWafSimu)/10000;
179 if((nStripReal == nStripSimu) && (idWafReal == idWafSimu) && (iSideReal == iSideSimu))
181 LOG_DEBUG<<Form(
"simu side=%d idWafer=%d Ladder=%d wafer=%d nstrip=%d signal=%d",iSideSimu,idWafSimu,iLadSimu,iWafSimu,nStripSimu,strip_simu[j].adc_count)<<endm;
182 LOG_DEBUG<<Form(
"real side=%d idWafer=%d Ladder=%d wafer=%d nstrip=%d signal=%d",iSideReal,idWafReal,iLadReal,iWafReal,nStripReal,strip_real[i].adc_count)<<endm;
183 out_strip.id = currRecord + 1;
184 out_strip.adc_count = (int)(strip_simu[j].adc_count + strip_real[i].adc_count);
185 out_strip.id_strip = 10000*(10*nStripSimu + iSideSimu)+idWafSimu;
186 for (Int_t e = 0 ; e < 5 ; e++)
188 out_strip.id_mchit[e] = strip_simu[j].id_mchit[e];
189 out_strip.id_mctrack[e] = strip_simu[j].id_mctrack[e];
191 mSsdSimuReal->AddAt(&out_strip);
192 IdCommon[currRecordCommon] = (int)strip_real[i].id_strip;
196 LOG_DEBUG<<Form(
"# of strips in common =%d id=%d",currRecordCommon,(
int)strip_real[i].id_strip)<<endm;
199 for(Int_t ii=0;ii<5;ii++){
200 LOG_INFO <<
"mchit["<<ii<<
"]="<<strip_simu[j].id_mchit[ii]<<endm;
201 LOG_INFO <<
"mctrack["<<ii<<
"]="<<strip_simu[j].id_mctrack[ii]<<endm;
202 LOG_INFO <<
" "<< endm;
210 out_strip.id = currRecord + 1;
211 out_strip.adc_count = (int)(strip_real[i].adc_count);
212 out_strip.id_strip = 10000*(10*nStripReal + iSideReal)+idWafReal;
213 for (Int_t e = 0 ; e < 5 ; e++)
215 out_strip.id_mchit[e] = 0;
216 out_strip.id_mctrack[e] = 0;
218 mSsdSimuReal->AddAt(&out_strip);
225 for(Int_t k=0; k <mSsdSimuData->GetNRows();k++)
228 for (Int_t kk=0;kk<currRecordCommon;kk++)
230 if((
int)strip_simu[k].id_strip == IdCommon[kk]){
231 LOG_DEBUG<<Form(
"k = %d strip id =%d",k,(
int)strip_simu[k].id_strip)<<endm;
236 nStripSimu = (int)(strip_simu[k].id_strip/100000.);
237 idWafSimu = strip_simu[k].id_strip-10000*((int)(strip_simu[k].id_strip/10000.));
238 iWafSimu = idWaferToWafer(idWafSimu);
239 iLadSimu = (int)(idWafSimu - mSsdLayer*1000 - (iWafSimu+1)*100 - 1);
240 iSideSimu = (strip_simu[k].id_strip - nStripSimu*100000 - idWafSimu)/10000;
241 out_strip.id = currRecord + 1;
242 out_strip.adc_count = (int)(strip_simu[k].adc_count);
243 out_strip.id_strip = 10000*(10*nStripSimu + iSideSimu)+idWafSimu;
244 for (Int_t e = 0 ; e < 5 ; e++)
246 out_strip.id_mchit[e] = strip_simu[k].id_mchit[e];
247 out_strip.id_mctrack[e] = strip_simu[k].id_mctrack[e];
249 mSsdSimuReal->AddAt(&out_strip);
254 LOG_INFO<<Form(
"# in common = %d totstrips after add = %d totstrips for simu only = %d for real only = %d",currRecordCommon,currRecord,currRecordSimu,currRecordReal)<<endm;
263 void StSsdEmbeddingMaker::setDoEmbedding(Bool_t doIt){
267 void StSsdEmbeddingMaker::setPlainSimEvenIfNoSSD(Bool_t doIt){
268 mPlainSimIfNoSSD= doIt;
271 Int_t StSsdEmbeddingMaker::NoSsd()
275 dataSet = GetDataSet(
"StDAQReader");
277 LOG_ERROR<<(
"BIG TROUBLE: cannot find StDAQReader in the chain and you want to run embedding")<<endm;
282 LOG_ERROR<<(
"BIG TROUBLE: StDAQReader is empty and you want to run embedding")<<endm;
285 if (!daqReader->SSDPresent ())
287 LOG_INFO<<(
"NO SSD in DAQ")<<endm;
291 LOG_INFO<<(
"SSD found in DAQ")<<endm;
295 void StSsdEmbeddingMaker::CheckTables(){
296 spa_strip_st *strip = mSsdSimuData->GetTable();
304 LOG_DEBUG<<
"check simu table :" << endm;
305 for (i = 0 ; i < mSsdSimuData->GetNRows(); i++)
307 nStrip = (int)(strip[i].id_strip/100000.);
308 idWaf = strip[i].id_strip-10000*((int)(strip[i].id_strip/10000.));
309 iWaf = idWaferToWafer(idWaf);
310 iLad = (int)(idWaf - mSsdLayer*1000 - (iWaf+1)*100 - 1);
311 iSide = (strip[i].id_strip - nStrip*100000 - idWaf)/10000;
312 LOG_DEBUG<<Form(
"side=%d idWafer=%d Ladder=%d wafer=%d nstrip=%d signal=%d",iSide,idWaf,iLad,iWaf,nStrip,strip[i].adc_count)<<endm;
313 for(Int_t ii=0;ii<5;ii++){printf(
"id_mchit[%d] =%d\n",ii,strip[i].id_mchit[ii]);}
316 LOG_DEBUG <<
"check real table : " << endm;
317 strip = mSsdrealData->GetTable();
318 for (i = 0 ; i < mSsdrealData->GetNRows(); i++)
320 nStrip = (int)(strip[i].id_strip/100000.);
321 idWaf = strip[i].id_strip-10000*((int)(strip[i].id_strip/10000.));
322 iWaf = idWaferToWafer(idWaf);
323 iLad = (int)(idWaf - mSsdLayer*1000 - (iWaf+1)*100 - 1);
324 iSide = (strip[i].id_strip - nStrip*100000 - idWaf)/10000;
325 LOG_DEBUG<<Form(
"side=%d Ladder=%d wafer=%d nstrip=%d signal=%d",iSide,iLad,iWaf,nStrip,strip[i].adc_count)<<endm;
330 void StSsdEmbeddingMaker::setSsdParameters(ssdDimensions_st *geom_par){
331 mDimensions = geom_par;
333 mDetectorLargeEdge = 2.*geom_par[0].waferHalfActLength;
334 mDetectorSmallEdge = 2.*geom_par[0].waferHalfActWidth;
336 mNWaferPerLadder = geom_par[0].wafersPerLadder;
337 mNStripPerSide = geom_par[0].stripPerSide;
338 mStripPitch = geom_par[0].stripPitch;
339 mTheta = geom_par[0].stereoAngle;
virtual TObject * GetObject() const
The depricated method (left here for the sake of the backward compatibility)
virtual Int_t InitRun(int)
All database dependent data are read here.