Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 12:33:19

0001 from __future__ import print_function
0002 import os
0003 import sys
0004 import ROOT
0005 
0006 if len(sys.argv) < 4:
0007     print("Error. Expected at least 3 arguments\n\nUsage: python3 GetRecoTauVFromDQM_MC_cff.py InputFile OutputFile EventType")
0008     sys.exit()
0009 
0010 
0011 Input  = sys.argv[1]
0012 Output = sys.argv[2]
0013 ET     = sys.argv[3]
0014 
0015 InputFileName  = "%s" % Input
0016 OutputFileName = "%s" % Output
0017 EventType      = "%s" % ET
0018 
0019 
0020 #opening output file 
0021 outFile = ROOT.TFile(OutputFileName,"recreate")
0022 
0023 #opening input file
0024 fullFile = ROOT.TFile(InputFileName)
0025 
0026     #retrieving interesting Directory position
0027 source = ROOT.gDirectory.ls()
0028 
0029     #retrieving interesting Directory position
0030 source = ROOT.gDirectory.ls()
0031 next=ROOT.TIter(fullFile.GetListOfKeys())
0032 dirFound0 = None
0033 dirFound1 = None
0034 dirFound2 = None
0035 dirFound3 = None
0036 
0037 for key in next:
0038     cl = ROOT.gROOT.GetClass(key.GetClassName())
0039     if(cl.InheritsFrom("TDirectory")):
0040        dir=key.ReadObj()
0041        dirFound0=dir.GetName()
0042        next2=ROOT.TIter(dir.GetListOfKeys())
0043        for key in next2:
0044            cl2 = ROOT.gROOT.GetClass(key.GetClassName())
0045            if(cl2.InheritsFrom("TDirectory")):
0046               dir2=key.ReadObj()
0047               dirFound1 = dir2.GetName()
0048               next3=ROOT.TIter(dir2.GetListOfKeys())
0049               for key in next3:
0050                   cl3 = ROOT.gROOT.GetClass(key.GetClassName())
0051                   if(cl3.InheritsFrom("TDirectory")):
0052                      dir3=key.ReadObj()
0053                      if 'RecoTauV' in dir3.GetName():
0054                         dirFound2 = dir3.GetName()
0055                         next4=ROOT.TIter(dir3.GetListOfKeys())
0056                         for key in next4:
0057                             cl4 = ROOT.gROOT.GetClass(key.GetClassName())
0058                             if(cl4.InheritsFrom("TDirectory")):
0059                                 dir4=key.ReadObj()
0060                                 dirFound3 = dir4.GetName()
0061 
0062 InputDir = dirFound0+"/"+dirFound1+"/"+dirFound2+"/"+dirFound3
0063 ROOT.gDirectory.cd(InputDir)
0064 
0065     #Listing subdirectories of TargetDir
0066 SubDirs = []
0067 next5=ROOT.TIter(ROOT.gDirectory.GetListOfKeys())
0068 for key in next5:
0069     cl5 = ROOT.gROOT.GetClass(key.GetClassName())
0070     if(cl5.InheritsFrom("TDirectory")):
0071        dirFound4=key.ReadObj()
0072        dirFound4_name=dirFound4.GetName()
0073        if EventType in dirFound4_name:
0074           SubDirs.append(dirFound4_name)  
0075 
0076     #Writing objects to file
0077 for sub in SubDirs:
0078     outFile.cd()
0079     ROOT.gDirectory.mkdir(sub)
0080     fullFile.cd()
0081     ROOT.gDirectory.cd(InputDir+"/"+sub)
0082     HList = ROOT.TIter(ROOT.gDirectory.GetListOfKeys())
0083     for k in HList:
0084        kk = ROOT.gROOT.GetClass(k.GetClassName())
0085        if(kk.InheritsFrom("TH1F")):
0086           outFile.cd()
0087           ROOT.gDirectory.cd(sub)
0088           obj = k.ReadObj()
0089           obj.Write()
0090           
0091 outFile.Close()