ATLAS Offline Software
Loading...
Searching...
No Matches
lhMM_runII_fromTxt_commonTool.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2022 CERN for the benefit of the ATLAS collaboration
3*/
4
5#include <iostream>
6#include <fstream>
7#include <TH1F.h>
8#include <TH2F.h>
9#include <TMath.h>
10#include <TFile.h>
11#include <TRandom3.h>
14
15int main ( int argc,char *argv[] ){
16
17 TRandom3 rand(349867);
18
19 LhoodMM_tools* l = new LhoodMM_tools();
20 if (l ==0) {
21 std::cout << "null!" << std::endl;
22 return 1;
23 }
24
25 TH1F* h_ht = new TH1F("ht", "ht", 10, 0, 1000);
26 float ht;
27 TH1F* h_phi = new TH1F("phi", "phi", 10, 0, 7);
28 float phi;
29 TH2F* h_2d = new TH2F("ht_vs_phi", "ht_vs_phi", 10, 0, 7, 10, 0, 1000);
30 l->register1DHistogram(h_ht, &ht);
31 l->register1DHistogram(h_phi, &phi);
32 l->register2DHistogram(h_2d, &phi, &ht);
33
34 // loop over all the input txt files
35 for (int itxtfile = 1; itxtfile < argc-1; itxtfile++) {
36
37 char* txtFilename = argv[itxtfile];
38 fstream txtFile(txtFilename);
39 while (!txtFile.eof()) {
40 std::cout << "reading..." << std::endl;
41 int nlep;
42 std::vector<bool> isTight_vals;
43 std::vector<double> realEff_vals;
44 std::vector<double> fakeEff_vals;
45 txtFile >> nlep;
46 std::vector<FakeBkgTools::Particle> particles;
47 for (int ilep = 0; ilep<nlep; ilep++) {
48 bool is_tight;
49 float real_eff;
50 float fake_eff;
51 FakeBkgTools::Particle p;
52 txtFile >> is_tight >> real_eff >> fake_eff;
53 p.is_tight = is_tight;
54 p.real_eff = real_eff;
55 p.fake_eff = fake_eff;
56
57 particles.push_back(p);
58 }
59
60 ht = 1000.*rand.Uniform();
61 phi = 2*TMath::Pi()*rand.Uniform();
62
63 if (!txtFile.eof()) {
64 l->BaseFakeBkgTool::addEvent(particles);
65 }
66 }
67
68 l->fillHistograms();
69
70 TFile f("test.root", "RECREATE");
71 f.cd();
72 h_ht->Write();
73 h_phi->Write();
74 h_2d->Write();
75 f.Close();
76 }
77
78 double nfakes, poserr, negerr;
79 // l->setPrintLevel(1);
80 FakeBkgTools::Yield y = l->getTotalYield(); // need to update once
81 // syntax interpreter is available
82
83 nfakes = y.value;
85 u.index = 0;
86 poserr = y.uncertainties[u].up;
87 negerr = y.uncertainties[u].down;
88
89 std::cout << "nfakes = " << nfakes << " + " << poserr << " - " << -1.0*negerr << std::endl;
90
91 TFile rootFile(argv[argc-1], "RECREATE");
92 TH1F* h_count = new TH1F("h_count", "h_count", 2, 0, 2);
93 h_count->SetBinContent(1, nfakes);
94 h_count->SetBinError(1, TMath::Max(TMath::Abs(poserr), TMath::Abs(negerr)));
95 rootFile.cd();
96 h_count->Write();
97 rootFile.Close();
98
99}
Scalar phi() const
phi method
#define y
int main()
Definition hello.cxx:18
a structure to hold an event yield together with a statistical uncertainty and a variable number of s...