File indexing completed on 2025-01-18 09:15:00
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011 #include "TEveManager.h"
0012 #include "TEveStraightLineSet.h"
0013 #include "TEvePointSet.h"
0014 #include <iostream>
0015
0016 #include "lcio.h"
0017 #include "EVENT/LCEvent.h"
0018 #include "EVENT/LCCollection.h"
0019 #include "EVENT/SimCalorimeterHit.h"
0020 #include "EVENT/SimTrackerHit.h"
0021 #include "EVENT/CalorimeterHit.h"
0022 #include "EVENT/TrackerHit.h"
0023 #include "UTIL/Operators.h"
0024
0025 #include "DD4hep/DD4hepUnits.h"
0026
0027 #include "MultiView.h"
0028
0029 using namespace lcio;
0030
0031
0032
0033 template <class T>
0034 TEveElement* createPointSet( lcio::LCCollection* col, const std::string& name, unsigned color=kMagenta, unsigned size=1, unsigned style=4 ) ;
0035
0036
0037
0038
0039
0040 template <class T>
0041 class LCIOTObject : public TObject{
0042 const T* _obj ;
0043 LCIOTObject() {}
0044 public:
0045 LCIOTObject( const T* o) : _obj(o) {}
0046 void Print() {
0047 std::cout << *_obj ;
0048 }
0049 } ;
0050
0051
0052 void next_event(){
0053
0054 static int count = 1 ;
0055
0056 static LCReader* rdr = 0 ;
0057
0058 std::string lcioFileName = "teve_infile.slcio" ;
0059
0060 std::cout << " next_event_lcio called ..." << std::endl ;
0061
0062 if( count==1 ){
0063
0064 rdr = LCFactory::getInstance()->createLCReader() ;
0065
0066 try{
0067
0068 rdr->open( lcioFileName ) ;
0069
0070 }catch(lcio::IOException& e) {
0071
0072 std::cout << " ------------------------------------------------------------------------------------------------ " << std::endl
0073 << "*** file " << lcioFileName << " does not exist - can't read LCIO events ! " << std::endl
0074 << " will display detector geometry only. Link LCIO file to " << lcioFileName << " to display events ! "<< std::endl
0075 << " -------------------------------------------------------------------------------------------------"
0076 << std::endl ;
0077
0078 return ;
0079 }
0080 }
0081
0082 if( rdr == 0 )
0083
0084 return ;
0085
0086
0087 TEveElementList* tevent = (TEveElementList* ) gEve->GetCurrentEvent() ;
0088
0089 if( tevent )
0090 tevent->DestroyElements() ;
0091
0092 LCEvent* evt = rdr->readNextEvent() ;
0093
0094 if( evt != 0 ){
0095
0096 const std::vector< std::string >& colNames = * evt->getCollectionNames() ;
0097
0098 for(unsigned icol=0, ncol = colNames.size() ; icol < ncol ; ++icol ){
0099
0100 LCCollection* col = evt->getCollection( colNames[ icol ] ) ;
0101
0102 std::cout << " **** reading collection " << colNames[ icol ] << std::endl ;
0103
0104
0105 if( col->getTypeName() == LCIO::SIMTRACKERHIT ){
0106
0107 MultiView::instance()->ImportEvent( createPointSet<EVENT::SimTrackerHit>( col , colNames[ icol ] , kMagenta+2 , 1 , 4 ) ) ;
0108 }
0109 else if( col->getTypeName() == LCIO::SIMCALORIMETERHIT ){
0110
0111 MultiView::instance()->ImportEvent( createPointSet<EVENT::SimCalorimeterHit>( col , colNames[ icol ] , kMagenta+4 , 1 , 4 ) ) ;
0112 }
0113 else if( col->getTypeName() == LCIO::TRACKERHIT ){
0114
0115 MultiView::instance()->ImportEvent( createPointSet<EVENT::TrackerHit>( col , colNames[ icol ] , kBlue+2 , 1 , 4 ) ) ;
0116 }
0117 else if( col->getTypeName() == LCIO::CALORIMETERHIT ){
0118
0119 MultiView::instance()->ImportEvent( createPointSet<EVENT::CalorimeterHit>( col , colNames[ icol ] , kBlue+4 , 1 , 4 ) ) ;
0120 }
0121
0122 }
0123
0124 } else{
0125
0126 std::cout << "WARNING: can't read LCEvent from input file ! " << std::endl ;
0127 }
0128
0129
0130 gEve->Redraw3D();
0131
0132 ++count ;
0133
0134 }
0135
0136
0137
0138 template <class T>
0139 TEveElement* createPointSet( lcio::LCCollection* col, const std::string& name, unsigned color, unsigned size, unsigned style ) {
0140
0141 TEvePointSet* ps = new TEvePointSet( name.c_str() );
0142 ps->SetOwnIds(kTRUE);
0143
0144 int nHit = col->getNumberOfElements() ;
0145
0146 for( int i=0 ; i< nHit ; ++i ){
0147
0148 T* hit = (T*) col->getElementAt( i ) ;
0149
0150 double pos[3] = { hit->getPosition()[0], hit->getPosition()[1] , hit->getPosition()[2] } ;
0151
0152
0153
0154
0155 ps->SetNextPoint( pos[0]*dd4hep::mm , pos[1]*dd4hep::mm, pos[2]*dd4hep::mm );
0156
0157 int id[2] ;
0158 id[0] = hit->getCellID0() ;
0159 id[1] = hit->getCellID1() ;
0160
0161 ps->SetPointIntIds( id ) ;
0162
0163
0164 }
0165
0166 ps->SetMarkerColor( color ) ;
0167 ps->SetMarkerSize( size );
0168 ps->SetMarkerStyle( style );
0169
0170 return ps;
0171
0172
0173 }
0174
0175