41 matchDR_ ( p.getParameter<double> (
"matchDR") ),
42 pdgIdToSelect_( p.getParameter<
int> (
"pdgIdToSelect") ),
43 ptMinParticle_( p.getParameter<double>(
"ptMinParticle") ),
44 ptMinShower_( p.getParameter<double>(
"ptMinShower") ),
45 etaMaxParticle_( p.getParameter<double>(
"etaMaxParticle" )),
46 etaMaxShower_( p.getParameter<double>(
"etaMaxShower" )),
47 flavorHistoryName_( p.getParameter<
string>(
"flavorHistoryName") ),
48 verbose_( p.getUntrackedParameter<
bool>(
"verbose" ) )
58 if (
verbose_ )
cout <<
"---------- Hello from FlavorHistoryProducer! -----" << endl;
70 particles.push_back(&*
p);
74 vector<int> partonIndices;
76 vector<int> progenitorIndices;
78 vector<int> sisterIndices;
80 vector<FlavorHistory::FLAVOR_T> flavorSources;
83 auto flavorHistoryEvent = std::make_unique<FlavorHistoryEvent>();
90 for( j=0; j<j_max; ++j ) {
97 bool foundProgenitor =
false;
102 int nDa = (
p)->numberOfDaughters();
106 if ( idabs <= FlavorHistory::tQuarkId && p->
status() == 2 &&
113 if(
verbose_)
cout <<
"--------------------------" << endl;
114 if(
verbose_)
cout <<
"Processing particle " << j <<
", status = " << p->
status() <<
", pdg id = " << p->
pdgId() << endl;
118 vector<Candidate const *> allParents;
122 cout <<
"Parents : " << endl;
123 vector<Candidate const *>::const_iterator iprint = allParents.begin(),
124 iprintend = allParents.end();
125 for ( ; iprint != iprintend; ++iprint )
126 cout <<
" status = " << (*iprint)->status() <<
", pdg id = " << (*iprint)->pdgId() <<
", pt = " << (*iprint)->pt() << endl;
156 vector<Candidate const *>::const_iterator
found =
find(particles.begin(),particles.end(),aParent);
160 progenitorIndex = found - particles.begin();
167 if( progenitorIndex > 5 ) {
179 if(
verbose_)
cout <<
"Matrix Element progenitor" << endl;
180 if ( flavorSource == FlavorHistory::FLAVOR_NULL ) flavorSource = FlavorHistory::FLAVOR_ME;
181 foundProgenitor =
true;
184 else if( (aParentId>
pdgIdToSelect_ && aParentId<FlavorHistory::gluonId) ||
185 aParentId > FlavorHistory::gluonId ) {
187 if ( flavorSource == FlavorHistory::FLAVOR_NULL ) flavorSource = FlavorHistory::FLAVOR_DECAY;
188 foundProgenitor =
true;
195 if ( !foundProgenitor ) {
196 if ( flavorSource == FlavorHistory::FLAVOR_NULL ) flavorSource = FlavorHistory::FLAVOR_GS;
200 vector<Candidate const *>::const_iterator
found =
find(particles.begin(),particles.end(),aParent);
202 progenitorIndex = found - particles.begin();
205 foundProgenitor =
true;
216 if ( !foundProgenitor ) progenitorIndex = j_max;
220 partonIndices.push_back( partonIndex );
221 progenitorIndices.push_back( progenitorIndex );
222 flavorSources.push_back(flavorSource);
223 sisterIndices.push_back( -1 );
234 if ( partonIndices.size() == progenitorIndices.size() && !partonIndices.empty() ) {
236 for (
unsigned int ii = 0;
ii < partonIndices.size(); ++
ii ) {
238 const Candidate * candi = particles[partonIndices[
ii]];
239 if (
verbose_ )
cout <<
" Sister candidate particle 1: " <<
ii <<
", pdgid = " << candi->
pdgId() <<
", status = " << candi->
status() << endl;
243 for (
unsigned int jj = 0;
jj < partonIndices.size(); ++
jj ) {
245 const Candidate * candj = particles[partonIndices[
jj]];
246 if (
verbose_ )
cout <<
" Sister candidate particle 2: " <<
jj <<
", pdgid = " << candj->
pdgId() <<
", status = " << candj->
status() << endl;
250 sisterIndices[
ii] = partonIndices[
jj];
251 if (
verbose_ )
cout <<
"Parton " << partonIndices[
ii] <<
" has sister " << sisterIndices[
ii] << endl;
257 if ( sisterIndices[
ii] < 0 ) {
258 if (
verbose_ )
cout <<
"No sister. Classified as flavor excitation" << endl;
259 flavorSources[
ii] = FlavorHistory::FLAVOR_EXC;
272 ( sisterIndices[
ii] >= 0 &&
static_cast<unsigned int>(sisterIndices[
ii]) < particles.size() ) ?
276 if (
verbose_ )
cout <<
"Making matched shallow clones : ";
278 if ( matched != matchedEnd ) {
285 if (
verbose_ )
cout <<
"Making sister shallow clones : ";
287 if ( sister != matchedEnd ) {
294 if (
verbose_ )
cout <<
"Making history object" << endl;
298 partonIndices[ii], progenitorIndices[ii], sisterIndices[ii],
301 if (
verbose_ )
cout <<
"Adding flavor history : " << history << endl;
302 flavorHistoryEvent->push_back( history );
307 if ( flavorHistoryEvent->size() > 0 ) {
310 if (
verbose_ )
cout <<
"Caching flavor history event" << endl;
311 flavorHistoryEvent->cache();
314 cout <<
"Outputting pdg id = " <<
pdgIdToSelect_ <<
" with nelements = " << flavorHistoryEvent->size() << endl;
315 vector<FlavorHistory>::const_iterator
i = flavorHistoryEvent->begin(),
316 iend = flavorHistoryEvent->end();
317 for ( ; i !=iend; ++
i ) {
330 vector<Candidate const *> & moms )
337 moms.push_back( dau );
353 for ( ; j != jend; ++j ) {
354 double dri =
deltaR( parton.
p4(), j->p4() );
FlavorHistoryProducer(const edm::ParameterSet &)
constructor
~FlavorHistoryProducer() override
destructor
OrphanHandle< PROD > put(std::unique_ptr< PROD > product)
Put a new product.
bool getByToken(EDGetToken token, Handle< PROD > &result) const
virtual const Candidate * mother(size_type i=0) const =0
return pointer to mother
std::string flavorHistoryName_
void find(edm::Handle< EcalRecHitCollection > &hits, DetId thisDet, std::vector< EcalRecHitCollection::const_iterator > &hit, bool debug=false)
void produce(edm::Event &e, const edm::EventSetup &) override
process one event
reco::CandidateView::const_iterator getClosestJet(edm::Handle< reco::CandidateView > const &pJets, reco::Candidate const &parton) const
edm::EDGetTokenT< reco::CandidateView > srcToken_
virtual int status() const =0
status word
#define DEFINE_FWK_MODULE(type)
const_iterator begin() const
virtual const LorentzVector & p4() const =0
four-momentum Lorentz vector
virtual int pdgId() const =0
PDG identifier.
virtual size_type numberOfMothers() const =0
number of mothers (zero or one in most of but not all the cases)
Abs< T >::type abs(const T &t)
edm::Ptr< Candidate > CandidatePtr
persistent reference to an object in a collection of Candidate objects
void getAncestors(const reco::Candidate &c, std::vector< reco::Candidate const * > &moms)
boost::indirect_iterator< typename seq_t::const_iterator > const_iterator
const_iterator end() const
edm::EDGetTokenT< reco::CandidateView > matchedSrcToken_