00001
00002
00003 #include "StuDraw3DEvent.h"
00004 #include "TSystem.h"
00005 #include "TVirtualPad.h"
00006 #include "TColor.h"
00007 #include "StEventHelper.h"
00008 #include "StEvent.h"
00009 #include "StTrack.h"
00010 #include "StHit.h"
00011 #include "StTpcHit.h"
00012 #include "StFtpcHit.h"
00013 #include "StEmcRawHit.h"
00014 #include "StTrackNode.h"
00015 #include "StTrackGeometry.h"
00016 #include "StTpcHitCollection.h"
00017 #include "StEmcCollection.h"
00018 #include "StFtpcHitCollection.h"
00019 #include "StFtpcSectorHitCollection.h"
00020 #include "StFtpcPlaneHitCollection.h"
00021 #include "StEmcDetector.h"
00022 #include "StEmcModule.h"
00023 #include "StMeasuredPoint.h"
00024 #include "TMath.h"
00025 #include "StTrackDetectorInfo.h"
00026 #include "StEmcUtil/geometry/StEmcGeom.h"
00027 #include "StEventHitIter.h"
00028 #include "StMessMgr.h"
00029
00030
00031
00033
00060 ClassImp(StuDraw3DEvent)
00061
00062 StuDraw3DEvent::StuDraw3DEvent( const char *detectorName,TVirtualPad *pad):StDraw3D(detectorName,pad)
00063 {
00064
00065
00066
00067 if (!gEventDisplay) gEventDisplay = this;
00068 }
00069
00070
00072
00075
00076 StuDraw3DEvent::~StuDraw3DEvent()
00077 {
00078 if (gEventDisplay == this) gEventDisplay = 0;
00079 }
00080
00082
00090
00091 TObject *StuDraw3DEvent::EmcHit(Int_t emcHitsSoftId, Color_t col,Style_t sty,Size_t siz, const char *detId)
00092 {
00093 TObject *model = 0;
00094 StEmcGeom *emcGeom =StEmcGeom::getEmcGeom(detId);
00095 if (emcGeom) {
00096 Int_t softId=emcHitsSoftId;
00097 Float_t eta;
00098 Float_t phi;
00099 emcGeom->getEtaPhi(softId,eta,phi);
00100 Float_t etaStep = 1.0/emcGeom->NEta();
00101 Float_t phiStep = TMath::Pi()/60;
00102 static int entries = 0;
00103
00104
00105 entries++;
00106 model = Tower(emcGeom->Radius(), StarRoot::StEta(eta,etaStep)
00107 , phi, phiStep
00108 , col,sty+(strcmp(detId,"bemc")?0:kBarrelStyle),siz);
00109 } else {
00110 LOG_ERROR << __FILE__ << ": there is no geometry information for \"" << detId << "\"" << endm;
00111 }
00112 return model;
00113 }
00114
00116
00124
00125 TObject *StuDraw3DEvent::EmcHit(const StEmcRawHit &emcHit, Color_t col,Style_t sty,Size_t siz, const char *detId)
00126 {
00127 TObject *model = 0;
00128 if (!detId || !detId[0]) detId = "bemc";
00129 StEmcGeom *emcGeom =StEmcGeom::getEmcGeom(detId);
00130 if (emcGeom) {
00131 int m, e, s;
00132 Int_t softId;
00133 emcHit.modEtaSub(m,e,s);
00134 emcGeom->getId(m,e,s,softId);
00135 EmcHit(softId, col,sty,siz,detId);
00136 SetModel((TObject*)&emcHit);
00137 } else {
00138 LOG_ERROR << __FILE__ << ": there is no geometry information for \"" << detId << "\"" << endm;
00139 }
00140 return model;
00141 }
00142
00143
00145
00152
00153 void StuDraw3DEvent::EmcHits(const StEvent* event,const char *detId)
00154 {
00155 Color_t colorResponce = 0;
00156 if (!detId || !detId[0]) detId = "bemc";
00157 StEmcCollection* emcC =(StEmcCollection*)event->emcCollection();
00158 if (emcC) {
00159 StEmcDetector* det = emcC->detector( strcmp(detId,"bemc") ? kEndcapEmcTowerId : kBarrelEmcTowerId);
00160 for(unsigned int md=1; md <=det->numberOfModules(); md++) {
00161 StEmcModule* module=det->module(md);
00162 StSPtrVecEmcRawHit& hit= module->hits();
00163
00164 for(unsigned int ih=0;ih < hit.size();ih++){
00165 StEmcRawHit *h=hit[ih];
00166 double rawAdc=h->adc()-5;
00167 float energy = h->energy();
00168 Style_t style=0;
00169
00170
00171 if ( rawAdc>0 && energy > 0 && energy < 30) {
00172
00173 if ( energy < 0.3) {
00174 colorResponce = kBlue;
00175
00176
00177 } else if ( energy < 1.0 ) colorResponce = kGreen;
00178
00179 else if ( energy < 4.0 ) colorResponce = kYellow;
00180
00181 else colorResponce = kRed;
00182 if (energy > 1.0) {
00183
00184 }
00185 static const double maxSize = 400.;
00186 static const double scale = 200.;
00187 double size =(energy > 0.3 ? scale : scale/30.)*energy;
00188 if (size > maxSize) size = maxSize ;
00189 EmcHit(*h,colorResponce,style, size,detId);
00190 }
00191 }
00192 }
00193 }
00194 }
00195
00196
00198
00206
00207 TObject *StuDraw3DEvent::Track(const StTrack &track, Color_t col,Style_t sty,Size_t siz)
00208 {
00209 StTrackHelper trPnt(&track);
00210 Int_t size;
00211 Float_t *xyz = trPnt.GetPoints(size);
00212 TObject *l = Line(size,xyz,col,sty,siz);
00213 SetModel((TObject*)&track);
00214 return l;
00215 }
00216
00218
00220
00221 TObject *StuDraw3DEvent::Track(const StTrack &track, EDraw3DStyle sty)
00222 {
00223 const StDraw3DStyle &style = Style(sty);
00224 return Track(track, style.Col(),style.Sty(),style.Siz() );
00225 }
00226
00227
00229
00237
00238 TObject *StuDraw3DEvent::Hit(const StMeasuredPoint &hit
00239 , Color_t col, Style_t sty, Size_t siz)
00240 {
00241
00242 const StThreeVectorF& position = hit.position();
00243 TObject *p = Point(position.x(),position.y(),position.z(),col,sty,siz);
00244 SetModel((TObject*)&hit);
00245 return p;
00246 }
00247
00248
00250
00252
00253 TObject *StuDraw3DEvent::Hit(const StMeasuredPoint &hit, EDraw3DStyle sty)
00254 {
00255 const StDraw3DStyle &style = Style(sty);
00256 return Hit(hit, style.Col(),style.Sty(),style.Siz() );
00257 }
00258
00259
00261
00269
00270 TObject *StuDraw3DEvent::Vertex(const StMeasuredPoint &vertex
00271 , Color_t col, Style_t sty, Size_t siz)
00272 {
00273 return Hit(vertex,col,sty,siz);
00274 }
00275
00276
00278
00284
00285 TObject *StuDraw3DEvent::Vertex(const StMeasuredPoint &vtx, EDraw3DStyle sty)
00286 {
00287 const StDraw3DStyle &style = Style(sty);
00288 return Vertex(vtx, style.Col(),style.Sty(),style.Siz() );
00289 }
00290
00291
00293
00298
00299 void StuDraw3DEvent::Hits(const StTrack &track)
00300 {
00301
00302
00303 if (track.flag() > 0 && track.detectorInfo()&& !track.bad() ) {
00304 Style_t sty = Style(kUsedHit).Sty();
00305 Size_t siz = Style(kUsedHit).Siz();
00306 double pt = track.geometry()->momentum().perp();
00307 Hits(track, StDraw3DStyle::Pt2Color(pt),sty,siz);
00308 }
00309 }
00310
00311
00313
00320
00321 void StuDraw3DEvent::Hits(const StTrack &track
00322 , Color_t col
00323 , Style_t sty
00324 , Size_t siz )
00325 {
00326
00327
00328 std::vector<float> hitPoints;
00329 const StPtrVecHit& trackHits = track.detectorInfo()->hits(kTpcId);
00330 unsigned int m=0;
00331 StHit *hit = 0;
00332 for (m=0; m<trackHits.size(); m++) {
00333 hit = trackHits[m];
00334 hitPoints.push_back( hit->position().x());
00335 hitPoints.push_back( hit->position().y());
00336 hitPoints.push_back( hit->position().z());
00337 }
00338 {
00339 std::vector<float>::iterator xyz = hitPoints.begin();
00340 Points(hitPoints.size()/3,&*xyz,col,sty,siz);
00341 }
00342
00343
00344 const StPtrVecHit& trackWestHits = track.detectorInfo()->hits(kFtpcWestId);
00345
00346 hitPoints.clear();
00347 for (m=0; m<trackWestHits.size(); m++) {
00348 hit = trackWestHits[m];
00349 hitPoints.push_back( hit->position().x());
00350 hitPoints.push_back( hit->position().y());
00351 hitPoints.push_back( hit->position().z());
00352 }
00353 {
00354 std::vector<float>::iterator xyz = hitPoints.begin();
00355 Points(hitPoints.size()/3,&*xyz,col,sty,siz);
00356 }
00357
00358
00359 hitPoints.clear();
00360 const StPtrVecHit& trackEastHits = track.detectorInfo()->hits(kFtpcEastId);
00361 for (m=0; m<trackEastHits.size(); m++) {
00362 hit = trackEastHits[m];
00363 hitPoints.push_back( hit->position().x());
00364 hitPoints.push_back( hit->position().y());
00365 hitPoints.push_back( hit->position().z());
00366 }
00367 {
00368 std::vector<float>::iterator xyz = hitPoints.begin();
00369 Points(hitPoints.size()/3,&*xyz,col,sty,siz);
00370 }
00371
00372 }
00373
00374
00376
00378
00379 void StuDraw3DEvent::Hits(const StTrack &track, EDraw3DStyle sty)
00380 {
00381
00382
00383 const StDraw3DStyle &style = Style(sty);
00384 Hits(track, style.Col(),style.Sty(),style.Siz());
00385 }
00386
00387
00389
00398
00399 TObject *StuDraw3DEvent::TrackInOut(const StTrack &track, Bool_t in
00400 , Color_t col, Style_t sty, Size_t siz)
00401 {
00402 StInnOutPoints trInOut(&track,in);
00403 return Points(trInOut.Size(),trInOut.GetXYZ(0),col,sty,siz);
00404 }
00405
00406
00408
00415
00416 TObject *StuDraw3DEvent::TrackInOut(const StTrack &track, EDraw3DStyle sty,Bool_t in)
00417 {
00418 const StDraw3DStyle &style = Style(sty);
00419 return TrackInOut(track, in, style.Col(),style.Sty(),style.Siz() );
00420 }
00421
00422
00423
00425
00433
00434 void StuDraw3DEvent::Tracks(const StEvent* event, StTrackType type)
00435 {
00436 Hits(event,kTracksOnly,type);
00437 }
00438
00439
00441
00449
00450 void StuDraw3DEvent::Tracks(const StSPtrVecTrackNode &theNodes
00451 , StTrackType type)
00452 {
00453 StTrack *track;
00454 StThreeVectorD p;
00455 unsigned int i;
00456
00457
00458 for (i=0; i<theNodes.size(); i++) {
00459 track = theNodes[i]->track(type);
00460 if (track && track->flag() > 0
00461
00462 )
00463 {
00464 double pt = track->geometry()->momentum().perp();
00465 Track(*track,StDraw3DStyle::Pt2Color(pt));
00466 }
00467 }
00468 }
00469
00470 void StuDraw3DEvent::Hits(const StEvent *event,EStuDraw3DEvent trackHitsOnly, StTrackType type)
00471 {
00472 if (!event) return;
00473 const StTpcHitCollection* hits = event->tpcHitCollection();
00474 if (!hits) return;
00475 unsigned int m, n, h;
00476 if (trackHitsOnly != kUnusedHitsOnly) {
00477 Style_t sty = Style(kUsedHit).Sty();
00478 Size_t siz = Style(kUsedHit).Siz();
00479 Style_t styPnt = Style(kTrackBegin).Sty();
00480 Size_t sizPnt = Style(kTrackBegin).Siz();
00481
00482 const StSPtrVecTrackNode& theNodes = event->trackNodes();
00483 for (unsigned int i=0; i<theNodes.size(); i++) {
00484 StTrack *track = theNodes[i]->track(type);
00485 if (track && track->flag() > 0
00486 && track->detectorInfo()
00487 && !track->bad()
00488
00489 )
00490 {
00491 double pt = track->geometry()->momentum().perp();
00492 Color_t trackColor = StDraw3DStyle::Pt2Color(pt);
00493 if ( trackHitsOnly != kUsedHits) {
00494 Track(*track,trackColor);
00495 TrackInOut(*track, true, trackColor, styPnt, sizPnt);
00496 TrackInOut(*track, false, trackColor, styPnt, sizPnt);
00497 }
00498 if ( trackHitsOnly != kTracksOnly) {
00499 Hits(*track,trackColor,sty,siz);
00500 if (trackHitsOnly == kUsedHits) SetModel(track);
00501 }
00502 }
00503 }
00504 } else {
00505 const StTpcHit *hit;
00506 std::vector<float> hitPoints;
00507 for (n=0; n<hits->numberOfSectors(); n++) {
00508 for (m=0; m<hits->sector(n)->numberOfPadrows(); m++) {
00509 for (h=0; h<hits->sector(n)->padrow(m)->hits().size(); h++) {
00510 hit = hits->sector(n)->padrow(m)->hits()[h];
00511 hitPoints.push_back( hit->position().x());
00512 hitPoints.push_back( hit->position().y());
00513 hitPoints.push_back( hit->position().z());
00514 }
00515 }
00516 }
00517 std::vector<float>::iterator xyz = hitPoints.begin();
00518 Points(hitPoints.size()/3,&*xyz,kUnusedHit);
00519 SetComment("Unused TPC hits");
00520 }
00521 }
00522
00523
00524 void StuDraw3DEvent::FtpcHits(const StEvent *event,EStuDraw3DEvent trackHitsOnly, StTrackType type)
00525 {
00526 if (!event) return;
00527 unsigned int m, n, h;
00528 if (trackHitsOnly != kUnusedHitsOnly) {
00529 Style_t sty = Style(kUsedHit).Sty();
00530 Size_t siz = Style(kUsedHit).Siz();
00531 Style_t styPnt = Style(kTrackBegin).Sty();
00532 Size_t sizPnt = Style(kTrackBegin).Siz();
00533 int trackCounter = 0;
00534 const StSPtrVecTrackNode& theNodes = event->trackNodes();
00535 for (unsigned int i=0; i<theNodes.size(); i++) {
00536 StTrack *track = theNodes[i]->track(type);
00537 if (track && track->flag() > 0
00538 && track->detectorInfo()
00539 && ( track->detectorInfo()->numberOfPoints(kFtpcWestId) || track->detectorInfo()->numberOfPoints(kFtpcEastId) )
00540 && !track->bad()
00541 )
00542 {
00543 ++trackCounter;
00544 double pt = track->geometry()->momentum().perp();
00545 Color_t trackColor = StDraw3DStyle::Pt2Color(pt);
00546 if ( trackHitsOnly != kUsedHits) {
00547 Track(*track,trackColor);
00548 TrackInOut(*track, true, trackColor, styPnt, sizPnt);
00549 TrackInOut(*track, false, trackColor, styPnt, sizPnt);
00550 }
00551 if ( trackHitsOnly != kTracksOnly) {
00552 Hits(*track,trackColor,sty,siz);
00553 if (trackHitsOnly == kUsedHits) SetModel(track);
00554 }
00555 }
00556 }
00557 printf(" Ftpc tracks total : %d\n", trackCounter);
00558 } else {
00559 const StHit *hit= 0;
00560 std::vector<float> hitPoints;
00561 const StFtpcHitCollection* ftpHits = event->ftpcHitCollection();
00562 if (ftpHits->numberOfHits()>0) {
00563 for (n=0;n<ftpHits-> numberOfPlanes();++n ) {
00564 for (m=0; m<ftpHits->plane(n)->numberOfSectors(); m++) {
00565 for (h=0; h<ftpHits->plane(n)->sector(m)->hits().size(); h++) {
00566 hit = ftpHits->plane(n)->sector(m)->hits()[h];
00567 hitPoints.push_back( hit->position().x());
00568 hitPoints.push_back( hit->position().y());
00569 hitPoints.push_back( hit->position().z());
00570 } } }
00571 std::vector<float>::iterator xyz = hitPoints.begin();
00572 Points(hitPoints.size()/3,&*xyz,kUnusedHit);
00573 SetComment("Unused FTPC hits");
00574 printf(" FTPC hits counter total : %d\n", hitPoints.size()/3);
00575 }
00576 }
00577 }
00578
00579
00581
00582 StuDraw3DEvent *StuDraw3DEvent::Display(){ return gEventDisplay;}
00583
00584 StuDraw3DEvent *gEventDisplay = new StuDraw3DEvent();
00585
00586 void StuDraw3DEvent::Hits(StEventHitIter &iter)
00587 {
00588 std::vector<float> hitPoints;
00589 for (const StHit *sth=0;(sth = *(iter));++iter) {
00590 const float *f = sth->position().xyz();
00591 hitPoints.push_back(f[0]);
00592 hitPoints.push_back(f[1]);
00593 hitPoints.push_back(f[2]);
00594 }
00595 std::vector<float>::iterator xyz = hitPoints.begin();
00596 Points(hitPoints.size()/3,&*xyz,kUsedHit);
00597 }
00598
00599
00600 void StuDraw3DEvent::Wait()
00601 {
00602 if (gEventDisplay) gEventDisplay->UpdateModified();
00603 fprintf(stderr,"StvDraw::Waiting...\n");
00604 while(!gSystem->ProcessEvents()){gSystem->Sleep(200);};
00605 }
00606