CMS 3D CMS Logo

Public Member Functions | Private Attributes

JetMatchingTools Class Reference

#include <JetMatchingTools.h>

List of all members.

Public Member Functions

int generatorId (unsigned fSimTrackId)
 Generator ID.
std::vector< const CaloRecHit * > getCaloRecHits (int fGeneratorId)
 CaloRecHits.
std::vector< const CaloTower * > getCaloTowers (int fGeneratorId)
 CaloTowers.
std::vector< DetIdgetConstituentIds (const CaloTower &fTower)
 get cells contributing to the tower
std::vector< const CaloTower * > getConstituents (const reco::CaloJet &fJet)
 get towers contributing to CaloJet
std::vector< const CaloRecHit * > getConstituents (const CaloTower &fTower)
 get CaloRecHits contributing to the tower
const EBRecHitCollectiongetEBRecHitCollection ()
const edm::PCaloHitContainergetEBSimHitCollection ()
const EERecHitCollectiongetEERecHitCollection ()
const edm::PCaloHitContainergetEESimHitCollection ()
const reco::GenParticlegetGenParticle (int fGeneratorId)
 GenParticle.
std::vector< const
reco::GenParticle * > 
getGenParticles (const reco::CaloJet &fJet, bool fVerbose=true)
 GenParticles for CaloJet.
std::vector< const
reco::GenParticle * > 
getGenParticles (const reco::GenJet &fJet)
 GenParticles for GenJet.
const reco::CandidateCollectiongetGenParticlesCollection ()
const HBHERecHitCollectiongetHBHERecHitCollection ()
const edm::PCaloHitContainergetHcalSimHitCollection ()
const HFRecHitCollectiongetHFRecHitCollection ()
const HORecHitCollectiongetHORecHitCollection ()
std::vector< const PCaloHit * > getPCaloHits (DetId fId)
 get PCaloHits contributing to the detId
std::vector< const PCaloHit * > getPCaloHits (int fGeneratorId)
 CaloSimHits.
const edm::SimTrackContainergetSimTrackCollection ()
const edm::SimVertexContainergetSimVertexCollection ()
const SimTrackgetTrack (unsigned fSimTrackId)
 convert trackId to SimTrack
int getTrackId (const PCaloHit &fHit)
 GEANT track ID.
 JetMatchingTools (const edm::Event &fEvent)
double lostEnergyFraction (const reco::CaloJet &fJet)
 energy in broken links
double overlapEnergyFraction (const std::vector< const reco::GenParticle * > &fObject, const std::vector< const reco::GenParticle * > &fReference) const
 energy overlap
 ~JetMatchingTools ()

Private Attributes

const EBRecHitCollectionmEBRecHitCollection
const edm::PCaloHitContainermEBSimHitCollection
const EERecHitCollectionmEERecHitCollection
const edm::PCaloHitContainermEESimHitCollection
const edm::EventmEvent
const reco::CandidateCollectionmGenParticleCollection
const HBHERecHitCollectionmHBHERecHitCollection
const edm::PCaloHitContainermHcalSimHitCollection
const HFRecHitCollectionmHFRecHitCollection
const HORecHitCollectionmHORecHitCollection
const edm::SimTrackContainermSimTrackCollection
const edm::SimVertexContainermSimVertexCollection

Detailed Description

Definition at line 25 of file JetMatchingTools.h.


Constructor & Destructor Documentation

JetMatchingTools::JetMatchingTools ( const edm::Event fEvent)
JetMatchingTools::~JetMatchingTools ( )

Definition at line 55 of file JetMatchingTools.cc.

{}

Member Function Documentation

int JetMatchingTools::generatorId ( unsigned  fSimTrackId)

Generator ID.

Definition at line 221 of file JetMatchingTools.cc.

References benchmark_cfg::cerr, SimTrack::genpartIndex(), getSimVertexCollection(), getTrack(), SimTrack::noGenpart(), SimVertex::noParent(), SimTrack::noVertex(), SimVertex::parentIndex(), and SimTrack::vertIndex().

Referenced by getGenParticles(), and lostEnergyFraction().

                                                       {
  const SimTrack* track = getTrack (fSimTrackId);
  if (!track) return -1;
  while (track->noGenpart ()) {
    if (track->noVertex ()) {
      std::cerr << "JetMatchingTools::generatorId-> No vertex for track " << *track << std::endl;
      return -1;
    }
    const SimVertex* vertex = &((*getSimVertexCollection ())[track->vertIndex ()]);
    if (vertex->noParent()) {
      std::cerr << "JetMatchingTools::generatorId-> No track for vertex " << *vertex << std::endl;
      return -1;
    }
    track = getTrack (vertex->parentIndex ());
  }
  return track->genpartIndex ();
}
std::vector<const CaloRecHit*> JetMatchingTools::getCaloRecHits ( int  fGeneratorId)

CaloRecHits.

std::vector<const CaloTower*> JetMatchingTools::getCaloTowers ( int  fGeneratorId)

CaloTowers.

std::vector< DetId > JetMatchingTools::getConstituentIds ( const CaloTower fTower)

get cells contributing to the tower

Definition at line 185 of file JetMatchingTools.cc.

References CaloTower::constituent(), CaloTower::constituentsSize(), i, and query::result.

Referenced by getGenParticles().

                                                                              {
  std::vector <DetId> result;
  for (unsigned i = 0; i < fTower.constituentsSize(); ++i) {
    DetId id = fTower.constituent (i);
    result.push_back (id);
  }
  return result;
}
std::vector< const CaloRecHit * > JetMatchingTools::getConstituents ( const CaloTower fTower)

get CaloRecHits contributing to the tower

Definition at line 154 of file JetMatchingTools.cc.

References benchmark_cfg::cerr, CaloTower::constituent(), CaloTower::constituentsSize(), DetId::Ecal, EcalBarrel, EcalEndcap, getEBRecHitCollection(), getEERecHitCollection(), getHBHERecHitCollection(), getHFRecHitCollection(), getHORecHitCollection(), DetId::Hcal, HcalBarrel, HcalEndcap, HcalForward, HcalOuter, i, and query::result.

                                                                                        {
  std::vector <const CaloRecHit*> result;
  for (unsigned i = 0; i < fTower.constituentsSize(); ++i) {
    DetId id = fTower.constituent (i);
    const CaloRecHit* hit = 0;
    if (id.det () == DetId::Ecal) {
      if ((EcalSubdetector) id.subdetId () == EcalBarrel) {
        hit = getHit (*getEBRecHitCollection (), id);
      } 
      else if ((EcalSubdetector) id.subdetId () == EcalEndcap) {
        hit = getHit (*getEERecHitCollection (), id);
      }
    }
    else if (id.det () == DetId::Hcal) {
      if ((HcalSubdetector) id.subdetId () == HcalBarrel || (HcalSubdetector) id.subdetId () == HcalEndcap) {
        hit = getHit (*getHBHERecHitCollection (), id);
      }
      else if ((HcalSubdetector) id.subdetId () == HcalOuter) {
        hit = getHit (*getHORecHitCollection (), id);
      }
      if ((HcalSubdetector) id.subdetId () == HcalForward) {
        hit = getHit (*getHFRecHitCollection (), id);
      }
    }
    if (hit) result.push_back (hit);
    else std::cerr << "Can not find rechit for id " << id.rawId () << std::endl;
  } 
  return result;
}
std::vector< const CaloTower * > JetMatchingTools::getConstituents ( const reco::CaloJet fJet)

get towers contributing to CaloJet

Definition at line 147 of file JetMatchingTools.cc.

References reco::CaloJet::getCaloConstituents(), i, and query::result.

Referenced by getGenParticles(), and lostEnergyFraction().

                                                                                        {
  std::vector <const CaloTower*> result;
  std::vector<CaloTowerPtr> constituents = fJet.getCaloConstituents ();
  for (unsigned i = 0; i < constituents.size(); ++i) result.push_back (&*(constituents[i]));
  return result;
}
const EBRecHitCollection * JetMatchingTools::getEBRecHitCollection ( )

Definition at line 57 of file JetMatchingTools.cc.

References edm::Event::getByLabel(), mEBRecHitCollection, and mEvent.

Referenced by getConstituents().

                                                                   {
  if (!mEBRecHitCollection) {
    edm::Handle<EBRecHitCollection> recHits;
    mEvent->getByLabel (edm::InputTag ("ecalRecHit:EcalRecHitsEB"), recHits);
    mEBRecHitCollection = &*recHits;
  }
  return mEBRecHitCollection;
}
const PCaloHitContainer * JetMatchingTools::getEBSimHitCollection ( )
const EERecHitCollection * JetMatchingTools::getEERecHitCollection ( )

Definition at line 65 of file JetMatchingTools.cc.

References edm::Event::getByLabel(), mEERecHitCollection, and mEvent.

Referenced by getConstituents().

                                                                   {
  if (!mEERecHitCollection) {
    edm::Handle<EERecHitCollection> recHits;
    mEvent->getByLabel (edm::InputTag ("ecalRecHit:EcalRecHitsEE"), recHits);
    mEERecHitCollection = &*recHits;
  }
  return mEERecHitCollection;
}
const PCaloHitContainer * JetMatchingTools::getEESimHitCollection ( )
const reco::GenParticle * JetMatchingTools::getGenParticle ( int  fGeneratorId)

GenParticle.

Definition at line 240 of file JetMatchingTools.cc.

References benchmark_cfg::cerr, reco::GenJet::genParticle(), getGenParticlesCollection(), findQualityFiles::size, and edm::OwnVector< T, P >::size().

Referenced by getGenParticles().

                                                                         {
  if (fGeneratorId > int (getGenParticlesCollection ()->size())) {
    std::cerr << "JetMatchingTools::getGenParticle-> requested index " << fGeneratorId << " is grater then container size " << getGenParticlesCollection ()->size() << std::endl;
    return 0;
  }
  return reco::GenJet::genParticle ( &(*getGenParticlesCollection ())[fGeneratorId-1]); // knowhow: index is shifted by 1
}
std::vector< const reco::GenParticle * > JetMatchingTools::getGenParticles ( const reco::CaloJet fJet,
bool  fVerbose = true 
)

GenParticles for CaloJet.

Definition at line 249 of file JetMatchingTools.cc.

References benchmark_cfg::cerr, generatorId(), getConstituentIds(), getConstituents(), getGenParticle(), getPCaloHits(), getTrackId(), and query::result.

Referenced by CaloJetTester::analyze().

                                                                                                            {
  std::set <const reco::GenParticle*> result;
  // follow the chain
  std::vector <const CaloTower*> towers = getConstituents (fJet) ;
  for (unsigned itower = 0; itower < towers.size (); ++itower) {
    std::vector <DetId> detids = getConstituentIds (*(towers[itower])) ;
    for (unsigned iid = 0; iid < detids.size(); ++iid) {
      std::vector <const PCaloHit*> phits = getPCaloHits (detids[iid]);
      for (unsigned iphit = 0; iphit < phits.size(); ++iphit) {
        int trackId = getTrackId (*(phits[iphit]));
        if (trackId >= 0) {
          int genId = generatorId (trackId);
          if (genId >= 0) {
            const reco::GenParticle* genPart = getGenParticle (genId);
            if (genPart) {
              result.insert (genPart);
            }
            else if (fVerbose) {
              std::cerr << "JetMatchingTools::getGenParticles-> Can not convert genId " << genId << " to GenParticle" << std::endl;
            }
          }
          else if (fVerbose) {
            std::cerr << "JetMatchingTools::getGenParticles-> Can not convert trackId " << trackId << " to genId" << std::endl;
          }
        }
        else if (fVerbose) {
          std::cerr << "JetMatchingTools::getGenParticles-> Unknown trackId for PCaloHit " << *(phits[iphit]) << std::endl;
        }
      }
    }
  }
  return std::vector <const reco::GenParticle*> (result.begin (), result.end());
}
std::vector< const reco::GenParticle * > JetMatchingTools::getGenParticles ( const reco::GenJet fJet)

GenParticles for GenJet.

Definition at line 284 of file JetMatchingTools.cc.

References reco::GenJet::getGenConstituents().

                                                                                            {
  return fJet.getGenConstituents ();
}
const reco::CandidateCollection * JetMatchingTools::getGenParticlesCollection ( )
const HBHERecHitCollection * JetMatchingTools::getHBHERecHitCollection ( )

Definition at line 73 of file JetMatchingTools.cc.

References edm::Event::getByLabel(), mEvent, and mHBHERecHitCollection.

Referenced by getConstituents().

const PCaloHitContainer * JetMatchingTools::getHcalSimHitCollection ( )
const HFRecHitCollection * JetMatchingTools::getHFRecHitCollection ( )

Definition at line 89 of file JetMatchingTools.cc.

References edm::Event::getByLabel(), mEvent, and mHFRecHitCollection.

Referenced by getConstituents().

const HORecHitCollection * JetMatchingTools::getHORecHitCollection ( )

Definition at line 81 of file JetMatchingTools.cc.

References edm::Event::getByLabel(), mEvent, and mHORecHitCollection.

Referenced by getConstituents().

std::vector< const PCaloHit * > JetMatchingTools::getPCaloHits ( DetId  fId)

get PCaloHits contributing to the detId

Definition at line 194 of file JetMatchingTools.cc.

References DetId::det(), DetId::Ecal, EcalBarrel, EcalEndcap, getEBSimHitCollection(), getEESimHitCollection(), getHcalSimHitCollection(), DetId::Hcal, query::result, and DetId::subdetId().

Referenced by getGenParticles(), and lostEnergyFraction().

                                                                     {
  std::vector <const PCaloHit*> result;
  if (fId.det () == DetId::Ecal) {
    if ((EcalSubdetector) fId.subdetId () == EcalBarrel) {
      result = getSimHits (*getEBSimHitCollection (), fId);
    } 
    else if ((EcalSubdetector) fId.subdetId () == EcalEndcap) {
      result = getSimHits (*getEESimHitCollection (), fId);
    }
  }
  else if (fId.det () == DetId::Hcal) {
    result = getSimHits (*getHcalSimHitCollection (), fId);
  }
  return result;
}
std::vector<const PCaloHit*> JetMatchingTools::getPCaloHits ( int  fGeneratorId)

CaloSimHits.

const SimTrackContainer * JetMatchingTools::getSimTrackCollection ( )
const SimVertexContainer * JetMatchingTools::getSimVertexCollection ( )
const SimTrack * JetMatchingTools::getTrack ( unsigned  fSimTrackId)

convert trackId to SimTrack

Definition at line 214 of file JetMatchingTools.cc.

References getSimTrackCollection(), and i.

Referenced by generatorId().

                                                                {
  for (unsigned i = 0; i < getSimTrackCollection ()->size (); ++i) {
    if ((*getSimTrackCollection ())[i].trackId() == fSimTrackId) return &(*getSimTrackCollection ())[i];
  }
  return 0;
}
int JetMatchingTools::getTrackId ( const PCaloHit fHit)

GEANT track ID.

Definition at line 210 of file JetMatchingTools.cc.

References PCaloHit::geantTrackId().

Referenced by getGenParticles(), and lostEnergyFraction().

                                                      {
  return fHit.geantTrackId ();
}
double JetMatchingTools::lostEnergyFraction ( const reco::CaloJet fJet)

energy in broken links

Definition at line 289 of file JetMatchingTools.cc.

References cond::rpcobgas::detid, generatorId(), getConstituents(), getPCaloHits(), and getTrackId().

                                                                     {
  double totalEnergy = 0;
  double lostEnergy = 0;
  // follow the chain
  std::vector <const CaloTower*> towers = getConstituents (fJet) ;
  for (unsigned itower = 0; itower < towers.size (); ++itower) {
    std::vector <const CaloRecHit*> recHits = getConstituents (*(towers[itower]));
    for (unsigned ihit = 0; ihit < recHits.size(); ++ihit) {
      double foundSimEnergy = 0;
      double lostSimEnergy = 0;
      std::vector <const PCaloHit*> phits = getPCaloHits (recHits[ihit]->detid());
      for (unsigned iphit = 0; iphit < phits.size(); ++iphit) {
        double simEnergy = phits[iphit]->energy ();
        int trackId = getTrackId (*(phits[iphit]));
        if (trackId < 0 || generatorId (trackId) < 0)   lostSimEnergy += simEnergy;
        else   foundSimEnergy += simEnergy;
      }
      if (foundSimEnergy > 0 || lostSimEnergy > 0) {
        totalEnergy += recHits[ihit]->energy ();
        lostEnergy += recHits[ihit]->energy () * lostSimEnergy / (foundSimEnergy + lostSimEnergy);
      }
    }
  }
  return lostEnergy / totalEnergy;
}
double JetMatchingTools::overlapEnergyFraction ( const std::vector< const reco::GenParticle * > &  fObject,
const std::vector< const reco::GenParticle * > &  fReference 
) const

energy overlap

Definition at line 316 of file JetMatchingTools.cc.

References relval_parameters_module::energy, spr::find(), and i.

Referenced by CaloJetTester::analyze().

                                                                                                            {
  if (fObject.empty()) return 0;
  double totalEnergy = 0;
  double overlapEnergy = 0;
  for (unsigned i = 0; i < fObject.size(); ++i) {
    totalEnergy += fObject [i]->energy();
    if (find (fReference.begin(), fReference.end(), fObject [i]) != fReference.end ()) overlapEnergy += fObject [i]->energy();
  }
  return overlapEnergy / totalEnergy;
}

Member Data Documentation

Definition at line 83 of file JetMatchingTools.h.

Referenced by getEBRecHitCollection().

Definition at line 88 of file JetMatchingTools.h.

Referenced by getEBSimHitCollection().

Definition at line 84 of file JetMatchingTools.h.

Referenced by getEERecHitCollection().

Definition at line 89 of file JetMatchingTools.h.

Referenced by getEESimHitCollection().

Definition at line 93 of file JetMatchingTools.h.

Referenced by getGenParticlesCollection().

Definition at line 85 of file JetMatchingTools.h.

Referenced by getHBHERecHitCollection().

Definition at line 90 of file JetMatchingTools.h.

Referenced by getHcalSimHitCollection().

Definition at line 87 of file JetMatchingTools.h.

Referenced by getHFRecHitCollection().

Definition at line 86 of file JetMatchingTools.h.

Referenced by getHORecHitCollection().

Definition at line 91 of file JetMatchingTools.h.

Referenced by getSimTrackCollection().

Definition at line 92 of file JetMatchingTools.h.

Referenced by getSimVertexCollection().