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 std::vector<double> area_hardJets;
00074
00075
00076
00077 std::vector<CompoundPseudoJet>::const_iterator it = fjCompoundJets_.begin(),
00078 iEnd = fjCompoundJets_.end(),
00079 iBegin = fjCompoundJets_.begin();
00080 indices.resize( fjCompoundJets_.size() );
00081 for ( ; it != iEnd; ++it ) {
00082 int jetIndex = it - iBegin;
00083 fastjet::PseudoJet localJet = it->hardJet();
00084
00085 p4_hardJets.push_back( math::XYZTLorentzVector(localJet.px(), localJet.py(), localJet.pz(), localJet.e() ));
00086 area_hardJets.push_back( it->hardJetArea() );
00087
00088
00089 std::vector<CompoundPseudoSubJet>::const_iterator itSubJetBegin = it->subjets().begin(),
00090 itSubJet = itSubJetBegin, itSubJetEnd = it->subjets().end();
00091 for (; itSubJet != itSubJetEnd; ++itSubJet ){
00092
00093 fastjet::PseudoJet subjet = itSubJet->subjet();
00094 math::XYZTLorentzVector p4Subjet(subjet.px(), subjet.py(), subjet.pz(), subjet.e() );
00095 reco::Particle::Point point(0,0,0);
00096
00097
00098 std::vector<reco::CandidatePtr> subjetConstituents;
00099
00100
00101 std::vector<int> const & subjetFastjetConstituentIndices = itSubJet->constituents();
00102 std::vector<int>::const_iterator fastSubIt = subjetFastjetConstituentIndices.begin(),
00103 transConstBegin = subjetFastjetConstituentIndices.begin(),
00104 transConstEnd = subjetFastjetConstituentIndices.end();
00105 for ( ; fastSubIt != transConstEnd; ++fastSubIt ) {
00106
00107 if ( *fastSubIt < static_cast<int>(inputs_.size()) )
00108 subjetConstituents.push_back( inputs_[*fastSubIt] );
00109 }
00110
00111
00112 indices[jetIndex].push_back( subjetCollection->size() );
00113
00114
00115
00116 T jet;
00117 reco::writeSpecific( jet, p4Subjet, point, subjetConstituents, iSetup);
00118 jet.setJetArea( itSubJet->subjetArea() );
00119 subjetCollection->push_back( jet );
00120
00121 }
00122 }
00123
00124 subjetHandleAfterPut = iEvent.put( subjetCollection, jetCollInstanceName_ );
00125
00126
00127
00128 std::vector<math::XYZTLorentzVector>::const_iterator ip4 = p4_hardJets.begin(),
00129 ip4Begin = p4_hardJets.begin(),
00130 ip4End = p4_hardJets.end();
00131
00132 for ( ; ip4 != ip4End; ++ip4 ) {
00133 int p4_index = ip4 - ip4Begin;
00134 std::vector<int> & ind = indices[p4_index];
00135 std::vector<reco::CandidatePtr> i_hardJetConstituents;
00136
00137 for( std::vector<int>::const_iterator isub = ind.begin();
00138 isub != ind.end(); ++isub ) {
00139 reco::CandidatePtr candPtr( subjetHandleAfterPut, *isub, false );
00140 i_hardJetConstituents.push_back( candPtr );
00141 }
00142 reco::Particle::Point point(0,0,0);
00143 reco::BasicJet toput( *ip4, point, i_hardJetConstituents);
00144 toput.setJetArea( area_hardJets[ip4 - ip4Begin] );
00145 jetCollection->push_back( toput );
00146 }
00147
00148
00149 iEvent.put( jetCollection);
00150
00151 }