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"
37 static DDTest test(
"cellid_position_converter" ) ;
41 const double epsilon = dd4hep::micrometer ;
61 typedef std::map<std::string, TestCounters >
TestMap ;
68 std::cout <<
" usage: test_cellid_position_converter compact.xml lcio_file.slcio" << std::endl ;
72 std::string inFile = argv[1] ;
74 Detector& description = Detector::getInstance();
85 std::string lcioFileName = argv[2] ;
87 LCReader* rdr = LCFactory::getInstance()->createLCReader() ;
88 rdr->open( lcioFileName ) ;
94 std::set< std::string > subset = {} ;
99 std::set< std::string > subsetIgnore = {
"HCalBarrelRPCHits",
"HCalECRingRPCHits",
"HCalEndcapRPCHits" } ;
103 while( ( evt = rdr->readNextEvent() ) != 0 ){
105 const std::vector< std::string >& colNames = *evt->getCollectionNames() ;
107 for(
unsigned icol=0, ncol = colNames.size() ; icol < ncol ; ++icol ){
109 LCCollection* col = evt->getCollection( colNames[ icol ] ) ;
111 std::string typeName = col->getTypeName() ;
113 if( typeName != lcio::LCIO::SIMCALORIMETERHIT )
116 if( !subset.empty() && subset.find( colNames[icol] ) == subset.end() )
119 if( !subsetIgnore.empty() && subsetIgnore.find( colNames[icol] ) != subsetIgnore.end() )
122 std::cout <<
" -- testing collection : " << colNames[ icol ] << std::endl ;
124 std::string cellIDEcoding = col->getParameters().getStringVal(
"CellIDEncoding") ;
129 int nHit = std::min( col->getNumberOfElements(),
maxHit ) ;
132 for(
int i=0 ; i< nHit ; ++i){
134 SimCalorimeterHit* sHit = (SimCalorimeterHit*) col->getElementAt(i) ;
141 Position point( sHit->getPosition()[0]* dd4hep::mm , sHit->getPosition()[1]* dd4hep::mm , sHit->getPosition()[2]* dd4hep::mm ) ;
149 std::stringstream sst ;
150 sst <<
" compare ids: " <<
det.name() <<
" " << idDecoder0.
valueString(
id) <<
" - " << idDecoder1.
valueString(idFromDecoder) ;
152 test(
id, idFromDecoder, sst.str() ) ;
155 tMap[ colNames[icol] ].cellid.passed++ ;
157 tMap[ colNames[icol] ].cellid.failed++ ;
161 double d =
dist(pointFromDecoder, point) ;
162 std::stringstream sst1 ;
163 sst1 <<
" dist " << d <<
" ( " << point <<
" ) - ( " << pointFromDecoder <<
" ) - detElement: "
166 test( d <
epsilon ,
true , sst1.str() ) ;
169 tMap[ colNames[icol] ].position.passed++ ;
171 tMap[ colNames[icol] ].position.failed++ ;
180 std::cout <<
"\n ----------------------- summary ---------------------- " << std::endl ;
183 for(
const auto& res : tMap ) {
184 const std::string& name = res.first;
185 unsigned total = res.second.position.passed+res.second.position.failed ;
186 unsigned pos_failed = res.second.position.failed ;
187 unsigned id_failed = res.second.cellid.failed ;
190 printf(
" %-30s \t failed position: %5d failed cellID: %5d of total: %5d \n",
191 name.c_str(), pos_failed , id_failed, total ) ;
194 std::cout <<
"\n -------------------------------------------------------- " << std::endl ;