We present an all-around study of the visitors flow in crowded museums: a combination of Lagrangian field measurements and statistical analyses enable us to create stochastic digital-twins of the guests dynamics, unlocking comfort- and safety-driven optimizations. Our case study is the Galleria Borghese museum in Rome (Italy), in which we performed a real-life data acquisition campaign. We specifically employ a Lagrangian IoT-based visitor tracking system based on Raspberry Pi receivers, displaced in fixed positions throughout the museum rooms, and on portable Bluetooth Low Energy beacons handed over to the visitors. Thanks to two algorithms: a sliding window-based statistical analysis and an MLP neural network, we filter the beacons RSSI and accurately reconstruct visitor trajectories at room-scale. Via a clustering analysis, hinged on an original Wasserstein-like trajectory-space metric, we analyze the visitor paths to get behavioral insights, including the most common flow patterns. On these bases, we build the transition matrix describing, in probability, the room-scale visitor flows. Such a matrix is the cornerstone of a stochastic model capable of generating visitor trajectories in silico. We conclude by employing the simulator to increase the number of daily visitors while respecting numerous logistic and safety constraints. This is possible thanks to optimized ticketing and new entrance/exit management.