I’ve written the following code, which takes in three sorted ROOT files, each containing a TNtupleD of UNIX timestamps from the year 2015, and pairs them up into the closest unique triplets of the form {a,b,c}. I then plot these triplets on a TH2, with the horizontal axis being a-b, and the vertical axis being a-c.
To ensure the algorithm is working properly, I produced two ROOT files of completely random timestamps, using gRandom->Uniform() and setting the seed value using time(). I fed the code one live dataset, and the two random datasets. I expected random distribution, but instead I’m getting these weird, perfect diagonal lines: https://filebin.net/spbswnhkfy8xdkp8/random_plot.pdf?t=48f2yhjq
Moreover, when I plot using three real datasets, if I use enough bins there is a weird diagonal line, two more lines running straight through the graph horizontally and vertically. Have I made some mistake with my code? Is this a ROOT thing? A C++ problem?
My code:
void unbiasedAnalysis(){
TNtupleD *D = new TNtupleD("D","D","x:y");
ROOT::RDataFrame statn1("D", "./pathtodata");
ROOT::RDataFrame statn2("D", "./pathtodata");
ROOT::RDataFrame statn3("D", "./pathtodata");
vector<double> vec_1, vec_2, vec_3;
statn1.Foreach([&](double tstamp){ vec_1.push_back(tstamp); },{"UNIX"});
statn2.Foreach([&](double tstamp){ vec_2.push_back(tstamp); },{"UNIX"});
statn3.Foreach([&](double tstamp){ vec_3.push_back(tstamp); },{"UNIX"});
vector<vector<double>> pairs;
for(auto tstamp : vec_1){
double first,second;
//get iterator pointing to closest element greater than or equal to
auto geq = std::lower_bound(vec_2.begin(), vec_2.end(), tstamp);
//get iterator pointing to nearest element less than
auto leq = geq - 1;
double foo = tstamp - *geq;
double bar = tstamp - *leq;
//compare iterators, save the closest
if(dabs(foo) < dabs(bar)){ first = *geq; }
else { first = *leq; }
//repeat
geq = std::lower_bound(vec_3.begin(), vec_3.end(), tstamp);
leq = geq - 1;
foo = tstamp - *geq;
bar = tstamp - *leq;
if(dabs(foo) < dabs(bar)){ second = *geq; }
else { second = *leq; }
//add to pairs
pairs.push_back({tstamp, first, second, (tstamp-first), (tstamp-second), std::min((tstamp-first), (tstamp-second))});
}
//sort vector of vectors by size of smallest difference
std::sort(pairs.begin(), pairs.end(),
[](const vector<double>& A, const vector<double>& B){
return A[5] < B[5];
});
std::set<double> cache;
ROOT::EnableImplicitMT();
for(auto pair : pairs){
//if not in cache, add to TNtuple
if(cache.find(pair[1]) == cache.end() && cache.find(pair[2]) == cache.end()){
D->Fill(pair[3],pair[4]);
//add to cache
cache.insert(pair[1]); cache.insert(pair[2]);
}
}
D->Draw("x:y>>htemp(100,-0.02,0.02,100,-0.02,0.02)","","colz");
}
Please read tips for efficient and successful posting and posting code
ROOT Version: Not Provided
Platform: Not Provided
Compiler: Not Provided