Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 12:27:48

0001 /* class PFRecoTauDiscriminationAgainstElectron2
0002  * created : Apr 3, 2014
0003  * revised : ,
0004  * Authorss : Aruna Nayak (DESY)
0005  */
0006 
0007 #include "FWCore/Utilities/interface/Exception.h"
0008 
0009 #include <FWCore/ParameterSet/interface/ConfigurationDescriptions.h>
0010 #include <FWCore/ParameterSet/interface/ParameterSetDescription.h>
0011 
0012 #include "RecoTauTag/RecoTau/interface/TauDiscriminationProducerBase.h"
0013 #include "RecoTauTag/RecoTau/interface/AntiElectronIDCut2.h"
0014 
0015 #include "DataFormats/ParticleFlowCandidate/interface/PFCandidate.h"
0016 #include "DataFormats/ParticleFlowCandidate/interface/PFCandidateFwd.h"
0017 #include "DataFormats/TrackReco/interface/Track.h"
0018 #include "DataFormats/TauReco/interface/PFTauDiscriminator.h"
0019 #include "DataFormats/Math/interface/deltaR.h"
0020 
0021 #include <TMath.h>
0022 #include "TPRegexp.h"
0023 #include <TObjString.h>
0024 
0025 #include <iostream>
0026 #include <sstream>
0027 #include <fstream>
0028 #include <vector>
0029 
0030 using namespace reco;
0031 typedef std::pair<double, double> pdouble;
0032 
0033 class PFRecoTauDiscriminationAgainstElectron2 : public PFTauDiscriminationProducerBase {
0034 public:
0035   explicit PFRecoTauDiscriminationAgainstElectron2(const edm::ParameterSet& iConfig)
0036       : PFTauDiscriminationProducerBase(iConfig) {
0037     LeadPFChargedHadrEoP_barrel_min_ = iConfig.getParameter<double>("LeadPFChargedHadrEoP_barrel_min");
0038     LeadPFChargedHadrEoP_barrel_max_ = iConfig.getParameter<double>("LeadPFChargedHadrEoP_barrel_max");
0039     Hcal3x3OverPLead_barrel_max_ = iConfig.getParameter<double>("Hcal3x3OverPLead_barrel_max");
0040     GammaEtaMom_barrel_max_ = iConfig.getParameter<double>("GammaEtaMom_barrel_max");
0041     GammaPhiMom_barrel_max_ = iConfig.getParameter<double>("GammaPhiMom_barrel_max");
0042     GammaEnFrac_barrel_max_ = iConfig.getParameter<double>("GammaEnFrac_barrel_max");
0043     LeadPFChargedHadrEoP_endcap_min1_ = iConfig.getParameter<double>("LeadPFChargedHadrEoP_endcap_min1");
0044     LeadPFChargedHadrEoP_endcap_max1_ = iConfig.getParameter<double>("LeadPFChargedHadrEoP_endcap_max1");
0045     LeadPFChargedHadrEoP_endcap_min2_ = iConfig.getParameter<double>("LeadPFChargedHadrEoP_endcap_min2");
0046     LeadPFChargedHadrEoP_endcap_max2_ = iConfig.getParameter<double>("LeadPFChargedHadrEoP_endcap_max2");
0047     Hcal3x3OverPLead_endcap_max_ = iConfig.getParameter<double>("Hcal3x3OverPLead_endcap_max");
0048     GammaEtaMom_endcap_max_ = iConfig.getParameter<double>("GammaEtaMom_endcap_max");
0049     GammaPhiMom_endcap_max_ = iConfig.getParameter<double>("GammaPhiMom_endcap_max");
0050     GammaEnFrac_endcap_max_ = iConfig.getParameter<double>("GammaEnFrac_endcap_max");
0051     keepTausInEcalCrack_ = iConfig.getParameter<bool>("keepTausInEcalCrack");
0052     rejectTausInEcalCrack_ = iConfig.getParameter<bool>("rejectTausInEcalCrack");
0053 
0054     applyCut_hcal3x3OverPLead_ = iConfig.getParameter<bool>("applyCut_hcal3x3OverPLead");
0055     applyCut_leadPFChargedHadrEoP_ = iConfig.getParameter<bool>("applyCut_leadPFChargedHadrEoP");
0056     applyCut_GammaEtaMom_ = iConfig.getParameter<bool>("applyCut_GammaEtaMom");
0057     applyCut_GammaPhiMom_ = iConfig.getParameter<bool>("applyCut_GammaPhiMom");
0058     applyCut_GammaEnFrac_ = iConfig.getParameter<bool>("applyCut_GammaEnFrac");
0059     applyCut_HLTSpecific_ = iConfig.getParameter<bool>("applyCut_HLTSpecific");
0060 
0061     etaCracks_string_ = iConfig.getParameter<std::vector<std::string>>("etaCracks");
0062 
0063     verbosity_ = iConfig.getParameter<int>("verbosity");
0064 
0065     cuts2_ = new AntiElectronIDCut2();
0066   }
0067 
0068   void beginEvent(const edm::Event&, const edm::EventSetup&) override;
0069 
0070   double discriminate(const PFTauRef&) const override;
0071 
0072   ~PFRecoTauDiscriminationAgainstElectron2() override {}
0073 
0074   static void fillDescriptions(edm::ConfigurationDescriptions& descriptions);
0075 
0076 private:
0077   bool isInEcalCrack(double) const;
0078   std::vector<pdouble> etaCracks_;
0079   std::vector<std::string> etaCracks_string_;
0080 
0081   AntiElectronIDCut2* cuts2_;
0082 
0083   double LeadPFChargedHadrEoP_barrel_min_;
0084   double LeadPFChargedHadrEoP_barrel_max_;
0085   double Hcal3x3OverPLead_barrel_max_;
0086   double GammaEtaMom_barrel_max_;
0087   double GammaPhiMom_barrel_max_;
0088   double GammaEnFrac_barrel_max_;
0089   double LeadPFChargedHadrEoP_endcap_min1_;
0090   double LeadPFChargedHadrEoP_endcap_max1_;
0091   double LeadPFChargedHadrEoP_endcap_min2_;
0092   double LeadPFChargedHadrEoP_endcap_max2_;
0093   double Hcal3x3OverPLead_endcap_max_;
0094   double GammaEtaMom_endcap_max_;
0095   double GammaPhiMom_endcap_max_;
0096   double GammaEnFrac_endcap_max_;
0097 
0098   bool keepTausInEcalCrack_;
0099   bool rejectTausInEcalCrack_;
0100 
0101   bool applyCut_hcal3x3OverPLead_;
0102   bool applyCut_leadPFChargedHadrEoP_;
0103   bool applyCut_GammaEtaMom_;
0104   bool applyCut_GammaPhiMom_;
0105   bool applyCut_GammaEnFrac_;
0106   bool applyCut_HLTSpecific_;
0107 
0108   int verbosity_;
0109 };
0110 
0111 void PFRecoTauDiscriminationAgainstElectron2::beginEvent(const edm::Event& evt, const edm::EventSetup& es) {
0112   cuts2_->SetBarrelCutValues(LeadPFChargedHadrEoP_barrel_min_,
0113                              LeadPFChargedHadrEoP_barrel_max_,
0114                              Hcal3x3OverPLead_barrel_max_,
0115                              GammaEtaMom_barrel_max_,
0116                              GammaPhiMom_barrel_max_,
0117                              GammaEnFrac_barrel_max_);
0118 
0119   cuts2_->SetEndcapCutValues(LeadPFChargedHadrEoP_endcap_min1_,
0120                              LeadPFChargedHadrEoP_endcap_max1_,
0121                              LeadPFChargedHadrEoP_endcap_min2_,
0122                              LeadPFChargedHadrEoP_endcap_max2_,
0123                              Hcal3x3OverPLead_endcap_max_,
0124                              GammaEtaMom_endcap_max_,
0125                              GammaPhiMom_endcap_max_,
0126                              GammaEnFrac_endcap_max_);
0127 
0128   cuts2_->ApplyCut_EcalCrack(keepTausInEcalCrack_, rejectTausInEcalCrack_);
0129 
0130   cuts2_->ApplyCuts(applyCut_hcal3x3OverPLead_,
0131                     applyCut_leadPFChargedHadrEoP_,
0132                     applyCut_GammaEtaMom_,
0133                     applyCut_GammaPhiMom_,
0134                     applyCut_GammaEnFrac_,
0135                     applyCut_HLTSpecific_);
0136   //Ecal cracks in eta
0137   etaCracks_.clear();
0138   TPRegexp regexpParser_range("([0-9.e+/-]+):([0-9.e+/-]+)");
0139   for (std::vector<std::string>::const_iterator etaCrack = etaCracks_string_.begin();
0140        etaCrack != etaCracks_string_.end();
0141        ++etaCrack) {
0142     TObjArray* subStrings = regexpParser_range.MatchS(etaCrack->data());
0143     if (subStrings->GetEntries() == 3) {
0144       //std::cout << "substrings(1) = " << ((TObjString*)subStrings->At(1))->GetString() << std::endl;
0145       double range_begin = ((TObjString*)subStrings->At(1))->GetString().Atof();
0146       //std::cout << "substrings(2) = " << ((TObjString*)subStrings->At(2))->GetString() << std::endl;
0147       double range_end = ((TObjString*)subStrings->At(2))->GetString().Atof();
0148       etaCracks_.push_back(pdouble(range_begin, range_end));
0149     }
0150   }
0151 
0152   cuts2_->SetEcalCracks(etaCracks_);
0153 }
0154 
0155 double PFRecoTauDiscriminationAgainstElectron2::discriminate(const PFTauRef& thePFTauRef) const {
0156   double discriminator = 0.;
0157 
0158   // ensure tau has at least one charged object
0159 
0160   if ((*thePFTauRef).leadChargedHadrCand().isNull()) {
0161     return 0.;
0162   } else {
0163     discriminator = cuts2_->Discriminator(*thePFTauRef);
0164   }
0165 
0166   if (verbosity_) {
0167     std::cout << " Taus : " << TauProducer_ << std::endl;
0168     std::cout << "<PFRecoTauDiscriminationAgainstElectron2::discriminate>:" << std::endl;
0169     std::cout << " tau: Pt = " << thePFTauRef->pt() << ", eta = " << thePFTauRef->eta()
0170               << ", phi = " << thePFTauRef->phi() << std::endl;
0171     std::cout << " discriminator value = " << discriminator << std::endl;
0172     std::cout << " Prongs in tau: " << thePFTauRef->signalChargedHadrCands().size() << std::endl;
0173   }
0174 
0175   return discriminator;
0176 }
0177 
0178 bool PFRecoTauDiscriminationAgainstElectron2::isInEcalCrack(double eta) const {
0179   eta = fabs(eta);
0180   return (eta < 0.018 || (eta > 0.423 && eta < 0.461) || (eta > 0.770 && eta < 0.806) || (eta > 1.127 && eta < 1.163) ||
0181           (eta > 1.460 && eta < 1.558));
0182 }
0183 
0184 void PFRecoTauDiscriminationAgainstElectron2::fillDescriptions(edm::ConfigurationDescriptions& descriptions) {
0185   // pfRecoTauDiscriminationAgainstElectron2
0186   edm::ParameterSetDescription desc;
0187   desc.add<bool>("rejectTausInEcalCrack", false);
0188   desc.add<edm::InputTag>("PFTauProducer", edm::InputTag("pfRecoTauProducer"));
0189   desc.add<bool>("applyCut_GammaEnFrac", true);
0190   desc.add<bool>("applyCut_HLTSpecific", true);
0191   desc.add<double>("GammaEnFrac_barrel_max", 0.15);
0192   desc.add<bool>("keepTausInEcalCrack", true);
0193   {
0194     edm::ParameterSetDescription psd0;
0195     psd0.add<std::string>("BooleanOperator", "and");
0196     {
0197       edm::ParameterSetDescription psd1;
0198       psd1.add<double>("cut");
0199       psd1.add<edm::InputTag>("Producer");
0200       psd0.addOptional<edm::ParameterSetDescription>("leadTrack", psd1);
0201     }
0202     desc.add<edm::ParameterSetDescription>("Prediscriminants", psd0);
0203   }
0204   desc.add<bool>("applyCut_GammaPhiMom", false);
0205   desc.add<double>("GammaPhiMom_endcap_max", 1.5);
0206   desc.add<double>("GammaPhiMom_barrel_max", 1.5);
0207   desc.add<bool>("applyCut_leadPFChargedHadrEoP", true);
0208   desc.add<double>("LeadPFChargedHadrEoP_barrel_max", 1.01);
0209   desc.add<double>("GammaEtaMom_endcap_max", 1.5);
0210   desc.add<double>("GammaEtaMom_barrel_max", 1.5);
0211   desc.add<double>("Hcal3x3OverPLead_endcap_max", 0.1);
0212   desc.add<double>("LeadPFChargedHadrEoP_barrel_min", 0.99);
0213   desc.add<double>("LeadPFChargedHadrEoP_endcap_max2", 1.01);
0214   desc.add<double>("LeadPFChargedHadrEoP_endcap_min1", 0.7);
0215   desc.add<double>("LeadPFChargedHadrEoP_endcap_min2", 0.99);
0216   desc.add<double>("LeadPFChargedHadrEoP_endcap_max1", 1.3);
0217   desc.add<int>("verbosity", 0);
0218   desc.add<double>("GammaEnFrac_endcap_max", 0.2);
0219   desc.add<bool>("applyCut_hcal3x3OverPLead", true);
0220   desc.add<bool>("applyCut_GammaEtaMom", false);
0221   desc.add<std::vector<std::string>>("etaCracks",
0222                                      {
0223                                          "0.0:0.018",
0224                                          "0.423:0.461",
0225                                          "0.770:0.806",
0226                                          "1.127:1.163",
0227                                          "1.460:1.558",
0228                                      });
0229   desc.add<double>("Hcal3x3OverPLead_barrel_max", 0.2);
0230   descriptions.add("pfRecoTauDiscriminationAgainstElectron2", desc);
0231 }
0232 
0233 DEFINE_FWK_MODULE(PFRecoTauDiscriminationAgainstElectron2);