def process(self): histos = self.histograms preselection = self.preselection fill_histos = self.fill_histos event_weight = self.event_weight channel = self.channel # if len(self.objects) == 4: # Find the right version of each event to deal with combinatorics issues zmass = 91.1876 for row in self.tree : ossfs = selections.getOSSF(row,channel,*self.objects) if len(ossfs) == 4 : allGood = True for lep in ossfs: allGood = allGood and selections.objSelection(row, lep) if allGood: mz1 = getattr(row, getVar2(ossfs[0], ossfs[1], 'Mass')) ptSum = getattr(row, getVar(ossfs[2], 'Pt')) + getattr(row,getVar(ossfs[3], 'Pt')) evNum = getattr(row, 'evt') if evNum not in self.comboMap or \ abs(zmass - self.comboMap[evNum][0]) > abs(zmass - mz1) or \ abs(zmass - self.comboMap[evNum][0]) == abs(zmass - mz1) and ptSum > self.comboMap[evNum][1]: self.comboMap[evNum] = (mz1, ptSum) self.cut_flow_init() usedEvents = self.jsonToDict() counter = 0 for row in self.tree: if self.cutmap["Initial"] % 5000 == 0: print("Processing record " + str(self.cutmap["Initial"])) self.cutmap["Initial"] += 1 event = row.evt lumi = row.lumi run = row.run eventkey = [run, lumi, event] counter += 1 self.ossf = selections.numberOSSF(row,channel) self.onZ = selections.numberOnZ(row,channel) self.objectmap = self.getObjectMap(row) for key, selection in self.build_zz_folder_structure().iteritems(): # fill all events if key == "signal": if preselection(row,"Signal"): # check if we already used this event if eventkey in usedEvents["Signal"]["Preselection"]: continue self.cutmap["Signal"]["Preselection"]["Events"] += 1 fill_histos(histos, selection, row, event_weight(row)) # mark event as used usedEvents["Signal"]["Preselection"].append(eventkey) ossfs = selections.getOSSF(row,channel,*self.objects) # If this event should be in my skim of the official Higgs events, store it for later printing m4l = getattr(row, 'Mass') mz1 = getattr(row, getVar2(ossfs[0], ossfs[1], 'Mass')) mz2 = getattr(row, getVar2(ossfs[2], ossfs[3], 'Mass')) if m4l > 100 and m4l < 1000 and mz1 > 60 and mz1 < 120 and mz2 > 60 and mz2 < 120: pt4l = 0 for lept in self.objects: pt4l += getattr(row, getVar(lept, 'Pt')) self.hzz_passed.append([('event', getattr(row,'evt')), ('m4l', m4l), ('mz1', mz1), ('mz2', mz2), ('pt4l', pt4l)]) continue # fill controls foundControl = 0 for control in self.controls: if key == control: if preselection(row,key): # check if we already used this event if eventkey in usedEvents["Control"][control]: continue self.cutmap["Control"][key]["Events"] += 1 fill_histos(histos, selection, row, event_weight(row)) # add to list of used events usedEvents["Control"][control].append(eventkey) foundControl = 1 if foundControl: continue # select appropriate regions # ossf = key[0] # onZ = key[1] # if selections.numberOSSF(row,channel)!=int(ossf): continue # if selections.numberOnZ(row,channel)!=int(onZ): continue fill_histos(histos, selection, row, event_weight(row)) self.dictToJson(usedEvents) self.output_cut_flow()
def __init__(self, tree, outfile, wrapper, channel, **kwargs): super(ZZAnalyzerBase, self).__init__(tree, outfile, **kwargs) # Cython wrapper class must be passed self.tree = wrapper(tree) self.hzz_passfile = 'HZZ_passed.txt' self.hzz_passed = [] self.out = outfile self.jobid = os.environ['jobid'] self.is7TeV = bool('7TeV' in self.jobid) self.histograms = {} self.channel = channel self.comboMap = {} # a dictionary to keep track of events that have been used # format: self.combinatorics[EventNumber]=(Z1 mass of best found so far, Z2 pt sum of best found so far) self.jsonfile = self.getJsonFileName() self.hfunc = { #maps the name of non-trivial histograms to a function to get the proper value, the function MUST have two args (evt and weight). Used in fill_histos later 'nTruePU' : lambda row, weight: (row.nTruePU,None), 'weight' : lambda row, weight: (weight,None) if weight is not None else (1.,None), 'Event_ID': lambda row, weight: (array.array("f", [row.run,row.lumi,int(row.evt)/10**5,int(row.evt)%10**5] ), None), } self.hfunc['Z1Mass'] = lambda row, weight: self.objectmap['Z1']['mass'] self.hfunc['Z1Pt'] = lambda row, weight: self.objectmap['Z1']['pt'] self.hfunc['Z1Eta'] = lambda row, weight: self.objectmap['Z1']['eta'] self.hfunc['Z1Phi'] = lambda row, weight: self.objectmap['Z1']['phi'] self.hfunc['Z2Mass'] = lambda row, weight: self.objectmap['Z2']['mass'] self.hfunc['Z2Pt'] = lambda row, weight: self.objectmap['Z2']['pt'] self.hfunc['Z2Eta'] = lambda row, weight: self.objectmap['Z2']['eta'] self.hfunc['Z2Phi'] = lambda row, weight: self.objectmap['Z2']['phi'] # self.hfunc['j1_Z1_dPhi'] = lambda row, weight: row.j1Phi-self.objectmap['Z1']['phi'] # self.hfunc['j1_Z2_dPhi'] = lambda row, weight: row.j1Phi-self.objectmap['Z2']['phi'] # self.hfunc['j2_Z1_dPhi'] = lambda row, weight: row.j2Phi-self.objectmap['Z1']['phi'] # self.hfunc['j2_Z2_dPhi'] = lambda row, weight: row.j2Phi-self.objectmap['Z2']['phi'] # self.hfunc['j1_Z1_Mass'] = lambda row, weight: self.getInvariant(row,'j1','Z1')['mass'] # self.hfunc['j1_Z2_Mass'] = lambda row, weight: self.getInvariant(row,'j1','Z2')['mass'] # self.hfunc['j2_Z1_Mass'] = lambda row, weight: self.getInvariant(row,'j2','Z1')['mass'] # self.hfunc['j2_Z2_Mass'] = lambda row, weight: self.getInvariant(row,'j2','Z2')['mass'] self.hfunc['Z1_Z2_Mass'] = lambda row, weight: self.getInvariant(row,'Z1','Z2')['mass'] # self.hfunc['numberOSSF'] = lambda row, weight: selections.numberOSSF(row,channel) self.hfunc['numberOnZ'] = lambda row, weight: selections.numberOnZ(row,channel) # self.hfunc['numberBjet'] = lambda row, weight: selections.numberBjet(row) self.hfunc['numJets'] = lambda row, weight: row.jetVeto30 # self.hfunc['numBJets'] = lambda row, weight: row.bjetCSVVeto30 self.hfunc['Z1_Z2_Scatter'] = lambda row, weight: (self.objectmap['Z1']['mass'], self.objectmap['Z2']['mass']) # self.objects = [] self.passList = [2226124,\ 2780787,\ 3634214,\ 5379966,\ 9172701,\ 18955331,\ 26763019,\ 30975991,\ 32432249,\ 36559877,\ 37061827,\ 37968037,\ 38166085,\ 38426260,\ 41527702,\ 41830321,\ 43697222,\ 48304581,\ 49951784,\ 53125147,\ 53211301,\ 55134076,\ 58141565,\ 59123305,\ 67672479,\ 67917612,\ 70540430,\ 73285337,\ 76117998,\ 76732703,\ 78300349,\ 79591576,\ 80529749,\ 80889207,\ 82625945,\ 84544694,\ 85848214,\ 88111521,\ 93268337,\ 93572313,\ 95922345,\ 98100215,\ 103675675,\ 105011803,\ 107217493,\ 109881951,\ 112990898,\ 114003150,\ 114371709,\ 114538016,\ 115301904,\ 116169718,\ 117459264,\ 120536614,\ 121019123,\ 123988832,\ 128008670,\ 132410624,\ 132706940,\ 133641846,\ 134355928,\ 138519342,\ 139537140,\ 140486819,\ 141178966,\ 146471772,\ 147388276,\ 151083216,\ 152805866,\ 155730849,\ 155753218,\ 159726794,\ 167209826,\ 168130224,\ 168194676,\ 169100521,\ 174781164,\ 174957822,\ 176859852,\ 177095997,\ 177815904,\ 178044443,\ 178829388,\ 185135060,\ 190051995,\ 191382222,\ 194675981,\ 194955393,\ 196674650,\ 199183870,\ 201387532,\ 215099909,\ 217502611,\ 221918655,\ 225565614,\ 231762704,\ 232018566,\ 232250171,\ 233725391,\ 234207734,\ 235647099,\ 243501633,\ 244623214,\ 244791672,\ 245339434,\ 247836553,\ 252537006,\ 259508756,\ 263194986,\ 276785714,\ 279759749,\ 290344628,\ 291820678,\ 293533566,\ 295324467,\ 301478208,\ 306664497,\ 306811048,\ 309219190,\ 312032921,\ 318322030,\ 319813054,\ 322510503,\ 323790844,\ 327118504,\ 330091192,\ 331257910,\ 331969560,\ 333246186,\ 335391276,\ 338722570,\ 340486709,\ 340900299,\ 345644314,\ 346074761,\ 350555096,\ 352383455,\ 353162207,\ 356427819,\ 356725032,\ 359837986,\ 363484809,\ 363949741,\ 368602597,\ 372667387,\ 372893489,\ 384016969,\ 388474764,\ 389766970,\ 389977932,\ 393582426,\ 394007716,\ 395759900,\ 396825385,\ 400957190,\ 401042600,\ 401484983,\ 402443918,\ 402600389,\ 402678830,\ 407076966,\ 412076062,\ 415865014,\ 420041037,\ 426559109,\ 440202539,\ 446438292,\ 448152127,\ 450362044,\ 455057868,\ 469467267,\ 472815275,\ 477289466,\ 477862388,\ 481791479,\ 483168057,\ 487671954,\ 502821363,\ 504370493,\ 513078030,\ 519019963,\ 519488427,\ 520953305,\ 530312812,\ 539665282,\ 546604424,\ 547514345,\ 553270298,\ 559670208,\ 563981267,\ 565245444,\ 567117841,\ 573405437,\ 575302642,\ 599229718,\ 607057396,\ 609157237,\ 616574429,\ 617265349,\ 617795227,\ 622426000,\ 626206528,\ 630169854,\ 630809308,\ 630954116,\ 637834076,\ 646351604,\ 660605607,\ 673638714,\ 685265684,\ 687711552,\ 703712657,\ 708573825,\ 714036395,\ 719208626,\ 723782287,\ 739864564,\ 742912724,\ 758109065,\ 760006400,\ 769186804,\ 770334833,\ 779714361,\ 792210029,\ 793110394,\ 794370838,\ 802036099,\ 809605982,\ 813802208,\ 818802354,\ 836690441,\ 845122892,\ 854616700,\ 863682922,\ 865434697,\ 865695065,\ 873005082,\ 873201612,\ 876208309,\ 883384151,\ 933835054,\ 947734353,\ 955425019,\ 963906726,\ 970333313,\ 970724930,\ 971857351,\ 979037526,\ 990710339,\ 991082101,\ 1003127634,\ 1021783875,\ 1022410825,\ 1023081043,\ 1023292406,\ 1037471026,\ 1053831791,\ 1066576272,\ 1069824602,\ 1072952721,\ 1087639087,\ 1089558842,\ 1097456291,\ 1103535297,\ 1134909166,\ 1154853710,\ 1181788896,\ 1210674923,\ 1233293430,\ 1238510739,\ 1248257881,\ 1259337833,\ 1269360116,\ 1278946974,\ 1294338754,\ 1315227994,\ 1344760175,\ 1347277781,\ 1394353502,\ 1409704558,\ 1464344864,\ 1511453808,\ 1530537922,\ 1580150704,\ 1621079578,\ 1730707882,\ 1745216870,\ 1820521419,\ 2073195431] self.passDict = {} self.HZZPassFile = 'HZZ_all_official.txt'