00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050
00051
00052
00053
00054
00055
00056
00057
00058
00059
00060 #include <Stiostream.h>
00061 #include <stdlib.h>
00062 #include "St_sls_Maker.h"
00063 #include "TDataSetIter.h"
00064 #include "TFile.h"
00065 #include "StMessMgr.h"
00066
00067 #include "StSsdUtil/StSsdBarrel.hh"
00068 #include "StSsdUtil/StSsdPoint.hh"
00069 #include "StSsdUtil/StSsdPointList.hh"
00070 #include "StSsdUtil/StSsdStrip.hh"
00071 #include "StSsdUtil/StSsdStripList.hh"
00072 #include "tables/St_sls_strip_Table.h"
00073 #include "tables/St_g2t_svt_hit_Table.h"
00074 #include "tables/St_g2t_ssd_hit_Table.h"
00075 #include "tables/St_ssdDimensions_Table.h"
00076
00077 #include "tables/St_slsCtrl_Table.h"
00078 #include "StSsdUtil/StSsdBarrel.hh"
00079
00080 #include "StBFChain.h"
00081 #include "StChain.h"
00082 #include "StMaker.h"
00083
00084 #include "tables/St_g2t_track_Table.h"
00085 #include "StThreeVectorD.hh"
00086 #include "StPhysicalHelixD.hh"
00087 #include "SystemOfUnits.h"
00088 #include "StarMagField.h"
00089 #include "StMcEvent/StMcSsdHitCollection.hh"
00090 #include "StMcEvent.hh"
00091 #include "StEventTypes.h"
00092 #include "StMcEventTypes.hh"
00093 #include "StDAQMaker/StDAQReader.h"
00094 #include "St_ObjectSet.h"
00095 #include "StThreeVectorF.hh"
00096 #include "StSsdDbMaker/StSsdDbMaker.h"
00097
00098 ClassImp(St_sls_Maker)
00099 St_sls_Maker::St_sls_Maker(const char *name):StMaker(name){
00100 mHit = 0;
00101 m_ctrl = 0;
00102 };
00103
00104 St_sls_Maker::~St_sls_Maker(){ }
00105
00106 Int_t St_sls_Maker::Init(){
00107 if (IAttr(".histos")) {
00108 hRejected = new TH1F("hRejected","hits after removal / hits GEANT",110,0,1.1);
00109 }
00110 return kStOk;
00111 }
00112
00113 Int_t St_sls_Maker::InitRun(Int_t runNumber) {
00114 assert(StSsdBarrel::Instance());
00115 LOG_DEBUG << " instance of barrel ... done " << endm;
00116
00117 m_ctrl = gStSsdDbMaker->GetSlsCtrl();
00118 m_dimensions = 0;
00119 m_dimensions = gStSsdDbMaker->GetssdDimensions();
00120 m_positions = 0;
00121 m_positions = gStSsdDbMaker->GetssdWafersPos();
00122
00123 if (!m_ctrl) {
00124 LOG_ERROR << "No access to control parameters" << endm;
00125 return kStFatal;
00126 }
00127 if ((!m_dimensions)||(!m_positions)) {
00128 LOG_ERROR << "No access to geometry parameters" << endm;
00129 return kStFatal;
00130 }
00131 if(m_positions){
00132 LOG_DEBUG << " m_positions found " << endl;
00133 positions = m_positions->GetTable();
00134 N = m_positions->GetNRows();
00135 LOG_DEBUG << " size is : " <<N << endl;
00136 }
00137
00138 Float_t center[3]={0,0,0};
00139 Float_t B[3]={0,0,0};
00140 StarMagField::Instance()->BField(center,B);
00141 mBField = B[2]*kilogauss;
00142 return kStOk;
00143 }
00144
00145 Int_t St_sls_Maker::Make()
00146 {
00147 if (Debug()==true) {LOG_DEBUG << "Make() ..." << endm;}
00148
00149
00150 ssdDimensions_st *dimensions = m_dimensions->GetTable();
00151
00152 setSsdParameters(dimensions);
00153 if(Debug()){
00154 printSsdParameters();}
00155
00156 Int_t res = 0;
00157 St_sls_strip *sls_strip = new St_sls_strip("sls_strip",40000);
00158 m_DataSet->Add(sls_strip);
00159
00160 TDataSetIter geant(GetInputDS("geant"));
00161 St_g2t_svt_hit *g2t_svt_hit = (St_g2t_svt_hit *) geant("g2t_svt_hit");
00162 St_g2t_ssd_hit *g2t_ssd_hit = (St_g2t_ssd_hit *) geant("g2t_ssd_hit");
00163
00164
00165
00166
00167 LOG_INFO<<"#################################################"<<endm;
00168 LOG_INFO<<"#### START OF SSD LAZY SIMULATOR ####"<<endm;
00169 LOG_INFO<<"#### SSD BARREL INITIALIZATION ####"<<endm;
00170 LOG_INFO<<"#### SSD WAFERS INITIALIZATION ####"<<endm;
00171 Int_t nSsdHits = 0;
00172 if (g2t_ssd_hit)
00173 {
00174
00175
00176 St_DataSet *g2t_tracks = GetDataSet("g2t_track");
00177 St_DataSetIter g2t_track_it(g2t_tracks);
00178 St_g2t_track *g2t_track = (St_g2t_track *) g2t_track_it.Find("g2t_track");
00179 if(!g2t_track){
00180 LOG_WARN <<" no track table , abort event because we cannot procede IdealTorealMethod()" << endm;
00181 return kStErr;
00182 }
00183 LOG_INFO<<Form("Num of SSD geant hits =%ld",g2t_ssd_hit->GetNRows());
00184
00185 nSsdHits = readPointFromTableWithEmbedding(g2t_ssd_hit,g2t_track,N,positions);
00186 if(g2t_ssd_hit->GetNRows())hRejected->Fill((float)nSsdHits/g2t_ssd_hit->GetNRows());
00187 }
00188 if (nSsdHits == 0)
00189 {
00190 if (g2t_svt_hit)
00191 {
00192 nSsdHits = readPointFromTable( g2t_svt_hit);
00193 }
00194 }
00195 LOG_INFO <<"#### -> "<<nSsdHits<<" HITS READ FROM TABLE ####"<<endm;
00196 StSsdBarrel::Instance()->convertGlobalFrameToOther();
00197 Int_t inactiveHit = 0;
00198 if (g2t_ssd_hit)
00199 {
00200 inactiveHit = removeInactiveHitInTable(g2t_ssd_hit);
00201 }
00202 else
00203 {
00204 if (g2t_svt_hit)
00205 {
00206 inactiveHit = removeInactiveHitInTable(g2t_svt_hit);
00207 }
00208 }
00209 LOG_INFO<<"#### -> "<<inactiveHit<<" DEAD ZONE HITS REMOVED ####"<<endm;
00210
00211 chargeSharingOverStrip(m_ctrl);
00212 Int_t nSsdStrips = writeStripToTable(sls_strip);
00213 sls_strip->Purge();
00214 LOG_INFO<<"#### -> "<<nSsdStrips<<" FIRED STRIPS INTO TABLE ####"<<endm;
00215 LOG_INFO<<"#### END OF SSD LAZY SIMULATOR ####"<<endm;
00216 LOG_INFO<<"#################################################"<<endm;
00217 StSsdBarrel::Instance()->Reset();
00218 if (nSsdStrips) res = kStOK;
00219
00220 if(res!=kStOK){
00221 LOG_WARN<<"no output"<<endm;
00222 return kStWarn;
00223 }
00224 if(Debug()==true){ LOG_DEBUG << "Make():end ... "<< endm;}
00225 return kStOK;
00226 }
00227
00228 void St_sls_Maker::PrintInfo() {
00229 if (Debug()==true){ StMaker::PrintInfo();}
00230 }
00231
00232 Int_t St_sls_Maker::Finish() {
00233 if (Debug()==true){LOG_DEBUG << "Finish() ... " << endm;}
00234 return kStOK;
00235 }
00236
00237 Int_t St_sls_Maker::readPointFromTable(St_g2t_ssd_hit *g2t_ssd_hit) {
00238 g2t_ssd_hit_st *g2t = g2t_ssd_hit->GetTable();
00239
00240
00241
00242
00243 Int_t minWaf = StSsdBarrel::Instance()->getSsdLayer()*1000;
00244 Int_t currWafId = 0;
00245 Int_t currWafNumb = 0;
00246 Int_t currLadder = 0;
00247 Int_t counter = 0;
00248 Int_t i = 0 ;
00249 Int_t j = 0 ;
00250
00251 Float_t p[3] = {0,0,0};
00252 for (i = 0; i < g2t_ssd_hit->GetNRows() ; i++) {
00253 currWafId=g2t[i].volume_id%10000;
00254 if (currWafId > minWaf) {
00255 counter++;
00256 currLadder=StSsdBarrel::Instance()->idWaferToLadderNumb(currWafId);
00257 currWafNumb=StSsdBarrel::Instance()->idWaferToWafer(currWafId);
00258 for (j = 0; j<3; j++) {p[j] = g2t[i].p[j];}
00259 StSsdBarrel::Instance()->mLadders[currLadder]->mWafers[currWafNumb]->
00260 addHit(g2t[i].id, g2t[i].id, g2t[i].track_p, g2t[i].x, g2t[i].de, p);
00261 }
00262 }
00263 return counter;
00264 }
00265
00266 Int_t St_sls_Maker::removeInactiveHitInTable(St_g2t_ssd_hit *g2t_ssd_hit) {
00267 g2t_ssd_hit_st *g2t = g2t_ssd_hit->GetTable();
00268 StSsdPointList *inactiveHits = StSsdBarrel::Instance()->getInactiveHitList();
00269 Int_t localSize = 0;
00270 localSize=inactiveHits->getSize();
00271 if (localSize)
00272 {
00273 Int_t firstSsdPoint=0;
00274 Int_t iP1 = 0;
00275 for (iP1 = 0; ((iP1 < g2t_ssd_hit->GetNRows())&&(g2t[iP1].volume_id%10000 < StSsdBarrel::Instance()->getSsdLayer()*1000)) ; iP1++)
00276 firstSsdPoint=iP1;
00277 firstSsdPoint++;
00278 Int_t isG2tSorted = 1;
00279 Int_t iP2 = 0;
00280 for (iP2 = firstSsdPoint+1 ; (iP2 < g2t_ssd_hit->GetNRows())&&(isG2tSorted) ;iP2++)
00281 {
00282 if (g2t[iP2].id < g2t[iP2 - 1].id) isG2tSorted = 0;
00283 }
00284 StSsdPoint *currToDele = inactiveHits->first();
00285 Int_t nDeleted = 0;
00286 Int_t isAllRemove = 0;
00287 if (isG2tSorted)
00288 {
00289 Int_t ipScan = 0;
00290 Int_t ipKeep = firstSsdPoint;
00291 for (ipScan = firstSsdPoint; (ipScan<g2t_ssd_hit->GetNRows()); ipScan++)
00292 {
00293 if ((!isAllRemove)&&(g2t[ipScan].id == currToDele->getNId()))
00294 {
00295 currToDele=inactiveHits->next(currToDele);
00296 if (currToDele == 0) isAllRemove = 1;
00297 nDeleted++;
00298 }
00299 else
00300 {
00301 g2t[ipKeep]=g2t[ipScan];
00302 ipKeep++;
00303 }
00304 }
00305 g2t_ssd_hit->SetNRows( g2t_ssd_hit->GetNRows() - nDeleted );
00306 }
00307 else
00308 {
00309 Int_t iLoop = 0;
00310 for (iLoop = 0 ; (iLoop < localSize)&&(!isAllRemove); iLoop++)
00311 {
00312 Int_t ipScan = 0;
00313 Int_t nLoopDeleted = 0;
00314 for (ipScan = firstSsdPoint; ipScan < g2t_ssd_hit->GetNRows() ; ipScan++)
00315 {
00316 if (!isAllRemove)
00317 {
00318 if (g2t[ipScan].id == currToDele->getNId())
00319 {
00320 currToDele=inactiveHits->next(currToDele);
00321 if (currToDele == 0)
00322 {
00323 isAllRemove = 1;
00324 }
00325 else
00326 {
00327 nDeleted++;
00328 nLoopDeleted++;
00329 }
00330 }
00331 }
00332 g2t[ipScan]=g2t[ipScan + nLoopDeleted];
00333 }
00334 g2t_ssd_hit->SetNRows( g2t_ssd_hit->GetNRows() - nDeleted );
00335 }
00336 }
00337 }
00338 StSsdBarrel::Instance()->renumHitAfterRemove();
00339 delete inactiveHits;
00340 return localSize;
00341 }
00342
00343 void St_sls_Maker::chargeSharingOverStrip(slsCtrl_st *ctrl)
00344 {
00345 StSsdBarrel::Instance()->convertToStrip(ctrl[0].pairCreationEnergy,
00346 ctrl[0].nstripInACluster,
00347 ctrl[0].parDiffP,
00348 ctrl[0].parDiffN,
00349 ctrl[0].parIndRightP,
00350 ctrl[0].parIndRightN,
00351 ctrl[0].parIndLeftP,
00352 ctrl[0].parIndLeftN);
00353 }
00354
00355 Int_t St_sls_Maker::writeStripToTable(St_sls_strip *sls_strip) {
00356 sls_strip_st strip;
00357
00358 Int_t currRecord = 0;
00359
00360 for (Int_t iLad = 0; iLad < StSsdBarrel::Instance()->getNumberOfLadders(); iLad++)
00361 for (Int_t iWaf = 0; iWaf < StSsdBarrel::Instance()->getNWaferPerLadder(); iWaf++) {
00362 StSsdWafer *wafer = StSsdBarrel::Instance()->getLadder(iLad)->getWafer(iWaf);
00363
00364 Int_t idCurrentWaf = StSsdBarrel::Instance()->getSsdLayer()*1000 +((iWaf+1)*100)+(iLad+1);
00365 StSsdStripList *stripP = wafer->getStripP();
00366 StSsdStripList *stripN = wafer->getStripN();
00367 StSsdStrip *pStripP = stripP->first();
00368 Int_t iP = 0;
00369 for (iP = 0; iP < stripP->getSize() ; iP++) {
00370 strip.id = currRecord + 1;
00371 strip.adc_count = pStripP->getDigitSig();
00372 strip.noise_count = 0;
00373 strip.id_strip = 10000*(10*pStripP->getNStrip() + 0)+idCurrentWaf;
00374 strip.id_cluster = 0;
00375 strip.N_hits = pStripP->getNHits();
00376 strip.de = pStripP->getAnalogSig();
00377 for (Int_t i = 0 ; i < 5 ; i++) {
00378 strip.id_hit[i] = pStripP->getIdHit(i);
00379 strip.id_mchit[i] = pStripP->getIdMcHit(i);
00380 strip.id_mctrack[i] = pStripP->getIdMcTrack(i);
00381 LOG_DEBUG<<Form("idwafer=%d strip_id=%d side P i=%d IdMcHit=%d IdMcTrack=%d signal(adc)=%d signal(GeV)=%f",
00382 idCurrentWaf,pStripP->getNStrip(),i,pStripP->getIdMcHit(i),pStripP->getIdMcTrack(i),pStripP->getDigitSig(),pStripP->getAnalogSig())
00383 <<endm;
00384 }
00385 sls_strip->AddAt(&strip);
00386 currRecord++;
00387 pStripP = stripP->next(pStripP);
00388 }
00389
00390 StSsdStrip *pStripN = stripN->first();
00391 Int_t iN = 0;
00392 for (iN = 0 ; iN < stripN->getSize() ; iN++) {
00393 strip.id = currRecord + 1;
00394 strip.adc_count = pStripN->getDigitSig();
00395 strip.noise_count = 0;
00396 strip.id_strip = 10000*(10*pStripN->getNStrip() + 1)+idCurrentWaf;
00397 strip.id_cluster = 0;
00398 strip.N_hits = pStripN->getNHits() ;
00399 strip.de = pStripN->getAnalogSig();
00400 for (Int_t i = 0 ; i < 5 ; i++) {
00401 strip.id_hit[i] = pStripN->getIdHit(i);
00402 strip.id_mchit[i] = pStripN->getIdMcHit(i);
00403 strip.id_mctrack[i] = pStripN->getIdMcTrack(i);
00404 LOG_DEBUG <<Form("idwafer=%d strip_id=%d side N i=%d IdMcHit=%d IdMcTrack=%d signal(adc)=%d signal(GeV)=%f",
00405 idCurrentWaf,pStripN->getNStrip(),i,pStripN->getIdMcHit(i),pStripN->getIdMcTrack(i),pStripN->getDigitSig(),pStripN->getAnalogSig())
00406 <<endm;
00407 }
00408 sls_strip->AddAt(&strip);
00409 currRecord++;
00410 pStripN = stripN->next(pStripN);
00411 }
00412 }
00413 return currRecord;
00414 }
00415
00416
00417 Int_t St_sls_Maker::readPointFromTableWithEmbedding(St_g2t_ssd_hit *g2t_ssd_hit, St_g2t_track *g2t_track,Int_t N,ssdWafersPosition_st *positions){
00418 StMcEvent* mcEvent = 0;
00419 mcEvent = (StMcEvent*) GetDataSet("StMcEvent");
00420
00421 StMcSsdHitCollection *mcCol = 0;
00422 StMcSsdHitCollection *mcCol1 = 0;
00423 if(mcEvent)
00424 {
00425 mcCol = mcEvent->ssdHitCollection();
00426 if (!mcCol)
00427 {
00428 LOG_WARN <<"StSsdEmbeddingMaker -E- no SsdHitCollection!" << endm;
00429 mcCol = new StMcSsdHitCollection;
00430 mcEvent->setSsdHitCollection(mcCol);
00431 LOG_WARN <<"Make() has added a non existing StSsdHitCollection" <<endm;
00432 }
00433 else {
00434
00435
00436 mcCol1 = new StMcSsdHitCollection;
00437 mcEvent->setSsdHitCollection(mcCol1);
00438 }
00439 }
00440
00441 g2t_ssd_hit_st *g2t = g2t_ssd_hit->GetTable();
00442 g2t_track_st *g2tTrack = 0;
00443 g2tTrack = g2t_track->GetTable();
00444 LOG_DEBUG << "Size of track Table=" << g2t_track->GetNRows() << endm;
00445 LOG_DEBUG << "Size of SSD Table=" << g2t_ssd_hit->GetNRows() << endm;
00446
00447 if(Debug()){
00448 for(Int_t i =0;i<N;i++)
00449 {
00450 for(Int_t ii=0;ii<3;ii++){
00451 LOG_INFO <<"Id " << positions[i].id <<" drift["<<ii<<"] ="<< positions[i].driftDirection[ii]<< endm;
00452 LOG_INFO <<" Transverse["<<ii<<"] ="<< positions[i].transverseDirection[ii]<< endm;
00453 LOG_INFO <<" Id " << positions[i].id <<" normal["<<ii<<"] ="<< positions[i].normalDirection[ii]<< endm;
00454 LOG_INFO <<" center["<<ii<<"] ="<< positions[i].centerPosition[ii]<< endm;
00455 }
00456 }
00457 }
00458 StThreeVector<double> VecG(0,0,0);
00459 StThreeVector<double> VecL(0,0,0);
00460 StThreeVector<double> mtm(0,0,0);
00461 Double_t myVectG[3] = {0,0,0};
00462 Double_t myVectL[3] = {0,0,0};
00463 Int_t NumOfHits = 0;
00464 Int_t foundGoodHits = 0;
00465 Int_t currWafId = 0;
00466 Int_t currLadder = 0;
00467 Int_t currWafNumb = 0;
00468 Int_t trackId = 0;
00469 Int_t FinalLadder = 0;
00470 Int_t FinalWafer = 0;
00471 Int_t idWafer = 0;
00472 Int_t iWaf = 0;
00473 Float_t Flag_Energy = 1.0;
00474 N = m_positions->GetNRows();
00475 NumOfHits = g2t_ssd_hit->GetNRows();
00476 if (NumOfHits>0){
00477 for (int j=0;j<NumOfHits ;j++)
00478 {
00479 Flag_Energy =1.0;
00480 currWafId = g2t[j].volume_id%10000;
00481 trackId = g2t[j].track_p;
00482 if( currWafId < mSsdLayer*1000) continue;
00483 currLadder = StSsdBarrel::Instance()->idWaferToLadderNumb(currWafId);
00484 currWafNumb = StSsdBarrel::Instance()->idWaferToWafer(currWafId);
00485 LOG_DEBUG <<"geant hit #"<<j<<" volumeID="<< currWafId << " x=" << g2t[j].x[0] << " y=" << g2t[j].x[1] << " z=" << g2t[j].x[2]<<endm;
00486 VecG.setX(g2t[j].x[0]);
00487 VecG.setY(g2t[j].x[1]);
00488 VecG.setZ(g2t[j].x[2]);
00489 mtm.setX(g2t[j].p[0]);
00490 mtm.setY(g2t[j].p[1]);
00491 mtm.setZ(g2t[j].p[2]);
00492 for (Int_t i = 0; i < N; i++)
00493 {
00494 idWafer = positions[i].id;
00495 iWaf = idWaferToWafer(idWafer);
00496 if ((idWafer > mSsdLayer*1000)&&
00497 (idWafer == currWafId)){
00498 if(Debug()){
00499 for(Int_t ii=0;ii<3;ii++){
00500 LOG_INFO <<"Id " << idWafer <<" drift["<<ii<<"] ="<< positions[i].driftDirection[ii]<< endm;
00501 LOG_INFO <<" Transverse["<<ii<<"] ="<< positions[i].transverseDirection[ii]<< endm;
00502 LOG_INFO <<" Id " << idWafer <<" normal["<<ii<<"] ="<< positions[i].normalDirection[ii]<< endm;
00503 LOG_INFO <<" center["<<ii<<"] ="<< positions[i].centerPosition[ii]<< endm;
00504 }
00505 }
00506 LOG_DEBUG << " idWafer =" << idWafer << " TrackId="<<trackId <<" hit id="<<g2t[j].id <<endm;
00507 Int_t iok = ideal2RealTranslation(&VecG,&mtm,(double)g2tTrack[trackId-1].charge,currWafId,i,positions,&FinalLadder,&FinalWafer);
00508 if(iok==kStSkip){
00509 LOG_DEBUG << "Not found correct wafer "<<endm;
00510 Flag_Energy =-1.0;
00511 }
00512
00513 g2t[j].de = Flag_Energy*g2t[j].de;
00514
00515
00516 Int_t finalVolumeId = 7000+(FinalLadder+1)+(FinalWafer+1)*100;
00517 LOG_DEBUG<<Form("New ladder=%d New Wafer=%d New volume id =%d",FinalLadder,FinalWafer,finalVolumeId) << endm;
00518 g2t[j].volume_id = 10000*(g2t[j].volume_id/10000) + (long)finalVolumeId;
00519 StMcTrack *t = 0;
00520 t = new StMcTrack(&(g2tTrack[trackId-1]));
00521
00522 mHit = new StMcSsdHit(&g2t[j]);
00523 LOG_DEBUG<<Form("from mHit:ladder=%d wafer=%d energy =%f x=%f y=%f z=%f",mHit->ladder(),mHit->wafer(),mHit->dE(),mHit->position().x(),mHit->position().y(),mHit->position().z())<<endm;
00524 mHit->setParentTrack(t);
00525
00526 t->addSsdHit(mHit);
00527 mcEvent->ssdHitCollection()->addHit(mHit);
00528 LOG_DEBUG<<Form("check :finalVolumeid =%d fromhit ladder=%d wafer=%d ParentTrack=%ld",finalVolumeId,mHit->ladder(),mHit->wafer(),mHit->parentTrack()->key())<<endm;
00529 if (iok != kStOK) continue;
00530 foundGoodHits++;
00531
00532 myVectG[0] = VecG.x();
00533 myVectG[1] = VecG.y();
00534 myVectG[2] = VecG.z();
00535 StSsdBarrel::Instance()->mLadders[currLadder]->mWafers[currWafNumb]->MasterToLocal(myVectG,myVectL);
00536
00537 VecL.setX(myVectL[0]);
00538 VecL.setY(myVectL[1]);
00539 VecL.setZ(myVectL[2]);
00540
00541 Float_t p[3],tempo[3];
00542 for (Int_t jj = 0; jj<3; jj++) {p[jj] = g2t[j].p[jj];tempo[jj] = myVectG[jj];}
00543 trackId = g2t[j].track_p;
00544 LOG_DEBUG<<Form("Final Ladder=%d FinalWafer=%d geantId=%d xg=%f yg=%f zg=%f energy=%f trackId=%d",FinalLadder,FinalWafer,g2t[j].id,myVectG[0],myVectG[1],myVectG[2],g2t[j].de,trackId)<<endm;
00545 StSsdBarrel::Instance()->mLadders[FinalLadder]->mWafers[FinalWafer]->addHit(g2t[j].id, g2t[j].id, trackId, tempo, g2t[j].de, p);
00546 }
00547 }
00548 }
00549 }
00550 if(mcEvent){
00551 LOG_DEBUG << Form("Size of collection =%ld",mcEvent->ssdHitCollection()->numberOfHits())<<endm;
00552 }
00553 return foundGoodHits;
00554 }
00555
00556
00557 Int_t St_sls_Maker::idWaferToWaferNumb(Int_t idWafer)
00558 {
00559
00560 Int_t iW = (int)((idWafer - mSsdLayer*1000)/100);
00561 Int_t iL = idWafer - mSsdLayer*1000 - iW*100;
00562 return ((iL-1)*mNWaferPerLadder + iW -1);
00563 }
00564
00565 Int_t St_sls_Maker::idWaferToLadderNumb(Int_t idWafer)
00566 {
00567
00568 Int_t iW = (int)((idWafer - mSsdLayer*1000)/100);
00569 Int_t iL = idWafer - mSsdLayer*1000 - iW*100;
00570 return iL-1;
00571 }
00572
00573 Int_t St_sls_Maker::waferNumbToIdWafer(Int_t waferNumb)
00574 {
00575 Int_t iL = 1+(int)((waferNumb)/mNLadder);
00576 Int_t iW = waferNumb-((iL-1)*mNLadder)+1;
00577 return mSsdLayer*1000 + iW*100 + iL;
00578 }
00579
00580 void St_sls_Maker::setSsdParameters(ssdDimensions_st *geom_par){
00581 mDimensions = geom_par;
00582 mSsdLayer = 7;
00583 mDetectorLargeEdge = 2.*geom_par[0].waferHalfActLength;
00584 mDetectorSmallEdge = 2.*geom_par[0].waferHalfActWidth;
00585 mNLadder = 20;
00586 mNWaferPerLadder = geom_par[0].wafersPerLadder;
00587 mNStripPerSide = geom_par[0].stripPerSide;
00588 mStripPitch = geom_par[0].stripPitch;
00589 mTheta = geom_par[0].stereoAngle;
00590 }
00591
00592 void St_sls_Maker::printSsdParameters(){
00593 LOG_INFO << "###Ladders = " <<mNLadder<<"###"<< endm;
00594 LOG_INFO << "###Wafers per Ladder = " <<mNWaferPerLadder<<"###"<< endm;
00595 LOG_INFO << "###half Active LargeEdge = " << mDetectorLargeEdge << "###" << endm;
00596 LOG_INFO << "###half Active SmallEdge = " << mDetectorSmallEdge << "###" << endm;
00597 }
00598
00599 void St_sls_Maker::debugUnPeu() {
00600 Int_t monladder,monwafer;
00601 for(monladder=0;monladder<mNLadder;monladder++)
00602 for(monwafer=0;monwafer<mNWaferPerLadder;monwafer++)
00603 StSsdBarrel::Instance()->debugUnPeu(monladder,monwafer);
00604 }
00605
00606 int St_sls_Maker::IsOnWafer(const StThreeVector<double>& LocalPosition){
00607
00608 if((LocalPosition[0] >(mDetectorLargeEdge/2.)) || (LocalPosition[0] < (-mDetectorLargeEdge/2.)) ||
00609 ( LocalPosition[1]>(mDetectorSmallEdge/2.)) || (LocalPosition[1] < (-mDetectorSmallEdge/2.)))
00610 return 0;
00611 else return 1;
00612
00613
00614
00615
00616
00617
00618 }
00619
00620 Int_t St_sls_Maker::ideal2RealTranslation(StThreeVector<double> *pos, StThreeVector<double> *mtm, double charge, int wafId, int index, ssdWafersPosition_st *positions,Int_t *IL,Int_t *IW){
00621 StThreeVector<double> x(0,0,0);
00622
00623 StThreeVector<double> wafCent(0,0,0);
00624 StThreeVector<double> wafNorm(0,0,0);
00625 wafCent.setX(positions[index].centerPosition[0]);
00626 wafCent.setY(positions[index].centerPosition[1]);
00627 wafCent.setZ(positions[index].centerPosition[2]);
00628 wafNorm.setX(positions[index].normalDirection[0]);
00629 wafNorm.setY(positions[index].normalDirection[1]);
00630 wafNorm.setZ(positions[index].normalDirection[2]);
00631 Int_t Ladder = idWaferToLadderNumb(wafId);
00632 Int_t Wafer = idWaferToWafer(wafId);
00633
00634 StPhysicalHelixD tHelix( *mtm, *pos, mBField, charge);
00635 LOG_DEBUG << "pos going in : "<< *pos << endm;
00636 double s = tHelix.pathLength(wafCent,wafNorm);
00637 x = tHelix.at(s);
00638 LOG_DEBUG << "Helix pathLength="<< s <<" x="<<x.x()<<" y="<<x.y()<<" z="<<x.z()<<endm;
00639 pos->setX(x.x());
00640 pos->setY(x.y());
00641 pos->setZ(x.z());
00642 LOG_DEBUG << "Track projection on Global x =" << pos->x() <<" y =" << pos->y() <<" z =" << pos->z() <<endm;
00643 Double_t xg[3] = {0,0,0};
00644 xg[0] = pos->x();
00645 xg[1] = pos->y();
00646 xg[2] = pos->z();
00647 Double_t xl[3] = {0,0,0};
00648
00649 StSsdBarrel::Instance()->mLadders[Ladder]->mWafers[Wafer]->MasterToLocal(xg,xl);
00650 if (Debug()){
00651 for(Int_t i=0;i<3;i++){
00652 LOG_DEBUG << "xg["<<i<<"] = "<<xg[i] << "--> to local --> xl["<<i<<"] = "<<xl[i] <<endm;}
00653 }
00654 if(IsOnWafer(xl))
00655 {
00656 LOG_DEBUG << " First Pass Coming out " << *pos << endm;
00657 x = tHelix.momentumAt(s,mBField);
00658 mtm->setX(x.x());
00659 mtm->setY(x.y());
00660 mtm->setZ(x.z());
00661 *IL = Ladder;
00662 *IW = Wafer;
00663 return kStOK;
00664 }
00665 LOG_DEBUG <<"not found at the first pass, continue "<<endm;
00666
00667
00668 Int_t iladder,theLadder = 0;
00669 StThreeVector<double> newx(0,0,0);
00670 for( iladder = -1; iladder <= 1; iladder++){
00671 theLadder = Ladder + iladder;
00672 if( theLadder==20) theLadder=0;
00673 else
00674 if( theLadder==-1) theLadder=19;
00675 for( Int_t iwaf = 0; iwaf < mNWaferPerLadder; iwaf++){
00676 LOG_DEBUG << "Wafer ="<< iwaf << " Ladder="<<theLadder << endm;
00677 wafId = 1000*mSsdLayer + 100*(iwaf+1) + (theLadder+1);
00678 Int_t NewLadder = idWaferToLadderNumb(wafId);
00679 Int_t NewWafer = idWaferToWafer(wafId);
00680 index = idWaferToWaferNumb(wafId);
00681 wafCent.setX(positions[index].centerPosition[0]);
00682 wafCent.setY(positions[index].centerPosition[1]);
00683 wafCent.setZ(positions[index].centerPosition[2]);
00684 wafNorm.setX(positions[index].normalDirection[0]);
00685 wafNorm.setY(positions[index].normalDirection[1]);
00686 wafNorm.setZ(positions[index].normalDirection[2]);
00687 double news = tHelix.pathLength(wafCent,wafNorm);
00688 if(TMath::Abs(news)>5) continue;
00689 newx = tHelix.at(news);
00690 pos->setX(newx.x());
00691 pos->setY(newx.y());
00692 pos->setZ(newx.z());
00693 Double_t XG[3]={0,0,0};
00694 XG[0] = newx.x();
00695 XG[1] = newx.y();
00696 XG[2] = newx.z();
00697 Double_t XL[3]={0,0,0};
00698 StSsdBarrel::Instance()->mLadders[NewLadder]->mWafers[NewWafer]->MasterToLocal(XG,XL);
00699 if(IsOnWafer(XL))
00700 {
00701 LOG_DEBUG << " after search, found it Coming out " << *pos << endm;
00702 newx = tHelix.momentumAt(news,mBField);
00703 mtm->setX(newx.x());
00704 mtm->setY(newx.y());
00705 mtm->setZ(newx.z());
00706 *IL = NewLadder;
00707 *IW = NewWafer;
00708 return kStOk;
00709 }
00710 else{LOG_DEBUG <<" Not found wafer for this hit/track projection, will reject the hit"<<endm;}
00711 }
00712 }
00713 return kStSkip;
00714 }
00715
00716 void St_sls_Maker::Clear(Option_t *option)
00717 {
00718 LOG_DEBUG << "Clear()" <<endm;
00719 StMaker::Clear();
00720 }
00721