How to attach custom parameter to LCIO object

Contents

Important note

It is strongly discouraged to modify any LCIO objects in any way for your personal analysis!!!

LCIO is supposed to be a single and common framework for multiple different experiments and analyses!

If something is missing which you think would be nice to have, communicate and ask, so it is implemented in the common software for general use.

For this you can open an issue for discussion in the github repository https://github.com/iLCSoft/LCIO/issues

With this in mind, LCIO objects are designed, so you cannot simply write your custom members to the class on will.

However, workaround exists to attach additional parameters to the ReconstructedParticle objects.

How to write custom parameters

You can use PIDHandler to attach a parameter to existing ReconstructedParticle object like this:

void MyWriteMarlinProcessor::processEvent(EVENT::LCEvent * evt){

    LCCollection* pfos = evt->getCollection("PandoraPFOs");
    PIDHandler pidHandler( pfos );

    int algoID = pidHandler.addAlgorithm( "MyCustomParameters", {"Awesomeness", "Cutiness"} );

    
    for (int i=0; i<pfos->getNumberOfElements(); ++i){
        ReconstructedParticle* pfo = static_cast <ReconstructedParticle*> ( pfos->getElementAt(i) );
        float awesomeness = std::sqrt( pfo->getEnergy()*42.);
        float cutiness = i*42/365.;

        std::vector<float> parameters = {awesomeness, cutiness};

        // This line attached our parameters to the specific pfo object inside our algorihm PID information.
        pidHandler.setParticleID(pfo , 0, 0, 0., algoID, parameters);
    }

}

You should be able to see corresponding lines saved in the dumpevent.

This does NOT write information to the actual slcio file stored on the disk which is being processed.

So this information will be accessible only within current Marlin run for further executed processors.

To save this information on a disk you will need to create an output file using e.g. LCIOOutputProcessor.

How to read custom parameters

Here is code example how to access attached parameters to the ReconstructedParticle:

// Simple utility function that extracts requested parameter from the PFO
float MyReadMarlinProcessor::getParameterFromPID(ReconstructedParticle* pfo, PIDHandler& pidHandler, std::string algorithmName, std::string parameterName){
    int algorithmID = pidHandler.getAlgorithmID(algorithmName);
    const ParticleID& pfoPID = pidHandler.getParticleID(pfo, algorithmID);
    const std::vector<float>& parameters = pfoPID.getParameters();
    int parIdx = pidHandler.getParameterIndex(algorithmID, parameterName);
    return parameters[parIdx]; 
}

void MyReadMarlinProcessor::processEvent(LCEvent* event){
    LCCollection* pfos = event->getCollection("PandoraPFOs");
    PIDHandler pidHandler(pfos);

    for(int i=0; i < pfos->getNumberOfElements(); ++i){
        ReconstructedParticle* pfo = static_cast <ReconstructedParticle*> ( pfos->getElementAt(i) );
        float awesomenessOfThisPFO = getParameterFromPID(pfo, pidHandler, "MyCustomParameters", "Awesomeness");
        float cutinessOfThisPFO = getParameterFromPID(pfo, pidHandler, "MyCustomParameters", "Cutiness");
    }
}

HowToAttachCustomParameterToLCIOObject (last edited 2022-06-20 16:31:04 by BohdanDudar)