diff --git a/Calibration/HcalAlCaRecoProducers/BuildFile.xml b/Calibration/HcalAlCaRecoProducers/BuildFile.xml index 12bc65939d924..24dedb6428bc6 100644 --- a/Calibration/HcalAlCaRecoProducers/BuildFile.xml +++ b/Calibration/HcalAlCaRecoProducers/BuildFile.xml @@ -33,4 +33,6 @@ + + diff --git a/Calibration/HcalAlCaRecoProducers/interface/AlCaDiJetsProducer.h b/Calibration/HcalAlCaRecoProducers/interface/AlCaDiJetsProducer.h deleted file mode 100644 index 8dadf3a06f9f8..0000000000000 --- a/Calibration/HcalAlCaRecoProducers/interface/AlCaDiJetsProducer.h +++ /dev/null @@ -1,65 +0,0 @@ -#ifndef AlCaDiJetsProducer_h -#define AlCaDiJetsProducer_h - - -// -*- C++ -*- - - -// system include files -#include -#include -// user include files -#include "FWCore/Framework/interface/Frameworkfwd.h" -#include "FWCore/Framework/interface/EDProducer.h" -#include "FWCore/Framework/interface/Event.h" -#include "FWCore/Framework/interface/MakerMacros.h" -#include "FWCore/ParameterSet/interface/ParameterSet.h" -#include "FWCore/Framework/interface/ESHandle.h" -#include "FWCore/Framework/interface/EventSetup.h" - -#include "DataFormats/Common/interface/Ref.h" -#include "DataFormats/CaloTowers/interface/CaloTowerCollection.h" -#include "DataFormats/DetId/interface/DetId.h" - -#include "DataFormats/JetReco/interface/CaloJetCollection.h" -#include "DataFormats/HcalRecHit/interface/HcalRecHitCollections.h" -#include "DataFormats/EcalRecHit/interface/EcalRecHitCollections.h" - -#include "Geometry/CaloGeometry/interface/CaloGeometry.h" - -// -// class declaration -// -namespace edm { - class ParameterSet; - class Event; - class EventSetup; -} - -namespace cms -{ - -class AlCaDiJetsProducer : public edm::EDProducer { - public: - explicit AlCaDiJetsProducer(const edm::ParameterSet&); - ~AlCaDiJetsProducer(); - - virtual void beginJob() ; - - virtual void produce(edm::Event &, const edm::EventSetup&); - private: - // ----------member data --------------------------- - std::vector ecalLabels_; - - edm::EDGetTokenT tok_jets_; - edm::EDGetTokenT tok_hbhe_; - edm::EDGetTokenT tok_ho_; - edm::EDGetTokenT tok_hf_; - - std::vector > toks_ecal_; - - bool allowMissingInputs_; - -}; -}// end namespace cms -#endif diff --git a/Calibration/HcalAlCaRecoProducers/interface/AlCaGammaJetProducer.h b/Calibration/HcalAlCaRecoProducers/interface/AlCaGammaJetProducer.h deleted file mode 100644 index 6de54d4717475..0000000000000 --- a/Calibration/HcalAlCaRecoProducers/interface/AlCaGammaJetProducer.h +++ /dev/null @@ -1,75 +0,0 @@ -#ifndef AlCaGammaJetProducer_AlCaHcalProducers_h -#define AlCaGammaJetProducer_AlCaHcalProducers_h - - -// -*- C++ -*- - - -// system include files -#include -#include -// user include files -#include "FWCore/Framework/interface/Frameworkfwd.h" -#include "FWCore/Framework/interface/EDProducer.h" -#include "FWCore/Framework/interface/Event.h" -#include "FWCore/Framework/interface/MakerMacros.h" -#include "FWCore/ParameterSet/interface/ParameterSet.h" -#include "FWCore/Framework/interface/ESHandle.h" -#include "FWCore/Framework/interface/EventSetup.h" - -#include "DataFormats/HcalRecHit/interface/HcalRecHitCollections.h" -#include "DataFormats/EcalRecHit/interface/EcalRecHitCollections.h" -#include "DataFormats/JetReco/interface/CaloJetCollection.h" -#include "TrackingTools/TransientTrack/interface/TransientTrack.h" -#include "DataFormats/EgammaReco/interface/SuperCluster.h" -#include "DataFormats/EgammaReco/interface/SuperClusterFwd.h" - -#include "Geometry/CaloGeometry/interface/CaloGeometry.h" - -// -// class declaration -// -namespace edm { - class ParameterSet; - class Event; - class EventSetup; -} - -//namespace cms -//{ - -class AlCaGammaJetProducer : public edm::EDProducer { - public: - explicit AlCaGammaJetProducer(const edm::ParameterSet&); - ~AlCaGammaJetProducer(); - virtual void beginJob() ; - - virtual void produce(edm::Event &, const edm::EventSetup&); - private: - // ----------member data --------------------------- - std::vector ecalLabels_; - std::vector mInputCalo; - - std::vector > toks_ecal_; - std::vector > toks_calo_; - - std::string correctedIslandBarrelSuperClusterCollection_; - std::string correctedIslandBarrelSuperClusterProducer_; - std::string correctedIslandEndcapSuperClusterCollection_; - std::string correctedIslandEndcapSuperClusterProducer_; - - edm::EDGetTokenT tok_hbhe_; - edm::EDGetTokenT tok_ho_; - edm::EDGetTokenT tok_hf_; - edm::EDGetTokenT tok_inputTrack_; - edm::EDGetTokenT tok_EBSC_; // token for corrected island barrel super cluster collection - edm::EDGetTokenT tok_EESC_; // token for corrected island end-cap super cluster - - bool allowMissingInputs_; - - // Calo geometry - const CaloGeometry* geo; - -}; -//}// end namespace cms -#endif diff --git a/Calibration/HcalAlCaRecoProducers/interface/AlCaIsoTracksProducer.h b/Calibration/HcalAlCaRecoProducers/interface/AlCaIsoTracksProducer.h deleted file mode 100644 index 32b9eb6258e00..0000000000000 --- a/Calibration/HcalAlCaRecoProducers/interface/AlCaIsoTracksProducer.h +++ /dev/null @@ -1,109 +0,0 @@ -// -*- C++ -*- - - -// system include files -#include -#include -// user include files -#include "FWCore/Framework/interface/Frameworkfwd.h" -#include "FWCore/Framework/interface/EDProducer.h" - -#include "FWCore/Framework/interface/Event.h" -#include "FWCore/Framework/interface/MakerMacros.h" - -#include "FWCore/ParameterSet/interface/ParameterSet.h" -#include "FWCore/Framework/interface/Frameworkfwd.h" -#include "FWCore/Framework/interface/Event.h" -#include "FWCore/Framework/interface/MakerMacros.h" -#include "FWCore/Framework/interface/ESHandle.h" -#include "FWCore/Framework/interface/EventSetup.h" -#include "FWCore/ParameterSet/interface/ParameterSet.h" - -#include "DataFormats/Common/interface/Ref.h" -#include "DataFormats/DetId/interface/DetId.h" -//#include "DataFormats/CaloTowers/interface/CaloTowerDetId.h" - -#include "Geometry/Records/interface/IdealGeometryRecord.h" -#include "Geometry/CaloGeometry/interface/CaloGeometry.h" -#include "DataFormats/GeometryVector/interface/GlobalPoint.h" - -#include "DataFormats/HcalRecHit/interface/HcalRecHitCollections.h" -#include "DataFormats/EcalRecHit/interface/EcalRecHitCollections.h" -#include "RecoTracker/TrackProducer/interface/TrackProducerBase.h" -#include "TrackingTools/TransientTrack/interface/TransientTrack.h" - -#include "TrackPropagation/SteppingHelixPropagator/interface/SteppingHelixPropagator.h" -#include "TrackingTools/TrackAssociator/interface/TrackDetectorAssociator.h" -#include "TrackingTools/TrackAssociator/interface/TrackAssociatorParameters.h" -#include "TrackingTools/TrackAssociator/interface/TrackDetMatchInfo.h" - -#include "Geometry/Records/interface/IdealGeometryRecord.h" -#include "Geometry/CaloGeometry/interface/CaloGeometry.h" - -#include "DataFormats/HLTReco/interface/TriggerEvent.h" - -#include "TH1F.h" -class TFile; - -// -// class declaration -// - -class AlCaIsoTracksProducer : public edm::EDProducer { -public: - explicit AlCaIsoTracksProducer(const edm::ParameterSet&); - ~AlCaIsoTracksProducer(); - - virtual void produce(edm::Event &, const edm::EventSetup&); - void endJob(void); - -private: - - TrackDetectorAssociator trackAssociator_; - TrackAssociatorParameters parameters_; - - - const CaloGeometry* geo; - std::vector ecalLabels_; - - int nHitsMinCore_; - int nHitsMinIso_; - double m_dvCut; - double m_ddirCut; - bool useConeCorr_; - double m_pCut; - double m_ptCut; - double m_ecalCut; - - double taECALCone_; - double taHCALCone_; - - bool skipNeutrals_; - bool checkHLTMatch_; - std::vector hltFiltTag_; - double hltMatchingCone_; - - double isolE_; - double etaMax_; - double cluRad_; - double ringOutRad_; - double ringInnRad_; - - bool useECALCluMatrix_; - int matrixSize_; - int matrixInnerSize_; - int matrixOuterSize_; - - std::string l1FilterTag_; - double l1jetVetoCone_; - - edm::EDGetTokenT tok_ho_; - edm::EDGetTokenT tok_hbhe_; - edm::EDGetTokenT tok_track_; - edm::EDGetTokenT tok_hlt_; - - std::vector > toks_ecal_; - edm::EDGetTokenT tok_ps_; - -}; - diff --git a/Calibration/HcalAlCaRecoProducers/plugins/AlCaIsoTracksFilter.cc b/Calibration/HcalAlCaRecoProducers/plugins/AlCaIsoTracksFilter.cc new file mode 100644 index 0000000000000..f2a14b59daefb --- /dev/null +++ b/Calibration/HcalAlCaRecoProducers/plugins/AlCaIsoTracksFilter.cc @@ -0,0 +1,376 @@ +// system include files +#include +#include +#include +#include +#include + +// user include files +#include "FWCore/Framework/interface/Frameworkfwd.h" +#include "FWCore/Framework/interface/EDFilter.h" +#include "FWCore/Framework/interface/Event.h" +#include "FWCore/Framework/interface/Run.h" +#include "FWCore/Framework/interface/ESHandle.h" +#include "FWCore/Framework/interface/LuminosityBlock.h" +#include "FWCore/ParameterSet/interface/ParameterSet.h" +#include "FWCore/ParameterSet/interface/ConfigurationDescriptions.h" +#include "FWCore/Common/interface/TriggerNames.h" + +#include "DataFormats/Common/interface/Handle.h" +//Tracks +#include "DataFormats/TrackReco/interface/Track.h" +#include "DataFormats/TrackReco/interface/TrackFwd.h" +#include "DataFormats/TrackReco/interface/HitPattern.h" +#include "DataFormats/TrackReco/interface/TrackBase.h" +// Vertices +#include "DataFormats/VertexReco/interface/VertexFwd.h" +#include "DataFormats/VertexReco/interface/Vertex.h" +#include "DataFormats/BeamSpot/interface/BeamSpot.h" +// RecHits +#include "DataFormats/EcalRecHit/interface/EcalRecHitCollections.h" +#include "DataFormats/HcalRecHit/interface/HcalRecHitCollections.h" +//Triggers +#include "DataFormats/Common/interface/TriggerResults.h" +#include "DataFormats/HLTReco/interface/TriggerEvent.h" + +#include "HLTrigger/HLTcore/interface/HLTConfigProvider.h" + +#include "Calibration/IsolatedParticles/interface/CaloPropagateTrack.h" +#include "Calibration/IsolatedParticles/interface/ChargeIsolation.h" +#include "Calibration/IsolatedParticles/interface/eCone.h" +#include "Calibration/IsolatedParticles/interface/TrackSelection.h" + +#include "MagneticField/Engine/interface/MagneticField.h" +#include "MagneticField/Records/interface/IdealMagneticFieldRecord.h" +#include "Geometry/CaloGeometry/interface/CaloGeometry.h" +#include "Geometry/CaloGeometry/interface/CaloSubdetectorGeometry.h" +#include "Geometry/CaloEventSetup/interface/CaloTopologyRecord.h" +#include "Geometry/CaloTopology/interface/CaloSubdetectorTopology.h" +#include "Geometry/CaloTopology/interface/HcalTopology.h" +#include "Geometry/CaloTopology/interface/CaloTopology.h" +#include "CondFormats/DataRecord/interface/EcalChannelStatusRcd.h" +#include "Geometry/CaloTopology/interface/EcalTrigTowerConstituentsMap.h" +#include "RecoLocalCalo/EcalRecAlgos/interface/EcalSeverityLevelAlgo.h" +#include "RecoLocalCalo/EcalRecAlgos/interface/EcalSeverityLevelAlgoRcd.h" + +// +// class declaration +// + +class AlCaIsoTracksFilter : public edm::EDFilter { +public: + explicit AlCaIsoTracksFilter(const edm::ParameterSet&); + ~AlCaIsoTracksFilter(); + + static void fillDescriptions(edm::ConfigurationDescriptions& descriptions); + +private: + virtual bool filter(edm::Event&, const edm::EventSetup&) override; + virtual void endJob() override; + virtual void beginRun(edm::Run const&, edm::EventSetup const&); + virtual void endRun(edm::Run const&, edm::EventSetup const&); + + // ----------member data --------------------------- + HLTConfigProvider hltConfig_; + std::vector trigNames, HLTNames; + std::vector trigKount, trigPass; + spr::trackSelectionParameters selectionParameters; + std::string theTrackQuality, processName; + std::string l1Filter, l2Filter, l3Filter; + double a_mipR, a_coneR, a_charIsoR; + double pTrackMin_, eEcalMax_, eIsolation_; + int nRun, nAll, nGood; + edm::InputTag triggerEvent_, theTriggerResultsLabel, labelHBHE_; + edm::InputTag labelGenTrack_, labelRecVtx_, labelEB_, labelEE_; + edm::EDGetTokenT tok_trigEvt; + edm::EDGetTokenT tok_trigRes; + + edm::EDGetTokenT tok_genTrack_; + edm::EDGetTokenT tok_recVtx_; + edm::EDGetTokenT tok_bs_; + edm::EDGetTokenT tok_EB_; + edm::EDGetTokenT tok_EE_; + edm::EDGetTokenT tok_hbhe_; +}; + +// +// constants, enums and typedefs +// + +// +// static data member definitions +// + +// +// constructors and destructor +// +AlCaIsoTracksFilter::AlCaIsoTracksFilter(const edm::ParameterSet& iConfig) : + nRun(0), nAll(0), nGood(0) { + //now do what ever initialization is needed + trigNames = iConfig.getParameter >("Triggers"); + theTrackQuality = iConfig.getParameter("TrackQuality"); + processName = iConfig.getParameter("ProcessName"); + l1Filter = iConfig.getParameter("L1Filter"); + l2Filter = iConfig.getParameter("L2Filter"); + l3Filter = iConfig.getParameter("L3Filter"); + reco::TrackBase::TrackQuality trackQuality_=reco::TrackBase::qualityByName(theTrackQuality); + selectionParameters.minPt = iConfig.getParameter("MinTrackPt"); + selectionParameters.minQuality = trackQuality_; + selectionParameters.maxDxyPV = iConfig.getParameter("MaxDxyPV"); + selectionParameters.maxDzPV = iConfig.getParameter("MaxDzPV"); + selectionParameters.maxChi2 = iConfig.getParameter("MaxChi2"); + selectionParameters.maxDpOverP = iConfig.getParameter("MaxDpOverP"); + selectionParameters.minOuterHit = iConfig.getParameter("MinOuterHit"); + selectionParameters.minLayerCrossed = iConfig.getParameter("MinLayerCrossed"); + selectionParameters.maxInMiss = iConfig.getParameter("MaxInMiss"); + selectionParameters.maxOutMiss = iConfig.getParameter("MaxOutMiss"); + a_coneR = iConfig.getParameter("ConeRadius"); + a_charIsoR = a_coneR + 28.9; + a_mipR = iConfig.getParameter("ConeRadiusMIP"); + pTrackMin_ = iConfig.getParameter("MinimumTrackP"); + eEcalMax_ = iConfig.getParameter("MaximumEcalEnergy"); + eIsolation_ = iConfig.getParameter("IsolationEnergy"); + triggerEvent_ = iConfig.getParameter("TriggerEventLabel"); + theTriggerResultsLabel = iConfig.getParameter("TriggerResultLabel"); + labelGenTrack_ = iConfig.getParameter("TrackLabel"); + labelRecVtx_ = iConfig.getParameter("VertexLabel"); + labelEB_ = iConfig.getParameter("EBRecHitLabel"); + labelEE_ = iConfig.getParameter("EERecHitLabel"); + labelHBHE_ = iConfig.getParameter("HBHERecHitLabel"); + + // define tokens for access + tok_trigEvt = consumes(triggerEvent_); + tok_trigRes = consumes(theTriggerResultsLabel); + tok_genTrack_ = consumes(labelGenTrack_); + tok_recVtx_ = consumes(labelRecVtx_); + tok_bs_ = consumes(iConfig.getParameter("BeamSpotLabel")); + + tok_EB_ = consumes(labelEB_); + tok_EE_ = consumes(labelEE_); + tok_hbhe_ = consumes(labelHBHE_); + + std::vector dummy(trigNames.size(),0); + trigKount = trigPass = dummy; + edm::LogInfo("HcalIsoTrack") <<"Parameters read from config file \n" + <<"\t minPt " << selectionParameters.minPt + <<"\t theTrackQuality " << theTrackQuality + <<"\t minQuality " << selectionParameters.minQuality + <<"\t maxDxyPV " << selectionParameters.maxDxyPV + <<"\t maxDzPV " << selectionParameters.maxDzPV + <<"\t maxChi2 " << selectionParameters.maxChi2 + <<"\t maxDpOverP " << selectionParameters.maxDpOverP + <<"\t minOuterHit " << selectionParameters.minOuterHit + <<"\t minLayerCrossed " << selectionParameters.minLayerCrossed + <<"\t maxInMiss " << selectionParameters.maxInMiss + <<"\t maxOutMiss " << selectionParameters.maxOutMiss + <<"\t a_coneR " << a_coneR + <<"\t a_charIsoR " << a_charIsoR + <<"\t a_mipR " << a_mipR; + edm::LogInfo("HcalIsoTrack") << "Process " << processName << " L1Filter:" + << l1Filter << " L2Filter:" << l2Filter + << " L3Filter:" << l3Filter; + for (unsigned int k=0; k triggerEventHandle; + iEvent.getByToken(tok_trigEvt, triggerEventHandle); + if (!triggerEventHandle.isValid()) { + edm::LogWarning("HcalIsoTrack") << "Error! Can't get the product " + << triggerEvent_.label() ; + } else { + triggerEvent = *(triggerEventHandle.product()); + + /////////////////////////////TriggerResults + edm::Handle triggerResults; + iEvent.getByToken(tok_trigRes, triggerResults); + if (triggerResults.isValid()) { + bool ok(false); + std::vector modules; + const edm::TriggerNames & triggerNames = iEvent.triggerNames(*triggerResults); + const std::vector & triggerNames_ = triggerNames.triggerNames(); + for (unsigned int iHLT=0; iHLTsize(); iHLT++) { + int hlt = triggerResults->accept(iHLT); + for (unsigned int i=0; i 0) { + ok = true; + trigPass[i]++; + } + LogDebug("HcalIsoTrack") <<"This is the trigger we are looking for " + << triggerNames_[iHLT] << " Flag " << hlt + << ":" << ok; + } + } + } + if (ok) { + //Step2: Get geometry/B-field information + //Get magnetic field + edm::ESHandle bFieldH; + iSetup.get().get(bFieldH); + const MagneticField *bField = bFieldH.product(); + // get handles to calogeometry and calotopology + edm::ESHandle pG; + iSetup.get().get(pG); + const CaloGeometry* geo = pG.product(); + + //Also relevant information to extrapolate tracks to Hcal surface + bool okC(true); + //Get track collection + edm::Handle trkCollection; + iEvent.getByToken(tok_genTrack_, trkCollection); + if (!trkCollection.isValid()) { + edm::LogWarning("HcalIsoTrack") << "Cannot access the collection " << labelGenTrack_; + okC = false; + } + reco::TrackCollection::const_iterator trkItr; + + //Define the best vertex and the beamspot + edm::Handle recVtxs; + iEvent.getByToken(tok_recVtx_, recVtxs); + edm::Handle beamSpotH; + iEvent.getByToken(tok_bs_, beamSpotH); + math::XYZPoint leadPV(0,0,0); + if (recVtxs->size()>0 && !((*recVtxs)[0].isFake())) { + leadPV = math::XYZPoint((*recVtxs)[0].x(),(*recVtxs)[0].y(), + (*recVtxs)[0].z()); + } else if (beamSpotH.isValid()) { + leadPV = beamSpotH->position(); + } + LogDebug("HcalIsoTrack") << "Primary Vertex " << leadPV; + + // RecHits + edm::Handle barrelRecHitsHandle; + iEvent.getByToken(tok_EB_, barrelRecHitsHandle); + if (!barrelRecHitsHandle.isValid()) { + edm::LogWarning("HcalIsoTrack") << "Cannot access the collection " << labelEB_; + okC = false; + } + edm::Handle endcapRecHitsHandle; + iEvent.getByToken(tok_EE_, endcapRecHitsHandle); + if (!endcapRecHitsHandle.isValid()) { + edm::LogWarning("HcalIsoTrack") << "Cannot access the collection " << labelEE_; + okC = false; + } + edm::Handle hbhe; + iEvent.getByToken(tok_hbhe_, hbhe); + if (!hbhe.isValid()) { + edm::LogWarning("HcalIsoTrack") << "Cannot access the collection " << labelHBHE_; + okC = false; + } + + if (okC) { + //Step3 propagate the tracks to calorimeter surface and find + // candidates for isolated tracks + //Propagate tracks to calorimeter surface) + std::vector trkCaloDirections; + spr::propagateCALO(trkCollection, geo, bField, theTrackQuality, + trkCaloDirections, false); + + std::vector::const_iterator trkDetItr; + unsigned int nTracks(0), nselTracks(0); + for (trkDetItr = trkCaloDirections.begin(),nTracks=0; + trkDetItr != trkCaloDirections.end(); trkDetItr++,nTracks++) { + const reco::Track* pTrack = &(*(trkDetItr->trkItr)); + math::XYZTLorentzVector v4(pTrack->px(), pTrack->py(), + pTrack->pz(), pTrack->p()); + LogDebug("HcalIsoTrack") << "This track : " << nTracks + << " (pt|eta|phi|p) :" << pTrack->pt() + << "|" << pTrack->eta() << "|" + << pTrack->phi() << "|" << pTrack->p(); + + //Selection of good track + bool qltyFlag = spr::goodTrack(pTrack,leadPV,selectionParameters,false); + LogDebug("HcalIsoTrack") << "qltyFlag|okECAL|okHCAL : " << qltyFlag + << "|" << trkDetItr->okECAL << "|" + << trkDetItr->okHCAL; + if (qltyFlag && trkDetItr->okECAL && trkDetItr->okHCAL) { + double t_p = pTrack->p(); + nselTracks++; + int nRH_eMipDR(0), nNearTRKs(0); + double eMipDR = spr::eCone_ecal(geo, barrelRecHitsHandle, + endcapRecHitsHandle, + trkDetItr->pointHCAL, + trkDetItr->pointECAL, a_mipR, + trkDetItr->directionECAL, + nRH_eMipDR); + double hmaxNearP = spr::chargeIsolationCone(nTracks, + trkCaloDirections, + a_charIsoR, + nNearTRKs, false); + LogDebug("HcalIsoTrack") << "This track : " << nTracks + << " (pt|eta|phi|p) :" << pTrack->pt() + << "|" << pTrack->eta() << "|" + << pTrack->phi() << "|" << t_p + << "e_MIP " << eMipDR + << " Chg Isolation " << hmaxNearP; + if (t_p>pTrackMin_ && eMipDR + + diff --git a/Calibration/HcalAlCaRecoProducers/python/ALCARECOHcalCalDijets_Output_cff.py b/Calibration/HcalAlCaRecoProducers/python/ALCARECOHcalCalDijets_Output_cff.py index d905dcb23c4d6..a94c14a48a730 100644 --- a/Calibration/HcalAlCaRecoProducers/python/ALCARECOHcalCalDijets_Output_cff.py +++ b/Calibration/HcalAlCaRecoProducers/python/ALCARECOHcalCalDijets_Output_cff.py @@ -9,8 +9,13 @@ SelectEvents = cms.vstring('pathALCARECOHcalCalDijets') ), outputCommands = cms.untracked.vstring( - 'keep *_DiJProd_*_*', - 'keep triggerTriggerEvent_*_*_*') + 'keep *_DiJetsProd_*_*', + 'keep triggerTriggerEvent_*_*_*', + 'keep *_particleFlow_*_*', + 'keep recoPFBlocks_particleFlowBlock_*_*', + 'keep recoPFClusters_*_*_*', + 'keep *_fixedGridRhoFastjetAll_*_*', + 'keep recoTracks_generalTracks_*_*') ) import copy diff --git a/Calibration/HcalAlCaRecoProducers/python/ALCARECOHcalCalDijets_cff.py b/Calibration/HcalAlCaRecoProducers/python/ALCARECOHcalCalDijets_cff.py index c697f8c657fc7..894820e18db77 100644 --- a/Calibration/HcalAlCaRecoProducers/python/ALCARECOHcalCalDijets_cff.py +++ b/Calibration/HcalAlCaRecoProducers/python/ALCARECOHcalCalDijets_cff.py @@ -15,5 +15,5 @@ ) -seqALCARECOHcalCalDijets = cms.Sequence(dijetsHLT*DiJProd) +seqALCARECOHcalCalDijets = cms.Sequence(dijetsHLT*DiJetsProd) diff --git a/Calibration/HcalAlCaRecoProducers/python/ALCARECOHcalCalGammaJet_Output_cff.py b/Calibration/HcalAlCaRecoProducers/python/ALCARECOHcalCalGammaJet_Output_cff.py index 692e89658d9a7..dd36f0da36e10 100644 --- a/Calibration/HcalAlCaRecoProducers/python/ALCARECOHcalCalGammaJet_Output_cff.py +++ b/Calibration/HcalAlCaRecoProducers/python/ALCARECOHcalCalGammaJet_Output_cff.py @@ -8,7 +8,13 @@ SelectEvents = cms.vstring('pathALCARECOHcalCalGammaJet') ), outputCommands = cms.untracked.vstring( - 'keep *_GammaJetProd_*_*') + 'keep recoPhotonCores_*_*_*', + 'keep recoSuperClusters_*_*_*', + 'keep recoTracks_generalTracks_*_*', + 'keep *_particleFlow_*_*', + 'keep recoPFBlocks_particleFlowBlock_*_*', + 'keep recoPFClusters_*_*_*', + 'keep *_GammaJetProd_*_*') ) import copy diff --git a/Calibration/HcalAlCaRecoProducers/python/ALCARECOHcalCalMinBias_cff.py b/Calibration/HcalAlCaRecoProducers/python/ALCARECOHcalCalMinBias_cff.py index 3e154ceab44c7..2acf0d24aa4a5 100644 --- a/Calibration/HcalAlCaRecoProducers/python/ALCARECOHcalCalMinBias_cff.py +++ b/Calibration/HcalAlCaRecoProducers/python/ALCARECOHcalCalMinBias_cff.py @@ -27,6 +27,7 @@ ) seqALCARECOHcalCalMinBias = cms.Sequence(hcalminbiasHLT*hcalDigiAlCaMB*gtDigisAlCaMB*hbherecoNoise*hfrecoNoise*hfrecoMBspecial*horecoNoise) +seqALCARECOHcalCalMinBiasNoHLT = cms.Sequence(hcalDigiAlCaMB*gtDigisAlCaMB*hbherecoNoise*hfrecoNoise*hfrecoMBspecial*horecoNoise) gtDigisAlCaMB.DaqGtInputTag = 'source' diff --git a/Calibration/HcalAlCaRecoProducers/python/alcaIsoTracksFilter_cfi.py b/Calibration/HcalAlCaRecoProducers/python/alcaIsoTracksFilter_cfi.py new file mode 100644 index 0000000000000..0b538dc3e9429 --- /dev/null +++ b/Calibration/HcalAlCaRecoProducers/python/alcaIsoTracksFilter_cfi.py @@ -0,0 +1,32 @@ +import FWCore.ParameterSet.Config as cms + +AlcaIsoTracksFilter = cms.EDFilter("AlCaIsoTracksFilter", + TrackLabel = cms.InputTag("generalTracks"), + VertexLabel = cms.InputTag("offlinePrimaryVertices"), + BeamSpotLabel = cms.InputTag("offlineBeamSpot"), + EBRecHitLabel = cms.InputTag("ecalRecHit","EcalRecHitsEB"), + EERecHitLabel = cms.InputTag("ecalRecHit","EcalRecHitsEE"), + HBHERecHitLabel = cms.InputTag("hbhereco"), + TriggerEventLabel = cms.InputTag("hltTriggerSummaryAOD","","HLT"), + TriggerResultLabel= cms.InputTag("TriggerResults","","HLT"), + Triggers = cms.vstring("HLT_PFJet40","HLT_PFJet80","HLT_PFJet140","HLT_PFJet200","HLT_PFJet260","HLT_PFJet320","HLT_PFJet320","HLT_PFJet400"), + TrackQuality = cms.string("highPurity"), + ProcessName = cms.string("HLT"), + L1Filter = cms.string("hltL1s"), + L2Filter = cms.string("L2Filter"), + L3Filter = cms.string("PFJet"), + MinTrackPt = cms.double(10.0), + MaxDxyPV = cms.double(10.0), + MaxDzPV = cms.double(100.0), + MaxChi2 = cms.double(5.0), + MaxDpOverP = cms.double(0.1), + MinOuterHit = cms.int32(4), + MinLayerCrossed = cms.int32(8), + MaxInMiss = cms.int32(2), + MaxOutMiss = cms.int32(2), + ConeRadius = cms.double(34.98), + ConeRadiusMIP = cms.double(14.0), + MinimumTrackP = cms.double(20.0), + MaximumEcalEnergy = cms.double(2.0), + IsolationEnergy = cms.double(2.0), +) diff --git a/Calibration/HcalAlCaRecoProducers/python/alcadijets_cfi.py b/Calibration/HcalAlCaRecoProducers/python/alcadijets_cfi.py index 8aea7e9475161..e9b4ac2402887 100644 --- a/Calibration/HcalAlCaRecoProducers/python/alcadijets_cfi.py +++ b/Calibration/HcalAlCaRecoProducers/python/alcadijets_cfi.py @@ -1,13 +1,15 @@ import FWCore.ParameterSet.Config as cms -# producer for alcadijets (HCAL di-jets) +# producer for alcadijet (HCAL dijet) +DiJetsProd = cms.EDProducer("AlCaDiJetsProducer", + PFjetInput = cms.InputTag("ak4PFJetsCHS"), + HBHEInput = cms.InputTag("hbhereco"), + HFInput = cms.InputTag("hfreco"), + HOInput = cms.InputTag("horeco"), + #TriggerResults = cms.InputTag("TriggerResults::HLT"), + particleFlowInput = cms.InputTag("particleFlow"), + VertexInput = cms.InputTag("offlinePrimaryVertices"), + MinPtJet = cms.double(20.0) + ) -DiJProd = cms.EDProducer("AlCaDiJetsProducer", - jetsInput = cms.InputTag("iterativeCone5CaloJets"), - ecalInputs = cms.VInputTag(cms.InputTag("ecalRecHit","EcalRecHitsEB"), cms.InputTag("ecalRecHit","EcalRecHitsEE")), - hbheInput = cms.InputTag("hbhereco"), - hoInput = cms.InputTag("horeco"), - hfInput = cms.InputTag("hfreco") -) - diff --git a/Calibration/HcalAlCaRecoProducers/python/alcagammajet_cfi.py b/Calibration/HcalAlCaRecoProducers/python/alcagammajet_cfi.py index f8244d4b81c5b..188e6653619b1 100644 --- a/Calibration/HcalAlCaRecoProducers/python/alcagammajet_cfi.py +++ b/Calibration/HcalAlCaRecoProducers/python/alcagammajet_cfi.py @@ -2,17 +2,23 @@ # producer for alcadijets (HCAL gamma-jet) GammaJetProd = cms.EDProducer("AlCaGammaJetProducer", - hbheInput = cms.InputTag("hbhereco"), - correctedIslandBarrelSuperClusterCollection = cms.string(''), - correctedIslandEndcapSuperClusterCollection = cms.string(''), - hfInput = cms.InputTag("hfreco"), - hoInput = cms.InputTag("horeco"), - correctedIslandEndcapSuperClusterProducer = cms.string('correctedIslandEndcapSuperClusters'), - correctedIslandBarrelSuperClusterProducer = cms.string('correctedIslandBarrelSuperClusters'), - ecalInputs = cms.VInputTag(cms.InputTag("ecalRecHit","EcalRecHitsEB"), cms.InputTag("ecalRecHit","EcalRecHitsEE")), - # VInputTag srcCalo = {iterativeCone5CaloJets, midPointCone5CaloJets, midPointCone7CaloJets,ktCaloJets} - srcCalo = cms.VInputTag(cms.InputTag("iterativeCone7CaloJets")), - inputTrackLabel = cms.untracked.string('generalTracks') -) + PhoInput = cms.InputTag("gedPhotons"), + PFjetInput = cms.InputTag("ak4PFJetsCHS"), + HBHEInput = cms.InputTag("hbhereco"), + HFInput = cms.InputTag("hfreco"), + HOInput = cms.InputTag("horeco"), + METInput = cms.InputTag("pfMet"), + TriggerResults = cms.InputTag("TriggerResults::HLT"), + gsfeleInput = cms.InputTag("gedGsfElectrons"), + particleFlowInput = cms.InputTag("particleFlow"), + VertexInput = cms.InputTag("offlinePrimaryVertices"), + ConversionsInput = cms.InputTag("allConversions"), + rhoInput = cms.InputTag("fixedGridRhoFastjetAll"), + BeamSpotInput = cms.InputTag("offlineBeamSpot"), + PhoLoose = cms.InputTag("PhotonIDProdGED", "PhotonCutBasedIDLoose"), + PhoTight = cms.InputTag("PhotonIDProdGED", "PhotonCutBasedIDTight"), + MinPtJet = cms.double(10.0), + MinPtPhoton = cms.double(10.0) + ) diff --git a/Calibration/HcalAlCaRecoProducers/python/alcahbhemuon_cfi.py b/Calibration/HcalAlCaRecoProducers/python/alcahbhemuon_cfi.py new file mode 100644 index 0000000000000..a1a6f702cd173 --- /dev/null +++ b/Calibration/HcalAlCaRecoProducers/python/alcahbhemuon_cfi.py @@ -0,0 +1,14 @@ +import FWCore.ParameterSet.Config as cms + +# producer for alcahbhemuon (HCAL with muons) +HBHEMuonProd = cms.EDProducer("AlCaHBHEMuonProducer", + TriggerResultLabel= cms.InputTag("TriggerResults","","HLT"), + BeamSpotLabel = cms.InputTag("offlineBeamSpot"), + VertexLabel = cms.InputTag("offlinePrimaryVertices"), + EBRecHitLabel = cms.InputTag("ecalRecHit","EcalRecHitsEB"), + EERecHitLabel = cms.InputTag("ecalRecHit","EcalRecHitsEE"), + HBHERecHitLabel = cms.InputTag("hbhereco"), + MuonLabel = cms.InputTag("muons"), + MinimumMuonP = cms.double(10.0), + ) + diff --git a/Calibration/HcalAlCaRecoProducers/python/alcaisotrk_cfi.py b/Calibration/HcalAlCaRecoProducers/python/alcaisotrk_cfi.py index 1fe4e0df2ab37..c6d628fb7ea90 100644 --- a/Calibration/HcalAlCaRecoProducers/python/alcaisotrk_cfi.py +++ b/Calibration/HcalAlCaRecoProducers/python/alcaisotrk_cfi.py @@ -1,35 +1,35 @@ import FWCore.ParameterSet.Config as cms # producer for alcaisotrk (HCAL isolated tracks) -from TrackingTools.TrackAssociator.default_cfi import * -from TrackingTools.TrackAssociator.DetIdAssociatorESProducer_cff import * IsoProd = cms.EDProducer("AlCaIsoTracksProducer", - TrackAssociatorParameterBlock, - HBHEInput = cms.InputTag("hbhereco"), - InputTracksLabel = cms.InputTag("generalTracks"), - vtxCut = cms.double(10.0), - MinTrackPt = cms.double(0.0), - ECALRingOuterRadius = cms.double(35.0), - ECALRingInnerRadius = cms.double(15.0), - ECALClusterRadius = cms.double(9.0), - HOInput = cms.InputTag("horeco"), - MaxNearbyTrackEnergy = cms.double(2.0), - RIsolAtHCALSurface = cms.double(64.0), - MinNumberOfHitsCoreTrack=cms.int32(8), - MinNumberOfHitsInConeTracks=cms.int32(3), - UseLowPtConeCorrection = cms.bool(False), - ECALInputs = cms.VInputTag(cms.InputTag("ecalRecHit","EcalRecHitsEB"), cms.InputTag("ecalRecHit","EcalRecHitsEE")), - MaxTrackEta = cms.double(2.0), - SkipNeutralIsoCheck = cms.untracked.bool(True), - MinTrackP = cms.double(10.0), - CheckHLTMatch=cms.bool(False), - hltTriggerEventLabel = cms.InputTag("hltTriggerSummaryAOD"), - hltL3FilterLabels = cms.vstring("hltIsolPixelTrackL3FilterHB","hltIsolPixelTrackL3FilterHE"), - hltMatchingCone=cms.double(0.2), - ClusterECALasMatrix = cms.bool (False), - ECALMatrixFullSize = cms.int32(7), - l1FilterLabel = cms.string("hltL1sJet52"), - l1JetVetoCone = cms.double (1.2) + TrackLabel = cms.InputTag("generalTracks"), + VertexLabel = cms.InputTag("offlinePrimaryVertices"), + BeamSpotLabel = cms.InputTag("offlineBeamSpot"), + EBRecHitLabel = cms.InputTag("ecalRecHit","EcalRecHitsEB"), + EERecHitLabel = cms.InputTag("ecalRecHit","EcalRecHitsEE"), + HBHERecHitLabel = cms.InputTag("hbhereco"), + L1GTSeedLabel = cms.InputTag("hltL1sIsoTrack"), + TriggerEventLabel = cms.InputTag("hltTriggerSummaryAOD","","HLT"), + TriggerResultLabel= cms.InputTag("TriggerResults","","HLT"), + Triggers = cms.vstring("HLT_IsoTrackHB","HLT_IsoTrackHE"), + TrackQuality = cms.string("highPurity"), + ProcessName = cms.string("HLT"), + L1Filter = cms.string(""), + L2Filter = cms.string("L2Filter"), + L3Filter = cms.string("Filter"), + MinTrackPt = cms.double(10.0), + MaxDxyPV = cms.double(10.0), + MaxDzPV = cms.double(100.0), + MaxChi2 = cms.double(5.0), + MaxDpOverP = cms.double(0.1), + MinOuterHit = cms.int32(4), + MinLayerCrossed = cms.int32(8), + MaxInMiss = cms.int32(2), + MaxOutMiss = cms.int32(2), + ConeRadius = cms.double(34.98), + ConeRadiusMIP = cms.double(14.0), + MinimumTrackP = cms.double(20.0), + MaximumEcalEnergy = cms.double(2.0), + IsolationEnergy = cms.double(2.0), ) - diff --git a/Calibration/HcalAlCaRecoProducers/python/alcastreamHcalHBHEMuonOutput_cff.py b/Calibration/HcalAlCaRecoProducers/python/alcastreamHcalHBHEMuonOutput_cff.py new file mode 100644 index 0000000000000..23f02f4a91777 --- /dev/null +++ b/Calibration/HcalAlCaRecoProducers/python/alcastreamHcalHBHEMuonOutput_cff.py @@ -0,0 +1,9 @@ +import FWCore.ParameterSet.Config as cms + +# output block for alcastream HCAL HBHEMuon +# output module +# module alcastreamHcalHBHEMuonOutput = PoolOutputModule +alcastreamHcalHBHEMuonOutput = cms.PSet( + outputCommands = cms.untracked.vstring('drop *', + 'keep *_HBHEMuonProd_*_*') + ) diff --git a/Calibration/HcalAlCaRecoProducers/python/alcastreamHcalHBHEMuon_cff.py b/Calibration/HcalAlCaRecoProducers/python/alcastreamHcalHBHEMuon_cff.py new file mode 100644 index 0000000000000..af3a378a380ab --- /dev/null +++ b/Calibration/HcalAlCaRecoProducers/python/alcastreamHcalHBHEMuon_cff.py @@ -0,0 +1,7 @@ +import FWCore.ParameterSet.Config as cms + +#------------------------------------------------ +#AlCaReco filtering for HCAL hbhemuon: +#------------------------------------------------ +from Calibration.HcalAlCaRecoProducers.alcahbhemuon_cfi import * +seqAlcastreamHcalHBHEMuon = cms.Sequence(HBHEMuonProd) diff --git a/Calibration/HcalAlCaRecoProducers/python/gammajetHLT_cfi.py b/Calibration/HcalAlCaRecoProducers/python/gammajetHLT_cfi.py index 4c9cd2783c9cf..82f1755889327 100644 --- a/Calibration/HcalAlCaRecoProducers/python/gammajetHLT_cfi.py +++ b/Calibration/HcalAlCaRecoProducers/python/gammajetHLT_cfi.py @@ -5,9 +5,11 @@ import FWCore.ParameterSet.Config as cms import HLTrigger.HLTfilters.hltHighLevel_cfi +# Adjusted based on +# https://twiki.cern.ch/twiki/bin/view/CMSPublic/SWGuideAlCaRecoTriggerBits + gammajetHLT = HLTrigger.HLTfilters.hltHighLevel_cfi.hltHighLevel.clone( - HLTPaths = ['HLT_IsoPhoton30_L1I','HLT_IsoPhoton15_L1R'], + HLTPaths = ['HLT_L1SingleEG*','HLT_Photon*'], +# eventSetupPathsKey='HcalCalGammaJet', throw = False ) - - diff --git a/Calibration/HcalAlCaRecoProducers/src/AlCaDiJetsProducer.cc b/Calibration/HcalAlCaRecoProducers/src/AlCaDiJetsProducer.cc index 68f8314c34740..75bb596df6547 100644 --- a/Calibration/HcalAlCaRecoProducers/src/AlCaDiJetsProducer.cc +++ b/Calibration/HcalAlCaRecoProducers/src/AlCaDiJetsProducer.cc @@ -1,200 +1,215 @@ -#include "Calibration/HcalAlCaRecoProducers/interface/AlCaDiJetsProducer.h" +// system include files +#include +#include +// user include files +#include "FWCore/Framework/interface/Frameworkfwd.h" +#include "FWCore/Framework/interface/EDProducer.h" +#include "FWCore/Framework/interface/Event.h" +#include "FWCore/Framework/interface/MakerMacros.h" +#include "FWCore/ParameterSet/interface/ParameterSet.h" +#include "FWCore/Framework/interface/ESHandle.h" +#include "FWCore/Framework/interface/EventSetup.h" #include "FWCore/MessageLogger/interface/MessageLogger.h" -#include "Geometry/Records/interface/CaloGeometryRecord.h" + +#include "DataFormats/DetId/interface/DetId.h" +#include "DataFormats/EgammaCandidates/interface/Photon.h" +#include "DataFormats/EgammaCandidates/interface/PhotonFwd.h" +#include "DataFormats/JetReco/interface/PFJetCollection.h" +#include "DataFormats/HcalRecHit/interface/HBHERecHit.h" +#include "DataFormats/HcalRecHit/interface/HFRecHit.h" +#include "DataFormats/HcalRecHit/interface/HORecHit.h" +#include "DataFormats/Common/interface/ValueMap.h" +#include "DataFormats/Common/interface/TriggerResults.h" +#include "DataFormats/HLTReco/interface/TriggerEvent.h" +#include "DataFormats/HLTReco/interface/TriggerObject.h" +#include "DataFormats/ParticleFlowCandidate/interface/PFCandidate.h" +#include "DataFormats/METReco/interface/PFMET.h" +#include "DataFormats/METReco/interface/PFMETCollection.h" +#include "DataFormats/VertexReco/interface/Vertex.h" +#include "DataFormats/VertexReco/interface/VertexFwd.h" #include "DataFormats/GeometryVector/interface/GlobalPoint.h" -#include "FWCore/Utilities/interface/Exception.h" - -using namespace edm; -using namespace std; -using namespace reco; - -namespace cms -{ - -AlCaDiJetsProducer::AlCaDiJetsProducer(const edm::ParameterSet& iConfig) -{ - tok_jets_ = consumes(iConfig.getParameter("jetsInput")); - ecalLabels_=iConfig.getParameter >("ecalInputs"); - tok_hbhe_ = consumes(iConfig.getParameter("hbheInput")); - tok_ho_ = consumes(iConfig.getParameter("hoInput")); - tok_hf_ = consumes(iConfig.getParameter("hfInput")); - allowMissingInputs_ = true; - - // fill ecal tokens from input labels - const unsigned nLabels = ecalLabels_.size(); - for ( unsigned i=0; i != nLabels; i++ ) - toks_ecal_.push_back(consumes(ecalLabels_[i])); - -//register your products - produces("DiJetsBackToBackCollection"); - produces("DiJetsEcalRecHitCollection"); - produces("DiJetsHBHERecHitCollection"); - produces("DiJetsHORecHitCollection"); - produces("DiJetsHFRecHitCollection"); -} -void AlCaDiJetsProducer::beginJob() -{ +#include "Geometry/CaloGeometry/interface/CaloGeometry.h" +#include "Geometry/Records/interface/CaloGeometryRecord.h" +#include + +// +// class declaration +// + +class AlCaDiJetsProducer : public edm::EDProducer { + public: + explicit AlCaDiJetsProducer(const edm::ParameterSet&); + ~AlCaDiJetsProducer(); + virtual void beginJob() ; + virtual void produce(edm::Event &, const edm::EventSetup&); + virtual void endJob(); + private: + bool select (reco::PFJetCollection); + + // ----------member data --------------------------- + + edm::InputTag labelPFJet_, labelHBHE_, labelHF_, labelHO_, labelPFCandidate_, labelVertex_;//labelTrigger_, + double minPtJet_; + int nAll_, nSelect_; + + edm::EDGetTokenT tok_PFJet_; + edm::EDGetTokenT>> tok_HBHE_; + edm::EDGetTokenT>> tok_HF_; + edm::EDGetTokenT>> tok_HO_; + //edm::EDGetTokenT tok_TrigRes_; + edm::EDGetTokenT tok_PFCand_; + edm::EDGetTokenT tok_Vertex_; +}; + +AlCaDiJetsProducer::AlCaDiJetsProducer(const edm::ParameterSet& iConfig) : nAll_(0), nSelect_(0) { + // Take input + labelPFJet_ = iConfig.getParameter("PFjetInput"); + labelHBHE_ = iConfig.getParameter("HBHEInput"); + labelHF_ = iConfig.getParameter("HFInput"); + labelHO_ = iConfig.getParameter("HOInput"); + //labelTrigger_ = iConfig.getParameter("TriggerResults"); + labelPFCandidate_= iConfig.getParameter("particleFlowInput"); + labelVertex_ = iConfig.getParameter("VertexInput"); + minPtJet_ = iConfig.getParameter("MinPtJet"); + + tok_PFJet_ = consumes(labelPFJet_); + tok_HBHE_ = consumes>>(labelHBHE_); + tok_HF_ = consumes>>(labelHF_); + tok_HO_ = consumes>>(labelHO_); + //tok_TrigRes_= consumes(labelTrigger_); + tok_PFCand_ = consumes(labelPFCandidate_); + tok_Vertex_ = consumes(labelVertex_); + + // register your products + produces(labelPFJet_.encode()); + produces>>(labelHBHE_.encode()); + produces>>(labelHF_.encode()); + produces>>(labelHO_.encode()); + //produces(labelTrigger_.encode()); + produces(labelPFCandidate_.encode()); + produces(labelVertex_.encode()); } -AlCaDiJetsProducer::~AlCaDiJetsProducer() -{ - +AlCaDiJetsProducer::~AlCaDiJetsProducer() { } -} +void AlCaDiJetsProducer::beginJob() { } +void AlCaDiJetsProducer::endJob() { + edm::LogInfo("AlcaDiJets") << "Accepts " << nSelect_ << " events from a total of " << nAll_ << " events"; +} +bool AlCaDiJetsProducer::select (reco::PFJetCollection jt) { + if (jt.size()<2) return false; + if (((jt.at(0)).pt()) result (new CaloJetCollection); //Corrected jets - std::auto_ptr miniDiJetsEcalRecHitCollection(new EcalRecHitCollection); - std::auto_ptr miniDiJetsHBHERecHitCollection(new HBHERecHitCollection); - std::auto_ptr miniDiJetsHORecHitCollection(new HORecHitCollection); - std::auto_ptr miniDiJetsHFRecHitCollection(new HFRecHitCollection); - - edm::ESHandle pG; - iSetup.get().get(pG); - const CaloGeometry* geo = pG.product(); - - // Jets Collections - - vector jetv; - - CaloJet fJet1, fJet2, fJet3; - edm::Handle jets; - iEvent.getByToken(tok_jets_, jets); - int iflag_select = 0; - if(jets->size()>1){ - fJet1 = (*jets)[0]; - fJet2 = (*jets)[1]; - double dphi = fabs(fJet1.phi() - fJet2.phi()); - if(dphi > pi){dphi = 2*pi - dphi;} - double degreedphi = dphi*180./pi; - if(fabs(degreedphi-180)<30.){iflag_select = 1;} - } - if(iflag_select == 1){ - result->push_back(fJet1); - result->push_back(fJet2); - jetv.push_back(fJet1); - jetv.push_back(fJet2); - if(jets->size()>2){ - fJet3 = (*jets)[2]; - result->push_back(fJet3); - jetv.push_back(fJet3); - } - } else { - iEvent.put( result, "DiJetsBackToBackCollection"); - iEvent.put( miniDiJetsEcalRecHitCollection,"DiJetsEcalRecHitCollection"); - iEvent.put( miniDiJetsHBHERecHitCollection, "DiJetsHBHERecHitCollection"); - iEvent.put( miniDiJetsHORecHitCollection, "DiJetsHORecHitCollection"); - iEvent.put( miniDiJetsHFRecHitCollection, "DiJetsHFRecHitCollection"); - return; - } - - // Ecal Collections - - std::vector >::const_iterator i; - for (i=toks_ecal_.begin(); i!=toks_ecal_.end(); i++) { - edm::Handle ec; - iEvent.getByToken(*i,ec); - for(EcalRecHitCollection::const_iterator ecItr = (*ec).begin(); - ecItr != (*ec).end(); ++ecItr) - { -// EcalBarrel = 1, EcalEndcap = 2 - GlobalPoint pos = geo->getPosition(ecItr->detid()); - double phihit = pos.phi(); - double etahit = pos.eta(); - int iflag_select = 0; - for(unsigned int i=0; i pi) dphi = 2*pi - dphi; - double dr = sqrt(deta*deta+dphi*dphi); - if(dr < 1.4){iflag_select = 1;} - } - if(iflag_select==1){miniDiJetsEcalRecHitCollection->push_back(*ecItr);} - } - - } - - // HB & HE Collections - - edm::Handle hbhe; - iEvent.getByToken(tok_hbhe_,hbhe); - for(HBHERecHitCollection::const_iterator hbheItr=hbhe->begin(); - hbheItr!=hbhe->end(); hbheItr++) - { - GlobalPoint pos = geo->getPosition(hbheItr->detid()); - double phihit = pos.phi(); - double etahit = pos.eta(); - int iflag_select = 0; - for(unsigned int i=0; i pi) dphi = 2*pi - dphi; - double dr = sqrt(deta*deta+dphi*dphi); - if(dr < 1.4){iflag_select = 1;} - } - if(iflag_select==1){miniDiJetsHBHERecHitCollection->push_back(*hbheItr);} - } - +void AlCaDiJetsProducer::produce(edm::Event& iEvent, const edm::EventSetup& iSetup) { + nAll_++; + + // Access the collections from iEvent + edm::Handle pfjet; + iEvent.getByToken(tok_PFJet_,pfjet); + if (!pfjet.isValid()) { + edm::LogWarning("AlCaDiJets") << "AlCaDiJetsProducer: Error! can't get product " << labelPFJet_; + return ; + } + const reco::PFJetCollection pfjets = *(pfjet.product()); + + edm::Handle pfc; + iEvent.getByToken(tok_PFCand_,pfc); + if (!pfc.isValid()) { + edm::LogWarning("AlCaDiJets") << "AlCaDiJetsProducer: Error! can't get product " << labelPFCandidate_; + return ; + } + const reco::PFCandidateCollection pfcand = *(pfc.product()); + + edm::Handle vt; + iEvent.getByToken(tok_Vertex_,vt); + if (!vt.isValid()) { + edm::LogWarning("AlCaDiJets") << "AlCaDiJetsProducer: Error! can't get product " << labelVertex_; + return ; + } + const reco::VertexCollection vtx = *(vt.product()); + + edm::Handle > > hbhe; + iEvent.getByToken(tok_HBHE_,hbhe); + if (!hbhe.isValid()) { + edm::LogWarning("AlCaDiJets") << "AlCaDiJetsProducer: Error! can't get product " << labelHBHE_; + return ; + } + const edm::SortedCollection > Hithbhe = *(hbhe.product()); + + edm::Handle > > ho; + iEvent.getByToken(tok_HO_,ho); + if(!ho.isValid()) { + edm::LogWarning("AlCaDiJets") << "AlCaDiJetsProducer: Error! can't get product " << labelHO_; + return ; + } + const edm::SortedCollection > Hitho = *(ho.product()); + + edm::Handle > > hf; + iEvent.getByToken(tok_HF_,hf); + if(!hf.isValid()) { + edm::LogWarning("AlCaDiJets") << "AlCaDiJetsProducer: Error! can't get product " << labelHF_; + return ; + } + const edm::SortedCollection > Hithf = *(hf.product()); + + // See if this event is useful + bool accept = select(pfjets); + if (accept) { + nSelect_++; + + //Copy from standard place + std::auto_ptr miniPFjetCollection(new reco::PFJetCollection); + for(reco::PFJetCollection::const_iterator pfjetItr=pfjets.begin(); + pfjetItr!=pfjets.end(); pfjetItr++) { + miniPFjetCollection->push_back(*pfjetItr); + } + + std::auto_ptr miniPFCandCollection(new reco::PFCandidateCollection); + for(reco::PFCandidateCollection::const_iterator pfcItr=pfcand.begin(); + pfcItr!=pfcand.end(); pfcItr++) { + miniPFCandCollection->push_back(*pfcItr); + } + + std::auto_ptr miniVtxCollection(new reco::VertexCollection); + for(reco::VertexCollection::const_iterator vtxItr=vtx.begin(); + vtxItr!=vtx.end(); vtxItr++) { + miniVtxCollection->push_back(*vtxItr); + } + + std::auto_ptr>> miniHBHECollection(new edm::SortedCollection>); + for(edm::SortedCollection >::const_iterator hbheItr=Hithbhe.begin(); + hbheItr!=Hithbhe.end(); hbheItr++) { + miniHBHECollection->push_back(*hbheItr); + } + + std::auto_ptr>> miniHOCollection(new edm::SortedCollection>); + for(edm::SortedCollection >::const_iterator hoItr=Hitho.begin(); + hoItr!=Hitho.end(); hoItr++) { + miniHOCollection->push_back(*hoItr); + } + + std::auto_ptr>> miniHFCollection(new edm::SortedCollection>); + for(edm::SortedCollection >::const_iterator hfItr=Hithf.begin(); + hfItr!=Hithf.end(); hfItr++) { + miniHFCollection->push_back(*hfItr); + } + + //Put them in the event + iEvent.put( miniPFjetCollection, labelPFJet_.encode()); + iEvent.put( miniHBHECollection, labelHBHE_.encode()); + iEvent.put( miniHFCollection, labelHF_.encode()); + iEvent.put( miniHOCollection, labelHO_.encode()); + //iEvent.put( miniTriggerCollection, labelTrigger_.encode()); + iEvent.put( miniPFCandCollection, labelPFCandidate_.encode()); + iEvent.put( miniVtxCollection, labelVertex_.encode()); + } + return; -// HO Collections - - - edm::Handle ho; - iEvent.getByToken(tok_ho_,ho); - for(HORecHitCollection::const_iterator hoItr=ho->begin(); - hoItr!=ho->end(); hoItr++) - { - GlobalPoint pos = geo->getPosition(hoItr->detid()); - double phihit = pos.phi(); - double etahit = pos.eta(); - int iflag_select = 0; - for(unsigned int i=0; i pi) dphi = 2*pi - dphi; - double dr = sqrt(deta*deta+dphi*dphi); - if(dr < 1.4){iflag_select = 1;} - } - if(iflag_select==1){miniDiJetsHORecHitCollection->push_back(*hoItr);} - } - - // HF Collection - - - edm::Handle hf; - iEvent.getByToken(tok_hf_,hf); - for(HFRecHitCollection::const_iterator hfItr=hf->begin(); - hfItr!=hf->end(); hfItr++) - { - GlobalPoint pos = geo->getPosition(hfItr->detid()); - double phihit = pos.phi(); - double etahit = pos.eta(); - int iflag_select = 0; - for(unsigned int i=0; i pi) dphi = 2*pi - dphi; - double dr = sqrt(deta*deta+dphi*dphi); - if(dr < 1.4){iflag_select = 1;} - } - if(iflag_select==1){miniDiJetsHFRecHitCollection->push_back(*hfItr);} - } - - - //Put selected information in the event - - iEvent.put( result, "DiJetsBackToBackCollection"); - iEvent.put( miniDiJetsEcalRecHitCollection,"DiJetsEcalRecHitCollection"); - iEvent.put( miniDiJetsHBHERecHitCollection, "DiJetsHBHERecHitCollection"); - iEvent.put( miniDiJetsHORecHitCollection, "DiJetsHORecHitCollection"); - iEvent.put( miniDiJetsHFRecHitCollection, "DiJetsHFRecHitCollection"); -} } + +DEFINE_FWK_MODULE(AlCaDiJetsProducer); diff --git a/Calibration/HcalAlCaRecoProducers/src/AlCaGammaJetProducer.cc b/Calibration/HcalAlCaRecoProducers/src/AlCaGammaJetProducer.cc index a98cac898788b..42e938ee7a1aa 100644 --- a/Calibration/HcalAlCaRecoProducers/src/AlCaGammaJetProducer.cc +++ b/Calibration/HcalAlCaRecoProducers/src/AlCaGammaJetProducer.cc @@ -1,458 +1,381 @@ -#include "Calibration/HcalAlCaRecoProducers/interface/AlCaGammaJetProducer.h" +// system include files +#include +#include +// user include files +#include "FWCore/Framework/interface/Frameworkfwd.h" +#include "FWCore/Framework/interface/EDProducer.h" +#include "FWCore/Framework/interface/Event.h" +#include "FWCore/Framework/interface/MakerMacros.h" +#include "FWCore/ParameterSet/interface/ParameterSet.h" +#include "FWCore/Framework/interface/ESHandle.h" +#include "FWCore/Framework/interface/EventSetup.h" +#include "FWCore/MessageLogger/interface/MessageLogger.h" + #include "DataFormats/DetId/interface/DetId.h" -#include "Geometry/Records/interface/CaloGeometryRecord.h" +#include "DataFormats/EgammaCandidates/interface/Photon.h" +#include "DataFormats/EgammaCandidates/interface/PhotonFwd.h" +#include "DataFormats/JetReco/interface/PFJetCollection.h" +#include "DataFormats/HcalRecHit/interface/HBHERecHit.h" +#include "DataFormats/HcalRecHit/interface/HFRecHit.h" +#include "DataFormats/HcalRecHit/interface/HORecHit.h" +#include "DataFormats/Common/interface/ValueMap.h" +#include "DataFormats/Common/interface/TriggerResults.h" +#include "DataFormats/HLTReco/interface/TriggerEvent.h" +#include "DataFormats/HLTReco/interface/TriggerObject.h" +#include "DataFormats/ParticleFlowCandidate/interface/PFCandidate.h" +#include "DataFormats/METReco/interface/PFMET.h" +#include "DataFormats/METReco/interface/PFMETCollection.h" +#include "DataFormats/VertexReco/interface/Vertex.h" +#include "DataFormats/VertexReco/interface/VertexFwd.h" #include "DataFormats/GeometryVector/interface/GlobalPoint.h" -using namespace edm; -using namespace std; -using namespace reco; +#include "Geometry/CaloGeometry/interface/CaloGeometry.h" +#include "Geometry/Records/interface/CaloGeometryRecord.h" +#include -//namespace cms -//{ +// +// class declaration +// -AlCaGammaJetProducer::AlCaGammaJetProducer(const edm::ParameterSet& iConfig) -{ - // Take input - - tok_hbhe_= consumes(iConfig.getParameter("hbheInput")); - tok_ho_ = consumes(iConfig.getParameter("hoInput")); - tok_hf_ = consumes(iConfig.getParameter("hfInput")); - - mInputCalo = iConfig.getParameter >("srcCalo"); - ecalLabels_=iConfig.getParameter >("ecalInputs"); - - unsigned nLabels = mInputCalo.size(); - for ( unsigned i=0; i != nLabels; i++ ) - toks_calo_.push_back( consumes( mInputCalo[i] ) ); - - nLabels = ecalLabels_.size(); - for ( unsigned i=0; i != nLabels; i++ ) - toks_ecal_.push_back( consumes( ecalLabels_[i] ) ); - - - tok_inputTrack_ = consumes(iConfig.getUntrackedParameter("inputTrackLabel","generalTracks")); - correctedIslandBarrelSuperClusterCollection_ = iConfig.getParameter("correctedIslandBarrelSuperClusterCollection"); - correctedIslandBarrelSuperClusterProducer_ = iConfig.getParameter("correctedIslandBarrelSuperClusterProducer"); - tok_EBSC_ = consumes( - edm::InputTag(correctedIslandBarrelSuperClusterProducer_, - correctedIslandBarrelSuperClusterCollection_)); - - correctedIslandEndcapSuperClusterCollection_ = iConfig.getParameter("correctedIslandEndcapSuperClusterCollection"); - correctedIslandEndcapSuperClusterProducer_ = iConfig.getParameter("correctedIslandEndcapSuperClusterProducer"); - tok_EESC_ = consumes( - edm::InputTag(correctedIslandEndcapSuperClusterProducer_, - correctedIslandEndcapSuperClusterCollection_)); - - allowMissingInputs_=iConfig.getUntrackedParameter("AllowMissingInputs",true); - - - //register your products - produces("GammaJetTracksCollection"); - produces("GammaJetEcalRecHitCollection"); - produces("GammaJetHBHERecHitCollection"); - produces("GammaJetHORecHitCollection"); - produces("GammaJetHFRecHitCollection"); - produces("GammaJetJetBackToBackCollection"); - produces("GammaJetGammaBackToBackCollection"); +class AlCaGammaJetProducer : public edm::EDProducer { - - +public: + explicit AlCaGammaJetProducer(const edm::ParameterSet&); + ~AlCaGammaJetProducer(); + virtual void beginJob() ; + virtual void produce(edm::Event &, const edm::EventSetup&); + virtual void endJob(); + +private: + bool select (reco::PhotonCollection, reco::PFJetCollection); + + // ----------member data --------------------------- + + edm::InputTag labelPhoton_, labelPFJet_, labelHBHE_, labelHF_, labelHO_, labelTrigger_, labelPFCandidate_, labelVertex_, labelPFMET_, labelGsfEle_, labelRho_, labelConv_, labelBeamSpot_, labelLoosePhot_, labelTightPhot_; + double minPtJet_, minPtPhoton_; + int nAll_, nSelect_; + + edm::EDGetTokenT tok_Photon_; + edm::EDGetTokenT tok_PFJet_; + edm::EDGetTokenT>> tok_HBHE_; + edm::EDGetTokenT>> tok_HF_; + edm::EDGetTokenT>> tok_HO_; + edm::EDGetTokenT tok_TrigRes_; + edm::EDGetTokenT tok_PFCand_; + edm::EDGetTokenT tok_Vertex_; + edm::EDGetTokenT tok_PFMET_; + edm::EDGetTokenT tok_GsfElec_; + edm::EDGetTokenT tok_Rho_; + edm::EDGetTokenT tok_Conv_; + edm::EDGetTokenT tok_BS_; + edm::EDGetTokenT > tok_loosePhoton_; + edm::EDGetTokenT > tok_tightPhoton_; +}; + +AlCaGammaJetProducer::AlCaGammaJetProducer(const edm::ParameterSet& iConfig) : nAll_(0), nSelect_(0) { + // Take input + labelPhoton_ = iConfig.getParameter("PhoInput"); + labelPFJet_ = iConfig.getParameter("PFjetInput"); + labelHBHE_ = iConfig.getParameter("HBHEInput"); + labelHF_ = iConfig.getParameter("HFInput"); + labelHO_ = iConfig.getParameter("HOInput"); + labelTrigger_ = iConfig.getParameter("TriggerResults"); + labelPFCandidate_= iConfig.getParameter("particleFlowInput"); + labelVertex_ = iConfig.getParameter("VertexInput"); + labelPFMET_ = iConfig.getParameter("METInput"); + labelGsfEle_ = iConfig.getParameter("gsfeleInput"); + labelRho_ = iConfig.getParameter("rhoInput"); + labelConv_ = iConfig.getParameter("ConversionsInput"); + labelBeamSpot_ = iConfig.getParameter("BeamSpotInput"); + labelLoosePhot_ = iConfig.getParameter("PhoLoose"); + labelTightPhot_ = iConfig.getParameter("PhoTight"); + minPtJet_ = iConfig.getParameter("MinPtJet"); + minPtPhoton_ = iConfig.getParameter("MinPtPhoton"); + + tok_Photon_ = consumes(labelPhoton_); + tok_PFJet_ = consumes(labelPFJet_); + tok_HBHE_ = consumes>>(labelHBHE_); + tok_HF_ = consumes>>(labelHF_); + tok_HO_ = consumes>>(labelHO_); + tok_TrigRes_= consumes(labelTrigger_); + tok_PFCand_ = consumes(labelPFCandidate_); + tok_Vertex_ = consumes(labelVertex_); + tok_PFMET_ = consumes(labelPFMET_); + tok_loosePhoton_ = consumes >(labelLoosePhot_); + tok_tightPhoton_ = consumes >(labelTightPhot_); + tok_GsfElec_ = consumes(labelGsfEle_); + tok_Rho_ = consumes(labelRho_); + tok_Conv_ = consumes(labelConv_); + tok_BS_ = consumes(labelBeamSpot_); + + // register your products + produces(labelPhoton_.encode()); + produces(labelPFJet_.encode()); + produces>>(labelHBHE_.encode()); + produces>>(labelHF_.encode()); + produces>>(labelHO_.encode()); + produces(labelTrigger_.encode()); + produces>(labelLoosePhot_.encode()); + produces>(labelTightPhot_.encode()); + produces(labelRho_.encode()); + produces(labelPFCandidate_.encode()); + produces(labelVertex_.encode()); + produces(labelPFMET_.encode()); + produces(labelGsfEle_.encode()); + produces(labelConv_.encode()); + produces(labelBeamSpot_.encode()); + } -void AlCaGammaJetProducer::beginJob() -{ + +AlCaGammaJetProducer::~AlCaGammaJetProducer() { } + +void AlCaGammaJetProducer::beginJob() { } + +void AlCaGammaJetProducer::endJob() { + edm::LogInfo("AlcaGammaJet") << "Accepts " << nSelect_ << " events from a total of " << nAll_ << " events"; } -AlCaGammaJetProducer::~AlCaGammaJetProducer() -{ +bool AlCaGammaJetProducer::select (reco::PhotonCollection ph, reco::PFJetCollection jt) { - + if (jt.size()<1) return false; + if (ph.size()<1) return false; + if (((jt.at(0)).pt()) phoHandle; + iEvent.getByToken(tok_Photon_,phoHandle); + if (!phoHandle.isValid()) { + edm::LogWarning("AlCaGammaJet") << "AlCaGammaJetProducer: Error! can't get the product " << labelPhoton_; + return ; + } + const reco::PhotonCollection photon = *(phoHandle.product()); + edm::Handle pfjet; + iEvent.getByToken(tok_PFJet_,pfjet); + if (!pfjet.isValid()) { + edm::LogWarning("AlCaGammaJet") << "AlCaGammaJetProducer: Error! can't get product " << labelPFJet_; + return ; + } + const reco::PFJetCollection pfjets = *(pfjet.product()); -// ------------ method called to produce the data ------------ -void -AlCaGammaJetProducer::produce(edm::Event& iEvent, const edm::EventSetup& iSetup) -{ - using namespace edm; - using namespace std; + edm::Handle pfc; + iEvent.getByToken(tok_PFCand_,pfc); + if (!pfc.isValid()) { + edm::LogWarning("AlCaGammaJet") << "AlCaGammaJetProducer: Error! can't get product " << labelPFCandidate_; + return ; + } + const reco::PFCandidateCollection pfcand = *(pfc.product()); - edm::ESHandle pG; - iSetup.get().get(pG); - geo = pG.product(); + edm::Handle vt; + iEvent.getByToken(tok_Vertex_,vt); + if (!vt.isValid()) { + edm::LogWarning("AlCaGammaJet") << "AlCaGammaJetProducer: Error! can't get product " << labelVertex_; + return ; + } + const reco::VertexCollection vtx = *(vt.product()); -// Produced collections - - std::auto_ptr result (new reco::SuperClusterCollection); //Corrected jets - std::auto_ptr resultjet (new CaloJetCollection); //Corrected jets - std::auto_ptr miniEcalRecHitCollection(new EcalRecHitCollection); - std::auto_ptr miniHBHERecHitCollection(new HBHERecHitCollection); - std::auto_ptr miniHORecHitCollection(new HORecHitCollection); - std::auto_ptr miniHFRecHitCollection(new HFRecHitCollection); - std::auto_ptr outputTColl(new reco::TrackCollection); - - -// Get Corrected supercluster collection - int nclusb = 0; - int ncluse = 0; - reco::SuperClusterCollection::const_iterator maxclusbarrel; - reco::SuperClusterCollection::const_iterator maxclusendcap; - - double vetmax = -100.; - Handle pCorrectedIslandBarrelSuperClusters; - iEvent.getByToken(tok_EBSC_, - pCorrectedIslandBarrelSuperClusters); - if (!pCorrectedIslandBarrelSuperClusters.isValid()) { - // can't find it! - if (!allowMissingInputs_) { - *pCorrectedIslandBarrelSuperClusters; // will throw the proper exception - } - } else { - const reco::SuperClusterCollection* correctedIslandBarrelSuperClusters = pCorrectedIslandBarrelSuperClusters.product(); - - // loop over the super clusters and find the highest - maxclusbarrel = correctedIslandBarrelSuperClusters->begin(); - for(reco::SuperClusterCollection::const_iterator aClus = correctedIslandBarrelSuperClusters->begin(); - aClus != correctedIslandBarrelSuperClusters->end(); aClus++) { - double vet = aClus->energy()/cosh(aClus->eta()); - cout<<" Barrel supercluster " << vet <<" energy "<energy()<<" eta "<eta()<20.) { - if(vet > vetmax) - { - vetmax = vet; - maxclusbarrel = aClus; - nclusb = 1; - } - } - } - + edm::Handle pfmt; + iEvent.getByToken(tok_PFMET_,pfmt); + if (!pfmt.isValid()) { + edm::LogWarning("AlCaGammaJet") << "AlCaGammaJetProducer: Error! can't get product " << labelPFMET_; + return ; } + const reco::PFMETCollection pfmet = *(pfmt.product()); - Handle pCorrectedIslandEndcapSuperClusters; - iEvent.getByToken(tok_EESC_, - pCorrectedIslandEndcapSuperClusters); - if (!pCorrectedIslandEndcapSuperClusters.isValid()) { - // can't find it! - if (!allowMissingInputs_) { - *pCorrectedIslandEndcapSuperClusters; // will throw the proper exception - } - } else { - const reco::SuperClusterCollection* correctedIslandEndcapSuperClusters = pCorrectedIslandEndcapSuperClusters.product(); + edm::Handle > > hbhe; + iEvent.getByToken(tok_HBHE_,hbhe); + if (!hbhe.isValid()) { + edm::LogWarning("AlCaGammaJet") << "AlCaGammaJetProducer: Error! can't get product " << labelHBHE_; + return ; + } + const edm::SortedCollection > Hithbhe = *(hbhe.product()); + + edm::Handle > > ho; + iEvent.getByToken(tok_HO_,ho); + if(!ho.isValid()) { + edm::LogWarning("AlCaGammaJet") << "AlCaGammaJetProducer: Error! can't get product " << labelHO_; + return ; + } + const edm::SortedCollection > Hitho = *(ho.product()); - // loop over the super clusters and find the highest - maxclusendcap = correctedIslandEndcapSuperClusters->end(); - double vetmaxe = vetmax; - for(reco::SuperClusterCollection::const_iterator aClus = correctedIslandEndcapSuperClusters->begin(); - aClus != correctedIslandEndcapSuperClusters->end(); aClus++) { - double vet = aClus->energy()/cosh(aClus->eta()); - // cout<<" Endcap supercluster " << vet <<" energy "<energy()<<" eta "<eta()<20.) { - if(vet > vetmaxe) - { - vetmaxe = vet; - maxclusendcap = aClus; - ncluse = 1; - } - } - } + edm::Handle > > hf; + iEvent.getByToken(tok_HF_,hf); + if(!hf.isValid()) { + edm::LogWarning("AlCaGammaJet") << "AlCaGammaJetProducer: Error! can't get product " << labelHF_; + return ; } - - cout<<" Number of gammas "< > Hithf = *(hf.product()); + + edm::Handle trig; + iEvent.getByToken(tok_TrigRes_,trig); + if (!trig.isValid()) { + edm::LogWarning("AlCaGammaJet") << "AlCaGammaJetProducer: Error! can't get product " << labelTrigger_; + return ; } + const edm::TriggerResults trigres = *(trig.product()); - double phigamma = -100.; - double etagamma = -100.; - if(ncluse == 1) - { - result->push_back(*maxclusendcap); - phigamma = (*maxclusendcap).phi(); - etagamma = (*maxclusendcap).eta(); - - } else - { - result->push_back(*maxclusbarrel); - phigamma = (*maxclusbarrel).phi(); - etagamma = (*maxclusbarrel).eta(); + edm::Handle rh; + iEvent.getByToken(tok_Rho_,rh); + if (!rh.isValid()) { + edm::LogWarning("AlCaGammaJet") << "AlCaGammaJetProducer: Error! can't get product " << labelRho_; + return ; } - -// cout<<" Size of egamma clusters "<size()< gsf; + iEvent.getByToken(tok_GsfElec_,gsf); + if (!gsf.isValid()){ + edm::LogWarning("AlCaGammaJet") << "AlCaGammaJetProducer: Error! can't get product " << labelGsfEle_; + return ; + } + const reco::GsfElectronCollection gsfele = *(gsf.product()); + + edm::Handle con; + iEvent.getByToken(tok_Conv_,con); + if (!con.isValid()){ + edm::LogWarning("AlCaGammaJet") << "AlCaGammaJetProducer: Error! can't get product " << labelConv_; + return ; + } + const reco::ConversionCollection conv = *(con.product()); + + edm::Handle bs; + iEvent.getByToken(tok_BS_,bs); + if (!bs.isValid()){ + edm::LogWarning("AlCaGammaJet") << "AlCaGammaJetProducer: Error! can't get product " << labelBeamSpot_; + return ; + } + const reco::BeamSpot beam = *(bs.product()); + + // declare variables + // copy from standard place, if the event is useful + std::auto_ptr miniPFjetCollection(new reco::PFJetCollection); + std::auto_ptr miniPhotonCollection(new reco::PhotonCollection); + std::auto_ptr miniPFCandCollection(new reco::PFCandidateCollection); + std::auto_ptr miniVtxCollection(new reco::VertexCollection); + std::auto_ptr miniPFMETCollection(new reco::PFMETCollection); + std::auto_ptr>> miniHBHECollection(new edm::SortedCollection>); + std::auto_ptr>> miniHOCollection(new edm::SortedCollection>); + std::auto_ptr>> miniHFCollection(new edm::SortedCollection>); + std::auto_ptr miniGSFeleCollection(new reco::GsfElectronCollection); + std::auto_ptr miniConversionCollection(new reco::ConversionCollection); + + std::auto_ptr miniBeamSpotCollection(new reco::BeamSpot(beam.position(),beam.sigmaZ(), + beam.dxdz(),beam.dydz(),beam.BeamWidthX(), + beam.covariance(),beam.type())); - std::vector >::const_iterator ic; - for (ic=toks_calo_.begin(); ic!=toks_calo_.end(); ic++) { - - edm::Handle jets; - iEvent.getByToken(*ic, jets); - if (!jets.isValid()) { - // can't find it! - if (!allowMissingInputs_) { - *jets; // will throw the proper exception - } - } else { - reco::CaloJetCollection::const_iterator jet = jets->begin (); + std::auto_ptr miniTriggerCollection(new edm::TriggerResults); - // cout<<" Size of jets "<size()< miniRhoCollection(new double); + std::auto_ptr > miniLoosePhoton(new std::vector()); + std::auto_ptr > miniTightPhoton(new std::vector()); - if( jets->size() == 0 ) continue; - int iejet = 0; - int numjet = 0; - - for (; jet != jets->end (); jet++) - { - phijet0 = (*jet).phi(); - etajet0 = (*jet).eta(); - -// Only 3 jets are kept - numjet++; - if(numjet > 3) break; - - cout<<" phi,eta "<< phigamma<<" "<< etagamma<<" "< 4.*atan(1.)) dphi = 8.*atan(1.) - dphi; - double deta = fabs(etagamma-etajet0); - double dr = sqrt(dphi*dphi+deta*deta); - if(dr < 0.5 ) continue; - resultjet->push_back ((*jet)); - - dphi = dphi*180./(4.*atan(1.)); - if( fabs(dphi-180) < 30. ) - { - // cout<<" Jet is found "<clear(); - } - } // Jet collection - - if( resultjet->size() == 0 ) { - - iEvent.put( outputTColl, "GammaJetTracksCollection"); - iEvent.put( miniEcalRecHitCollection, "GammaJetEcalRecHitCollection"); - iEvent.put( miniHBHERecHitCollection, "GammaJetHBHERecHitCollection"); - iEvent.put( miniHORecHitCollection, "GammaJetHORecHitCollection"); - iEvent.put( miniHFRecHitCollection, "GammaJetHFRecHitCollection"); - iEvent.put( result, "GammaJetGammaBackToBackCollection"); - iEvent.put( resultjet, "GammaJetJetBackToBackCollection"); - - return; - } - // cout<<" Accepted event "<size()<<" PHI gamma "<push_back(*pfjetItr); + } - - std::vector >::const_iterator i; - for (i=toks_ecal_.begin(); i!=toks_ecal_.end(); i++) { - edm::Handle ec; - iEvent.getByToken(*i,ec); - if (!ec.isValid()) { - // can't find it! - if (!allowMissingInputs_) { - cout<<" No ECAL input "<getPosition(recHit->detid()); - double phihit = pos.phi(); - double etahit = pos.eta(); - - double dphi = fabs(phigamma - phihit); - if(dphi > 4.*atan(1.)) dphi = 8.*atan(1.) - dphi; - double deta = fabs(etagamma - etahit); - double dr = sqrt(dphi*dphi + deta*deta); - if(dr<1.) miniEcalRecHitCollection->push_back(*recHit); - - dphi = fabs(phijet - phihit); - if(dphi > 4.*atan(1.)) dphi = 8.*atan(1.) - dphi; - deta = fabs(etajet - etahit); - dr = sqrt(dphi*dphi + deta*deta); - if(dr<1.4) miniEcalRecHitCollection->push_back(*recHit); - - } - } + for(reco::PhotonCollection::const_iterator phoItr=photon.begin(); + phoItr!=photon.end(); phoItr++) { + miniPhotonCollection->push_back(*phoItr); } -// cout<<" Ecal is done "<push_back(*pfcItr); + } - edm::Handle hbhe; - iEvent.getByToken(tok_hbhe_,hbhe); - if (!hbhe.isValid()) { - // can't find it! - if (!allowMissingInputs_) { - *hbhe; // will throw the proper exception - } - } else { - const HBHERecHitCollection Hithbhe = *(hbhe.product()); - for(HBHERecHitCollection::const_iterator hbheItr=Hithbhe.begin(); hbheItr!=Hithbhe.end(); hbheItr++) - { - GlobalPoint pos = geo->getPosition(hbheItr->detid()); - double phihit = pos.phi(); - double etahit = pos.eta(); - - double dphi = fabs(phigamma - phihit); - if(dphi > 4.*atan(1.)) dphi = 8.*atan(1.) - dphi; - double deta = fabs(etagamma - etahit); - double dr = sqrt(dphi*dphi + deta*deta); - - - if(dr<1.) miniHBHERecHitCollection->push_back(*hbheItr); - dphi = fabs(phijet - phihit); - if(dphi > 4.*atan(1.)) dphi = 8.*atan(1.) - dphi; - deta = fabs(etajet - etahit); - dr = sqrt(dphi*dphi + deta*deta); - if(dr<1.4) miniHBHERecHitCollection->push_back(*hbheItr); - } - } + for(reco::VertexCollection::const_iterator vtxItr=vtx.begin(); + vtxItr!=vtx.end(); vtxItr++) { + miniVtxCollection->push_back(*vtxItr); + } -// cout<<" HBHE is done "< ho; - iEvent.getByToken(tok_ho_,ho); - if (!ho.isValid()) { - // can't find it! - if (!allowMissingInputs_) { - *ho; // will throw the proper exception - } - } else { - const HORecHitCollection Hitho = *(ho.product()); - for(HORecHitCollection::const_iterator hoItr=Hitho.begin(); hoItr!=Hitho.end(); hoItr++) - { - GlobalPoint pos = geo->getPosition(hoItr->detid()); - double phihit = pos.phi(); - double etahit = pos.eta(); - - double dphi = fabs(phigamma - phihit); - if(dphi > 4.*atan(1.)) dphi = 8.*atan(1.) - dphi; - double deta = fabs(etagamma - etahit); - double dr = sqrt(dphi*dphi + deta*deta); - - if(dr<1.) miniHORecHitCollection->push_back(*hoItr); - dphi = fabs(phijet - phihit); - if(dphi > 4.*atan(1.)) dphi = 8.*atan(1.) - dphi; - deta = fabs(etajet - etahit); - dr = sqrt(dphi*dphi + deta*deta); - if(dr<1.4) miniHORecHitCollection->push_back(*hoItr); - - } - } + for(reco::PFMETCollection::const_iterator pfmetItr=pfmet.begin(); + pfmetItr!=pfmet.end(); pfmetItr++) { + miniPFMETCollection->push_back(*pfmetItr); + } - // cout<<" HO is done "< hf; - iEvent.getByToken(tok_hf_,hf); - if (!hf.isValid()) { - // can't find it! - if (!allowMissingInputs_) { - *hf; // will throw the proper exception - } - } else { - const HFRecHitCollection Hithf = *(hf.product()); - // cout<<" Size of HF collection "<getPosition(hfItr->detid()); - - double phihit = pos.phi(); - double etahit = pos.eta(); - - double dphi = fabs(phigamma - phihit); - if(dphi > 4.*atan(1.)) dphi = 8.*atan(1.) - dphi; - double deta = fabs(etagamma - etahit); - double dr = sqrt(dphi*dphi + deta*deta); - - if(dr<1.) miniHFRecHitCollection->push_back(*hfItr); - dphi = fabs(phijet - phihit); - if(dphi > 4.*atan(1.)) dphi = 8.*atan(1.) - dphi; - deta = fabs(etajet - etahit); - dr = sqrt(dphi*dphi + deta*deta); - - if( dr < 1.4 ) miniHFRecHitCollection->push_back(*hfItr); - } - } + for(edm::SortedCollection >::const_iterator hbheItr=Hithbhe.begin(); + hbheItr!=Hithbhe.end(); hbheItr++) { + miniHBHECollection->push_back(*hbheItr); + } + + for(edm::SortedCollection >::const_iterator hoItr=Hitho.begin(); + hoItr!=Hitho.end(); hoItr++) { + miniHOCollection->push_back(*hoItr); + } - // cout<<" Size of mini HF collection "<size()< >::const_iterator hfItr=Hithf.begin(); + hfItr!=Hithf.end(); hfItr++) { + miniHFCollection->push_back(*hfItr); + } + + for(reco::GsfElectronCollection::const_iterator gsfItr=gsfele.begin(); + gsfItr!=gsfele.end(); gsfItr++) { + miniGSFeleCollection->push_back(*gsfItr); + } + + for(reco::ConversionCollection::const_iterator convItr=conv.begin(); + convItr!=conv.end(); convItr++) { + miniConversionCollection->push_back(*convItr); + } -// Track Collection - edm::Handle trackCollection; - iEvent.getByToken(tok_inputTrack_,trackCollection); - if (!trackCollection.isValid()) { - // can't find it! - if (!allowMissingInputs_) { - *trackCollection; // will throw the proper exception + *miniTriggerCollection = trigres; + *miniRhoCollection = rho_val; + + edm::Handle > loosePhotonQual; + iEvent.getByToken(tok_loosePhoton_, loosePhotonQual); + edm::Handle > tightPhotonQual; + iEvent.getByToken(tok_tightPhoton_, tightPhotonQual); + if (loosePhotonQual.isValid() && tightPhotonQual.isValid()) { + miniLoosePhoton->reserve(miniPhotonCollection->size()); + miniTightPhoton->reserve(miniPhotonCollection->size()); + for (int iPho=0; iPhosize()); ++iPho) { + edm::Ref photonRef(phoHandle,iPho); + if (!photonRef) { + std::cout << "failed ref" << std::endl; + miniLoosePhoton->push_back(-1); + miniTightPhoton->push_back(-1); + } + else { + miniLoosePhoton->push_back((*loosePhotonQual)[photonRef]); + miniTightPhoton->push_back((*tightPhotonQual)[photonRef]); } - } else { - const reco::TrackCollection tC = *(trackCollection.product()); - - //Create empty output collections - - - for (reco::TrackCollection::const_iterator track=tC.begin(); track!=tC.end(); track++) - { - - double deta = track->momentum().eta() - etagamma; - - double dphi = fabs(track->momentum().phi() - phigamma); - - if (dphi > atan(1.)*4.) dphi = 8.*atan(1.) - dphi; - double ddir1 = sqrt(deta*deta+dphi*dphi); - - - - deta = track->momentum().eta() - etajet; - dphi = fabs(track->momentum().phi() - phijet); - if (dphi > atan(1.)*4.) dphi = 8.*atan(1.) - dphi; - double ddir2 = sqrt(deta*deta+dphi*dphi); - - if( ddir1 < 1.4 || ddir2 < 1.4) - { - outputTColl->push_back(*track); - } - } } - - //Put selected information in the event - - iEvent.put( outputTColl, "GammaJetTracksCollection"); - iEvent.put( miniEcalRecHitCollection, "GammaJetEcalRecHitCollection"); - iEvent.put( miniHBHERecHitCollection, "GammaJetHBHERecHitCollection"); - iEvent.put( miniHORecHitCollection, "GammaJetHORecHitCollection"); - iEvent.put( miniHFRecHitCollection, "GammaJetHFRecHitCollection"); - iEvent.put( result, "GammaJetGammaBackToBackCollection"); - iEvent.put( resultjet, "GammaJetJetBackToBackCollection"); + } + } + + //Put them in the event + iEvent.put( miniPhotonCollection, labelPhoton_.encode()); + iEvent.put( miniPFjetCollection, labelPFJet_.encode()); + iEvent.put( miniHBHECollection, labelHBHE_.encode()); + iEvent.put( miniHFCollection, labelHF_.encode()); + iEvent.put( miniHOCollection, labelHO_.encode()); + iEvent.put( miniTriggerCollection, labelTrigger_.encode()); + iEvent.put( miniPFCandCollection, labelPFCandidate_.encode()); + iEvent.put( miniVtxCollection, labelVertex_.encode()); + iEvent.put( miniPFMETCollection, labelPFMET_.encode()); + iEvent.put( miniGSFeleCollection, labelGsfEle_.encode()); + iEvent.put( miniRhoCollection, labelRho_.encode()); + iEvent.put( miniConversionCollection, labelConv_.encode()); + iEvent.put( miniBeamSpotCollection, labelBeamSpot_.encode()); + iEvent.put( miniLoosePhoton, labelLoosePhot_.encode()); + iEvent.put( miniTightPhoton, labelTightPhot_.encode()); + + return; + } -//} + +DEFINE_FWK_MODULE(AlCaGammaJetProducer); diff --git a/Calibration/HcalAlCaRecoProducers/src/AlCaHBHEMuonProducer.cc b/Calibration/HcalAlCaRecoProducers/src/AlCaHBHEMuonProducer.cc new file mode 100644 index 0000000000000..9d4b5fbf6b8aa --- /dev/null +++ b/Calibration/HcalAlCaRecoProducers/src/AlCaHBHEMuonProducer.cc @@ -0,0 +1,247 @@ +// -*- C++ -*- + + +// system include files +#include +#include +#include +#include +#include +#include +#include +#include + +// user include files +#include "FWCore/Framework/interface/Frameworkfwd.h" +#include "FWCore/Framework/interface/EDProducer.h" +#include "FWCore/Framework/interface/Event.h" +#include "FWCore/Framework/interface/ESHandle.h" +#include "FWCore/Framework/interface/EventSetup.h" +#include "FWCore/Framework/interface/Run.h" +#include "FWCore/MessageLogger/interface/MessageLogger.h" +#include "FWCore/ParameterSet/interface/ParameterSet.h" +#include "FWCore/ParameterSet/interface/ConfigurationDescriptions.h" +#include "FWCore/Utilities/interface/Exception.h" + +#include "DataFormats/BeamSpot/interface/BeamSpot.h" +#include "DataFormats/Common/interface/Handle.h" +#include "DataFormats/Common/interface/Ref.h" +#include "DataFormats/Common/interface/TriggerResults.h" +#include "DataFormats/EcalRecHit/interface/EcalRecHitCollections.h" +#include "DataFormats/HcalRecHit/interface/HcalRecHitCollections.h" +#include "DataFormats/MuonReco/interface/Muon.h" +#include "DataFormats/MuonReco/interface/MuonFwd.h" +#include "DataFormats/VertexReco/interface/VertexFwd.h" +#include "DataFormats/VertexReco/interface/Vertex.h" + +// +// class declaration +// + +class AlCaHBHEMuonProducer : public edm::EDProducer { +public: + explicit AlCaHBHEMuonProducer(const edm::ParameterSet&); + ~AlCaHBHEMuonProducer(); + + virtual void produce(edm::Event &, const edm::EventSetup&); + +private: + + virtual void beginJob() ; + virtual void endJob() ; + virtual void beginRun(edm::Run const&, edm::EventSetup const&); + virtual void endRun(edm::Run const&, edm::EventSetup const&); + bool select(const reco::MuonCollection &); + + // ----------member data --------------------------- + int nRun, nAll, nGood; + edm::InputTag labelTriggerResults_, labelBS_, labelVtx_; + edm::InputTag labelEB_, labelEE_, labelHBHE_, labelMuon_; + double pMuonMin_; + + edm::EDGetTokenT tok_trigRes_; + edm::EDGetTokenT tok_BS_; + edm::EDGetTokenT tok_Vtx_; + edm::EDGetTokenT tok_EB_; + edm::EDGetTokenT tok_EE_; + edm::EDGetTokenT tok_HBHE_; + edm::EDGetTokenT tok_Muon_; +}; + + +AlCaHBHEMuonProducer::AlCaHBHEMuonProducer(const edm::ParameterSet& iConfig) : + nRun(0), nAll(0), nGood(0) { + //Get the run parameters + labelTriggerResults_ = iConfig.getParameter("TriggerResultLabel"); + labelBS_ = iConfig.getParameter("BeamSpotLabel"); + labelVtx_ = iConfig.getParameter("VertexLabel"); + labelEB_ = iConfig.getParameter("EBRecHitLabel"); + labelEE_ = iConfig.getParameter("EERecHitLabel"); + labelHBHE_ = iConfig.getParameter("HBHERecHitLabel"); + labelMuon_ = iConfig.getParameter("MuonLabel"); + pMuonMin_ = iConfig.getParameter("MinimumMuonP"); + + // define tokens for access + tok_trigRes_ = consumes(labelTriggerResults_); + tok_Vtx_ = consumes(labelVtx_); + tok_BS_ = consumes(labelBS_); + tok_EB_ = consumes(labelEB_); + tok_EE_ = consumes(labelEE_); + tok_HBHE_ = consumes(labelHBHE_); + tok_Muon_ = consumes(labelMuon_); + + edm::LogInfo("HcalIsoTrack") <<"Parameters read from config file \n" + <<"\t minP of muon " << pMuonMin_ + <<"\t input labels " << labelTriggerResults_ + <<" " << labelBS_ << " " << labelVtx_ + <<" " << labelEB_ << " " << labelEE_ + <<" " << labelHBHE_ << " " << labelMuon_; + + //saves the following collections + produces(labelTriggerResults_.encode()); + produces(labelBS_.encode()); + produces(labelVtx_.encode()); + produces(labelEB_.encode()); + produces(labelEE_.encode()); + produces(labelHBHE_.encode()); + produces(labelMuon_.encode()); + +} + +AlCaHBHEMuonProducer::~AlCaHBHEMuonProducer() { } + +void AlCaHBHEMuonProducer::produce(edm::Event& iEvent, const edm::EventSetup& iSetup) { + + nAll++; + LogDebug("HcalHBHEMuon") << "Run " << iEvent.id().run() << " Event " + << iEvent.id().event() << " Luminosity " + << iEvent.luminosityBlock() << " Bunch " + << iEvent.bunchCrossing(); + + //Step1: Get all the relevant containers + edm::Handle triggerResults; + iEvent.getByToken(tok_trigRes_, triggerResults); + if (!triggerResults.isValid()) { + edm::LogWarning("HcalHBHEMuon") << "AlCaHBHEMuonProducer: Error! can't get product " << labelTriggerResults_; + return; + } + const edm::TriggerResults trigres = *(triggerResults.product()); + + edm::Handle bmspot; + iEvent.getByToken(tok_BS_, bmspot); + if (!bmspot.isValid()){ + edm::LogWarning("HcalHBHEMuon") << "AlCaHBHEMuonProducer: Error! can't get product " << labelBS_; + return; + } + const reco::BeamSpot beam = *(bmspot.product()); + + edm::Handle vt; + iEvent.getByToken(tok_Vtx_, vt); + if (!vt.isValid()) { + edm::LogWarning("HcalHBHEMuon") << "AlCaHBHEMuonProducer: Error! can't get product " << labelVtx_; + return ; + } + const reco::VertexCollection vtx = *(vt.product()); + + edm::Handle barrelRecHitsHandle; + iEvent.getByToken(tok_EB_, barrelRecHitsHandle); + if (!barrelRecHitsHandle.isValid()) { + edm::LogWarning("HcalHBHEMuon") << "AlCaHBHEMuonProducer: Error! can't get product " << labelEB_; + return ; + } + const EcalRecHitCollection ebcoll = *(barrelRecHitsHandle.product()); + + edm::Handle endcapRecHitsHandle; + iEvent.getByToken(tok_EE_, endcapRecHitsHandle); + if (!endcapRecHitsHandle.isValid()) { + edm::LogWarning("HcalHBHEMuon") << "AlCaHBHEMuonProducer: Error! can't get product " << labelEE_; + return ; + } + const EcalRecHitCollection eecoll = *(endcapRecHitsHandle.product()); + + edm::Handle hbhe; + iEvent.getByToken(tok_HBHE_, hbhe); + if (!hbhe.isValid()) { + edm::LogWarning("HcalHBHEMuon") << "AlCaHBHEMuonProducer: Error! can't get product " << labelHBHE_; + return ; + } + const HBHERecHitCollection hbhecoll = *(hbhe.product()); + + edm::Handle muonhandle; + iEvent.getByToken(tok_Muon_, muonhandle); + if (!muonhandle.isValid()) { + edm::LogWarning("HcalHBHEMuon") << "AlCaHBHEMuonProducer: Error! can't get product " << labelMuon_; + return ; + } + const reco::MuonCollection muons = *(muonhandle.product()); + + LogDebug("HcalHBHEMuon") << "Has obtained all the collections"; + + //For accepted events + bool accept = select(muons); + if (accept) { + nGood++; + + std::auto_ptr outputTriggerResults(new edm::TriggerResults); + *outputTriggerResults = trigres; + + std::auto_ptr outputBeamSpot(new reco::BeamSpot(beam.position(),beam.sigmaZ(), + beam.dxdz(),beam.dydz(),beam.BeamWidthX(), + beam.covariance(),beam.type())); + + std::auto_ptr outputVColl(new reco::VertexCollection); + for (reco::VertexCollection::const_iterator vtr=vtx.begin(); vtr!=vtx.end(); ++vtr) + outputVColl->push_back(*vtr); + + std::auto_ptr outputEBColl(new EBRecHitCollection); + for (edm::SortedCollection::const_iterator ehit=ebcoll.begin(); ehit!=ebcoll.end(); ++ehit) + outputEBColl->push_back(*ehit); + + std::auto_ptr outputEEColl(new EERecHitCollection); + for (edm::SortedCollection::const_iterator ehit=eecoll.begin(); ehit!=eecoll.end(); ++ehit) + outputEEColl->push_back(*ehit); + + std::auto_ptr outputHBHEColl(new HBHERecHitCollection); + for (std::vector::const_iterator hhit=hbhecoll.begin(); hhit!=hbhecoll.end(); ++hhit) + outputHBHEColl->push_back(*hhit); + + + std::auto_ptr outputMColl(new reco::MuonCollection); + for (reco::MuonCollection::const_iterator muon=muons.begin(); muon!=muons.end(); ++muon) + outputMColl->push_back(*muon); + + iEvent.put(outputTriggerResults, labelTriggerResults_.encode()); + iEvent.put(outputBeamSpot, labelBS_.encode()); + iEvent.put(outputVColl, labelVtx_.encode()); + iEvent.put(outputEBColl, labelEB_.encode()); + iEvent.put(outputEEColl, labelEE_.encode()); + iEvent.put(outputHBHEColl, labelHBHE_.encode()); + iEvent.put(outputMColl, labelMuon_.encode()); + } +} + +void AlCaHBHEMuonProducer::beginJob() { } + +void AlCaHBHEMuonProducer::endJob() { + edm::LogInfo("HcalHBHEMuon") << "Finds " << nGood << " good tracks in " + << nAll << " events from " << nRun << " runs"; +} + +void AlCaHBHEMuonProducer::beginRun(edm::Run const& iRun, edm::EventSetup const& iSetup) { + edm::LogInfo("HcalHBHEMuon") << "Run[" << nRun << "] " << iRun.run(); +} + +void AlCaHBHEMuonProducer::endRun(edm::Run const& iRun, edm::EventSetup const&) { + nRun++; + edm::LogInfo("HcalHBHEMuon") << "endRun[" << nRun << "] " << iRun.run(); +} + +bool AlCaHBHEMuonProducer::select(const reco::MuonCollection & muons) { + + bool ok = (muons.size() > 0) ? (muons[0].p() > pMuonMin_) : false; + return ok; +} + +#include "FWCore/Framework/interface/MakerMacros.h" + +DEFINE_FWK_MODULE(AlCaHBHEMuonProducer); diff --git a/Calibration/HcalAlCaRecoProducers/src/AlCaIsoTracksProducer.cc b/Calibration/HcalAlCaRecoProducers/src/AlCaIsoTracksProducer.cc index 3cbd5557fd503..84f0bae8cdf26 100644 --- a/Calibration/HcalAlCaRecoProducers/src/AlCaIsoTracksProducer.cc +++ b/Calibration/HcalAlCaRecoProducers/src/AlCaIsoTracksProducer.cc @@ -1,206 +1,206 @@ +// -*- C++ -*- + + +// system include files +#include +#include +#include +#include +#include +#include +#include +#include + +// user include files +#include "FWCore/Framework/interface/Frameworkfwd.h" +#include "FWCore/Framework/interface/EDProducer.h" +#include "FWCore/Framework/interface/Event.h" #include "FWCore/Framework/interface/ESHandle.h" #include "FWCore/Framework/interface/EventSetup.h" -#include "Calibration/HcalAlCaRecoProducers/interface/AlCaIsoTracksProducer.h" #include "FWCore/MessageLogger/interface/MessageLogger.h" -#include "Geometry/Records/interface/CaloGeometryRecord.h" -#include "Geometry/CaloGeometry/interface/CaloGeometry.h" -#include "Geometry/CaloGeometry/interface/CaloSubdetectorGeometry.h" -#include "Geometry/CaloGeometry/interface/CaloCellGeometry.h" -#include "DataFormats/EcalDetId/interface/EcalSubdetector.h" -#include "DataFormats/HcalDetId/interface/HcalSubdetector.h" -#include "DataFormats/GeometrySurface/interface/Cylinder.h" -#include "DataFormats/GeometrySurface/interface/Plane.h" -#include "Geometry/CommonDetUnit/interface/GeomDetUnit.h" -#include "MagneticField/Engine/interface/MagneticField.h" -#include "MagneticField/Records/interface/IdealMagneticFieldRecord.h" -#include "TrackPropagation/SteppingHelixPropagator/interface/SteppingHelixPropagator.h" - -#include "DataFormats/HcalRecHit/interface/HcalRecHitCollections.h" -#include "DataFormats/EcalRecHit/interface/EcalRecHitCollections.h" +#include "FWCore/ParameterSet/interface/ParameterSet.h" +#include "FWCore/ParameterSet/interface/ConfigurationDescriptions.h" +#include "FWCore/Common/interface/TriggerNames.h" #include "FWCore/Utilities/interface/Exception.h" -#include "Geometry/CaloTopology/interface/EcalPreshowerTopology.h" - -#include "DataFormats/TrackReco/interface/TrackExtra.h" -#include "DataFormats/TrackReco/interface/TrackExtraFwd.h" -#include "RecoTracker/TrackProducer/interface/TrackProducerBase.h" - -#include "DataFormats/HcalIsolatedTrack/interface/IsolatedPixelTrackCandidate.h" -#include "DataFormats/HcalIsolatedTrack/interface/IsolatedPixelTrackCandidateFwd.h" - +#include "DataFormats/Common/interface/Handle.h" +#include "DataFormats/Common/interface/Ref.h" +#include "DataFormats/DetId/interface/DetId.h" +#include "DataFormats/EcalDetId/interface/EcalSubdetector.h" #include "DataFormats/EcalDetId/interface/EBDetId.h" #include "DataFormats/EcalDetId/interface/EEDetId.h" - -#include "Math/GenVector/VectorUtil.h" -#include "Math/GenVector/PxPyPzE4D.h" - +#include "DataFormats/EcalRecHit/interface/EcalRecHitCollections.h" +#include "DataFormats/HcalDetId/interface/HcalSubdetector.h" +#include "DataFormats/HcalDetId/interface/HcalDetId.h" +#include "DataFormats/HcalRecHit/interface/HcalRecHitCollections.h" +#include "DataFormats/HcalIsolatedTrack/interface/HcalIsolatedTrackCandidate.h" +#include "DataFormats/HLTReco/interface/TriggerEvent.h" +#include "DataFormats/HLTReco/interface/TriggerFilterObjectWithRefs.h" #include "DataFormats/L1Trigger/interface/L1JetParticleFwd.h" #include "DataFormats/L1Trigger/interface/L1JetParticle.h" - #include "DataFormats/Provenance/interface/ProductID.h" +#include "DataFormats/TrackReco/interface/Track.h" +#include "DataFormats/TrackReco/interface/TrackFwd.h" +#include "DataFormats/TrackReco/interface/TrackExtra.h" +#include "DataFormats/TrackReco/interface/TrackExtraFwd.h" +#include "DataFormats/TrackReco/interface/HitPattern.h" +#include "DataFormats/TrackReco/interface/TrackBase.h" +#include "DataFormats/VertexReco/interface/VertexFwd.h" +#include "DataFormats/VertexReco/interface/Vertex.h" +#include "DataFormats/BeamSpot/interface/BeamSpot.h" +#include "DataFormats/Common/interface/TriggerResults.h" -#include "Calibration/HcalAlCaRecoProducers/plugins/ConeDefinition.h" - -#include - -double getDistInCM(double eta1, double phi1, double eta2, double phi2) -{ - double dR, Rec; - double theta1=2*atan(exp(-eta1)); - double theta2=2*atan(exp(-eta2)); - if (fabs(eta1)<1.479) Rec=129; //radius of ECAL barrel - else Rec=tan(theta1)*317; //distance from IP to ECAL endcap - - //|vect| times tg of acos(scalar product) - double angle=acos((sin(theta1)*sin(theta2)*(sin(phi1)*sin(phi2)+cos(phi1)*cos(phi2))+cos(theta1)*cos(theta2))); - if (angleacos(-1)) dphi = 2*acos(-1)-dphi; - double dr = sqrt(dphi*dphi + std::pow(eta1-eta2,2)); - return dr; -} - -bool checkHLTMatch(edm::Event& iEvent, edm::EDGetTokenT &hltToken, std::vector hltFilterTag_, double eta, double phi, double hltMatchingCone_) -{ - bool match =false; - double minDDD=1000; - - edm::Handle trEv; - iEvent.getByToken(hltToken,trEv); - const trigger::TriggerObjectCollection& TOCol(trEv->getObjects()); - - trigger::Keys KEYS; - const trigger::size_type nFilt(trEv->sizeFilters()); - for (trigger::size_type iFilt=0; iFilt!=nFilt; iFilt++) - { - for (unsigned l=0; lfilterTag(iFilt).label()).substr(0,27)==hltFilterTag_[l]) - { - KEYS=trEv->filterKeys(iFilt); - } - } - } - trigger::size_type nReg=KEYS.size(); - for (trigger::size_type iReg=0; iReghltMatchingCone_) match=false; - else match=true; - - return match; -} - -std::pair getL1triggerDirection(edm::Event& iEvent, edm::EDGetTokenT &hltToken, std::string l1FilterTag_) -{ - edm::Handle trEv; - iEvent.getByToken(hltToken,trEv); - const trigger::TriggerObjectCollection& TOCol(trEv->getObjects()); - - trigger::Keys KEYS; - const trigger::size_type nFilt(trEv->sizeFilters()); - for (trigger::size_type iFilt=0; iFilt!=nFilt; iFilt++) - { - if ((trEv->filterTag(iFilt).label()).substr(0,14)==l1FilterTag_) KEYS=trEv->filterKeys(iFilt); - } - trigger::size_type nReg=KEYS.size(); - double etaTrig=-10000; - double phiTrig=-10000; - double ptMax=0; - for (trigger::size_type iReg=0; iRegptMax) - { - etaTrig=TObj.eta(); - phiTrig=TObj.phi(); - ptMax=TObj.pt(); - } - } - return std::pair(etaTrig,phiTrig); -} - +#include "HLTrigger/HLTcore/interface/HLTConfigProvider.h" -AlCaIsoTracksProducer::AlCaIsoTracksProducer(const edm::ParameterSet& iConfig) -{ - - tok_track_ = consumes(iConfig.getParameter("InputTracksLabel")); +#include "Calibration/IsolatedParticles/interface/CaloPropagateTrack.h" +#include "Calibration/IsolatedParticles/interface/ChargeIsolation.h" +#include "Calibration/IsolatedParticles/interface/eCone.h" +#include "Calibration/IsolatedParticles/interface/TrackSelection.h" - tok_ho_ = consumes(iConfig.getParameter("HOInput")); +#include "MagneticField/Engine/interface/MagneticField.h" +#include "MagneticField/Records/interface/IdealMagneticFieldRecord.h" +#include "Geometry/CaloGeometry/interface/CaloGeometry.h" +#include "Geometry/CaloGeometry/interface/CaloSubdetectorGeometry.h" +#include "Geometry/CaloEventSetup/interface/CaloTopologyRecord.h" +#include "Geometry/CaloTopology/interface/CaloSubdetectorTopology.h" +#include "Geometry/CaloTopology/interface/HcalTopology.h" +#include "Geometry/CaloTopology/interface/CaloTopology.h" +#include "Geometry/CaloTopology/interface/EcalTrigTowerConstituentsMap.h" +#include "Geometry/Records/interface/CaloGeometryRecord.h" +#include "CondFormats/DataRecord/interface/EcalChannelStatusRcd.h" +#include "RecoLocalCalo/EcalRecAlgos/interface/EcalSeverityLevelAlgo.h" +#include "RecoLocalCalo/EcalRecAlgos/interface/EcalSeverityLevelAlgoRcd.h" - ecalLabels_=iConfig.getParameter >("ECALInputs"); - const unsigned nLabels = ecalLabels_.size(); - for ( unsigned i=0; i != nLabels; i++ ) - toks_ecal_.push_back( consumes(ecalLabels_[i]) ); - tok_ps_ = consumes(edm::InputTag("ecalPreshowerRecHit","EcalRecHitsES")); +// +// class declaration +// - tok_hbhe_ = consumes(iConfig.getParameter("HBHEInput")); - - m_dvCut = iConfig.getParameter("vtxCut"); - m_ddirCut = iConfig.getParameter("RIsolAtHCALSurface"); - useConeCorr_=iConfig.getParameter("UseLowPtConeCorrection"); - m_pCut = iConfig.getParameter("MinTrackP"); - m_ptCut = iConfig.getParameter("MinTrackPt"); - m_ecalCut = iConfig.getUntrackedParameter("NeutralIsolCut",8.); - - taECALCone_=iConfig.getUntrackedParameter("TrackAssociatorECALCone",0.5); - taHCALCone_=iConfig.getUntrackedParameter("TrackAssociatorHCALCone",1.0); - - skipNeutrals_=iConfig.getUntrackedParameter("SkipNeutralIsoCheck",false); - - nHitsMinCore_=iConfig.getParameter("MinNumberOfHitsCoreTrack"); - nHitsMinIso_=iConfig.getParameter("MinNumberOfHitsInConeTracks"); - - isolE_ = iConfig.getParameter("MaxNearbyTrackEnergy"); - etaMax_= iConfig.getParameter("MaxTrackEta"); - cluRad_ = iConfig.getParameter("ECALClusterRadius"); - ringOutRad_ = iConfig.getParameter("ECALRingOuterRadius"); - ringInnRad_=iConfig.getParameter("ECALRingInnerRadius"); - - useECALCluMatrix_=iConfig.getParameter("ClusterECALasMatrix"); - matrixSize_=iConfig.getParameter("ECALMatrixFullSize"); - - checkHLTMatch_=iConfig.getParameter("CheckHLTMatch"); - tok_hlt_ = consumes(iConfig.getParameter("hltTriggerEventLabel")); - hltFiltTag_=iConfig.getParameter >("hltL3FilterLabels"); - hltMatchingCone_=iConfig.getParameter("hltMatchingCone"); - l1FilterTag_=iConfig.getParameter("l1FilterLabel"); - l1jetVetoCone_=iConfig.getParameter("l1JetVetoCone"); +class AlCaIsoTracksProducer : public edm::EDProducer { +public: + explicit AlCaIsoTracksProducer(const edm::ParameterSet&); + ~AlCaIsoTracksProducer(); - ////////// -// -// Parameters for track associator =========================== -// - edm::ParameterSet parameters = iConfig.getParameter("TrackAssociatorParameters"); - edm::ConsumesCollector iC = consumesCollector(); - parameters_.loadParameters( parameters, iC ); - trackAssociator_.useDefaultPropagator(); -// =============================================================== + virtual void produce(edm::Event &, const edm::EventSetup&); + +private: + + virtual void beginJob() ; + virtual void endJob() ; + virtual void beginRun(edm::Run const&, edm::EventSetup const&); + virtual void endRun(edm::Run const&, edm::EventSetup const&); + reco::HcalIsolatedTrackCandidateCollection* select(edm::Handle& triggerResults, const std::vector & triggerNames_, edm::Handle& trkCollection, math::XYZPoint& leadPV,edm::Handle& barrelRecHitsHandle, edm::Handle& endcapRecHitsHandle, edm::Handle& hbhe); + void setPtEtaPhi(std::vector< edm::Ref >& objref, double &ptL1, double &etaL1, double &phiL1); + + // ----------member data --------------------------- + HLTConfigProvider hltConfig_; + std::vector trigNames, HLTNames; + std::vector trigKount, trigPass; + spr::trackSelectionParameters selectionParameters; + std::string theTrackQuality, processName; + std::string l1Filter, l2Filter, l3Filter; + double a_mipR, a_coneR, a_charIsoR; + double pTrackMin_, eEcalMax_, eIsolation_; + int nRun, nAll, nGood; + edm::InputTag labelTriggerEvent_, labelTriggerResults_, labelBS_; + edm::InputTag labelGenTrack_, labelRecVtx_, labelHltGT_; + edm::InputTag labelEB_, labelEE_, labelHBHE_; + const MagneticField *bField; + const CaloGeometry *geo; + double ptL1, etaL1, phiL1; + + edm::EDGetTokenT tok_hltGT_; + edm::EDGetTokenT tok_trigEvt_; + edm::EDGetTokenT tok_trigRes_; + edm::EDGetTokenT tok_genTrack_; + edm::EDGetTokenT tok_recVtx_; + edm::EDGetTokenT tok_bs_; + edm::EDGetTokenT tok_EB_; + edm::EDGetTokenT tok_EE_; + edm::EDGetTokenT tok_hbhe_; +}; + + +AlCaIsoTracksProducer::AlCaIsoTracksProducer(const edm::ParameterSet& iConfig) : + nRun(0), nAll(0), nGood(0) { + //Get the run parameters + trigNames = iConfig.getParameter >("Triggers"); + theTrackQuality = iConfig.getParameter("TrackQuality"); + processName = iConfig.getParameter("ProcessName"); + l1Filter = iConfig.getParameter("L1Filter"); + l2Filter = iConfig.getParameter("L2Filter"); + l3Filter = iConfig.getParameter("L3Filter"); + selectionParameters.minPt = iConfig.getParameter("MinTrackPt"); + selectionParameters.minQuality = reco::TrackBase::qualityByName(theTrackQuality); + selectionParameters.maxDxyPV = iConfig.getParameter("MaxDxyPV"); + selectionParameters.maxDzPV = iConfig.getParameter("MaxDzPV"); + selectionParameters.maxChi2 = iConfig.getParameter("MaxChi2"); + selectionParameters.maxDpOverP = iConfig.getParameter("MaxDpOverP"); + selectionParameters.minOuterHit = iConfig.getParameter("MinOuterHit"); + selectionParameters.minLayerCrossed = iConfig.getParameter("MinLayerCrossed"); + selectionParameters.maxInMiss = iConfig.getParameter("MaxInMiss"); + selectionParameters.maxOutMiss = iConfig.getParameter("MaxOutMiss"); + a_coneR = iConfig.getParameter("ConeRadius"); + a_charIsoR = a_coneR + 28.9; + a_mipR = iConfig.getParameter("ConeRadiusMIP"); + pTrackMin_ = iConfig.getParameter("MinimumTrackP"); + eEcalMax_ = iConfig.getParameter("MaximumEcalEnergy"); + eIsolation_ = iConfig.getParameter("IsolationEnergy"); + labelGenTrack_ = iConfig.getParameter("TrackLabel"); + labelRecVtx_ = iConfig.getParameter("VertexLabel"); + labelBS_ = iConfig.getParameter("BeamSpotLabel"); + labelEB_ = iConfig.getParameter("EBRecHitLabel"); + labelEE_ = iConfig.getParameter("EERecHitLabel"); + labelHBHE_ = iConfig.getParameter("HBHERecHitLabel"); + labelHltGT_ = iConfig.getParameter("L1GTSeedLabel"); + labelTriggerEvent_ = iConfig.getParameter("TriggerEventLabel"); + labelTriggerResults_ = iConfig.getParameter("TriggerResultLabel"); + + // define tokens for access + tok_hltGT_ = consumes(labelHltGT_); + tok_trigEvt_ = consumes(labelTriggerEvent_); + tok_trigRes_ = consumes(labelTriggerResults_); + tok_genTrack_ = consumes(labelGenTrack_); + tok_recVtx_ = consumes(labelRecVtx_); + tok_bs_ = consumes(labelBS_); + tok_EB_ = consumes(labelEB_); + tok_EE_ = consumes(labelEE_); + tok_hbhe_ = consumes(labelHBHE_); + + edm::LogInfo("HcalIsoTrack") <<"Parameters read from config file \n" + <<"\t minPt " << selectionParameters.minPt + <<"\t theTrackQuality " << theTrackQuality + <<"\t minQuality " << selectionParameters.minQuality + <<"\t maxDxyPV " << selectionParameters.maxDxyPV + <<"\t maxDzPV " << selectionParameters.maxDzPV + <<"\t maxChi2 " << selectionParameters.maxChi2 + <<"\t maxDpOverP " << selectionParameters.maxDpOverP + <<"\t minOuterHit " << selectionParameters.minOuterHit + <<"\t minLayerCrossed " << selectionParameters.minLayerCrossed + <<"\t maxInMiss " << selectionParameters.maxInMiss + <<"\t maxOutMiss " << selectionParameters.maxOutMiss + <<"\t a_coneR " << a_coneR + <<"\t a_charIsoR " << a_charIsoR + <<"\t a_mipR " << a_mipR + <<"\t pTrackMin " << pTrackMin_ + <<"\t eEcalMax " << eEcalMax_ + <<"\t eIsolation " << eIsolation_; + edm::LogInfo("HcalIsoTrack") << "Process " << processName << " L1Filter:" + << l1Filter << " L2Filter:" << l2Filter + << " L3Filter:" << l3Filter; + for (unsigned int k=0; k dummy(trigNames.size(),0); + trigKount = trigPass = dummy; //create also IsolatedPixelTrackCandidateCollection which contains isolation info and reference to primary track - produces("HcalIsolatedTrackCollection"); - - produces("IsoTrackTracksCollection"); - produces("IsoTrackExtraTracksCollection"); - - produces("IsoTrackEcalRecHitCollection"); - produces("IsoTrackPSEcalRecHitCollection"); - - produces("IsoTrackHBHERecHitCollection"); - produces("IsoTrackHORecHitCollection"); + produces("HcalIsolatedTrackCollection"); + produces(labelGenTrack_.encode()); + produces(labelRecVtx_.encode()); + produces(labelEB_.encode()); + produces(labelEE_.encode()); + produces(labelHBHE_.encode()); } @@ -208,354 +208,274 @@ AlCaIsoTracksProducer::AlCaIsoTracksProducer(const edm::ParameterSet& iConfig) AlCaIsoTracksProducer::~AlCaIsoTracksProducer() { } -void AlCaIsoTracksProducer::produce(edm::Event& iEvent, const edm::EventSetup& iSetup) -{ - std::auto_ptr outputHcalIsoTrackColl(new reco::IsolatedPixelTrackCandidateCollection); - std::auto_ptr outputTColl(new reco::TrackCollection); - std::auto_ptr outputExTColl(new reco::TrackExtraCollection); - - reco::TrackExtraRefProd rTrackExtras = iEvent.getRefBeforePut("IsoTrackExtraTracksCollection"); - std::auto_ptr outputEColl(new EcalRecHitCollection); - std::auto_ptr outputESColl(new EcalRecHitCollection); - std::auto_ptr outputHColl(new HBHERecHitCollection); - std::auto_ptr outputHOColl(new HORecHitCollection); - - edm::ESHandle pG; - iSetup.get().get(pG); - geo = pG.product(); - - edm::Handle trackCollection; - iEvent.getByToken(tok_track_,trackCollection); - - - // temporary collection of EB+EE recHits - std::auto_ptr tmpEcalRecHitCollection(new EcalRecHitCollection); - - std::vector >::const_iterator i; - for (i=toks_ecal_.begin(); i!=toks_ecal_.end(); i++) - { - edm::Handle ec; - iEvent.getByToken(*i,ec); - for(EcalRecHitCollection::const_iterator recHit = (*ec).begin(); recHit != (*ec).end(); ++recHit) - { - tmpEcalRecHitCollection->push_back(*recHit); - } - } - - edm::Handle hbheRHcol; - iEvent.getByToken(tok_hbhe_, hbheRHcol); +void AlCaIsoTracksProducer::produce(edm::Event& iEvent, const edm::EventSetup& iSetup) { - const reco::TrackCollection tC = *(trackCollection.product()); - - int itrk=0; - int nisotr=0; - edm::Ref::key_type idx = 0; - - // Parameters for TrackDetAssociator ================================ - // For Low momentum tracks need to look for larger cone for search ==== - // ==================================================================== - - parameters_.useEcal = true; - parameters_.useHcal = true; - parameters_.useCalo = false; - parameters_.useMuon = false; - parameters_.dREcal = taECALCone_; - parameters_.dRHcal = taHCALCone_; + nAll++; + LogDebug("HcalIsoTrack") << "Run " << iEvent.id().run() << " Event " + << iEvent.id().event() << " Luminosity " + << iEvent.luminosityBlock() << " Bunch " + << iEvent.bunchCrossing(); - /////////////////////////////// - - ///vector of used hits: - std::vector usedHitsHC; - std::vector usedHitsEC; - /// - - // main loop over input tracks - for (reco::TrackCollection::const_iterator track=tC.begin(); track!=tC.end(); track++) { - bool noChargedTracks = true; - int itrk1=0; - itrk++; - double px = track->px(); - double py = track->py(); - double pz = track->pz(); - double ptrack = sqrt(px*px+py*py+pz*pz); + //Step1: Get all the relevant containers + trigger::TriggerEvent triggerEvent; + edm::Handle triggerEventHandle; + iEvent.getByToken(tok_trigEvt_, triggerEventHandle); + if (!triggerEventHandle.isValid()) { + edm::LogWarning("HcalIsoTrack") << "Cannot access the collection " << labelTriggerEvent_; + return; + } + edm::Handle triggerResults; + iEvent.getByToken(tok_trigRes_, triggerResults); + if (!triggerResults.isValid()) { + edm::LogWarning("HcalIsoTrack") << "Cannot access the collection " << labelTriggerResults_; + return; + } + + edm::Handle trkCollection; + iEvent.getByToken(tok_genTrack_, trkCollection); + if (!trkCollection.isValid()) { + edm::LogWarning("HcalIsoTrack") << "Cannot access the collection " << labelGenTrack_; + return; + } + reco::TrackCollection::const_iterator trkItr; + edm::Handle recVtxs; + iEvent.getByToken(tok_recVtx_, recVtxs); + if (!trkCollection.isValid()) { + edm::LogWarning("HcalIsoTrack") << "Cannot access the collection " << labelGenTrack_; + return; + } + + edm::Handle beamSpotH; + iEvent.getByToken(tok_bs_, beamSpotH); + math::XYZPoint leadPV(0,0,0); + if (recVtxs->size()>0 && !((*recVtxs)[0].isFake())) { + leadPV = math::XYZPoint((*recVtxs)[0].x(),(*recVtxs)[0].y(), + (*recVtxs)[0].z()); + } else if (beamSpotH.isValid()) { + leadPV = beamSpotH->position(); + } + LogDebug("HcalIsoTrack") << "Primary Vertex " << leadPV; + + edm::Handle barrelRecHitsHandle; + iEvent.getByToken(tok_EB_, barrelRecHitsHandle); + if (!barrelRecHitsHandle.isValid()) { + edm::LogWarning("HcalIsoTrack") << "Cannot access the collection " << labelEB_; + return; + } + edm::Handle endcapRecHitsHandle; + iEvent.getByToken(tok_EE_, endcapRecHitsHandle); + if (!endcapRecHitsHandle.isValid()) { + edm::LogWarning("HcalIsoTrack") << "Cannot access the collection " << labelEE_; + return; + } + edm::Handle hbhe; + iEvent.getByToken(tok_hbhe_, hbhe); + if (!hbhe.isValid()) { + edm::LogWarning("HcalIsoTrack") << "Cannot access the collection " << labelHBHE_; + return; + } + + //Get L1 trigger object + ptL1 = etaL1 = phiL1 = 0; + edm::Handle l1trigobj; + iEvent.getByToken(tok_hltGT_, l1trigobj); + + std::vector< edm::Ref > l1tauobjref; + l1trigobj->getObjects(trigger::TriggerL1TauJet, l1tauobjref); + setPtEtaPhi(l1tauobjref,ptL1,etaL1,phiL1); + + std::vector< edm::Ref > l1jetobjref; + l1trigobj->getObjects(trigger::TriggerL1CenJet, l1jetobjref); + setPtEtaPhi(l1jetobjref,ptL1,etaL1,phiL1); + + std::vector< edm::Ref > l1forjetobjref; + l1trigobj->getObjects(trigger::TriggerL1ForJet, l1forjetobjref); + setPtEtaPhi(l1forjetobjref,ptL1,etaL1,phiL1); + + //For valid HLT record + if (!triggerEventHandle.isValid()) { + edm::LogWarning("HcalIsoTrack") << "Error! Can't get the product " + << labelTriggerEvent_.label() ; + } else { + trigger::TriggerEvent triggerEvent = *(triggerEventHandle.product()); + if (triggerResults.isValid()) { + const edm::TriggerNames & triggerNames = iEvent.triggerNames(*triggerResults); + const std::vector & triggerNames_ = triggerNames.triggerNames(); + reco::HcalIsolatedTrackCandidateCollection* isotk = select(triggerResults,triggerNames_,trkCollection,leadPV, barrelRecHitsHandle, endcapRecHitsHandle, hbhe); + + if (isotk->size() > 0) { + std::auto_ptr outputHcalIsoTrackColl(isotk); + std::auto_ptr outputTColl(new reco::TrackCollection); + std::auto_ptr outputVColl(new reco::VertexCollection); + std::auto_ptr outputEBColl(new EBRecHitCollection); + std::auto_ptr outputEEColl(new EERecHitCollection); + std::auto_ptr outputHBHEColl(new HBHERecHitCollection); - if (ptrack < m_pCut || track->pt() < m_ptCut ) continue; - - if (track->hitPattern().numberOfValidHits() < nHitsMinCore_) continue; + for (reco::TrackCollection::const_iterator track=trkCollection->begin(); track!=trkCollection->end(); ++track) + outputTColl->push_back(*track); - // check that track is not in the region of L1 jet - double l1jDR=deltaR(track->eta(), track->phi(), getL1triggerDirection(iEvent,tok_hlt_,l1FilterTag_).first,getL1triggerDirection(iEvent,tok_hlt_,l1FilterTag_).second); - if (l1jDRbegin(); vtx!=recVtxs->end(); ++vtx) + outputVColl->push_back(*vtx); + + for (edm::SortedCollection::const_iterator ehit=barrelRecHitsHandle->begin(); ehit!=barrelRecHitsHandle->end(); ++ehit) + outputEBColl->push_back(*ehit); - GlobalPoint gPointHcal(info.trkGlobPosAtHcal.x(),info.trkGlobPosAtHcal.y(),info.trkGlobPosAtHcal.z()); - - GlobalVector trackMomAtHcal = info.trkMomAtHcal; + for (edm::SortedCollection::const_iterator ehit=endcapRecHitsHandle->begin(); ehit!=endcapRecHitsHandle->end(); ++ehit) + outputEEColl->push_back(*ehit); - double etaecal=info.trkGlobPosAtEcal.eta(); - double phiecal=info.trkGlobPosAtEcal.phi(); + for (std::vector::const_iterator hhit=hbhe->begin(); hhit!=hbhe->end(); ++hhit) + outputHBHEColl->push_back(*hhit); + + iEvent.put(outputHcalIsoTrackColl, "HcalIsolatedTrackCollection"); + iEvent.put(outputTColl, labelGenTrack_.encode()); + iEvent.put(outputVColl, labelRecVtx_.encode()); + iEvent.put(outputEBColl, labelEB_.encode()); + iEvent.put(outputEEColl, labelEE_.encode()); + iEvent.put(outputHBHEColl, labelHBHE_.encode()); + } + } + } +} - if (etaecal==0&&phiecal==0) continue; +void AlCaIsoTracksProducer::beginJob() { } - //check matching to HLT object (optional) +void AlCaIsoTracksProducer::endJob() { + edm::LogInfo("HcalIsoTrack") << "Finds " << nGood << " good tracks in " + << nAll << " events from " << nRun << " runs"; + for (unsigned int k=0; keta())>etaMax_) continue; - - // check charged isolation from all other tracks - double maxPNearby=-10; - double sumPNearby=0; - for (reco::TrackCollection::const_iterator track1=tC.begin(); track1!=tC.end(); track1++) - { - itrk1++; - if (track == track1) continue; - if (track->hitPattern().numberOfValidHits() < nHitsMinIso_) continue; - double ptrack1 = sqrt(track1->px()*track1->px()+track1->py()*track1->py()+track1->pz()*track1->pz()); - - TrackDetMatchInfo info1 = trackAssociator_.associate(iEvent, iSetup, trackAssociator_.getFreeTrajectoryState(iSetup, *track1), parameters_); - - GlobalPoint gPointHcal1(info1.trkGlobPosAtHcal.x(),info1.trkGlobPosAtHcal.y(),info1.trkGlobPosAtHcal.z()); - - double etaecal1=info1.trkGlobPosAtEcal.eta(); - double phiecal1=info1.trkGlobPosAtEcal.phi(); - - if (etaecal1==0&&phiecal1==0) continue; - - double hcDist=getDistInPlaneTrackDir(gPointHcal, trackMomAtHcal, gPointHcal1); - -// double hcDist=getDistInCM(etaecal,phiecal,etaecal1,phiecal1); - - // increase required separation for low momentum tracks - double factor=1.; - double factor1=1.; - - if (useConeCorr_) - { - if(ptrack<10.)factor+=(10.-ptrack)/20.; - if(ptrack1<10.)factor1+=(10.-ptrack1)/20.; - } - - if( hcDist < m_ddirCut*factor*factor1 ) - { - //calculate maximum P and sum P near seed track - if (track1->p()>maxPNearby) - { - maxPNearby=track1->p(); - } - sumPNearby+=track1->p(); - - //apply loose isolation criteria - if (track1->p()>isolE_) - { - noChargedTracks = false; - break; - } - ////////////// - } - - } //second track loop +void AlCaIsoTracksProducer::beginRun(edm::Run const& iRun, edm::EventSetup const& iSetup) { + bool changed(false); + edm::LogInfo("HcalIsoTrack") << "Run[" << nRun << "] " << iRun.run() + << " hltconfig.init " << hltConfig_.init(iRun,iSetup,processName,changed); - bool noNeutrals = false; - - // we have a good charge-isolated track, so check neutral isolation and write it out - - if(noChargedTracks) - { - //find ecal cluster energy and write ecal recHits - double ecClustR=0; - double ecClustN=0; - double ecOutRingR=0; - - //get index of ECAL crystal hit by track - std::vector crossedECids=info.crossedEcalRecHits; - int etaIDcenter=-10000; - int phiIDcenter=-10000; - double enMax=0; - for (unsigned int i=0; iid()); - if (crossedECids[i]->energy()>enMax) - { - enMax=crossedECids[i]->energy(); - etaIDcenter=did.iy(); - phiIDcenter=did.ix(); - } - } - if ((*crossedECids[i]).id().subdetId()==EcalBarrel) - { - EBDetId did(crossedECids[i]->id()); - if (crossedECids[i]->energy()>enMax) - { - enMax=crossedECids[i]->energy(); - etaIDcenter=did.ieta(); - phiIDcenter=did.iphi(); - } - } - } - for (std::vector::const_iterator ehit=tmpEcalRecHitCollection->begin(); ehit!=tmpEcalRecHitCollection->end(); ehit++) - { - ////////////////////// FIND ECAL CLUSTER ENERGY - // R scheme of ECAL CLUSTERIZATION - GlobalPoint posH = geo->getPosition((*ehit).detid()); - double phihit = posH.phi(); - double etahit = posH.eta(); - - double dHit=deltaR(etaecal,phiecal,etahit,phihit); - - double dHitCM=getDistInPlaneTrackDir(gPointHcal, trackMomAtHcal, posH); - - if (dHitCMenergy(); - } - - if (dHitCM>ringInnRad_&&dHitCMenergy(); - } - - ////////////////////////////////// - //NxN scheme & check whether hit was used or not, if not used push into usedHits - bool hitIsUsed=false; - int hitHashedIndex=-10000; - if (ehit->id().subdetId()==EcalBarrel) - { - EBDetId did(ehit->id()); - hitHashedIndex=did.hashedIndex(); - if (fabs(did.ieta()-etaIDcenter)<=matrixSize_/2&&fabs(did.iphi()-phiIDcenter)<=matrixSize_/2) ecClustN+=ehit->energy(); - } - - if (ehit->id().subdetId()==EcalEndcap) - { - EEDetId did(ehit->id()); - hitHashedIndex=did.hashedIndex(); - if (fabs(did.iy()-etaIDcenter)<=matrixSize_/2&&fabs(did.ix()-phiIDcenter)<=matrixSize_/2) ecClustN+=ehit->energy(); - } - for (uint32_t i=0; ipush_back(*ehit); - } - } + edm::ESHandle bFieldH; + iSetup.get().get(bFieldH); + bField = bFieldH.product(); + edm::ESHandle pG; + iSetup.get().get(pG); + geo = pG.product(); +} - //check neutrals - if (ecOutRingRpush_back(*track); - reco::Track & mytrack = outputTColl->back(); - - mytrack.setExtra( teref ); - outputExTColl->push_back(*myextra); - // reco::TrackExtra & tx = outputExTColl->back(); - - //Create IsolatedPixelTrackCandidate (will change naming in future release) - reco::IsolatedPixelTrackCandidate newHITCandidate(reco::Candidate::LorentzVector(track->px(),track->py(),track->pz(),track->p())); - newHITCandidate.SetSumPtPxl(sumPNearby); - newHITCandidate.SetMaxPtPxl(maxPNearby); - - //set cluster energy deposition and ring energy deposition and push_back - if (!useECALCluMatrix_) newHITCandidate.SetEnergyIn(ecClustR); - else newHITCandidate.SetEnergyIn(ecClustN); - newHITCandidate.SetEnergyOut(ecOutRingR); - outputHcalIsoTrackColl->push_back(newHITCandidate); - - //save hcal recHits - for (std::vector::const_iterator hhit=hbheRHcol->begin(); hhit!=hbheRHcol->end(); hhit++) - { - //check that this hit was not considered before and push it into usedHits - bool hitIsUsed=false; - for (uint32_t i=0; iid()) hitIsUsed=true; - } - if (hitIsUsed) continue; - usedHitsHC.push_back(hhit->id()); - //////////// - - GlobalPoint posH = geo->getPosition((*hhit).detid()); - double phihit = posH.phi(); - double etahit = posH.eta(); - - double dHit=deltaR(etaecal,phiecal,etahit,phihit); - - if(dHit<1.) +void AlCaIsoTracksProducer::endRun(edm::Run const& iRun, edm::EventSetup const&) { + nRun++; + edm::LogInfo("HcalIsoTrack") << "endRun[" << nRun << "] " << iRun.run(); +} - { - outputHColl->push_back(*hhit); - } +reco::HcalIsolatedTrackCandidateCollection* +AlCaIsoTracksProducer::select(edm::Handle& triggerResults, + const std::vector & triggerNames_, + edm::Handle& trkCollection, + math::XYZPoint& leadPV,edm::Handle& barrelRecHitsHandle, + edm::Handle& endcapRecHitsHandle, + edm::Handle& hbhe) { + + reco::HcalIsolatedTrackCandidateCollection* trackCollection=new reco::HcalIsolatedTrackCandidateCollection; + bool ok(false); + + // Find a good HLT trigger + for (unsigned int iHLT=0; iHLTsize(); iHLT++) { + int hlt = triggerResults->accept(iHLT); + for (unsigned int i=0; i 0) { + ok = true; + trigPass[i]++; + } + LogDebug("HcalIsoTrack") <<"This is the trigger we are looking for " + << triggerNames_[iHLT] << " Flag " << hlt + << ":" << ok; + } + } + } + if (ok) { + //Propagate tracks to calorimeter surface) + std::vector trkCaloDirections; + spr::propagateCALO(trkCollection, geo, bField, theTrackQuality, + trkCaloDirections, false); + + std::vector::const_iterator trkDetItr; + unsigned int nTracks(0), nselTracks(0); + for (trkDetItr = trkCaloDirections.begin(),nTracks=0; + trkDetItr != trkCaloDirections.end(); trkDetItr++,nTracks++) { + const reco::Track* pTrack = &(*(trkDetItr->trkItr)); + math::XYZTLorentzVector v4(pTrack->px(), pTrack->py(), + pTrack->pz(), pTrack->p()); + LogDebug("HcalIsoTrack") << "This track : " << nTracks + << " (pt|eta|phi|p) :" << pTrack->pt() + << "|" << pTrack->eta() << "|" + << pTrack->phi() << "|" << pTrack->p(); + + //Selection of good track + bool qltyFlag = spr::goodTrack(pTrack,leadPV,selectionParameters,false); + LogDebug("HcalIsoTrack") << "qltyFlag|okECAL|okHCAL : " << qltyFlag + << "|" << trkDetItr->okECAL << "|" + << trkDetItr->okHCAL; + if (qltyFlag && trkDetItr->okECAL && trkDetItr->okHCAL) { + double t_p = pTrack->p(); + nselTracks++; + int nRH_eMipDR(0), nNearTRKs(0); + double eMipDR = spr::eCone_ecal(geo, barrelRecHitsHandle, + endcapRecHitsHandle, + trkDetItr->pointHCAL, + trkDetItr->pointECAL, a_mipR, + trkDetItr->directionECAL, + nRH_eMipDR); + double hmaxNearP = spr::chargeIsolationCone(nTracks, + trkCaloDirections, + a_charIsoR, + nNearTRKs, false); + LogDebug("HcalIsoTrack") << "This track : " << nTracks + << " (pt|eta|phi|p) :" << pTrack->pt() + << "|" << pTrack->eta() << "|" + << pTrack->phi() << "|" << t_p + << "e_MIP " << eMipDR + << " Chg Isolation " << hmaxNearP; + if (t_p>pTrackMin_ && eMipDRpointECAL).eta(), + (trkDetItr->pointECAL).phi()); + HcalDetId detId = HcalDetId(trkDetItr->detIdHCAL); + newCandidate.SetEtaPhiHcal((trkDetItr->pointHCAL).eta(), + (trkDetItr->pointHCAL).phi(), + detId.ieta(), detId.iphi()); + int indx(0); + reco::TrackCollection::const_iterator trkItr1; + for (trkItr1=trkCollection->begin(); trkItr1 != trkCollection->end(); ++trkItr1,++indx) { + const reco::Track* pTrack1 = &(*trkItr1); + if (pTrack1 == pTrack) { + reco::TrackRef tRef = reco::TrackRef(trkCollection,indx); + newCandidate.setTrack(tRef); + break; } } - - nisotr++; - - } //if (noNeutrals.... - - } // end of main track loop - - if(outputTColl->size() > 0) - { - // Take HO collection - edm::Handle ho; - iEvent.getByToken(tok_ho_,ho); - - const HORecHitCollection Hitho = *(ho.product()); - for(HORecHitCollection::const_iterator hoItr=Hitho.begin(); hoItr!=Hitho.end(); hoItr++) - { - outputHOColl->push_back(*hoItr); + trackCollection->push_back(newCandidate); } - - // Take Preshower collection - - // get the ps geometry - edm::ESHandle geoHandle; - iSetup.get().get(geoHandle); - - // get the ps topology - EcalPreshowerTopology psTopology(geoHandle); - - // process rechits - edm::Handle pRecHits; - iEvent.getByToken(tok_ps_,pRecHits); - const EcalRecHitCollection& psrechits = *(pRecHits.product()); + } + } + } + return trackCollection; +} - typedef EcalRecHitCollection::const_iterator IT; - - for(IT i=psrechits.begin(); i!=psrechits.end(); i++) - { - outputESColl->push_back( *i ); - } - } - - iEvent.put( outputHcalIsoTrackColl, "HcalIsolatedTrackCollection"); - iEvent.put( outputTColl, "IsoTrackTracksCollection"); - iEvent.put( outputExTColl, "IsoTrackExtraTracksCollection"); - iEvent.put( outputEColl, "IsoTrackEcalRecHitCollection"); - iEvent.put( outputESColl, "IsoTrackPSEcalRecHitCollection"); - iEvent.put( outputHColl, "IsoTrackHBHERecHitCollection"); - iEvent.put( outputHOColl, "IsoTrackHORecHitCollection"); +void AlCaIsoTracksProducer::setPtEtaPhi(std::vector< edm::Ref >& objref, double &ptL1, double &etaL1, double &phiL1) { + + for (unsigned int p=0; ppt()>ptL1) { + ptL1 = objref[p]->pt(); + phiL1 = objref[p]->phi(); + etaL1 = objref[p]->eta(); + } + } } -void AlCaIsoTracksProducer::endJob(void) {} +#include "FWCore/Framework/interface/MakerMacros.h" +DEFINE_FWK_MODULE(AlCaIsoTracksProducer); diff --git a/Calibration/HcalAlCaRecoProducers/src/SealModule.cc b/Calibration/HcalAlCaRecoProducers/src/SealModule.cc index cf445d9209819..ced88749c125e 100644 --- a/Calibration/HcalAlCaRecoProducers/src/SealModule.cc +++ b/Calibration/HcalAlCaRecoProducers/src/SealModule.cc @@ -1,16 +1,9 @@ #include "FWCore/PluginManager/interface/ModuleDef.h" #include "FWCore/Framework/interface/MakerMacros.h" -#include "Calibration/HcalAlCaRecoProducers/interface/AlCaIsoTracksProducer.h" #include "Calibration/HcalAlCaRecoProducers/interface/AlCaEcalHcalReadoutsProducer.h" -#include "Calibration/HcalAlCaRecoProducers/interface/AlCaDiJetsProducer.h" -#include "Calibration/HcalAlCaRecoProducers/interface/AlCaGammaJetProducer.h" #include "Calibration/HcalAlCaRecoProducers/src/ProducerAnalyzer.h" -using cms::AlCaDiJetsProducer; using cms::ProducerAnalyzer; -DEFINE_FWK_MODULE(AlCaIsoTracksProducer); DEFINE_FWK_MODULE(AlCaEcalHcalReadoutsProducer); -DEFINE_FWK_MODULE(AlCaDiJetsProducer); -DEFINE_FWK_MODULE(AlCaGammaJetProducer); DEFINE_FWK_MODULE(ProducerAnalyzer); diff --git a/Calibration/HcalAlCaRecoProducers/test/AlCaDiJetsProducer_cfg.py b/Calibration/HcalAlCaRecoProducers/test/AlCaDiJetsProducer_cfg.py new file mode 100644 index 0000000000000..4242f1132848c --- /dev/null +++ b/Calibration/HcalAlCaRecoProducers/test/AlCaDiJetsProducer_cfg.py @@ -0,0 +1,35 @@ +import FWCore.ParameterSet.Config as cms + +process = cms.Process("MYDIJETS") + +process.load("Configuration.Geometry.GeometryIdeal_cff") +process.load("Configuration.StandardSequences.MagneticField_cff") +process.load('Configuration.StandardSequences.FrontierConditions_GlobalTag_cff') +from Configuration.AlCa.autoCond import autoCond +process.GlobalTag.globaltag=autoCond['startup'] + +process.options = cms.untracked.PSet( + wantSummary = cms.untracked.bool(True) +) + +process.load('FWCore.MessageService.MessageLogger_cfi') +process.maxEvents = cms.untracked.PSet( input = cms.untracked.int32(-1) ) +process.MessageLogger.cerr.FwkReport.reportEvery=cms.untracked.int32(1000) +process.options = cms.untracked.PSet( wantSummary = cms.untracked.bool(True) ) + +process.source = cms.Source("PoolSource", fileNames = cms.untracked.vstring( + '/store/relval/CMSSW_7_3_0/RelValQCD_Pt_80_120_13/GEN-SIM-RECO/MCRUN2_73_V9_71XGENSIM_FIXGT-v1/00000/8E758AAA-4DA2-E411-8068-003048FFCB96.root', + '/store/relval/CMSSW_7_3_0/RelValQCD_Pt_80_120_13/GEN-SIM-RECO/MCRUN2_73_V9_71XGENSIM_FIXGT-v1/00000/CE0DAE28-56A2-E411-AEFF-003048FFD79C.root', + '/store/relval/CMSSW_7_3_0/RelValQCD_Pt_80_120_13/GEN-SIM-RECO/MCRUN2_73_V9_71XGENSIM_FIXGT-v1/00000/D4D21D16-56A2-E411-A0C4-0026189438E2.root' +)) + +process.load("Calibration.HcalAlCaRecoProducers.alcadijets_cfi") +process.load("Calibration.HcalAlCaRecoProducers.ALCARECOHcalCalDijets_Output_cff") + +process.DiJetsRecos = cms.OutputModule("PoolOutputModule", + outputCommands = process.OutALCARECOHcalCalDijets.outputCommands, + fileName = cms.untracked.string('dijets.root') +) + +process.p = cms.Path(process.DiJetsProd) +process.e = cms.EndPath(process.DiJetsRecos) diff --git a/Calibration/HcalAlCaRecoProducers/test/AlCaGammaJetProducer_cfg.py b/Calibration/HcalAlCaRecoProducers/test/AlCaGammaJetProducer_cfg.py new file mode 100644 index 0000000000000..6221fed554b68 --- /dev/null +++ b/Calibration/HcalAlCaRecoProducers/test/AlCaGammaJetProducer_cfg.py @@ -0,0 +1,51 @@ +import FWCore.ParameterSet.Config as cms + +process = cms.Process("MYGAMMAJET") + +process.load("Configuration.Geometry.GeometryIdeal_cff") +process.load("Configuration.StandardSequences.MagneticField_cff") +process.load('Configuration.StandardSequences.FrontierConditions_GlobalTag_cff') +from Configuration.AlCa.autoCond import autoCond +process.GlobalTag.globaltag=autoCond['startup'] + +process.options = cms.untracked.PSet( + wantSummary = cms.untracked.bool(True) +) + +process.maxEvents = cms.untracked.PSet( +# input = cms.untracked.int32(100) + input = cms.untracked.int32(-1) +) +process.source = cms.Source("PoolSource", + fileNames = +cms.untracked.vstring( +# 'file:/tmp/andriusj/6EC8FCC8-E2A8-E411-9506-002590596468.root' + '/store/relval/CMSSW_7_4_0_pre6/RelValPhotonJets_Pt_10_13/GEN-SIM-RECO/MCRUN2_74_V1-v1/00000/6EC8FCC8-E2A8-E411-9506-002590596468.root' + ) +) + +process.load("Calibration.HcalAlCaRecoProducers.alcagammajet_cfi") +process.load("Calibration.HcalAlCaRecoProducers.ALCARECOHcalCalGammaJet_Output_cff") + +#process.GammaJetRecos = cms.OutputModule("PoolOutputModule", +# outputCommands = cms.untracked.vstring('drop *', +## 'keep recoPhotonCores_*_*_*', +# 'keep recoSuperClusters_*_*_*', +# #'keep recoTracks_*_*_*', +# 'keep recoTracks_generalTracks_*_*', +# #'keep *_PhotonIDProd_*_*', +# 'keep *_particleFlow_*_*', +# 'keep recoPFBlocks_particleFlowBlock_*_*', +# 'keep recoPFClusters_*_*_*', +## 'keep *_particleFlowPtrs_*_*', +# 'keep *_GammaJetProd_*_*'), +# fileName = cms.untracked.string('gjet.root') +#) + +process.GammaJetRecos = cms.OutputModule("PoolOutputModule", + outputCommands = process.OutALCARECOHcalCalGammaJet.outputCommands, + fileName = cms.untracked.string('gjet.root') +) + +process.p = cms.Path(process.GammaJetProd) +process.e = cms.EndPath(process.GammaJetRecos) diff --git a/Calibration/HcalAlCaRecoProducers/test/AlCaHBHEMuonProducer_cfg.py b/Calibration/HcalAlCaRecoProducers/test/AlCaHBHEMuonProducer_cfg.py new file mode 100644 index 0000000000000..ea45ffb91e648 --- /dev/null +++ b/Calibration/HcalAlCaRecoProducers/test/AlCaHBHEMuonProducer_cfg.py @@ -0,0 +1,20 @@ +import FWCore.ParameterSet.Config as cms + +process = cms.Process("RaddamMuon") + +process.load("Calibration.HcalAlCaRecoProducers.alcahbhemuon_cfi") +process.maxEvents = cms.untracked.PSet( input = cms.untracked.int32(-1) ) +process.source = cms.Source("PoolSource", + fileNames = cms.untracked.vstring( + 'root://xrootd.unl.edu//store/mc/Phys14DR/DYToMuMu_M-50_Tune4C_13TeV-pythia8/GEN-SIM-RECO/PU20bx25_tsg_castor_PHYS14_25_V1-v1/10000/184C1AC9-A775-E411-9196-002590200824.root' + ) + + ) + +process.muonOutput = cms.OutputModule("PoolOutputModule", + fileName = cms.untracked.string('PoolOutput.root'), + outputCommands = cms.untracked.vstring('keep *_HBHEMuonProd_*_*') + ) + +process.p = cms.Path(process.HBHEMuonProd) +process.e = cms.EndPath(process.muonOutput) diff --git a/Calibration/HcalAlCaRecoProducers/test/phi_sym_cfg.py b/Calibration/HcalAlCaRecoProducers/test/phi_sym_cfg.py new file mode 100644 index 0000000000000..a27e15e08809c --- /dev/null +++ b/Calibration/HcalAlCaRecoProducers/test/phi_sym_cfg.py @@ -0,0 +1,37 @@ +import FWCore.ParameterSet.Config as cms + +process = cms.Process("PHISYM") + + +process.load("Configuration.StandardSequences.Geometry_cff") +process.load("Configuration.StandardSequences.MagneticField_cff") + +process.maxEvents = cms.untracked.PSet( + input = cms.untracked.int32(100) +) +process.source = cms.Source("PoolSource", + fileNames = +#cms.untracked.vstring('/store/relval/CMSSW_3_1_0_pre3/RelValQCD_Pt_80_120/GEN-SIM-RECO/IDEAL_30X_v1/0001/087DC4B2-640A-DE11-86E5-000423D98DD4.root') +cms.untracked.vstring('file:/afs/cern.ch/cms/Tutorials/TWIKI_DATA/CMSDataAnaSch_RelValZMM536.root') +) + +process.PhiSymIter = cms.EDProducer("AlCaEcalHcalReadoutsProducer", + hbheInput = cms.InputTag("hbhereco"), + hoInput = cms.InputTag("horeco"), + hfInput = cms.InputTag("hfreco") +) + +process.PhiSymOut = cms.OutputModule("PoolOutputModule", + outputCommands = cms.untracked.vstring('drop *', + "keep *_horeco_*_*", + "keep *_hfreco_*_*", + "keep *_hbhereco_*_*", + "keep *_offlinePrimaryVertices_*_*", + "keep edmTriggerResults_*_*_HLT" +), + fileName = cms.untracked.string('phi_sym.root') +) + +process.p = cms.Path(process.PhiSymIter) +process.e = cms.EndPath(process.PhiSymOut) + diff --git a/Calibration/HcalCalibAlgos/BuildFile.xml b/Calibration/HcalCalibAlgos/BuildFile.xml index 1a79e9af0cd25..8d0de3761b96d 100644 --- a/Calibration/HcalCalibAlgos/BuildFile.xml +++ b/Calibration/HcalCalibAlgos/BuildFile.xml @@ -18,9 +18,15 @@ + + + + + + diff --git a/Calibration/HcalCalibAlgos/interface/Analyzer_minbias.h b/Calibration/HcalCalibAlgos/interface/Analyzer_minbias.h index 7ef8fa1dd582b..5591891bf28be 100644 --- a/Calibration/HcalCalibAlgos/interface/Analyzer_minbias.h +++ b/Calibration/HcalCalibAlgos/interface/Analyzer_minbias.h @@ -18,11 +18,14 @@ #include "DataFormats/CaloTowers/interface/CaloTowerCollection.h" #include "DataFormats/Candidate/interface/Candidate.h" #include "DataFormats/DetId/interface/DetId.h" +#include "DataFormats/HcalDetId/interface/HcalDetId.h" #include "DataFormats/JetReco/interface/Jet.h" #include "DataFormats/JetReco/interface/CaloJet.h" #include "DataFormats/JetReco/interface/CaloJetCollection.h" #include "DataFormats/HcalRecHit/interface/HcalRecHitCollections.h" #include "DataFormats/EcalRecHit/interface/EcalRecHitCollections.h" +#include "DataFormats/L1GlobalTrigger/interface/L1GlobalTriggerObjectMap.h" +#include "DataFormats/L1GlobalTrigger/interface/L1GlobalTriggerObjectMapRecord.h" #include "Geometry/CaloGeometry/interface/CaloGeometry.h" #include "Geometry/Records/interface/CaloGeometryRecord.h" #include "DataFormats/GeometryVector/interface/GlobalPoint.h" @@ -30,8 +33,6 @@ #include "FWCore/Framework/interface/ESHandle.h" #include "FWCore/Framework/interface/EventSetup.h" #include "FWCore/Framework/interface/Run.h" -#include "DataFormats/L1GlobalTrigger/interface/L1GlobalTriggerReadoutRecord.h" -//#include "CalibFormats/HcalObjects/interface/HcalDbService.h" #include "TFile.h" #include "TH1.h" #include "TH2.h" @@ -39,106 +40,55 @@ #include "DataFormats/HcalDetId/interface/HcalDetId.h" #include #include -//#include "CalibCalorimetry/CaloMiscalibTools/interface/CaloMiscalibMapHcal.h" + #include #include #include #include -// // class declaration -// namespace cms{ -class Analyzer_minbias : public edm::EDAnalyzer { - public: - explicit Analyzer_minbias(const edm::ParameterSet&); - ~Analyzer_minbias(); - - virtual void analyze(const edm::Event&, const edm::EventSetup&); - virtual void beginJob() ; - virtual void endJob() ; - virtual void beginRun( const edm::Run& r, const edm::EventSetup& iSetup); - virtual void endRun( const edm::Run& r, const edm::EventSetup& iSetup); - - private: - // ----------member data --------------------------- - std::string fOutputFileName ; - std::string hcalfile_; - std::ofstream *myout_hcal; - - // names of modules, producing object collections - - TFile* hOutputFile ; - TTree* myTree; - TH1F* hCalo1[73][43]; - TH1F* hCalo2[73][43]; - TH1F* hCalo1mom2[73][43]; - TH1F* hCalo2mom2[73][43]; - TH1F* hbheNoiseE; - TH1F* hbheSignalE; - TH1F* hfNoiseE; - TH1F* hfSignalE; - - TH2F* hHBHEsize_vs_run; - TH2F* hHFsize_vs_run; - // Root tree members - int nevent_run; - int mydet, mysubd, depth, iphi, ieta; - float phi,eta; - float mom0_MB,mom1_MB,mom2_MB,mom3_MB,mom4_MB,occup; - float mom0_Noise,mom1_Noise,mom2_Noise,mom3_Noise,mom4_Noise; - float mom0_Diff,mom1_Diff,mom2_Diff,mom3_Diff,mom4_Diff; - - // Noise subtraction - - double meannoise_pl[73][43],meannoise_min[73][43]; - double noise_pl[73][43],noise_min[73][43]; - - // counters - - double nevent; - double theMBFillDetMapPl0[5][5][73][43]; - double theMBFillDetMapPl1[5][5][73][43]; - double theMBFillDetMapPl2[5][5][73][43]; - double theMBFillDetMapPl4[5][5][73][43]; - - double theMBFillDetMapMin0[5][5][73][43]; - double theMBFillDetMapMin1[5][5][73][43]; - double theMBFillDetMapMin2[5][5][73][43]; - double theMBFillDetMapMin4[5][5][73][43]; - - double theNSFillDetMapPl0[5][5][73][43]; - double theNSFillDetMapPl1[5][5][73][43]; - double theNSFillDetMapPl2[5][5][73][43]; - double theNSFillDetMapPl4[5][5][73][43]; - - double theNSFillDetMapMin0[5][5][73][43]; - double theNSFillDetMapMin1[5][5][73][43]; - double theNSFillDetMapMin2[5][5][73][43]; - double theNSFillDetMapMin4[5][5][73][43]; - - double theDFFillDetMapPl0[5][5][73][43]; - double theDFFillDetMapPl1[5][5][73][43]; - double theDFFillDetMapPl2[5][5][73][43]; - double theDFFillDetMapMin0[5][5][73][43]; - double theDFFillDetMapMin1[5][5][73][43]; - double theDFFillDetMapMin2[5][5][73][43]; - - - edm::EDGetTokenT tok_hbhe_; - edm::EDGetTokenT tok_ho_; - edm::EDGetTokenT tok_hf_; - - edm::EDGetTokenT tok_hbheNoise_; - edm::EDGetTokenT tok_hoNoise_; - edm::EDGetTokenT tok_hfNoise_; - - // - edm::EDGetTokenT tok_gtRec_; - edm::EDGetTokenT tok_hbheNorm_; - - bool theRecalib; + class Analyzer_minbias : public edm::EDAnalyzer { + public: + explicit Analyzer_minbias(const edm::ParameterSet&); + ~Analyzer_minbias(); + virtual void analyze(const edm::Event&, const edm::EventSetup&); + virtual void beginJob() ; + virtual void endJob() ; + virtual void beginRun( const edm::Run& r, const edm::EventSetup& iSetup); + virtual void endRun( const edm::Run& r, const edm::EventSetup& iSetup); + + private: + + // ----------member data --------------------------- + std::string fOutputFileName ; + std::string hcalfile_; + std::ofstream *myout_hcal; + TFile* hOutputFile ; + TTree* myTree; -}; + // Root tree members + double rnnum, rnnumber; + int mydet, mysubd, depth, iphi, ieta, cells, trigbit; + float phi,eta; + float mom0_MB,mom1_MB,mom2_MB,mom3_MB,mom4_MB,occup; + float mom0_Noise,mom1_Noise,mom2_Noise,mom3_Noise,mom4_Noise; + float mom0_Diff,mom1_Diff,mom2_Diff,mom3_Diff,mom4_Diff; + struct myInfo{ + double theMB0, theMB1, theMB2, theMB4, theNS0, theNS1, theNS2, theNS4; + double theDif0, theDif1, theDif2, runcheck; + void MyInfo() { + theMB0 = theMB1 = theMB2 = theMB4 = theNS0 = theNS1 = theNS2 = theNS4 = 0; + theDif0 = theDif1 = theDif2 = runcheck = 0; + } + }; + std::map,myInfo> myMap; + edm::EDGetTokenT tok_hbherecoMB_, tok_hbherecoNoise_; + edm::EDGetTokenT tok_hfrecoMB_, tok_hfrecoNoise_; + edm::EDGetTokenT tok_horecoMB_, tok_horecoNoise_; + bool theRecalib; + edm::EDGetTokenT tok_hbheNormal_; + edm::EDGetTokenT tok_hltL1GtMap_; + }; } #endif diff --git a/Calibration/HcalCalibAlgos/interface/DiJetAnalyzer.h b/Calibration/HcalCalibAlgos/interface/DiJetAnalyzer.h index fc4c7a2b5642f..9ec4c56656a6d 100644 --- a/Calibration/HcalCalibAlgos/interface/DiJetAnalyzer.h +++ b/Calibration/HcalCalibAlgos/interface/DiJetAnalyzer.h @@ -1,112 +1,178 @@ #ifndef DiJetAnalyzer_h #define DiJetAnalyzer_h - // system include files #include +#include +#include +#include +#include + +#include "TTree.h" +#include "TFile.h" +#include "TH1D.h" +#include "TH2D.h" +#include "TClonesArray.h" // user include files #include "FWCore/Framework/interface/Frameworkfwd.h" #include "FWCore/Framework/interface/EDAnalyzer.h" -#include "FWCore/Framework/interface/ESHandle.h" - #include "FWCore/Framework/interface/Event.h" #include "FWCore/Framework/interface/EventSetup.h" #include "FWCore/Framework/interface/MakerMacros.h" - +#include "FWCore/Framework/interface/ESHandle.h" #include "FWCore/ParameterSet/interface/ParameterSet.h" - -#include "Geometry/CaloGeometry/interface/CaloGeometry.h" -#include "DataFormats/DetId/interface/DetId.h" - -#include "CondFormats/HcalObjects/interface/HcalRespCorrs.h" - -// collections #include "DataFormats/JetReco/interface/CaloJetCollection.h" -#include "DataFormats/HcalRecHit/interface/HcalRecHitCollections.h" -#include "DataFormats/EcalRecHit/interface/EcalRecHitCollections.h" -#include "DataFormats/CaloTowers/interface/CaloTowerCollection.h" - -/* -#include "TFile.h" -#include "TTree.h" -*/ - -#include "TString.h" -#include "TFile.h" -#include "TTree.h" -#include "TObject.h" -#include "TObjArray.h" -#include "TClonesArray.h" -#include "TRefArray.h" -#include "TLorentzVector.h" - -#include "Calibration/HcalCalibAlgos/src/TCell.h" - +#include "DataFormats/JetReco/interface/PFJetCollection.h" +#include "DataFormats/JetReco/interface/GenJetCollection.h" +#include "DataFormats/HcalRecHit/interface/HBHERecHit.h" +#include "DataFormats/HcalRecHit/interface/HFRecHit.h" +#include "DataFormats/HcalRecHit/interface/HORecHit.h" +#include "DataFormats/ParticleFlowReco/interface/PFBlockFwd.h" +#include "DataFormats/ParticleFlowReco/interface/PFBlock.h" +#include "DataFormats/ParticleFlowReco/interface/PFCluster.h" +#include "DataFormats/ParticleFlowReco/interface/PFRecHit.h" +#include "DataFormats/ParticleFlowReco/interface/PFRecHitFwd.h" +#include "DataFormats/ParticleFlowCandidate/interface/PFCandidate.h" +#include "DataFormats/HcalDetId/interface/HcalDetId.h" +#include "DataFormats/TrackReco/interface/TrackFwd.h" +#include "Geometry/CaloGeometry/interface/CaloGeometry.h" +#include "Geometry/CaloGeometry/interface/CaloSubdetectorGeometry.h" +#include "Geometry/Records/interface/CaloGeometryRecord.h" +#include "DataFormats/HepMCCandidate/interface/GenParticle.h" +#include "SimDataFormats/GeneratorProducts/interface/GenEventInfoProduct.h" +#include "JetMETCorrections/Objects/interface/JetCorrector.h" +#include "CondFormats/JetMETObjects/interface/JetCorrectorParameters.h" +#include "JetMETCorrections/Objects/interface/JetCorrectionsRecord.h" +#include "DataFormats/VertexReco/interface/VertexFwd.h" +#include "FWCore/Utilities/interface/EDMException.h" + +// forward declarations +class TH1D; +class TH2D; +class TFile; +class TTree; // -// class decleration +// class declarations // -namespace cms{ -class DiJetAnalyzer : public edm::EDAnalyzer { - public: - explicit DiJetAnalyzer(const edm::ParameterSet&); - ~DiJetAnalyzer(); - - - private: - virtual void beginJob() ; - virtual void analyze(const edm::Event&, const edm::EventSetup&); - virtual void endJob() ; - - // ----------member data --------------------------- - - - edm::EDGetTokenT tok_jets_; - edm::EDGetTokenT tok_ec_; - edm::EDGetTokenT tok_hbhe_; - edm::EDGetTokenT tok_ho_; - edm::EDGetTokenT tok_hf_; - - - - // output file name with histograms - std::string fOutputFileName ; - - - TFile* hOutputFile ; - TTree* tree; +class JetCorretPair : protected std::pair { + public: + JetCorretPair() { + first=0; + second=1.0; + } + JetCorretPair(const reco::PFJet* j, double s) { + first=j; + second=s; + } + ~JetCorretPair() {} + + inline const reco::PFJet* jet(void) const { return first; } + inline void jet(const reco::PFJet* j) { first=j; return; } + inline double scale(void) const { return second; } + inline void scale(double d) { second=d; return; } + + private: - UInt_t eventNumber; - UInt_t runNumber; - Int_t iEtaHit; - UInt_t iPhiHit; - - Float_t xTrkHcal; - Float_t yTrkHcal; - Float_t zTrkHcal; - - Float_t PxTrkHcal; - Float_t PyTrkHcal; - Float_t PzTrkHcal; - - TClonesArray* cells; - - Float_t emEnergy; - Float_t targetE; +}; - Float_t etVetoJet; - TLorentzVector* tagJetP4; - TLorentzVector* probeJetP4; - Float_t tagJetEmFrac; - Float_t probeJetEmFrac; +class DiJetAnalyzer : public edm::EDAnalyzer { + public: + explicit DiJetAnalyzer(const edm::ParameterSet&); + ~DiJetAnalyzer(); + + + private: + virtual void beginJob();//(const edm::EventSetup&); + virtual void analyze(const edm::Event&, const edm::EventSetup&); + virtual void endJob(); + + // parameters + bool debug_; // print debug statements + std::string pfJetCollName_; // label for the PF jet collection + std::string pfJetCorrName_; // label for the PF jet correction service + std::string hbheRecHitName_; // label for HBHERecHits collection + std::string hfRecHitName_; // label for HFRecHit collection + std::string hoRecHitName_; // label for HORecHit collection + std::string pvCollName_; // label for primary vertex collection + std::string rootHistFilename_; // name of the histogram file + double maxDeltaEta_; // maximum delta-|Eta| between Jets + double minTagJetEta_; // minimum |eta| of the tag jet + double maxTagJetEta_; // maximum |eta| of the tag jet + double minSumJetEt_; // minimum Sum of the tag and probe jet Et + double minJetEt_; // minimum Jet Et + double maxThirdJetEt_; // maximum 3rd jet Et + + edm::EDGetTokenT tok_PFJet_; + edm::EDGetTokenT > > tok_HBHE_; + edm::EDGetTokenT > > tok_HF_; + edm::EDGetTokenT > > tok_HO_; + edm::EDGetTokenT tok_Vertex_; + + + // root file/histograms + TFile* rootfile_; + + TH1D* h_PassSelPF_; + TTree* tree_; + + float tpfjet_pt_, tpfjet_p_, tpfjet_E_, tpfjet_eta_, tpfjet_phi_, tpfjet_EMfrac_, tpfjet_hadEcalEfrac_, tpfjet_scale_, tpfjet_area_; + int tpfjet_jetID_; + float tpfjet_EBE_, tpfjet_EEE_, tpfjet_HBE_, tpfjet_HEE_, tpfjet_HFE_; + float tpfjet_unkown_E_, tpfjet_unkown_px_, tpfjet_unkown_py_, tpfjet_unkown_pz_, tpfjet_unkown_EcalE_; + float tpfjet_electron_E_, tpfjet_electron_px_, tpfjet_electron_py_, tpfjet_electron_pz_, tpfjet_electron_EcalE_; + float tpfjet_muon_E_, tpfjet_muon_px_, tpfjet_muon_py_, tpfjet_muon_pz_, tpfjet_muon_EcalE_; + float tpfjet_photon_E_, tpfjet_photon_px_, tpfjet_photon_py_, tpfjet_photon_pz_, tpfjet_photon_EcalE_; + int tpfjet_unkown_n_, tpfjet_electron_n_, tpfjet_muon_n_, tpfjet_photon_n_; + int tpfjet_had_n_; + std::vector tpfjet_had_E_, tpfjet_had_px_, tpfjet_had_py_, tpfjet_had_pz_, tpfjet_had_EcalE_, tpfjet_had_rawHcalE_, tpfjet_had_emf_; + std::vector tpfjet_had_id_, tpfjet_had_candtrackind_, tpfjet_had_ntwrs_; + int tpfjet_ntwrs_; + std::vector tpfjet_twr_ieta_, tpfjet_twr_iphi_, tpfjet_twr_depth_, tpfjet_twr_subdet_, tpfjet_twr_candtrackind_, tpfjet_twr_hadind_, tpfjet_twr_elmttype_, tpfjet_twr_clusterind_; + std::vector tpfjet_twr_hade_, tpfjet_twr_frac_, tpfjet_twr_dR_; + int tpfjet_cluster_n_; + std::vector tpfjet_cluster_eta_, tpfjet_cluster_phi_, tpfjet_cluster_dR_; + int tpfjet_ncandtracks_; + std::vector tpfjet_candtrack_px_, tpfjet_candtrack_py_, tpfjet_candtrack_pz_, tpfjet_candtrack_EcalE_; + float ppfjet_pt_, ppfjet_p_, ppfjet_E_, ppfjet_eta_, ppfjet_phi_, ppfjet_EMfrac_, ppfjet_hadEcalEfrac_, ppfjet_scale_, ppfjet_area_; + int ppfjet_jetID_; + float ppfjet_EBE_, ppfjet_EEE_, ppfjet_HBE_, ppfjet_HEE_, ppfjet_HFE_; + float ppfjet_unkown_E_, ppfjet_unkown_px_, ppfjet_unkown_py_, ppfjet_unkown_pz_, ppfjet_unkown_EcalE_; + float ppfjet_electron_E_, ppfjet_electron_px_, ppfjet_electron_py_, ppfjet_electron_pz_, ppfjet_electron_EcalE_; + float ppfjet_muon_E_, ppfjet_muon_px_, ppfjet_muon_py_, ppfjet_muon_pz_, ppfjet_muon_EcalE_; + float ppfjet_photon_E_, ppfjet_photon_px_, ppfjet_photon_py_, ppfjet_photon_pz_, ppfjet_photon_EcalE_; + int ppfjet_unkown_n_, ppfjet_electron_n_, ppfjet_muon_n_, ppfjet_photon_n_; + int ppfjet_had_n_; + std::vector ppfjet_had_E_, ppfjet_had_px_, ppfjet_had_py_, ppfjet_had_pz_, ppfjet_had_EcalE_, ppfjet_had_rawHcalE_, ppfjet_had_emf_; + std::vector ppfjet_had_id_, ppfjet_had_candtrackind_, ppfjet_had_ntwrs_; + int ppfjet_ntwrs_; + std::vector ppfjet_twr_ieta_, ppfjet_twr_iphi_, ppfjet_twr_depth_, ppfjet_twr_subdet_, ppfjet_twr_candtrackind_, ppfjet_twr_hadind_, ppfjet_twr_elmttype_, ppfjet_twr_clusterind_; + std::vector ppfjet_twr_hade_, ppfjet_twr_frac_, ppfjet_twr_dR_; + int ppfjet_cluster_n_; + std::vector ppfjet_cluster_eta_, ppfjet_cluster_phi_, ppfjet_cluster_dR_; + int ppfjet_ncandtracks_; + std::vector ppfjet_candtrack_px_, ppfjet_candtrack_py_, ppfjet_candtrack_pz_, ppfjet_candtrack_EcalE_; + float pf_dijet_deta_, pf_dijet_dphi_, pf_dijet_balance_; + float pf_thirdjet_px_, pf_thirdjet_py_, pf_realthirdjet_px_, pf_realthirdjet_py_, pf_realthirdjet_scale_; + int pf_Run_, pf_Lumi_, pf_Event_; + int pf_NPV_; + + // helper functions + double deltaR(const reco::Jet* j1, const reco::Jet* j2); + double deltaR(const double eta1, const double phi1, const double eta2, const double phi2); + int getEtaPhi(const DetId id); + int getEtaPhi(const HcalDetId id); + + struct JetCorretPairComp { + inline bool operator() ( const JetCorretPair& a, const JetCorretPair& b) { + return (a.jet()->pt()*a.scale()) > (b.jet()->pt()*b.scale()); + } + }; - bool allowMissingInputs_; +}; - HcalRespCorrs* oldRespCorrs; -}; -} #endif diff --git a/Calibration/HcalCalibAlgos/python/diJetAnalyzer_cfi.py b/Calibration/HcalCalibAlgos/python/diJetAnalyzer_cfi.py new file mode 100644 index 0000000000000..4501ac6b4da77 --- /dev/null +++ b/Calibration/HcalCalibAlgos/python/diJetAnalyzer_cfi.py @@ -0,0 +1,19 @@ +import FWCore.ParameterSet.Config as cms + +diJetAnalyzer = cms.EDAnalyzer( + 'DiJetAnalyzer', + pfJetCollName = cms.string('DiJetsProd:ak4PFJetsCHS'), + pfJetCorrName = cms.string('ak4PFCHSL1FastL2L3'), + hbheRecHitName = cms.string('DiJetsProd:hbhereco'), + hfRecHitName = cms.string('DiJetsProd:hfreco'), + hoRecHitName = cms.string('DiJetsProd:horeco'), + pvCollName = cms.string('DiJetsProd:offlinePrimaryVertices'), + rootHistFilename = cms.string('dijettree.root'), + maxDeltaEta = cms.double(1.5), + minTagJetEta = cms.double(0.0), + maxTagJetEta = cms.double(5.0), + minSumJetEt = cms.double(50.), + minJetEt = cms.double(20.), + maxThirdJetEt = cms.double(75.), + debug = cms.untracked.bool(False) + ) diff --git a/Calibration/HcalCalibAlgos/python/gammaJetAnalysis_CHSJECs_cff.py b/Calibration/HcalCalibAlgos/python/gammaJetAnalysis_CHSJECs_cff.py new file mode 100644 index 0000000000000..cf67b688e7098 --- /dev/null +++ b/Calibration/HcalCalibAlgos/python/gammaJetAnalysis_CHSJECs_cff.py @@ -0,0 +1,29 @@ +import FWCore.ParameterSet.Config as cms + +# Define CHS correctors +ak5PFchsL1Fastjet = cms.ESProducer( + 'L1FastjetCorrectionESProducer', + level = cms.string('L1FastJet'), + algorithm = cms.string('AK5PFchs'), + srcRho = cms.InputTag('kt6PFJets','rho') +) +ak5PFchsL2Relative = cms.ESProducer( + 'LXXXCorrectionESProducer', + level = cms.string('L2Relative'), + algorithm = cms.string('AK5PFchs') +) +ak5PFchsL3Absolute = cms.ESProducer( + 'LXXXCorrectionESProducer', + level = cms.string('L3Absolute'), + algorithm = cms.string('AK5PFchs') +) +ak5PFJetschsL1FastL2L3 = cms.ESProducer( + 'JetCorrectionESChain', + correctors = cms.vstring('ak5PFchsL1Fastjet','ak5PFchsL2Relative', 'ak5PFchsL3Absolute') +) + +ak5PFchsL2L3 = cms.ESProducer( + 'JetCorrectionESChain', + correctors = cms.vstring('ak5PFchsL2Relative', 'ak5PFchsL3Absolute') + ) + diff --git a/Calibration/HcalCalibAlgos/python/gammaJetAnalysis_cfi.py b/Calibration/HcalCalibAlgos/python/gammaJetAnalysis_cfi.py new file mode 100644 index 0000000000000..5ab4834950270 --- /dev/null +++ b/Calibration/HcalCalibAlgos/python/gammaJetAnalysis_cfi.py @@ -0,0 +1,35 @@ +import FWCore.ParameterSet.Config as cms +from RecoJets.Configuration.RecoJets_cff import * +from RecoJets.Configuration.RecoPFJets_cff import * +from CommonTools.ParticleFlow.pfNoPileUp_cff import * + +GammaJetAnalysis = cms.EDAnalyzer('GammaJetAnalysis', + rhoColl = cms.InputTag("fixedGridRhoFastjetAll"), + PFMETColl = cms.InputTag("pfMet"), + PFMETTYPE1Coll = cms.InputTag("pfType1CorrectedMet"), + photonCollName = cms.string('gedPhotons'), + pfJetCollName = cms.string('ak4PFJetsCHS'), + pfJetCorrName = cms.string('ak4PFCHSL2L3'), + genJetCollName = cms.string('ak4GenJets'), + genParticleCollName = cms.string('genParticles'), + genEventInfoName = cms.string('generator'), + hbheRecHitName = cms.string('hbhereco'), + hfRecHitName = cms.string('hfreco'), + hoRecHitName = cms.string('horeco'), + rootHistFilename = cms.string('PhotonPlusJet_tree.root'), + pvCollName = cms.string('offlinePrimaryVertices'), + prodProcess = cms.untracked.string('reRECO'), + allowNoPhoton = cms.bool(False), + photonJetDPhiMin = cms.double(2.0), # 0.75 pi= 2.356, 0.7 pi=2.2 + photonPtMin = cms.double(15.), + jetEtMin = cms.double(15.), + jet2EtMax = cms.double(100.), + jet3EtMax = cms.double(50.), + photonTriggers = cms.vstring(''), #HLT_Photon20_*, HLT_Photon135*'), + jetTriggers = cms.vstring(''), #HLT_Jet30*'), + writeTriggerPrescale= cms.bool(False), + doPFJets = cms.bool(True), + doGenJets = cms.bool(True), + debug = cms.untracked.int32(0), + workOnAOD = cms.int32(0) + ) diff --git a/Calibration/HcalCalibAlgos/python/hcalHBHEMuon_cfi.py b/Calibration/HcalCalibAlgos/python/hcalHBHEMuon_cfi.py new file mode 100644 index 0000000000000..9c07ff7aa95b2 --- /dev/null +++ b/Calibration/HcalCalibAlgos/python/hcalHBHEMuon_cfi.py @@ -0,0 +1,13 @@ +import FWCore.ParameterSet.Config as cms + +HcalHBHEMuonAnalyzer = cms.EDAnalyzer("HcalHBHEMuonAnalyzer", + HLTriggerResults = cms.InputTag("TriggerResults","","HLT"), + LabelBS = cms.InputTag("offlineBeamSpot"), + LabelVertex = cms.InputTag("offlinePrimaryVertices"), + LabelEBRecHit = cms.InputTag("ecalRecHit","EcalRecHitsEB"), + LabelEERecHit = cms.InputTag("ecalRecHit","EcalRecHitsEE"), + LabelHBHERecHit = cms.InputTag("hbhereco"), + LabelMuon = cms.InputTag("muons"), + Verbosity = cms.untracked.int32(0), + MaxDepth = cms.untracked.int32(4), + ) diff --git a/Calibration/HcalCalibAlgos/python/isoAnalyzer_cfi.py b/Calibration/HcalCalibAlgos/python/isoAnalyzer_cfi.py index e20accd61e3d1..ae69f17c1ff19 100644 --- a/Calibration/HcalCalibAlgos/python/isoAnalyzer_cfi.py +++ b/Calibration/HcalCalibAlgos/python/isoAnalyzer_cfi.py @@ -1,38 +1,32 @@ import FWCore.ParameterSet.Config as cms -# producer for alcaisotrk (HCAL isolated tracks) -from TrackingTools.TrackAssociator.default_cfi import * -from TrackingTools.TrackAssociator.DetIdAssociatorESProducer_cff import * - -TrackAssociatorParameterBlock.TrackAssociatorParameters.EERecHitCollectionLabel = cms.InputTag("IsoProd","IsoTrackEcalRecHitCollection") -TrackAssociatorParameterBlock.TrackAssociatorParameters.EBRecHitCollectionLabel = cms.InputTag("IsoProd","IsoTrackEcalRecHitCollection") -TrackAssociatorParameterBlock.TrackAssociatorParameters.HBHERecHitCollectionLabel = cms.InputTag("IsoProd","IsoTrackHBHERecHitCollection") -TrackAssociatorParameterBlock.TrackAssociatorParameters.HORecHitCollectionLabel = cms.InputTag("IsoProd","IsoTrackHORecHitCollection") - -isoAnalyzer = cms.EDAnalyzer("HcalIsoTrkAnalyzer", - TrackAssociatorParameterBlock, - hbheInput = cms.InputTag("IsoProd:IsoTrackHBHERecHitCollection"), - hoInput = cms.InputTag("IsoProd:IsoTrackHORecHitCollection"), - eInput = cms.InputTag("IsoProd:IsoTrackEcalRecHitCollection"), - HcalIsolTrackInput = cms.InputTag("IsoProd:HcalIsolatedTrackCollection"), - trackInput = cms.InputTag("IsoProd:IsoTrackTracksCollection"), - - outputFileName = cms.string("output_IsoAnalyzer.root"), - AxB = cms.string("Cone"), - calibrationConeSize = cms.double(50.), - associationConeSize = cms.double(60), - EcalCone = cms.double(9.), - EcalConeOuter = cms.double(40.), - hottestHitDistance = cms.double(18.), - - noOfIterations = cms.int32(10), - eventWeight = cms.double(2.0), - energyMinIso = cms.double(10.0), - energyMaxIso = cms.double(1000.0), - energyECALmip = cms.double(1.0), - maxPNear = cms.double(2.0), - MinNTrackHitsBarrel = cms.int32(13), - MinNTECHitsEndcap = cms.int32(11) +HcalIsoTrkAnalyzer = cms.EDAnalyzer("HcalIsoTrkAnalyzer", + TrackLabel = cms.InputTag("generalTracks"), + VertexLabel = cms.InputTag("offlinePrimaryVertices"), + BeamSpotLabel = cms.InputTag("offlineBeamSpot"), + EBRecHitLabel = cms.InputTag("ecalRecHit","EcalRecHitsEB"), + EERecHitLabel = cms.InputTag("ecalRecHit","EcalRecHitsEE"), + HBHERecHitLabel = cms.InputTag("hbhereco"), + TriggerEventLabel = cms.InputTag("hltTriggerSummaryAOD","","HLT"), + TriggerResultLabel= cms.InputTag("TriggerResults","","HLT"), + Triggers = cms.vstring("HLT_IsoTrackHB","HLT_IsoTrackHE"), + TrackQuality = cms.string("highPurity"), + ProcessName = cms.string("HLT"), + L1Filter = cms.string(""), + L2Filter = cms.string("L2Filter"), + L3Filter = cms.string("Filter"), + MinTrackPt = cms.double(10.0), + MaxDxyPV = cms.double(0.02), + MaxDzPV = cms.double(0.02), + MaxChi2 = cms.double(5.0), + MaxDpOverP = cms.double(0.1), + MinOuterHit = cms.int32(4), + MinLayerCrossed = cms.int32(8), + MaxInMiss = cms.int32(0), + MaxOutMiss = cms.int32(0), + ConeRadius = cms.double(34.98), + ConeRadiusMIP = cms.double(14.0), + MinimumTrackP = cms.double(20.0), + MaximumEcalEnergy = cms.double(2.0), + IsolationEnergy = cms.double(2.0), ) - - diff --git a/Calibration/HcalCalibAlgos/python/recAnalyzerMinbias_cfi.py b/Calibration/HcalCalibAlgos/python/recAnalyzerMinbias_cfi.py new file mode 100644 index 0000000000000..b0b00d2b6e074 --- /dev/null +++ b/Calibration/HcalCalibAlgos/python/recAnalyzerMinbias_cfi.py @@ -0,0 +1,9 @@ +import FWCore.ParameterSet.Config as cms + +RecAnalyzerMinbias = cms.EDAnalyzer("RecAnalyzerMinbias", + HistOutFile = cms.untracked.string('analysis_minbias.root'), + hbheInputMB = cms.InputTag("hbherecoMB"), + hfInputMB = cms.InputTag("hfrecoMB"), + Recalib = cms.bool(False), + IgnoreL1 = cms.untracked.bool(False) + ) diff --git a/Calibration/HcalCalibAlgos/python/simAnalyzerMinbias_cfi.py b/Calibration/HcalCalibAlgos/python/simAnalyzerMinbias_cfi.py new file mode 100644 index 0000000000000..7f09f22363aea --- /dev/null +++ b/Calibration/HcalCalibAlgos/python/simAnalyzerMinbias_cfi.py @@ -0,0 +1,6 @@ +import FWCore.ParameterSet.Config as cms + +simAnalyzerMinbias = cms.EDAnalyzer("SimAnalyzerMinbias", + HistOutFile = cms.untracked.string("simOutput.root"), + TimeCut = cms.untracked.double(500), + ) diff --git a/Calibration/HcalCalibAlgos/src/Analyzer_minbias.cc b/Calibration/HcalCalibAlgos/src/Analyzer_minbias.cc index a35d62507f30f..563589867bac1 100644 --- a/Calibration/HcalCalibAlgos/src/Analyzer_minbias.cc +++ b/Calibration/HcalCalibAlgos/src/Analyzer_minbias.cc @@ -11,736 +11,409 @@ #include "Geometry/CaloGeometry/interface/CaloCellGeometry.h" #include "DataFormats/HcalDetId/interface/HcalSubdetector.h" #include "DataFormats/HcalDetId/interface/HcalDetId.h" +#include "DataFormats/L1GlobalTrigger/interface/L1GlobalTriggerReadoutRecord.h" #include "DataFormats/L1GlobalTrigger/interface/L1GtfeWord.h" #include "DataFormats/L1GlobalTrigger/interface/L1GlobalTriggerReadoutRecord.h" #include "DataFormats/L1GlobalTrigger/interface/L1GlobalTriggerRecord.h" #include "DataFormats/L1GlobalTrigger/interface/L1GlobalTriggerObjectMapRecord.h" #include "CondFormats/L1TObjects/interface/L1GtTriggerMenu.h" #include "CondFormats/DataRecord/interface/L1GtTriggerMenuRcd.h" - +#include "DataFormats/FEDRawData/interface/FEDRawData.h" +#include "DataFormats/FEDRawData/interface/FEDRawDataCollection.h" +#include "DataFormats/FEDRawData/interface/FEDNumbering.h" +#include "DataFormats/HcalDigi/interface/HcalCalibrationEventTypes.h" +#include "EventFilter/HcalRawToDigi/interface/HcalDCCHeader.h" #include "TFile.h" #include "TH1.h" #include "TH2.h" #include #include - #include "CondFormats/HcalObjects/interface/HcalRespCorrs.h" #include "CondFormats/DataRecord/interface/HcalRespCorrsRcd.h" -#include "DataFormats/L1GlobalTrigger/interface/L1GlobalTriggerObjectMap.h" -#include "DataFormats/L1GlobalTrigger/interface/L1GlobalTriggerObjectMapRecord.h" -using namespace std; -using namespace reco; -// +#include "DataFormats/Common/interface/TriggerResults.h" +#include "FWCore/Common/interface/TriggerNames.h" + // constructors and destructor -// namespace cms{ -Analyzer_minbias::Analyzer_minbias(const edm::ParameterSet& iConfig) -{ - // get name of output file with histogramms - fOutputFileName = iConfig.getUntrackedParameter("HistOutFile"); - // get names of modules, producing object collections + Analyzer_minbias::Analyzer_minbias(const edm::ParameterSet& iConfig) { + // get name of output file with histogramms + + fOutputFileName = iConfig.getUntrackedParameter("HistOutFile"); + + // get token names of modules, producing object collections + tok_hbherecoMB_ = consumes(iConfig.getParameter("hbheInputMB")); + tok_horecoMB_ = consumes(iConfig.getParameter("hoInputMB")); + tok_hfrecoMB_ = consumes(iConfig.getParameter("hfInputMB")); + + tok_hbherecoNoise_= consumes(iConfig.getParameter("hbheInputNoise")); + tok_horecoNoise_ = consumes(iConfig.getParameter("hoInputNoise")); + tok_hfrecoNoise_ = consumes(iConfig.getParameter("hfInputNoise")); + + theRecalib = iConfig.getParameter("Recalib"); + + tok_hbheNormal_ = consumes(edm::InputTag("hbhereco")); + tok_hltL1GtMap_ = consumes(edm::InputTag("hltL1GtObjectMap")); + } - tok_hbhe_ = consumes(iConfig.getParameter("hbheInputMB")); - tok_ho_ = consumes(iConfig.getParameter("hoInputMB")); - tok_hf_ = consumes(iConfig.getParameter("hfInputMB")); + Analyzer_minbias::~Analyzer_minbias() { } - tok_hbheNoise_ = consumes(iConfig.getParameter("hbheInputNoise")); - tok_hoNoise_ = consumes(iConfig.getParameter("hoInputNoise")); - tok_hfNoise_ = consumes(iConfig.getParameter("hfInputNoise")); - - // this was hardcodded.. - tok_gtRec_ = consumes(edm::InputTag("gtDigisAlCaMB")); - tok_hbheNorm_ = consumes(edm::InputTag("hbhereco")); + void Analyzer_minbias::beginRun( const edm::Run& r, const edm::EventSetup& iSetup) { } - theRecalib = iConfig.getParameter("Recalib"); - -// -// - for(int i=0; i<73; i++) - { - for(int j=0; j<43; j++) - { - noise_min[i][j] = 0.; - noise_pl[i][j] = 0.; - } + void Analyzer_minbias::endRun( const edm::Run& r, const edm::EventSetup& iSetup) { } + + void Analyzer_minbias::beginJob() { + + hOutputFile = new TFile( fOutputFileName.c_str(), "RECREATE" ) ; + + myTree = new TTree("RecJet","RecJet Tree"); + myTree->Branch("mydet", &mydet, "mydet/I"); + myTree->Branch("mysubd", &mysubd, "mysubd/I"); + myTree->Branch("cells", &cells, "cells"); + myTree->Branch("depth", &depth, "depth/I"); + myTree->Branch("ieta", &ieta, "ieta/I"); + myTree->Branch("iphi", &iphi, "iphi/I"); + myTree->Branch("eta", &eta, "eta/F"); + myTree->Branch("phi", &phi, "phi/F"); + myTree->Branch("mom0_MB", &mom0_MB, "mom0_MB/F"); + myTree->Branch("mom1_MB", &mom1_MB, "mom1_MB/F"); + myTree->Branch("mom2_MB", &mom2_MB, "mom2_MB/F"); + myTree->Branch("mom4_MB", &mom4_MB, "mom4_MB/F"); + myTree->Branch("mom0_Noise", &mom0_Noise, "mom0_Noise/F"); + myTree->Branch("mom1_Noise", &mom1_Noise, "mom1_Noise/F"); + myTree->Branch("mom2_Noise", &mom2_Noise, "mom2_Noise/F"); + myTree->Branch("mom4_Noise", &mom4_Noise, "mom4_Noise/F"); + myTree->Branch("mom0_Diff", &mom0_Diff, "mom0_Diff/F"); + myTree->Branch("mom1_Diff", &mom1_Diff, "mom1_Diff/F"); + myTree->Branch("mom2_Diff", &mom2_Diff, "mom2_Diff/F"); + myTree->Branch("occup", &occup, "occup/F"); + myTree->Branch("trigbit", &trigbit, "trigbit/I"); + myTree->Branch("rnnumber", &rnnumber, "rnnumber/D"); + + myMap.clear(); + return ; } -// -// - -} - -Analyzer_minbias::~Analyzer_minbias() -{ - - // do anything here that needs to be done at desctruction time - // (e.g. close files, deallocate resources etc.) - -} - -void Analyzer_minbias::beginRun( const edm::Run& r, const edm::EventSetup& iSetup) -{ - nevent_run = 0; -} -void Analyzer_minbias::endRun( const edm::Run& r, const edm::EventSetup& iSetup) -{ - std::cout<<" Runnumber "<Branch("mydet", &mydet, "mydet/I"); - myTree->Branch("mysubd", &mysubd, "mysubd/I"); - myTree->Branch("depth", &depth, "depth/I"); - myTree->Branch("ieta", &ieta, "ieta/I"); - myTree->Branch("iphi", &iphi, "iphi/I"); - myTree->Branch("eta", &eta, "eta/F"); - myTree->Branch("phi", &phi, "phi/F"); - - myTree->Branch("mom0_MB", &mom0_MB, "mom0_MB/F"); - myTree->Branch("mom1_MB", &mom1_MB, "mom1_MB/F"); - myTree->Branch("mom2_MB", &mom2_MB, "mom2_MB/F"); - myTree->Branch("mom4_MB", &mom4_MB, "mom4_MB/F"); - - myTree->Branch("mom0_Noise", &mom0_Noise, "mom0_Noise/F"); - myTree->Branch("mom1_Noise", &mom1_Noise, "mom1_Noise/F"); - myTree->Branch("mom2_Noise", &mom2_Noise, "mom2_Noise/F"); - myTree->Branch("mom4_Noise", &mom4_Noise, "mom4_Noise/F"); - - myTree->Branch("mom0_Diff", &mom0_Diff, "mom0_Diff/F"); - myTree->Branch("mom1_Diff", &mom1_Diff, "mom1_Diff/F"); - myTree->Branch("mom2_Diff", &mom2_Diff, "mom2_Diff/F"); - - myTree->Branch("occup", &occup, "occup/F"); - - std::cout<<" Before ordering Histos "<,myInfo>::const_iterator itr=myMap.begin(); itr != myMap.end(); ++itr) { + int h = itr->first.first; + LogDebug("AnalyzerMB") << "Fired trigger bit number " << h; + int i = itr->first.second.subdet(); + int j = itr->first.second.depth(); + int k = itr->first.second.iphi(); + int l = itr->first.second.ieta(); + myInfo info = itr->second; + if (info.theMB0 > 0) { + mom0_MB = info.theMB0; + mom1_MB = info.theMB1; + mom2_MB = info.theMB2; + mom4_MB = info.theMB4; + mom0_Noise = info.theNS0; + mom1_Noise = info.theNS1; + mom2_Noise = info.theNS2; + mom4_Noise = info.theNS4; + mom0_Diff = info.theDif0; + mom1_Diff = info.theDif1; + mom2_Diff = info.theDif2; + rnnumber = info.runcheck; + trigbit= h; + mysubd = i; + depth = j; + ieta = l; + iphi = k; + + LogDebug("AnalyzerMB") << " Result= " << trigbit << " " << mysubd + << " " << ieta << " " << iphi << " mom0 " + << mom0_MB << " mom1 " << mom1_MB << " mom2 " + << mom2_MB << " mom4 " << mom4_MB + << " mom0_Noise " << mom0_Noise << " mom1_Noise " + << mom1_Noise << " mom2_Noise " << mom2_Noise + << " mom4_Noise " << mom4_Noise << " mom0_Diff " + << mom0_Diff << " mom1_Diff " << mom1_Diff + << " mom2_Diff " << mom2_Diff; + myTree->Fill(); + ii++; + } } - else - { -// HF -// first order moment -// cout<<" "<Write(); + hOutputFile->cd(); + myTree->Write(); + hOutputFile->Close() ; + return ; + } + // + // member functions + // + + // ------------ method called to produce the data ------------ + + void Analyzer_minbias::analyze(const edm::Event& iEvent, const edm::EventSetup& iSetup) { - - std::cout<<" After ordering Histos "< recalibCorrs; + iSetup.get().get("recalibrate",recalibCorrs); + myRecalib = recalibCorrs.product(); + } // theRecalib + + // Noise part for HB HE + + std::map,myInfo> tmpMap; + tmpMap.clear(); + + edm::Handle hbheNormal; + iEvent.getByToken(tok_hbheNormal_, hbheNormal); + if (!hbheNormal.isValid()) { + edm::LogInfo("AnalyzerMB") << " hbheNormal failed"; + } else { + LogDebug("AnalyzerMB") << " The size of the normal collection " + << hbheNormal->size(); + } + edm::Handle hbheNS; + iEvent.getByToken(tok_hbherecoNoise_, hbheNS); + if (!hbheNS.isValid()) { + edm::LogInfo("AnalyzerMB") << "HcalCalibAlgos: Error! can't get hbhe product!"; + return ; } - } - return ; -} -// -// EndJob -// -void Analyzer_minbias::endJob() -{ - int ii=0; - - for (int i=1; i<5;i++) - { - for (int j=1; j<5;j++) - { - for (int k=1; k<73;k++) - { - for (int l=1; l<43;l++) - { - if(theMBFillDetMapPl0[i][j][k][l] > 0) - { - mom0_MB = theMBFillDetMapPl0[i][j][k][l]; - mom1_MB = theMBFillDetMapPl1[i][j][k][l]; - mom2_MB = theMBFillDetMapPl2[i][j][k][l]; - mom4_MB = theMBFillDetMapPl4[i][j][k][l]; - mom0_Noise = theNSFillDetMapPl0[i][j][k][l]; - mom1_Noise = theNSFillDetMapPl1[i][j][k][l]; - mom2_Noise = theNSFillDetMapPl2[i][j][k][l]; - mom4_Noise = theNSFillDetMapPl4[i][j][k][l]; - mom0_Diff = theDFFillDetMapPl0[i][j][k][l]; - mom1_Diff = theDFFillDetMapPl1[i][j][k][l]; - mom2_Diff = theDFFillDetMapPl2[i][j][k][l]; - - mysubd = i; - depth = j; - ieta = l; - iphi = k; - cout<<" Result Plus= "<Fill(); - ii++; - } // Pl > 0 - - - if(theMBFillDetMapMin0[i][j][k][l] > 0) - { - mom0_MB = theMBFillDetMapMin0[i][j][k][l]; - mom1_MB = theMBFillDetMapMin1[i][j][k][l]; - mom2_MB = theMBFillDetMapMin2[i][j][k][l]; - mom4_MB = theMBFillDetMapMin4[i][j][k][l]; - mom0_Noise = theNSFillDetMapMin0[i][j][k][l]; - mom1_Noise = theNSFillDetMapMin1[i][j][k][l]; - mom2_Noise = theNSFillDetMapMin2[i][j][k][l]; - mom4_Noise = theNSFillDetMapMin4[i][j][k][l]; - mom0_Diff = theDFFillDetMapMin0[i][j][k][l]; - mom1_Diff = theDFFillDetMapMin1[i][j][k][l]; - mom2_Diff = theDFFillDetMapMin2[i][j][k][l]; - - - mysubd = i; - depth = j; - ieta = -1*l; - iphi = k; - cout<<" Result Minus= "<Fill(); - ii++; - - } // Min>0 - } // ieta - } // iphi - } // depth - } //subd - - - - cout<<" Number of cells "<Write(); - - hOutputFile->cd(); - - myTree->Write(); - - hHBHEsize_vs_run->Write() ; - hHFsize_vs_run->Write() ; - - for(int i=1;i<73;i++){ - for(int j=1;j<43;j++){ - hCalo1[i][j]->Write(); - hCalo2[i][j]->Write(); - hCalo1mom2[i][j]->Write(); - hCalo2mom2[i][j]->Write(); - } - } - - hbheNoiseE->Write() ; - hfNoiseE->Write() ; - hbheSignalE->Write() ; - hfSignalE->Write() ; - - - hOutputFile->Close() ; - - cout<<" File is closed "< theProvenance; - iEvent.getAllProvenance(theProvenance); - - for( std::vector::const_iterator ip = theProvenance.begin(); - ip != theProvenance.end(); ip++) - { - cout<<" Print all module/label names "<<(**ip).moduleName()<<" "<<(**ip).moduleLabel()<< - " "<<(**ip).productInstanceName()< menuRcd; - iSetup.get().get(menuRcd) ; - const L1GtTriggerMenu* menu = menuRcd.product(); - const AlgorithmMap& bitMap = menu->gtAlgorithmMap(); - - edm::Handle gtRecord; - iEvent.getByToken(tok_gtRec_, gtRecord); - - if (!gtRecord.isValid()) { - -// LogDebug("L1GlobalTriggerRecordProducer") -// << "\n\n Error: no L1GlobalTriggerReadoutRecord found with input tag " -// << m_l1GtReadoutRecord -// << "\n Returning empty L1GlobalTriggerRecord.\n\n" -// << std::endl; - cout<<" No L1 trigger record "<decisionWord(); - - for (CItAlgo itAlgo = bitMap.begin(); itAlgo != bitMap.end(); itAlgo++) - { - bool decision=menu->gtAlgorithmResult(itAlgo->first,dWord); - if(decision == 1) std::cout<<" Trigger "<first<<" "< recalibCorrs; - iSetup.get().get("recalibrate",recalibCorrs); - myRecalib = recalibCorrs.product(); -// end - } // theRecalib - -// Noise part for HB HE - - double tmpNSFillDetMapPl1[5][5][73][43]; - double tmpNSFillDetMapMin1[5][5][73][43]; - - for (int i=0; i<5;i++) - { - for (int j=0; j<5;j++) - { - for (int k=0; k<73;k++) - { - for (int l=0; l<43;l++) - { - tmpNSFillDetMapPl1[i][j][k][l] = 0.; - tmpNSFillDetMapMin1[i][j][k][l] = 0.; - } - } + + edm::Handle hbheMB; + iEvent.getByToken(tok_hbherecoMB_, hbheMB); + + if (!hbheMB.isValid()) { + edm::LogInfo("AnalyzerMB") << "HcalCalibAlgos: Error! can't get hbhe product!"; + return ; } - } - edm::Handle hbheNormal; - iEvent.getByToken(tok_hbheNorm_, hbheNormal); - if(!hbheNormal.isValid()){ - cout<<" hbheNormal failed "<size()< hbheNS; - iEvent.getByToken(tok_hbheNoise_, hbheNS); - - - if(!hbheNS.isValid()){ - LogDebug("") << "HcalCalibAlgos: Error! can't get hbhe product!" << std::endl; - cout<<" No HBHE MS "<Fill(rnnum,(float)HithbheNS.size()); - - if(HithbheNS.size()!= 5184) { - cout<<" HBHE problem "< hbheMB; - iEvent.getByToken(tok_hbhe_, hbheMB); - - if(!hbheMB.isValid()){ - LogDebug("") << "HcalCalibAlgos: Error! can't get hbhe product!" << std::endl; - cout<<" No HBHE MB"< hfNS; - iEvent.getByToken(tok_hfNoise_, hfNS); - - if(!hfNS.isValid()){ - LogDebug("") << "HcalCalibAlgos: Error! can't get hbhe product!" << std::endl; - cout<<" No HF NS "<Fill(rnnum,(float)HithfNS.size()); - if(HithfNS.size()!= 1728) { - cout<<" HF problem "< hfMB; - iEvent.getByToken(tok_hf_, hfMB); - - if(!hfMB.isValid()){ - LogDebug("") << "HcalCalibAlgos: Error! can't get hbhe product!" << std::endl; - cout<<" No HBHE MB"<id().rawId(); - if( theRecalib ) icalconst=myRecalib->getValues(mydetid)->getValue(); - HBHERecHit aHit(hbheItr->id(),hbheItr->energy()*icalconst,hbheItr->time()); - - double energyhit = aHit.energy(); - - DetId id = (*hbheItr).detid(); - HcalDetId hid=HcalDetId(id); - - - - int mysu = ((hid).rawId()>>25)&0x7; - if( hid.ieta() > 0 ) { - theNSFillDetMapPl0[mysu][hid.depth()][hid.iphi()][hid.ieta()] = theNSFillDetMapPl0[mysu][hid.depth()][hid.iphi()][hid.ieta()]+ 1.; - theNSFillDetMapPl1[mysu][hid.depth()][hid.iphi()][hid.ieta()] = theNSFillDetMapPl1[mysu][hid.depth()][hid.iphi()][hid.ieta()]+energyhit; - theNSFillDetMapPl2[mysu][hid.depth()][hid.iphi()][hid.ieta()] = theNSFillDetMapPl2[mysu][hid.depth()][hid.iphi()][hid.ieta()]+pow(energyhit,2); - theNSFillDetMapPl4[mysu][hid.depth()][hid.iphi()][hid.ieta()] = theNSFillDetMapPl4[mysu][hid.depth()][hid.iphi()][hid.ieta()]+pow(energyhit,4); - - tmpNSFillDetMapPl1[mysu][hid.depth()][hid.iphi()][hid.ieta()] = energyhit; - - - } else { - theNSFillDetMapMin0[mysu][hid.depth()][hid.iphi()][abs(hid.ieta())] = theNSFillDetMapMin0[mysu][hid.depth()][hid.iphi()][abs(hid.ieta())]+ 1.; - theNSFillDetMapMin1[mysu][hid.depth()][hid.iphi()][abs(hid.ieta())] = theNSFillDetMapMin1[mysu][hid.depth()][hid.iphi()][abs(hid.ieta())]+energyhit; - theNSFillDetMapMin2[mysu][hid.depth()][hid.iphi()][abs(hid.ieta())] = theNSFillDetMapMin2[mysu][hid.depth()][hid.iphi()][abs(hid.ieta())]+pow(energyhit,2); - theNSFillDetMapMin4[mysu][hid.depth()][hid.iphi()][abs(hid.ieta())] = theNSFillDetMapMin4[mysu][hid.depth()][hid.iphi()][abs(hid.ieta())]+pow(energyhit,4); - - - tmpNSFillDetMapMin1[mysu][hid.depth()][hid.iphi()][hid.ieta()] = energyhit; - - } - - if(hid.depth() == 1) { - hbheNoiseE->Fill(energyhit); - - if(energyhit<-2.) std::cout<<" Run "< 0 ) { - // hCalo1[hid.iphi()][hid.ieta()]->Fill(energyhit-noise_pl[hid.iphi()][hid.ieta()]); - // hCalo1mom2[hid.iphi()][hid.ieta()]->Fill(pow(energyhit,2)); - // } else { - // hCalo2[hid.iphi()][abs(hid.ieta())]->Fill(energyhit-noise_min[hid.iphi()][abs(hid.ieta())]); - // hCalo2mom2[hid.iphi()][abs(hid.ieta())]->Fill(pow(energyhit,2)); - // } // eta><0 - - } // depth=1 - - - } // HBHE_NS - - -// Signal part for HB HE - - - for(HBHERecHitCollection::const_iterator hbheItr=HithbheMB.begin(); hbheItr!=HithbheMB.end(); hbheItr++) - { -// Recalibration of energy - float icalconst=1.; - DetId mydetid = hbheItr->id().rawId(); - if( theRecalib ) icalconst=myRecalib->getValues(mydetid)->getValue(); + const HBHERecHitCollection HithbheMB = *(hbheMB.product()); + LogDebug("AnalyzerMB") << "HBHE MB size of collection " << HithbheMB.size(); + if(HithbheMB.size() < 5100) { + edm::LogInfo("AnalyzerMB") << "HBHE problem " << rnnum << " size " + << HithbheMB.size(); + return; + } - HBHERecHit aHit(hbheItr->id(),hbheItr->energy()*icalconst,hbheItr->time()); - - double energyhit = aHit.energy(); - - DetId id = (*hbheItr).detid(); - HcalDetId hid=HcalDetId(id); - - int mysu = ((hid).rawId()>>25)&0x7; - if( hid.ieta() > 0 ) { - theMBFillDetMapPl0[mysu][hid.depth()][hid.iphi()][hid.ieta()] = theMBFillDetMapPl0[mysu][hid.depth()][hid.iphi()][hid.ieta()]+ 1.; - theMBFillDetMapPl1[mysu][hid.depth()][hid.iphi()][hid.ieta()] = theMBFillDetMapPl1[mysu][hid.depth()][hid.iphi()][hid.ieta()]+energyhit; - theMBFillDetMapPl2[mysu][hid.depth()][hid.iphi()][hid.ieta()] = theMBFillDetMapPl2[mysu][hid.depth()][hid.iphi()][hid.ieta()]+pow(energyhit,2); - theMBFillDetMapPl4[mysu][hid.depth()][hid.iphi()][hid.ieta()] = theMBFillDetMapPl4[mysu][hid.depth()][hid.iphi()][hid.ieta()]+pow(energyhit,4); - float mydiff = energyhit - tmpNSFillDetMapPl1[mysu][hid.depth()][hid.iphi()][hid.ieta()]; - - - theDFFillDetMapPl1[mysu][hid.depth()][hid.iphi()][hid.ieta()] = theDFFillDetMapPl1[mysu][hid.depth()][hid.iphi()][hid.ieta()]+mydiff; - theDFFillDetMapPl2[mysu][hid.depth()][hid.iphi()][hid.ieta()] = theDFFillDetMapPl2[mysu][hid.depth()][hid.iphi()][hid.ieta()]+pow(mydiff,2); - } else { - theMBFillDetMapMin0[mysu][hid.depth()][hid.iphi()][abs(hid.ieta())] = theMBFillDetMapMin0[mysu][hid.depth()][hid.iphi()][abs(hid.ieta())]+ 1.; - theMBFillDetMapMin1[mysu][hid.depth()][hid.iphi()][abs(hid.ieta())] = theMBFillDetMapMin1[mysu][hid.depth()][hid.iphi()][abs(hid.ieta())]+energyhit; - theMBFillDetMapMin2[mysu][hid.depth()][hid.iphi()][abs(hid.ieta())] = theMBFillDetMapMin2[mysu][hid.depth()][hid.iphi()][abs(hid.ieta())]+pow(energyhit,2); - theMBFillDetMapMin4[mysu][hid.depth()][hid.iphi()][abs(hid.ieta())] = theMBFillDetMapMin4[mysu][hid.depth()][hid.iphi()][abs(hid.ieta())]+pow(energyhit,4); - - - float mydiff = energyhit - tmpNSFillDetMapMin1[mysu][hid.depth()][hid.iphi()][hid.ieta()]; - theDFFillDetMapMin1[mysu][hid.depth()][hid.iphi()][hid.ieta()] = theDFFillDetMapMin1[mysu][hid.depth()][hid.iphi()][hid.ieta()]+mydiff; - theDFFillDetMapMin2[mysu][hid.depth()][hid.iphi()][hid.ieta()] = theDFFillDetMapMin2[mysu][hid.depth()][hid.iphi()][hid.ieta()]+pow(mydiff,2); - } - - - if(hid.depth() == 1) { - - hbheSignalE->Fill(energyhit); - - if( hid.ieta() > 0 ) { - hCalo1[hid.iphi()][hid.ieta()]->Fill(energyhit); - hCalo1mom2[hid.iphi()][hid.ieta()]->Fill(pow(energyhit,2)); - } else { - hCalo2[hid.iphi()][abs(hid.ieta())]->Fill(energyhit); - hCalo2mom2[hid.iphi()][abs(hid.ieta())]->Fill(pow(energyhit,2)); - } // eta><0 - - } // depth=1 - - - } // HBHE_MB - -// HF - - for(HFRecHitCollection::const_iterator hbheItr=HithfNS.begin(); hbheItr!=HithfNS.end(); hbheItr++) - { -// Recalibration of energy - float icalconst=1.; - DetId mydetid = hbheItr->id().rawId(); - if( theRecalib ) icalconst=myRecalib->getValues(mydetid)->getValue(); + edm::Handle hfNS; + iEvent.getByToken(tok_hfrecoNoise_, hfNS); - HFRecHit aHit(hbheItr->id(),hbheItr->energy()*icalconst,hbheItr->time()); - - double energyhit = aHit.energy(); -// -// Remove PMT hits -// - if(fabs(energyhit) > 40. ) continue; - - DetId id = (*hbheItr).detid(); - HcalDetId hid=HcalDetId(id); - - int mysu = ((hid).rawId()>>25)&0x7; - if( hid.ieta() > 0 ) { - theNSFillDetMapPl0[mysu][hid.depth()][hid.iphi()][hid.ieta()] = theNSFillDetMapPl0[mysu][hid.depth()][hid.iphi()][hid.ieta()]+ 1.; - theNSFillDetMapPl1[mysu][hid.depth()][hid.iphi()][hid.ieta()] = theNSFillDetMapPl1[mysu][hid.depth()][hid.iphi()][hid.ieta()]+energyhit; - theNSFillDetMapPl2[mysu][hid.depth()][hid.iphi()][hid.ieta()] = theNSFillDetMapPl2[mysu][hid.depth()][hid.iphi()][hid.ieta()]+pow(energyhit,2); - theNSFillDetMapPl4[mysu][hid.depth()][hid.iphi()][hid.ieta()] = theNSFillDetMapPl4[mysu][hid.depth()][hid.iphi()][hid.ieta()]+pow(energyhit,4); - - tmpNSFillDetMapPl1[mysu][hid.depth()][hid.iphi()][hid.ieta()] = energyhit; - - - } else { - theNSFillDetMapMin0[mysu][hid.depth()][hid.iphi()][abs(hid.ieta())] = theNSFillDetMapMin0[mysu][hid.depth()][hid.iphi()][abs(hid.ieta())]+ 1.; - theNSFillDetMapMin1[mysu][hid.depth()][hid.iphi()][abs(hid.ieta())] = theNSFillDetMapMin1[mysu][hid.depth()][hid.iphi()][abs(hid.ieta())]+energyhit; - theNSFillDetMapMin2[mysu][hid.depth()][hid.iphi()][abs(hid.ieta())] = theNSFillDetMapMin2[mysu][hid.depth()][hid.iphi()][abs(hid.ieta())]+pow(energyhit,2); - theNSFillDetMapMin4[mysu][hid.depth()][hid.iphi()][abs(hid.ieta())] = theNSFillDetMapMin4[mysu][hid.depth()][hid.iphi()][abs(hid.ieta())]+pow(energyhit,4); - - - tmpNSFillDetMapMin1[mysu][hid.depth()][hid.iphi()][hid.ieta()] = energyhit; - - } - - if(hid.depth() == 1) { - hfNoiseE->Fill(energyhit); - - //if( hid.ieta() > 0 ) { - // hCalo1[hid.iphi()][hid.ieta()]->Fill(energyhit-noise_pl[hid.iphi()][hid.ieta()]); - // hCalo1mom2[hid.iphi()][hid.ieta()]->Fill(pow(energyhit,2)); - //} else { - // hCalo2[hid.iphi()][abs(hid.ieta())]->Fill(energyhit-noise_min[hid.iphi()][abs(hid.ieta())]); - // hCalo2mom2[hid.iphi()][abs(hid.ieta())]->Fill(pow(energyhit,2)); - //} // eta><0 - - } // depth=1 - - } // HBHE_NS - - -// Signal part for HB HE - - for(HFRecHitCollection::const_iterator hbheItr=HithfMB.begin(); hbheItr!=HithfMB.end(); hbheItr++) - { -// Recalibration of energy - float icalconst=1.; - DetId mydetid = hbheItr->id().rawId(); - if( theRecalib ) icalconst=myRecalib->getValues(mydetid)->getValue(); + if (!hfNS.isValid()) { + edm::LogInfo("AnalyzerMB") << "HcalCalibAlgos: Error! can't get hbhe product!"; + return ; + } - HFRecHit aHit(hbheItr->id(),hbheItr->energy()*icalconst,hbheItr->time()); - - double energyhit = aHit.energy(); -// -// Remove PMT hits -// - if(fabs(energyhit) > 40. ) continue; - - DetId id = (*hbheItr).detid(); - HcalDetId hid=HcalDetId(id); - - int mysu = ((hid).rawId()>>25)&0x7; - if( hid.ieta() > 0 ) { - theMBFillDetMapPl0[mysu][hid.depth()][hid.iphi()][hid.ieta()] = theMBFillDetMapPl0[mysu][hid.depth()][hid.iphi()][hid.ieta()]+ 1.; - theMBFillDetMapPl1[mysu][hid.depth()][hid.iphi()][hid.ieta()] = theMBFillDetMapPl1[mysu][hid.depth()][hid.iphi()][hid.ieta()]+energyhit; - theMBFillDetMapPl2[mysu][hid.depth()][hid.iphi()][hid.ieta()] = theMBFillDetMapPl2[mysu][hid.depth()][hid.iphi()][hid.ieta()]+pow(energyhit,2); - theMBFillDetMapPl4[mysu][hid.depth()][hid.iphi()][hid.ieta()] = theMBFillDetMapPl4[mysu][hid.depth()][hid.iphi()][hid.ieta()]+pow(energyhit,4); - - - theDFFillDetMapPl1[mysu][hid.depth()][hid.iphi()][hid.ieta()] = theDFFillDetMapPl1[mysu][hid.depth()][hid.iphi()][hid.ieta()]+energyhit-tmpNSFillDetMapPl1[mysu][hid.depth()][hid.iphi()][hid.ieta()]; - theDFFillDetMapPl2[mysu][hid.depth()][hid.iphi()][hid.ieta()] = - theDFFillDetMapPl2[mysu][hid.depth()][hid.iphi()][hid.ieta()]+pow((energyhit-tmpNSFillDetMapPl1[mysu][hid.depth()][hid.iphi()][hid.ieta()]),2); - } else { - theMBFillDetMapMin0[mysu][hid.depth()][hid.iphi()][abs(hid.ieta())] = theMBFillDetMapMin0[mysu][hid.depth()][hid.iphi()][abs(hid.ieta())]+ 1.; - theMBFillDetMapMin1[mysu][hid.depth()][hid.iphi()][abs(hid.ieta())] = theMBFillDetMapMin1[mysu][hid.depth()][hid.iphi()][abs(hid.ieta())]+energyhit; - theMBFillDetMapMin2[mysu][hid.depth()][hid.iphi()][abs(hid.ieta())] = theMBFillDetMapMin2[mysu][hid.depth()][hid.iphi()][abs(hid.ieta())]+pow(energyhit,2); - theMBFillDetMapMin4[mysu][hid.depth()][hid.iphi()][abs(hid.ieta())] = theMBFillDetMapMin4[mysu][hid.depth()][hid.iphi()][abs(hid.ieta())]+pow(energyhit,4); - - theDFFillDetMapMin1[mysu][hid.depth()][hid.iphi()][hid.ieta()] = theDFFillDetMapMin1[mysu][hid.depth()][hid.iphi()][hid.ieta()]+energyhit-tmpNSFillDetMapMin1[mysu][hid.depth()][hid.iphi()][hid.ieta()]; - theDFFillDetMapMin2[mysu][hid.depth()][hid.iphi()][hid.ieta()] = - theDFFillDetMapMin2[mysu][hid.depth()][hid.iphi()][hid.ieta()]+pow((energyhit-tmpNSFillDetMapMin1[mysu][hid.depth()][hid.iphi()][hid.ieta()]),2); - } - - - if(hid.depth() == 1) { - hfSignalE->Fill(energyhit); + const HFRecHitCollection HithfNS = *(hfNS.product()); + LogDebug("AnalyzerMB") << "HF NS size of collection "<< HithfNS.size(); + if (HithfNS.size() < 1700) { + edm::LogInfo("AnalyzerMB") << "HF problem " << rnnum << " size " + << HithfNS.size(); + return; + } + + edm::Handle hfMB; + iEvent.getByToken(tok_hfrecoMB_, hfMB); + + if (!hfMB.isValid()) { + edm::LogInfo("AnalyzerMB") << "HcalCalibAlgos: Error! can't get hbhe product!"; + return ; + } + + const HFRecHitCollection HithfMB = *(hfMB.product()); + LogDebug("AnalyzerMB") << "HF MB size of collection " << HithfMB.size(); + if(HithfMB.size() < 1700) { + edm::LogInfo("AnalyzerMB") << "HF problem " << rnnum << " size " + < gtObjectMapRecord; + iEvent.getByToken(tok_hltL1GtMap_, gtObjectMapRecord); + + if (gtObjectMapRecord.isValid()) { + const std::vector& objMapVec = gtObjectMapRecord->gtObjectMap(); + int ii(0); + bool ok(false); + for (std::vector::const_iterator itMap = objMapVec.begin(); + itMap != objMapVec.end(); ++itMap, ++ii) { + float algoBit = (*itMap).algoBitNumber(); + bool resultGt = (*itMap).algoGtlResult(); + std::string algoNameStr = (*itMap).algoName(); + + if (resultGt == 1) { + ok = true; + for(HBHERecHitCollection::const_iterator hbheItr=HithbheNS.begin(); hbheItr!=HithbheNS.end(); hbheItr++) { - if( hid.ieta() > 0 ) - { - hCalo1[hid.iphi()][hid.ieta()]->Fill(energyhit); - hCalo1mom2[hid.iphi()][hid.ieta()]->Fill(pow(energyhit,2)); - } else - { - hCalo2[hid.iphi()][abs(hid.ieta())]->Fill(energyhit); - hCalo2mom2[hid.iphi()][abs(hid.ieta())]->Fill(pow(energyhit,2)); - } // eta><0 - - } // depth=1 - - } // HF_MB - - std::cout<<" Event is finished "<id().rawId(); + if( theRecalib ) icalconst=myRecalib->getValues(mydetid)->getValue(); + + HBHERecHit aHit(hbheItr->id(),hbheItr->energy()*icalconst,hbheItr->time()); + + double energyhit = aHit.energy(); + + DetId id = (*hbheItr).detid(); + HcalDetId hid=HcalDetId(id); + std::map,myInfo>::iterator itr1 = myMap.find(std::pair(algoBit,hid)); + if (itr1 == myMap.end()) { + myInfo info; + myMap[std::pair(algoBit,hid)] = info; + itr1 = myMap.find(std::pair(algoBit,hid)); + } + itr1->second.theNS0++; + itr1->second.theNS1 += energyhit; + itr1->second.theNS2 += (energyhit*energyhit); + itr1->second.theNS4 += (energyhit*energyhit*energyhit*energyhit); + itr1->second.runcheck = rnnum; + + std::map,myInfo>::iterator itr2 = tmpMap.find(std::pair(algoBit,hid)); + if (itr2 == tmpMap.end()) { + myInfo info; + tmpMap[std::pair(algoBit,hid)] = info; + itr2 = tmpMap.find(std::pair(algoBit,hid)); + } + itr2->second.theNS0++; + itr2->second.theNS1 += energyhit; + itr2->second.theNS2 += (energyhit*energyhit); + itr2->second.theNS4 += (energyhit*energyhit*energyhit*energyhit); + itr2->second.runcheck = rnnum; + + } // HBHE_NS + + // Signal part for HB HE + + for (HBHERecHitCollection::const_iterator hbheItr=HithbheMB.begin(); hbheItr!=HithbheMB.end(); hbheItr++) { + // Recalibration of energy + float icalconst=1.; + DetId mydetid = hbheItr->id().rawId(); + if( theRecalib ) icalconst=myRecalib->getValues(mydetid)->getValue(); + + HBHERecHit aHit(hbheItr->id(),hbheItr->energy()*icalconst,hbheItr->time()); + double energyhit = aHit.energy(); + + DetId id = (*hbheItr).detid(); + HcalDetId hid=HcalDetId(id); + + std::map,myInfo>::iterator itr1 = myMap.find(std::pair(algoBit,hid)); + std::map,myInfo>::iterator itr2 = tmpMap.find(std::pair(algoBit,hid)); + + if (itr1 == myMap.end()) { + myInfo info; + myMap[std::pair(algoBit,hid)] = info; + itr1 = myMap.find(std::pair(algoBit,hid)); + } + itr1->second.theMB0++; + itr1->second.theDif0 = 0; + itr1->second.theMB1 += energyhit; + itr1->second.theMB2 += (energyhit*energyhit); + itr1->second.theMB4 += (energyhit*energyhit*energyhit*energyhit); + itr1->second.runcheck = rnnum; + float mydiff = 0.0; + if (itr2 !=tmpMap.end()) { + mydiff = energyhit - (itr2->second.theNS1); + itr1->second.theDif0++; + itr1->second.theDif1 += mydiff; + itr1->second.theDif2 += (mydiff*mydiff); + } + } // HBHE_MB + + // HF + + for (HFRecHitCollection::const_iterator hbheItr=HithfNS.begin(); hbheItr!=HithfNS.end(); hbheItr++) { + // Recalibration of energy + float icalconst=1.; + DetId mydetid = hbheItr->id().rawId(); + if( theRecalib ) icalconst=myRecalib->getValues(mydetid)->getValue(); + + HFRecHit aHit(hbheItr->id(),hbheItr->energy()*icalconst,hbheItr->time()); + double energyhit = aHit.energy(); + // Remove PMT hits + if(fabs(energyhit) > 40. ) continue; + + DetId id = (*hbheItr).detid(); + HcalDetId hid=HcalDetId(id); + + std::map,myInfo>::iterator itr1 = myMap.find(std::pair(algoBit,hid)); + + if (itr1 == myMap.end()) { + myInfo info; + myMap[std::pair(algoBit,hid)] = info; + itr1 = myMap.find(std::pair(algoBit,hid)); + } + itr1->second.theNS0++; + itr1->second.theNS1 += energyhit; + itr1->second.theNS2 += (energyhit*energyhit); + itr1->second.theNS4 += (energyhit*energyhit*energyhit*energyhit); + itr1->second.runcheck = rnnum; + + std::map,myInfo>::iterator itr2 = tmpMap.find(std::pair(algoBit,hid)); + if (itr2 == tmpMap.end()) { + myInfo info; + tmpMap[std::pair(algoBit,hid)] = info; + itr2 = tmpMap.find(std::pair(algoBit,hid)); + } + itr2->second.theNS0++; + itr2->second.theNS1 += energyhit; + itr2->second.theNS2 += (energyhit*energyhit); + itr2->second.theNS4 += (energyhit*energyhit*energyhit*energyhit); + itr2->second.runcheck = rnnum; + + } // HF_NS + + + // Signal part for HF + + for (HFRecHitCollection::const_iterator hbheItr=HithfMB.begin(); hbheItr!=HithfMB.end(); hbheItr++) { + // Recalibration of energy + float icalconst=1.; + DetId mydetid = hbheItr->id().rawId(); + if( theRecalib ) icalconst=myRecalib->getValues(mydetid)->getValue(); + HFRecHit aHit(hbheItr->id(),hbheItr->energy()*icalconst,hbheItr->time()); + + double energyhit = aHit.energy(); + // Remove PMT hits + if(fabs(energyhit) > 40. ) continue; + + DetId id = (*hbheItr).detid(); + HcalDetId hid=HcalDetId(id); + + std::map,myInfo>::iterator itr1 = myMap.find(std::pair(algoBit,hid)); + std::map,myInfo>::iterator itr2 = tmpMap.find(std::pair(algoBit,hid)); + + if (itr1 == myMap.end()) { + myInfo info; + myMap[std::pair(algoBit,hid)] = info; + itr1 = myMap.find(std::pair(algoBit,hid)); + } + itr1->second.theMB0++; + itr1->second.theDif0 = 0; + itr1->second.theMB1 += energyhit; + itr1->second.theMB2 += (energyhit*energyhit); + itr1->second.theMB4 += (energyhit*energyhit*energyhit*energyhit); + itr1->second.runcheck = rnnum; + float mydiff = 0.0; + if (itr2 !=tmpMap.end()) { + mydiff = energyhit - (itr2->second.theNS1); + itr1->second.theDif0++; + itr1->second.theDif1 += mydiff; + itr1->second.theDif2 += (mydiff*mydiff); + } + } + } + } + if (!ok) LogDebug("AnalyzerMB") << "No passed L1 Triggers"; + } + } } -//define this as a plug-in -//DEFINE_ANOTHER_FWK_MODULE(Analyzer_minbias) - diff --git a/Calibration/HcalCalibAlgos/src/DiJetAnalyzer.cc b/Calibration/HcalCalibAlgos/src/DiJetAnalyzer.cc index ad03df68ddf34..a593594553153 100644 --- a/Calibration/HcalCalibAlgos/src/DiJetAnalyzer.cc +++ b/Calibration/HcalCalibAlgos/src/DiJetAnalyzer.cc @@ -1,271 +1,1296 @@ +// +// DiJetAnalyzer.cc +// +// description: Create an ntuple necessary for dijet balance calibration for the HCAL +// + #include "Calibration/HcalCalibAlgos/interface/DiJetAnalyzer.h" -#include "DataFormats/GeometryVector/interface/GlobalPoint.h" -#include "Geometry/Records/interface/CaloGeometryRecord.h" +DiJetAnalyzer::DiJetAnalyzer(const edm::ParameterSet& iConfig) +{ + // set parameters + pfJetCollName_ = iConfig.getParameter("pfJetCollName"); + pfJetCorrName_ = iConfig.getParameter("pfJetCorrName"); + hbheRecHitName_ = iConfig.getParameter("hbheRecHitName"); + hfRecHitName_ = iConfig.getParameter("hfRecHitName"); + hoRecHitName_ = iConfig.getParameter("hoRecHitName"); + pvCollName_ = iConfig.getParameter("pvCollName"); + rootHistFilename_ = iConfig.getParameter("rootHistFilename"); + maxDeltaEta_ = iConfig.getParameter("maxDeltaEta"); + minTagJetEta_ = iConfig.getParameter("minTagJetEta"); + maxTagJetEta_ = iConfig.getParameter("maxTagJetEta"); + minSumJetEt_ = iConfig.getParameter("minSumJetEt"); + minJetEt_ = iConfig.getParameter("minJetEt"); + maxThirdJetEt_ = iConfig.getParameter("maxThirdJetEt"); + debug_ = iConfig.getUntrackedParameter("debug", false); -#include "DataFormats/JetReco/interface/CaloJet.h" -#include "DataFormats/CaloTowers/interface/CaloTowerDetId.h" -#include "DataFormats/HcalDetId/interface/HcalDetId.h" -#include "DataFormats/DetId/interface/DetId.h" + tok_PFJet_ = consumes(pfJetCollName_); + tok_HBHE_ = consumes > >(hbheRecHitName_); + tok_HF_ = consumes > >(hfRecHitName_); + tok_HO_ = consumes > >(hoRecHitName_); + tok_Vertex_ = consumes(pvCollName_); +} -#include "Calibration/Tools/interface/GenericMinL3Algorithm.h" -#include "CondFormats/DataRecord/interface/HcalRespCorrsRcd.h" -#include "CalibCalorimetry/HcalAlgos/interface/HcalDbASCIIIO.h" +DiJetAnalyzer::~DiJetAnalyzer() +{ +} + +// +// member functions +// + +// ------------ method called to for each event ------------ +void +DiJetAnalyzer::analyze(const edm::Event& iEvent, const edm::EventSetup& evSetup) +{ + pf_Run_ = iEvent.id().run(); + pf_Lumi_ = iEvent.id().luminosityBlock(); + pf_Event_ = iEvent.id().event(); + + // Get PFJets + edm::Handle pfjets; + iEvent.getByToken(tok_PFJet_,pfjets); + if(!pfjets.isValid()) { + throw edm::Exception(edm::errors::ProductNotFound) + << " could not find PFJetCollection named " << pfJetCollName_ << ".\n"; + return; + } -#include "FWCore/Utilities/interface/Exception.h" -#include + // Get RecHits in HB and HE + edm::Handle>> hbhereco; + iEvent.getByToken(tok_HBHE_,hbhereco); + if(!hbhereco.isValid()) { + throw edm::Exception(edm::errors::ProductNotFound) + << " could not find HBHERecHit named " << hbheRecHitName_ << ".\n"; + return; + } + // Get RecHits in HF + edm::Handle>> hfreco; + iEvent.getByToken(tok_HF_,hfreco); + if(!hfreco.isValid()) { + throw edm::Exception(edm::errors::ProductNotFound) + << " could not find HFRecHit named " << hfRecHitName_ << ".\n"; + return; + } + // Get RecHits in HO + edm::Handle>> horeco; + iEvent.getByToken(tok_HO_,horeco); + if(!horeco.isValid()) { + throw edm::Exception(edm::errors::ProductNotFound) + << " could not find HORecHit named " << hoRecHitName_ << ".\n"; + return; + } -#include "TString.h" -#include "TFile.h" -#include "TTree.h" -#include "TObject.h" -#include "TObjArray.h" -#include "TClonesArray.h" -#include "TRefArray.h" -#include "TLorentzVector.h" + // Get geometry + edm::ESHandle geoHandle; + evSetup.get().get(geoHandle); + const CaloSubdetectorGeometry *HBGeom = geoHandle->getSubdetectorGeometry(DetId::Hcal, 1); + const CaloSubdetectorGeometry *HEGeom = geoHandle->getSubdetectorGeometry(DetId::Hcal, 2); + const CaloSubdetectorGeometry *HOGeom = geoHandle->getSubdetectorGeometry(DetId::Hcal, 3); + const CaloSubdetectorGeometry *HFGeom = geoHandle->getSubdetectorGeometry(DetId::Hcal, 4); + + int HBHE_n = 0; + for(edm::SortedCollection>::const_iterator ith=hbhereco->begin(); ith!=hbhereco->end(); ++ith){ + HBHE_n++; + } + int HF_n = 0; + for(edm::SortedCollection>::const_iterator ith=hfreco->begin(); ith!=hfreco->end(); ++ith){ + HF_n++; + } + int HO_n = 0; + for(edm::SortedCollection>::const_iterator ith=horeco->begin(); ith!=horeco->end(); ++ith){ + HO_n++; + } + // Get primary vertices + edm::Handle> pv; + iEvent.getByToken(tok_Vertex_,pv); + if(!pv.isValid()) { + throw edm::Exception(edm::errors::ProductNotFound) + << " could not find Vertex named " << pvCollName_ << ".\n"; + return; + } + pf_NPV_ = 0; + for(std::vector::const_iterator it=pv->begin(); it!=pv->end(); ++it){ + if(!it->isFake() && it->ndof() > 4) ++pf_NPV_; + } + + // Get jet corrections + const JetCorrector* correctorPF = JetCorrector::getJetCorrector(pfJetCorrName_,evSetup); + + ////////////////////////////// + // Event Selection + ////////////////////////////// + + // determine which cut results in failure + int passSelPF=0; + // sort jets by corrected et + std::set pfjetcorretpairset; + for(reco::PFJetCollection::const_iterator it=pfjets->begin(); it!=pfjets->end(); ++it) { + const reco::PFJet* jet=&(*it); + double jec = correctorPF->correction(*it, iEvent, evSetup); + pfjetcorretpairset.insert(JetCorretPair(jet, jec)); + } -namespace cms -{ -DiJetAnalyzer::DiJetAnalyzer(const edm::ParameterSet& iConfig) -{ - tok_jets_ = consumes(iConfig.getParameter("jetsInput")); - tok_ec_ = consumes(iConfig.getParameter("ecInput")); - tok_hbhe_ = consumes(iConfig.getParameter("hbheInput")); - tok_ho_ = consumes(iConfig.getParameter("hoInput")); - tok_hf_ = consumes(iConfig.getParameter("hfInput")); + JetCorretPair pf_tag, pf_probe; + pf_thirdjet_px_=pf_thirdjet_py_=0.0; + pf_realthirdjet_px_=pf_realthirdjet_py_=0.0; + pf_realthirdjet_px_ = 1; + int cntr=0; + for(std::set::const_iterator it=pfjetcorretpairset.begin(); it!=pfjetcorretpairset.end(); ++it) { + JetCorretPair jet=(*it); + ++cntr; + if(cntr==1) pf_tag=jet; + else if(cntr==2) pf_probe=jet; + else { + pf_thirdjet_px_ += jet.scale()*jet.jet()->px(); + pf_thirdjet_py_ += jet.scale()*jet.jet()->py(); + if(cntr==3){ + pf_realthirdjet_px_ = jet.jet()->px(); + pf_realthirdjet_py_ = jet.jet()->py(); + pf_realthirdjet_scale_ = jet.scale(); + } + } + } + + if(pf_tag.jet() && pf_probe.jet()){ + // require that the first two jets are above some minimum, + // and the rest are below some maximum + if((pf_tag.jet()->et()+pf_probe.jet()->et())et()et()maxThirdJetEt_) passSelPF |= 0x4; + + // force the tag jet to have the smaller |eta| + if(std::fabs(pf_tag.jet()->eta())>std::fabs(pf_probe.jet()->eta())) { + JetCorretPair temp=pf_tag; + pf_tag=pf_probe; + pf_probe=temp; + } + + // eta cuts + double dAbsEta=std::fabs(std::fabs(pf_tag.jet()->eta())-std::fabs(pf_probe.jet()->eta())); + if(dAbsEta>maxDeltaEta_) passSelPF |= 0x8; + if(fabs(pf_tag.jet()->eta())eta())>maxTagJetEta_) passSelPF |= 0x10; + } + else{ + passSelPF = 0x40; + } + + h_PassSelPF_->Fill(passSelPF); + if(passSelPF) return; + // dump + if(debug_) { + std::cout << "Run: " << iEvent.id().run() << "; Event: " << iEvent.id().event() << std::endl; + for(reco::PFJetCollection::const_iterator it=pfjets->begin(); it!=pfjets->end(); ++it) { + const reco::PFJet *jet=&(*it); + std::cout << "istag=" << (jet==pf_tag.jet()) << "; isprobe=" << (jet==pf_probe.jet()) << "; et=" << jet->et() << "; eta=" << jet->eta() << std::endl; + } + } - // get name of output file with histogramms - fOutputFileName = iConfig.getUntrackedParameter("HistOutFile"); + // Reset particle variables + tpfjet_unkown_E_ = tpfjet_unkown_px_ = tpfjet_unkown_py_ = tpfjet_unkown_pz_ = tpfjet_unkown_EcalE_ = 0.0; + tpfjet_electron_E_ = tpfjet_electron_px_ = tpfjet_electron_py_ = tpfjet_electron_pz_ = tpfjet_electron_EcalE_ = 0.0; + tpfjet_muon_E_ = tpfjet_muon_px_ = tpfjet_muon_py_ = tpfjet_muon_pz_ = tpfjet_muon_EcalE_ = 0.0; + tpfjet_photon_E_ = tpfjet_photon_px_ = tpfjet_photon_py_ = tpfjet_photon_pz_ = tpfjet_photon_EcalE_ = 0.0; + tpfjet_unkown_n_ = tpfjet_electron_n_ = tpfjet_muon_n_ = tpfjet_photon_n_ = 0; + tpfjet_had_n_ = 0; + tpfjet_cluster_n_ = 0; + ppfjet_unkown_E_ = ppfjet_unkown_px_ = ppfjet_unkown_py_ = ppfjet_unkown_pz_ = ppfjet_unkown_EcalE_ = 0.0; + ppfjet_electron_E_ = ppfjet_electron_px_ = ppfjet_electron_py_ = ppfjet_electron_pz_ = ppfjet_electron_EcalE_ = 0.0; + ppfjet_muon_E_ = ppfjet_muon_px_ = ppfjet_muon_py_ = ppfjet_muon_pz_ = ppfjet_muon_EcalE_ = 0.0; + ppfjet_photon_E_ = ppfjet_photon_px_ = ppfjet_photon_py_ = ppfjet_photon_pz_ = ppfjet_photon_EcalE_ = 0.0; + ppfjet_unkown_n_ = ppfjet_electron_n_ = ppfjet_muon_n_ = ppfjet_photon_n_ = 0; + ppfjet_had_n_ = 0; + ppfjet_cluster_n_ = 0; + + tpfjet_had_E_.clear(); + tpfjet_had_px_.clear(); + tpfjet_had_py_.clear(); + tpfjet_had_pz_.clear(); + tpfjet_had_EcalE_.clear(); + tpfjet_had_rawHcalE_.clear(); + tpfjet_had_emf_.clear(); + tpfjet_had_id_.clear(); + tpfjet_had_candtrackind_.clear(); + tpfjet_had_ntwrs_.clear(); + tpfjet_twr_ieta_.clear(); + tpfjet_twr_iphi_.clear(); + tpfjet_twr_depth_.clear(); + tpfjet_twr_subdet_.clear(); + tpfjet_twr_candtrackind_.clear(); + tpfjet_twr_hadind_.clear(); + tpfjet_twr_elmttype_.clear(); + tpfjet_twr_hade_.clear(); + tpfjet_twr_frac_.clear(); + tpfjet_twr_dR_.clear(); + tpfjet_twr_clusterind_.clear(); + tpfjet_cluster_eta_.clear(); + tpfjet_cluster_phi_.clear(); + tpfjet_cluster_dR_.clear(); + tpfjet_candtrack_px_.clear(); + tpfjet_candtrack_py_.clear(); + tpfjet_candtrack_pz_.clear(); + tpfjet_candtrack_EcalE_.clear(); + ppfjet_had_E_.clear(); + ppfjet_had_px_.clear(); + ppfjet_had_py_.clear(); + ppfjet_had_pz_.clear(); + ppfjet_had_EcalE_.clear(); + ppfjet_had_rawHcalE_.clear(); + ppfjet_had_emf_.clear(); + ppfjet_had_id_.clear(); + ppfjet_had_candtrackind_.clear(); + ppfjet_had_ntwrs_.clear(); + ppfjet_twr_ieta_.clear(); + ppfjet_twr_iphi_.clear(); + ppfjet_twr_depth_.clear(); + ppfjet_twr_subdet_.clear(); + ppfjet_twr_candtrackind_.clear(); + ppfjet_twr_hadind_.clear(); + ppfjet_twr_elmttype_.clear(); + ppfjet_twr_hade_.clear(); + ppfjet_twr_frac_.clear(); + ppfjet_twr_dR_.clear(); + ppfjet_twr_clusterind_.clear(); + ppfjet_cluster_eta_.clear(); + ppfjet_cluster_phi_.clear(); + ppfjet_cluster_dR_.clear(); + ppfjet_candtrack_px_.clear(); + ppfjet_candtrack_py_.clear(); + ppfjet_candtrack_pz_.clear(); + ppfjet_candtrack_EcalE_.clear(); - allowMissingInputs_ = true; -} + std::map>> tpfjet_rechits; + std::map>> ppfjet_rechits; + std::map tpfjet_clusters; + std::map ppfjet_clusters; + + // fill tag jet variables + tpfjet_pt_ = pf_tag.jet()->pt(); + tpfjet_p_ = pf_tag.jet()->p(); + tpfjet_E_ = pf_tag.jet()->energy(); + tpfjet_eta_ = pf_tag.jet()->eta(); + tpfjet_phi_ = pf_tag.jet()->phi(); + tpfjet_scale_ = pf_tag.scale(); + tpfjet_area_ = pf_tag.jet()->jetArea(); + tpfjet_ntwrs_=0; + tpfjet_ncandtracks_=0; + tpfjet_jetID_ = 0; // Not a loose, medium, or tight jet + if(fabs(pf_tag.jet()->eta()) < 2.4){ + if(pf_tag.jet()->chargedHadronEnergyFraction() > 0 && + pf_tag.jet()->chargedMultiplicity() > 0 && + pf_tag.jet()->chargedEmEnergyFraction() < 0.99 && + (pf_tag.jet()->chargedMultiplicity() + pf_tag.jet()->neutralMultiplicity()) > 1){ + if(pf_tag.jet()->neutralHadronEnergyFraction() < 0.9 && + pf_tag.jet()->neutralEmEnergyFraction() < 0.9){ + tpfjet_jetID_ = 3; // Tight jet + } + else if(pf_tag.jet()->neutralHadronEnergyFraction() < 0.95 && + pf_tag.jet()->neutralEmEnergyFraction() < 0.95){ + tpfjet_jetID_ = 2; // Medium jet + } + else if(pf_tag.jet()->neutralHadronEnergyFraction() < 0.99 && + pf_tag.jet()->neutralEmEnergyFraction() < 0.99){ + tpfjet_jetID_ = 1; // Loose jet + } + } + } + else if((pf_tag.jet()->chargedMultiplicity() + pf_tag.jet()->neutralMultiplicity()) > 1){ + if(pf_tag.jet()->neutralHadronEnergyFraction() < 0.9 && + pf_tag.jet()->neutralEmEnergyFraction() < 0.9){ + tpfjet_jetID_ = 3; // Tight jet + } + else if(pf_tag.jet()->neutralHadronEnergyFraction() < 0.95 && + pf_tag.jet()->neutralEmEnergyFraction() < 0.95){ + tpfjet_jetID_ = 2; // Medium jet + } + else if(pf_tag.jet()->neutralHadronEnergyFraction() < 0.99 && + pf_tag.jet()->neutralEmEnergyFraction() < 0.99){ + tpfjet_jetID_ = 1; // Loose jet + } + } -DiJetAnalyzer::~DiJetAnalyzer() -{ + ///////////////////////////////////////////// + // Get PF constituents and fill HCAL towers + ///////////////////////////////////////////// + + // Get tag PFCandidates + std::vector tagconst=pf_tag.jet()->getPFConstituents(); + for(std::vector::const_iterator it=tagconst.begin(); it!=tagconst.end(); ++it){ + bool hasTrack = false; + // Test PFCandidate type + reco::PFCandidate::ParticleType candidateType = (*it)->particleId(); + switch(candidateType){ + case reco::PFCandidate::X: + tpfjet_unkown_E_ += (*it)->energy(); + tpfjet_unkown_px_ += (*it)->px(); + tpfjet_unkown_py_ += (*it)->py(); + tpfjet_unkown_pz_ += (*it)->pz(); + tpfjet_unkown_EcalE_ += (*it)->ecalEnergy(); + tpfjet_unkown_n_++; + continue; + case reco::PFCandidate::h: + { + tpfjet_had_E_.push_back((*it)->energy()); + tpfjet_had_px_.push_back((*it)->px()); + tpfjet_had_py_.push_back((*it)->py()); + tpfjet_had_pz_.push_back((*it)->pz()); + tpfjet_had_EcalE_.push_back((*it)->ecalEnergy()); + tpfjet_had_rawHcalE_.push_back((*it)->rawHcalEnergy()); + tpfjet_had_id_.push_back(0); + tpfjet_had_ntwrs_.push_back(0); + tpfjet_had_n_++; -} + reco::TrackRef trackRef = (*it)->trackRef(); + if(trackRef.isNonnull()){ + reco::Track track = *trackRef; + tpfjet_candtrack_px_.push_back(track.px()); + tpfjet_candtrack_py_.push_back(track.py()); + tpfjet_candtrack_pz_.push_back(track.pz()); + tpfjet_candtrack_EcalE_.push_back((*it)->ecalEnergy()); + tpfjet_had_candtrackind_.push_back(tpfjet_ncandtracks_); + hasTrack = true; + tpfjet_ncandtracks_++; + } + else{ + tpfjet_had_candtrackind_.push_back(-2); + } + } + break; + case reco::PFCandidate::e: + tpfjet_electron_E_ += (*it)->energy(); + tpfjet_electron_px_ += (*it)->px(); + tpfjet_electron_py_ += (*it)->py(); + tpfjet_electron_pz_ += (*it)->pz(); + tpfjet_electron_EcalE_ += (*it)->ecalEnergy(); + tpfjet_electron_n_++; + continue; + case reco::PFCandidate::mu: + tpfjet_muon_E_ += (*it)->energy(); + tpfjet_muon_px_ += (*it)->px(); + tpfjet_muon_py_ += (*it)->py(); + tpfjet_muon_pz_ += (*it)->pz(); + tpfjet_muon_EcalE_ += (*it)->ecalEnergy(); + tpfjet_muon_n_++; + continue; + case reco::PFCandidate::gamma: + tpfjet_photon_E_ += (*it)->energy(); + tpfjet_photon_px_ += (*it)->px(); + tpfjet_photon_py_ += (*it)->py(); + tpfjet_photon_pz_ += (*it)->pz(); + tpfjet_photon_EcalE_ += (*it)->ecalEnergy(); + tpfjet_photon_n_++; + continue; + case reco::PFCandidate::h0: + { + tpfjet_had_E_.push_back((*it)->energy()); + tpfjet_had_px_.push_back((*it)->px()); + tpfjet_had_py_.push_back((*it)->py()); + tpfjet_had_pz_.push_back((*it)->pz()); + tpfjet_had_EcalE_.push_back((*it)->ecalEnergy()); + tpfjet_had_rawHcalE_.push_back((*it)->rawHcalEnergy()); + tpfjet_had_id_.push_back(1); + tpfjet_had_candtrackind_.push_back(-1); + tpfjet_had_ntwrs_.push_back(0); + tpfjet_had_n_++; + break; + } + case reco::PFCandidate::h_HF: + { + tpfjet_had_E_.push_back((*it)->energy()); + tpfjet_had_px_.push_back((*it)->px()); + tpfjet_had_py_.push_back((*it)->py()); + tpfjet_had_pz_.push_back((*it)->pz()); + tpfjet_had_EcalE_.push_back((*it)->ecalEnergy()); + tpfjet_had_rawHcalE_.push_back((*it)->rawHcalEnergy()); + tpfjet_had_id_.push_back(2); + tpfjet_had_candtrackind_.push_back(-1); + tpfjet_had_ntwrs_.push_back(0); + tpfjet_had_n_++; + break; + } + case reco::PFCandidate::egamma_HF: + { + tpfjet_had_E_.push_back((*it)->energy()); + tpfjet_had_px_.push_back((*it)->px()); + tpfjet_had_py_.push_back((*it)->py()); + tpfjet_had_pz_.push_back((*it)->pz()); + tpfjet_had_EcalE_.push_back((*it)->ecalEnergy()); + tpfjet_had_rawHcalE_.push_back((*it)->rawHcalEnergy()); + tpfjet_had_id_.push_back(3); + tpfjet_had_candtrackind_.push_back(-1); + tpfjet_had_ntwrs_.push_back(0); + tpfjet_had_n_++; + break; + } + } + std::map twrietas; + float HFHAD_E = 0; + float HFEM_E = 0; + int maxElement=(*it)->elementsInBlocks().size(); + for(int e=0; eelementsInBlocks()[e].first; + const edm::OwnVector& elements = blockRef->elements(); + for(unsigned iEle=0; iEleelementsInBlocks()[e].second){ + if(elements[iEle].type() == reco::PFBlockElement::HCAL){ // Element is HB or HE + // Get cluster and hits + reco::PFClusterRef clusterref = elements[iEle].clusterRef(); + reco::PFCluster cluster = *clusterref; + double cluster_dR = deltaR(tpfjet_eta_,tpfjet_phi_,cluster.eta(),cluster.phi()); + if(tpfjet_clusters.count(cluster_dR) == 0){ + tpfjet_clusters[cluster_dR] = tpfjet_cluster_n_; + tpfjet_cluster_eta_.push_back(cluster.eta()); + tpfjet_cluster_phi_.push_back(cluster.phi()); + tpfjet_cluster_dR_.push_back(cluster_dR); + tpfjet_cluster_n_++; + } + int cluster_ind = tpfjet_clusters[cluster_dR]; -// -// member functions -// + std::vector> hitsAndFracs = cluster.hitsAndFractions(); + + // Run over hits and match + int nHits = hitsAndFracs.size(); + for(int iHit=0; iHit>::const_iterator ith=hbhereco->begin(); ith!=hbhereco->end(); ++ith){ + int etaPhiRecHit = getEtaPhi((*ith).id()); + if(etaPhiPF == etaPhiRecHit){ + tpfjet_had_ntwrs_.at(tpfjet_had_n_ - 1)++; + if(tpfjet_rechits.count((*ith).id()) == 0){ + tpfjet_twr_ieta_.push_back((*ith).id().ieta()); + tpfjet_twr_iphi_.push_back((*ith).id().iphi()); + tpfjet_twr_depth_.push_back((*ith).id().depth()); + tpfjet_twr_subdet_.push_back((*ith).id().subdet()); + if(hitsAndFracs[iHit].second > 0.05 && (*ith).energy() > 0.0) twrietas[(*ith).id().ieta()]++; + tpfjet_twr_hade_.push_back((*ith).energy()); + tpfjet_twr_frac_.push_back(hitsAndFracs[iHit].second); + tpfjet_rechits[(*ith).id()].second.insert(hitsAndFracs[iHit].second); + tpfjet_twr_hadind_.push_back(tpfjet_had_n_ - 1); + tpfjet_twr_elmttype_.push_back(0); + tpfjet_twr_clusterind_.push_back(cluster_ind); + if(hasTrack){ + tpfjet_twr_candtrackind_.push_back(tpfjet_ncandtracks_ - 1); + } + else{ + tpfjet_twr_candtrackind_.push_back(-1); + } + switch((*ith).id().subdet()){ + case HcalSubdetector::HcalBarrel: + { + const CaloCellGeometry *thisCell = HBGeom->getGeometry((*ith).id().rawId()); + const CaloCellGeometry::CornersVec& cv = thisCell->getCorners(); + float avgeta = (cv[0].eta() + cv[2].eta())/2.0; + float avgphi = (static_cast(cv[0].phi()) + static_cast(cv[2].phi()))/2.0; + if(cv[0].phi() < cv[2].phi()) avgphi = (2.0*3.141592653 + static_cast(cv[0].phi()) + static_cast(cv[2].phi()))/2.0; + tpfjet_twr_dR_.push_back(deltaR(tpfjet_eta_,tpfjet_phi_,avgeta,avgphi)); + break; + } + case HcalSubdetector::HcalEndcap: + { + const CaloCellGeometry *thisCell = HEGeom->getGeometry((*ith).id().rawId()); + const CaloCellGeometry::CornersVec& cv = thisCell->getCorners(); + float avgeta = (cv[0].eta() + cv[2].eta())/2.0; + float avgphi = (static_cast(cv[0].phi()) + static_cast(cv[2].phi()))/2.0; + if(cv[0].phi() < cv[2].phi()) avgphi = (2.0*3.141592653 + static_cast(cv[0].phi()) + static_cast(cv[2].phi()))/2.0; + tpfjet_twr_dR_.push_back(deltaR(tpfjet_eta_,tpfjet_phi_,avgeta,avgphi)); + break; + } + default: + tpfjet_twr_dR_.push_back(-1); + break; + } + tpfjet_rechits[(*ith).id()].first = tpfjet_ntwrs_; + ++tpfjet_ntwrs_; + } + else if(tpfjet_rechits[(*ith).id()].second.count(hitsAndFracs[iHit].second) == 0){ + tpfjet_twr_frac_.at(tpfjet_rechits[(*ith).id()].first) += hitsAndFracs[iHit].second; + if(cluster_dR < tpfjet_cluster_dR_.at(tpfjet_twr_clusterind_.at(tpfjet_rechits[(*ith).id()].first))){ + tpfjet_twr_clusterind_.at(tpfjet_rechits[(*ith).id()].first) = cluster_ind; + } + tpfjet_rechits[(*ith).id()].second.insert(hitsAndFracs[iHit].second); + } + } // Test if ieta,iphi matches + } // Loop over rechits + } // Loop over hits + } // Test if element is from HCAL + else if(elements[iEle].type() == reco::PFBlockElement::HFHAD){ // Element is HF + for(edm::SortedCollection>::const_iterator ith=hfreco->begin(); ith!=hfreco->end(); ++ith){ + if((*ith).id().depth() == 1) continue; // Remove long fibers + const CaloCellGeometry *thisCell = HFGeom->getGeometry((*ith).id().rawId()); + const CaloCellGeometry::CornersVec& cv = thisCell->getCorners(); -// ------------ method called to for each event ------------ -void -DiJetAnalyzer::analyze(const edm::Event& iEvent, const edm::EventSetup& iSetup) -{ + bool passMatch = false; + if((*it)->eta() < cv[0].eta() && (*it)->eta() > cv[2].eta()){ + if((*it)->phi() < cv[0].phi() && (*it)->phi() > cv[2].phi()) passMatch = true; + else if(cv[0].phi() < cv[2].phi()){ + if((*it)->phi() < cv[0].phi()) passMatch = true; + else if((*it)->phi() > cv[2].phi()) passMatch = true; + } + } - using namespace std; - using namespace edm; - using namespace reco; - - const double pi = 4.*atan(1.); - - // event number & run number - eventNumber = iEvent.id().event(); - runNumber = iEvent.id().run(); - - - // read jets - CaloJet jet1, jet2, jet3; - try { - edm::Handle jets; - iEvent.getByToken(tok_jets_,jets); - if(jets->size()>1){ - jet1 = (*jets)[0]; - jet2 = (*jets)[1]; - if(fabs(jet1.eta())>fabs(jet2.eta())){ - CaloJet jet = jet1; - jet1 = jet2; - jet2 = jet; - } - // if(fabs(jet1.eta())>eta_1 || (fabs(jet2.eta())-jet_R) < eta_2){ return;} - } else {return;} - tagJetP4->SetPxPyPzE(jet1.px(), jet1.py(), jet1.pz(), jet1.energy()); - probeJetP4->SetPxPyPzE(jet2.px(), jet2.py(), jet2.pz(), jet2.energy()); - if(jets->size()>2){ - jet3 = (*jets)[2]; - etVetoJet = jet3.et(); - } else { etVetoJet = 0.;} - }catch (cms::Exception& e) { // can't find it! - if (!allowMissingInputs_) { throw e; } - } - - - double dR = 1000.; - edm::ESHandle pG; - iSetup.get().get(pG); - const CaloGeometry* geo = pG.product(); - vector vid = geo->getValidDetIds(); - for(vector::const_iterator idItr = vid.begin(); idItr != vid.end(); idItr++) - { - if( (*idItr).det() == DetId::Hcal ) { - GlobalPoint pos = geo->getPosition(*idItr); - double deta = fabs(jet2.eta() - pos.eta()); - double dphi = fabs(jet2.phi() - pos.phi()); - if(dphi>pi){dphi=2*pi-dphi;} - double dR_candidate = sqrt(deta*deta + dphi*dphi); - int ieta = HcalDetId(*idItr).ieta(); - int iphi = HcalDetId(*idItr).iphi(); - int idepth = HcalDetId(*idItr).depth(); - if(dR_candidate < dR && idepth == 1){ - dR = dR_candidate; - iEtaHit = ieta; - iPhiHit = iphi; - } + if(passMatch){ + tpfjet_had_ntwrs_.at(tpfjet_had_n_ - 1)++; + tpfjet_twr_ieta_.push_back((*ith).id().ieta()); + tpfjet_twr_iphi_.push_back((*ith).id().iphi()); + tpfjet_twr_depth_.push_back((*ith).id().depth()); + tpfjet_twr_subdet_.push_back((*ith).id().subdet()); + tpfjet_twr_hade_.push_back((*ith).energy()); + tpfjet_twr_frac_.push_back(1.0); + tpfjet_twr_hadind_.push_back(tpfjet_had_n_ - 1); + tpfjet_twr_elmttype_.push_back(1); + tpfjet_twr_clusterind_.push_back(-1); + tpfjet_twr_candtrackind_.push_back(-1); + float avgeta = (cv[0].eta() + cv[2].eta())/2.0; + float avgphi = (static_cast(cv[0].phi()) + static_cast(cv[2].phi()))/2.0; + if(cv[0].phi() < cv[2].phi()) avgphi = (2.0*3.141592653 + static_cast(cv[0].phi()) + static_cast(cv[2].phi()))/2.0; + tpfjet_twr_dR_.push_back(deltaR(tpfjet_eta_,tpfjet_phi_,avgeta,avgphi)); + ++tpfjet_ntwrs_; + HFHAD_E += (*ith).energy(); + } + } + } + else if(elements[iEle].type() == reco::PFBlockElement::HFEM){ // Element is HF + for(edm::SortedCollection>::const_iterator ith=hfreco->begin(); ith!=hfreco->end(); ++ith){ + if((*ith).id().depth() == 2) continue; // Remove short fibers + const CaloCellGeometry *thisCell = HFGeom->getGeometry((*ith).id().rawId()); + const CaloCellGeometry::CornersVec& cv = thisCell->getCorners(); + + bool passMatch = false; + if((*it)->eta() < cv[0].eta() && (*it)->eta() > cv[2].eta()){ + if((*it)->phi() < cv[0].phi() && (*it)->phi() > cv[2].phi()) passMatch = true; + else if(cv[0].phi() < cv[2].phi()){ + if((*it)->phi() < cv[0].phi()) passMatch = true; + else if((*it)->phi() > cv[2].phi()) passMatch = true; + } + } + + if(passMatch){ + tpfjet_had_ntwrs_.at(tpfjet_had_n_ - 1)++; + tpfjet_twr_ieta_.push_back((*ith).id().ieta()); + tpfjet_twr_iphi_.push_back((*ith).id().iphi()); + tpfjet_twr_depth_.push_back((*ith).id().depth()); + tpfjet_twr_subdet_.push_back((*ith).id().subdet()); + tpfjet_twr_hade_.push_back((*ith).energy()); + tpfjet_twr_frac_.push_back(1.0); + tpfjet_twr_hadind_.push_back(tpfjet_had_n_ - 1); + tpfjet_twr_elmttype_.push_back(2); + tpfjet_twr_clusterind_.push_back(-1); + tpfjet_twr_candtrackind_.push_back(-1); + float avgeta = (cv[0].eta() + cv[2].eta())/2.0; + float avgphi = (static_cast(cv[0].phi()) + static_cast(cv[2].phi()))/2.0; + if(cv[0].phi() < cv[2].phi()) avgphi = (2.0*3.141592653 + static_cast(cv[0].phi()) + static_cast(cv[2].phi()))/2.0; + tpfjet_twr_dR_.push_back(deltaR(tpfjet_eta_,tpfjet_phi_,avgeta,avgphi)); + ++tpfjet_ntwrs_; + HFEM_E += (*ith).energy(); + } + } + } + else if(elements[iEle].type() == reco::PFBlockElement::HO){ // Element is HO + reco::PFClusterRef clusterref = elements[iEle].clusterRef(); + reco::PFCluster cluster = *clusterref; + double cluster_dR = deltaR(tpfjet_eta_,tpfjet_phi_,cluster.eta(),cluster.phi()); + if(tpfjet_clusters.count(cluster_dR) == 0){ + tpfjet_clusters[cluster_dR] = tpfjet_cluster_n_; + tpfjet_cluster_eta_.push_back(cluster.eta()); + tpfjet_cluster_phi_.push_back(cluster.phi()); + tpfjet_cluster_dR_.push_back(cluster_dR); + tpfjet_cluster_n_++; + } + int cluster_ind = tpfjet_clusters[cluster_dR]; + + std::vector> hitsAndFracs = cluster.hitsAndFractions(); + int nHits = hitsAndFracs.size(); + for(int iHit=0; iHit>::const_iterator ith=horeco->begin(); ith!=horeco->end(); ++ith){ + int etaPhiRecHit = getEtaPhi((*ith).id()); + if(etaPhiPF == etaPhiRecHit){ + tpfjet_had_ntwrs_.at(tpfjet_had_n_ - 1)++; + if(tpfjet_rechits.count((*ith).id()) == 0){ + tpfjet_twr_ieta_.push_back((*ith).id().ieta()); + tpfjet_twr_iphi_.push_back((*ith).id().iphi()); + tpfjet_twr_depth_.push_back((*ith).id().depth()); + tpfjet_twr_subdet_.push_back((*ith).id().subdet()); + if(hitsAndFracs[iHit].second > 0.05 && (*ith).energy() > 0.0) twrietas[(*ith).id().ieta()]++; + tpfjet_twr_hade_.push_back((*ith).energy()); + tpfjet_twr_frac_.push_back(hitsAndFracs[iHit].second); + tpfjet_rechits[(*ith).id()].second.insert(hitsAndFracs[iHit].second); + tpfjet_twr_hadind_.push_back(tpfjet_had_n_ - 1); + tpfjet_twr_elmttype_.push_back(3); + tpfjet_twr_clusterind_.push_back(cluster_ind); + if(hasTrack){ + tpfjet_twr_candtrackind_.push_back(tpfjet_ncandtracks_ - 1); + } + else{ + tpfjet_twr_candtrackind_.push_back(-1); + } + const CaloCellGeometry *thisCell = HOGeom->getGeometry((*ith).id().rawId()); + const CaloCellGeometry::CornersVec& cv = thisCell->getCorners(); + float avgeta = (cv[0].eta() + cv[2].eta())/2.0; + float avgphi = (static_cast(cv[0].phi()) + static_cast(cv[2].phi()))/2.0; + if(cv[0].phi() < cv[2].phi()) avgphi = (2.0*3.141592653 + static_cast(cv[0].phi()) + static_cast(cv[2].phi()))/2.0; + tpfjet_twr_dR_.push_back(deltaR(tpfjet_eta_,tpfjet_phi_,avgeta,avgphi)); + tpfjet_rechits[(*ith).id()].first = tpfjet_ntwrs_; + ++tpfjet_ntwrs_; + } + else if(tpfjet_rechits[(*ith).id()].second.count(hitsAndFracs[iHit].second) == 0){ + tpfjet_twr_frac_.at(tpfjet_rechits[(*ith).id()].first) += hitsAndFracs[iHit].second; + if(cluster_dR < tpfjet_cluster_dR_.at(tpfjet_twr_clusterind_.at(tpfjet_rechits[(*ith).id()].first))){ + tpfjet_twr_clusterind_.at(tpfjet_rechits[(*ith).id()].first) = cluster_ind; + } + tpfjet_rechits[(*ith).id()].second.insert(hitsAndFracs[iHit].second); + } + } // Test if ieta,iphi match + } // Loop over rechits + } // Loop over hits + } // Test if element is HO + } // Test for right element index + } // Loop over elements + } // Loop over elements in blocks + + switch(candidateType){ + case reco::PFCandidate::h_HF: + tpfjet_had_emf_.push_back(HFEM_E/(HFEM_E + HFHAD_E)); + break; + case reco::PFCandidate::egamma_HF: + tpfjet_had_emf_.push_back(-1); + break; + default: + tpfjet_had_emf_.push_back(-1); + break; + } + } // Loop over PF constitutents + + int tag_had_EcalE = 0; + int tag_had_rawHcalE = 0; + for(int i=0; ipt(); + ppfjet_p_ = pf_probe.jet()->p(); + ppfjet_E_ = pf_probe.jet()->energy(); + ppfjet_eta_ = pf_probe.jet()->eta(); + ppfjet_phi_ = pf_probe.jet()->phi(); + ppfjet_scale_ = pf_probe.scale(); + ppfjet_area_ = pf_probe.jet()->jetArea(); + ppfjet_ntwrs_=0; + ppfjet_ncandtracks_=0; + + ppfjet_jetID_ = 0; // Not a loose, medium, or tight jet + if(fabs(pf_probe.jet()->eta()) < 2.4){ + if(pf_probe.jet()->chargedHadronEnergyFraction() > 0 && + pf_probe.jet()->chargedMultiplicity() > 0 && + pf_probe.jet()->chargedEmEnergyFraction() < 0.99 && + (pf_probe.jet()->chargedMultiplicity() + pf_probe.jet()->neutralMultiplicity()) > 1){ + if(pf_probe.jet()->neutralHadronEnergyFraction() < 0.9 && + pf_probe.jet()->neutralEmEnergyFraction() < 0.9){ + ppfjet_jetID_ = 3; // Tight jet } - } - - targetE = jet1.et()/sin(jet2.theta()); - - std::map mapId; - vector towers_fw = jet2.getCaloConstituents(); - vector::const_iterator towersItr; - for(towersItr = towers_fw.begin(); towersItr != towers_fw.end(); towersItr++){ - size_t tower_size = (*towersItr)->constituentsSize(); - for(size_t i=0; iconstituent(i); - mapId[id] = 1; + else if(pf_probe.jet()->neutralHadronEnergyFraction() < 0.95 && + pf_probe.jet()->neutralEmEnergyFraction() < 0.95){ + ppfjet_jetID_ = 2; // Medium jet } - } - + else if(pf_probe.jet()->neutralHadronEnergyFraction() < 0.99 && + pf_probe.jet()->neutralEmEnergyFraction() < 0.99){ + ppfjet_jetID_ = 1; // Loose jet + } + } + } + else if((pf_probe.jet()->chargedMultiplicity() + pf_probe.jet()->neutralMultiplicity()) > 1){ + if(pf_probe.jet()->neutralHadronEnergyFraction() < 0.9 && + pf_probe.jet()->neutralEmEnergyFraction() < 0.9){ + ppfjet_jetID_ = 3; // Tight jet + } + else if(pf_probe.jet()->neutralHadronEnergyFraction() < 0.95 && + pf_probe.jet()->neutralEmEnergyFraction() < 0.95){ + ppfjet_jetID_ = 2; // Medium jet + } + else if(pf_probe.jet()->neutralHadronEnergyFraction() < 0.99 && + pf_probe.jet()->neutralEmEnergyFraction() < 0.99){ + ppfjet_jetID_ = 1; // Loose jet + } + } - // probeJetEmFrac = 0.; - double emEnergy = 0.; - try { - Handle ec; - iEvent.getByToken(tok_ec_,ec); - for(EcalRecHitCollection::const_iterator ecItr = (*ec).begin(); - ecItr != (*ec).end(); ++ecItr) + // Get PF constituents and fill HCAL towers + std::vector probeconst=pf_probe.jet()->getPFConstituents(); + for(std::vector::const_iterator it=probeconst.begin(); it!=probeconst.end(); ++it){ + bool hasTrack = false; + reco::PFCandidate::ParticleType candidateType = (*it)->particleId(); + switch(candidateType){ + case reco::PFCandidate::X: + ppfjet_unkown_E_ += (*it)->energy(); + ppfjet_unkown_px_ += (*it)->px(); + ppfjet_unkown_py_ += (*it)->py(); + ppfjet_unkown_pz_ += (*it)->pz(); + ppfjet_unkown_EcalE_ += (*it)->ecalEnergy(); + ppfjet_unkown_n_++; + continue; + case reco::PFCandidate::h: { - DetId id = ecItr->detid(); - if(mapId[id]==1){ - emEnergy += ecItr->energy(); + ppfjet_had_E_.push_back((*it)->energy()); + ppfjet_had_px_.push_back((*it)->px()); + ppfjet_had_py_.push_back((*it)->py()); + ppfjet_had_pz_.push_back((*it)->pz()); + ppfjet_had_EcalE_.push_back((*it)->ecalEnergy()); + ppfjet_had_rawHcalE_.push_back((*it)->rawHcalEnergy()); + ppfjet_had_id_.push_back(0); + ppfjet_had_ntwrs_.push_back(0); + ppfjet_had_n_++; + + reco::TrackRef trackRef = (*it)->trackRef(); + if(trackRef.isNonnull()){ + reco::Track track = *trackRef; + ppfjet_candtrack_px_.push_back(track.px()); + ppfjet_candtrack_py_.push_back(track.py()); + ppfjet_candtrack_pz_.push_back(track.pz()); + ppfjet_candtrack_EcalE_.push_back((*it)->ecalEnergy()); + ppfjet_had_candtrackind_.push_back(ppfjet_ncandtracks_); + hasTrack = true; + ppfjet_ncandtracks_++; + } + else{ + ppfjet_had_candtrackind_.push_back(-2); } } - } catch (cms::Exception& e) { // can't find it! - if (!allowMissingInputs_) throw e; - } - - targetE += -emEnergy; - probeJetEmFrac = emEnergy/jet2.energy(); - - int nHits = 0; - try { - Handle hbhe; - iEvent.getByToken(tok_hbhe_, hbhe); - for(HBHERecHitCollection::const_iterator hbheItr=hbhe->begin(); - hbheItr!=hbhe->end(); hbheItr++) + break; + case reco::PFCandidate::e: + ppfjet_electron_E_ += (*it)->energy(); + ppfjet_electron_px_ += (*it)->px(); + ppfjet_electron_py_ += (*it)->py(); + ppfjet_electron_pz_ += (*it)->pz(); + ppfjet_electron_EcalE_ += (*it)->ecalEnergy(); + ppfjet_electron_n_++; + continue; + case reco::PFCandidate::mu: + ppfjet_muon_E_ += (*it)->energy(); + ppfjet_muon_px_ += (*it)->px(); + ppfjet_muon_py_ += (*it)->py(); + ppfjet_muon_pz_ += (*it)->pz(); + ppfjet_muon_EcalE_ += (*it)->ecalEnergy(); + ppfjet_muon_n_++; + continue; + case reco::PFCandidate::gamma: + ppfjet_photon_E_ += (*it)->energy(); + ppfjet_photon_px_ += (*it)->px(); + ppfjet_photon_py_ += (*it)->py(); + ppfjet_photon_pz_ += (*it)->pz(); + ppfjet_photon_EcalE_ += (*it)->ecalEnergy(); + ppfjet_photon_n_++; + continue; + case reco::PFCandidate::h0: { - DetId id = hbheItr->detid(); - if(mapId[id]==1){ - TCell* cell = new TCell(id.rawId(),hbheItr->energy()); - (*cells)[nHits] = cell; - nHits++; - } + ppfjet_had_E_.push_back((*it)->energy()); + ppfjet_had_px_.push_back((*it)->px()); + ppfjet_had_py_.push_back((*it)->py()); + ppfjet_had_pz_.push_back((*it)->pz()); + ppfjet_had_EcalE_.push_back((*it)->ecalEnergy()); + ppfjet_had_rawHcalE_.push_back((*it)->rawHcalEnergy()); + ppfjet_had_id_.push_back(1); + ppfjet_had_candtrackind_.push_back(-1); + ppfjet_had_ntwrs_.push_back(0); + ppfjet_had_n_++; + break; } - } catch (cms::Exception& e) { // can't find it! - if (!allowMissingInputs_) throw e; - } - - - try { - Handle ho; - iEvent.getByToken(tok_ho_, ho); - for(HORecHitCollection::const_iterator hoItr=ho->begin(); - hoItr!=ho->end(); hoItr++) + case reco::PFCandidate::h_HF: { - DetId id = hoItr->detid(); - if(mapId[id]==1){ - TCell* cell = new TCell(id.rawId(),hoItr->energy()); - (*cells)[nHits] = cell; - nHits++; - } + ppfjet_had_E_.push_back((*it)->energy()); + ppfjet_had_px_.push_back((*it)->px()); + ppfjet_had_py_.push_back((*it)->py()); + ppfjet_had_pz_.push_back((*it)->pz()); + ppfjet_had_EcalE_.push_back((*it)->ecalEnergy()); + ppfjet_had_rawHcalE_.push_back((*it)->rawHcalEnergy()); + ppfjet_had_id_.push_back(2); + ppfjet_had_candtrackind_.push_back(-1); + ppfjet_had_ntwrs_.push_back(0); + ppfjet_had_n_++; + break; } - } catch (cms::Exception& e) { // can't find it! - if (!allowMissingInputs_) throw e; - } - - try { - Handle hf; - iEvent.getByToken(tok_hf_, hf); - for(HFRecHitCollection::const_iterator hfItr=hf->begin(); - hfItr!=hf->end(); hfItr++) + case reco::PFCandidate::egamma_HF: { - DetId id = hfItr->detid(); - if(mapId[id]==1){ - TCell* cell = new TCell(id.rawId(),hfItr->energy()); - (*cells)[nHits] = cell; - nHits++; - } + ppfjet_had_E_.push_back((*it)->energy()); + ppfjet_had_px_.push_back((*it)->px()); + ppfjet_had_py_.push_back((*it)->py()); + ppfjet_had_pz_.push_back((*it)->pz()); + ppfjet_had_EcalE_.push_back((*it)->ecalEnergy()); + ppfjet_had_rawHcalE_.push_back((*it)->rawHcalEnergy()); + ppfjet_had_id_.push_back(3); + ppfjet_had_candtrackind_.push_back(-1); + ppfjet_had_ntwrs_.push_back(0); + ppfjet_had_n_++; + break; } - } catch (cms::Exception& e) { // can't find it! - if (!allowMissingInputs_) throw e; - } - - probeJetEmFrac = emEnergy/jet2.energy(); - -PxTrkHcal = 0; -PyTrkHcal = 0; -PzTrkHcal = 0; + } + + float HFHAD_E = 0; + float HFEM_E = 0; + int maxElement=(*it)->elementsInBlocks().size(); + for(int e=0; eelementsInBlocks()[e].first; + const edm::OwnVector& elements = blockRef->elements(); + for(unsigned iEle=0; iEleelementsInBlocks()[e].second){ + if(elements[iEle].type() == reco::PFBlockElement::HCAL){ // Element is HB or HE + // Get cluster and hits + reco::PFClusterRef clusterref = elements[iEle].clusterRef(); + reco::PFCluster cluster = *clusterref; + double cluster_dR = deltaR(ppfjet_eta_,ppfjet_phi_,cluster.eta(),cluster.phi()); + if(ppfjet_clusters.count(cluster_dR) == 0){ + ppfjet_clusters[cluster_dR] = ppfjet_cluster_n_; + ppfjet_cluster_eta_.push_back(cluster.eta()); + ppfjet_cluster_phi_.push_back(cluster.phi()); + ppfjet_cluster_dR_.push_back(cluster_dR); + ppfjet_cluster_n_++; + } + int cluster_ind = ppfjet_clusters[cluster_dR]; + std::vector> hitsAndFracs = cluster.hitsAndFractions(); + + // Run over hits and match + int nHits = hitsAndFracs.size(); + for(int iHit=0; iHit>::const_iterator ith=hbhereco->begin(); ith!=hbhereco->end(); ++ith){ + int etaPhiRecHit = getEtaPhi((*ith).id()); + if(etaPhiPF == etaPhiRecHit){ + ppfjet_had_ntwrs_.at(ppfjet_had_n_ - 1)++; + if(ppfjet_rechits.count((*ith).id()) == 0){ + ppfjet_twr_ieta_.push_back((*ith).id().ieta()); + ppfjet_twr_iphi_.push_back((*ith).id().iphi()); + ppfjet_twr_depth_.push_back((*ith).id().depth()); + ppfjet_twr_subdet_.push_back((*ith).id().subdet()); + ppfjet_twr_hade_.push_back((*ith).energy()); + ppfjet_twr_frac_.push_back(hitsAndFracs[iHit].second); + ppfjet_rechits[(*ith).id()].second.insert(hitsAndFracs[iHit].second); + ppfjet_twr_hadind_.push_back(ppfjet_had_n_ - 1); + ppfjet_twr_elmttype_.push_back(0); + ppfjet_twr_clusterind_.push_back(cluster_ind); + if(hasTrack){ + ppfjet_twr_candtrackind_.push_back(ppfjet_ncandtracks_ - 1); + } + else{ + ppfjet_twr_candtrackind_.push_back(-1); + } + switch((*ith).id().subdet()){ + case HcalSubdetector::HcalBarrel: + { + const CaloCellGeometry *thisCell = HBGeom->getGeometry((*ith).id().rawId()); + const CaloCellGeometry::CornersVec& cv = thisCell->getCorners(); + float avgeta = (cv[0].eta() + cv[2].eta())/2.0; + float avgphi = (static_cast(cv[0].phi()) + static_cast(cv[2].phi()))/2.0; + if(cv[0].phi() < cv[2].phi()) avgphi = (2.0*3.141592653 + static_cast(cv[0].phi()) + static_cast(cv[2].phi()))/2.0; + ppfjet_twr_dR_.push_back(deltaR(ppfjet_eta_,ppfjet_phi_,avgeta,avgphi)); + break; + } + case HcalSubdetector::HcalEndcap: + { + const CaloCellGeometry *thisCell = HEGeom->getGeometry((*ith).id().rawId()); + const CaloCellGeometry::CornersVec& cv = thisCell->getCorners(); + float avgeta = (cv[0].eta() + cv[2].eta())/2.0; + float avgphi = (static_cast(cv[0].phi()) + static_cast(cv[2].phi()))/2.0; + if(cv[0].phi() < cv[2].phi()) avgphi = (2.0*3.141592653 + static_cast(cv[0].phi()) + static_cast(cv[2].phi()))/2.0; + ppfjet_twr_dR_.push_back(deltaR(ppfjet_eta_,ppfjet_phi_,avgeta,avgphi)); + break; + } + default: + ppfjet_twr_dR_.push_back(-1); + break; + } + ppfjet_rechits[(*ith).id()].first = ppfjet_ntwrs_; + ++ppfjet_ntwrs_; + } + else if(ppfjet_rechits[(*ith).id()].second.count(hitsAndFracs[iHit].second) == 0){ + ppfjet_twr_frac_.at(ppfjet_rechits[(*ith).id()].first) += hitsAndFracs[iHit].second; + if(cluster_dR < ppfjet_cluster_dR_.at(ppfjet_twr_clusterind_.at(ppfjet_rechits[(*ith).id()].first))){ + ppfjet_twr_clusterind_.at(ppfjet_rechits[(*ith).id()].first) = cluster_ind; + } + ppfjet_rechits[(*ith).id()].second.insert(hitsAndFracs[iHit].second); + } + } // Test if ieta,iphi matches + } // Loop over rechits + } // Loop over hits + } // Test if element is from HCAL + else if(elements[iEle].type() == reco::PFBlockElement::HFHAD){ // Element is HF + for(edm::SortedCollection>::const_iterator ith=hfreco->begin(); ith!=hfreco->end(); ++ith){ + if((*ith).id().depth() == 1) continue; // Remove long fibers + const CaloCellGeometry *thisCell = HFGeom->getGeometry((*ith).id().rawId()); + const CaloCellGeometry::CornersVec& cv = thisCell->getCorners(); + + bool passMatch = false; + if((*it)->eta() < cv[0].eta() && (*it)->eta() > cv[2].eta()){ + if((*it)->phi() < cv[0].phi() && (*it)->phi() > cv[2].phi()) passMatch = true; + else if(cv[0].phi() < cv[2].phi()){ + if((*it)->phi() < cv[0].phi()) passMatch = true; + else if((*it)->phi() > cv[2].phi()) passMatch = true; + } + } + + if(passMatch){ + ppfjet_had_ntwrs_.at(ppfjet_had_n_ - 1)++; + ppfjet_twr_ieta_.push_back((*ith).id().ieta()); + ppfjet_twr_iphi_.push_back((*ith).id().iphi()); + ppfjet_twr_depth_.push_back((*ith).id().depth()); + ppfjet_twr_subdet_.push_back((*ith).id().subdet()); + ppfjet_twr_hade_.push_back((*ith).energy()); + ppfjet_twr_frac_.push_back(1.0); + ppfjet_twr_hadind_.push_back(ppfjet_had_n_ - 1); + ppfjet_twr_elmttype_.push_back(1); + ppfjet_twr_clusterind_.push_back(-1); + ppfjet_twr_candtrackind_.push_back(-1); + float avgeta = (cv[0].eta() + cv[2].eta())/2.0; + float avgphi = (static_cast(cv[0].phi()) + static_cast(cv[2].phi()))/2.0; + if(cv[0].phi() < cv[2].phi()) avgphi = (2.0*3.141592653 + static_cast(cv[0].phi()) + static_cast(cv[2].phi()))/2.0; + ppfjet_twr_dR_.push_back(deltaR(ppfjet_eta_,ppfjet_phi_,avgeta,avgphi)); + ++ppfjet_ntwrs_; + HFHAD_E += (*ith).energy(); + } + } + } + else if(elements[iEle].type() == reco::PFBlockElement::HFEM){ // Element is HF + for(edm::SortedCollection>::const_iterator ith=hfreco->begin(); ith!=hfreco->end(); ++ith){ + if((*ith).id().depth() == 2) continue; // Remove short fibers + const CaloCellGeometry *thisCell = HFGeom->getGeometry((*ith).id().rawId()); + const CaloCellGeometry::CornersVec& cv = thisCell->getCorners(); + + bool passMatch = false; + if((*it)->eta() < cv[0].eta() && (*it)->eta() > cv[2].eta()){ + if((*it)->phi() < cv[0].phi() && (*it)->phi() > cv[2].phi()) passMatch = true; + else if(cv[0].phi() < cv[2].phi()){ + if((*it)->phi() < cv[0].phi()) passMatch = true; + else if((*it)->phi() > cv[2].phi()) passMatch = true; + } + } + + if(passMatch){ + ppfjet_had_ntwrs_.at(ppfjet_had_n_ - 1)++; + ppfjet_twr_ieta_.push_back((*ith).id().ieta()); + ppfjet_twr_iphi_.push_back((*ith).id().iphi()); + ppfjet_twr_depth_.push_back((*ith).id().depth()); + ppfjet_twr_subdet_.push_back((*ith).id().subdet()); + ppfjet_twr_hade_.push_back((*ith).energy()); + ppfjet_twr_frac_.push_back(1.0); + ppfjet_twr_hadind_.push_back(ppfjet_had_n_ - 1); + ppfjet_twr_elmttype_.push_back(2); + ppfjet_twr_clusterind_.push_back(-1); + ppfjet_twr_candtrackind_.push_back(-1); + float avgeta = (cv[0].eta() + cv[2].eta())/2.0; + float avgphi = (static_cast(cv[0].phi()) + static_cast(cv[2].phi()))/2.0; + if(cv[0].phi() < cv[2].phi()) avgphi = (2.0*3.141592653 + static_cast(cv[0].phi()) + static_cast(cv[2].phi()))/2.0; + ppfjet_twr_dR_.push_back(deltaR(ppfjet_eta_,ppfjet_phi_,avgeta,avgphi)); + ++ppfjet_ntwrs_; + HFEM_E += (*ith).energy(); + } + } + } + else if(elements[iEle].type() == reco::PFBlockElement::HO){ // Element is HO + reco::PFClusterRef clusterref = elements[iEle].clusterRef(); + reco::PFCluster cluster = *clusterref; + double cluster_dR = deltaR(ppfjet_eta_,ppfjet_phi_,cluster.eta(),cluster.phi()); + if(ppfjet_clusters.count(cluster_dR) == 0){ + ppfjet_clusters[cluster_dR] = ppfjet_cluster_n_; + ppfjet_cluster_eta_.push_back(cluster.eta()); + ppfjet_cluster_phi_.push_back(cluster.phi()); + ppfjet_cluster_dR_.push_back(cluster_dR); + ppfjet_cluster_n_++; + } + int cluster_ind = ppfjet_clusters[cluster_dR]; + + std::vector> hitsAndFracs = cluster.hitsAndFractions(); + int nHits = hitsAndFracs.size(); + for(int iHit=0; iHit>::const_iterator ith=horeco->begin(); ith!=horeco->end(); ++ith){ + int etaPhiRecHit = getEtaPhi((*ith).id()); + if(etaPhiPF == etaPhiRecHit){ + ppfjet_had_ntwrs_.at(ppfjet_had_n_ - 1)++; + if(ppfjet_rechits.count((*ith).id()) == 0){ + ppfjet_twr_ieta_.push_back((*ith).id().ieta()); + ppfjet_twr_iphi_.push_back((*ith).id().iphi()); + ppfjet_twr_depth_.push_back((*ith).id().depth()); + ppfjet_twr_subdet_.push_back((*ith).id().subdet()); + ppfjet_twr_hade_.push_back((*ith).energy()); + ppfjet_twr_frac_.push_back(hitsAndFracs[iHit].second); + ppfjet_rechits[(*ith).id()].second.insert(hitsAndFracs[iHit].second); + ppfjet_twr_hadind_.push_back(ppfjet_had_n_ - 1); + ppfjet_twr_elmttype_.push_back(3); + ppfjet_twr_clusterind_.push_back(cluster_ind); + if(hasTrack){ + ppfjet_twr_candtrackind_.push_back(ppfjet_ncandtracks_ - 1); + } + else{ + ppfjet_twr_candtrackind_.push_back(-1); + } + const CaloCellGeometry *thisCell = HOGeom->getGeometry((*ith).id().rawId()); + const CaloCellGeometry::CornersVec& cv = thisCell->getCorners(); + float avgeta = (cv[0].eta() + cv[2].eta())/2.0; + float avgphi = (static_cast(cv[0].phi()) + static_cast(cv[2].phi()))/2.0; + if(cv[0].phi() < cv[2].phi()) avgphi = (2.0*3.141592653 + static_cast(cv[0].phi()) + static_cast(cv[2].phi()))/2.0; + ppfjet_twr_dR_.push_back(deltaR(ppfjet_eta_,ppfjet_phi_,avgeta,avgphi)); + ppfjet_rechits[(*ith).id()].first = ppfjet_ntwrs_; + ++ppfjet_ntwrs_; + } + else if(ppfjet_rechits[(*ith).id()].second.count(hitsAndFracs[iHit].second) == 0){ + ppfjet_twr_frac_.at(ppfjet_rechits[(*ith).id()].first) += hitsAndFracs[iHit].second; + if(cluster_dR < ppfjet_cluster_dR_.at(ppfjet_twr_clusterind_.at(ppfjet_rechits[(*ith).id()].first))){ + ppfjet_twr_clusterind_.at(ppfjet_rechits[(*ith).id()].first) = cluster_ind; + } + ppfjet_rechits[(*ith).id()].second.insert(hitsAndFracs[iHit].second); + } + } // Test if ieta,iphi match + } // Loop over rechits + } // Loop over hits + } // Test if element is from HO + } // Test for right element index + } // Loop over elements + } // Loop over elements in blocks + switch(candidateType){ + case reco::PFCandidate::h_HF: + ppfjet_had_emf_.push_back(HFEM_E/(HFEM_E + HFHAD_E)); + break; + case reco::PFCandidate::egamma_HF: + ppfjet_had_emf_.push_back(-1); + break; + default: + ppfjet_had_emf_.push_back(-1); + break; + } + } // Loop over PF constitutents + + int probe_had_EcalE = 0; + int probe_had_rawHcalE = 0; + for(int i=0; ieta())-std::fabs(pf_probe.jet()->eta())); + pf_dijet_dphi_=pf_tag.jet()->phi()-pf_probe.jet()->phi(); + if(pf_dijet_dphi_>3.1415) pf_dijet_dphi_ = 6.2832-pf_dijet_dphi_; + pf_dijet_balance_ = (tpfjet_pt_-ppfjet_pt_)/(tpfjet_pt_+ppfjet_pt_); + + tree_->Fill(); - tree->Fill(); - + return; } - // ------------ method called once each job just before starting event loop ------------ -void -DiJetAnalyzer::beginJob() +void DiJetAnalyzer::beginJob() { + // book histograms + rootfile_ = new TFile(rootHistFilename_.c_str(), "RECREATE"); - hOutputFile = new TFile( fOutputFileName.c_str(), "RECREATE" ) ; - - tree = new TTree("hcalCalibTree", "Tree for IsoTrack Calibration"); + h_PassSelPF_ = new TH1D("h_PassSelectionPF", "Selection Pass Failures PFJets",200,-0.5,199.5); - cells = new TClonesArray("TCell"); - tagJetP4 = new TLorentzVector(); - probeJetP4 = new TLorentzVector(); - + tree_ = new TTree("dijettree", "tree for dijet balancing"); - tree->Branch("eventNumber", &eventNumber, "eventNumber/i"); - tree->Branch("runNumber", &runNumber, "runNumber/i"); - tree->Branch("iEtaHit", &iEtaHit, "iEtaHit/I"); - tree->Branch("iPhiHit", &iPhiHit, "iPhiHit/i"); + tree_->Branch("tpfjet_pt",&tpfjet_pt_, "tpfjet_pt/F"); + tree_->Branch("tpfjet_p",&tpfjet_p_, "tpfjet_p/F"); + tree_->Branch("tpfjet_E",&tpfjet_E_, "tpfjet_E/F"); + tree_->Branch("tpfjet_eta",&tpfjet_eta_, "tpfjet_eta/F"); + tree_->Branch("tpfjet_phi",&tpfjet_phi_, "tpfjet_phi/F"); + tree_->Branch("tpfjet_EMfrac",&tpfjet_EMfrac_, "tpfjet_EMfrac/F"); + tree_->Branch("tpfjet_hadEcalEfrac",&tpfjet_hadEcalEfrac_, "tpfjet_hadEcalEfrac/F"); + tree_->Branch("tpfjet_scale",&tpfjet_scale_, "tpfjet_scale/F"); + tree_->Branch("tpfjet_area",&tpfjet_area_, "tpfjet_area/F"); + tree_->Branch("tpfjet_jetID",&tpfjet_jetID_, "tpfjet_jetID/I"); + tree_->Branch("tpfjet_unkown_E",&tpfjet_unkown_E_, "tpfjet_unkown_E/F"); + tree_->Branch("tpfjet_electron_E",&tpfjet_electron_E_, "tpfjet_electron_E/F"); + tree_->Branch("tpfjet_muon_E",&tpfjet_muon_E_, "tpfjet_muon_E/F"); + tree_->Branch("tpfjet_photon_E",&tpfjet_photon_E_, "tpfjet_photon_E/F"); + tree_->Branch("tpfjet_unkown_px",&tpfjet_unkown_px_, "tpfjet_unkown_px/F"); + tree_->Branch("tpfjet_electron_px",&tpfjet_electron_px_, "tpfjet_electron_px/F"); + tree_->Branch("tpfjet_muon_px",&tpfjet_muon_px_, "tpfjet_muon_px/F"); + tree_->Branch("tpfjet_photon_px",&tpfjet_photon_px_, "tpfjet_photon_px/F"); + tree_->Branch("tpfjet_unkown_py",&tpfjet_unkown_py_, "tpfjet_unkown_py/F"); + tree_->Branch("tpfjet_electron_py",&tpfjet_electron_py_, "tpfjet_electron_py/F"); + tree_->Branch("tpfjet_muon_py",&tpfjet_muon_py_, "tpfjet_muon_py/F"); + tree_->Branch("tpfjet_photon_py",&tpfjet_photon_py_, "tpfjet_photon_py/F"); + tree_->Branch("tpfjet_unkown_pz",&tpfjet_unkown_pz_, "tpfjet_unkown_pz/F"); + tree_->Branch("tpfjet_electron_pz",&tpfjet_electron_pz_, "tpfjet_electron_pz/F"); + tree_->Branch("tpfjet_muon_pz",&tpfjet_muon_pz_, "tpfjet_muon_pz/F"); + tree_->Branch("tpfjet_photon_pz",&tpfjet_photon_pz_, "tpfjet_photon_pz/F"); + tree_->Branch("tpfjet_unkown_EcalE",&tpfjet_unkown_EcalE_, "tpfjet_unkown_EcalE/F"); + tree_->Branch("tpfjet_electron_EcalE",&tpfjet_electron_EcalE_, "tpfjet_electron_EcalE/F"); + tree_->Branch("tpfjet_muon_EcalE",&tpfjet_muon_EcalE_, "tpfjet_muon_EcalE/F"); + tree_->Branch("tpfjet_photon_EcalE",&tpfjet_photon_EcalE_, "tpfjet_photon_EcalE/F"); + tree_->Branch("tpfjet_unkown_n",&tpfjet_unkown_n_, "tpfjet_unkown_n/I"); + tree_->Branch("tpfjet_electron_n",&tpfjet_electron_n_, "tpfjet_electron_n/I"); + tree_->Branch("tpfjet_muon_n",&tpfjet_muon_n_, "tpfjet_muon_n/I"); + tree_->Branch("tpfjet_photon_n",&tpfjet_photon_n_, "tpfjet_photon_n/I"); + tree_->Branch("tpfjet_had_n",&tpfjet_had_n_, "tpfjet_had_n/I"); + tree_->Branch("tpfjet_had_E",&tpfjet_had_E_); + tree_->Branch("tpfjet_had_px",&tpfjet_had_px_); + tree_->Branch("tpfjet_had_py",&tpfjet_had_py_); + tree_->Branch("tpfjet_had_pz",&tpfjet_had_pz_); + tree_->Branch("tpfjet_had_EcalE",&tpfjet_had_EcalE_); + tree_->Branch("tpfjet_had_rawHcalE",&tpfjet_had_rawHcalE_); + tree_->Branch("tpfjet_had_emf",&tpfjet_had_emf_); + tree_->Branch("tpfjet_had_id",&tpfjet_had_id_); + tree_->Branch("tpfjet_had_candtrackind",&tpfjet_had_candtrackind_); + tree_->Branch("tpfjet_had_ntwrs",&tpfjet_had_ntwrs_); + tree_->Branch("tpfjet_ntwrs",&tpfjet_ntwrs_, "tpfjet_ntwrs/I"); + tree_->Branch("tpfjet_twr_ieta",&tpfjet_twr_ieta_); + tree_->Branch("tpfjet_twr_iphi",&tpfjet_twr_iphi_); + tree_->Branch("tpfjet_twr_depth",&tpfjet_twr_depth_); + tree_->Branch("tpfjet_twr_subdet",&tpfjet_twr_subdet_); + tree_->Branch("tpfjet_twr_hade",&tpfjet_twr_hade_); + tree_->Branch("tpfjet_twr_frac",&tpfjet_twr_frac_); + tree_->Branch("tpfjet_twr_candtrackind",&tpfjet_twr_candtrackind_); + tree_->Branch("tpfjet_twr_hadind",&tpfjet_twr_hadind_); + tree_->Branch("tpfjet_twr_elmttype",&tpfjet_twr_elmttype_); + tree_->Branch("tpfjet_twr_dR",&tpfjet_twr_dR_); + tree_->Branch("tpfjet_twr_clusterind",&tpfjet_twr_clusterind_); + tree_->Branch("tpfjet_cluster_n",&tpfjet_cluster_n_, "tpfjet_cluster_n/I"); + tree_->Branch("tpfjet_cluster_eta",&tpfjet_cluster_eta_); + tree_->Branch("tpfjet_cluster_phi",&tpfjet_cluster_phi_); + tree_->Branch("tpfjet_cluster_dR",&tpfjet_cluster_dR_); + tree_->Branch("tpfjet_ncandtracks",&tpfjet_ncandtracks_, "tpfjet_ncandtracks/I"); + tree_->Branch("tpfjet_candtrack_px",&tpfjet_candtrack_px_); + tree_->Branch("tpfjet_candtrack_py",&tpfjet_candtrack_py_); + tree_->Branch("tpfjet_candtrack_pz",&tpfjet_candtrack_pz_); + tree_->Branch("tpfjet_candtrack_EcalE",&tpfjet_candtrack_EcalE_); + tree_->Branch("ppfjet_pt",&ppfjet_pt_, "ppfjet_pt/F"); + tree_->Branch("ppfjet_p",&ppfjet_p_, "ppfjet_p/F"); + tree_->Branch("ppfjet_E",&ppfjet_E_, "ppfjet_E/F"); + tree_->Branch("ppfjet_eta",&ppfjet_eta_, "ppfjet_eta/F"); + tree_->Branch("ppfjet_phi",&ppfjet_phi_, "ppfjet_phi/F"); + tree_->Branch("ppfjet_EMfrac",&ppfjet_EMfrac_, "ppfjet_EMfrac/F"); + tree_->Branch("ppfjet_hadEcalEfrac",&ppfjet_hadEcalEfrac_, "ppfjet_hadEcalEfrac/F"); + tree_->Branch("ppfjet_scale",&ppfjet_scale_, "ppfjet_scale/F"); + tree_->Branch("ppfjet_area",&ppfjet_area_, "ppfjet_area/F"); + tree_->Branch("ppfjet_jetID",&ppfjet_jetID_, "ppfjet_jetID/I"); + tree_->Branch("ppfjet_unkown_E",&ppfjet_unkown_E_, "ppfjet_unkown_E/F"); + tree_->Branch("ppfjet_electron_E",&ppfjet_electron_E_, "ppfjet_electron_E/F"); + tree_->Branch("ppfjet_muon_E",&ppfjet_muon_E_, "ppfjet_muon_E/F"); + tree_->Branch("ppfjet_photon_E",&ppfjet_photon_E_, "ppfjet_photon_E/F"); + tree_->Branch("ppfjet_unkown_px",&ppfjet_unkown_px_, "ppfjet_unkown_px/F"); + tree_->Branch("ppfjet_electron_px",&ppfjet_electron_px_, "ppfjet_electron_px/F"); + tree_->Branch("ppfjet_muon_px",&ppfjet_muon_px_, "ppfjet_muon_px/F"); + tree_->Branch("ppfjet_photon_px",&ppfjet_photon_px_, "ppfjet_photon_px/F"); + tree_->Branch("ppfjet_unkown_py",&ppfjet_unkown_py_, "ppfjet_unkown_py/F"); + tree_->Branch("ppfjet_electron_py",&ppfjet_electron_py_, "ppfjet_electron_py/F"); + tree_->Branch("ppfjet_muon_py",&ppfjet_muon_py_, "ppfjet_muon_py/F"); + tree_->Branch("ppfjet_photon_py",&ppfjet_photon_py_, "ppfjet_photon_py/F"); + tree_->Branch("ppfjet_unkown_pz",&ppfjet_unkown_pz_, "ppfjet_unkown_pz/F"); + tree_->Branch("ppfjet_electron_pz",&ppfjet_electron_pz_, "ppfjet_electron_pz/F"); + tree_->Branch("ppfjet_muon_pz",&ppfjet_muon_pz_, "ppfjet_muon_pz/F"); + tree_->Branch("ppfjet_photon_pz",&ppfjet_photon_pz_, "ppfjet_photon_pz/F"); + tree_->Branch("ppfjet_unkown_EcalE",&ppfjet_unkown_EcalE_, "ppfjet_unkown_EcalE/F"); + tree_->Branch("ppfjet_electron_EcalE",&ppfjet_electron_EcalE_, "ppfjet_electron_EcalE/F"); + tree_->Branch("ppfjet_muon_EcalE",&ppfjet_muon_EcalE_, "ppfjet_muon_EcalE/F"); + tree_->Branch("ppfjet_photon_EcalE",&ppfjet_photon_EcalE_, "ppfjet_photon_EcalE/F"); + tree_->Branch("ppfjet_unkown_n",&ppfjet_unkown_n_, "ppfjet_unkown_n/I"); + tree_->Branch("ppfjet_electron_n",&ppfjet_electron_n_, "ppfjet_electron_n/I"); + tree_->Branch("ppfjet_muon_n",&ppfjet_muon_n_, "ppfjet_muon_n/I"); + tree_->Branch("ppfjet_photon_n",&ppfjet_photon_n_, "ppfjet_photon_n/I"); + tree_->Branch("ppfjet_had_n",&ppfjet_had_n_, "ppfjet_had_n/I"); + tree_->Branch("ppfjet_had_E",&ppfjet_had_E_); + tree_->Branch("ppfjet_had_px",&ppfjet_had_px_); + tree_->Branch("ppfjet_had_py",&ppfjet_had_py_); + tree_->Branch("ppfjet_had_pz",&ppfjet_had_pz_); + tree_->Branch("ppfjet_had_EcalE",&ppfjet_had_EcalE_); + tree_->Branch("ppfjet_had_rawHcalE",&ppfjet_had_rawHcalE_); + tree_->Branch("ppfjet_had_emf",&ppfjet_had_emf_); + tree_->Branch("ppfjet_had_id",&ppfjet_had_id_); + tree_->Branch("ppfjet_had_candtrackind",&ppfjet_had_candtrackind_); + tree_->Branch("ppfjet_had_ntwrs",&ppfjet_had_ntwrs_); + tree_->Branch("ppfjet_ntwrs",&ppfjet_ntwrs_, "ppfjet_ntwrs/I"); + tree_->Branch("ppfjet_twr_ieta",&ppfjet_twr_ieta_); + tree_->Branch("ppfjet_twr_iphi",&ppfjet_twr_iphi_); + tree_->Branch("ppfjet_twr_depth",&ppfjet_twr_depth_); + tree_->Branch("ppfjet_twr_subdet",&ppfjet_twr_subdet_); + tree_->Branch("ppfjet_twr_hade",&ppfjet_twr_hade_); + tree_->Branch("ppfjet_twr_frac",&ppfjet_twr_frac_); + tree_->Branch("ppfjet_twr_candtrackind",&ppfjet_twr_candtrackind_); + tree_->Branch("ppfjet_twr_hadind",&ppfjet_twr_hadind_); + tree_->Branch("ppfjet_twr_elmttype",&ppfjet_twr_elmttype_); + tree_->Branch("ppfjet_twr_dR",&ppfjet_twr_dR_); + tree_->Branch("ppfjet_twr_clusterind",&ppfjet_twr_clusterind_); + tree_->Branch("ppfjet_cluster_n",&ppfjet_cluster_n_, "ppfjet_cluster_n/I"); + tree_->Branch("ppfjet_cluster_eta",&ppfjet_cluster_eta_); + tree_->Branch("ppfjet_cluster_phi",&ppfjet_cluster_phi_); + tree_->Branch("ppfjet_cluster_dR",&ppfjet_cluster_dR_); + tree_->Branch("ppfjet_ncandtracks",&ppfjet_ncandtracks_, "ppfjet_ncandtracks/I"); + tree_->Branch("ppfjet_candtrack_px",&ppfjet_candtrack_px_); + tree_->Branch("ppfjet_candtrack_py",&ppfjet_candtrack_py_); + tree_->Branch("ppfjet_candtrack_pz",&ppfjet_candtrack_pz_); + tree_->Branch("ppfjet_candtrack_EcalE",&ppfjet_candtrack_EcalE_); + tree_->Branch("pf_dijet_deta",&pf_dijet_deta_, "pf_dijet_deta/F"); + tree_->Branch("pf_dijet_dphi",&pf_dijet_dphi_, "pf_dijet_dphi/F"); + tree_->Branch("pf_dijet_balance",&pf_dijet_balance_, "pf_dijet_balance/F"); + tree_->Branch("pf_thirdjet_px",&pf_thirdjet_px_, "pf_thirdjet_px/F"); + tree_->Branch("pf_thirdjet_py",&pf_thirdjet_py_, "pf_thirdjet_py/F"); + tree_->Branch("pf_realthirdjet_px",&pf_realthirdjet_px_, "pf_realthirdjet_px/F"); + tree_->Branch("pf_realthirdjet_py",&pf_realthirdjet_py_, "pf_realthirdjet_py/F"); + tree_->Branch("pf_realthirdjet_scale",&pf_realthirdjet_scale_, "pf_realthirdjet_scale/F"); + tree_->Branch("pf_Run",&pf_Run_, "pf_Run/I"); + tree_->Branch("pf_Lumi",&pf_Lumi_, "pf_Lumi/I"); + tree_->Branch("pf_Event",&pf_Event_, "pf_Event/I"); + tree_->Branch("pf_NPV",&pf_NPV_, "pf_NPV/I"); - - tree->Branch("xTrkHcal", &xTrkHcal, "xTrkHcal/F"); - tree->Branch("yTrkHcal", &yTrkHcal, "yTrkHcal/F"); - tree->Branch("zTrkHcal", &zTrkHcal, "zTrkHcal/F"); - - tree->Branch("PxTrkHcal", &PxTrkHcal, "PxTrkHcal/F"); - tree->Branch("PyTrkHcal", &PyTrkHcal, "PyTrkHcal/F"); - tree->Branch("PzTrkHcal", &PzTrkHcal, "PzTrkHcal/F"); - - tree->Branch("cells", &cells, 64000); - tree->Branch("emEnergy", &emEnergy, "emEnergy/F"); - tree->Branch("targetE", &targetE, "targetE/F"); - tree->Branch("etVetoJet", &etVetoJet, "etVetoJet/F"); - tree->Branch("tagJetP4", "TLorentzVector", &tagJetP4); - tree->Branch("probeJetP4", "TLorentzVector", &probeJetP4); - tree->Branch("tagJetEmFrac", &tagJetEmFrac,"tagJetEmFrac/F"); - tree->Branch("probeJetEmFrac", &probeJetEmFrac,"probeJetEmFrac/F"); - -} + return; +} // ------------ method called once each job just after ending the event loop ------------ void DiJetAnalyzer::endJob() { + // write histograms + rootfile_->cd(); + + h_PassSelPF_->Write(); + tree_->Write(); - hOutputFile->SetCompressionLevel(2); - hOutputFile->cd(); - tree->Write(); - hOutputFile->Close() ; + rootfile_->Close(); } + +// helper function + +double DiJetAnalyzer::deltaR(const reco::Jet* j1, const reco::Jet* j2) +{ + double deta = j1->eta()-j2->eta(); + double dphi = std::fabs(j1->phi()-j2->phi()); + if(dphi>3.1415927) dphi = 2*3.1415927 - dphi; + return std::sqrt(deta*deta + dphi*dphi); } + +double DiJetAnalyzer::deltaR(const double eta1, const double phi1, const double eta2, const double phi2) +{ + double deta = eta1 - eta2; + double dphi = std::fabs(phi1 - phi2); + if(dphi>3.1415927) dphi = 2*3.1415927 - dphi; + return std::sqrt(deta*deta + dphi*dphi); +} + +int DiJetAnalyzer::getEtaPhi(const DetId id) +{ + return id.rawId() & 0x3FFF; // Get 14 least-significant digits +} + +int DiJetAnalyzer::getEtaPhi(const HcalDetId id) +{ + return id.rawId() & 0x3FFF; // Get 14 least-significant digits +} + + +//define this as a plug-in +DEFINE_FWK_MODULE(DiJetAnalyzer); diff --git a/Calibration/HcalCalibAlgos/src/GammaJetAnalysis.cc b/Calibration/HcalCalibAlgos/src/GammaJetAnalysis.cc index bac41bc4a247b..a0e51dbab8bf3 100644 --- a/Calibration/HcalCalibAlgos/src/GammaJetAnalysis.cc +++ b/Calibration/HcalCalibAlgos/src/GammaJetAnalysis.cc @@ -1,427 +1,1942 @@ -// user include files -#include "GammaJetAnalysis.h" - -#include "FWCore/Framework/interface/Frameworkfwd.h" -#include "FWCore/Framework/interface/EDAnalyzer.h" -#include "FWCore/Framework/interface/Event.h" -/* #include "FWCore/Framework/interface/MakerMacros.h" */ -#include "FWCore/Framework/interface/ESHandle.h" -#include "FWCore/Framework/interface/EventSetup.h" - -#include "DataFormats/Common/interface/Ref.h" -#include "DataFormats/DetId/interface/DetId.h" - -#include "Geometry/Records/interface/CaloGeometryRecord.h" -#include "Geometry/CaloGeometry/interface/CaloGeometry.h" -#include "DataFormats/GeometryVector/interface/GlobalPoint.h" -#include "DataFormats/CaloTowers/interface/CaloTowerCollection.h" -#include "DataFormats/CaloTowers/interface/CaloTowerDetId.h" -// #include "DataFormats/HcalRecHit/interface/HcalRecHitCollections.h" -// #include "DataFormats/EcalRecHit/interface/EcalRecHitCollections.h" -#include "DataFormats/JetReco/interface/CaloJetCollection.h" -#include "DataFormats/JetReco/interface/CaloJet.h" -#include "DataFormats/JetReco/interface/GenJetCollection.h" -//#include "DataFormats/JetReco/interface/GenJetfwd.h" -#include "DataFormats/JetReco/interface/GenJet.h" - -//#include "DataFormats/JetReco/interface/CaloJetCollection.h" -#include "DataFormats/EgammaReco/interface/BasicCluster.h" -#include "DataFormats/EgammaReco/interface/SuperCluster.h" -#include "DataFormats/EgammaReco/interface/ClusterShape.h" - -#include "SimDataFormats/GeneratorProducts/interface/HepMCProduct.h" -#include "DataFormats/Provenance/interface/Provenance.h" -#include "HepMC/GenParticle.h" -#include "HepMC/GenVertex.h" -#include "TFile.h" +// +#include "Calibration/HcalCalibAlgos/src/GammaJetAnalysis.h" +#include "JetMETCorrections/Objects/interface/JetCorrector.h" +#include "FWCore/Utilities/interface/EDMException.h" +#include "FWCore/MessageLogger/interface/MessageLogger.h" +#include "RecoEgamma/EgammaElectronAlgos/interface/ElectronHcalHelper.h" +#include "RecoEgamma/EgammaTools/interface/ConversionTools.h" +#include "RecoEgamma/EgammaTools/interface/ConversionFinder.h" +#include "DataFormats/EgammaCandidates/interface/GsfElectron.h" +#include "CondFormats/JetMETObjects/interface/JetCorrectorParameters.h" +#include "JetMETCorrections/Objects/interface/JetCorrectionsRecord.h" +#include "DataFormats/Common/interface/TriggerResults.h" +#include "HLTrigger/HLTcore/interface/HLTConfigProvider.h" +#include "FWCore/Common/interface/TriggerNames.h" #include "TTree.h" +#include "TFile.h" +#include "TClonesArray.h" +#include +#include +#include +#include +#include +inline void HERE(const char *msg) { + if (0 && msg) edm::LogWarning("GammaJetAnalysis") << msg; +} -using namespace std; -namespace cms -{ -GammaJetAnalysis::GammaJetAnalysis(const edm::ParameterSet& iConfig) +double getNeutralPVCorr(double eta, int intNPV, double area, bool isMC_) { + double NPV = static_cast(intNPV); + double etaArray[101] = {-5, -4.9, -4.8, -4.7, -4.6, -4.5, -4.4, -4.3, -4.2, -4.1, -4, -3.9, -3.8, -3.7, -3.6, -3.5, -3.4, -3.3, -3.2, -3.1, -3, -2.9, -2.8, -2.7, -2.6, -2.5, -2.4, -2.3, -2.2, -2.1, -2, -1.9, -1.8, -1.7, -1.6, -1.5, -1.4, -1.3, -1.2, -1.1, -1, -0.9, -0.8, -0.7, -0.6, -0.5, -0.4, -0.3, -0.2, -0.1, 0, 0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9, 1, 1.1, 1.2, 1.3, 1.4, 1.5, 1.6, 1.7, 1.8, 1.9, 2, 2.1, 2.2, 2.3, 2.4, 2.5, 2.6, 2.7, 2.8, 2.9, 3, 3.1, 3.2, 3.3, 3.4, 3.5, 3.6, 3.7, 3.8, 3.9, 4, 4.1, 4.2, 4.3, 4.4, 4.5, 4.6, 4.7, 4.8, 4.9, 5}; + int ind = -1; + for(int i=0; i<100; ++i){ + if(eta > etaArray[i] && eta < etaArray[i+1]){ + ind = i; + break; + } + } + if(ind < 0) return 0; + double pt_density; + if(isMC_){ + double p0[100] = {0.08187, 0.096718, 0.11565, 0.12115, 0.12511, 0.12554, 0.13858, 0.14282, 0.14302, 0.15054, 0.14136, 0.14992, 0.13812, 0.13771, 0.13165, 0.12609, 0.12446, 0.11311, 0.13771, 0.16401, 0.20454, 0.27899, 0.34242, 0.43096, 0.50742, 0.59683, 0.66877, 0.68664, 0.69541, 0.66873, 0.64175, 0.61097, 0.58524, 0.5712, 0.55752, 0.54869, 0.31073, 0.22667, 0.55614, 0.55962, 0.54348, 0.53206, 0.51594, 0.49928, 0.49139, 0.48766, 0.49157, 0.49587, 0.50109, 0.5058, 0.51279, 0.51515, 0.51849, 0.52607, 0.52362, 0.52169, 0.53579, 0.54821, 0.56262, 0.58355, 0.58809, 0.57525, 0.52539, 0.53505, 0.52307, 0.52616, 0.52678, 0.53536, 0.55141, 0.58107, 0.60556, 0.62601, 0.60897, 0.59018, 0.49593, 0.40462, 0.32052, 0.24436, 0.18867, 0.12591, 0.095421, 0.090578, 0.078767, 0.11797, 0.14057, 0.14614, 0.15232, 0.14742, 0.15647, 0.14947, 0.15805, 0.14467, 0.14526, 0.14081, 0.1262, 0.12429, 0.11951, 0.11146, 0.095677, 0.083126}; + double p1[100] = {0.26831, 0.30901, 0.37017, 0.38747, 0.41547, 0.45237, 0.49963, 0.54074, 0.54949, 0.5937, 0.56904, 0.60766, 0.58042, 0.59823, 0.58535, 0.54594, 0.58403, 0.601, 0.65401, 0.65049, 0.65264, 0.6387, 0.60646, 0.59669, 0.55561, 0.5053, 0.42889, 0.37264, 0.36456, 0.36088, 0.36728, 0.37439, 0.38779, 0.40133, 0.40989, 0.41722, 0.47539, 0.49848, 0.42642, 0.42431, 0.42113, 0.41285, 0.41003, 0.41116, 0.41231, 0.41634, 0.41795, 0.41806, 0.41786, 0.41765, 0.41779, 0.41961, 0.42144, 0.42192, 0.4209, 0.41885, 0.4163, 0.4153, 0.41864, 0.4257, 0.43018, 0.43218, 0.43798, 0.42723, 0.42185, 0.41349, 0.40553, 0.39132, 0.3779, 0.37055, 0.36522, 0.37057, 0.38058, 0.43259, 0.51052, 0.55918, 0.60178, 0.60995, 0.64087, 0.65554, 0.65308, 0.65654, 0.60466, 0.58678, 0.54392, 0.58277, 0.59651, 0.57916, 0.60744, 0.56882, 0.59323, 0.5499, 0.54003, 0.49938, 0.4511, 0.41499, 0.38676, 0.36955, 0.30803, 0.26659}; + double p2[100] = {0.00080918, 0.00083447, 0.0011378, 0.0011221, 0.0013613, 0.0016362, 0.0015854, 0.0019131, 0.0017474, 0.0020078, 0.001856, 0.0020331, 0.0020823, 0.001898, 0.0020096, 0.0016464, 0.0032413, 0.0045615, 0.0054495, 0.0057584, 0.0058982, 0.0058956, 0.0055109, 0.0051433, 0.0042098, 0.0032096, 0.00044089, -0.0003884, -0.0007059, -0.00092769, -0.001116, -0.0010437, -0.00080318, -0.00044142, 6.7232e-05, 0.00055265, -0.0014486, -0.0020432, 0.0015121, 0.0016343, 0.0015638, 0.0015707, 0.0014403, 0.0012886, 0.0011684, 0.00099089, 0.00091497, 0.00087915, 0.00084703, 0.00084542, 0.00087419, 0.00088013, 0.00090493, 0.00095853, 0.0010389, 0.0011191, 0.0012643, 0.0013833, 0.001474, 0.0015401, 0.0015582, 0.0014265, 0.00087453, 0.00086639, 0.00042986, -5.0257e-06, -0.00053124, -0.00086417, -0.0011228, -0.0011749, -0.0010068, -0.00083012, -0.00062906, 0.00021515, 0.0028714, 0.0038835, 0.0047212, 0.0051427, 0.0055762, 0.0055872, 0.0054989, 0.0053033, 0.0044519, 0.0032223, 0.0017641, 0.0021165, 0.0019909, 0.0021061, 0.0020322, 0.0018357, 0.0019829, 0.001683, 0.0018553, 0.0015304, 0.0015822, 0.0013119, 0.0010745, 0.0010808, 0.00080678, 0.00079756}; + pt_density = p0[ind] + p1[ind]*(NPV - 1) + p2[ind]*(NPV - 1)*(NPV - 1); + } + else{ + double p0[100] = {0.12523, 0.14896, 0.17696, 0.19376, 0.20038, 0.21353, 0.25069, 0.27089, 0.29124, 0.31947, 0.31781, 0.35453, 0.35424, 0.38159, 0.39453, 0.4003, 0.34798, 0.26303, 0.24824, 0.22857, 0.22609, 0.26793, 0.30096, 0.37637, 0.44461, 0.55692, 0.70328, 0.72458, 0.75065, 0.73569, 0.72485, 0.69933, 0.69804, 0.70775, 0.70965, 0.71439, 0.72189, 0.73691, 0.74847, 0.74968, 0.73467, 0.70115, 0.6732, 0.65971, 0.65724, 0.67751, 0.69569, 0.70905, 0.71815, 0.72119, 0.72128, 0.71645, 0.70588, 0.68958, 0.66978, 0.65959, 0.66889, 0.68713, 0.71063, 0.74283, 0.75153, 0.74733, 0.73335, 0.71346, 0.70168, 0.69445, 0.68841, 0.67761, 0.67654, 0.6957, 0.70276, 0.71057, 0.68176, 0.64651, 0.49156, 0.38366, 0.31375, 0.24127, 0.21395, 0.17783, 0.19026, 0.21486, 0.24689, 0.3434, 0.40184, 0.39876, 0.3873, 0.36462, 0.36337, 0.32777, 0.328, 0.29868, 0.28087, 0.25713, 0.22466, 0.20784, 0.19798, 0.18054, 0.15022, 0.12811}; + double p1[100] = {0.26829, 0.30825, 0.37034, 0.38736, 0.41645, 0.45985, 0.51433, 0.56215, 0.5805, 0.63926, 0.62007, 0.67895, 0.66015, 0.68817, 0.67975, 0.64161, 0.70887, 0.74454, 0.80197, 0.78873, 0.77892, 0.74943, 0.70034, 0.6735, 0.60774, 0.53312, 0.42132, 0.36279, 0.3547, 0.35014, 0.35655, 0.3646, 0.37809, 0.38922, 0.39599, 0.40116, 0.40468, 0.40645, 0.40569, 0.4036, 0.39874, 0.39326, 0.39352, 0.39761, 0.40232, 0.40729, 0.41091, 0.41247, 0.413, 0.41283, 0.41289, 0.4134, 0.41322, 0.41185, 0.40769, 0.40193, 0.39707, 0.39254, 0.39274, 0.3989, 0.40474, 0.40758, 0.40788, 0.40667, 0.40433, 0.40013, 0.39371, 0.38154, 0.36723, 0.3583, 0.35148, 0.35556, 0.36172, 0.41073, 0.50629, 0.57068, 0.62972, 0.65188, 0.69954, 0.72967, 0.74333, 0.76148, 0.71418, 0.69062, 0.63065, 0.67117, 0.68278, 0.66028, 0.68147, 0.62494, 0.64452, 0.58685, 0.57076, 0.52387, 0.47132, 0.42637, 0.39554, 0.37989, 0.31825, 0.27969}; + double p2[100] = {-0.0014595, -0.0014618, -0.0011988, -0.00095404, -5.3893e-05, 0.00018901, 0.00012553, 0.0004172, 0.00020229, 0.00051942, 0.00052088, 0.00076727, 0.0010407, 0.0010184, 0.0013442, 0.0011271, 0.0032841, 0.0045259, 0.0051803, 0.0054477, 0.0055691, 0.0056668, 0.0053084, 0.0050978, 0.0042061, 0.003321, 0.00045155, 0.00021376, 0.0001178, -2.6836e-05, -0.00017689, -0.00014723, 0.00016887, 0.00067322, 0.0012952, 0.0019229, 0.0024702, 0.0028854, 0.0031576, 0.003284, 0.0032643, 0.0031061, 0.0028377, 0.0025386, 0.0022583, 0.0020448, 0.001888, 0.0017968, 0.0017286, 0.0016989, 0.0017014, 0.0017302, 0.0017958, 0.0018891, 0.0020609, 0.0022876, 0.0025391, 0.0028109, 0.0030294, 0.0031867, 0.0032068, 0.0030755, 0.0028181, 0.0023893, 0.0018359, 0.0012192, 0.00061654, 0.00016088, -0.00015204, -0.00019503, -3.7236e-05, 0.00016663, 0.00033833, 0.00082988, 0.0034005, 0.0042941, 0.0050884, 0.0052612, 0.0055901, 0.0054357, 0.0052671, 0.0049174, 0.0042236, 0.0031138, 0.0011733, 0.0014057, 0.0010843, 0.0010992, 0.0007966, 0.00052196, 0.00053029, 0.00021273, 0.00041664, 0.00010455, 0.00015173, -9.7827e-05, -0.0010859, -0.0013748, -0.0016641, -0.0016887}; + pt_density = p0[ind] + p1[ind]*(NPV - 1) + p2[ind]*(NPV - 1)*(NPV - 1); + } + double ECorr = pt_density*area*cosh(eta); + return ECorr; +} + +// ------------------------------------------------- + +inline +unsigned int helper_findTrigger(const std::vector& list, + const std::string& name) { - // get names of modules, producing object collections + boost::regex re(std::string("^(")+name+"|"+name+"_v\\d*)$"); + for (unsigned int i = 0,n = list.size() ; i < n ; ++i) { + if(boost::regex_match(list[i],re)) return i; + } + return list.size(); +} - nameProd_ = iConfig.getUntrackedParameter("nameProd"); - jetCalo_ = iConfig.getUntrackedParameter("jetCalo","GammaJetJetBackToBackCollection"); +// ------------------------------------------------- - tok_jets_ = consumes( edm::InputTag(nameProd_, - jetCalo_) ); +GammaJetAnalysis::GammaJetAnalysis(const edm::ParameterSet& iConfig) { + // set parameters + debug_ = iConfig.getUntrackedParameter("debug", 0); + debugHLTTrigNames = iConfig.getUntrackedParameter("debugHLTTrigNames",1); + debugEvent = iConfig.getUntrackedParameter("debugEvent",0); + pfMETColl = iConfig.getParameter("PFMETColl"); + pfType1METColl = iConfig.getParameter("PFMETTYPE1Coll"); + rhoCollection_ = iConfig.getParameter("rhoColl"); + photonCollName_ = iConfig.getParameter("photonCollName"); + pfJetCollName_ = iConfig.getParameter("pfJetCollName"); + pfJetCorrName_ = iConfig.getParameter("pfJetCorrName"); + genJetCollName_ = iConfig.getParameter("genJetCollName"); + genParticleCollName_ = iConfig.getParameter("genParticleCollName"); + genEventInfoName_ = iConfig.getParameter("genEventInfoName"); + hbheRecHitName_ = iConfig.getParameter("hbheRecHitName"); + hfRecHitName_ = iConfig.getParameter("hfRecHitName"); + hoRecHitName_ = iConfig.getParameter("hoRecHitName"); + rootHistFilename_ = iConfig.getParameter("rootHistFilename"); + pvCollName_ = iConfig.getParameter("pvCollName"); + prodProcess_ = "MYGAMMA"; + if (iConfig.exists("prodProcess")) + prodProcess_ = iConfig.getUntrackedParameter("prodProcess"); - gammaClus_ = iConfig.getUntrackedParameter("gammaClus","GammaJetGammaBackToBackCollection"); + allowNoPhoton_ = iConfig.getParameter("allowNoPhoton"); + photonPtMin_ = iConfig.getParameter("photonPtMin"); + photonJetDPhiMin_ = iConfig.getParameter("photonJetDPhiMin"); + jetEtMin_ = iConfig.getParameter("jetEtMin"); + jet2EtMax_ = iConfig.getParameter("jet2EtMax"); + jet3EtMax_ = iConfig.getParameter("jet3EtMax"); + photonTrigNamesV_ = iConfig.getParameter>("photonTriggers"); + jetTrigNamesV_ = iConfig.getParameter>("jetTriggers"); + writeTriggerPrescale_= iConfig.getParameter("writeTriggerPrescale"); + doPFJets_ = iConfig.getParameter("doPFJets"); + doGenJets_ = iConfig.getParameter("doGenJets"); + workOnAOD_ = iConfig.getParameter("workOnAOD"); + ignoreHLT_ = iConfig.getUntrackedParameter("ignoreHLT",false); - tok_egamma_ = consumes( edm::InputTag(nameProd_, - gammaClus_) ); + eventWeight_ = 1.0; + eventPtHat_ = 0.; + nProcessed_ = 0; - ecalInput_=iConfig.getUntrackedParameter("ecalInput","GammaJetEcalRecHitCollection"); + //Get the tokens + // FAST FIX + if (workOnAOD_ < 2) { // origin data file + tok_Photon_ = consumes(photonCollName_); + tok_PFJet_ = consumes(pfJetCollName_); + tok_GenJet_ = consumes >(genJetCollName_); + tok_GenPart_ = consumes >(genParticleCollName_); + tok_GenEvInfo_ = consumes(genEventInfoName_); + tok_HBHE_ = consumes > >(hbheRecHitName_); + tok_HF_ = consumes > >(hfRecHitName_); + tok_HO_ = consumes > >(hoRecHitName_); + tok_loosePhoton_ = consumes >(edm::InputTag("PhotonIDProdGED","PhotonCutBasedIDLoose")); + tok_tightPhoton_ = consumes >(edm::InputTag("PhotonIDProdGED:PhotonCutBasedIDTight")); + tok_PFCand_ = consumes(edm::InputTag("particleFlow")); + tok_Vertex_ = consumes(edm::InputTag("offlinePrimaryVertices")); + tok_GsfElec_ = consumes(edm::InputTag("gsfElectrons")); + tok_Rho_ = consumes(rhoCollection_); + tok_Conv_ = consumes(edm::InputTag("allConversions")); + tok_BS_ = consumes(edm::InputTag("offlineBeamSpot")); + tok_PV_ = consumes >(pvCollName_); + tok_PFMET_ = consumes(pfMETColl); + tok_PFType1MET_ = consumes(pfType1METColl); + tok_TrigRes_ = consumes(edm::InputTag("TriggerResults::HLT")); - tok_ecal_ = consumes( edm::InputTag(nameProd_, ecalInput_) ); + } else { + // FAST FIX + const char* prod= "GammaJetProd"; + if (prodProcess_.size()==0) { + edm::LogError("GammaJetAnalysis") << "prodProcess needs to be defined"; + throw edm::Exception(edm::errors::ProductNotFound); + } + const char* an= prodProcess_.c_str(); + edm::LogWarning("GammaJetAnalysis") << "FAST FIX: changing " << photonCollName_ + << " to" << edm::InputTag(prod,photonCollName_,an); + tok_Photon_ = consumes(edm::InputTag(prod,photonCollName_,an)); + tok_PFJet_ = consumes(edm::InputTag(prod,pfJetCollName_,an)); + tok_GenJet_ = consumes >(edm::InputTag(prod,genJetCollName_,an)); + tok_GenPart_ = consumes >(edm::InputTag(prod,genParticleCollName_,an)); + tok_GenEvInfo_ = consumes(edm::InputTag(prod,genEventInfoName_,an)); + tok_HBHE_ = consumes > >(edm::InputTag(prod,hbheRecHitName_,an)); + tok_HF_ = consumes > >(edm::InputTag(prod,hfRecHitName_,an)); + tok_HO_ = consumes > >(edm::InputTag(prod,hoRecHitName_,an)); + //tok_loosePhoton_ = consumes >(edm::InputTag("PhotonIDProdGED","PhotonCutBasedIDLoose")); + //tok_tightPhoton_ = consumes >(edm::InputTag("PhotonIDProdGED:PhotonCutBasedIDTight")); + tok_loosePhotonV_ = consumes >(edm::InputTag(prod,"PhotonIDProdGED:PhotonCutBasedIDLoose",an)); + tok_tightPhotonV_ = consumes >(edm::InputTag(prod,"PhotonIDProdGED:PhotonCutBasedIDTight",an)); + tok_PFCand_ = consumes(edm::InputTag(prod,"particleFlow",an)); + tok_Vertex_ = consumes(edm::InputTag(prod,"offlinePrimaryVertices",an)); + tok_GsfElec_ = consumes(edm::InputTag(prod,"gedGsfElectrons",an)); + tok_Rho_ = consumes(edm::InputTag(prod,rhoCollection_.label(),an)); + tok_Conv_ = consumes(edm::InputTag(prod,"allConversions",an)); + tok_BS_ = consumes(edm::InputTag(prod,"offlineBeamSpot",an)); + tok_PV_ = consumes >(edm::InputTag(prod,pvCollName_,an)); + tok_PFMET_ = consumes(edm::InputTag(prod,pfMETColl.label(),an)); + tok_PFType1MET_ = consumes(edm::InputTag(prod,pfType1METColl.label(),an)); + TString HLTlabel = "TriggerResults::HLT"; + if (prodProcess_.find("reRECO")!=std::string::npos) + HLTlabel.ReplaceAll("HLT","reHLT"); + tok_TrigRes_ = consumes(edm::InputTag(prod,HLTlabel.Data(),an)); + } +} - hbheInput_ = iConfig.getUntrackedParameter("hbheInput"); +GammaJetAnalysis::~GammaJetAnalysis() {} + +// +// member functions +// + +// ------------ method called to for each event ------------ +void GammaJetAnalysis::analyze(const edm::Event& iEvent, const edm::EventSetup& evSetup) { + nProcessed_++; - tok_hbhe_ = consumes(edm::InputTag(nameProd_,hbheInput_)); + LogDebug("GammaJetAnalysis") << "nProcessed=" << nProcessed_ << "\n"; - hoInput_ = iConfig.getUntrackedParameter("hoInput"); + // 1st. Get Photons // + edm::Handle photons; + iEvent.getByToken(tok_Photon_, photons); + if(!photons.isValid()) { + edm::LogWarning("GammaJetAnalysis") << "Could not find PhotonCollection named " + << photonCollName_; + return; + } - tok_ho_ = consumes(edm::InputTag(nameProd_,hoInput_)); + if ((photons->size()==0) && !allowNoPhoton_) { + if (debug_>0) LogDebug("GammaJetAnalysis") << "No photons in the event"; + return; + } - hfInput_ = iConfig.getUntrackedParameter("hfInput"); + nPhotons_= photons->size(); + LogDebug("GammaJetAnalysis") << "nPhotons_=" << nPhotons_; - tok_hf_ = consumes(edm::InputTag(nameProd_,hfInput_)); + // Get photon quality flags + edm::Handle > loosePhotonQual, tightPhotonQual; + edm::Handle > loosePhotonQual_Vec, tightPhotonQual_Vec; + if (workOnAOD_ < 2) { + iEvent.getByToken(tok_loosePhoton_, loosePhotonQual); + iEvent.getByToken(tok_tightPhoton_, tightPhotonQual); + if (!loosePhotonQual.isValid() || !tightPhotonQual.isValid()) { + edm::LogWarning("GammaJetAnalysis") << "Failed to get photon quality flags"; + return; + } + } + else { + iEvent.getByToken(tok_loosePhotonV_, loosePhotonQual_Vec); + iEvent.getByToken(tok_tightPhotonV_, tightPhotonQual_Vec); + if (!loosePhotonQual_Vec.isValid() || !tightPhotonQual_Vec.isValid()) { + edm::LogWarning("GammaJetAnalysis") << "Failed to get photon quality flags (vec)"; + return; + } + } - Tracks_ = iConfig.getUntrackedParameter("Tracks","GammaJetTracksCollection"); - CutOnEgammaEnergy_ = iConfig.getParameter("CutOnEgammaEnergy"); + // sort photons by Et // + // counter is needed later to get the reference to the ptr + std::set photonpairset; + int counter=0; + for(reco::PhotonCollection::const_iterator it=photons->begin(); it!=photons->end(); ++it) { + //HERE(Form("photon counter=%d",counter)); + const reco::Photon* photon=&(*it); + //if(loosePhotonQual.isValid()){ + photonpairset.insert( PhotonPair(photon, photon->pt(), counter) ); + counter++; + //} + } - myName = iConfig.getParameter ("textout"); - useMC = iConfig.getParameter("useMCInfo"); - allowMissingInputs_=iConfig.getUntrackedParameter("AllowMissingInputs",false); - // get name of output file with histogramms - fOutputFileName = iConfig.getUntrackedParameter("HistOutFile"); - risol[0] = 0.5; - risol[1] = 0.7; - risol[2] = 1.0; - - ecut[0][0] = 0.09; - ecut[0][1] = 0.18; - ecut[0][2] = 0.27; - - ecut[1][0] = 0.45; - ecut[1][1] = 0.9; - ecut[1][2] = 1.35; - - ecut[2][0] = 0.5; - ecut[2][1] = 1.; - ecut[2][2] = 1.5; -} + HERE(Form("photonpairset.size=%d",int(photonpairset.size()))); + if ((photonpairset.size()==0) && !allowNoPhoton_) { + if (debug_>0) LogDebug("GammaJetAnalysis") << "No good quality photons in the event"; + return; + } -GammaJetAnalysis::~GammaJetAnalysis() -{ - - // do anything here that needs to be done at desctruction time - // (e.g. close files, deallocate resources etc.) + /////////////////////////////// + // TAG = Highest Et photon + /////////////////////////////// -} + // find highest Et photon // + PhotonPair photon_tag; + PhotonPair photon_2nd; + counter=0; + for(std::set::const_iterator it=photonpairset.begin(); it!=photonpairset.end(); ++it) { + PhotonPair photon=(*it); + ++counter; + if(counter==1) photon_tag = photon; + else if (counter==2) photon_2nd = photon; + else break; + } -void GammaJetAnalysis::beginJob() -{ - hOutputFile = new TFile( fOutputFileName.c_str(), "RECREATE" ) ; - myTree = new TTree("GammaJet","GammaJet Tree"); - myTree->Branch("run", &run, "run/I"); - myTree->Branch("event", &event, "event/I"); - - NumRecoJets = 0; - NumGenJets = 0; - NumRecoGamma = 0; - NumRecoTrack = 0; - NumPart = 0; -// Jet block - myTree->Branch("NumRecoJets", &NumRecoJets, "NumRecoJets/I"); - myTree->Branch("JetRecoEt", JetRecoEt, "JetRecoEt[10]/F"); - myTree->Branch("JetRecoEta", JetRecoEta, "JetRecoEta[10]/F"); - myTree->Branch("JetRecoPhi", JetRecoPhi, "JetRecoPhi[10]/F"); - myTree->Branch("JetRecoType", JetRecoType, "JetRecoType[10]/F"); - -// Gamma block for ECAL isolated gammas - myTree->Branch("NumRecoGamma", &NumRecoGamma, "NumRecoGamma/I"); - myTree->Branch("EcalClusDet", &EcalClusDet, "EcalClusDet[20]/I"); - myTree->Branch("GammaRecoEt", GammaRecoEt, "GammaRecoEt[20]/F"); - myTree->Branch("GammaRecoEta", GammaRecoEta, "GammaRecoEta[20]/F"); - myTree->Branch("GammaRecoPhi", GammaRecoPhi, "GammaRecoPhi[20]/F"); - myTree->Branch("GammaIsoEcal", GammaIsoEcal, "GammaIsoEcal[9][20]/F"); - -// Tracks block - myTree->Branch("NumRecoTrack", &NumRecoTrack, "NumRecoTrack/I"); - myTree->Branch("TrackRecoEt", TrackRecoEt, "TrackRecoEt[200]/F"); - myTree->Branch("TrackRecoEta", TrackRecoEta, "TrackRecoEta[200]/F"); - myTree->Branch("TrackRecoPhi", TrackRecoPhi, "TrackRecoPhi[200]/F"); - -// end of tree declaration - -// edm::ESHandle pG; -// iSetup.get().get(pG); -// geo = pG.product(); - - myout_part = new std::ofstream((myName+"_part.dat").c_str()); - if(!myout_part) cout << " Output file not open!!! "<SetCompressionLevel(2); - hOutputFile->cd(); - myTree->Write(); - hOutputFile->Close() ; - cout << "===== End writing user histograms =======" << endl; -} + // cut on photon pt + if (photon_tag.isValid() && ( photon_tag.pt() < photonPtMin_ )) { + if (debug_>0) LogDebug("GammaJetAnalysis") << "largest photonPt=" << photon_tag.pt(); + return; + } + HERE("aa"); -// -// member functions -// + // 2nd. Get Jets + edm::Handle pfjets; + nPFJets_=0; + nGenJets_=0; -// ------------ method called to produce the data ------------ -void -GammaJetAnalysis::analyze(const edm::Event& iEvent, const edm::EventSetup& iSetup) -{ + unsigned int anyJetCount=0; - edm::ESHandle pG; - iSetup.get().get(pG); - geo = pG.product(); - - - using namespace edm; - std::vector theProvenance; - iEvent.getAllProvenance(theProvenance); -// for( std::vector::const_iterator ip = theProvenance.begin(); -// ip != theProvenance.end(); ip++) -// { -// cout<<" Print all module/label names "<<(**ip).moduleName()<<" "<<(**ip).moduleLabel()<< -// " "<<(**ip).productInstanceName()<size(); + nPFJets_ = pfjets->size(); + } + + HERE(Form("anyJetCount=%d",anyJetCount)); + + if (anyJetCount==0) { + if (debug_>0) LogDebug("GammaJetAnalysis") << "Event contains no jets"; + return; + } + if (debug_>0) LogDebug("GammaJetAnalysis") << "nPhotons=" << nPhotons_ << ", nPFJets=" + << nPFJets_; + + HERE(Form("nPhotons_=%d, nPFJets_=%d",nPhotons_,nPFJets_)); + + // 3rd. Check the trigger + photonTrigFired_.clear(); + photonTrigPrescale_.clear(); + jetTrigFired_.clear(); + jetTrigPrescale_.clear(); + + HERE("trigger"); + + // HLT Trigger + // assign "trig fired" if no triggers are specified + bool photonTrigFlag= (photonTrigNamesV_.size()==0) ? true : false; + bool jetTrigFlag= (jetTrigNamesV_.size()==0) ? true : false; + if ((photonTrigNamesV_.size()==1) && + (photonTrigNamesV_[0].length()==0)) photonTrigFlag=true; + if ((jetTrigNamesV_.size()==1) && + (jetTrigNamesV_[0].length()==0)) jetTrigFlag=true; + + // If needed, process trigger information + if (!photonTrigFlag || !jetTrigFlag) { + // check the triggers + edm::Handle triggerResults; + if( !iEvent.getByToken(tok_TrigRes_,triggerResults) ) { + edm::LogWarning("GammaJetAnalysis") << "Could not find TriggerResults::HLT"; + return; + } + const edm::TriggerNames &evTrigNames =iEvent.triggerNames(*triggerResults); + + if (debugHLTTrigNames>0) { + if (debug_>1) LogDebug("GammaJetAnalysis") << "debugHLTTrigNames is on"; + const std::vector *trNames= & evTrigNames.triggerNames(); + for (size_t i=0; isize(); ++i) { + if (trNames->at(i).find("_Photon")!=std::string::npos) { + if (debug_>1) LogDebug("GammaJetAnalysis") << " - " << trNames->at(i); + } + } + if (debug_>1) LogDebug("GammaJetAnalysis") << " "; + debugHLTTrigNames--; + } + + size_t id = 0; + for (size_t i=0; iaccept(id); + if (fired) photonTrigFlag=true; + photonTrigFired_.push_back(fired); + if (!writeTriggerPrescale_) photonTrigPrescale_.push_back(-1); + else { + // for triggers with two L1 seeds this fails + std::pair prescaleVals= hltConfig_.prescaleValues(iEvent,evSetup, evTrigNames.triggerName(id)); + photonTrigPrescale_.push_back(prescaleVals.first * prescaleVals.second); + } + } + for (size_t i=0; iaccept(id); + if (fired) jetTrigFlag=true; + jetTrigFired_.push_back(fired); + std::pair prescaleVals= hltConfig_.prescaleValues(iEvent,evSetup,evTrigNames.triggerName(id)); + jetTrigPrescale_.push_back(prescaleVals.first * prescaleVals.second); + } + } + + if (!photonTrigFlag && !jetTrigFlag) { + if (debug_>0) LogDebug("GammaJetAnalysis") << "no trigger fired"; + return; + } + + HERE("start isolation"); + + tagPho_pfiso_mycharged03.clear(); + + edm::Handle> genjets; + edm::Handle > genparticles; + edm::Handle pfHandle; + iEvent.getByToken(tok_PFCand_, pfHandle); + + edm::Handle vtxHandle; + iEvent.getByToken(tok_Vertex_, vtxHandle); - std::vector::const_iterator ic; - int jettype = 0; - int jetexist = -100; - int reco = 1; - double etlost = -100.1; + edm::Handle gsfElectronHandle; + iEvent.getByToken(tok_GsfElec_, gsfElectronHandle); + edm::Handle rhoHandle_2012; + iEvent.getByToken(tok_Rho_, rhoHandle_2012); + rho2012_ = *(rhoHandle_2012.product()); + //rho2012_ = -1e6; + + edm::Handle convH; + iEvent.getByToken(tok_Conv_, convH); + edm::Handle beamSpotHandle; + iEvent.getByToken(tok_BS_, beamSpotHandle); + + HERE("doGenJets"); + + if(doGenJets_){ + // Get GenJets + iEvent.getByToken(tok_GenJet_,genjets); + if(!genjets.isValid()) { + edm::LogWarning("GammaJetAnalysis") << "Could not find GenJet vector named " + << genJetCollName_; + return; + } + nGenJets_= genjets->size(); + + // Get GenParticles + iEvent.getByToken(tok_GenPart_,genparticles); + if(!genparticles.isValid()) { + edm::LogWarning("GammaJetAnalysis") << "Could not find GenParticle vector named " << genParticleCollName_; + return; + } + + // Get weights + edm::Handle genEventInfoProduct; + iEvent.getByToken(tok_GenEvInfo_, genEventInfoProduct); + if(!genEventInfoProduct.isValid()){ + edm::LogWarning("GammaJetAnalysis") << "Could not find GenEventInfoProduct named " << genEventInfoName_; + return; + } + eventWeight_ = genEventInfoProduct->weight(); + eventPtHat_ = 0.; + if (genEventInfoProduct->hasBinningValues()) { + eventPtHat_ = genEventInfoProduct->binningValues()[0]; + } + } + + runNumber_ = iEvent.id().run(); + lumiBlock_ = iEvent.id().luminosityBlock(); + eventNumber_ = iEvent.id().event(); + + HERE(Form("runNumber=%d, eventNumber=%d",runNumber_,eventNumber_)); + + // fill tag photon variables + if (!photon_tag.isValid()) { + tagPho_pt_=-1; + pho_2nd_pt_=-1; + tagPho_energy_=-1; + tagPho_eta_=0; + tagPho_phi_=0; + tagPho_sieie_=0; + tagPho_HoE_=0; + tagPho_r9_=0; + tagPho_EcalIsoDR04_=0; + tagPho_HcalIsoDR04_=0; + tagPho_HcalIsoDR0412_=0; + tagPho_TrkIsoHollowDR04_=0; + tagPho_pfiso_myphoton03_=0; + tagPho_pfiso_myneutral03_=0; + tagPho_pfiso_mycharged03.clear(); + tagPho_pixelSeed_=0; + tagPho_ConvSafeEleVeto_=0; + tagPho_idTight_=0; + tagPho_idLoose_=0; + tagPho_genPt_=0; + tagPho_genEnergy_=0; + tagPho_genEta_=0; + tagPho_genPhi_=0; + tagPho_genDeltaR_=0; + } + else { + HERE("bb"); + + tagPho_pt_ = photon_tag.photon()->pt(); + pho_2nd_pt_ = (photon_2nd.photon()) ? photon_2nd.photon()->pt() : -1.; + tagPho_energy_ = photon_tag.photon()->energy(); + tagPho_eta_ = photon_tag.photon()->eta(); + tagPho_phi_ = photon_tag.photon()->phi(); + tagPho_sieie_ = photon_tag.photon()->sigmaIetaIeta(); + tagPho_HoE_ = photon_tag.photon()->hadTowOverEm(); + tagPho_r9_ = photon_tag.photon()->r9(); + tagPho_pixelSeed_ = photon_tag.photon()->hasPixelSeed(); + tagPho_TrkIsoHollowDR04_ = photon_tag.photon()->trkSumPtHollowConeDR04(); + tagPho_EcalIsoDR04_ = photon_tag.photon()->ecalRecHitSumEtConeDR04(); + tagPho_HcalIsoDR04_ = photon_tag.photon()->hcalTowerSumEtConeDR04(); + tagPho_HcalIsoDR0412_ = photon_tag.photon()->hcalTowerSumEtConeDR04() + (photon_tag.photon()->hadronicOverEm() - photon_tag.photon()->hadTowOverEm())*(photon_tag.photon()->energy()/cosh((photon_tag.photon()->eta()))); + + HERE("tt"); - NumRecoJets = 0; + tagPho_pfiso_myphoton03_ = pfEcalIso(photon_tag.photon(), pfHandle, 0.3, 0.0, 0.070, 0.015, 0.0, 0.0, 0.0, reco::PFCandidate::gamma); + tagPho_pfiso_myneutral03_ = pfHcalIso(photon_tag.photon(), pfHandle, 0.3, 0.0, reco::PFCandidate::h0); + HERE("calc charged pfiso"); + tagPho_pfiso_mycharged03.push_back(pfTkIsoWithVertex(photon_tag.photon(), pfHandle, vtxHandle, 0.3, 0.02, 0.02, 0.0, 0.2, 0.1, reco::PFCandidate::h)); + + HERE("got isolation"); + + //tagPho_ConvSafeEleVeto_ = ((int)ConversionTools::hasMatchedPromptElectron(photon_tag.photon()->superCluster(), gsfElectronHandle, convH, beamSpotHandle->position())); + tagPho_ConvSafeEleVeto_ = -999; + + HERE("get id"); + if (workOnAOD_ < 2) { + HERE(Form("workOnAOD_<2. loose photon qual size=%d",int(loosePhotonQual->size()))); + + edm::Ref photonRef(photons, photon_tag.idx()); + HERE(Form("got photon ref, photon_tag.idx()=%d",photon_tag.idx())); + + //std::cout << "loosePhotonQual->at(photon_tag.idx())=" << loosePhotonQual->at(photon_tag.idx()) << std::endl; + + tagPho_idLoose_ = (loosePhotonQual.isValid()) ? (*loosePhotonQual)[photonRef] : -1; + tagPho_idTight_ = (tightPhotonQual.isValid()) ? (*tightPhotonQual)[photonRef] : -1; + } + else { + tagPho_idLoose_ = (loosePhotonQual_Vec.isValid()) ? loosePhotonQual_Vec->at(photon_tag.idx()) : -1; + tagPho_idTight_ = (tightPhotonQual_Vec.isValid()) ? tightPhotonQual_Vec->at(photon_tag.idx()) : -1; + } + + if (debug_>1) LogDebug("GammaJetAnalysis") << "photon tag ID = " << tagPho_idLoose_ + << " and " << tagPho_idTight_; + + HERE(Form("tagPhoID= %d and %d",tagPho_idLoose_,tagPho_idTight_)); + + HERE("reset pho gen"); - try { - - edm::Handle jets; - iEvent.getByToken(tok_jets_, jets); - reco::CaloJetCollection::const_iterator jet = jets->begin (); - cout<<" Size of Calo jets "<size()<size() > 0 ) - { - int ij = 0; - for (; jet != jets->end (); jet++) - { - cout<<" Jet et "<<(*jet).et()<<" "<<(*jet).eta()<<" "<<(*jet).phi()<::const_iterator itmc=genparticles->begin(); + itmc!=genparticles->end(); itmc++) { + if (itmc->status() == 1 && itmc->pdgId()==22) { + float dR= deltaR(tagPho_eta_,tagPho_phi_, + itmc->eta(),itmc->phi()); + if (dR < tagPho_genDeltaR_) { + tagPho_genPt_ = itmc->pt(); + tagPho_genEnergy_ = itmc->energy(); + tagPho_genEta_ = itmc->eta(); + tagPho_genPhi_ = itmc->phi(); + tagPho_genDeltaR_ = dR; + } + } + } + } + } - std::vector::const_iterator i; - vector > theRecHits; - - try { - - edm::Handle ec; - iEvent.getByToken(tok_ecal_,ec); - - for(EcalRecHitCollection::const_iterator recHit = (*ec).begin(); - recHit != (*ec).end(); ++recHit) - { -// EcalBarrel = 1, EcalEndcap = 2 - - GlobalPoint pos = geo->getPosition(recHit->detid()); - theRecHits.push_back(std::pair(recHit->detid(), recHit->energy())); - - if( (*recHit).energy()> ecut[recHit->detid().subdetId()-1][0] ) - (*myout_ecal)<detid().subdetId()<<" "<<(*recHit).energy()<<" "< hbhe; - iEvent.getByToken(tok_hbhe_,hbhe); - -// (*myout_hcal)<<(*hbhe).size()<detid(); - GlobalPoint pos = geo->getPosition(hbheItr->detid()); - (*myout_hcal)<(hbheItr->detid(), hbheItr->energy())); + HERE("run over PFJets"); + + // Run over PFJets // + + if(doPFJets_ && (nPFJets_>0)){ + + // Get RecHits in HB and HE + edm::Handle>> hbhereco; + iEvent.getByToken(tok_HBHE_,hbhereco); + if(!hbhereco.isValid() && !workOnAOD_) { + edm::LogWarning("GammaJetAnalysis") << "Could not find HBHERecHit named " + << hbheRecHitName_; + return; + } + + // Get RecHits in HF + edm::Handle>> hfreco; + iEvent.getByToken(tok_HF_,hfreco); + if(!hfreco.isValid() && !workOnAOD_) { + edm::LogWarning("GammaJetAnalysis") << "Could not find HFRecHit named " + << hfRecHitName_; + return; + } + + // Get RecHits in HO + edm::Handle>> horeco; + iEvent.getByToken(tok_HO_,horeco); + if(!horeco.isValid() && !workOnAOD_) { + edm::LogWarning("GammaJetAnalysis") << "Could not find HORecHit named " + << hoRecHitName_; + return; + } + + HERE("get geometry"); + + // Get geometry + edm::ESHandle geoHandle; + evSetup.get().get(geoHandle); + const CaloSubdetectorGeometry *HBGeom = geoHandle->getSubdetectorGeometry(DetId::Hcal, 1); + const CaloSubdetectorGeometry *HEGeom = geoHandle->getSubdetectorGeometry(DetId::Hcal, 2); + const CaloSubdetectorGeometry *HOGeom = geoHandle->getSubdetectorGeometry(DetId::Hcal, 3); + const CaloSubdetectorGeometry *HFGeom = geoHandle->getSubdetectorGeometry(DetId::Hcal, 4); + + HERE("work"); + int HBHE_n = 0; + if (hbhereco.isValid()) { + for(edm::SortedCollection>::const_iterator ith=hbhereco->begin(); ith!=hbhereco->end(); ++ith){ + HBHE_n++; + if(iEvent.id().event() == debugEvent){ + if (debug_>1) LogDebug("GammaJetAnalysis") << (*ith).id().ieta() << " " + << (*ith).id().iphi(); + } } - } catch (cms::Exception& e) { // can't find it! - if (!allowMissingInputs_) { - cout<<" HBHE collection is missed "<>::const_iterator ith=hfreco->begin(); ith!=hfreco->end(); ++ith){ + HF_n++; + if(iEvent.id().event() == debugEvent){ + } + } + } + int HO_n = 0; + if (horeco.isValid()) { + for(edm::SortedCollection>::const_iterator ith=horeco->begin(); ith!=horeco->end(); ++ith){ + HO_n++; + if(iEvent.id().event() == debugEvent){ + } } } - - for(int i = 0; i<9; i++) - { - for(int j= 0; j<10; j++) GammaIsoEcal[i][j] = 0.; - } - -// Load Ecal clusters - jetexist = -100; - int barrel = 1; - NumRecoGamma = 0; - - try { - int ij = 0; - // Get island super clusters after energy correction - Handle eclus; - iEvent.getByToken(tok_egamma_, eclus); - const reco::SuperClusterCollection* correctedSuperClusters=eclus.product(); - // loop over the super clusters and fill the histogram - for(reco::SuperClusterCollection::const_iterator aClus = correctedSuperClusters->begin(); - aClus != correctedSuperClusters->end(); aClus++) { - double vet = aClus->energy()/cosh(aClus->eta()); - cout<<" Supercluster " << ij<<" Et "<< vet <<" energy "<energy()<<" eta "<eta()<<" Cut "<CutOnEgammaEnergy_) { - ij++; - float gammaiso_ecal[9] = {0.,0.,0.,0.,0.,0.,0.,0.,0.}; - for(vector >::const_iterator it = theRecHits.begin(); it != theRecHits.end(); it++) - { - GlobalPoint pos = geo->getPosition(it->first); - double eta = pos.eta(); - double phi = pos.phi(); - double deta = fabs(eta-aClus->eta()); - double dphi = fabs(phi-aClus->phi()); - if(dphi>4.*atan(1.)) dphi = 8.*atan(1.)-dphi; - double dr = sqrt(deta*deta+dphi*dphi); - - double rmin = 0.07; - if( fabs(aClus->eta()) > 1.47 ) rmin = 0.07*(fabs(aClus->eta())-.47)*1.2; - if( fabs(aClus->eta()) > 2.2 ) rmin = 0.07*(fabs(aClus->eta())-.47)*1.4; - - int itype_ecal = 0; - double ecutn = 0.; - for (int i = 0; i<3; i++) - { - for (int j = 0; j<3; j++) - { - - if(it->first.det() == DetId::Ecal ) - { - if(it->first.subdetId() == 1) ecutn = ecut[0][j]; - if(it->first.subdetId() == 2) ecutn = ecut[1][j]; - if( dr>rmin && dr ecutn) gammaiso_ecal[itype_ecal] = gammaiso_ecal[itype_ecal]+(*it).second/cosh(eta); - } + HERE("Get primary vertices"); + + // Get primary vertices + edm::Handle> pv; + iEvent.getByToken(tok_PV_,pv); + if(!pv.isValid()) { + edm::LogWarning("GammaJetAnalysis") << "Could not find Vertex named " + << pvCollName_; + return; + } + pf_NPV_ = 0; + for(std::vector::const_iterator it=pv->begin(); it!=pv->end(); ++it){ + if(!it->isFake() && it->ndof() > 4) ++pf_NPV_; + } + + HERE("get corrector"); + + // Get jet corrections + const JetCorrector* correctorPF = JetCorrector::getJetCorrector(pfJetCorrName_,evSetup); + + // sort jets by corrected et + std::set pfjetcorretpairset; + for(reco::PFJetCollection::const_iterator it=pfjets->begin(); it!=pfjets->end(); ++it) { + const reco::PFJet* jet=&(*it); + // do not let the jet to be close to the tag photon + if (deltaR(photon_tag,jet)<0.5) continue; + double jec = correctorPF->correction(*it, iEvent, evSetup); + pfjetcorretpairset.insert( PFJetCorretPair(jet, jec)); + } + + PFJetCorretPair pfjet_probe; + PFJetCorretPair pf_2ndjet; + PFJetCorretPair pf_3rdjet; + int jet_cntr=0; + for(std::set::const_iterator it=pfjetcorretpairset.begin(); it!=pfjetcorretpairset.end(); ++it) { + PFJetCorretPair jet=(*it); + ++jet_cntr; + if(jet_cntr==1) pfjet_probe = jet; + else if(jet_cntr==2) pf_2ndjet = jet; + else if(jet_cntr==3) pf_3rdjet = jet; + //else break; // don't break for the statistics + } + + HERE("reached selection"); + + // Check selection + int failSelPF = 0; + + if (!pfjet_probe.isValid()) failSelPF |= 1; + else { + if (pfjet_probe.scaledEt() < jetEtMin_) failSelPF |= 2; + if (calc_dPhi(photon_tag,pfjet_probe) < photonJetDPhiMin_) failSelPF |= 3; + if (deltaR(photon_tag,pfjet_probe.jet())<0.5) failSelPF |= 4; + if (pf_2ndjet.isValid() && (pf_2ndjet.scaledEt() > jet2EtMax_)) + failSelPF |= 5; + if (pf_3rdjet.isValid() && (pf_3rdjet.scaledEt() > jet3EtMax_)) + failSelPF |= 6; + } + + if (!failSelPF) { + // put values into 3rd jet quantities + if (pf_3rdjet.isValid()) { + pf_thirdjet_et_ = pf_3rdjet.jet()->et(); + pf_thirdjet_pt_ = pf_3rdjet.jet()->pt(); + pf_thirdjet_p_ = pf_3rdjet.jet()->p(); + pf_thirdjet_px_ = pf_3rdjet.jet()->px(); + pf_thirdjet_py_ = pf_3rdjet.jet()->py(); + pf_thirdjet_E_ = pf_3rdjet.jet()->energy(); + pf_thirdjet_eta_= pf_3rdjet.jet()->eta(); + pf_thirdjet_phi_= pf_3rdjet.jet()->phi(); + pf_thirdjet_scale_= pf_3rdjet.scale(); + } + else { + pf_thirdjet_et_ = 0; + pf_thirdjet_pt_ = pf_thirdjet_p_ = 0; + pf_thirdjet_px_ = pf_thirdjet_py_ = 0; + pf_thirdjet_E_ = pf_thirdjet_eta_ = pf_thirdjet_phi_ = 0; + pf_thirdjet_scale_=0; + } + + HERE("fill PF jet"); + + int types = 0; + int ntypes = 0; + + ///////////////////////////////////////////// + // Get PF constituents and fill HCAL towers + ///////////////////////////////////////////// + + // fill jet variables + // First start from a second jet, then fill the first jet + PFJetCorretPair pfjet_probe_store = pfjet_probe; + for (int iJet=2; iJet>0; iJet--) { + // prepare the container + clear_leadingPfJetVars(); + + if (iJet==2) pfjet_probe= pf_2ndjet; + else pfjet_probe = pfjet_probe_store; + + if(!pfjet_probe.jet()) { + if (iJet==2) { + // put zeros into 2nd jet quantities + copy_leadingPfJetVars_to_pfJet2(); + } else { + edm::LogWarning("GammaJetAnalysis") << "error in the code: leading pf jet is null"; + } + continue; + } + + HERE("work further"); + + // temporary variables + std::map>> ppfjet_rechits; + std::map ppfjet_clusters; + + // fill the values + ppfjet_pt_ = pfjet_probe.jet()->pt(); + ppfjet_p_ = pfjet_probe.jet()->p(); + ppfjet_eta_ = pfjet_probe.jet()->eta(); + ppfjet_area_ = pfjet_probe.jet()->jetArea(); + ppfjet_E_ = pfjet_probe.jet()->energy(); + ppfjet_E_NPVcorr_ = pfjet_probe.jet()->energy() - getNeutralPVCorr(ppfjet_eta_,pf_NPV_,ppfjet_area_,doGenJets_); + ppfjet_phi_ = pfjet_probe.jet()->phi(); + ppfjet_NeutralHadronFrac_ = pfjet_probe.jet()->neutralHadronEnergyFraction(); + ppfjet_NeutralEMFrac_ = pfjet_probe.jet()->neutralEmEnergyFraction(); + ppfjet_nConstituents_ = pfjet_probe.jet()->nConstituents(); + ppfjet_ChargedHadronFrac_ = pfjet_probe.jet()->chargedHadronEnergyFraction(); + ppfjet_ChargedMultiplicity_= pfjet_probe.jet()->chargedMultiplicity(); + ppfjet_ChargedEMFrac_ = pfjet_probe.jet()->chargedEmEnergyFraction(); + ppfjet_scale_ = pfjet_probe.scale(); + ppfjet_ntwrs_=0; + ppfjet_cluster_n_=0; + ppfjet_ncandtracks_=0; + + HERE("Get PF constituents"); + + // Get PF constituents and fill HCAL towers + std::vector probeconst=pfjet_probe.jet()->getPFConstituents(); + HERE(Form("probeconst.size=%d",int(probeconst.size()))); + int iPF=0; + for(std::vector::const_iterator it=probeconst.begin(); it!=probeconst.end(); ++it){ + bool hasTrack = false; + if (!(*it)) HERE("\tnull probeconst iterator value\n"); + reco::PFCandidate::ParticleType candidateType = (*it)->particleId(); + iPF++; + HERE(Form("iPF=%d",iPF)); + + // store information + switch(candidateType){ + case reco::PFCandidate::X: + ppfjet_unkown_E_ += (*it)->energy(); + ppfjet_unkown_px_ += (*it)->px(); + ppfjet_unkown_py_ += (*it)->py(); + ppfjet_unkown_pz_ += (*it)->pz(); + ppfjet_unkown_EcalE_ += (*it)->ecalEnergy(); + ppfjet_unkown_n_++; + continue; + case reco::PFCandidate::h: + { + ppfjet_had_E_.push_back((*it)->energy()); + ppfjet_had_px_.push_back((*it)->px()); + ppfjet_had_py_.push_back((*it)->py()); + ppfjet_had_pz_.push_back((*it)->pz()); + ppfjet_had_EcalE_.push_back((*it)->ecalEnergy()); + ppfjet_had_rawHcalE_.push_back((*it)->rawHcalEnergy()); + ppfjet_had_id_.push_back(0); + ppfjet_had_ntwrs_.push_back(0); + ppfjet_had_n_++; + + if(doGenJets_){ + float gendr = 99999; + float genE = 0; + int genpdgId = 0; + for(std::vector::const_iterator itmc = genparticles->begin(); itmc != genparticles->end(); itmc++){ + if(itmc->status() == 1 && itmc->pdgId() > 100){ + double dr = deltaR((*it)->eta(),(*it)->phi(),itmc->eta(),itmc->phi()); + if(dr < gendr){ + gendr = dr; + genE = itmc->energy(); + genpdgId = itmc->pdgId(); + } + } + } + ppfjet_had_E_mctruth_.push_back(genE); + ppfjet_had_mcpdgId_.push_back(genpdgId); + } + + reco::TrackRef trackRef = (*it)->trackRef(); + if(trackRef.isNonnull()){ + reco::Track track = *trackRef; + ppfjet_candtrack_px_.push_back(track.px()); + ppfjet_candtrack_py_.push_back(track.py()); + ppfjet_candtrack_pz_.push_back(track.pz()); + ppfjet_candtrack_EcalE_.push_back((*it)->ecalEnergy()); + ppfjet_had_candtrackind_.push_back(ppfjet_ncandtracks_); + hasTrack = true; + ppfjet_ncandtracks_++; + } + else{ + ppfjet_had_candtrackind_.push_back(-2); + } + } + break; + case reco::PFCandidate::e: + ppfjet_electron_E_ += (*it)->energy(); + ppfjet_electron_px_ += (*it)->px(); + ppfjet_electron_py_ += (*it)->py(); + ppfjet_electron_pz_ += (*it)->pz(); + ppfjet_electron_EcalE_ += (*it)->ecalEnergy(); + ppfjet_electron_n_++; + continue; + case reco::PFCandidate::mu: + ppfjet_muon_E_ += (*it)->energy(); + ppfjet_muon_px_ += (*it)->px(); + ppfjet_muon_py_ += (*it)->py(); + ppfjet_muon_pz_ += (*it)->pz(); + ppfjet_muon_EcalE_ += (*it)->ecalEnergy(); + ppfjet_muon_n_++; + continue; + case reco::PFCandidate::gamma: + ppfjet_photon_E_ += (*it)->energy(); + ppfjet_photon_px_ += (*it)->px(); + ppfjet_photon_py_ += (*it)->py(); + ppfjet_photon_pz_ += (*it)->pz(); + ppfjet_photon_EcalE_ += (*it)->ecalEnergy(); + ppfjet_photon_n_++; + continue; + case reco::PFCandidate::h0: + { + ppfjet_had_E_.push_back((*it)->energy()); + ppfjet_had_px_.push_back((*it)->px()); + ppfjet_had_py_.push_back((*it)->py()); + ppfjet_had_pz_.push_back((*it)->pz()); + ppfjet_had_EcalE_.push_back((*it)->ecalEnergy()); + ppfjet_had_rawHcalE_.push_back((*it)->rawHcalEnergy()); + ppfjet_had_id_.push_back(1); + ppfjet_had_candtrackind_.push_back(-1); + ppfjet_had_ntwrs_.push_back(0); + ppfjet_had_n_++; + + if(doGenJets_){ + float gendr = 99999; + float genE = 0; + int genpdgId = 0; + for(std::vector::const_iterator itmc = genparticles->begin(); itmc != genparticles->end(); itmc++){ + if(itmc->status() == 1 && itmc->pdgId() > 100){ + double dr = deltaR((*it)->eta(),(*it)->phi(),itmc->eta(),itmc->phi()); + if(dr < gendr){ + gendr = dr; + genE = itmc->energy(); + genpdgId = itmc->pdgId(); + } + } + } + ppfjet_had_E_mctruth_.push_back(genE); + ppfjet_had_mcpdgId_.push_back(genpdgId); + } + + break; + } + case reco::PFCandidate::h_HF: + { + ppfjet_had_E_.push_back((*it)->energy()); + ppfjet_had_px_.push_back((*it)->px()); + ppfjet_had_py_.push_back((*it)->py()); + ppfjet_had_pz_.push_back((*it)->pz()); + ppfjet_had_EcalE_.push_back((*it)->ecalEnergy()); + ppfjet_had_rawHcalE_.push_back((*it)->rawHcalEnergy()); + ppfjet_had_id_.push_back(2); + ppfjet_had_candtrackind_.push_back(-1); + ppfjet_had_ntwrs_.push_back(0); + ppfjet_had_n_++; + + if(doGenJets_){ + float gendr = 99999; + float genE = 0; + int genpdgId = 0; + for(std::vector::const_iterator itmc = genparticles->begin(); itmc != genparticles->end(); itmc++){ + if(itmc->status() == 1 && itmc->pdgId() > 100){ + double dr = deltaR((*it)->eta(),(*it)->phi(),itmc->eta(),itmc->phi()); + if(dr < gendr){ + gendr = dr; + genE = itmc->energy(); + genpdgId = itmc->pdgId(); + } + } + } + ppfjet_had_E_mctruth_.push_back(genE); + ppfjet_had_mcpdgId_.push_back(genpdgId); + } + + break; + } + case reco::PFCandidate::egamma_HF: + { + ppfjet_had_E_.push_back((*it)->energy()); + ppfjet_had_px_.push_back((*it)->px()); + ppfjet_had_py_.push_back((*it)->py()); + ppfjet_had_pz_.push_back((*it)->pz()); + ppfjet_had_EcalE_.push_back((*it)->ecalEnergy()); + ppfjet_had_rawHcalE_.push_back((*it)->rawHcalEnergy()); + ppfjet_had_id_.push_back(3); + ppfjet_had_candtrackind_.push_back(-1); + ppfjet_had_ntwrs_.push_back(0); + ppfjet_had_n_++; + + if(doGenJets_){ + float gendr = 99999; + float genE = 0; + int genpdgId = 0; + for(std::vector::const_iterator itmc = genparticles->begin(); itmc != genparticles->end(); itmc++){ + if(itmc->status() == 1 && itmc->pdgId() > 100){ + double dr = deltaR((*it)->eta(),(*it)->phi(),itmc->eta(),itmc->phi()); + if(dr < gendr){ + gendr = dr; + genE = itmc->energy(); + genpdgId = itmc->pdgId(); + } + } + } + ppfjet_had_E_mctruth_.push_back(genE); + ppfjet_had_mcpdgId_.push_back(genpdgId); + } + + break; + } + } + + float HFHAD_E = 0; + float HFEM_E = 0; + int HFHAD_n_ = 0; + int HFEM_n_ = 0; + int HF_type_ = 0; + int maxElement=(*it)->elementsInBlocks().size(); + if (debug_>1) LogDebug("GammaJetAnalysis") << "maxElement=" << maxElement; + if (workOnAOD_==1) { + maxElement=0; + if (debug_>1) LogDebug("GammaJetAnalysis") << "forced 0"; + } + HERE(Form("maxElement=%d",maxElement)); + for(int e=0; eelementsInBlocks()[e].first; + const edm::OwnVector& elements = blockRef->elements(); + for(unsigned iEle=0; iEleelementsInBlocks()[e].second){ + if(elements[iEle].type() == reco::PFBlockElement::HCAL){ // Element is HB or HE + HF_type_ |= 0x1; + // Get cluster and hits + reco::PFClusterRef clusterref = elements[iEle].clusterRef(); + reco::PFCluster cluster = *clusterref; + double cluster_dR = deltaR(ppfjet_eta_,ppfjet_phi_,cluster.eta(),cluster.phi()); + if(ppfjet_clusters.count(cluster_dR) == 0){ + ppfjet_clusters[cluster_dR] = ppfjet_cluster_n_; + ppfjet_cluster_eta_.push_back(cluster.eta()); + ppfjet_cluster_phi_.push_back(cluster.phi()); + ppfjet_cluster_dR_.push_back(cluster_dR); + ppfjet_cluster_n_++; } + int cluster_ind = ppfjet_clusters[cluster_dR]; + std::vector> hitsAndFracs = cluster.hitsAndFractions(); + + // Run over hits and match + int nHits = hitsAndFracs.size(); + for(int iHit=0; iHit>::const_iterator ith=hbhereco->begin(); ith!=hbhereco->end(); ++ith){ + int etaPhiRecHit = getEtaPhi((*ith).id()); + if(etaPhiPF == etaPhiRecHit){ + ppfjet_had_ntwrs_.at(ppfjet_had_n_ - 1)++; + if(ppfjet_rechits.count((*ith).id()) == 0){ + ppfjet_twr_ieta_.push_back((*ith).id().ieta()); + ppfjet_twr_iphi_.push_back((*ith).id().iphi()); + ppfjet_twr_depth_.push_back((*ith).id().depth()); + ppfjet_twr_subdet_.push_back((*ith).id().subdet()); + ppfjet_twr_hade_.push_back((*ith).energy()); + ppfjet_twr_frac_.push_back(hitsAndFracs[iHit].second); + ppfjet_rechits[(*ith).id()].second.insert(hitsAndFracs[iHit].second); + ppfjet_twr_hadind_.push_back(ppfjet_had_n_ - 1); + ppfjet_twr_elmttype_.push_back(0); + ppfjet_twr_clusterind_.push_back(cluster_ind); + if(hasTrack){ + ppfjet_twr_candtrackind_.push_back(ppfjet_ncandtracks_ - 1); + } + else{ + ppfjet_twr_candtrackind_.push_back(-1); + } + switch((*ith).id().subdet()){ + case HcalSubdetector::HcalBarrel: + { + const CaloCellGeometry *thisCell = HBGeom->getGeometry((*ith).id().rawId()); + const CaloCellGeometry::CornersVec& cv = thisCell->getCorners(); + float avgeta = (cv[0].eta() + cv[2].eta())/2.0; + float avgphi = (static_cast(cv[0].phi()) + static_cast(cv[2].phi()))/2.0; + if((cv[0].phi() < cv[2].phi()) && (debug_>1)) LogDebug("GammaJetAnalysis") << "pHB" << cv[0].phi() << " " << cv[2].phi(); + if(cv[0].phi() < cv[2].phi()) avgphi = (2.0*3.141592653 + static_cast(cv[0].phi()) + static_cast(cv[2].phi()))/2.0; + ppfjet_twr_dR_.push_back(deltaR(ppfjet_eta_,ppfjet_phi_,avgeta,avgphi)); + break; + } + case HcalSubdetector::HcalEndcap: + { + const CaloCellGeometry *thisCell = HEGeom->getGeometry((*ith).id().rawId()); + const CaloCellGeometry::CornersVec& cv = thisCell->getCorners(); + float avgeta = (cv[0].eta() + cv[2].eta())/2.0; + float avgphi = (static_cast(cv[0].phi()) + static_cast(cv[2].phi()))/2.0; + if((cv[0].phi() < cv[2].phi()) && (debug_>1)) LogDebug("GammaJetAnalysis") << "pHE" << cv[0].phi() << " " << cv[2].phi(); + if(cv[0].phi() < cv[2].phi()) avgphi = (2.0*3.141592653 + static_cast(cv[0].phi()) + static_cast(cv[2].phi()))/2.0; + ppfjet_twr_dR_.push_back(deltaR(ppfjet_eta_,ppfjet_phi_,avgeta,avgphi)); + break; + } + default: + ppfjet_twr_dR_.push_back(-1); + break; + } + ppfjet_rechits[(*ith).id()].first = ppfjet_ntwrs_; + ++ppfjet_ntwrs_; + } + else if(ppfjet_rechits[(*ith).id()].second.count(hitsAndFracs[iHit].second) == 0){ + ppfjet_twr_frac_.at(ppfjet_rechits[(*ith).id()].first) += hitsAndFracs[iHit].second; + if(cluster_dR < ppfjet_cluster_dR_.at(ppfjet_twr_clusterind_.at(ppfjet_rechits[(*ith).id()].first))){ + ppfjet_twr_clusterind_.at(ppfjet_rechits[(*ith).id()].first) = cluster_ind; + } + ppfjet_rechits[(*ith).id()].second.insert(hitsAndFracs[iHit].second); + } + } // Test if ieta,iphi matches + } // Loop over rechits + } // Loop over hits + } // Test if element is from HCAL + else if(elements[iEle].type() == reco::PFBlockElement::HFHAD){ // Element is HF + types |= 0x2; + ntypes++; + HFHAD_n_++; + HF_type_ |= 0x2; - if(it->first.det() == DetId::Hcal ) - { - ecutn = ecut[2][j]; - if( dr>rmin && dr ecutn) - { - gammaiso_ecal[itype_ecal] = gammaiso_ecal[itype_ecal]+(*it).second/cosh(eta); - } - } - } - jetexist = ij; - itype_ecal++; + //// h_etaHFHAD_->Fill((*it)->eta()); + + for(edm::SortedCollection>::const_iterator ith=hfreco->begin(); ith!=hfreco->end(); ++ith){ + if((*ith).id().depth() == 1) continue; // Remove long fibers + const CaloCellGeometry *thisCell = HFGeom->getGeometry((*ith).id().rawId()); + const CaloCellGeometry::CornersVec& cv = thisCell->getCorners(); + + bool passMatch = false; + if((*it)->eta() < cv[0].eta() && (*it)->eta() > cv[2].eta()){ + if((*it)->phi() < cv[0].phi() && (*it)->phi() > cv[2].phi()) passMatch = true; + else if(cv[0].phi() < cv[2].phi()){ + if((*it)->phi() < cv[0].phi()) passMatch = true; + else if((*it)->phi() > cv[2].phi()) passMatch = true; + } + } + + if(passMatch){ + ppfjet_had_ntwrs_.at(ppfjet_had_n_ - 1)++; + ppfjet_twr_ieta_.push_back((*ith).id().ieta()); + ppfjet_twr_iphi_.push_back((*ith).id().iphi()); + ppfjet_twr_depth_.push_back((*ith).id().depth()); + ppfjet_twr_subdet_.push_back((*ith).id().subdet()); + ppfjet_twr_hade_.push_back((*ith).energy()); + ppfjet_twr_frac_.push_back(1.0); + ppfjet_twr_hadind_.push_back(ppfjet_had_n_ - 1); + ppfjet_twr_elmttype_.push_back(1); + ppfjet_twr_clusterind_.push_back(-1); + ppfjet_twr_candtrackind_.push_back(-1); + float avgeta = (cv[0].eta() + cv[2].eta())/2.0; + float avgphi = (static_cast(cv[0].phi()) + static_cast(cv[2].phi()))/2.0; + if((cv[0].phi() < cv[2].phi()) && (debug_>1)) LogDebug("GammaJetAnalysis") << "pHFhad" << cv[0].phi() << " " << cv[2].phi(); + if(cv[0].phi() < cv[2].phi()) avgphi = (2.0*3.141592653 + static_cast(cv[0].phi()) + static_cast(cv[2].phi()))/2.0; + ppfjet_twr_dR_.push_back(deltaR(ppfjet_eta_,ppfjet_phi_,avgeta,avgphi)); + ++ppfjet_ntwrs_; + HFHAD_E += (*ith).energy(); + } + } + } + else if(elements[iEle].type() == reco::PFBlockElement::HFEM){ // Element is HF + types |= 0x4; + ntypes++; + HFEM_n_++; + HF_type_ |= 0x4; - } // Ecal - } // cycle on iso radii - } // cycle on rechits - + for(edm::SortedCollection>::const_iterator ith=hfreco->begin(); ith!=hfreco->end(); ++ith){ + if((*ith).id().depth() == 2) continue; // Remove short fibers + const CaloCellGeometry *thisCell = HFGeom->getGeometry((*ith).id().rawId()); + const CaloCellGeometry::CornersVec& cv = thisCell->getCorners(); + + bool passMatch = false; + if((*it)->eta() < cv[0].eta() && (*it)->eta() > cv[2].eta()){ + if((*it)->phi() < cv[0].phi() && (*it)->phi() > cv[2].phi()) passMatch = true; + else if(cv[0].phi() < cv[2].phi()){ + if((*it)->phi() < cv[0].phi()) passMatch = true; + else if((*it)->phi() > cv[2].phi()) passMatch = true; + } + } + + if(passMatch){ + ppfjet_had_ntwrs_.at(ppfjet_had_n_ - 1)++; + ppfjet_twr_ieta_.push_back((*ith).id().ieta()); + ppfjet_twr_iphi_.push_back((*ith).id().iphi()); + ppfjet_twr_depth_.push_back((*ith).id().depth()); + ppfjet_twr_subdet_.push_back((*ith).id().subdet()); + ppfjet_twr_hade_.push_back((*ith).energy()); + ppfjet_twr_frac_.push_back(1.0); + ppfjet_twr_hadind_.push_back(ppfjet_had_n_ - 1); + ppfjet_twr_elmttype_.push_back(2); + ppfjet_twr_clusterind_.push_back(-1); + ppfjet_twr_candtrackind_.push_back(-1); + float avgeta = (cv[0].eta() + cv[2].eta())/2.0; + float avgphi = (static_cast(cv[0].phi()) + static_cast(cv[2].phi()))/2.0; + if((cv[0].phi() < cv[2].phi()) && (debug_>1)) LogDebug("GammaJetAnalysis") << "pHFem" << cv[0].phi() << " " << cv[2].phi(); + if(cv[0].phi() < cv[2].phi()) avgphi = (2.0*3.141592653 + static_cast(cv[0].phi()) + static_cast(cv[2].phi()))/2.0; + ppfjet_twr_dR_.push_back(deltaR(ppfjet_eta_,ppfjet_phi_,avgeta,avgphi)); + ++ppfjet_ntwrs_; + HFEM_E += (*ith).energy(); + } + } + } + else if(elements[iEle].type() == reco::PFBlockElement::HO){ // Element is HO + types |= 0x8; + ntypes++; + HF_type_ |= 0x8; + reco::PFClusterRef clusterref = elements[iEle].clusterRef(); + reco::PFCluster cluster = *clusterref; + double cluster_dR = deltaR(ppfjet_eta_,ppfjet_phi_,cluster.eta(),cluster.phi()); + if(ppfjet_clusters.count(cluster_dR) == 0){ + ppfjet_clusters[cluster_dR] = ppfjet_cluster_n_; + ppfjet_cluster_eta_.push_back(cluster.eta()); + ppfjet_cluster_phi_.push_back(cluster.phi()); + ppfjet_cluster_dR_.push_back(cluster_dR); + ppfjet_cluster_n_++; + } + int cluster_ind = ppfjet_clusters[cluster_dR]; + + std::vector> hitsAndFracs = cluster.hitsAndFractions(); + int nHits = hitsAndFracs.size(); + for(int iHit=0; iHit>::const_iterator ith=horeco->begin(); ith!=horeco->end(); ++ith){ + int etaPhiRecHit = getEtaPhi((*ith).id()); + if(etaPhiPF == etaPhiRecHit){ + ppfjet_had_ntwrs_.at(ppfjet_had_n_ - 1)++; + if(ppfjet_rechits.count((*ith).id()) == 0){ + ppfjet_twr_ieta_.push_back((*ith).id().ieta()); + ppfjet_twr_iphi_.push_back((*ith).id().iphi()); + ppfjet_twr_depth_.push_back((*ith).id().depth()); + ppfjet_twr_subdet_.push_back((*ith).id().subdet()); + ppfjet_twr_hade_.push_back((*ith).energy()); + ppfjet_twr_frac_.push_back(hitsAndFracs[iHit].second); + ppfjet_rechits[(*ith).id()].second.insert(hitsAndFracs[iHit].second); + ppfjet_twr_hadind_.push_back(ppfjet_had_n_ - 1); + ppfjet_twr_elmttype_.push_back(3); + ppfjet_twr_clusterind_.push_back(cluster_ind); + if(hasTrack){ + ppfjet_twr_candtrackind_.push_back(ppfjet_ncandtracks_ - 1); + } + else{ + ppfjet_twr_candtrackind_.push_back(-1); + } + const CaloCellGeometry *thisCell = HOGeom->getGeometry((*ith).id().rawId()); + const CaloCellGeometry::CornersVec& cv = thisCell->getCorners(); + float avgeta = (cv[0].eta() + cv[2].eta())/2.0; + float avgphi = (static_cast(cv[0].phi()) + static_cast(cv[2].phi()))/2.0; + if((cv[0].phi() < cv[2].phi()) && (debug_>1)) LogDebug("GammaJetAnalysis") << "pHO" << cv[0].phi() << " " << cv[2].phi(); + if(cv[0].phi() < cv[2].phi()) avgphi = (2.0*3.141592653 + static_cast(cv[0].phi()) + static_cast(cv[2].phi()))/2.0; + + ppfjet_twr_dR_.push_back(deltaR(ppfjet_eta_,ppfjet_phi_,avgeta,avgphi)); + ppfjet_rechits[(*ith).id()].first = ppfjet_ntwrs_; + ++ppfjet_ntwrs_; + } + else if(ppfjet_rechits[(*ith).id()].second.count(hitsAndFracs[iHit].second) == 0){ + ppfjet_twr_frac_.at(ppfjet_rechits[(*ith).id()].first) += hitsAndFracs[iHit].second; + if(cluster_dR < ppfjet_cluster_dR_.at(ppfjet_twr_clusterind_.at(ppfjet_rechits[(*ith).id()].first))){ + ppfjet_twr_clusterind_.at(ppfjet_rechits[(*ith).id()].first) = cluster_ind; + } + ppfjet_rechits[(*ith).id()].second.insert(hitsAndFracs[iHit].second); + } + } // Test if ieta,iphi match + } // Loop over rechits + } // Loop over hits + } // Test if element is from HO + } // Test for right element index + } // Loop over elements + } // Loop over elements in blocks + switch(candidateType){ + case reco::PFCandidate::h_HF: + ppfjet_had_emf_.push_back(HFEM_E/(HFEM_E + HFHAD_E)); + break; + case reco::PFCandidate::egamma_HF: + ppfjet_had_emf_.push_back(-1); + break; + default: + ppfjet_had_emf_.push_back(-1); + break; + } + } // Loop over PF constitutents -// Fill Tree - if( NumRecoGamma < 10 ) - { - for (int ii = 0; ii<9 ; ii++) - { - GammaIsoEcal[ii][NumRecoGamma] = gammaiso_ecal[ii]; - } - EcalClusDet[NumRecoGamma] = 1; - GammaRecoEt[NumRecoGamma] = vet; - GammaRecoEta[NumRecoGamma] = aClus->eta(); - GammaRecoPhi[NumRecoGamma] = aClus->phi(); - NumRecoGamma++; - } - (*myout_photon)<eta()<<" "<phi()<<" "<::const_iterator it=genjets->begin(); it!=genjets->end(); ++it){ + const reco::GenJet* jet=&(*it); + double dr=deltaR(jet, pfjet_probe.jet()); + if(drpt(); + ppfjet_genp_ = jet->p(); + ppfjet_genE_ = jet->energy(); + } + } + } // doGenJets_ + if (iJet==2) { + copy_leadingPfJetVars_to_pfJet2(); + } + } + // double jer= (ppfjet_genpt_==double(0)) ? + // 0. : pfjet_probe.jet()->et()/ppfjet_genpt_; + ///h_pfrecoOgen_et->Fill(jer, eventWeight_); + + ///// MET ///// + edm::Handle pfmet_h; + iEvent.getByToken(tok_PFMET_, pfmet_h); + if (!pfmet_h.isValid()) { + edm::LogWarning("GammaJetAnalysis") << " could not find " << pfMETColl; + return; + } + met_value_ = pfmet_h->begin()->et(); + met_phi_ = pfmet_h->begin()->phi(); + met_sumEt_ = pfmet_h->begin()->sumEt(); + + edm::Handle pfmetType1_h; + iEvent.getByToken(tok_PFType1MET_, pfmetType1_h); + if ( pfmetType1_h.isValid()) { + metType1_value_ = pfmetType1_h->begin()->et(); + metType1_phi_ = pfmetType1_h->begin()->phi(); + metType1_sumEt_ = pfmetType1_h->begin()->sumEt(); + } + else { + // do we need an exception here? + metType1_value_ = -999.; + metType1_phi_ = -999.; + metType1_sumEt_ = -999.; + } + + + // fill photon+jet variables + pf_tree_->Fill(); + } + } + return; + +} + +// ------------ method called once each job just before starting event loop ------------ +void GammaJetAnalysis::beginJob() +{ + rootfile_ = new TFile(rootHistFilename_.c_str(), "RECREATE"); + if (doPFJets_) { + pf_tree_ = new TTree("pf_gammajettree", "tree for gamma+jet balancing using PFJets"); + assert(pf_tree_); + } + + for (int iJet=0; iJet<2; iJet++) { + bool doJet=doPFJets_; + if (!doJet) continue; + if (iJet>0) continue; // ! caloJet are no longer there, so store only once + TTree *tree= pf_tree_; + + // Event triggers + tree->Branch("photonTrig_fired", &photonTrigFired_); + tree->Branch("photonTrig_prescale", &photonTrigPrescale_); + tree->Branch("jetTrig_fired", &jetTrigFired_); + tree->Branch("jetTrig_prescale", &jetTrigPrescale_); + + // Event info + tree->Branch("RunNumber",&runNumber_, "RunNumber/I"); + tree->Branch("LumiBlock",&lumiBlock_, "LumiBlock/I"); + tree->Branch("EventNumber",&eventNumber_, "EventNumber/I"); + tree->Branch("EventWeight",&eventWeight_, "EventWeight/F"); + tree->Branch("EventPtHat",&eventPtHat_, "EventPtHat/F"); + + // Photon info + tree->Branch("rho2012", &rho2012_, "rho2012/F"); + tree->Branch("tagPho_pt", &tagPho_pt_, "tagPho_pt/F"); + tree->Branch("pho_2nd_pt", &pho_2nd_pt_, "pho_2nd_pt/F"); + tree->Branch("tagPho_energy", &tagPho_energy_, "tagPho_energy/F"); + tree->Branch("tagPho_eta", &tagPho_eta_, "tagPho_eta/F"); + tree->Branch("tagPho_phi", &tagPho_phi_, "tagPho_phi/F"); + tree->Branch("tagPho_sieie", &tagPho_sieie_, "tagPho_sieie/F"); + tree->Branch("tagPho_HoE", &tagPho_HoE_, "tagPho_HoE/F"); + tree->Branch("tagPho_r9", &tagPho_r9_, "tagPho_r9/F"); + tree->Branch("tagPho_EcalIsoDR04",&tagPho_EcalIsoDR04_, "tagPho_EcalIsoDR04/F"); + tree->Branch("tagPho_HcalIsoDR04",&tagPho_HcalIsoDR04_, "tagPho_HcalIsoDR04/F"); + tree->Branch("tagPho_HcalIsoDR0412",&tagPho_HcalIsoDR0412_, "tagPho_HcalIsoDR0412/F"); + tree->Branch("tagPho_TrkIsoHollowDR04",&tagPho_TrkIsoHollowDR04_, "tagPho_TrkIsoHollowDR04/F"); + tree->Branch("tagPho_pfiso_myphoton03",&tagPho_pfiso_myphoton03_, "tagPho_pfiso_myphoton03/F"); + tree->Branch("tagPho_pfiso_myneutral03",&tagPho_pfiso_myneutral03_, "tagPho_pfiso_myneutral03/F"); + tree->Branch("tagPho_pfiso_mycharged03","std::vector >", &tagPho_pfiso_mycharged03); + tree->Branch("tagPho_pixelSeed", &tagPho_pixelSeed_, "tagPho_pixelSeed/I"); + tree->Branch("tagPho_ConvSafeEleVeto", &tagPho_ConvSafeEleVeto_, "tagPho_ConvSafeEleVeto/I"); + tree->Branch("tagPho_idTight",&tagPho_idTight_, "tagPho_idTight/I"); + tree->Branch("tagPho_idLoose",&tagPho_idLoose_, "tagPho_idLoose/I"); + // gen.info on photon + if(doGenJets_){ + tree->Branch("tagPho_genPt",&tagPho_genPt_, "tagPho_genPt/F"); + tree->Branch("tagPho_genEnergy",&tagPho_genEnergy_,"tagPho_genEnergy/F"); + tree->Branch("tagPho_genEta",&tagPho_genEta_, "tagPho_genEta/F"); + tree->Branch("tagPho_genPhi",&tagPho_genPhi_, "tagPho_genPhi/F"); + tree->Branch("tagPho_genDeltaR",&tagPho_genDeltaR_,"tagPho_genDeltaR/F"); + } + // counters + tree->Branch("nPhotons",&nPhotons_, "nPhotons/I"); + tree->Branch("nGenJets",&nGenJets_, "nGenJets/I"); + } + + //////// Particle Flow //////// + + if (doPFJets_) { + + pf_tree_->Branch("nPFJets",&nPFJets_, "nPFJets/I"); + + // Leading jet info + pf_tree_->Branch("ppfjet_pt",&ppfjet_pt_, "ppfjet_pt/F"); + pf_tree_->Branch("ppfjet_p",&ppfjet_p_, "ppfjet_p/F"); + pf_tree_->Branch("ppfjet_E",&ppfjet_E_, "ppfjet_E/F"); + pf_tree_->Branch("ppfjet_E_NPVcorr",&ppfjet_E_NPVcorr_, "ppfjet_E_NPVcorr/F"); + pf_tree_->Branch("ppfjet_area",&ppfjet_area_, "ppfjet_area/F"); + pf_tree_->Branch("ppfjet_eta",&ppfjet_eta_, "ppfjet_eta/F"); + pf_tree_->Branch("ppfjet_phi",&ppfjet_phi_, "ppfjet_phi/F"); + pf_tree_->Branch("ppfjet_scale",&ppfjet_scale_, "ppfjet_scale/F"); + pf_tree_->Branch("ppfjet_NeutralHadronFrac", &ppfjet_NeutralHadronFrac_, "ppfjet_NeutralHadronFrac/F"); + pf_tree_->Branch("ppfjet_NeutralEMFrac", &ppfjet_NeutralEMFrac_, "ppfjet_NeutralEMFrac/F"); + pf_tree_->Branch("ppfjet_nConstituents", &ppfjet_nConstituents_, "ppfjet_nConstituents/I"); + pf_tree_->Branch("ppfjet_ChargedHadronFrac", &ppfjet_ChargedHadronFrac_, "ppfjet_ChargedHadronFrac/F"); + pf_tree_->Branch("ppfjet_ChargedMultiplicity", &ppfjet_ChargedMultiplicity_, "ppfjet_ChargedMultiplicity/F"); + pf_tree_->Branch("ppfjet_ChargedEMFrac", &ppfjet_ChargedEMFrac_, "ppfjet_ChargedEMFrac/F"); + if(doGenJets_){ + pf_tree_->Branch("ppfjet_genpt",&ppfjet_genpt_, "ppfjet_genpt/F"); + pf_tree_->Branch("ppfjet_genp",&ppfjet_genp_, "ppfjet_genp/F"); + pf_tree_->Branch("ppfjet_genE",&ppfjet_genE_, "ppfjet_genE/F"); + pf_tree_->Branch("ppfjet_gendr",&ppfjet_gendr_, "ppfjet_gendr/F"); + } + pf_tree_->Branch("ppfjet_unkown_E",&ppfjet_unkown_E_, "ppfjet_unkown_E/F"); + pf_tree_->Branch("ppfjet_electron_E",&ppfjet_electron_E_, "ppfjet_electron_E/F"); + pf_tree_->Branch("ppfjet_muon_E",&ppfjet_muon_E_, "ppfjet_muon_E/F"); + pf_tree_->Branch("ppfjet_photon_E",&ppfjet_photon_E_, "ppfjet_photon_E/F"); + pf_tree_->Branch("ppfjet_unkown_px",&ppfjet_unkown_px_, "ppfjet_unkown_px/F"); + pf_tree_->Branch("ppfjet_electron_px",&ppfjet_electron_px_, "ppfjet_electron_px/F"); + pf_tree_->Branch("ppfjet_muon_px",&ppfjet_muon_px_, "ppfjet_muon_px/F"); + pf_tree_->Branch("ppfjet_photon_px",&ppfjet_photon_px_, "ppfjet_photon_px/F"); + pf_tree_->Branch("ppfjet_unkown_py",&ppfjet_unkown_py_, "ppfjet_unkown_py/F"); + pf_tree_->Branch("ppfjet_electron_py",&ppfjet_electron_py_, "ppfjet_electron_py/F"); + pf_tree_->Branch("ppfjet_muon_py",&ppfjet_muon_py_, "ppfjet_muon_py/F"); + pf_tree_->Branch("ppfjet_photon_py",&ppfjet_photon_py_, "ppfjet_photon_py/F"); + pf_tree_->Branch("ppfjet_unkown_pz",&ppfjet_unkown_pz_, "ppfjet_unkown_pz/F"); + pf_tree_->Branch("ppfjet_electron_pz",&ppfjet_electron_pz_, "ppfjet_electron_pz/F"); + pf_tree_->Branch("ppfjet_muon_pz",&ppfjet_muon_pz_, "ppfjet_muon_pz/F"); + pf_tree_->Branch("ppfjet_photon_pz",&ppfjet_photon_pz_, "ppfjet_photon_pz/F"); + pf_tree_->Branch("ppfjet_unkown_EcalE",&ppfjet_unkown_EcalE_, "ppfjet_unkown_EcalE/F"); + pf_tree_->Branch("ppfjet_electron_EcalE",&ppfjet_electron_EcalE_, "ppfjet_electron_EcalE/F"); + pf_tree_->Branch("ppfjet_muon_EcalE",&ppfjet_muon_EcalE_, "ppfjet_muon_EcalE/F"); + pf_tree_->Branch("ppfjet_photon_EcalE",&ppfjet_photon_EcalE_, "ppfjet_photon_EcalE/F"); + pf_tree_->Branch("ppfjet_unkown_n",&ppfjet_unkown_n_, "ppfjet_unkown_n/I"); + pf_tree_->Branch("ppfjet_electron_n",&ppfjet_electron_n_, "ppfjet_electron_n/I"); + pf_tree_->Branch("ppfjet_muon_n",&ppfjet_muon_n_, "ppfjet_muon_n/I"); + pf_tree_->Branch("ppfjet_photon_n",&ppfjet_photon_n_, "ppfjet_photon_n/I"); + pf_tree_->Branch("ppfjet_had_n",&ppfjet_had_n_, "ppfjet_had_n/I"); + pf_tree_->Branch("ppfjet_had_E",&ppfjet_had_E_); + pf_tree_->Branch("ppfjet_had_px",&ppfjet_had_px_); + pf_tree_->Branch("ppfjet_had_py",&ppfjet_had_py_); + pf_tree_->Branch("ppfjet_had_pz",&ppfjet_had_pz_); + pf_tree_->Branch("ppfjet_had_EcalE",&ppfjet_had_EcalE_); + pf_tree_->Branch("ppfjet_had_rawHcalE",&ppfjet_had_rawHcalE_); + pf_tree_->Branch("ppfjet_had_emf",&ppfjet_had_emf_); + pf_tree_->Branch("ppfjet_had_id",&ppfjet_had_id_); + pf_tree_->Branch("ppfjet_had_candtrackind",&ppfjet_had_candtrackind_); + if(doGenJets_){ + pf_tree_->Branch("ppfjet_had_E_mctruth",&ppfjet_had_E_mctruth_); + pf_tree_->Branch("ppfjet_had_mcpdgId",&ppfjet_had_mcpdgId_); + } + pf_tree_->Branch("ppfjet_had_ntwrs",&ppfjet_had_ntwrs_); + pf_tree_->Branch("ppfjet_ntwrs",&ppfjet_ntwrs_, "ppfjet_ntwrs/I"); + pf_tree_->Branch("ppfjet_twr_ieta",&ppfjet_twr_ieta_); + pf_tree_->Branch("ppfjet_twr_iphi",&ppfjet_twr_iphi_); + pf_tree_->Branch("ppfjet_twr_depth",&ppfjet_twr_depth_); + pf_tree_->Branch("ppfjet_twr_subdet",&ppfjet_twr_subdet_); + pf_tree_->Branch("ppfjet_twr_hade",&ppfjet_twr_hade_); + pf_tree_->Branch("ppfjet_twr_frac",&ppfjet_twr_frac_); + pf_tree_->Branch("ppfjet_twr_candtrackind",&ppfjet_twr_candtrackind_); + pf_tree_->Branch("ppfjet_twr_hadind",&ppfjet_twr_hadind_); + pf_tree_->Branch("ppfjet_twr_elmttype",&ppfjet_twr_elmttype_); + pf_tree_->Branch("ppfjet_twr_dR",&ppfjet_twr_dR_); + pf_tree_->Branch("ppfjet_twr_clusterind",&ppfjet_twr_clusterind_); + pf_tree_->Branch("ppfjet_cluster_n",&ppfjet_cluster_n_, "ppfjet_cluster_n/I"); + pf_tree_->Branch("ppfjet_cluster_eta",&ppfjet_cluster_eta_); + pf_tree_->Branch("ppfjet_cluster_phi",&ppfjet_cluster_phi_); + pf_tree_->Branch("ppfjet_cluster_dR",&ppfjet_cluster_dR_); + pf_tree_->Branch("ppfjet_ncandtracks",&ppfjet_ncandtracks_, "ppfjet_ncandtracks/I"); + pf_tree_->Branch("ppfjet_candtrack_px",&ppfjet_candtrack_px_); + pf_tree_->Branch("ppfjet_candtrack_py",&ppfjet_candtrack_py_); + pf_tree_->Branch("ppfjet_candtrack_pz",&ppfjet_candtrack_pz_); + pf_tree_->Branch("ppfjet_candtrack_EcalE",&ppfjet_candtrack_EcalE_); + + // Subleading jet info + pf_tree_->Branch("pfjet2_pt",&pfjet2_pt_, "pfjet2_pt/F"); + pf_tree_->Branch("pfjet2_p",&pfjet2_p_, "pfjet2_p/F"); + pf_tree_->Branch("pfjet2_E",&pfjet2_E_, "pfjet2_E/F"); + pf_tree_->Branch("pfjet2_E_NPVcorr",&pfjet2_E_NPVcorr_, "pfjet2_E_NPVcorr/F"); + pf_tree_->Branch("pfjet2_area",&pfjet2_area_, "pfjet2_area/F"); + pf_tree_->Branch("pfjet2_eta",&pfjet2_eta_, "pfjet2_eta/F"); + pf_tree_->Branch("pfjet2_phi",&pfjet2_phi_, "pfjet2_phi/F"); + pf_tree_->Branch("pfjet2_scale",&pfjet2_scale_, "pfjet2_scale/F"); + pf_tree_->Branch("pfjet2_NeutralHadronFrac", &pfjet2_NeutralHadronFrac_, "pfjet2_NeutralHadronFrac/F"); + pf_tree_->Branch("pfjet2_NeutralEMFrac", &pfjet2_NeutralEMFrac_, "pfjet2_NeutralEMFrac/F"); + pf_tree_->Branch("pfjet2_nConstituents", &pfjet2_nConstituents_, "pfjet2_nConstituents/I"); + pf_tree_->Branch("pfjet2_ChargedHadronFrac", &pfjet2_ChargedHadronFrac_, "pfjet2_ChargedHadronFrac/F"); + pf_tree_->Branch("pfjet2_ChargedMultiplicity", &pfjet2_ChargedMultiplicity_, "pfjet2_ChargedMultiplicity/F"); + pf_tree_->Branch("pfjet2_ChargedEMFrac", &pfjet2_ChargedEMFrac_, "pfjet2_ChargedEMFrac/F"); + if(doGenJets_){ + pf_tree_->Branch("pfjet2_genpt",&pfjet2_genpt_, "pfjet2_genpt/F"); + pf_tree_->Branch("pfjet2_genp",&pfjet2_genp_, "pfjet2_genp/F"); + pf_tree_->Branch("pfjet2_genE",&pfjet2_genE_, "pfjet2_genE/F"); + pf_tree_->Branch("pfjet2_gendr",&pfjet2_gendr_, "pfjet2_gendr/F"); + } + pf_tree_->Branch("pfjet2_unkown_E",&pfjet2_unkown_E_, "pfjet2_unkown_E/F"); + pf_tree_->Branch("pfjet2_electron_E",&pfjet2_electron_E_, "pfjet2_electron_E/F"); + pf_tree_->Branch("pfjet2_muon_E",&pfjet2_muon_E_, "pfjet2_muon_E/F"); + pf_tree_->Branch("pfjet2_photon_E",&pfjet2_photon_E_, "pfjet2_photon_E/F"); + pf_tree_->Branch("pfjet2_unkown_px",&pfjet2_unkown_px_, "pfjet2_unkown_px/F"); + pf_tree_->Branch("pfjet2_electron_px",&pfjet2_electron_px_, "pfjet2_electron_px/F"); + pf_tree_->Branch("pfjet2_muon_px",&pfjet2_muon_px_, "pfjet2_muon_px/F"); + pf_tree_->Branch("pfjet2_photon_px",&pfjet2_photon_px_, "pfjet2_photon_px/F"); + pf_tree_->Branch("pfjet2_unkown_py",&pfjet2_unkown_py_, "pfjet2_unkown_py/F"); + pf_tree_->Branch("pfjet2_electron_py",&pfjet2_electron_py_, "pfjet2_electron_py/F"); + pf_tree_->Branch("pfjet2_muon_py",&pfjet2_muon_py_, "pfjet2_muon_py/F"); + pf_tree_->Branch("pfjet2_photon_py",&pfjet2_photon_py_, "pfjet2_photon_py/F"); + pf_tree_->Branch("pfjet2_unkown_pz",&pfjet2_unkown_pz_, "pfjet2_unkown_pz/F"); + pf_tree_->Branch("pfjet2_electron_pz",&pfjet2_electron_pz_, "pfjet2_electron_pz/F"); + pf_tree_->Branch("pfjet2_muon_pz",&pfjet2_muon_pz_, "pfjet2_muon_pz/F"); + pf_tree_->Branch("pfjet2_photon_pz",&pfjet2_photon_pz_, "pfjet2_photon_pz/F"); + pf_tree_->Branch("pfjet2_unkown_EcalE",&pfjet2_unkown_EcalE_, "pfjet2_unkown_EcalE/F"); + pf_tree_->Branch("pfjet2_electron_EcalE",&pfjet2_electron_EcalE_, "pfjet2_electron_EcalE/F"); + pf_tree_->Branch("pfjet2_muon_EcalE",&pfjet2_muon_EcalE_, "pfjet2_muon_EcalE/F"); + pf_tree_->Branch("pfjet2_photon_EcalE",&pfjet2_photon_EcalE_, "pfjet2_photon_EcalE/F"); + pf_tree_->Branch("pfjet2_unkown_n",&pfjet2_unkown_n_, "pfjet2_unkown_n/I"); + pf_tree_->Branch("pfjet2_electron_n",&pfjet2_electron_n_, "pfjet2_electron_n/I"); + pf_tree_->Branch("pfjet2_muon_n",&pfjet2_muon_n_, "pfjet2_muon_n/I"); + pf_tree_->Branch("pfjet2_photon_n",&pfjet2_photon_n_, "pfjet2_photon_n/I"); + pf_tree_->Branch("pfjet2_had_n",&pfjet2_had_n_, "pfjet2_had_n/I"); + pf_tree_->Branch("pfjet2_had_E",&pfjet2_had_E_); + pf_tree_->Branch("pfjet2_had_px",&pfjet2_had_px_); + pf_tree_->Branch("pfjet2_had_py",&pfjet2_had_py_); + pf_tree_->Branch("pfjet2_had_pz",&pfjet2_had_pz_); + pf_tree_->Branch("pfjet2_had_EcalE",&pfjet2_had_EcalE_); + pf_tree_->Branch("pfjet2_had_rawHcalE",&pfjet2_had_rawHcalE_); + pf_tree_->Branch("pfjet2_had_emf",&pfjet2_had_emf_); + pf_tree_->Branch("pfjet2_had_id",&pfjet2_had_id_); + pf_tree_->Branch("pfjet2_had_candtrackind",&pfjet2_had_candtrackind_); + if(doGenJets_){ + pf_tree_->Branch("pfjet2_had_E_mctruth",&pfjet2_had_E_mctruth_); + pf_tree_->Branch("pfjet2_had_mcpdgId",&pfjet2_had_mcpdgId_); + } + pf_tree_->Branch("pfjet2_had_ntwrs",&pfjet2_had_ntwrs_); + pf_tree_->Branch("pfjet2_ntwrs",&pfjet2_ntwrs_, "pfjet2_ntwrs/I"); + pf_tree_->Branch("pfjet2_twr_ieta",&pfjet2_twr_ieta_); + pf_tree_->Branch("pfjet2_twr_iphi",&pfjet2_twr_iphi_); + pf_tree_->Branch("pfjet2_twr_depth",&pfjet2_twr_depth_); + pf_tree_->Branch("pfjet2_twr_subdet",&pfjet2_twr_subdet_); + pf_tree_->Branch("pfjet2_twr_hade",&pfjet2_twr_hade_); + pf_tree_->Branch("pfjet2_twr_frac",&pfjet2_twr_frac_); + pf_tree_->Branch("pfjet2_twr_candtrackind",&pfjet2_twr_candtrackind_); + pf_tree_->Branch("pfjet2_twr_hadind",&pfjet2_twr_hadind_); + pf_tree_->Branch("pfjet2_twr_elmttype",&pfjet2_twr_elmttype_); + pf_tree_->Branch("pfjet2_twr_dR",&pfjet2_twr_dR_); + pf_tree_->Branch("pfjet2_twr_clusterind",&pfjet2_twr_clusterind_); + pf_tree_->Branch("pfjet2_cluster_n",&pfjet2_cluster_n_, "pfjet2_cluster_n/I"); + pf_tree_->Branch("pfjet2_cluster_eta",&pfjet2_cluster_eta_); + pf_tree_->Branch("pfjet2_cluster_phi",&pfjet2_cluster_phi_); + pf_tree_->Branch("pfjet2_cluster_dR",&pfjet2_cluster_dR_); + pf_tree_->Branch("pfjet2_ncandtracks",&pfjet2_ncandtracks_, "pfjet2_ncandtracks/I"); + pf_tree_->Branch("pfjet2_candtrack_px",&pfjet2_candtrack_px_); + pf_tree_->Branch("pfjet2_candtrack_py",&pfjet2_candtrack_py_); + pf_tree_->Branch("pfjet2_candtrack_pz",&pfjet2_candtrack_pz_); + pf_tree_->Branch("pfjet2_candtrack_EcalE",&pfjet2_candtrack_EcalE_); + + // third pf jet + pf_tree_->Branch("pf_thirdjet_et", &pf_thirdjet_et_, "pf_thirdjet_et/F"); + pf_tree_->Branch("pf_thirdjet_pt", &pf_thirdjet_pt_, "pf_thirdjet_pt/F"); + pf_tree_->Branch("pf_thirdjet_p", &pf_thirdjet_p_, "pf_thirdjet_p/F"); + pf_tree_->Branch("pf_thirdjet_px", &pf_thirdjet_px_, "pf_thirdjet_px/F"); + pf_tree_->Branch("pf_thirdjet_py", &pf_thirdjet_py_, "pf_thirdjet_py/F"); + pf_tree_->Branch("pf_thirdjet_E", &pf_thirdjet_E_, "pf_thirdjet_E/F"); + pf_tree_->Branch("pf_thirdjet_eta", &pf_thirdjet_eta_, "pf_thirdjet_eta/F"); + pf_tree_->Branch("pf_thirdjet_phi", &pf_thirdjet_phi_, "pf_thirdjet_phi/F"); + pf_tree_->Branch("pf_thirdjet_scale", &pf_thirdjet_scale_, "pf_thirdjet_scale/F"); + + pf_tree_->Branch("met_value", &met_value_, "met_value/F"); + pf_tree_->Branch("met_phi", &met_phi_, "met_phi/F"); + pf_tree_->Branch("met_sumEt", &met_sumEt_, "met_sumEt/F"); + pf_tree_->Branch("metType1_value", &metType1_value_, "metType1_value/F"); + pf_tree_->Branch("metType1_phi", &metType1_phi_, "metType1_phi/F"); + pf_tree_->Branch("metType1_sumEt", &metType1_sumEt_, "metType1_sumEt/F"); + pf_tree_->Branch("pf_NPV",&pf_NPV_, "pf_NPV/I"); + } + + return; +} + +// ------------ method called once each job just after ending the event loop ------------ +void +GammaJetAnalysis::endJob() { + rootfile_->cd(); + + if(doPFJets_){ + pf_tree_->Write(); + } + // write miscItems + // Save info about the triggers and other misc items + { + rootfile_->cd(); + rootfile_->mkdir("miscItems"); + rootfile_->cd("miscItems"); + misc_tree_= new TTree("misc_tree","tree for misc.info"); + misc_tree_->Branch("ignoreHLT",&ignoreHLT_,"ignoreHLT/O"); + misc_tree_->Branch("doPFJets",&doPFJets_,"doPFJets/O"); + misc_tree_->Branch("doGenJets",&doGenJets_,"doGenJets/O"); + misc_tree_->Branch("workOnAOD",&workOnAOD_,"workOnAOD/O"); + misc_tree_->Branch("photonTriggerNames",&photonTrigNamesV_); + misc_tree_->Branch("jetTriggerNames",&jetTrigNamesV_); + misc_tree_->Branch("nProcessed",&nProcessed_,"nProcessed/l"); + // put time stamp + time_t ltime; + ltime=time(NULL); + TString str = TString(asctime(localtime(<ime))); + if (str[str.Length()-1]=='\n') str.Remove(str.Length()-1,1); + TObjString date(str); + date.Write(str.Data()); + misc_tree_->Fill(); + misc_tree_->Write(); + rootfile_->cd(); + } + + rootfile_->Close(); +} + + +// --------------------------------------------------------------------- + +void GammaJetAnalysis::beginRun(const edm::Run &iRun, + const edm::EventSetup &setup) +{ + if (debug_>1) LogDebug("GammaJetAnalysis") << "beginRun()"; + + if (!ignoreHLT_) { + int noPhotonTrigger= (photonTrigNamesV_.size()==0) ? 1:0; + int noJetTrigger= (jetTrigNamesV_.size()==0) ? 1:0; + if (!noPhotonTrigger && + (photonTrigNamesV_.size()==1) && + (photonTrigNamesV_[0].length()==0)) noPhotonTrigger=1; + if (!noJetTrigger && + (jetTrigNamesV_.size()==1) && + (jetTrigNamesV_[0].length()==0)) noJetTrigger=1; + if (noPhotonTrigger && noJetTrigger) { + ignoreHLT_=true; + if (debug_>1) LogDebug("GammaJetAnalysis") << "HLT trigger ignored: no trigger requested"; + } + } + else { + // clear trigger names, if needed + photonTrigNamesV_.clear(); + jetTrigNamesV_.clear(); + } + + if (!ignoreHLT_) { + if (debug_>0) LogDebug("GammaJetAnalysis") << "Initializing trigger information for individual run"; + bool changed(true); + std::string processName="HLT"; + if (hltConfig_.init(iRun,setup,processName,changed)) { + // if init returns TRUE, initialisation has succeeded! + if (changed) { + // The HLT config has actually changed wrt the previous Run, hence rebook your + // histograms or do anything else dependent on the revised HLT config + } + } + else { + // if init returns FALSE, initialisation has NOT succeeded, which indicates a problem + // with the file and/or code and needs to be investigated! + throw edm::Exception(edm::errors::ProductNotFound) + << " HLT config extraction failure with process name " << processName; + // In this case, all access methods will return empty values! + } + } +} + +// --------------------------------------------------------------------- + +// helper function + +float GammaJetAnalysis::pfEcalIso(const reco::Photon* localPho1, edm::Handle pfHandle, float dRmax, float dRVetoBarrel, float dRVetoEndcap, float etaStripBarrel, float etaStripEndcap, float energyBarrel, float energyEndcap, reco::PFCandidate::ParticleType pfToUse) { + if (debug_>1) LogDebug("GammaJetAnalysis") << "Inside pfEcalIso"; + reco::Photon* localPho = localPho1->clone(); + float dRVeto; + float etaStrip; + + if (localPho->isEB()) { + dRVeto = dRVetoBarrel; + etaStrip = etaStripBarrel; + } else { + dRVeto = dRVetoEndcap; + etaStrip = etaStripEndcap; + } + const reco::PFCandidateCollection* forIsolation = pfHandle.product(); + int nsize = forIsolation->size(); + float sum = 0; + for (int i=0; isuperCluster().isNonnull()) { + if (pfc.superClusterRef() == localPho->superCluster()) + continue; + } + + if (localPho->isEB()) { + if (fabs(pfc.pt()) < energyBarrel) + continue; + } else { + if (fabs(pfc.energy()) < energyEndcap) + continue; + } + // Shift the photon direction vector according to the PF vertex + math::XYZPoint pfvtx = pfc.vertex(); + math::XYZVector photon_directionWrtVtx(localPho->superCluster()->x() - pfvtx.x(), + localPho->superCluster()->y() - pfvtx.y(), + localPho->superCluster()->z() - pfvtx.z()); + + float dEta = fabs(photon_directionWrtVtx.Eta() - pfc.momentum().Eta()); + float dR = deltaR(photon_directionWrtVtx.Eta(), photon_directionWrtVtx.Phi(), pfc.momentum().Eta(), pfc.momentum().Phi()); + + if (dEta < etaStrip) + continue; + + if(dR > dRmax || dR < dRVeto) + continue; + + sum += pfc.pt(); + } + } + return sum; +} + +// --------------------------------------------------------------------- + +float GammaJetAnalysis::pfHcalIso(const reco::Photon* localPho,edm::Handle pfHandle,float dRmax, float dRveto,reco::PFCandidate::ParticleType pfToUse) { + if (debug_>1) LogDebug("GammaJetAnalysis") << "Inside pfHcalIso"; + return pfEcalIso(localPho, pfHandle, dRmax, dRveto, dRveto, 0.0, 0.0, 0.0, 0.0, pfToUse); + +} + +// --------------------------------------------------------------------- + +std::vector GammaJetAnalysis::pfTkIsoWithVertex(const reco::Photon* localPho1, edm::Handle pfHandle, edm::Handle vtxHandle, float dRmax, float dRvetoBarrel, float dRvetoEndcap, float ptMin, float dzMax, float dxyMax, reco::PFCandidate::ParticleType pfToUse) { + + if (debug_>1) LogDebug("GammaJetAnalysis") << "Inside pfTkIsoWithVertex()"; + reco::Photon* localPho = localPho1->clone(); + + float dRveto; + if (localPho->isEB()) + dRveto = dRvetoBarrel; + else + dRveto = dRvetoEndcap; + + std::vector result; + const reco::PFCandidateCollection* forIsolation = pfHandle.product(); + + //Calculate isolation sum separately for each vertex + if (debug_>1) LogDebug("GammaJetAnalysis") << "vtxHandle->size() = " << vtxHandle->size(); + for(unsigned int ivtx=0; ivtx<(vtxHandle->size()); ++ivtx) { + if (debug_>1) LogDebug("GammaJetAnalysis") << "Vtx " << ivtx; + // Shift the photon according to the vertex + reco::VertexRef vtx(vtxHandle, ivtx); + math::XYZVector photon_directionWrtVtx(localPho->superCluster()->x() - vtx->x(), + localPho->superCluster()->y() - vtx->y(), + localPho->superCluster()->z() - vtx->z()); + if (debug_>1) LogDebug("GammaJetAnalysis") << "pfTkIsoWithVertex :: Will Loop over the PFCandidates"; + float sum = 0; + // Loop over the PFCandidates + for(unsigned i=0; isize(); i++) { + if (debug_>1) LogDebug("GammaJetAnalysis") << "inside loop"; + const reco::PFCandidate& pfc = (*forIsolation)[i]; + + //require that PFCandidate is a charged hadron + if (debug_>1) LogDebug("GammaJetAnalysis") << "pfToUse=" << pfToUse; + if (debug_>1) LogDebug("GammaJetAnalysis") << "pfc.particleId()=" << pfc.particleId(); - jetexist = ij; - } //vet - } // number of superclusters - } catch (cms::Exception& e) { // can't find it! - if (!allowMissingInputs_) { - cout<<" Ecal barrel clusters are missed "<1) LogDebug("GammaJetAnalysis") << "\n ***** HERE pfc.particleId() == pfToUse "; + if (debug_>1) LogDebug("GammaJetAnalysis") << "pfc.pt()=" << pfc.pt(); + if (pfc.pt() < ptMin) + continue; + + float dz = fabs(pfc.trackRef()->dz(vtx->position())); + if (dz > dzMax) continue; + + float dxy = fabs(pfc.trackRef()->dxy(vtx->position())); + if(fabs(dxy) > dxyMax) continue; + float dR = deltaR(photon_directionWrtVtx.Eta(), photon_directionWrtVtx.Phi(), pfc.momentum().Eta(), pfc.momentum().Phi()); + if(dR > dRmax || dR < dRveto) continue; + sum += pfc.pt(); + if (debug_>1) LogDebug("GammaJetAnalysis") << "pt=" << pfc.pt(); + } + } + if (debug_>1) LogDebug("GammaJetAnalysis") << "sum=" << sum; + sum = sum*1.0; + result.push_back(sum); } + if (debug_>1) LogDebug("GammaJetAnalysis") << "Will return result"; + if (debug_>1) LogDebug("GammaJetAnalysis") << "result" << &result; + return result; + if (debug_>1) LogDebug("GammaJetAnalysis") << "Result returned"; +} - cout<<" After iso cuts "<Fill(); - -} // analyze method -} // namespace cms +void GammaJetAnalysis::clear_leadingPfJetVars() { + ppfjet_pt_ = ppfjet_p_ = ppfjet_E_ = 0; + ppfjet_eta_ = ppfjet_phi_ = ppfjet_scale_ = 0.; + ppfjet_area_ = ppfjet_E_NPVcorr_ = 0.; + ppfjet_NeutralHadronFrac_ = ppfjet_NeutralEMFrac_ = 0.; + ppfjet_nConstituents_ = 0; + ppfjet_ChargedHadronFrac_ = ppfjet_ChargedMultiplicity_ = 0; + ppfjet_ChargedEMFrac_ = 0.; + ppfjet_gendr_ = ppfjet_genpt_ = ppfjet_genp_ = ppfjet_genE_ = 0.; + // Reset particle variables + ppfjet_unkown_E_ = ppfjet_unkown_px_ = ppfjet_unkown_py_ = ppfjet_unkown_pz_ = ppfjet_unkown_EcalE_ = 0.0; + ppfjet_electron_E_ = ppfjet_electron_px_ = ppfjet_electron_py_ = ppfjet_electron_pz_ = ppfjet_electron_EcalE_ = 0.0; + ppfjet_muon_E_ = ppfjet_muon_px_ = ppfjet_muon_py_ = ppfjet_muon_pz_ = ppfjet_muon_EcalE_ = 0.0; + ppfjet_photon_E_ = ppfjet_photon_px_ = ppfjet_photon_py_ = ppfjet_photon_pz_ = ppfjet_photon_EcalE_ = 0.0; + ppfjet_unkown_n_ = ppfjet_electron_n_ = ppfjet_muon_n_ = ppfjet_photon_n_ = 0; + ppfjet_had_n_ = 0; + ppfjet_ntwrs_ = 0; + ppfjet_cluster_n_ = 0; + ppfjet_ncandtracks_ = 0; + + ppfjet_had_E_.clear(); + ppfjet_had_px_.clear(); + ppfjet_had_py_.clear(); + ppfjet_had_pz_.clear(); + ppfjet_had_EcalE_.clear(); + ppfjet_had_rawHcalE_.clear(); + ppfjet_had_emf_.clear(); + ppfjet_had_E_mctruth_.clear(); + ppfjet_had_id_.clear(); + ppfjet_had_candtrackind_.clear(); + ppfjet_had_mcpdgId_.clear(); + ppfjet_had_ntwrs_.clear(); + ppfjet_twr_ieta_.clear(); + ppfjet_twr_iphi_.clear(); + ppfjet_twr_depth_.clear(); + ppfjet_twr_subdet_.clear(); + ppfjet_twr_candtrackind_.clear(); + ppfjet_twr_hadind_.clear(); + ppfjet_twr_elmttype_.clear(); + ppfjet_twr_hade_.clear(); + ppfjet_twr_frac_.clear(); + ppfjet_twr_dR_.clear(); + ppfjet_twr_clusterind_.clear(); + ppfjet_cluster_eta_.clear(); + ppfjet_cluster_phi_.clear(); + ppfjet_cluster_dR_.clear(); + ppfjet_candtrack_px_.clear(); + ppfjet_candtrack_py_.clear(); + ppfjet_candtrack_pz_.clear(); + ppfjet_candtrack_EcalE_.clear(); + +} + +// --------------------------------------------------------------------- + +void GammaJetAnalysis::copy_leadingPfJetVars_to_pfJet2() { + pfjet2_pt_ = ppfjet_pt_; + pfjet2_p_ = ppfjet_p_; + pfjet2_E_ = ppfjet_E_; + pfjet2_eta_ = ppfjet_eta_; + pfjet2_phi_ = ppfjet_phi_; + pfjet2_scale_ = ppfjet_scale_; + pfjet2_area_ = ppfjet_area_; + pfjet2_E_NPVcorr_ = ppfjet_E_NPVcorr_; + pfjet2_NeutralHadronFrac_ = ppfjet_NeutralHadronFrac_; + pfjet2_NeutralEMFrac_ = ppfjet_NeutralEMFrac_; + pfjet2_nConstituents_ = ppfjet_nConstituents_; + pfjet2_ChargedHadronFrac_ = ppfjet_ChargedHadronFrac_; + pfjet2_ChargedMultiplicity_ = ppfjet_ChargedMultiplicity_; + pfjet2_ChargedEMFrac_ = ppfjet_ChargedEMFrac_; + + pfjet2_gendr_ = ppfjet_gendr_; + pfjet2_genpt_ = ppfjet_genpt_; + pfjet2_genp_ = ppfjet_genp_; + pfjet2_genE_ = ppfjet_genE_; + + pfjet2_unkown_E_ = ppfjet_unkown_E_; + pfjet2_unkown_px_ = ppfjet_unkown_px_; + pfjet2_unkown_py_ = ppfjet_unkown_py_; + pfjet2_unkown_pz_ = ppfjet_unkown_pz_; + pfjet2_unkown_EcalE_ = ppfjet_unkown_EcalE_; + + pfjet2_electron_E_ = ppfjet_electron_E_; + pfjet2_electron_px_ = ppfjet_electron_px_; + pfjet2_electron_py_ = ppfjet_electron_py_; + pfjet2_electron_pz_ = ppfjet_electron_pz_; + pfjet2_electron_EcalE_ = ppfjet_electron_EcalE_; + + pfjet2_muon_E_ = ppfjet_muon_E_; + pfjet2_muon_px_ = ppfjet_muon_px_; + pfjet2_muon_py_ = ppfjet_muon_py_; + pfjet2_muon_pz_ = ppfjet_muon_pz_; + pfjet2_muon_EcalE_ = ppfjet_muon_EcalE_; + + pfjet2_photon_E_ = ppfjet_photon_E_; + pfjet2_photon_px_ = ppfjet_photon_px_; + pfjet2_photon_py_ = ppfjet_photon_py_; + pfjet2_photon_pz_ = ppfjet_photon_pz_; + pfjet2_photon_EcalE_ = ppfjet_photon_EcalE_; + + pfjet2_unkown_n_ = ppfjet_unkown_n_; + pfjet2_electron_n_ = ppfjet_electron_n_; + pfjet2_muon_n_ = ppfjet_muon_n_; + pfjet2_photon_n_ = ppfjet_photon_n_; + pfjet2_had_n_ = ppfjet_had_n_; + + pfjet2_had_E_ = ppfjet_had_E_; + pfjet2_had_px_ = ppfjet_had_px_; + pfjet2_had_py_ = ppfjet_had_py_; + pfjet2_had_pz_ = ppfjet_had_pz_; + pfjet2_had_EcalE_ = ppfjet_had_EcalE_; + pfjet2_had_rawHcalE_ = ppfjet_had_rawHcalE_; + pfjet2_had_emf_ = ppfjet_had_emf_; + pfjet2_had_E_mctruth_ = ppfjet_had_E_mctruth_; + + pfjet2_had_id_ = ppfjet_had_id_; + pfjet2_had_candtrackind_ = ppfjet_had_candtrackind_; + pfjet2_had_mcpdgId_ = ppfjet_had_mcpdgId_; + pfjet2_had_ntwrs_ = ppfjet_had_ntwrs_; + + pfjet2_ntwrs_ = ppfjet_ntwrs_; + pfjet2_twr_ieta_ = ppfjet_twr_ieta_; + pfjet2_twr_iphi_ = ppfjet_twr_iphi_; + pfjet2_twr_depth_ = ppfjet_twr_depth_; + pfjet2_twr_subdet_ = ppfjet_twr_subdet_; + pfjet2_twr_candtrackind_ = ppfjet_twr_candtrackind_; + pfjet2_twr_hadind_ = ppfjet_twr_hadind_; + pfjet2_twr_elmttype_ = ppfjet_twr_elmttype_; + pfjet2_twr_clusterind_ = ppfjet_twr_clusterind_; + + pfjet2_twr_hade_ = ppfjet_twr_hade_; + pfjet2_twr_frac_ = ppfjet_twr_frac_; + pfjet2_twr_dR_ = ppfjet_twr_dR_; + + pfjet2_cluster_n_ = ppfjet_cluster_n_; + pfjet2_cluster_eta_ = ppfjet_cluster_eta_; + pfjet2_cluster_phi_ = ppfjet_cluster_phi_; + pfjet2_cluster_dR_ = ppfjet_cluster_dR_; + + pfjet2_ncandtracks_ = ppfjet_ncandtracks_; + pfjet2_candtrack_px_ = ppfjet_candtrack_px_; + pfjet2_candtrack_py_ = ppfjet_candtrack_py_; + pfjet2_candtrack_pz_ = ppfjet_candtrack_pz_; + pfjet2_candtrack_EcalE_ = ppfjet_candtrack_EcalE_; +} + +// --------------------------------------------------------------------- + +double GammaJetAnalysis::deltaR(const reco::Jet* j1, const reco::Jet* j2) +{ + double deta = j1->eta()-j2->eta(); + double dphi = std::fabs(j1->phi()-j2->phi()); + if(dphi>3.1415927) dphi = 2*3.1415927 - dphi; + return std::sqrt(deta*deta + dphi*dphi); +} + +// --------------------------------------------------------------------- + +double GammaJetAnalysis::deltaR(const double eta1, const double phi1, const double eta2, const double phi2) +{ + double deta = eta1 - eta2; + double dphi = std::fabs(phi1 - phi2); + if(dphi>3.1415927) dphi = 2*3.1415927 - dphi; + return std::sqrt(deta*deta + dphi*dphi); +} + +// --------------------------------------------------------------------- + +/* +// DetId rawId bits xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx +// 1111222 3333345555556666666 +// 1 = detector +// 2 = subdetector +// 3 = depth +// 4 = zside: 0 = negative z, 1 = positive z \ +// 5 = abs(ieta) | ieta,iphi +// 6 = abs(iphi) / +*/ + +// --------------------------------------------------------------------- + +int GammaJetAnalysis::getEtaPhi(const DetId id) +{ + return id.rawId() & 0x3FFF; // Get 14 least-significant digits +} + +// --------------------------------------------------------------------- + +int GammaJetAnalysis::getEtaPhi(const HcalDetId id) +{ + return id.rawId() & 0x3FFF; // Get 14 least-significant digits +} + +// --------------------------------------------------------------------- + + +//define this as a plug-in + +DEFINE_FWK_MODULE(GammaJetAnalysis); diff --git a/Calibration/HcalCalibAlgos/src/GammaJetAnalysis.h b/Calibration/HcalCalibAlgos/src/GammaJetAnalysis.h index e644c946a5531..7e724879bd315 100644 --- a/Calibration/HcalCalibAlgos/src/GammaJetAnalysis.h +++ b/Calibration/HcalCalibAlgos/src/GammaJetAnalysis.h @@ -1,115 +1,325 @@ -#ifndef GammaJetAnalysis_h -#define GammaJetAnalysis_h +#ifndef Calibration_HcalCalibAlgos_GammaJetAnalysis_H_ +#define Calibration_HcalCalibAlgos_GammaJetAnalysis_H_ + // system include files #include #include -#include -#include // user include files -// #include "FWCore/Framework/interface/Frameworkfwd.h" +#include "FWCore/Framework/interface/Frameworkfwd.h" #include "FWCore/Framework/interface/EDAnalyzer.h" + +#include "FWCore/Framework/interface/Event.h" +#include "FWCore/Framework/interface/EventSetup.h" +#include "FWCore/Framework/interface/MakerMacros.h" +#include "FWCore/Framework/interface/ESHandle.h" #include "FWCore/ParameterSet/interface/ParameterSet.h" -/* #include "FWCore/Framework/interface/Event.h" */ -/* #include "FWCore/Framework/interface/MakerMacros.h" */ -/* #include "FWCore/Framework/interface/ESHandle.h" */ -/* #include "FWCore/Framework/interface/EventSetup.h" */ -/* #include "FWCore/ParameterSet/interface/ParameterSet.h" */ - -/* #include "DataFormats/Common/interface/Ref.h" */ -/* #include "DataFormats/DetId/interface/DetId.h" */ - -/* #include "Geometry/Records/interface/IdealGeometryRecord.h" */ -/* #include "Geometry/CaloGeometry/interface/CaloGeometry.h" */ -/* #include "Geometry/Vector/interface/GlobalPoint.h" */ -/* #include "DataFormats/CaloTowers/interface/CaloTowerCollection.h" */ -/* #include "DataFormats/CaloTowers/interface/CaloTowerDetId.h" */ - #include "DataFormats/HcalRecHit/interface/HcalRecHitCollections.h" -#include "DataFormats/EcalRecHit/interface/EcalRecHitCollections.h" -#include "DataFormats/JetReco/interface/CaloJetCollection.h" -/* #include "DataFormats/JetReco/interface/CaloJet.h" */ -#include "DataFormats/EgammaReco/interface/SuperClusterFwd.h" - -#include - - -namespace edm { - class ParameterSet; - class Event; - class EventSetup; -} +#include "DataFormats/EgammaCandidates/interface/PhotonFwd.h" +#include "DataFormats/EgammaCandidates/interface/Photon.h" +#include "DataFormats/JetReco/interface/CaloJetCollection.h" +#include "DataFormats/JetReco/interface/GenJetCollection.h" +#include "DataFormats/JetReco/interface/PFJetCollection.h" +#include "DataFormats/HcalRecHit/interface/HBHERecHit.h" +#include "DataFormats/HcalRecHit/interface/HFRecHit.h" +#include "DataFormats/HcalRecHit/interface/HORecHit.h" +#include "DataFormats/METReco/interface/METCollection.h" +#include "DataFormats/METReco/interface/PFMET.h" +#include "DataFormats/METReco/interface/PFMETCollection.h" +#include "DataFormats/ParticleFlowReco/interface/PFBlockFwd.h" +#include "DataFormats/ParticleFlowReco/interface/PFBlock.h" +#include "DataFormats/ParticleFlowCandidate/interface/PFCandidate.h" +#include "DataFormats/ParticleFlowReco/interface/PFCluster.h" +#include "DataFormats/ParticleFlowReco/interface/PFRecHit.h" +#include "DataFormats/ParticleFlowReco/interface/PFRecHitFwd.h" +#include "DataFormats/HcalDetId/interface/HcalDetId.h" +#include "DataFormats/TrackReco/interface/TrackFwd.h" +#include "DataFormats/TrackReco/interface/Track.h" +#include "DataFormats/TrackReco/interface/TrackExtra.h" +#include "DataFormats/Common/interface/TriggerResults.h" +#include "DataFormats/HLTReco/interface/TriggerEvent.h" +#include "DataFormats/HLTReco/interface/TriggerObject.h" + +#include "Geometry/CaloGeometry/interface/CaloGeometry.h" +#include "Geometry/CaloGeometry/interface/CaloSubdetectorGeometry.h" +#include "Geometry/Records/interface/CaloGeometryRecord.h" +#include "DataFormats/HepMCCandidate/interface/GenParticle.h" +#include "SimDataFormats/GeneratorProducts/interface/GenEventInfoProduct.h" +#include "DataFormats/VertexReco/interface/Vertex.h" +#include "DataFormats/VertexReco/interface/VertexFwd.h" +#include "DataFormats/ParticleFlowCandidate/interface/PFCandidate.h" +#include "DataFormats/ParticleFlowCandidate/interface/PFCandidateFwd.h" +#include "HLTrigger/HLTcore/interface/HLTConfigProvider.h" + +// forward declarations +class TH1D; +class TH2D; class TFile; class TTree; -class CaloGeometry; // -// class decleration +// class declarations // -namespace cms -{ + +class PhotonPair : protected std::pair { + +public: + PhotonPair() { + first=0; + second=0.0; + fIdx=-1; + } + PhotonPair(const reco::Photon* ph, double pt, int setIdx=-1) { + first=ph; + second=pt; + fIdx=setIdx; + } + ~PhotonPair() {} + + inline const reco::Photon* photon(void) const { return first; } + inline void photon(const reco::Photon* ph) { first=ph; return; } + inline double pt(void) const { return second; } + inline void pt(double d) { second=d; return; } + void idx(int set_idx) { fIdx=set_idx; }; + int idx() const { return fIdx; } + bool isValid() const { return (first!=NULL) ? true:false; } + +private: + int fIdx; // index in the photon collection +}; + +class PFJetCorretPair : protected std::pair { +public: + PFJetCorretPair() { + first=0; + second=1.0; + } + PFJetCorretPair(const reco::PFJet* j, double s) { + first=j; + second=s; + } + ~PFJetCorretPair() {} + + inline const reco::PFJet* jet(void) const { return first; } + inline void jet(const reco::PFJet* j) { first=j; return; } + inline double scale(void) const { return second; } + inline void scale(double d) { second=d; return; } + double scaledEt() const { return first->et() * second; } + bool isValid() const { return (first!=NULL) ? true:false; } + +private: + +}; + +// -------------------------------------------- +// Main class +// -------------------------------------------- + class GammaJetAnalysis : public edm::EDAnalyzer { - public: - explicit GammaJetAnalysis(const edm::ParameterSet&); - ~GammaJetAnalysis(); - - virtual void analyze(const edm::Event&, const edm::EventSetup&); - virtual void beginJob() ; - virtual void endJob() ; - - private: - // ----------member data --------------------------- - // names of modules, producing object collections - - std::string nameProd_; - std::string jetCalo_; - std::string gammaClus_; - std::string ecalInput_; - std::string hbheInput_; - std::string hoInput_; - std::string hfInput_; - std::string Tracks_; - std::string myName; - double CutOnEgammaEnergy_; - - edm::EDGetTokenT tok_jets_; - edm::EDGetTokenT tok_egamma_; - edm::EDGetTokenT tok_ecal_; - edm::EDGetTokenT tok_hbhe_; - edm::EDGetTokenT tok_ho_; - edm::EDGetTokenT tok_hf_; - - // stuff for histogramms - // output file name with histograms - std::string fOutputFileName ; - bool allowMissingInputs_; - bool useMC; - // - TFile* hOutputFile ; - TTree * myTree; - std::ofstream *myout_part; - std::ofstream *myout_hcal; - std::ofstream *myout_ecal; - std::ofstream *myout_jet; - std::ofstream *myout_photon; - // - int NumRecoJets,NumGenJets,NumRecoGamma,NumRecoTrack,NumRecoHcal,NumPart; - int run,event; - float JetRecoEt[10],JetRecoEta[10],JetRecoPhi[10],JetRecoType[10]; - float JetGenEt[10],JetGenEta[10],JetGenPhi[10],JetGenType[10]; - float TrackRecoEt[10],TrackRecoEta[10],TrackRecoPhi[10]; - int EcalClusDet[20]; - float GammaRecoEt[20],GammaRecoEta[20],GammaRecoPhi[20],GammaIsoEcal[9][20],GammaIsoHcal[9][20]; - float HcalDet[8000],HcalRecoEt[8000],HcalRecoEta[8000],HcalRecoPhi[8000]; - int Status[4000],Code[4000],Mother1[4000]; - float partpx[4000],partpy[4000],partpz[4000],parte[4000],partm[4000],partvx[4000]; - float partvy[4000],partvz[4000],partvt[4000]; - float risol[3]; - float ecut[3][3]; - -// Calo geometry - const CaloGeometry* geo; +public: + explicit GammaJetAnalysis(const edm::ParameterSet&); + ~GammaJetAnalysis(); + + float pfEcalIso(const reco::Photon* localPho1, edm::Handle pfHandle, float dRmax, float dRVetoBarrel, float dRVetoEndcap, float etaStripBarrel, float etaStripEndcap, float energyBarrel, float energyEndcap, reco::PFCandidate::ParticleType pfToUse); + + float pfHcalIso(const reco::Photon* localPho,edm::Handle pfHandle,float dRmax, float dRveto,reco::PFCandidate::ParticleType pfToUse); + + std::vector pfTkIsoWithVertex(const reco::Photon* localPho1, edm::Handle pfHandle, edm::Handle vtxHandle, float dRmax, float dRvetoBarrel, float dRvetoEndcap, float ptMin, float dzMax, float dxyMax, reco::PFCandidate::ParticleType pfToUse); + +private: + virtual void beginJob();//(const edm::EventSetup&); + virtual void analyze(const edm::Event&, const edm::EventSetup&); + virtual void endJob(); + void beginRun(const edm::Run&, const edm::EventSetup&); + + + // parameters + int debug_; // print debug statements + unsigned int debugEvent; + int debugHLTTrigNames; + + edm::InputTag rhoCollection_; + edm::InputTag pfType1METColl, pfMETColl ; + + std::string photonCollName_; // label for the photon collection + std::string pfJetCollName_; // label for the PF jet collection + std::string pfJetCorrName_; // label for the PF jet correction service + std::string genJetCollName_; // label for the genjet collection + std::string genParticleCollName_; // label for the genparticle collection + std::string genEventInfoName_; // label for the generator event info collection + std::string hbheRecHitName_; // label for HBHERecHits collection + std::string hfRecHitName_; // label for HFRecHit collection + std::string hoRecHitName_; // label for HORecHit collection + std::string rootHistFilename_; // name of the histogram file + std::string pvCollName_; // label for primary vertex collection + std::string prodProcess_; // the producer process for AOD=2 + + bool allowNoPhoton_; // whether module is used for dijet analysis + double photonPtMin_; // lowest value of the leading photon pT + double photonJetDPhiMin_; // phi angle between the leading photon and the leading jet + double jetEtMin_; // lowest value of the leading jet ET + double jet2EtMax_; // largest value of the subleading jet ET + double jet3EtMax_; // largest value of the third jet ET + std::vector photonTrigNamesV_; // photon trigger names + std::vector jetTrigNamesV_; // jet trigger names + bool writeTriggerPrescale_; // whether attempt to record the prescale + + //Tokens + edm::EDGetTokenT tok_Photon_; + edm::EDGetTokenT tok_PFJet_; + edm::EDGetTokenT > tok_GenJet_; + edm::EDGetTokenT > tok_GenPart_; + edm::EDGetTokenT tok_GenEvInfo_; + edm::EDGetTokenT > > tok_HBHE_; + edm::EDGetTokenT > > tok_HF_; + edm::EDGetTokenT > > tok_HO_; + edm::EDGetTokenT > tok_loosePhoton_; + edm::EDGetTokenT > tok_tightPhoton_; + edm::EDGetTokenT > tok_loosePhotonV_; + edm::EDGetTokenT > tok_tightPhotonV_; + edm::EDGetTokenT tok_PFCand_; + edm::EDGetTokenT tok_Vertex_; + edm::EDGetTokenT tok_GsfElec_; + edm::EDGetTokenT tok_Rho_; + edm::EDGetTokenT tok_Conv_; + edm::EDGetTokenT tok_BS_; + edm::EDGetTokenT > tok_PV_; + edm::EDGetTokenT tok_PFMET_; + edm::EDGetTokenT tok_PFType1MET_; + edm::EDGetTokenT tok_TrigRes_; + bool doPFJets_; // use PFJets + bool doGenJets_; // use GenJets + int workOnAOD_; + bool ignoreHLT_; + + // root file/histograms + TFile* rootfile_; + + TTree* misc_tree_; // misc.information. Will be filled only once + TTree* calo_tree_; + TTree* pf_tree_; + + // trigger info + HLTConfigProvider hltConfig_; // variable for the access + std::vector photonTrigFired_; + std::vector photonTrigPrescale_; + std::vector jetTrigFired_; + std::vector jetTrigPrescale_; + + // Event info + int runNumber_, lumiBlock_, eventNumber_; + float eventWeight_, eventPtHat_; + int nPhotons_, nGenJets_; + int nPFJets_; + ULong64_t nProcessed_; + int pf_NPV_; + + /// MET info + float met_value_, met_phi_, met_sumEt_ ; + float metType1_value_, metType1_phi_, metType1_sumEt_ ; + + // photon info + float rho2012_; + float tagPho_pt_, pho_2nd_pt_, tagPho_energy_, tagPho_eta_, tagPho_phi_, tagPho_sieie_; + float tagPho_HoE_, tagPho_r9_, tagPho_EcalIsoDR04_, tagPho_HcalIsoDR04_, tagPho_HcalIsoDR0412_, tagPho_TrkIsoHollowDR04_, tagPho_pfiso_myphoton03_; + float tagPho_pfiso_myneutral03_; + std::vector > tagPho_pfiso_mycharged03 ; + int tagPho_pixelSeed_; + int tagPho_ConvSafeEleVeto_; + int tagPho_idTight_, tagPho_idLoose_; + float tagPho_genPt_, tagPho_genEnergy_, tagPho_genEta_, tagPho_genPhi_; + float tagPho_genDeltaR_; + + // Particle-flow jets + // leading Et jet info + float ppfjet_pt_, ppfjet_p_, ppfjet_E_, ppfjet_eta_, ppfjet_phi_, ppfjet_scale_; + float ppfjet_area_, ppfjet_E_NPVcorr_; + float ppfjet_NeutralHadronFrac_, ppfjet_NeutralEMFrac_; + int ppfjet_nConstituents_; + float ppfjet_ChargedHadronFrac_, ppfjet_ChargedMultiplicity_, ppfjet_ChargedEMFrac_; + float ppfjet_gendr_, ppfjet_genpt_, ppfjet_genp_, ppfjet_genE_; + float ppfjet_unkown_E_, ppfjet_unkown_px_, ppfjet_unkown_py_, ppfjet_unkown_pz_, ppfjet_unkown_EcalE_; + float ppfjet_electron_E_, ppfjet_electron_px_, ppfjet_electron_py_, ppfjet_electron_pz_, ppfjet_electron_EcalE_; + float ppfjet_muon_E_, ppfjet_muon_px_, ppfjet_muon_py_, ppfjet_muon_pz_, ppfjet_muon_EcalE_; + float ppfjet_photon_E_, ppfjet_photon_px_, ppfjet_photon_py_, ppfjet_photon_pz_, ppfjet_photon_EcalE_; + int ppfjet_unkown_n_, ppfjet_electron_n_, ppfjet_muon_n_, ppfjet_photon_n_; + int ppfjet_had_n_; + std::vector ppfjet_had_E_, ppfjet_had_px_, ppfjet_had_py_, ppfjet_had_pz_, ppfjet_had_EcalE_, ppfjet_had_rawHcalE_, ppfjet_had_emf_, ppfjet_had_E_mctruth_; + std::vector ppfjet_had_id_, ppfjet_had_candtrackind_, ppfjet_had_mcpdgId_, ppfjet_had_ntwrs_; + int ppfjet_ntwrs_; + std::vector ppfjet_twr_ieta_, ppfjet_twr_iphi_, ppfjet_twr_depth_, ppfjet_twr_subdet_, ppfjet_twr_candtrackind_, ppfjet_twr_hadind_, ppfjet_twr_elmttype_, ppfjet_twr_clusterind_; + std::vector ppfjet_twr_hade_, ppfjet_twr_frac_, ppfjet_twr_dR_; + int ppfjet_cluster_n_; + std::vector ppfjet_cluster_eta_, ppfjet_cluster_phi_, ppfjet_cluster_dR_; + int ppfjet_ncandtracks_; + std::vector ppfjet_candtrack_px_, ppfjet_candtrack_py_, ppfjet_candtrack_pz_, ppfjet_candtrack_EcalE_; + + // subleading Et jet info + float pfjet2_pt_, pfjet2_p_, pfjet2_E_, pfjet2_eta_, pfjet2_phi_, pfjet2_scale_; + float pfjet2_area_, pfjet2_E_NPVcorr_; + float pfjet2_NeutralHadronFrac_, pfjet2_NeutralEMFrac_; + int pfjet2_nConstituents_; + float pfjet2_ChargedHadronFrac_, pfjet2_ChargedMultiplicity_, pfjet2_ChargedEMFrac_; + float pfjet2_gendr_, pfjet2_genpt_, pfjet2_genp_, pfjet2_genE_; + float pfjet2_unkown_E_, pfjet2_unkown_px_, pfjet2_unkown_py_, pfjet2_unkown_pz_, pfjet2_unkown_EcalE_; + float pfjet2_electron_E_, pfjet2_electron_px_, pfjet2_electron_py_, pfjet2_electron_pz_, pfjet2_electron_EcalE_; + float pfjet2_muon_E_, pfjet2_muon_px_, pfjet2_muon_py_, pfjet2_muon_pz_, pfjet2_muon_EcalE_; + float pfjet2_photon_E_, pfjet2_photon_px_, pfjet2_photon_py_, pfjet2_photon_pz_, pfjet2_photon_EcalE_; + int pfjet2_unkown_n_, pfjet2_electron_n_, pfjet2_muon_n_, pfjet2_photon_n_; + int pfjet2_had_n_; + std::vector pfjet2_had_E_, pfjet2_had_px_, pfjet2_had_py_, pfjet2_had_pz_, pfjet2_had_EcalE_, pfjet2_had_rawHcalE_, pfjet2_had_emf_, pfjet2_had_E_mctruth_; + std::vector pfjet2_had_id_, pfjet2_had_candtrackind_, pfjet2_had_mcpdgId_, pfjet2_had_ntwrs_; + int pfjet2_ntwrs_; + std::vector pfjet2_twr_ieta_, pfjet2_twr_iphi_, pfjet2_twr_depth_, pfjet2_twr_subdet_, pfjet2_twr_candtrackind_, pfjet2_twr_hadind_, pfjet2_twr_elmttype_, pfjet2_twr_clusterind_; + std::vector pfjet2_twr_hade_, pfjet2_twr_frac_, pfjet2_twr_dR_; + int pfjet2_cluster_n_; + std::vector pfjet2_cluster_eta_, pfjet2_cluster_phi_, pfjet2_cluster_dR_; + int pfjet2_ncandtracks_; + std::vector pfjet2_candtrack_px_, pfjet2_candtrack_py_, pfjet2_candtrack_pz_, pfjet2_candtrack_EcalE_; + + float pf_thirdjet_et_; + float pf_thirdjet_pt_, pf_thirdjet_p_, pf_thirdjet_px_, pf_thirdjet_py_; + float pf_thirdjet_E_, pf_thirdjet_eta_, pf_thirdjet_phi_, pf_thirdjet_scale_; + + // helper functions + template + float calc_dPhi(const PhotonPair &pho, const JetPair_type &jet) { + if (!pho.isValid() || !jet.isValid()) return 9999.; + float phi1=pho.photon()->phi(); + float phi2=jet.jet()->phi(); + float dphi=fabs(phi1-phi2); + const float cPi= 4*atan(1); + while (dphi>cPi) dphi = fabs(2*cPi - dphi); + return dphi; + } + + double deltaR(const reco::Jet* j1, const reco::Jet* j2); + double deltaR(const double eta1, const double phi1, const double eta2, const double phi2); + int getEtaPhi(const DetId id); + int getEtaPhi(const HcalDetId id); + + void clear_leadingPfJetVars(); + void copy_leadingPfJetVars_to_pfJet2(); + + template + double deltaR(const PhotonPair &photon, const Jet_type *jet) { + if (!photon.isValid()) return 9999.; + return deltaR(photon.photon()->eta(),photon.photon()->phi(), + jet->eta(), jet->phi()); + } + + struct PFJetCorretPairComp { + inline bool operator() ( const PFJetCorretPair& a, const PFJetCorretPair& b) { + return (a.jet()->pt()*a.scale()) > (b.jet()->pt()*b.scale()); + } + }; + + struct PhotonPairComp { + inline bool operator() ( const PhotonPair& a, const PhotonPair& b) { + return ( (a.photon()->pt()) > (b.photon()->pt()) ); + } + }; }; -} + #endif diff --git a/Calibration/HcalCalibAlgos/src/HcalHBHEMuonAnalyzer.cc b/Calibration/HcalCalibAlgos/src/HcalHBHEMuonAnalyzer.cc new file mode 100644 index 0000000000000..af520f5ec1a93 --- /dev/null +++ b/Calibration/HcalCalibAlgos/src/HcalHBHEMuonAnalyzer.cc @@ -0,0 +1,763 @@ +#include +#include +#include +#include +#include +#include "TPRegexp.h" + +// user include files +#include "FWCore/Framework/interface/Frameworkfwd.h" +#include "FWCore/Framework/interface/EDAnalyzer.h" +#include "FWCore/Framework/interface/Event.h" +#include "FWCore/MessageLogger/interface/MessageLogger.h" +#include "FWCore/ParameterSet/interface/ParameterSet.h" +#include "FWCore/ParameterSet/interface/ConfigurationDescriptions.h" +#include "FWCore/ServiceRegistry/interface/Service.h" +#include "FWCore/Common/interface/TriggerNames.h" +#include "CommonTools/UtilAlgos/interface/TFileService.h" + +#include "DataFormats/HcalDetId/interface/HcalDetId.h" +#include "DataFormats/MuonReco/interface/Muon.h" +#include "DataFormats/MuonReco/interface/MuonFwd.h" +#include "DataFormats/VertexReco/interface/Vertex.h" +#include "DataFormats/VertexReco/interface/VertexFwd.h" +#include "DataFormats/TrackReco/interface/Track.h" + +//////////////trigger info//////////////////////////////////// + +#include "DataFormats/Common/interface/TriggerResults.h" +#include "DataFormats/HLTReco/interface/TriggerObject.h" +#include "DataFormats/HLTReco/interface/TriggerEvent.h" +#include "DataFormats/EcalDetId/interface/EcalSubdetector.h" +#include "DataFormats/EcalDetId/interface/EBDetId.h" +#include "DataFormats/EcalDetId/interface/EEDetId.h" +#include "DataFormats/HcalDetId/interface/HcalDetId.h" +#include "DataFormats/EcalRecHit/interface/EcalRecHitCollections.h" +#include "DataFormats/HcalRecHit/interface/HcalRecHitCollections.h" + +#include "HLTrigger/HLTcore/interface/HLTConfigProvider.h" +#include "HLTrigger/HLTcore/interface/HLTConfigData.h" + +#include "CondFormats/DataRecord/interface/EcalChannelStatusRcd.h" +#include "RecoLocalCalo/EcalRecAlgos/interface/EcalSeverityLevelAlgo.h" +#include "RecoLocalCalo/EcalRecAlgos/interface/EcalSeverityLevelAlgoRcd.h" + +#include "Calibration/IsolatedParticles/interface/CaloPropagateTrack.h" +#include "Calibration/IsolatedParticles/interface/eECALMatrix.h" +#include "Calibration/IsolatedParticles/interface/eHCALMatrix.h" + +#include "Geometry/CaloGeometry/interface/CaloGeometry.h" +#include "Geometry/Records/interface/CaloGeometryRecord.h" +#include "Geometry/CaloGeometry/interface/CaloSubdetectorGeometry.h" +#include "Geometry/CaloEventSetup/interface/CaloTopologyRecord.h" +#include "Geometry/CaloTopology/interface/CaloSubdetectorTopology.h" +#include "Geometry/CaloTopology/interface/HcalTopology.h" +#include "Geometry/CaloTopology/interface/CaloTopology.h" +#include "MagneticField/Engine/interface/MagneticField.h" +#include "MagneticField/Records/interface/IdealMagneticFieldRecord.h" + +class HcalDDDRecConstantsTemp { + +public: + + HcalDDDRecConstantsTemp(); + ~HcalDDDRecConstantsTemp(); + + struct HcalActiveLength { + int ieta, depth; + double eta, thick; + HcalActiveLength(int ie=0, int d=0, double et=0, + double t=0) : ieta(ie), depth(d), eta(et), thick(t) {} + }; + + std::vector getThickActive(const int type) const; + +private: + + std::vector actHB, actHE; +}; + + +HcalDDDRecConstantsTemp::HcalDDDRecConstantsTemp() { + int ietaHB[18] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, + 11, 12, 13, 14, 15, 15, 16, 16}; + int depthHB[18] = {1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 2, 1, 2}; + double etaHB[18] = {0.0435, 0.1305, 0.2175, 0.3045, 0.3915, 0.4785, + 0.5655, 0.6525, 0.7395, 0.8265, 0.9135, 1.0005, + 1.0875, 1.1745, 1.2615, 1.2615, 1.3485, 1.3485}; + double actLHB[18]= {7.35696, 7.41268, 7.52454, 7.69339, 7.92051, 8.20761, + 8.55688, 8.97096, 9.45298, 10.0066, 10.6360, 11.3460, + 12.1419, 13.0297, 10.1832, 3.83301, 2.61066, 5.32410}; + actHB.clear(); + for (int i=0; i<18; ++i) { + HcalDDDRecConstantsTemp::HcalActiveLength act(ietaHB[i],depthHB[i],etaHB[i],actLHB[i]); + actHB.push_back(act); + } + + int ietaHE[28] = {16, 17, 18, 18, 19, 19, 20, 20, 21, 21, + 22, 22, 23, 23, 24, 24, 25, 25, 26, 26, + 27, 27, 27, 28, 28, 28, 29, 29}; + int depthHE[28] = {3, 1, 1, 2, 1, 2, 1, 2, 1, 2, + 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, + 1, 2, 3, 1, 2, 3, 1, 2}; + double etaHE[28] = {1.3485, 1.4355, 1.5225, 1.5225, 1.6095, 1.6095, 1.6965, + 1.6965, 1.7850, 1.7850, 1.8800, 1.8800, 1.9865, 1.9865, + 2.1075, 2.1075, 2.2470, 2.2470, 2.4110, 2.4110, 2.5750, + 2.5750, 2.5750, 2.7590, 2.7590, 2.8250, 2.9340, 2.9340}; + double actLHE[28]= {4.23487, 8.05342, 2.21090, 5.69774, 2.57831, 5.21078, + 2.54554, 5.14455, 2.51790, 5.08871, 2.49347, 5.03933, + 2.47129, 4.99449, 2.45137, 4.95424, 2.43380, 4.91873, + 2.41863, 4.88808, 1.65913, 0.74863, 4.86612, 1.65322, + 0.74596, 4.84396, 1.64930, 0.744198}; + actHE.clear(); + for (int i=0; i<28; ++i) { + HcalDDDRecConstantsTemp::HcalActiveLength act(ietaHE[i],depthHE[i],etaHE[i],actLHE[i]); + actHE.push_back(act); + } +} + +HcalDDDRecConstantsTemp::~HcalDDDRecConstantsTemp() { + std::cout << "HcalDDDRecConstantsTemp::destructed!!!" << std::endl; +} + +std::vector +HcalDDDRecConstantsTemp::getThickActive(const int type) const { + + if (type == 0) return actHB; + else return actHE; +} + +class HcalHBHEMuonAnalyzer : public edm::EDAnalyzer { + +public: + explicit HcalHBHEMuonAnalyzer(const edm::ParameterSet&); + ~HcalHBHEMuonAnalyzer(); + + static void fillDescriptions(edm::ConfigurationDescriptions& descriptions); + +private: + virtual void beginJob() ; + virtual void analyze(const edm::Event&, const edm::EventSetup& ); + virtual void endJob() ; + virtual void beginRun(edm::Run const&, edm::EventSetup const&); + virtual void endRun(edm::Run const&, edm::EventSetup const&); + virtual void beginLuminosityBlock(edm::LuminosityBlock const&, edm::EventSetup const&); + virtual void endLuminosityBlock(edm::LuminosityBlock const&, edm::EventSetup const&); + void clearVectors(); + int matchId(const HcalDetId&, const HcalDetId&); + double activeLength(const DetId&); + bool isGoodVertex(const reco::Vertex& vtx); + // ----------member data --------------------------- + HLTConfigProvider hltConfig_; + edm::Service fs; + edm::InputTag HLTriggerResults_, labelBS_, labelVtx_, labelEBRecHit_; + edm::InputTag labelEERecHit_, labelHBHERecHit_, labelMuon_; + int verbosity_, maxDepth_; + + edm::EDGetTokenT tok_trigRes_; + edm::EDGetTokenT tok_BS_; + edm::EDGetTokenT tok_Vtx_; + edm::EDGetTokenT tok_EB_; + edm::EDGetTokenT tok_EE_; + edm::EDGetTokenT tok_HBHE_; + edm::EDGetTokenT tok_Muon_; + + ////////////////////////////////////////////////////// + std::vector PtGlob ,track_cosmic_positionIX ,track_cosmic_positionIY , track_cosmic_positionIZ, track_cosmic_positionOX, track_cosmic_positionOY, track_cosmic_positionOZ; + + std::vector track_cosmic_momentumOX,track_cosmic_momentumOY,track_cosmic_momentumOZ,track_cosmic_momentumIX,track_cosmic_momentumIY,track_cosmic_momentumIZ, track_cosmic_detIDinner, track_cosmic_detIDouter; + std::vector EtaGlob; + std::vector PhiGlob,chiGlobal,GlobalMuonHits,MatchedStat,GlobalTrckPt,GlobalTrckEta,GlobalTrckPhi; + std::vector TrackerLayer,innerTrackpt,innerTracketa,innerTrackphi; + std::vector NumPixelLayers,chiTracker,DxyTracker,DzTracker; + std::vector OuterTrackPt,OuterTrackEta,OuterTrackPhi,OuterTrackChi,OuterTrackHits,OuterTrackRHits; + std::vector trackerlayer_hits,No_pixelLayers,NormChi2,ImpactParameter; + std::vector Tight_GlobalMuonTrkFit,Tight_MuonHits,Tight_MatchedStations,Tight_LongPara,Tight_PixelHits,Tight_TrkerLayers,Tight_TransImpara,High_TrackLayers; + std::vector innerTrack, OuterTrack, GlobalTrack; + std::vector IsolationR04,IsolationR03; + std::vector Energy,MuonHcalEnergy,MuonEcalEnergy,MuonHOEnergy,MuonEcal3x3Energy,MuonHcal1x1Energy, Pmuon; + std::vector MuonEcalDetId,MuonHcalDetId,MuonEHcalDetId, MuonHcalHot; + std::vector MuonHcalDepth1Energy,MuonHcalDepth2Energy,MuonHcalDepth3Energy,MuonHcalDepth4Energy,MuonHcalDepth5Energy,MuonHcalDepth6Energy,MuonHcalDepth7Energy; + std::vector MuonHcalDepth1HotEnergy,MuonHcalDepth2HotEnergy,MuonHcalDepth3HotEnergy,MuonHcalDepth4HotEnergy,MuonHcalDepth5HotEnergy,MuonHcalDepth6HotEnergy,MuonHcalDepth7HotEnergy; + std::vector MuonHcalActiveLength; + std::vector actHB , actHE; + int type; + + std::string hltlabel_; + std::vector all_triggers,all_triggers1,all_triggers2,all_triggers3,all_triggers4,all_triggers5; + //////////////////////////////////////////////////////////// + + std::vector isHB, isHE; + TTree *TREE; + std::vector all_ifTriggerpassed; + std::vector muon_is_good, muon_global, muon_tracker, Trk_match_MuStat; + std::vector hltresults; + std::vector hltpaths,TrigName_; + std::vector v_RH_h3x3_ieta; + std::vector v_RH_h3x3_iphi; + std::vector v_RH_h3x3_ene, PxGlob, PyGlob,PzGlob,Pthetha; + std::vector PCharge,PChi2,PD0, PD0Error,dxyWithBS,dzWithBS,PdxyTrack, PdzTrack,PNormalizedChi2, PNDoF, PValidHits, PLostHits, NPvx, NPvy, NPvz, NQOverP, NQOverPError, NTrkMomentum, NRefPointX, NRefPointY, NRefPointZ; + std::vector NTrkQuality; + double h3x3; + unsigned int RunNumber, EventNumber , LumiNumber, BXNumber; + double _RecoMuon1TrackIsoSumPtMaxCutValue_03, _RecoMuon1TrackIsoSumPtMaxCutValue_04; + int ntriggers; + std::string theTrackQuality; + edm::InputTag muonsrc_; + std::vector track_cosmic_xposition , track_cosmic_yposition, track_cosmic_zposition, track_cosmic_xmomentum,track_cosmic_ymomentum, track_cosmic_zmomentum, track_cosmic_rad, track_cosmic_detid; + + }; + +HcalHBHEMuonAnalyzer::HcalHBHEMuonAnalyzer(const edm::ParameterSet& iConfig) { + //now do what ever initialization is needed + HLTriggerResults_ = iConfig.getParameter("HLTriggerResults"); + labelBS_ = iConfig.getParameter("LabelBS"); + labelVtx_ = iConfig.getParameter("LabelVertex"); + labelEBRecHit_ = iConfig.getParameter("LabelEBRecHit"); + labelEERecHit_ = iConfig.getParameter("LabelEERecHit"); + labelHBHERecHit_ = iConfig.getParameter("LabelHBHERecHit"); + labelMuon_ = iConfig.getParameter("LabelMuon"); + verbosity_ = iConfig.getUntrackedParameter("Verbosity",0); + maxDepth_ = iConfig.getUntrackedParameter("MaxDepth",4); + if (maxDepth_ > 7) maxDepth_ = 7; + else if (maxDepth_ < 1) maxDepth_ = 4; + + tok_trigRes_ = consumes(HLTriggerResults_); + tok_BS_ = consumes(labelBS_); + tok_Vtx_ = consumes(labelVtx_); + tok_EB_ = consumes(labelEBRecHit_); + tok_EE_ = consumes(labelEERecHit_); + tok_HBHE_ = consumes(labelHBHERecHit_); + tok_Muon_ = consumes(labelMuon_); +} + +HcalHBHEMuonAnalyzer::~HcalHBHEMuonAnalyzer() { + // do anything here that needs to be done at desctruction time + // (e.g. close files, deallocate resources etc.) +} + +// +// member functions +// + +// ------------ method called for each event ------------ +void HcalHBHEMuonAnalyzer::analyze(const edm::Event& iEvent, const edm::EventSetup& iSetup) { + + clearVectors(); + RunNumber = iEvent.id().run(); + EventNumber = iEvent.id().event(); + LumiNumber = iEvent.id().luminosityBlock(); + BXNumber = iEvent.bunchCrossing(); + LogDebug("HcalHBHEMuon") << "Run " << RunNumber << " Event " << EventNumber + << " Lumi " << LumiNumber << " BX " << BXNumber; + + edm::Handle _Triggers; + iEvent.getByToken(tok_trigRes_, _Triggers); + + LogDebug("HcalHBHEMuon") << "Size of all triggers " << all_triggers.size(); + int Ntriggers = all_triggers.size(); + LogDebug("HcalHBHEMuon") << "Size of HLT MENU: " << _Triggers->size(); + + if (_Triggers.isValid()) { + const edm::TriggerNames &triggerNames_ = iEvent.triggerNames(*_Triggers); + std::vector index; + for (int i=0;i < Ntriggers;i++) { + index.push_back(triggerNames_.triggerIndex(all_triggers[i])); + int triggerSize =int( _Triggers->size()); + LogDebug("HcalHBHEMuon") << "outside loop " << index[i] + << "\ntriggerSize " << triggerSize; + if (index[i] < triggerSize) { + hltresults.push_back(_Triggers->accept(index[i])) ; + LogDebug("HcalHBHEMuon") << "Trigger_info " << triggerSize + << " triggerSize " << index[i] + << " trigger_index " << hltresults.at(i) + << " hltresult"; + } else { + edm::LogInfo("HcalHBHEMuon") << "Requested HLT path \"" << "\" does not exist"; + } + } + } + + // get handles to calogeometry and calotopology + edm::ESHandle pG; + iSetup.get().get(pG); + const CaloGeometry* geo = pG.product(); + + edm::ESHandle bFieldH; + iSetup.get().get(bFieldH); + const MagneticField* bField = bFieldH.product(); + + edm::ESHandle ecalChStatus; + iSetup.get().get(ecalChStatus); + const EcalChannelStatus* theEcalChStatus = ecalChStatus.product(); + + edm::ESHandle sevlv; + iSetup.get().get(sevlv); + + edm::ESHandle theCaloTopology; + iSetup.get().get(theCaloTopology); + const CaloTopology *caloTopology = theCaloTopology.product(); + + edm::ESHandle htopo; + iSetup.get().get(htopo); + const HcalTopology* theHBHETopology = htopo.product(); + + // Relevant blocks from iEvent + edm::Handle bmspot; + iEvent.getByToken(tok_BS_, bmspot); + + edm::Handle vtx; + iEvent.getByToken(tok_Vtx_, vtx); + + edm::Handle barrelRecHitsHandle; + iEvent.getByToken(tok_EB_, barrelRecHitsHandle); + edm::Handle endcapRecHitsHandle; + iEvent.getByToken(tok_EE_, endcapRecHitsHandle); + + edm::Handle hbhe; + iEvent.getByToken(tok_HBHE_, hbhe); + + edm::Handle _Muon; + iEvent.getByToken(tok_Muon_, _Muon); + + reco::VertexCollection::const_iterator firstGoodVertex = vtx->end(); + for (reco::VertexCollection::const_iterator it = vtx->begin(); it != firstGoodVertex; it++) + { + if(isGoodVertex(*it)){ + firstGoodVertex = it; + break; + } + } + // require a good vertex + if (firstGoodVertex == vtx->end()) return; + + math::XYZPoint bspot; + bspot= (bmspot.isValid()) ? bmspot->position() : math::XYZPoint(0,0,0); + + + if (_Muon.isValid()) { + for (reco::MuonCollection::const_iterator RecMuon = _Muon->begin(); RecMuon!= _Muon->end(); ++RecMuon) { + muon_is_good.push_back(RecMuon->isPFMuon()); + muon_global.push_back(RecMuon->isGlobalMuon()); + muon_tracker.push_back(RecMuon->isTrackerMuon()); + PtGlob.push_back((RecMuon)->pt()); + EtaGlob.push_back(RecMuon->eta()); + PhiGlob.push_back(RecMuon->phi()); + Energy.push_back(RecMuon->energy()); + Pmuon.push_back(RecMuon->p()); + // acessing tracker hits info + if (RecMuon->track().isNonnull()) { + TrackerLayer.push_back(RecMuon->track()->hitPattern().trackerLayersWithMeasurement()); + } else { + TrackerLayer.push_back(-1); + } + if (RecMuon->innerTrack().isNonnull()) { + innerTrack.push_back(true); + NumPixelLayers.push_back(RecMuon->innerTrack()->hitPattern().pixelLayersWithMeasurement()); + chiTracker.push_back(RecMuon->innerTrack()->normalizedChi2()); + DxyTracker.push_back(fabs(RecMuon->innerTrack()->dxy((*firstGoodVertex).position()))); + DzTracker.push_back(fabs(RecMuon->innerTrack()->dz((*firstGoodVertex).position()))); + innerTrackpt.push_back(RecMuon->innerTrack()->pt()); + innerTracketa.push_back(RecMuon->innerTrack()->eta()); + innerTrackphi.push_back(RecMuon->innerTrack()->phi()); + Tight_PixelHits.push_back(RecMuon->innerTrack()->hitPattern().numberOfValidPixelHits()); + } else { + innerTrack.push_back(false); + NumPixelLayers.push_back(0); + chiTracker.push_back(0); + DxyTracker.push_back(0); + DzTracker.push_back(0); + innerTrackpt.push_back(0); + innerTracketa.push_back(0); + innerTrackphi.push_back(0); + Tight_PixelHits.push_back(0); + } + // outer track info + if (RecMuon->outerTrack().isNonnull()) { + OuterTrack.push_back(true); + OuterTrackPt.push_back(RecMuon->outerTrack()->pt()); + OuterTrackEta.push_back(RecMuon->outerTrack()->eta()); + OuterTrackPhi.push_back(RecMuon->outerTrack()->phi()); + OuterTrackChi.push_back(RecMuon->outerTrack()->normalizedChi2()); + OuterTrackHits.push_back(RecMuon->outerTrack()->numberOfValidHits()); + OuterTrackRHits.push_back(RecMuon->outerTrack()->recHitsSize()); + } else { + OuterTrack.push_back(false); + OuterTrackPt.push_back(0); + OuterTrackEta.push_back(0); + OuterTrackPhi.push_back(0); + OuterTrackChi.push_back(0); + OuterTrackHits.push_back(0); + OuterTrackRHits.push_back(0); + } + // Tight Muon cuts + if (RecMuon->globalTrack().isNonnull()) { + GlobalTrack.push_back(true); + chiGlobal.push_back(RecMuon->globalTrack()->normalizedChi2()); + GlobalMuonHits.push_back(RecMuon->globalTrack()->hitPattern().numberOfValidMuonHits()); + MatchedStat.push_back(RecMuon->numberOfMatchedStations()); + GlobalTrckPt.push_back(RecMuon->globalTrack()->pt()); + GlobalTrckEta.push_back(RecMuon->globalTrack()->eta()); + GlobalTrckPhi.push_back(RecMuon->globalTrack()->phi()); + Tight_TransImpara.push_back(fabs(RecMuon->muonBestTrack()->dxy((*firstGoodVertex).position()))); + Tight_LongPara.push_back(fabs(RecMuon->muonBestTrack()->dz((*firstGoodVertex).position()))); + } else { + GlobalTrack.push_back(false); + chiGlobal.push_back(0); + GlobalMuonHits.push_back(0); + MatchedStat.push_back(0); + GlobalTrckPt.push_back(0); + GlobalTrckEta.push_back(0); + GlobalTrckPhi.push_back(0); + Tight_TransImpara.push_back(0); + Tight_LongPara.push_back(0); + } + + IsolationR04.push_back(((RecMuon->pfIsolationR04().sumChargedHadronPt + std::max(0.,RecMuon->pfIsolationR04().sumNeutralHadronEt + RecMuon->pfIsolationR04().sumPhotonEt - (0.5 *RecMuon->pfIsolationR04().sumPUPt))) / RecMuon->pt()) ); + + IsolationR03.push_back(((RecMuon->pfIsolationR03().sumChargedHadronPt + std::max(0.,RecMuon->pfIsolationR03().sumNeutralHadronEt + RecMuon->pfIsolationR03().sumPhotonEt - (0.5 * RecMuon->pfIsolationR03().sumPUPt))) / RecMuon->pt())); + + MuonEcalEnergy.push_back(RecMuon->calEnergy().emS9); + MuonHcalEnergy.push_back(RecMuon->calEnergy().hadS9); + MuonHOEnergy.push_back(RecMuon->calEnergy().hoS9); + + double eEcal(0),eHcal(0),activeL(0),eHcalDepth[7],eHcalDepthHot[7]; + unsigned int isHot = 0; + for (int i=0; i<7; ++i) eHcalDepth[i]=eHcalDepthHot[i]=-10000; + + if (RecMuon->innerTrack().isNonnull()) { + const reco::Track* pTrack = (RecMuon->innerTrack()).get(); + spr::propagatedTrackID trackID = spr::propagateCALO(pTrack, geo, bField, (((verbosity_/100)%10>0))); + + MuonEcalDetId.push_back((trackID.detIdECAL)()); + MuonHcalDetId.push_back((trackID.detIdHCAL)()); + MuonEHcalDetId.push_back((trackID.detIdEHCAL)()); + + if (trackID.okECAL) { + const DetId isoCell(trackID.detIdECAL); + std::pair e3x3 = spr::eECALmatrix(isoCell,barrelRecHitsHandle,endcapRecHitsHandle,*theEcalChStatus,geo,caloTopology,sevlv.product(),1,1,-100.0,-100.0,-500.0,500.0,false); + eEcal = e3x3.first; + } + + if (trackID.okHCAL) { + const DetId closestCell(trackID.detIdHCAL); + eHcal = spr::eHCALmatrix(theHBHETopology, closestCell, hbhe,0,0, false, true, -100.0, -100.0, -100.0, -100.0, -500.,500.); + std::vector > ehdepth; + spr::energyHCALCell((HcalDetId) closestCell, hbhe, ehdepth, maxDepth_, -100.0, -100.0, -100.0, -100.0, -500.0, 500.0, (((verbosity_/1000)%10)>0)); + for (unsigned int i=0; i > ehdepth; + spr::energyHCALCell(hotCell, hbhe, ehdepth, maxDepth_, -100.0, -100.0, -100.0, -100.0, -500.0, 500.0, false);//(((verbosity_/1000)%10)>0 )); + for (unsigned int i=0; iFill(); +} + +// ------------ method called once each job just before starting event loop ------------ +void HcalHBHEMuonAnalyzer::beginJob() { + + TREE = fs->make("TREE", "TREE"); + TREE->Branch("Event_No",&EventNumber); + TREE->Branch("Run_No",&RunNumber); + TREE->Branch("LumiNumber",&LumiNumber); + TREE->Branch("BXNumber",&BXNumber); + TREE->Branch("pt_of_muon",&PtGlob); + TREE->Branch("eta_of_muon",&EtaGlob); + TREE->Branch("phi_of_muon",&PhiGlob); + TREE->Branch("energy_of_muon",&Energy); + TREE->Branch("p_of_muon",&Pmuon); + TREE->Branch("PF_Muon",&muon_is_good); + TREE->Branch("Global_Muon",&muon_global); + TREE->Branch("Tracker_muon",&muon_tracker); + + TREE->Branch("hcal_3into3",&MuonHcalEnergy); + TREE->Branch("hcal_1x1",&MuonHcal1x1Energy); + TREE->Branch("hcal_detID",&MuonHcalDetId); + TREE->Branch("hcal_edepth1",&MuonHcalDepth1Energy); + TREE->Branch("hcal_edepth2",&MuonHcalDepth2Energy); + TREE->Branch("hcal_edepth3",&MuonHcalDepth3Energy); + TREE->Branch("hcal_edepth4",&MuonHcalDepth4Energy); + TREE->Branch("hcal_edepthHot1",&MuonHcalDepth1HotEnergy); + TREE->Branch("hcal_edepthHot2",&MuonHcalDepth2HotEnergy); + TREE->Branch("hcal_edepthHot3",&MuonHcalDepth3HotEnergy); + TREE->Branch("hcal_edepthHot4",&MuonHcalDepth4HotEnergy); + + if (maxDepth_ > 4) { + TREE->Branch("hcal_edepth5",&MuonHcalDepth5Energy); + TREE->Branch("hcal_edepthHot5",&MuonHcalDepth5HotEnergy); + if (maxDepth_ > 5) { + TREE->Branch("hcal_edepth6",&MuonHcalDepth6Energy); + TREE->Branch("hcal_edepthHot6",&MuonHcalDepth6HotEnergy); + if (maxDepth_ > 6) { + TREE->Branch("hcal_edepth7",&MuonHcalDepth7Energy); + TREE->Branch("hcal_edepthHot7",&MuonHcalDepth7HotEnergy); + } + } + } + + + TREE->Branch("TrackerLayer",&TrackerLayer); + TREE->Branch("innerTrack",&innerTrack); + TREE->Branch("innerTrackpt",&innerTrackpt); + TREE->Branch("innerTracketa",&innerTracketa); + TREE->Branch("innerTrackphi",&innerTrackphi); + TREE->Branch("MatchedStat",&MatchedStat); + TREE->Branch("GlobalTrckPt",&GlobalTrckPt); + TREE->Branch("GlobalTrckEta",&GlobalTrckEta); + TREE->Branch("GlobalTrckPhi",&GlobalTrckPhi); + TREE->Branch("NumPixelLayers",&NumPixelLayers); + TREE->Branch("chiTracker",&chiTracker); + TREE->Branch("DxyTracker",&DxyTracker); + TREE->Branch("DzTracker",&DzTracker); + TREE->Branch("OuterTrack",&OuterTrack); + TREE->Branch("OuterTrackPt",&OuterTrackPt); + TREE->Branch("OuterTrackEta",&OuterTrackEta); + TREE->Branch("OuterTrackPhi",&OuterTrackPhi); + TREE->Branch("OuterTrackHits",&OuterTrackHits); + TREE->Branch("OuterTrackRHits",&OuterTrackRHits); + TREE->Branch("OuterTrackChi",&OuterTrackChi); + TREE->Branch("GlobalTrack",&GlobalTrack); + TREE->Branch("GlobTrack_Chi",&chiGlobal); + TREE->Branch("Global_Muon_Hits",&GlobalMuonHits); + TREE->Branch("MatchedStations",&MatchedStat); + TREE->Branch("Global_Track_Pt",&GlobalTrckPt); + TREE->Branch("Global_Track_Eta",&GlobalTrckEta); + TREE->Branch("Global_Track_Phi",&GlobalTrckPhi); + /////////////////////////////// + TREE->Branch("Tight_LongitudinalImpactparameter",&Tight_LongPara); + TREE->Branch("Tight_TransImpactparameter",&Tight_TransImpara); + TREE->Branch("InnerTrackPixelHits",&Tight_PixelHits); + TREE->Branch("IsolationR04",&IsolationR04); + TREE->Branch("IsolationR03",&IsolationR03); + + TREE->Branch("hcal_cellHot",&MuonHcalHot); + TREE->Branch("ecal_3into3",&MuonEcalEnergy); + TREE->Branch("ecal_3x3",&MuonEcal3x3Energy); + TREE->Branch("ecal_detID",&MuonEcalDetId); + TREE->Branch("ehcal_detID",&MuonEHcalDetId); + TREE->Branch("tracker_3into3",&MuonHOEnergy); + TREE->Branch("activeLength",&MuonHcalActiveLength); + + /////////////////////////////// + TREE->Branch("hltresults",&hltresults); + TREE->Branch("all_triggers",&all_triggers); + +} + +// ------------ method called once each job just after ending the event loop ------------ +void HcalHBHEMuonAnalyzer::endJob() {} + +// ------------ method called when starting to processes a run ------------ +void HcalHBHEMuonAnalyzer::beginRun(edm::Run const& iRun, edm::EventSetup const& iSetup) { + + /* edm::ESHandle pHRNDC; + iSetup.get().get(pHRNDC); + const HcalDDDRecConstants & hdc = (*pHRNDC); + */ + + HcalDDDRecConstantsTemp hdc; + actHB.clear(); + actHE.clear(); + actHB = hdc.getThickActive(0); + actHE = hdc.getThickActive(1); + + bool changed = true; + all_triggers.clear(); + if (hltConfig_.init(iRun, iSetup,"HLT" , changed)) { + // if init returns TRUE, initialisation has succeeded! + edm::LogInfo("TriggerBlock") << "HLT config with process name " + << "HLT" << " successfully extracted"; + std::string string_search[5]={"HLT_IsoMu_","HLT_L1SingleMu_","HLT_L2Mu","HLT_Mu","HLT_RelIso1p0Mu"}; + unsigned int ntriggers = hltConfig_.size(); + for (unsigned int t=0;t 2.) return false; + if (fabs(vtx.position().Z()) > 24.) return false; + return true; +} + +//define this as a plug-in +#include "FWCore/Framework/interface/MakerMacros.h" + +DEFINE_FWK_MODULE(HcalHBHEMuonAnalyzer); + diff --git a/Calibration/HcalCalibAlgos/src/HcalIsoTrkAnalyzer.cc b/Calibration/HcalCalibAlgos/src/HcalIsoTrkAnalyzer.cc index 642424666e1e6..f56420c2ca45e 100644 --- a/Calibration/HcalCalibAlgos/src/HcalIsoTrkAnalyzer.cc +++ b/Calibration/HcalCalibAlgos/src/HcalIsoTrkAnalyzer.cc @@ -1,658 +1,556 @@ -// -*- C++ -*- -// -// Package: HcalCalibAlgos -// Class: HcalIsoTrkAnalyzer - -// -/**\class HcalIsoTrkAnalyzer HcalIsoTrkAnalyzer.cc Calibration/HcalCalibAlgos/src/HcalIsoTrkAnalyzer.cc - - Description: see twiki for details: https://twiki.cern.ch/twiki/bin/view/CMS/IsoTrackAnalyzer - - Implementation: -*/ -// -// Original Authors: Andrey Pozdnyakov, Sergey Petrushanko, -// Grigory Safronov, Olga Kodolova -// Created: Thu Jul 12 18:12:19 CEST 2007 -// -// - // system include files #include -// user include files +// Root objects +#include "TROOT.h" +#include "TSystem.h" +#include "TFile.h" +#include "TProfile.h" +#include "TDirectory.h" +#include "TTree.h" +#include "TLorentzVector.h" +#include "TInterpreter.h" + +//Tracks +#include "DataFormats/TrackReco/interface/Track.h" +#include "DataFormats/TrackReco/interface/TrackFwd.h" +#include "DataFormats/TrackReco/interface/HitPattern.h" +#include "DataFormats/TrackReco/interface/TrackBase.h" +// Vertices +#include "DataFormats/VertexReco/interface/VertexFwd.h" +#include "DataFormats/VertexReco/interface/Vertex.h" +#include "DataFormats/BeamSpot/interface/BeamSpot.h" + +//Triggers +#include "DataFormats/Common/interface/TriggerResults.h" +#include "DataFormats/HLTReco/interface/TriggerEvent.h" +#include "DataFormats/HLTReco/interface/TriggerObject.h" +#include "DataFormats/L1GlobalTrigger/interface/L1GlobalTriggerReadoutRecord.h" +#include "DataFormats/Luminosity/interface/LumiDetails.h" +#include "DataFormats/Math/interface/LorentzVector.h" +#include "DataFormats/Math/interface/deltaR.h" + #include "FWCore/Framework/interface/Frameworkfwd.h" #include "FWCore/Framework/interface/EDAnalyzer.h" #include "FWCore/Framework/interface/Event.h" #include "FWCore/Framework/interface/MakerMacros.h" +#include "FWCore/ServiceRegistry/interface/Service.h" #include "FWCore/ParameterSet/interface/ParameterSet.h" -#include "DataFormats/TrackReco/interface/Track.h" -#include "DataFormats/TrackReco/interface/TrackFwd.h" -#include "FWCore/Framework/interface/ESHandle.h" -#include "FWCore/Framework/interface/EventSetup.h" - -#include "DataFormats/HcalRecHit/interface/HcalRecHitCollections.h" -#include "DataFormats/EcalRecHit/interface/EcalRecHitCollections.h" -#include "FWCore/Utilities/interface/Exception.h" - -#include "TrackingTools/TrackAssociator/interface/TrackDetMatchInfo.h" -#include "TrackingTools/TrackAssociator/interface/TrackAssociatorParameters.h" -#include "TrackingTools/TrackAssociator/interface/TrackDetectorAssociator.h" - -#include "DataFormats/EcalDetId/interface/EcalSubdetector.h" -#include "DataFormats/HcalDetId/interface/HcalSubdetector.h" - -#include "Geometry/CaloGeometry/interface/CaloSubdetectorGeometry.h" -#include "Geometry/CaloGeometry/interface/CaloCellGeometry.h" +#include "FWCore/Common/interface/TriggerNames.h" +#include "CommonTools/UtilAlgos/interface/TFileService.h" +#include "HLTrigger/HLTcore/interface/HLTConfigProvider.h" + +#include "Calibration/IsolatedParticles/interface/CaloPropagateTrack.h" +#include "Calibration/IsolatedParticles/interface/ChargeIsolation.h" +#include "Calibration/IsolatedParticles/interface/eCone.h" +#include "Calibration/IsolatedParticles/interface/eECALMatrix.h" +#include "Calibration/IsolatedParticles/interface/TrackSelection.h" + +#include "MagneticField/Engine/interface/MagneticField.h" +#include "MagneticField/Records/interface/IdealMagneticFieldRecord.h" #include "Geometry/CaloGeometry/interface/CaloGeometry.h" +#include "Geometry/CaloGeometry/interface/CaloSubdetectorGeometry.h" #include "Geometry/CaloEventSetup/interface/CaloTopologyRecord.h" -#include "Geometry/CommonDetUnit/interface/GeomDetUnit.h" - -#include "DataFormats/HcalDetId/interface/HcalDetId.h" -#include "FWCore/MessageLogger/interface/MessageLogger.h" -#include "TrackPropagation/SteppingHelixPropagator/interface/SteppingHelixPropagator.h" -#include "DataFormats/EcalDetId/interface/EBDetId.h" -#include "DataFormats/EcalDetId/interface/EEDetId.h" -#include "DataFormats/HcalIsolatedTrack/interface/IsolatedPixelTrackCandidate.h" -#include "DataFormats/HcalIsolatedTrack/interface/IsolatedPixelTrackCandidateFwd.h" -#include "Calibration/Tools/interface/MinL3AlgoUniv.h" -#include "Calibration/HcalCalibAlgos/src/TCell.h" -#include "CondFormats/HcalObjects/interface/HcalRespCorrs.h" -#include "CondFormats/DataRecord/interface/HcalRespCorrsRcd.h" - -#include "Calibration/HcalCalibAlgos/interface/CommonUsefulStuff.h" - - -#include "TROOT.h" -#include "TH1.h" -#include "TH2.h" -#include "TFile.h" -#include "TTree.h" - -#include "TString.h" -#include "TObject.h" -#include "TObjArray.h" -#include "TClonesArray.h" -#include "TRefArray.h" -#include "TLorentzVector.h" - - -#include -#include - -using namespace edm; -using namespace std; -using namespace reco; - -// -// class decleration -// +#include "Geometry/CaloTopology/interface/CaloSubdetectorTopology.h" +#include "Geometry/CaloTopology/interface/HcalTopology.h" +#include "Geometry/CaloTopology/interface/CaloTopology.h" +#include "CondFormats/DataRecord/interface/EcalChannelStatusRcd.h" +#include "Geometry/CaloTopology/interface/EcalTrigTowerConstituentsMap.h" +#include "RecoLocalCalo/EcalRecAlgos/interface/EcalSeverityLevelAlgo.h" +#include "RecoLocalCalo/EcalRecAlgos/interface/EcalSeverityLevelAlgoRcd.h" class HcalIsoTrkAnalyzer : public edm::EDAnalyzer { + public: explicit HcalIsoTrkAnalyzer(const edm::ParameterSet&); ~HcalIsoTrkAnalyzer(); - - //double getDistInPlaneSimple(const GlobalPoint caloPoint, const GlobalPoint rechitPoint); + + static void fillDescriptions(edm::ConfigurationDescriptions& descriptions); private: - virtual void beginJob() override ; - virtual void analyze(const edm::Event&, const edm::EventSetup&) override; - virtual void endJob() override ; - - // ----------member data --------------------------- - + virtual void beginJob() ; + virtual void analyze(const edm::Event&, const edm::EventSetup&); + virtual void endJob() ; + virtual void beginRun(edm::Run const&, edm::EventSetup const&); + virtual void endRun(edm::Run const&, edm::EventSetup const&); + virtual void beginLuminosityBlock(edm::LuminosityBlock const&, edm::EventSetup const&); + virtual void endLuminosityBlock(edm::LuminosityBlock const&, edm::EventSetup const&); - TrackDetectorAssociator trackAssociator_; - TrackAssociatorParameters parameters_; - - const CaloGeometry* geo; - edm::EDGetTokenT tok_hbhe_; - edm::EDGetTokenT tok_ho_; - edm::EDGetTokenT tok_ecal_; - edm::EDGetTokenT tok_track_; - edm::EDGetTokenT tok_track1_; - - std::string m_inputTrackLabel; - std::string m_ecalLabel; - std::string m_ebInstance; - std::string m_eeInstance; - std::string m_hcalLabel; - int m_histoFlag; - - double associationConeSize_, calibrationConeSize_; - string AxB_; - bool allowMissingInputs_; - string outputFileName_; - - double trackEta, trackPhi; - double rvert; - - - int nIterations, MinNTrackHitsBarrel,MinNTECHitsEndcap; - float eventWeight; - double energyMinIso, energyMaxIso; - double energyECALmip, maxPNear; - double hottestHitDistance, EcalCone, EcalConeOuter; - - TFile* rootFile; - TTree* tree; - Float_t targetE; - UInt_t numberOfCells; - UInt_t cell; - Float_t cellEnergy; - - TClonesArray* cells; - TRefArray* cells3x3; - TRefArray* cellsPF; - UInt_t eventNumber; - UInt_t runNumber; - Int_t iEtaHit; - UInt_t iPhiHit; - - Float_t xTrkEcal, yTrkEcal, zTrkEcal; - Float_t xTrkHcal, yTrkHcal, zTrkHcal; - Float_t PxTrkHcal, PyTrkHcal, PzTrkHcal; - - Float_t emEnergy, emRingEnergy; - - // TLorentzVector* exampleP4; - TLorentzVector* tagJetP4; // dijet - TLorentzVector* probeJetP4; // dijet - Float_t etVetoJet; // dijet - Float_t tagJetEmFrac; // dijet - Float_t probeJetEmFrac; // dijet - - std::ofstream input_to_L3; - + double dR(math::XYZTLorentzVector&, math::XYZTLorentzVector&); + + bool changed; + edm::Service fs; + HLTConfigProvider hltConfig_; + std::vector trigNames, HLTNames; + std::vector trigKount, trigPass; + spr::trackSelectionParameters selectionParameters; + std::string theTrackQuality, processName; + std::string l1Filter, l2Filter, l3Filter; + double a_mipR, a_coneR, a_charIsoR; + double pTrackMin_, eEcalMax_, eIsolation_; + int nRun, nAll, nGood; + edm::InputTag triggerEvent_, theTriggerResultsLabel, labelHBHE_; + edm::InputTag labelGenTrack_, labelRecVtx_, labelEB_, labelEE_; + edm::EDGetTokenT tok_trigEvt; + edm::EDGetTokenT tok_trigRes; + + edm::EDGetTokenT tok_genTrack_; + edm::EDGetTokenT tok_recVtx_; + edm::EDGetTokenT tok_bs_; + edm::EDGetTokenT tok_EB_; + edm::EDGetTokenT tok_EE_; + edm::EDGetTokenT tok_hbhe_; + + TTree *tree; + int t_Run, t_Event, t_ieta; + double t_EventWeight, t_l1pt, t_l1eta, t_l1phi; + double t_l3pt, t_l3eta, t_l3phi, t_p, t_mindR1; + double t_mindR2, t_eMipDR, t_eHcal, t_hmaxNearP; + bool t_selectTk,t_qltyFlag,t_qltyMissFlag,t_qltyPVFlag; + std::vector *t_DetIds; + std::vector *t_HitEnergies, pbin; + std::vector *t_trgbits; + std::vector trgnames; }; - -HcalIsoTrkAnalyzer::HcalIsoTrkAnalyzer(const edm::ParameterSet& iConfig) -{ - - m_ecalLabel = iConfig.getUntrackedParameter ("ecalRecHitsLabel","ecalRecHit"); - m_ebInstance = iConfig.getUntrackedParameter ("ebRecHitsInstance","EcalRecHitsEB"); - m_eeInstance = iConfig.getUntrackedParameter ("eeRecHitsInstance","EcalRecHitsEE"); - m_hcalLabel = iConfig.getUntrackedParameter ("hcalRecHitsLabel","hbhereco"); +HcalIsoTrkAnalyzer::HcalIsoTrkAnalyzer(const edm::ParameterSet& iConfig) : + changed(false), nRun(0), nAll(0), nGood(0) { + //now do whatever initialization is needed + trigNames = iConfig.getParameter >("Triggers"); + theTrackQuality = iConfig.getParameter("TrackQuality"); + processName = iConfig.getParameter("ProcessName"); + l1Filter = iConfig.getParameter("L1Filter"); + l2Filter = iConfig.getParameter("L2Filter"); + l3Filter = iConfig.getParameter("L3Filter"); + reco::TrackBase::TrackQuality trackQuality_=reco::TrackBase::qualityByName(theTrackQuality); + selectionParameters.minPt = iConfig.getParameter("MinTrackPt"); + selectionParameters.minQuality = trackQuality_; + selectionParameters.maxDxyPV = iConfig.getParameter("MaxDxyPV"); + selectionParameters.maxDzPV = iConfig.getParameter("MaxDzPV"); + selectionParameters.maxChi2 = iConfig.getParameter("MaxChi2"); + selectionParameters.maxDpOverP = iConfig.getParameter("MaxDpOverP"); + selectionParameters.minOuterHit = iConfig.getParameter("MinOuterHit"); + selectionParameters.minLayerCrossed = iConfig.getParameter("MinLayerCrossed"); + selectionParameters.maxInMiss = iConfig.getParameter("MaxInMiss"); + selectionParameters.maxOutMiss = iConfig.getParameter("MaxOutMiss"); + a_coneR = iConfig.getParameter("ConeRadius"); + a_charIsoR = a_coneR + 28.9; + a_mipR = iConfig.getParameter("ConeRadiusMIP"); + pTrackMin_ = iConfig.getParameter("MinimumTrackP"); + eEcalMax_ = iConfig.getParameter("MaximumEcalEnergy"); + eIsolation_ = iConfig.getParameter("IsolationEnergy"); + triggerEvent_ = iConfig.getParameter("TriggerEventLabel"); + theTriggerResultsLabel = iConfig.getParameter("TriggerResultLabel"); + labelGenTrack_ = iConfig.getParameter("TrackLabel"); + labelRecVtx_ = iConfig.getParameter("VertexLabel"); + labelEB_ = iConfig.getParameter("EBRecHitLabel"); + labelEE_ = iConfig.getParameter("EERecHitLabel"); + labelHBHE_ = iConfig.getParameter("HBHERecHitLabel"); + + // define tokens for access + tok_trigEvt = consumes(triggerEvent_); + tok_trigRes = consumes(theTriggerResultsLabel); + tok_genTrack_ = consumes(labelGenTrack_); + tok_recVtx_ = consumes(labelRecVtx_); + tok_bs_ = consumes(iConfig.getParameter("BeamSpotLabel")); - tok_hbhe_ = consumes(iConfig.getParameter("hbheInput")); - tok_ho_ = consumes(iConfig.getParameter("hoInput")); - tok_ecal_ = consumes(iConfig.getParameter("eInput")); - tok_track_ = consumes(iConfig.getParameter("HcalIsolTrackInput")); - tok_track1_ = consumes(iConfig.getParameter("trackInput")); - associationConeSize_=iConfig.getParameter("associationConeSize"); - allowMissingInputs_=iConfig.getUntrackedParameter("allowMissingInputs",true); - outputFileName_=iConfig.getParameter("outputFileName"); - - AxB_=iConfig.getParameter("AxB"); - calibrationConeSize_=iConfig.getParameter("calibrationConeSize"); - - nIterations = iConfig.getParameter("noOfIterations"); - eventWeight = iConfig.getParameter("eventWeight"); - energyMinIso = iConfig.getParameter("energyMinIso"); - energyMaxIso = iConfig.getParameter("energyMaxIso"); - energyECALmip = iConfig.getParameter("energyECALmip"); - maxPNear = iConfig.getParameter("maxPNear"); - MinNTrackHitsBarrel = iConfig.getParameter("MinNTrackHitsBarrel"); - MinNTECHitsEndcap = iConfig.getParameter("MinNTECHitsEndcap"); - hottestHitDistance = iConfig.getParameter("hottestHitDistance"); - EcalCone = iConfig.getParameter("EcalCone"); - EcalConeOuter = iConfig.getParameter("EcalConeOuter"); - - edm::ParameterSet parameters = iConfig.getParameter("TrackAssociatorParameters"); - edm::ConsumesCollector iC = consumesCollector(); - parameters_.loadParameters( parameters, iC ); - trackAssociator_.useDefaultPropagator(); - + tok_EB_ = consumes(labelEB_); + tok_EE_ = consumes(labelEE_); + tok_hbhe_ = consumes(labelHBHE_); + + std::vector dummy(trigNames.size(),0); + trigKount = trigPass = dummy; + edm::LogInfo("HcalIsoTrack") <<"Parameters read from config file \n" + <<"\t minPt " << selectionParameters.minPt + <<"\t theTrackQuality " << theTrackQuality + <<"\t minQuality " << selectionParameters.minQuality + <<"\t maxDxyPV " << selectionParameters.maxDxyPV + <<"\t maxDzPV " << selectionParameters.maxDzPV + <<"\t maxChi2 " << selectionParameters.maxChi2 + <<"\t maxDpOverP " << selectionParameters.maxDpOverP + <<"\t minOuterHit " << selectionParameters.minOuterHit + <<"\t minLayerCrossed " << selectionParameters.minLayerCrossed + <<"\t maxInMiss " << selectionParameters.maxInMiss + <<"\t maxOutMiss " << selectionParameters.maxOutMiss + <<"\t a_coneR " << a_coneR + <<"\t a_charIsoR " << a_charIsoR + <<"\t a_mipR " << a_mipR; + edm::LogInfo("HcalIsoTrack") << "Process " << processName << " L1Filter:" + << l1Filter << " L2Filter:" << l2Filter + << " L3Filter:" << l3Filter; + for (unsigned int k=0; k rawEnergyVec; - vector detiphi; - vector detieta; - vector i3i5; - vector detidvec; - float calEnergy; - - edm::Handle isoProdTracks; - iEvent.getByToken(tok_track1_,isoProdTracks); - - edm::Handle isoPixelTracks; - iEvent.getByToken(tok_track_,isoPixelTracks); - - edm::Handle ecal; - iEvent.getByToken(tok_ecal_,ecal); - const EcalRecHitCollection Hitecal = *(ecal.product()); - - edm::Handle hbhe; - iEvent.getByToken(tok_hbhe_,hbhe); - const HBHERecHitCollection Hithbhe = *(hbhe.product()); +void HcalIsoTrkAnalyzer::analyze(const edm::Event& iEvent, const edm::EventSetup& iSetup) { + + t_Run = iEvent.id().run(); + t_Event = iEvent.id().event(); + nAll++; + LogDebug("HcalIsoTrack") << "Run " << t_Run << " Event " << t_Event + << " Luminosity " << iEvent.luminosityBlock() + << " Bunch " << iEvent.bunchCrossing(); + //Get magnetic field and ECAL channel status + edm::ESHandle bFieldH; + iSetup.get().get(bFieldH); + const MagneticField *bField = bFieldH.product(); + + // get handles to calogeometry and calotopology edm::ESHandle pG; iSetup.get().get(pG); - geo = pG.product(); - - const CaloSubdetectorGeometry* gHcal = geo->getSubdetectorGeometry(DetId::Hcal,HcalBarrel); - //Note: even though it says HcalBarrel, we actually get the whole Hcal detector geometry! - - -// rof 16.05.2008 start: include the possibility for recalibration (use "recalibrate" label for safety) -/* - edm::ESHandle recalibCorrs; - iSetup.get().get("recalibrate",recalibCorrs); - const HcalRespCorrs* myRecalib = recalibCorrs.product(); -*/ -// rof end - - parameters_.useEcal = true; - parameters_.useHcal = true; - parameters_.useCalo = false; - parameters_.useMuon = false; - parameters_.dREcal = 0.5; - parameters_.dRHcal = 0.6; - - if (isoPixelTracks->size()==0) return; - - for (reco::TrackCollection::const_iterator trit=isoProdTracks->begin(); trit!=isoProdTracks->end(); trit++) - { - reco::IsolatedPixelTrackCandidateCollection::const_iterator isoMatched=isoPixelTracks->begin(); - bool matched=false; - - //Note: this part needs to be changed: obtain isoPixelTracks from isoProdTracks (should be a way) - for (reco::IsolatedPixelTrackCandidateCollection::const_iterator it = isoPixelTracks->begin(); it!=isoPixelTracks->end(); it++) - { - - if (abs((trit->pt() - it->pt())/it->pt()) < 0.005 && abs(trit->eta() - it->eta()) < 0.01) - { - isoMatched=it; - matched=true; - break; - } - } - if (!matched) continue; - - if (trit->hitPattern().numberOfValidHits()eta())>1.47&&trit->hitPattern().numberOfValidStripTECHits()px()*trit->px()+trit->py()*trit->py()+trit->pz()*trit->pz()+0.14*0.14); - - trackEta = trit->eta(); - trackPhi = trit->phi(); - - double corrHCAL = 1.; //another possibility for correction. - why? - - // cout << endl << " ISO TRACK E = "<< calEnergy << " ETA = " << trackEta<< " PHI = " << trackPhi << " Correction " << corrHCAL<< endl; - - rvert = sqrt(trit->vx()*trit->vx()+trit->vy()*trit->vy()+trit->vz()*trit->vz()); - - //Associate track with a calorimeter - TrackDetMatchInfo info = trackAssociator_.associate(iEvent, iSetup,trackAssociator_.getFreeTrajectoryState(iSetup, *trit),parameters_); - - - xTrkHcal=info.trkGlobPosAtHcal.x(); - yTrkHcal=info.trkGlobPosAtHcal.y(); - zTrkHcal=info.trkGlobPosAtHcal.z(); - - xTrkEcal=info.trkGlobPosAtEcal.x(); - yTrkEcal=info.trkGlobPosAtEcal.y(); - zTrkEcal=info.trkGlobPosAtEcal.z(); - - if (xTrkEcal==0 && yTrkEcal==0&& zTrkEcal==0) {cout<<"zero point at Ecal"<energyIn(); - emEnergy = ecalEnergyInCone(gPointEcal, EcalCone, Hitecal, geo); - - emRingEnergy = ecalEnergyInCone(gPointEcal, EcalConeOuter, Hitecal, geo) - ecalEnergyInCone(gPointEcal, EcalCone, Hitecal, geo); - - - int iphitrue = -10; - int ietatrue = 100; - - const HcalDetId tempId = gHcal->getClosestCell(gPointHcal); - ietatrue = tempId.ieta(); - iphitrue = tempId.iphi(); - - - //container for used recHits - std::vector usedHits; - // - //clear usedHits - usedHits.clear(); - - - // Find Hcal RecHit with maximum energy and collect other information - MaxHit_struct MaxHit; - MaxHit.hitenergy=-100; - - - for (HBHERecHitCollection::const_iterator hhit=Hithbhe.begin(); hhit!=Hithbhe.end(); hhit++) - { + const CaloGeometry* geo = pG.product(); + + bool okC(true); + //Get track collection + edm::Handle trkCollection; + iEvent.getByToken(tok_genTrack_, trkCollection); + reco::TrackCollection::const_iterator trkItr; + if (!trkCollection.isValid()) { + edm::LogWarning("HcalIsoTrack") << "Cannot access the collection " << labelGenTrack_; + okC = false; + } + + //event weight for FLAT sample + t_EventWeight = 1.0; + + //Define the best vertex and the beamspot + edm::Handle recVtxs; + iEvent.getByToken(tok_recVtx_, recVtxs); + edm::Handle beamSpotH; + iEvent.getByToken(tok_bs_, beamSpotH); + math::XYZPoint leadPV(0,0,0); + if (recVtxs->size()>0 && !((*recVtxs)[0].isFake())) { + leadPV = math::XYZPoint( (*recVtxs)[0].x(),(*recVtxs)[0].y(), (*recVtxs)[0].z() ); + } else if (beamSpotH.isValid()) { + leadPV = beamSpotH->position(); + } + LogDebug("HcalIsoTrack") << "Primary Vertex " << leadPV; + if (beamSpotH.isValid()) LogDebug("HcalIsoTrack") << "Beam Spot " + << beamSpotH->position(); + + // RecHits + edm::Handle barrelRecHitsHandle; + iEvent.getByToken(tok_EB_, barrelRecHitsHandle); + if (!barrelRecHitsHandle.isValid()) { + edm::LogWarning("HcalIsoTrack") << "Cannot access the collection " << labelEB_; + okC = false; + } + edm::Handle endcapRecHitsHandle; + iEvent.getByToken(tok_EE_, endcapRecHitsHandle); + if (!endcapRecHitsHandle.isValid()) { + edm::LogWarning("HcalIsoTrack") << "Cannot access the collection " << labelEE_; + okC = false; + } + edm::Handle hbhe; + iEvent.getByToken(tok_hbhe_, hbhe); + if (!hbhe.isValid()) { + edm::LogWarning("HcalIsoTrack") << "Cannot access the collection " << labelHBHE_; + okC = false; + } - //check that this hit was not considered before and push it into usedHits - bool hitIsUsed=false; - DetId hitId=hhit->id(); - for (uint32_t i=0; i trkCaloDirections; + spr::propagateCALO(trkCollection, geo, bField, theTrackQuality, + trkCaloDirections, false); + std::vector::const_iterator trkDetItr; + + //Trigger + trgnames.clear(); + t_trgbits->clear(); + for (unsigned int i=0; ipush_back(false); + + trigger::TriggerEvent triggerEvent; + edm::Handle triggerEventHandle; + iEvent.getByToken(tok_trigEvt, triggerEventHandle); + if (!triggerEventHandle.isValid()) { + edm::LogWarning("HcalIsoTrack") << "Error! Can't get the product " + << triggerEvent_.label() ; + } else if (okC) { + triggerEvent = *(triggerEventHandle.product()); + + const trigger::TriggerObjectCollection& TOC(triggerEvent.getObjects()); + /////////////////////////////TriggerResults + edm::Handle triggerResults; + iEvent.getByToken(tok_trigRes, triggerResults); + if (triggerResults.isValid()) { + std::vector modules; + const edm::TriggerNames & triggerNames = iEvent.triggerNames(*triggerResults); + const std::vector & triggerNames_ = triggerNames.triggerNames(); + for (unsigned int iHLT=0; iHLTsize(); iHLT++) { + bool ok(false); + int hlt = triggerResults->accept(iHLT); + for (unsigned int i=0; iat(i) = (hlt>0); + trigKount[i]++; + if (hlt > 0) { + ok = true; + trigPass[i]++; } - if (hitIsUsed) continue; - usedHits.push_back(hitId); - // - - // rof 16.05.2008 start: include the possibility for recalibration - float recal = 1; - // rof end - - GlobalPoint pos = geo->getPosition(hhit->detid()); - - int iphihitm = (hhit->id()).iphi(); - int ietahitm = (hhit->id()).ieta(); - int depthhit = (hhit->id()).depth(); - double enehit = hhit->energy() * recal; - - if (depthhit!=1) continue; - - - double distAtHcal = getDistInPlaneTrackDir(gPointHcal, trackMomAtHcal, pos); - //double distAtHcal = getDistInPlaneSimple(gPointHcal, pos); - - //if(drid()).iphi(); - int ietahitm2 = (hhit2->id()).ieta(); - int depthhit2 = (hhit2->id()).depth(); - double enehit2 = hhit2->energy() * recal; - - if ( iphihitm==iphihitm2 && ietahitm==ietahitm2 && depthhit!=depthhit2){ - - enehit = enehit+enehit2; + LogDebug("HcalIsoTrack") <<"This is the trigger we are looking for " + << triggerNames_[iHLT] << " Flag " << hlt + << ":" << ok; + } + } + + if (ok) { + unsigned int triggerindx = hltConfig_.triggerIndex(triggerNames_[iHLT]); + const std::vector& moduleLabels(hltConfig_.moduleLabels(triggerindx)); + std::vector vec[3]; + //loop over all trigger filters in event (i.e. filters passed) + for (unsigned int ifilter=0; ifilter Keys; + std::string label = triggerEvent.filterTag(ifilter).label(); + //loop over keys to objects passing this filter + for (unsigned int imodule=0; imodule MaxHit.hitenergy) - { - MaxHit.hitenergy = enehit; - MaxHit.ietahitm = (hhit->id()).ieta(); - MaxHit.iphihitm = (hhit->id()).iphi(); - MaxHit.depthhit = (hhit->id()).depth(); - MaxHit.dr = distAtHcal; - - MaxHit.posMax = geo->getPosition(hhit->detid()); - - } + LogDebug("HcalIsoTrack") << "sizes " << vec[0].size() << ":" + << vec[1].size() <<":" < energyMinIso && calEnergy < energyMaxIso && emEnergy < energyECALmip && - isoMatched->maxPtPxl() < maxPNear && abs(MaxHit.ietahitm)<30 && MaxHit.hitenergy > 0. && - MaxHit.dr < hottestHitDistance && emRingEnergy<8.){ passCuts = kTRUE; } - - - if(AxB_=="5x5" || AxB_=="3x3" || AxB_=="7x7"|| AxB_=="Cone") - { - - //clear usedHits - usedHits.clear(); - // - - for (HBHERecHitCollection::const_iterator hhit=Hithbhe.begin(); hhit!=Hithbhe.end(); hhit++) - { - - //check that this hit was not considered before and push it into usedHits - bool hitIsUsed=false; - DetId hitId=hhit->id(); - for (uint32_t i=0; iid()).ieta()<<" iphi: "<<(hhit->id()).iphi()<<" depth: "<<(hhit->id()).depth()<<" hashed_index: "<id()).ieta()>0) - { - DIETA = MaxHit.ietahitm - (hhit->id()).ieta(); - } - if(MaxHit.ietahitm*(hhit->id()).ieta()<0) - { - DIETA = MaxHit.ietahitm - (hhit->id()).ieta(); - DIETA = DIETA>0 ? DIETA-1 : DIETA+1; - } - - int DIPHI = abs(MaxHit.iphihitm - (hhit->id()).iphi()); - DIPHI = DIPHI>36 ? 72-DIPHI : DIPHI; - /*AP DIPHI = DIPHI<-36 ? 72+DIPHI : DIPHI; */ - - int numbercell=0; - if(AxB_=="3x3") numbercell = 1; - if(AxB_=="5x5") numbercell = 2; - if(AxB_=="7x7") numbercell = 3; - if(AxB_=="Cone") numbercell = 1000; - - if( abs(DIETA)<=numbercell && (abs(DIPHI)<=numbercell || ( abs(MaxHit.ietahitm)>=20 && abs(DIPHI)<=numbercell+1)) ) { - - // rof 16.05.2008 start: include the possibility for recalibration - float recal = 1; - - int iii3i5 = 0; - - const GlobalPoint pos2 = geo->getPosition(hhit->detid()); - - if(passCuts){ - - if(AxB_=="5x5" || AxB_=="3x3" || AxB_=="7x7") { - - rawEnergyVec.push_back(hhit->energy() * recal * corrHCAL); - detidvec.push_back(hhit->id()); - detiphi.push_back((hhit->id()).iphi()); - detieta.push_back((hhit->id()).ieta()); - i3i5.push_back(iii3i5); - - } - - if (AxB_=="Cone" && getDistInPlaneTrackDir(gPointHcal, trackMomAtHcal, pos2) < calibrationConeSize_) { - //if (AxB_=="Cone" && getDistInPlaneSimple(gPointHcal,pos2) < calibrationConeSize_) { - - rawEnergyVec.push_back(hhit->energy() * recal * corrHCAL); - detidvec.push_back(hhit->id()); - detiphi.push_back((hhit->id()).iphi()); - detieta.push_back((hhit->id()).ieta()); - i3i5.push_back(iii3i5); - - } - - } + } + double dr; + //// deta, dphi and dR for leading L1 object with L2 objects + math::XYZTLorentzVector mindRvec1; + double mindR1(999); + for (int lvl=1; lvl<3; lvl++) { + for (unsigned int i=0; iFill(); - - cells->Clear(); - - } - - rawEnergyVec.clear(); - detidvec.clear(); - detiphi.clear(); - detieta.clear(); - i3i5.clear(); - - try { - Handle ho; - iEvent.getByToken(tok_ho_,ho); - const HORecHitCollection Hitho = *(ho.product()); - - //clear usedHits - usedHits.clear(); - // - - for(HORecHitCollection::const_iterator hoItr=Hitho.begin(); hoItr!=Hitho.end(); hoItr++) - { - - //check that this hit was not considered before and push it into usedHits - bool hitIsUsed=false; - DetId hitId=hoItr->id(); - for (uint32_t i=0; i0) { + t_l3pt = vec[2][0].pt(); + t_l3eta = vec[2][0].eta(); + t_l3phi = vec[2][0].phi(); + } + //Loop over tracks + std::vector::const_iterator trkDetItr; + unsigned int nTracks(0), nselTracks(0); + for (trkDetItr = trkCaloDirections.begin(),nTracks=0; + trkDetItr != trkCaloDirections.end(); trkDetItr++,nTracks++) { + const reco::Track* pTrack = &(*(trkDetItr->trkItr)); + math::XYZTLorentzVector v4(pTrack->px(), pTrack->py(), + pTrack->pz(), pTrack->p()); + LogDebug("HcalIsoTrack") << "This track : " << nTracks + << " (pt|eta|phi|p) :" << pTrack->pt() + << "|" << pTrack->eta() << "|" + << pTrack->phi() << "|" << pTrack->p(); + math::XYZTLorentzVector mindRvec2; + t_mindR2 = 999; + + for (unsigned int k=0; kgetPosition(hoItr->detid()); - double phihit = pos.phi(); - double etahit = pos.eta(); - - int iphihitm = (hoItr->id()).iphi(); - int ietahitm = (hoItr->id()).ieta(); - int depthhit = (hoItr->id()).depth(); - - double dphi = fabs(trackPhi - phihit); - if(dphi > 4.*atan(1.)) dphi = 8.*atan(1.) - dphi; - double deta = fabs(trackEta - etahit); - double dr = sqrt(dphi*dphi + deta*deta); - */ + } + t_mindR1 = dR(vec[0][0],v4); + LogDebug("HcalIsoTrack") << "Closest L3 object at mindr :" + << t_mindR2 << " is " << mindRvec2 + << " and from L1 " << t_mindR1; + //Selection of good track + t_selectTk = spr::goodTrack(pTrack,leadPV,selectionParameters,false); + spr::trackSelectionParameters oneCutParameters = selectionParameters; + oneCutParameters.maxDxyPV = 10; + oneCutParameters.maxDzPV = 100; + oneCutParameters.maxInMiss = 2; + oneCutParameters.maxOutMiss= 2; + bool qltyFlag = spr::goodTrack(pTrack,leadPV,oneCutParameters,false); + oneCutParameters = selectionParameters; + oneCutParameters.maxDxyPV = 10; + oneCutParameters.maxDzPV = 100; + t_qltyMissFlag = spr::goodTrack(pTrack,leadPV,oneCutParameters,false); + oneCutParameters = selectionParameters; + oneCutParameters.maxInMiss = 2; + oneCutParameters.maxOutMiss= 2; + t_qltyPVFlag = spr::goodTrack(pTrack,leadPV,oneCutParameters,false); + t_ieta = 0; + if (trkDetItr->okHCAL) { + HcalDetId detId = (HcalDetId)(trkDetItr->detIdHCAL); + t_ieta = detId.ieta(); + } + LogDebug("HcalIsoTrack") << "qltyFlag|okECAL|okHCAL : " << qltyFlag + << "|" << trkDetItr->okECAL << "|" + << trkDetItr->okHCAL; + t_qltyFlag = (qltyFlag && trkDetItr->okECAL && trkDetItr->okHCAL); + t_p = pTrack->p(); + if (t_qltyFlag) { + nselTracks++; + int nRH_eMipDR(0), nNearTRKs(0), nRecHits(-999); + t_eMipDR = spr::eCone_ecal(geo, barrelRecHitsHandle, + endcapRecHitsHandle, + trkDetItr->pointHCAL, + trkDetItr->pointECAL, + a_mipR, trkDetItr->directionECAL, + nRH_eMipDR); + t_DetIds->clear(); t_HitEnergies->clear(); + std::vector ids; + t_eHcal = spr::eCone_hcal(geo, hbhe, trkDetItr->pointHCAL, + trkDetItr->pointECAL, a_coneR, + trkDetItr->directionHCAL,nRecHits, + ids, *t_HitEnergies); + for (unsigned int k=0; kpush_back(ids[k].rawId()); + } + t_hmaxNearP = spr::chargeIsolationCone(nTracks,trkCaloDirections, + a_charIsoR, nNearTRKs, + false); + LogDebug("HcalIsoTrack") << "This track : " << nTracks + << " (pt|eta|phi|p) :" << pTrack->pt() + << "|" << pTrack->eta() << "|" + << pTrack->phi() << "|" << t_p; + LogDebug("HcalIsoTrack") << "e_MIP " << t_eMipDR + << " Chg Isolation " << t_hmaxNearP + << " eHcal" << t_eHcal << " ieta " + << t_ieta << " Quality " + << t_qltyMissFlag << ":" + << t_qltyPVFlag << ":" << t_selectTk; + for (unsigned int lll=0;lllsize();lll++) { + LogDebug("HcalIsoTrack") << "det id is = " <at(lll) + << " hit enery is = " + << t_HitEnergies->at(lll) ; + } + if (t_p>pTrackMin_ && t_eMipDRFill(); + nGood++; + for (unsigned int k=0; ksize(); k++) + LogDebug("HcalIsoTrack") << "trigger bit is = " + << t_trgbits->at(k); + } + } } - } catch (cms::Exception& e) { // can't find it! - if (!allowMissingInputs_) throw e; + } + } + // check if trigger names in (new) config + if (changed) { + changed = false; + LogDebug("HcalIsoTrack") << "New trigger menu found !!!"; + const unsigned int n(hltConfig_.size()); + for (unsigned itrig=0; itrig= n) + LogDebug("HcalIsoTrack") << triggerNames_[itrig] << " " + << triggerindx << " does not exist in " + << "the current menu"; + else + LogDebug("HcalIsoTrack") << triggerNames_[itrig] << " " + << triggerindx << " exists"; + } } } + } } - - - -// ------------ method called once each job just before starting event loop ------------ -void -HcalIsoTrkAnalyzer::beginJob() -{ - - // MyL3Algo = new MinL3AlgoUniv(eventWeight); - - input_to_L3.open("input_to_l3.txt"); - - rootFile = new TFile("rootFile.root", "RECREATE"); - tree = new TTree("hcalCalibTree", "Tree for IsoTrack Calibration"); - cells = new TClonesArray("TCell", 10000); -// cells3x3 = new TRefArray; -// cellsPF = new TRefArray; -// exampleP4 = new TLorentzVector(); - tagJetP4 = new TLorentzVector(); // dijet - probeJetP4 = new TLorentzVector(); // dijet - - tree->Branch("cells", &cells, 64000, 0); - tree->Branch("targetE", &targetE, "targetE/F"); - tree->Branch("emEnergy", &emEnergy, "emEnergy/F"); - - tree->Branch("PxTrkHcal", &PxTrkHcal, "PxTrkHcal/F"); - tree->Branch("PyTrkHcal", &PyTrkHcal, "PyTrkHcal/F"); - tree->Branch("PzTrkHcal", &PzTrkHcal, "PzTrkHcal/F"); - - - tree->Branch("xTrkHcal", &xTrkHcal, "xTrkHcal/F"); - tree->Branch("yTrkHcal", &yTrkHcal, "yTrkHcal/F"); - tree->Branch("zTrkHcal", &zTrkHcal, "zTrkHcal/F"); - - tree->Branch("iEtaHit", &iEtaHit, "iEtaHit/I"); - tree->Branch("iPhiHit", &iPhiHit, "iPhiHit/i"); - tree->Branch("eventNumber", &eventNumber, "eventNumber/i"); - tree->Branch("runNumber", &runNumber, "runNumber/i"); - - tree->Branch("tagJetP4", "TLorentzVector", &tagJetP4); // dijet - tree->Branch("probeJetP4", "TLorentzVector", &probeJetP4); // dijet - tree->Branch("etVetoJet", &etVetoJet, "etVetoJet/F"); // dijet - tree->Branch("tagJetEmFrac", &tagJetEmFrac,"tagJetEmFrac/F"); // dijet - tree->Branch("probeJetEmFrac", &probeJetEmFrac,"probeJetEmFrac/F"); // dijet +void HcalIsoTrkAnalyzer::beginJob() { + + tree = fs->make("CalibTree", "CalibTree"); + + tree->Branch("t_Run", &t_Run, "t_Run/I"); + tree->Branch("t_Event", &t_Event, "t_Event/I"); + tree->Branch("t_ieta", &t_ieta, "t_ieta/I"); + tree->Branch("t_EventWeight", &t_EventWeight, "t_EventWeight/D"); + tree->Branch("t_l1pt", &t_l1pt, "t_l1pt/D"); + tree->Branch("t_l1eta", &t_l1eta, "t_l1eta/D"); + tree->Branch("t_l1phi", &t_l1phi, "t_l1phi/D"); + tree->Branch("t_l3pt", &t_l3pt, "t_l3pt/D"); + tree->Branch("t_l3eta", &t_l3eta, "t_l3eta/D"); + tree->Branch("t_l3phi", &t_l3phi, "t_l3phi/D"); + tree->Branch("t_p", &t_p, "t_p/D"); + tree->Branch("t_mindR1", &t_mindR1, "t_mindR1/D"); + tree->Branch("t_mindR2", &t_mindR2, "t_mindR2/D"); + tree->Branch("t_eMipDR", &t_eMipDR, "t_eMipDR/D"); + tree->Branch("t_eHcal", &t_eHcal, "t_eHcal/D"); + tree->Branch("t_hmaxNearP", &t_hmaxNearP, "t_hmaxNearP/D"); + tree->Branch("t_selectTk", &t_selectTk, "t_selectTk/O"); + tree->Branch("t_qltyFlag", &t_qltyFlag, "t_qltyFlag/O"); + tree->Branch("t_qltyMissFlag",&t_qltyMissFlag,"t_qltyMissFlag/O"); + tree->Branch("t_qltyPVFlag", &t_qltyPVFlag, "t_qltyPVFlag/O)"); + + t_DetIds = new std::vector(); + t_HitEnergies = new std::vector(); + t_trgbits = new std::vector(); + tree->Branch("t_DetIds", "std::vector", &t_DetIds); + tree->Branch("t_HitEnergies", "std::vector", &t_HitEnergies); + tree->Branch("t_trgbits","std::vector", &t_trgbits); } // ------------ method called once each job just after ending the event loop ------------ -void -HcalIsoTrkAnalyzer::endJob() { +void HcalIsoTrkAnalyzer::endJob() { + edm::LogInfo("HcalIsoTrack") << "Finds " << nGood << " good tracks in " + << nAll << " events from " << nRun << " runs"; + for (unsigned int k=0; kWrite(); - rootFile->Close(); +// ------------ method called when ending the processing of a run ------------ +void HcalIsoTrkAnalyzer::endRun(edm::Run const& iRun, edm::EventSetup const&) { + nRun++; + edm::LogInfo("HcalIsoTrack") << "endRun[" << nRun << "] " << iRun.run(); +} - if (cells) delete cells; -// if (cells3x3) delete cells3x3; -// if (cellsPF) delete cellsPF; -// if (exampleP4) delete exampleP4; - if (tagJetP4) delete tagJetP4; // dijet - if (probeJetP4) delete probeJetP4; // dijet +// ------------ method called when starting to processes a luminosity block ------------ +void HcalIsoTrkAnalyzer::beginLuminosityBlock(edm::LuminosityBlock const&, edm::EventSetup const&) {} +// ------------ method called when ending the processing of a luminosity block ------------ +void HcalIsoTrkAnalyzer::endLuminosityBlock(edm::LuminosityBlock const&, edm::EventSetup const&) {} +// ------------ method fills 'descriptions' with the allowed parameters for the module ------------ +void HcalIsoTrkAnalyzer::fillDescriptions(edm::ConfigurationDescriptions& descriptions) { + //The following says we do not know what parameters are allowed so do no validation + // Please change this to state exactly what you do use, even if it is no parameters + edm::ParameterSetDescription desc; + desc.setUnknown(); + descriptions.addDefault(desc); +} +double HcalIsoTrkAnalyzer::dR(math::XYZTLorentzVector& vec1, math::XYZTLorentzVector& vec2) { + return reco::deltaR(vec1.eta(),vec1.phi(),vec2.eta(),vec2.phi()); } //define this as a plug-in diff --git a/Calibration/HcalCalibAlgos/src/RecAnalyzerMinbias.cc b/Calibration/HcalCalibAlgos/src/RecAnalyzerMinbias.cc new file mode 100644 index 0000000000000..5612e21e453f8 --- /dev/null +++ b/Calibration/HcalCalibAlgos/src/RecAnalyzerMinbias.cc @@ -0,0 +1,279 @@ +// system include files +#include +#include +#include +#include +#include +#include +#include + +// user include files +#include "CondFormats/DataRecord/interface/HcalRespCorrsRcd.h" +#include "CondFormats/HcalObjects/interface/HcalRespCorrs.h" +#include "FWCore/Common/interface/TriggerNames.h" +#include "FWCore/Framework/interface/EDAnalyzer.h" +#include "FWCore/Framework/interface/ESHandle.h" +#include "FWCore/Framework/interface/Event.h" +#include "FWCore/Framework/interface/EventSetup.h" +#include "FWCore/Framework/interface/Frameworkfwd.h" +#include "FWCore/MessageLogger/interface/MessageLogger.h" +#include "FWCore/ParameterSet/interface/ParameterSet.h" +#include "DataFormats/Common/interface/TriggerResults.h" +#include "DataFormats/HcalDetId/interface/HcalDetId.h" +#include "DataFormats/HcalDetId/interface/HcalSubdetector.h" +#include "DataFormats/HcalRecHit/interface/HcalRecHitCollections.h" +#include "DataFormats/L1GlobalTrigger/interface/L1GlobalTriggerObjectMap.h" +#include "DataFormats/L1GlobalTrigger/interface/L1GlobalTriggerObjectMapRecord.h" + +#include "TFile.h" +#include "TTree.h" + +#define debugLog + +// class declaration +class RecAnalyzerMinbias : public edm::EDAnalyzer { + +public: + explicit RecAnalyzerMinbias(const edm::ParameterSet&); + ~RecAnalyzerMinbias(); + virtual void analyze(const edm::Event&, const edm::EventSetup&); + virtual void beginJob() ; + virtual void endJob() ; + +private: + void analyzeHcal(const HBHERecHitCollection&, const HFRecHitCollection&, + const HcalRespCorrs*, int); + + // ----------member data --------------------------- + std::string fOutputFileName ; + bool theRecalib, ignoreL1; + TFile* hOutputFile ; + TTree* myTree; + + // Root tree members + double rnnum, rnnumber; + int mysubd, depth, iphi, ieta, cells, trigbit; + float mom0_MB, mom1_MB, mom2_MB, mom3_MB, mom4_MB; + struct myInfo{ + double theMB0, theMB1, theMB2, theMB4, runcheck; + void MyInfo() { + theMB0 = theMB1 = theMB2 = theMB4 = runcheck = 0; + } + }; + std::map,myInfo> myMap; + edm::EDGetTokenT tok_hbherecoMB_; + edm::EDGetTokenT tok_hfrecoMB_; + edm::EDGetTokenT tok_hltL1GtMap_; +}; + +// constructors and destructor +RecAnalyzerMinbias::RecAnalyzerMinbias(const edm::ParameterSet& iConfig) { + + // get name of output file with histogramms + fOutputFileName = iConfig.getUntrackedParameter("HistOutFile"); + theRecalib = iConfig.getParameter("Recalib"); + ignoreL1 = iConfig.getUntrackedParameter("IgnoreL1", false); + + // get token names of modules, producing object collections + tok_hbherecoMB_ = consumes(iConfig.getParameter("hbheInputMB")); + tok_hfrecoMB_ = consumes(iConfig.getParameter("hfInputMB")); + + tok_hltL1GtMap_ = consumes(edm::InputTag("hltL1GtObjectMap")); +} + +RecAnalyzerMinbias::~RecAnalyzerMinbias() {} + +void RecAnalyzerMinbias::beginJob() { + + hOutputFile = new TFile( fOutputFileName.c_str(), "RECREATE" ) ; + myTree = new TTree("RecJet","RecJet Tree"); + myTree->Branch("cells", &cells, "cells/I"); + myTree->Branch("mysubd", &mysubd, "mysubd/I"); + myTree->Branch("depth", &depth, "depth/I"); + myTree->Branch("ieta", &ieta, "ieta/I"); + myTree->Branch("iphi", &iphi, "iphi/I"); + myTree->Branch("mom0_MB", &mom0_MB, "mom0_MB/F"); + myTree->Branch("mom1_MB", &mom1_MB, "mom1_MB/F"); + myTree->Branch("mom2_MB", &mom2_MB, "mom2_MB/F"); + myTree->Branch("mom4_MB", &mom4_MB, "mom4_MB/F"); + myTree->Branch("trigbit", &trigbit, "trigbit/I"); + myTree->Branch("rnnumber", &rnnumber, "rnnumber/D"); + myMap.clear(); + return ; +} + +// EndJob +// + +void RecAnalyzerMinbias::endJob() { + cells = 0; + for (std::map,myInfo>::const_iterator itr=myMap.begin(); itr != myMap.end(); ++itr) { +#ifdef debugLog + std::cout << "Fired trigger bit number " << itr->first.first << std::endl; +#endif + myInfo info = itr->second; + if (info.theMB0 > 0) { + mom0_MB = info.theMB0; + mom1_MB = info.theMB1; + mom2_MB = info.theMB2; + mom4_MB = info.theMB4; + rnnumber = info.runcheck; + trigbit = itr->first.first; + mysubd = itr->first.second.subdet(); + depth = itr->first.second.depth(); + iphi = itr->first.second.iphi(); + ieta = itr->first.second.ieta(); +#ifdef debugLog + std::cout << " Result= " << trigbit << " " << mysubd << " " << ieta + << " " << iphi << " mom0 " << mom0_MB << " mom1 " << mom1_MB + << " mom2 " << mom2_MB << " mom4 " << mom4_MB << std::endl; +#endif + myTree->Fill(); + cells++; + } + } +#ifdef debugLog + std::cout << "cells" << " " << cells << std::endl; +#endif + hOutputFile->Write(); + hOutputFile->cd(); + myTree->Write(); + hOutputFile->Close() ; +} + +// +// member functions +// +// ------------ method called to produce the data ------------ + +void RecAnalyzerMinbias::analyze(const edm::Event& iEvent, const edm::EventSetup& iSetup) { + + rnnum = (float)iEvent.run(); + const HcalRespCorrs* myRecalib=0; + if (theRecalib ) { + edm::ESHandle recalibCorrs; + iSetup.get().get("recalibrate",recalibCorrs); + myRecalib = recalibCorrs.product(); + } // theRecalib + + edm::Handle hbheMB; + iEvent.getByToken(tok_hbherecoMB_, hbheMB); + if (!hbheMB.isValid()) { + edm::LogInfo("AnalyzerMB") << "HcalCalibAlgos: Error! can't get hbhe product!"; + return ; + } + const HBHERecHitCollection HithbheMB = *(hbheMB.product()); +#ifdef debugLog + std::cout << "HBHE MB size of collection " << HithbheMB.size() << std::endl; +#endif + if (HithbheMB.size() < 5100) { + edm::LogWarning("AnalyzerMB") << "HBHE problem " << rnnum << " size " + << HithbheMB.size(); + return; + } + + edm::Handle hfMB; + iEvent.getByToken(tok_hfrecoMB_, hfMB); + if (!hfMB.isValid()) { + edm::LogInfo("AnalyzerMB") << "HcalCalibAlgos: Error! can't get hbhe product!"; + return ; + } + const HFRecHitCollection HithfMB = *(hfMB.product()); +#ifdef debugLog + std::cout << "HF MB size of collection " << HithfMB.size() << std::endl; +#endif + if (HithfMB.size() < 1700) { + edm::LogWarning("AnalyzerMB") << "HF problem " << rnnum << " size " + << HithfMB.size(); + return; + } + + if (ignoreL1) { + analyzeHcal(HithbheMB, HithfMB, myRecalib, 1); + } else { + edm::Handle gtObjectMapRecord; + iEvent.getByToken(tok_hltL1GtMap_, gtObjectMapRecord); + if (gtObjectMapRecord.isValid()) { + const std::vector& objMapVec = gtObjectMapRecord->gtObjectMap(); + bool ok(false); + for (std::vector::const_iterator itMap = objMapVec.begin(); + itMap != objMapVec.end(); ++itMap) { + bool resultGt = (*itMap).algoGtlResult(); + if (resultGt) { + int algoBit = (*itMap).algoBitNumber(); + analyzeHcal(HithbheMB, HithfMB, myRecalib, algoBit); + ok = true; + } + } + if (!ok) { +#ifdef debugLog + std::cout << "No passed L1 Trigger found" << std::endl; +#endif + } + } + } +} + +void RecAnalyzerMinbias::analyzeHcal(const HBHERecHitCollection & HithbheMB, + const HFRecHitCollection & HithfMB, + const HcalRespCorrs* myRecalib, + int algoBit) { + // Signal part for HB HE + for (HBHERecHitCollection::const_iterator hbheItr=HithbheMB.begin(); + hbheItr!=HithbheMB.end(); hbheItr++) { + // Recalibration of energy + float icalconst=1.; + DetId mydetid = hbheItr->id().rawId(); + if (theRecalib) icalconst = myRecalib->getValues(mydetid)->getValue(); + HBHERecHit aHit(hbheItr->id(),hbheItr->energy()*icalconst,hbheItr->time()); + double energyhit = aHit.energy(); + DetId id = (*hbheItr).detid(); + HcalDetId hid = HcalDetId(id); + + std::map,myInfo>::iterator itr1 = myMap.find(std::pair(algoBit,hid)); + if (itr1 == myMap.end()) { + myInfo info; + myMap[std::pair(algoBit,hid)] = info; + itr1 = myMap.find(std::pair(algoBit,hid)); + } + itr1->second.theMB0++; + itr1->second.theMB1 += energyhit; + itr1->second.theMB2 += (energyhit*energyhit); + itr1->second.theMB4 += (energyhit*energyhit*energyhit*energyhit); + itr1->second.runcheck = rnnum; + } // HBHE_MB + + // Signal part for HF + for (HFRecHitCollection::const_iterator hfItr=HithfMB.begin(); + hfItr!=HithfMB.end(); hfItr++) { + // Recalibration of energy + float icalconst=1.; + DetId mydetid = hfItr->id().rawId(); + if (theRecalib) icalconst = myRecalib->getValues(mydetid)->getValue(); + HFRecHit aHit(hfItr->id(),hfItr->energy()*icalconst,hfItr->time()); + + double energyhit = aHit.energy(); + DetId id = (*hfItr).detid(); + HcalDetId hid = HcalDetId(id); + // + // Remove PMT hits + // + if (fabs(energyhit) > 40.) continue; + + std::map,myInfo>::iterator itr1 = myMap.find(std::pair(algoBit,hid)); + if (itr1 == myMap.end()) { + myInfo info; + myMap[std::pair(algoBit,hid)] = info; + itr1 = myMap.find(std::pair(algoBit,hid)); + } + itr1->second.theMB0++; + itr1->second.theMB1 += energyhit; + itr1->second.theMB2 += (energyhit*energyhit); + itr1->second.theMB4 += (energyhit*energyhit*energyhit*energyhit); + itr1->second.runcheck = rnnum; + } +} + +//define this as a plug-in +#include "FWCore/Framework/interface/MakerMacros.h" +DEFINE_FWK_MODULE(RecAnalyzerMinbias); diff --git a/Calibration/HcalCalibAlgos/src/SealModule.cc b/Calibration/HcalCalibAlgos/src/SealModule.cc index 8ace1eee029f2..d81ddcad9dfb5 100644 --- a/Calibration/HcalCalibAlgos/src/SealModule.cc +++ b/Calibration/HcalCalibAlgos/src/SealModule.cc @@ -1,27 +1,17 @@ #include "FWCore/PluginManager/interface/ModuleDef.h" #include "FWCore/Framework/interface/MakerMacros.h" #include "Calibration/HcalCalibAlgos/interface/Analyzer_minbias.h" -#include "Calibration/HcalCalibAlgos/src/GammaJetAnalysis.h" -#include "Calibration/HcalCalibAlgos/interface/DiJetAnalyzer.h" #include "Calibration/HcalCalibAlgos/interface/HcalConstantsASCIIWriter.h" #include "Calibration/HcalCalibAlgos/src/HitReCalibrator.h" #include "Calibration/HcalCalibAlgos/interface/HcalCalibrator.h" using cms::Analyzer_minbias; -using cms::GammaJetAnalysis; -using cms::DiJetAnalyzer; using cms::HcalConstantsASCIIWriter; using cms::HitReCalibrator; -//using cms::HcalCalibrator; - - DEFINE_FWK_MODULE(Analyzer_minbias); -DEFINE_FWK_MODULE(GammaJetAnalysis); -DEFINE_FWK_MODULE(DiJetAnalyzer); DEFINE_FWK_MODULE(HcalConstantsASCIIWriter); DEFINE_FWK_MODULE(HitReCalibrator); -//DEFINE_FWK_MODULE(HcalCalibrator); diff --git a/Calibration/HcalCalibAlgos/src/SimAnalyzerMinbias.cc b/Calibration/HcalCalibAlgos/src/SimAnalyzerMinbias.cc new file mode 100644 index 0000000000000..fb4463b55a795 --- /dev/null +++ b/Calibration/HcalCalibAlgos/src/SimAnalyzerMinbias.cc @@ -0,0 +1,214 @@ +// system include files +#include +#include +#include +#include +#include +#include +#include + +// user include files +#include "FWCore/Framework/interface/Frameworkfwd.h" +#include "FWCore/Framework/interface/EDAnalyzer.h" +#include "FWCore/Framework/interface/Event.h" +#include "FWCore/Framework/interface/EventSetup.h" +#include "FWCore/Framework/interface/EDProducer.h" +#include "FWCore/ParameterSet/interface/ParameterSet.h" +#include "FWCore/MessageLogger/interface/MessageLogger.h" + +#include "CondFormats/HcalObjects/interface/HcalRespCorrs.h" +#include "CondFormats/DataRecord/interface/HcalRespCorrsRcd.h" +#include "CondFormats/DataRecord/interface/L1GtTriggerMenuRcd.h" +#include "CondFormats/L1TObjects/interface/L1GtTriggerMenu.h" + +#include "DataFormats/DetId/interface/DetId.h" +#include "DataFormats/HcalDetId/interface/HcalSubdetector.h" +#include "DataFormats/HcalDetId/interface/HcalDetId.h" +#include "SimDataFormats/CaloHit/interface/PCaloHitContainer.h" +#include "SimDataFormats/GeneratorProducts/interface/HepMCProduct.h" + +#include "EventFilter/HcalRawToDigi/interface/HcalDCCHeader.h" + +#include "TFile.h" +#include "TTree.h" + +// class declaration +class SimAnalyzerMinbias : public edm::EDAnalyzer { + +public: + explicit SimAnalyzerMinbias(const edm::ParameterSet&); + ~SimAnalyzerMinbias(); + virtual void analyze(const edm::Event&, const edm::EventSetup&); + virtual void beginJob() ; + virtual void endJob() ; + virtual void beginRun(const edm::Run& r, const edm::EventSetup& iSetup); + virtual void endRun(const edm::Run& r, const edm::EventSetup& iSetup); + +private: + + // ----------member data --------------------------- + std::string fOutputFileName ; + double timeCut; + TFile* hOutputFile ; + TTree* myTree; + + // Root tree members + int mydet, mysubd, depth, iphi, ieta, cells; + float mom0_MB, mom1_MB, mom2_MB, mom3_MB, mom4_MB; + struct myInfo{ + double theMB0, theMB1, theMB2, theMB4; + void MyInfo() { + theMB0 = theMB1 = theMB2 = theMB4 = 0; + } + }; + std::map myMap; + edm::EDGetTokenT tok_evt_; + edm::EDGetTokenT tok_hcal_; +}; + +// constructors and destructor + +SimAnalyzerMinbias::SimAnalyzerMinbias(const edm::ParameterSet& iConfig) { + // get name of output file with histogramms + fOutputFileName = iConfig.getUntrackedParameter("HistOutFile", "simOutput.root"); + timeCut = iConfig.getUntrackedParameter("TimeCut", 500); + + // get token names of modules, producing object collections + tok_evt_ = consumes(edm::InputTag("generator")); + tok_hcal_ = consumes(edm::InputTag("g4SimHits","HcalHits")); +} + +SimAnalyzerMinbias::~SimAnalyzerMinbias() { + // do anything here that needs to be done at desctruction time + // (e.g. close files, deallocate resources etc.) +} + +void SimAnalyzerMinbias::beginRun( const edm::Run& r, const edm::EventSetup& iSetup) { +} + +void SimAnalyzerMinbias::endRun( const edm::Run& r, const edm::EventSetup& iSetup) { +} + +void SimAnalyzerMinbias::beginJob() { + hOutputFile = new TFile( fOutputFileName.c_str(), "RECREATE" ) ; + + myTree = new TTree("SimJet","SimJet Tree"); + myTree->Branch("mydet", &mydet, "mydet/I"); + myTree->Branch("mysubd", &mysubd, "mysubd/I"); + myTree->Branch("cells", &cells, "cells"); + myTree->Branch("depth", &depth, "depth/I"); + myTree->Branch("ieta", &ieta, "ieta/I"); + myTree->Branch("iphi", &iphi, "iphi/I"); + myTree->Branch("mom0_MB", &mom0_MB, "mom0_MB/F"); + myTree->Branch("mom1_MB", &mom1_MB, "mom1_MB/F"); + myTree->Branch("mom2_MB", &mom2_MB, "mom2_MB/F"); + myTree->Branch("mom4_MB", &mom4_MB, "mom4_MB/F"); + + myMap.clear(); + return ; +} + +// EndJob +// +void SimAnalyzerMinbias::endJob() { + + cells = 0; + // std::cout << " Hello me here" << std::endl; + for (std::map::const_iterator itr=myMap.begin(); + itr != myMap.end(); ++itr) { + // std::cout << " Hello me here" << std::endl; + mysubd = itr->first.subdet(); + depth = itr->first.depth(); + iphi = itr->first.iphi(); + ieta = itr->first.ieta(); + myInfo info = itr->second; + if (info.theMB0 > 0) { + mom0_MB = info.theMB0; + mom1_MB = info.theMB1; + mom2_MB = info.theMB2; + mom4_MB = info.theMB4; + cells++; + + edm::LogInfo("AnalyzerMB") << " Result= " << mysubd << " " << ieta << " " + << iphi << " mom0 " << mom0_MB << " mom1 " + << mom1_MB << " mom2 " << mom2_MB << " mom4 " + << mom4_MB; + myTree->Fill(); + } + } + edm::LogInfo("AnalyzerMB") << "cells" << " " << cells; + hOutputFile->cd(); + myTree->Write(); + hOutputFile->Write(); + hOutputFile->Close() ; + return ; +} + +// +// member functions +// + +// ------------ method called to produce the data ------------ + +void SimAnalyzerMinbias::analyze(const edm::Event& iEvent, + const edm::EventSetup&) { + + //std::cout<<" Start SimAnalyzerMinbias::analyze "< evtMC; + iEvent.getByToken(tok_evt_, evtMC); + if (!evtMC.isValid()) { + edm::LogInfo("AnalyzerMB") << "no HepMCProduct found"; + } else { + const HepMC::GenEvent * myGenEvent = evtMC->GetEvent(); + edm::LogInfo("AnalyzerMB") << "Event with " << myGenEvent->particles_size() + << " particles + " << myGenEvent->vertices_size() + << " vertices"; + } + + + edm::Handle hcalHits; + iEvent.getByToken(tok_hcal_,hcalHits); + if (!hcalHits.isValid()) { + edm::LogInfo("AnalyzerMB") << "Error! can't get HcalHits product!"; + return ; + } + + const edm::PCaloHitContainer * HitHcal = hcalHits.product () ; + std::map hitMap; + for (std::vector::const_iterator hcalItr = HitHcal->begin (); + hcalItr != HitHcal->end(); ++hcalItr) { + double time = hcalItr->time(); + if (time < timeCut) { + double energyhit = hcalItr->energy(); + HcalDetId hid = HcalDetId(hcalItr->id()); + std::map::iterator itr1 = hitMap.find(hid); + if (itr1 == hitMap.end()) { + hitMap[hid] = 0; + itr1 = hitMap.find(hid); + } + itr1->second += energyhit; + } + } + + for (std::map::const_iterator hcalItr=hitMap.begin(); + hcalItr != hitMap.end(); ++hcalItr) { + HcalDetId hid = hcalItr->first; + double energyhit = hcalItr->second; + std::map::iterator itr1 = myMap.find(hid); + if (itr1 == myMap.end()) { + myInfo info; + myMap[hid] = info; + itr1 = myMap.find(hid); + } + itr1->second.theMB0++; + itr1->second.theMB1 += energyhit; + itr1->second.theMB2 += (energyhit*energyhit); + itr1->second.theMB4 += (energyhit*energyhit*energyhit*energyhit); + } +} + +//define this as a plug-in +#include "FWCore/Framework/interface/MakerMacros.h" +DEFINE_FWK_MODULE(SimAnalyzerMinbias); + diff --git a/Calibration/HcalCalibAlgos/test/analysis_rec_minbias_cfg.py b/Calibration/HcalCalibAlgos/test/analysis_rec_minbias_cfg.py new file mode 100644 index 0000000000000..11e0854778aa9 --- /dev/null +++ b/Calibration/HcalCalibAlgos/test/analysis_rec_minbias_cfg.py @@ -0,0 +1,92 @@ +import FWCore.ParameterSet.Config as cms + +process = cms.Process('RecAna') + +# import of standard configurations +process.load('Configuration.StandardSequences.Services_cff') +process.load('Geometry.HcalEventSetup.HcalTopology_cfi') +process.load('FWCore.MessageService.MessageLogger_cfi') +process.load('Configuration.StandardSequences.GeometryExtended_cff') +process.load('Configuration.StandardSequences.MagneticField_38T_cff') +process.load('Configuration.StandardSequences.RawToDigi_Data_cff') +process.load('Configuration.StandardSequences.EndOfProcess_cff') +process.load('Configuration.StandardSequences.FrontierConditions_GlobalTag_cff') +process.load('RecoLocalCalo.Configuration.RecoLocalCalo_cff') +process.load('RecoLocalCalo.Configuration.hcalLocalRecoNZS_cff') +process.load('Calibration.HcalAlCaRecoProducers.ALCARECOHcalCalMinBias_cff') + + +process.configurationMetadata = cms.untracked.PSet( + version = cms.untracked.string('$Revision: 1.163 $'), + annotation = cms.untracked.string('Reconstruction.py nevts:10'), + name = cms.untracked.string('PyReleaseValidation') + ) +process.maxEvents = cms.untracked.PSet( + input = cms.untracked.int32(-1) + ) +process.options = cms.untracked.PSet( + + ) +# Input source +process.source = cms.Source("PoolSource", + fileNames = cms.untracked.vstring( + 'root://cmsxrootd.fnal.gov//store/data/Run2012C/HcalNZS/RAW/v1/000/203/522/F233228C-D206-E211-BC2E-0025901D629C.root', + 'root://cmsxrootd.fnal.gov//store/data/Run2012C/HcalNZS/RAW/v1/000/197/556/D673F957-93C0-E111-8332-003048D2BF1C.root', + 'root://cmsxrootd.fnal.gov//store/data/Run2012C/HcalNZS/RAW/v1/000/198/941/3AA08F69-9ECD-E111-A338-5404A63886C5.root', + 'root://cmsxrootd.fnal.gov//store/data/Run2012C/HcalNZS/RAW/v1/000/197/601/BAC19C2C-3EC1-E111-8A78-001D09F241B9.root', + 'root://cmsxrootd.fnal.gov//store/data/Run2012C/HcalNZS/RAW/v1/000/197/610/F68235DD-01C1-E111-9583-0019B9F72CE5.root', + 'root://cmsxrootd.fnal.gov//store/data/Run2012C/HcalNZS/RAW/v1/000/197/719/2AADB426-7BC1-E111-9053-001D09F24353.root', + 'root://cmsxrootd.fnal.gov//store/data/Run2012A/HcalNZS/RAW/v1/000/190/456/88BBA906-3B7F-E111-BD13-001D09F2441B.root', + 'root://cmsxrootd.fnal.gov//store/data/Run2012C/HcalNZS/RAW/v1/000/199/975/24F29491-FADA-E111-A19B-BCAEC5329716.root', + ) +) + +############################################################################ +process.load("Configuration.StandardSequences.FrontierConditions_GlobalTag_cff") +from Configuration.AlCa.autoCond import autoCond +process.GlobalTag.globaltag = autoCond['startup'] #data + +process.es_pool = cms.ESSource("PoolDBESSource", + process.CondDBSetup, + timetype = cms.string('runnumber'), + toGet = cms.VPSet( + cms.PSet( + record = cms.string("HcalRespCorrsRcd"), + tag = cms.string("HcalRespCorrs_v4.5_offline")), + + cms.PSet( + record = cms.string('HcalGainsRcd'), + tag = cms.string('HcalGains_v5.07_offline')), + + ), + connect = cms.string('frontier://FrontierProd/CMS_COND_31X_HCAL'), + authenticationMethod = cms.untracked.uint32(0), + ) +process.es_prefer_es_pool = cms.ESPrefer( "PoolDBESSource", "es_pool") + +############################################################################ +#### Analysis + +process.minbiasana = cms.EDAnalyzer("Analyzer_minbias", + HistOutFile = cms.untracked.string('recanalyzer.root'), + hbheInputMB = cms.InputTag("hbherecoMB"), + hoInputMB = cms.InputTag("horecoMB"), + hfInputMB = cms.InputTag("hfrecoMBspecial"), + hbheInputNoise = cms.InputTag("hbherecoNoise"), + hoInputNoise = cms.InputTag("horecoNoise"), + hfInputNoise = cms.InputTag("hfrecoNoise"), + triglabel=cms.untracked.InputTag('TriggerResults','','HLT'), + Recalib = cms.bool(False) + ) + +process.schedule = cms.Path( + process.hcalDigis* + process.gtDigis* + process.hcalLocalRecoSequenceNZS* + process.seqALCARECOHcalCalMinBiasNoHLT* + process.minbiasana* + process.endOfProcess + ) + + + diff --git a/Calibration/HcalCalibAlgos/test/analysis_sim_minbias_cfg.py b/Calibration/HcalCalibAlgos/test/analysis_sim_minbias_cfg.py new file mode 100644 index 0000000000000..b64592be2fd78 --- /dev/null +++ b/Calibration/HcalCalibAlgos/test/analysis_sim_minbias_cfg.py @@ -0,0 +1,77 @@ +import FWCore.ParameterSet.Config as cms + +process = cms.Process('SimAna') + +# import of standard configurations +process.load('Configuration.StandardSequences.Services_cff') +process.load('Configuration.StandardSequences.GeometryExtended_cff') +process.load('Configuration.StandardSequences.MagneticField_38T_cff') +process.load('Configuration.StandardSequences.RawToDigi_Data_cff') +process.load('Configuration.StandardSequences.EndOfProcess_cff') +process.load('Configuration.StandardSequences.FrontierConditions_GlobalTag_cff') +process.load('RecoLocalCalo.Configuration.RecoLocalCalo_cff') +process.load('RecoLocalCalo.Configuration.hcalLocalRecoNZS_cff') +process.load('Geometry.HcalEventSetup.HcalTopology_cfi') +process.load('Calibration.HcalAlCaRecoProducers.ALCARECOHcalCalMinBias_cff') + + +process.load("FWCore.MessageLogger.MessageLogger_cfi") +process.MessageLogger.cerr.FwkReport.reportEvery = 1000 + + +process.configurationMetadata = cms.untracked.PSet( + version = cms.untracked.string('$Revision: 1.163 $'), + annotation = cms.untracked.string('Reconstruction.py nevts:10'), + name = cms.untracked.string('PyReleaseValidation') + ) +process.maxEvents = cms.untracked.PSet( + input = cms.untracked.int32(-1) + ) +process.options = cms.untracked.PSet( + + ) + +# Input source +process.source = cms.Source("PoolSource", + fileNames = cms.untracked.vstring( + 'root://cmsxrootd.fnal.gov//store/data/Run2012C/HcalNZS/RAW/v1/000/197/559/FA519929-93C0-E111-9C4A-BCAEC532971C.root', + ) +) + +############################################################################ +process.load("Configuration.StandardSequences.FrontierConditions_GlobalTag_cff") +from Configuration.AlCa.autoCond import autoCond +process.GlobalTag.globaltag = autoCond['startup'] #data + +process.es_pool = cms.ESSource("PoolDBESSource", + process.CondDBSetup, + timetype = cms.string('runnumber'), + toGet = cms.VPSet( + cms.PSet( + record = cms.string("HcalRespCorrsRcd"), + tag = cms.string("HcalRespCorrs_v4.5_offline")), + + cms.PSet( + record = cms.string('HcalGainsRcd'), + tag = cms.string('HcalGains_v5.07_offline')), + + ), + connect = cms.string('frontier://FrontierProd/CMS_COND_31X_HCAL'), + authenticationMethod = cms.untracked.uint32(0), + ) +process.es_prefer_es_pool = cms.ESPrefer( "PoolDBESSource", "es_pool") + +############################################################################ +#### Analysis + +process.minbiasana = cms.EDAnalyzer("SimAnalyzerMinbias", + HistOutFile = cms.untracked.string('simanalyzer.root'), + TimeCut = cms.untracked.double(100.0) + ) + +process.schedule = cms.Path( + process.minbiasana* + process.endOfProcess + ) + + diff --git a/Calibration/HcalCalibAlgos/test/dijetanalyzer_cfg.py b/Calibration/HcalCalibAlgos/test/dijetanalyzer_cfg.py new file mode 100644 index 0000000000000..0795761c6da32 --- /dev/null +++ b/Calibration/HcalCalibAlgos/test/dijetanalyzer_cfg.py @@ -0,0 +1,45 @@ +import FWCore.ParameterSet.Config as cms + +process = cms.Process('DIJETANALYSIS') + +process.load('FWCore.MessageService.MessageLogger_cfi') + +process.load('Configuration.StandardSequences.Services_cff') +process.load('Configuration.StandardSequences.FrontierConditions_GlobalTag_cff') +from Configuration.AlCa.autoCond import autoCond +process.load("Configuration.Geometry.GeometryIdeal_cff") +process.GlobalTag.globaltag=autoCond['startup'] + +#load the response corrections calculator +process.load('Calibration.HcalCalibAlgos.diJetAnalyzer_cfi') +process.load('JetMETCorrections.Configuration.JetCorrectionProducers_cff') + +# run over files + +process.source = cms.Source("PoolSource", fileNames = cms.untracked.vstring( + '/store/relval/CMSSW_7_3_0/RelValQCD_Pt_80_120_13/GEN-SIM-RECO/MCRUN2_73_V9_71XGENSIM_FIXGT-v1/00000/8E758AAA-4DA2-E411-8068-003048FFCB96.root', + '/store/relval/CMSSW_7_3_0/RelValQCD_Pt_80_120_13/GEN-SIM-RECO/MCRUN2_73_V9_71XGENSIM_FIXGT-v1/00000/CE0DAE28-56A2-E411-AEFF-003048FFD79C.root', + '/store/relval/CMSSW_7_3_0/RelValQCD_Pt_80_120_13/GEN-SIM-RECO/MCRUN2_73_V9_71XGENSIM_FIXGT-v1/00000/D4D21D16-56A2-E411-A0C4-0026189438E2.root' + )) + +#print readFiles + +process.maxEvents = cms.untracked.PSet( input = cms.untracked.int32(-1) ) +process.MessageLogger.cerr.FwkReport.reportEvery=cms.untracked.int32(1000) +process.options = cms.untracked.PSet( wantSummary = cms.untracked.bool(True) ) + +# Load pfNoPileUP + +#process.load("CommonTools.ParticleFlow.pfNoPileUp_cff") +#process.load("CommonTools.ParticleFlow.PF2PAT_cff") +#from RecoJets.JetProducers.ak5PFJets_cfi import * +#process.ak5PFJetsCHS = ak5PFJets.clone( +# src = cms.InputTag("pfNoPileUp") +# ) +#process.load('HcalClosureTest.Analyzers.calcrespcorr_CHSJECs_cff') + +# timing +#process.Timing = cms.Service('Timing') + +#process.p = cms.Path(process.pfNoPileUpSequence+process.PF2PAT+process.ak5PFJetsCHS+process.calcrespcorrdijets) +process.p = cms.Path(process.diJetAnalyzer) diff --git a/Calibration/HcalCalibAlgos/test/gammaJetAnalysis_cfg.py b/Calibration/HcalCalibAlgos/test/gammaJetAnalysis_cfg.py new file mode 100644 index 0000000000000..3bbd13ec45958 --- /dev/null +++ b/Calibration/HcalCalibAlgos/test/gammaJetAnalysis_cfg.py @@ -0,0 +1,85 @@ +import FWCore.ParameterSet.Config as cms +process = cms.Process('ANALYSIS') + +process.load('FWCore.MessageService.MessageLogger_cfi') +process.load('Configuration.StandardSequences.Services_cff') +process.load('Configuration.StandardSequences.FrontierConditions_GlobalTag_cff') + +#process.MessageLogger.messages = cms.untracked.PSet( +# threshold = cms.untracked.vstring('DEBUG') +#) + +process.load("Configuration.Geometry.GeometryIdeal_cff") +process.load("MagneticField.Engine.autoMagneticFieldProducer_cfi") +from Configuration.AlCa.autoCond import autoCond +process.GlobalTag.globaltag=autoCond['startup'] + +# Specify IdealMagneticField ESSource (needed for CMSSW 730) + +#load the response corrections calculator +process.load('Calibration.HcalCalibAlgos.gammaJetAnalysis_cfi') +# needed for nonCHS +process.load('JetMETCorrections.Configuration.JetCorrectionProducers_cff') + +# run over files +process.GammaJetAnalysis.rootHistFilename = cms.string('PhoJet_tree_CHS_ported.root') +process.GammaJetAnalysis.doPFJets = cms.bool(True) +process.GammaJetAnalysis.doGenJets = cms.bool(True) + +# trigger names should not end with '_' +process.GammaJetAnalysis.photonTriggers = cms.vstring( + 'HLT_Photon20_CaloIdVL_IsoL','HLT_Photon30_CaloIdVL_IsoL', + 'HLT_Photon50_CaloIdVL_IsoL','HLT_Photon75_CaloIdVL_IsoL', + 'HLT_Photon90_CaloIdVL_IsoL','HLT_Photon135', + 'HLT_Photon150','HLT_Photon160') +# triggers for CMSSW 730 +process.GammaJetAnalysis.photonTriggers += cms.vstring( + 'HLT_Photon22', 'HLT_Photon30', 'HLT_Photon36', + 'HLT_Photon50', 'HLT_Photon75', + 'HLT_Photon90', 'HLT_Photon120', 'HLT_Photon175', + 'HLT_Photon250_NoHE', 'HLT_Photon300_NoHE' +) +# to disable photonTriggers assign an empty vstring +#process.GammaJetAnalysis.photonTriggers = cms.vstring() + +# a clone without CHS +process.GammaJetAnalysis_noCHS= process.GammaJetAnalysis.clone() +process.GammaJetAnalysis_noCHS.rootHistFilename = cms.string('PhoJet_tree_nonCHS_ported.root') +# for 7XY use ak4* instead of ak5 +process.GammaJetAnalysis_noCHS.pfJetCollName = cms.string('ak4PFJets') +process.GammaJetAnalysis_noCHS.pfJetCorrName = cms.string('ak4PFL2L3') + +process.source = cms.Source("PoolSource", + fileNames = cms.untracked.vstring( +# '/store/relval/CMSSW_7_3_0/RelValPhotonJets_Pt_10_13/GEN-SIM-RECO/MCRUN2_73_V7-v1/00000/522CE329-7B81-E411-B6C3-0025905A6110.root', +# '/store/relval/CMSSW_7_3_0/RelValPhotonJets_Pt_10_13/GEN-SIM-RECO/MCRUN2_73_V7-v1/00000/5279D224-7B81-E411-BCAA-002618943930.root' + 'file:../../HcalAlCaRecoProducers/test/gjet.root' + ) +) + +process.maxEvents = cms.untracked.PSet( input = cms.untracked.int32(-1) ) +#process.MessageLogger.cerr.threshold = cms.untracked.string('DEBUG') # does not work? +process.MessageLogger.cerr.FwkReport.reportEvery=cms.untracked.int32(500) +process.MessageLogger.cerr.FwkReport.reportEvery=cms.untracked.int32(1) +process.options = cms.untracked.PSet( wantSummary = cms.untracked.bool(False) ) + +# Load pfNoPileUP +#process.load("CommonTools.ParticleFlow.pfNoPileUp_cff") +#process.load("CommonTools.ParticleFlow.PF2PAT_cff") +#from RecoJets.JetProducers.ak5PFJets_cfi import * +#process.ak5PFJetsCHS = ak5PFJets.clone( +# src = cms.InputTag("pfNoPileUp") +#) + +#process.load('Calibration.HcalCalibAlgos.gammaJetAnalysis_CHSJECs_cff') + +# specify 'workOnAOD=2' to apply tokens from GammaJetProd producer +process.GammaJetAnalysis.workOnAOD = cms.int32(2) +process.GammaJetAnalysis.doGenJets = cms.bool(False) +process.GammaJetAnalysis.debug = cms.untracked.int32(1) + +process.p = cms.Path( +# process.PF2PAT +# +process.ak5PFJetsCHS + process.GammaJetAnalysis +) diff --git a/Calibration/HcalCalibAlgos/test/gammaJetAnalysis_noGJetProd_cfg.py b/Calibration/HcalCalibAlgos/test/gammaJetAnalysis_noGJetProd_cfg.py new file mode 100644 index 0000000000000..de1031605954b --- /dev/null +++ b/Calibration/HcalCalibAlgos/test/gammaJetAnalysis_noGJetProd_cfg.py @@ -0,0 +1,62 @@ +import FWCore.ParameterSet.Config as cms +process = cms.Process('ANALYSIS') + +process.load('FWCore.MessageService.MessageLogger_cfi') +process.load('Configuration.StandardSequences.Services_cff') +process.load('Configuration.StandardSequences.FrontierConditions_GlobalTag_cff') + +process.load("Configuration.Geometry.GeometryIdeal_cff") +process.load("MagneticField.Engine.autoMagneticFieldProducer_cfi") +from Configuration.AlCa.autoCond import autoCond +process.GlobalTag.globaltag=autoCond['startup'] + +# Specify IdealMagneticField ESSource (needed for CMSSW 730) + +#load the response corrections calculator +process.load('Calibration.HcalCalibAlgos.gammaJetAnalysis_cfi') +# needed for nonCHS +process.load('JetMETCorrections.Configuration.JetCorrectors_cff') +process.load('JetMETCorrections.Configuration.JetCorrectionProducers_cff') + +# run over files +process.GammaJetAnalysis.rootHistFilename = cms.string('PhoJet_tree_CHS_ported_noGJetProd.root') +process.GammaJetAnalysis.doPFJets = cms.bool(True) +process.GammaJetAnalysis.doGenJets = cms.bool(True) + +# trigger names should not end with '_' +process.GammaJetAnalysis.photonTriggers = cms.vstring( + 'HLT_Photon20_CaloIdVL_IsoL','HLT_Photon30_CaloIdVL_IsoL', + 'HLT_Photon50_CaloIdVL_IsoL','HLT_Photon75_CaloIdVL_IsoL', + 'HLT_Photon90_CaloIdVL_IsoL','HLT_Photon135', + 'HLT_Photon150','HLT_Photon160') +# triggers for CMSSW 730 +process.GammaJetAnalysis.photonTriggers += cms.vstring( + 'HLT_Photon22', 'HLT_Photon30', 'HLT_Photon36', + 'HLT_Photon50', 'HLT_Photon75', + 'HLT_Photon90', 'HLT_Photon120', 'HLT_Photon175', + 'HLT_Photon250_NoHE', 'HLT_Photon300_NoHE' +) +# to disable photonTriggers assign an empty vstring +#process.GammaJetAnalysis.photonTriggers = cms.vstring() + +# a clone without CHS +process.GammaJetAnalysis_noCHS= process.GammaJetAnalysis.clone() +process.GammaJetAnalysis_noCHS.rootHistFilename = cms.string('PhoJet_tree_nonCHS_ported_noGJetProd.root') +# for 7XY use ak4* instead of ak5 +process.GammaJetAnalysis_noCHS.pfJetCollName = cms.string('ak4PFJets') +process.GammaJetAnalysis_noCHS.pfJetCorrName = cms.string('ak4PFL2L3') + +process.source = cms.Source("PoolSource", + fileNames = cms.untracked.vstring( + 'file:/tmp/andriusj/6EC8FCC8-E2A8-E411-9506-002590596468.root' +# '/store/relval/CMSSW_7_4_0_pre6/RelValPhotonJets_Pt_10_13/GEN-SIM-RECOMCRUN2_74_V1-v1/00000/6EC8FCC8-E2A8-E411-9506-002590596468.root' + ) +) + +process.maxEvents = cms.untracked.PSet( input = cms.untracked.int32(-1) ) +process.MessageLogger.cerr.FwkReport.reportEvery=cms.untracked.int32(500) +process.options = cms.untracked.PSet( wantSummary = cms.untracked.bool(False) ) + +process.p = cms.Path( + process.GammaJetAnalysis +) diff --git a/Calibration/HcalCalibAlgos/test/hcalHBHEMuon_cfg.py b/Calibration/HcalCalibAlgos/test/hcalHBHEMuon_cfg.py new file mode 100644 index 0000000000000..3119f503a6b4d --- /dev/null +++ b/Calibration/HcalCalibAlgos/test/hcalHBHEMuon_cfg.py @@ -0,0 +1,24 @@ +import FWCore.ParameterSet.Config as cms + +process = cms.Process("RaddamMuon") + +process.load("FWCore.MessageService.MessageLogger_cfi") +process.load("Configuration.Geometry.GeometryIdeal_cff") +process.load("Configuration.StandardSequences.MagneticField_cff") +process.load("Configuration.StandardSequences.FrontierConditions_GlobalTag_cff") +process.load("RecoLocalCalo.EcalRecAlgos.EcalSeverityLevelESProducer_cfi") +process.load("Calibration.HcalCalibAlgos.hcalHBHEMuon_cfi") +process.GlobalTag.globaltag = cms.string('GR_R_70_V2::All') + +process.maxEvents = cms.untracked.PSet( input = cms.untracked.int32(-1) ) +process.source = cms.Source("PoolSource", + fileNames = cms.untracked.vstring( + 'root://xrootd.unl.edu//store/mc/Phys14DR/DYToMuMu_M-50_Tune4C_13TeV-pythia8/GEN-SIM-RECO/PU20bx25_tsg_castor_PHYS14_25_V1-v1/10000/184C1AC9-A775-E411-9196-002590200824.root' + ) + ) + +process.TFileService = cms.Service("TFileService", + fileName = cms.string("Validation.root") +) + +process.p = cms.Path(process.HcalHBHEMuonAnalyzer) diff --git a/DataFormats/HcalIsolatedTrack/interface/HcalIsolatedTrackCandidate.h b/DataFormats/HcalIsolatedTrack/interface/HcalIsolatedTrackCandidate.h new file mode 100644 index 0000000000000..18c6f0db3af9f --- /dev/null +++ b/DataFormats/HcalIsolatedTrack/interface/HcalIsolatedTrackCandidate.h @@ -0,0 +1,130 @@ +#ifndef HcalIsolatedTrack_HcalIsolatedTrackCandidate_h +#define HcalIsolatedTrack_HcalIsolatedTrackCandidate_h +/** \class reco::HcalIsolatedTrackCandidate + * + * + */ + +#include "DataFormats/RecoCandidate/interface/RecoCandidate.h" +#include "DataFormats/TrackReco/interface/Track.h" +#include "DataFormats/L1Trigger/interface/L1JetParticle.h" +#include "DataFormats/L1Trigger/interface/L1JetParticleFwd.h" +#include "DataFormats/Math/interface/LorentzVector.h" +#include "DataFormats/HcalIsolatedTrack/interface/HcalIsolatedTrackCandidateFwd.h" + +#include +#include +#include + +namespace reco { + + class HcalIsolatedTrackCandidate: public RecoCandidate { + + public: + + // default constructor + HcalIsolatedTrackCandidate() : RecoCandidate() { + maxP_ =-1; + enEcal_ =-1; + ptL1_ =etaL1_ =phiL1_=0; + etaEcal_=phiEcal_=0; + etaHcal_=phiHcal_=ietaHcal_=iphiHcal_=0; + etaPhiEcal_=etaPhiHcal_=false; + } + ///constructor from LorentzVector + HcalIsolatedTrackCandidate(const LorentzVector& v): RecoCandidate(0,v) { + maxP_ =-1; + enEcal_ =-1; + ptL1_ =etaL1_ =phiL1_=0; + etaEcal_=phiEcal_=0; + etaHcal_=phiHcal_=ietaHcal_=iphiHcal_=0; + etaPhiEcal_=etaPhiHcal_=false; + } + /// constructor from a track + HcalIsolatedTrackCandidate(const reco::TrackRef & tr, double max, double ene): + RecoCandidate( 0, LorentzVector((tr.get()->px()),(tr.get())->py(),(tr.get())->pz(),(tr.get())->p()) ), + track_(tr), maxP_(max), enEcal_(ene) { + ptL1_ =etaL1_ =phiL1_=0; + etaEcal_=phiEcal_=0; + etaHcal_=phiHcal_=ietaHcal_=iphiHcal_=0; + etaPhiEcal_=etaPhiHcal_=false; + } + /// Copy constructor + HcalIsolatedTrackCandidate(const HcalIsolatedTrackCandidate&); + + /// destructor + virtual ~HcalIsolatedTrackCandidate(); + + /// returns a clone of the candidate + virtual HcalIsolatedTrackCandidate * clone() const; + + /// refrence to a Track + virtual reco::TrackRef track() const; + void setTrack(const reco::TrackRef & tr) { track_ = tr; } + + /// highest energy of other tracks in the cone around the candidate + double maxP() const {return maxP_;} + void SetMaxP(double mp) {maxP_=mp;} + + /// get reference to L1 jet + virtual l1extra::L1JetParticleRef l1jet() const; + void setL1Jet(const l1extra::L1JetParticleRef & jetRef) { l1Jet_ = jetRef; } + std::pair EtaPhiL1() const { + return std::pair(etaL1_,phiL1_); + } + math::XYZTLorentzVector l1jetp() const; + void setL1(double pt, double eta, double phi) { + ptL1_ = pt; etaL1_ = eta; phiL1_ = phi; + } + + /// ECAL energy in the inner cone around tau jet + double energyEcal() const {return enEcal_;} + void SetEnergyEcal(double a) {enEcal_=a;} + + ///eta, phi at ECAL surface + void SetEtaPhiEcal(double eta, double phi) { + etaEcal_=eta; phiEcal_=phi; etaPhiEcal_=true; + } + std::pair EtaPhiEcal() const { + return ((etaPhiEcal_) ? std::pair(etaEcal_,phiEcal_) : std::pair(0,0)); + } + bool etaPhiEcal() const {return etaPhiEcal_;} + + ///eta, phi at HCAL surface + void SetEtaPhiHcal(double eta, double phi, int ieta, int iphi) { + etaHcal_=eta; phiHcal_=phi; ietaHcal_=ieta; iphiHcal_=iphi; etaPhiHcal_=true; + } + std::pair EtaPhiHcal() const { + return ((etaPhiHcal_) ? std::pair(etaHcal_,phiHcal_) : std::pair(0,0)); + } + std::pair towerIndex() const { + return ((etaPhiHcal_) ? std::pair(ietaHcal_,iphiHcal_) : std::pair(0,0)); + } + bool etaPhiHcal() const {return etaPhiHcal_;} + + private: + /// check overlap with another candidate + virtual bool overlap( const Candidate & ) const; + /// reference to a Track + reco::TrackRef track_; + /// reference to a L1 tau jet + l1extra::L1JetParticleRef l1Jet_; + /// highest P of other tracks in the cone around the candidate + double maxP_; + /// energy in ECAL around a cone around the track + double enEcal_; + /// pt, eta, phi of L1 object + double ptL1_, etaL1_, phiL1_; + /// eta, phi at ECAL + bool etaPhiEcal_; + double etaEcal_, phiEcal_; + /// eta, phi at HCAL + bool etaPhiHcal_; + double etaHcal_, phiHcal_; + int ietaHcal_, iphiHcal_; + }; + + +} + +#endif diff --git a/DataFormats/HcalIsolatedTrack/interface/HcalIsolatedTrackCandidateFwd.h b/DataFormats/HcalIsolatedTrack/interface/HcalIsolatedTrackCandidateFwd.h new file mode 100644 index 0000000000000..d6f38a983aabe --- /dev/null +++ b/DataFormats/HcalIsolatedTrack/interface/HcalIsolatedTrackCandidateFwd.h @@ -0,0 +1,30 @@ +#ifndef HcalIsolatedTrack_HcalIsolatedTrackCandidateFwd_h +#define HcalIsolatedTrack_HcalIsolatedTrackCandidateFwd_h +#include +#include "DataFormats/Common/interface/Ref.h" +#include "DataFormats/Common/interface/RefProd.h" +#include "DataFormats/Common/interface/RefVector.h" + +namespace reco { + class HcalIsolatedTrackCandidate; + + /// collectin of HcalIsolatedTrackCandidate objects + typedef std::vector HcalIsolatedTrackCandidateCollection; + + /// reference to an object in a collection of HcalIsolatedTrackCandidate objects + typedef edm::Ref HcalIsolatedTrackCandidateRef; + + /// reference to a collection of HcalIsolatedTrackCandidate objects + typedef edm::RefProd HcalIsolatedTrackCandidateRefProd; + + /// vector of objects in the same collection of HcalIsolatedTrackCandidate objects + typedef edm::RefVector HcalIsolatedTrackCandidateRefVector; + + /// iterator over a vector of reference to HcalIsolatedTrackCandidate objects + typedef HcalIsolatedTrackCandidateRefVector::iterator HcalIsolatedTrackCandidateIterator; + + typedef std::vector HcalIsolatedTrackCandidateSimpleRefVector; +} + +#endif + diff --git a/DataFormats/HcalIsolatedTrack/src/HcalIsolatedTrackCandidate.cc b/DataFormats/HcalIsolatedTrack/src/HcalIsolatedTrackCandidate.cc new file mode 100644 index 0000000000000..6105b5eefe637 --- /dev/null +++ b/DataFormats/HcalIsolatedTrack/src/HcalIsolatedTrackCandidate.cc @@ -0,0 +1,45 @@ +#include "DataFormats/HcalIsolatedTrack/interface/HcalIsolatedTrackCandidate.h" + +using namespace reco; + +HcalIsolatedTrackCandidate::HcalIsolatedTrackCandidate(const HcalIsolatedTrackCandidate& right) : RecoCandidate(right), track_(right.track_), l1Jet_(right.l1Jet_) { + maxP_ = right.maxP_; + enEcal_ = right.enEcal_; + ptL1_ = right.ptL1_; + etaL1_ = right.etaL1_; + phiL1_ = right.phiL1_; + etaPhiEcal_= right.etaPhiEcal_; + etaEcal_ = right.etaEcal_; + phiEcal_ = right.phiEcal_; + etaPhiHcal_= right.etaPhiHcal_; + etaHcal_ = right.etaHcal_; + phiHcal_ = right.phiHcal_; + ietaHcal_ = right.ietaHcal_; + iphiHcal_ = right.iphiHcal_; +} + +HcalIsolatedTrackCandidate::~HcalIsolatedTrackCandidate() { } + +HcalIsolatedTrackCandidate * HcalIsolatedTrackCandidate::clone() const { + return new HcalIsolatedTrackCandidate( * this ); +} + +reco::TrackRef HcalIsolatedTrackCandidate::track() const { + return track_; +} + +l1extra::L1JetParticleRef HcalIsolatedTrackCandidate::l1jet() const { + return l1Jet_; +} + +math::XYZTLorentzVector HcalIsolatedTrackCandidate::l1jetp() const { + double pL1_ = ptL1_*cosh(etaL1_); + math::XYZTLorentzVector pL1(ptL1_*cos(phiL1_), ptL1_*sin(phiL1_), + pL1_*tanh(etaL1_), pL1_); + return pL1; +} + +bool HcalIsolatedTrackCandidate::overlap( const Candidate & c ) const { + const RecoCandidate * o = dynamic_cast( & c ); + return ( o != 0 && checkOverlap( track(), o->track() ) ); +} diff --git a/DataFormats/HcalIsolatedTrack/src/classes.h b/DataFormats/HcalIsolatedTrack/src/classes.h index 0d4832ee6bf76..984900484a557 100644 --- a/DataFormats/HcalIsolatedTrack/src/classes.h +++ b/DataFormats/HcalIsolatedTrack/src/classes.h @@ -1,4 +1,5 @@ #include "DataFormats/Common/interface/Wrapper.h" +#include "DataFormats/HcalIsolatedTrack/interface/HcalIsolatedTrackCandidate.h" #include "DataFormats/HcalIsolatedTrack/interface/IsolatedPixelTrackCandidate.h" #include "DataFormats/HcalIsolatedTrack/interface/EcalIsolatedParticleCandidate.h" namespace DataFormats_HcalIsolatedTrack { @@ -6,23 +7,33 @@ namespace DataFormats_HcalIsolatedTrack { edm::Wrapper > > w2; - reco::IsolatedPixelTrackCandidate ptc1; - reco::IsolatedPixelTrackCandidateCollection ptc_c1; - reco::IsolatedPixelTrackCandidateRef ptc_r1; - reco::IsolatedPixelTrackCandidateRefProd ptc_rp1; - reco::IsolatedPixelTrackCandidateRefVector ptc_rv1; - edm::Wrapper ptc_wc1; + reco::IsolatedPixelTrackCandidate ptc1; + reco::IsolatedPixelTrackCandidateCollection ptc_c1; + reco::IsolatedPixelTrackCandidateRef ptc_r1; + reco::IsolatedPixelTrackCandidateRefProd ptc_rp1; + reco::IsolatedPixelTrackCandidateRefVector ptc_rv1; + edm::Wrapper ptc_wc1; edm::reftobase::Holder ptc_h1; - edm::Ref ptc_sr1; - reco::IsolatedPixelTrackCandidateSimpleRefVector ptc_srv1; + edm::Ref ptc_sr1; + reco::IsolatedPixelTrackCandidateSimpleRefVector ptc_srv1; - reco::EcalIsolatedParticleCandidate ptc2; - reco::EcalIsolatedParticleCandidateCollection ptc_c2; - reco::EcalIsolatedParticleCandidateRef ptc_r2; - reco::EcalIsolatedParticleCandidateRefProd ptc_rp2; - reco::EcalIsolatedParticleCandidateRefVector ptc_rv2; - edm::Wrapper ptc_wc2; + reco::EcalIsolatedParticleCandidate ptc2; + reco::EcalIsolatedParticleCandidateCollection ptc_c2; + reco::EcalIsolatedParticleCandidateRef ptc_r2; + reco::EcalIsolatedParticleCandidateRefProd ptc_rp2; + reco::EcalIsolatedParticleCandidateRefVector ptc_rv2; + edm::Wrapper ptc_wc2; edm::reftobase::Holder ptc_h2; + reco::HcalIsolatedTrackCandidate ptc3; + reco::HcalIsolatedTrackCandidateCollection ptc_c3; + reco::HcalIsolatedTrackCandidateRef ptc_r3; + reco::HcalIsolatedTrackCandidateRefProd ptc_rp3; + reco::HcalIsolatedTrackCandidateRefVector ptc_rv3; + edm::Wrapper ptc_wc3; + edm::reftobase::Holder ptc_h3; + edm::Ref ptc_sr3; + reco::HcalIsolatedTrackCandidateSimpleRefVector ptc_srv3; + }; } diff --git a/DataFormats/HcalIsolatedTrack/src/classes_def.xml b/DataFormats/HcalIsolatedTrack/src/classes_def.xml index d1f5342f62ab6..1c9ac0386232f 100644 --- a/DataFormats/HcalIsolatedTrack/src/classes_def.xml +++ b/DataFormats/HcalIsolatedTrack/src/classes_def.xml @@ -36,4 +36,17 @@ + + + + + + + + + + + + +