-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathskimAllRelevantEvents.py
43 lines (40 loc) · 1.21 KB
/
skimAllRelevantEvents.py
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
import ROOT as r
import pickle
import os
import sys
r.gROOT.SetBatch(True)
r.gStyle.SetOptStat(0)
def makeSkim(inputFile,outputFile,cutString,test=False):
if inputFile == outputFile:
print "DON'T OVERWRITE THE INPUT!"
exit()
inputFile = r.TFile(inputFile)
tree = inputFile.Get("MuonSystem")
if test:
tree.Draw(">>eList",cutString,"entryList",1000);
else:
tree.Draw(">>eList",cutString,"entryList",);
eList = r.gDirectory.Get("eList");
tree.SetEntryList(eList);
newFile = r.TFile(outputFile,"RECREATE");
newTree = tree.CloneTree(0)
for i in range(eList.GetN()):
iEntry = eList.GetEntry(i)
tree.GetEntry(iEntry)
newTree.Fill()
newTree.AutoSave()
oHist = inputFile.Get("NEvents")
newFile.cd()
oHist.Write()
if __name__ == "__main__":
defaultCutString = "nDtRechitClusters>0"
if len(sys.argv) < 3:
print "usage python skimAllRelevantEvents.py <inputFile> <outputFile> <optional: cut string>"
exit()
inputFile = sys.argv[1]
outputFile = sys.argv[2]
if len(sys.argv) == 4:
cutString = sys.argv[3]
else:
cutString = defaultCutString
makeSkim(inputFile,outputFile,cutString)