20 #include "TObjString.h"
22 #include "TObjArray.h"
23 #include "TObjString.h"
145 unsigned int nNull = 0;
147 bool ok = (
size > 0);
153 bool ok = (
size > 0);
159 cout << i1 <<
"-" << i2 << endl;
181 std::vector<unsigned int> hashV, indexV;
182 unsigned int nTot = 0;
186 if (!history)
continue;
187 for (
unsigned int j = 0; j < history->
nData(); j++) {
190 if (
data.isDisconnected())
continue;
191 if (nTot % 10000 == 0) cout << nTot << endl;
192 if (
data.energy() > eCut) {
193 cout <<
"E = " <<
data.energy() <<
" " <<
i <<
" " << j << endl;
203 for (
unsigned int i = 0;
i < hashV.size();
i++) {
208 cout << hashV.size() <<
"/" << nTot << endl;
217 if (!history)
continue;
219 cout <<
"Invalid LArSamplesHistory at hash = " <<
i << endl;
230 std::vector<const Interface*> interfaces;
231 interfaces.push_back(
this);
232 interfaces.push_back(&
other);
240 for (
unsigned int i = 0;
i < interfaces.size();
i++)
241 accessors.push_back(&interfaces[
i]->accessor());
248 std::vector<const Interface*> interfaces;
249 interfaces.push_back(
this);
250 interfaces.push_back(&
other);
258 for (
unsigned int i = 0;
i < interfaces.size();
i++)
259 accessors.push_back(&interfaces[
i]->accessor());
268 if (!
multi)
return nullptr;
269 std::vector<const Interface*> justOne;
270 justOne.push_back(
multi);
277 if (!
multi)
return nullptr;
278 std::vector<const Interface*> justOne;
279 justOne.push_back(
multi);
288 TObjArray*
list = filters.Tokenize(
",;");
289 if (
list->GetEntries() == 0) {
290 cout <<
"No filtering specified, exiting.";
295 for (
int k = 0;
k <
list->GetEntries();
k++) {
296 TObjString* tobs = (TObjString*)(
list->At(
k));
297 TObjArray*
items = tobs->String().Tokenize(
":");
298 if (
items->GetEntries() != 2) {
299 cout <<
"Invalid filter entry " << tobs->String() <<
", exiting." << endl;
304 TString
params = ((TObjString*)(
items->At(0)))->String();
305 TString
suffix = ((TObjString*)(
items->At(1)))->String();
308 cout <<
"---" << endl;
316 if (!tweak.
set(tweaks))
return 0;
319 if (!
multi)
return 0;
325 std::vector<MultiTreeAccessor*> filtered_mts = mt->
filterComponents(filterList, tweak);
326 if (filtered_mts.size() != filterList.
size()){
331 cout <<
"Component filtering done!" << endl;
335 for (
unsigned int f = 0;
f < filtered_mts.size();
f++) {
336 std::vector<TString>
files;
337 for (
unsigned int i = 0;
i < filtered_mts[
f]->nAccessors();
i++) {
339 cout <<
"Added " <<
files.back() << endl;
341 delete filtered_mts[
f];
344 std::vector<const Interface*> justOne;
345 justOne.push_back(filtered_multi);
357 if (!
f.set(
sel))
return nullptr;
360 if (!tweak.
set(tweaks))
return nullptr;
365 if (not pAccess)
return nullptr;
367 if (newFN !=
"") thisFN = std::move(newFN);
369 return filter(
f, tweak, thisFN);
378 return rootName +
"_" +
suffix +
".root";
402 return filter(
f, tw, newFileName);
415 if (
info->region() != region)
continue;
429 if (
info->feb() != feb)
continue;
444 if (
ft >= 0 &&
info->feedThrough() !=
ft)
continue;
445 if (slot >= 0 &&
info->slot() != slot)
continue;
458 if (!
f.set(
sel))
return nullptr;
460 std::vector<TString> vars;
461 std::vector<DataFuncSet> funcs;
462 std::vector<DataFuncArgs>
args;
464 cout <<
"Invalid variable specification " <<
var << endl;
468 TString
title = vars[0];
471 TH1D*
h =
m.dist(funcs[0],
args[0], vars[0],
nBins, xMin, xMax,
472 title, vars[0],
"digits",
f);
473 if (!
h)
return nullptr;
480 int nBinsY,
double yMin,
double yMax,
481 const TString&
sel,
const TString&
opt)
const
485 if (!
f.set(
sel))
return nullptr;
487 std::vector<TString> vars;
488 std::vector<DataFuncSet> funcs;
489 std::vector<DataFuncArgs>
args;
491 cout <<
"Invalid variable specification " <<
varList << endl;
495 TString
title = vars[1] +
" vs. " + vars[0];
498 TH2D*
h =
m.dist(funcs[0],
args[0], funcs[1],
args[1], vars[0] +
"_" + vars[1],
499 nBinsX, xMin, xMax, nBinsY, yMin, yMax,
500 title, vars[0], vars[1],
f);
501 if (!
h)
return nullptr;
508 const TString&
sel,
const TString&
opt,
513 if (!
f.set(
sel))
return nullptr;
515 std::vector<TString> vars;
516 std::vector<DataFuncSet> funcs;
517 std::vector<DataFuncArgs>
args;
519 cout <<
"Invalid variable specification " <<
var << endl;
528 if (!
h)
return nullptr;
535 const TString&
sel,
const TString&
opt,
540 if (!
f.set(
sel))
return nullptr;
542 std::vector<TString> vars;
543 std::vector<DataFuncSet> funcs;
544 std::vector<DataFuncArgs>
args;
546 cout <<
"Invalid variable specification " <<
var << endl;
554 if (!
h)
return nullptr;
564 if (!
f.set(
sel))
return 0;
573 if (!
f.set(
sel))
return 0;
581 if (!history)
return false;
589 if (!
f.set(
sel))
return false;
592 if (!history)
continue;
596 if (hDesc ==
"")
continue;
597 cout << Form(
"Hash = %-5d : ",
i) << hDesc
598 <<
"-----------------------------------------------------------------------------"
608 if (!
f.set(
sel))
return false;
609 std::map< std::pair<unsigned int, unsigned int>,
unsigned int > eventCells;
610 std::map< std::pair<unsigned int, unsigned int>,
double > eventEnergy;
614 if ((
i+1) % 50000 == 0) cout <<
"Cell # " <<
i+1 <<
"/" <<
nChannels() << endl;
616 if (!history)
continue;
617 for (
unsigned int j = 0; j < history->
nData(); j++) {
618 std::pair<unsigned int, unsigned int>
ev = std::make_pair(history->
data(j)->
run(), history->
data(j)->
event());
624 for (
unsigned int i = 0;
i <
nEvents();
i++) {
626 std::pair<unsigned int, unsigned int>
id(evtData->
run(), evtData->
event());
629 printout += Form(
" : %6d LAr hits, %7.1f MeV", eventCells[
id], eventEnergy[
id]);
630 cout << printout << endl;
639 std::map<unsigned int, unsigned int>
events;
646 for (
unsigned int i = 0;
i <
nRuns();
i++) {
650 printout += Form(
" : %6d events",
events[rData->
run()]);
651 cout << printout << endl;
662 if (!
f.set(
sel))
return 0;
664 std::vector<TString> vars;
665 std::vector<DataFuncSet> funcs;
666 std::vector<DataFuncArgs>
args;
668 cout <<
"Invalid variable specification " <<
varList << endl;
672 TVectorD
mean(vars.size()), meanErr(vars.size());
673 TMatrixD
covMatrix(vars.size(), vars.size()), covMatrixErr(vars.size(), vars.size());
677 cout <<
"---------------------------" << endl;
678 for (
unsigned int i = 0;
i < vars.size();
i++)
679 cout << Form(
"| %10s | %-9.4g |", vars[
i].
Data(),
mean(
i)) << endl;
680 cout <<
"---------------------------" << endl << endl;
683 for (
unsigned int i = 0;
i < vars.size();
i++) cout <<
" |";
684 cout << endl <<
"--------------";
685 for (
unsigned int i = 0;
i < vars.size();
i++) cout <<
"-------------";
687 for (
unsigned int i1 = 0; i1 < vars.size(); i1++) {
688 cout << Form(
"| %10s |", vars[i1].
Data());
689 for (
unsigned int i2 = 0; i2 < vars.size(); i2++)
690 cout << Form(
" %-9.4g |",
covMatrix(i1, i2));
693 cout <<
"--------------";
694 for (
unsigned int i = 0;
i < vars.size();
i++) cout <<
"-------------";
698 cout <<
"---------------------------" << endl;
699 for (
unsigned int i = 0;
i < vars.size();
i++)
700 cout << Form(
"| %10s | %-9.4g +/- %-9.4g |", vars[
i].
Data(),
mean(
i), meanErr(
i)) << endl;
701 cout <<
"---------------------------" << endl << endl;
704 for (
unsigned int i = 0;
i < vars.size();
i++) cout <<
" |";
705 cout << endl <<
"--------------";
706 for (
unsigned int i = 0;
i < vars.size();
i++) cout <<
"---------------------------";
708 for (
unsigned int i1 = 0; i1 < vars.size(); i1++) {
709 cout << Form(
"| %10s |", vars[i1].
Data());
710 for (
unsigned int i2 = 0; i2 < vars.size(); i2++)
711 cout << Form(
" %-9.4g +/- %-9.4g |",
covMatrix(i1, i2), covMatrixErr(i1, i2));
714 cout <<
"--------------";
715 for (
unsigned int i = 0;
i < vars.size();
i++) cout <<
"---------------------------";
727 if (!otherCell)
continue;
728 if (
cell.position().DeltaR(otherCell->
position()) > dRCut) {
delete otherCell;
continue; }
740 if (!
cell)
return true;
742 if (
layer < 0)
return true;
743 std::vector<unsigned int> allHashes;
751 if (
layer == -2) {
hashes = allHashes;
return true; }
752 for (
unsigned int h : allHashes) {
777 if (!history)
continue;
778 const Data* dataForEvent = history->data_for_event(
event);
779 if (dataForEvent)
data.push_back(
new Data(*dataForEvent));
787 std::vector<float*> floatVars;
788 std::vector<int*> intVars;
789 std::vector<std::vector<float>*> floatVects;
790 std::vector<std::vector<int>*> intVects;
791 std::map<TString, unsigned int> varIndex;
793 std::vector<TString> vars;
794 std::vector<DataFuncSet> funcs;
795 std::vector<DataFuncArgs>
args;
798 cout <<
"Making trees..." << endl;
800 TFile* flatFile = TFile::Open(
fileName +
"_tmpFlatFile.root",
"RECREATE");
801 TTree* flatTree =
new TTree(
"flatTree",
"Flat tree");
803 TFile* eventFile = TFile::Open(
fileName,
"RECREATE");
804 TTree* eventTree =
new TTree(
"eventTree",
"Event tree");
806 for (
unsigned int j = 0; j < vars.size(); j++) {
807 unsigned int index = 0;
808 if (funcs[j].isNull())
return false;
809 if (funcs[j].isInt()) {
810 int* varCont =
new int(0);
811 std::vector<int>* vectCont =
new std::vector<int>();
812 index = intVars.size();
813 intVars.push_back(varCont);
814 intVects.push_back(vectCont);
815 flatTree->Branch(vars[j], varCont);
816 eventTree->Branch(vars[j], vectCont);
819 float* varCont =
new float(0);
820 std::vector<float>* vectCont =
new std::vector<float>();
821 index = floatVars.size();
822 floatVars.push_back(varCont);
823 floatVects.push_back(vectCont);
824 flatTree->Branch(vars[j], varCont);
825 eventTree->Branch(vars[j], vectCont);
827 varIndex[vars[j]] =
index;
828 cout << vars[j] <<
" -> " <<
index << endl;
830 std::map< unsigned int, std::map< unsigned int, std::vector<long long> > > runEventIndices;
831 cout <<
"Making flat ntuple" << endl;
832 unsigned int count = 0;
836 if (
count % 100 == 0) cout <<
"Processing entry " <<
count <<
" (hash = " << iter.pos() <<
"), size = " <<
hist->nData() << endl;
837 for (
unsigned int k = 0;
k <
hist->nData();
k++) {
838 for (
unsigned int j = 0; j < vars.size(); j++) {
839 if (funcs[j].isInt())
840 *intVars[varIndex[vars[j]]] =
int(funcs[j].intVal(*
hist->data(
k),
args[j]));
842 *floatVars[varIndex[vars[j]]] = funcs[j].doubleVal(*
hist->data(
k),
args[j]);
844 runEventIndices[
hist->data(
k)->run()][
hist->data(
k)->event()].push_back(flatTree->GetEntries());
849 cout <<
"Making event tuple" << endl;
851 for (
const auto&
run : runEventIndices) {
853 cout <<
"Processing run " <<
run.first <<
" (" <<
runCount <<
" of " << runEventIndices.size() <<
")" << endl;
854 unsigned int eventCount = 0;
855 for (
const auto&
event :
run.second) {
857 if (eventCount % 1000 == 0)
858 cout <<
" processing event " <<
event.first <<
" (" << eventCount <<
" of " <<
run.second.size() <<
"), size = " <<
event.second.size() << endl;
859 for (
unsigned int j = 0; j < intVects.size(); j++) intVects[j]->
clear();
860 for (
unsigned int j = 0; j < floatVects.size(); j++) floatVects[j]->
clear();
862 flatTree->GetEntry(
index);
863 for (
unsigned int j = 0; j < vars.size(); j++) {
864 if (funcs[j].isInt())
865 intVects[varIndex[vars[j]]]->push_back(*intVars[varIndex[vars[j]]]);
867 floatVects[varIndex[vars[j]]]->push_back(*floatVars[varIndex[vars[j]]]);
874 cout <<
"Writing data..." << endl;
880 cout <<
"Cleaning up..." << endl;
886 for (
unsigned int j = 0; j < intVects.size(); j++)
delete intVects[j];
887 for (
unsigned int j = 0; j < floatVects.size(); j++)
delete floatVects[j];
888 for (
unsigned int j = 0; j < intVars.size(); j++)
delete intVars[j];
889 for (
unsigned int j = 0; j < floatVars.size(); j++)
delete floatVars[j];
891 cout <<
"Done!" << endl;