Nested If Statements to Create Histograms

I have a set of if statements linked together but I feel like the syntax is not quite right. When I run the code, the first histogram gets filled (mass of jet pair 1 after pt/eta cuts) but the second histogram doesn’t fill (mass of pair 2 after pt/eta cuts) and when the third histogram fills (mass of all 4 jets after mass selection and pt/eta cuts on both pairs), it looks as if it is only filling for the mass cuts and not taking into account the previous conditions on pt and eta. I appreciate that its a bit of a long piece of code but it’s really just a nested set of if-loops, I was hoping someone could spot the syntax error in it to get it to all link together.

     if((j1->PT)>30 && (j2->PT)>30  && abs((j1->Eta) - (j2->Eta))<1){
     if(((j1->P4()+j2->P4()).M())>40){
       invm->Fill(((j1->P4()+j2->P4()).M()),norm);
       if((j3->PT)>30 && (j4->PT)>30  && abs((j3->Eta) - (j4->Eta))<1){
    if(((j3->P4()+j4->P4()).M())>40){
    inv12->Fill(((j3->P4()+j4->P4()).M()),norm);
        if(((((j1->P4()+j2->P4()).M())>70 || ((j3->P4()+j4->P4()).M())>70)  && (((j3->P4()+j4->P4()).M())>40 ||
((j1->P4()+j2->P4()).M())>40)) && ((j1->P4()+j2->P4()).M())<100  && ((j3->P4()+j4->P4()).M())<100)
           invmpair->Fill((j1->P4()+j2->P4()+j3->P4()+j4->P4()).M(),norm);

Hi,

I’d suggest you add a few printouts to the code. You can start by looking if there are jets satisfying your third requirement:

if((j3->PT)>30 && (j4->PT)>30  && abs((j3->Eta) - (j4->Eta))<1){

RIght after this line, try adding something like

printf("Jet 3 has pT = %f GeV, jet 4 has pT = %f GeV, absolute difference in eta is %f\n", j3->PT, j4->PT, abs((j3->Eta) - (j4->Eta)));

If you don’t see this printout when running the code, it means you don’t have such jets - no wonder the second histogram does not get filled! Then you can move this printout to the line right before your second requirement and make sure again that you don’t have such jets.

Thanks a lot for your great suggestion, I’ve done this and the printout does appear in the output along with the relevant values, so there are jets which satisfy the requirements. I really feel like there is something wrong with the syntax of the whole code piece but don’t know how to debug it.

Could I perhaps post the whole piece of code so you can see if there is something obviously wrong with it? The intention is to simply calculate masses taking permutations into account.

So what about jets that satisfy your fourth requirement? Do you have them? You could modify the printf line to something like

printf("Jet 3 has pT = %f GeV, jet 4 has pT = %f GeV, absolute difference in eta is %f, mass = %f GeV\n", j3->PT, j4->PT, abs((j3->Eta) - (j4->Eta)), ((j3->P4()+j4->P4()).M()));

Are there any printouts with m>40 GeV?

You can certainly post the entire piece of code if you think that’ll help.

I’ve tried with the printout for mass requirement and there are cases where jets 3 and 4 have mass > 40. I will add the code with printouts removed in case it helps as I can’t see what is wrong with it. Essentially, I am attempting to reconstruct mass from two jet pairs but I have to take into account permutations and avoid over-counting ie. jets 1 and 2 could actually be jets 3 and 4. The first pair is for a particular invariant mass window and the second pair for a different range. The n and r refer to the fact that we are working with r combinations of n objects. Obviously, the single jets have a momentum selection and there is a requirement on the absolute eta difference between two jets in a pair, so something is going wrong somewhere.

   Jet *jet1, *jet2, *jet3, *jet4, *j1, *j2, *j3, *j4;

   int njets = branchJet->GetEntries();
   int n, r;
   n = njets;
   r=4;

   std::vector<bool> v(n);
   std::fill(v.begin(), v.begin() + r, true);

   int ord = 0;
   do {
       for (int i = 0; i < njets; ++i) {
           if (v[i]) {
               ord++;
               if(ord==1) j1 = (Jet *) branchJet->At(i);
               if(ord==2) j2 = (Jet *) branchJet->At(i);
               if(ord==3) j3 = (Jet *) branchJet->At(i);
               if(ord==4) j4 =(Jet *) branchJet->At(i);
              cout<<" "<<i;
           }
 }
   cout<<endl;

     if((j1->PT)>30 && (j2->PT)>30  && abs((j1->Eta) - (j2->Eta))<1){
       invm->Fill(((j1->P4()+j2->P4()).M()),norm);
       if((j3->PT)>30 && (j4->PT)>30  && abs((j3->Eta) - (j4->Eta))<1){
    inv12->Fill(((j3->P4()+j4->P4()).M()),norm);
        if(((((j1->P4()+j2->P4()).M())>70 || ((j3->P4()+j4->P4()).M())>70)  && (((j3->P4()+j4->P4()).M())>40 ||
((j1->P4()+j2->P4()).M())>40)) && ((j1->P4()+j2->P4()).M())<100  && ((j3->P4()+j4->P4()).M())<100){
           invmpair->Fill((j1->P4()+j2->P4()+j3->P4()+j4->P4()).M(),norm);
 


      }
     }
    }
 }
  while (std::prev_permutation(v.begin(), v.end()));

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.