Methods of TClonesArray

I have a file with collision data, and what I want to do is to get which events had three jets.

The file has a branch called jetP4, of type TClonesArray, where all the jet data is in, and inside there is a leaf called @size, which I am told it has how many jets per event where there, and its histogram is consistent with that, just whole numbers smaller than 8.

What I want to do is to use the data of this @size, and I have done things like that in the past but I don’t know why it doesn’t work this time, but i have one idea: other data in the branch is in leafs of type TLorentzVector, while this is a TClonesArray, the same type as the branch, and maybe that’s the reason.

For example, to extract the transverse energy I would:

  //Upload the file with the data
  TFile* file = TFile::Open("NeroNtuples_9.root");
  
  //Upload the tree with the event data
  TTree *tree=(TTree*)file->Get("nero/events");
  
  //Create a variable to store all the jet event data
  TClonesArray *jetdata = new TClonesArray("jetdata");
  
  //Specify where all the jet event data will be stored
  tree->SetBranchAddress("jetP4", &jetdata);
  
  //Get how many events we have to loop through
  int nentries = tree->GetEntries();

  //Create a variable to store the mass values
  Int_t mass;

  //Loop through all the events
  for(int ientry = 0; ientry < nentries; ientry++) 
  {
      //Reset the jet data 
    jetdata->Clear();

    //This line stores the proper data in the variables qe specified
    tree->GetEntry(ientry);
    
    //Store all the data in this lorentz vector
      TLorentzVector * lorentz_jetdata = (TLorentzVector *)jetdata->At(0);

      //Get the transverse mass of that lorentz vector
      mass=lorentz_jetdata->Mt();
      
      cout<<mass<<endl;
  }

And to extract the amount of jets I tried with

  //Upload the file with the data
  TFile* file = TFile::Open("NeroNtuples_9.root");
  
  //Upload the tree with the event data
  TTree *tree=(TTree*)file->Get("nero/events");

  //Create a variable to store all the jet event data
  TClonesArray *jetsize = new TClonesArray("jetdata");

  //I guess jetP4.@size() is the way to call it
  //I tried declaring it without that and use ->size(), but it didn't work
  tree->SetBranchAddress("jetP4.@size()", &jetsize);

  //Get how many events we have to loop through
  int nentries = tree->GetEntries();

  //Loop through all the events
  for(int ientry = 0; ientry < nentries; ientry++) 
  {

    //Reset the jet data 
    jetsize->Clear();

    //This line stores the proper data in the variables qe specified
    tree->GetEntry(ientry);
      
      //Perhaps I need to use a method here?, size, Getsize, and others don't work here
    cout<<jetsize<<endl;
 }

Thanks a lot

Hi,

[quote] tree->SetBranchAddress(“jetP4.@size()”, &jetsize);
//I guess jetP4.@size() is the way to call it
[/quote]

The ‘@size()’ is a part of the TTreeFormula language and is useable only from TTreeFormula itself or the tool that uses it (TTree::Draw, TTree::Scan).

[quote] //I tried declaring it without that and use ->size(), but it didn’t work[/quote]This is on the right track. To get the number of elements in a TClonesArray use ->GetEntries()

Cheers,
Philippe