bdela
February 28, 2017, 7:05pm
1
Hello,
I am trying to write a concise if condition in ROOT, the analogue of the python line
if sum(muon)>=2 and sum(charge[np.where(muon==1)])==0: #at least one muon track and sum of charges of muon tracks = 0
i.e. I would like to select all the events with at leat two muon tracks and the sum of the muon charges to be zero. I know that the Scan
method is useful for this, but I it not quite what I need for my if condition.
Can anyone suggest how to do this, and in general how manipulate indices as above in python arrays?
Thanks,
-B
ganis
March 1, 2017, 8:41am
2
Hello,
See replay to the other post.
Can you specify what are the types of ‘muon’ and ‘charge’ and how they appear in your tree (branch name, …)?
G Ganis
bdela
March 1, 2017, 9:47am
3
Hello,
Thank you for your advice. I attach below a snippet of the mymacro.h I obtained via the method of MakeClass, following the tutorial.
// Header file for the classes stored in the TTree if any.
class mymacro {
public :
TTree *fChain; //!pointer to the analyzed TTree or TChain
Int_t fCurrent; //!current Tree number in a TChain
// Fixed size dimensions of array or collections stored in the TTree if any.
// Declaration of leaf types
Int_t run;
Int_t evt;
Int_t bunchid;
Int_t bunchtype;
Int_t trighlt1;
Int_t trigmu;
Int_t l0dim;
Int_t l0m;
Int_t stripphi;
Int_t nlong;
Int_t nvelo;
Int_t down;
Int_t ntk;
Int_t nspd;
Int_t ntotphot;
Int_t nout;
Int_t nphotons;
Float_t etprev1;
Float_t etprev2;
Int_t tt[10]; //[nout]
Float_t tx[10]; //[nout]
Float_t ty[10]; //[nout]
Float_t tz[10]; //[nout]
Float_t px[10]; //[nout]
Float_t py[10]; //[nout]
Float_t pz[10]; //[nout]
Float_t pt[10]; //[nout]
Int_t charge[10]; //[nout]
Int_t muon[10]; //[nout]
Int_t muacc[10]; //[nout]
Float_t pide[10]; //[nout]
Float_t pidk[10]; //[nout]
Float_t pidpi[10]; //[nout]
Float_t pidp[10]; //[nout]
Float_t pidm[10]; //[nout]
Float_t ecal[10]; //[nout]
Float_t hcal[10]; //[nout]
Float_t eoverp[10]; //[nout]
Float_t phx[6]; //[nphotons]
Float_t phy[6]; //[nphotons]
Float_t phz[6]; //[nphotons]
Int_t spd[6]; //[nphotons]
Int_t prs[6]; //[nphotons]
Int_t nl0;
Float_t l0et[3]; //[nl0]
Float_t l0phi[3]; //[nl0]
Float_t l0theta[3]; //[nl0]
Int_t nher;
Int_t herchan[30]; //[nher]
Int_t heradc[30]; //[nher]
// List of branches
TBranch *b_run; //!
TBranch *b_evt; //!
TBranch *b_bunchid; //!
TBranch *b_bunchtype; //!
TBranch *b_trighlt1; //!
TBranch *b_trigmu; //!
TBranch *b_l0dim; //!
TBranch *b_l0m; //!
TBranch *b_stripphi; //!
TBranch *b_nlong; //!
TBranch *b_nvelo; //!
TBranch *b_ndown; //!
TBranch *b_ntk; //!
TBranch *b_nspd; //!
TBranch *b_ntotphot; //!
TBranch *b_nout; //!
TBranch *b_nphotons; //!
TBranch *b_etprev1; //!
TBranch *b_etprev2; //!
TBranch *b_tt; //!
TBranch *b_tx; //!
TBranch *b_ty; //!
TBranch *b_tz; //!
TBranch *b_px; //!
TBranch *b_py; //!
TBranch *b_pz; //!
TBranch *b_pt; //!
TBranch *b_charge; //!
TBranch *b_muon; //!
TBranch *b_muacc; //!
TBranch *b_pide; //!
TBranch *b_pidk; //!
TBranch *b_pidpi; //!
TBranch *b_pidp; //!
TBranch *b_pidm; //!
TBranch *b_ecal; //!
TBranch *b_hcal; //!
TBranch *b_eoverp; //!
TBranch *b_phx; //!
TBranch *b_phy; //!
TBranch *b_phz; //!
TBranch *b_spd; //!
TBranch *b_prs; //!
TBranch *b_nl0; //!
TBranch *b_l0et; //!
TBranch *b_l0phi; //!
TBranch *b_l0theta; //!
TBranch *b_nher; //!
TBranch *b_herchan; //!
TBranch *b_heradc; //!
In this case I am considering the branches muon
and charge
, such that
Int_t charge[10]; //[nout]
Int_t muon[10]; //[nout]
Thanks again,
B
ganis
March 1, 2017, 10:04am
4
Hello,
From your tree definition it looks that the number of muons is ‘nout’.
So this should plot the sum of charges or at least 2 muons:
tree->Draw("Sum$(charge)", "nout>=2")
and this select those with total charge null:
tree->Scan(..., "nout>=2 && Sum$(charge)==0")
G Ganis
1 Like
bdela
March 1, 2017, 10:23am
5
Hello,
nout
is the number of tracks per event, not necessarily the number of muon tracks. These are a subset of nout
such that muon==1
.
However, your advice is still quite helpful. Thank you.
system
Closed
March 15, 2017, 10:23am
6
This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.