@@ -124,19 +124,7 @@ def _calculate_variables(self, df, verify=False): # pylint: disable=invalid-name
124124 self .logger .info ('calculating variables' )
125125 if len (df ) == 0 :
126126 return df
127- df ['dr' ] = np .sqrt ((df .fJetEta - df .fEta )** 2 + ((df .fJetPhi - df .fPhi + math .pi ) % math .tau - math .pi )** 2 )
128- df ['jetPx' ] = df .fJetPt * np .cos (df .fJetPhi )
129- df ['jetPy' ] = df .fJetPt * np .sin (df .fJetPhi )
130- df ['jetPz' ] = df .fJetPt * np .sinh (df .fJetEta )
131- df ['hfPx' ] = df .fPt * np .cos (df .fPhi )
132- df ['hfPy' ] = df .fPt * np .sin (df .fPhi )
133- df ['hfPz' ] = df .fPt * np .sinh (df .fEta )
134- df ['zpar_num' ] = df .jetPx * df .hfPx + df .jetPy * df .hfPy + df .jetPz * df .hfPz
135- df ['zpar_den' ] = df .jetPx * df .jetPx + df .jetPy * df .jetPy + df .jetPz * df .jetPz
136- df ['zpar' ] = df .zpar_num / df .zpar_den
137- df [df ['zpar' ] >= 1. ]['zpar' ] = .999 # move 1 to last bin
138127 df ['nsub21' ] = df .fNSub2 / df .fNSub1
139-
140128 self .logger .debug ('zg' )
141129 df ['zg_array' ] = np .array (.5 - abs (df .fPtSubLeading / (df .fPtLeading + df .fPtSubLeading ) - .5 ))
142130 zcut = self .cfg ('zcut' , .1 )
@@ -150,6 +138,20 @@ def _calculate_variables(self, df, verify=False): # pylint: disable=invalid-name
150138 (lambda ar : np .log (ar .fPtSubLeading * np .sin (ar .fTheta ))), axis = 1 )
151139 df ['lntheta' ] = df ['fTheta' ].apply (lambda x : - np .log (x ))
152140 # df['lntheta'] = np.array(-np.log(df.fTheta))
141+
142+ if self .cfg ('hfjet' , True ):
143+ df ['dr' ] = np .sqrt ((df .fJetEta - df .fEta )** 2 + ((df .fJetPhi - df .fPhi + math .pi ) % math .tau - math .pi )** 2 )
144+ df ['jetPx' ] = df .fJetPt * np .cos (df .fJetPhi )
145+ df ['jetPy' ] = df .fJetPt * np .sin (df .fJetPhi )
146+ df ['jetPz' ] = df .fJetPt * np .sinh (df .fJetEta )
147+ df ['hfPx' ] = df .fPt * np .cos (df .fPhi )
148+ df ['hfPy' ] = df .fPt * np .sin (df .fPhi )
149+ df ['hfPz' ] = df .fPt * np .sinh (df .fEta )
150+ df ['zpar_num' ] = df .jetPx * df .hfPx + df .jetPy * df .hfPy + df .jetPz * df .hfPz
151+ df ['zpar_den' ] = df .jetPx * df .jetPx + df .jetPy * df .jetPy + df .jetPz * df .jetPz
152+ df ['zpar' ] = df .zpar_num / df .zpar_den
153+ df [df ['zpar' ] >= 1. ]['zpar' ] = .999 # move 1 to last bin
154+
153155 self .logger .debug ('done' )
154156 if verify :
155157 self ._verify_variables (df )
@@ -172,18 +174,20 @@ def process_histomass_single(self, index):
172174 dfevtorig = read_df (self .l_evtorig [index ])
173175 histonorm = TH1F ("histonorm" , "histonorm" , 4 , 0 , 4 )
174176 histonorm .SetBinContent (1 , len (dfquery (dfevtorig , self .s_evtsel )))
175- dfcollcnt = read_df (self .l_collcnt [index ])
176- ser_collcnt = dfcollcnt [self .cfg (f'counter_read_{ self .mcordata } ' )]
177- collcnt_read = functools .reduce (lambda x ,y : float (x )+ float (y ), (ar [0 ] for ar in ser_collcnt ))
178- ser_collcnt = dfcollcnt [self .cfg ('counter_tvx' )]
179- collcnt_tvx = functools .reduce (lambda x ,y : float (x )+ float (y ), (ar [0 ] for ar in ser_collcnt ))
180- dfbccnt = read_df (self .l_bccnt [index ])
181- ser_bccnt = dfbccnt [self .cfg ('counter_tvx' )]
182- bccnt_tvx = functools .reduce (lambda x ,y : float (x )+ float (y ), (ar [0 ] for ar in ser_bccnt ))
183- self .logger .info ('sampled %g collisions' , collcnt_read )
184- histonorm .SetBinContent (2 , collcnt_read )
185- histonorm .SetBinContent (3 , collcnt_tvx )
186- histonorm .SetBinContent (4 , bccnt_tvx )
177+ if self .l_collcnt :
178+ dfcollcnt = read_df (self .l_collcnt [index ])
179+ ser_collcnt = dfcollcnt [self .cfg (f'counter_read_{ self .mcordata } ' )]
180+ collcnt_read = functools .reduce (lambda x ,y : float (x )+ float (y ), (ar [0 ] for ar in ser_collcnt ))
181+ self .logger .info ('sampled %g collisions' , collcnt_read )
182+ histonorm .SetBinContent (2 , collcnt_read )
183+ ser_collcnt = dfcollcnt [self .cfg ('counter_tvx' )]
184+ collcnt_tvx = functools .reduce (lambda x ,y : float (x )+ float (y ), (ar [0 ] for ar in ser_collcnt ))
185+ histonorm .SetBinContent (3 , collcnt_tvx )
186+ if self .l_bccnt :
187+ dfbccnt = read_df (self .l_bccnt [index ])
188+ ser_bccnt = dfbccnt [self .cfg ('counter_tvx' )]
189+ bccnt_tvx = functools .reduce (lambda x ,y : float (x )+ float (y ), (ar [0 ] for ar in ser_bccnt ))
190+ histonorm .SetBinContent (4 , bccnt_tvx )
187191 get_axis (histonorm , 0 ).SetBinLabel (1 , 'N_{evt}' )
188192 get_axis (histonorm , 0 ).SetBinLabel (2 , 'N_{coll}' )
189193 get_axis (histonorm , 0 ).SetBinLabel (3 , 'N_{coll}^{TVX}' )
@@ -314,23 +318,26 @@ def process_efficiency_single(self, index):
314318 hist .SetName (hist .GetName () + '_frac' )
315319
316320 with TFile .Open (self .l_histoeff [index ], "recreate" ) as rfile :
317- # TODO: avoid hard-coding values here (check if restriction is needed at all)
318- cols = ['ismcprompt' , 'ismcsignal' , 'ismcfd' , 'fPt' , 'fEta' , 'fPhi' , 'fJetPt' , 'fJetEta' , 'fJetPhi' ,
319- 'fPtLeading' , 'fPtSubLeading' , 'fTheta' , 'fNSub2DR' , 'fNSub1' , 'fNSub2' ]
321+ # # TODO: avoid hard-coding values here (check if restriction is needed at all)
322+ # cols = ['ismcprompt', 'ismcsignal', 'ismcfd', 'fPt', 'fEta', 'fPhi', 'fJetPt', 'fJetEta', 'fJetPhi',
323+ # 'fPtLeading', 'fPtSubLeading', 'fTheta', 'fNSub2DR', 'fNSub1', 'fNSub2']
320324
321325 # read generator level
322- dfgen_orig = pd .concat (read_df (self .mptfiles_gensk [bin ][index ], columns = cols )
326+ dfgen_orig = pd .concat (read_df (self .mptfiles_gensk [bin ][index ])
323327 for bin in self .active_bins_skim )
324328 df = self ._calculate_variables (dfgen_orig )
325329 df = df .rename (lambda name : name + '_gen' , axis = 1 )
326- dfgen = {'pr' : df .loc [(df .ismcsignal_gen == 1 ) & (df .ismcprompt_gen == 1 )],
327- 'np' : df .loc [(df .ismcsignal_gen == 1 ) & (df .ismcfd_gen == 1 )]}
330+ if self .cfg ('hfjet' , True ):
331+ dfgen = {'pr' : df .loc [(df .ismcsignal_gen == 1 ) & (df .ismcprompt_gen == 1 )],
332+ 'np' : df .loc [(df .ismcsignal_gen == 1 ) & (df .ismcfd_gen == 1 )]}
333+ else :
334+ dfgen = {'pr' : df , 'np' : df }
328335
329336 # read detector level
330- cols .extend (self .cfg ('efficiency.extra_cols' , []))
331- if idx := self .cfg ('efficiency.index_match' ):
332- cols .append (idx )
333- df = pd .concat (read_df (self .mptfiles_recosk [bin ][index ], columns = cols )
337+ # cols.extend(self.cfg('efficiency.extra_cols', []))
338+ # if idx := self.cfg('efficiency.index_match'):
339+ # cols.append(idx)
340+ df = pd .concat (read_df (self .mptfiles_recosk [bin ][index ])
334341 for bin in self .active_bins_skim )
335342
336343 # Custom skimming cuts
@@ -342,8 +349,11 @@ def process_efficiency_single(self, index):
342349 else :
343350 self .logger .warning ('No matching criterion specified, cannot match det and gen' )
344351 df = self ._calculate_variables (df )
345- dfdet = {'pr' : df .loc [(df .ismcsignal == 1 ) & (df .ismcprompt == 1 )],
346- 'np' : df .loc [(df .ismcsignal == 1 ) & (df .ismcfd == 1 )]}
352+ if self .cfg ('hfjet' , True ):
353+ dfdet = {'pr' : df .loc [(df .ismcsignal == 1 ) & (df .ismcprompt == 1 )],
354+ 'np' : df .loc [(df .ismcsignal == 1 ) & (df .ismcfd == 1 )]}
355+ else :
356+ dfdet = {'pr' : df , 'np' : df }
347357
348358 dfmatch = {cat : pd .merge (dfdet [cat ], dfgen [cat ], left_on = ['df' , 'idx_match' ], right_index = True )
349359 for cat in cats if 'idx_match' in dfdet [cat ]}
0 commit comments