Skip to content

Commit

Permalink
Make sure to set the necessary type information in relation collectio…
Browse files Browse the repository at this point in the history
…ns that are created (#69)

* Make the SpacePoint relations carry type information

Necessary for automatic conversion to EDM4hep

* Use unique_ptr to manage memory

* Make sure to propagate type information into the relation

* Make sure to keep necessary type information in output relations
  • Loading branch information
tmadlener authored Feb 16, 2024
1 parent b7126a9 commit f37b282
Show file tree
Hide file tree
Showing 5 changed files with 44 additions and 80 deletions.
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 f37b282

Please sign in to comment.