Filter and counts events from a TTree

The “(Edep_size > 0 ? Edep->at(1) : 0.)” is wrong.

If you want to access the vector’s element “n”, you must make sure that the vector’s size is at least “n + 1”, e.g.:
(Edep_size > n ? Edep->at(n) : 0.)

See the std::vector::size and the std::vector::at methods descriptions (and try the examples shown therein).