ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/UserCode/RootMacros/plotFromMultipleFiles.py
(Generate patch)

Comparing UserCode/RootMacros/plotFromMultipleFiles.py (file contents):
Revision 1.1 by anderson, Wed Nov 4 18:49:28 2009 UTC vs.
Revision 1.2 by anderson, Wed Nov 4 22:52:35 2009 UTC

# Line 23 | Line 23 | class rootFile:
23          self.name  = fileName
24          self.scale = theScale
25          self.cuts  = theCuts
26 <        self.file  = TFile(fileName, "read")
26 >        self.file  = TFile(fileName, "read")       # Open TFile
27          if self.file.IsZombie():
28 <            print "Error opening "+self.name+", exiting..."
28 >            print "Error opening %s, exiting..." % self.name
29              sys.exit(0)
30          self.ttree = TTree()
31 <        self.file.GetObject(ttreeName, self.ttree)  # ttreeName is set in variables below
31 >        self.file.GetObject(ttreeName, self.ttree) # ttreeName is set in variables below
32   ########################################
33  
34  
# Line 40 | Line 40 | ttreeName = "TreePhotonJet"  # TTree nam
40  
41   #                        Filename,              scale=invLum*(cross section)/events analyzed,                cuts
42   listOfFiles = [rootFile("QCD_Pt15_Summer09.root",invLum*(1.457E9-1.091E7)/4.667392e+06,"event_genEventScale>15&&event_genEventScale<30"),
43 <               rootFile("QCD_Pt30_Summer09.root",invLum*(1.091E7-1.93E6)/1.779232e+06,"event_genEventScale>30&&event_genEventScale<80"),
44 <               rootFile("QCD_Pt80_Summer09.root",invLum*(1.93E6-6.2E4)/2.14780e+06,"event_genEventScale>80&&event_genEventScale<170")]
43 >               rootFile("QCD_Pt30_Summer09.root",invLum*(1.091E7-1.93E6)/1.779232e+06, "event_genEventScale>30&&event_genEventScale<80"),
44 >               rootFile("QCD_Pt80_Summer09.root",invLum*(1.93E6-6.2E4)/2.14780e+06,    "event_genEventScale>80&&event_genEventScale<170")]
45 >
46 > # Cut applied to all files
47 > cutForAllFiles = "photon_et>15.0&&abs(photon_eta)<2.5"
48  
49   # Histogram bins
50   #   Converting with "array" is done because ROOT wants an array of Float_t
# Line 58 | Line 61 | outputFilename = "QCD_combined_%s.root"
61  
62  
63   ########################################
64 < # Let user know what's up
64 > # Print names of opened files
65   for aFile in listOfFiles:
66      print "Opened %s, scale=%.2e, cuts='%s'" % (aFile.name, aFile.scale, aFile.cuts)
67  
# Line 73 | Line 76 | print "Creating plots...",
76   # Loop over all things to plot
77   for plot in listOfPlots:
78      # Loop over all TTrees (from the different files)
76    i = 0
79      for aFile in listOfFiles:
80 <        tempHistName = "temp%i" % i
81 <        tempHist = listOfPlots[plot].Clone(tempHistName)                          # Create temp histogram
82 <        aFile.ttree.Draw( "%s >> %s" % (plot, tempHistName), aFile.cuts, "goff" ) # Draw into it (with cuts)
83 <        tempHist.Scale(aFile.scale)                                               # Scale it
84 <        listOfPlots[plot].Add(tempHist)                                           # Add it to total histogram
83 <        i += 1
80 >        tempHist = listOfPlots[plot].Clone("temp")            # Create temp histogram
81 >        cuts = "%s&&%s" % (cutForAllFiles, aFile.cuts)        # Set cuts
82 >        aFile.ttree.Draw( "%s >> temp" % plot, cuts, "goff" ) # Draw into it (with cuts)
83 >        tempHist.Scale(aFile.scale)                           # Scale it
84 >        listOfPlots[plot].Add(tempHist)                       # Add it to total histogram
85   print "done."
86   ########################################
87  
# Line 89 | Line 90 | print "done."
90   #   Store and save/close files
91   outputFile.cd()
92   for plot in listOfPlots:
93 <    try:
93 <        listOfPlots[plot].Write()
94 <    except Exception, e:
95 <        print plot, e
93 >    listOfPlots[plot].Write()
94  
95 < print "Closing files..."
95 > print "Closing files...",
96   outputFile.Close()
97   for aFile in listOfFiles:
98      aFile.file.Close()
99 < print "Histograms stored in %s" % outputFilename
99 > print "done.\n\nHistograms stored in %s" % outputFilename
100   ########################################

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines