diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml new file mode 100644 index 0000000000000000000000000000000000000000..e5fe6afb120b02ee1d662f81e0c664b0a6da7aca --- /dev/null +++ b/.gitlab-ci.yml @@ -0,0 +1,11 @@ +before_script: + - ruby -v + - which ruby + +rspec: + script: + - bundle exec rspec + +rubocop: + script: + - bundle exec rubocop diff --git a/scripts/compact_geo_test2.cxx b/scripts/compact_geo_test2.cxx index 683be9a14f09557adb8bb078139fb76a66568e77..3025e49c521554a553bb6e9475d91693b6603e6d 100644 --- a/scripts/compact_geo_test2.cxx +++ b/scripts/compact_geo_test2.cxx @@ -37,9 +37,9 @@ std::vector<std::string> get_files_in_directory(std::string path = "data/.") { //______________________________________________________________________________ -void compact_geo_test( - const char* DIRNAME = "data/electrons", - const char* result_file_prefix = "SID_1T", +void compact_geo_test2( + const char* DIRNAME = "data/tests", + const char* result_file_prefix = "tests", const char* compact_file = "detectors/SiD/slic/sieic3/sieic3_compact.xml") //const char* compact_file = "detectors/SiD/compact/sid_working/sidloi3_v00.xml") { @@ -61,24 +61,75 @@ void compact_geo_test( TH1F * hZ0 = new TH1F("hZ0","Z;Z [mm];",100,-1000,1000); TH2F * hZR0 = new TH2F("hZR0","ZR;Z [mm];R [mm];",100,-1000,1000,100,0,1000); + using namespace DD4hep; + + DD4hep::Geometry::DetElement det = lcdd.detector( "SiVertexBarrel" ) ; + + //DD4hep::DDRec::SurfaceManager& surfMan = *lcdd.extension<DD4hep::DDRec::SurfaceManager>() ; + //_map = surfMan.map( det.name() ) ; + + //if( ! _map ) { + // std::stringstream err ; err << " Could not find surface map for detector: " + // << _subDetName << " in SurfaceManager " ; + // std::cout << err << std::endl;; + //} + auto readout = lcdd.readout("SiTrackerBarrelHits"); + auto det_el = lcdd.detector("SiVertexBarrel"); + auto vol_man = lcdd.volumeManager(); + std::cout << " detector type : " << det_el.type() << std::endl; + std::cout << " detector key : " << det_el.key() << std::endl; + std::cout << " detector level : " << det_el.level() << std::endl; + std::cout << " detector id : " << det_el.id() << std::endl; + std::cout << " detector ppath : " << det_el.placementPath() << std::endl; + std::cout << " children : " << det_el.children().size() << std::endl; + auto children = det_el.children(); + for(auto& child : children) { + //std::cout << " child : " << child.first << std::endl; + //std::cout << " child type : " << child.second.type() << std::endl; + //std::cout << " child key : " << child.second.key() << std::endl; + //std::cout << " child level : " << child.second.level() << std::endl; + //std::cout << " child id : " << child.second.id() << std::endl; + std::cout << " grandchildren: " << child.second.children().size() << std::endl; + for(auto& gc : child.second.children()) { + //std::cout << " grandchild : " << gc.first << std::endl; + //std::cout << " grandchild name : " << gc.second.name() << std::endl; + //std::cout << " grandchild type : " << gc.second.type() << std::endl; + //std::cout << " grandchild key : " << gc.second.key() << std::endl; + //std::cout << " grandchild level : " << gc.second.level() << std::endl; + std::cout << " grandgrandchildren: " << gc.second.children().size() << std::endl; + for(auto& g2c : gc.second.children()) { + std::cout << " g2child : " << g2c.first << std::endl; + std::cout << " g2child name : " << g2c.second.name() << std::endl; + std::cout << " g2child type : " << g2c.second.type() << std::endl; + std::cout << " g2child key : " << g2c.second.key() << std::endl; + std::cout << " g2child level : " << g2c.second.level() << std::endl; + std::cout << " g3children : " << g2c.second.children().size() << std::endl; + } + } + } + + auto seg = readout.segmentation(); + std::cout << " num col " << readout.numCollections() << std::endl; auto id = readout.idSpec(); + //std::cout << "id encode " << id.encode({1,0,1,3,1,0,0}) << std::endl; std::cout << " id spec " << id.toString() << std::endl; std::cout << " field " << id.fieldDescription() << std::endl; std::cout << " decoder " << id.decoder() << std::endl; auto bf = id.decoder(); - std::cout << " barrel " << bf->index("barrel")<<std::endl; - std::cout << " barrel " << (*bf)["barrel"].name() <<std::endl; - std::cout << " barrel " << (*bf)["barrel"].offset() <<std::endl; - std::cout << " barrel " << (*bf)["barrel"].width() <<std::endl; - std::cout << " barrel " << (*bf)["barrel"].value() <<std::endl; + //std::cout << " barrel " << bf->index("barrel")<<std::endl; + //std::cout << " barrel " << (*bf)["barrel"].name() <<std::endl; + //std::cout << " barrel " << (*bf)["barrel"].offset() <<std::endl; + //std::cout << " barrel " << (*bf)["barrel"].width() <<std::endl; + //std::cout << " barrel " << (*bf)["barrel"].value() <<std::endl; int max_files = 2; int nEvents = 0 ; int n_files_read = 0; - auto files = get_files_in_directory(DIRNAME); + //auto files = get_files_in_directory(DIRNAME); + std::vector<std::string> files = {"data/tests/slic_ddsim_out.slcio"}; IO::LCReader* lcReader = IOIMPL::LCFactory::getInstance()->createLCReader() ; EVENT::LCEvent* evt = 0 ; @@ -87,6 +138,8 @@ void compact_geo_test( std::sort(files.begin(),files.end()); + //auto id_decoder = DD4hep::DDRec::IDDecoder::getInstance() + for(auto aFile : files) { std::cout << "Opening " << aFile << '\n'; @@ -97,44 +150,89 @@ void compact_geo_test( while( (evt = lcReader->readNextEvent()) != 0 ) { if(nEvents%1000==0) { - if(nEvents==0)UTIL::LCTOOLS::dumpEvent( evt ) ; + if(nEvents==0) + UTIL::LCTOOLS::dumpEvent( evt ) ; std::cout << "Event " << nEvents << '\n'; } IMPL::LCCollectionVec* thrown_col = (IMPL::LCCollectionVec*) evt->getCollection( "MCParticle" ) ; - IMPL::LCCollectionVec* tracks_col = (IMPL::LCCollectionVec*) evt->getCollection( "Tracks" ) ; - IMPL::LCCollectionVec* simtrackhits_col = (IMPL::LCCollectionVec*) evt->getCollection("SiTrackerBarrelHits") ; + IMPL::LCCollectionVec* simtrackhits_col = (IMPL::LCCollectionVec*) evt->getCollection("SiVertexBarrelHits") ; + + UTIL::LCTOOLS::printSimTrackerHits( simtrackhits_col ); //UTIL::LCTOOLS::printMCParticles( col ) ; int nMCP = thrown_col->getNumberOfElements() ; - int nTracks = tracks_col->getNumberOfElements() ; - bool hasOneTrack = (nTracks==1); - bool hasTwoTracks = (nTracks==2); int nSimTrackHits = simtrackhits_col->getNumberOfElements() ; + CellIDDecoder<SimTrackerHit> lcio_id(simtrackhits_col); + for(int i_track=0 ; i_track<nSimTrackHits ; ++i_track) { auto ahit = (EVENT::SimTrackerHit*) simtrackhits_col->getElementAt(i_track); double hit_time = ahit->getTime(); double EDep = ahit->getEDep(); - //std::cout << "id " << ahit->id() << std::endl; + auto cell_id = ahit->getCellID0(); + //std::cout << "id " << ahit->getCellID0() << std::endl; //if(hit_time != 0.0) { // std::cout << " time " << hit_time << '\n'; //} TVector3 x0(ahit->getPosition()); TVector3 x1(ahit->getPosition()); x1.Print(); - auto cellid = seg.cellID( - DD4hep::Geometry::Position(x0.x(),x0.y(),x0.z()), - DD4hep::Geometry::Position(x1.x(),x1.y(),x1.z()), - 5); + //auto cellid = seg.cellID( + // DD4hep::Geometry::Position(x0.x(),x0.y(),x0.z()), + // DD4hep::Geometry::Position(x1.x(),x1.y(),x1.z()), + // 1); // std::cout << " cellid " << cellid << std::endl; - auto pos = seg.position(cellid); + //if(col->getParameters().getStringVal(LCIO::CellIDEncoding) != ""){ + std::cout << " id-fields: ("<< lcio_id(const_cast<EVENT::SimTrackerHit*>(ahit)).valueString() << ")" << std::endl ; + + //auto det_el_mod = det_el.children(lcio_bf["layer" ].value() + + //auto lcio_bf = lcio_id(const_cast<EVENT::SimTrackerHit*>(ahit)); + //auto bf = id.decoder(); + //bf->setValue( lcio_bf.getValue() ); + + //DD4hep::Geometry::IDDescriptor an_id(lcio_id(const_cast<EVENT::SimTrackerHit*>(ahit)).valueString()); + // + //auto bf2 = (*bf) ; + //(bf2)["system"] = lcio_bf["system"].value(); + //(bf2)["barrel"] = lcio_bf["barrel"].value(); + //(bf2)["layer" ] = lcio_bf["layer" ].value(); + //(bf2)["module"] = lcio_bf["module"].value(); + //(bf2)["sensor"] = 0;//lcio_bf["sensor"].value(); + //(bf2)["side" ] = 0;//lcio_bf["side" ].value(); + //(bf2)["strip" ] = 0;//lcio_bf["strip" ].value(); + + //std::cout << " DD4hep bf value " << bf2.getValue() << std::endl; + //std::cout << " Lcio bf value " << lcio_bf.getValue() << std::endl; + + //auto pv = vol_man.lookupPlacement(bf2.getValue()); + //std::cout << pv.toString() << std::endl; + + //std::vector<double> v = {0,0,0}; + //pv->LocalToMaster(pv->GetMatrix()->GetTranslation(),&v[0] ); + //TVector3 aPos(&v[0] ); + //aPos.Print(); + ////pv.name() + + //std::cout << "system" << lcio_bf["system"].value() << std::endl; + //std::cout << "barrel" << lcio_bf["barrel"].value() << std::endl; + //std::cout << "layer " << lcio_bf["layer" ].value() << std::endl; + //std::cout << "module" << lcio_bf["module"].value() << std::endl; + //std::cout << "sensor" << lcio_bf["sensor"].value() << std::endl; + //std::cout << "side " << lcio_bf["side" ].value() << std::endl; + //std::cout << "strip " << lcio_bf["strip" ].value() << std::endl; + + //seg.setDecoder( bf ); + + //auto cell_id2 = lcio_bf.getValue(); + //auto pos = seg.position(cell_id2); //std::cout << " x=" << pos.x() << ", y=" << pos.y() << ", z=" << pos.z() << std::endl; - //std::cout << " R = " << pos.R() << std::endl; - //std::cout << " rho = " << pos.Rho() << std::endl; - hR0->Fill(pos.R()); - hZR0->Fill(pos.Z(),pos.R()); + ////std::cout << " R = " << pos.R() << std::endl; + ////std::cout << " rho = " << pos.Rho() << std::endl; + //hR0->Fill(pos.R()); + //hZR0->Fill(pos.Z(),pos.R()); //if(nTracks>1) { // std::cout << (*track) << std::endl;