CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
METManager.cc
Go to the documentation of this file.
2 
5 
9 
11 
12 METManager::METManager(std::string Filename)
13 {
14  outmetfilename_=Filename;
15  std::cout << "Info: DQM is not yet used in METManager."<<std::endl;
16  std::cout << "pfMET validation histograms will be saved to '" << outmetfilename_ << "'" << std::endl;
17  outfile_ = new TFile(outmetfilename_.c_str(), "RECREATE");
18  //void setup(DQMStore *, bool PlotAgainstReco, minDeltaEt,
19  // float maxDeltaEt, float minDeltaPhi, float maxDeltaPhi);
20  //GenBenchmark_.setup(NULL, true, -200., 200., -3.2, 3.2);
21 }
22 
23 void METManager::FillHisto(std::string Name)
24 {
25  //std::cout << "Name = " << Name << std::endl;
26  const std::string fullname=outmetfilename_+":/PFTask/Benchmarks/"+Name;
27 
28  std::map<std::string, GenericBenchmark>::const_iterator i = GenBenchmarkMap_.find( Name );
29  if ( i == GenBenchmarkMap_.end() )
30  {
31  std::cout << "Error in METManager::FillHisto(string): " << Name << " is not in GenBenchmarkMap_" << std::endl;
32  }
33  else
34  {
35  GenBenchmarkMap_[Name].setfile(outfile_);
36  std::vector<reco::MET> vmet1;
37  std::vector<reco::MET> vmet2;
38  vmet1.push_back(MET1_);
39  vmet2.push_back(MET2_);
40  GenBenchmarkMap_[Name].fill(&vmet2,&vmet1,true,false,false,-1.,-1.,-1.,999.);
41  //std::cout << "MET1_.met = " << MET1_.pt() << std::endl;
42  //std::cout << "MET1_.phi = " << MET1_.phi() << std::endl;
43  //std::cout << "MET1_.sumEt = " << MET1_.sumEt() << std::endl;
44  }
45  return;
46 }
47 
49 {
50  if (GenBenchmarkMap_.size()>0)
51  {
52  std::map<std::string, GenericBenchmark>::iterator i = GenBenchmarkMap_.begin();
53  ((*i).second).write(outmetfilename_);
54  }
55 }
56 
58 {
59  MET1_=*met;
60 }
61 
63 {
64  MET2_=*met;
65 }
66 
68 {
69  MET1_=computeGenMET(genParticleList);
70 }
71 
73 {
74  MET2_=computeGenMET(genParticleList);
75 }
76 
78 {
79  MET1_=recomputePFMET(pfCandidates);
80 }
81 
83 {
84  MET2_=recomputePFMET(pfCandidates);
85 }
86 
87 void METManager::SetIgnoreParticlesIDs(const std::vector<unsigned int>* vIgnoreParticlesIDs)
88 {
89  vIgnoreParticlesIDs_=(*vIgnoreParticlesIDs);
90 }
91 
92 void METManager::SetSpecificIdCut(const std::vector<unsigned int>* Id, const std::vector<double>* Eta)
93 {
96 }
97 
99 {
100 
101  double trueMEY = 0.0;
102  double trueMEX = 0.0;;
103  double true_met = 0.0;;
104  double true_set = 0.0;;
105 
106  //std::cout << "(*genParticleList).size() = " << (*genParticleList).size() << std::endl;
107  for( unsigned i = 0; i < (*genParticleList).size(); i++ ) {
108 
109  //std::cout << "(*genParticleList)[i].eta() = " << (*genParticleList)[i].eta() << std::endl;
110 
111  if( (*genParticleList)[i].status() == 1 && fabs((*genParticleList)[i].eta()) < 5.0 ) {
112 
113  bool ignoreThisPart=false;
114  if (vIgnoreParticlesIDs_.size()==0) std::cout << "Warning : METManager: vIgnoreParticlesIDs_.size()==0" << std::endl;
115  for (unsigned int idc=0;idc<vIgnoreParticlesIDs_.size();++idc)
116  {
117  if(std::abs((*genParticleList)[i].pdgId()) == (int)vIgnoreParticlesIDs_[idc])
118  ignoreThisPart=true;
119  }
120  for (unsigned int specificIdc=0;specificIdc<trueMetSpecificIdCut_.size();++specificIdc)
121  {
122  if (std::abs((*genParticleList)[i].pdgId())== (int)trueMetSpecificIdCut_[specificIdc] &&
123  fabs((*genParticleList)[i].eta()) > trueMetSpecificEtaCut_[specificIdc])
124  ignoreThisPart=true;
125  }
126 
127  if (!ignoreThisPart) {
128  //trueMEX -= (*genParticleList)[i].px();
129  //trueMEY -= (*genParticleList)[i].py();
130  trueMEX -= (*genParticleList)[i].et()*cos((*genParticleList)[i].phi());
131  trueMEY -= (*genParticleList)[i].et()*sin((*genParticleList)[i].phi());
132  true_set += (*genParticleList)[i].pt();
133  }
134  }
135  }
136  true_met = sqrt( trueMEX*trueMEX + trueMEY*trueMEY );
137  //const double true_phi = atan2(trueMEY,trueMEX);
138  //std::cout << "true_met = " << true_met << std::endl;
139  //std::cout << "true_phi = " << true_phi << std::endl;
140  math::XYZTLorentzVector p4(trueMEX, trueMEY, 0., true_met);
141  math::XYZPoint vtx(0.,0.,0.);
142  return reco::MET(true_set,p4,vtx);
143 }
144 
145 void METManager::addGenBenchmark(std::string GenBenchmarkName)
146 {
147  GenericBenchmark GenBenchmark;
148  std::string path = outmetfilename_+":/PFTask";
149  if (GenBenchmarkMap_.size()==0)
150  {
151  //gDirectory->pwd();
152  outfile_->mkdir("PFTask");
153  //std::cout << "FL : path.c_str() = " << path.c_str() << std::endl;
154  //outfile_->pwd();
155  //outfile_->cd(path.c_str());
156  gDirectory->cd(path.c_str());
157  //gDirectory->pwd();
158  //outfile_->pwd();
159  gDirectory->mkdir("Benchmarks");
160  //outfile_->mkdir("Benchmarks");
161  //outfile_->pwd();
162  }
163  path = outmetfilename_+":/PFTask/Benchmarks";
164  gDirectory->cd(path.c_str());
165  gDirectory->mkdir(GenBenchmarkName.c_str());
166  path = outmetfilename_+":/PFTask/Benchmarks/"+GenBenchmarkName;
167  //std::cout << "FL : path.c_str() = " << path.c_str() << std::endl;
168  gDirectory->cd(path.c_str());
169  //gDirectory->pwd();
170  //const std::string path = outmetfilename_+":/PFTask/Benchmarks/"+GenBenchmarkName; //+ "/";
171  //std::cout << "path.c_str() = " << path.c_str() << std::endl;
172  //void setup(DQMStore *, bool PlotAgainstReco, minDeltaEt,
173  // float maxDeltaEt, float minDeltaPhi, float maxDeltaPhi);
174  GenBenchmark.setfile(outfile_);
175  GenBenchmark.setup(NULL, true, -200., 200., -3.2, 3.2, true);
176 
177  GenBenchmarkMap_[GenBenchmarkName]=GenBenchmark;
178  //GenBenchmarkV_.push_back(GenBenchmark);
179 }
180 
182 {
183 
185  typedef math::XYZPoint Point;
186 
187  double sum_et = 0.0;
188  double sum_ex = 0.0;
189  double sum_ey = 0.0;
190  double sum_ez = 0.0;
191 
192  double NeutralEMEt = 0.0;
193  double NeutralHadEt = 0.0;
194  double ChargedEMEt = 0.0;
195  double ChargedHadEt = 0.0;
196  double MuonEt = 0.0;
197  double type6Et = 0.0;
198  double type7Et = 0.0;
199 
200  for (unsigned int pfc=0;pfc<pfCandidates.size();++pfc) {
201  double phi = pfCandidates[pfc].phi();
202  double theta = pfCandidates[pfc].theta();
203  double e = pfCandidates[pfc].energy();
204  double et = e*sin(theta);
205  sum_ez += e*cos(theta);
206  sum_et += et;
207  sum_ex += et*cos(phi);
208  sum_ey += et*sin(phi);
209 
210  // compute met specific data:
211  if (pfCandidates[pfc].particleId() == 1) ChargedHadEt += et;
212  if (pfCandidates[pfc].particleId() == 2) ChargedEMEt += et;
213  if (pfCandidates[pfc].particleId() == 3) MuonEt += et;
214  if (pfCandidates[pfc].particleId() == 4) NeutralEMEt += et;
215  if (pfCandidates[pfc].particleId() == 5) NeutralHadEt += et;
216  if (pfCandidates[pfc].particleId() == 6) type6Et += et;
217  if (pfCandidates[pfc].particleId() == 7) type7Et += et;
218 
219  }
220 
221  const double Et_total=NeutralEMEt+NeutralHadEt+ChargedEMEt+ChargedHadEt+MuonEt+type6Et+type7Et;
222 
223  double met = sqrt( sum_ex*sum_ex + sum_ey*sum_ey );
224  const LorentzVector p4( -sum_ex, -sum_ey, 0.0, met);
225  const Point vtx(0.0,0.0,0.0);
226 
228  specific.NeutralEMFraction = NeutralEMEt/Et_total;
229  specific.NeutralHadFraction = NeutralHadEt/Et_total;
230  specific.ChargedEMFraction = ChargedEMEt/Et_total;
231  specific.ChargedHadFraction = ChargedHadEt/Et_total;
232  specific.MuonFraction = MuonEt/Et_total;
233  specific.Type6Fraction = type6Et/Et_total;
234  specific.Type7Fraction = type7Et/Et_total;
235 
236  reco::PFMET specificPFMET( specific, sum_et, p4, vtx );
237  return specificPFMET;
238 }
239 
240 void METManager::coutTailEvents(const int entry, const double DeltaMETcut, const double DeltaPhicut, const double MET1cut) const
241 {
242  const double deltaMET=MET2_.pt()-MET1_.pt();
244  //std::cout << "Delta Phi = " << deltaPhi << std::endl;
245  //std::cout << "fabs(Delta Phi) = " << fabs(deltaPhi) << std::endl;
246 
247  if (MET1_.pt()>MET1cut && (fabs(deltaMET)>DeltaMETcut || fabs(deltaPhi)>DeltaPhicut))
248  {
249  std::cout << " =====================PFMETBenchmark =================" << std::endl;
250  std::cout << "process entry "<< entry << std::endl;
251  std::cout << "Delta MET = " << deltaMET << std::endl;
252  std::cout << "MET1 = " << MET1_.pt() << std::endl;
253  std::cout << "MET2 = " << MET2_.pt() << std::endl;
254 
255  std::cout << "Delta Phi = " << deltaPhi << std::endl;
256  std::cout << "Phi1 = " << MET1_.phi() << std::endl;
257  std::cout << "Phi2 = " << MET2_.phi() << std::endl;
258 
259  }
260 }
261 
262 void METManager::propagateJECtoMET1(const std::vector<reco::CaloJet> caloJets,
263  const std::vector<reco::CaloJet> corr_caloJets)
264 {
265  MET1_=propagateJEC(MET1_,caloJets,corr_caloJets);
266 }
267 
268 void METManager::propagateJECtoMET2(const std::vector<reco::CaloJet> caloJets,
269  const std::vector<reco::CaloJet> corr_caloJets)
270 {
271  MET2_=propagateJEC(MET2_,caloJets,corr_caloJets);
272 }
273 
274 reco::MET METManager::propagateJEC(const reco::MET &MET, const std::vector<reco::CaloJet> caloJets,
275  const std::vector<reco::CaloJet> corr_caloJets) const
276 {
277 
278  //std::cout << "FL : MET = " << MET.pt() << std::endl;
279  double caloJetCorPX = 0.0;
280  double caloJetCorPY = 0.0;
281  double caloJetCorSET = 0.0;
282 
283  if (caloJets.size()>0 && corr_caloJets.size()==0) std::cout << "No corrected calo jets found !" << std::endl;
284  //std::cout << "caloJets.size() = " << caloJets.size() << std::endl;
285  //std::cout << "corr_caloJets.size() = " << corr_caloJets.size() << std::endl;
286 
287  for(unsigned int caloJetc=0;caloJetc<caloJets.size();++caloJetc)
288  {
289  //std::cout << "caloJets[" << caloJetc << "].pt() = " << caloJets[caloJetc].pt() << std::endl;
290  //std::cout << "caloJets[" << caloJetc << "].phi() = " << caloJets[caloJetc].phi() << std::endl;
291  //std::cout << "caloJets[" << caloJetc << "].eta() = " << caloJets[caloJetc].eta() << std::endl;
292  //}
293  for(unsigned int corr_caloJetc=0;corr_caloJetc<corr_caloJets.size();++corr_caloJetc)
294  {
295  //std::cout << "corr_caloJets[" << corr_caloJetc << "].pt() = " << corr_caloJets[corr_caloJetc].pt() << std::endl;
296  //std::cout << "corr_caloJets[" << corr_caloJetc << "].phi() = " << corr_caloJets[corr_caloJetc].phi() << std::endl;
297  //std::cout << "corr_caloJets[" << corr_caloJetc << "].eta() = " << corr_caloJets[corr_caloJetc].eta() << std::endl;
298  //}
299  Float_t DeltaPhi = corr_caloJets[corr_caloJetc].phi() - caloJets[caloJetc].phi();
300  Float_t DeltaEta = corr_caloJets[corr_caloJetc].eta() - caloJets[caloJetc].eta();
301  Float_t DeltaR2 = DeltaPhi*DeltaPhi + DeltaEta*DeltaEta;
302  if( DeltaR2 < 0.0001 && caloJets[caloJetc].pt() > 20.0 )
303  {
304  caloJetCorPX += (corr_caloJets[corr_caloJetc].px() - caloJets[caloJetc].px());
305  caloJetCorPY += (corr_caloJets[corr_caloJetc].py() - caloJets[caloJetc].py());
306  caloJetCorSET += (corr_caloJets[corr_caloJetc].pt() - caloJets[caloJetc].pt());
307  }
308  }
309  }
310  const double corr_calomet=sqrt((MET.px()-caloJetCorPX)*(MET.px()-caloJetCorPX)+(MET.py()-caloJetCorPY)*(MET.py()-caloJetCorPY));
311  const double corr_set=MET.sumEt()+caloJetCorSET;
312  //calo_phi = atan2((cm.py()-caloJetCorPY),(cm.px()-caloJetCorPX));
313  math::XYZTLorentzVector p4(MET.px()-caloJetCorPX, MET.py()-caloJetCorPY, 0., corr_calomet);
314  math::XYZPoint vtx(0.,0.,0.);
315 
316  //std::cout << "FL : corrMET = " << corr_calomet << std::endl;
317  return reco::MET(corr_set,p4,vtx);
318 }
void propagateJECtoMET1(const std::vector< reco::CaloJet > caloJets, const std::vector< reco::CaloJet > corr_caloJets)
propagate the Jet Energy Corrections to the MET
Definition: METManager.cc:262
std::vector< GenParticle > GenParticleCollection
collection of GenParticles
void addGenBenchmark(std::string GenBenchmarkName)
setup a genericBenchmark
Definition: METManager.cc:145
int i
Definition: DBlmapReader.cc:9
dictionary specific
METManager(std::string outmetfilename)
Definition: METManager.cc:12
void write()
Write the output root file of the genericBenchmark.
Definition: METManager.cc:48
TFile * outfile_
Definition: METManager.h:74
void setfile(TFile *file)
Sin< T >::type sin(const T &t)
Definition: Sin.h:22
Geom::Theta< T > theta() const
#define abs(x)
Definition: mlp_lapack.h:159
#define NULL
Definition: scimark2.h:8
reco::MET MET2_
Definition: METManager.h:70
reco::MET recomputePFMET(const reco::PFCandidateCollection &) const
Definition: METManager.cc:181
void coutTailEvents(const int entry, const double DeltaMETcut, const double DeltaPhicut, const double MET1cut) const
cout events in tail of Delta(MET1,MET2)
Definition: METManager.cc:240
T eta() const
std::pair< double, double > Point
Definition: CaloEllipse.h:18
reco::MET computeGenMET(const reco::GenParticleCollection *) const
private functions
Definition: METManager.cc:98
std::vector< PFCandidatePtr > pfCandidates(const PFJet &jet, int particleId, bool sort=true)
XYZTLorentzVectorD XYZTLorentzVector
Lorentz vector with cylindrical internal representation using pseudorapidity.
Definition: LorentzVector.h:30
list path
Definition: scaleCards.py:51
double sumEt() const
Definition: MET.h:48
void FillHisto(std::string)
Definition: METManager.cc:23
Definition: MET.h:32
T sqrt(T t)
Definition: SSEVec.h:46
double p4[4]
Definition: TauolaWrapper.h:92
std::pair< std::string, MonitorElement * > entry
Definition: ME_MAP.h:8
void setMET2(const reco::MET *)
Definition: METManager.cc:62
Cos< T >::type cos(const T &t)
Definition: Cos.h:22
std::string outmetfilename_
Definition: METManager.h:73
MET made from Particle Flow Candidates.
void propagateJECtoMET2(const std::vector< reco::CaloJet > caloJets, const std::vector< reco::CaloJet > corr_caloJets)
Definition: METManager.cc:268
void setMET1(const reco::MET *)
Definition: METManager.cc:57
reco::MET MET1_
data members
Definition: METManager.h:69
std::vector< reco::PFCandidate > PFCandidateCollection
collection of PFCandidates
virtual double px() const
x coordinate of momentum vector
virtual double pt() const
transverse momentum
XYZPointD XYZPoint
point in space with cartesian internal representation
Definition: Point3D.h:13
std::vector< unsigned int > vIgnoreParticlesIDs_
Definition: METManager.h:75
std::map< std::string, GenericBenchmark > GenBenchmarkMap_
map of GenericBenchmarks, the key is his name
Definition: METManager.h:72
std::vector< double > trueMetSpecificEtaCut_
Definition: METManager.h:77
std::vector< unsigned int > trueMetSpecificIdCut_
Definition: METManager.h:76
void SetIgnoreParticlesIDs(const std::vector< unsigned int > *)
Definition: METManager.cc:87
tuple cout
Definition: gather_cfg.py:121
static double deltaPhi(const T *, const U *)
void setup(DQMStore *DQM=NULL, bool PlotAgainstReco_=true, float minDeltaEt=-100., float maxDeltaEt=50., float minDeltaPhi=-0.5, float maxDeltaPhi=0.5, bool doMetPlots=false)
virtual double phi() const
momentum azimuthal angle
virtual double py() const
y coordinate of momentum vector
reco::MET propagateJEC(const reco::MET &, const std::vector< reco::CaloJet > caloJets, const std::vector< reco::CaloJet > corr_caloJets) const
Definition: METManager.cc:274
math::PtEtaPhiELorentzVectorF LorentzVector
Definition: DDAxes.h:10
void SetSpecificIdCut(const std::vector< unsigned int > *, const std::vector< double > *)
Definition: METManager.cc:92