I have developed a macro which is used to create three double numbers and then I want to find out the smallest among three in each entry. But this script is not working. Kindly correct my mistake.
" for (int i=0;i<1000;i++) {
TLorentzVector tmp1, tmp2, tmp3;
t->GetEntry(i);
// for(int m=0; m<VetoMu;m++) {
if(VetoMu<2)continue;
int m1=0, m2=1, m3=2;
if(m1==0) tmp1.SetPxPyPzE(VetoMu_px[m1], VetoMu_py[m1], VetoMu_pz[m1], VetoMu_en[m1]);
if(m2==1) tmp2.SetPxPyPzE(VetoMu_px[m2], VetoMu_py[m2], VetoMu_pz[m2], VetoMu_en[m2]);
if(m3==2) tmp3.SetPxPyPzE(VetoMu_px[m3], VetoMu_py[m3], VetoMu_pz[m3], VetoMu_en[m3]);
if (VetoMu_charge[m1]*VetoMu_charge[m2] < 0.) {
double a = (tmp1 + tmp2).M();
}
if (VetoMu_charge[m2]*VetoMu_charge[m3] < 0.) {
double b = (tmp2 + tmp3).M();
}
if (VetoMu_charge[m3]*VetoMu_charge[m1] < 0.) {
double c = (tmp1 + tmp3).M();
}
/* Taking input */
cin >> a >> b >> c;
/* If a is smaller than b and c */
if (a < b && a < c) {
cout << "smallest number is " << a;
/* If b is smaller than a and c */
}
else if (b < a && b < c) {
cout << "smallest number is " << b;
}
else if {
cout << "smallest number is " << c;
}
return 0;
} "
I tried all these tutorial examples but I donot explain which is the smallest in a, b and c.
I used these lines
" d = a<b? (a<c?a:c) : (b<c?b:c);
cout << "the smallest of the numbers is: " <<d<<endl; "
Could you please explain what does it mean? I want to say according to these lines which is the smallest number either a,b or c
I want to add some lines in my code which just save a single number which is smallest of all. That may be “a” sometime may be “b” sometime or may be “c” depending on the situation or the number of entries.
I have added these lines in my script
" d = a<b? (a<c?a:c) : (b<c?b:c);
cout << "the smallest of the numbers is: " <<d<<endl;
cout<<"a : "<< a<<endl;
cout<<"b : "<< b<<endl;
cout<<"c : "<< c<<endl;
"
and the output is like
" the smallest of the numbers is: 40.6711
a : 85.3864
b : 40.6711
c : 42.4108
the smallest of the numbers is: 42.4108
a : 90.4736
b : 67.2951
c : 42.4108
the smallest of the numbers is: 32.0982
a : 32.0982
b : 67.2951
c : 87.6047
the smallest of the numbers is: 37.6647
a : 89.5612
b : 37.6647
c : 87.6047
the smallest of the numbers is: 41.5752
a : 92.0955
b : 41.5752
c : 87.6047
the smallest of the numbers is: 41.5752
a : 182.359
b : 41.5752
c : 93.1043
"
The problem is the smallest value differs for each entry. How would I know which is the smallest occurring number (a,b,c) in average. One way is to check each entry manually and then note it down which is off course not possible because entries may exceed thousand or above. I want to develop an algorithm which just runs on it and tell me which value is smallest on average. And then I will save it in a histogram or in a tree.
int counta = 0, countb = 0, countc=0;
for(...)//Here a for loop over the events...
{
if(a==b && b==c)
{
cout << "The three numbers are equal";
counta++;
countb++;
countc++;
}
else if(a==b)
{
if(c<a)
{
cout << "c is the smallest";
countc++;
}
else
{
cout << "a and b are the smallest";
counta++;
countb++;
}
}
else if(a==c)
{
if(b<a)
{
cout << "b is the smallest";
countb++;
}
else
{
cout << "a and c are the smallest";
counta++;
countc++;
}
}
else if(b==c)
{
if(a<b)
{
cout << "a is the smallest";
counta++;
}
else
{
cout << "b and c are the smallest";
countb++;
countc++;
}
}
else if(a<b)
{
if(a<c)
{
cout << "a is the smallest";
counta++;
}
else
{
cout << "c is the smallest";
countc++;
}
}
else
{
if(b<c)
{
cout << "b is the smallest";
countb++;
}
else
{
cout << "c is the smallest";
countc++;
}
}
}//Finish for loop
cout << "Ranking of smallest: " << counta << " " << countb << " " << countc << endl;
The other thing you were asking is about the ternary operators: