plotSNR.C
1 // Simple macro to calculate trigger efficiency as a function of SNR
3 // To run: root -b -q plotSNR.C
4 // author: L. Cremonesi l.cremonesi@ucl.ac.uk
6 
7 void plotSNR(){
8 
9  // Change pathname to the path to your icemc runs
10  // string path = "/datapool/software/anitaBuildTool/build/components/icemc/outputs";
11  string path = "/unix/anita3/linda/SimulatedFiles/Production4/anita3/wais_MaskingAndDeadTime//Energy_222/";
12 
13  // Change first and last run number appropriately
14  int firstRun = 1;
15  int lastRun = 100;
16 
17  // Define TChains for the head and truth Trees
18  TChain *tHead = new TChain("headTree");
19  TChain *tTrue = new TChain("truthAnitaTree");
20 
21  // Read the trees
22  for (int irun=firstRun; irun<=lastRun; irun++){
23  tHead->Add(Form("%s/run%d/SimulatedAnitaHeadFile%d.root", path.c_str(), irun, irun));
24  tTrue->Add(Form("%s/run%d/SimulatedAnitaTruthFile%d.root", path.c_str(), irun, irun));
25 
26  }
27 
28  RawAnitaHeader *header = NULL;
29  TruthAnitaEvent *truth = NULL;
30 
31  tHead->SetBranchAddress("header", &header);
32  tTrue->SetBranchAddress("truth", &truth);
33 
34  int nentries = tHead->GetEntries();
35 
36  int ntot = 40;
37  double snrmin = 0.;
38  double snrmax = 20.;
39 
40  // Define the numerator and denominator histograms to calculate the efficiency
41  TH1D *hNum = new TH1D ("hNum", "", ntot, snrmin, snrmax);
42  TH1D *hDenom = new TH1D ("hDenom", "", ntot, snrmin, snrmax);
43  hNum->Sumw2();
44  hDenom->Sumw2();
45 
46  TH1D *hNumt = new TH1D ("hNumt", "", ntot, snrmin, snrmax);
47  TH1D *hDenomt = new TH1D ("hDenomt", "", ntot, snrmin, snrmax);
48  hNumt->Sumw2();
49  hDenomt->Sumw2();
50 
51  double snr=0.;
52  double snrt=0.;
53 
54  // Define output file
55  TFile *fout = new TFile("icemcWAISeff2.root", "recreate");
56 
57 
58  // Loop over all the entries in the TChains
59  for (int ientry=0; ientry<nentries; ientry++){
60 
61  tHead->GetEntry(ientry);
62  tTrue->GetEntry(ientry);
63  cout << header->l3TrigPatternH << endl;
64  // Get SNR value at Digitizer (change V to H in case of using HPOL)
65  snr = truth->maxSNRAtDigitizerH;
66  if (snr>snrmax) snr=snrmax*0.9999;
67 
68  snrt = truth->maxSNRAtTriggerH;
69  if (snrt>snrmax) snrt=snrmax*0.9999;
70 
71  hDenom->Fill(snr, 1);
72  hDenomt->Fill(snrt, 1);
73 
74 
75  // hDenom->Fill(snr, 1);
76 
77  // if there is a trigger add the event to the numerator
78  // NB l3TrigPattern is for VPOL
79  // l3TrigPatternH is for HPOL
80 
81  if (header->l3TrigPatternH>0){
82  hNum->Fill(snr, 1);
83  hNumt->Fill(snrt, 1);
84  }
85  // cout << header->eventNumber << " " << truth->maxSNRAtDigitizerH << " " << 1 << endl;
86  }
87 cout << hDenom << " = denominator" <<endl;
88 cout << hDenom << " = numerator" << endl;
89 cout << nentries << " = number of entries/events" << endl;
90 
91  TEfficiency *eff = 0;
92  TEfficiency *efft = 0;
93 
94  // Define the TEfficiency from the numerator and denominator
95  if (TEfficiency::CheckConsistency(*hNum, *hDenom)){
96  eff = new TEfficiency(*hNum, *hDenom);
97 
98  TCanvas *c = new TCanvas("c");
99  eff->Draw();
100 
101  eff->Write("icemcWAIS");
102 
103  }
104 
105  if (TEfficiency::CheckConsistency(*hNumt, *hDenomt)){
106  efft = new TEfficiency(*hNumt, *hDenomt);
107 
108  efft->Write("icemcWAIS");
109 
110  }
111 
112 }
113 
114 
115 // used branches:
UShort_t l3TrigPatternH
Bit mask for l3 global triggers. eg. if the bit 1 (the lowest bit) is active it means that phi sector...
RawAnitaHeader – The Raw ANITA Event Header.
TruthAnitaEvent – The Truth ANITA Event.
Double_t maxSNRAtTriggerH
Max SNR at trigger H-POL.
Double_t maxSNRAtDigitizerH
Max SNR at digitizer H-POL.