Go to the documentation of this file.00001
00002 #include "FWCore/Framework/interface/MakerMacros.h"
00003 #include "RecoJets/JetProducers/plugins/CompoundJetProducer.h"
00004 #include "FWCore/Utilities/interface/Exception.h"
00005 #include "RecoJets/JetProducers/interface/JetSpecific.h"
00006
00007 using namespace std;
00008 using namespace reco;
00009 using namespace edm;
00010 using namespace cms;
00011
00012 namespace {
00013 const bool debug = false;
00014
00015 }
00016
00017
00018 CompoundJetProducer::CompoundJetProducer(edm::ParameterSet const& conf):
00019 VirtualJetProducer( conf )
00020 {
00021
00022 produces<reco::BasicJetCollection>();
00023
00024 }
00025
00026
00027 void CompoundJetProducer::inputTowers( )
00028 {
00029 fjCompoundJets_.clear();
00030 VirtualJetProducer::inputTowers();
00031 }
00032
00033 void CompoundJetProducer::output(edm::Event & iEvent, edm::EventSetup const& iSetup)
00034 {
00035
00036 switch( jetTypeE ) {
00037 case JetType::CaloJet :
00038 writeCompoundJets<reco::CaloJet>( iEvent, iSetup );
00039 break;
00040 case JetType::PFJet :
00041 writeCompoundJets<reco::PFJet>( iEvent, iSetup );
00042 break;
00043 case JetType::GenJet :
00044 writeCompoundJets<reco::GenJet>( iEvent, iSetup );
00045 break;
00046 case JetType::BasicJet :
00047 writeCompoundJets<reco::BasicJet>( iEvent, iSetup );
00048 break;
00049 default:
00050 throw cms::Exception("InvalidInput") << "invalid jet type in CompoundJetProducer\n";
00051 break;
00052 };
00053
00054 }
00055
00057 template< class T>
00058 void CompoundJetProducer::writeCompoundJets( edm::Event & iEvent, edm::EventSetup const& iSetup)
00059 {
00060
00061
00062 std::auto_ptr<reco::BasicJetCollection> jetCollection( new reco::BasicJetCollection() );
00063
00064 std::auto_ptr<std::vector<T> > subjetCollection( new std::vector<T>() );
00065
00066
00067 edm::OrphanHandle< std::vector<T> > subjetHandleAfterPut;
00068
00069 std::vector< std::vector<int> > indices;
00070
00071 std::vector<math::XYZTLorentzVector> p4_hardJets;
00072
00073
00074 std::vector<CompoundPseudoJet>::const_iterator it = fjCompoundJets_.begin(),
00075 iEnd = fjCompoundJets_.end(),
00076 iBegin = fjCompoundJets_.begin();
00077 indices.resize( fjCompoundJets_.size() );
00078 for ( ; it != iEnd; ++it ) {
00079 int jetIndex = it - iBegin;
00080 fastjet::PseudoJet localJet = it->hardJet();
00081
00082 p4_hardJets.push_back( math::XYZTLorentzVector(localJet.px(), localJet.py(), localJet.pz(), localJet.e() ));
00083
00084
00085 std::vector<CompoundPseudoSubJet>::const_iterator itSubJetBegin = it->subjets().begin(),
00086 itSubJet = itSubJetBegin, itSubJetEnd = it->subjets().end();
00087 for (; itSubJet != itSubJetEnd; ++itSubJet ){
00088
00089 fastjet::PseudoJet subjet = itSubJet->subjet();
00090 math::XYZTLorentzVector p4Subjet(subjet.px(), subjet.py(), subjet.pz(), subjet.e() );
00091 reco::Particle::Point point(0,0,0);
00092
00093
00094 std::vector<reco::CandidatePtr> subjetConstituents;
00095
00096
00097 std::vector<int> const & subjetFastjetConstituentIndices = itSubJet->constituents();
00098 std::vector<int>::const_iterator fastSubIt = subjetFastjetConstituentIndices.begin(),
00099 transConstBegin = subjetFastjetConstituentIndices.begin(),
00100 transConstEnd = subjetFastjetConstituentIndices.end();
00101 for ( ; fastSubIt != transConstEnd; ++fastSubIt ) {
00102
00103 if ( *fastSubIt < static_cast<int>(inputs_.size()) )
00104 subjetConstituents.push_back( inputs_[*fastSubIt] );
00105 }
00106
00107
00108 indices[jetIndex].push_back( subjetCollection->size() );
00109
00110
00111
00112 T jet;
00113 reco::writeSpecific( jet, p4Subjet, point, subjetConstituents, iSetup);
00114 subjetCollection->push_back( jet );
00115
00116 }
00117 }
00118
00119 subjetHandleAfterPut = iEvent.put( subjetCollection, jetCollInstanceName_ );
00120
00121
00122
00123 std::vector<math::XYZTLorentzVector>::const_iterator ip4 = p4_hardJets.begin(),
00124 ip4Begin = p4_hardJets.begin(),
00125 ip4End = p4_hardJets.end();
00126
00127 for ( ; ip4 != ip4End; ++ip4 ) {
00128 int p4_index = ip4 - ip4Begin;
00129 std::vector<int> & ind = indices[p4_index];
00130 std::vector<reco::CandidatePtr> i_hardJetConstituents;
00131
00132 for( std::vector<int>::const_iterator isub = ind.begin();
00133 isub != ind.end(); ++isub ) {
00134 reco::CandidatePtr candPtr( subjetHandleAfterPut, *isub, false );
00135 i_hardJetConstituents.push_back( candPtr );
00136 }
00137 reco::Particle::Point point(0,0,0);
00138 jetCollection->push_back( reco::BasicJet( *ip4, point, i_hardJetConstituents) );
00139 }
00140
00141
00142 iEvent.put( jetCollection);
00143
00144 }