21 #include <framework/logging/Logger.h>
24 #define B2FATAL(arg) { std::cout << arg << std::endl; std::exit(1);}
25 #define B2ASSERT(str, cond) { if((cond) == false) {std::cout << __FILE__ <<", line "<<__LINE__ << std::endl << "" << #cond << " failed" << std::endl; std::exit(1);} }
27 #define B2INFO(arg) { std::cout << arg << std::endl;}
28 #define B2WARNING(arg) { std::cout << "WARNING : "<< arg << std::endl;}
81 std::map<ExpRun, std::pair<double, double>>
filter(
const std::map<ExpRun, std::pair<double, double>>& runs,
double cut,
82 std::map<ExpRun, std::pair<double, double>>& runsRemoved);
85 std::pair<int, int>
getStartEndIndexes(
int nIntervals, std::vector<int> breaks,
int indx);
89 inline std::vector<Atom>
slice(std::vector<Atom> vec,
int s,
int e)
91 return std::vector<Atom>(vec.begin() + s, vec.begin() + e + 1);
101 std::vector<std::map<ExpRun, std::pair<double, double>>>
breaks2intervalsSep(
const std::map<ExpRun,
102 std::pair<double, double>>& runsMap,
const std::vector<Atom>& currVec,
const std::vector<int>& breaks);
124 static std::pair<double, double>
getStartEnd(std::vector<std::map<
ExpRun, std::pair<double, double>>> res)
126 return {res.front().begin()->second.first,
127 res.back().rbegin()->second.second};
135 static std::vector<double>
getBreaks(std::vector<std::map<
ExpRun, std::pair<double, double>>> res)
137 std::vector<double> breaks;
138 for (
int k = 0; k < int(res.size()) - 1; ++k) {
139 double e = res.at(k).rbegin()->second.second;
140 double s = res.at(k + 1).begin()->second.first;
141 breaks.push_back((e + s) / 2.);
152 static std::map<ExpRun, std::pair<double, double>>
mergeIntervals(std::map<
ExpRun, std::pair<double, double>> I1,
153 std::map<
ExpRun, std::pair<double, double>> I2);
165 template<
typename Evt>
166 std::vector<std::vector<std::map<ExpRun, std::pair<double, double>>>>
getIntervals(
167 const std::map<
ExpRun, std::pair<double, double>>& runs, std::vector<Evt> evts,
168 TString lossFunctionOuter, TString lossFunctionInner)
171 std::sort(evts.begin(), evts.end(), [](
const Evt & e1,
const Evt & e2) { return (e1.t > e2.t); });
174 std::vector<std::pair<double, double>> smallRuns =
splitToSmall(runs, 0.1);
176 std::vector<Atom> atoms =
createAtoms(smallRuns, evts);
183 std::vector<std::vector<std::map<ExpRun, std::pair<double, double>>>> splitsRun;
188 std::vector<int> breaksVtx;
189 for (
int i = 0; i < int(breaksSize.size()) + 1; ++i) {
194 auto currVec =
slice(atoms, s, e);
204 splitsRun.push_back(splitSeg);
206 if (s != 0) breaksVtx.push_back(s - 1);
207 for (
auto b : breaksSmall)
208 breaksVtx.push_back(b + s);
209 if (e !=
int(breaksSize.size())) breaksVtx.push_back(e);
222 std::vector<int>
dynamicBreaks(
const std::vector<Atom>& runs);
234 double getMinLoss(
const std::vector<Atom>& vec,
int e, std::vector<int>& breaks);
244 double lossFunction(
const std::vector<Atom>& vec,
int s,
int e)
const;
254 static std::vector<std::pair<double, double>>
splitToSmall(std::map<
ExpRun, std::pair<double, double>> runs,
255 double intSize = 1. / 60);
262 template<
typename Evt>
263 inline std::vector<Atom>
createAtoms(
const std::vector<std::pair<double, double>>& atomsTimes,
const std::vector<Evt>& evts)
265 std::vector<Atom> atoms(atomsTimes.size());
268 for (
unsigned a = 0; a < atoms.size(); ++a) {
269 atoms[a].t1 = atomsTimes[a].first;
270 atoms[a].t2 = atomsTimes[a].second;
275 for (
unsigned i = 0; i < evts.size(); ++i) {
276 for (
unsigned a = 0; a < atoms.size(); ++a)
277 if (atoms[a].t1 <= evts[i].t && evts[i].t < atoms[a].t2)
291 LossString.ReplaceAll(
"rawTime",
"[0]");
292 LossString.ReplaceAll(
"netTime",
"[1]");
293 LossString.ReplaceAll(
"maxGap",
"[2]");
294 LossString.ReplaceAll(
"nEv",
"[3]");
296 return (
new TF1(
"lossFun", LossString));
304 std::vector<std::pair<double, std::vector<int>>>
cache;
314 template<
typename Evt>
315 inline std::map<ExpRun, std::pair<double, double>>
getRunInfo(
const std::vector<Evt>& evts)
317 std::map<ExpRun, std::pair<double, double>> runsInfo;
319 for (
auto& evt : evts) {
323 if (runsInfo.count(
ExpRun(Exp, Run))) {
325 std::tie(tMin, tMax) = runsInfo.at(
ExpRun(Exp, Run));
326 tMin = std::min(tMin, time);
327 tMax = std::max(tMax, time);
328 runsInfo.at(
ExpRun(Exp, Run)) = {tMin, tMax};
330 runsInfo[
ExpRun(Exp, Run)] = {time, time};
343 template<
typename Evt>
347 double tBreak = -1e10;
348 for (
auto& e : events) {
365 template<
typename Evt>
366 std::vector<ExpRunEvt>
convertSplitPoints(
const std::vector<Evt>& events, std::vector<double> splitPoints)
369 std::vector<ExpRunEvt> breakPos;
370 for (
auto p : splitPoints) {
372 breakPos.push_back(pos);