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