44 std::vector<TFile*>& inputFilesToDelete) {
46 throw cms::Exception(
"PFRecoTauDiscriminationAgainstMuonMVA::loadMVA")
47 <<
" Failed to find File = " << inputFileName <<
" !!\n";
53 throw cms::Exception(
"PFRecoTauDiscriminationAgainstMuonMVA::loadMVA")
54 <<
" Failed to load MVA = " << mvaName.data() <<
" from file = " << inputFileName.
fullPath().data()
57 inputFilesToDelete.push_back(inputFile);
72 moduleLabel_(cfg.getParameter<
std::
string>(
"@module_label")),
76 loadMVAfromDB_ = cfg.
getParameter<
bool>(
"loadMVAfromDB");
77 if (!loadMVAfromDB_) {
80 mvaInput_ =
new float[11];
83 Muons_token = consumes<reco::MuonCollection>(srcMuons_);
88 produces<PFTauDiscriminator>(
"category");
93 double discriminate(
const PFTauRef&)
const override;
101 for (std::vector<TFile*>::iterator it = inputFilesToDelete_.begin(); it != inputFilesToDelete_.end(); ++it) {
123 std::unique_ptr<PFTauDiscriminator> category_output_;
125 std::vector<TFile*> inputFilesToDelete_;
132 if (loadMVAfromDB_) {
135 mvaReader_ = loadMVAfromFile(inputFileName_, mvaName_, inputFilesToDelete_);
147 std::vector<int>& numHitsDT,
148 std::vector<int>& numHitsCSC,
149 std::vector<int>& numHitsRPC) {
159 if (muonStation >= 0 && muonStation < 4) {
161 ++numHitsDT[muonStation];
163 ++numHitsCSC[muonStation];
165 ++numHitsRPC[muonStation];
175 edm::LogPrint(
"PFTauAgainstMuonMVA") <<
"<PFRecoTauDiscriminationAgainstMuonMVA::discriminate>:";
176 edm::LogPrint(
"PFTauAgainstMuonMVA") <<
" moduleLabel = " << moduleLabel_;
181 category_output_->setValue(tauIndex_, category);
184 if (tau->leadPFChargedHadrCand().
isNull())
188 double tauCaloEnECAL = 0.;
189 double tauCaloEnHCAL = 0.;
190 const std::vector<reco::PFCandidatePtr>& tauSignalPFCands = tau->signalPFCands();
191 for (std::vector<reco::PFCandidatePtr>::const_iterator tauSignalPFCand = tauSignalPFCands.begin();
192 tauSignalPFCand != tauSignalPFCands.end();
194 tauCaloEnECAL += (*tauSignalPFCand)->ecalEnergy();
195 tauCaloEnHCAL += (*tauSignalPFCand)->hcalEnergy();
197 mvaInput_[1] = TMath::Sqrt(
TMath::Max(0., tauCaloEnECAL));
198 mvaInput_[2] = TMath::Sqrt(
TMath::Max(0., tauCaloEnHCAL));
199 mvaInput_[3] = tau->leadPFChargedHadrCand()->pt() /
TMath::Max(1., Double_t(tau->pt()));
200 mvaInput_[4] = TMath::Sqrt(
TMath::Max(0., tau->leadPFChargedHadrCand()->ecalEnergy()));
201 mvaInput_[5] = TMath::Sqrt(
TMath::Max(0., tau->leadPFChargedHadrCand()->hcalEnergy()));
203 std::vector<int> numHitsDT(4);
204 std::vector<int> numHitsCSC(4);
205 std::vector<int> numHitsRPC(4);
206 for (
int iStation = 0; iStation < 4; ++iStation) {
207 numHitsDT[iStation] = 0;
208 numHitsCSC[iStation] = 0;
209 numHitsRPC[iStation] = 0;
211 if (tau->leadPFChargedHadrCand().
isNonnull()) {
212 reco::MuonRef muonRef = tau->leadPFChargedHadrCand()->muonRef();
215 countHits(*muonRef, numHitsDT, numHitsCSC, numHitsRPC);
219 for (
size_t idxMuon = 0; idxMuon <
numMuons; ++idxMuon) {
221 if (tau->leadPFChargedHadrCand().
isNonnull() && tau->leadPFChargedHadrCand()->muonRef().
isNonnull() &&
222 muon == tau->leadPFChargedHadrCand()->muonRef()) {
226 if (dR < dRmuonMatch_) {
228 countHits(*muon, numHitsDT, numHitsCSC, numHitsRPC);
231 mvaInput_[6] = numMatches;
232 mvaInput_[7] = numHitsDT[0] + numHitsCSC[0] + numHitsRPC[0];
233 mvaInput_[8] = numHitsDT[1] + numHitsCSC[1] + numHitsRPC[1];
234 mvaInput_[9] = numHitsDT[2] + numHitsCSC[2] + numHitsRPC[2];
235 mvaInput_[10] = numHitsDT[3] + numHitsCSC[3] + numHitsRPC[3];
237 double mvaValue = mvaReader_->GetClassifier(mvaInput_);
239 edm::LogPrint(
"PFTauAgainstMuonMVA") <<
"mvaValue = " << mvaValue;
254 desc.
add<
double>(
"mvaMin", 0.0);
255 desc.add<
std::string>(
"mvaName",
"againstMuonMVA");
257 desc.add<
int>(
"verbosity", 0);
258 desc.add<
bool>(
"returnMVA",
true);
260 desc.add<
bool>(
"loadMVAfromDB",
true);
266 psd1.
add<
double>(
"cut");
272 desc.
add<
double>(
"dRmuonMatch", 0.3);
274 descriptions.add(
"pfRecoTauDiscriminationAgainstMuonMVA", desc);
T getParameter(std::string const &) const
OrphanHandle< PROD > put(std::unique_ptr< PROD > product)
Put a new product.
ParameterDescriptionBase * addOptional(U const &iLabel, T const &value)
edm::RefProd< TauCollection > TauRefProd
bool isNonnull() const
Checks for non-null.
bool getByToken(EDGetToken token, Handle< PROD > &result) const
#define DEFINE_FWK_MODULE(type)
static bool muonCSCHitFilter(uint16_t pattern)
virtual void beginEvent(const edm::Event &, const edm::EventSetup &)
static uint32_t getHitType(uint16_t pattern)
int numberOfAllHits(HitCategory category) const
const LorentzVector & p4() const final
four-momentum Lorentz vector
LocationCode location() const
Where was the file found?
ParameterDescriptionBase * add(U const &iLabel, T const &value)
bool isNull() const
Checks for null.
virtual TrackRef outerTrack() const
reference to Track reconstructed in the muon detector only
constexpr auto deltaR(const T1 &t1, const T2 &t2) -> decltype(t1.eta())
static bool muonHitFilter(uint16_t pattern)
virtual double discriminate(const TauRef &tau) const =0
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
int numberOfMatches(ArbitrationType type=SegmentAndTrackArbitration) const
get number of chambers with matched segments
static bool muonDTHitFilter(uint16_t pattern)
std::string fullPath() const
static uint16_t getMuonStation(uint16_t pattern)
Muon station (1-4). Only valid for muon patterns, of course. only for patterns from muon...
uint16_t getHitPattern(HitCategory category, int position) const
static bool muonRPCHitFilter(uint16_t pattern)
T const * product() const
void countHits(const reco::Muon &muon, std::vector< int > &numHitsDT, std::vector< int > &numHitsCSC, std::vector< int > &numHitsRPC)
virtual void endEvent(edm::Event &)