StRoot  1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
StuDraw3DEvent.cxx
1 // $Id: StuDraw3DEvent.cxx,v 1.35 2018/06/29 17:21:24 perev Exp $
2 // *-- Author : Valery Fine(fine@bnl.gov) 27/04/2008
3 #include "StuDraw3DEvent.h"
4 #include "TSystem.h"
5 #include "TVirtualPad.h"
6 #include "TColor.h"
7 #include "StEventHelper.h"
8 #include "StEvent.h"
9 #include "StTrack.h"
10 #include "StGlobalTrack.h"
11 #include "StHit.h"
12 #include "StTpcHit.h"
13 #include "StFtpcHit.h"
14 #include "StEmcRawHit.h"
15 #include "StTrackNode.h"
16 #include "StTrackGeometry.h"
17 #include "StTpcHitCollection.h"
18 #include "StEmcCollection.h"
19 #include "StFtpcHitCollection.h"
20 #include "StFtpcSectorHitCollection.h"
21 #include "StFtpcPlaneHitCollection.h"
22 #include "StEmcDetector.h"
23 #include "StEmcModule.h"
24 #include "StMeasuredPoint.h"
25 #include "TMath.h"
26 #include "StTrackDetectorInfo.h"
27 #include "StEmcUtil/geometry/StEmcGeom.h"
28 #include "StEventHitIter.h"
29 #include "StMessMgr.h"
30 
31 
32 //____________________________________________________________________________________
34 
61 ClassImp(StuDraw3DEvent)
62 //___________________________________________________
63 StuDraw3DEvent::StuDraw3DEvent( const char *detectorName,TVirtualPad *pad):StDraw3D(detectorName,pad)
64 {
65  // The detectorName is a comma separated list of the OpenInventor files with no extension
66  // For all names on the list one should provide the iv file with the "iv extension:
67  // <name>.iv
68  if (!gEventDisplay) gEventDisplay = this;
69 }
70 
71 //____________________________________________________________________________________
73 
76 //____________________________________________________________________________________
78 {
79  if (gEventDisplay == this) gEventDisplay = 0;
80 }
81 //____________________________________________________________________________________
83 
91 //____________________________________________________________________________________
92 TObject *StuDraw3DEvent::EmcHit(Int_t emcHitsSoftId, Color_t col,Style_t sty,Size_t siz, const char *detId)
93 {
94  TObject *model = 0;
95  StEmcGeom *emcGeom =StEmcGeom::getEmcGeom(detId);
96  if (emcGeom) {
97  Int_t softId=emcHitsSoftId;
98  Float_t eta;
99  Float_t phi;
100  emcGeom->getEtaPhi(softId,eta,phi);
101  Float_t etaStep = 1.0/emcGeom->NEta();
102  Float_t phiStep = TMath::Pi()/60;
103  static int entries = 0;
104  //if (entries) return 0;
105  // printf(" m=%d, e=%d, s=%d; eta=%e deta=%e phi=%e dphi=%e id %d\n",m, e, s,eta,etaStep ,phi, phiStep, softId);
106  entries++;
107  model = Tower(emcGeom->Radius(), StarRoot::StEta(eta,etaStep)
108  , phi, phiStep
109  , col,sty+(strcmp(detId,"bemc")?0:kBarrelStyle),siz);
110  } else {
111  LOG_ERROR << __FILE__ << ": there is no geometry information for \"" << detId << "\"" << endm;
112  }
113  return model;
114 }
115 //____________________________________________________________________________________
117 
125 //____________________________________________________________________________________
126 TObject *StuDraw3DEvent::EmcHit(const StEmcRawHit &emcHit, Color_t col,Style_t sty,Size_t siz, const char *detId)
127 {
128  TObject *model = 0;
129  if (!detId || !detId[0]) detId = "bemc";
130  StEmcGeom *emcGeom =StEmcGeom::getEmcGeom(detId);
131  if (emcGeom) {
132  int m, e, s;
133  Int_t softId;
134  emcHit.modEtaSub(m,e,s);
135  emcGeom->getId(m,e,s,softId);
136  EmcHit(softId, col,sty,siz,detId);
137  SetModel((TObject*)&emcHit);
138  } else {
139  LOG_ERROR << __FILE__ << ": there is no geometry information for \"" << detId << "\"" << endm;
140  }
141  return model;
142 }
143 
144 //____________________________________________________________________________________
146 
153 //______________________________________________________________________________________
154 void StuDraw3DEvent::EmcHits(const StEvent* event,const char *detId)
155 {
156  Color_t colorResponce = 0;
157  if (!detId || !detId[0]) detId = "bemc";
158  StEmcCollection* emcC =(StEmcCollection*)event->emcCollection();
159  if (emcC) {
160  StEmcDetector* det = emcC->detector( strcmp(detId,"bemc") ? kEndcapEmcTowerId : kBarrelEmcTowerId);
161  if (det) {
162  for(unsigned int md=1; md <=det->numberOfModules(); md++) {
163  StEmcModule* module=det->module(md);
164  StSPtrVecEmcRawHit& hit= module->hits();
165 
166  for(unsigned int ih=0;ih < hit.size();ih++){
167  StEmcRawHit *h=hit[ih];
168  double rawAdc=h->adc()-5; // raw ADC
169  float energy = h->energy();
170  Style_t style=0; // solid
171 // energy = (rawAdc+5)/5;
172 // printf(" EmcHits %d adc = %e energy = %e\n", ih,rawAdc, energy);
173  if ( rawAdc>0 && energy > 0 && energy < 30) {
174  // If edep less then MIP (~300 MeV), 60GeV <-> 4096 ADC counts
175  if ( energy < 0.3) {
176  colorResponce = kBlue;
177  // style = 4001; //wireframe
178  // If edep large then MIP but less then 1 GeV
179  } else if ( energy < 1.0 ) colorResponce = kGreen;
180  // If between 1 GeV and lowest HT threshold (4 GeV for Run7)
181  else if ( energy < 4.0 ) colorResponce = kYellow;
182  // If above lowest HT thershold
183  else colorResponce = kRed;
184  if (energy > 1.0) {
185  // printf(" Emchit adc = %e energy = %e\n",rawAdc, energy);
186  }
187  static const double maxSize = 400.; // (cm)
188  static const double scale = 200.; // (cm/Gev)
189  double size =(energy > 0.3 ? scale : scale/30.)*energy;
190  if (size > maxSize) size = maxSize ;
191  EmcHit(*h,colorResponce,style, size,detId);
192  }
193  }
194  }
195  }
196  }
197 }
198 
199 //____________________________________________________________________________________
201 
209 //____________________________________________________________________________________
210 TObject *StuDraw3DEvent::Track(const StTrack &track, Color_t col,Style_t sty,Size_t siz)
211 {
212  StTrackHelper trPnt(&track);
213  Int_t size;
214  Float_t *xyz = trPnt.GetPoints(size);
215  TObject *l = Line(size,xyz,col,sty,siz);
216  SetModel((TObject*)&track);
217  return l;
218 }
219 
221 
223 //___________________________________________________
224 TObject *StuDraw3DEvent::Track(const StTrack &track, EDraw3DStyle sty)
225 {
226  const StDraw3DStyle &style = Style(sty);
227  return Track(track, style.Col(),style.Sty(),style.Siz() );
228 }
229 //____________________________________________________________________________________
230 TObject *StuDraw3DEvent::Track(const StGlobalTrack &track, Color_t col,Style_t sty,Size_t siz)
231 {
232  StTrackHelper trPnt(&track);
233  Int_t size;
234  Float_t *xyz = trPnt.GetPoints(size);
235  TObject *l = Line(size,xyz,col,sty,siz);
236  SetModel((TObject*)&track);
237  return l;
238 }
239 
241 
243 //___________________________________________________
244 TObject *StuDraw3DEvent::Track(const StGlobalTrack &track, EDraw3DStyle sty)
245 {
246  const StDraw3DStyle &style = Style(sty);
247  return Track(track, style.Col(),style.Sty(),style.Siz() );
248 }
249 
250 //____________________________________________________________________________________
252 
260 //____________________________________________________________________________________
262  , Color_t col, Style_t sty, Size_t siz)
263 {
264  // Draw the StMeasuredPoint, StHit, StVertex with the graphical attribute provided
265  const StThreeVectorF& position = hit.position();
266  TObject *p = Point(position.x(),position.y(),position.z(),col,sty,siz);
267  SetModel((TObject*)&hit);
268  return p;
269 }
270 
271 //____________________________________________________________________________________
273 
275 //____________________________________________________________________________________
276 TObject *StuDraw3DEvent::Hit(const StMeasuredPoint &hit, EDraw3DStyle sty)
277 {
278  const StDraw3DStyle &style = Style(sty);
279  return Hit(hit, style.Col(),style.Sty(),style.Siz() );
280 }
281 
282 //____________________________________________________________________________________
284 
292 //____________________________________________________________________________________
294  , Color_t col, Style_t sty, Size_t siz)
295 {
296  return Hit(vertex,col,sty,siz);
297 }
298 
299 //____________________________________________________________________________________
301 
307 //____________________________________________________________________________________
308 TObject *StuDraw3DEvent::Vertex(const StMeasuredPoint &vtx, EDraw3DStyle sty)
309 {
310  const StDraw3DStyle &style = Style(sty);
311  return Vertex(vtx, style.Col(),style.Sty(),style.Siz() );
312 }
313 
314 //____________________________________________________________________________________
316 
321 //____________________________________________________________________________________
322 void StuDraw3DEvent::Hits(const StTrack &track)
323 {
324  // Draw hits the "track" was built from
325  // with the graphical attributes defined by "track"
326  if (track.flag() > 0 && track.detectorInfo()&& !track.bad() ) {
327  Style_t sty = Style(kUsedHit).Sty();
328  Size_t siz = Style(kUsedHit).Siz();
329  double pt = track.geometry()->momentum().perp();
330  Hits(track, StDraw3DStyle::Pt2Color(pt),sty,siz);
331  }
332 }
333 
334 //____________________________________________________________________________________
336 
343 //____________________________________________________________________________________
344 void StuDraw3DEvent::Hits(const StTrack &track
345  , Color_t col
346  , Style_t sty
347  , Size_t siz )
348 {
349  // Draw hits the "track" was built from
350  // with the graphical attributes "col", "sty", "siz"
351  std::vector<float> hitPoints;
352  const StPtrVecHit& trackHits = track.detectorInfo()->hits(kTpcId);
353  unsigned int m=0;
354  StHit *hit = 0;
355  for (m=0; m<trackHits.size(); m++) {
356  hit = trackHits[m];
357  hitPoints.push_back( hit->position().x());
358  hitPoints.push_back( hit->position().y());
359  hitPoints.push_back( hit->position().z());
360  }
361  {
362  std::vector<float>::iterator xyz = hitPoints.begin();
363  Points(hitPoints.size()/3,&*xyz,col,sty,siz);
364  }
365  // printf(" Tpc hits # %d\n", m);
366 
367  const StPtrVecHit& trackWestHits = track.detectorInfo()->hits(kFtpcWestId);
368 
369  hitPoints.clear();
370  for (m=0; m<trackWestHits.size(); m++) {
371  hit = trackWestHits[m];
372  hitPoints.push_back( hit->position().x());
373  hitPoints.push_back( hit->position().y());
374  hitPoints.push_back( hit->position().z());
375  }
376  {
377  std::vector<float>::iterator xyz = hitPoints.begin();
378  Points(hitPoints.size()/3,&*xyz,col,sty,siz);
379  }
380  // printf(" Ftpc West hits # %d\n", m);
381 
382  hitPoints.clear();
383  const StPtrVecHit& trackEastHits = track.detectorInfo()->hits(kFtpcEastId);
384  for (m=0; m<trackEastHits.size(); m++) {
385  hit = trackEastHits[m];
386  hitPoints.push_back( hit->position().x());
387  hitPoints.push_back( hit->position().y());
388  hitPoints.push_back( hit->position().z());
389  }
390  {
391  std::vector<float>::iterator xyz = hitPoints.begin();
392  Points(hitPoints.size()/3,&*xyz,col,sty,siz);
393  }
394  // printf(" Ftpc East hits # %d\n", m);
395 }
396 
397 //____________________________________________________________________________________
399 
401 //____________________________________________________________________________________
402 void StuDraw3DEvent::Hits(const StTrack &track, EDraw3DStyle sty)
403 {
404  // Draw hits the "track" was built from
405  // using the "sty" graphical style provided
406  const StDraw3DStyle &style = Style(sty);
407  Hits(track, style.Col(),style.Sty(),style.Siz());
408 }
409 
410 //____________________________________________________________________________________
412 
421 //____________________________________________________________________________________
422 TObject *StuDraw3DEvent::TrackInOut(const StTrack &track, Bool_t in
423  , Color_t col, Style_t sty, Size_t siz)
424 {
425  StInnOutPoints trInOut(&track,in);
426  return Points(trInOut.Size(),trInOut.GetXYZ(0),col,sty,siz);
427 }
428 
429 //____________________________________________________________________________________
431 
438 //____________________________________________________________________________________
439 TObject *StuDraw3DEvent::TrackInOut(const StTrack &track, EDraw3DStyle sty,Bool_t in)
440 {
441  const StDraw3DStyle &style = Style(sty);
442  return TrackInOut(track, in, style.Col(),style.Sty(),style.Siz() );
443 }
444 
445 
446 //____________________________________________________________________________________
448 
456 //____________________________________________________________________________________
457 void StuDraw3DEvent::Tracks(const StEvent* event, StTrackType type)
458 {
459  Hits(event,kTracksOnly,type);
460 }
461 
462 //____________________________________________________________________________________
464 
472 //____________________________________________________________________________________
473 void StuDraw3DEvent::Tracks(const StSPtrVecTrackNode &theNodes
474  , StTrackType type)
475 {
476  StTrack *track;
477  StThreeVectorD p;
478  unsigned int i;
479  // double pt;
480  // int minFitPoints = mAllGlobalTracks ? 1 : mMinFitPoints;
481  for (i=0; i<theNodes.size(); i++) {
482  track = (StTrack *) theNodes[i]->track(type);
483  if (track && track->flag() > 0
484  // && track->fitTraits().numberOfFitPoints(kTpcId) >= minFitPoints)
485  )
486  {
487  double pt = track->geometry()->momentum().perp();
488  Track(*track,StDraw3DStyle::Pt2Color(pt));
489  }
490  }
491 }
492 //___________________________________________________
493 void StuDraw3DEvent::Hits(const StEvent *event,EStuDraw3DEvent trackHitsOnly, StTrackType type)
494 {
495  if (!event) return; // no event
496  const StTpcHitCollection* hits = event->tpcHitCollection();
497  if (!hits) return; // there is no hits
498  unsigned int m, n, h;
499  if (trackHitsOnly != kUnusedHitsOnly) {
500  Style_t sty = Style(kUsedHit).Sty();
501  Size_t siz = Style(kUsedHit).Siz();
502  Style_t styPnt = Style(kTrackBegin).Sty();
503  Size_t sizPnt = Style(kTrackBegin).Siz();
504 
505  const StSPtrVecTrackNode& theNodes = event->trackNodes();
506  for (unsigned int i=0; i<theNodes.size(); i++) {
507  StTrack *track = (StTrack *)theNodes[i]->track(type);
508  if (track && track->flag() > 0
509  && track->detectorInfo()
510  && !track->bad()
511  // && track->fitTraits().numberOfFitPoints(kTpcId) >= minFitPoints)
512  )
513  {
514  double pt = track->geometry()->momentum().perp();
515  Color_t trackColor = StDraw3DStyle::Pt2Color(pt);
516  if ( trackHitsOnly != kUsedHits) {
517  Track(*track,trackColor);
518  TrackInOut(*track, true, trackColor, styPnt, sizPnt);
519  TrackInOut(*track, false, trackColor, styPnt, sizPnt);
520  }
521  if ( trackHitsOnly != kTracksOnly) {
522  Hits(*track,trackColor,sty,siz);
523  if (trackHitsOnly == kUsedHits) SetModel(track);
524  }
525  }
526  }
527  } else {
528  const StTpcHit *hit;
529  std::vector<float> hitPoints;
530  for (n=0; n<hits->numberOfSectors(); n++) {
531  for (m=0; m<hits->sector(n)->numberOfPadrows(); m++) {
532  for (h=0; h<hits->sector(n)->padrow(m)->hits().size(); h++) {
533  hit = hits->sector(n)->padrow(m)->hits()[h];
534  hitPoints.push_back( hit->position().x());
535  hitPoints.push_back( hit->position().y());
536  hitPoints.push_back( hit->position().z());
537  }
538  }
539  }
540  std::vector<float>::iterator xyz = hitPoints.begin();
541  Points(hitPoints.size()/3,&*xyz,kUnusedHit);
542  SetComment("Unused TPC hits");
543  }
544 }
545 
546 //___________________________________________________
547 void StuDraw3DEvent::FtpcHits(const StEvent *event,EStuDraw3DEvent trackHitsOnly, StTrackType type)
548 {
549  if (!event) return; // no event
550  unsigned int m, n, h;
551  if (trackHitsOnly != kUnusedHitsOnly) {
552  Style_t sty = Style(kUsedHit).Sty();
553  Size_t siz = Style(kUsedHit).Siz();
554  Style_t styPnt = Style(kTrackBegin).Sty();
555  Size_t sizPnt = Style(kTrackBegin).Siz();
556  int trackCounter = 0;
557  const StSPtrVecTrackNode& theNodes = event->trackNodes();
558  for (unsigned int i=0; i<theNodes.size(); i++) {
559  StTrack *track = (StTrack *) theNodes[i]->track(type);
560  if (track && track->flag() > 0
561  && track->detectorInfo()
562  && ( track->detectorInfo()->numberOfPoints(kFtpcWestId) || track->detectorInfo()->numberOfPoints(kFtpcEastId) )
563  && !track->bad()
564  )
565  {
566  ++trackCounter;
567  double pt = track->geometry()->momentum().perp();
568  Color_t trackColor = StDraw3DStyle::Pt2Color(pt);
569  if ( trackHitsOnly != kUsedHits) {
570  Track(*track,trackColor);
571  TrackInOut(*track, true, trackColor, styPnt, sizPnt);
572  TrackInOut(*track, false, trackColor, styPnt, sizPnt);
573  }
574  if ( trackHitsOnly != kTracksOnly) {
575  Hits(*track,trackColor,sty,siz);
576  if (trackHitsOnly == kUsedHits) SetModel(track);
577  }
578  }
579  }
580  printf(" Ftpc tracks total : %d\n", trackCounter);
581  } else {
582  const StHit *hit= 0;
583  std::vector<float> hitPoints;
584  const StFtpcHitCollection* ftpHits = event->ftpcHitCollection();
585  if (ftpHits->numberOfHits()>0) {
586  for (n=0;n<ftpHits-> numberOfPlanes();++n ) {
587  for (m=0; m<ftpHits->plane(n)->numberOfSectors(); m++) {
588  for (h=0; h<ftpHits->plane(n)->sector(m)->hits().size(); h++) {
589  hit = ftpHits->plane(n)->sector(m)->hits()[h];
590  hitPoints.push_back( hit->position().x());
591  hitPoints.push_back( hit->position().y());
592  hitPoints.push_back( hit->position().z());
593  } } }
594  std::vector<float>::iterator xyz = hitPoints.begin();
595  Points(hitPoints.size()/3,&*xyz,kUnusedHit);
596  SetComment("Unused FTPC hits");
597  printf(" FTPC hits counter total : %d\n", hitPoints.size()/3);
598  }
599  }
600 }
601 
602 //____________________________________________________________________________________
604 //____________________________________________________________________________________
605 StuDraw3DEvent *StuDraw3DEvent::Display(){ return gEventDisplay;}
606 
607 StuDraw3DEvent *gEventDisplay = new StuDraw3DEvent();
608 //____________________________________________________________________________________
609 void StuDraw3DEvent::Hits(StEventHitIter &iter)
610 {
611  std::vector<float> hitPoints;
612  for (const StHit *sth=0;(sth = *(iter));++iter) {
613  const float *f = sth->position().xyz();
614  hitPoints.push_back(f[0]);
615  hitPoints.push_back(f[1]);
616  hitPoints.push_back(f[2]);
617  }
618  std::vector<float>::iterator xyz = hitPoints.begin();
619  Points(hitPoints.size()/3,&*xyz,kUsedHit);
620 }
621 //____________________________________________________________________________________
622 //_____________________________________________________________________________
623 void StuDraw3DEvent::Wait()
624 {
625  if (gEventDisplay) gEventDisplay->UpdateModified();
626  fprintf(stderr,"StvDraw::Waiting...\n");
627  while(!gSystem->ProcessEvents()){gSystem->Sleep(200);};
628 }
629 
StEventHitIter is the top level hook, providing hits to the Stv tracking code.
Definition: StHit.h:125
virtual const StDraw3DStyle & Style(EDraw3DStyle type) const
Return the reference to the predefined StDraw3DStyle object.
Definition: StDraw3D.cxx:482
StDraw3DStyle maps &quot;STAR event&quot; EDraw3DStyle onto ROOT (color,style,size) attributes.
Definition: StDraw3D.h:29
virtual ~StuDraw3DEvent()
~StuDraw3DEvent( ) dtor
virtual void Tracks(const StEvent *event, StTrackType type=global)
Add all tracks of the given type from the event to the display list.
virtual TObject * EmcHit(Int_t emcHitsSoftId, Color_t col, Style_t sty, Size_t siz, const char *det="bemc")
Add EMC hit defined emcHitsSoftId to the display list with the col color sty and size if provided...
static Color_t Pt2Color(double pt)
Maps the track pt to the STAR StTrack track color code.
Definition: StDraw3D.cxx:78
virtual TObject * Tower(float radius, float lambda, float lambda1, float lambda2, float phi, float dphi, Color_t col, Style_t sty, Size_t siz)
This is an overloaded member function, provided for convenience.
Definition: StDraw3D.cxx:1425
virtual TObject * Line(int n, const double *xyz, Color_t col=Color_t(-1), Style_t sty=Style_t(-1), Size_t siz=Size_t(-1))
This is an overloaded member function, provided for convenience.
Definition: StDraw3D.cxx:807
Class StDraw3D - to draw the 3D primitives like 3D points and 3D lines decorated with the STAR detect...
Definition: StDraw3D.h:165
virtual TObject * Track(const StTrack &track, Color_t col, Style_t sty=Style_t(-1), Size_t siz=Size_t(-1))
Add track to the display list with the col color sty and size if provided.
virtual TObject * Hit(const StMeasuredPoint &hit, Color_t col, Style_t sty=Style_t(-1), Size_t siz=Size_t(-1))
Add one hit to the display list with the col color sty and siz size if provided.
virtual TObject * Vertex(const StMeasuredPoint &hit, Color_t col, Style_t sty=Style_t(-1), Size_t siz=Size_t(-1))
This is an overloaded member function, provided for convenience.
static StuDraw3DEvent * Display()
virtual void EmcHits(const StEvent *event, const char *det="bemc")
Add all emcHits those can pass the internal filter from the given detector detId type from the event ...
virtual TObject * TrackInOut(const StTrack &track, Bool_t in, Color_t col=Color_t(-1), Style_t sty=Style_t(-1), Size_t siz=Size_t(-1))
Add the in point of the given track to the display list with the col color sty and siz size if provid...
virtual Float_t * GetPoints(int &npoints) const
virtual TObject * Points(int n, const float *xyz, EDraw3DStyle sty)
This is an overloaded member function, provided for convenience.
Definition: StDraw3D.cxx:596
Class StuDraw3DEvent - to draw the 3D StEvent primitives like StTrack, StHit, StVertex decorated with...