Linear Collider Forum



Home » Software Tools » LCIO » Meeting Minutes
Re: Minutes of Meeting 2004-09-14 [message #156 is a reply to message #155] Thu, 18 November 2004 03:10 Go to previous message
gaede
Messages: 232
Registered: January 2004
Location: DESY, Hamburg
Hi Guilherme,

LCRelations are stored in ordinary LCCollections as any other LCObject. Some example code is in src/cpp/src/EXAMPLE/recjob.cc.
For your case you'd do sth. like:


    LCCollectionVec* calHits = new LCCollectionVec( LCIO::RAWCALORIMETERHIT )  ;



    LCCollectionVec* scRel = new LCCollectionVec(LCIO::LCRELATION ) ;
    scRel->parameters().setValue( "RelationFromType" ,  LCIO::RAWCALORIMETERHIT ) ;
    scRel->parameters().setValue( "RelationToType"   ,  LCIO::SIMCALORIMETERHIT ) ;


    // use collection of existing SimCalorimeterHits
    int nSimHits = simcalHits->getNumberOfElements() ;
    for(int j=0;j<nSimHits;j++){

      RawCalorimeterHitImpl* calHit = new RawCalorimeterHitImpl ;

      SimCalorimeterHit* simcalHit =  dynamic_cast<SimCalorimeterHit*> ( simcalHits->getElementAt(j)  ) ;
       // the cast is only needed to access the SimCalorimeterHit's attributes
       // for the relation you can treat it as LCObject:
       // LCObject* simcalHit = simcalHits->getElementAt(j) ;
     
      // set calHit attributes 
      //  ....


      // add relation
      scRel->addElement( new LCRelationImpl( calHit , simcalHit , 1.0 ) ) ;

      // this assumes 1-1 relation 
      // if you have n-m (e.g. due to crosstalk)
      // you can add as many relations as needed
      // possibly using the weight as (relative) energy            
      // contribution

      calHits->addElement( calHit ) ;
    }
    evt->addCollection( calHits , "CalorimeterHits") ;

    LCFlagImpl relFlag(0) ;
    relFlag.setBit( LCIO::LCREL_WEIGHTED ) ;
    scRel->setFlag( relFlag.getFlag()  ) ;

    evt->addCollection( scRel , "CalorimeterHitsSimRel" ) ;





For reading back the relations there is a convenience class LCRelationNavigator that makes it easier to access the information, example code is also in recjob.cc.
I hope this helps.
Cheers, Frank.
 
Read Message
Read Message icon2.gif
Read Message feedback.gif
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Previous Topic:segfaulting PIDHandler in python
Goto Forum:
  


Current Time: Tue Aug 14 20:42:48 Pacific Daylight Time 2018
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.1.
Copyright ©2001-2010 FUDforum Bulletin Board Software