Skip to content

Commit

Permalink
Merge v02-12-05 for ILCSoft
Browse files Browse the repository at this point in the history
  • Loading branch information
pandreetto committed May 31, 2024
2 parents 64539f3 + 5503ee6 commit 442e9e6
Show file tree
Hide file tree
Showing 8 changed files with 65 additions and 104 deletions.
27 changes: 7 additions & 20 deletions .github/workflows/key4hep.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,27 +5,14 @@ jobs:
build-and-test:
runs-on: ubuntu-latest
strategy:
matrix:
build_type: ["release", "nightly"]
image: ["alma9", "ubuntu22", "centos7"]
fail-fast: false

steps:
- uses: actions/checkout@v3
- uses: cvmfs-contrib/github-action-cvmfs@v3
- uses: aidasoft/run-lcg-view@v4
- uses: actions/checkout@v4
- uses: key4hep/key4hep-actions/key4hep-build@main
with:
container: centos7
view-path: /cvmfs/sw-nightlies.hsf.org/key4hep
run: |
mkdir build
cd build
echo "::group::Run CMake"
cmake -GNinja \
-DCMAKE_CXX_FLAGS=" -fdiagnostics-color=always " \
-DCMAKE_CXX_STANDARD=17 \
-DCMAKE_INSTALL_PREFIX=../install \
..
echo "::endgroup::" && echo "::group::Build"
ninja -k0
echo "::endgroup::" && echo "::group::Run Tests"
ctest --output-on-failure
echo "::endgroup::" && echo "::group::Install"
ninja install
build_type: ${{ matrix.build_type }}
image: ${{ matrix.image }}
8 changes: 4 additions & 4 deletions .github/workflows/linux.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@ jobs:
strategy:
fail-fast: false
matrix:
COMPILER: [gcc10, clang11]
LCG: [100]
COMPILER: [gcc11]
LCG: [104]

steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
- uses: cvmfs-contrib/github-action-cvmfs@v3
- uses: aidasoft/run-lcg-view@v4
with:
Expand All @@ -20,7 +20,7 @@ jobs:
run: |
mkdir build
cd build
cmake -GNinja -C ${ILCSOFT}/ILCSoft.cmake -DCMAKE_CXX_FLAGS=" -fdiagnostics-color=always " -DINSTALL_DOC=ON ..
cmake -GNinja -C ${ILCSOFT}/ILCSoft.cmake -DCMAKE_CXX_FLAGS=" -fdiagnostics-color=always " ..
ninja -k0
ctest --output-on-failure
ninja install
10 changes: 10 additions & 0 deletions doc/ReleaseNotes.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,13 @@
# v02-12-05

* 2024-02-16 tmadlener ([PR#69](https://github.com/iLCSoft/MarlinTrkProcessors/pull/69))
- Use the `LCRelationNavigator` to create output relation collections with the necessary type information.
- This is necessary for automatic conversion from LCIO to EDM4hep when used within the MarlinWrapper and Gaudi.

* 2024-02-16 tmadlener ([PR#68](https://github.com/iLCSoft/MarlinTrkProcessors/pull/68))
- Switch to the `key4hep-build` github action for building against key4hep stacks
- Update the clicdp nightlies based workflow to the latest available version of the nightlies

# v02-12-04

* 2023-06-12 tmadlener ([PR#66](https://github.com/iLCSoft/MarlinTrkProcessors/pull/66))
Expand Down
9 changes: 6 additions & 3 deletions source/Digitisers/include/DDTPCDigiProcessor.h
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,10 @@ class Voxel_tpc;

class TPCModularEndplate ;

namespace UTIL {
class LCRelationNavigator;
}

/** ====== DDTPCDigiProcessor ====== <br>
*
* This Processor depends on Circle.h from MarlinUtil
Expand Down Expand Up @@ -138,8 +142,8 @@ class DDTPCDigiProcessor : public marlin::Processor {
*/
virtual void end() ;

void writeVoxelToHit( Voxel_tpc* aVoxel) ;
void writeMergedVoxelsToHit( std::vector <Voxel_tpc*>* hitList ) ;
void writeVoxelToHit( Voxel_tpc* aVoxel, UTIL::LCRelationNavigator& hitSimHitNav) ;
void writeMergedVoxelsToHit( std::vector <Voxel_tpc*>* hitList, UTIL::LCRelationNavigator& hitSimHitNav ) ;
void plotHelixHitResidual(MCParticle *mcp, CLHEP::Hep3Vector *thisPointRPhi);
double getPadPhi( CLHEP::Hep3Vector* thisPointRPhi, CLHEP::Hep3Vector* firstPointRPhi, CLHEP::Hep3Vector* middlePointRPhi, CLHEP::Hep3Vector* lastPointRPhi);
double getPadTheta( CLHEP::Hep3Vector* firstPointRPhi, CLHEP::Hep3Vector* middlePointRPhi, CLHEP::Hep3Vector* lastPointRPhi );
Expand Down Expand Up @@ -204,7 +208,6 @@ class DDTPCDigiProcessor : public marlin::Processor {
int lenpos{};

LCCollectionVec* _trkhitVec{};
LCCollectionVec* _relCol{};
CellIDEncoder<TrackerHitImpl>* _cellid_encoder {};

int _NSimTPCHits{};
Expand Down
33 changes: 7 additions & 26 deletions source/Digitisers/src/DDSpacePointBuilder.cc
Original file line number Diff line number Diff line change
Expand Up @@ -176,14 +176,10 @@ void DDSpacePointBuilder::processEvent( LCEvent * evt ) {


LCCollectionVec * spCol = new LCCollectionVec(LCIO::TRACKERHIT); // output spacepoint collection
LCCollectionVec* relCol = new LCCollectionVec(LCIO::LCRELATION); // outpur relation collection

// to store the weights
LCFlagImpl lcFlag(0) ;
lcFlag.setBit( LCIO::LCREL_WEIGHTED ) ;
relCol->setFlag( lcFlag.getFlag() ) ;



// Relation navigator for creating SpacePoint - SimTrackerHit relations
auto spSimHitNav = UTIL::LCRelationNavigator(LCIO::TRACKERHIT, LCIO::SIMTRACKERHIT);

unsigned nHits = col->getNumberOfElements() ;

streamlog_out(DEBUG3) << "Number of hits: " << nHits <<"\n";
Expand Down Expand Up @@ -304,38 +300,22 @@ void DDSpacePointBuilder::processEvent( LCEvent * evt ) {

///////////////////////////////
// make the relations

if( simHitsFront.size() == 1 ){

SimTrackerHit* simHit = dynamic_cast< SimTrackerHit* >( simHitsFront[0] );

if( simHit != NULL ){
LCRelationImpl* rel = new LCRelationImpl;
rel->setFrom (spacePoint);
rel->setTo (simHit);
rel->setWeight( 0.5 );
relCol->addElement(rel);
spSimHitNav.addRelation(spacePoint, simHit, 0.5);
}
}



if( simHitsBack.size() == 1 ){

SimTrackerHit* simHit = dynamic_cast< SimTrackerHit* >( simHitsBack[0] );

if( simHit != NULL ){
LCRelationImpl* rel = new LCRelationImpl;
rel->setFrom (spacePoint);
rel->setTo (simHit);
rel->setWeight( 0.5 );
relCol->addElement(rel);
spSimHitNav.addRelation(spacePoint, simHit, 0.5);
}
}




} else {

if ( ghost_hit == true ) {
Expand All @@ -356,6 +336,7 @@ void DDSpacePointBuilder::processEvent( LCEvent * evt ) {
}

evt->addCollection( spCol, _SpacePointsCollection);
auto* relCol = spSimHitNav.createLCCollection();
evt->addCollection( relCol , _relColName ) ;

streamlog_out(DEBUG3)<< "\nCreated " << createdSpacePoints
Expand Down
39 changes: 14 additions & 25 deletions source/Digitisers/src/DDTPCDigiProcessor.cc
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
//
#include "UTIL/LCTrackerConf.h"
#include <UTIL/ILDConf.h>
#include <UTIL/LCRelationNavigator.h>

// --- DD4hep ---
#include "DD4hep/Detector.h"
Expand Down Expand Up @@ -500,12 +501,8 @@ void DDTPCDigiProcessor::processEvent( LCEvent * evt )

// created the collection which will be written out
_trkhitVec = new LCCollectionVec( LCIO::TRACKERHIT ) ;
_relCol = new LCCollectionVec(LCIO::LCRELATION);

// to store the weights
LCFlagImpl lcFlag(0) ;
lcFlag.setBit( LCIO::LCREL_WEIGHTED ) ;
_relCol->setFlag( lcFlag.getFlag() ) ;
// relations from created trackerhits to the SimTrackerHits that caused them
auto hitSimHitNav = UTIL::LCRelationNavigator(LCIO::TRACKERHIT, LCIO::SIMTRACKERHIT);

_cellid_encoder = new CellIDEncoder<TrackerHitImpl>( lcio::LCTrackerCellID::encoding_string() , _trkhitVec ) ;

Expand Down Expand Up @@ -1017,7 +1014,7 @@ void DDTPCDigiProcessor::processEvent( LCEvent * evt )
}

if(seed_hit->getNumberOfAdjacent()==0){ // no adjacent hits so smear and write to hit collection
writeVoxelToHit(seed_hit);
writeVoxelToHit(seed_hit, hitSimHitNav);
}

else if(seed_hit->getNumberOfAdjacent() < (_maxMerge)){ // potential 3-hit cluster, can use simple average merge.
Expand All @@ -1028,7 +1025,7 @@ void DDTPCDigiProcessor::processEvent( LCEvent * evt )

if( clusterSize <= _maxMerge ){ // merge cluster
seed_hit->setIsMerged();
writeMergedVoxelsToHit(hitsToMerge);
writeMergedVoxelsToHit(hitsToMerge, hitSimHitNav);
}
delete hitsToMerge;
}
Expand Down Expand Up @@ -1074,7 +1071,8 @@ void DDTPCDigiProcessor::processEvent( LCEvent * evt )

// add the collection to the event
evt->addCollection( _trkhitVec , _TPCTrackerHitsCol ) ;
evt->addCollection( _relCol , _outRelColName ) ;
auto relCol = hitSimHitNav.createLCCollection();
evt->addCollection( relCol , _outRelColName ) ;

// delete voxels
for (unsigned int i = 0; i<_tpcRowHits.size(); ++i){
Expand Down Expand Up @@ -1149,7 +1147,7 @@ void DDTPCDigiProcessor::end()
//
}

void DDTPCDigiProcessor::writeVoxelToHit( Voxel_tpc* aVoxel){
void DDTPCDigiProcessor::writeVoxelToHit( Voxel_tpc* aVoxel, UTIL::LCRelationNavigator& hitSimHitNav){


Voxel_tpc* seed_hit = aVoxel;
Expand Down Expand Up @@ -1261,13 +1259,8 @@ void DDTPCDigiProcessor::writeVoxelToHit( Voxel_tpc* aVoxel){
trkHit->rawHits().push_back( _tpcHitMap[seed_hit] );
}

LCRelationImpl* rel = new LCRelationImpl;

rel->setFrom (trkHit);
rel->setTo (_tpcHitMap[seed_hit]);
rel->setWeight( 1.0 );
_relCol->addElement(rel);

hitSimHitNav.addRelation(trkHit, _tpcHitMap[seed_hit], 1.0);

_trkhitVec->addElement( trkHit );
_NRecTPCHits++;
}
Expand Down Expand Up @@ -1298,7 +1291,7 @@ void DDTPCDigiProcessor::writeVoxelToHit( Voxel_tpc* aVoxel){
#endif
}

void DDTPCDigiProcessor::writeMergedVoxelsToHit( vector <Voxel_tpc*>* hitsToMerge){
void DDTPCDigiProcessor::writeMergedVoxelsToHit( vector <Voxel_tpc*>* hitsToMerge, UTIL::LCRelationNavigator& hitSimHitNav){


TrackerHitImpl* trkHit = new TrackerHitImpl ;
Expand All @@ -1324,13 +1317,9 @@ void DDTPCDigiProcessor::writeMergedVoxelsToHit( vector <Voxel_tpc*>* hitsToMerg
trkHit->rawHits().push_back( _tpcHitMap[hitsToMerge->at(ihitCluster)] );
}

LCRelationImpl* rel = new LCRelationImpl;

rel->setFrom (trkHit);
rel->setTo (_tpcHitMap[ hitsToMerge->at(ihitCluster) ]);
rel->setWeight( float(1.0/number_of_hits_to_merge) );
_relCol->addElement(rel);

hitSimHitNav.addRelation(trkHit,
_tpcHitMap[hitsToMerge->at(ihitCluster)],
float(1.0/number_of_hits_to_merge));
}

double avgZ = sumZ/(hitsToMerge->size());
Expand Down
4 changes: 3 additions & 1 deletion source/Refitting/include/RefitProcessor.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@

#include <EVENT/TrackerHit.h>

#include <memory>

namespace MarlinTrk{
class IMarlinTrkSystem ;
}
Expand Down Expand Up @@ -79,7 +81,7 @@ class RefitProcessor : public marlin::Processor {
lcio::LCCollection* GetCollection( lcio::LCEvent * evt, std::string colName ) ;

/* helper function to get relations using try catch block */
lcio::LCRelationNavigator* GetRelations(lcio::LCEvent * evt, std::string RelName ) ;
std::unique_ptr<lcio::LCRelationNavigator> GetRelations(lcio::LCEvent * evt, std::string RelName ) ;

/** Input track collection name for refitting.
*/
Expand Down
39 changes: 14 additions & 25 deletions source/Refitting/src/RefitProcessor.cc
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ void RefitProcessor::processEvent( LCEvent * evt ) {
// get input collection and relations
LCCollection* input_track_col = this->GetCollection( evt, _input_track_col_name ) ;

LCRelationNavigator* input_track_rels = this->GetRelations( evt, _input_track_rel_name ) ;
auto input_track_rels = this->GetRelations( evt, _input_track_rel_name ) ;

if( input_track_col != 0 ){

Expand All @@ -207,12 +207,11 @@ void RefitProcessor::processEvent( LCEvent * evt ) {
LCFlagImpl trkFlag(0) ;
trkFlag.setBit( LCIO::TRBIT_HITS ) ;
trackVec->setFlag( trkFlag.getFlag() ) ;
// establish the track relations collection that will be created
LCCollectionVec* trackRelVec = new LCCollectionVec( LCIO::LCRELATION ) ;

// establish the track relations collection that will be created
auto trackRelNav = UTIL::LCRelationNavigator(LCIO::TRACK, LCIO::MCPARTICLE);

int nTracks = input_track_col->getNumberOfElements() ;

streamlog_out(DEBUG4) << "Processing input collection " << _input_track_col_name << " with " << nTracks << " tracks\n";

// loop over the input tacks and refit using KalTest
Expand Down Expand Up @@ -394,28 +393,18 @@ void RefitProcessor::processEvent( LCEvent * evt ) {

// assign the relations previously assigned to the input tracks
if(input_track_rels){
LCObjectVec objVec = input_track_rels->getRelatedToObjects( track_to_refit );
FloatVec weights = input_track_rels->getRelatedToWeights( track_to_refit );
const auto& objVec = input_track_rels->getRelatedToObjects( track_to_refit );
const auto& weights = input_track_rels->getRelatedToWeights( track_to_refit );

for( unsigned int irel=0 ; irel < objVec.size() ; ++irel ){

LCRelationImpl* rel = new LCRelationImpl ;
rel->setFrom (refittedTrack) ;
rel->setTo ( objVec[irel] ) ;
rel->setWeight(weights[irel]) ;
trackRelVec->addElement( rel );

trackRelNav.addRelation(refittedTrack, objVec[irel], weights[irel]);
}
}



}
}

evt->addCollection( trackVec , _output_track_col_name) ;
auto trackRelVec = trackRelNav.createLCCollection();
evt->addCollection( trackRelVec , _output_track_rel_name) ;
delete input_track_rels; input_track_rels = 0;

}
++_n_evt ;
}
Expand Down Expand Up @@ -452,13 +441,13 @@ LCCollection* RefitProcessor::GetCollection( LCEvent * evt, std::string colName

}

LCRelationNavigator* RefitProcessor::GetRelations(LCEvent * evt , std::string RelName ) {
std::unique_ptr<LCRelationNavigator> RefitProcessor::GetRelations(LCEvent * evt , std::string RelName ) {

LCRelationNavigator* nav = 0 ;
std::unique_ptr<UTIL::LCRelationNavigator> nav = nullptr;

try{
nav = new LCRelationNavigator(evt->getCollection( RelName.c_str() ));
streamlog_out( DEBUG2 ) << "RefitProcessor --> " << RelName << " track relation collection in event = " << nav << std::endl;
nav.reset(new LCRelationNavigator(evt->getCollection( RelName.c_str() )));
streamlog_out( DEBUG2 ) << "RefitProcessor --> " << RelName << " track relation collection in event = " << nav.get() << std::endl;
}
catch(DataNotAvailableException &e){
streamlog_out( DEBUG2 ) << "RefitProcessor --> " << RelName.c_str() << " track relation collection absent in event" << std::endl;
Expand Down

0 comments on commit 442e9e6

Please sign in to comment.