Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 11:59:01

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