Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-02-14 13:32:26

0001 #include "FWCore/Framework/interface/EDAnalyzer.h"
0002 #include "FWCore/Framework/interface/Event.h"
0003 #include "DataFormats/Common/interface/Handle.h"
0004 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0005 #include "FWCore/Utilities/interface/InputTag.h"
0006 #include "DataFormats/Candidate/interface/Candidate.h"
0007 #include "FWCore/Utilities/interface/EDMException.h"
0008 using namespace std;
0009 using namespace edm;
0010 using namespace reco;
0011 
0012 class TestGenParticleCandidates : public EDAnalyzer {
0013 private:
0014   bool dumpHepMC_;
0015 public:
0016   explicit TestGenParticleCandidates( const ParameterSet & cfg ) :
0017     srcToken_( consumes<CandidateCollection>( cfg.getParameter<InputTag>( "src" ) ) ) {
0018   }
0019 private:
0020   void analyze( const Event & evt, const EventSetup&) override {
0021     Handle<CandidateCollection> gen;
0022     evt.getByToken( srcToken_, gen );
0023     size_t n = gen->size();
0024     if (n == 0)
0025       throw Exception(errors::EventCorruption)
0026     << "No particles in genParticleCandidates\n";
0027     for(size_t i = 0; i < n; ++ i) {
0028       const Candidate & p = (*gen)[i];
0029       size_t nd = p.numberOfDaughters();
0030       if(nd==0 && p.status()==3)
0031       throw Exception(errors::EventCorruption)
0032         << "Particle with no daughters and status " << p.status()
0033         << ", pdgId = " << p.pdgId() << "\n";
0034       for(size_t j = 0; j < nd; ++ j ) {
0035     const Candidate * d = p.daughter(j);
0036     size_t nm = d->numberOfMothers();
0037     bool noMother = true;
0038     for(size_t k = 0; k < nm; ++ k ) {
0039       if(d->mother(k)==&p) {
0040         noMother = false;
0041         break;
0042       }
0043     }
0044     if(noMother)
0045       throw Exception(errors::EventCorruption)
0046         << "Inconsistent mother/daughter relation, pdgId = " << d->pdgId() << "\n";
0047        }
0048     }
0049   }
0050   EDGetTokenT<CandidateCollection> srcToken_;
0051 };
0052 
0053 #include "FWCore/Framework/interface/MakerMacros.h"
0054 
0055 DEFINE_FWK_MODULE( TestGenParticleCandidates );
0056 
0057 
0058