/
generate_sample.C
78 lines (63 loc) · 1.68 KB
/
generate_sample.C
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
#include <string>
#include <vector>
#include <exception>
#include <vector>
#include <utility>
#include "TROOT.h"
#include "TFile.h"
#include "TDirectory.h"
#include "TChain.h"
#include "TObject.h"
#include "TCanvas.h"
#include "TMath.h"
#include "TLegend.h"
#include "TGraph.h"
#include "TH1.h"
#include "TH2.h"
#include "TH3.h"
#include "TTree.h"
#include "TF1.h"
#include "TGraphAsymmErrors.h"
#include "TPaveText.h"
#include "TRandom3.h"
#include "TProfile.h"
#include "TDirectory.h"
#include "TCanvas.h"
#include "TProfile.h"
#include "TPaveText.h"
#include "TRandom.h"
#include "TLorentzVector.h"
#include "TH1.h"
#include "TFile.h"
void generate_sample(string OutFilePath="out.txt", string unusedArgument="")
{
if(OutFilePath == "")return;
FILE* OutputFile = fopen(OutFilePath.c_str(), "w");
float mu=0.5;
float sigma=0.1;
float nb_events=1000000;
TRandom3 rand(12345);
TFile* OutputHisto = new TFile((OutFilePath+".root").c_str(),"RECREATE");
OutputHisto->cd();
TH2F* HGen = new TH2F("pdf", "pdf;x;y", 100,0,1, 100, 0, 1 );
int i=0;
while(i<nb_events){
double x = rand.Uniform();
double y = rand.Uniform();
// double r=0.5+rand.Uniform()* 0.2; //rand.Gaus(0.2, 0.1);
// double phi=rand.Uniform() * 2.0 * 3.1415;
// double x=r*cos(phi);
// double y=r*sin(phi);
double eps=0.1;
double fct=1.0+eps*(2.0*y);
double max_weight=1.0+2*eps;
// if(fct>max_weight*rand.Uniform()){
if(true){
fprintf(OutputFile, "%8f %8f \n", x, y );
HGen->Fill(x,y);
i++;
}
}
fclose(OutputFile);
HGen->Write();
}