Hi everyone. I am stuck in a problem. The problem is as follows:
I have a root file which have a single tree and a single branch. The branch contains the information on the event no’s generated from a MC sample. As there are multiple candidates in a single event, these candidates take the same event no. What I want to do is assign the candidates with the same event no by a user defined number. An example of this would be like,
eventno user _defined_no
1 1
2 1
3 -10
3 -10
4 1
5 -10
5 -10
For this purpose, I have wriiten a macro which is shown below,
void event_count_sample()
{
TFile *f1 = new TFile("sample1.root");
TTree* t1 = (TTree*)f1-> Get("h1");
float eventno = 0;
float count = 0;
float flag = -1;
t1->SetBranchAddress("eventno",&eventno);
int nentries = t1->GetEntries();
for(int i = 1; i < 10; i = i+1)
{
t1->GetEntry(i);
if((eventno>flag) )
{
flag = eventno;
count = 1;
}
else
{
count = -10;
}
std::cout<<" eventno : "<<eventno<<" count : "<<count<<std::endl;
}
}
The following is the output for 10 entries,
eventno : 7 count : 1
eventno : 8 count : 1
eventno : 12 count : 1
eventno : 14 count : 1
eventno : 17 count : 1
eventno : 17 count : -10
eventno : 24 count : 1
eventno : 31 count : 1
eventno : 39 count : 1
The problem with the code is that at event no: 17 the user defined no which is expected to be -10 appears to be 1. The intention is to print -10 for both the events 17 as they are multiple candidates belonging to the same event. May someone help me in solving this issue?
Thanking you in advance.
Attachments : A root file containing the events.
Regards,
Jyotirmoisample1.root (11.2 KB)