Hello Rooters,
I am trying to select the entries in an TTree by imposing conditions on the Branches. Let me explain:
- I have written a TTree to file, with new Branches, like below:
TFile *fin = new TFile("tmp_outfile.root");
TTree *t1 = (TTree*)fin->Get("t1");
Float_t NTracks; //overall amount of tracks in event
Float_t nKaonTracks;//number of kaon tracks
Float_t M_KK; //Invariant mass of Kaon pairs
Float_t PIDK; //Kaon PID
Float_t PIDK1; //1st Kaon PID
Float_t PIDK2; //2nd Kaon PID
t1->Branch("NTracks", &NTracks,"NTracks/F");
t1->Branch("nKaonTracks", &nKaonTracks,"nKaonTracks/F");
t1->Branch("M_KK", &M_KK,"M_KK/F");
t1->Branch("PIDK", &PIDK,"PIDK/F");
t1->Branch("PIDK1", &PIDK1,"PIDK1/F");
t1->Branch("PIDK2", &PIDK2,"PIDK2/F");
if (some condition)
{
t1->Fill();
}
Now, I have a file tmp_outfile.root
that stores the computed invariant mass of kaon pairs M_KK
and the PID information of the tracks PIDK1
and PIDK2
. What I would like to do is to fill a histogram by selecting all the entries in M_KK
with a corresponding PIDK1
and/or PIDK2
values greater than a set number.
I am finding looping through the events particularly awkward; I have this basic attempt
TTree *t1 = (TTree*)fin->Get("t1");
Float_t NTracks; //overall amount of tracks in event
Float_t nKaonTracks;//number of kaon tracks
Float_t M_KK; //Invariant mass of Kaon pairs
Float_t PIDK; //Kaon PID
Float_t PIDK1; //1st Kaon PID
Float_t PIDK2; //2nd Kaon PID
t1->SetBranchAddress("NTracks",&NTracks);
t1->SetBranchAddress("nKaonTracks",&nKaonTracks);
t1->SetBranchAddress("M_KK",&M_KK);
t1->SetBranchAddress("PIDK",&PIDK);
t1->SetBranchAddress("PIDK1",&PIDK1);
t1->SetBranchAddress("PIDK2",&PIDK2);
Long64_t nentries = t1->GetEntriesFast();
for (Long64_t i=0; i<<nentries;++i)
{
t1->GetEntry(i);
<some if condition>
}
I was hoping someone could help me with the if loop: what I want to do is something like
for (int j=0; i<PIDK1[i].size(); ++j)
{
if(PID[j][i] >= 0)
{
h.Fill(M_KK[i][j]);
}
}
Where h
is a histogram and i
is the index in the previous loop with GetEntry(i)
; Again, all I want to do is take all the entries with a given value of PIDK1
greater than a value n and fill a histogram with the corresponding M_KK
entries.
Thank you for your help, I hope I was clear enough.
Blaise