def main() : parser = optparse.OptionParser(description="Switch for data/MC running") parser.add_option('-m', action="store_true", default=False, dest="isMC") parser.add_option('-d', action="store_true", default=False, dest="debug") parser.add_option('-s', action="store", default="gjets",dest="sample", type="string") parser.add_option('-f', action="store", default="0", dest="subsec", type="int") parser.add_option('-t', action="store", default="directPhotonsID",dest="treeName", type="string") parser.add_option('-p', action="store", default=100.0,dest="minpt", type="float") parser.add_option('-r', action="store", default=0.5,dest="cutDR", type="float") options, args = parser.parse_args() r.gROOT.SetBatch(True) subfiles = [ "*",#0 "*_?_?_???",#1 "*_1?_?_???","*_2?_?_???","*_3?_?_???","*_4?_?_???","*_5?_?_???","*_6?_?_???","*_7?_?_???","*_8?_?_???","*_9?_?_???",#10 "*_11?_?_???","*_12?_?_???","*_13?_?_???","*_14?_?_???","*_15?_?_???","*_16?_?_???","*_17?_?_???","*_18?_?_???","*_19?_?_???",#19 "*_21?_?_???","*_22?_?_???","*_23?_?_???","*_24?_?_???","*_25?_?_???","*_26?_?_???","*_27?_?_???","*_28?_?_???","*_29?_?_???",#28 "*_31?_?_???","*_32?_?_???","*_33?_?_???","*_34?_?_???","*_35?_?_???","*_36?_?_???","*_37?_?_???","*_38?_?_???","*_39?_?_???",#37 "*_41?_?_???","*_42?_?_???","*_43?_?_???","*_44?_?_???","*_45?_?_???","*_46?_?_???","*_47?_?_???","*_48?_?_???","*_49?_?_???",#46 "*_51?_?_???","*_52?_?_???","*_53?_?_???","*_54?_?_???","*_55?_?_???","*_56?_?_???","*_57?_?_???","*_58?_?_???","*_59?_?_???",#55 "*_61?_?_???","*_62?_?_???","*_63?_?_???","*_64?_?_???","*_65?_?_???","*_66?_?_???","*_67?_?_???","*_68?_?_???","*_69?_?_???",#64 "*_71?_?_???","*_72?_?_???","*_73?_?_???","*_74?_?_???","*_75?_?_???","*_76?_?_???","*_77?_?_???","*_78?_?_???","*_79?_?_???",#73 "*_81?_?_???","*_82?_?_???","*_83?_?_???","*_84?_?_???","*_85?_?_???","*_86?_?_???","*_87?_?_???","*_88?_?_???","*_89?_?_???",#82 "*_91?_?_???","*_92?_?_???","*_93?_?_???","*_94?_?_???","*_95?_?_???","*_96?_?_???","*_97?_?_???","*_98?_?_???","*_99?_?_???",#91 "*_101?_?_???","*_102?_?_???","*_103?_?_???","*_104?_?_???","*_105?_?_???","*_106?_?_???","*_107?_?_???","*_108?_?_???","*_109?_?_???",#100 ] outFileName = "sampleTreeDR%2.1f_%s_%d.root"%(options.cutDR,options.sample,options.subsec) if options.debug: outFileName = "sampleTreeDR%2.1f_%s_test.root"%(options.cutDR,options.sample) print outFileName sys.stdout.flush() outFile = r.TFile(outFileName,"RECREATE") tree = r.TTree( 'tree', 'tree for sample ' ) nJetsHT = array( 'i', [ 0 ] ) nJetsMHT = array( 'i', [ 0 ] ) htVal = array( 'd', [ 0. ] ) mhtVal = array( 'd', [ 0. ] ) dphi1 = array( 'd', [ 0. ] ) dphi2 = array( 'd', [ 0. ] ) dphi3 = array( 'd', [ 0. ] ) photonPt = array( 'd', [ 0. ] ) photonEta = array( 'd', [ 0. ] ) photonMinDR = array( 'd', [ 0. ] ) photonpfCH = array( 'd', [ 0. ] ) photonpfNU = array( 'd', [ 0. ] ) photonpfGA = array( 'd', [ 0. ] ) muon1Pt = array( 'd', [ 0. ] ) muon1Eta = array( 'd', [ 0. ] ) muon1MinDR = array( 'd', [ 0. ] ) muon2Pt = array( 'd', [ 0. ] ) muon2Eta = array( 'd', [ 0. ] ) muon2MinDR = array( 'd', [ 0. ] ) dimuonPt = array( 'd', [ 0. ] ) dimuonEta = array( 'd', [ 0. ] ) dimuonMinDR = array( 'd', [ 0. ] ) dimuonM = array( 'd', [ 0. ] ) jet1Pt = array( 'd', [ 0. ] ) jet1Eta = array( 'd', [ 0. ] ) jet2Pt = array( 'd', [ 0. ] ) jet2Eta = array( 'd', [ 0. ] ) jet3Pt = array( 'd', [ 0. ] ) jet3Eta = array( 'd', [ 0. ] ) eventWt = array( 'd', [ 0. ] ) puWt = array( 'd', [ 0. ] ) tree.Branch( 'nJetsHT', nJetsHT, 'nJetsHT/I' ) tree.Branch( 'nJetsMHT', nJetsMHT, 'nJetsMHT/I' ) tree.Branch( 'htVal', htVal, 'htVal/D' ) tree.Branch( 'mhtVal', mhtVal, 'mhtVal/D' ) tree.Branch( 'dphi1', dphi1, 'dphi1/D' ) tree.Branch( 'dphi2', dphi2, 'dphi2/D' ) tree.Branch( 'dphi3', dphi3, 'dphi3/D' ) tree.Branch( 'photonPt', photonPt, 'photonPt/D' ) tree.Branch( 'photonEta', photonEta, 'photonEta/D' ) tree.Branch( 'photonMinDR', photonMinDR, 'photonMinDR/D' ) tree.Branch( 'photonpfCH',photonpfCH, 'photonpfCH/D' ) tree.Branch( 'photonpfNU',photonpfNU, 'photonpfNU/D' ) tree.Branch( 'photonpfGA',photonpfGA, 'photonpfGA/D' ) tree.Branch( 'muon1Pt', muon1Pt, 'muon1Pt/D' ) tree.Branch( 'muon1Eta', muon1Eta, 'muon1Eta/D' ) tree.Branch( 'muon1MinDR', muon1MinDR, 'muon1MinDR/D' ) tree.Branch( 'muon2Pt', muon2Pt, 'muon2Pt/D' ) tree.Branch( 'muon2Eta', muon2Eta, 'muon2Eta/D' ) tree.Branch( 'muon2MinDR', muon2MinDR, 'muon2MinDR/D' ) tree.Branch( 'dimuonPt', dimuonPt, 'dimuonPt/D' ) tree.Branch( 'dimuonEta',dimuonEta, 'dimuonEta/D' ) tree.Branch( 'dimuonMinDR',dimuonMinDR, 'dimuonMinDR/D' ) tree.Branch( 'dimuonM', dimuonM, 'dimuonM/D' ) tree.Branch( 'jet1Pt', jet1Pt, 'jet1Pt/D' ) tree.Branch( 'jet1Eta', jet1Eta, 'jet1Eta/D' ) tree.Branch( 'jet2Pt', jet2Pt, 'jet2Pt/D' ) tree.Branch( 'jet2Eta', jet2Eta, 'jet2Eta/D' ) tree.Branch( 'jet3Pt', jet3Pt, 'jet3Pt/D' ) tree.Branch( 'jet3Eta', jet3Eta, 'jet3Eta/D' ) tree.Branch( 'eventWt', eventWt, 'eventWt/D' ) tree.Branch( 'puWt', puWt, 'puWt/D' ) myChain = r.TChain('%s/RA2Values'%(options.treeName)) ################## if options.debug: if options.sample=="gjets": ##noht200## myChain.Add("/uscmst1b_scratch/lpc1/3DayLifetime/sturdy07/tmp/cmssw525p1/treeMaker/gjetsht200_reco_tree_ra2/res/*_?_?_???.root") myChain.Add("/uscmst1b_scratch/lpc1/3DayLifetime/sturdy07/tmp/cmssw525p1/treeMaker/gjetsht400_reco_tree_ra2/res/*_?_?_???.root") elif options.sample=="data": myChain.Add("/uscmst1b_scratch/lpc1/3DayLifetime/sturdy07/tmp/cmssw525p1/treeMaker/run2012a_tree_ra2/res/*_?_?_???.root") myChain.Add("/uscmst1b_scratch/lpc1/3DayLifetime/sturdy07/tmp/cmssw525p1/treeMaker/run2012b_tree_ra2/res/*_?_?_???.root") elif options.sample=="zinv": ##noht200## myChain.Add("/uscmst1b_scratch/lpc1/3DayLifetime/sturdy07/tmp/cmssw525p1/treeMaker/zinvht200_reco_tree_ra2/res/*_?_?_???.root") myChain.Add("/uscmst1b_scratch/lpc1/3DayLifetime/sturdy07/tmp/cmssw525p1/treeMaker/zinvht400_reco_tree_ra2/res/*_?_?_???.root") elif options.sample=="zmumu": ##noht200## myChain.Add("/uscmst1b_scratch/lpc1/3DayLifetime/sturdy07/tmp/cmssw525p1/treeMaker/dyjetstoll_ht200_reco_tree_ra2/res/*_?_?_???.root") myChain.Add("/uscmst1b_scratch/lpc1/3DayLifetime/sturdy07/tmp/cmssw525p1/treeMaker/dyjetstoll_ht400_reco_tree_ra2/res/*_?_?_???.root") else: if options.sample=="gjets": ##noht200## myChain.Add("/uscmst1b_scratch/lpc1/3DayLifetime/sturdy07/tmp/cmssw525p1/treeMaker/gjetsht200_reco_tree_ra2/res/%s.root"%(subfiles[options.subsec])) myChain.Add("/uscmst1b_scratch/lpc1/3DayLifetime/sturdy07/tmp/cmssw525p1/treeMaker/gjetsht400_reco_tree_ra2/res/%s.root"%(subfiles[options.subsec])) elif options.sample=="data": myChain.Add("/uscmst1b_scratch/lpc1/3DayLifetime/sturdy07/tmp/cmssw525p1/treeMaker/run2012a_tree_ra2/res/%s.root"%(subfiles[options.subsec])) myChain.Add("/uscmst1b_scratch/lpc1/3DayLifetime/sturdy07/tmp/cmssw525p1/treeMaker/run2012b_tree_ra2/res/%s.root"%(subfiles[options.subsec])) elif options.sample=="zinv": ##noht200## myChain.Add("/uscmst1b_scratch/lpc1/3DayLifetime/sturdy07/tmp/cmssw525p1/treeMaker/zinvht200_reco_tree_ra2/res/%s.root"%(subfiles[options.subsec])) myChain.Add("/uscmst1b_scratch/lpc1/3DayLifetime/sturdy07/tmp/cmssw525p1/treeMaker/zinvht400_reco_tree_ra2/res/%s.root"%(subfiles[options.subsec])) elif options.sample=="zmumu": ##noht200## myChain.Add("/uscmst1b_scratch/lpc1/3DayLifetime/sturdy07/tmp/cmssw525p1/treeMaker/dyjetstoll_ht200_reco_tree_ra2/res/%s.root"%(subfiles[options.subsec])) myChain.Add("/uscmst1b_scratch/lpc1/3DayLifetime/sturdy07/tmp/cmssw525p1/treeMaker/dyjetstoll_ht400_reco_tree_ra2/res/%s.root"%(subfiles[options.subsec])) fChain = myChain ###Timing information decade = 0 century = 0 tsw = r.TStopwatch() tenpcount = 1 onepcount = 1 nentries = fChain.GetEntries() print "nentries %d"%(nentries) sys.stdout.flush() i = 0 for event in fChain: # ==============print number of events done == == == == == == == = if ( i==0): tsw.Start() #print('.', end='') sys.stdout.write('.') sys.stdout.flush() if ((i*10)/nentries == tenpcount ) : tsw.Stop() time = tsw.RealTime() tsw.Start(r.kFALSE) finTime = 0. frac = (i*1.0)/(nentries*1.0) if (frac>0): finTime = time / frac - time finMin = finTime / 60. sys.stdout.write("%d%% done. "%(tenpcount*10)) # sys.stdout.write("t=7.2f"%(time)) sys.stdout.write("t="+str(time)) sys.stdout.write(" projected finish=%7d s("%(finTime)) sys.stdout.write("%2.2f min). "%(finMin)) sys.stdout.write("\n") sys.stdout.flush() tenpcount = tenpcount + 1 elif ( (i*100)/nentries == onepcount ) : #print('.', end='') sys.stdout.write('.') sys.stdout.flush() onepcount = onepcount + 1 nJetsHT[0] = event.ra2_nJetsPt50Eta25 nJetsMHT[0] = event.ra2_nJetsPt30Eta50 htVal[0] = event.ra2_HT mhtVal[0] = event.ra2_MHT dphi1[0] = event.ra2_dPhiMHT1 dphi2[0] = event.ra2_dPhiMHT2 dphi3[0] = event.ra2_dPhiMHT3 jet1Pt[0] = event.ra2_Jet1Pt jet1Eta[0] = event.ra2_Jet1Eta jet2Pt[0] = event.ra2_Jet2Pt jet2Eta[0] = event.ra2_Jet2Eta jet3Pt[0] = event.ra2_Jet3Pt jet3Eta[0] = event.ra2_Jet3Eta puWt[0] = event.ra2_PUWt eventWt[0] = event.ra2_EventWt triggers = True if options.sample == "gjets" or options.sample == "data": photonPt[0] = event.ra2_Photon1Pt photonEta[0] = event.ra2_Photon1Eta photonMinDR[0] = event.ra2_Photon1MinDR photonpfCH[0] = event.ra2_Photon1pfCH photonpfNU[0] = event.ra2_Photon1pfNU photonpfGA[0] = event.ra2_Photon1pfGA if not options.isMC: triggers = (event.ra2_Photon70PFHT400 or event.ra2_Photon70PFNoPUHT400) if options.sample == "zmumu": muon1Pt[0] = event.ra2_Muon1Pt muon1Eta[0] = event.ra2_Muon1Eta muon1MinDR[0] = event.ra2_Muon1MinDR muon2Pt[0] = event.ra2_Muon2Pt muon2Eta[0] = event.ra2_Muon2Eta muon2MinDR[0] = event.ra2_Muon2MinDR dimuonPt[0] = event.ra2_DiMuonPt dimuonEta[0] = event.ra2_DiMuonEta dimuonMinDR[0] = event.ra2_DiMuonMinDR dimuonM[0] = event.ra2_DiMuonInvM if not options.isMC: triggers = (event.ra2_Mu13_Mu8 or event.ra2_Mu17_Mu8) if options.isMC: triggers = True extra = True if options.sample == "gjets" or options.sample == "data": extra = cutF.ra2PhotonSelection(event,options.minpt, options.cutDR) if options.sample == "zmumu": extra = cutF.ra2MuonSelection(event,options.minpt, options.cutDR) if (triggers) and extra and cutF.ra2Baseline(event): tree.Fill() ######### i = i + 1 #tree.Write() outFile.Write() outFile.Close()
def main() : parser = optparse.OptionParser(description="Switch for data/MC running") parser.add_option('-m', action="store_true", default=False, dest="isMC") parser.add_option('-d', action="store_true", default=False, dest="debug") parser.add_option('-s', action="store", default="gjets",dest="sample", type="string") parser.add_option('-f', action="store", default="0", dest="subsec", type="int") parser.add_option('-t', action="store", default="directPhotonsID",dest="treeName", type="string") parser.add_option('-p', action="store", default=100.0,dest="minpt", type="float") parser.add_option('-r', action="store", default=0.5,dest="cutDR", type="float") options, args = parser.parse_args() r.gROOT.SetBatch(True) subfiles = [ "*",#0 "*_?_?_???",#1 "*_1?_?_???","*_2?_?_???","*_3?_?_???","*_4?_?_???","*_5?_?_???","*_6?_?_???","*_7?_?_???","*_8?_?_???","*_9?_?_???",#10 "*_11?_?_???","*_12?_?_???","*_13?_?_???","*_14?_?_???","*_15?_?_???","*_16?_?_???","*_17?_?_???","*_18?_?_???","*_19?_?_???",#19 "*_21?_?_???","*_22?_?_???","*_23?_?_???","*_24?_?_???","*_25?_?_???","*_26?_?_???","*_27?_?_???","*_28?_?_???","*_29?_?_???",#28 "*_31?_?_???","*_32?_?_???","*_33?_?_???","*_34?_?_???","*_35?_?_???","*_36?_?_???","*_37?_?_???","*_38?_?_???","*_39?_?_???",#37 "*_41?_?_???","*_42?_?_???","*_43?_?_???","*_44?_?_???","*_45?_?_???","*_46?_?_???","*_47?_?_???","*_48?_?_???","*_49?_?_???",#46 "*_51?_?_???","*_52?_?_???","*_53?_?_???","*_54?_?_???","*_55?_?_???","*_56?_?_???","*_57?_?_???","*_58?_?_???","*_59?_?_???",#55 "*_61?_?_???","*_62?_?_???","*_63?_?_???","*_64?_?_???","*_65?_?_???","*_66?_?_???","*_67?_?_???","*_68?_?_???","*_69?_?_???",#64 "*_71?_?_???","*_72?_?_???","*_73?_?_???","*_74?_?_???","*_75?_?_???","*_76?_?_???","*_77?_?_???","*_78?_?_???","*_79?_?_???",#73 "*_81?_?_???","*_82?_?_???","*_83?_?_???","*_84?_?_???","*_85?_?_???","*_86?_?_???","*_87?_?_???","*_88?_?_???","*_89?_?_???",#82 "*_91?_?_???","*_92?_?_???","*_93?_?_???","*_94?_?_???","*_95?_?_???","*_96?_?_???","*_97?_?_???","*_98?_?_???","*_99?_?_???",#91 "*_101?_?_???","*_102?_?_???","*_103?_?_???","*_104?_?_???","*_105?_?_???","*_106?_?_???","*_107?_?_???","*_108?_?_???","*_109?_?_???",#100 ] outFileName = "estimateTreeDR%2.1f_%s_%d.root"%(options.cutDR,options.sample,options.subsec) if options.debug: outFileName = "estimateTreeDR%2.1f_%s_test.root"%(options.cutDR,options.sample) print outFileName sys.stdout.flush() outFile = r.TFile(outFileName,"RECREATE") tree = r.TTree( 'tree', 'tree for estimate ' ) nJetsHT = array( 'i', [ 0 ] ) nJetsMHT = array( 'i', [ 0 ] ) htVal = array( 'd', [ 0. ] ) mhtVal = array( 'd', [ 0. ] ) dphi1 = array( 'd', [ 0. ] ) dphi2 = array( 'd', [ 0. ] ) dphi3 = array( 'd', [ 0. ] ) photonPt = array( 'd', [ 0. ] ) photonEta = array( 'd', [ 0. ] ) jet1Pt = array( 'd', [ 0. ] ) jet1Eta = array( 'd', [ 0. ] ) jet2Pt = array( 'd', [ 0. ] ) jet2Eta = array( 'd', [ 0. ] ) jet3Pt = array( 'd', [ 0. ] ) jet3Eta = array( 'd', [ 0. ] ) eventWt = array( 'd', [ 0. ] ) puWt = array( 'd', [ 0. ] ) phen = array( 'd', [ 0. ] ) phenErrStat = array( 'd', [ 0. ] ) acc = array( 'd', [ 0. ] ) accErrStat = array( 'd', [ 0. ] ) recoID = array( 'd', [ 0. ] ) recoIDErrStat = array( 'd', [ 0. ] ) recoPFIso = array( 'd', [ 0. ] ) recoPFIsoErrStat = array( 'd', [ 0. ] ) purity = array( 'd', [ 0. ] ) purityErr = array( 'd', [ 0. ] ) datamcScaleF = array( 'd', [ 0. ] ) datamcScaleFErrStat = array( 'd', [ 0. ] ) datamcScaleFErrSyst = array( 'd', [ 0. ] ) datamcVetoF = array( 'd', [ 0. ] ) datamcVetoFErrStat = array( 'd', [ 0. ] ) corrFactor = array( 'd', [ 0. ] ) tree.Branch( 'nJetsHT', nJetsHT, 'nJetsHT/I' ) tree.Branch( 'nJetsMHT', nJetsMHT, 'nJetsMHT/I' ) tree.Branch( 'htVal', htVal, 'htVal/D' ) tree.Branch( 'mhtVal', mhtVal, 'mhtVal/D' ) tree.Branch( 'dphi1', dphi1, 'dphi1/D' ) tree.Branch( 'dphi2', dphi2, 'dphi2/D' ) tree.Branch( 'dphi3', dphi3, 'dphi3/D' ) tree.Branch( 'photonPt', photonPt, 'photonPt/D' ) tree.Branch( 'photonEta',photonEta, 'photonEta/D' ) tree.Branch( 'jet1Pt', jet1Pt, 'jet1Pt/D' ) tree.Branch( 'jet1Eta', jet1Eta, 'jet1Eta/D' ) tree.Branch( 'jet2Pt', jet2Pt, 'jet2Pt/D' ) tree.Branch( 'jet2Eta', jet2Eta, 'jet2Eta/D' ) tree.Branch( 'jet3Pt', jet3Pt, 'jet3Pt/D' ) tree.Branch( 'jet3Eta', jet3Eta, 'jet3Eta/D' ) tree.Branch( 'eventWt', eventWt, 'eventWt/D' ) tree.Branch( 'puWt', puWt, 'puWt/D' ) tree.Branch( 'phen', phen, 'phen/D' ) tree.Branch( 'phenErrStat', phenErrStat, 'phenErrStat/D' ) tree.Branch( 'acc', acc, 'acc/D' ) tree.Branch( 'accErrStat', accErrStat, 'accErrStat/D' ) tree.Branch( 'recoID', recoID, 'recoID/D' ) tree.Branch( 'recoIDErrStat', recoIDErrStat, 'recoIDErrStat/D' ) tree.Branch( 'recoPFIso', recoPFIso, 'recoPFIso/D' ) tree.Branch( 'recoPFIsoErrStat', recoPFIsoErrStat, 'recoPFIsoErrStat/D' ) tree.Branch( 'purity', purity, 'purity/D' ) tree.Branch( 'purityErr', purityErr, 'purityErr/D' ) tree.Branch( 'datamcScaleF', datamcScaleF, 'datamcScaleF/D' ) tree.Branch( 'datamcScaleFErrStat', datamcScaleFErrStat, 'datamcScaleFErrStat/D' ) tree.Branch( 'datamcScaleFErrSyst', datamcScaleFErrSyst, 'datamcScaleFErrSyst/D' ) tree.Branch( 'datamcVetoF', datamcVetoF, 'datamcVetoF/D' ) tree.Branch( 'datamcVetoFErrStat', datamcVetoFErrStat, 'datamcVetoFErrStat/D' ) tree.Branch( 'corrFactor', corrFactor, 'corrFactor/D' ) myChain = r.TChain('%s/RA2Values'%(options.treeName)) ################## if options.debug: if options.sample=="gjets": ##noht200## myChain.Add("/uscmst1b_scratch/lpc1/3DayLifetime/sturdy07/tmp/cmssw525p1/treeMaker/gjetsht200_reco_tree_ra2/res/*_?_?_???.root") myChain.Add("/uscmst1b_scratch/lpc1/3DayLifetime/sturdy07/tmp/cmssw525p1/treeMaker/gjetsht400_reco_tree_ra2/res/*_?_?_???.root") elif options.sample=="data": myChain.Add("/uscmst1b_scratch/lpc1/3DayLifetime/sturdy07/tmp/cmssw525p1/treeMaker/run2012a_tree_ra2/res/*_?_?_???.root") myChain.Add("/uscmst1b_scratch/lpc1/3DayLifetime/sturdy07/tmp/cmssw525p1/treeMaker/run2012b_tree_ra2/res/*_?_?_???.root") else: if options.sample=="gjets": ##noht200## myChain.Add("/uscmst1b_scratch/lpc1/3DayLifetime/sturdy07/tmp/cmssw525p1/treeMaker/gjetsht200_reco_tree_ra2/res/%s.root"%(subfiles[options.subsec])) myChain.Add("/uscmst1b_scratch/lpc1/3DayLifetime/sturdy07/tmp/cmssw525p1/treeMaker/gjetsht400_reco_tree_ra2/res/%s.root"%(subfiles[options.subsec])) elif options.sample=="data": myChain.Add("/uscmst1b_scratch/lpc1/3DayLifetime/sturdy07/tmp/cmssw525p1/treeMaker/run2012a_tree_ra2/res/%s.root"%(subfiles[options.subsec])) myChain.Add("/uscmst1b_scratch/lpc1/3DayLifetime/sturdy07/tmp/cmssw525p1/treeMaker/run2012b_tree_ra2/res/%s.root"%(subfiles[options.subsec])) fChain = myChain ###Timing information decade = 0 century = 0 tsw = r.TStopwatch() tenpcount = 1 onepcount = 1 nentries = fChain.GetEntries() print "nentries %d"%(nentries) sys.stdout.flush() i = 0 for event in fChain: # ==============print number of events done == == == == == == == = if ( i==0): tsw.Start() #print('.', end='') sys.stdout.write('.') sys.stdout.flush() if ((i*10)/nentries == tenpcount ) : tsw.Stop() time = tsw.RealTime() tsw.Start(r.kFALSE) finTime = 0. frac = (i*1.0)/(nentries*1.0) if (frac>0): finTime = time / frac - time finMin = finTime / 60. sys.stdout.write("%d%% done. "%(tenpcount*10)) # sys.stdout.write("t=7.2f"%(time)) sys.stdout.write("t="+str(time)) sys.stdout.write(" projected finish=%7d s("%(finTime)) sys.stdout.write("%2.2f min). "%(finMin)) sys.stdout.write("\n") sys.stdout.flush() tenpcount = tenpcount + 1 elif ( (i*100)/nentries == onepcount ) : #print('.', end='') sys.stdout.write('.') sys.stdout.flush() onepcount = onepcount + 1 nJetsHT[0] = event.ra2_nJetsPt50Eta25 nJetsMHT[0] = event.ra2_nJetsPt30Eta50 htVal[0] = event.ra2_HT mhtVal[0] = event.ra2_MHT dphi1[0] = event.ra2_dPhiMHT1 dphi2[0] = event.ra2_dPhiMHT2 dphi3[0] = event.ra2_dPhiMHT3 photonPt[0] = event.ra2_Photon1Pt photonEta[0] = event.ra2_Photon1Eta jet1Pt[0] = event.ra2_Jet1Pt jet1Eta[0] = event.ra2_Jet1Eta jet2Pt[0] = event.ra2_Jet2Pt jet2Eta[0] = event.ra2_Jet2Eta jet3Pt[0] = event.ra2_Jet3Pt jet3Eta[0] = event.ra2_Jet3Eta puWt[0] = event.ra2_PUWt eventWt[0] = event.ra2_EventWt ra2_Photon70PFHT400 = event.ra2_Photon70PFHT400 ra2_Photon70PFNoPUHT400 = event.ra2_Photon70PFNoPUHT400 triggers = (ra2_Photon70PFHT400 or ra2_Photon70PFNoPUHT400) if options.isMC: triggers = True if (triggers) and (cutF.ra2PhotonSelection(event,options.minpt, options.cutDR)) and cutF.ra2Baseline(event): pheno = corrs.pheno(nJetsHT[0],mhtVal[0]) phen[0] = pheno[0] phenErrStat[0] = pheno[1] result = corrs.acc(nJetsHT[0]) acc[0] = result[0] accErrStat[0] = result[1] result = corrs.acc(nJetsHT[0]) recoID[0] = result[0] recoIDErrStat[0] = result[1] result = corrs.acc(nJetsHT[0]) recoPFIso[0] = result[0] recoPFIsoErrStat[0] = result[1] purity[0] = 0.97 purityErr[0] = 0.01 result = corrs.datamcPhotonIDPFIsoScaleFactor(photonEta[0]) datamcScaleF[0] = result[0] datamcScaleFErrStat[0] = result[1] datamcScaleFErrSyst[0] = result[2] result = corrs.datamcElectronVetoScaleFactor(photonEta[0]) # print result datamcVetoF[0] = result[0] datamcVetoFErrStat[0] = result[1] corrFactor[0] = purity[0]*phen[0]/(acc[0]*recoID[0]*recoPFIso[0]*datamcScaleF[0]*datamcVetoF[0]) tree.Fill() ######### i = i + 1 #tree.Write() outFile.Write() outFile.Close()
def main() : ##parser = argparse.ArgumentParser(description="Switch for data/MC running") ##parser.add_argument('-m', action="store_true", dest="isMC", default=False) ##parser.add_argument('-d', action="store_true", dest="debug", default=False) ##results = parser.parse_args() parser = optparse.OptionParser(description="Switch for data/MC running") parser.add_option('-m', action="store_true", default=False, dest="isMC") parser.add_option('-d', action="store_true", default=False, dest="debug") options, args = parser.parse_args() r.gROOT.SetBatch(True) #debug = False #isMC = True myWorkingDir = os.getcwd() suffix = "data" if options.isMC: suffix = "mc" outFileName = "photonPlots_%s.root"%(suffix) if options.debug: outFileName = "photonPlots_%s_test.root"%(suffix) print "output file %s"%(outFileName) outputFile = r.TFile(outFileName,"RECREATE") myChain = r.TChain('analysisIDPFIso/RA2Values') if options.isMC: if options.debug: myChain.Add("/uscmst1b_scratch/lpc1/3DayLifetime/sturdy07/tmp/cmssw525p1/treeMaker/gjetsht200_reco_tree_topTagged_v3/res/*_?_?_???.root") myChain.Add("/uscmst1b_scratch/lpc1/3DayLifetime/sturdy07/tmp/cmssw525p1/treeMaker/gjetsht400_reco_tree_topTagged_v3/res/*_?_?_???.root") else: myChain.Add("/uscmst1b_scratch/lpc1/3DayLifetime/sturdy07/tmp/cmssw525p1/treeMaker/gjetsht200_reco_tree_topTagged_v3/res/*.root") myChain.Add("/uscmst1b_scratch/lpc1/3DayLifetime/sturdy07/tmp/cmssw525p1/treeMaker/gjetsht400_reco_tree_topTagged_v3/res/*.root") else: if options.debug: myChain.Add("/uscmst1b_scratch/lpc1/3DayLifetime/sturdy07/tmp/cmssw525p1/treeMaker/run2012a_tree_topTagged_v2/res/*_?_?_???.root") myChain.Add("/uscmst1b_scratch/lpc1/3DayLifetime/sturdy07/tmp/cmssw525p1/treeMaker/run2012b_tree_topTagged_v2/res/*_?_?_???.root") else: myChain.Add("/uscmst1b_scratch/lpc1/3DayLifetime/sturdy07/tmp/cmssw525p1/treeMaker/run2012a_tree_topTagged_v2/res/*.root") myChain.Add("/uscmst1b_scratch/lpc1/3DayLifetime/sturdy07/tmp/cmssw525p1/treeMaker/run2012b_tree_topTagged_v2/res/*.root") ###variables nVertices = r.TH1D("h_nVertices","h_nVertices",50, -0.5, 49.5) nJetsAll = r.TH1D("h_nJetsAll","h_nJetsAll",15, -0.5, 14.5) phot1Pt = r.TH1D("h_phot1Pt","h_phot1Pt",50, 0, 500) jet1Pt = r.TH1D("h_jet1Pt","h_jet1Pt",50, 0, 1000) jet2Pt = r.TH1D("h_jet2Pt","h_jet2Pt",50, 0, 500) jet3Pt = r.TH1D("h_jet3Pt","h_jet3Pt",50, 0, 500) jet4Pt = r.TH1D("h_jet4Pt","h_jet4Pt",50, 0, 500) ht = r.TH1D("h_ht","h_ht",30, 0, 3000) ht2 = r.TH1D("h_ht2","h_ht2",30, 0, 3000) ht3 = r.TH1D("h_ht3","h_ht3",30, 0, 3000) mht = r.TH1D("h_mht","h_mht",20, 0, 1000) mht2 = r.TH1D("h_mht2","h_mht2",20, 0, 1000) mht3 = r.TH1D("h_mht3","h_mht3",20, 0, 1000) dPhi1 = r.TH1D("h_dPhi1","h_dPhi1",50, 0, 3.2) dPhi2 = r.TH1D("h_dPhi2","h_dPhi2",50, 0, 3.2) dPhi3 = r.TH1D("h_dPhi3","h_dPhi3",50, 0, 3.2) nVerticesReWt = r.TH1D("h_nVerticesReWt","h_nVerticesReWt",50, -0.5, 49.5) nJetsAllPU = r.TH1D("h_nJetsAllPU","h_nJetsAllPU",15, -0.5, 14.5) phot1PtPU = r.TH1D("h_phot1PtPU","h_phot1PtPU",50, 0, 500) jet1PtPU = r.TH1D("h_jet1PtPU","h_jet1PtPU",100, 0, 100) jet2PtPU = r.TH1D("h_jet2PtPU","h_jet2PtPU",50, 0, 500) jet3PtPU = r.TH1D("h_jet3PtPU","h_jet3PtPU",50, 0, 500) jet4PtPU = r.TH1D("h_jet4PtPU","h_jet4PtPU",50, 0, 500) htPU = r.TH1D("h_htPU","h_htPU",30, 0, 3000) ht2PU = r.TH1D("h_ht2PU","h_ht2PU",30, 0, 3000) ht3PU = r.TH1D("h_ht3PU","h_ht3PU",30, 0, 3000) mhtPU = r.TH1D("h_mhtPU","h_mhtPU",20, 0, 1000) mht2PU = r.TH1D("h_mht2PU","h_mht2PU",20, 0, 1000) mht3PU = r.TH1D("h_mht3PU","h_mht3PU",20, 0, 1000) dPhi1PU = r.TH1D("h_dPhi1PU","h_dPhi1PU",50, 0, 3.2) dPhi2PU = r.TH1D("h_dPhi2PU","h_dPhi2PU",50, 0, 3.2) dPhi3PU = r.TH1D("h_dPhi3PU","h_dPhi3PU",50, 0, 3.2) nVertices .Sumw2() nJetsAll.Sumw2() phot1Pt.Sumw2() jet1Pt.Sumw2() jet2Pt.Sumw2() jet3Pt.Sumw2() jet4Pt.Sumw2() ht .Sumw2() ht2 .Sumw2() ht3 .Sumw2() mht .Sumw2() mht2 .Sumw2() mht3 .Sumw2() dPhi1.Sumw2() dPhi2.Sumw2() dPhi3.Sumw2() nVerticesReWt.Sumw2() nJetsAllPU.Sumw2() phot1PtPU.Sumw2() jet1PtPU.Sumw2() jet2PtPU.Sumw2() jet3PtPU.Sumw2() jet4PtPU.Sumw2() htPU .Sumw2() ht2PU .Sumw2() ht3PU .Sumw2() mhtPU .Sumw2() mht2PU .Sumw2() mht3PU .Sumw2() dPhi1PU.Sumw2() dPhi2PU.Sumw2() dPhi3PU.Sumw2() fChain = myChain ###Timing information decade = 0 century = 0 tsw = r.TStopwatch() tenpcount = 1 onepcount = 1 nentries = fChain.GetEntries() print "nentries %d"%(nentries) sys.stdout.flush() i = 0 #for i,event in enumerate(fChain): for event in fChain: # ==============print number of events done == == == == == == == = #double progress1 = 100.0 * jentry / (1.0 * nentries) #double progress10 = 10.0 * jentry / (1.0 * nentries) #int d = int (progress1) #int k = int (progress10) #if (d > century) # cout << "." #century = d #if (k > decade) # cout << 10 * k << " %" << endl #decade = k if ( i==0): tsw.Start() #print('.', end='') sys.stdout.write('.') sys.stdout.flush() if ((i*10)/nentries == tenpcount ) : tsw.Stop() time = tsw.RealTime() tsw.Start(r.kFALSE) finTime = 0. frac = (i*1.0)/(nentries*1.0) if (frac>0): finTime = time / frac - time finMin = finTime / 60. sys.stdout.write("%d%% done. "%(tenpcount*10)) #sys.stdout.write("t=7.2f"%(time)) sys.stdout.write("t="+str(time)) sys.stdout.write(" projected finish=%7d s("%(finTime)) sys.stdout.write("%2.2f min). "%(finMin)) sys.stdout.write("\n") sys.stdout.flush() tenpcount = tenpcount + 1 elif ( (i*100)/nentries == onepcount ) : #print('.', end='') sys.stdout.write('.') sys.stdout.flush() onepcount = onepcount + 1 #sys.stdout.flush() #print "PU_et %2.2f"%(event.ra2_PUWt) ra2_Vertices = event.ra2_Vertices ra2_nJetsPt50Eta25 = event.ra2_nJetsPt50Eta25 ra2_PUWt = event.ra2_PUWt ra2_EventWt = event.ra2_EventWt ra2_HT = event.ra2_HT ra2_MHT = event.ra2_MHT ra2_dPhi1 = event.ra2_dPhiMHT1 ra2_dPhi2 = event.ra2_dPhiMHT2 ra2_dPhi3 = event.ra2_dPhiMHT3 ra2_Jet1Pt = event.ra2_Jet1Pt ra2_Jet1Eta = event.ra2_Jet1Eta ra2_Jet2Pt = event.ra2_Jet2Pt ra2_Jet2Eta = event.ra2_Jet2Eta ra2_Jet3Pt = event.ra2_Jet3Pt ra2_Jet3Eta = event.ra2_Jet3Eta ra2_Jet4Pt = event.ra2_Jet4Pt ra2_Jet4Eta = event.ra2_Jet4Eta ra2_nPhotonsIso = event.ra2_nPhotonsIso ra2_Photon1Pt = event.ra2_Photon1Pt ra2_Photon70PFHT400 = event.ra2_Photon70PFHT400 ra2_Photon70PFNoPUHT400 = event.ra2_Photon70PFNoPUHT400 triggers = (ra2_Photon70PFHT400 or ra2_Photon70PFNoPUHT400) if options.isMC: triggers = True if (triggers) and (ra2_nPhotonsIso>0 and ra2_Photon1Pt>100) and cutF.ra2Baseline(event): ####Fill plots nVertices.Fill(ra2_Vertices,ra2_EventWt) nJetsAll.Fill(ra2_nJetsPt50Eta25,ra2_EventWt) phot1Pt.Fill(ra2_Photon1Pt,ra2_EventWt) jet1Pt.Fill(ra2_Jet1Pt,ra2_EventWt) jet2Pt.Fill(ra2_Jet2Pt,ra2_EventWt) jet3Pt.Fill(ra2_Jet3Pt,ra2_EventWt) jet4Pt.Fill(ra2_Jet4Pt,ra2_EventWt) ht .Fill(ra2_HT,ra2_EventWt) mht .Fill(ra2_MHT,ra2_EventWt) dPhi1.Fill(ra2_dPhi1,ra2_EventWt) dPhi2.Fill(ra2_dPhi2,ra2_EventWt) dPhi3.Fill(ra2_dPhi3,ra2_EventWt) nVerticesReWt.Fill(ra2_Vertices,ra2_EventWt*ra2_PUWt) nJetsAllPU.Fill(ra2_nJetsPt50Eta25,ra2_EventWt*ra2_PUWt) phot1PtPU.Fill(ra2_Photon1Pt,ra2_EventWt*ra2_PUWt) jet1PtPU.Fill(ra2_Jet1Pt,ra2_EventWt*ra2_PUWt) jet2PtPU.Fill(ra2_Jet2Pt,ra2_EventWt*ra2_PUWt) jet3PtPU.Fill(ra2_Jet3Pt,ra2_EventWt*ra2_PUWt) jet4PtPU.Fill(ra2_Jet4Pt,ra2_EventWt*ra2_PUWt) htPU .Fill(ra2_HT,ra2_EventWt*ra2_PUWt) mhtPU .Fill(ra2_MHT,ra2_EventWt*ra2_PUWt) dPhi1PU.Fill(ra2_dPhi1,ra2_EventWt*ra2_PUWt) dPhi2PU.Fill(ra2_dPhi2,ra2_EventWt*ra2_PUWt) dPhi3PU.Fill(ra2_dPhi3,ra2_EventWt*ra2_PUWt) if ra2_nJetsPt50Eta25 == 2: ht2 .Fill(ra2_HT,ra2_EventWt) mht2 .Fill(ra2_MHT,ra2_EventWt) ht2PU .Fill(ra2_HT,ra2_EventWt*ra2_PUWt) mht2PU.Fill(ra2_MHT,ra2_EventWt*ra2_PUWt) if ra2_nJetsPt50Eta25 > 2: ht3 .Fill(ra2_HT,ra2_EventWt) mht3 .Fill(ra2_MHT,ra2_EventWt) ht3PU .Fill(ra2_HT,ra2_EventWt*ra2_PUWt) mht3PU.Fill(ra2_MHT,ra2_EventWt*ra2_PUWt) ######### i = i + 1 ##### outputFile.cd() nVertices .Write() nJetsAll.Write() phot1Pt.Write() jet1Pt.Write() jet2Pt.Write() jet3Pt.Write() jet4Pt.Write() ht .Write() ht2 .Write() ht3 .Write() mht .Write() mht2 .Write() mht3 .Write() dPhi1.Write() dPhi2.Write() dPhi3.Write() nVerticesReWt.Write() nJetsAllPU.Write() phot1PtPU.Write() jet1PtPU.Write() jet2PtPU.Write() jet3PtPU.Write() jet4PtPU.Write() htPU .Write() ht2PU .Write() ht3PU .Write() mhtPU .Write() mht2PU .Write() mht3PU .Write() dPhi1PU.Write() dPhi2PU.Write() dPhi3PU.Write() outputFile.Write() outputFile.Close()