Logo ROOT   6.10/09
Reference Guide
tprofile2polyRealisticModuleError.C
Go to the documentation of this file.
1 // Brief: Simulate faulty detector panel w.r.t. particle charge
2 
3 #include <iostream>
4 #include <fstream>
5 using namespace std;
6 
7 void tprofile2polyRealisticModuleError(Int_t numEvents = 1000000)
8 {
9  TCanvas *c1 = new TCanvas("c1", "4 Malfunctioning Panels", 800, 400);
10  c1->Divide(3, 1);
11 
12  // -------------------- Construct detector bins ------------------------
13  auto th2p = new TH2Poly();
14  auto avg = new TProfile2Poly();
15  auto err = new TProfile2Poly();
16 
17  ifstream infile;
18  infile.open("./tutorials/hist/data/tprofile2poly_tutorial.data");
19 
20  vector<pair<Double_t, Double_t>> allCoords;
21  Double_t a, b;
22  while (infile >> a >> b) {
23  pair<Double_t, Double_t> coord(a, b);
24  allCoords.push_back(coord);
25  }
26 
27  if (allCoords.size() % 3 != 0) {
28  cout << "[ERROR] Bad file" << endl;
29  return;
30  }
31 
32  Double_t x[3], y[3];
33  for (Int_t i = 0; i < allCoords.size(); i += 3) {
34  x[0] = allCoords[i + 0].first;
35  y[0] = allCoords[i + 0].second;
36  x[1] = allCoords[i + 1].first;
37  y[1] = allCoords[i + 1].second;
38  x[2] = allCoords[i + 2].first;
39  y[2] = allCoords[i + 2].second;
40  th2p->AddBin(3, x, y);
41  avg->AddBin(3, x, y);
42  err->AddBin(3, x, y);
43  }
44 
45  // -------------------- Generate particles ------------------------
46  TRandom ran;
47  for (int j = 0; j < numEvents; ++j) {
48  Double_t r1 = ran.Gaus(0, 10);
49  Double_t r2 = ran.Gaus(0, 8);
50  Double_t rok = ran.Gaus(20, 2);
51  Double_t rbad1 = ran.Gaus(1, 2);
52  Double_t rbad2 = ran.Gaus(2, 0);
53 
54  Double_t val = rok;
55  // -------------------- Malfunctioning panels -------------------
56  if (th2p->IsInsideBin(4, r1, r2)) val = rok - rbad1;
57  if (th2p->IsInsideBin(20, r1, r2)) val = rok - rbad2;
58  if (th2p->IsInsideBin(13, r1, r2)) val = rok + rbad1;
59  if (th2p->IsInsideBin(37, r1, r2)) val = rok + rbad2;
60 
61  // -------------------- Fill histograms ------------------------
62  th2p->Fill(r1, r2, val);
63  avg->Fill(r1, r2, val);
64  err->Fill(r1, r2, val);
65  }
66 
67  // -------------------- Display end state ------------------------
68  c1->cd(1);
69  th2p->SetStats(0);
70  th2p->SetTitle("total hits");
71  th2p->Draw("COLZ");
72 
73  c1->cd(2);
74  avg->SetStats(0);
75  avg->SetTitle("average charge");
76  avg->Draw("COLZ");
77 
78  c1->cd(3);
79  err->SetStats(0);
80  err->SetContentToError();
81  err->SetTitle("error");
82  err->Draw("COLZ");
83 }
virtual Double_t Gaus(Double_t mean=0, Double_t sigma=1)
Samples a random number from the standard Normal (Gaussian) Distribution with the given mean and sigm...
Definition: TRandom.cxx:235
return c1
Definition: legend1.C:41
TVirtualPad * cd(Int_t subpadnumber=0)
Set current canvas & pad.
Definition: TCanvas.cxx:679
int Int_t
Definition: RtypesCore.h:41
TArc * a
Definition: textangle.C:12
STL namespace.
Double_t x[n]
Definition: legend1.C:17
This is the base class for the ROOT Random number generators.
Definition: TRandom.h:27
void tprofile2polyRealisticModuleError(Int_t numEvents=1000000)
unsigned int r1[N_CITIES]
Definition: simanTSP.cxx:321
virtual void SetTitle(const char *title="")=0
The Canvas class.
Definition: TCanvas.h:31
double Double_t
Definition: RtypesCore.h:55
Double_t y[n]
Definition: legend1.C:17
virtual void Divide(Int_t nx=1, Int_t ny=1, Float_t xmargin=0.01, Float_t ymargin=0.01, Int_t color=0)
Automatic pad generation by division.
Definition: TPad.cxx:1135
you should not use this method at all Int_t Int_t Double_t Double_t Double_t Int_t Double_t Double_t Double_t Double_t b
Definition: TRolke.cxx:630
unsigned int r2[N_CITIES]
Definition: simanTSP.cxx:322
2D Histogram with Polygonal Bins
Definition: TH2Poly.h:66