Skip to content

Commit 9e6cb6c

Browse files
authored
Merge pull request #47403 from KIT-CMS/embedding_backport_CMSSW_12_4_X
Backport to produce 2022 Tau Embedding samples (HLT step)
2 parents 51b204e + 7334b5b commit 9e6cb6c

36 files changed

+2690
-1089
lines changed

DataFormats/GsfTrackReco/src/classes_def.xml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,4 +52,11 @@
5252
<class name="edm::reftobase::Holder<reco::Track, reco::GsfTrackRef>" />
5353
<class name="edm::reftobase::RefHolder<reco::GsfTrackRef>" />
5454

55+
<!-- ValueMap<reco::GsfTrack> -->
56+
<class name="edm::ValueMap<reco::GsfTrackRefVector>" />
57+
<class name="edm::Wrapper<edm::ValueMap<reco::GsfTrackRefVector> >" />
58+
<class name="std::vector<edm::RefVector<std::vector<reco::GsfTrack>,reco::GsfTrack,edm::refhelper::FindUsingAdvance<std::vector<reco::GsfTrack>,reco::GsfTrack> > >"/>
59+
<class name="edm::Wrapper<edm::RefVector<std::vector<reco::GsfTrack>,reco::GsfTrack,edm::refhelper::FindUsingAdvance<std::vector<reco::GsfTrack>,reco::GsfTrack> > >"/>
60+
<class name="std::vector<edm::Ref<std::vector<reco::GsfTrack>,reco::GsfTrack,edm::refhelper::FindUsingAdvance<std::vector<reco::GsfTrack>,reco::GsfTrack> > >"/>
61+
5562
</lcgdict>

RecoEgamma/EgammaElectronProducers/plugins/LowPtGSFToTrackLinker.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ void LowPtGSFToTrackLinker::produce(edm::StreamID, edm::Event& iEvent, const edm
5454
//map Track --> GSF and fill GSF --> PackedCandidates and GSF --> Lost associations
5555
for (unsigned int igsf = 0; igsf < ngsf; ++igsf) {
5656
reco::GsfTrackRef gref(gsftracks, igsf);
57-
reco::TrackRef trk = preid->at(gref->seedRef().castTo<reco::ElectronSeedRef>().index()).trackRef();
57+
reco::TrackRef trk = gref->seedRef().castTo<reco::ElectronSeedRef>()->ctfTrack();
5858

5959
if (trk.id() != tracks.id()) {
6060
throw cms::Exception(

RecoEgamma/EgammaPhotonAlgos/src/ConversionHitChecker.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ std::pair<uint8_t, Measurement1DFloat> ConversionHitChecker::nHitsBeforeVtx(cons
2525
}
2626
++closest;
2727
}
28-
auto globalPosition = recHit->surface()->toGlobal(trajParams[0].position());
28+
auto globalPosition = recHit->surface()->toGlobal(trajParams[closest].position());
2929
auto distance2 = (vtxPos - globalPosition).mag2();
3030
int nhits = 1;
3131
for (unsigned int h = closest + 1; h < track.recHitsSize(); ++h) {

TauAnalysis/MCEmbeddingTools/docs/README

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,4 +27,4 @@ cmsDriver.py ...
2727
--customise TauAnalysis/MCEmbeddingTools/customisers.customisoptions,TauAnalysis/MCEmbeddingTools/customisers.customiseMerging \
2828

2929

30-
You can find some working examples for CMSSW_8_0_21 in this folder.
30+
You can find some working examples for CMSSW_8_0_21 in this folder.
Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,14 @@
1-
<use name="FWCore/Framework"/>
2-
<use name="FWCore/ParameterSet"/>
3-
<use name="DataFormats/PatCandidates"/>
41
<use name="pythia8"/>
52
<use name="DataFormats/RPCRecHit"/>
63
<use name="DataFormats/EcalRecHit"/>
74
<use name="DataFormats/HcalRecHit"/>
85
<use name="TrackingTools/TrackAssociator"/>
9-
<use name="DataFormats/TrackReco"/>
106
<use name="CondFormats/BeamSpotObjects"/>
117
<use name="SimDataFormats/GeneratorProducts"/>
8+
<use name="CommonTools/UtilAlgos"/>
9+
<use name="PhysicsTools/UtilAlgos"/>
10+
<use name="CondFormats/JetMETObjects"/>
11+
<use name="JetMETCorrections/Objects"/>
12+
<use name="JetMETCorrections/JetCorrector"/>
13+
<use name="RecoMET/METAlgorithms"/>
1214
<flags EDM_PLUGIN="1"/>

TauAnalysis/MCEmbeddingTools/plugins/CaloCleaner.cc

Lines changed: 74 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -5,23 +5,92 @@
55
#include "DataFormats/HcalRecHit/interface/HFRecHit.h"
66
#include "DataFormats/HcalRecHit/interface/HORecHit.h"
77
#include "DataFormats/HcalRecHit/interface/ZDCRecHit.h"
8-
#include "DataFormats/HcalRecHit/interface/CastorRecHit.h"
98

109
typedef CaloCleaner<EcalRecHit> EcalRecHitColCleaner;
1110
typedef CaloCleaner<HBHERecHit> HBHERecHitColCleaner;
1211
typedef CaloCleaner<HFRecHit> HFRecHitColCleaner;
1312
typedef CaloCleaner<HORecHit> HORecHitColCleaner;
14-
typedef CaloCleaner<CastorRecHit> CastorRecHitColCleaner;
1513
typedef CaloCleaner<ZDCRecHit> ZDCRecHitColCleaner;
1614

15+
template <typename T>
16+
CaloCleaner<T>::CaloCleaner(const edm::ParameterSet &iConfig)
17+
: mu_input_(consumes<edm::View<pat::Muon>>(iConfig.getParameter<edm::InputTag>("MuonCollection"))),
18+
propagatorToken_(esConsumes(edm::ESInputTag("", "SteppingHelixPropagatorAny"))) {
19+
std::vector<edm::InputTag> inCollections = iConfig.getParameter<std::vector<edm::InputTag>>("oldCollection");
20+
for (const auto &inCollection : inCollections) {
21+
inputs_[inCollection.instance()] = consumes<RecHitCollection>(inCollection);
22+
produces<RecHitCollection>(inCollection.instance());
23+
}
24+
25+
is_preshower_ = iConfig.getUntrackedParameter<bool>("is_preshower", false);
26+
edm::ParameterSet parameters = iConfig.getParameter<edm::ParameterSet>("TrackAssociatorParameters");
27+
edm::ConsumesCollector iC = consumesCollector();
28+
parameters_.loadParameters(parameters, iC);
29+
}
30+
31+
template <typename T>
32+
CaloCleaner<T>::~CaloCleaner() {
33+
// nothing to be done yet...
34+
}
35+
36+
template <typename T>
37+
void CaloCleaner<T>::produce(edm::Event &iEvent, const edm::EventSetup &iSetup) {
38+
auto const &propagator = iSetup.getData(propagatorToken_);
39+
trackAssociator_.setPropagator(&propagator);
40+
41+
edm::Handle<edm::View<pat::Muon>> muonHandle;
42+
iEvent.getByToken(mu_input_, muonHandle);
43+
edm::View<pat::Muon> muons = *muonHandle;
44+
45+
std::map<uint32_t, float> correction_map;
46+
47+
// Fill the correction map
48+
for (edm::View<pat::Muon>::const_iterator iMuon = muons.begin(); iMuon != muons.end(); ++iMuon) {
49+
const reco::Track *track = nullptr;
50+
if (iMuon->track().isNonnull())
51+
track = iMuon->track().get();
52+
else if (iMuon->standAloneMuon().isNonnull())
53+
track = iMuon->standAloneMuon().get();
54+
else
55+
throw cms::Exception("FatalError")
56+
<< "Failed to fill muon id information for a muon with undefined references to tracks";
57+
TrackDetMatchInfo info =
58+
trackAssociator_.associate(iEvent, iSetup, *track, parameters_, TrackDetectorAssociator::Any);
59+
fill_correction_map(&info, &correction_map);
60+
}
61+
62+
// Copy the old collection and correct if necessary
63+
for (const auto &input_ : inputs_) {
64+
std::unique_ptr<RecHitCollection> recHitCollection_output(new RecHitCollection());
65+
edm::Handle<RecHitCollection> recHitCollection;
66+
iEvent.getByToken(input_.second, recHitCollection);
67+
for (typename RecHitCollection::const_iterator recHit = recHitCollection->begin();
68+
recHit != recHitCollection->end();
69+
++recHit) {
70+
if (correction_map[recHit->detid().rawId()] > 0) {
71+
float new_energy = recHit->energy() - correction_map[recHit->detid().rawId()];
72+
if (new_energy <= 0)
73+
continue; // Do not save empty Hits
74+
T newRecHit(*recHit);
75+
newRecHit.setEnergy(new_energy);
76+
recHitCollection_output->push_back(newRecHit);
77+
} else {
78+
recHitCollection_output->push_back(*recHit);
79+
}
80+
}
81+
// Save the new collection
82+
recHitCollection_output->sort();
83+
iEvent.put(std::move(recHitCollection_output), input_.first);
84+
}
85+
}
86+
1787
//-------------------------------------------------------------------------------
1888
// define 'buildRecHit' functions used for different types of recHits
1989
//-------------------------------------------------------------------------------
2090

2191
template <typename T>
2292
void CaloCleaner<T>::fill_correction_map(TrackDetMatchInfo *, std::map<uint32_t, float> *) {
23-
assert(0); // CV: make sure general function never gets called;
24-
// always use template specializations
93+
assert(0);
2594
}
2695

2796
template <>
@@ -36,7 +105,6 @@ void CaloCleaner<EcalRecHit>::fill_correction_map(TrackDetMatchInfo *info, std::
36105
for (std::vector<const EcalRecHit *>::const_iterator hit = info->crossedEcalRecHits.begin();
37106
hit != info->crossedEcalRecHits.end();
38107
hit++) {
39-
// (*cor_map) [(*hit)->detid().rawId()] +=(*hit)->energy();
40108
(*cor_map)[(*hit)->detid().rawId()] = (*hit)->energy();
41109
}
42110
}
@@ -65,20 +133,14 @@ void CaloCleaner<HFRecHit>::fill_correction_map(TrackDetMatchInfo *info, std::ma
65133
return; // No corrections for HF
66134
}
67135

68-
template <>
69-
void CaloCleaner<CastorRecHit>::fill_correction_map(TrackDetMatchInfo *info, std::map<uint32_t, float> *cor_map) {
70-
return; // No corrections for Castor
71-
}
72-
73136
template <>
74137
void CaloCleaner<ZDCRecHit>::fill_correction_map(TrackDetMatchInfo *info, std::map<uint32_t, float> *cor_map) {
75-
return; // No corrections for Castor
138+
return; // No corrections for ZDC
76139
}
77140

78141
DEFINE_FWK_MODULE(EcalRecHitColCleaner);
79142
DEFINE_FWK_MODULE(HBHERecHitColCleaner);
80143
DEFINE_FWK_MODULE(HORecHitColCleaner);
81144
// no need for cleaning outside of tracker, so just a copy of the old collection
82145
DEFINE_FWK_MODULE(HFRecHitColCleaner);
83-
DEFINE_FWK_MODULE(CastorRecHitColCleaner);
84146
DEFINE_FWK_MODULE(ZDCRecHitColCleaner);
Lines changed: 15 additions & 101 deletions
Original file line numberDiff line numberDiff line change
@@ -1,141 +1,55 @@
11
/** \class CaloCleaner
22
*
33
* Clean collections of calorimeter recHits
4-
* (detectors supported at the moment: EB/EE, HB/HE and HO)
5-
*
4+
* (detectors supported: EB/EE, HB/HE and HO)
5+
*
66
* \author Tomasz Maciej Frueboes;
77
* Christian Veelken, LLR
8-
*
9-
*
10-
*
118
* Clean Up from STefan Wayand, KIT
9+
* Clean Up from Christian Winter & Sebastian Brommer, KIT
1210
*/
1311
#ifndef TauAnalysis_MCEmbeddingTools_CaloCleaner_H
1412
#define TauAnalysis_MCEmbeddingTools_CaloCleaner_H
1513

16-
#include "FWCore/Framework/interface/stream/EDProducer.h"
17-
#include "FWCore/Framework/interface/Event.h"
18-
#include "FWCore/ParameterSet/interface/ParameterSet.h"
1914
#include "DataFormats/Common/interface/Handle.h"
20-
#include "DataFormats/PatCandidates/interface/Muon.h"
2115
#include "DataFormats/MuonReco/interface/MuonEnergy.h"
16+
#include "DataFormats/PatCandidates/interface/Muon.h"
17+
#include "FWCore/Framework/interface/Event.h"
2218
#include "FWCore/Framework/interface/MakerMacros.h"
19+
#include "FWCore/Framework/interface/stream/EDProducer.h"
20+
#include "FWCore/ParameterSet/interface/ParameterSet.h"
2321

22+
#include "TrackingTools/Records/interface/TrackingComponentsRecord.h"
2423
#include "TrackingTools/TrackAssociator/interface/TrackAssociatorParameters.h"
2524
#include "TrackingTools/TrackAssociator/interface/TrackDetectorAssociator.h"
26-
#include "TrackingTools/Records/interface/TrackingComponentsRecord.h"
2725

2826
#include "DataFormats/Common/interface/SortedCollection.h"
2927
#include "DataFormats/EcalRecHit/interface/EcalRecHit.h"
3028

31-
#include <string>
3229
#include <iostream>
3330
#include <map>
31+
#include <string>
3432

3533
template <typename T>
3634
class CaloCleaner : public edm::stream::EDProducer<> {
3735
public:
38-
explicit CaloCleaner(const edm::ParameterSet&);
36+
explicit CaloCleaner(const edm::ParameterSet &);
3937
~CaloCleaner() override;
4038

4139
private:
42-
void produce(edm::Event&, const edm::EventSetup&) override;
40+
void produce(edm::Event &, const edm::EventSetup &) override;
4341

4442
typedef edm::SortedCollection<T> RecHitCollection;
4543

46-
const edm::EDGetTokenT<edm::View<pat::Muon> > mu_input_;
44+
const edm::EDGetTokenT<edm::View<pat::Muon>> mu_input_;
4745

48-
std::map<std::string, edm::EDGetTokenT<RecHitCollection> > inputs_;
46+
std::map<std::string, edm::EDGetTokenT<RecHitCollection>> inputs_;
4947
edm::ESGetToken<Propagator, TrackingComponentsRecord> propagatorToken_;
5048

5149
TrackDetectorAssociator trackAssociator_;
5250
TrackAssociatorParameters parameters_;
5351

5452
bool is_preshower_;
55-
void fill_correction_map(TrackDetMatchInfo*, std::map<uint32_t, float>*);
53+
void fill_correction_map(TrackDetMatchInfo *, std::map<uint32_t, float> *);
5654
};
57-
58-
template <typename T>
59-
CaloCleaner<T>::CaloCleaner(const edm::ParameterSet& iConfig)
60-
: mu_input_(consumes<edm::View<pat::Muon> >(iConfig.getParameter<edm::InputTag>("MuonCollection"))),
61-
propagatorToken_(esConsumes(edm::ESInputTag("", "SteppingHelixPropagatorAny"))) {
62-
std::vector<edm::InputTag> inCollections = iConfig.getParameter<std::vector<edm::InputTag> >("oldCollection");
63-
for (const auto& inCollection : inCollections) {
64-
inputs_[inCollection.instance()] = consumes<RecHitCollection>(inCollection);
65-
produces<RecHitCollection>(inCollection.instance());
66-
}
67-
68-
is_preshower_ = iConfig.getUntrackedParameter<bool>("is_preshower", false);
69-
edm::ParameterSet parameters = iConfig.getParameter<edm::ParameterSet>("TrackAssociatorParameters");
70-
edm::ConsumesCollector iC = consumesCollector();
71-
parameters_.loadParameters(parameters, iC);
72-
//trackAssociator_.useDefaultPropagator();
73-
}
74-
75-
template <typename T>
76-
CaloCleaner<T>::~CaloCleaner() {
77-
// nothing to be done yet...
78-
}
79-
80-
template <typename T>
81-
void CaloCleaner<T>::produce(edm::Event& iEvent, const edm::EventSetup& iSetup) {
82-
auto const& propagator = iSetup.getData(propagatorToken_);
83-
trackAssociator_.setPropagator(&propagator);
84-
85-
edm::Handle<edm::View<pat::Muon> > muonHandle;
86-
iEvent.getByToken(mu_input_, muonHandle);
87-
edm::View<pat::Muon> muons = *muonHandle;
88-
89-
std::map<uint32_t, float> correction_map;
90-
91-
// Fill the correction map
92-
for (edm::View<pat::Muon>::const_iterator iMuon = muons.begin(); iMuon != muons.end(); ++iMuon) {
93-
// get the basic informaiton like fill reco mouon does
94-
// RecoMuon/MuonIdentification/plugins/MuonIdProducer.cc
95-
const reco::Track* track = nullptr;
96-
if (iMuon->track().isNonnull())
97-
track = iMuon->track().get();
98-
else if (iMuon->standAloneMuon().isNonnull())
99-
track = iMuon->standAloneMuon().get();
100-
else
101-
throw cms::Exception("FatalError")
102-
<< "Failed to fill muon id information for a muon with undefined references to tracks";
103-
TrackDetMatchInfo info =
104-
trackAssociator_.associate(iEvent, iSetup, *track, parameters_, TrackDetectorAssociator::Any);
105-
fill_correction_map(&info, &correction_map);
106-
}
107-
108-
// Copy the old collection and correct if necessary
109-
for (auto input_ : inputs_) {
110-
std::unique_ptr<RecHitCollection> recHitCollection_output(new RecHitCollection());
111-
edm::Handle<RecHitCollection> recHitCollection;
112-
// iEvent.getByToken(input_.second[0], recHitCollection);
113-
iEvent.getByToken(input_.second, recHitCollection);
114-
for (typename RecHitCollection::const_iterator recHit = recHitCollection->begin();
115-
recHit != recHitCollection->end();
116-
++recHit) {
117-
if (correction_map[recHit->detid().rawId()] > 0) {
118-
float new_energy = recHit->energy() - correction_map[recHit->detid().rawId()];
119-
if (new_energy <= 0)
120-
continue; // Do not save empty Hits
121-
T newRecHit(*recHit);
122-
newRecHit.setEnergy(new_energy);
123-
recHitCollection_output->push_back(newRecHit);
124-
} else {
125-
recHitCollection_output->push_back(*recHit);
126-
}
127-
/* For the inveted collection
128-
if (correction_map[recHit->detid().rawId()] > 0){
129-
float new_energy = correction_map[recHit->detid().rawId()];
130-
if (new_energy < 0) new_energy =0;
131-
T newRecHit(*recHit);
132-
newRecHit.setEnergy(new_energy);
133-
recHitCollection_output->push_back(newRecHit);
134-
}*/
135-
}
136-
// Save the new collection
137-
recHitCollection_output->sort();
138-
iEvent.put(std::move(recHitCollection_output), input_.first);
139-
}
140-
}
141-
#endif
55+
#endif

0 commit comments

Comments
 (0)