No member named 'PT'

hi im very new to root & delphes. im trying to modify the tutorial https://cp3.irmp.ucl.ac.be/projects/delphes/wiki/WorkBook/TutorialBologna
im trying to sort the PT after the cuts with

std::sort(electrons->PT.begin(), electrons->PT.end(), std::greater<int>());

but ending up with error

error: no member named 'PT' in 'std::__1::vector<const Electron *,
std::__1::allocator<const Electron *> >'___

here is some part of my code

// Create object of class ExRootTreeReader
  ExRootTreeReader *treeReader = new ExRootTreeReader(&chain);
  Long64_t numberOfEntries = treeReader->GetEntries();
  
  // Get pointers to branches used in this analysis
  TClonesArray *branchParticle = treeReader->UseBranch("Particle");
  TClonesArray *branchElectron = treeReader->UseBranch("Electron");
  TClonesArray *branchMuon = treeReader->UseBranch("Muon");
  
//Declare variable
    
    const Electron *elec1, *elec2, *elec3, *elec4;
    const Muon     *muon1, *muon2, *muon3, *muon4;
   
    
    vector<const Electron*>   *electrons = new vector<const Electron*>();;
    vector<const Muon*>           *muons = new vector<const Muon*>();;
   // Loop over all events begins
    for(Int_t entry = 0; entry < numberOfEntries; ++entry)
    {
      // print event number in the file
      if(entry%100==0) cout << "Reading Event " << entry << endl;
      
      // Load selected branches with data from specified event
      treeReader->ReadEntry(entry);
    
       electrons -> clear();
       muons     -> clear();

       // Select leptons e||mu with pT > 5 || 7  GeV and |eta| < 2.5 || 2.4
       CollectionFilter(*branchElectron, *electrons , 5.0 , 2.5);
       CollectionFilter(*branchMuon    , *muons     , 7.0 , 2.4);
   
    //sort the PT from highest to lowest
        std::sort(electrons->PT.begin(), electrons->PT.end(), std::greater<int>());

   // sort Muon PT, High to low
        std::sort(muons->PT.begin(), muons->PT.end(), std::greater<int>());
    ```
i think i am declaring the vectors wrongly, any suggestions on how i can fix this? thanks

_Please read [tips for efficient and successful posting](https://root-forum.cern.ch/t/tips-for-efficient-and-successful-posting/28292) and [posting code](https://root-forum.cern.ch/t/posting-code-read-this-first/28293)_

_ROOT Version:6.22
_Platform:mac osx catalina 15.15.7
_Compiler:Apple clang version 11.0.3 (clang-1103.0.32.29)

Hi,
I wonder if you actually need a
std::sort(electrons.begin(),elecrrons.end(),[]( const & electron1, const & electron2) { return electron1. Pt() < electron2. Pt()} ;
It all depends on the signatures of your containers i think.

1 Like

hi,
i wanted to sort my PT in decending order, though i see the example skipping this part

Also i wanted to add the P px py pz to the muons which is in another branch ‘particle’ im not very sure how to do this either, im getting error
no member named ‘P’ in ‘Muon’ when i execute muon.P()
below is the example; does leading & subleading means that it is already sorted?

gSystem->Load("libDelphes");

  // Create chain of root trees
  TChain chain("Delphes");
  chain.Add(inputFile);

  // Create object of class ExRootTreeReader
  ExRootTreeReader *treeReader = new ExRootTreeReader(&chain);
  Long64_t numberOfEntries = treeReader->GetEntries();

  // Get pointers to branches used in this analysis
  TClonesArray *branchParticle = treeReader->UseBranch("Particle");
  TClonesArray *branchElectron = treeReader->UseBranch("Electron");
  TClonesArray *branchMuon     = treeReader->UseBranch("Muon");

  // Book histograms
  TH1F *histMinMass = new TH1F("mass_min", "", 50, 00.0, 140.0);
  TH1F *histMaxMass = new TH1F("mass_max", "", 50, 00.0, 140.0);
  TH1F *histMass = new TH1F("mass", "", 50, 100, 150);

  TH1F *histMinMassGen = new TH1F("mass_min_gen", "", 50, 0.0, 140.0);
  TH1F *histMaxMassGen = new TH1F("mass_max_gen", "", 50, 00.0, 140.0);
  TH1F *histMassGen = new TH1F("mass_gen", "", 50, 100, 150);

  // Define variables
  const Electron *elec1, *elec2;
  const Muon     *muon1, *muon2;

  const GenParticle *gen_elec1, *gen_elec2;
  const GenParticle *gen_muon1, *gen_muon2;

  vector<const Electron*>   *electrons = new vector<const Electron*>();;
  vector<const Muon*>           *muons = new vector<const Muon*>();;

  Double_t massMin, massMax, mass, massEE, massMM;
  Double_t gen_massMin, gen_massMax, gen_mass, gen_massEE, gen_massMM;

  // Loop over all events
  for(Int_t entry = 0; entry < numberOfEntries; ++entry)
  {
    // Load selected branches with data from specified event
    treeReader->ReadEntry(entry);

    electrons -> clear();
    muons     -> clear();

    // Select leptons with pT > 10 GeV and |eta| < 2.5
    CollectionFilter(*branchElectron, *electrons , 10.0 , 2.5);
    CollectionFilter(*branchMuon    , *muons     , 10.0 , 2.5);

    // Select event with at least 2 electrons and 2 muons
    if(electrons->size() < 2) continue;
    if(muons->size() < 2)     continue;

    // Define leading and subleading leptons
    elec1 = electrons->at(0);
    elec2 = electrons->at(1);
    muon1 = muons->at(0);
    muon2 = muons->at(1); 

Hi,

does leading & subleading means that it is already sorted?

Likely, but should be easy to test, right? And for sorting, Renato is certainly right!

Cheers, Axel.