ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/UserCode/JetFitAnalyzer/test/JetFinderAnalyzer.cc
(Generate patch)

Comparing UserCode/JetFitAnalyzer/test/JetFinderAnalyzer.cc (file contents):
Revision 1.5 by dnisson, Fri Sep 4 15:30:38 2009 UTC vs.
Revision 1.19 by dnisson, Tue Nov 10 01:25:49 2009 UTC

# Line 13 | Line 13
13   #include "DataFormats/ParticleFlowCandidate/interface/PFCandidate.h"
14   #include "DataFormats/ParticleFlowReco/interface/PFBlock.h"
15  
16 + /* Jet reco stuff */
17 + #include "DataFormats/JetReco/interface/PFJetCollection.h"
18 + #include "DataFormats/JetReco/interface/GenJetCollection.h"
19 + #include "DataFormats/JetReco/interface/PFJet.h"
20 + #include "DataFormats/JetReco/interface/GenJet.h"
21 +
22   #include <map>
23   #include <vector>
24   #include <limits>
25   #include <cmath>
26   #include <cstdlib>
27 + #include <iostream>
28   #include <fstream>
29   #include <sstream>
30  
# Line 64 | Line 71 | private:
71      return sum1 * sum2;
72    }
73  
74 <  static void jetfinder(TMinuit *gMinuit, TH2 *hist, int ngauss) {
75 <    double dist_sq = numeric_limits<double>::infinity();
69 <    unique_jets[hist].resize(ngauss);
70 <    int nbinsX = hist->GetXaxis()->GetNbins();
71 <    int nbinsY = hist->GetYaxis()->GetNbins();
72 <    double XbinSize = (hist->GetXaxis()->GetXmax()
73 <                       - hist->GetXaxis()->GetXmin())
74 <      / static_cast<double>(nbinsX);
75 <    double YbinSize = (hist->GetYaxis()->GetXmax()
76 <                       - hist->GetYaxis()->GetXmin())
77 <      / static_cast<double>(nbinsY);
78 <    for (int i = 0; i < ngauss; i++) {
79 <      double N, mu_x, mu_y, sig, err, lo, hi;
80 <      int iuint;
81 <      TString name;
82 <      gMinuit->mnpout(4*i, name, N, err, lo, hi, iuint);
83 <      gMinuit->mnpout(4*i + 1, name, mu_x, err, lo, hi, iuint);
84 <      gMinuit->mnpout(4*i + 2, name, mu_y, err, lo, hi, iuint);
85 <      gMinuit->mnpout(4*i + 3, name, sig, err, lo, hi, iuint);
86 <      for (int j = 0; j < i; j++) {
87 <        double N2, mu_x2, mu_y2, sig2;
88 <        gMinuit->mnpout(4*j, name, N2, err, lo, hi, iuint);
89 <        gMinuit->mnpout(4*j + 1, name, mu_x2, err, lo, hi, iuint);
90 <        gMinuit->mnpout(4*j + 2, name, mu_y2, err, lo, hi, iuint);
91 <        gMinuit->mnpout(4*j + 3, name, sig2, err, lo, hi, iuint);
92 <        double _dist_sq = (mu_x2 - mu_x)*(mu_x2 - mu_x)
93 <          + (mu_y2 - mu_y)*(mu_y2 - mu_y);
94 <        if (_dist_sq < dist_sq)
95 <          dist_sq = _dist_sq;
96 <      }
97 <
98 <      jet j;
99 <      j.energy = N;
100 <      j.eta = mu_x; j.phi = mu_y;
101 <      unique_jets[hist][ngauss-1].push_back(j);
102 <    }
103 <  }
104 <
105 <  virtual void beginJob(const edm::EventSetup&);
106 <  virtual TH2D* make_histo(const edm::Event&, const edm::EventSetup&);
74 >  virtual void beginJob(const edm::EventSetup &es);
75 >  virtual TH2D * make_histo(const edm::Event &, const edm::EventSetup &);
76    virtual jetfit::model_def& make_model_def(const edm::Event&,
77                                             const edm::EventSetup&,
78                                             TH2 *);
79    virtual void analyze_results(jetfit::results r,
80                                 std::vector<jetfit::trouble> t, TH2 *);
81    vector<reco::Candidate *> get_particles(const edm::Event&);
113  void fetchCandidateCollection(edm::Handle<reco::PFCandidateCollection>&,
114                                const edm::InputTag&, const edm::Event&) const;
115  void fetchCandidateCollection(edm::Handle<reco::GenParticleCollection>&,
116                                const edm::InputTag&, const edm::Event&) const;
82  
83    fstream ofs;
84    edm::InputTag inputTagPFCandidates_;
# Line 121 | Line 86 | private:
86    int info_type_;
87    double smear_;
88    int smear_coord_;
89 +  string jet_algo_;
90 +  string reclustered_jet_algo_;
91   };
92  
93   map<TH2 *, vector< vector< JetFinderAnalyzer::jet > > >
# Line 142 | Line 109 | JetFinderAnalyzer::JetFinderAnalyzer(con
109    smear_coord_ = pSet.getUntrackedParameter("smear_coord", 0);
110    // 0 = eta-phi smear
111    // 1 = proper angle smear
112 <  set_user_minuit(jetfinder);
113 < }
147 <
148 < void
149 < JetFinderAnalyzer::fetchCandidateCollection(edm::Handle<reco::PFCandidateCollection>& c,
150 <                                      const edm::InputTag& tag,
151 <                                      const edm::Event& iEvent) const {
152 <  
153 <  bool found = iEvent.getByLabel(tag, c);
154 <  
155 <  if(!found ) {
156 <    ostringstream  err;
157 <    err<<" cannot get PFCandidates: "
158 <       <<tag<<endl;
159 <    edm::LogError("PFCandidates")<<err.str();
160 <    throw cms::Exception( "MissingProduct", err.str());
161 <  }
162 <  
112 >  jet_algo_ = pSet.getParameter<string>("jet_algo");
113 >  set_user_minuit(0); // we don't need this feature--it's deprecated
114   }
115  
116 < void
117 < JetFinderAnalyzer::fetchCandidateCollection(edm::Handle<reco::GenParticleCollection>& c,
167 <                                      const edm::InputTag& tag,
168 <                                      const edm::Event& iEvent) const {
169 <  
170 <  bool found = iEvent.getByLabel(tag, c);
171 <  
172 <  if(!found ) {
173 <    ostringstream  err;
174 <    err<<" cannot get GenParticles: "
175 <       <<tag<<endl;
176 <    edm::LogError("GenParticles")<<err.str();
177 <    throw cms::Exception( "MissingProduct", err.str());
178 <  }
179 <  
180 < }
116 > TH2D * JetFinderAnalyzer::make_histo(const edm::Event &evt, const edm::EventSetup&) {
117 >  const reco::Jet * highest_e_jet = 0;
118  
182 vector<reco::Candidate *> JetFinderAnalyzer::get_particles(const edm::Event &evt) {
183 // fill unreduced histo
184  edm::Handle<reco::GenParticleCollection> hRaw;
185  edm::Handle<reco::PFCandidateCollection> hPFlow;
119    if (info_type_ == 0) {
120 <    fetchCandidateCollection(hRaw,
121 <                             inputTagGenParticles_,
122 <                             evt);
123 <  }
124 <  if (info_type_ == 1) {
125 <    fetchCandidateCollection(hPFlow,
193 <                             inputTagPFCandidates_,
194 <                             evt);
195 <  }
196 <    
197 <  vector<reco::Candidate *> particles;
198 <
199 <  switch (info_type_) {
200 <  case 0:
201 <    for (unsigned i = 0; i < hRaw->size(); i++) {
202 <      if ((*hRaw)[i].status() == 1) {
203 <        particles.push_back((reco::Candidate *)&((*hRaw)[i]));
120 >    edm::Handle< vector<reco::GenJet> > evtJets;
121 >    evt.getByLabel(jet_algo_, evtJets);
122 >    for (unsigned i = 0; i < evtJets->size(); i++) {
123 >      if (highest_e_jet == 0
124 >          || (*evtJets)[i].energy() > highest_e_jet->energy()) {
125 >        highest_e_jet = &((*evtJets)[i]);
126        }
127      }
206    break;
207  case 1:
208    for (unsigned i = 0; i < hPFlow->size(); i++) {
209      particles.push_back((reco::Candidate *)&((*hPFlow)[i]));
210    }
211    break;
212  default:
213    cerr << "Unknown event type" << endl; // TODO use MessageLogger
214  }
215
216  return particles;
217 }
218
219 TH2D * JetFinderAnalyzer::make_histo(const edm::Event &evt, const edm::EventSetup&) {
220  ostringstream oss;
221  oss << "eta_phi_energy_unred"<<evt.id().event() << flush;
222  TH2D *unred_histo = new TH2D(oss.str().c_str(), oss.str().c_str(),
223                               600, -2.5, 2.5, 600, -PI, PI);
224
225  vector<reco::Candidate *> particles = get_particles(evt);
226  for (int i = 0; i < particles.size(); i++) {
227    unred_histo->Fill(particles[i]->eta(),
228                      particles[i]->phi(),
229                      particles[i]->energy());
128    }
129 <
130 <  // reduce histo
131 <  ostringstream oss2;
132 <  oss2 << "eta_phi_energy_red"<<evt.id().event() << flush;
133 <  edm::Service<TFileService> fs;
134 <  // draw cone of radius 0.5 around highest energy bin, reduce
135 <  double maxE = 0.0;
238 <  int max_i = 29, max_j = 29;
239 <  for (int i = 0; i < unred_histo->GetNbinsX(); i++) {
240 <    for (int j = 0; j < unred_histo->GetNbinsY(); j++) {
241 <      double E = unred_histo->GetBinContent(i+1, j+1);
242 <      if (E > maxE) {
243 <        maxE = E;
244 <        max_i = i;
245 <        max_j = j;
129 >  else if (info_type_ == 1) {
130 >    edm::Handle< vector<reco::PFJet> > evtJets;
131 >    evt.getByLabel(jet_algo_, evtJets);
132 >    for (unsigned i = 0; i < evtJets->size(); i++) {
133 >      if (highest_e_jet == 0
134 >          || (*evtJets)[i].energy() > highest_e_jet->energy()) {
135 >        highest_e_jet = &((*evtJets)[i]);
136        }
137      }
138    }
139 <  
140 <  double rcone = 0.5;
141 <  double Xlo = unred_histo->GetXaxis()->GetXmin();
142 <  double Xhi = unred_histo->GetXaxis()->GetXmax();
253 <  double Ylo = unred_histo->GetYaxis()->GetXmin();
254 <  double Yhi = unred_histo->GetYaxis()->GetXmax();
255 <  double XbinSize = (Xhi - Xlo) /
256 <    static_cast<double>(unred_histo->GetXaxis()->GetNbins());
257 <  double YbinSize = (Yhi - Ylo) /
258 <    static_cast<double>(unred_histo->GetYaxis()->GetNbins());
259 <  double max_x = (static_cast<double>(max_i) + 0.5) * XbinSize + Xlo;
260 <  double max_y = (static_cast<double>(max_j) + 0.5) * YbinSize + Ylo;
261 <  TH2D *histo = fs->make<TH2D>(oss2.str().c_str(), oss2.str().c_str(),
262 <                               60, max_x-rcone, max_x+rcone,
263 <                               60, max_y-rcone, max_y+rcone);
264 <
265 <  // create an unsmeared reduced histo
266 <  TH2D *histo_unsmeared = fs->make<TH2D>((oss2.str()+"_unsmeared").c_str(),
267 <                                         (oss2.str()+"_unsmeared").c_str(),
268 <                                         60, max_x-rcone, max_x+rcone,
269 <                                         60, max_y-rcone, max_y+rcone);
270 <  for (int i = 0; i < particles.size(); i++) {
271 <    double N = particles[i]->energy();
272 <    double x = particles[i]->eta();
273 <    double y = particles[i]->phi();
274 <    histo_unsmeared->Fill(x, y, N);
139 >    
140 >  if (highest_e_jet == 0) {
141 >    cerr << "No fat jets found!" << endl;
142 >    return 0;
143    }
144  
145 <  // create a smeared reduced histo
145 >  vector<const reco::Candidate *> particles =
146 >    highest_e_jet->getJetConstituentsQuick();
147 >
148 >  ostringstream oss;
149 >  oss << "eta_phi_energy"<<evt.id().event() << flush;
150 >  edm::Service<TFileService> fs;
151 >  TH2D *histo = fs->make<TH2D>(oss.str().c_str(), oss.str().c_str(),
152 >                         30,
153 >                         highest_e_jet->eta()-0.5,
154 >                         highest_e_jet->eta()+0.5,
155 >                         30,
156 >                         highest_e_jet->phi()-0.5,
157 >                         highest_e_jet->phi()+0.5);
158 >
159 >  if (smear_ > 0.0) {
160 >  // create a smeared histo
161    // create a temporary 2D vector for smeared energies
162 <  XbinSize = (histo->GetXaxis()->GetXmax()
162 >  double XbinSize = (histo->GetXaxis()->GetXmax()
163                - histo->GetXaxis()->GetXmin()) /
164      static_cast<double>(histo->GetXaxis()->GetNbins());
165 <  YbinSize = (histo->GetYaxis()->GetXmax()
165 >  double YbinSize = (histo->GetYaxis()->GetXmax()
166                - histo->GetYaxis()->GetXmin()) /
167      static_cast<double>(histo->GetYaxis()->GetNbins());
168 <  vector< vector<double> > smeared(60, vector<double>(60, 0.0) );
168 >  double Xlo = histo->GetXaxis()->GetXmin();
169 >  double Xhi = histo->GetXaxis()->GetXmax();
170 >  double Ylo = histo->GetYaxis()->GetXmin();
171 >  double Yhi = histo->GetYaxis()->GetXmax();
172 >  vector< vector<double> > smeared(30, vector<double>(30, 0.0) );
173    switch (smear_coord_) {
174    case 1:
175      for (int i = 0; i < particles.size(); i++) {
176        double N = particles[i]->energy();
177        double x = particles[i]->eta();
178        double y = particles[i]->phi();
179 +      if (y < Ylo) {
180 +        y += 2.0*PI;
181 +      }
182 +      if (y > Yhi) {
183 +        y -= 2.0*PI;
184 +      }
185        // loop over bins and add Gaussian in proper angle to smeared
186 <      for (vector< vector<double> >::size_type i2 = 0; i2 < 60; i2++) {
187 <        for (vector< double >::size_type j2 = 0; j2 < 60; j2++) {
186 >      for (vector< vector<double> >::size_type i2 = 0; i2 < 30; i2++) {
187 >        for (vector< double >::size_type j2 = 0; j2 < 30; j2++) {
188            double eta = static_cast<double>((signed int)i2) * XbinSize +
189 <            max_x - rcone - x;
190 <          double phi = acos(cos(static_cast<double>((signed int)j2) * YbinSize +
191 <            max_y - rcone - y));
192 <          phi = sin(phi) > 0 ? phi : -phi;
300 <          
189 >            Xlo - x;
190 >          double phi = static_cast<double>((signed int)j2) * YbinSize +
191 >            Ylo - y;
192 >
193            // transform eta, phi to proper angle
194            double theta = 2.0*atan(exp(-eta));
195            double iota = asin(sin(theta)*sin(phi));
# Line 314 | Line 206 | TH2D * JetFinderAnalyzer::make_histo(con
206        double N = particles[i]->energy();
207        double x = particles[i]->eta();
208        double y = particles[i]->phi();
209 +      if (y < Ylo) {
210 +        y += 2.0*PI;
211 +      }
212 +      if (y > Yhi) {
213 +        y -= 2.0*PI;
214 +      }
215        // loop over bins and add Gaussian to smeared
216 <      for (vector< vector<double> >::size_type i2 = 0; i2 < 60; i2++) {
217 <        for (vector< double >::size_type j2 = 0; j2 < 60; j2++) {
216 >      for (vector< vector<double> >::size_type i2 = 0; i2 < 30; i2++) {
217 >        for (vector< double >::size_type j2 = 0; j2 < 30; j2++) {
218            double eta = static_cast<double>((signed int)i2) * XbinSize
219 <            + max_x - rcone - x;
220 <          double phi = acos(cos(static_cast<double>((signed int)j2) * YbinSize
221 <            + max_y - rcone - y));
222 <          phi = sin(phi) > 0 ? phi : -phi;
219 >            + Xlo - x;
220 >          double phi = static_cast<double>((signed int)j2) * YbinSize +
221 >            Ylo - y;
222 >
223            smeared[i2][j2] += (N*XbinSize*YbinSize/(2.0*PI*smear_*smear_))
224              * exp(-0.5*(eta*eta + phi*phi)/(smear_*smear_));
225          }
# Line 329 | Line 227 | TH2D * JetFinderAnalyzer::make_histo(con
227      }  
228    }
229    // set histogram to match smear vector
230 <  for (int i = 1; i <= 60; i++) {
231 <    for (int j = 1; j <= 60; j++) {
230 >  for (int i = 1; i <= 30; i++) {
231 >    for (int j = 1; j <= 30; j++) {
232        histo->SetBinContent(i, j, smeared[i-1][j-1]);
233      }
234    }
235 <
236 <  return histo;
237 < }
238 <
239 < void seed_with_CA(vector<reco::Candidate *> gParticles, TH2 *histo,
240 <                  jetfit::model_def &_mdef) {
343 <  // create a PseudoJet vector
344 <  vector<PseudoJet> particles;
345 <  for (unsigned i = 0; i < gParticles.size(); i++) {
346 <    double x_max = (histo->GetXaxis()->GetXmax()
347 <                    + histo->GetXaxis()->GetXmin()) / 2.0;
348 <    double y_max = (histo->GetYaxis()->GetXmax()
349 <                    + histo->GetYaxis()->GetXmin()) / 2.0;
350 <    valarray<double> pmom(4);
351 <    pmom[0] = gParticles[i]->px();
352 <    pmom[1] = gParticles[i]->py();
353 <    pmom[2] = gParticles[i]->pz();
354 <    pmom[3] = gParticles[i]->energy();
355 <    double eta = gParticles[i]->eta();
356 <    double phi = gParticles[i]->phi();
357 <    if ((eta - x_max)*(eta - x_max) + (phi - y_max)*(phi - y_max) < 0.25) {
358 <      PseudoJet j(pmom);
359 <      particles.push_back(j);
235 >  }
236 >  else {
237 >    // don't smear--just fill with particles
238 >    for (int i = 0; i < particles.size(); i++) {
239 >      histo->Fill(particles[i]->eta(), particles[i]->phi(),
240 >                  particles[i]->energy());
241      }
242    }
243  
244 <  // choose a jet definition
245 <  double R = 0.2;
365 <  JetDefinition jet_def(cambridge_algorithm, R);
366 <
367 <  // run clustering and extract the jets
368 <  ClusterSequence cs(particles, jet_def);
369 <  vector<PseudoJet> jets = cs.inclusive_jets();
370 <
371 <  double XbinSize = (histo->GetXaxis()->GetXmax()
372 <                     - histo->GetXaxis()->GetXmin()) /
373 <    static_cast<double>(histo->GetXaxis()->GetNbins());
374 <  double YbinSize = (histo->GetYaxis()->GetXmax()
375 <                     - histo->GetYaxis()->GetXmin()) /
376 <    static_cast<double>(histo->GetYaxis()->GetNbins());
244 >  return histo;
245 > }
246  
247 <  // seed with C-A jets
247 > template <class Jet>
248 > void seed_with_jetcoll(vector<Jet> jets,
249 >                  jetfit::model_def &_mdef, double phi_lo = -PI,
250 >                       double phi_hi = PI) {
251 >  // seed with jet collection
252    int ijset = 0;
253    for (unsigned ij = 0; ij < jets.size(); ij++) {
254 <    double N = jets[ij].e();
255 <    if (N > 50.0) {
256 <      cout << N << endl;
254 >    double N = jets[ij].energy();
255 >    double eta = jets[ij].eta();
256 >    double phi = jets[ij].phi();
257 >    if (N > 10.0) {
258        _mdef.set_special_par(ijset, 0, N, _mdef.chisquare_error(N)*0.1,
259                              0.0, 1.0e6);
260 <      _mdef.set_special_par(ijset, 1, jets[ij].eta(), 0.01,
260 >      _mdef.set_special_par(ijset, 1, eta, 0.01,
261                              0.0, 0.0);
262 <      double mdef_phi = jets[ij].phi() > PI ? jets[ij].phi() - 2*PI
263 <        : jets[ij].phi();
264 <      _mdef.set_special_par(ijset, 2, mdef_phi, 0.01,
262 >      if (phi < phi_lo) {
263 >        phi += 2.0*PI;
264 >      }
265 >      if (phi > phi_hi) {
266 >        phi -= 2.0*PI;
267 >      }
268 >      _mdef.set_special_par(ijset, 2, phi, 0.01,
269                              0.0, 0.0);
270        _mdef.set_special_par(ijset, 3, 0.1, 0.001, 0.0, 0.0);
271        ijset++;
# Line 401 | Line 279 | jetfit::model_def& JetFinderAnalyzer::ma
279    class jf_model_def : public jetfit::model_def {
280    public:
281      virtual double chisquare_error(double E) {
282 <      return E > 2.7 ? 0.55*E - 1.0 : 0.5;
405 <      // study from 09-03-09
282 >      return 0.298 - 0.9557*E; // study 11-09-09
283      }
284    };
285  
# Line 418 | Line 295 | jetfit::model_def& JetFinderAnalyzer::ma
295    _mdef->set_indiv_par(2, string("mu_y"), 0.0, 0.0, 0.0, 0.0);
296    _mdef->set_indiv_par(3, string("sig"), 0.1, 0.001, 0.0, 0.0);
297  
298 <  seed_with_CA(get_particles(evt), histo, *_mdef);
298 >  // get jetcoll from event file and select highest e jet
299 >  if (info_type_ == 0) {
300 >    edm::Handle< vector<reco::GenJet> > jet_collection;
301 >    evt.getByLabel(jet_algo_, jet_collection);
302 >    reco::GenJet highest_e_jet;
303 >    bool found_jet = false;
304 >    for (unsigned i = 0; i < jet_collection->size(); i++) {
305 >      if (!found_jet || (*jet_collection)[i].energy() > highest_e_jet.energy())
306 >        {
307 >          highest_e_jet = (*jet_collection)[i];
308 >          found_jet = true;
309 >        }
310 >    }
311 >    vector<reco::GenJet> highest_e_jet_coll;
312 >    highest_e_jet_coll.push_back(highest_e_jet);
313 >    seed_with_jetcoll(highest_e_jet_coll, *_mdef,
314 >                      histo->GetYaxis()->GetXmin(),
315 >                      histo->GetYaxis()->GetXmax());
316 >  }
317 >  if (info_type_ == 1) {
318 >    edm::Handle< vector<reco::PFJet> > jet_collection;
319 >    evt.getByLabel(jet_algo_, jet_collection);
320 >    reco::PFJet highest_e_jet;
321 >    bool found_jet = false;
322 >    for (unsigned i = 0; i < jet_collection->size(); i++) {
323 >      if (!found_jet || (*jet_collection)[i].energy() > highest_e_jet.energy())
324 >        {
325 >          highest_e_jet = (*jet_collection)[i];
326 >          found_jet = true;
327 >        }
328 >    }
329 >    vector<reco::PFJet> highest_e_jet_coll;
330 >    highest_e_jet_coll.push_back(highest_e_jet);
331 >    seed_with_jetcoll(highest_e_jet_coll, *_mdef,
332 >                      histo->GetYaxis()->GetXmin(),
333 >                      histo->GetYaxis()->GetXmax());
334 >  }
335  
336    jetfit::set_model_def(_mdef);
337  
# Line 445 | Line 358 | jetfit::model_def& JetFinderAnalyzer::ma
358    double Ylo = histo->GetYaxis()->GetXmin();
359    double Yhi = histo->GetYaxis()->GetXmax();
360  
361 <  for (int i = 0; i < 60; i++) {
362 <    for (int j = 0; j < 60; j++) {
361 >  for (int i = 0; i < 30; i++) {
362 >    for (int j = 0; j < 30; j++) {
363        double x = (static_cast<double>(i) + 0.5)*XbinSize + Xlo;
364        double y = (static_cast<double>(j) + 0.5)*YbinSize + Ylo;
365        double pval[256];
# Line 465 | Line 378 | jetfit::model_def& JetFinderAnalyzer::ma
378        }
379        jetfit::set_ngauss(_mdef->get_n_special_par_sets());
380        init_fit_histo->SetBinContent(i+1, j+1,
381 <                                    jetfit::fit_fcn(x, y, pval));
381 >                                    jetfit::fit_fcn(x, y, pval)
382 >                                    * XbinSize * YbinSize);
383      }
384    }
385  
# Line 518 | Line 432 | ostream& operator<<(ostream &out, jetfit
432      else
433        out << "Not calculated" << endl;
434    }
435 +  else {
436 +    out << "Error matrix accurate" << endl;
437 +  }
438  
439    return out;
440   }
# Line 526 | Line 443 | void JetFinderAnalyzer::analyze_results(
443                                       std::vector<jetfit::trouble> t,
444                                       TH2 *hist_orig) {
445    ofs << "Histogram "<<hist_orig->GetName() << endl;
446 <  for (int i = 0; i < unique_jets[hist_orig].size(); i++) {
446 >  for (int i = unique_jets[hist_orig].size() - r.chisquare.size();
447 >       i < unique_jets[hist_orig].size(); i++) {
448 >    int ir = i - unique_jets[hist_orig].size() + r.chisquare.size();
449      ofs << "For "<<i+1<<" gaussians: " << endl
450 <        << t.at(i) << endl
451 <        << unique_jets[hist_orig][i].size()<<" unique jets found" << endl;
450 >        << t.at(i) << endl;
451 >    ofs << "chisquare="<<r.chisquare.at(ir)
452 >        << endl;
453 >    ofs << unique_jets[hist_orig][i].size()<<" unique jets found" << endl;
454      for (int j = 0; j < unique_jets[hist_orig][i].size(); j++) {
455        jet _jet = unique_jets[hist_orig][i][j];
456        ofs << "Jet "<<j<<": Energy = "<<_jet.energy<<", eta = "<<_jet.eta
# Line 565 | Line 486 | void JetFinderAnalyzer::analyze_results(
486                                       hist_orig->GetYaxis()->GetNbins(),
487                                       hist_orig->GetYaxis()->GetXmin(),
488                                       hist_orig->GetYaxis()->GetXmax());
489 <    TH1 *tf2_histo = tf2->CreateHistogram();
490 <    double XbinSize = (fit_histo->GetXaxis()->GetXmax()
491 <                       - fit_histo->GetXaxis()->GetXmin())
492 <      / static_cast<double>(fit_histo->GetXaxis()->GetNbins());
493 <    double YbinSize = (fit_histo->GetYaxis()->GetXmax()
494 <                       - fit_histo->GetYaxis()->GetXmin())
495 <      / static_cast<double>(fit_histo->GetYaxis()->GetNbins());
496 <    for (int ih = 0; ih < tf2->GetNpx(); ih++) {
497 <      for (int jh = 0; jh < tf2->GetNpy(); jh++) {
498 <        fit_histo->SetBinContent(ih+1, jh+1,
499 <                        tf2_histo->GetBinContent(ih+1, jh+1)
500 <                                 * XbinSize * YbinSize);
489 >    double XbinSize = (hist_orig->GetXaxis()->GetXmax()
490 >                       - hist_orig->GetXaxis()->GetXmin())
491 >      / hist_orig->GetXaxis()->GetNbins();
492 >    double YbinSize = (hist_orig->GetYaxis()->GetXmax()
493 >                       - hist_orig->GetYaxis()->GetXmin())
494 >      / hist_orig->GetYaxis()->GetNbins();
495 >    for (int i = 1; i <= fit_histo->GetXaxis()->GetNbins(); i++) {
496 >      for (int j = 1; j <= fit_histo->GetYaxis()->GetNbins(); j++) {
497 >        double x = static_cast<double>(i - 1)
498 >          * (fit_histo->GetXaxis()->GetXmax()
499 >             - fit_histo->GetXaxis()->GetXmin())
500 >          / static_cast<double>(fit_histo->GetXaxis()->GetNbins())
501 >          + fit_histo->GetXaxis()->GetXmin();;
502 >        double y = static_cast<double>(j - 1)
503 >          * (fit_histo->GetYaxis()->GetXmax()
504 >             - fit_histo->GetYaxis()->GetXmin())
505 >          / static_cast<double>(fit_histo->GetYaxis()->GetNbins())
506 >          + fit_histo->GetYaxis()->GetXmin();
507 >        fit_histo->SetBinContent(i, j, tf2->Eval(x, y) * XbinSize * YbinSize);
508        }
509      }
510    }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines