1
|
//This code creates 5 histograms, two seperate histograms using input object (helicity, etc.) and input variable(fadc_a)(h0, h1), one for the subtraction of these 2 (h2), one for addition of the two (h3), then final one divividing them (h4).
|
2
|
|
3
|
void hsad() {
|
4
|
// Creates 2 histograms
|
5
|
TH1F* h0 = new TH1F("h0", "fadc_a, h0", 1000, 0, 25000); //Adjust "fadc_a" to any variable in tree
|
6
|
TH1F* h1 = new TH1F("h1", "fadc_a, h1", 1000, 0, 25000);
|
7
|
|
8
|
// Fills histograms with different helicity (can also test differences in objects other than helicity)
|
9
|
T->Draw("fadc_a>>h0", "helicity==0");
|
10
|
T->Draw("fadc_a>>h1", "helicity==1");
|
11
|
|
12
|
// Subtracts h0 - h1 and writes to new histogram "h2"
|
13
|
TH1F* h2 = (TH1F*)h0->Clone("h2");
|
14
|
h2->Add(h1, -1);
|
15
|
|
16
|
// Reinitializes h0
|
17
|
h0->Reset();
|
18
|
T->Draw("fadc_a>>h0", "helicity==0");
|
19
|
|
20
|
// Adds h0 + h1 and fills new histogram "h3"
|
21
|
TH1F* h3 = (TH1F*)h0->Clone("h3");
|
22
|
h3->SetName("fadc_a, +");
|
23
|
h3->SetTitle("fadc_a, +;x-axis;y-axis"); //OPTIONAL- set name and axis for addition histogram
|
24
|
h3->Add(h1, 1);
|
25
|
|
26
|
// Divides h2 / h3 and fills new histogram "h4"
|
27
|
TH1F* h4 = (TH1F*)h2->Clone("h4");
|
28
|
h4->SetName("fadc_a"); //Var
|
29
|
h4->SetTitle("fadc_a;x-axis;y-axis"); //Set name of final histogram and set x and y axis names
|
30
|
h4->Divide(h3);
|
31
|
|
32
|
// Reinitializes h0 and h2
|
33
|
h0->Reset();
|
34
|
T->Draw("fadc_a>>h0", "helicity==0");
|
35
|
h2->Reset();
|
36
|
h2->Add(h1, -1);
|
37
|
h2->SetName("fadc_a, -");
|
38
|
h2->SetTitle("fadc_a, -;x-axis;y-axis"); //OPTIONAL- set name and axis for subtraction histogram
|
39
|
h0->Reset();
|
40
|
T->Draw("fadc_a>>h0", "helicity==0");
|
41
|
|
42
|
//gPad->SetLogx();
|
43
|
// Draw final result
|
44
|
h4->Draw(); //Change "h4" to desired histogram
|
45
|
}
|