CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
L2TauAnalyzer.cc
Go to the documentation of this file.
2 #include "Math/GenVector/VectorUtil.h"
3 #include <iostream>
4 #include <iomanip>
5 #include <fstream>
6 
8  l2TauInfoAssoc_(consumes<reco::L2TauInfoAssociation>(iConfig.getParameter<edm::InputTag>("L2InfoAssociationInput"))),
9  l1Taus_(consumes<l1extra::L1JetParticleCollection>(iConfig.getParameter<edm::InputTag>("L1TauCollection"))),
10  l1Jets_(consumes<l1extra::L1JetParticleCollection>(iConfig.getParameter<edm::InputTag>("L1JetCollection"))),
11  rootFile_(iConfig.getParameter<std::string>("outputFileName")),
12  IsSignal_(iConfig.getParameter<bool>("IsSignal")),
13  mcColl_(consumes<LVColl>(iConfig.getParameter<edm::InputTag>("MatchedCollection")))
14 {
15  //File Setup
16  l2file = new TFile(rootFile_.c_str(),"recreate");
17  //Tree Setup
18  l2tree = new TTree("l2tree","Level 2 Tau Tree");
19 
20 
21  //Initialize the vars
22  ecalIsol_Et=0.;
23  towerIsol_Et=0.;
24  cl_etaRMS=0.;
25  cl_phiRMS=0.;
26  cl_drRMS=0.;
27  MCeta=0.;
28  MCet=0.;
29  cl_Nclusters=0;
30  seedTowerEt = 0.;
31  JetEt=0.;
32  JetEta=0.;
33  L1et=0.;
34  L1eta=0.;
35  jetEMF = 0.;
36 
37  //Setup Branches
38  l2tree->Branch("ecalIsolEt",&ecalIsol_Et,"ecalIsolEt/F");
39  l2tree->Branch("jetEMF",&jetEMF,"jetEMF/F");
40  l2tree->Branch("towerIsolEt",&towerIsol_Et,"towerIsolEt/F");
41  l2tree->Branch("clEtaRMS",&cl_etaRMS,"clEtaRMS/F");
42  l2tree->Branch("clPhiRMS",&cl_phiRMS,"clPhiRMS/F");
43  l2tree->Branch("clDrRMS",&cl_drRMS,"clDrRMS/F");
44  l2tree->Branch("mcEta",&MCeta,"mcEta/F");
45  l2tree->Branch("mcEt",&MCet,"mcEt/F");
46  l2tree->Branch("clNclusters",&cl_Nclusters,"clNclusters/I");
47  l2tree->Branch("seedTowerEt",&seedTowerEt,"seedTowerEt/F");
48  l2tree->Branch("jetEt",&JetEt,"jetEt/F");
49  l2tree->Branch("jetEta",&JetEta,"jetEta/F");
50  l2tree->Branch("L1Et",&L1et,"L1Et/F");
51  l2tree->Branch("L1Eta",&L1eta,"L1Eta/F");
52 
53 }
54 
55 
57 {
58 }
59 
60 
61 
62 void
64 {
65  using namespace edm;
66  using namespace reco;
67 
68  Handle<L2TauInfoAssociation> l2TauInfoAssoc; //Handle to the input (L2 Tau Info Association)
69  Handle<LVColl> McInfo; //Handle To The Truth!!!!
70  Handle<l1extra::L1JetParticleCollection> L1Taus; //Handle To The L1 Taus
71  Handle<l1extra::L1JetParticleCollection> L1Jets; //Handle To The L1 jets
72 
73  if(iEvent.getByToken(l2TauInfoAssoc_,l2TauInfoAssoc))//get the handle
74  {
75  if(l2TauInfoAssoc->size()>0)
76  for(L2TauInfoAssociation::const_iterator p = l2TauInfoAssoc->begin();p!=l2TauInfoAssoc->end();++p)
77  {
78  const L2TauIsolationInfo l2info = p->val;
79  const CaloJet& jet =*(p->key);
80 
81  MatchElementL2 mcMatch;
82  mcMatch.matched=false;
83  mcMatch.mcEt=0;
84  mcMatch.mcEta=0;
85  mcMatch.deltar=0;
86 
87  if(IsSignal_) //Get Collection and match it
88  {
89  if(iEvent.getByToken(mcColl_,McInfo))
90  mcMatch=match(jet,*McInfo);
91  }
92 
93  if((mcMatch.matched&&IsSignal_)||(!IsSignal_))
94  {
95  //Fill variables
96  jetEMF = jet.emEnergyFraction();
97  ecalIsol_Et=l2info.ecalIsolEt();
98  towerIsol_Et=l2info.hcalIsolEt();
99  cl_Nclusters=l2info.nEcalHits();
100  cl_etaRMS=l2info.ecalClusterShape()[0];
101  cl_phiRMS=l2info.ecalClusterShape()[1];
102  cl_drRMS=l2info.ecalClusterShape()[2];
103  seedTowerEt = l2info.seedHcalHitEt();
104  MCeta =mcMatch.mcEta;
105  MCet=mcMatch.mcEt;
106  JetEt = jet.et();
107  JetEta = jet.eta();
108 
109  //Match with L1 and fill
110  L1et=0;
111  L1eta=0;
112  if(iEvent.getByToken(l1Taus_,L1Taus))
113  {
114  MatchElementL2 l1Match;
115  l1Match.matched=false;
116  l1Match.mcEt=0;
117  l1Match.mcEta=0;
118  l1Match.deltar=0;
119  l1Match=match(jet,*L1Taus);
120  if(l1Match.matched)
121  {
122  L1et=l1Match.mcEt;
123  L1eta=l1Match.mcEta;
124  }
125  //If not matched look at the jet collection
126  else
127  {
128  if(iEvent.getByToken(l1Jets_,L1Jets))
129  {
130  l1Match=match(jet,*L1Taus);
131  if(l1Match.matched)
132  {
133  L1et=l1Match.mcEt;
134  L1eta=l1Match.mcEta;
135  }
136 
137  }
138  }
139 
140  }
141  //Fill Tree
142  l2tree->Fill();
143  }
144 
145  }
146  }
147 }
148 
149 
150 
151 void
153 {
154 
155 }
156 
157 
158 void
160  l2file->Write();
161 
162 }
163 
166 {
167 
168  //Loop On the Collection and see if your tau jet is matched to one there
169  //Also find the nearest Matched MC Particle to your Jet (to be complete)
170 
171  bool matched=false;
172  double delta_min=100.;
173  double mceta=0;
174  double mcet=0;
175 
176  double matchingDR=0.3;
177 
178 
179 
180 
181  if(McInfo.size()>0)
182  for(std::vector<LV>::const_iterator it = McInfo.begin();it!=McInfo.end();++it)
183  {
184  double delta = ROOT::Math::VectorUtil::DeltaR(jet.p4().Vect(),*it);
185  if(delta<matchingDR)
186  {
187  matched=true;
188  if(delta<delta_min)
189  {
190  delta_min=delta;
191  mceta=it->eta();
192  mcet=it->Et();
193  }
194  }
195  }
196 
197  //Create Struct and send it out!
199  match.matched=matched;
200  match.deltar=delta_min;
201  match.mcEta = mceta;
202  match.mcEt = mcet;
203 
204 
205  return match;
206 }
207 
210 {
211 
212  //Loop On the Collection and see if your tau jet is matched to one there
213  //Also find the nearest Matched MC Particle to your Jet (to be complete)
214 
215  bool matched=false;
216  double delta_min=100.;
217  double mceta=0;
218  double mcet=0;
219 
220  double matchingDR=0.5;
221 
222 
223 
224 
225  if(McInfo.size()>0)
226  for(l1extra::L1JetParticleCollection::const_iterator it = McInfo.begin();it!=McInfo.end();++it)
227  {
228  double delta = ROOT::Math::VectorUtil::DeltaR(jet.p4().Vect(),it->p4().Vect());
229  if(delta<matchingDR)
230  {
231  matched=true;
232  if(delta<delta_min)
233  {
234  delta_min=delta;
235  mceta=it->eta();
236  mcet=it->et();
237  }
238  }
239  }
240 
241  //Create Struct and send it out!
243  match.matched=matched;
244  match.deltar=delta_min;
245  match.mcEta = mceta;
246  match.mcEt = mcet;
247 
248 
249  return match;
250 }
251 
252 
253 
254 
255 
dbl * delta
Definition: mlp_gen.cc:36
Jets made from CaloTowers.
Definition: CaloJet.h:29
virtual double et() const
transverse energy
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:434
Base class for all types of Jets.
Definition: Jet.h:20
std::vector< L1JetParticle > L1JetParticleCollection
virtual void analyze(const edm::Event &, const edm::EventSetup &)
TFile * l2file
Definition: L2TauAnalyzer.h:61
virtual void endJob()
int iEvent
Definition: GenABIO.cc:230
L2TauAnalyzer(const edm::ParameterSet &)
Definition: L2TauAnalyzer.cc:7
edm::EDGetTokenT< LVColl > mcColl_
Definition: L2TauAnalyzer.h:54
edm::EDGetTokenT< reco::L2TauInfoAssociation > l2TauInfoAssoc_
Definition: L2TauAnalyzer.h:49
edm::AssociationMap< edm::OneToValue< reco::CaloJetCollection, reco::L2TauIsolationInfo > > L2TauInfoAssociation
std::vector< LV > LVColl
virtual float eta() const
momentum pseudorapidity
edm::EDGetTokenT< l1extra::L1JetParticleCollection > l1Taus_
Definition: L2TauAnalyzer.h:50
MatchElementL2 match(const reco::Jet &, const LVColl &)
std::string rootFile_
Definition: L2TauAnalyzer.h:52
float towerIsol_Et
Definition: L2TauAnalyzer.h:60
edm::EDGetTokenT< l1extra::L1JetParticleCollection > l1Jets_
Definition: L2TauAnalyzer.h:51
std::vector< double > ecalClusterShape() const
TTree * l2tree
Definition: L2TauAnalyzer.h:62
virtual const LorentzVector & p4() const
four-momentum Lorentz vector
float emEnergyFraction() const
Definition: CaloJet.h:102
virtual void beginJob()