Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2023-03-17 10:53:44

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