- #1
ChrisVer
Gold Member
- 3,378
- 464
Hello, well I am not sure how to search for this online, but I raise this question here:
Suppose that I have several bins of let's say cuts, here I list 3 but the main idea is to make their numbers tunable by the user:
and I want to combine all of them together
Where add_cuts is just a function which loops over the cut expression and concatenates the cut expressions approriately...eg:
cut_comb["p10"]["BoolPass"]["High"] would be: "(p<=10)&&(bool)&&(T<0)"
How could I make the so ugly for-in-for-in-for loop look better [and also be able to change some cuts, eg remove the cut3, without having to rewrite the code]... I was thinking about using recursion on a list that contains [cut1,cut2,cut3], but I don't know I get stuck in the logic somewhere, in particular the increasing dict type of cut_comb...maybe I could change the whole name of the key? instead of having 3 keys for example, to have only one with concatenated the expressions, eg:
cut_comb["p10_BoolPass_High"] would be: "(p<=10)&&(bool)&&(T<0)"
But still I'm not sure.
Suppose that I have several bins of let's say cuts, here I list 3 but the main idea is to make their numbers tunable by the user:
Python:
cut1 = { "p10" : "p <= 10" ,
"11p20 " : "10<p && p<=20" ,
"21p " : "p>20" ,
}
cut2 = { "BoolPass" : "bool" ,
"BoolFail" : "!bool" ,
}
cut3 = { "High" : "T>=0" ,
"Low" : "T<0",
}
and I want to combine all of them together
Python:
cut_comb = dict()
for cutname1,cut1 in cut1.items():
cut_comb[cutname1] =dict()
for cutname2,cut2 in cut2.items():
cut_comb[cutname1][cutname2] =dict()
for cutname3,cut3 in cut3.items():
cut_comb[cutname1][cutname2][cutname3] = add_cuts( [cut1,cut2,cut3] , name="{}_{}_{}".format(cutname1,cutname2,cutname3) )
Where add_cuts is just a function which loops over the cut expression and concatenates the cut expressions approriately...eg:
cut_comb["p10"]["BoolPass"]["High"] would be: "(p<=10)&&(bool)&&(T<0)"
How could I make the so ugly for-in-for-in-for loop look better [and also be able to change some cuts, eg remove the cut3, without having to rewrite the code]... I was thinking about using recursion on a list that contains [cut1,cut2,cut3], but I don't know I get stuck in the logic somewhere, in particular the increasing dict type of cut_comb...maybe I could change the whole name of the key? instead of having 3 keys for example, to have only one with concatenated the expressions, eg:
cut_comb["p10_BoolPass_High"] would be: "(p<=10)&&(bool)&&(T<0)"
But still I'm not sure.
Last edited: