DD4hep  1.30.0
Detector Description Toolkit for High Energy Physics
next_event_lcio.cpp
Go to the documentation of this file.
1 //==========================================================================
2 // AIDA Detector description implementation
3 //--------------------------------------------------------------------------
4 // Copyright (C) Organisation europeenne pour la Recherche nucleaire (CERN)
5 // All rights reserved.
6 //
7 // For the licensing terms see $DD4hepINSTALL/LICENSE.
8 // For the list of contributors see $DD4hepINSTALL/doc/CREDITS.
9 //
10 //==========================================================================
11 #include "TEveManager.h"
12 #include "TEveStraightLineSet.h"
13 #include "TEvePointSet.h"
14 #include <iostream>
15 
16 #include "lcio.h"
17 #include "EVENT/LCEvent.h"
18 #include "EVENT/LCCollection.h"
19 #include "EVENT/SimCalorimeterHit.h"
20 #include "EVENT/SimTrackerHit.h"
21 #include "EVENT/CalorimeterHit.h"
22 #include "EVENT/TrackerHit.h"
23 #include "UTIL/Operators.h"
24 
25 #include "DD4hep/DD4hepUnits.h"
26 
27 #include "MultiView.h"
28 
29 using namespace lcio;
30 
31 //=====================================================================================
32 
33 template <class T>
34 TEveElement* createPointSet( lcio::LCCollection* col, const std::string& name, unsigned color=kMagenta, unsigned size=1, unsigned style=4 ) ;
35 
36 //=====================================================================================
37 
40 template <class T>
41 class LCIOTObject : public TObject{
42  const T* _obj ;
44 public:
45  LCIOTObject( const T* o) : _obj(o) {}
46  void Print() {
47  std::cout << *_obj ;
48  }
49 } ;
50 
51 
52 void next_event(){
53 
54  static int count = 1 ;
55 
56  static LCReader* rdr = 0 ;
57 
58  std::string lcioFileName = "teve_infile.slcio" ;
59 
60  std::cout << " next_event_lcio called ..." << std::endl ;
61 
62  if( count==1 ){
63 
64  rdr = LCFactory::getInstance()->createLCReader() ;
65 
66  try{
67 
68  rdr->open( lcioFileName ) ;
69 
70  }catch(lcio::IOException& e) {
71 
72  std::cout << " ------------------------------------------------------------------------------------------------ " << std::endl
73  << "*** file " << lcioFileName << " does not exist - can't read LCIO events ! " << std::endl
74  << " will display detector geometry only. Link LCIO file to " << lcioFileName << " to display events ! "<< std::endl
75  << " -------------------------------------------------------------------------------------------------"
76  << std::endl ;
77 
78  return ;
79  }
80  }
81 
82  if( rdr == 0 )
83  // nothing to do as inputfile does not exist:
84  return ;
85 
86 
87  TEveElementList* tevent = (TEveElementList* ) gEve->GetCurrentEvent() ;
88 
89  if( tevent )
90  tevent->DestroyElements() ;
91 
92  LCEvent* evt = rdr->readNextEvent() ;
93 
94  if( evt != 0 ){
95 
96  const std::vector< std::string >& colNames = * evt->getCollectionNames() ;
97 
98  for(unsigned icol=0, ncol = colNames.size() ; icol < ncol ; ++icol ){
99 
100  LCCollection* col = evt->getCollection( colNames[ icol ] ) ;
101 
102  std::cout << " **** reading collection " << colNames[ icol ] << std::endl ;
103 
104 
105  if( col->getTypeName() == LCIO::SIMTRACKERHIT ){
106 
107  MultiView::instance()->ImportEvent( createPointSet<EVENT::SimTrackerHit>( col , colNames[ icol ] , kMagenta+2 , 1 , 4 ) ) ;
108  }
109  else if( col->getTypeName() == LCIO::SIMCALORIMETERHIT ){
110 
111  MultiView::instance()->ImportEvent( createPointSet<EVENT::SimCalorimeterHit>( col , colNames[ icol ] , kMagenta+4 , 1 , 4 ) ) ;
112  }
113  else if( col->getTypeName() == LCIO::TRACKERHIT ){
114 
115  MultiView::instance()->ImportEvent( createPointSet<EVENT::TrackerHit>( col , colNames[ icol ] , kBlue+2 , 1 , 4 ) ) ;
116  }
117  else if( col->getTypeName() == LCIO::CALORIMETERHIT ){
118 
119  MultiView::instance()->ImportEvent( createPointSet<EVENT::CalorimeterHit>( col , colNames[ icol ] , kBlue+4 , 1 , 4 ) ) ;
120  }
121 
122  }
123 
124  } else{
125 
126  std::cout << "WARNING: can't read LCEvent from input file ! " << std::endl ;
127  }
128 
129 
130  gEve->Redraw3D();
131 
132  ++count ;
133  //count += 3 ;
134 }
135 
136 
137 //=====================================================================================
138 template <class T>
139 TEveElement* createPointSet( lcio::LCCollection* col, const std::string& name, unsigned color, unsigned size, unsigned style ) {
140 
141  TEvePointSet* ps = new TEvePointSet( name.c_str() );
142  ps->SetOwnIds(kTRUE);
143 
144  int nHit = col->getNumberOfElements() ;
145 
146  for( int i=0 ; i< nHit ; ++i ){
147 
148  T* hit = (T*) col->getElementAt( i ) ;
149 
150  double pos[3] = { hit->getPosition()[0], hit->getPosition()[1] , hit->getPosition()[2] } ;
151  // pos[0] = hit->getPosition()[0] ;
152  // pos[1] = hit->getPosition()[1] ;
153  // pos[2] = hit->getPosition()[2] ;
154 
155  ps->SetNextPoint( pos[0]*dd4hep::mm , pos[1]*dd4hep::mm, pos[2]*dd4hep::mm );
156 
157  int id[2] ;
158  id[0] = hit->getCellID0() ;
159  id[1] = hit->getCellID1() ;
160 
161  ps->SetPointIntIds( id ) ;
162  // does work for the point itself ...
163  // ps->SetSourceObject( new LCIOTObject<T>( hit ) ) ;
164  }
165 
166  ps->SetMarkerColor( color ) ;
167  ps->SetMarkerSize( size );
168  ps->SetMarkerStyle( style );
169 
170  return ps;
171 
172 
173 }
174 //=====================================================================================
175 
MultiView.h
LCIOTObject
Definition: next_event_lcio.cpp:41
TEveElementList
Class of the ROOT toolkit. See http://root.cern.ch/root/htmldoc/ClassIndex.html.
Definition: ROOTClasses.h:13
LCIOTObject::LCIOTObject
LCIOTObject()
Definition: next_event_lcio.cpp:43
createPointSet
TEveElement * createPointSet(lcio::LCCollection *col, const std::string &name, unsigned color=kMagenta, unsigned size=1, unsigned style=4)
Definition: next_event_lcio.cpp:139
MultiView::instance
static MultiView * instance()
Definition: MultiView.h:57
next_event
void next_event()
Definition: next_event_lcio.cpp:52
LCIOTObject::LCIOTObject
LCIOTObject(const T *o)
Definition: next_event_lcio.cpp:45
TObject
Class of the ROOT toolkit. See http://root.cern.ch/root/htmldoc/ClassIndex.html.
Definition: ROOTClasses.h:41
LCIOTObject::Print
void Print()
Definition: next_event_lcio.cpp:46
DD4hepUnits.h
MultiView::ImportEvent
void ImportEvent(TEveElement *el)
Definition: MultiView.h:180
LCIOTObject::_obj
const T * _obj
Definition: next_event_lcio.cpp:42