0

I am having problems using an if statement. I only want to keep muons of quality 1, however, I am having problems with if (recomuons_qualiy != 1 ) continue; I am not sure how to solve this problem, as there is an issue between the variable recomuons_qualiy being stored as a vector<int> and using it an an int.

#include "trigReader.C"
//#include "trigReader.h"
#include <TH2.h>
#include <TStyle.h>
 #include <TCanvas.h>
include <TChain.h>

void Plots() { //OPENING BRACE

 //##################################
 //        OPEN ROOT FILE
 //##################################

  TFile *file = new TFile ("/afs/cern.ch/work/a/atee/private/qualification_task    /PEB_Work_Part_5/user.hrussell.data17_13TeV.00334443.physics_EnhancedBias.r10013_r10014_p3313.bntup_11_tmpBphys.root/nTuple.root", "READ");

  TTree *tree = (TTree*)file->Get("trig");

//##############################
//  VARIABLE DECLARATIONS
//##############################

Int_t HLT_3mu4;
Int_t eventNumber;
vector<int> *recomuons_qualiy;

trigReader *trig = new trigReader(tree);  //Created an object which will contain the objects

for (int ievent=0; ievent<tree->GetEntries(); ievent++) { //Need to loop through the tree to get the number of events.
    trig->GetEntry(ievent);

    HLT_3mu4 = trig->HLT_3mu4;
    recomuons_qualiy = trig->recomuons_qualiy;

    event = trig->eventNumber;  //resets the event number to the current      event number. Hence when printing the eventNumber use event!!!!

//#####################################
//         RECO MUONS STUFF
//#####################################

    Int_t nRecoMuons = trig->recomuons->size();

    for (Int_t i=0; i<trig->recomuons->size(); i++) { //Reco Muons are unique
        if (HLT_3mu4 == 0) continue;   //Now make plots for events which pass the HLT_3mu4 trigger

        if(*recomuons_qualiy != 1 ) continue; //Remove all reco muons whose quality is not equal to 1. This leaves only tight muons.

    }// END OF FOR LOOP FOR RECOMUONS
}// CLOSING MAIN FOR LOOP
ivpavici
  • 1,117
  • 2
  • 19
  • 30
Amy Tee
  • 13
  • 8
  • 1
    What do you think `if(recomuons_qualiy != 1 )` should do?? Did you want to check for the vector size? – user0042 Dec 17 '17 at 12:38
  • 1
    I guess you mean `(*recomuons_qualiy)[i] != 1`. – John Zwinck Dec 17 '17 at 12:39
  • Never point to a std::vector! The vector might change its address when elements are added. On the issue: you can't compare all elements of a vector with a scalar value like this. You need to check each element on its own. – wolff Dec 17 '17 at 12:40
  • Also please read here: https://stackoverflow.com/questions/46991224/are-there-any-valid-use-cases-to-use-new-and-delete-raw-pointers-or-c-style-arr – user0042 Dec 17 '17 at 12:42
  • Thanks! This *I think* has solved the problem Wolff. – Amy Tee Dec 17 '17 at 12:45

0 Answers0