CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
L3MuonIsolationProducer.cc
Go to the documentation of this file.
2 
3 // Framework
8 
10 
12 
16 
19 
22 
25 
27 
28 #include <string>
29 
30 using namespace edm;
31 using namespace std;
32 using namespace reco;
33 using namespace muonisolation;
34 
37  : theConfig(par),
38  theMuonCollectionLabel(par.getParameter<InputTag>("inputMuonCollection")),
39  optOutputIsoDeposits(par.getParameter<bool>("OutputMuIsoDeposits")),
40  theTrackPt_Min(-1) {
41  LogDebug("RecoMuon|L3MuonIsolationProducer") << " L3MuonIsolationProducer CTOR";
42 
43  theMuonCollectionToken = consumes<RecoChargedCandidateCollection>(theMuonCollectionLabel);
44 
46  produces<reco::IsoDepositMap>();
47  produces<edm::ValueMap<bool>>();
48 
49  //
50  // Extractor
51  //
52  edm::ParameterSet extractorPSet = theConfig.getParameter<edm::ParameterSet>("ExtractorPSet");
54  theTrackPt_Min = theConfig.getParameter<double>("TrackPt_Min");
55  std::string extractorName = extractorPSet.getParameter<std::string>("ComponentName");
56  theExtractor = std::unique_ptr<reco::isodeposit::IsoDepositExtractor>{
57  IsoDepositExtractorFactory::get()->create(extractorName, extractorPSet, consumesCollector())};
58  std::string depositType = extractorPSet.getUntrackedParameter<std::string>("DepositLabel");
59 
60  //
61  // Cuts
62  //
64  std::string cutsName = cutsPSet.getParameter<std::string>("ComponentName");
65  if (cutsName == "SimpleCuts") {
66  theCuts = Cuts(cutsPSet);
67  } else if (
68  // (cutsName== "L3NominalEfficiencyCuts_PXLS" && depositType=="PXLS")
69  // || (cutsName== "L3NominalEfficiencyCuts_TRKS" && depositType=="TRKS")
71  (cutsName == "L3NominalEfficiencyCuts_PXLS") || (cutsName == "L3NominalEfficiencyCuts_TRKS")) {
73  } else {
74  LogError("L3MuonIsolationProducer::beginJob") << "cutsName: " << cutsPSet << " is not recognized:"
75  << " theCuts not set!";
76  }
77  LogTrace("") << theCuts.print();
78 
79  // (kludge) additional cut on the number of tracks
80  theMaxNTracks = cutsPSet.getParameter<int>("maxNTracks");
81  theApplyCutsORmaxNTracks = cutsPSet.getParameter<bool>("applyCutsORmaxNTracks");
82 }
83 
86  LogDebug("RecoMuon|L3MuonIsolationProducer") << " L3MuonIsolationProducer DTOR";
87 }
88 
90  std::string metname = "RecoMuon|L3MuonIsolationProducer";
91 
92  LogDebug(metname) << " L3 Muon Isolation producing..."
93  << " BEGINING OF EVENT "
94  << "================================";
95 
96  // Take the SA container
97  LogTrace(metname) << " Taking the muons: " << theMuonCollectionLabel;
99  event.getByToken(theMuonCollectionToken, muons);
100 
101  auto depMap = std::make_unique<reco::IsoDepositMap>();
102  auto isoMap = std::make_unique<edm::ValueMap<bool>>();
103 
104  //
105  // get Vetos and deposits
106  //
107  unsigned int nMuons = muons->size();
108 
109  IsoDeposit::Vetos vetos(nMuons);
110 
111  std::vector<IsoDeposit> deps(nMuons);
112  std::vector<bool> isos(nMuons, false);
113 
114  for (unsigned int i = 0; i < nMuons; i++) {
115  TrackRef mu(muons, i);
116  deps[i] = theExtractor->deposit(event, eventSetup, *mu);
117  vetos[i] = deps[i].veto();
118  }
119 
120  //
121  // add here additional vetos
122  //
123  //.....
124 
125  //
126  // actual cut step
127  //
128  for (unsigned int iMu = 0; iMu < nMuons; ++iMu) {
129  const reco::Track* mu = &(*muons)[iMu];
130 
131  const IsoDeposit& deposit = deps[iMu];
132  LogTrace(metname) << deposit.print();
133 
134  const Cuts::CutSpec& cut = theCuts(mu->eta());
135  std::pair<double, int> sumAndCount = deposit.depositAndCountWithin(cut.conesize, vetos, theTrackPt_Min);
136 
137  double value = sumAndCount.first;
138  int count = sumAndCount.second;
139 
140  bool result = (value < cut.threshold);
142  result |= count <= theMaxNTracks;
143  LogTrace(metname) << "deposit in cone: " << value << "with count " << count << " is isolated: " << result;
144 
145  isos[iMu] = result;
146  }
147 
148  //
149  // store
150  //
151  if (optOutputIsoDeposits) {
152  reco::IsoDepositMap::Filler depFiller(*depMap);
153  depFiller.insert(muons, deps.begin(), deps.end());
154  depFiller.fill();
155  event.put(std::move(depMap));
156  }
157  edm::ValueMap<bool>::Filler isoFiller(*isoMap);
158  isoFiller.insert(muons, isos.begin(), isos.end());
159  isoFiller.fill();
160  event.put(std::move(isoMap));
161 
162  LogTrace(metname) << " END OF EVENT "
163  << "================================";
164 }
const std::string metname
void insert(const H &h, I begin, I end)
Definition: ValueMap.h:53
~L3MuonIsolationProducer() override
destructor
Log< level::Error, false > LogError
#define LogTrace(id)
tuple result
Definition: mps_fire.py:311
std::string print() const
Definition: Cuts.cc:54
bool theApplyCutsORmaxNTracks
apply or not the maxN cut on top of the sumPt (or nominall eff) &lt; cuts
double eta() const
pseudorapidity of momentum vector
Definition: TrackBase.h:652
edm::EDGetTokenT< reco::RecoChargedCandidateCollection > theMuonCollectionToken
def move
Definition: eostools.py:511
const int mu
Definition: Constants.h:22
L3MuonIsolationProducer(const edm::ParameterSet &)
constructor with config
std::unique_ptr< reco::isodeposit::IsoDepositExtractor > theExtractor
tuple deps
Definition: symbols.py:61
T getParameter(std::string const &) const
Definition: ParameterSet.h:303
tuple muons
Definition: patZpeak.py:41
std::pair< double, int > depositAndCountWithin(double coneSize, const Vetos &vetos=Vetos(), double threshold=-1e+36, bool skipDepositVeto=false) const
Get deposit.
Definition: IsoDeposit.cc:37
std::string print() const
Definition: IsoDeposit.cc:178
#define get
void produce(edm::Event &, const edm::EventSetup &) override
Produce isolation maps.
#define LogDebug(id)