CMS 3D CMS Logo

Public Member Functions | Private Member Functions | Private Attributes

JetCrystalsAssociator Class Reference

#include <RecoBTag/JetCrystalsAssociator/src/JetCrystalsAssociator.cc>

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

List of all members.

Public Member Functions

 JetCrystalsAssociator (const edm::ParameterSet &)
virtual void produce (edm::Event &, const edm::EventSetup &)
 ~JetCrystalsAssociator ()

Private Member Functions

std::auto_ptr
< JetCrystalsAssociationCollection
associate (const edm::Handle< CaloJetCollection > &jets, const edm::OrphanHandle< EMLorentzVectorCollection > &myLorentzRecHits) const

Private Attributes

double m_deltaRCut
edm::InputTag m_EBRecHits
edm::InputTag m_EERecHits
edm::InputTag m_jetsSrc

Detailed Description

Description: <one line="" class="" summary>="">

Implementation: <Notes on="" implementation>="">

Definition at line 67 of file JetCrystalsAssociator.cc.


Constructor & Destructor Documentation

JetCrystalsAssociator::JetCrystalsAssociator ( const edm::ParameterSet iConfig) [explicit]

Definition at line 89 of file JetCrystalsAssociator.cc.

References edm::ParameterSet::getParameter().

{
  produces<reco::JetCrystalsAssociationCollection>();
  produces<reco::EMLorentzVectorCollection>();

  m_EBRecHits = iConfig.getParameter<edm::InputTag>("EBRecHits");
  m_EERecHits = iConfig.getParameter<edm::InputTag>("EERecHits");
  m_jetsSrc   = iConfig.getParameter<edm::InputTag>("jets");
  m_deltaRCut = iConfig.getParameter<double>("coneSize");
}
JetCrystalsAssociator::~JetCrystalsAssociator ( )

Definition at line 101 of file JetCrystalsAssociator.cc.

{
 
  // do anything here that needs to be done at desctruction time
  // (e.g. close files, deallocate resources etc.)

}

Member Function Documentation

std::auto_ptr< JetCrystalsAssociationCollection > JetCrystalsAssociator::associate ( const edm::Handle< CaloJetCollection > &  jets,
const edm::OrphanHandle< EMLorentzVectorCollection > &  myLorentzRecHits 
) const [private]

Definition at line 210 of file JetCrystalsAssociator.cc.

References delta, j, p4, and matplotRender::t.

{
  // we know we will save an element per input jet
  std::auto_ptr<JetCrystalsAssociationCollection> outputCollection( new JetCrystalsAssociationCollection( jets->size() ) );

  //loop on jets and associate
  for (size_t j = 0; j < jets->size(); j++) {
    (*outputCollection)[j].first = edm::RefToBase<Jet>(CaloJetRef(jets, j));
    for (size_t t = 0; t < myLorentzRecHits->size(); t++) {
      double delta = ROOT::Math::VectorUtil::DeltaR((*jets)[j].p4().Vect(), (*myLorentzRecHits)[t]);
      if (delta < m_deltaRCut)
        (*outputCollection)[j].second.push_back( EMLorentzVectorRef(myLorentzRecHits, t) );
    }
  }  
  return outputCollection;
}
void JetCrystalsAssociator::produce ( edm::Event iEvent,
const edm::EventSetup iSetup 
) [virtual]

Implements edm::EDProducer.

Definition at line 116 of file JetCrystalsAssociator.cc.

References DetId::det(), egHLT::errCodes::EBRecHits, DetId::Ecal, EcalBarrel, EcalEndcap, egHLT::errCodes::EERecHits, relval_parameters_module::energy, ExpressReco_HICollisions_FallBack::et, eta(), PV3DBase< T, PVType, FrameType >::eta(), geometry, edm::EventSetup::get(), edm::Event::getByLabel(), CaloCellGeometry::getPosition(), j, analyzePatCleaning_cfg::jets, M_PI, L1TEmulatorMonitor_cff::p, PV3DBase< T, PVType, FrameType >::phi(), phi, edm::Event::put(), dt_offlineAnalysis_common_cff::reco, funct::sin(), DetId::subdetId(), matplotRender::t, theta(), and PV3DBase< T, PVType, FrameType >::theta().

{
  using namespace edm;
  using namespace reco;
  using namespace std;

  // geometry initialization
  ESHandle<CaloGeometry> geometry;
  iSetup.get<CaloGeometryRecord>().get(geometry);
  
  const CaloSubdetectorGeometry* EB = geometry->getSubdetectorGeometry(DetId::Ecal,EcalBarrel);
   const CaloSubdetectorGeometry* EE = geometry->getSubdetectorGeometry(DetId::Ecal,EcalEndcap);
   // end 
   
   Handle<CaloJetCollection> jets;
   iEvent.getByLabel(m_jetsSrc, jets);
   
   // get calo towers collection
   //   Handle<CaloTowerCollection> caloTowers; 
   //   iEvent.getByLabel(m_towersSrc, caloTowers);

   // calculation of ECAL isolation
   Handle<EBRecHitCollection> EBRecHits;
   Handle<EERecHitCollection> EERecHits;
   iEvent.getByLabel( m_EBRecHits, EBRecHits );
   iEvent.getByLabel( m_EERecHits, EERecHits );
   
   std::auto_ptr<EMLorentzVectorCollection> jetRecHits( new EMLorentzVectorCollection() );
   //loop on jets and associate
   for (size_t t = 0; t < jets->size(); t++)
    {
      const std::vector<CaloTowerPtr>  myTowers=(*jets)[t].getCaloConstituents();
      //      cout <<"Jet id "<<t<<endl;
      //      cout <<"Tower size "<<myTowers.size()<<endl;
      for (unsigned int iTower = 0; iTower < myTowers.size(); iTower++)
        {
          CaloTowerPtr theTower = myTowers[iTower];
          size_t numRecHits = theTower->constituentsSize();
        // access CaloRecHits
        for (size_t j = 0; j < numRecHits; j++) {
          DetId RecHitDetID=theTower->constituent(j);
          DetId::Detector DetNum=RecHitDetID.det();
          if( DetNum == DetId::Ecal ){
            int EcalNum =  RecHitDetID.subdetId();
            if( EcalNum == 1 ){
              EBDetId EcalID = RecHitDetID;
              EBRecHitCollection::const_iterator theRecHit=EBRecHits->find(EcalID);
              if(theRecHit != EBRecHits->end()){
                DetId id = theRecHit->detid();
                const CaloCellGeometry* this_cell = EB->getGeometry(id);
                if (this_cell) {
                  GlobalPoint posi = this_cell->getPosition();
                  double energy = theRecHit->energy();
                  double eta = posi.eta();
                  double phi = posi.phi();
                  double theta = posi.theta();
                  if(theta > M_PI) theta = 2 * M_PI- theta;
                  double et = energy * sin(theta);
                  // cout <<"Et "<<et<<endl;
                  EMLorentzVector p(et, eta, phi, energy);
                  jetRecHits->push_back(p);
                }
              }
            } else if ( EcalNum == 2 ) {
              EEDetId EcalID = RecHitDetID;
              EERecHitCollection::const_iterator theRecHit=EERecHits->find(EcalID);         
              if(theRecHit != EBRecHits->end()){
                DetId id = theRecHit->detid();
                const CaloCellGeometry* this_cell = EE->getGeometry(id);
                if (this_cell) {
                  GlobalPoint posi = this_cell->getPosition();
                  double energy = theRecHit->energy();
                  double eta = posi.eta();
                  double phi = posi.phi();
                  double theta = posi.theta();
                  if (theta > M_PI) theta = 2 * M_PI - theta;
                  double et = energy * sin(theta);
                  // cout <<"Et "<<et<<endl;
                  EMLorentzVector p(et, eta, phi, energy);
                  jetRecHits->push_back(p);
                }
              }
            }
          }
        }
      }
    }

  edm::OrphanHandle <reco::EMLorentzVectorCollection> myRecHits = iEvent.put(jetRecHits);

  std::auto_ptr<JetCrystalsAssociationCollection> jetCrystals = associate(jets,myRecHits);
  iEvent.put( jetCrystals );
}

Member Data Documentation

Definition at line 86 of file JetCrystalsAssociator.cc.

Definition at line 83 of file JetCrystalsAssociator.cc.

Definition at line 84 of file JetCrystalsAssociator.cc.

Definition at line 82 of file JetCrystalsAssociator.cc.