From dafebc11c4adf07edad6a0def0bba74f5e66bce2 Mon Sep 17 00:00:00 2001 From: nancy Date: Tue, 7 Jul 2020 12:58:48 +0200 Subject: [PATCH 1/2] Add a module (ConversionSelector) which reads conversions from miniAOD and applies the selection of conversions interesting for this study (see pas presentations, radius and quality) --- BParkingNano/BuildFile.xml | 3 +- BParkingNano/plugins/ConversionSelector.cc | 687 ++++++++++++++++++++ BParkingNano/plugins/ConversionSelector.h | 288 ++++++++ BParkingNano/python/conversionsBPark_cff.py | 211 ++++++ BParkingNano/python/nanoBPark_cff.py | 5 + BParkingNano/test/run_nano_cfg.py | 1 + 6 files changed, 1194 insertions(+), 1 deletion(-) create mode 100644 BParkingNano/plugins/ConversionSelector.cc create mode 100644 BParkingNano/plugins/ConversionSelector.h create mode 100644 BParkingNano/python/conversionsBPark_cff.py diff --git a/BParkingNano/BuildFile.xml b/BParkingNano/BuildFile.xml index 07cde32c97e..17b30107f9f 100644 --- a/BParkingNano/BuildFile.xml +++ b/BParkingNano/BuildFile.xml @@ -1,5 +1,6 @@ + - \ No newline at end of file + diff --git a/BParkingNano/plugins/ConversionSelector.cc b/BParkingNano/plugins/ConversionSelector.cc new file mode 100644 index 00000000000..765408e6815 --- /dev/null +++ b/BParkingNano/plugins/ConversionSelector.cc @@ -0,0 +1,687 @@ +#include +// +#include "FWCore/ServiceRegistry/interface/Service.h" +#include "CommonTools/UtilAlgos/interface/TFileService.h" +// +#include "ConversionSelector.h" + +// +#include "FWCore/Framework/interface/MakerMacros.h" +#include "FWCore/MessageLogger/interface/MessageLogger.h" +#include "FWCore/Utilities/interface/Exception.h" + + +#include "CLHEP/Units/GlobalPhysicalConstants.h" +#include "CommonTools/Statistics/interface/ChiSquaredProbability.h" +// +#include "MagneticField/Engine/interface/MagneticField.h" +#include "Geometry/TrackerGeometryBuilder/interface/TrackerGeometry.h" +#include "Geometry/Records/interface/TrackerDigiGeometryRecord.h" +#include "MagneticField/Records/interface/IdealMagneticFieldRecord.h" +//#include "TrackingTools/Records/interface/TrackingComponentsRecord.h" +//#include "TrackingTools/TrajectoryState/interface/TrajectoryStateOnSurface.h" +//#include "TrackingTools/TrajectoryState/interface/TrajectoryStateTransform.h" +//#include "TrackingTools/MaterialEffects/interface/PropagatorWithMaterial.h" + +// +#include "DataFormats/Common/interface/Handle.h" +#include "DataFormats/TrackReco/interface/Track.h" +#include "DataFormats/TrackReco/interface/TrackExtra.h" +#include "DataFormats/TrackReco/interface/TrackFwd.h" +#include "DataFormats/EgammaCandidates/interface/GsfElectron.h" +#include "DataFormats/EgammaCandidates/interface/Conversion.h" +#include "DataFormats/EgammaCandidates/interface/Photon.h" +#include "DataFormats/EgammaReco/interface/SuperCluster.h" +#include "DataFormats/TrackCandidate/interface/TrackCandidateCollection.h" +#include "DataFormats/TrackingRecHit/interface/TrackingRecHit.h" +#include "DataFormats/EgammaReco/interface/BasicCluster.h" +#include "DataFormats/EgammaReco/interface/BasicCluster.h" +#include "DataFormats/EgammaReco/interface/BasicClusterFwd.h" +#include "DataFormats/CaloRecHit/interface/CaloCluster.h" +#include "DataFormats/CaloRecHit/interface/CaloClusterFwd.h" +#include "DataFormats/DetId/interface/DetId.h" +#include "DataFormats/JetReco/interface/GenJetCollection.h" +#include "DataFormats/HepMCCandidate/interface/GenParticle.h" +#include "DataFormats/GeometrySurface/interface/BoundCylinder.h" +#include "DataFormats/GeometrySurface/interface/BoundDisk.h" +#include "DataFormats/GeometrySurface/interface/SimpleCylinderBounds.h" +#include "DataFormats/GeometrySurface/interface/SimpleDiskBounds.h" +#include "DataFormats/Math/interface/deltaPhi.h" +#include "DataFormats/GsfTrackReco/interface/GsfTrackFwd.h" +#include "TrackingTools/IPTools/interface/IPTools.h" +#include "TrackingTools/TransientTrack/interface/TransientTrackBuilder.h" +#include "TrackingTools/Records/interface/TransientTrackRecord.h" + +// +#include "RecoEgamma/EgammaMCTools/interface/PhotonMCTruthFinder.h" +#include "RecoEgamma/EgammaMCTools/interface/PhotonMCTruth.h" +#include "RecoEgamma/EgammaMCTools/interface/ElectronMCTruth.h" +#include "RecoEcal/EgammaCoreTools/interface/EcalClusterTools.h" +#include "Geometry/Records/interface/CaloGeometryRecord.h" +#include "Geometry/CaloTopology/interface/CaloTopology.h" +#include "Geometry/CaloEventSetup/interface/CaloTopologyRecord.h" + +#include "RecoEgamma/EgammaPhotonAlgos/interface/ConversionHitChecker.h" +#include "DataFormats/PatCandidates/interface/CompositeCandidate.h" +// +// +#include "TFile.h" +#include "TH1.h" +#include "TH2.h" +#include "TTree.h" +#include "TVector3.h" +#include "TProfile.h" +// +/** \class ConversionSelector + ** + ** + ** $Id: ConversionSelector + ** \author N.Marinelli - Univ. of Notre Dame + ** + ***/ + +using namespace std; + + +ConversionSelector::ConversionSelector( const edm::ParameterSet& pset ) + { + outputFileName_ = pset.getParameter("outFileName"); + verbosity_ = pset.getUntrackedParameter("Verbosity"); + parameters_ = pset; + + lowPtElectronCollection_ = pset.getParameter("lowPtElectronCollection"); + lowPtElectronProducer_ = pset.getParameter("lowPtElectronProducer"); + lowPtElectronCollectionPr_Token_ = consumes >(edm::InputTag(lowPtElectronProducer_,lowPtElectronCollection_)); + + conversionCollectionProducer_ = pset.getParameter("convProducer"); + conversionCollection_ = pset.getParameter("conversionCollection"); + conversionCollectionPr_Token_ = consumes ( + edm::InputTag(conversionCollectionProducer_, + conversionCollection_)); + + unBiased_ = consumes>( pset.getParameter("unbiasedSeeding") ); + mvaId_src_ = consumes>( pset.getParameter("mvaId") ); + + // use configuration file to setup output collection names + filteredConvertedPhotonCollection_ = pset.getParameter("filteredConversions"); + + // Register the product + produces(filteredConvertedPhotonCollection_); + + minPtOnTracks_ = pset.getParameter("minPtOnTracks"); + minPhoEtCut_ = pset.getParameter("minPhoEtCut"); + generalTracksOnly_ = pset.getParameter("generalTracksOnly"); + gsfTracksOpenOnly_ = pset.getParameter("gsfTracksOpenOnly"); + arbitratedMerged_ = pset.getParameter("arbitratedMerged"); + arbitratedEcalSeeded_ = pset.getParameter("arbitratedEcalSeeded"); + ecalalgotracks_ = pset.getParameter("ecalalgotracks"); + highPurity_ = pset.getParameter("highPurity"); + minProb_ = pset.getParameter("minProb"); + maxHitsBeforeVtx_ = pset.getParameter("maxHitsBeforeVtx"); + minLxy_ = pset.getParameter("minLxy"); + + + offline_pvToken_ = consumes(pset.getUntrackedParameter ("offlinePV", + edm::InputTag("offlineSlimmedPrimaryVertices"))); + + beamspotToken_ = consumes(pset.getUntrackedParameter ("beamspot",edm::InputTag("offlineBeamSpot"))); + rho_token_ = consumes(pset.getParameter ("rhoHandle")); + + + nEvt_=0; + isMatchedToLowPtSC_.reserve(2); + + nAcceptedConvTot=0; + + } + + + +ConversionSelector::~ConversionSelector() { + + + edm::LogInfo("ConversionSelector") << "Analyzed " << nEvt_ << "\n"; + // std::cout << "::endJob Analyzed " << nEvt_ << " events " << " with total " << nPho_ << " Photons " << "\n"; + std::cout << "ConversionSelector::DTOR Analyzed " << nEvt_ << " events " << "\n"; + + + +} + + + + +void ConversionSelector::produce(edm::Event& e, const edm::EventSetup& esup ) { + + + using namespace edm; + // const float etaPhiDistance=0.01; + // Fiducial region + // const float TRK_BARL =0.9; + const float BARL = 1.4442; // DAQ TDR p.290 + // const float END_LO = 1.566; // unused + const float END_HI = 2.5; + // Electron mass + // const Float_t mElec= 0.000511; // unused + + isMatchedToLowPtSC_.clear(); + + pat::CompositeCandidateCollection outFilteredConversionCollection; + auto outFilteredConversionCollection_p = std::make_unique(); + + + nEvt_++; + LogInfo("ConversionSelector") << "ConversionSelector Analyzing event number: " << e.id() << " Global Counter " << nEvt_ <<"\n"; + + + + ///// Get the recontructed conversions + Handle convHandle; + e.getByToken(conversionCollectionPr_Token_, convHandle); + const reco::ConversionCollection convCollection = *(convHandle.product()); + if (!convHandle.isValid()) { + edm::LogError("ConversionSelector") << "Error! Can't get the collection "<< std::endl; + return; + } + + + ///// Get the recontructed low pt gsfElectrons + Handle > lowPtEleHandle; + e.getByToken(lowPtElectronCollectionPr_Token_, lowPtEleHandle); + std::vector lowPtElectronCollection = *(lowPtEleHandle.product()); + if (!lowPtEleHandle.isValid()) { + edm::LogError("ConversionSelector") << "Error! Can't get the lowPt electron collection "<< std::endl; + return; + } + + edm::Handle > unBiased; + e.getByToken(unBiased_, unBiased); + + edm::Handle > mvaId; + e.getByToken(mvaId_src_, mvaId); + + + + // offline Primary vertex + /* +bool valid_pvtx = false; + edm::Handle vertexHandle; + reco::VertexCollection vertexCollection; + e.getByToken(offline_pvToken_, vertexHandle); + if (!vertexHandle.isValid()) { + edm::LogError("ConvAnalysisMiniAod") << "Error! Can't get the product primary Vertex Collection "<< "\n"; + } else { + vertexCollection = *(vertexHandle.product()); + } + + reco::Vertex pvtx; + if (!vertexCollection.empty()){ + pvtx = *(vertexCollection.begin()); + //asking for one good vertex + if (pvtx.isValid() && fabs(pvtx.position().z())<=15 && pvtx.position().Rho()<=2){ + valid_pvtx = true; + } + } + */ + + + + edm::Handle bsHandle; + e.getByToken(beamspotToken_, bsHandle); + if (!bsHandle.isValid()) { + edm::LogError("TrackerOnlyConversionProducer") + << "Error! Can't get the product primary Vertex Collection "<< "\n"; + return; + } + const reco::BeamSpot &thebs = *bsHandle.product(); + + + edm::Handle rhoHandle; + e.getByToken(rho_token_, rhoHandle); + rho_ = *rhoHandle; + + edm::ESHandle theB ; + esup.get().get("TransientTrackBuilder",theB); + + + + //std::cout << " ConversionSelector Conversion collection size " << convHandle->size() << std::endl; + int nAcceptedConv=0; + for (reco::ConversionCollection::const_iterator conv = convHandle->begin();conv!=convHandle->end();++conv) { + const reco::Conversion aConv = (*conv); + + if ( arbitratedMerged_ && !aConv.quality(reco::Conversion::arbitratedMerged) ) continue; + if ( generalTracksOnly_ && !aConv.quality(reco::Conversion::generalTracksOnly) ) continue; + if ( arbitratedEcalSeeded_ && !aConv.quality(reco::Conversion::arbitratedEcalSeeded) ) continue; + if ( highPurity_ && !aConv.quality(reco::Conversion::highPurity) ) continue; + + + std::vector > tracks = aConv.tracks(); + RefToBase tk1 = aConv.tracks().front(); + RefToBase tk2 = aConv.tracks().back(); + const reco::Track refTk1 = aConv.conversionVertex().refittedTracks().front(); + const reco::Track refTk2 = aConv.conversionVertex().refittedTracks().back(); + const reco::Vertex& vtx = aConv.conversionVertex(); + + + //requires two tracks and a valid vertex + if (tracks.size() !=2 || !(vtx.isValid())) continue; + if ( tk1->pt() < minPtOnTracks_ || tk2->pt() < minPtOnTracks_) continue; + + + //compute transverse decay length with respect to beamspot + math::XYZVectorF refittedMom = aConv.refittedPairMomentum(); + double dbsx = aConv.conversionVertex().x() - thebs.x0(); + double dbsy = aConv.conversionVertex().y() - thebs.y0(); + double lxy = (refittedMom.x()*dbsx + refittedMom.y()*dbsy)/refittedMom.rho(); + lxy_=lxy; + // if (lxyalgo()==reco::TrackBase::outInEcalSeededConv || tk1->algo()==reco::TrackBase::inOutEcalSeededConv) || !(tk2->algo()==reco::TrackBase::outInEcalSeededConv || tk2->algo()==reco::TrackBase::inOutEcalSeededConv) ) ) continue; + + nAcceptedConv++; + + + + //TODO replace it with phi at vertex + //float dPhiTracksAtVtx = aConv.dPhiTracksAtVtx(); + + /////////// Quantities per conversion + + float invM=aConv.pairInvariantMass(); + invMass_fromDF_=invM; + + float chi2Prob = ChiSquaredProbability( aConv.conversionVertex().chi2(), aConv.conversionVertex().ndof() ); + uint maxNHitsBeforeVtx = aConv.nHitsBeforeVtx().size()>1 ? max(aConv.nHitsBeforeVtx().at(0),aConv.nHitsBeforeVtx().at(1)) : 0; + uint sumNHitsBeforeVtx = aConv.nHitsBeforeVtx().size()>1 ? aConv.nHitsBeforeVtx().at(0) + aConv.nHitsBeforeVtx().at(1) : 0; + + + if (chi2Prob <= 0.0005) continue; + float vtxR = sqrt(aConv.conversionVertex().position().perp2()); + if (vtxR < 1.5 || vtxR > 4) continue; + + + + unsigned int ilead = 0, itrail = 1; + // use pt of tracks before refitting + if (tk2->pt() > tk1->pt()) { + ilead = 1; + itrail = 0; + } + + //std::cout << " ilead " << ilead << " itrail " << itrail << std::endl; + + math::XYZVectorF leadPin = aConv.tracksPin().at(ilead); + math::XYZVectorF trailPin = aConv.tracksPin().at(itrail); + + RefToBase tkleadBeforeVtxFit = aConv.tracks().at(ilead); + RefToBase tktrailBeforeVtxFit = aConv.tracks().at(itrail); + + const reco::Track tklead = aConv.conversionVertex().refittedTracks().at(ilead); + const reco::Track tktrail = aConv.conversionVertex().refittedTracks().at(itrail); + + // calculate invariant mass before the fit to common vertex from Pin + float invMass_fromPin=mee( leadPin.x(), + leadPin.y(), + leadPin.z(), + trailPin.x(), + trailPin.y(), + trailPin.z()); + invMass_fromPin_=invMass_fromPin; + + // calculate invariant mass before the fit to common vertex + + float invMass_beforeFit= mee ( tkleadBeforeVtxFit->px(), + tkleadBeforeVtxFit->py(), + tkleadBeforeVtxFit->pz(), + tktrailBeforeVtxFit->px(), + tktrailBeforeVtxFit->py(), + tktrailBeforeVtxFit->pz() ); + invMass_beforeFit_=invMass_beforeFit; + + // calculate invariant mass after the fit to common vertex + float invMass_afterFit=mee( tklead.px(), + tklead.py(), + tklead.pz(), + tktrail.px(), + tktrail.py(), + tktrail.pz()); + invMass_afterFit_ = invMass_afterFit; + + + int deltaExpectedHitsInner = tklead.hitPattern().numberOfLostHits(reco::HitPattern::MISSING_INNER_HITS) + - tktrail.hitPattern().numberOfLostHits(reco::HitPattern::MISSING_INNER_HITS); + //int leadExpectedHitsInner = tklead.hitPattern().numberOfLostHits(reco::HitPattern::MISSING_INNER_HITS); + uint leadNHitsBeforeVtx = aConv.nHitsBeforeVtx().size()>1 ? aConv.nHitsBeforeVtx().at(ilead) : 0; + uint trailNHitsBeforeVtx = aConv.nHitsBeforeVtx().size()>1 ? aConv.nHitsBeforeVtx().at(itrail) : 0; + float dCotFromPin = 1./tan(trailPin.theta())-1./tan(leadPin.theta()); + + + pat::CompositeCandidate cand; + math::PtEtaPhiMLorentzVector convp4( + aConv.pairMomentum().perp2(), + aConv.pairMomentum().eta(), + aConv.pairMomentum().phi(), + invMass_fromPin + ); + + cand.setP4(convp4); + cand.addUserFloat("rho",rho_); + cand.addUserFloat("vtxChi2Prob",chi2Prob); + cand.addUserFloat("vtxR",sqrt(aConv.conversionVertex().position().perp2())); + cand.addUserFloat("vtxX",aConv.conversionVertex().position().x()); + cand.addUserFloat("vtxY",aConv.conversionVertex().position().y()); + cand.addUserFloat("vtxZ",aConv.conversionVertex().position().z()); + cand.addUserFloat("dCotFromPin",dCotFromPin); + cand.addUserFloat("dMinAppTracks",aConv.distOfMinimumApproach()); + cand.addUserFloat("dPhiTracksAtVtx", aConv.dPhiTracksAtVtx()); + cand.addUserFloat("maxNHitsBeforeVtx",maxNHitsBeforeVtx); + cand.addUserFloat("leadNHitsBeforeVtx",leadNHitsBeforeVtx); + cand.addUserFloat("trailNHitsBeforeVtx",trailNHitsBeforeVtx); + cand.addUserFloat("sumNHitsBeforeVtx",sumNHitsBeforeVtx); + cand.addUserFloat("deltaExpectedHitsInner",deltaExpectedHitsInner); + + + + + std::vector unbiased_seedBDT; + std::vector mvaIdV; + + + std::vector eleV; + + std::vector elePt; + std::vector eleCh; + std::vector eleEta; + std::vector elePhi; + std::vector ele_seed_dEta; + std::vector ele_eclu_EoverP; + std::vector ele_sc_dEta; + std::vector ele_sc_dPhi; + std::vector ele_fBrem; + std::vector ele_shFrInHits; + + std::vector cluSize; + std::vector gsfPmode; + std::vector gsfChi2; + std::vector gsfNhits; + std::vector gsfDR; + + std::vector scEnergy; + std::vector scEta; + std::vector scEtaWidth; + std::vector scPhiWidth; + std::vector full5x5_r9; + std::vector full5x5_HoverE; + std::vector kf_Chi2; + std::vector kf_p; + std::vector kf_nHits; + std::vector kf_DR; + + + + + eleV.resize(2); + + elePt.resize(2); + eleCh.resize(2); + eleEta.resize(2); + elePhi.resize(2); + + ele_seed_dEta.resize(2); + ele_eclu_EoverP.resize(2); + ele_sc_dEta.resize(2); + ele_sc_dPhi.resize(2); + ele_fBrem.resize(2); + ele_shFrInHits.resize(2); + cluSize.resize(2); + scEnergy.resize(2); + scEta.resize(2); + scEtaWidth.resize(2); + scPhiWidth.resize(2); + full5x5_HoverE.resize(2); + full5x5_r9.resize(2); + kf_Chi2.resize(2); + kf_p.resize(2); + kf_nHits.resize(2); + kf_DR.resize(2); + + gsfPmode.resize(2); + gsfChi2.resize(2); + gsfNhits.resize(2); + gsfDR.resize(2); + + unbiased_seedBDT.resize(2); + mvaIdV.resize(2); + + // check here the -hard- matching between the tracks and lowPt electron objects. Should be 100% by construction + int nMatchedTracks=0; + int iOrd=0; + for ( unsigned int i=0; ipt(); + //std::cout << " Track " << iOrd << " tracks[i].id() " << tracks[iOrd].id() << " key " << tracks[iOrd].key() << std::endl; + + isMatchedToLowPtSC_[iOrd]=0; + // std::cout << " gsfEle size " << lowPtElectronCollection.size() << std::endl; + + + int idx=0; + for( std::vector::const_iterator iEle = lowPtElectronCollection.begin(); iEle != lowPtElectronCollection.end(); iEle++) { + edm::Ref ref(lowPtEleHandle,idx); + idx++; + + pat::Electron myPatEle = pat::Electron(*iEle); + reco::GsfElectron myEle = reco::GsfElectron(*iEle); + + reco::GsfTrackRef gsfTrk= myEle.gsfTrack(); + + if (gsfTrk.isNull()) continue; + + float mva_id = 999.; + mva_id = float((*mvaId)[ref]); + + + if ( gsfTrk.id() == tracks[iOrd].id() && gsfTrk.key() == tracks[iOrd].key() ) { + nMatchedTracks++; + + float clusize = myEle.superCluster()->clustersSize(); + eleV[iOrd]=myEle; + + + + // + elePt[iOrd]=myEle.pt(); + eleCh[iOrd]=myEle.charge(); + eleEta[iOrd]=myEle.eta(); + elePhi[iOrd]=myEle.phi(); + // + ele_seed_dEta[iOrd]= myEle.deltaEtaSeedClusterTrackAtCalo(); + ele_eclu_EoverP[iOrd]=(1./myEle.ecalEnergy()) - (1./myEle.p()); + ele_sc_dEta[iOrd]=myEle.deltaEtaSuperClusterTrackAtVtx(); + ele_sc_dPhi[iOrd]=myEle.deltaPhiSuperClusterTrackAtVtx(); + ele_fBrem[iOrd]= myEle.fbrem(); + ele_shFrInHits[iOrd]=myEle.shFracInnerHits(); + + if ( myEle.core().isNonnull() ) { + cluSize[iOrd]=myEle.superCluster()->clustersSize(); + scEta[iOrd] = myEle.superCluster()->eta(); + scEnergy[iOrd] = myEle.superCluster()->energy(); + scEtaWidth[iOrd] = myEle.superCluster()->etaWidth(); + scPhiWidth[iOrd] = myEle.superCluster()->phiWidth(); + } + full5x5_HoverE[iOrd] = myEle.full5x5_hcalOverEcal(); + full5x5_r9[iOrd] = myEle.full5x5_r9(); + gsfPmode[iOrd]=gsfTrk->pMode(); + gsfChi2[iOrd]=gsfTrk->normalizedChi2(); + gsfNhits[iOrd]=(float)gsfTrk->found(); + + TVector3 gsfTV3(0,0,0); + gsfTV3.SetPtEtaPhi(gsfTrk->ptMode(), gsfTrk->etaMode(), gsfTrk->phiMode()); + TVector3 eleTV3(0,0,0); + eleTV3.SetPtEtaPhi(myEle.pt(), myEle.eta(), myEle.phi()); + gsfDR[iOrd] = eleTV3.DeltaR(gsfTV3); + + + + + unbiased_seedBDT[iOrd] = float((*unBiased)[gsfTrk]); + mvaIdV[iOrd]=mva_id; + + + // std::cout << " Matching ele to track " << i <pt()); + cand.addUserFloat("tkTrail_pt",aConv.tracks()[itrail]->pt()); + cand.addUserFloat("tkLead_eta",aConv.tracks()[ilead]->eta()); + cand.addUserFloat("tkTrail_eta",aConv.tracks()[itrail]->eta()); + cand.addUserFloat("tkLead_phi",aConv.tracks()[ilead]->phi()); + cand.addUserFloat("tkTrail_phi",aConv.tracks()[itrail]->phi()); + cand.addUserFloat("tkLead_nHits",aConv.tracks()[ilead]->found()); + cand.addUserFloat("tkTrail_nHits",aConv.tracks()[itrail]->found()); + cand.addUserInt("tkLead_isMatchedToLowPtEle",isMatchedToLowPtSC_[ilead]); + cand.addUserInt("tkTrail_isMatchedToLowPtEle",isMatchedToLowPtSC_[itrail]); + /// variables taken from the electron object after checking that is the same ele as in the conversion + cand.addUserFloat("eleLead_pt", elePt[ilead]); + cand.addUserFloat("eleTrail_pt", elePt[itrail]); + cand.addUserFloat("eleLead_ch", eleCh[ilead]); + cand.addUserFloat("eleTrail_ch", eleCh[itrail]); + cand.addUserFloat("eleLead_eta", eleEta[ilead]); + cand.addUserFloat("eleTrail_eta", eleEta[itrail]); + cand.addUserFloat("eleLead_phi", elePhi[ilead]); + cand.addUserFloat("eleTrail_phi", elePhi[itrail]); + // + cand.addUserFloat("eleLead_scEnergy", scEnergy[ilead]); + cand.addUserFloat("eleTrail_scEnergy", scEnergy[itrail]); + cand.addUserFloat("eleLead_scEta", scEta[ilead]); + cand.addUserFloat("eleTrail_scEta", scEta[itrail]); + cand.addUserFloat("eleLead_scEtaWidth", scEtaWidth[ilead]); + cand.addUserFloat("eleTrail_scEtaWidth", scEtaWidth[itrail]); + cand.addUserFloat("eleLead_scPhiWidth", scPhiWidth[ilead]); + cand.addUserFloat("eleTrail_scPhiWidth", scPhiWidth[itrail]); + cand.addUserFloat("eleLead_cluSize",cluSize[ilead]); + cand.addUserFloat("eleTrail_cluSize",cluSize[itrail]); + cand.addUserFloat("eleLead_full5x5_HoverE",full5x5_HoverE[ilead]); + cand.addUserFloat("eleTrail_full5x5_HoverE",full5x5_HoverE[itrail]); + cand.addUserFloat("eleLead_full5x5_r9",full5x5_r9[ilead]); + cand.addUserFloat("eleTrail_full5x5_r9",full5x5_r9[itrail]); + // + + cand.addUserFloat("eleLead_seed_dEta",ele_seed_dEta[ilead]); + cand.addUserFloat("eleTrail_seed_dEta",ele_seed_dEta[itrail]); + cand.addUserFloat("eleLead_eclu_EOverP",ele_eclu_EoverP[ilead]); + cand.addUserFloat("eleTrail_eclu_EOverP",ele_eclu_EoverP[itrail]); + cand.addUserFloat("eleLead_scEOverP",eleV[ilead].eSuperClusterOverP()); + cand.addUserFloat("eleTrail_scEOverP",eleV[itrail].eSuperClusterOverP()); + + cand.addUserFloat("eleLead_sc_dEta",ele_sc_dEta[ilead]); + cand.addUserFloat("eleTrail_sc_dEta",ele_sc_dEta[itrail]); + cand.addUserFloat("eleLead_sc_dPhi",ele_sc_dPhi[ilead]); + cand.addUserFloat("eleTrail_sc_dPhi",ele_sc_dPhi[itrail]); + // + cand.addUserFloat("eleLead_fBrem",ele_fBrem[ilead]); + cand.addUserFloat("eleTrail_fBrem",ele_fBrem[itrail]); + cand.addUserFloat("eleLead_shFracHits",ele_shFrInHits[ilead]); + cand.addUserFloat("eleTrail_shFracHits",ele_shFrInHits[itrail]); + + cand.addUserFloat("eleLead_pMode",gsfPmode[ilead]); + cand.addUserFloat("eleTrail_pMode",gsfPmode[itrail]); + cand.addUserFloat("eleLead_chi2",gsfChi2[ilead]); + cand.addUserFloat("eleTrail_chi2",gsfChi2[itrail]); + cand.addUserFloat("eleLead_nHits",gsfNhits[ilead]); + cand.addUserFloat("eleTrail_nHits",gsfNhits[itrail]); + cand.addUserFloat("eleLead_dR",gsfDR[ilead]); + cand.addUserFloat("eleTrail_dR",gsfDR[itrail]); + + cand.addUserFloat("eleLead_unbiasedSeedBDT",unbiased_seedBDT[ilead]); + cand.addUserFloat("eleTrail_unbiasedSeedBDT",unbiased_seedBDT[itrail]); + cand.addUserFloat("eleLead_mvaId",mvaIdV[ilead]); + cand.addUserFloat("eleTrail_mvaId",mvaIdV[itrail]); + + + + if ( nMatchedTracks ==2 ) { + + /* + isTwoSuperClusterConversion_=false; + dEtaTracksAtECAL_whenTwoSC_=-99.; + dPhiTracksAtECAL_whenTwoSC_=-99.; + dEtaSC_whenTwoSC_ = -99.; + dPhiSC_whenTwoSC_ = -99.; + + + + if ( eleV[ilead].superCluster().id() == eleV[itrail].superCluster().id() && eleV[ilead].superCluster().key() == eleV[itrail].superCluster().key() ) { + std::cout << " the two electrons have the same supercluster " << std::endl; + } else { + std::cout << " the two electrons DO NOT have the same supercluster " << std::endl; + isTwoSuperClusterConversion_=true; + dEtaTracksAtECAL_whenTwoSC_ = eleV[ilead].trackPositionAtCalo().eta() - eleV[itrail].trackPositionAtCalo().eta(); + dPhiTracksAtECAL_whenTwoSC_ = reco::deltaPhi( eleV[ilead].trackPositionAtCalo().phi(),eleV[itrail].trackPositionAtCalo().phi()); + dEtaSC_whenTwoSC_ = eleV[ilead].superClusterPosition().eta() - eleV[itrail].superClusterPosition().eta(); + dPhiSC_whenTwoSC_ = reco::deltaPhi( eleV[ilead].superClusterPosition().phi(),eleV[itrail].superClusterPosition().phi()); + + } + + */ + } + + outFilteredConversionCollection.push_back(cand); + + } // loop over reco conversions + + + nAcceptedConvTot=nAcceptedConvTot + outFilteredConversionCollection.size(); + //std::cout << " Accepted conv per event " << nAcceptedConv << std::endl; + //std::cout << " All Accepted conv " << nAcceptedConvTot << std::endl; + + + + + outFilteredConversionCollection_p ->assign(outFilteredConversionCollection.begin(), outFilteredConversionCollection.end()); + e.put(std::move(outFilteredConversionCollection_p), filteredConvertedPhotonCollection_); +} + + + + + + + +float ConversionSelector::mee (float ipx1, float ipy1, float ipz1, float ipx2, float ipy2, float ipz2){ + const float mElec= 0.000511; + float invMass=-99.; + const float px = ipx1+ipx2; + const float py = ipy1+ipy2; + const float pz = ipz1+ipz2; + const float mom1 = ipx1*ipx1+ipy1*ipy1+ipz1*ipz1; + const float mom2 = ipx2*ipx2+ipy2*ipy2+ipz2*ipz2; + const float e = sqrt( mom1+ mElec*mElec ) + sqrt( mom2 + mElec*mElec ); + invMass= ( e*e - px*px -py*py - pz*pz); + if ( invMass>0.) invMass = sqrt(invMass); + else + invMass = -1; + return invMass; +} + +DEFINE_FWK_MODULE(ConversionSelector); diff --git a/BParkingNano/plugins/ConversionSelector.h b/BParkingNano/plugins/ConversionSelector.h new file mode 100644 index 00000000000..a90a276381d --- /dev/null +++ b/BParkingNano/plugins/ConversionSelector.h @@ -0,0 +1,288 @@ +#ifndef ConversionSelector_H +#define ConversionSelector_H +#include "Geometry/TrackerGeometryBuilder/interface/TrackerGeometry.h" +#include "Geometry/CaloGeometry/interface/CaloGeometry.h" +#include "Geometry/CaloTopology/interface/CaloTopology.h" +//#include "FWCore/Framework/interface/EDAnalyzer.h" +//#include "FWCore/Framework/interface/global/EDProducer.h" +#include "FWCore/Framework/interface/EDProducer.h" +#include "FWCore/ParameterSet/interface/ParameterSet.h" +#include "FWCore/Framework/interface/Event.h" +#include "FWCore/Framework/interface/EventSetup.h" +#include "FWCore/Framework/interface/ESHandle.h" +#include "RecoEgamma/EgammaMCTools/interface/PhotonMCTruthFinder.h" +#include "SimDataFormats/Associations/interface/TrackToTrackingParticleAssociator.h" +#include "MagneticField/Engine/interface/MagneticField.h" +#include "DataFormats/Common/interface/RefToBaseVector.h" +#include "DataFormats/Common/interface/RefVector.h" +#include "DataFormats/VertexReco/interface/VertexFwd.h" +#include "DataFormats/VertexReco/interface/Vertex.h" +#include "DataFormats/EgammaCandidates/interface/GsfElectronFwd.h" +#include "DataFormats/EgammaCandidates/interface/ConversionFwd.h" +#include "DataFormats/EgammaCandidates/interface/PhotonFwd.h" +#include "DataFormats/EgammaReco/interface/SuperClusterFwd.h" +#include "DataFormats/JetReco/interface/GenJetCollection.h" +#include "SimDataFormats/TrackingAnalysis/interface/TrackingParticleFwd.h" +#include "DataFormats/PatCandidates/interface/Electron.h" + +// +#include +#include + +// forward declarations +class TFile; +class TTree; +/** \class ConversionSelector + ** + ** + ** $Id: ConversionSelector + ** \author N.Marinelli - Univ. of Notre Dame + ** + ***/ + + +class ConversionSelector : public edm::EDProducer { + + public: + + // + explicit ConversionSelector( const edm::ParameterSet& ) ; + virtual ~ConversionSelector(); + + void produce(edm::Event&, const edm::EventSetup&) ; + + private: + // + + float mee (float ipx1, float ipy1, float ipz1, float ipx2, float ipy2, float ipz2); + + TTree *tree_; + TFile *histfile_; + std::string outputFileName_; + + std::string fName_; + edm::ESHandle theMF_; + + int verbosity_; + int nEvt_; + int nEntry_; + int nSimConv_[2]; + int nMatched_; + int nRecConv_; + int nRecConvAss_; + int nRecConvAssWithEcal_; + int nInvalidPCA_; + + int nAcceptedConvTot; + + + edm::ParameterSet parameters_; + edm::ESHandle theCaloGeom_; + edm::ESHandle theCaloTopo_; + + std::string conversionCollectionProducer_; + std::string conversionCollection_; + edm::EDGetTokenT conversionCollectionPr_Token_; + + std::string filteredConvertedPhotonCollection_; + + std::string conversionTrackProducer_; + + std::string photonCollectionProducer_; + std::string photonCollection_; + edm::EDGetTokenT photonCollectionPr_Token_; + + std::string lowPtElectronProducer_; + std::string lowPtElectronCollection_; + edm::EDGetTokenT > lowPtElectronCollectionPr_Token_; + edm::EDGetTokenT> unBiased_; + edm::EDGetTokenT> mvaId_src_; + + + edm::EDGetTokenT offline_pvToken_; + edm::EDGetTokenT beamspotToken_; + edm::EDGetTokenT rho_token_; + edm::EDGetTokenT g4_simTk_Token_; + edm::EDGetTokenT g4_simVtx_Token_; + edm::EDGetTokenT tpSelForEff_Token_; + edm::EDGetTokenT tpSelForFake_Token_; + edm::EDGetTokenT hepMC_Token_; + edm::EDGetTokenT genjets_Token_; + edm::EDGetTokenT trackAssociator_Token_; + + + edm::InputTag label_tp_; + + PhotonMCTruthFinder* thePhotonMCTruthFinder_; + + bool isRunCentrally_; + double minPtOnTracks_; + double minPhoEtCut_; + double trkIsolExtRadius_; + double trkIsolInnRadius_; + double trkPtLow_; + double lip_; + double ecalIsolRadius_; + double bcEtLow_; + double hcalIsolExtRadius_; + double hcalIsolInnRadius_; + double hcalHitEtLow_; + int numOfTracksInCone_; + double trkPtSumCut_; + double ecalEtSumCut_; + double hcalEtSumCut_; + bool dCotCutOn_; + double dCotCutValue_; + double dCotHardCutValue_; + bool generalTracksOnly_; + bool gsfTracksOpenOnly_; + bool arbitratedMerged_; + bool arbitratedEcalSeeded_; + bool ecalalgotracks_; + bool highPurity_; + double minProb_; + uint maxHitsBeforeVtx_; + double minLxy_; + + + /// global variable for the MC photon + double mcPhi_; + double mcEta_; + double mcConvPt_; + double mcConvR_; + double mcConvZ_; + double mcConvY_; + double mcConvX_; + double mcConvPhi_; + double mcConvEta_; + double mcJetEta_; + double mcJetPhi_; + + edm::RefVector theConvTP_; + //std::vector theConvTP_; + + double minPhoPtForEffic; + double maxPhoEtaForEffic; + double maxPhoZForEffic; + double maxPhoRForEffic; + double minPhoPtForPurity; + double maxPhoEtaForPurity; + double maxPhoZForPurity; + double maxPhoRForPurity; + + double simMinPt_; + double simMaxPt_; + + /// Global variables for reco Photon + double recMinPt_; + double recMaxPt_; + + // variables in the tree per conversion + double rho_; + int convAlgo_; + int convMatchSC_; + int isTwoSuperClusterConversion_; + float vtxChiSquaredProb_; + double lxy_; + double vtxR_; + double vtxX_; + double vtxY_; + double vtxZ_; + + + float etaBeforeFit_; + float phiBeforeFit_; + float ptBeforeFit_; + float etaAfterFit_; + float phiAfterFit_; + float ptAfterFit_; + + + float invMass_fromDF_; + float invMass_fromPin_; + float invMass_beforeFit_; + float invMass_afterFit_; + float leadTrkPt_; + float subleadTrkPt_; + float leadTrkEta_; + float subleadTrkEta_; + float leadTrkTheta_; + float subleadTrkTheta_; + float dCotTracksFromPin_; + float dCotTracksBeforeVtxFit_; + float dCotTracksAfterVtxFit_ ; + float maxNHitsBeforeVtx_; + float leadNHitsBeforeVtx_; + float trailNHitsBeforeVtx_; + float distMinAppTracks_; + float dPhiTracksAtVtx_; + float dEtaTracksAtECAL_whenTwoSC_; + float dPhiTracksAtECAL_whenTwoSC_; + float dEtaSC_whenTwoSC_; + float dPhiSC_whenTwoSC_; + float dEtaTracksAtECAL_whenOneSC_; + float dPhiTracksAtECAL_whenOneSC_; + + + // variables in the tree for all tracks + int nTracks_; + std::vector trk_pt_beforeVtx_; + std::vector trk_eta_beforeVtx_; + std::vector trk_phi_beforeVtx_; + + + std::vector trk_ptMode_; + std::vector trk_etaMode_; + std::vector trk_phiMode_; + + + + std::vector trk_pt_afterVtx_; + std::vector trk_eta_afterVtx_; + std::vector trk_phi_afterVtx_; + + std::vector trk_found_nhits_; + std::vector trk_valid_nhits_; + std::vector trk_dxy_; + std::vector trk_dxy_err_; + std::vector trk_pin_; + std::vector trk_pout_; + std::vector trk_chi2_; + std::vector trk_d0_; + std::vector trk_charge_; + std::vector trk_chargeMode_; + + + + std::vector dEtaTrkSCAtVtx_; + std::vector dPhiTrkSCAtVtx_; + std::vector dEtaTrkSCAtEcal_; + std::vector dPhiTrkSCAtEcal_; + std::vector isMatchedToLowPtSC_; + + std::vector EoverP_; + std::vector BremFrac_; + + std::vector elePt_; + std::vector eleSC_energy_; + std::vector eleSC_eta_; + std::vector eleSC_clusterSize_; + std::vector eleSC_etaWidth_; + std::vector eleSC_phiWidth_; + std::vector full5x5_sigmaIetaIeta_; + std::vector full5x5_sigmaIphiIphi_; + std::vector full5x5_circularity_; + std::vector full5x5_e1x5_; + std::vector full5x5_e2x5Max_; + std::vector full5x5_e5x5_; + std::vector full5x5_r9_; + std::vector full5x5_HoverE_; + + + +}; + + + + +#endif diff --git a/BParkingNano/python/conversionsBPark_cff.py b/BParkingNano/python/conversionsBPark_cff.py new file mode 100644 index 00000000000..fbd9a4a0d1e --- /dev/null +++ b/BParkingNano/python/conversionsBPark_cff.py @@ -0,0 +1,211 @@ +import FWCore.ParameterSet.Config as cms +from PhysicsTools.NanoAOD.common_cff import * +from PhysicsTools.BParkingNano.common_cff import * + +filteredConversions = cms.EDProducer("ConversionSelector", + Name = cms.untracked.string('myConvSelection'), + outFileName = cms.string('ValidationHistos.root'), + convProducer = cms.string('gsfTracksOpenConversions'), + conversionCollection = cms.string('gsfTracksOpenConversions'), + lowPtElectronProducer = cms.string('slimmedLowPtElectrons'), + lowPtElectronCollection = cms.string(''), + unbiasedSeeding = cms.InputTag("lowPtGsfElectronSeedValueMaps","unbiased","RECO"), + mvaId = cms.InputTag("lowPtGsfElectronLatestID"), + phoProducer = cms.string('photons'), + photonCollection = cms.string(''), + filteredConversions = cms.string(''), + rhoHandle = cms.string('fixedGridRhoAll'), + dqmpath = cms.string('EgammaV/ConversionValidator/'), + Verbosity = cms.untracked.int32(0), + generalTracksOnly = cms.bool(False), + gsfTracksOpenOnly = cms.bool(True), + arbitratedMerged = cms.bool(False), + arbitratedEcalSeeded = cms.bool(False), + ecalalgotracks = cms.bool(False), + minPtOnTracks = cms.double(0.5), + highPurity = cms.bool(True), + minProb = cms.double(0.0005), + maxHitsBeforeVtx = cms.uint32(1), + minLxy = cms.double(0.), + + minPhoPtForEffic = cms.double(0.3),#when hardcoded it was 2.5 + maxPhoEtaForEffic = cms.double(2.5), + maxPhoZForEffic = cms.double(200.), + maxPhoRForEffic = cms.double(100.), + minPhoPtForPurity = cms.double(0.),#when hardcoded it was 0.5 + maxPhoEtaForPurity = cms.double(2.5), + maxPhoZForPurity = cms.double(200.), + maxPhoRForPurity = cms.double(100.), + +# + minPhoEtCut = cms.double(0.), + +# + useTP = cms.bool(True), +# + + etBin = cms.int32(100), + etMax = cms.double(100.0), + etMin = cms.double(0.0), +# + etaBin = cms.int32(100), + etaBin2 = cms.int32(25), + etaMin = cms.double(-2.5), + etaMax = cms.double(2.5), +# + phiBin = cms.int32(100), + phiMin = cms.double(-3.14), + phiMax = cms.double(3.14), +# + resBin = cms.int32(100), + resMin = cms.double(0.), + resMax = cms.double(1.1), +# + eoverpBin = cms.int32(100), + eoverpMin = cms.double(0.), + eoverpMax = cms.double(5.), +# + dEtaTracksBin = cms.int32(100), + dEtaTracksMin = cms.double(-0.2), + dEtaTracksMax = cms.double(0.2), +# + dPhiTracksBin = cms.int32(100), + dPhiTracksMin = cms.double(-0.5), + dPhiTracksMax = cms.double(0.5), +# + dEtaBin = cms.int32(100), + dEtaMin = cms.double(-0.2), + dEtaMax = cms.double(0.2), +# + dPhiBin = cms.int32(100), + dPhiMin = cms.double(-0.05), + dPhiMax = cms.double(0.05), +# + rBin = cms.int32(60), + rMin = cms.double(0.), + rMax = cms.double(120), +# + zBin = cms.int32(100), + zMin = cms.double(-220.), + zMax = cms.double(220), +# + + dCotTracksBin = cms.int32(100), + dCotTracksMin = cms.double(-0.12), + dCotTracksMax = cms.double(0.12), +# + chi2Min = cms.double(0.), + chi2Max = cms.double(20.), +# + + rBinForXray = cms.int32(200), + rMinForXray = cms.double(0.), + rMaxForXray = cms.double(80.), + zBinForXray = cms.int32(100), + zBin2ForXray = cms.int32(560), + zMinForXray = cms.double(0.), + zMaxForXray = cms.double(280.), + + simTracks = cms.InputTag("g4SimHits") +) + + +conversionTable = cms.EDProducer("SimpleCompositeCandidateFlatTableProducer", + #src = cms.InputTag("gsfTracksOpenConversions","gsfTracksOpenConversions"), + src = cms.InputTag("filteredConversions"), + cut = cms.string(""), #we should not filter on cross linked collections + name = cms.string("Conversion"), + doc = cms.string("Our packedCandidate table"), + singleton = cms.bool(False), # the number of entries is variable + extension = cms.bool(False), # this is the main table for the muons + variables = cms.PSet(CandVars, + rho = ufloat('rho'), + vtxChi2Prob = ufloat('vtxChi2Prob'), + vtxR = ufloat('vtxR'), + vtxX = ufloat('vtxX'), + vtxY = ufloat('vtxY'), + vtxZ = ufloat('vtxZ'), + dCotFromPin = ufloat('dCotFromPin'), + dMinAppTracks = ufloat('dMinAppTracks'), + dPhiTracksAtVtx = ufloat('dPhiTracksAtVtx'), +# + tkLead_pt = ufloat('tkLead_pt'), + tkTrail_pt = ufloat('tkTrail_pt'), + tkLead_eta = ufloat('tkLead_eta'), + tkTrail_eta = ufloat('tkTrail_eta'), + tkLead_phi = ufloat('tkLead_phi'), + tkTrail_phi = ufloat('tkTrail_phi'), + tkLead_nHits = ufloat('tkLead_nHits'), + tkTrail_nHits = ufloat('tkTrail_nHits'), + tkLead_isMatchedToLowPtEle = uint('tkLead_isMatchedToLowPtEle'), + tkTrail_isMatchedToLowPtEle = uint('tkTrail_isMatchedToLowPtEle'), +# + eleLead_pt = ufloat('eleLead_pt'), + eleTrail_pt = ufloat('eleTrail_pt'), + eleLead_ch = ufloat('eleLead_ch'), + eleTrail_ch = ufloat('eleTrail_ch'), + eleLead_eta = ufloat('eleLead_eta'), + eleTrail_eta = ufloat('eleTrail_eta'), + eleLead_phi = ufloat('eleLead_phi'), + eleTrail_phi = ufloat('eleTrail_phi'), +# + eleLead_scEnergy = ufloat('eleLead_scEnergy'), + eleTrail_scEnergy = ufloat('eleTrail_scEnergy'), + eleLead_scEta = ufloat('eleLead_scEta'), + eleTrail_scEta = ufloat('eleTrail_scEta'), + eleLead_scEtaWidth = ufloat('eleLead_scEtaWidth'), + eleTrail_scEtaWidth = ufloat('eleTrail_scEtaWidth'), + eleLead_scPhiWidth = ufloat('eleLead_scPhiWidth'), + eleTrail_scPhiWidth = ufloat('eleTrail_scPhiWidth'), + eleLead_cluSize = ufloat('eleLead_cluSize'), + eleTrail_cluSize = ufloat('eleTrail_cluSize'), + eleLead_full5x5_HoverE = ufloat('eleLead_full5x5_HoverE'), + eleTrail_full5x5_HoverE = ufloat('eleTrail_full5x5_HoverE'), + eleLead_full5x5_r9 = ufloat('eleLead_full5x5_r9'), + eleTrail_full5x5_r9 = ufloat('eleTrail_full5x5_r9'), +# + eleLead_seed_dEta = ufloat('eleLead_seed_dEta'), + eleTrail_seed_dEta = ufloat('eleTrail_seed_dEta'), + eleLead_eclu_EOverP =ufloat('eleLead_eclu_EOverP'), + eleTrail_eclu_EOverP =ufloat('eleTrail_eclu_EOverP'), + + eleLead_scEOverP = ufloat('eleLead_scEOverP'), + eleTrail_scEOverP = ufloat('eleTrail_scEOverP'), + eleLead_sc_dEta = ufloat('eleLead_sc_dEta'), + eleTrail_sc_dEta = ufloat('eleTrail_sc_dEta'), + eleLead_sc_dPhi = ufloat('eleLead_sc_dPhi'), + eleTrail_sc_dPhi = ufloat('eleTrail_sc_dPhi'), + + eleLead_fBrem = ufloat('eleLead_fBrem'), + eleTrail_fBrem = ufloat('eleTrail_fBrem'), + eleLead_shFracHits = ufloat('eleLead_shFracHits'), + eleTrail_shFracHits = ufloat('eleTrail_shFracHits'), + + eleLead_pMode = ufloat('eleLead_pMode'), + eleTrail_pMode = ufloat('eleTrail_pMode'), + eleLead_chi2 = ufloat('eleLead_chi2'), + eleTrail_chi2 = ufloat('eleTrail_chi2'), + eleLead_nHits = ufloat('eleLead_nHits'), + eleTrail_nHits = ufloat('eleTrail_nHits'), + eleLead_dR = ufloat('eleLead_dR'), + eleTrail_dR = ufloat('eleTrail_dR'), +# + eleLead_unbiasedSeedBDT = ufloat('eleLead_unbiasedSeedBDT'), + eleTrail_unbiasedSeedBDT = ufloat('eleTrail_unbiasedSeedBDT'), + eleLead_mvaId = ufloat('eleLead_mvaId'), + eleTrail_mvaId = ufloat('eleTrail_mvaId'), + + + + + + + ) +) + +from Configuration.Eras.Modifier_fastSim_cff import fastSim +if fastSim.isChosen(): + tkConversionValidation.simTracks = cms.InputTag("famosSimHits") + +#conversionBParkSequence = cms.Sequence(filteredConversions+conversionTable) +conversionBParkSequence = cms.Sequence(filteredConversions) diff --git a/BParkingNano/python/nanoBPark_cff.py b/BParkingNano/python/nanoBPark_cff.py index fbd357f5240..09693c878ba 100644 --- a/BParkingNano/python/nanoBPark_cff.py +++ b/BParkingNano/python/nanoBPark_cff.py @@ -18,6 +18,7 @@ ## filtered input collections from PhysicsTools.BParkingNano.electronsBPark_cff import * from PhysicsTools.BParkingNano.tracksBPark_cff import * +from PhysicsTools.BParkingNano.conversionsBPark_cff import * ## B collections from PhysicsTools.BParkingNano.BToKLL_cff import * @@ -44,6 +45,10 @@ def nanoAOD_customizeTrackFilteredBPark(process): process.nanoSequence = cms.Sequence( process.nanoSequence + tracksBParkSequence + tracksBParkTables) return process +def nanoAOD_customizeConversionFilteredBPark(process): + process.nanoSequence = cms.Sequence ( process.nanoSequence + electronsBParkSequence+ conversionBParkSequence + conversionTable) + return process + def nanoAOD_customizeElectronFilteredBPark(process): process.nanoBKeeSequence = cms.Sequence( electronsBParkSequence + electronBParkTables) process.nanoBKstarEESequence = cms.Sequence( electronsBParkSequence + electronBParkTables) diff --git a/BParkingNano/test/run_nano_cfg.py b/BParkingNano/test/run_nano_cfg.py index 08ab3881ded..e4a5d97197d 100644 --- a/BParkingNano/test/run_nano_cfg.py +++ b/BParkingNano/test/run_nano_cfg.py @@ -128,6 +128,7 @@ from PhysicsTools.BParkingNano.nanoBPark_cff import * process = nanoAOD_customizeMuonTriggerBPark(process) +process = nanoAOD_customizeConversionFilteredBPark(process) process = nanoAOD_customizeElectronFilteredBPark(process) process = nanoAOD_customizeTrackFilteredBPark(process) process = nanoAOD_customizeBToKLL(process) From b2664edf25358954b73fbaaa58ef9de40d31e657 Mon Sep 17 00:00:00 2001 From: nancy Date: Tue, 8 Sep 2020 17:22:09 +0200 Subject: [PATCH 2/2] Add a cfg which produces a tree with conversions where events are only pre-selected by the trigger and not by the physics channel --- BParkingNano/test/run_nano_conversions_cfg.py | 192 ++++++++++++++++++ 1 file changed, 192 insertions(+) create mode 100644 BParkingNano/test/run_nano_conversions_cfg.py diff --git a/BParkingNano/test/run_nano_conversions_cfg.py b/BParkingNano/test/run_nano_conversions_cfg.py new file mode 100644 index 00000000000..047f64c91a3 --- /dev/null +++ b/BParkingNano/test/run_nano_conversions_cfg.py @@ -0,0 +1,192 @@ +from FWCore.ParameterSet.VarParsing import VarParsing +import FWCore.ParameterSet.Config as cms + +options = VarParsing('python') + +options.register('isMC', False, + VarParsing.multiplicity.singleton, + VarParsing.varType.bool, + "Run this on real data" +) +options.register('globalTag', 'NOTSET', + VarParsing.multiplicity.singleton, + VarParsing.varType.string, + "Set global tag" +) +options.register('wantSummary', True, + VarParsing.multiplicity.singleton, + VarParsing.varType.bool, + "Run this on real data" +) +options.register('wantFullRECO', False, + VarParsing.multiplicity.singleton, + VarParsing.varType.bool, + "Run this on real data" +) +options.register('reportEvery', 10, + VarParsing.multiplicity.singleton, + VarParsing.varType.int, + "report every N events" +) +options.register('skip', 0, + VarParsing.multiplicity.singleton, + VarParsing.varType.int, + "skip first N events" +) + +options.setDefault('maxEvents', 100) +options.setDefault('tag', '10215') +options.parseArguments() + +globaltag = '102X_dataRun2_v11' if not options.isMC else '102X_upgrade2018_realistic_v15' +if options._beenSet['globalTag']: + globaltag = options.globalTag + +extension = {False : 'data', True : 'mc'} +outputFileNANO = cms.untracked.string('_'.join(['BParkNANO', extension[options.isMC], options.tag])+'.root') +outputFileFEVT = cms.untracked.string('_'.join(['BParkFullEvt', extension[options.isMC], options.tag])+'.root') +if not options.inputFiles: + options.inputFiles = ['/store/data/Run2018B/ParkingBPH4/MINIAOD/05May2019-v2/230000/6B5A24B1-0E6E-504B-8331-BD899EB60110.root', + '/store/data/Run2018B/ParkingBPH4/MINIAOD/05May2019-v2/240000/97C494CC-A1A7-E94D-AC5D-1D679DC5A68C.root' ] if not options.isMC else \ + ['/store/cmst3/group/bpark/BToKmumu_1000Events_MINIAOD.root'] +annotation = '%s nevts:%d' % (outputFileNANO, options.maxEvents) + +from Configuration.StandardSequences.Eras import eras +process = cms.Process('BParkNANO',eras.Run2_2018) + +# import of standard configurations +process.load('Configuration.StandardSequences.Services_cff') +process.load('SimGeneral.HepPDTESSource.pythiapdt_cfi') +process.load('FWCore.MessageService.MessageLogger_cfi') +process.load('Configuration.EventContent.EventContent_cff') +process.load('Configuration.StandardSequences.GeometryRecoDB_cff') +process.load("Configuration.StandardSequences.MagneticField_cff") +process.load('PhysicsTools.BParkingNano.nanoBPark_cff') +process.load('Configuration.StandardSequences.EndOfProcess_cff') +process.load('Configuration.StandardSequences.FrontierConditions_GlobalTag_cff') + +process.MessageLogger.cerr.FwkReport.reportEvery = options.reportEvery +process.maxEvents = cms.untracked.PSet( + input = cms.untracked.int32(options.maxEvents) +) + +# Input source +process.source = cms.Source( + "PoolSource", + fileNames = cms.untracked.vstring(options.inputFiles), + secondaryFileNames = cms.untracked.vstring(), + skipEvents=cms.untracked.uint32(options.skip), +) + +process.options = cms.untracked.PSet( + wantSummary = cms.untracked.bool(options.wantSummary), +) + +process.nanoMetadata.strings.tag = annotation +# Production Info +process.configurationMetadata = cms.untracked.PSet( + annotation = cms.untracked.string(annotation), + name = cms.untracked.string('Applications'), + version = cms.untracked.string('$Revision: 1.19 $') +) + +# Output definition +process.FEVTDEBUGHLToutput = cms.OutputModule("PoolOutputModule", + dataset = cms.untracked.PSet( + dataTier = cms.untracked.string('GEN-SIM-RECO'), + filterName = cms.untracked.string('') + ), + fileName = outputFileFEVT, + outputCommands = (cms.untracked.vstring('keep *', + 'drop *_*_SelectedTransient*_*', + )), + splitLevel = cms.untracked.int32(0) +) + +process.NANOAODoutput = cms.OutputModule("NanoAODOutputModule", + compressionAlgorithm = cms.untracked.string('LZMA'), + compressionLevel = cms.untracked.int32(9), + dataset = cms.untracked.PSet( + dataTier = cms.untracked.string('NANOAOD'), + filterName = cms.untracked.string('') + ), + fileName = outputFileNANO, + outputCommands = cms.untracked.vstring( + 'drop *', + "keep nanoaodFlatTable_*Table_*_*", # event data + "keep nanoaodUniqueString_nanoMetadata_*_*", # basic metadata + ) + +) + + +# Additional output definition + +# Other statements +from Configuration.AlCa.GlobalTag import GlobalTag +process.GlobalTag = GlobalTag(process.GlobalTag, globaltag, '') + + +from PhysicsTools.BParkingNano.nanoBPark_cff import * + +process = nanoAOD_customizeMuonTriggerBPark(process) +process = nanoAOD_customizeConversionFilteredBPark(process) +process = nanoAOD_customizeElectronFilteredBPark(process) +process = nanoAOD_customizeTrackFilteredBPark(process) +process = nanoAOD_customizeBToKLL(process) +process = nanoAOD_customizeBToKstarEE(process) +process = nanoAOD_customizeBToKstarMuMu(process) +process = nanoAOD_customizeTriggerBitsBPark(process) + + + + +# Path and EndPath definitions +process.nanoAOD_TEST = cms.Path(process.nanoSequence) +process.nanoAOD_KMuMu_step = cms.Path(process.nanoSequence + process.nanoBKMuMuSequence + CountBToKmumu ) +process.nanoAOD_Kee_step = cms.Path(process.nanoSequence + process.nanoBKeeSequence + CountBToKee ) +process.nanoAOD_KstarMuMu_step = cms.Path(process.nanoSequence + process.KstarToKPiSequence + process.nanoBKstarMuMuSequence + CountBToKstarMuMu ) +process.nanoAOD_KstarEE_step = cms.Path(process.nanoSequence+ process.KstarToKPiSequence + process.nanoBKstarEESequence + CountBToKstarEE ) + +# customisation of the process. +if options.isMC: + from PhysicsTools.BParkingNano.nanoBPark_cff import nanoAOD_customizeMC + nanoAOD_customizeMC(process) + +process.endjob_step = cms.EndPath(process.endOfProcess) +process.FEVTDEBUGHLToutput_step = cms.EndPath(process.FEVTDEBUGHLToutput) +process.NANOAODoutput_step = cms.EndPath(process.NANOAODoutput) + +# Schedule definition +process.schedule = cms.Schedule( + process.nanoAOD_TEST, + process.endjob_step, + process.NANOAODoutput_step + + ) +if options.wantFullRECO: + process.schedule = cms.Schedule( + process.nanoAOD_TEST, + process.endjob_step, + process.FEVTDEBUGHLToutput_step, + process.NANOAODoutput_step + ) +from PhysicsTools.PatAlgos.tools.helpers import associatePatAlgosToolsTask +associatePatAlgosToolsTask(process) + + +process.NANOAODoutput.SelectEvents = cms.untracked.PSet( + SelectEvents = cms.vstring( + 'nanoAOD_TEST' + ) +) + + + +### from https://hypernews.cern.ch/HyperNews/CMS/get/physics-validation/3287/1/1/1/1/1.html +process.add_(cms.Service('InitRootHandlers', EnableIMT = cms.untracked.bool(False))) +process.NANOAODoutput.fakeNameForCrab=cms.untracked.bool(True) + +process.load("TrackingTools/TransientTrack/TransientTrackBuilder_cfi") +from Configuration.StandardSequences.earlyDeleteSettings_cff import customiseEarlyDelete +process = customiseEarlyDelete(process)