Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
vo005_Combinations.py File Reference

Detailed Description

View in nbviewer Open in SWAN
In this tutorial we learn how combinations of RVecs can be built.

import ROOT
from ROOT.VecOps import Take, Combinations
# RVec can be sorted in Python with the inbuilt sorting function because
# PyROOT implements a Python iterator
v1 = ROOT.RVecD(3)
v1[0], v1[1], v1[2] = 1, 2, 3
v2 = ROOT.RVecD(2)
v2[0], v2[1] = -4, -5
# To get the indices, which result in all combinations, you can call the
# following helper.
# Note that you can also pass the size of the vectors directly.
idx = Combinations(v1, v2)
# Next, the respective elements can be taken via the computed indices.
c1 = Take(v1, idx[0])
c2 = Take(v2, idx[1])
# Finally, you can perform any set of operations conveniently.
v3 = c1 * c2
print("Combinations of {} and {}:".format(v1, v2))
for i in range(len(v3)):
print("{} * {} = {}".format(c1[i], c2[i], v3[i]))
print
# However, if you want to compute operations on unique combinations of a
# single RVec, you can perform this as follows.
# Get the indices of unique triples for the given vector.
v4 = ROOT.RVecD(4)
v4[0], v4[1], v4[2], v4[3] = 1, 2, 3, 4
idx2 = Combinations(v4, 3)
# Take the elements and compute any operation on the returned collections.
c3 = Take(v4, idx2[0])
c4 = Take(v4, idx2[1])
c5 = Take(v4, idx2[2])
v5 = c3 * c4 * c5
print("Unique triples of {}:".format(v4))
for i in range(len(v5)):
print("{} * {} * {} = {}".format(c3[i], c4[i], c5[i], v5[i]))
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t WindowAttributes_t Float_t Float_t Float_t Int_t Int_t UInt_t UInt_t Rectangle_t Int_t Int_t Window_t TString Int_t GCValues_t GetPrimarySelectionOwner GetDisplay GetScreen GetColormap GetNativeEvent const char const char dpyName wid window const char font_name cursor keysym reg const char only_if_exist regb h Point_t winding char text const char depth char const char Int_t count const char ColorStruct_t color const char Pixmap_t Pixmap_t PictureAttributes_t attr const char char ret_data h unsigned char height h Atom_t Int_t ULong_t ULong_t unsigned char prop_list Atom_t Atom_t Atom_t Time_t UChar_t len
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t WindowAttributes_t Float_t Float_t Float_t Int_t Int_t UInt_t UInt_t Rectangle_t Int_t Int_t Window_t TString Int_t GCValues_t GetPrimarySelectionOwner GetDisplay GetScreen GetColormap GetNativeEvent const char const char dpyName wid window const char font_name cursor keysym reg const char only_if_exist regb h Point_t winding char text const char depth char const char Int_t count const char ColorStruct_t color const char Pixmap_t Pixmap_t PictureAttributes_t attr const char char ret_data h unsigned char height h Atom_t Int_t ULong_t ULong_t unsigned char prop_list Atom_t Atom_t Atom_t Time_t format
Combinations of { 1.0000000, 2.0000000, 3.0000000 } and { -4.0000000, -5.0000000 }:
1.0 * -4.0 = -4.0
1.0 * -5.0 = -5.0
2.0 * -4.0 = -8.0
2.0 * -5.0 = -10.0
3.0 * -4.0 = -12.0
3.0 * -5.0 = -15.0
Unique triples of { 1.0000000, 2.0000000, 3.0000000, 4.0000000 }:
1.0 * 2.0 * 3.0 = 6.0
1.0 * 2.0 * 4.0 = 8.0
1.0 * 3.0 * 4.0 = 12.0
2.0 * 3.0 * 4.0 = 24.0
Date
August 2018
Author
Stefan Wunsch

Definition in file vo005_Combinations.py.