Plotting Sum over selected quantities through TTree::Draw

Dear ROOT experts,

I have a tree, containing e.g. jet quantities, and want to plot the px sum only of certaing jets (e.g., with pt>10 and |eta|<3). The corresponding loop would be:

  TChain *c = new TChain("miniTree");
  c->Add("mini*.root");
  t = (TTree *) gROOT->FindObject("miniTree");
  TH1F *mht2 = new TH1F("mht2","",100,0,1000);
  int CaloJet_nJets;
  float CaloJet_pt[100],CaloJet_px[100],CaloJet_eta[100];

  t->SetBranchAddress("CaloJet_eta",CaloJet_eta);
  t->SetBranchAddress("CaloJet_pt",CaloJet_pt);
  t->SetBranchAddress("CaloJet_px",CaloJet_px);
  t->SetBranchAddress("CaloJet_nJets",&CaloJet_nJets);

  for(int i=0;i<t->GetEntries();i++){
    t->GetEntry(i);
    float MHT=0;
    for(int j=0; j<CaloJet_nJets;j++){
      if(CaloJet_pt[j]>10 && fabs(CaloJet_eta[j])<3){
        MHT += CaloJet_px[j];
      }
    }
    mht2->Fill(MHT);
  }

I would like to do this with TTree::Draw, and I tried this:

t->Draw(">>selJets","CaloJet_pt>10 && abs(CaloJet_eta) <3");
t->SetEventList(selJets);
t->Draw("Sum$(CaloJet_px) >>mht1(100,0,1000)");

and seems to work… Could you please confirm that’s correct, or if there’s a better way for doing that?

thanks a lot
leo

Hi,

t->Draw(">>selJets","CaloJet_pt>10 && abs(CaloJet_eta) <3"); t->SetEventList(selJets); t->Draw("Sum$(CaloJet_px) >>mht1(100,0,1000)");plots the px of ALL jets for any event that have at least one jet with pt>10 and |eta|<3.
The plot you want is:t->Draw("Sum$(CaloJet_px) >>mht1(100,0,1000)","CaloJet_pt>10 && abs(CaloJet_eta) <3");

Cheers,
Philippe.

PS. The loop corresponding to the first plot is code[code] TChain c = new TChain(“miniTree”);
c->Add("mini
.root");
t = (TTree *) gROOT->FindObject(“miniTree”);
TH1F *mht2 = new TH1F(“mht2”,"",100,0,1000);
int CaloJet_nJets;
float CaloJet_pt[100],CaloJet_px[100],CaloJet_eta[100];

t->SetBranchAddress(“CaloJet_eta”,CaloJet_eta);
t->SetBranchAddress(“CaloJet_pt”,CaloJet_pt);
t->SetBranchAddress(“CaloJet_px”,CaloJet_px);
t->SetBranchAddress(“CaloJet_nJets”,&CaloJet_nJets);

for(int i=0;iGetEntries();i++){
t->GetEntry(i);
bool event_is_wanted = false;
for(int j=0; j<CaloJet_nJets;j++){
if(CaloJet_pt[j]>10 && fabs(CaloJet_eta[j])<3){
event_is_wanted = true;
break;
}
}
if (event_is_wanted) {
float MHT=0;
for(int j=0; j<CaloJet_nJets;j++){
MHT += CaloJet_px[j];
}
mht2->Fill(MHT);
}
}
}[/code]