I am currently working on doing a mass reconstruction exercise, where I look at all the jets in each event from a set of events, and then add the masses of two jet pairs where the pairs meet certain criteria for mass and closeness in eta. However, it has been pointed out by users on the forum that there is double-counting, because j =i, for example and I have realized that I should be considering all possible permutations of the 4 jets without double-counting.

I am aware that there is a function in C++ to loop over all permutations but I am unsure how to use this to modify what I have. Basically, I need to follow the example in the link somehow but with int myints[] = {1,2,3,4} for the 4 jets; and then calculate the invariant masses from the first two jets and the last two of the permutation. The intention is for each possible permutation to do the mass calculation and then add the invariant masses of the pairs and put them into the same histogram. My current piece of code is below with double-counting.

*Edit*: I have realized that the permutation function below will not work either, as I need all combinations of 4 jets out of njets. If anyone has any suggestions that would be appreciated.

http://www.cplusplus.com/reference/algorithm/next_permutation/

```
if(njets>3){
for(int i =0; i<njets; i++){
j1 = (Jet *) branchJet->At(i);
if((j1->PT)>30) {
for(int j = i; j < njets; j++){
j2 = (Jet *) branchJet->At(j);
if((j2->PT)>30 & ((j1->P4()+j2->P4()).M())>70 &&((j1->P4()+j2->P4()).M())<100 && abs((j1->Eta) - (j2->Eta))<1){
for(int k =j; k<njets; k++){
j3 = (Jet *) branchJet->At(k);
if((j3->PT)>30) {
for(int l = k; l < njets; l++){
j4 = (Jet *) branchJet->At(l);
if((j4->PT)>30 && ((j3->P4()+j4->P4()).M())>20 && ((j3->P4()+j4->P4()).M())<50 &&
abs((j3->Eta) - (j4->Eta))<1){invmjets->Fill((j1->P4()+j2->P4()).M() + (j3->P4()+j4->P4()).M(),norm);
}
}
}
}
}
}
}
} }
```