Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-02-14 13:09:17

0001 // -*- C++ -*-
0002 //
0003 // Package:   BeamSplash
0004 // Class:     BeamSPlash
0005 //
0006 //
0007 // Original Author:  Luca Malgeri
0008 
0009 #include <iostream>
0010 #include <memory>
0011 #include <vector>
0012 #include <map>
0013 #include <set>
0014 
0015 // user include files
0016 #include "DPGAnalysis/Skims/interface/BeamSplash.h"
0017 
0018 #include "FWCore/Utilities/interface/InputTag.h"
0019 #include "FWCore/Framework/interface/Frameworkfwd.h"
0020 #include "FWCore/Framework/interface/EDFilter.h"
0021 #include "FWCore/Framework/interface/Event.h"
0022 #include "FWCore/Framework/interface/MakerMacros.h"
0023 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0024 #include "FWCore/Framework/interface/ESHandle.h"
0025 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0026 #include "DataFormats/EcalRecHit/interface/EcalRecHit.h"
0027 #include "DataFormats/EcalDetId/interface/EBDetId.h"
0028 #include "DataFormats/EcalDetId/interface/EEDetId.h"
0029 #include "DataFormats/EcalRecHit/interface/EcalRecHitCollections.h"
0030 #include "DataFormats/HcalRecHit/interface/HcalRecHitCollections.h"
0031 #include "DataFormats/HcalDetId/interface/HcalDetId.h"
0032 
0033 using namespace edm;
0034 using namespace std;
0035 
0036 BeamSplash::BeamSplash(const edm::ParameterSet& iConfig) {
0037   EBRecHitCollection_ = iConfig.getParameter<edm::InputTag>("ebrechitcollection");
0038   EERecHitCollection_ = iConfig.getParameter<edm::InputTag>("eerechitcollection");
0039   HBHERecHitCollection_ = iConfig.getParameter<edm::InputTag>("hbherechitcollection");
0040 
0041   EnergyCutTot = iConfig.getUntrackedParameter<double>("energycuttot");
0042   EnergyCutEcal = iConfig.getUntrackedParameter<double>("energycutecal");
0043   EnergyCutHcal = iConfig.getUntrackedParameter<double>("energycuthcal");
0044   applyfilter = iConfig.getUntrackedParameter<bool>("applyfilter", true);
0045 }
0046 
0047 BeamSplash::~BeamSplash() {}
0048 
0049 bool BeamSplash::filter(edm::Event& iEvent, const edm::EventSetup& iSetup) {
0050   bool accepted = false;
0051 
0052   bool acceptedtot = false;
0053   bool acceptedEcal = false;
0054   bool acceptedHcal = false;
0055 
0056   int ievt = iEvent.id().event();
0057   int irun = iEvent.id().run();
0058   int ils = iEvent.luminosityBlock();
0059   int ibx = iEvent.bunchCrossing();
0060 
0061   double totene = 0;
0062   double ecalene = 0;
0063   double hcalene = 0;
0064 
0065   Handle<EBRecHitCollection> pEBRecHits;
0066   Handle<EERecHitCollection> pEERecHits;
0067   Handle<HBHERecHitCollection> pHBHERecHits;
0068 
0069   const EBRecHitCollection* EBRecHits = nullptr;
0070   const EERecHitCollection* EERecHits = nullptr;
0071   const HBHERecHitCollection* HBHERecHits = nullptr;
0072 
0073   if (!EBRecHitCollection_.label().empty() && !EBRecHitCollection_.instance().empty()) {
0074     iEvent.getByLabel(EBRecHitCollection_, pEBRecHits);
0075     if (pEBRecHits.isValid()) {
0076       EBRecHits = pEBRecHits.product();  // get a ptr to the product
0077     } else {
0078       edm::LogError("EcalRecHitError") << "Error! can't get the product " << EBRecHitCollection_.label();
0079     }
0080   }
0081 
0082   if (!EERecHitCollection_.label().empty() && !EERecHitCollection_.instance().empty()) {
0083     iEvent.getByLabel(EERecHitCollection_, pEERecHits);
0084 
0085     if (pEERecHits.isValid()) {
0086       EERecHits = pEERecHits.product();  // get a ptr to the product
0087     } else {
0088       edm::LogError("EcalRecHitError") << "Error! can't get the product " << EERecHitCollection_.label();
0089     }
0090   }
0091 
0092   if (!HBHERecHitCollection_.label().empty()) {
0093     iEvent.getByLabel(HBHERecHitCollection_, pHBHERecHits);
0094 
0095     if (pHBHERecHits.isValid()) {
0096       HBHERecHits = pHBHERecHits.product();  // get a ptr to the product
0097     } else {
0098       edm::LogError("HcalRecHitError") << "Error! can't get the product " << HBHERecHitCollection_.label();
0099     }
0100   }
0101 
0102   // now sum over them
0103   if (EBRecHits) {
0104     for (EBRecHitCollection::const_iterator it = EBRecHits->begin(); it != EBRecHits->end(); ++it) {
0105       totene += it->energy();
0106       ecalene += it->energy();
0107     }
0108   }
0109   if (EERecHits) {
0110     for (EERecHitCollection::const_iterator it = EERecHits->begin(); it != EERecHits->end(); ++it) {
0111       totene += it->energy();
0112       ecalene += it->energy();
0113     }
0114   }
0115   if (HBHERecHits) {
0116     for (HBHERecHitCollection::const_iterator it = HBHERecHits->begin(); it != HBHERecHits->end(); ++it) {
0117       totene += it->energy();
0118       hcalene += it->energy();
0119     }
0120   }
0121 
0122   if (totene > EnergyCutTot)
0123     acceptedtot = true;
0124   if (ecalene > EnergyCutEcal)
0125     acceptedEcal = true;
0126   if (hcalene > EnergyCutHcal)
0127     acceptedHcal = true;
0128 
0129   accepted = acceptedtot | acceptedEcal | acceptedHcal;
0130 
0131   if (accepted) {
0132     edm::LogVerbatim("BeamSplash") << "!!!!!!!BeamSplash!!!!!!!: run:" << irun << " event:" << ievt << " ls:" << ils
0133                                    << " bx= " << ibx << " totene=" << totene << " ecalene=" << ecalene
0134                                    << " hcalene=" << hcalene;
0135     std::cout << "!!!!!!!BeamSplash!!!!!!!: run:" << irun << " event:" << ievt << " ls:" << ils << " bx= " << ibx
0136               << " totene=" << totene << " ecalene=" << ecalene << " hcalene=" << hcalene << std::endl;
0137   }
0138 
0139   if (applyfilter)
0140     return accepted;
0141   else
0142     return true;
0143 }
0144 
0145 //define this as a plug-in
0146 DEFINE_FWK_MODULE(BeamSplash);