WCSim
read_PMT.C
Go to the documentation of this file.
1 #include <stdio.h>
2 #include <stdlib.h>
3 
4 #include "TSystem.h"
5 #include "TFile.h"
6 #include "TTree.h"
7 #include "TROOT.h"
8 #include "TStyle.h"
9 #include "TH1D.h"
10 #include "TH2D.h"
11 #include "TProfile.h"
12 #include "TCanvas.h"
13 
14 #include "WCSimRootEvent.hh"
15 
16 int read_PMT(const char *filename="../wcsim.root") {
17  /* A simple script to plot aspects of phototube hits
18  * This code is rather cavalier; I should be checking return values, etc.
19  * First revision 6-24-10 David Webber
20  *
21  * I like to run this macro as
22  * $ root -l -x 'read_PMT.C("../wcsim.root")'
23  */
24 
25  gROOT->Reset();
26  gStyle->SetOptStat(1);
27 
28  TFile *f = new TFile(filename);
29  if (!f->IsOpen()){
30  cout << "Error, could not open input file: " << filename << endl;
31  return -1;
32  }
33 
34  TTree *wcsimT = 0;
35  f->GetObject("wcsimT", wcsimT);
36 
37  WCSimRootEvent *wcsimrootsuperevent = new WCSimRootEvent();
38  wcsimT->SetBranchAddress("wcsimrootevent",&wcsimrootsuperevent);
39 
40  // Force deletion to prevent memory leak when issuing multiple
41  // calls to GetEvent()
42  wcsimT->GetBranch("wcsimrootevent")->SetAutoDelete(kTRUE);
43 
44  wcsimT->GetEvent(0);
45 
46  // Currently only looks at one subevent. I suspect you could loop over more subevents, if they existed.
47  WCSimRootTrigger *wcsimrootevent = wcsimrootsuperevent->GetTrigger(0);
48 
49  //--------------------------
50  // As you can see, there are lots of ways to get the number of hits.
51  cout << "Number of tube hits " << wcsimrootevent->GetNumTubesHit() << endl;
52  cout << "Number of Cherenkov tube hits " << wcsimrootevent->GetNcherenkovhits() << endl;
53  cout << "Number of Cherenkov tube hits " << wcsimrootevent->GetCherenkovHits()->GetEntries() << endl;
54 
55  cout << "Number of digitized tube hits " << wcsimrootevent->GetNumDigiTubesHit() << endl;
56  cout << "Number of digitized Cherenkov tube hits " << wcsimrootevent->GetNcherenkovdigihits() << endl;
57  cout << "Number of digitized Cherenkov tube hits " << wcsimrootevent->GetCherenkovDigiHits()->GetEntries() << endl;
58 
59  cout << "Number of photoelectron hit times " << wcsimrootevent->GetCherenkovHitTimes()->GetEntries() << endl;
60 
61  //-----------------------
62 
63  TH1D *PE = new TH1D("PEmult","Photoelectron multiplicty", 16,-0.5,15.5);
64  PE->SetXTitle("Photoelectrons");
65 
66  TH1D *PMT_hits = new TH1D("PMT_hits","Hits vs PMT detector number", 120000,-0.5,120000-0.5);
67 
68  int max=wcsimrootevent->GetNcherenkovhits();
69  for (int i = 0; i<max; i++){
70  TObject * element = wcsimrootevent->GetCherenkovHits()->At(i);
71  if(!element)
72  continue;
73  WCSimRootCherenkovHit *chit = dynamic_cast<WCSimRootCherenkovHit*>(element);
74  PMT_hits->Fill(chit->GetTubeID());
75  //WCSimRootCherenkovHit has methods GetTubeId(), GetTotalPe(int)
76  PE->Fill(chit->GetTotalPe(1));
77  }
78  //PE->Draw("");
79 
80  //----------------------------
81 
82  TH2D *QvsT = new TH2D("QvsT","charge vs. time", 40, 900, 1400, 40, -0.5, 15.5);
83  QvsT->SetXTitle("time");
84  QvsT->SetYTitle("charge");
85 
86  max = wcsimrootevent->GetNcherenkovdigihits_slots();
87  for (int i = 0; i<max; i++){
88  TObject* element = wcsimrootevent->GetCherenkovDigiHits()->At(i);
89  if(!element)
90  continue;
91  WCSimRootCherenkovDigiHit *cDigiHit = dynamic_cast<WCSimRootCherenkovDigiHit*>(element);
92  if(!cDigiHit)
93  continue;
94  //WCSimRootChernkovDigiHit has methods GetTubeId(), GetT(), GetQ()
95  QvsT->Fill(cDigiHit->GetT(), cDigiHit->GetQ());
96  //WCSimRootCherenkovHitTime *cHitTime = wcsimrootevent->GetCherenkovHitTimes()->At(i); // this should loop over wcsimrootevent->GetCherenkovHitTimes()!
97  //WCSimRootCherenkovHitTime has methods GetTubeId(), GetTruetime()
98  }
99 
100  TH1 *temp;
101  TProfile * temp_profile;
102  float win_scale=0.75;
103  int n_wide=2;
104  int n_high=3;
105  TCanvas *c1 = new TCanvas("c1","c1",700*n_wide*win_scale,500*n_high*win_scale);
106  c1->Divide(n_wide,n_high);
107  c1->cd(1);
108  QvsT->Draw("colz");
109 
110  c1->cd(2);
111  temp=QvsT->ProjectionY();
112  temp->SetTitle("charge");
113  temp->Draw();
114  c1->GetPad(2)->SetLogy();
115 
116  c1->cd(3);
117  temp=QvsT->ProjectionX();
118  temp->SetTitle("hits vs time");
119  temp->Draw();
120  c1->GetPad(3)->SetLogy();
121 
122  c1->cd(4);
123  temp_profile=QvsT->ProfileX();
124  temp_profile->SetTitle("average charge vs time");
125  temp_profile->Draw();
126 
127  c1->cd(5);
128  temp=PE;
129  temp->Draw();
130  c1->GetPad(5)->SetLogy();
131 
132  return 0;
133 }
Class holding digitised hit (aka digit or digi) information (after PMT & electronics simulation + tri...
Int_t GetNumDigiTubesHit() const
int read_PMT(const char *filename="../wcsim.root")
Definition: read_PMT.C:16
Int_t GetNcherenkovhits() const
TClonesArray * GetCherenkovHits() const
Int_t GetNcherenkovdigihits() const
Class storing trigger information.
Int_t GetTotalPe(int i) const
WCSimRootTrigger * GetTrigger(int number)
TClonesArray * GetCherenkovHitTimes() const
Int_t GetNumTubesHit() const
string filename
Definition: MakeKin.py:235
Class containing event information.
Int_t GetNcherenkovdigihits_slots() const
Class holding true (Cherenkov photon + dark noise) hit information.
TClonesArray * GetCherenkovDigiHits() const