CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
L3MuonCombinedRelativeIsolationProducer.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  useRhoCorrectedCaloDeps(par.existsAs<bool>("UseRhoCorrectedCaloDeposits") ?
41  par.getParameter<bool>("UseRhoCorrectedCaloDeposits") : false),
42  theCaloDepsLabel(par.existsAs<InputTag>("CaloDepositsLabel") ?
43  par.getParameter<InputTag>("CaloDepositsLabel") :
44  InputTag("hltL3CaloMuonCorrectedIsolations")),
45  caloExtractor(0),
46  trkExtractor(0),
47  theTrackPt_Min(-1),
48  printDebug (par.getParameter<bool>("printDebug"))
49  {
50  LogDebug("RecoMuon|L3MuonCombinedRelativeIsolationProducer")<<" L3MuonCombinedRelativeIsolationProducer CTOR";
51 
53  produces<reco::IsoDepositMap>("trkIsoDeposits");
54  if( useRhoCorrectedCaloDeps==false ) // otherwise, calo deposits have been previously computed
55  produces<reco::IsoDepositMap>("caloIsoDeposits");
56  //produces<std::vector<double> >("combinedRelativeIsoDeposits");
57  produces<edm::ValueMap<double> >("combinedRelativeIsoDeposits");
58  }
59  produces<edm::ValueMap<bool> >();
60 
61 }
62 
65  LogDebug("RecoMuon|L3MuonCombinedRelativeIsolationProducer")<<" L3MuonCombinedRelativeIsolationProducer DTOR";
66  if (caloExtractor) delete caloExtractor;
67  if (trkExtractor) delete trkExtractor;
68 }
69 
71 {
72 
73  //
74  // Extractor
75  //
76  // Calorimeters (ONLY if not previously computed)
77  //
78  if( useRhoCorrectedCaloDeps==false ) {
79  edm::ParameterSet caloExtractorPSet = theConfig.getParameter<edm::ParameterSet>("CaloExtractorPSet");
80 
81  theTrackPt_Min = theConfig.getParameter<double>("TrackPt_Min");
82  std::string caloExtractorName = caloExtractorPSet.getParameter<std::string>("ComponentName");
83  caloExtractor = IsoDepositExtractorFactory::get()->create( caloExtractorName, caloExtractorPSet);
84  //std::string caloDepositType = caloExtractorPSet.getUntrackedParameter<std::string>("DepositLabel"); // N.B. Not used in the following!
85  }
86 
87  // Tracker
88  //
89  edm::ParameterSet trkExtractorPSet = theConfig.getParameter<edm::ParameterSet>("TrkExtractorPSet");
90 
91  std::string trkExtractorName = trkExtractorPSet.getParameter<std::string>("ComponentName");
92  trkExtractor = IsoDepositExtractorFactory::get()->create( trkExtractorName, trkExtractorPSet);
93  //std::string trkDepositType = trkExtractorPSet.getUntrackedParameter<std::string>("DepositLabel"); // N.B. Not used in the following!
94 
95 
96 
97  //
98  // Cuts for track isolation
99  //
101  std::string cutsName = cutsPSet.getParameter<std::string>("ComponentName");
102  if (cutsName == "SimpleCuts") {
103  theCuts = Cuts(cutsPSet);
104  }
105  else if (
106  // (cutsName== "L3NominalEfficiencyCuts_PXLS" && depositType=="PXLS")
107  // || (cutsName== "L3NominalEfficiencyCuts_TRKS" && depositType=="TRKS")
109  (cutsName== "L3NominalEfficiencyCuts_PXLS" )
110  || (cutsName== "L3NominalEfficiencyCuts_TRKS") ) {
112  }
113  else {
114  LogError("L3MuonCombinedRelativeIsolationProducer::beginJob")
115  <<"cutsName: "<<cutsPSet<<" is not recognized:"
116  <<" theCuts not set!";
117  }
118  LogTrace("")<< theCuts.print();
119 
120  // (kludge) additional cut on the number of tracks
121  theMaxNTracks = cutsPSet.getParameter<int>("maxNTracks");
122  theApplyCutsORmaxNTracks = cutsPSet.getParameter<bool>("applyCutsORmaxNTracks");
123 }
124 
126  std::string metname = "RecoMuon|L3MuonCombinedRelativeIsolationProducer";
127 
128  if (printDebug) std::cout <<" L3 Muon Isolation producing..."
129  <<" BEGINING OF EVENT " <<"================================" <<std::endl;
130 
131  // Take the SA container
132  if (printDebug) std::cout <<" Taking the muons: "<<theMuonCollectionLabel << std::endl;
134  event.getByLabel(theMuonCollectionLabel,muons);
135 
136  // Take calo deposits with rho corrections (ONLY if previously computed)
137  Handle< edm::ValueMap<float> > caloDepWithCorrMap;
139  event.getByLabel(theCaloDepsLabel, caloDepWithCorrMap);
140 
141  std::auto_ptr<reco::IsoDepositMap> caloDepMap( new reco::IsoDepositMap());
142  std::auto_ptr<reco::IsoDepositMap> trkDepMap( new reco::IsoDepositMap());
143 
144  std::auto_ptr<edm::ValueMap<bool> > comboIsoDepMap( new edm::ValueMap<bool> ());
145 
146  //std::auto_ptr<std::vector<double> > combinedRelativeDeps(new std::vector<double>());
147  std::auto_ptr<edm::ValueMap<double> > combinedRelativeDepMap(new edm::ValueMap<double>());
148 
149 
150  //
151  // get Vetos and deposits
152  //
153  unsigned int nMuons = muons->size();
154 
155  IsoDeposit::Vetos trkVetos(nMuons);
156  std::vector<IsoDeposit> trkDeps(nMuons);
157 
158 
159  // IsoDeposit::Vetos caloVetos(nMuons);
160  // std::vector<IsoDeposit> caloDeps(nMuons);
161  // std::vector<float> caloCorrDeps(nMuons, 0.); // if calo deposits with corrections available
162 
163  IsoDeposit::Vetos caloVetos;
164  std::vector<IsoDeposit> caloDeps;
165  std::vector<float> caloCorrDeps; // if calo deposits with corrections available
166 
168  caloCorrDeps.resize(nMuons, 0.);
169  }
170  else {
171  caloVetos.resize(nMuons);
172  caloDeps.resize(nMuons);
173  }
174 
175  std::vector<double> combinedRelativeDeps(nMuons, 0.);
176  std::vector<bool> combinedRelativeIsos(nMuons, false);
177 
178  for (unsigned int i=0; i<nMuons; i++) {
179 
180  TrackRef mu(muons,i);
181 
182  trkDeps[i] = trkExtractor->deposit(event, eventSetup, *mu);
183  trkVetos[i] = trkDeps[i].veto();
184 
186  caloCorrDeps[i] = (*caloDepWithCorrMap)[mu];
187  }
188  else {
189  caloDeps[i] = caloExtractor->deposit(event, eventSetup, *mu);
190  caloVetos[i] = caloDeps[i].veto();
191  }
192 
193  }
194 
195  //
196  // add here additional vetos
197  //
198  //.....
199 
200  //
201  // actual cut step
202  //
203 
204  if (printDebug) std::cout << "Looping over deposits...." << std::endl;
205  for(unsigned int iMu=0; iMu < nMuons; ++iMu){
206 
207  if (printDebug) std::cout << "Muon number = " << iMu << std::endl;
208  const reco::Track* mu = &(*muons)[iMu];
209 
210  // cuts
211  const Cuts::CutSpec & cut = theCuts( mu->eta());
212 
213 
214  if (printDebug) std::cout << "CUTDEBUG: Muon eta = " << mu->eta() << std::endl
215  << "CUTDEBUG: Muon pt = " << mu->pt() << std::endl
216  << "CUTDEBUG: minEta = " << cut.etaRange.min() << std::endl
217  << "CUTDEBUG: maxEta = " << cut.etaRange.max() << std::endl
218  << "CUTDEBUG: consize = " << cut.conesize << std::endl
219  << "CUTDEBUG: thresho = " << cut.threshold << std::endl;
220 
221  const IsoDeposit & trkDeposit = trkDeps[iMu];
222  if (printDebug) std::cout << trkDeposit.print();
223  std::pair<double, int> trkIsoSumAndCount = trkDeposit.depositAndCountWithin(cut.conesize, trkVetos, theTrackPt_Min);
224 
225  double caloIsoSum = 0.;
227  caloIsoSum = caloCorrDeps[iMu];
228  if(caloIsoSum<0.) caloIsoSum = 0.;
229  if(printDebug) std::cout << "Rho-corrected calo deposit (min. 0) = " << caloIsoSum << std::endl;
230  }
231  else {
232  const IsoDeposit & caloDeposit = caloDeps[iMu];
233  if (printDebug) std::cout << caloDeposit.print();
234  caloIsoSum = caloDeposit.depositWithin(cut.conesize, caloVetos);
235  }
236 
237  double trkIsoSum = trkIsoSumAndCount.first;
238  int count = trkIsoSumAndCount.second;
239 
240  double muPt = mu->pt();
241  if( muPt<1. ) muPt = 1.;
242  double combinedRelativeDeposit = ((trkIsoSum + caloIsoSum ) / muPt);
243  bool result = ( combinedRelativeDeposit < cut.threshold);
244  if (theApplyCutsORmaxNTracks ) result |= count <= theMaxNTracks;
245  if (printDebug) std::cout <<" trk dep in cone: " << trkIsoSum << " with count "<<count <<std::endl
246  <<" calo dep in cone: " << caloIsoSum << std::endl
247  <<" muPt: " << muPt << std::endl
248  <<" relIso: " <<combinedRelativeDeposit << std::endl
249  <<" is isolated: "<<result << std::endl;
250 
251  combinedRelativeIsos[iMu] = result;
252  //combinedRelativeDeps->push_back(combinedRelativeDeposit);
253  combinedRelativeDeps[iMu] = combinedRelativeDeposit;
254  }
255 
256  //
257  // store
258  //
260 
261  reco::IsoDepositMap::Filler depFillerTrk(*trkDepMap);
262  depFillerTrk.insert(muons, trkDeps.begin(), trkDeps.end());
263  depFillerTrk.fill();
264  event.put(trkDepMap, "trkIsoDeposits");
265 
266  if( useRhoCorrectedCaloDeps==false ) {
267  reco::IsoDepositMap::Filler depFillerCalo(*caloDepMap);
268  depFillerCalo.insert(muons, caloDeps.begin(), caloDeps.end());
269  depFillerCalo.fill();
270  event.put(caloDepMap, "caloIsoDeposits");
271  }
272 
273  //event.put(combinedRelativeDeps, "combinedRelativeIsoDeposits");
274  edm::ValueMap<double>::Filler depFillerCombRel(*combinedRelativeDepMap);
275  depFillerCombRel.insert(muons, combinedRelativeDeps.begin(), combinedRelativeDeps.end());
276  depFillerCombRel.fill();
277  event.put(combinedRelativeDepMap, "combinedRelativeIsoDeposits");
278 
279  }
280  edm::ValueMap<bool>::Filler isoFiller(*comboIsoDepMap);
281  isoFiller.insert(muons, combinedRelativeIsos.begin(), combinedRelativeIsos.end());
282  isoFiller.fill();
283  event.put(comboIsoDepMap);
284 
285  if (printDebug) std::cout <<" END OF EVENT " <<"================================";
286 }
#define LogDebug(id)
T getParameter(std::string const &) const
int i
Definition: DBlmapReader.cc:9
const T & max() const
Definition: Range.h:25
const Veto & veto() const
Get veto area.
Definition: IsoDeposit.h:73
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
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
double eta() const
pseudorapidity of momentum vector
Definition: TrackBase.h:141
muonisolation::Range< double > etaRange
Definition: Cuts.h:15
virtual void produce(edm::Event &, const edm::EventSetup &)
Produce isolation maps.
double pt() const
track transverse momentum
Definition: TrackBase.h:131
tuple result
Definition: query.py:137
const int mu
Definition: Constants.h:23
How EventSelector::AcceptEvent() decides whether to accept an event for output otherwise it is excluding the probing of A single or multiple positive and the trigger will pass if any such matching triggers are PASS or EXCEPTION[A criterion thatmatches no triggers at all is detected and causes a throw.] A single negative with an expectation of appropriate bit checking in the decision and the trigger will pass if any such matching triggers are FAIL or EXCEPTION A wildcarded negative criterion that matches more than one trigger in the trigger but the state exists so we define the behavior If all triggers are the negative crieriion will lead to accepting the event(this again matches the behavior of"!*"before the partial wildcard feature was incorporated).The per-event"cost"of each negative criterion with multiple relevant triggers is about the same as!*was in the past
#define LogTrace(id)
L3MuonCombinedRelativeIsolationProducer(const edm::ParameterSet &)
constructor with config
const T & min() const
Definition: Range.h:23
tuple muons
Definition: patZpeak.py:38
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
tuple cout
Definition: gather_cfg.py:121
virtual reco::IsoDeposit deposit(const edm::Event &ev, const edm::EventSetup &evSetup, const reco::Track &track) const =0
T get(const Candidate &c)
Definition: component.h:56