CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
GetRecoTauVFromDQM_MC_cff.py
Go to the documentation of this file.
1 import os
2 import sys
3 import ROOT
4 
5 if len(sys.argv) < 4:
6  print "Error. Expected at least 3 arguments\n\nUsage: python GetRecoTauVFromDQM_MC_cff.py InputFile OutputFile EventType"
7  sys.exit()
8 
9 
10 Input = sys.argv[1]
11 Output = sys.argv[2]
12 ET = sys.argv[3]
13 
14 InputFileName = "%s" % Input
15 OutputFileName = "%s" % Output
16 EventType = "%s" % ET
17 
18 
19 #opening output file
20 outFile = ROOT.TFile(OutputFileName,"recreate")
21 
22 #opening input file
23 fullFile = ROOT.TFile(InputFileName)
24 
25  #retrieving interesting Directory position
26 source = ROOT.gDirectory.ls()
27 
28  #retrieving interesting Directory position
29 source = ROOT.gDirectory.ls()
30 next=ROOT.TIter(fullFile.GetListOfKeys())
31 dirFound0 = None
32 dirFound1 = None
33 dirFound2 = None
34 dirFound3 = None
35 
36 for key in next:
37  cl = ROOT.gROOT.GetClass(key.GetClassName())
38  if(cl.InheritsFrom("TDirectory")):
39  dir=key.ReadObj()
40  dirFound0=dir.GetName()
41  next2=ROOT.TIter(dir.GetListOfKeys())
42  for key in next2:
43  cl2 = ROOT.gROOT.GetClass(key.GetClassName())
44  if(cl2.InheritsFrom("TDirectory")):
45  dir2=key.ReadObj()
46  dirFound1 = dir2.GetName()
47  next3=ROOT.TIter(dir2.GetListOfKeys())
48  for key in next3:
49  cl3 = ROOT.gROOT.GetClass(key.GetClassName())
50  if(cl3.InheritsFrom("TDirectory")):
51  dir3=key.ReadObj()
52  if 'RecoTauV' in dir3.GetName():
53  dirFound2 = dir3.GetName()
54  next4=ROOT.TIter(dir3.GetListOfKeys())
55  for key in next4:
56  cl4 = ROOT.gROOT.GetClass(key.GetClassName())
57  if(cl4.InheritsFrom("TDirectory")):
58  dir4=key.ReadObj()
59  dirFound3 = dir4.GetName()
60 
61 InputDir = dirFound0+"/"+dirFound1+"/"+dirFound2+"/"+dirFound3
62 ROOT.gDirectory.cd(InputDir)
63 
64  #Listing subdirectories of TargetDir
65 SubDirs = []
66 next5=ROOT.TIter(ROOT.gDirectory.GetListOfKeys())
67 for key in next5:
68  cl5 = ROOT.gROOT.GetClass(key.GetClassName())
69  if(cl5.InheritsFrom("TDirectory")):
70  dirFound4=key.ReadObj()
71  dirFound4_name=dirFound4.GetName()
72  if EventType in dirFound4_name:
73  SubDirs.append(dirFound4_name)
74 
75  #Writing objects to file
76 for sub in SubDirs:
77  outFile.cd()
78  ROOT.gDirectory.mkdir(sub)
79  fullFile.cd()
80  ROOT.gDirectory.cd(InputDir+"/"+sub)
81  HList = ROOT.TIter(ROOT.gDirectory.GetListOfKeys())
82  for k in HList:
83  kk = ROOT.gROOT.GetClass(k.GetClassName())
84  if(kk.InheritsFrom("TH1F")):
85  outFile.cd()
86  ROOT.gDirectory.cd(sub)
87  obj = k.ReadObj()
88  obj.Write()
89 
90 outFile.Close()
if(dp >Float(M_PI)) dp-