CMS 3D CMS Logo

HLTProdCand.cc

Go to the documentation of this file.
00001 
00012 #include "HLTrigger/HLTexample/interface/HLTProdCand.h"
00013 
00014 #include "DataFormats/Common/interface/Handle.h"
00015 
00016 #include "FWCore/Framework/interface/Event.h"
00017 #include "FWCore/Framework/interface/EventSetup.h"
00018 
00019 #include "DataFormats/RecoCandidate/interface/RecoEcalCandidate.h"
00020 #include "DataFormats/RecoCandidate/interface/RecoEcalCandidateFwd.h"
00021 #include "DataFormats/EgammaCandidates/interface/Electron.h"
00022 #include "DataFormats/EgammaCandidates/interface/ElectronFwd.h"
00023 #include "DataFormats/RecoCandidate/interface/RecoChargedCandidate.h"
00024 #include "DataFormats/RecoCandidate/interface/RecoChargedCandidateFwd.h"
00025 #include "DataFormats/JetReco/interface/CaloJet.h"
00026 #include "DataFormats/JetReco/interface/CaloJetCollection.h"
00027 #include "DataFormats/Candidate/interface/CompositeCandidate.h"
00028 #include "DataFormats/Candidate/interface/CompositeCandidateFwd.h"
00029 #include "DataFormats/METReco/interface/CaloMET.h"
00030 #include "DataFormats/METReco/interface/CaloMETFwd.h"
00031 #include "DataFormats/METReco/interface/MET.h"
00032 #include "DataFormats/METReco/interface/METFwd.h"
00033 
00034 #include "DataFormats/JetReco/interface/GenJet.h"
00035 #include "DataFormats/JetReco/interface/GenJetCollection.h"
00036 #include "DataFormats/METReco/interface/GenMET.h"
00037 #include "DataFormats/METReco/interface/GenMETCollection.h"
00038 
00039 #include "SimDataFormats/HepMCProduct/interface/HepMCProduct.h"
00040 
00041 #include "FWCore/MessageLogger/interface/MessageLogger.h"
00042 
00043 #include "HepPDT/ParticleID.hh"
00044 
00045 //
00046 // constructors and destructor
00047 //
00048  
00049 HLTProdCand::HLTProdCand(const edm::ParameterSet& iConfig) :
00050   jetsTag_ (iConfig.getParameter<edm::InputTag>("jetsTag")),
00051   metsTag_ (iConfig.getParameter<edm::InputTag>("metsTag"))
00052 {
00053   LogDebug("") << "Inputs: jets/mets: " << jetsTag_.encode() << " / " << metsTag_.encode();
00054 
00055    //register your products
00056 
00057    produces<reco::RecoEcalCandidateCollection>("photons");
00058    produces<reco::ElectronCollection>("electrons");
00059    produces<reco::RecoChargedCandidateCollection>("muons");
00060    produces<reco::CaloJetCollection>("taus");
00061    produces<reco::CaloJetCollection>("jets");
00062    produces<reco::CaloMETCollection>("mets");
00063    produces<reco::METCollection>("hts");
00064 
00065    produces<reco::RecoChargedCandidateCollection>("tracks");
00066    produces<reco::RecoEcalCandidateCollection>("clusters");
00067 
00068 }
00069 
00070 HLTProdCand::~HLTProdCand()
00071 {
00072 }
00073 
00074 //
00075 // member functions
00076 //
00077 
00078 // ------------ method called to produce the data  ------------
00079 void
00080 HLTProdCand::produce(edm::Event& iEvent, const edm::EventSetup& iSetup)
00081 {
00082    using namespace std;
00083    using namespace edm;
00084    using namespace reco;
00085 
00086    // produce collections of photons, electrons, muons, taus, jets, MET
00087    auto_ptr<RecoEcalCandidateCollection>    phot (new RecoEcalCandidateCollection);
00088    auto_ptr<ElectronCollection> elec (new ElectronCollection);
00089    auto_ptr<RecoChargedCandidateCollection> muon (new RecoChargedCandidateCollection);
00090    auto_ptr<CaloJetCollection>  taus (new CaloJetCollection); // stored as jets
00091    auto_ptr<CaloJetCollection>  jets (new CaloJetCollection);
00092    auto_ptr<CaloMETCollection>  mets (new CaloMETCollection);
00093    auto_ptr<METCollection>  hts (new METCollection);
00094 
00095    // as well as charged tracks and elmg. superclusters
00096    auto_ptr<RecoChargedCandidateCollection> trck (new RecoChargedCandidateCollection);
00097    auto_ptr<RecoEcalCandidateCollection>    ecal (new RecoEcalCandidateCollection);
00098 
00099    // jets and MET are special: check whether clustered jets and mets
00100    // exist already
00101    int njets(-1);
00102    edm::Handle<GenJetCollection> mcjets;
00103    iEvent.getByLabel(jetsTag_,mcjets);
00104    if (mcjets.isValid()) njets=mcjets->size();
00105    LogDebug("") << "MC-truth jets found: " << njets;
00106    for (int i=0; i<njets; i++) {
00107      math::XYZTLorentzVector p4(((*mcjets)[i]).p4());
00108      CaloJet::Specific specific;
00109      Jet::Constituents jetconst;
00110      jets->push_back(CaloJet(p4,specific,jetconst));
00111    }
00112 
00113    int nmets(-1);
00114    edm::Handle<GenMETCollection> mcmets;
00115    iEvent.getByLabel(metsTag_,mcmets);
00116    if (mcmets.isValid()) nmets=mcmets->size();
00117    LogDebug("") << "MC-truth mets found: " << nmets;
00118    for (int i=0; i<nmets; i++) {
00119      math::XYZTLorentzVector p4(((*mcmets)[i]).p4());
00120      SpecificCaloMETData specific;
00121      mets->push_back(CaloMET(specific,p4.Et(),p4,math::XYZPoint(0,0,0)));
00122    }
00123 
00124    // photons, electrons, muons and taus: generator level
00125    // tracks: all charged particles; superclusters: electrons and photons
00126 
00127    // get hold of generator records
00128    vector<edm::Handle<edm::HepMCProduct> > hepmcs;
00129    edm::Handle<edm::HepMCProduct> hepmc;
00130    iEvent.getManyByType(hepmcs);
00131    LogDebug("") << "Number of HepMC products found: " << hepmcs.size();
00132 
00133    // loop over all final-state particles in all generator records
00134    for (unsigned int i=0; i!=hepmcs.size(); i++) {
00135      hepmc=hepmcs[i];
00136      const HepMC::GenEvent* evt = hepmc->GetEvent();
00137      for (HepMC::GenEvent::particle_const_iterator pitr=evt->particles_begin(); pitr!=evt->particles_end(); pitr++) {
00138 
00139        // stable particles only!
00140        if ( (*pitr)->status()==1) {
00141          // particle type
00142          const int ipdg((*pitr)->pdg_id());
00143          // 4-momentum
00144          const HepMC::FourVector p((*pitr)->momentum());
00145          const math::XYZTLorentzVector 
00146            p4(math::XYZTLorentzVector(p.x(),p.y(),p.z(),p.t()));
00147          // charge
00148          const int qX3(HepPDT::ParticleID(ipdg).threeCharge());
00149 
00150          // charged particles yield tracks
00151          if ( qX3 != 0 ) {
00152            trck->push_back(RecoChargedCandidate(qX3/abs(qX3),p4));
00153          }
00154 
00155          if (abs(ipdg)==11) {
00156            // e+ e-
00157            elec->push_back(    Electron     (-ipdg/abs(ipdg),p4));
00158            ecal->push_back(RecoEcalCandidate(-ipdg/abs(ipdg),p4));
00159          } else if (abs(ipdg)==13) {
00160            // mu+ mu-
00161            muon->push_back(RecoChargedCandidate(-ipdg/abs(ipdg),p4));
00162          } else if (abs(ipdg)==15 || abs(ipdg)==17) {
00163            // tau+ tau- or 4th generation tau'+ tau'-
00164            CaloJet::Specific specific;
00165            Jet::Constituents jetconst;
00166            taus->push_back(CaloJet(p4,specific,jetconst));
00167          } else if (abs(ipdg)==22) {
00168            // photon
00169            phot->push_back(RecoEcalCandidate(0,p4));
00170            ecal->push_back(RecoEcalCandidate(0,p4));
00171          } else if (abs(ipdg)==12 || abs(ipdg)==14 || abs(ipdg)==16 || abs(ipdg)==18) {
00172            // neutrinos (e mu tau 4th generation)
00173            if (nmets==-1) {
00174              // if no prepared mets, each becomes a met on its own (crude)!
00175              SpecificCaloMETData specific;
00176              mets->push_back(CaloMET(specific,p4.Et(),p4,math::XYZPoint(0,0,0)));
00177            }
00178          } else {
00179            // any other particle
00180            if (njets==-1) {
00181              // if no prepared jets, each becomes a jet on its own (crude)!
00182              CaloJet::Specific specific;
00183              Jet::Constituents jetconst;
00184              jets->push_back(CaloJet(p4,specific,jetconst));
00185            }
00186          }
00187        }
00188      }
00189    }
00190 
00191    LogDebug("") << "Number of g/e/m/t/j/M/H/TR/SC objects reconstructed:"
00192                 << " " << phot->size()
00193                 << " " << elec->size()
00194                 << " " << muon->size()
00195                 << " " << taus->size()
00196                 << " " << jets->size()
00197                 << " " << mets->size()
00198                 << " " << hts->size()
00199                 << " " << trck->size()
00200                 << " " << ecal->size()
00201                 ;
00202 
00203    // put them into the event
00204 
00205    iEvent.put(phot,"photons");
00206    iEvent.put(elec,"electrons");
00207    iEvent.put(muon,"muons");
00208    iEvent.put(taus,"taus");
00209    iEvent.put(jets,"jets");
00210    iEvent.put(mets,"mets");
00211    iEvent.put(hts,"hts");
00212    iEvent.put(trck,"tracks");
00213    iEvent.put(ecal,"clusters");
00214 
00215    return;
00216 }

Generated on Tue Jun 9 17:37:54 2009 for CMSSW by  doxygen 1.5.4