Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2022-02-18 08:23:06

0001 #include <memory>
0002 #include <iostream>
0003 #include <fstream>
0004 #include <vector>
0005 #include <TFile.h>
0006 #include <TTree.h>
0007 #include "TPRegexp.h"
0008 
0009 // user include files
0010 #include "FWCore/Framework/interface/Frameworkfwd.h"
0011 #include "FWCore/Framework/interface/one/EDAnalyzer.h"
0012 #include "FWCore/Framework/interface/Event.h"
0013 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0014 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0015 #include "FWCore/ParameterSet/interface/ConfigurationDescriptions.h"
0016 #include "FWCore/ServiceRegistry/interface/Service.h"
0017 #include "FWCore/Common/interface/TriggerNames.h"
0018 #include "CommonTools/UtilAlgos/interface/TFileService.h"
0019 
0020 #include "DataFormats/HcalCalibObjects/interface/HcalHBHEMuonVariables.h"
0021 
0022 //#define EDM_ML_DEBUG
0023 
0024 class HcalHBHENewMuonAnalyzer : public edm::one::EDAnalyzer<edm::one::SharedResources> {
0025 public:
0026   explicit HcalHBHENewMuonAnalyzer(const edm::ParameterSet&);
0027   ~HcalHBHENewMuonAnalyzer() override = default;
0028 
0029   static void fillDescriptions(edm::ConfigurationDescriptions& descriptions);
0030 
0031 private:
0032   void beginJob() override;
0033   void analyze(edm::Event const&, edm::EventSetup const&) override;
0034 
0035   // ----------member data ---------------------------
0036   const edm::InputTag labelHBHEMuonVar_;
0037   const int useRaw_;
0038   const int maxDepth_;
0039   int kount_;
0040 
0041   const edm::EDGetTokenT<HcalHBHEMuonVariablesCollection> tokHBHEMuonVar_;
0042 
0043   //////////////////////////////////////////////////////
0044   static const int depthMax_ = 7;
0045   TTree* tree_;
0046   unsigned int runNumber_, eventNumber_, lumiNumber_, bxNumber_;
0047   unsigned int goodVertex_;
0048   bool muon_is_good_, muon_global_, muon_tracker_;
0049   bool muon_is_tight_, muon_is_medium_;
0050   double ptGlob_, etaGlob_, phiGlob_, energyMuon_, pMuon_;
0051   float muon_trkKink_, muon_chi2LocalPosition_, muon_segComp_;
0052   int trackerLayer_, numPixelLayers_, tight_PixelHits_;
0053   bool innerTrack_, outerTrack_, globalTrack_;
0054   double chiTracker_, dxyTracker_, dzTracker_;
0055   double innerTrackpt_, innerTracketa_, innerTrackphi_;
0056   double tight_validFraction_, outerTrackChi_;
0057   double outerTrackPt_, outerTrackEta_, outerTrackPhi_;
0058   int outerTrackHits_, outerTrackRHits_;
0059   double globalTrckPt_, globalTrckEta_, globalTrckPhi_;
0060   int globalMuonHits_, matchedStat_;
0061   double chiGlobal_, tight_LongPara_, tight_TransImpara_;
0062   double isolationR04_, isolationR03_;
0063   double ecalEnergy_, hcalEnergy_, hoEnergy_;
0064   bool matchedId_, hcalHot_;
0065   double ecal3x3Energy_, hcal1x1Energy_;
0066   unsigned int ecalDetId_, hcalDetId_, ehcalDetId_;
0067   int hcal_ieta_, hcal_iphi_;
0068   double hcalDepthEnergy_[depthMax_];
0069   double hcalDepthActiveLength_[depthMax_];
0070   double hcalDepthEnergyHot_[depthMax_];
0071   double hcalDepthActiveLengthHot_[depthMax_];
0072   double hcalDepthChargeHot_[depthMax_];
0073   double hcalDepthChargeHotBG_[depthMax_];
0074   double hcalDepthEnergyCorr_[depthMax_];
0075   double hcalDepthEnergyHotCorr_[depthMax_];
0076   bool hcalDepthMatch_[depthMax_];
0077   bool hcalDepthMatchHot_[depthMax_];
0078   double hcalActiveLength_, hcalActiveLengthHot_;
0079   std::vector<std::string> all_triggers_;
0080   std::vector<int> hltresults_;
0081   ////////////////////////////////////////////////////////////
0082 };
0083 
0084 HcalHBHENewMuonAnalyzer::HcalHBHENewMuonAnalyzer(const edm::ParameterSet& iConfig)
0085     : labelHBHEMuonVar_(iConfig.getParameter<edm::InputTag>("hbheMuonLabel")),
0086       useRaw_(iConfig.getParameter<int>("useRaw")),
0087       maxDepth_(iConfig.getUntrackedParameter<int>("maxDepth", 4)),
0088       tokHBHEMuonVar_(consumes<HcalHBHEMuonVariablesCollection>(labelHBHEMuonVar_)) {
0089   usesResource(TFileService::kSharedResource);
0090   //now do what ever initialization is needed
0091   kount_ = 0;
0092 
0093   edm::LogVerbatim("HBHEMuon") << "Parameters read from config file \n\t maxDepth__ " << maxDepth_ << "\n\t Labels "
0094                                << labelHBHEMuonVar_;
0095 }
0096 
0097 //
0098 // member functions
0099 //
0100 
0101 // ------------ method called for each event  ------------
0102 void HcalHBHENewMuonAnalyzer::analyze(const edm::Event& iEvent, const edm::EventSetup& iSetup) {
0103   ++kount_;
0104   runNumber_ = iEvent.id().run();
0105   eventNumber_ = iEvent.id().event();
0106   lumiNumber_ = iEvent.id().luminosityBlock();
0107   bxNumber_ = iEvent.bunchCrossing();
0108 #ifdef EDM_ML_DEBUG
0109   edm::LogVerbatim("HBHEMuon") << "Run " << runNumber_ << " Event " << eventNumber_ << " Lumi " << lumiNumber_ << " BX "
0110                                << bxNumber_ << std::endl;
0111 #endif
0112 
0113   auto const& hbheMuonColl = iEvent.getHandle(tokHBHEMuonVar_);
0114   if (hbheMuonColl.isValid()) {
0115     for (const auto& itr : (*(hbheMuonColl.product()))) {
0116       goodVertex_ = itr.goodVertex_;
0117       muon_is_good_ = itr.muonGood_;
0118       muon_global_ = itr.muonGlobal_;
0119       muon_tracker_ = itr.muonTracker_;
0120       muon_is_tight_ = itr.muonTight_;
0121       muon_is_medium_ = itr.muonMedium_;
0122       ptGlob_ = itr.ptGlob_;
0123       etaGlob_ = itr.etaGlob_;
0124       phiGlob_ = itr.phiGlob_;
0125       energyMuon_ = itr.energyMuon_;
0126       pMuon_ = itr.pMuon_;
0127       muon_trkKink_ = itr.muonTrkKink_;
0128       muon_chi2LocalPosition_ = itr.muonChi2LocalPosition_;
0129       muon_segComp_ = itr.muonSegComp_;
0130       trackerLayer_ = itr.trackerLayer_;
0131       numPixelLayers_ = itr.numPixelLayers_;
0132       tight_PixelHits_ = itr.tightPixelHits_;
0133       innerTrack_ = itr.innerTrack_;
0134       outerTrack_ = itr.outerTrack_;
0135       globalTrack_ = itr.globalTrack_;
0136       chiTracker_ = itr.chiTracker_;
0137       dxyTracker_ = itr.dxyTracker_;
0138       dzTracker_ = itr.dzTracker_;
0139       innerTrackpt_ = itr.innerTrackPt_;
0140       innerTracketa_ = itr.innerTrackEta_;
0141       innerTrackphi_ = itr.innerTrackPhi_;
0142       tight_validFraction_ = itr.tightValidFraction_;
0143       outerTrackChi_ = itr.outerTrackChi_;
0144       outerTrackPt_ = itr.outerTrackPt_;
0145       outerTrackEta_ = itr.outerTrackEta_;
0146       outerTrackPhi_ = itr.outerTrackPhi_;
0147       outerTrackHits_ = itr.outerTrackHits_;
0148       outerTrackRHits_ = itr.outerTrackRHits_;
0149       globalTrckPt_ = itr.globalTrackPt_;
0150       globalTrckEta_ = itr.globalTrackEta_;
0151       globalTrckPhi_ = itr.globalTrackPhi_;
0152       globalMuonHits_ = itr.globalMuonHits_;
0153       matchedStat_ = itr.matchedStat_;
0154       chiGlobal_ = itr.chiGlobal_;
0155       tight_LongPara_ = itr.tightLongPara_;
0156       tight_TransImpara_ = itr.tightTransImpara_;
0157       isolationR04_ = itr.isolationR04_;
0158       isolationR03_ = itr.isolationR03_;
0159       ecalEnergy_ = itr.ecalEnergy_;
0160       hcalEnergy_ = itr.hcalEnergy_;
0161       hoEnergy_ = itr.hoEnergy_;
0162       matchedId_ = itr.matchedId_;
0163       hcalHot_ = itr.hcalHot_;
0164       ecal3x3Energy_ = itr.ecal3x3Energy_;
0165       ecalDetId_ = itr.ecalDetId_;
0166       hcalDetId_ = itr.hcalDetId_;
0167       ehcalDetId_ = itr.ehcalDetId_;
0168       hcal_ieta_ = itr.hcalIeta_;
0169       hcal_iphi_ = itr.hcalIphi_;
0170       if (useRaw_ == 1)
0171         hcal1x1Energy_ = itr.hcal1x1EnergyAux_;
0172       else if (useRaw_ == 2)
0173         hcal1x1Energy_ = itr.hcal1x1EnergyRaw_;
0174       else
0175         hcal1x1Energy_ = itr.hcal1x1Energy_;
0176       for (unsigned int i = 0; i < itr.hcalDepthEnergy_.size(); ++i) {
0177         hcalDepthActiveLength_[i] = itr.hcalDepthActiveLength_[i];
0178         hcalDepthActiveLengthHot_[i] = itr.hcalDepthActiveLengthHot_[i];
0179         if (useRaw_ == 1) {
0180           hcalDepthEnergy_[i] = itr.hcalDepthEnergyAux_[i];
0181           hcalDepthEnergyHot_[i] = itr.hcalDepthEnergyHotAux_[i];
0182           hcalDepthEnergyCorr_[i] = itr.hcalDepthEnergyCorrAux_[i];
0183           hcalDepthEnergyHotCorr_[i] = itr.hcalDepthEnergyHotCorrAux_[i];
0184           hcalDepthChargeHot_[i] = itr.hcalDepthChargeHotAux_[i];
0185           hcalDepthChargeHotBG_[i] = itr.hcalDepthChargeHotBGAux_[i];
0186         } else if (useRaw_ == 2) {
0187           hcalDepthEnergy_[i] = itr.hcalDepthEnergyRaw_[i];
0188           hcalDepthEnergyHot_[i] = itr.hcalDepthEnergyHotRaw_[i];
0189           hcalDepthEnergyCorr_[i] = itr.hcalDepthEnergyCorrRaw_[i];
0190           hcalDepthEnergyHotCorr_[i] = itr.hcalDepthEnergyHotCorrRaw_[i];
0191           hcalDepthChargeHot_[i] = itr.hcalDepthChargeHotRaw_[i];
0192           hcalDepthChargeHotBG_[i] = itr.hcalDepthChargeHotBGRaw_[i];
0193         } else {
0194           hcalDepthEnergy_[i] = itr.hcalDepthEnergy_[i];
0195           hcalDepthEnergyHot_[i] = itr.hcalDepthEnergyHot_[i];
0196           hcalDepthEnergyCorr_[i] = itr.hcalDepthEnergyCorr_[i];
0197           hcalDepthEnergyHotCorr_[i] = itr.hcalDepthEnergyHotCorr_[i];
0198           hcalDepthChargeHot_[i] = itr.hcalDepthChargeHot_[i];
0199           hcalDepthChargeHotBG_[i] = itr.hcalDepthChargeHotBG_[i];
0200         }
0201         hcalDepthMatch_[i] = itr.hcalDepthMatch_[i];
0202         hcalDepthMatchHot_[i] = itr.hcalDepthMatchHot_[i];
0203       }
0204       hcalActiveLength_ = itr.hcalActiveLength_;
0205       hcalActiveLengthHot_ = itr.hcalActiveLengthHot_;
0206       all_triggers_ = itr.allTriggers_;
0207       hltresults_ = itr.hltResults_;
0208       tree_->Fill();
0209     }
0210   }
0211 }
0212 
0213 // ------------ method called once each job just before starting event loop  ------------
0214 void HcalHBHENewMuonAnalyzer::beginJob() {
0215   edm::Service<TFileService> fs;
0216   tree_ = fs->make<TTree>("TREE", "TREE");
0217   tree_->Branch("Event_No", &eventNumber_);
0218   tree_->Branch("Run_No", &runNumber_);
0219   tree_->Branch("LumiNumber", &lumiNumber_);
0220   tree_->Branch("BXNumber", &bxNumber_);
0221   tree_->Branch("GoodVertex", &goodVertex_);
0222   tree_->Branch("PF_Muon", &muon_is_good_);
0223   tree_->Branch("Global_Muon", &muon_global_);
0224   tree_->Branch("Tracker_muon", &muon_tracker_);
0225   tree_->Branch("MuonIsTight", &muon_is_tight_);
0226   tree_->Branch("MuonIsMedium", &muon_is_medium_);
0227   tree_->Branch("pt_of_muon", &ptGlob_);
0228   tree_->Branch("eta_of_muon", &etaGlob_);
0229   tree_->Branch("phi_of_muon", &phiGlob_);
0230   tree_->Branch("energy_of_muon", &energyMuon_);
0231   tree_->Branch("p_of_muon", &pMuon_);
0232   tree_->Branch("muon_trkKink", &muon_trkKink_);
0233   tree_->Branch("muon_chi2LocalPosition", &muon_chi2LocalPosition_);
0234   tree_->Branch("muon_segComp", &muon_segComp_);
0235 
0236   tree_->Branch("TrackerLayer", &trackerLayer_);
0237   tree_->Branch("NumPixelLayers", &numPixelLayers_);
0238   tree_->Branch("InnerTrackPixelHits", &tight_PixelHits_);
0239   tree_->Branch("innerTrack", &innerTrack_);
0240   tree_->Branch("chiTracker", &chiTracker_);
0241   tree_->Branch("DxyTracker", &dxyTracker_);
0242   tree_->Branch("DzTracker", &dzTracker_);
0243   tree_->Branch("innerTrackpt", &innerTrackpt_);
0244   tree_->Branch("innerTracketa", &innerTracketa_);
0245   tree_->Branch("innerTrackphi", &innerTrackphi_);
0246   tree_->Branch("tight_validFraction", &tight_validFraction_);
0247 
0248   tree_->Branch("OuterTrack", &outerTrack_);
0249   tree_->Branch("OuterTrackChi", &outerTrackChi_);
0250   tree_->Branch("OuterTrackPt", &outerTrackPt_);
0251   tree_->Branch("OuterTrackEta", &outerTrackEta_);
0252   tree_->Branch("OuterTrackPhi", &outerTrackPhi_);
0253   tree_->Branch("OuterTrackHits", &outerTrackHits_);
0254   tree_->Branch("OuterTrackRHits", &outerTrackRHits_);
0255 
0256   tree_->Branch("GlobalTrack", &globalTrack_);
0257   tree_->Branch("GlobalTrckPt", &globalTrckPt_);
0258   tree_->Branch("GlobalTrckEta", &globalTrckEta_);
0259   tree_->Branch("GlobalTrckPhi", &globalTrckPhi_);
0260   tree_->Branch("Global_Muon_Hits", &globalMuonHits_);
0261   tree_->Branch("MatchedStations", &matchedStat_);
0262   tree_->Branch("GlobTrack_Chi", &chiGlobal_);
0263   tree_->Branch("Tight_LongitudinalImpactparameter", &tight_LongPara_);
0264   tree_->Branch("Tight_TransImpactparameter", &tight_TransImpara_);
0265 
0266   tree_->Branch("IsolationR04", &isolationR04_);
0267   tree_->Branch("IsolationR03", &isolationR03_);
0268   tree_->Branch("ecal_3into3", &ecalEnergy_);
0269   tree_->Branch("hcal_3into3", &hcalEnergy_);
0270   tree_->Branch("tracker_3into3", &hoEnergy_);
0271 
0272   tree_->Branch("matchedId", &matchedId_);
0273   tree_->Branch("hcal_cellHot", &hcalHot_);
0274 
0275   tree_->Branch("ecal_3x3", &ecal3x3Energy_);
0276   tree_->Branch("hcal_1x1", &hcal1x1Energy_);
0277   tree_->Branch("ecal_detID", &ecalDetId_);
0278   tree_->Branch("hcal_detID", &hcalDetId_);
0279   tree_->Branch("ehcal_detID", &ehcalDetId_);
0280   tree_->Branch("hcal_ieta", &hcal_ieta_);
0281   tree_->Branch("hcal_iphi", &hcal_iphi_);
0282 
0283   char name[100];
0284   for (int k = 0; k < maxDepth_; ++k) {
0285     sprintf(name, "hcal_edepth%d", (k + 1));
0286     tree_->Branch(name, &hcalDepthEnergy_[k]);
0287     sprintf(name, "hcal_activeL%d", (k + 1));
0288     tree_->Branch(name, &hcalDepthActiveLength_[k]);
0289     sprintf(name, "hcal_edepthHot%d", (k + 1));
0290     tree_->Branch(name, &hcalDepthEnergyHot_[k]);
0291     sprintf(name, "hcal_activeHotL%d", (k + 1));
0292     tree_->Branch(name, &hcalDepthActiveLengthHot_[k]);
0293     sprintf(name, "hcal_cdepthHot%d", (k + 1));
0294     tree_->Branch(name, &hcalDepthChargeHot_[k]);
0295     sprintf(name, "hcal_cdepthHotBG%d", (k + 1));
0296     tree_->Branch(name, &hcalDepthChargeHotBG_[k]);
0297     sprintf(name, "hcal_edepthCorrect%d", (k + 1));
0298     tree_->Branch(name, &hcalDepthEnergyCorr_[k]);
0299     sprintf(name, "hcal_edepthHotCorrect%d", (k + 1));
0300     tree_->Branch(name, &hcalDepthEnergyHotCorr_[k]);
0301     sprintf(name, "hcal_depthMatch%d", (k + 1));
0302     tree_->Branch(name, &hcalDepthMatch_[k]);
0303     sprintf(name, "hcal_depthMatchHot%d", (k + 1));
0304     tree_->Branch(name, &hcalDepthMatchHot_[k]);
0305   }
0306 
0307   tree_->Branch("activeLength", &hcalActiveLength_);
0308   tree_->Branch("activeLengthHot", &hcalActiveLengthHot_);
0309 
0310   tree_->Branch("hltresults", &hltresults_);
0311   tree_->Branch("all_triggers", &all_triggers_);
0312 }
0313 
0314 // ------------ method fills 'descriptions' with the allowed parameters for the module  ------------
0315 void HcalHBHENewMuonAnalyzer::fillDescriptions(edm::ConfigurationDescriptions& descriptions) {
0316   edm::ParameterSetDescription desc;
0317   desc.add<edm::InputTag>("hbheMuonLabel", edm::InputTag("alcaHcalHBHEMuonProducer", "hbheMuon"));
0318   desc.add<int>("useRaw", 0);
0319   desc.addUntracked<int>("maxDepth", 4);
0320   descriptions.add("hcalHBHEMuonAnalysis", desc);
0321 }
0322 
0323 //define this as a plug-in
0324 #include "FWCore/Framework/interface/MakerMacros.h"
0325 
0326 DEFINE_FWK_MODULE(HcalHBHENewMuonAnalyzer);