20#include "TObjString.h"
23#include "TObjString.h"
99 for (
unsigned int i = 0; i <
nChannels(); i++)
145 for (
unsigned int i = 0; i <
nChannels(); i++)
154 unsigned int nNull = 0;
156 bool ok = (
size > 0);
159 for (
unsigned int i = 0; i <
nChannels(); i++) {
162 bool ok = (
size > 0);
168 cout << i1 <<
"-" << i2 << endl;
190 std::vector<unsigned int> hashV, indexV;
191 unsigned int nTot = 0;
193 for (
unsigned int i = 0; i <
nChannels(); i++) {
195 if (!history)
continue;
196 for (
unsigned int j = 0; j < history->
nData(); j++) {
199 if (
data.isDisconnected())
continue;
200 if (nTot % 10000 == 0) cout << nTot << endl;
201 if (
data.energy() > eCut) {
202 cout <<
"E = " <<
data.energy() <<
" " << i <<
" " << j << endl;
209 hashes.Set(hashV.size());
210 indices.Set(indexV.size());
212 for (
unsigned int i = 0; i < hashV.size(); i++) {
213 hashes[i] = hashV[i];
214 indices[i] = indexV[i];
217 cout << hashV.size() <<
"/" << nTot << endl;
224 for (
unsigned int i = 0; i <
nChannels(); i++) {
226 if (!history)
continue;
228 cout <<
"Invalid LArSamplesHistory at hash = " << i << endl;
239 std::vector<const Interface*> interfaces;
240 interfaces.push_back(
this);
241 interfaces.push_back(&other);
242 return merge(interfaces, fileName);
248 std::vector<const Accessor*> accessors;
249 for (
unsigned int i = 0; i < interfaces.size(); i++)
250 accessors.push_back(&interfaces[i]->accessor());
257 std::vector<const Interface*> interfaces;
258 interfaces.push_back(
this);
259 interfaces.push_back(&other);
260 return merge(interfaces, fileName, LBFile);
266 std::vector<const Accessor*> accessors;
267 for (
unsigned int i = 0; i < interfaces.size(); i++)
268 accessors.push_back(&interfaces[i]->accessor());
277 if (!multi)
return nullptr;
278 std::vector<const Interface*> justOne;
279 justOne.push_back(multi);
280 return merge(justOne, fileName);
286 if (!multi)
return nullptr;
287 std::vector<const Interface*> justOne;
288 justOne.push_back(multi);
289 return merge(justOne, fileName, LBFile);
297 TObjArray* list = filters.Tokenize(
",;");
298 if (list->GetEntries() == 0) {
299 cout <<
"No filtering specified, exiting.";
304 for (
int k = 0; k < list->GetEntries(); k++) {
305 TObjString* tobs = (TObjString*)(list->At(k));
306 TObjArray* items = tobs->String().Tokenize(
":");
307 if (items->GetEntries() != 2) {
308 cout <<
"Invalid filter entry " << tobs->String() <<
", exiting." << endl;
313 TString params = ((TObjString*)(items->At(0)))->String();
314 TString suffix = ((TObjString*)(items->At(1)))->String();
316 if (!f.set(params))
return 0;
317 cout <<
"---" << endl;
325 if (!tweak.
set(tweaks))
return 0;
328 if (!multi)
return 0;
334 std::vector<MultiTreeAccessor*> filtered_mts = mt->
filterComponents(filterList, tweak);
335 if (filtered_mts.size() != filterList.
size()){
340 cout <<
"Component filtering done!" << endl;
344 for (
unsigned int f = 0; f < filtered_mts.size(); f++) {
345 std::vector<TString>
files;
346 for (
unsigned int i = 0; i < filtered_mts[f]->nAccessors(); i++) {
348 cout <<
"Added " <<
files.back() << endl;
350 delete filtered_mts[f];
353 std::vector<const Interface*> justOne;
354 justOne.push_back(filtered_multi);
366 if (!f.set(
sel))
return nullptr;
369 if (!tweak.
set(tweaks))
return nullptr;
371 TString thisFN = fileName;
374 if (not pAccess)
return nullptr;
375 TString newFN =
addSuffix(pAccess->fileName(), fileName);
376 if (newFN !=
"") thisFN = std::move(newFN);
378 return filter(f, tweak, thisFN);
384 TString rootName = fileName;
385 if (fileName(fileName.Length() - 5, 5) ==
".root") rootName = fileName(0, fileName.Length() - 5);
387 return rootName +
"_" + suffix +
".root";
411 return filter(f, tw, newFileName);
417 for (
unsigned int i = 0; i <
nChannels(); i++) {
421 if (info->layer() != layer)
continue;
422 if (info->iEta() != iEta)
continue;
423 if (info->iPhi() != iPhi)
continue;
424 if (info->region() != region)
continue;
434 for (
unsigned int i = 0; i <
nChannels(); i++) {
438 if (info->feb() != feb)
continue;
439 if (info->channel() != channel)
continue;
449 for (
unsigned int i = 0; i <
nChannels(); i++) {
453 if (ft >= 0 && info->feedThrough() != ft)
continue;
454 if (slot >= 0 && info->slot() != slot)
continue;
455 if (channel >= 0 && info->channel() != channel)
continue;
463TH1D*
Interface::Draw(
const TString& var,
int nBins,
double xMin,
double xMax,
const TString&
sel,
const TString& opt)
const
467 if (!f.set(
sel))
return nullptr;
469 std::vector<TString> vars;
470 std::vector<DataFuncSet> funcs;
471 std::vector<DataFuncArgs> args;
473 cout <<
"Invalid variable specification " << var << endl;
477 TString title = vars[0];
478 if (TString(
sel) !=
"") title = title +
", " +
sel;
480 TH1D*
h = m.dist(funcs[0], args[0], vars[0], nBins, xMin, xMax,
481 title, vars[0],
"digits", f);
482 if (!
h)
return nullptr;
489 int nBinsY,
double yMin,
double yMax,
490 const TString&
sel,
const TString& opt)
const
494 if (!f.set(
sel))
return nullptr;
496 std::vector<TString> vars;
497 std::vector<DataFuncSet> funcs;
498 std::vector<DataFuncArgs> args;
500 cout <<
"Invalid variable specification " << varList << endl;
504 TString title = vars[1] +
" vs. " + vars[0];
506 if (TString(
sel) !=
"") title = title +
", " +
sel;
507 TH2D*
h = m.dist(funcs[0], args[0], funcs[1], args[1], vars[0] +
"_" + vars[1],
508 nBinsX, xMin, xMax, nBinsY, yMin, yMax,
509 title, vars[0], vars[1], f);
510 if (!
h)
return nullptr;
517 const TString&
sel,
const TString& opt,
522 if (!f.set(
sel))
return nullptr;
524 std::vector<TString> vars;
525 std::vector<DataFuncSet> funcs;
526 std::vector<DataFuncArgs> args;
528 cout <<
"Invalid variable specification " << var << endl;
533 title = title +
", " +
Id::str(partition);
534 if (TString(
sel) !=
"") title = title +
", " +
sel;
536 TH2D*
h = m.partitionMap(funcs[0], args[0], var, partition, title, comb, f);
537 if (!
h)
return nullptr;
544 const TString&
sel,
const TString& opt,
549 if (!f.set(
sel))
return nullptr;
551 std::vector<TString> vars;
552 std::vector<DataFuncSet> funcs;
553 std::vector<DataFuncArgs> args;
555 cout <<
"Invalid variable specification " << var << endl;
559 title += Form(
", %s, layer %d",
Id::str(calo).
Data(), layer);
560 if (TString(
sel) !=
"") title = title +
", " +
sel;
562 TH2D*
h = m.etaPhiMap(funcs[0], args[0], var, calo, layer, title, comb, f);
563 if (!
h)
return nullptr;
573 if (!f.set(
sel))
return 0;
574 return m.dump(vars, f, verbosity);
582 if (!f.set(
sel))
return 0;
583 return m.dump(vars, comb, f, ranges, verbosity);
590 if (!history)
return false;
598 if (!f.set(
sel))
return false;
599 for (
unsigned int i = 0; i <
nChannels(); i++) {
601 if (!history)
continue;
605 if (hDesc ==
"")
continue;
606 cout << Form(
"Hash = %-5d : ", i) << hDesc
607 <<
"-----------------------------------------------------------------------------"
617 if (!f.set(
sel))
return false;
618 std::map< std::pair<unsigned int, unsigned int>,
unsigned int > eventCells;
619 std::map< std::pair<unsigned int, unsigned int>,
double > eventEnergy;
622 for (
unsigned int i = 0; i <
nChannels(); i++) {
623 if ((i+1) % 50000 == 0) cout <<
"Cell # " << i+1 <<
"/" <<
nChannels() << endl;
625 if (!history)
continue;
626 for (
unsigned int j = 0; j < history->
nData(); j++) {
627 std::pair<unsigned int, unsigned int>
ev = std::make_pair(history->
data(j)->
run(), history->
data(j)->
event());
633 for (
unsigned int i = 0; i <
nEvents(); i++) {
635 std::pair<unsigned int, unsigned int> id(evtData->
run(), evtData->
event());
636 TString printout = Form(
"%d : ", i) + evtData->
description(verbosity);
638 printout += Form(
" : %6d LAr hits, %7.1f MeV", eventCells[
id], eventEnergy[
id]);
639 cout << printout << endl;
648 std::map<unsigned int, unsigned int> events;
651 for (
unsigned int i = 0; i <
nEvents(); i++)
655 for (
unsigned int i = 0; i <
nRuns(); i++) {
659 printout += Form(
" : %6d events", events[rData->
run()]);
660 cout << printout << endl;
671 if (!f.set(
sel))
return 0;
673 std::vector<TString> vars;
674 std::vector<DataFuncSet> funcs;
675 std::vector<DataFuncArgs> args;
677 cout <<
"Invalid variable specification " << varList << endl;
681 TVectorD
mean(vars.size()), meanErr(vars.size());
682 TMatrixD covMatrix(vars.size(), vars.size()), covMatrixErr(vars.size(), vars.size());
683 if (!m.statParams(funcs, args,
mean, meanErr, covMatrix, covMatrixErr, f))
return false;
686 cout <<
"---------------------------" << endl;
687 for (
unsigned int i = 0; i < vars.size(); i++)
688 cout << Form(
"| %10s | %-9.4g |", vars[i].
Data(),
mean(i)) << endl;
689 cout <<
"---------------------------" << endl << endl;
692 for (
unsigned int i = 0; i < vars.size(); i++) cout <<
" |";
693 cout << endl <<
"--------------";
694 for (
unsigned int i = 0; i < vars.size(); i++) cout <<
"-------------";
696 for (
unsigned int i1 = 0; i1 < vars.size(); i1++) {
697 cout << Form(
"| %10s |", vars[i1].
Data());
698 for (
unsigned int i2 = 0; i2 < vars.size(); i2++)
699 cout << Form(
" %-9.4g |", covMatrix(i1, i2));
702 cout <<
"--------------";
703 for (
unsigned int i = 0; i < vars.size(); i++) cout <<
"-------------";
707 cout <<
"---------------------------" << endl;
708 for (
unsigned int i = 0; i < vars.size(); i++)
709 cout << Form(
"| %10s | %-9.4g +/- %-9.4g |", vars[i].
Data(),
mean(i), meanErr(i)) << endl;
710 cout <<
"---------------------------" << endl << endl;
713 for (
unsigned int i = 0; i < vars.size(); i++) cout <<
" |";
714 cout << endl <<
"--------------";
715 for (
unsigned int i = 0; i < vars.size(); i++) cout <<
"---------------------------";
717 for (
unsigned int i1 = 0; i1 < vars.size(); i1++) {
718 cout << Form(
"| %10s |", vars[i1].
Data());
719 for (
unsigned int i2 = 0; i2 < vars.size(); i2++)
720 cout << Form(
" %-9.4g +/- %-9.4g |", covMatrix(i1, i2), covMatrixErr(i1, i2));
723 cout <<
"--------------";
724 for (
unsigned int i = 0; i < vars.size(); i++) cout <<
"---------------------------";
734 for (
unsigned int i = 0; i <
nChannels(); i++) {
736 if (!otherCell)
continue;
737 if (cell.position().DeltaR(otherCell->
position()) > dRCut) {
delete otherCell;
continue; }
749 if (!cell)
return true;
751 if (layer < 0)
return true;
752 std::vector<unsigned int> allHashes;
757 if (!
neighbors(*cell, 0.15, allHashes))
return false;
760 for (
unsigned int h : allHashes) {
763 if (info->layer() == layer) hashes.push_back(
h);
777 for (std::vector<unsigned int>::const_iterator hash = hashes.begin(); hash != hashes.end(); ++hash) {
785 if (!history)
continue;
786 const Data* dataForEvent = history->data_for_event(event);
787 if (dataForEvent)
data.push_back(
new Data(*dataForEvent));
795 std::vector<float*> floatVars;
796 std::vector<int*> intVars;
797 std::vector<std::vector<float>*> floatVects;
798 std::vector<std::vector<int>*> intVects;
799 std::map<TString, unsigned int> varIndex;
801 std::vector<TString> vars;
802 std::vector<DataFuncSet> funcs;
803 std::vector<DataFuncArgs> args;
806 cout <<
"Making trees..." << endl;
808 TFile* flatFile = TFile::Open(fileName +
"_tmpFlatFile.root",
"RECREATE");
809 TTree* flatTree =
new TTree(
"flatTree",
"Flat tree");
811 TFile* eventFile = TFile::Open(fileName,
"RECREATE");
812 TTree* eventTree =
new TTree(
"eventTree",
"Event tree");
814 for (
unsigned int j = 0; j < vars.size(); j++) {
815 unsigned int index = 0;
816 if (funcs[j].isNull())
return false;
817 if (funcs[j].isInt()) {
818 int* varCont =
new int(0);
819 std::vector<int>* vectCont =
new std::vector<int>();
820 index = intVars.size();
821 intVars.push_back(varCont);
822 intVects.push_back(vectCont);
823 flatTree->Branch(vars[j], varCont);
824 eventTree->Branch(vars[j], vectCont);
827 float* varCont =
new float(0);
828 std::vector<float>* vectCont =
new std::vector<float>();
829 index = floatVars.size();
830 floatVars.push_back(varCont);
831 floatVects.push_back(vectCont);
832 flatTree->Branch(vars[j], varCont);
833 eventTree->Branch(vars[j], vectCont);
835 varIndex[vars[j]] =
index;
836 cout << vars[j] <<
" -> " <<
index << endl;
838 std::map< unsigned int, std::map< unsigned int, std::vector<long long> > > runEventIndices;
839 cout <<
"Making flat ntuple" << endl;
840 unsigned int count = 0;
842 const History* hist = iter.history();
844 if (
count % 100 == 0) cout <<
"Processing entry " <<
count <<
" (hash = " << iter.pos() <<
"), size = " << hist->nData() << endl;
845 for (
unsigned int k = 0; k < hist->nData(); k++) {
846 for (
unsigned int j = 0; j < vars.size(); j++) {
847 if (funcs[j].isInt())
848 *intVars[varIndex[vars[j]]] = int(funcs[j].intVal(*hist->data(k), args[j]));
850 *floatVars[varIndex[vars[j]]] = funcs[j].doubleVal(*hist->data(k), args[j]);
852 runEventIndices[hist->data(k)->run()][hist->data(k)->event()].push_back(flatTree->GetEntries());
857 cout <<
"Making event tuple" << endl;
858 unsigned int runCount = 0;
859 for (
const auto&
run : runEventIndices) {
861 cout <<
"Processing run " <<
run.first <<
" (" << runCount <<
" of " << runEventIndices.size() <<
")" << endl;
862 unsigned int eventCount = 0;
863 for (
const auto& event :
run.second) {
865 if (eventCount % 1000 == 0)
866 cout <<
" processing event " <<
event.first <<
" (" << eventCount <<
" of " <<
run.second.size() <<
"), size = " <<
event.second.size() << endl;
867 for (
unsigned int j = 0; j < intVects.size(); j++) intVects[j]->clear();
868 for (
unsigned int j = 0; j < floatVects.size(); j++) floatVects[j]->clear();
869 for (
long long index : event.second) {
870 flatTree->GetEntry(
index);
871 for (
unsigned int j = 0; j < vars.size(); j++) {
872 if (funcs[j].isInt())
873 intVects[varIndex[vars[j]]]->push_back(*intVars[varIndex[vars[j]]]);
875 floatVects[varIndex[vars[j]]]->push_back(*floatVars[varIndex[vars[j]]]);
882 cout <<
"Writing data..." << endl;
888 cout <<
"Cleaning up..." << endl;
894 for (
unsigned int j = 0; j < intVects.size(); j++)
delete intVects[j];
895 for (
unsigned int j = 0; j < floatVects.size(); j++)
delete floatVects[j];
896 for (
unsigned int j = 0; j < intVars.size(); j++)
delete intVars[j];
897 for (
unsigned int j = 0; j < floatVars.size(); j++)
delete floatVars[j];
899 cout <<
"Done!" << endl;
virtual unsigned int nChannels() const
virtual const CellInfo * getCellInfo(unsigned int i) const
const History * pass(unsigned int i, const FilterParams &f) const
virtual const History * cellHistory(unsigned int i) const
virtual const History * getSCHistory(unsigned int i) const =0
virtual const History * newCellHistory(unsigned int i) const
virtual const History * getCellHistory(unsigned int i) const =0
virtual const CellInfo * cellInfo(unsigned int i) const
virtual unsigned int historySize(unsigned int i) const =0
TVector3 position() const
void setRefit(bool refit=true)
void setFitParams(Chi2Params params)
bool set(const TString &tweaks)
TString description(unsigned int verbosity) const
void add(const FilterParams ¶ms, const TString &fileName)
unsigned int size() const
storage of the time histories of all the cells
TString description(unsigned int verbosity=1) const
const Data * data(unsigned int i) const
void setShapeErrorGetter(const AbsShapeErrorGetter *err) const
History * filter(const TString &cuts) const
unsigned int nData() const
void setInterface(const Interface *interface) const
static TString str(CaloId id)
static bool matchCalo(CaloId id, CaloId idSpec)
Interface * refit(const TString &newFileName, Chi2Params pars=DefaultChi2) const
static Interface * open(const TString &fileName)
Interface * makeTemplate(const TString &fileName) const
const Accessor & accessor() const
const AbsShapeErrorGetter * m_shapeErrorGetter
static Interface * openWild(const TString &wcName)
Interface * filter(const TString &sel, const TString &fileName, const TString &tweaks="") const
bool ShowRuns(unsigned int verbosity=1) const
unsigned int nRuns() const
Interface(const Accessor &accessor)
Constructor.
std::vector< unsigned int > m_neighborHistoryPos
static bool filterAndMerge(const TString &listFileName, const TString &outFile, const TString &filters, const TString &tweaks="")
TH2D * DrawPartition(PartitionId partition, const TString &var, const TString &sel="", const TString &opt="", CombinationType comb=TotalValue) const
HistoryIterator findEtaPhi(CaloId calo, short layer, short iEta, short iPhi, short region=0) const
bool highEData(double eCut, TArrayI &hashes, TArrayI &indices) const
bool firstNeighbors(unsigned int hash, std::vector< unsigned int > &hashes, short layer=-2) const
const CellInfo * getCellInfo(unsigned int i) const
Interface * merge(const Interface &other, const TString &fileName) const
bool neighbors(const CellInfo &cell, double dRCut, std::vector< unsigned int > &hashes) const
void printFilledRanges(unsigned int skip=0) const
bool ShowEvents(const TString &sel="", unsigned int verbosity=1) const
bool m_ownShapeErrorGetter
std::vector< std::vector< unsigned int > * > m_neighborCache
unsigned int nFilledChannels() const
TH2D * DrawEtaPhi(CaloId calo, short layer, const TString &var, const TString &sel="", const TString &opt="", CombinationType comb=TotalValue) const
unsigned int size() const
HistoryIterator begin(unsigned int pos=0, double eMin=-1, double adcMaxMin=-1) const
bool Scan(const TString &vars, const TString &sel="", unsigned int verbosity=1) const
bool ShowStats(const TString &varList, const TString &sel="", bool withErrors=false) const
bool data(const std::vector< unsigned int > &hashes, const EventData &event, std::vector< const Data * > &data) const
const Accessor * m_accessor
const EventData * eventData(unsigned int i) const
void setShapeError(double k)
const History * getCellHistory(unsigned int i) const
std::vector< const History * > m_neighborHistories
static TString addSuffix(const TString &fileName, const TString &suffix)
HistoryIterator findFTSlotChannel(CaloId calo, short ft, short slot, short channel) const
const History * getSCHistory(unsigned int i) const
HistoryIterator findFebChannel(CaloId calo, short feb, short channel) const
TH1D * Draw(const TString &var, int nBins, double xMin, double xMax, const TString &sel="", const TString &opt="") const
unsigned int nEvents() const
void setShapeErrorGetter(const AbsShapeErrorGetter *err)
unsigned int historySize(unsigned int i) const
bool dumpEventTuple(const TString &variables, const TString &fileName) const
const History * cellHistory(unsigned int i) const
static Interface * openList(const TString &fileList)
bool Show(unsigned int hash, unsigned int verbosity=1) const
const RunData * runData(unsigned int i) const
static bool parseVariables(TString varStr, std::vector< TString > &vars, std::vector< DataFuncSet > &funcs, std::vector< DataFuncArgs > &args)
static MultiTreeAccessor * openList(const TString &fileList)
std::vector< MultiTreeAccessor * > filterComponents(const FilterList &filterList, const DataTweaker &tweaker) const
static MultiTreeAccessor * open(const std::vector< TString > &files)
static MultiTreeAccessor * openWild(const TString &wcName)
TString description(unsigned int verbosity) const
static TreeAccessor * makeTemplate(const Accessor &accessor, const TString &fileName)
static TreeAccessor * filter(const Accessor &accessor, const FilterParams &filterParams, const TString &fileName, const DataTweaker &tweaker)
static TreeAccessor * merge(const std::vector< const Accessor * > &accessors, const TString &fileName="")
static TreeAccessor * open(const TString &fileName)
void mean(std::vector< double > &bins, std::vector< double > &values, const std::vector< std::string > &files, const std::string &histname, const std::string &tplotname, const std::string &label="")
std::vector< std::string > files
file names and file pointers
int count(std::string s, const std::string ®x)
count how many occurances of a regx are in a string
bool inInterval(const cool::ValidityKey n, const cool::ValidityKey from, const cool::ValidityKey to)