CMS 3D CMS Logo

Classes | Public Member Functions | Private Member Functions | Private Attributes

TrackingTruthAccumulator Class Reference

Replacement for TrackingTruthProducer in the new pileup mixing setup. More...

#include <TrackingTruthAccumulator.h>

Inheritance diagram for TrackingTruthAccumulator:
DigiAccumulatorMixMod

List of all members.

Classes

struct  OutputCollections

Public Member Functions

 TrackingTruthAccumulator (const edm::ParameterSet &config, edm::EDProducer &mixMod)

Private Member Functions

virtual void accumulate (const edm::Event &event, const edm::EventSetup &setup)
virtual void accumulate (const PileUpEventPrincipal &event, const edm::EventSetup &setup)
template<class T >
void accumulateEvent (const T &event, const edm::EventSetup &setup)
 Both forms of accumulate() delegate to this templated method.
template<class T >
void fillSimHits (std::vector< const PSimHit * > &returnValue, const T &event, const edm::EventSetup &setup)
 Fills the supplied vector with pointers to the SimHits, checking for bad modules if required.
virtual void finalizeEvent (edm::Event &event, const edm::EventSetup &setup)
virtual void initializeEvent (const edm::Event &event, const edm::EventSetup &setup)

Private Attributes

const bool addAncestors_
 Whether or not to add the full parentage of any TrackingParticle that is inserted in the collection.
bool allowDifferentProcessTypeForDifferentDetectors_
 When counting hits, allows hits in different detectors to have a different process type.
bool chargedOnly_
 Uses the same config as selector_, but can be used to drop out early since selector_ requires the TrackingParticle to be created first.
const bool createMergedCollection_
const bool createUnmergedCollection_
 If bremsstrahlung merging, whether to also add the unmerged collection to the event or not.
edm::InputTag genParticleLabel_
const bool ignoreTracksOutsideVolume_
const unsigned int maximumPreviousBunchCrossing_
const unsigned int maximumSubsequentBunchCrossing_
OutputCollections mergedOutput_
const std::string messageCategory_
 The message category used to send messages to MessageLogger.
const bool removeDeadModules_
 As of 11/Feb/2013 this option hasn't been implemented yet.
TrackingParticleSelector selector_
bool selectorFlag_
bool signalOnly_
 Uses the same config as selector_, but can be used to drop out early since selector_ requires the TrackingParticle to be created first.
edm::ParameterSet simHitCollectionConfig_
const edm::InputTag simTrackLabel_
const edm::InputTag simVertexLabel_
OutputCollections unmergedOutput_
const double volumeRadius_
const double volumeZ_

Detailed Description

Replacement for TrackingTruthProducer in the new pileup mixing setup.

The configuration parameters are:

Parameter name Type Description
volumeRadius double The volume radius in cm used if ignoreTracksOutsideVolume is true.
volumeZ double The volume z in cm used if ignoreTracksOutsideVolume is true.
ignoreTracksOutsideVolume bool If true, sim tracks that have a production vertex outside the volume specified by volumeRadius and volumeZ won't be turned into TrackingParticles. Doesn't make much difference to be honest, over a huge range of volume sizes so there must be a cut earlier in the simulation.
maximumPreviousBunchCrossing unsigned int Bunch crossings before this number (inclusive; use positive integer) won't be included. Setting to zero means only in-time.
maximumSubsequentBunchCrossing unsigned int Bunch crossings after this won't create any TrackingParticles.
createUnmergedCollection bool Whether to create the TrackingParticle collection without bremsstrahlung merged.
createMergedBremsstrahlung bool Whether to create the TrackingParticle collection with bremsstrahlung merged. At least one of createUnmergedCollection or createMergedBremsstrahlung should be true otherwise nothing will be produced.
alwaysAddAncestors bool If a sim track passes selection and is turned into a TrackingParticle, all of it's parents will also be created even if they fail the selection. This was the default behaviour for the old TrackingParticleProducer.
removeDeadModules bool Hasn't been implemented yet (as of 22/May/2013).
simTrackCollection edm::InputTag The input SimTrack collection
simVertexCollection edm::InputTag The input SimVerted collection
simHitCollections edm::ParameterSet A ParameterSet of vectors of InputTags that are the input PSimHits
genParticleCollection edm::InputTag The input reco::GenParticle collection. Note that there's a difference between reco::GenParticle and HepMC::GenParticle; the old TrackingTruthProducer used to use HepMC::GenParticle.
allowDifferentSimHitProcesses bool Should be false for FullSim and true for FastSim. There's more documentation in the code if you're really interested.
select edm::ParameterSet A ParameterSet used to configure a TrackingParticleSelector. If the TrackingParticle doesn't pass this selector then it's not added to the output.
Author:
Mark Grimes (mark.grimes@bristol.ac.uk)
Date:
11/Oct/2012

Definition at line 64 of file TrackingTruthAccumulator.h.


Constructor & Destructor Documentation

TrackingTruthAccumulator::TrackingTruthAccumulator ( const edm::ParameterSet config,
edm::EDProducer mixMod 
) [explicit]

Definition at line 216 of file TrackingTruthAccumulator.cc.

References chargedOnly_, createMergedCollection_, createUnmergedCollection_, edm::ParameterSet::exists(), edm::ParameterSet::getParameter(), messageCategory_, selector_, selectorFlag_, and signalOnly_.

                                                                                                          :
                messageCategory_("TrackingTruthAccumulator"),
                volumeRadius_( config.getParameter<double>("volumeRadius") ),
                volumeZ_( config.getParameter<double>("volumeZ") ),
                ignoreTracksOutsideVolume_( config.getParameter<bool>("ignoreTracksOutsideVolume") ),
                maximumPreviousBunchCrossing_( config.getParameter<unsigned int>("maximumPreviousBunchCrossing") ),
                maximumSubsequentBunchCrossing_( config.getParameter<unsigned int>("maximumSubsequentBunchCrossing") ),
                createUnmergedCollection_( config.getParameter<bool>("createUnmergedCollection") ),
                createMergedCollection_(config.getParameter<bool>("createMergedBremsstrahlung") ),
                addAncestors_( config.getParameter<bool>("alwaysAddAncestors") ),
                removeDeadModules_( config.getParameter<bool>("removeDeadModules") ),
                simTrackLabel_( config.getParameter<edm::InputTag>("simTrackCollection") ),
                simVertexLabel_( config.getParameter<edm::InputTag>("simVertexCollection") ),
                simHitCollectionConfig_( config.getParameter<edm::ParameterSet>("simHitCollections") ),
                genParticleLabel_( config.getParameter<edm::InputTag>("genParticleCollection") ),
                allowDifferentProcessTypeForDifferentDetectors_( config.getParameter<bool>("allowDifferentSimHitProcesses") )
{
        //
        // Make sure at least one of the merged and unmerged collections have been set
        // to be created.
        //
        if( !createUnmergedCollection_ && !createMergedCollection_ )
                edm::LogError(messageCategory_) << "Both \"createUnmergedCollection\" and \"createMergedBremsstrahlung\" have been"
                        << "set to false, which means no collections will be created";


        //
        // Initialize selection for building TrackingParticles
        //
        if( config.exists( "select" ) )
        {
                edm::ParameterSet param=config.getParameter<edm::ParameterSet>("select");
                selector_=TrackingParticleSelector( param.getParameter<double>( "ptMinTP" ),
                                param.getParameter<double>( "minRapidityTP" ),
                                param.getParameter<double>( "maxRapidityTP" ),
                                param.getParameter<double>( "tipTP" ),
                                param.getParameter<double>( "lipTP" ),
                                param.getParameter<int>( "minHitTP" ),
                                param.getParameter<bool>( "signalOnlyTP" ),
                                param.getParameter<bool>( "chargedOnlyTP" ),
                                param.getParameter<bool>( "stableOnlyTP" ),
                                param.getParameter<std::vector<int> >("pdgIdTP") );
                selectorFlag_=true;

                // Also set these two variables, which are used to drop out early if the SimTrack doesn't conform.
                // The selector_ requires a full TrackingParticle object, but these two variables can veto things early.
                chargedOnly_=param.getParameter<bool>( "chargedOnlyTP" );
                signalOnly_=param.getParameter<bool>( "signalOnlyTP" );
        }
        else
        {
                selectorFlag_=false;
                chargedOnly_=false;
                signalOnly_=false;
        }

        //
        // Need to state what collections are going to be added to the event. This
        // depends on which of the merged and unmerged collections have been configured
        // to be created.
        //
        if( createUnmergedCollection_ )
        {
                mixMod.produces<TrackingVertexCollection>();
                mixMod.produces<TrackingParticleCollection>();
        }

        if( createMergedCollection_ )
        {
                mixMod.produces<TrackingParticleCollection>("MergedTrackTruth");
                mixMod.produces<TrackingVertexCollection>("MergedTrackTruth");
        }
}

Member Function Documentation

void TrackingTruthAccumulator::accumulate ( const edm::Event event,
const edm::EventSetup setup 
) [private, virtual]

Implements DigiAccumulatorMixMod.

Definition at line 309 of file TrackingTruthAccumulator.cc.

References accumulateEvent().

{
        // Call the templated version that does the same for both signal and pileup events
        accumulateEvent( event, setup );
}
void TrackingTruthAccumulator::accumulate ( const PileUpEventPrincipal event,
const edm::EventSetup setup 
) [private, virtual]

Implements DigiAccumulatorMixMod.

Definition at line 315 of file TrackingTruthAccumulator.cc.

References accumulateEvent(), PileUpEventPrincipal::bunchCrossing(), maximumPreviousBunchCrossing_, maximumSubsequentBunchCrossing_, and messageCategory_.

{
        // If this bunch crossing is outside the user configured limit, don't do anything.
        if( event.bunchCrossing()>=-static_cast<int>(maximumPreviousBunchCrossing_) && event.bunchCrossing()<=static_cast<int>(maximumSubsequentBunchCrossing_) )
        {
                //edm::LogInfo(messageCategory_) << "Analysing pileup event for bunch crossing " << event.bunchCrossing();
                accumulateEvent( event, setup );
        }
        else edm::LogInfo(messageCategory_) << "Skipping pileup event for bunch crossing " << event.bunchCrossing();
}
template<class T >
void TrackingTruthAccumulator::accumulateEvent ( const T event,
const edm::EventSetup setup 
) [private]

Both forms of accumulate() delegate to this templated method.

Definition at line 349 of file TrackingTruthAccumulator.cc.

References addAncestors_, allowDifferentProcessTypeForDifferentDetectors_, EncodedEventId::bunchCrossing(), CoreSimTrack::charge(), chargedOnly_, createMergedCollection_, createUnmergedCollection_, EncodedEventId::event(), CoreSimTrack::eventId(), exception, fillSimHits(), genParticleLabel_, ignoreTracksOutsideVolume_, getHLTprescales::index, mergedOutput_, NULL, CoreSimVertex::position(), selector_, selectorFlag_, signalOnly_, simTrackLabel_, simVertexLabel_, unmergedOutput_, volumeRadius_, and volumeZ_.

Referenced by accumulate().

{
        //
        // Get the collections
        //
        edm::Handle<std::vector<SimTrack> > hSimTracks;
        edm::Handle<std::vector<SimVertex> > hSimVertices;
        edm::Handle< std::vector<reco::GenParticle> > hGenParticles;
        edm::Handle< std::vector<int> > hGenParticleIndices;

        event.getByLabel( simTrackLabel_, hSimTracks );
        event.getByLabel( simVertexLabel_, hSimVertices );

        try
        {
                event.getByLabel( genParticleLabel_, hGenParticles );
                event.getByLabel( genParticleLabel_, hGenParticleIndices );
        }
        catch( cms::Exception& exception )
        {
                //
                // The Monte Carlo is not always available, e.g. for pileup events. The information
                // is only used if it's available, but for some reason the PileUpEventPrincipal
                // wrapper throws an exception here rather than waiting to see if the handle is
                // used (as is the case for edm::Event). So I just want to catch this exception
                // and use the normal handle checking later on.
                //
        }

        // Run through the collections and work out the decay chain of each track/vertex. The
        // information in SimTrack and SimVertex only allows traversing upwards, but this will
        // allow traversal in both directions. This is required for things like grouping electrons
        // that bremsstrahlung as one TrackingParticle if "mergedBremsstrahlung" is set in the
        // config file.
        DecayChain decayChain( *hSimTracks, *hSimVertices );

        // I only want to create these collections if they're actually required
        std::auto_ptr< ::OutputCollectionWrapper> pUnmergedCollectionWrapper;
        std::auto_ptr< ::OutputCollectionWrapper> pMergedCollectionWrapper;
        if( createUnmergedCollection_ ) pUnmergedCollectionWrapper.reset( new ::OutputCollectionWrapper( decayChain, unmergedOutput_ ) );
        if( createMergedCollection_ ) pMergedCollectionWrapper.reset( new ::OutputCollectionWrapper( decayChain, mergedOutput_ ) );

        std::vector<const PSimHit*> simHitPointers;
        fillSimHits( simHitPointers, event, setup );
        TrackingParticleFactory objectFactory( decayChain, hGenParticles, hGenParticleIndices, simHitPointers, volumeRadius_, volumeZ_, allowDifferentProcessTypeForDifferentDetectors_ );

        // While I'm testing, perform some checks.
        // TODO - drop this call once I'm happy it works in all situations.
        //decayChain.integrityCheck();

        TrackingParticleSelector* pSelector=NULL;
        if( selectorFlag_ ) pSelector=&selector_;

        // Run over all of the SimTracks, but because I'm interested in the decay hierarchy
        // do it through the DecayChainTrack objects. These are looped over in sequence here
        // but they have the hierarchy information for the functions called to traverse the
        // decay chain.

        for( size_t index=0; index<decayChain.decayTracksSize; ++index )
        {
                ::DecayChainTrack* pDecayTrack=&decayChain.decayTracks[index];
                const SimTrack& simTrack=hSimTracks->at(pDecayTrack->simTrackIndex);


                // Perform some quick checks to see if we can drop out early. Note that these are
                // a subset of the cuts in the selector_ so the created TrackingParticle could still
                // fail. The selector_ requires the full TrackingParticle to be made however, which
                // can be computationally expensive.
                if( chargedOnly_ && simTrack.charge()==0 ) continue;
                if( signalOnly_ && (simTrack.eventId().bunchCrossing()!=0 || simTrack.eventId().event()!=0) ) continue;

                // Also perform a check to see if the production vertex is inside the tracker volume (if required).
                if( ignoreTracksOutsideVolume_ )
                {
                        const SimVertex& simVertex=hSimVertices->at( pDecayTrack->pParentVertex->simVertexIndex );
                        if( !objectFactory.vectorIsInsideVolume( simVertex.position() ) ) continue;
                }


                // This function creates the TrackinParticle and adds it to the collection if it
                // passes the selection criteria specified in the configuration. If the config
                // specifies adding ancestors, the function is called recursively to do that.
                ::addTrack( pDecayTrack, pSelector, pUnmergedCollectionWrapper.get(), pMergedCollectionWrapper.get(), objectFactory, addAncestors_ );
        }
}
template<class T >
void TrackingTruthAccumulator::fillSimHits ( std::vector< const PSimHit * > &  returnValue,
const T event,
const edm::EventSetup setup 
) [private]

Fills the supplied vector with pointers to the SimHits, checking for bad modules if required.

Definition at line 435 of file TrackingTruthAccumulator.cc.

References edm::ParameterSet::getParameter(), edm::ParameterSet::getParameterNames(), and simHitCollectionConfig_.

Referenced by accumulateEvent().

{
        std::vector<std::string> parameterNames=simHitCollectionConfig_.getParameterNames();

        // loop over the different parameter collections. The names of these are unimportant but
        // usually set to the sub-detectors, e.g. "muon", "pixel" etcetera.
        for( const auto& parameterName : parameterNames )
        {
                std::vector<edm::InputTag> collectionTags=simHitCollectionConfig_.getParameter<std::vector<edm::InputTag> >(parameterName);

                for( const auto& collectionTag : collectionTags )
                {
                        edm::Handle< std::vector<PSimHit> > hSimHits;
                        event.getByLabel( collectionTag, hSimHits );

                        // TODO - implement removing the dead modules
                        for( const auto& simHit : *hSimHits )
                        {
                                returnValue.push_back( &simHit );
                        }

                } // end of loop over InputTags
        } // end of loop over parameter names. These are arbitrary but usually "muon", "pixel" etcetera.
}
void TrackingTruthAccumulator::finalizeEvent ( edm::Event event,
const edm::EventSetup setup 
) [private, virtual]

Implements DigiAccumulatorMixMod.

Definition at line 326 of file TrackingTruthAccumulator.cc.

References createMergedCollection_, createUnmergedCollection_, mergedOutput_, TrackingTruthAccumulator::OutputCollections::pTrackingParticles, TrackingTruthAccumulator::OutputCollections::pTrackingVertices, and unmergedOutput_.

{

        if( createUnmergedCollection_ )
        {
                edm::LogInfo("TrackingTruthAccumulator") << "Adding " << unmergedOutput_.pTrackingParticles->size() << " TrackingParticles and " << unmergedOutput_.pTrackingVertices->size()
                                << " TrackingVertexs to the event.";

                event.put( unmergedOutput_.pTrackingParticles );
                event.put( unmergedOutput_.pTrackingVertices );
        }

        if( createMergedCollection_ )
        {
                edm::LogInfo("TrackingTruthAccumulator") << "Adding " << mergedOutput_.pTrackingParticles->size() << " merged TrackingParticles and " << mergedOutput_.pTrackingVertices->size()
                                << " merged TrackingVertexs to the event.";

                event.put( mergedOutput_.pTrackingParticles, "MergedTrackTruth" );
                event.put( mergedOutput_.pTrackingVertices, "MergedTrackTruth" );
        }

}
void TrackingTruthAccumulator::initializeEvent ( const edm::Event event,
const edm::EventSetup setup 
) [private, virtual]

Member Data Documentation

Whether or not to add the full parentage of any TrackingParticle that is inserted in the collection.

Definition at line 96 of file TrackingTruthAccumulator.h.

Referenced by accumulateEvent().

When counting hits, allows hits in different detectors to have a different process type.

Fast sim PSimHits seem to have a peculiarity where the process type (as reported by PSimHit::processType()) is different for the tracker than the muons. When counting how many hits there are, the code usually only counts the number of hits that have the same process type as the first hit. Setting this to true will also count hits that have the same process type as the first hit in the second detector.

Definition at line 119 of file TrackingTruthAccumulator.h.

Referenced by accumulateEvent().

Uses the same config as selector_, but can be used to drop out early since selector_ requires the TrackingParticle to be created first.

Definition at line 108 of file TrackingTruthAccumulator.h.

Referenced by accumulateEvent(), and TrackingTruthAccumulator().

If bremsstrahlung merging, whether to also add the unmerged collection to the event or not.

Definition at line 93 of file TrackingTruthAccumulator.h.

Referenced by accumulateEvent(), finalizeEvent(), initializeEvent(), and TrackingTruthAccumulator().

Definition at line 103 of file TrackingTruthAccumulator.h.

Referenced by accumulateEvent().

Definition at line 84 of file TrackingTruthAccumulator.h.

Referenced by accumulateEvent().

The maximum bunch crossing BEFORE the signal crossing to create TrackinParticles for. Use positive values. If set to zero no previous bunches are added and only in-time, signal and after bunches (defined by maximumSubsequentBunchCrossing_) are used.

Definition at line 88 of file TrackingTruthAccumulator.h.

Referenced by accumulate().

The maximum bunch crossing AFTER the signal crossing to create TrackinParticles for. E.g. if set to zero only uses the signal and in time pileup (and previous bunches defined by the maximumPreviousBunchCrossing_ parameter).

Definition at line 91 of file TrackingTruthAccumulator.h.

Referenced by accumulate().

Definition at line 132 of file TrackingTruthAccumulator.h.

Referenced by accumulateEvent(), finalizeEvent(), and initializeEvent().

const std::string TrackingTruthAccumulator::messageCategory_ [private]

The message category used to send messages to MessageLogger.

Definition at line 80 of file TrackingTruthAccumulator.h.

Referenced by accumulate(), and TrackingTruthAccumulator().

As of 11/Feb/2013 this option hasn't been implemented yet.

Definition at line 99 of file TrackingTruthAccumulator.h.

Definition at line 106 of file TrackingTruthAccumulator.h.

Referenced by accumulateEvent(), and TrackingTruthAccumulator().

Definition at line 105 of file TrackingTruthAccumulator.h.

Referenced by accumulateEvent(), and TrackingTruthAccumulator().

Uses the same config as selector_, but can be used to drop out early since selector_ requires the TrackingParticle to be created first.

Definition at line 110 of file TrackingTruthAccumulator.h.

Referenced by accumulateEvent(), and TrackingTruthAccumulator().

Definition at line 102 of file TrackingTruthAccumulator.h.

Referenced by fillSimHits().

Definition at line 100 of file TrackingTruthAccumulator.h.

Referenced by accumulateEvent().

Definition at line 101 of file TrackingTruthAccumulator.h.

Referenced by accumulateEvent().

Definition at line 131 of file TrackingTruthAccumulator.h.

Referenced by accumulateEvent(), finalizeEvent(), and initializeEvent().

Definition at line 82 of file TrackingTruthAccumulator.h.

Referenced by accumulateEvent().

const double TrackingTruthAccumulator::volumeZ_ [private]

Definition at line 83 of file TrackingTruthAccumulator.h.

Referenced by accumulateEvent().