StPixelFastSimMaker/StPixelFastSimMaker.cxx

00001 /* 00002 * 00003 * Author: A. Rose, LBL, Y. Fisyak, BNL, M. Miller, MIT 00004 * 00005 * 00006 ********************************************************** 00007 * $Log: StPixelFastSimMaker.cxx,v $ 00008 * Revision 1.42 2009/02/06 20:48:48 wleight 00009 * UPGR15 Update 00010 * 00011 * Revision 1.41 2009/01/26 14:50:46 fisyak 00012 * Clean up 00013 * 00014 * Revision 1.40 2007/12/03 20:42:43 wleight 00015 * Replaced couts with LOG_DEBUGs 00016 * 00017 * Revision 1.37 2007/11/13 19:09:51 wleight 00018 * Corrected bug causing pixel fast simulator to crash when there were no pixel and/or ist hits in the event 00019 * 00020 * Revision 1.36 2007/11/06 16:20:06 wleight 00021 * Digitized Pixel, removed all hit smearing, and implemented idTruth 00022 * 00023 * Revision 1.34 2007/10/18 16:31:44 fisyak 00024 * Add pile-up from weixie 00025 * 00026 * Revision 1.33 2007/10/18 14:25:13 didenko 00027 * updates for pile-up events 00028 * 00029 * Revision 1.32 2007/10/16 19:53:08 fisyak 00030 * rename Hft => Pxl, remove Hpd, Igt and Fst 00031 * 00032 * Revision 1.31 2007/10/16 19:50:46 fisyak 00033 * rename Hft => Pxl, remove Hpd, Igt and Fst 00034 * 00035 * Revision 1.30 2007/09/09 17:00:32 fisyak 00036 * Fix bug 1056 00037 * 00038 * Revision 1.29 2007/09/08 00:33:05 andrewar 00039 * Modifications for pileup hit read in. 00040 * 00041 * Revision 1.28 2007/05/17 13:18:52 andrewar 00042 * Removed cout in shiftHit. 00043 * 00044 * Revision 1.27 2007/05/16 15:06:55 andrewar 00045 * Switched cout's to LOG_INFO. 00046 * 00047 * Revision 1.26 2007/04/28 17:56:36 perev 00048 * Redundant StChain.h removed 00049 * 00050 * Revision 1.25 2007/04/27 18:41:29 wleight 00051 * Removed smearing of the coordinate not controlled by the strips in the 17cm layer 00052 * 00053 * Revision 1.24 2007/04/27 14:59:10 wleight 00054 * Corrected another error in the creation of new hits 00055 * 00056 * Revision 1.23 2007/04/26 04:08:41 perev 00057 * Remove StBFChain dependency 00058 * 00059 * Revision 1.22 2007/04/25 17:44:59 wleight 00060 * Corrected error in assignment of reconstructed IST hits 00061 * 00062 * Revision 1.21 2007/04/23 18:11:30 andrewar 00063 * Removed references to Hpd (includes were obsolete) 00064 * 00065 * Revision 1.19 2007/04/23 16:32:47 wleight 00066 * Added explicit casting for double to int in calculating strip number 00067 * 00068 * Revision 1.18 2007/04/22 22:57:23 wleight 00069 * The two hits in the 17 cm layer are no longer combined into 1 00070 * 00071 * Revision 1.17 2007/04/16 19:10:52 wleight 00072 * Added IST simulation (digitization but no clustering) 00073 * 00074 * Revision 1.16 2007/04/13 19:17:15 andrewar 00075 * Removed misleading errors. Changed cout and printf to gMessMgr. 00076 * 00077 * Revision 1.15 2007/04/06 21:46:36 andrewar 00078 * Removed some debug messages. 00079 * 00080 * Revision 1.14 2007/04/06 14:55:11 andrewar 00081 * Shift of HFT hit to face of ladder. 00082 * 00083 * Revision 1.13 2007/03/28 13:33:45 mmiller 00084 * Removed cout/printf's. 00085 * 00086 * Revision 1.12 2006/12/21 18:11:59 wleight 00087 * Fixed UPGR09 compatibility so it works with all versions 00088 * 00089 * Revision 1.11 2006/12/20 16:50:21 wleight 00090 * Added fix for UPGR09 problem with layer number mismatch 00091 * 00092 * Revision 1.10 2006/12/15 02:17:20 wleight 00093 * Ist now gets hit smearing parameters from the database 00094 * 00095 * Revision 1.9 2006/12/14 23:52:51 andrewar 00096 * Added Sevil's hit error db loader. 00097 * 00098 * Revision 1.7 2006/11/29 21:42:07 andrewar 00099 * Update with Pixel resolution smearing. 00100 * 00101 * Revision 1.6 2006/11/28 22:37:42 wleight 00102 * Fixed minor smearing bug 00103 * 00104 * Revision 1.4 2006/10/13 20:15:45 fisyak 00105 * Add Hpd fast simulation (Sevil) 00106 * 00107 * Revision 1.3 2006/02/17 21:44:29 andrewar 00108 * Remover streaming of each Pixel hit. 00109 * 00110 * Revision 1.2 2006/02/08 20:57:33 fisyak 00111 * Set proper Detector Id 00112 * 00113 * Revision 1.1 2006/02/03 20:11:56 fisyak 00114 * The initial revision 00115 * 00116 * 00117 */ 00118 00119 #include "Stiostream.h" 00120 #include "StPixelFastSimMaker.h" 00121 #include "StHit.h" 00122 #include "StEventTypes.h" 00123 #include "StEvent.h" 00124 #include "StRnDHit.h" 00125 #include "StMcEvent.hh" 00126 #include "StMcHit.hh" 00127 #include "StMcIstHit.hh" 00128 00129 #include "StMcPixelHit.hh" 00130 #include "StMcEventTypes.hh" 00131 #ifdef bug1056 00132 #include "Sti/Base/Factory.h" 00133 #include "Sti/StiPlanarShape.h" 00134 #include "Sti/StiCylindricalShape.h" 00135 #include "Sti/StiMaterial.h" 00136 #include "Sti/StiPlacement.h" 00137 #include "Sti/StiDetector.h" 00138 #include "Sti/StiToolkit.h" 00139 #include "Sti/StiDetectorBuilder.h" 00140 #endif 00141 #include <stdio.h> 00142 #include <map> 00143 #include <exception> 00144 using namespace std; 00145 #include <stdexcept> 00146 #include "tables/St_g2t_ist_hit_Table.h" 00147 #include "tables/St_g2t_pix_hit_Table.h" 00148 #include "tables/St_HitError_Table.h" 00149 #ifdef bug1056 00150 #include "Sti/StiHitErrorCalculator.h" 00151 #include "Sti/StiIsActiveFunctor.h" 00152 #include "Sti/StiNeverActiveFunctor.h" 00153 #include "Sti/StiElossCalculator.h" 00154 #include "Sti/StiVMCToolKit.h" 00155 #else 00156 #include "TGeoManager.h" 00157 #include "TGeoMatrix.h" 00158 #endif 00159 #include "StarClassLibrary/StRandom.hh" 00160 #include "tables/St_HitError_Table.h" 00161 #include <fstream> 00162 #include "TFile.h" 00163 #include "TTree.h" 00164 00165 ClassImp(StPixelFastSimMaker) 00166 00167 00168 StPixelFastSimMaker::~StPixelFastSimMaker(){ /*noop*/ } 00169 00170 int StPixelFastSimMaker::Init() 00171 { 00172 LOG_INFO<<"StPixelFastSimMaker::Init()"<<endm; 00173 int seed=time(NULL); 00174 myRandom=new StRandom(); 00175 myRandom->setSeed(seed); 00176 00177 00178 mSmear=1; 00179 return kStOk; 00180 } 00181 00182 //____________________________________________________________ 00183 int StPixelFastSimMaker::InitRun(int RunNo) 00184 { 00185 LOG_INFO<<"StPixelFastSimMaker::InitRun"<<endm; 00186 00187 TDataSet *set = GetDataBase("Calibrations/tracker"); 00188 St_HitError *istTableSet = (St_HitError *)set->Find("ist1HitError"); 00189 St_HitError *pixelTableSet = (St_HitError *)set->Find("PixelHitError"); 00190 //cout<<"found St_HitErrors"<<endl; 00191 HitError_st* istHitError = istTableSet->GetTable(); 00192 resXIst1 = sqrt(istHitError->coeff[0]); 00193 resZIst1 = sqrt(istHitError->coeff[3]); 00194 HitError_st* pixelHitError = pixelTableSet->GetTable(); 00195 resXPix = sqrt(pixelHitError->coeff[0]); 00196 resZPix = sqrt(pixelHitError->coeff[3]); 00197 00198 LoadPixPileUpHits(); //.. load the pile up hits for PIXEL 00199 //cout<<"done with StPixelFastSimMaker::InitRun"<<endl; 00200 00201 return kStOk; 00202 } 00203 00204 //___________________________ 00205 void StPixelFastSimMaker::LoadPixPileUpHits() 00206 { 00207 LOG_INFO<<"+++ loading the PIXEL pileup files +++"<<endm; 00208 00209 pileup_on = true; 00210 00211 TFile f_pileup("pileup.root"); 00212 if (f_pileup.IsZombie()) { 00213 00214 pileup_on = false; 00215 00216 LOG_INFO << "no PIXEL pileup file found. Will run with regular setup" << endm; 00217 return; 00218 } 00219 00220 LOG_INFO<<"+++ Loaded pileup.root for PIXEL pileup simulation +++"<<endm; 00221 00222 TTree* pileup_tree = (TTree*)f_pileup.Get("pileup_tree"); 00223 00224 const int maxhit = 200000; 00225 float x[maxhit], y[maxhit], z[maxhit], px[maxhit], py[maxhit], pz[maxhit], de[maxhit], ds[maxhit]; 00226 long key[maxhit], vid[maxhit]; 00227 int layer[maxhit], nhits; 00228 00229 TBranch *b_x = pileup_tree->GetBranch("x"); 00230 TBranch *b_y = pileup_tree->GetBranch("y"); 00231 TBranch *b_z = pileup_tree->GetBranch("z"); 00232 TBranch *b_px = pileup_tree->GetBranch("px"); 00233 TBranch *b_py = pileup_tree->GetBranch("py"); 00234 TBranch *b_pz = pileup_tree->GetBranch("pz"); 00235 TBranch *b_de = pileup_tree->GetBranch("de"); 00236 TBranch *b_ds = pileup_tree->GetBranch("ds"); 00237 TBranch *b_key = pileup_tree->GetBranch("key"); 00238 TBranch *b_vid = pileup_tree->GetBranch("vid"); 00239 TBranch *b_layer = pileup_tree->GetBranch("layer"); 00240 TBranch *b_nhits = pileup_tree->GetBranch("nhits"); 00241 b_x->SetAddress(x); 00242 b_y->SetAddress(y); 00243 b_z->SetAddress(z); 00244 b_px->SetAddress(px); 00245 b_py->SetAddress(py); 00246 b_pz->SetAddress(pz); 00247 b_de->SetAddress(de); 00248 b_ds->SetAddress(de); 00249 b_key->SetAddress(key); 00250 b_vid->SetAddress(vid); 00251 b_layer->SetAddress(layer); 00252 b_nhits->SetAddress(&nhits); 00253 00254 pileup_tree->GetEntry(0); //.. just one events 00255 00256 for(int ihit = 0; ihit<nhits; ihit++) { 00257 pileup_x.push_back(x[ihit]); 00258 pileup_y.push_back(y[ihit]); 00259 pileup_z.push_back(z[ihit]); 00260 00261 pileup_px.push_back(px[ihit]); 00262 pileup_py.push_back(py[ihit]); 00263 pileup_pz.push_back(pz[ihit]); 00264 00265 pileup_key.push_back(key[ihit]); 00266 pileup_vid.push_back(vid[ihit]); 00267 00268 pileup_de.push_back(de[ihit]); 00269 pileup_ds.push_back(ds[ihit]); 00270 } 00271 } 00272 //____________________________________________________________ 00273 void StPixelFastSimMaker::AddPixPileUpHit(StMcPixelHitCollection* pixHitCol) 00274 { 00275 for(unsigned int i = 0; i<pileup_x.size(); i++) { 00276 00277 StThreeVectorD pos(pileup_x[i], pileup_y[i], pileup_z[i]); 00278 StThreeVectorF mom(pileup_px[i], pileup_py[i], pileup_pz[i]); 00279 00280 float de = pileup_de[i]; 00281 float ds = pileup_ds[i]; 00282 00283 int key = pileup_key[i]; 00284 int vid = pileup_vid[i]; 00285 00286 StMcPixelHit* pixhit = new StMcPixelHit(pos, mom, de, ds, key, vid, 0); 00287 pixHitCol->addHit(pixhit); 00288 } 00289 } 00290 //____________________________________________________________ 00291 00292 Int_t StPixelFastSimMaker::Make() 00293 { 00294 LOG_INFO<<"StPixelFastSimMaker::Make()"<<endm; 00295 00296 // Get the input data structures from StEvent and StMcEvent 00297 StEvent* rcEvent = (StEvent*) GetInputDS("StEvent"); 00298 if (! rcEvent) {LOG_INFO << "No StEvent on input" << endl; return kStWarn;} 00299 StMcEvent* mcEvent = (StMcEvent *) GetInputDS("StMcEvent"); 00300 if (! mcEvent) {LOG_INFO << "No StMcEvent on input" << endl; return kStWarn;} 00301 TDataSetIter geant(GetInputDS("geant")); 00302 if (! gGeoManager) GetDataBase("VmcGeometry"); 00303 g2t_ist_hit_st* g2tIst=0; 00304 g2t_pix_hit_st* g2tPix=0; 00305 St_g2t_ist_hit *g2t_ist_hit=(St_g2t_ist_hit *)geant("g2t_ist_hit"); 00306 St_g2t_pix_hit *g2t_pix_hit=(St_g2t_pix_hit *)geant("g2t_pix_hit"); 00307 if(g2t_ist_hit) g2tIst=g2t_ist_hit->GetTable(); 00308 if(g2t_pix_hit) g2tPix=g2t_pix_hit->GetTable(); 00309 00310 // Store hits into RnD Hit Collection until we have our own 00311 StRnDHitCollection *col = new StRnDHitCollection; 00312 if (!col ) 00313 { 00314 gMessMgr->Info()<<"StPixelFastSimMaker -E- no RnDHitCollection!\n"; 00315 abort(); 00316 } 00317 00318 // Don't use realistic hit errors for now. When we transit to smeared 00319 // hits, this would be a good place to store offset info 00320 StThreeVectorF mHitError(0.,0.,0.); 00321 00322 //Get MC Pixel hit collection. This contains all pixel hits. 00323 StMcPixelHitCollection* pixHitCol = mcEvent->pixelHitCollection(); 00324 int nPixelPerWaferX=640; 00325 int nPixelPerWaferZ=640; 00326 int nWaferPerLadder=10; 00327 double pixelWidth=.003; 00328 float pixWaferHalf=.96; 00329 unsigned int nPixLadders[2]={9,24}; 00330 //int pixels[6400][640]; 00331 vector<int> pixels; 00332 vector<StMcPixelHit*> pixLadderHits; 00333 multimap<int,int> pixelToKey; 00334 int vid; 00335 float smearedX,smearedZ; 00336 00337 if (pixHitCol){ 00338 int layer,ladder; 00339 int counter_layer1 = 0; 00340 int counter_layer2 = 0; 00341 int counter = 0; 00342 float rad = 0; 00343 if(pileup_on) AddPixPileUpHit(pixHitCol); //.. add the pileup hits into the collection 00344 00345 Int_t nhits = pixHitCol->numberOfHits(); 00346 LOG_DEBUG<<"There are "<<nhits<<" pixel hits"<<endm; 00347 if (nhits){ 00348 Int_t id = col->numberOfHits(); 00349 if(g2tPix){ 00350 for(int jj=0;jj<g2t_pix_hit->GetTableSize();jj++) 00351 { 00352 rad = TMath::Sqrt(g2tPix[jj].x[0]*g2tPix[jj].x[0] + g2tPix[jj].x[1]*g2tPix[jj].x[1]); 00353 if((rad>2.2) && (rad<2.7)) { 00354 counter_layer1++; 00355 LOG_DEBUG <<"radius="<<rad<<" id="<<g2tPix[jj].id <<" x="<<g2tPix[jj].x[0]<<" y="<<g2tPix[jj].x[1]<<" z="<<g2tPix[jj].x[2]<<" truth is "<<g2tPix[jj].track_p<<" dE= "<<g2tPix[jj].de <<" counter layer 1 =" << counter_layer1 << endm; 00356 } 00357 else if((rad>7.9) && (rad<8.2)) { 00358 counter_layer2++; 00359 LOG_DEBUG <<"radius="<<rad<<" id="<<g2tPix[jj].id <<" x="<<g2tPix[jj].x[0]<<" y="<<g2tPix[jj].x[1]<<" z="<<g2tPix[jj].x[2]<<" truth is "<<g2tPix[jj].track_p<<" dE= "<<g2tPix[jj].de <<" counter layer 2 =" << counter_layer2 <<endm; 00360 } 00361 } 00362 } 00363 LOG_DEBUG << " there is " << counter_layer1 << " hits in the first layer " << endm; 00364 LOG_DEBUG << " there is " << counter_layer2 << " hits in the second layer " << endm; 00365 //for(int k=0;k<g2t_pix_hit->GetNRows();k++){ 00366 for (UInt_t k=0; k<pixHitCol->numberOfLayers(); k++){ 00367 if (pixHitCol->layer(k)){ 00368 LOG_DEBUG<<"Layer "<<k+1<<endm; 00369 //simple simulator for perfect hits that just converts StMcPixelHit to StRnDHit 00370 //as of 11/21/08, hits are now smeared with resolution taken from hit error table 00371 UInt_t nh = pixHitCol->layer(k)->hits().size(); 00372 LOG_DEBUG << " Number of hits in layer "<< k+1 <<" =" << nh << endm; 00373 for (UInt_t i = 0; i < nh; i++){ 00374 counter++; 00375 int vid=g2tPix[k].volume_id; 00376 int layer=vid/1000000; 00377 int ladder=(vid%1000000)/10000; 00378 StMcHit *mcH = pixHitCol->layer(k)->hits()[i]; 00379 StMcPixelHit* mcPix=dynamic_cast<StMcPixelHit*>(mcH); 00380 TString Path(""); 00381 if(k==0) Path= Form("/HALL_1/CAVE_1/PXMO_1/PXLA_1/PLMI_%i/PLAC_1",mcPix->ladder()); 00382 else Path=Form("/HALL_1/CAVE_1/PXMO_1/PXL1_2/PLM1_%i/PLA1_1",mcPix->ladder()); 00383 //LOG_DEBUG<<"mc pixel hit location x: "<<g2tPix[k].x[0]<<"; y: "<<g2tPix[k].x[1]<<"; z: "<<g2tPix[k].x[2]<<endm; 00384 LOG_DEBUG<<"pixel hit layer/ladder is "<<layer<<"/"<<ladder<<" and volume id "<<vid<<endm; 00385 gGeoManager->RestoreMasterVolume(); 00386 gGeoManager->CdTop(); 00387 gGeoManager->cd(Path); 00388 //double globalPixHitPos[3]={g2tPix[k].x[0],g2tPix[k].x[1],g2tPix[k].x[2]}; 00389 double globalPixHitPos[3]={mcPix->position().x(),mcPix->position().y(),mcPix->position().z()}; 00390 double localPixHitPos[3]={0,0,0}; 00391 gGeoManager->GetCurrentMatrix()->MasterToLocal(globalPixHitPos,localPixHitPos); 00392 smearedX=distortHit(localPixHitPos[0],resXPix,100); 00393 smearedZ=distortHit(localPixHitPos[2],resZPix,100); 00394 localPixHitPos[0]=smearedX; 00395 localPixHitPos[2]=smearedZ; 00396 double smearedGlobalPixHitPos[3]={0,0,0}; 00397 gGeoManager->GetCurrentMatrix()->LocalToMaster(localPixHitPos,smearedGlobalPixHitPos); 00398 StThreeVectorF gpixpos(smearedGlobalPixHitPos); 00399 StThreeVectorD mRndHitError(0.,0.,0.); 00400 //StRnDHit* tempHit = new StRnDHit(mcPix->position(), mRndHitError, 1, 1., 0, 1, 1, id++, kPxlId); 00401 StRnDHit* tempHit = new StRnDHit(gpixpos, mRndHitError, 1, 1., 0, 1, 1, id++, kPxlId); 00402 tempHit->setVolumeId(mcPix->volumeId()); 00403 tempHit->setLayer(k+1); 00404 tempHit->setLadder(mcPix->ladder()); 00405 tempHit->setKey(mcPix->key()); 00406 Int_t truth =0; 00407 if((k==0)&&(counter<=counter_layer1)) { 00408 truth = g2tPix[mcPix->key()-1].track_p; 00409 } 00410 else if((k==1)&&(counter<=(counter_layer2+pixHitCol->layer(0)->hits().size()))) 00411 { 00412 truth = g2tPix[mcPix->key()-1].track_p; 00413 } 00414 tempHit->setIdTruth(truth,100); 00415 LOG_DEBUG<<"key() : "<< mcPix->key()-1 << " idTruth: "<< truth <<endm; 00416 //LOG_DEBUG <<"from g2t : x= " << g2tPix[k].x[0] <<" y= " << g2tPix[k].x[1] <<" z= " << g2tPix[k].x[2] << endm; 00417 LOG_DEBUG<<"pixel rnd hit location x: "<<tempHit->position().x()<<"; y: "<<tempHit->position().y()<<"; z: "<<tempHit->position().z()<<endm; 00418 //LOG_DEBUG<<"pixel rnd hit location x: "<<tempHit->position().x()<<"; y: "<<tempHit->position().y()<<"; z: "<<tempHit->position().z()<<endm; 00419 col->addHit(tempHit); 00420 } 00421 } 00422 } 00423 } 00424 gMessMgr->Info() <<"StPixelFastSimMaker::Make() -I- Loaded "<<nhits<<"pixel hits. \n"; 00425 } 00426 else{ 00427 gMessMgr->Info() <<"No pixel hits found.\n"; 00428 } 00429 00430 00431 const StMcIstHitCollection* istHitCol = mcEvent->istHitCollection(); 00432 00433 //new simulator for new 1-layer design 00434 int nLadders=24; 00435 int nWafers=12; 00436 unsigned int ladderCount; 00437 unsigned int waferCount; 00438 double pos[3]; 00439 double localpos[3]; 00440 double gpos[3]; 00441 int id=0; 00442 //float smearedX,smearedZ; 00443 TString Path(""); 00444 if(istHitCol){ 00445 LOG_INFO<<"ist hit collection found"<<endm; 00446 int nIsthits=istHitCol->numberOfHits(); 00447 LOG_DEBUG<<"there are "<<nIsthits<<" ist hits"<<endm; 00448 vector<StMcIstHit*> ladderHits; 00449 if(nIsthits){ 00450 if(istHitCol->layer(0)){ 00451 //simple simulator for perfect hits that merely converts from StMcIstHit to StRnDHit 00452 //as of 11/21/08, the simulator now smears hits by hit resolutions taken from hit error tables 00453 for(unsigned int kk=0;kk<istHitCol->layer(0)->hits().size();kk++){ 00454 StMcHit* mcH=istHitCol->layer(0)->hits()[kk]; 00455 StMcIstHit* mcI=dynamic_cast<StMcIstHit*>(mcH); 00456 LOG_DEBUG<<"mc ist hit location x: "<<mcI->position().x()<<"; y: "<<mcI->position().y()<<"; z: "<<mcI->position().z()<<endm; 00457 TString Path(""); 00458 Path=Form("/HALL_1/CAVE_1/IBMO_1/IBMY_1/IBAM_%i/IBLM_%i/IBSS_1",mcI->ladder(),mcI->wafer()); 00459 gGeoManager->RestoreMasterVolume(); 00460 gGeoManager->CdTop(); 00461 gGeoManager->cd(Path); 00462 double globalIstHitPos[3]={mcI->position().x(),mcI->position().y(),mcI->position().z()}; 00463 double localIstHitPos[3]={0,0,0}; 00464 gGeoManager->GetCurrentMatrix()->MasterToLocal(globalIstHitPos,localIstHitPos); 00465 smearedX=distortHit(localIstHitPos[0],resXIst1,100); 00466 smearedZ=distortHit(localIstHitPos[2],resZIst1,100); 00467 localIstHitPos[0]=smearedX; 00468 localIstHitPos[2]=smearedZ; 00469 double smearedGlobalIstHitPos[3]={0,0,0}; 00470 gGeoManager->GetCurrentMatrix()->LocalToMaster(localIstHitPos,smearedGlobalIstHitPos); 00471 StThreeVectorF gistpos(smearedGlobalIstHitPos); 00472 StRnDHit* tempHit = new StRnDHit(gistpos, mHitError, 1, 1., 0, 1, 1, id++, kIstId); 00473 tempHit->setDetectorId(kIstId); 00474 tempHit->setVolumeId(mcI->volumeId()); 00475 tempHit->setKey(mcI->key()); 00476 tempHit->setLayer(1); 00477 tempHit->setLadder(mcI->ladder()); 00478 tempHit->setWafer(mcI->wafer()); 00479 tempHit->setIdTruth(g2tIst[kk].track_p,100); 00480 LOG_DEBUG<<"ist hit volume id: "<<tempHit->volumeId()<<endm; 00481 LOG_DEBUG<<"ist hit ladder/wafer: "<<tempHit->ladder()<<"/"<<tempHit->wafer()<<endm; 00482 col->addHit(tempHit); 00483 LOG_DEBUG<<"ist rnd hit location x: "<<tempHit->position().x()<<"; y: "<<tempHit->position().y()<<"; z: "<<tempHit->position().z()<<" idTruth = " << g2tIst[kk].track_p << endm; 00484 } 00485 } 00486 } 00487 } 00488 else{ 00489 LOG_INFO <<"No Ist hits found."<<endm; 00490 } 00491 00492 00493 const StMcFgtHitCollection* fgtHitCol = mcEvent->fgtHitCollection(); 00494 if (fgtHitCol) 00495 { 00496 Int_t nhits = fgtHitCol->numberOfHits(); 00497 if (nhits) 00498 { 00499 Int_t id = 0; 00500 //StSPtrVecHit *cont = new StSPtrVecHit(); 00501 //rcEvent->addHitCollection(cont, # Name ); 00502 for (UInt_t k=0; k<fgtHitCol->numberOfLayers(); k++){ 00503 if (fgtHitCol->layer(k)) 00504 { 00505 UInt_t nh = fgtHitCol->layer(k)->hits().size(); 00506 for (UInt_t i = 0; i < nh; i++) { 00507 StMcHit *mcH = fgtHitCol->layer(k)->hits()[i]; 00508 StRnDHit* tempHit = new StRnDHit(mcH->position(), mHitError, 1, 1., 0, 1, 1, id++); 00509 tempHit->setVolumeId(mcH->volumeId()); 00510 tempHit->setKey(mcH->key()); 00511 00512 StMcIstHit *mcI = dynamic_cast<StMcIstHit*>(mcH); 00513 if(mcI){ 00514 tempHit->setLayer(mcI->layer()); 00515 tempHit->setLadder(mcI->ladder()); 00516 tempHit->setWafer(mcI->wafer()); 00517 //tempHit->setExtraByte0(mcI->side()); 00518 } 00519 col->addHit(tempHit); 00520 } 00521 } 00522 } 00523 } 00524 } 00525 00526 rcEvent->setRnDHitCollection(col); 00527 return kStOK; 00528 } 00529 //________________________________________________________________________________ 00530 Bool_t StPixelFastSimMaker::accept(StEvent* event){ 00531 return event ? true : false; 00532 } 00533 //________________________________________________________________________________ 00534 Bool_t StPixelFastSimMaker::accept(StMcEvent* event){ 00535 return event ? true : false; 00536 } 00537 00538 double StPixelFastSimMaker::distortHit(double x, double res, double detLength){ 00539 double test; 00540 if(mSmear){ 00541 test = x + myRandom->gauss(0,res); 00542 while( fabs(test) > detLength){ 00543 test = x + myRandom->gauss(0,res); 00544 } 00545 //cout << " x was " <<x<< " and is now " << test<< endl; 00546 return test; 00547 } 00548 else return x; 00549 } 00550 //____________________________________________________________ 00551 00552 00553 //____________________________________________________________ 00554 void StPixelFastSimMaker::smearGaus(StThreeVectorD &mError, 00555 double sigma1, double sigma2) 00556 { 00557 00558 // smear hit in transverse plane, 00559 // sigma's are in microns 00560 double u1=-1; 00561 double u2=-1.; 00562 double v1=-1.; 00563 double v2=-1.;; 00564 double r = 2.; 00565 double z1 = 10.; 00566 double z2 = 10.; 00567 while(fabs(z1)>2. || fabs(z2)>2.) // sigma 00568 { 00569 r = 2.; 00570 while(r>1.) 00571 { 00572 u1 = rand()/double(RAND_MAX); 00573 u2 = rand()/double(RAND_MAX); 00574 v1 = 2*u1 - 1.; 00575 v2 = 2*u2 - 1.; 00576 r = pow(v1,2) + pow(v2,2); 00577 } 00578 z1 = v1*sqrt(-2.*log(r)/r); z2 = v2*sqrt(-2.*log(r)/r); 00579 } 00580 00581 //set to be cumulative with other transforms 00582 mError.setX(mError.x()+z1*sigma1/1.e04); 00583 mError.setY(mError.y()+z1*sigma1/1.e04); 00584 mError.setZ(mError.z()+z2*sigma2/1.e04); 00585 } 00586 00587 int StPixelFastSimMaker::sector(int layer, int ladder) 00588 { 00589 00590 if (layer ==1) 00591 { 00592 if ( ladder < 4 ) return 1; 00593 if ( ladder < 7 ) return 2; 00594 return 3; 00595 } 00596 else 00597 { 00598 if ( ladder < 9 ) return 1; 00599 if ( ladder < 17 ) return 2; 00600 return 3; 00601 } 00602 00603 00604 } 00605 00606 int StPixelFastSimMaker::secLadder(int layer, int ladder) 00607 { 00608 if (layer==1) 00609 return ladder - 3*(sector(layer,ladder)-1); 00610 else 00611 return ladder - 8*(sector(layer,ladder)-1)+3; 00612 } 00613 00614 00615 00616 double StPixelFastSimMaker::phiForLadder(int layer, int ladder) 00617 { 00618 int sec = sector(layer,ladder); 00619 int secLad = secLadder(layer,ladder); 00620 //double phi=0.; 00621 double secPhi=0.; 00622 double ladPhi=0.; 00623 switch (sec) 00624 { 00625 case 1: 00626 secPhi=0.; 00627 break; 00628 case 2: 00629 secPhi=120.; 00630 break; 00631 case 3: 00632 secPhi=240.; 00633 break; 00634 } 00635 00636 switch (secLad) 00637 { 00638 case 1: 00639 ladPhi=100.; 00640 break; 00641 case 2: 00642 ladPhi=60.; 00643 break; 00644 case 3: 00645 ladPhi=20.; 00646 break; 00647 case 4: 00648 ladPhi=105.; 00649 break; 00650 case 5: 00651 ladPhi=90.; 00652 break; 00653 case 6: 00654 ladPhi=75.; 00655 break; 00656 case 7: 00657 ladPhi=60.; 00658 break; 00659 case 8: 00660 ladPhi=45.; 00661 break; 00662 case 9: 00663 ladPhi=30.; 00664 break; 00665 case 10: 00666 ladPhi=15.; 00667 break; 00668 case 11: 00669 ladPhi=0.; 00670 break; 00671 } 00672 00673 return secPhi+ladPhi; 00674 } 00675 00676 00677 void StPixelFastSimMaker::shiftHit(StThreeVectorF &position,StThreeVectorF &mom, int layer, int ladder) 00678 { 00679 00680 //printf("Entering hit shift code. %i %i\n", 00681 // sector(layer,ladder), secLadder(layer,ladder)); 00682 LOG_DEBUG<<"Pixel Hit in layer "<<layer<<" and ladder "<<ladder<<" or sector "<<sector(layer,ladder)<<" and sector ladder "<<secLadder(layer,ladder)<<endm; 00683 00684 TString Path(""); 00685 Path = Form("/HALL_1/CAVE_1/PXMO_1/PSEC_%i/PLMO_%i/PLAC_1", 00686 sector(layer,ladder),secLadder(layer,ladder)); 00687 gGeoManager->RestoreMasterVolume(); 00688 //printf("Master volume.\n"); 00689 00690 gGeoManager->CdTop(); 00691 gGeoManager->cd(Path); 00692 TGeoPhysicalNode* node= (TGeoPhysicalNode*)(gGeoManager->GetCurrentNode()); 00693 if (!node ) LOG_ERROR<< "Failed to get node for sector(layer,ladder), secLadder(layer, ladder)"<<endm; 00694 00695 double pos[3]={position.x(),position.y(),position.z()}; 00696 double localpos[3]={0,0,0}; 00697 gGeoManager->GetCurrentMatrix()->MasterToLocal(pos,localpos); 00698 //printf("old hit: %g %g %g\n",localpos[0],localpos[1],localpos[2]); 00699 00700 //get ladder phi 00701 //TGeoHMatrix *hmat = (TGeoHMatrix*)(node->GetMatrix()); 00702 TGeoHMatrix *hmat = gGeoManager->GetCurrentMatrix(); 00703 00704 if (! hmat ) 00705 { 00706 LOG_ERROR<< "Can't shift hit - no hmat."<<endm; 00707 } 00708 00709 Double_t *rot = hmat->GetRotationMatrix(); 00710 if (! rot ) 00711 { 00712 LOG_ERROR <<"Can't shift hit - no rotation matrix."<<endm; 00713 } 00714 00715 StThreeVectorD normalVector(rot[1],rot[4],rot[7]); 00716 //double momentum = mom.magnitude(); 00717 StThreeVectorF momUnit(mom); 00718 momUnit/=momUnit.magnitude(); 00719 00720 //momentum mag, pt and z stay the same; angle changes 00721 momUnit.setPhi( momUnit.phi() - phiForLadder(layer,ladder)*3.141592654/180.); 00722 //printf("Mom dir: %g\n",momUnit.phi()); 00723 00724 // shift = x + y * tan(phi) 00725 //.006 is the half thickness of the active area. Hardcoded; not good; blah, blah. 00726 double dx = (.006)*(momUnit.y()/momUnit.x()); 00727 double dz = (.006)*(momUnit.y()/momUnit.z()); 00728 localpos[0] = localpos[0] - dx; 00729 localpos[2] = localpos[2] - dz; 00730 localpos[1] = localpos[1] - .006; //this isn't exactly right. The local position is just off of radius -.006, but it's close (~1-5 um). 00731 00732 gGeoManager->GetCurrentMatrix()->LocalToMaster(localpos,pos); 00733 00734 //printf("exit shift code.\n"); 00735 00736 }

Generated on Tue Mar 17 04:55:46 2009 for StRoot by doxygen 1.3.7