CMS 3D CMS Logo

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