Best Python code snippet using tox_python
process_base.py
Source:process_base.py
...171 if deltaR < jet_user_info.closest_jet_deltaR:172 jet_user_info.closest_jet = jet_match173 jet_user_info.closest_jet_deltaR = deltaR174 175 jet.set_python_info(jet_user_info)176 #---------------------------------------------------------------177 # Set accepted jet matches for pp case178 #179 # hname is the name of a matching QA histogram that will be created180 # it can be anything you want, e.g. 'hJetMatchingQA_R{}'.format(jetR)181 #---------------------------------------------------------------182 def set_matches_pp(self, jet_det, hname):183 # Create pp matching QA histogram, if not already created184 if hname and not hasattr(self, hname):185 bin_labels = ['all', 'has_matching_candidate', 'unique_match']186 nbins = len(bin_labels)187 h = ROOT.TH2F(hname, hname, nbins, 0, nbins, 30, 0., 300.)188 for i in range(1, nbins+1):189 h.GetXaxis().SetBinLabel(i,bin_labels[i-1])190 setattr(self, hname, h)191 192 if hname:193 h = getattr(self, hname)194 h.Fill('all', jet_det.pt(), 1)195 196 if jet_det.has_user_info():197 198 jet_info_det = jet_det.python_info()199 if hname:200 h.Fill('has_matching_candidate', jet_det.pt(), 1)201 202 if len(jet_info_det.matching_candidates) == 1:203 jet_truth = jet_info_det.closest_jet204 205 # Check that the match is unique206 if jet_truth.has_user_info():207 jet_info_truth = jet_truth.python_info()208 if len(jet_info_truth.matching_candidates) == 1:209 210 # Set accepted match211 jet_info_det.match = jet_truth212 jet_det.set_python_info(jet_info_det)213 if hname:214 h.Fill('unique_match', jet_det.pt(), 1)215 #---------------------------------------------------------------216 # Set accepted jet matches for Pb-Pb case217 #218 # hname is the name of a matching QA histogram that will be created219 # it can be anything you want, e.g. 'hJetMatchingQA_R{}'.format(jetR)220 #---------------------------------------------------------------221 def set_matches_AA(self, jet_det_combined, jetR, hname):222 223 set_match = False224 225 # Create Pb-Pb matching QA histogram, if not already created226 if not hasattr(self, hname):227 bin_labels = ['all', 'has_matching_ppdet_candidate', 'has_matching_pptrue_candidate', 'has_matching_pptrue_unique_candidate', 'mc_fraction', 'deltaR_combined-truth', 'passed_all_cuts']228 nbins = len(bin_labels)229 h = ROOT.TH2F(hname, hname, nbins, 0, nbins, 30, 0., 300.)230 for i in range(1, nbins+1):231 h.GetXaxis().SetBinLabel(i,bin_labels[i-1])232 setattr(self, hname, h)233 234 h = getattr(self, hname)235 h.Fill('all', jet_det_combined.pt(), 1)236 # Check if combined jet has a pp-det match (uniqueness not currently enforced)237 if jet_det_combined.has_user_info():238 239 h.Fill('has_matching_ppdet_candidate', jet_det_combined.pt(), 1)240 jet_info_combined = jet_det_combined.python_info()241 jet_pp_det = jet_info_combined.closest_jet242 243 # Check if the pp-det jet has a pp-truth match244 if jet_pp_det.has_user_info():245 246 jet_info_pp_det = jet_pp_det.python_info()247 jet_pp_truth = jet_info_pp_det.closest_jet248 h.Fill('has_matching_pptrue_candidate', jet_det_combined.pt(), 1)249 set_match = True250 251 # Check that pp-det to pp-true match is unique252 if self.is_match_unique(jet_pp_det):253 h.Fill('has_matching_pptrue_unique_candidate', jet_det_combined.pt(), 1)254 else:255 set_match = False256 257 # Check matching distance between combined jet and pp-truth258 if jet_det_combined.delta_R(jet_pp_truth) < self.jet_matching_distance*jetR:259 h.Fill('deltaR_combined-truth', jet_det_combined.pt(), 1)260 else:261 set_match = False262 263 # Check if >50% of the pp-det tracks are in the Pb-Pb det jet264 mc_fraction = self.mc_fraction(jet_pp_det, jet_det_combined)265 if mc_fraction > self.mc_fraction_threshold:266 h.Fill('mc_fraction', jet_det_combined.pt(), 1)267 else:268 set_match = False269 270 # Set accepted match271 if set_match:272 jet_info_combined.match = jet_pp_truth273 jet_det_combined.set_python_info(jet_info_combined)274 275 # Set also the pp-truth match info, since we will need to access the matching pp-det jet for prong matching276 jet_info_pp_truth = jet_pp_truth.python_info()277 jet_info_pp_truth.match = jet_pp_det278 jet_pp_truth.set_python_info(jet_info_pp_truth)279 280 h.Fill('passed_all_cuts', jet_det_combined.pt(), 1)281 #---------------------------------------------------------------282 # Set accepted jet matches for truth+background (i.e. no det-level)283 #284 # hname is the name of a matching QA histogram that will be created285 # it can be anything you want, e.g. 'hJetMatchingQA_R{}'.format(jetR)286 #---------------------------------------------------------------287 def set_matches_AA_truth(self, jet_combined, jetR, hname):288 289 set_match = False290 291 # Create Pb-Pb matching QA histogram, if not already created292 if not hasattr(self, hname):293 bin_labels = ['all', 'has_matching_candidate', 'has_matching_unique_candidate', 'mc_fraction', 'deltaR_combined-truth', 'passed_all_cuts']294 nbins = len(bin_labels)295 h = ROOT.TH2F(hname, hname, nbins, 0, nbins, 30, 0., 300.)296 for i in range(1, nbins+1):297 h.GetXaxis().SetBinLabel(i,bin_labels[i-1])298 setattr(self, hname, h)299 300 h = getattr(self, hname)301 h.Fill('all', jet_combined.pt(), 1)302 # Check if combined jet has a pp-det match (uniqueness not currently enforced)303 if jet_combined.has_user_info():304 305 h.Fill('has_matching_candidate', jet_combined.pt(), 1)306 jet_info_combined = jet_combined.python_info()307 jet_truth = jet_info_combined.closest_jet308 set_match = True309 310 # Check that match is unique311 if self.is_match_unique(jet_truth):312 h.Fill('has_matching_unique_candidate', jet_combined.pt(), 1)313 else:314 set_match = False315 316 # Check matching distance between combined jet and pp-truth317 if jet_combined.delta_R(jet_truth) < self.jet_matching_distance*jetR:318 h.Fill('deltaR_combined-truth', jet_combined.pt(), 1)319 else:320 set_match = False321 # Check if >50% of the pp-truth tracks are in the combined jet322 mc_fraction = self.mc_fraction(jet_truth, jet_combined)323 if mc_fraction > self.mc_fraction_threshold:324 h.Fill('mc_fraction', jet_combined.pt(), 1)325 else:326 set_match = False327 328 # Set accepted match329 if set_match:330 jet_info_combined.match = jet_truth331 jet_combined.set_python_info(jet_info_combined)332 h.Fill('passed_all_cuts', jet_combined.pt(), 1)333 #---------------------------------------------------------------334 # Return pt-fraction of tracks in jet_pp_det that are contained in jet_det_combined335 #---------------------------------------------------------------336 def mc_fraction(self, jet_pp_det, jet_det_combined):337 338 pt_total = jet_pp_det.pt()339 340 pt_contained = 0.341 for track in jet_det_combined.constituents():342 if track.user_index() >= 0:343 pt_contained += track.pt()344 345 return pt_contained/pt_total...
env.py
Source:env.py
...107 data["bazel"]["env.USE_BAZEL_VERSION"] = os.environ.get("USE_BAZEL_VERSION", "N/A")108 self._try_collect(collector=BazelInfoCollector(),109 action=set_bazel_info,110 not_found_message="'bazel' not installed")111 def set_python_info(python_info):112 data["python"]["path"] = str(python_info.path)113 data["python"]["version"] = str(python_info.version)114 self._try_collect(collector=PythonInfoCollector(),115 action=set_python_info,116 not_found_message="'python' not installed")117 return Snapshot(data)118 def _try_collect(self, collector, action, not_found_message="No data collected"):119 try:120 result = collector.collect(self.ctx)121 if result is not None:122 action(result)123 else:124 self.ctx.logger.warn(not_found_message)125 except Exception as err:...
Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!