Applied cut string does not work as expected

Take the “smallFile.root” and try:

Events->Scan("nElectron:Electron_pt", "", "", 10);
Events->Scan("nElectron:Electron_pt", "(nElectron<1) || (nElectron>0)", "", 10);
Events->Scan("nElectron:Electron_pt", "(nElectron<1) || (nElectron>0 && Electron_pt>0)", "", 10);
Events->Scan("nElectron:Electron_pt", "(nElectron<1) || (nElectron>0 && Alt$(Electron_pt,0)>0)", "", 10);

@couet Well, there may be two problems. One related to the usage of “Electron_pt” in the cut (without “Alt$”, it unconditionally requires that at least one electron is present, so it disregards the “nElectron<1” condition) and another one related to the “UInt_t” type of the “nElectron”.

@Alkass I do not know if the result will always be correct, but instead of:
"(Muon_pt>29 || Electron_pt>37)"
try to use:
"(Alt$(Muon_pt,0)>29 || Alt$(Electron_pt,0)>37)"

This is really under the expertise of @pcanal

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.

This is, for better or worse, the TTreeFormula semantic. When writing:

(Muon_pt>29 || Electron_pt>37)

TTreeFormula expands it to:

for(Int_t index = 0; index < min( num_of_elements(Muon_pt), num_of_elements(Electron_pt))
    use `(Muon_pt[index]>29 || Electron_pt[index]>37)

The Alt$ function was introduced to work around this limitation.

So implicitly,

(Muon_pt>29 || Electron_pt>37)

is equivalent to

(Muon_pt>29 || Electron_pt>37) && (nMuon > 0 && nElectron > 0 && Instance$ < nMuon && Instance$ < nElectron)
cut=(Muon_pt>29 || Electron_pt>37) ||  ( HLT_IsoMu24 || HLT_IsoMu27 || HLT_Ele35_WPTight_Gsf)

so naively, you should get events when either muon (electrons) have pt> 29 (37) and also when some HLT triggers exist in the event.

Actually this is more complex. Technically the cut is applied “per element” rather than “per event”, so it
used as:

(Muon_pt[index]>29 || Electron_pt[index]>37) ||  ( HLT_IsoMu24 || HLT_IsoMu27 || HLT_Ele35_WPTight_Gsf)

to get the “per event” filtering you can use:

(  Sum$(Muon_pt>29) || Sum$(Electron_pt>37)) ||  ( HLT_IsoMu24 || HLT_IsoMu27 || HLT_Ele35_W
PTight_Gsf)

(assuming the last 4 are not arrays, if they are array they also need the Sum$)