CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
FactorizedJetCorrectorDemo.cc
Go to the documentation of this file.
1 #include <memory>
2 #include "TH2F.h"
3 #include "TGraph.h"
4 #include "TGraphErrors.h"
5 #include "TRandom.h"
6 #include "TLorentzVector.h"
7 // user include files
10 
21 //TFile Service
24 
25 //
26 // class declaration
27 //
28 
30 public:
34 
35 private:
36  virtual void beginJob() ;
37  virtual void analyze(const edm::Event&, const edm::EventSetup&);
38  virtual void endJob() ;
39 
41  std::vector<std::string> mLevels;
45  std::vector<double> mVEta,mVPt;
46  double vjec_eta[100][1000],vjec_pt[100][1000],vpt[100][1000],vptcor[100][1000],veta[100][1000];
47  double vjecUnc_eta[100][1000],vUnc_eta[100][1000],vjecUnc_pt[100][1000],vUnc_pt[100][1000],vex_eta[100][1000],vex_pt[100][1000];
50  TGraphErrors *mVGraphEta[100],*mVGraphPt[100],*mVGraphCorPt[100];
51  TGraph *mUncEta[100], *mUncCorPt[100];
52  TRandom *mRandom;
53 };
54 //
55 //----------- Class Implementation ------------------------------------------
56 //
57 //---------------------------------------------------------------------------
59 {
60  mLevels = iConfig.getParameter<std::vector<std::string> > ("levels");
61  mPayloadName = iConfig.getParameter<std::string> ("PayloadName");
62  mUncertaintyTag = iConfig.getParameter<std::string> ("UncertaintyTag");
63  mUncertaintyFile = iConfig.getParameter<std::string> ("UncertaintyFile");
64  mNHistoPoints = iConfig.getParameter<int> ("NHistoPoints");
65  mNGraphPoints = iConfig.getParameter<int> ("NGraphPoints");
66  mEtaMin = iConfig.getParameter<double> ("EtaMin");
67  mEtaMax = iConfig.getParameter<double> ("EtaMax");
68  mPtMin = iConfig.getParameter<double> ("PtMin");
69  mPtMax = iConfig.getParameter<double> ("PtMax");
70  mVEta = iConfig.getParameter<std::vector<double> > ("VEta");
71  mVPt = iConfig.getParameter<std::vector<double> > ("VPt");
72  mDebug = iConfig.getUntrackedParameter<bool> ("Debug",false);
73 }
74 //---------------------------------------------------------------------------
76 {
77 
78 }
79 //---------------------------------------------------------------------------
81 {
82 
83  if ( mDebug )
84  std::cout << "Hello from FactorizedJetCorrectorDemo" << std::endl;
85  // retreive parameters from the DB this still need a proper configurable
86  // payloadName like: JetCorrectorParametersCollection_Spring10_AK5Calo.
88  iSetup.get<JetCorrectionsRecord>().get(mPayloadName, parameters);
89 
90  std::vector<JetCorrectorParameters> params;
91  for(std::vector<std::string>::const_iterator level=mLevels.begin(); level!=mLevels.end(); ++level){
92  const JetCorrectorParameters& ip = (*parameters)[*level]; //ip.printScreen();
93  if ( mDebug )
94  std::cout << "Adding level " << *level << std::endl;
95  params.push_back(ip);
96  }
97 
98  boost::shared_ptr<FactorizedJetCorrector> corrector ( new FactorizedJetCorrector(params));
99 
100 
101  double jec,rawPt,corPt,eta;
102  TLorentzVector P4;
103  double dEta = (mEtaMax-mEtaMin)/mNGraphPoints;
104  if ( mDebug )
105  std::cout << "Making JEC vs Eta and pT" << std::endl;
106  for(int i=0;i<mNHistoPoints;i++)
107  {
108  rawPt = mRandom->Uniform(mPtMin,mPtMax);
109  eta = mRandom->Uniform(mEtaMin,mEtaMax);
110  P4.SetPtEtaPhiE(rawPt,eta,0,0);
111  corrector->setJetEta( eta );
112  corrector->setJetPt( rawPt );
113  corrector->setJetE( P4.E() );
114  jec = corrector->getCorrection();
115  mJECvsEta->Fill(eta,jec);
116  mJECvsPt->Fill(rawPt,jec);
117  }
118  if ( mDebug )
119  std::cout << "Making JEC vs pT for different etas" << std::endl;
120  //--------- Pt Graphs ------------------
121  for(unsigned ieta=0;ieta<mVEta.size();ieta++)
122  {
123  double rPt = pow((3500./TMath::CosH(mVEta[ieta]))/mPtMin,1./mNGraphPoints);
124  for(int i=0;i<mNGraphPoints;i++)
125  {
126  rawPt = mPtMin*pow(rPt,i);
127  eta = mVEta[ieta];
128  vpt[ieta][i] = rawPt;
129  P4.SetPtEtaPhiE(rawPt,eta,0,0);
130  corrector->setJetEta( eta );
131  corrector->setJetPt( rawPt );
132  corrector->setJetE( P4.E() );
133  jec = corrector->getCorrection();
134  vjec_eta[ieta][i] = jec;
135  vptcor[ieta][i] = rawPt*jec;
136  vex_eta[ieta][i] = 0.0;
137  if (mDebug)
138  std::cout<<rawPt<<" "<<eta<<" "<<jec<<" "<<rawPt*jec<<std::endl;
139  }
140  }
141  if ( mDebug )
142  std::cout << "Making JEC vs eta for different pTs" << std::endl;
143  //--------- Eta Graphs -------------------
144  for(unsigned ipt=0;ipt<mVPt.size();ipt++)
145  {
146  for(int i=0;i<mNGraphPoints;i++)
147  {
148  eta = mEtaMin + i*dEta;
149  corPt = mVPt[ipt];
150  veta[ipt][i] = eta;
151  //---------- find the raw pt -----------
152  double e = 1.0;
153  int nLoop(0);
154  rawPt = corPt;
155  while(e > 0.0001 && nLoop < 10)
156  {
157  P4.SetPtEtaPhiE(rawPt,eta,0,0);
158  LorentzVector rawP4(P4.Px(),P4.Py(),P4.Pz(),P4.E());
159  corrector->setJetEta( eta );
160  corrector->setJetPt( rawPt );
161  corrector->setJetE( P4.E() );
162  jec = corrector->getCorrection();
163  double tmp = rawPt * jec;
164  e = fabs(tmp-corPt)/corPt;
165  if (jec > 0)
166  rawPt = corPt/jec;
167  nLoop++;
168  }
169  //--------- calculate the jec for the rawPt --------
170  P4.SetPtEtaPhiE(rawPt,eta,0,0);
171  LorentzVector rawP4(P4.Px(),P4.Py(),P4.Pz(),P4.E());
172  corrector->setJetEta( eta );
173  corrector->setJetPt( rawPt );
174  corrector->setJetE( P4.E() );
175  jec = corrector->getCorrection();
176  vjec_pt[ipt][i] = jec;
177  if (mDebug)
178  std::cout<<rawPt<<" "<<eta<<" "<<jec<<" "<<rawPt*jec<<std::endl;
179  }
180  }
181  if ( mDebug )
182  std::cout << "See ya!" << std::endl;
183 
184 }
185 //---------------------------------------------------------------------------
187 {
188  if (mNGraphPoints > 1000)
189  throw cms::Exception("FactorizedJetCorrectorDemo","Too many graph points !!! Maximum is 1000 !!!");
190  if (mVEta.size() > 100)
191  throw cms::Exception("FactorizedJetCorrectorDemo","Too many eta values !!! Maximum is 100 !!!");
192  if (mVPt.size() > 100)
193  throw cms::Exception("FactorizedJetCorrectorDemo","Too many pt values !!! Maximum is 100 !!!");
194  mJECvsEta = fs->make<TH2F>("JECvsEta","JECvsEta",200,mEtaMin,mEtaMax,100,0,5);
195  mJECvsPt = fs->make<TH2F>("JECvsPt","JECvsPt",200,mPtMin,mPtMax,100,0,5);
196  mRandom = new TRandom();
197  mRandom->SetSeed(0);
198 }
199 //---------------------------------------------------------------------------
201 {
202  char name[1000];
203  for(unsigned ipt=0;ipt<mVPt.size();ipt++)
204  {
205  mVGraphEta[ipt] = fs->make<TGraphErrors>(mNGraphPoints,veta[ipt],vjec_pt[ipt],vex_pt[ipt],vjecUnc_pt[ipt]);
206  sprintf(name,"JEC_vs_Eta_CorPt%1.1f",mVPt[ipt]);
207  mVGraphEta[ipt]->SetName(name);
208  mUncEta[ipt] = fs->make<TGraph>(mNGraphPoints,veta[ipt],vUnc_pt[ipt]);
209  sprintf(name,"UNC_vs_Eta_CorPt%1.1f",mVPt[ipt]);
210  mUncEta[ipt]->SetName(name);
211  }
212  for(unsigned ieta=0;ieta<mVEta.size();ieta++)
213  {
214  mVGraphPt[ieta] = fs->make<TGraphErrors>(mNGraphPoints,vpt[ieta],vjec_eta[ieta],vex_eta[ieta],vjecUnc_eta[ieta]);
215  sprintf(name,"JEC_vs_RawPt_eta%1.1f",mVEta[ieta]);
216  mVGraphPt[ieta]->SetName(name);
217  mVGraphCorPt[ieta] = fs->make<TGraphErrors>(mNGraphPoints,vptcor[ieta],vjec_eta[ieta],vex_eta[ieta],vjecUnc_eta[ieta]);
218  sprintf(name,"JEC_vs_CorPt_eta%1.1f",mVEta[ieta]);
219  mVGraphCorPt[ieta]->SetName(name);
220  mUncCorPt[ieta] = fs->make<TGraph>(mNGraphPoints,vptcor[ieta],vUnc_eta[ieta]);
221  sprintf(name,"UNC_vs_CorPt_eta%1.1f",mVEta[ieta]);
222  mUncCorPt[ieta]->SetName(name);
223  }
224 }
225 //---------------------------------------------------------------------------
226 //define this as a plug-in
228 
229 
230 
231 
232 
233 
234 
235 
236 
237 
238 
239 
240 
241 
242 
243 
244 
245 
246 
247 
248 
249 
250 
251 
T getParameter(std::string const &) const
T getUntrackedParameter(std::string const &, T const &) const
int i
Definition: DBlmapReader.cc:9
dictionary parameters
Definition: Parameters.py:2
virtual void analyze(const edm::Event &, const edm::EventSetup &)
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:17
std::vector< std::string > mLevels
T eta() const
edm::Service< TFileService > fs
int iEvent
Definition: GenABIO.cc:243
reco::Particle::LorentzVector LorentzVector
FactorizedJetCorrectorDemo(const edm::ParameterSet &)
const T & get() const
Definition: EventSetup.h:55
std::vector< std::vector< double > > tmp
Definition: MVATrainer.cc:100
T * make() const
make new ROOT object
tuple cout
Definition: gather_cfg.py:121
tuple level
Definition: testEve_cfg.py:34
math::XYZTLorentzVector LorentzVector
Lorentz vector.
Definition: Particle.h:25
Power< A, B >::type pow(const A &a, const B &b)
Definition: Power.h:40