Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 12:18:20

0001 /** \class EgammaHLTCaloIsolFilterPairs
0002  *
0003  *
0004  *  \author Alessio Ghezzi
0005  *
0006  */
0007 
0008 #include "HLTEgammaCaloIsolFilterPairs.h"
0009 
0010 #include "DataFormats/Common/interface/Handle.h"
0011 
0012 #include "FWCore/ParameterSet/interface/ConfigurationDescriptions.h"
0013 #include "FWCore/ParameterSet/interface/ParameterSetDescription.h"
0014 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0015 
0016 //
0017 // constructors and destructor
0018 //
0019 HLTEgammaCaloIsolFilterPairs::HLTEgammaCaloIsolFilterPairs(const edm::ParameterSet& iConfig) : HLTFilter(iConfig) {
0020   candTag_ = iConfig.getParameter<edm::InputTag>("candTag");
0021   isoTag_ = iConfig.getParameter<edm::InputTag>("isoTag");
0022   nonIsoTag_ = iConfig.getParameter<edm::InputTag>("nonIsoTag");
0023 
0024   isolcut_EB1 = iConfig.getParameter<double>("isolcutEB1");
0025   FracCut_EB1 = iConfig.getParameter<double>("IsoOverEtCutEB1");
0026   IsoloEt2_EB1 = iConfig.getParameter<double>("IsoOverEt2CutEB1");
0027   isolcut_EE1 = iConfig.getParameter<double>("isolcutEE1");
0028   FracCut_EE1 = iConfig.getParameter<double>("IsoOverEtCutEE1");
0029   IsoloEt2_EE1 = iConfig.getParameter<double>("IsoOverEt2CutEE1");
0030 
0031   isolcut_EB2 = iConfig.getParameter<double>("isolcutEB2");
0032   FracCut_EB2 = iConfig.getParameter<double>("IsoOverEtCutEB2");
0033   IsoloEt2_EB2 = iConfig.getParameter<double>("IsoOverEt2CutEB2");
0034   isolcut_EE2 = iConfig.getParameter<double>("isolcutEE2");
0035   FracCut_EE2 = iConfig.getParameter<double>("IsoOverEtCutEE2");
0036   IsoloEt2_EE2 = iConfig.getParameter<double>("IsoOverEt2CutEE2");
0037 
0038   AlsoNonIso_1 = iConfig.getParameter<bool>("AlsoNonIso1");
0039   AlsoNonIso_2 = iConfig.getParameter<bool>("AlsoNonIso2");
0040 
0041   candToken_ = consumes<trigger::TriggerFilterObjectWithRefs>(candTag_);
0042   isoToken_ = consumes<reco::RecoEcalCandidateIsolationMap>(isoTag_);
0043   if (AlsoNonIso_1 || AlsoNonIso_2)
0044     nonIsoToken_ = consumes<reco::RecoEcalCandidateIsolationMap>(nonIsoTag_);
0045 }
0046 
0047 HLTEgammaCaloIsolFilterPairs::~HLTEgammaCaloIsolFilterPairs() = default;
0048 
0049 void HLTEgammaCaloIsolFilterPairs::fillDescriptions(edm::ConfigurationDescriptions& descriptions) {
0050   edm::ParameterSetDescription desc;
0051   makeHLTFilterDescription(desc);
0052   desc.add<edm::InputTag>("candTag", edm::InputTag(""));
0053   desc.add<edm::InputTag>("isoTag", edm::InputTag(""));
0054   desc.add<edm::InputTag>("nonIsoTag", edm::InputTag(""));
0055   desc.add<double>("isolcutEB1", 0.0);
0056   desc.add<double>("IsoOverEtCutEB1", 0.0);
0057   desc.add<double>("IsoOverEt2CutEB1", 0.0);
0058   desc.add<double>("isolcutEE1", 0.0);
0059   desc.add<double>("IsoOverEtCutEE1", 0.0);
0060   desc.add<double>("IsoOverEt2CutEE1", 0.0);
0061   desc.add<double>("isolcutEB2", 0.0);
0062   desc.add<double>("IsoOverEtCutEB2", 0.0);
0063   desc.add<double>("IsoOverEt2CutEB2", 0.0);
0064   desc.add<double>("isolcutEE2", 0.0);
0065   desc.add<double>("IsoOverEtCutEE2", 0.0);
0066   desc.add<double>("IsoOverEt2CutEE2", 0.0);
0067   desc.add<bool>("AlsoNonIso1", false);
0068   desc.add<bool>("AlsoNonIso2", false);
0069   descriptions.add("hltEgammaCaloIsolFilterPairs", desc);
0070 }
0071 
0072 // ------------ method called to produce the data  ------------
0073 bool HLTEgammaCaloIsolFilterPairs::hltFilter(edm::Event& iEvent,
0074                                              const edm::EventSetup& iSetup,
0075                                              trigger::TriggerFilterObjectWithRefs& filterproduct) const {
0076   using namespace trigger;
0077 
0078   edm::Handle<trigger::TriggerFilterObjectWithRefs> PrevFilterOutput;
0079   iEvent.getByToken(candToken_, PrevFilterOutput);
0080 
0081   std::vector<edm::Ref<reco::RecoEcalCandidateCollection> > recoecalcands;
0082   PrevFilterOutput->getObjects(TriggerCluster, recoecalcands);
0083   if (recoecalcands.empty())
0084     PrevFilterOutput->getObjects(TriggerPhoton, recoecalcands);
0085 
0086   //get hold of ecal isolation association map
0087   edm::Handle<reco::RecoEcalCandidateIsolationMap> depMap;
0088   iEvent.getByToken(isoToken_, depMap);
0089 
0090   //get hold of ecal isolation association map
0091   edm::Handle<reco::RecoEcalCandidateIsolationMap> depNonIsoMap;
0092   if (AlsoNonIso_1 || AlsoNonIso_2)
0093     iEvent.getByToken(nonIsoToken_, depNonIsoMap);
0094 
0095   int n = 0;
0096   // the list should be interpreted as pairs:
0097   // <recoecalcands[0],recoecalcands[1]>
0098   // <recoecalcands[2],recoecalcands[3]>
0099   // <recoecalcands[4],recoecalcands[5]>
0100   // .......
0101 
0102   // Should I check that the size of recoecalcands is even ?
0103   for (unsigned int i = 0; i < recoecalcands.size(); i = i + 2) {
0104     edm::Ref<reco::RecoEcalCandidateCollection> r1 = recoecalcands[i];
0105     edm::Ref<reco::RecoEcalCandidateCollection> r2 = recoecalcands[i + 1];
0106     // std::cout<<"CaloIsol 1) Et Eta phi: "<<r1->et()<<" "<<r1->eta()<<" "<<r1->phi()<<" 2) Et eta phi: "<<r2->et()<<" "<<r2->eta()<<" "<<r2->phi()<<std::endl;
0107 
0108     if (PassCaloIsolation(r1, *depMap, *depNonIsoMap, 1, AlsoNonIso_1) &&
0109         PassCaloIsolation(r2, *depMap, *depNonIsoMap, 2, AlsoNonIso_2)) {
0110       n++;
0111       filterproduct.addObject(TriggerCluster, r1);
0112       filterproduct.addObject(TriggerCluster, r2);
0113     }
0114   }
0115 
0116   // filter decision
0117   bool accept(n >= 1);
0118 
0119   return accept;
0120 }
0121 
0122 bool HLTEgammaCaloIsolFilterPairs::PassCaloIsolation(edm::Ref<reco::RecoEcalCandidateCollection> ref,
0123                                                      const reco::RecoEcalCandidateIsolationMap& IsoMap,
0124                                                      const reco::RecoEcalCandidateIsolationMap& NonIsoMap,
0125                                                      int which,
0126                                                      bool ChekAlsoNonIso) const {
0127   reco::RecoEcalCandidateIsolationMap::const_iterator mapi = IsoMap.find(ref);
0128 
0129   if (mapi == IsoMap.end()) {
0130     if (ChekAlsoNonIso)
0131       mapi = NonIsoMap.find(ref);
0132   }
0133 
0134   float vali = mapi->val;
0135   float IsoOE = vali / ref->et();
0136   float IsoOE2 = IsoOE / ref->et();
0137   double isolcut = 0, FracCut = 0, IsoloEt2 = 0;
0138   if (fabs(ref->eta()) < 1.479) {
0139     if (which == 1) {
0140       isolcut = isolcut_EB1;
0141       FracCut = FracCut_EB1;
0142       IsoloEt2 = IsoloEt2_EB1;
0143     } else if (which == 2) {
0144       isolcut = isolcut_EB2;
0145       FracCut = FracCut_EB2;
0146       IsoloEt2 = IsoloEt2_EB2;
0147     } else {
0148       return false;
0149     }
0150   } else {
0151     if (which == 1) {
0152       isolcut = isolcut_EE1;
0153       FracCut = FracCut_EE1;
0154       IsoloEt2 = IsoloEt2_EE1;
0155     } else if (which == 2) {
0156       isolcut = isolcut_EE2;
0157       FracCut = FracCut_EE2;
0158       IsoloEt2 = IsoloEt2_EE2;
0159     } else {
0160       return false;
0161     }
0162   }
0163 
0164   if (vali < isolcut || IsoOE < FracCut || IsoOE2 < IsoloEt2) {
0165     return true;
0166   }
0167   return false;
0168 }
0169 
0170 // declare this class as a framework plugin
0171 #include "FWCore/Framework/interface/MakerMacros.h"
0172 DEFINE_FWK_MODULE(HLTEgammaCaloIsolFilterPairs);