WCSim
trigger_OD.C
Go to the documentation of this file.
1 #include <stdio.h>
2 #include <stdlib.h>
3 #include <libgen.h>
4 
5 void trigger_OD(char *filename=NULL) {
6  /* A simple script to plot aspects of phototube hits
7  *
8  * I like to run this macro as
9  * $ $WCSIMDIR/rootwc/rootwc -l -x 'trigger_OD.C("OD.root")'
10  */
11 
12  gROOT->Reset();
13 
14  gStyle->SetOptStat(1);
15 
16  TFile *f;
17  char fTest[128];
18  if (filename==NULL){
19  std::cout << "Please provide filename in option" << std::endl;
20  std::cout << "Will load auto wcsim.root in WCSIMDIR ..." << std::endl;
21  char* name = "wcsim.root";
22  strncpy(fTest, wcsimdirenv, sizeof(fTest));
23  strncat(fTest, "/", (sizeof(fTest) - strlen(fTest)) );
24  strncat(fTest, name, (sizeof(fTest) - strlen(fTest)) );
25  f = new TFile(fTest);
26  }else{
27  f = new TFile(filename);
28  }
29  if (!f->IsOpen()){
30  cout << "Error, could not open input file: " << filename << endl;
31  return -1;
32  }else{
33  if (filename==NULL) cout << "File open bro: " << fTest << endl;
34  else cout << "File open bro: " << filename << endl;
35  }
36 
37  char *dirc, *basec, *bname, *dname;
38 
39  dirc = strdup(filename);
40  basec = strdup(filename);
41  dname = dirname(dirc);
42  bname = basename(basec);
43  printf("dirname=%s, basename=%s\n", dname, bname);
44  // std::cout << "Filename : " << filename << std::endl;
45  // std::cout << "dirname(filename) : " << dirname(filename) << std::endl;
46  // std::cout << "basename(filename) : " << basename(filename) << std::endl;
47 
48  TTree *wcsimT = (TTree*)f->Get("wcsimT");
49 
50  WCSimRootEvent *wcsimrootsuperevent = new WCSimRootEvent();
51  wcsimT->SetBranchAddress("wcsimrootevent_OD",&wcsimrootsuperevent);
52 
53  // Force deletion to prevent memory leak when issuing multiple
54  // calls to GetEvent()
55  //wcsimT->GetBranch("wcsimrootevent_OD")->SetAutoDelete(kTRUE);
56 
57  // const long unsigned int nbEntries = wcsimT->GetEntries();
58  const long unsigned int nbEntries = wcsimT->GetEntries();
59  cout << "Nb of entries " << wcsimT->GetEntries() << endl;
60 
62  // HISTOGRAMS DEFINITION /////////////////
64 
65  const int nbThresh = 100;
66  int trigThresh[nbThresh];
67 
68  for(int iThresh=0;iThresh<nbThresh;iThresh++){
69  trigThresh[iThresh]=iThresh; // in PE
70  }
71 
72  TGraph *grEffVSThres = new TGraph();
73  grEffVSThres->SetName("grEffVSThres");
74  grEffVSThres->SetTitle("Trigger veto efficiency VS Trigger threshold; Threshold (PE) ; Eff (%)");
75  grEffVSThres->SetLineColor(kGreen+1);
76  grEffVSThres->SetLineWidth(1.);
77  grEffVSThres->SetMarkerColor(kGreen+1);
78  grEffVSThres->SetMarkerSize(1.);
79  grEffVSThres->SetMarkerStyle(kOpenThreeTriangles);
80 
81  TGraph *grMultVSThres = new TGraph();
82  grMultVSThres->SetName("grMultVSThres");
83  grMultVSThres->SetTitle("Multiplicity VS Trigger threshold; Threshold (PE) ; Multiplicity");
84  grMultVSThres->SetLineColor(kBlue-4);
85  grMultVSThres->SetLineWidth(1.);
86  grMultVSThres->SetMarkerColor(kBlue-4);
87  grMultVSThres->SetMarkerSize(1.);
88  grMultVSThres->SetMarkerStyle(kDiamond);
89 
90  TH1D *hMultByThresh[nbThresh];
91  const int nbBins = 10000;
92  const int nbODPMTs = 10000;
93 
94  int nbEffByThresh[nbThresh];
95  int nbMultByThresh[nbEntries][nbThresh];
96  for(int iThresh=0;iThresh<nbThresh;iThresh++){
97  nbEffByThresh[iThresh] = 0;
98  hMultByThresh[iThresh] = new TH1D(Form("hMultByThresh%d",iThresh),
99  Form("Multiplicity for thresh %d PE",iThresh),
100  nbBins,
101  0,
102  nbODPMTs);
103  for(long unsigned int iEntry = 0; iEntry < nbEntries; iEntry++){
104  nbMultByThresh[iEntry][iThresh] = 0;
105  }
106  }
107 
108 
109  // END HISTOGRAMS DEFINITION /////////////
111 
112  for(long unsigned int iEntry = 0; iEntry < nbEntries; iEntry++){
113  // Point to event iEntry inside WCSimTree
114  wcsimT->GetEvent(iEntry);
115 
116  // Nb of Trigger inside the event
117  const unsigned int nbTriggers = wcsimrootsuperevent->GetNumberOfEvents();
118  const unsigned int nbSubTriggers = wcsimrootsuperevent->GetNumberOfSubEvents();
119 
120  // cout << "iEntry : " << iEntry << endl;
121  // cout << "nbTrig : " << nbTriggers << endl;
122  // cout << "nbSubTrig : " << nbSubTriggers << endl;
123 
124  for(long unsigned int iTrig = 0; iTrig < nbTriggers; iTrig++){
125  WCSimRootTrigger *wcsimrootevent = wcsimrootsuperevent->GetTrigger(iTrig);
126 
127  // DIGI HITS
128  int digiMax = wcsimrootevent->GetNcherenkovdigihits();
129  int totDigiPE = 0;
130 
131  for (int i = 0; i < digiMax; i++){
132  //WCSimRootChernkovDigiHit has methods GetTubeId(), GetT(), GetQ()
133  WCSimRootCherenkovDigiHit *cDigiHit =
134  (WCSimRootCherenkovDigiHit*)wcsimrootevent->GetCherenkovDigiHits()->At(i);
135 
136  for(int iThresh=0;iThresh<nbThresh;iThresh++){
137  if(cDigiHit->GetQ() > trigThresh[iThresh]) nbMultByThresh[iEntry][iThresh]++;
138  }
139 
140  } // END FOR DIGI HITS
141 
142  } // END FOR iTRIG
143 
144  for(int iThresh=0;iThresh<nbThresh;iThresh++){
145  hMultByThresh[iThresh]->Fill(nbMultByThresh[iEntry][iThresh]);
146  }
147 
148  } // END FOR iENTRY
149 
151  // EFFICIENCY AND MULTIPILICITY //////////
153 
154  for(int iThresh=0;iThresh<nbThresh;iThresh++){
155 
156  for(long unsigned int iEntry = 0; iEntry < nbEntries; iEntry++){
157  if(nbMultByThresh[iEntry][iThresh] > 0){
158  nbEffByThresh[iThresh]++;
159  continue;
160  }
161  }
162 
163  grEffVSThres->SetPoint(iThresh,
164  trigThresh[iThresh],
165  (double)(nbEffByThresh[iThresh])/(double)(nbEntries));
166  grMultVSThres->SetPoint(iThresh,
167  trigThresh[iThresh],
168  hMultByThresh[iThresh]->GetMean());
169  }
170 
172  // DRAWING ///////////////////////////////
174 
175  TCanvas *c1;
176 
177  c1 = new TCanvas("cEff","cEff",800,600);
178  gPad->SetGrid();
179  grEffVSThres->Draw("APL");
180 
181  c1 = new TCanvas("cMult","cMult",800,600);
182  gPad->SetGrid();
183  grMultVSThres->Draw("APL");
184 
185  TFile *output=NULL;
186 
187  char outputName[1000];
188  sprintf(outputName,"TRIGGER_%s",bname);
189  output = new TFile(outputName,"recreate");
190  grEffVSThres->Write();
191  grMultVSThres->Write();
192 
193 } // END MACRO
Int_t GetNumberOfSubEvents() const
Class holding digitised hit (aka digit or digi) information (after PMT & electronics simulation + tri...
dirname
Definition: MakeKin.py:93
Int_t GetNcherenkovdigihits() const
Class storing trigger information.
WCSimRootTrigger * GetTrigger(int number)
string filename
Definition: MakeKin.py:235
Int_t GetNumberOfEvents() const
Class containing event information.
TClonesArray * GetCherenkovDigiHits() const
void trigger_OD(char *filename=NULL)
Definition: trigger_OD.C:5