forked from nuPRISM/WCSim
-
Notifications
You must be signed in to change notification settings - Fork 0
/
DynaRange_TreeBuildMulti.C
139 lines (101 loc) · 3.72 KB
/
DynaRange_TreeBuildMulti.C
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
#include <stdio.h>
#include <stdlib.h>
#include <cmath>
#include <string>
#include <vector>
/* Michael Walters, June 2015
*
* Builds tree of certain data for
* dynamic range analysis.
* Takes WCSim .root files.
*
*/
void DynaRange_TreeBuildMulti() {
gROOT->Reset();
char* wcsimdirenv;
wcsimdirenv = getenv ("WCSIMDIR");
if(wcsimdirenv != NULL){
gSystem->Load("${WCSIMDIR}/libWCSimRoot.so");
}else{
gSystem->Load("${HOME}/work/wcsim/WCSim/libWCSimRoot.so");
}
gStyle->SetOptStat(1);
TFile *f, *fout;
fout = new TFile("~/work/wcsim/WCSim/DynaRange_TreeBuildMulti_Out.root","RECREATE");
TTree *DRtree = new TTree("DRtree","DRtree Title");
char filename[100];
double start[3], stop[3]; // Location coordinates of source particle
double E,maxchrg,meanchrg; // Initial energy of source, max PE captured, mean PE accross PMTs
double PEthresh = 500.; // Threshold value
int eventID;
unsigned int nHits; // Number of PMT hits
unsigned int nHitsThresh; // Number above threshold
DRtree->Branch("filename",&filename,"filename/C");
DRtree->Branch("start",&start,"start[3]/D");
DRtree->Branch("stop",&stop,"stop[3]/D");
DRtree->Branch("E",&E,"E/D");
DRtree->Branch("maxchrg",&maxchrg,"maxchrg/D");
DRtree->Branch("meanchrg",&meanchrg,"meanchrg/D");
DRtree->Branch("PEthresh",&PEthresh,"PEthresh/D");
DRtree->Branch("eventID",&eventID,"eventID/I");
DRtree->Branch("nHits",&nHits,"nHits/i");
DRtree->Branch("nHitsThresh",&nHitsThresh,"nHitsThresh/i");
// Loop through files, building DRtree
int iFirst = 2;
int iLast = 4;
for(int iFile = iFirst; iFile < (iLast+1); iFile++) {
sprintf(filename,"/data14b/mwalters/wcsim_eIso%i.root",iFile);
f = new TFile(filename,"READ");
if (!f->IsOpen()){
cout << "Error, could not open input file: " << filename << endl;
return -1;
}
TTree *wcsimT = f->Get("wcsimT");
WCSimRootEvent *wcsimrootsuperevent = new WCSimRootEvent();
wcsimT->SetBranchAddress("wcsimrootevent",&wcsimrootsuperevent);
// Force deletion to prevent memory leak when issuing multiple
// calls to GetEvent()
wcsimT->GetBranch("wcsimrootevent")->SetAutoDelete(kTRUE);
int nevent = wcsimT->GetEntries();
//nevent = 400;
for(int ii = 0; ii < nevent; ii++) {
eventID = ii;
if(ii%50==0)
std::cout << "Event " << ii << std::endl;
wcsimT->GetEvent(ii);
// In the default vis.mac, only one event is run. I suspect you could loop over more events, if they existed.
WCSimRootTrigger *wcsimrootevent = wcsimrootsuperevent->GetTrigger(0);
int maxhits = wcsimrootevent->GetNcherenkovhits();
nHits = maxhits;
nHitsThresh = 0;
double cmean = 0.;
double clargest = 0.;
for(int i = 0; i < maxhits; i++) {
WCSimRootCherenkovHit *chit = (WCSimRootCherenkovHit*)wcsimrootevent->GetCherenkovHits()->At(i);
double charge = chit->GetTotalPe(1);
cmean += charge;
if(charge > PEthresh)
nHitsThresh++;
if(charge > clargest)
clargest = charge;
}
if(maxhits)
cmean /= (double)maxhits;
else
std::cout << "Event " << ii << ":\tNo Cherenkov hits, probably outside detector" << std::endl;
meanchrg = cmean;
maxchrg = clargest;
// Point the track to the source particle. Normally would be At(0) but
// there's this odd mirror that is produced everytime in that slot, so we want At(2)
WCSimRootTrack *track = (WCSimRootTrack*)wcsimrootevent->GetTracks()->At(2);
// Start and Stop vertices for source particle
for(int q = 0; q < 3; q++) {
start[q] = track->GetStart(q)/100;
stop[q] = track->GetStop(q)/100;
}
E = track->GetE()/1000;
DRtree->Fill();
}
}
fout->Write();
}