NEW: Code shared between analysis and MC