CMS 3D CMS Logo

Public Member Functions | Private Types | Private Member Functions | Private Attributes

CandIsoDepositProducer Class Reference

#include <CandIsoDepositProducer.h>

Inheritance diagram for CandIsoDepositProducer:
edm::EDProducer edm::ProducerBase edm::ProductRegistryHelper

List of all members.

Public Member Functions

 CandIsoDepositProducer (const edm::ParameterSet &)
 constructor with config
virtual void produce (edm::Event &, const edm::EventSetup &)
 build deposits
virtual ~CandIsoDepositProducer ()
 destructor

Private Types

enum  TrackType {
  FakeT, BestT, StandAloneMuonT, CombinedMuonT,
  TrackT, GsfT, CandidateT
}

Private Member Functions

const reco::TrackextractTrack (const reco::Candidate &cand, reco::Track *dummyStorage) const

Private Attributes

edm::InputTag theCandCollectionTag
edm::ParameterSet theConfig
std::vector< std::string > theDepositNames
reco::isodeposit::IsoDepositExtractortheExtractor
bool theMultipleDepositsFlag
TrackType theTrackType

Detailed Description

Definition at line 19 of file CandIsoDepositProducer.h.


Member Enumeration Documentation

Enumerator:
FakeT 
BestT 
StandAloneMuonT 
CombinedMuonT 
TrackT 
GsfT 
CandidateT 

Definition at line 30 of file CandIsoDepositProducer.h.


Constructor & Destructor Documentation

CandIsoDepositProducer::CandIsoDepositProducer ( const edm::ParameterSet par)

constructor with config

Definition at line 33 of file CandIsoDepositProducer.cc.

References BestT, CandidateT, CombinedMuonT, Exception, FakeT, reco::get(), edm::ParameterSet::getParameter(), GsfT, LogDebug, StandAloneMuonT, AlCaHLTBitMon_QueryRunRegistry::string, theConfig, theDepositNames, theExtractor, theMultipleDepositsFlag, theTrackType, and TrackT.

                                                                      :
  theConfig(par),
  theCandCollectionTag(par.getParameter<edm::InputTag>("src")),
  theDepositNames(std::vector<std::string>(1,"")),
  theMultipleDepositsFlag(par.getParameter<bool>("MultipleDepositsFlag")),
  theExtractor(0)
  {
  LogDebug("PhysicsTools|MuonIsolation")<<" CandIsoDepositProducer CTOR";

  edm::ParameterSet extractorPSet = theConfig.getParameter<edm::ParameterSet>("ExtractorPSet");
  std::string extractorName = extractorPSet.getParameter<std::string>("ComponentName");
  theExtractor = IsoDepositExtractorFactory::get()->create( extractorName, extractorPSet);

  if (! theMultipleDepositsFlag) produces<reco::IsoDepositMap>();
  else {
    theDepositNames = extractorPSet.getParameter<std::vector<std::string> >("DepositInstanceLabels");
    if (theDepositNames.size() > 10) throw cms::Exception("Configuration Error") << "This module supports only up to 10 deposits"; 
    for (unsigned int iDep=0; iDep<theDepositNames.size(); ++iDep){
      produces<reco::IsoDepositMap>(theDepositNames[iDep]);
    }
  }

  std::string trackType = par.getParameter<std::string>("trackType");
  if      (trackType == "fake") theTrackType = FakeT;
  else if (trackType == "best") theTrackType = BestT;
  else if (trackType == "standAloneMuon") theTrackType = StandAloneMuonT;
  else if (trackType == "combinedMuon")   theTrackType = CombinedMuonT;
  else if (trackType == "trackerMuon")    theTrackType = TrackT;
  else if (trackType == "track") theTrackType = TrackT;
  else if (trackType == "gsf") theTrackType = GsfT;
  else if (trackType == "candidate") theTrackType = CandidateT;
  else throw cms::Exception("Error")  << "Track type " << trackType << " not valid.";
}
CandIsoDepositProducer::~CandIsoDepositProducer ( ) [virtual]

destructor

Definition at line 68 of file CandIsoDepositProducer.cc.

References LogDebug, and theExtractor.

                                               {
  LogDebug("PhysicsTools/CandIsoDepositProducer")<<" CandIsoDepositProducer DTOR";
  delete theExtractor;
}

Member Function Documentation

const reco::Track * CandIsoDepositProducer::extractTrack ( const reco::Candidate cand,
reco::Track dummyStorage 
) const [inline, private]

Definition at line 73 of file CandIsoDepositProducer.cc.

References BestT, reco::RecoCandidate::bestTrack(), trackerHits::c, CandidateT, reco::Candidate::charge(), reco::RecoCandidate::combinedMuon(), CombinedMuonT, Exception, FakeT, edm::Ref< C, T, F >::get(), GsfT, reco::RecoCandidate::gsfTrack(), reco::Candidate::momentum(), reco::RecoCandidate::standAloneMuon(), StandAloneMuonT, theTrackType, reco::RecoCandidate::track(), TrackT, and reco::Candidate::vertex().

Referenced by produce().

                                                                                                            {
    if (theTrackType == CandidateT) {
        return 0;
    } else if (theTrackType == FakeT) {
        *dummy = Track(10,10,c.vertex(),c.momentum(),c.charge(), reco::Track::CovarianceMatrix());
        return dummy;
    } else {
        const RecoCandidate *rc = dynamic_cast<const RecoCandidate *>(&c);
        if (rc == 0) throw cms::Exception("Error") << " Candidate is not RecoCandidate: can't get a real track from it!";
        switch (theTrackType) {
            case FakeT: break; // to avoid warning
            case CandidateT: break; // to avoid warning
            case BestT: return rc->bestTrack(); break;
            case StandAloneMuonT: return &*rc->standAloneMuon(); break;
            case CombinedMuonT:   return &*rc->combinedMuon(); break;
            case TrackT: return &*rc->track(); break;
            case GsfT: return static_cast<const Track*>(rc->gsfTrack().get()); break;
        }
        return 0;
    }
}
void CandIsoDepositProducer::produce ( edm::Event event,
const edm::EventSetup eventSetup 
) [virtual]

build deposits

OK, now we know how many deps for how many muons each we will create might linearize this at some point (lazy) do it in case some muons are there only

well, it is empty already by construction, but still

for(i<nMuons)

now fill in selectively

some debugging stuff

fill the maps here

for(iDep<nDeps)

if (nMuons>0)

Implements edm::EDProducer.

Definition at line 96 of file CandIsoDepositProducer.cc.

References begin, trackerHits::c, CandidateT, reco::isodeposit::IsoDepositExtractor::deposit(), reco::isodeposit::IsoDepositExtractor::deposits(), end, extractTrack(), edm::helper::Filler< Map >::fill(), i, edm::helper::Filler< Map >::insert(), LogTrace, metname, edm::Event::put(), AlCaHLTBitMon_QueryRunRegistry::string, theCandCollectionTag, theDepositNames, theExtractor, theMultipleDepositsFlag, and theTrackType.

                                                                              {
  static const std::string metname = "CandIsoDepositProducer";

  edm::Handle< edm::View<reco::Candidate> > hCands;
  event.getByLabel(theCandCollectionTag, hCands);
    
  unsigned int nDeps = theMultipleDepositsFlag ? theDepositNames.size() : 1;

  static const unsigned int MAX_DEPS=10; 
  std::auto_ptr<reco::IsoDepositMap> depMaps[MAX_DEPS];
  
  if (nDeps >10 ) LogError(metname)<<"Unable to handle more than 10 input deposits"; 
  for (unsigned int i =0;i<nDeps; ++i){ // check if nDeps > 10??
    depMaps[i] =  std::auto_ptr<reco::IsoDepositMap>(new reco::IsoDepositMap()); 
  } 
   
  size_t nMuons = hCands->size();
  if (nMuons > 0){ 
    std::vector<std::vector<IsoDeposit> > deps2D(nDeps, std::vector<IsoDeposit>(nMuons)); 


    Track dummy;
    for (size_t i=0; i<  nMuons; ++i) {
      const Candidate &c = (*hCands)[i];
      const Track *track = extractTrack(c, &dummy);
      if ((theTrackType != CandidateT) && (!track)) {
        edm::LogWarning("CandIsoDepositProducer") << "Candidate #"<<i<<" has no bestTrack(), it will produce no deposit";
        reco::IsoDeposit emptyDep;
        for (size_t iDep=0;iDep<nDeps;++iDep) {
          deps2D[iDep][i] = emptyDep; 
        }
        continue;
      }
      if (!theMultipleDepositsFlag){
        IsoDeposit dep = ( ( theTrackType == CandidateT )
                             ? theExtractor->deposit(event, eventSetup, c)
                             : theExtractor->deposit(event, eventSetup, *track) );
        deps2D[0][i] = dep;
      } else {
        std::vector<IsoDeposit> deps = ( ( theTrackType == CandidateT )
                                           ? theExtractor->deposits(event, eventSetup, c)
                                           : theExtractor->deposits(event, eventSetup, *track) );
        for (unsigned int iDep=0; iDep < nDeps; ++iDep){        deps2D[iDep][i] =  deps[iDep];  }
      }
    }
    

    for (unsigned int iDep=0; iDep < nDeps; ++iDep){ 
      for (unsigned int iMu = 0; iMu< nMuons; ++iMu){ 
        LogTrace(metname)<<"Contents of "<<theDepositNames[iDep] 
                         <<" for a muon at index "<<iMu; 
        LogTrace(metname)<<deps2D[iDep][iMu].print(); 
      } 
 
      reco::IsoDepositMap::Filler filler(*depMaps[iDep]);      
      filler.insert(hCands, deps2D[iDep].begin(), deps2D[iDep].end()); 
      filler.fill();
    }
  }

  for (unsigned int iMap = 0; iMap < nDeps; ++iMap) event.put(depMaps[iMap], theDepositNames[iMap]);
}

Member Data Documentation

Definition at line 32 of file CandIsoDepositProducer.h.

Referenced by produce().

Definition at line 31 of file CandIsoDepositProducer.h.

Referenced by CandIsoDepositProducer().

std::vector<std::string> CandIsoDepositProducer::theDepositNames [private]

Definition at line 34 of file CandIsoDepositProducer.h.

Referenced by CandIsoDepositProducer(), and produce().

Definition at line 35 of file CandIsoDepositProducer.h.

Referenced by CandIsoDepositProducer(), and produce().

Definition at line 33 of file CandIsoDepositProducer.h.

Referenced by CandIsoDepositProducer(), extractTrack(), and produce().