CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
HLTTauRefProducer.cc
Go to the documentation of this file.
2 #include "TLorentzVector.h"
3 // TAU includes
8 // ELECTRON includes
17 // MUON includes
20 #include "TLorentzVector.h"
22 //CaloTower includes
26 #include "Math/GenVector/VectorUtil.h"
27 
28 
29 using namespace edm;
30 using namespace reco;
31 using namespace std;
32 
34 {
35 
36 
37  //One Parameter Set per Collection
38 
39  ParameterSet pfTau = iConfig.getUntrackedParameter<edm::ParameterSet>("PFTaus");
40  PFTaus_ = consumes<reco::PFTauCollection>(pfTau.getUntrackedParameter<InputTag>("PFTauProducer"));
41  auto discs = pfTau.getUntrackedParameter<std::vector<InputTag> >("PFTauDiscriminators");
42  for(edm::InputTag& tag: discs) {
43  PFTauDis_.push_back(consumes<reco::PFTauDiscriminator>(tag));
44  }
45  doPFTaus_ = pfTau.getUntrackedParameter<bool>("doPFTaus",false);
46  ptMinPFTau_= pfTau.getUntrackedParameter<double>("ptMin",15.);
47 
49  Electrons_ = consumes<reco::GsfElectronCollection>(electrons.getUntrackedParameter<InputTag>("ElectronCollection"));
50  doElectrons_ = electrons.getUntrackedParameter<bool>("doElectrons",false);
51  e_doID_ = electrons.getUntrackedParameter<bool>("doID",false);
52  if(e_doID_) {
53  e_idAssocProd_ = consumes<reco::ElectronIDAssociationCollection>(electrons.getUntrackedParameter<InputTag>("IdCollection"));
54  }
55  e_ctfTrackCollectionSrc_ = electrons.getUntrackedParameter<InputTag>("TrackCollection");
56  e_ctfTrackCollection_ = consumes<reco::TrackCollection>(e_ctfTrackCollectionSrc_);
57  ptMinElectron_= electrons.getUntrackedParameter<double>("ptMin",15.);
58  e_doTrackIso_ = electrons.getUntrackedParameter<bool>("doTrackIso",false);
59  e_trackMinPt_= electrons.getUntrackedParameter<double>("ptMinTrack",1.5);
60  e_lipCut_= electrons.getUntrackedParameter<double>("lipMinTrack",1.5);
61  e_minIsoDR_= electrons.getUntrackedParameter<double>("InnerConeDR",0.02);
62  e_maxIsoDR_= electrons.getUntrackedParameter<double>("OuterConeDR",0.6);
63  e_isoMaxSumPt_= electrons.getUntrackedParameter<double>("MaxIsoVar",0.02);
64 
66  Muons_ = consumes<reco::MuonCollection>(muons.getUntrackedParameter<InputTag>("MuonCollection"));
67  doMuons_ = muons.getUntrackedParameter<bool>("doMuons",false);
68  ptMinMuon_= muons.getUntrackedParameter<double>("ptMin",15.);
69 
71  Jets_ = consumes<reco::CaloJetCollection>(jets.getUntrackedParameter<InputTag>("JetCollection"));
72  doJets_ = jets.getUntrackedParameter<bool>("doJets");
73  ptMinJet_= jets.getUntrackedParameter<double>("etMin");
74 
75  ParameterSet towers = iConfig.getUntrackedParameter<edm::ParameterSet>("Towers");
76  Towers_ = consumes<CaloTowerCollection>(towers.getUntrackedParameter<InputTag>("TowerCollection"));
77  doTowers_ = towers.getUntrackedParameter<bool>("doTowers");
78  ptMinTower_= towers.getUntrackedParameter<double>("etMin");
79  towerIsol_= towers.getUntrackedParameter<double>("towerIsolation");
80 
82  Photons_ = consumes<reco::PhotonCollection>(photons.getUntrackedParameter<InputTag>("PhotonCollection"));
83  doPhotons_ = photons.getUntrackedParameter<bool>("doPhotons");
84  ptMinPhoton_= photons.getUntrackedParameter<double>("etMin");
85  photonEcalIso_= photons.getUntrackedParameter<double>("ECALIso");
86 
87 
88  etaMax = iConfig.getUntrackedParameter<double>("EtaMax",2.5);
89 
90 
91  //recoCollections
92  produces<LorentzVectorCollection>("PFTaus");
93  produces<LorentzVectorCollection>("Electrons");
94  produces<LorentzVectorCollection>("Muons");
95  produces<LorentzVectorCollection>("Jets");
96  produces<LorentzVectorCollection>("Photons");
97  produces<LorentzVectorCollection>("Towers");
98 
99 }
100 
102 
104 {
105  if(doPFTaus_)
106  doPFTaus(iEvent,iES);
107  if(doElectrons_)
108  doElectrons(iEvent,iES);
109  if(doMuons_)
110  doMuons(iEvent,iES);
111  if(doJets_)
112  doJets(iEvent,iES);
113  if(doPhotons_)
114  doPhotons(iEvent,iES);
115  if(doTowers_)
116  doTowers(iEvent,iES);
117 
118 }
119 
120 void
122 {
123  auto_ptr<LorentzVectorCollection> product_PFTaus(new LorentzVectorCollection);
124  //Retrieve the collection
126  if(iEvent.getByToken(PFTaus_,pftaus)) {
127  for(unsigned int i=0; i<pftaus->size(); ++i) {
128  if((*pftaus)[i].pt()>ptMinPFTau_&&fabs((*pftaus)[i].eta())<etaMax)
129  {
130  reco::PFTauRef thePFTau(pftaus,i);
131  bool passAll = true;
132  for(edm::EDGetTokenT<reco::PFTauDiscriminator>& token: PFTauDis_) {
134  if(iEvent.getByToken(token, pftaudis)) {
135  if((*pftaudis)[thePFTau] < 0.5) {
136  passAll = false;
137  break;
138  }
139  }
140  }
141  if(passAll) {
142  LorentzVector vec((*pftaus)[i].px(),(*pftaus)[i].py(),(*pftaus)[i].pz(),(*pftaus)[i].energy());
143  product_PFTaus->push_back(vec);
144  }
145  }
146  }
147  }
148  iEvent.put(product_PFTaus,"PFTaus");
149 }
150 
151 
152 void
154 {
155  auto_ptr<LorentzVectorCollection> product_Electrons(new LorentzVectorCollection);
156  //Retrieve the collections
157 
159  if(e_doID_){//UGLY HACK UNTIL GET ELETRON ID WORKING IN 210
160 
161  iEvent.getByToken(e_idAssocProd_, pEleID);
162 
163  if (!pEleID.isValid()){
164  edm::LogInfo("")<< "Error! Can't get electronIDAssocProducer by label. ";
165  e_doID_ = false;
166  }
167  }
169  iEvent.getByToken(e_ctfTrackCollection_, pCtfTracks);
170  if (!pCtfTracks.isValid()) {
171  edm::LogInfo("")<< "Error! Can't get " << e_ctfTrackCollectionSrc_.label() << " by label. ";
172  iEvent.put(product_Electrons,"Electrons");
173  return;
174  }
175  const reco::TrackCollection * ctfTracks = pCtfTracks.product();
177  if(iEvent.getByToken(Electrons_,electrons))
178  for(size_t i=0;i<electrons->size();++i)
179  {
180  edm::Ref<reco::GsfElectronCollection> electronRef(electrons,i);
181  bool idDec=false;
182  if(e_doID_){
184  tagIDAssocItr = pEleID->find(electronRef);
185  const reco::ElectronIDRef& id_tag = tagIDAssocItr->val;
186  idDec=id_tag->cutBasedDecision();
187  }else idDec=true;
188  if((*electrons)[i].pt()>ptMinElectron_&&fabs((*electrons)[i].eta())<etaMax&&idDec)
189  {
190  if(e_doTrackIso_){
191  reco::TrackCollection::const_iterator tr = ctfTracks->begin();
192  double sum_of_pt_ele=0;
193  for(;tr != ctfTracks->end();++tr)
194  {
195  double lip = (*electrons)[i].gsfTrack()->dz() - tr->dz();
196  if(tr->pt() > e_trackMinPt_ && fabs(lip) < e_lipCut_){
197  double dphi=fabs(tr->phi()-(*electrons)[i].trackMomentumAtVtx().phi());
198  if(dphi>acos(-1.))dphi=2*acos(-1.)-dphi;
199  double deta=fabs(tr->eta()-(*electrons)[i].trackMomentumAtVtx().eta());
200  double dr_ctf_ele = sqrt(deta*deta+dphi*dphi);
201  if((dr_ctf_ele>e_minIsoDR_) && (dr_ctf_ele<e_maxIsoDR_)){
202  double cft_pt_2 = (tr->pt())*(tr->pt());
203  sum_of_pt_ele += cft_pt_2;
204  }
205  }
206  }
207  double isolation_value_ele = sum_of_pt_ele/((*electrons)[i].trackMomentumAtVtx().Rho()*(*electrons)[i].trackMomentumAtVtx().Rho());
208  if(isolation_value_ele<e_isoMaxSumPt_){
209  LorentzVector vec((*electrons)[i].px(),(*electrons)[i].py(),(*electrons)[i].pz(),(*electrons)[i].energy());
210  product_Electrons->push_back(vec);
211  }
212 
213  }
214  else{
215  LorentzVector vec((*electrons)[i].px(),(*electrons)[i].py(),(*electrons)[i].pz(),(*electrons)[i].energy());
216  product_Electrons->push_back(vec);
217  }
218  }
219  }
220 
221  iEvent.put(product_Electrons,"Electrons");
222 }
223 
224 void
226 {
227  auto_ptr<LorentzVectorCollection> product_Muons(new LorentzVectorCollection);
228  //Retrieve the collection
230  if(iEvent.getByToken(Muons_,muons))
231 
232  for(size_t i = 0 ;i<muons->size();++i)
233  {
234 
235  if((*muons)[i].pt()>ptMinMuon_&&fabs((*muons)[i].eta())<etaMax)
236  {
237  LorentzVector vec((*muons)[i].px(),(*muons)[i].py(),(*muons)[i].pz(),(*muons)[i].energy());
238  product_Muons->push_back(vec);
239  }
240  }
241 
242 
243  iEvent.put(product_Muons,"Muons");
244 
245 }
246 
247 
248 void
250 {
251  auto_ptr<LorentzVectorCollection> product_Jets(new LorentzVectorCollection);
252  //Retrieve the collection
254  if(iEvent.getByToken(Jets_,jets))
255  for(size_t i = 0 ;i<jets->size();++i)
256  {
257  if((*jets)[i].et()>ptMinJet_&&fabs((*jets)[i].eta())<etaMax)
258  {
259  LorentzVector vec((*jets)[i].px(),(*jets)[i].py(),(*jets)[i].pz(),(*jets)[i].energy());
260  product_Jets->push_back(vec);
261  }
262  }
263  iEvent.put(product_Jets,"Jets");
264 }
265 
266 void
268 {
269  auto_ptr<LorentzVectorCollection> product_Towers(new LorentzVectorCollection);
270  //Retrieve the collection
272  if(iEvent.getByToken(Towers_,towers))
273  for(size_t i = 0 ;i<towers->size();++i)
274  {
275  if((*towers)[i].pt()>ptMinTower_&&fabs((*towers)[i].eta())<etaMax)
276  {
277  //calculate isolation
278  double isolET=0;
279  for(unsigned int j=0;j<towers->size();++j)
280  {
281  if(ROOT::Math::VectorUtil::DeltaR((*towers)[i].p4(),(*towers)[j].p4())<0.5)
282  isolET+=(*towers)[j].pt();
283  }
284  isolET-=(*towers)[i].pt();
285  if(isolET<towerIsol_)
286  {
287  LorentzVector vec((*towers)[i].px(),(*towers)[i].py(),(*towers)[i].pz(),(*towers)[i].energy());
288  product_Towers->push_back(vec);
289  }
290  }
291  }
292  iEvent.put(product_Towers,"Towers");
293 }
294 
295 
296 void
298 {
299  auto_ptr<LorentzVectorCollection> product_Gammas(new LorentzVectorCollection);
300  //Retrieve the collection
302  if(iEvent.getByToken(Photons_,photons))
303  for(size_t i = 0 ;i<photons->size();++i)
304  if((*photons)[i].ecalRecHitSumEtConeDR04()<photonEcalIso_)
305  {
306  if((*photons)[i].et()>ptMinPhoton_&&fabs((*photons)[i].eta())<etaMax)
307  {
308  LorentzVector vec((*photons)[i].px(),(*photons)[i].py(),(*photons)[i].pz(),(*photons)[i].energy());
309  product_Gammas->push_back(vec);
310  }
311  }
312  iEvent.put(product_Gammas,"Photons");
313 }
314 
T getUntrackedParameter(std::string const &, T const &) const
int i
Definition: DBlmapReader.cc:9
void doPFTaus(edm::Event &, const edm::EventSetup &)
virtual void produce(edm::Event &, const edm::EventSetup &)
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:434
const std::string id_tag("id")
std::vector< Track > TrackCollection
collection of Tracks
Definition: TrackFwd.h:10
HLTTauRefProducer(const edm::ParameterSet &)
T eta() const
void doTowers(edm::Event &, const edm::EventSetup &)
void doJets(edm::Event &, const edm::EventSetup &)
math::XYZTLorentzVectorD LorentzVector
int iEvent
Definition: GenABIO.cc:243
OrphanHandle< PROD > put(std::auto_ptr< PROD > product)
Put a new product.
Definition: Event.h:116
T sqrt(T t)
Definition: SSEVec.h:48
double p4[4]
Definition: TauolaWrapper.h:92
vector< PseudoJet > jets
int j
Definition: DBlmapReader.cc:9
bool isValid() const
Definition: HandleBase.h:76
void doMuons(edm::Event &, const edm::EventSetup &)
std::vector< LorentzVector > LorentzVectorCollection
T const * product() const
Definition: Handle.h:81
void doPhotons(edm::Event &, const edm::EventSetup &)
tuple muons
Definition: patZpeak.py:38
void doElectrons(edm::Event &, const edm::EventSetup &)