CMS 3D CMS Logo

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