Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 11:58:46

0001 // system include files
0002 #include <memory>
0003 #include <string>
0004 #include <iostream>
0005 
0006 // user include files
0007 
0008 #include "DataFormats/Provenance/interface/StableProvenance.h"
0009 #include "DataFormats/MuonReco/interface/Muon.h"
0010 #include "DataFormats/GeometryVector/interface/GlobalPoint.h"
0011 #include "DataFormats/HcalCalibObjects/interface/HOCalibVariables.h"
0012 #include "DataFormats/TrackReco/interface/TrackExtra.h"
0013 #include "DataFormats/TrackReco/interface/TrackExtraFwd.h"
0014 // collections
0015 #include "DataFormats/HcalRecHit/interface/HcalRecHitCollections.h"
0016 #include "DataFormats/EcalRecHit/interface/EcalRecHitCollections.h"
0017 #include "DataFormats/JetReco/interface/CaloJetCollection.h"
0018 #include "DataFormats/HcalCalibObjects/interface/HOCalibVariableCollection.h"
0019 #include "DataFormats/EgammaReco/interface/SuperCluster.h"
0020 #include "DataFormats/EgammaReco/interface/SuperClusterFwd.h"
0021 #include "DataFormats/TrackReco/interface/Track.h"
0022 #include "DataFormats/TrackReco/interface/TrackFwd.h"
0023 #include "DataFormats/MuonReco/interface/MuonFwd.h"
0024 
0025 #include "FWCore/Framework/interface/Frameworkfwd.h"
0026 #include "FWCore/Framework/interface/one/EDAnalyzer.h"
0027 #include "FWCore/Framework/interface/Event.h"
0028 #include "FWCore/Framework/interface/MakerMacros.h"
0029 #include "FWCore/Framework/interface/EventSetup.h"
0030 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0031 #include "FWCore/ParameterSet/interface/ConfigurationDescriptions.h"
0032 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0033 
0034 #include "Geometry/Records/interface/CaloGeometryRecord.h"
0035 #include "Geometry/CaloGeometry/interface/CaloGeometry.h"
0036 #include "Geometry/HcalTowerAlgo/interface/HcalGeometry.h"
0037 
0038 #include "RecoTracker/TrackProducer/interface/TrackProducerBase.h"
0039 #include "TrackingTools/TransientTrack/interface/TransientTrack.h"
0040 
0041 namespace cms {
0042 
0043   //
0044   // class declaration
0045   //
0046 
0047   class ProducerAnalyzer : public edm::one::EDAnalyzer<> {
0048   public:
0049     explicit ProducerAnalyzer(const edm::ParameterSet&);
0050     ~ProducerAnalyzer() override = default;
0051 
0052     void analyze(const edm::Event&, const edm::EventSetup&) override;
0053     void beginJob() override {}
0054     void endJob() override {}
0055     static void fillDescriptions(edm::ConfigurationDescriptions& descriptions);
0056 
0057   private:
0058     // ----------member data ---------------------------
0059     std::string nameProd_;
0060     std::string jetCalo_;
0061     std::string gammaClus_;
0062     std::string ecalInput_;
0063     std::string hbheInput_;
0064     std::string hoInput_;
0065     std::string hfInput_;
0066     std::string tracks_;
0067 
0068     edm::EDGetTokenT<HOCalibVariableCollection> tok_hovar_;
0069     edm::EDGetTokenT<HORecHitCollection> tok_horeco_;
0070     edm::EDGetTokenT<HORecHitCollection> tok_ho_;
0071     edm::EDGetTokenT<HORecHitCollection> tok_hoProd_;
0072 
0073     edm::EDGetTokenT<HFRecHitCollection> tok_hf_;
0074 
0075     edm::EDGetTokenT<reco::CaloJetCollection> tok_jets_;
0076     edm::EDGetTokenT<reco::SuperClusterCollection> tok_gamma_;
0077     edm::EDGetTokenT<reco::MuonCollection> tok_muons_;
0078     edm::EDGetTokenT<EcalRecHitCollection> tok_ecal_;
0079     edm::EDGetTokenT<reco::TrackCollection> tok_tracks_;
0080 
0081     edm::EDGetTokenT<HBHERecHitCollection> tok_hbhe_;
0082     edm::EDGetTokenT<HBHERecHitCollection> tok_hbheProd_;
0083 
0084     edm::ESGetToken<CaloGeometry, CaloGeometryRecord> tok_geom_;
0085   };
0086 }  // end namespace cms
0087 
0088 using namespace reco;
0089 
0090 namespace cms {
0091 
0092   //
0093   // constructors and destructor
0094   //
0095   ProducerAnalyzer::ProducerAnalyzer(const edm::ParameterSet& iConfig) {
0096     // get name of output file with histogramms
0097 
0098     nameProd_ = iConfig.getUntrackedParameter<std::string>("nameProd");
0099     jetCalo_ = iConfig.getUntrackedParameter<std::string>("jetCalo", "GammaJetJetBackToBackCollection");
0100     gammaClus_ = iConfig.getUntrackedParameter<std::string>("gammaClus");
0101     ecalInput_ = iConfig.getUntrackedParameter<std::string>("ecalInput");
0102     hbheInput_ = iConfig.getUntrackedParameter<std::string>("hbheInput");
0103     hoInput_ = iConfig.getUntrackedParameter<std::string>("hoInput");
0104     hfInput_ = iConfig.getUntrackedParameter<std::string>("hfInput");
0105     tracks_ = iConfig.getUntrackedParameter<std::string>("Tracks");
0106 
0107     tok_hovar_ = consumes<HOCalibVariableCollection>(edm::InputTag(nameProd_, hoInput_));
0108     tok_horeco_ = consumes<HORecHitCollection>(edm::InputTag("horeco"));
0109     tok_ho_ = consumes<HORecHitCollection>(edm::InputTag(hoInput_));
0110     tok_hoProd_ = consumes<HORecHitCollection>(edm::InputTag(nameProd_, hoInput_));
0111 
0112     tok_hf_ = consumes<HFRecHitCollection>(edm::InputTag(hfInput_));
0113 
0114     tok_jets_ = consumes<reco::CaloJetCollection>(edm::InputTag(nameProd_, jetCalo_));
0115     tok_gamma_ = consumes<reco::SuperClusterCollection>(edm::InputTag(nameProd_, gammaClus_));
0116     tok_muons_ = consumes<reco::MuonCollection>(edm::InputTag(nameProd_, "SelectedMuons"));
0117     tok_ecal_ = consumes<EcalRecHitCollection>(edm::InputTag(nameProd_, ecalInput_));
0118     tok_tracks_ = consumes<reco::TrackCollection>(edm::InputTag(nameProd_, tracks_));
0119 
0120     tok_hbheProd_ = consumes<HBHERecHitCollection>(edm::InputTag(nameProd_, hbheInput_));
0121     tok_hbhe_ = consumes<HBHERecHitCollection>(edm::InputTag(hbheInput_));
0122 
0123     tok_geom_ = esConsumes<CaloGeometry, CaloGeometryRecord>();
0124   }
0125 
0126   //
0127   // member functions
0128   //
0129 
0130   // ------------ method called to produce the data  ------------
0131   void ProducerAnalyzer::analyze(const edm::Event& iEvent, const edm::EventSetup& iSetup) {
0132     using namespace edm;
0133 
0134     const CaloGeometry* geo = &(iSetup.getData(tok_geom_));
0135 
0136     std::vector<StableProvenance const*> theProvenance;
0137     iEvent.getAllStableProvenance(theProvenance);
0138     for (auto const& provenance : theProvenance) {
0139       edm::LogVerbatim("HcalAlCa") << " Print all module/label names " << provenance->moduleName() << " "
0140                                    << provenance->moduleLabel() << " " << provenance->productInstanceName();
0141     }
0142 
0143     if (nameProd_ == "hoCalibProducer") {
0144       auto const& ho = iEvent.getHandle(tok_hovar_);
0145       const HOCalibVariableCollection Hitho = *(ho.product());
0146       edm::LogVerbatim("HcalAlCa") << " Size of HO " << (Hitho).size();
0147     }
0148 
0149     if (nameProd_ == "ALCARECOMuAlZMuMu") {
0150       auto const& ho = iEvent.getHandle(tok_horeco_);
0151       const HORecHitCollection Hitho = *(ho.product());
0152       edm::LogVerbatim("HcalAlCa") << " Size of HO " << (Hitho).size();
0153       auto const& mucand = iEvent.getHandle(tok_muons_);
0154       edm::LogVerbatim("HcalAlCa") << " Size of muon collection " << mucand->size();
0155       for (const auto& it : *(mucand.product())) {
0156         TrackRef mu = it.combinedMuon();
0157         edm::LogVerbatim("HcalAlCa") << " Pt muon " << mu->innerMomentum();
0158       }
0159     }
0160 
0161     if (nameProd_ != "IsoProd" && nameProd_ != "ALCARECOMuAlZMuMu" && nameProd_ != "hoCalibProducer") {
0162       auto const& hbhe = iEvent.getHandle(tok_hbhe_);
0163       const HBHERecHitCollection Hithbhe = *(hbhe.product());
0164       edm::LogVerbatim("HcalAlCa") << " Size of HBHE " << (Hithbhe).size();
0165 
0166       auto const& ho = iEvent.getHandle(tok_ho_);
0167       const HORecHitCollection Hitho = *(ho.product());
0168       edm::LogVerbatim("HcalAlCa") << " Size of HO " << (Hitho).size();
0169 
0170       auto const& hf = iEvent.getHandle(tok_hf_);
0171       const HFRecHitCollection Hithf = *(hf.product());
0172       edm::LogVerbatim("HcalAlCa") << " Size of HF " << (Hithf).size();
0173     }
0174     if (nameProd_ == "IsoProd") {
0175       edm::LogVerbatim("HcalAlCa") << " We are here ";
0176       auto const& tracks = iEvent.getHandle(tok_tracks_);
0177 
0178       edm::LogVerbatim("HcalAlCa") << " Tracks size " << (*tracks).size();
0179       for (const auto& track : *(tracks.product())) {
0180         edm::LogVerbatim("HcalAlCa") << " P track " << track.p() << " eta " << track.eta() << " phi " << track.phi()
0181                                      << " Outer " << track.outerMomentum() << " " << track.outerPosition();
0182         const TrackExtraRef& myextra = track.extra();
0183         edm::LogVerbatim("HcalAlCa") << " Track extra " << myextra->outerMomentum() << " " << myextra->outerPosition();
0184       }
0185 
0186       auto const& ecal = iEvent.getHandle(tok_ecal_);
0187       const EcalRecHitCollection Hitecal = *(ecal.product());
0188       edm::LogVerbatim("HcalAlCa") << " Size of Ecal " << (Hitecal).size();
0189 
0190       double energyECAL = 0.;
0191       double energyHCAL = 0.;
0192 
0193       for (const auto& hite : *(ecal.product())) {
0194         const GlobalPoint& posE = geo->getPosition(hite.detid());
0195 
0196         edm::LogVerbatim("HcalAlCa") << " Energy ECAL " << hite.energy() << " eta " << posE.eta() << " phi "
0197                                      << posE.phi();
0198 
0199         energyECAL = energyECAL + hite.energy();
0200       }
0201 
0202       auto const& hbhe = iEvent.getHandle(tok_hbheProd_);
0203       const HBHERecHitCollection Hithbhe = *(hbhe.product());
0204       edm::LogVerbatim("HcalAlCa") << " Size of HBHE " << (Hithbhe).size();
0205 
0206       for (const auto& hith : *(hbhe.product())) {
0207         GlobalPoint posH =
0208             (static_cast<const HcalGeometry*>(geo->getSubdetectorGeometry(hith.detid())))->getPosition(hith.detid());
0209 
0210         edm::LogVerbatim("HcalAlCa") << " Energy HCAL " << hith.energy() << " eta " << posH.eta() << " phi "
0211                                      << posH.phi();
0212 
0213         energyHCAL = energyHCAL + hith.energy();
0214       }
0215 
0216       edm::LogVerbatim("HcalAlCa") << " Energy ECAL " << energyECAL << " Energy HCAL " << energyHCAL;
0217     }
0218 
0219     if (nameProd_ == "GammaJetProd" || nameProd_ == "DiJProd") {
0220       edm::LogVerbatim("HcalAlCa") << " we are in GammaJetProd area ";
0221       auto const& ecal = iEvent.getHandle(tok_ecal_);
0222       edm::LogVerbatim("HcalAlCa") << " Size of ECAL " << (*ecal).size();
0223 
0224       auto const& jets = iEvent.getHandle(tok_jets_);
0225       edm::LogVerbatim("HcalAlCa") << " Jet size " << (*jets).size();
0226 
0227       for (const auto& jet : *(jets.product())) {
0228         edm::LogVerbatim("HcalAlCa") << " Et jet " << jet.et() << " eta " << jet.eta() << " phi " << jet.phi();
0229       }
0230 
0231       auto const& tracks = iEvent.getHandle(tok_tracks_);
0232       edm::LogVerbatim("HcalAlCa") << " Tracks size " << (*tracks).size();
0233     }
0234     if (nameProd_ == "GammaJetProd") {
0235       auto const& eclus = iEvent.getHandle(tok_gamma_);
0236       edm::LogVerbatim("HcalAlCa") << " GammaClus size " << (*eclus).size();
0237       for (const auto& iclus : *(eclus.product())) {
0238         edm::LogVerbatim("HcalAlCa") << " Et gamma " << iclus.energy() / cosh(iclus.eta()) << " eta " << iclus.eta()
0239                                      << " phi " << iclus.phi();
0240       }
0241     }
0242   }
0243 
0244   void ProducerAnalyzer::fillDescriptions(edm::ConfigurationDescriptions& descriptions) {
0245     edm::ParameterSetDescription desc;
0246     desc.addUntracked<std::string>("nameProd", "hoCalibProducer");
0247     desc.addUntracked<std::string>("jetCalo", "GammaJetJetBackToBackCollection");
0248     desc.addUntracked<std::string>("gammaClus", "GammaJetGammaBackToBackCollection");
0249     desc.addUntracked<std::string>("ecalInput", "GammaJetEcalRecHitCollection");
0250     desc.addUntracked<std::string>("hbheInput", "hbhereco");
0251     desc.addUntracked<std::string>("hoInput", "horeco");
0252     desc.addUntracked<std::string>("hfInput", "hfreco");
0253     desc.addUntracked<std::string>("Tracks", "GammaJetTracksCollection");
0254     descriptions.add("alcaHcalProducerAnalyzer", desc);
0255   }
0256 
0257 }  // namespace cms
0258 
0259 #include "FWCore/PluginManager/interface/ModuleDef.h"
0260 #include "FWCore/Framework/interface/MakerMacros.h"
0261 
0262 using cms::ProducerAnalyzer;
0263 DEFINE_FWK_MODULE(ProducerAnalyzer);