CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
L3MuonCombinedRelativeIsolationProducer.cc
Go to the documentation of this file.
2 
3 // Framework
8 
10 
12 
18 
21 
24 
27 
29 
30 #include <string>
31 
32 using namespace edm;
33 using namespace std;
34 using namespace reco;
35 using namespace muonisolation;
36 
39  : theConfig(par),
40  theMuonCollectionLabel(par.getParameter<InputTag>("inputMuonCollection")),
41  optOutputIsoDeposits(par.getParameter<bool>("OutputMuIsoDeposits")),
42  useCaloIso(par.existsAs<bool>("UseCaloIso") ? par.getParameter<bool>("UseCaloIso") : true),
43  useRhoCorrectedCaloDeps(par.existsAs<bool>("UseRhoCorrectedCaloDeposits")
44  ? par.getParameter<bool>("UseRhoCorrectedCaloDeposits")
45  : false),
46  theCaloDepsLabel(par.existsAs<InputTag>("CaloDepositsLabel") ? par.getParameter<InputTag>("CaloDepositsLabel")
47  : InputTag("hltL3CaloMuonCorrectedIsolations")),
48  theTrackPt_Min(-1),
49  printDebug(par.getParameter<bool>("printDebug")) {
50  LogDebug("RecoMuon|L3MuonCombinedRelativeIsolationProducer") << " L3MuonCombinedRelativeIsolationProducer CTOR";
51 
52  theMuonCollectionToken = consumes<RecoChargedCandidateCollection>(theMuonCollectionLabel);
53  theCaloDepsToken = consumes<edm::ValueMap<float>>(theCaloDepsLabel);
54 
56  produces<reco::IsoDepositMap>("trkIsoDeposits");
57  if (useRhoCorrectedCaloDeps == false) // otherwise, calo deposits have been previously computed
58  produces<reco::IsoDepositMap>("caloIsoDeposits");
59  //produces<std::vector<double> >("combinedRelativeIsoDeposits");
60  produces<edm::ValueMap<double>>("combinedRelativeIsoDeposits");
61  }
62  produces<edm::ValueMap<bool>>();
63 
64  //
65  // Extractor
66  //
67  // Calorimeters (ONLY if not previously computed)
68  //
69  if (useCaloIso && (useRhoCorrectedCaloDeps == false)) {
70  edm::ParameterSet caloExtractorPSet = theConfig.getParameter<edm::ParameterSet>("CaloExtractorPSet");
71 
72  std::string caloExtractorName = caloExtractorPSet.getParameter<std::string>("ComponentName");
73  caloExtractor = std::unique_ptr<reco::isodeposit::IsoDepositExtractor>{
74  IsoDepositExtractorFactory::get()->create(caloExtractorName, caloExtractorPSet, consumesCollector())};
75  //std::string caloDepositType = caloExtractorPSet.getUntrackedParameter<std::string>("DepositLabel"); // N.B. Not used in the following!
76  }
77 
78  // Tracker
79  //
80  edm::ParameterSet trkExtractorPSet = theConfig.getParameter<edm::ParameterSet>("TrkExtractorPSet");
81 
82  theTrackPt_Min = theConfig.getParameter<double>("TrackPt_Min");
83  std::string trkExtractorName = trkExtractorPSet.getParameter<std::string>("ComponentName");
84  trkExtractor = std::unique_ptr<reco::isodeposit::IsoDepositExtractor>{
85  IsoDepositExtractorFactory::get()->create(trkExtractorName, trkExtractorPSet, consumesCollector())};
86  //std::string trkDepositType = trkExtractorPSet.getUntrackedParameter<std::string>("DepositLabel"); // N.B. Not used in the following!
87 
88  //
89  // Cuts for track isolation
90  //
92  std::string cutsName = cutsPSet.getParameter<std::string>("ComponentName");
93  if (cutsName == "SimpleCuts") {
94  theCuts = Cuts(cutsPSet);
95  } else if (
96  // (cutsName== "L3NominalEfficiencyCuts_PXLS" && depositType=="PXLS")
97  // || (cutsName== "L3NominalEfficiencyCuts_TRKS" && depositType=="TRKS")
99  (cutsName == "L3NominalEfficiencyCuts_PXLS") || (cutsName == "L3NominalEfficiencyCuts_TRKS")) {
101  } else {
102  LogError("L3MuonCombinedRelativeIsolationProducer::beginJob") << "cutsName: " << cutsPSet << " is not recognized:"
103  << " theCuts not set!";
104  }
105  LogTrace("") << theCuts.print();
106 
107  // (kludge) additional cut on the number of tracks
108  theMaxNTracks = cutsPSet.getParameter<int>("maxNTracks");
109  theApplyCutsORmaxNTracks = cutsPSet.getParameter<bool>("applyCutsORmaxNTracks");
110 }
111 
114  LogDebug("RecoMuon|L3MuonCombinedRelativeIsolationProducer") << " L3MuonCombinedRelativeIsolationProducer DTOR";
115 }
116 
120  desc.add<bool>("UseRhoCorrectedCaloDeposits", false);
121  desc.add<bool>("UseCaloIso", true);
122  desc.add<edm::InputTag>("CaloDepositsLabel", edm::InputTag("hltL3CaloMuonCorrectedIsolations"));
123  desc.add<edm::InputTag>("inputMuonCollection", edm::InputTag("hltL3MuonCandidates"));
124  desc.add<bool>("OutputMuIsoDeposits", true);
125  desc.add<double>("TrackPt_Min", -1.0);
126  desc.add<bool>("printDebug", false);
128  {
129  cutsPSet.add<std::vector<double>>("ConeSizes", std::vector<double>(1, 0.24));
130  cutsPSet.add<std::string>("ComponentName", "SimpleCuts");
131  cutsPSet.add<std::vector<double>>("Thresholds", std::vector<double>(1, 0.1));
132  cutsPSet.add<int>("maxNTracks", -1);
133  cutsPSet.add<std::vector<double>>("EtaBounds", std::vector<double>(1, 2.411));
134  cutsPSet.add<bool>("applyCutsORmaxNTracks", false);
135  }
136  desc.add<edm::ParameterSetDescription>("CutsPSet", cutsPSet);
137  edm::ParameterSetDescription trkExtractorPSet;
138  {
139  trkExtractorPSet.add<double>("Chi2Prob_Min", -1.0);
140  trkExtractorPSet.add<double>("Chi2Ndof_Max", 1.0E64);
141  trkExtractorPSet.add<double>("Diff_z", 0.2);
142  trkExtractorPSet.add<edm::InputTag>("inputTrackCollection", edm::InputTag("hltPixelTracks"));
143  trkExtractorPSet.add<double>("ReferenceRadius", 6.0);
144  trkExtractorPSet.add<edm::InputTag>("BeamSpotLabel", edm::InputTag("hltOnlineBeamSpot"));
145  trkExtractorPSet.add<std::string>("ComponentName", "PixelTrackExtractor");
146  trkExtractorPSet.add<double>("DR_Max", 0.24);
147  trkExtractorPSet.add<double>("Diff_r", 0.1);
148  trkExtractorPSet.add<bool>("VetoLeadingTrack", true);
149  trkExtractorPSet.add<double>("DR_VetoPt", 0.025);
150  trkExtractorPSet.add<double>("DR_Veto", 0.01);
151  trkExtractorPSet.add<unsigned int>("NHits_Min", 0);
152  trkExtractorPSet.add<double>("Pt_Min", -1.0);
153  trkExtractorPSet.addUntracked<std::string>("DepositLabel", "PXLS");
154  trkExtractorPSet.add<std::string>("BeamlineOption", "BeamSpotFromEvent");
155  trkExtractorPSet.add<bool>("PropagateTracksToRadius", true);
156  trkExtractorPSet.add<double>("PtVeto_Min", 2.0);
157  }
158  desc.add<edm::ParameterSetDescription>("TrkExtractorPSet", trkExtractorPSet);
159  edm::ParameterSetDescription caloExtractorPSet;
160  {
161  caloExtractorPSet.add<double>("DR_Veto_H", 0.1);
162  caloExtractorPSet.add<bool>("Vertex_Constraint_Z", false);
163  caloExtractorPSet.add<double>("Threshold_H", 0.5);
164  caloExtractorPSet.add<std::string>("ComponentName", "CaloExtractor");
165  caloExtractorPSet.add<double>("Threshold_E", 0.2);
166  caloExtractorPSet.add<double>("DR_Max", 0.24);
167  caloExtractorPSet.add<double>("DR_Veto_E", 0.07);
168  caloExtractorPSet.add<double>("Weight_E", 1.5);
169  caloExtractorPSet.add<bool>("Vertex_Constraint_XY", false);
170  caloExtractorPSet.addUntracked<std::string>("DepositLabel", "EcalPlusHcal");
171  caloExtractorPSet.add<edm::InputTag>("CaloTowerCollectionLabel", edm::InputTag("hltTowerMakerForMuons"));
172  caloExtractorPSet.add<double>("Weight_H", 1.0);
173  }
174  desc.add<edm::ParameterSetDescription>("CaloExtractorPSet", caloExtractorPSet);
175  descriptions.add("hltL3MuonIsolations", desc);
176 }
177 
179  std::string metname = "RecoMuon|L3MuonCombinedRelativeIsolationProducer";
180 
181  if (printDebug)
182  std::cout << " L3 Muon Isolation producing..."
183  << " BEGINING OF EVENT "
184  << "================================" << std::endl;
185 
186  // Take the SA container
187  if (printDebug)
188  std::cout << " Taking the muons: " << theMuonCollectionLabel << std::endl;
190  event.getByToken(theMuonCollectionToken, muons);
191 
192  // Take calo deposits with rho corrections (ONLY if previously computed)
193  Handle<edm::ValueMap<float>> caloDepWithCorrMap;
195  event.getByToken(theCaloDepsToken, caloDepWithCorrMap);
196 
197  auto caloDepMap = std::make_unique<reco::IsoDepositMap>();
198  auto trkDepMap = std::make_unique<reco::IsoDepositMap>();
199 
200  auto comboIsoDepMap = std::make_unique<edm::ValueMap<bool>>();
201 
202  //auto combinedRelativeDeps = std::make_unique<std::vector<double>>();
203  auto combinedRelativeDepMap = std::make_unique<edm::ValueMap<double>>();
204 
205  //
206  // get Vetos and deposits
207  //
208  unsigned int nMuons = muons->size();
209 
210  IsoDeposit::Vetos trkVetos(nMuons);
211  std::vector<IsoDeposit> trkDeps(nMuons);
212 
213  // IsoDeposit::Vetos caloVetos(nMuons);
214  // std::vector<IsoDeposit> caloDeps(nMuons);
215  // std::vector<float> caloCorrDeps(nMuons, 0.); // if calo deposits with corrections available
216 
217  IsoDeposit::Vetos caloVetos;
218  std::vector<IsoDeposit> caloDeps;
219  std::vector<float> caloCorrDeps; // if calo deposits with corrections available
220 
222  caloCorrDeps.resize(nMuons, 0.);
223  } else if (useCaloIso) {
224  caloVetos.resize(nMuons);
225  caloDeps.resize(nMuons);
226  }
227 
228  std::vector<double> combinedRelativeDeps(nMuons, 0.);
229  std::vector<bool> combinedRelativeIsos(nMuons, false);
230 
231  for (unsigned int i = 0; i < nMuons; i++) {
232  RecoChargedCandidateRef candref(muons, i);
233  TrackRef mu = candref->track();
234 
235  trkDeps[i] = trkExtractor->deposit(event, eventSetup, *mu);
236  trkVetos[i] = trkDeps[i].veto();
237 
239  caloCorrDeps[i] = (*caloDepWithCorrMap)[candref];
240  } else if (useCaloIso) {
241  caloDeps[i] = caloExtractor->deposit(event, eventSetup, *mu);
242  caloVetos[i] = caloDeps[i].veto();
243  }
244  }
245 
246  //
247  // add here additional vetos
248  //
249  //.....
250 
251  //
252  // actual cut step
253  //
254 
255  if (printDebug)
256  std::cout << "Looping over deposits...." << std::endl;
257  for (unsigned int iMu = 0; iMu < nMuons; ++iMu) {
258  if (printDebug)
259  std::cout << "Muon number = " << iMu << std::endl;
260  TrackRef mu = (*muons)[iMu].track();
261 
262  // cuts
263  const Cuts::CutSpec& cut = theCuts(mu->eta());
264 
265  if (printDebug)
266  std::cout << "CUTDEBUG: Muon eta = " << mu->eta() << std::endl
267  << "CUTDEBUG: Muon pt = " << mu->pt() << std::endl
268  << "CUTDEBUG: minEta = " << cut.etaRange.min() << std::endl
269  << "CUTDEBUG: maxEta = " << cut.etaRange.max() << std::endl
270  << "CUTDEBUG: consize = " << cut.conesize << std::endl
271  << "CUTDEBUG: thresho = " << cut.threshold << std::endl;
272 
273  const IsoDeposit& trkDeposit = trkDeps[iMu];
274  if (printDebug)
275  std::cout << trkDeposit.print();
276  std::pair<double, int> trkIsoSumAndCount = trkDeposit.depositAndCountWithin(cut.conesize, trkVetos, theTrackPt_Min);
277 
278  double caloIsoSum = 0.;
280  caloIsoSum = caloCorrDeps[iMu];
281  if (caloIsoSum < 0.)
282  caloIsoSum = 0.;
283  if (printDebug)
284  std::cout << "Rho-corrected calo deposit (min. 0) = " << caloIsoSum << std::endl;
285  } else if (useCaloIso) {
286  const IsoDeposit& caloDeposit = caloDeps[iMu];
287  if (printDebug)
288  std::cout << caloDeposit.print();
289  caloIsoSum = caloDeposit.depositWithin(cut.conesize, caloVetos);
290  }
291 
292  double trkIsoSum = trkIsoSumAndCount.first;
293  int count = trkIsoSumAndCount.second;
294 
295  double muPt = mu->pt();
296  if (muPt < 1.)
297  muPt = 1.;
298  double combinedRelativeDeposit = ((trkIsoSum + caloIsoSum) / muPt);
299  bool result = (combinedRelativeDeposit < cut.threshold);
301  result |= count <= theMaxNTracks;
302  if (printDebug)
303  std::cout << " trk dep in cone: " << trkIsoSum << " with count " << count << std::endl
304  << " calo dep in cone: " << caloIsoSum << std::endl
305  << " muPt: " << muPt << std::endl
306  << " relIso: " << combinedRelativeDeposit << std::endl
307  << " is isolated: " << result << std::endl;
308 
309  combinedRelativeIsos[iMu] = result;
310  //combinedRelativeDeps->push_back(combinedRelativeDeposit);
311  combinedRelativeDeps[iMu] = combinedRelativeDeposit;
312  }
313 
314  //
315  // store
316  //
317  if (optOutputIsoDeposits) {
318  reco::IsoDepositMap::Filler depFillerTrk(*trkDepMap);
319  depFillerTrk.insert(muons, trkDeps.begin(), trkDeps.end());
320  depFillerTrk.fill();
321  event.put(std::move(trkDepMap), "trkIsoDeposits");
322 
323  if (useCaloIso && (useRhoCorrectedCaloDeps == false)) {
324  reco::IsoDepositMap::Filler depFillerCalo(*caloDepMap);
325  depFillerCalo.insert(muons, caloDeps.begin(), caloDeps.end());
326  depFillerCalo.fill();
327  event.put(std::move(caloDepMap), "caloIsoDeposits");
328  }
329 
330  //event.put(std::move(combinedRelativeDeps, "combinedRelativeIsoDeposits");
331  edm::ValueMap<double>::Filler depFillerCombRel(*combinedRelativeDepMap);
332  depFillerCombRel.insert(muons, combinedRelativeDeps.begin(), combinedRelativeDeps.end());
333  depFillerCombRel.fill();
334  event.put(std::move(combinedRelativeDepMap), "combinedRelativeIsoDeposits");
335  }
336  edm::ValueMap<bool>::Filler isoFiller(*comboIsoDepMap);
337  isoFiller.insert(muons, combinedRelativeIsos.begin(), combinedRelativeIsos.end());
338  isoFiller.fill();
339  event.put(std::move(comboIsoDepMap));
340 
341  if (printDebug)
342  std::cout << " END OF EVENT "
343  << "================================";
344 }
edm::EDGetTokenT< reco::RecoChargedCandidateCollection > theMuonCollectionToken
edm::EDGetTokenT< edm::ValueMap< float > > theCaloDepsToken
const std::string metname
bool theApplyCutsORmaxNTracks
apply or not the maxN cut on top of the sumPt (or nominall eff) &lt; cuts
void insert(const H &h, I begin, I end)
Definition: ValueMap.h:53
std::unique_ptr< reco::isodeposit::IsoDepositExtractor > trkExtractor
Log< level::Error, false > LogError
#define LogTrace(id)
tuple result
Definition: mps_fire.py:311
double depositWithin(double coneSize, const Vetos &vetos=Vetos(), bool skipDepositVeto=false) const
Get deposit.
Definition: IsoDeposit.cc:29
std::string print() const
Definition: Cuts.cc:54
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
ParameterSet descriptions.
def move
Definition: eostools.py:511
std::unique_ptr< reco::isodeposit::IsoDepositExtractor > caloExtractor
const int mu
Definition: Constants.h:22
ParameterDescriptionBase * add(U const &iLabel, T const &value)
void produce(edm::Event &, const edm::EventSetup &) override
Produce isolation maps.
L3MuonCombinedRelativeIsolationProducer(const edm::ParameterSet &)
constructor with config
T getParameter(std::string const &) const
Definition: ParameterSet.h:303
void add(std::string const &label, ParameterSetDescription const &psetDescription)
bool useCaloIso
flag to include or exclude calo iso from calculation
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
tuple cout
Definition: gather_cfg.py:144
#define get
#define LogDebug(id)