16 #include "DD4hep/DDTest.h"
23 #include "IO/LCReader.h"
24 #include "EVENT/LCEvent.h"
25 #include "EVENT/LCCollection.h"
26 #include "EVENT/SimCalorimeterHit.h"
38 static DDTest test(
"cellid_position_converter" ) ;
42 const double epsilon = dd4hep::micrometer ;
62 typedef std::map<std::string, TestCounters >
TestMap ;
69 std::cout <<
" usage: test_cellid_position_converter compact.xml lcio_file.slcio" << std::endl ;
73 std::string inFile = argv[1] ;
75 Detector& description = Detector::getInstance();
86 std::string lcioFileName = argv[2] ;
88 LCReader* rdr = LCFactory::getInstance()->createLCReader() ;
89 rdr->open( lcioFileName ) ;
95 std::set< std::string > subset = {} ;
100 std::set< std::string > subsetIgnore = {
"HCalBarrelRPCHits",
"HCalECRingRPCHits",
"HCalEndcapRPCHits" } ;
104 while( ( evt = rdr->readNextEvent() ) != 0 ){
106 const std::vector< std::string >& colNames = *evt->getCollectionNames() ;
108 for(
unsigned icol=0, ncol = colNames.size() ; icol < ncol ; ++icol ){
110 LCCollection* col = evt->getCollection( colNames[ icol ] ) ;
112 std::string typeName = col->getTypeName() ;
114 if( typeName != lcio::LCIO::SIMCALORIMETERHIT )
117 if( !subset.empty() && subset.find( colNames[icol] ) == subset.end() )
120 if( !subsetIgnore.empty() && subsetIgnore.find( colNames[icol] ) != subsetIgnore.end() )
123 std::cout <<
" -- testing collection : " << colNames[ icol ] << std::endl ;
125 std::string cellIDEcoding = col->getParameters().getStringVal(
"CellIDEncoding") ;
130 int nHit = std::min( col->getNumberOfElements(),
maxHit ) ;
133 for(
int i=0 ; i< nHit ; ++i){
135 SimCalorimeterHit* sHit = (SimCalorimeterHit*) col->getElementAt(i) ;
142 Position point( sHit->getPosition()[0]* dd4hep::mm , sHit->getPosition()[1]* dd4hep::mm , sHit->getPosition()[2]* dd4hep::mm ) ;
150 std::stringstream sst ;
151 sst <<
" compare ids: " <<
det.name() <<
" " << idDecoder0.
valueString(
id) <<
" - " << idDecoder1.
valueString(idFromDecoder) ;
153 test(
id, idFromDecoder, sst.str() ) ;
156 tMap[ colNames[icol] ].cellid.passed++ ;
158 tMap[ colNames[icol] ].cellid.failed++ ;
162 double d =
dist(pointFromDecoder, point) ;
163 std::stringstream sst1 ;
164 sst1 <<
" dist " << d <<
" ( " << point <<
" ) - ( " << pointFromDecoder <<
" ) - detElement: "
167 test( d <
epsilon ,
true , sst1.str() ) ;
170 tMap[ colNames[icol] ].position.passed++ ;
172 tMap[ colNames[icol] ].position.failed++ ;
181 std::cout <<
"\n ----------------------- summary ---------------------- " << std::endl ;
184 for(
auto res : tMap ){
186 std::string name = res.first ;
187 unsigned total = res.second.position.passed+res.second.position.failed ;
188 unsigned pos_failed = res.second.position.failed ;
189 unsigned id_failed = res.second.cellid.failed ;
192 printf(
" %-30s \t failed position: %5d failed cellID: %5d of total: %5d \n",
193 name.c_str(), pos_failed , id_failed, total ) ;
196 std::cout <<
"\n -------------------------------------------------------- " << std::endl ;