ATLAS Offline Software
Interface.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2021 CERN for the benefit of the ATLAS collaboration
3 */
4 
6 
10 #include "LArCafJobs/ShapeInfo.h"
11 #include "LArSamplesMon/Data.h"
12 #include "LArCafJobs/EventData.h"
13 #include "LArCafJobs/RunData.h"
18 #include "TObjString.h"
19 #include "TSystem.h"
20 #include "TObjArray.h"
21 #include "TObjString.h"
22 #include <iomanip>
23 #include <fstream>
24 #include <map>
25 
26 #include <iostream>
27 using std::cout;
28 using std::endl;
29 
30 using namespace LArSamples;
31 
32 
34 {
36  return (accessor ? new Interface(*accessor) : nullptr);
37 }
38 
39 
40 Interface* Interface::open(const std::vector<TString>& fileNames)
41 {
43  return (accessor ? new Interface(*accessor) : nullptr);
44 }
45 
46 
48 {
50  return (accessor ? new Interface(*accessor) : nullptr);
51 }
52 
53 
54 Interface* Interface::openWild(const TString& wcName)
55 {
57  return (accessor ? new Interface(*accessor) : nullptr);
58 }
59 
60 
62 {
64  delete m_accessor;
65 
66  for (std::vector<unsigned int>* neighbors : m_neighborCache)
67  delete neighbors;
68 }
69 
70 
72 {
75  m_ownShapeErrorGetter = false;
76 }
77 
78 
80 {
82  if (k == 0) { m_shapeErrorGetter = nullptr; m_ownShapeErrorGetter = false; return; }
84  m_ownShapeErrorGetter = true;
85 }
86 
87 
88 void Interface::setShapeError(const TString& fileName)
89 {
91 }
92 
93 
94 unsigned int Interface::size() const
95 {
96  unsigned int n = 0;
97  for (unsigned int i = 0; i < nChannels(); i++)
98  n += accessor().historySize(i);
99  return n;
100 }
101 
102 
103 const History* Interface::getCellHistory(unsigned int i) const
104 {
105  const History* history = accessor().getCellHistory(i);
106  if (history) {
108  history->setInterface(this);
109  }
110  return history;
111 }
112 
113 
114 const History* Interface::cellHistory(unsigned int i) const
115 {
116  const History* history = accessor().cellHistory(i);
117  if (history) {
119  history->setInterface(this);
120  }
121  return history;
122 }
123 
124 
125 const CellInfo* Interface::getCellInfo(unsigned int i) const
126 {
127  return accessor().getCellInfo(i);
128 }
129 
130 
131 unsigned int Interface::nFilledChannels() const
132 {
133  unsigned int n = 0;
134  for (unsigned int i = 0; i < nChannels(); i++)
135  n += (accessor().historySize(i) ? 1 : 0);
136  return n;
137 }
138 
139 
140 void Interface::printFilledRanges(unsigned int skip) const
141 {
142  int i1 = 0, i2 = 0;
143  unsigned int nNull = 0;
144  unsigned int size = accessor().historySize(0);
145  bool ok = (size > 0);
146  bool inInterval = ok;
147 
148  for (unsigned int i = 0; i < nChannels(); i++) {
149  size = accessor().historySize(i);
150  if (inInterval && nNull == 0) i2 = i;
151  bool ok = (size > 0);
152  if (!ok && inInterval) {
153  nNull++;
154  if (nNull > skip) {
155  nNull = 0;
156  inInterval = false;
157  cout << i1 << "-" << i2 << endl;
158  }
159  }
160  if (ok) nNull = 0;
161  if (ok && !inInterval) {
162  inInterval = true;
163  i1 = i;
164  }
165  }
166 
167  if (inInterval) cout << i1 << "-" << nChannels() << endl;
168 }
169 
170 
171 HistoryIterator Interface::begin(unsigned int pos, double eMin, double adcMaxMin) const
172 {
173  return HistoryIterator(*this, pos, eMin, adcMaxMin);
174 }
175 
176 
177 bool Interface::highEData(double eCut, TArrayI& hashes, TArrayI& indices) const
178 {
179  std::vector<unsigned int> hashV, indexV;
180  unsigned int nTot = 0;
181 
182  for (unsigned int i = 0; i < nChannels(); i++) {
183  const History* history = cellHistory(i);
184  if (!history) continue;
185  for (unsigned int j = 0; j < history->nData(); j++) {
186  const Data& data = *history->data(j);
187  nTot++;
188  if (data.isDisconnected()) continue;
189  if (nTot % 10000 == 0) cout << nTot << endl;
190  if (data.energy() > eCut) {
191  cout << "E = " << data.energy() << " " << i << " " << j << endl;
192  hashV.push_back(i);
193  indexV.push_back(j);
194  }
195  }
196  }
197 
198  hashes.Set(hashV.size());
199  indices.Set(indexV.size());
200 
201  for (unsigned int i = 0; i < hashV.size(); i++) {
202  hashes[i] = hashV[i];
203  indices[i] = indexV[i];
204  }
205 
206  cout << hashV.size() << "/" << nTot << endl;
207  return true;
208 }
209 
210 
211 bool Interface::isValid() const
212 {
213  for (unsigned int i = 0; i < nChannels(); i++) {
214  const History* history = cellHistory(i);
215  if (!history) continue;
216  if (!history->isValid()) {
217  cout << "Invalid LArSamplesHistory at hash = " << i << endl;
218  return false;
219  }
220  }
221 
222  return true;
223 }
224 
225 
226 Interface* Interface::merge(const Interface& other, const TString& fileName) const
227 {
228  std::vector<const Interface*> interfaces;
229  interfaces.push_back(this);
230  interfaces.push_back(&other);
231  return merge(interfaces, fileName);
232 }
233 
234 
235 Interface* Interface::merge(const std::vector<const Interface*>& interfaces, const TString& fileName)
236 {
237  std::vector<const Accessor*> accessors;
238  for (unsigned int i = 0; i < interfaces.size(); i++)
239  accessors.push_back(&interfaces[i]->accessor());
241  return new Interface(*newAccessor);
242 }
243 
244 Interface* Interface::merge(const Interface& other, const TString& fileName, const TString& LBFile) const
245 {
246  std::vector<const Interface*> interfaces;
247  interfaces.push_back(this);
248  interfaces.push_back(&other);
249  return merge(interfaces, fileName, LBFile);
250 }
251 
252 
253 Interface* Interface::merge(const std::vector<const Interface*>& interfaces, const TString& fileName, const TString& LBFile)
254 {
255  std::vector<const Accessor*> accessors;
256  for (unsigned int i = 0; i < interfaces.size(); i++)
257  accessors.push_back(&interfaces[i]->accessor());
258  TreeAccessor* newAccessor = TreeAccessor::merge(accessors, fileName, LBFile);
259  return new Interface(*newAccessor);
260 }
261 
262 
263 Interface* Interface::merge(const TString& listFileName, const TString& fileName)
264 {
265  Interface* multi = openList(listFileName);
266  if (!multi) return nullptr;
267  std::vector<const Interface*> justOne;
268  justOne.push_back(multi);
269  return merge(justOne, fileName);
270 }
271 
272 Interface* Interface::merge(const TString& listFileName, const TString& fileName, const TString& LBFile)
273 {
274  Interface* multi = openList(listFileName);
275  if (!multi) return nullptr;
276  std::vector<const Interface*> justOne;
277  justOne.push_back(multi);
278  return merge(justOne, fileName, LBFile);
279 }
280 
281 
282 bool Interface::filterAndMerge(const TString& listFileName, const TString& outFile, const TString& filters, const TString& tweaks)
283 {
284  FilterList filterList;
285 
286  TObjArray* list = filters.Tokenize(",;");
287  if (list->GetEntries() == 0) {
288  cout << "No filtering specified, exiting.";
289  delete list;
290  return 0;
291  }
292 
293  for (int k = 0; k < list->GetEntries(); k++) {
294  TObjString* tobs = (TObjString*)(list->At(k));
295  TObjArray* items = tobs->String().Tokenize(":");
296  if (items->GetEntries() != 2) {
297  cout << "Invalid filter entry " << tobs->String() << ", exiting." << endl;
298  delete list;
299  delete items;
300  return 0;
301  }
302  TString params = ((TObjString*)(items->At(0)))->String();
303  TString suffix = ((TObjString*)(items->At(1)))->String();
304  FilterParams f;
305  if (!f.set(params)) return 0;
306  cout << "---" << endl;
307  filterList.add(f, addSuffix(outFile, suffix));
308  delete items;
309  }
310  delete list;
311 
312 
313  DataTweaker tweak;
314  if (!tweak.set(tweaks)) return 0;
315 
316  Interface* multi = openList(listFileName);
317  if (!multi) return 0;
318  const MultiTreeAccessor* mt = dynamic_cast<const MultiTreeAccessor*>(&multi->accessor());
319  if (!mt) return 0;
320  std::vector<MultiTreeAccessor*> filtered_mts = mt->filterComponents(filterList, tweak);
321  if (filtered_mts.size() != filterList.size()) return 0;
322  delete multi;
323  cout << "Component filtering done!" << endl;
324  // The following line should work, but doesn't... so the block of code below replaces it.
325  //Interface* filtered_multi = new Interface(*filtered_mt);
326  //
327  for (unsigned int f = 0; f < filtered_mts.size(); f++) {
328  std::vector<TString> files;
329  for (unsigned int i = 0; i < filtered_mts[f]->nAccessors(); i++) {
330  files.push_back(((const TreeAccessor*)&filtered_mts[f]->accessor(i))->fileName());
331  cout << "Added " << files.back() << endl;
332  }
333  delete filtered_mts[f];
334  Interface* filtered_multi = open(files);
335  //
336  std::vector<const Interface*> justOne;
337  justOne.push_back(filtered_multi);
338  Interface* interface = merge(justOne, filterList.fileName(f));
339  delete interface;
340  }
341 
342  return true;
343 }
344 
345 
346 Interface* Interface::filter(const TString& sel, const TString& fileName, const TString& tweaks) const
347 {
348  FilterParams f;
349  if (!f.set(sel)) return nullptr;
350 
351  DataTweaker tweak;
352  if (!tweak.set(tweaks)) return nullptr;
353 
354  TString thisFN = fileName;
355  if (thisFN.Index(".root") < 0 && dynamic_cast<const TreeAccessor*>(&accessor())) {
356  TString newFN = addSuffix(dynamic_cast<const TreeAccessor*>(&accessor())->fileName(), fileName);
357  if (newFN != "") thisFN = newFN;
358  }
359  return filter(f, tweak, thisFN);
360 }
361 
362 
363 TString Interface::addSuffix(const TString& fileName, const TString& suffix)
364 {
365  TString rootName = fileName;
366  if (fileName(fileName.Length() - 5, 5) == ".root") rootName = fileName(0, fileName.Length() - 5);
367 
368  return rootName + "_" + suffix + ".root";
369 }
370 
371 
372 Interface* Interface::filter(const FilterParams& filterParams, const DataTweaker& tweaker, const TString& fileName) const
373 {
374  TreeAccessor* newAcc = TreeAccessor::filter(accessor(), filterParams, fileName, tweaker);
375  return new Interface(*newAcc);
376 }
377 
378 
380 {
382  return new Interface(*newAcc);
383 }
384 
385 
386 Interface* Interface::refit(const TString& newFileName, Chi2Params pars) const
387 {
388  FilterParams f;
389  DataTweaker tw;
390  tw.setRefit(true);
391  tw.setFitParams(pars);
392  return filter(f, tw, newFileName);
393 }
394 
395 
396 HistoryIterator Interface::findEtaPhi(CaloId calo, short layer, short iEta, short iPhi, short region) const
397 {
398  for (unsigned int i = 0; i < nChannels(); i++) {
399  const CellInfo* info = cellInfo(i);
400  if (!info) continue;
401  if (!Id::matchCalo(info->calo(), calo)) continue;
402  if (info->layer() != layer) continue;
403  if (info->iEta() != iEta) continue;
404  if (info->iPhi() != iPhi) continue;
405  if (info->region() != region) continue;
406  return HistoryIterator(*this, i);
407  }
408 
409  return HistoryIterator(*this, end());
410 }
411 
412 
414 {
415  for (unsigned int i = 0; i < nChannels(); i++) {
416  const CellInfo* info = cellInfo(i);
417  if (!info) continue;
418  if (!Id::matchCalo(info->calo(), calo)) continue;
419  if (info->feb() != feb) continue;
420  if (info->channel() != channel) continue;
421  return HistoryIterator(*this, i);
422  }
423 
424  return HistoryIterator(*this, end());
425 }
426 
427 
428 HistoryIterator Interface::findFTSlotChannel(CaloId calo, short ft, short slot, short channel) const
429 {
430  for (unsigned int i = 0; i < nChannels(); i++) {
431  const CellInfo* info = cellInfo(i);
432  if (!info) continue;
433  if (!Id::matchCalo(info->calo(), calo)) continue;
434  if (ft >= 0 && info->feedThrough() != ft) continue;
435  if (slot >= 0 && info->slot() != slot) continue;
436  if (channel >= 0 && info->channel() != channel) continue;
437  return HistoryIterator(*this, i);
438  }
439 
440  return HistoryIterator(*this, end());
441 }
442 
443 
444 TH1D* Interface::Draw(const TString& var, int nBins, double xMin, double xMax, const TString& sel, const TString& opt) const
445 {
446  MonitorBase m(*this);
447  FilterParams f;
448  if (!f.set(sel)) return nullptr;
449 
450  std::vector<TString> vars;
451  std::vector<DataFuncSet> funcs;
452  std::vector<DataFuncArgs> args;
453  if (!MonitorBase::parseVariables(var, vars, funcs, args) || funcs.size() != 1) {
454  cout << "Invalid variable specification " << var << endl;
455  return nullptr;
456  }
457 
458  TString title = vars[0];
459  if (TString(sel) != "") title = title + ", " + sel;
460 
461  TH1D* h = m.dist(funcs[0], args[0], vars[0], nBins, xMin, xMax,
462  title, vars[0], "digits", f);
463  if (!h) return nullptr;
464  h->Draw(opt);
465  return h;
466 }
467 
468 
469 TH2D* Interface::Draw(const TString& varList, int nBinsX, double xMin, double xMax,
470  int nBinsY, double yMin, double yMax,
471  const TString& sel, const TString& opt) const
472 {
473  MonitorBase m(*this);
474  FilterParams f;
475  if (!f.set(sel)) return nullptr;
476 
477  std::vector<TString> vars;
478  std::vector<DataFuncSet> funcs;
479  std::vector<DataFuncArgs> args;
480  if (!MonitorBase::parseVariables(varList, vars, funcs, args) || funcs.size() != 2) {
481  cout << "Invalid variable specification " << varList << endl;
482  return nullptr;
483  }
484 
485  TString title = vars[1] + " vs. " + vars[0];
486 
487  if (TString(sel) != "") title = title + ", " + sel;
488  TH2D* h = m.dist(funcs[0], args[0], funcs[1], args[1], vars[0] + "_" + vars[1],
489  nBinsX, xMin, xMax, nBinsY, yMin, yMax,
490  title, vars[0], vars[1], f);
491  if (!h) return nullptr;
492  h->Draw(opt);
493  return h;
494 }
495 
496 
498  const TString& sel, const TString& opt,
499  CombinationType comb) const
500 {
501  MonitorBase m(*this);
502  FilterParams f;
503  if (!f.set(sel)) return nullptr;
504 
505  std::vector<TString> vars;
506  std::vector<DataFuncSet> funcs;
507  std::vector<DataFuncArgs> args;
508  if (!MonitorBase::parseVariables(var, vars, funcs, args) || funcs.size() != 1) {
509  cout << "Invalid variable specification " << var << endl;
510  return nullptr;
511  }
512 
513  TString title = var;
514  title = title + ", " + Id::str(partition);
515  if (TString(sel) != "") title = title + ", " + sel;
516 
517  TH2D* h = m.partitionMap(funcs[0], args[0], var, partition, title, comb, f);
518  if (!h) return nullptr;
519  h->Draw(opt);
520  return h;
521 }
522 
523 
524 TH2D* Interface::DrawEtaPhi(CaloId calo, short layer, const TString& var,
525  const TString& sel, const TString& opt,
526  CombinationType comb) const
527 {
528  MonitorBase m(*this);
529  FilterParams f;
530  if (!f.set(sel)) return nullptr;
531 
532  std::vector<TString> vars;
533  std::vector<DataFuncSet> funcs;
534  std::vector<DataFuncArgs> args;
535  if (!MonitorBase::parseVariables(var, vars, funcs, args) || funcs.size() != 1) {
536  cout << "Invalid variable specification " << var << endl;
537  return nullptr;
538  }
539  TString title = var;
540  title += Form(", %s, layer %d", Id::str(calo).Data(), layer);
541  if (TString(sel) != "") title = title + ", " + sel;
542 
543  TH2D* h = m.etaPhiMap(funcs[0], args[0], var, calo, layer, title, comb, f);
544  if (!h) return nullptr;
545  h->Draw(opt);
546  return h;
547 }
548 
549 
550 bool Interface::Scan(const TString& vars, const TString& sel, unsigned int verbosity) const
551 {
552  MonitorBase m(*this);
553  FilterParams f;
554  if (!f.set(sel)) return 0;
555  return m.dump(vars, f, verbosity);
556 }
557 
558 
559 bool Interface::Scan(const TString& vars, CombinationType comb, const TString& sel, const TString& ranges, unsigned int verbosity) const
560 {
561  MonitorBase m(*this);
562  FilterParams f;
563  if (!f.set(sel)) return 0;
564  return m.dump(vars, comb, f, ranges, verbosity);
565 }
566 
567 
568 bool Interface::Show(unsigned int hash, unsigned int verbosity) const
569 {
570  const History* history = cellHistory(hash);
571  if (!history) return false;
572  cout << history->description(verbosity) << endl;
573  return true;
574 }
575 
576 bool Interface::Show(const TString& sel, unsigned int verbosity) const
577 {
578  FilterParams f;
579  if (!f.set(sel)) return false;
580  for (unsigned int i = 0; i < nChannels(); i++) {
581  const History* history = pass(i, f);
582  if (!history) continue;
583  History* filtered = history->filter(sel);
584  TString hDesc = filtered->description(verbosity);
585  delete filtered;
586  if (hDesc == "") continue;
587  cout << Form("Hash = %-5d : ", i) << hDesc
588  << "-----------------------------------------------------------------------------"
589  << endl;
590  }
591  return true;
592 }
593 
594 
595 bool Interface::ShowEvents(const TString& sel, unsigned int verbosity) const
596 {
597  FilterParams f;
598  if (!f.set(sel)) return false;
599  std::map< std::pair<unsigned int, unsigned int>, unsigned int > eventCells;
600  std::map< std::pair<unsigned int, unsigned int>, double > eventEnergy;
601 
602  if (verbosity & 8) {
603  for (unsigned int i = 0; i < nChannels(); i++) {
604  if ((i+1) % 50000 == 0) cout << "Cell # " << i+1 << "/" << nChannels() << endl;
605  const History* history = pass(i, f);
606  if (!history) continue;
607  for (unsigned int j = 0; j < history->nData(); j++) {
608  std::pair<unsigned int, unsigned int> ev = std::make_pair(history->data(j)->run(), history->data(j)->event());
609  eventCells[ev]++;
610  eventEnergy[ev] += history->data(j)->energy();
611  }
612  }
613  }
614  for (unsigned int i = 0; i < nEvents(); i++) {
615  const EventData* evtData = eventData(i);
616  std::pair<unsigned int, unsigned int> id(evtData->run(), evtData->event());
617  TString printout = Form("%d : ", i) + evtData->description(verbosity);
618  if (verbosity & 8)
619  printout += Form(" : %6d LAr hits, %7.1f MeV", eventCells[id], eventEnergy[id]);
620  cout << printout << endl;
621  }
622 
623  return true;
624 }
625 
626 
627 bool Interface::ShowRuns(unsigned int verbosity) const
628 {
629  std::map<unsigned int, unsigned int> events;
630 
631  if (verbosity & 8) {
632  for (unsigned int i = 0; i < nEvents(); i++)
633  events[eventData(i)->run()]++;
634  }
635 
636  for (unsigned int i = 0; i < nRuns(); i++) {
637  const RunData* rData = runData(i);
638  TString printout = rData->description(verbosity);
639  if (verbosity & 8)
640  printout += Form(" : %6d events", events[rData->run()]);
641  cout << printout << endl;
642  }
643 
644  return true;
645 }
646 
647 
648 bool Interface::ShowStats(const TString& varList, const TString& sel, bool withErrors) const
649 {
650  MonitorBase m(*this);
651  FilterParams f;
652  if (!f.set(sel)) return 0;
653 
654  std::vector<TString> vars;
655  std::vector<DataFuncSet> funcs;
656  std::vector<DataFuncArgs> args;
657  if (!MonitorBase::parseVariables(varList, vars, funcs, args)) {
658  cout << "Invalid variable specification " << varList << endl;
659  return 0;
660  }
661 
662  TVectorD mean(vars.size()), meanErr(vars.size());
663  TMatrixD covMatrix(vars.size(), vars.size()), covMatrixErr(vars.size(), vars.size());
664  if (!m.statParams(funcs, args, mean, meanErr, covMatrix, covMatrixErr, f)) return false;
665 
666  if (!withErrors) {
667  cout << "---------------------------" << endl;
668  for (unsigned int i = 0; i < vars.size(); i++)
669  cout << Form("| %10s | %-9.4g |", vars[i].Data(), mean(i)) << endl;
670  cout << "---------------------------" << endl << endl;
671 
672  cout << "| |";
673  for (unsigned int i = 0; i < vars.size(); i++) cout << " |";
674  cout << endl << "--------------";
675  for (unsigned int i = 0; i < vars.size(); i++) cout << "-------------";
676  cout << endl;
677  for (unsigned int i1 = 0; i1 < vars.size(); i1++) {
678  cout << Form("| %10s |", vars[i1].Data());
679  for (unsigned int i2 = 0; i2 < vars.size(); i2++)
680  cout << Form(" %-9.4g |", covMatrix(i1, i2));
681  cout << endl;
682  }
683  cout << "--------------";
684  for (unsigned int i = 0; i < vars.size(); i++) cout << "-------------";
685  cout << endl;
686  }
687  else {
688  cout << "---------------------------" << endl;
689  for (unsigned int i = 0; i < vars.size(); i++)
690  cout << Form("| %10s | %-9.4g +/- %-9.4g |", vars[i].Data(), mean(i), meanErr(i)) << endl;
691  cout << "---------------------------" << endl << endl;
692 
693  cout << "| |";
694  for (unsigned int i = 0; i < vars.size(); i++) cout << " |";
695  cout << endl << "--------------";
696  for (unsigned int i = 0; i < vars.size(); i++) cout << "---------------------------";
697  cout << endl;
698  for (unsigned int i1 = 0; i1 < vars.size(); i1++) {
699  cout << Form("| %10s |", vars[i1].Data());
700  for (unsigned int i2 = 0; i2 < vars.size(); i2++)
701  cout << Form(" %-9.4g +/- %-9.4g |", covMatrix(i1, i2), covMatrixErr(i1, i2));
702  cout << endl;
703  }
704  cout << "--------------";
705  for (unsigned int i = 0; i < vars.size(); i++) cout << "---------------------------";
706  cout << endl;
707  }
708 
709  return true;
710 }
711 
712 
713 bool Interface::neighbors(const CellInfo& cell, double dRCut, std::vector<unsigned int>& hashes) const
714 {
715  for (unsigned int i = 0; i < nChannels(); i++) {
716  const CellInfo* otherCell = cellInfo(i);
717  if (!otherCell) continue;
718  if (cell.position().DeltaR(otherCell->position()) > dRCut) { delete otherCell; continue; }
719  //cout << "Adding hash = " << i << " " << otherCell->location(3) << endl;
720  hashes.push_back(i);
721  delete otherCell;
722  }
723  return true;
724 }
725 
726 
727 bool Interface::firstNeighbors(unsigned int hash, std::vector<unsigned int>& hashes, short layer) const
728 {
729  const CellInfo* cell = cellInfo(hash);
730  if (!cell) return true;
731  if (!Id::matchCalo(cell->calo(), HEC)) return false; // for now!
732  if (layer < 0) return true;
733  std::vector<unsigned int> allHashes;
734  const std::vector<unsigned int>* cache = m_neighborCache[hash];
735  if (cache)
736  allHashes = *cache;
737  else {
738  if (!neighbors(*cell, 0.15, allHashes)) return false;
739  m_neighborCache[hash] = new std::vector<unsigned int>(allHashes);
740  }
741  if (layer == -2) { hashes = allHashes; return true; }
742  for (unsigned int h : allHashes) {
743  const CellInfo* info = cellInfo(h);
744  if (!info) continue;
745  if (info->layer() == layer) hashes.push_back(h);
746  delete info;
747  }
748  return true;
749 }
750 
751 
752 bool Interface::data(const std::vector<unsigned int>& hashes,const EventData& event, std::vector<const Data*>& data) const
753 {
754  if (hashes != m_neighborHistoryPos) {
755  for (const History* history : m_neighborHistories)
756  delete history;
757  m_neighborHistories.clear();
758  m_neighborHistoryPos.clear();
759  for (std::vector<unsigned int>::const_iterator hash = hashes.begin(); hash != hashes.end(); ++hash) {
760  const History* history = AbsLArCells::newCellHistory(*hash);// bypasses history caching in order not to invalidate cell
761  m_neighborHistories.push_back(history);
762  m_neighborHistoryPos.push_back(*hash);
763  }
764  }
765 
766  for (const History* history : m_neighborHistories) {
767  if (!history) continue;
768  const Data* dataForEvent = history->data_for_event(event);
769  if (dataForEvent) data.push_back(new Data(*dataForEvent));
770  }
771  return true;
772 }
773 
774 
775 bool Interface::dumpEventTuple(const TString& variables, const TString& fileName) const
776 {
777  std::vector<float*> floatVars;
778  std::vector<int*> intVars;
779  std::vector<std::vector<float>*> floatVects;
780  std::vector<std::vector<int>*> intVects;
781  std::map<TString, unsigned int> varIndex;
782 
783  std::vector<TString> vars;
784  std::vector<DataFuncSet> funcs;
785  std::vector<DataFuncArgs> args;
786  if (!MonitorBase::parseVariables(variables, vars, funcs, args)) return false;
787 
788  cout << "Making trees..." << endl;
789 
790  TFile* flatFile = TFile::Open(fileName + "_tmpFlatFile.root", "RECREATE");
791  TTree* flatTree = new TTree("flatTree", "Flat tree");
792 
793  TFile* eventFile = TFile::Open(fileName, "RECREATE");
794  TTree* eventTree = new TTree("eventTree", "Event tree");
795 
796  for (unsigned int j = 0; j < vars.size(); j++) {
797  unsigned int index = 0;
798  if (funcs[j].isNull()) return false;
799  if (funcs[j].isInt()) {
800  int* varCont = new int(0);
801  std::vector<int>* vectCont = new std::vector<int>();
802  index = intVars.size();
803  intVars.push_back(varCont);
804  intVects.push_back(vectCont);
805  flatTree->Branch(vars[j], varCont);
806  eventTree->Branch(vars[j], vectCont);
807  }
808  else {
809  float* varCont = new float(0);
810  std::vector<float>* vectCont = new std::vector<float>();
811  index = floatVars.size();
812  floatVars.push_back(varCont);
813  floatVects.push_back(vectCont);
814  flatTree->Branch(vars[j], varCont);
815  eventTree->Branch(vars[j], vectCont);
816  }
817  varIndex[vars[j]] = index;
818  cout << vars[j] << " -> " << index << endl;
819  }
820  std::map< unsigned int, std::map< unsigned int, std::vector<long long> > > runEventIndices;
821  cout << "Making flat ntuple" << endl;
822  unsigned int count = 0;
823  for (HistoryIterator iter = begin(); iter.isValid(); iter.next()) {
824  const History* hist = iter.history();
825  count++;
826  if (count % 100 == 0) cout << "Processing entry " << count << " (hash = " << iter.pos() << "), size = " << hist->nData() << endl;
827  for (unsigned int k = 0; k < hist->nData(); k++) {
828  for (unsigned int j = 0; j < vars.size(); j++) {
829  if (funcs[j].isInt())
830  *intVars[varIndex[vars[j]]] = int(funcs[j].intVal(*hist->data(k), args[j]));
831  else
832  *floatVars[varIndex[vars[j]]] = funcs[j].doubleVal(*hist->data(k), args[j]);
833  }
834  runEventIndices[hist->data(k)->run()][hist->data(k)->event()].push_back(flatTree->GetEntries());
835  flatTree->Fill();
836  }
837  }
838 
839  cout << "Making event tuple" << endl;
840  unsigned int runCount = 0;
841  for (const auto& run : runEventIndices) {
842  runCount++;
843  cout << "Processing run " << run.first << " (" << runCount << " of " << runEventIndices.size() << ")" << endl;
844  unsigned int eventCount = 0;
845  for (const auto& event : run.second) {
846  eventCount++;
847  if (eventCount % 1000 == 0)
848  cout << " processing event " << event.first << " (" << eventCount << " of " << run.second.size() << "), size = " << event.second.size() << endl;
849  for (unsigned int j = 0; j < intVects.size(); j++) intVects[j]->clear();
850  for (unsigned int j = 0; j < floatVects.size(); j++) floatVects[j]->clear();
851  for (long long index : event.second) {
852  flatTree->GetEntry(index);
853  for (unsigned int j = 0; j < vars.size(); j++) {
854  if (funcs[j].isInt())
855  intVects[varIndex[vars[j]]]->push_back(*intVars[varIndex[vars[j]]]);
856  else
857  floatVects[varIndex[vars[j]]]->push_back(*floatVars[varIndex[vars[j]]]);
858  }
859  }
860  eventTree->Fill();
861  }
862  }
863 
864  cout << "Writing data..." << endl;
865  flatFile->cd();
866  flatTree->Write();
867  eventFile->cd();
868  eventTree->Write();
869 
870  cout << "Cleaning up..." << endl;
871  delete eventTree;
872  delete eventFile;
873 
874  delete flatTree;
875  delete flatFile;
876  for (unsigned int j = 0; j < intVects.size(); j++) delete intVects[j];
877  for (unsigned int j = 0; j < floatVects.size(); j++) delete floatVects[j];
878  for (unsigned int j = 0; j < intVars.size(); j++) delete intVars[j];
879  for (unsigned int j = 0; j < floatVars.size(); j++) delete floatVars[j];
880 
881  cout << "Done!" << endl;
882  return true;
883 }
grepfile.info
info
Definition: grepfile.py:38
python.root_lsr_rank.hashes
hashes
Definition: root_lsr_rank.py:34
MultiTreeAccessor.h
RunData.h
TreeShapeErrorGetter.h
make_hlt_rep.pars
pars
Definition: make_hlt_rep.py:90
LArSamples::Interface::ShowEvents
bool ShowEvents(const TString &sel="", unsigned int verbosity=1) const
Definition: Interface.cxx:595
LArSamples::Interface::filterAndMerge
static bool filterAndMerge(const TString &listFileName, const TString &outFile, const TString &filters, const TString &tweaks="")
Definition: Interface.cxx:282
trigbs_pickEvents.ranges
ranges
Definition: trigbs_pickEvents.py:60
beamspotnt.var
var
Definition: bin/beamspotnt.py:1394
data
char data[hepevt_bytes_allocation_ATLAS]
Definition: HepEvt.cxx:11
LArSamples::Interface::printFilledRanges
void printFilledRanges(unsigned int skip=0) const
Definition: Interface.cxx:140
LArSamples::RunData::description
TString description(unsigned int verbosity) const
Definition: RunData.cxx:56
LArSamples::Interface::nRuns
unsigned int nRuns() const
Definition: Interface.h:52
LArSamples::Interface::ShowStats
bool ShowStats(const TString &varList, const TString &sel="", bool withErrors=false) const
Definition: Interface.cxx:648
python.CaloRecoConfig.f
f
Definition: CaloRecoConfig.py:127
LArSamples::HEC
@ HEC
Definition: CaloId.h:26
PlotCalibFromCool.ft
ft
Definition: PlotCalibFromCool.py:329
LArSamples::MultiTreeAccessor::openList
static MultiTreeAccessor * openList(const TString &fileList)
Definition: MultiTreeAccessor.cxx:42
mean
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="")
Definition: dependence.cxx:254
hotSpotInTAG.suffix
string suffix
Definition: hotSpotInTAG.py:186
python.SystemOfUnits.m
int m
Definition: SystemOfUnits.py:91
ReadCellNoiseFromCool.cell
cell
Definition: ReadCellNoiseFromCool.py:53
LArSamples::Id::matchCalo
static bool matchCalo(CaloId id, CaloId idSpec)
Definition: CaloId.cxx:188
LArSamples::AbsLArCells::newCellHistory
virtual const History * newCellHistory(unsigned int i) const
Definition: AbsLArCells.cxx:42
checkCoolLatestUpdate.variables
variables
Definition: checkCoolLatestUpdate.py:13
LArSamples::DataTweaker::setRefit
void setRefit(bool refit=true)
Definition: DataTweaker.h:40
plotting.yearwise_efficiency.channel
channel
Definition: yearwise_efficiency.py:28
LArSamples::FilterParams
Definition: FilterParams.h:50
checkxAOD.fileNames
fileNames
Definition: Tools/PyUtils/bin/checkxAOD.py:73
SimpleShape.h
LArSamples::Interface::Draw
TH1D * Draw(const TString &var, int nBins, double xMin, double xMax, const TString &sel="", const TString &opt="") const
Definition: Interface.cxx:444
LArSamples::HistoryIterator::isValid
bool isValid() const
Definition: HistoryIterator.cxx:32
CaloCellPos2Ntuple.int
int
Definition: CaloCellPos2Ntuple.py:24
LArSamples::Interface::findFTSlotChannel
HistoryIterator findFTSlotChannel(CaloId calo, short ft, short slot, short channel) const
Definition: Interface.cxx:428
LArSamples::EventData::event
int event() const
Definition: LArCalorimeter/LArCafJobs/LArCafJobs/EventData.h:44
LArSamples::AbsLArCells::cellHistory
virtual const History * cellHistory(unsigned int i) const
Definition: AbsLArCells.cxx:57
index
Definition: index.py:1
inInterval
bool inInterval(const cool::ValidityKey n, const cool::ValidityKey from, const cool::ValidityKey to)
Definition: openCoraCool.cxx:267
Data
@ Data
Definition: BaseObject.h:11
LArSamples::CombinationType
CombinationType
Definition: LArCalorimeter/LArSamplesMon/LArSamplesMon/MonitorBase.h:27
plotmaker.hist
hist
Definition: plotmaker.py:148
Trk::indices
std::pair< long int, long int > indices
Definition: AlSymMatBase.h:24
LArSamples::History
Definition: History.h:40
LArSamples::MultiTreeAccessor::filterComponents
std::vector< MultiTreeAccessor * > filterComponents(const FilterList &filterList, const DataTweaker &tweaker) const
Definition: MultiTreeAccessor.cxx:223
LArSamples::Interface::nEvents
unsigned int nEvents() const
Definition: Interface.h:51
LArSamples::Interface::size
unsigned int size() const
Definition: Interface.cxx:94
LArSamples::Interface::neighbors
bool neighbors(const CellInfo &cell, double dRCut, std::vector< unsigned int > &hashes) const
Definition: Interface.cxx:713
UniformShapeErrorGetter.h
LArSamples::Interface::Interface
Interface(const Accessor &accessor)
Constructor
Definition: Interface.h:41
LArSamples::Data::run
int run() const
Definition: Data.cxx:27
LArSamples::Id::str
static TString str(CaloId id)
Definition: CaloId.cxx:15
LArSamples::Interface::cellHistory
const History * cellHistory(unsigned int i) const
Definition: Interface.cxx:114
LArSamples::AbsLArCells::cellInfo
virtual const CellInfo * cellInfo(unsigned int i) const
Definition: AbsLArCells.cxx:69
CscCalibQuery.fileList
fileList
Definition: CscCalibQuery.py:330
LArSamples::Interface::nFilledChannels
unsigned int nFilledChannels() const
Definition: Interface.cxx:131
LArSamples::Interface::getCellHistory
const History * getCellHistory(unsigned int i) const
Definition: Interface.cxx:103
LArSamples::Interface::findFebChannel
HistoryIterator findFebChannel(CaloId calo, short feb, short channel) const
Definition: Interface.cxx:413
LArSamples
Definition: AbsShape.h:24
LArSamples::Interface::addSuffix
static TString addSuffix(const TString &fileName, const TString &suffix)
Definition: Interface.cxx:363
TreeAccessor.h
LArSamples::Chi2Params
Chi2Params
Definition: Chi2Calc.h:24
LArSamples::Interface::m_ownShapeErrorGetter
bool m_ownShapeErrorGetter
Definition: Interface.h:136
LArSamples::Interface::makeTemplate
Interface * makeTemplate(const TString &fileName) const
Definition: Interface.cxx:379
PlotCalibFromCool.multi
multi
Definition: PlotCalibFromCool.py:99
LArSamples::History::filter
History * filter(const TString &cuts) const
Definition: History.cxx:279
LArSamples::Interface::m_neighborCache
std::vector< std::vector< unsigned int > * > m_neighborCache
Definition: Interface.h:138
LArSamples::MultiTreeAccessor::open
static MultiTreeAccessor * open(const std::vector< TString > &files)
Definition: MultiTreeAccessor.cxx:25
FilterParams.h
python.DataFormatRates.events
events
Definition: DataFormatRates.py:105
LArSamples::AbsShapeErrorGetter
Definition: AbsShapeErrorGetter.h:23
XMLtoHeader.count
count
Definition: XMLtoHeader.py:85
LArSamples::Interface::end
unsigned int end() const
Definition: Interface.h:60
LArSamples::FilterList::add
void add(const FilterParams &params, const TString &fileName)
Definition: FilterList.h:27
LArSamples::Data::event
int event() const
Definition: Data.cxx:28
ShapeInfo.h
DataTweaker.h
LArSamples::Accessor::historySize
virtual unsigned int historySize(unsigned int i) const =0
LArSamples::RunData
Definition: RunData.h:21
LArSamples::History::data
const Data * data(unsigned int i) const
Definition: History.cxx:88
LArSamples::Interface::DrawPartition
TH2D * DrawPartition(PartitionId partition, const TString &var, const TString &sel="", const TString &opt="", CombinationType comb=TotalValue) const
Definition: Interface.cxx:497
LArSamples::History::setInterface
void setInterface(const Interface *interface) const
Definition: History.h:112
LArSamples::Interface::firstNeighbors
bool firstNeighbors(unsigned int hash, std::vector< unsigned int > &hashes, short layer=-2) const
Definition: Interface.cxx:727
LArSamples::Interface::findEtaPhi
HistoryIterator findEtaPhi(CaloId calo, short layer, short iEta, short iPhi, short region=0) const
Definition: Interface.cxx:396
LArSamples::Interface::accessor
const Accessor & accessor() const
Definition: Interface.h:93
FortranAlgorithmOptions.fileName
fileName
Definition: FortranAlgorithmOptions.py:13
LArSamples::MonitorBase::parseVariables
static bool parseVariables(TString varStr, std::vector< TString > &vars, std::vector< DataFuncSet > &funcs, std::vector< DataFuncArgs > &args)
Definition: LArCalorimeter/LArSamplesMon/src/MonitorBase.cxx:147
ev
int ev
Definition: globals.cxx:25
LArSamples::CellInfo::position
TVector3 position() const
Definition: CellInfo.cxx:204
event
POOL::TEvent event(POOL::TEvent::kClassAccess)
dqt_zlumi_pandas.err
err
Definition: dqt_zlumi_pandas.py:193
LArSamples::Interface::m_neighborHistories
std::vector< const History * > m_neighborHistories
Definition: Interface.h:140
lumiFormat.i
int i
Definition: lumiFormat.py:92
h
LArSamples::Interface::isValid
bool isValid() const
Definition: Interface.cxx:211
beamspotman.n
n
Definition: beamspotman.py:731
extractSporadic.h
list h
Definition: extractSporadic.py:97
LArSamples::MultiTreeAccessor::openWild
static MultiTreeAccessor * openWild(const TString &wcName)
Definition: MultiTreeAccessor.cxx:71
LArSamples::AbsLArCells::getCellInfo
virtual const CellInfo * getCellInfo(unsigned int i) const
Definition: AbsLArCells.cxx:86
LArSamples::Interface::m_neighborHistoryPos
std::vector< unsigned int > m_neighborHistoryPos
Definition: Interface.h:139
xAOD::covMatrix
covMatrix
Definition: TrackMeasurement_v1.cxx:19
TRT::Hit::layer
@ layer
Definition: HitInfo.h:79
LArSamples::History::setShapeErrorGetter
void setShapeErrorGetter(const AbsShapeErrorGetter *err) const
Definition: History.h:92
sel
sel
Definition: SUSYToolsTester.cxx:92
covarianceTool.title
title
Definition: covarianceTool.py:542
generateReferenceFile.files
files
Definition: generateReferenceFile.py:12
LArSamples::Interface::dumpEventTuple
bool dumpEventTuple(const TString &variables, const TString &fileName) const
Definition: Interface.cxx:775
LArSamples::Interface::eventData
const EventData * eventData(unsigned int i) const
Definition: Interface.h:54
LArSamples::TreeAccessor::makeTemplate
static TreeAccessor * makeTemplate(const Accessor &accessor, const TString &fileName)
Definition: TreeAccessor.cxx:425
LArSamples::EventData::run
int run() const
Definition: EventData.cxx:59
LArSamples::HistoryIterator
storage of the time histories of all the cells
Definition: HistoryIterator.h:20
LArSamples::PartitionId
PartitionId
Definition: CaloId.h:29
run
Definition: run.py:1
histSizes.list
def list(name, path='/')
Definition: histSizes.py:38
LArSamples::AbsLArCells::getCellHistory
virtual const History * getCellHistory(unsigned int i) const =0
LArSamples::DataTweaker
Definition: DataTweaker.h:23
LArSamples::History::nData
unsigned int nData() const
Definition: History.h:56
LArSamples::Interface::m_shapeErrorGetter
const AbsShapeErrorGetter * m_shapeErrorGetter
Definition: Interface.h:135
LArSamples::TreeAccessor::merge
static TreeAccessor * merge(const std::vector< const Accessor * > &accessors, const TString &fileName="")
Definition: TreeAccessor.cxx:73
EventData.h
LArSamples::Interface::DrawEtaPhi
TH2D * DrawEtaPhi(CaloId calo, short layer, const TString &var, const TString &sel="", const TString &opt="", CombinationType comb=TotalValue) const
Definition: Interface.cxx:524
LArSamples::Interface::getCellInfo
const CellInfo * getCellInfo(unsigned int i) const
Definition: Interface.cxx:125
LArSamples::DataTweaker::setFitParams
void setFitParams(Chi2Params params)
Definition: DataTweaker.h:41
DQPostProcessTest.outFile
outFile
Comment Out Those You do not wish to run.
Definition: DQPostProcessTest.py:37
LArSamples::Interface::ShowRuns
bool ShowRuns(unsigned int verbosity=1) const
Definition: Interface.cxx:627
LArSamples::FilterList
Definition: FilterList.h:21
LArSamples::Interface::~Interface
virtual ~Interface()
Definition: Interface.cxx:61
dumpTgcDigiJitter.nBins
list nBins
Definition: dumpTgcDigiJitter.py:29
LArSamples::AbsLArCells::pass
const History * pass(unsigned int i, const FilterParams &f) const
Definition: AbsLArCells.cxx:97
LArSamples::Interface::Scan
bool Scan(const TString &vars, const TString &sel="", unsigned int verbosity=1) const
Definition: Interface.cxx:550
LArSamples::Interface::open
static Interface * open(const TString &fileName)
Definition: Interface.cxx:33
id
SG::auxid_t id
Definition: Control/AthContainers/Root/debug.cxx:194
LArSamples::Data
Definition: Data.h:77
LArSamples::MultiTreeAccessor
Definition: MultiTreeAccessor.h:27
pmontree.opt
opt
Definition: pmontree.py:16
covarianceTool.verbosity
verbosity
Definition: covarianceTool.py:513
TrigJetMonitorAlgorithm.items
items
Definition: TrigJetMonitorAlgorithm.py:79
LArSamples::TreeShapeErrorGetter
Definition: TreeShapeErrorGetter.h:31
LArSamples::Interface::setShapeError
void setShapeError(double k)
Definition: Interface.cxx:79
LArSamples::CellInfo
Definition: CellInfo.h:31
LArSamples::CaloId
CaloId
Definition: CaloId.h:21
python.LumiBlobConversion.pos
pos
Definition: LumiBlobConversion.py:18
Trk::iPhi
@ iPhi
Definition: ParamDefs.h:53
LArSamples::Interface::merge
Interface * merge(const Interface &other, const TString &fileName) const
Definition: Interface.cxx:226
LArSamples::RunData::run
int run() const
Definition: RunData.h:36
LArSamples::TreeAccessor::filter
static TreeAccessor * filter(const Accessor &accessor, const FilterParams &filterParams, const TString &fileName, const DataTweaker &tweaker)
Definition: TreeAccessor.cxx:292
DeMoScan.index
string index
Definition: DeMoScan.py:362
InDetDD::other
@ other
Definition: InDetDD_Defs.h:16
VKalVrtAthena::varHolder_detail::clear
void clear(T &var)
Definition: NtupleVars.h:48
CaloCondBlobAlgs_fillNoiseFromASCII.hash
dictionary hash
Definition: CaloCondBlobAlgs_fillNoiseFromASCII.py:109
LArSamples::Interface::highEData
bool highEData(double eCut, TArrayI &hashes, TArrayI &indices) const
Definition: Interface.cxx:177
LArSamples::Interface::m_accessor
const Accessor * m_accessor
Definition: Interface.h:134
LArSamples::DataTweaker::set
bool set(const TString &tweaks)
Definition: DataTweaker.cxx:23
StateLessPT_NewConfig.partition
partition
Definition: StateLessPT_NewConfig.py:49
LArSamples::Interface::setShapeErrorGetter
void setShapeErrorGetter(const AbsShapeErrorGetter *err)
Definition: Interface.cxx:71
LArSamples::MonitorBase
Definition: LArCalorimeter/LArSamplesMon/LArSamplesMon/MonitorBase.h:30
LArSamples::Interface::refit
Interface * refit(const TString &newFileName, Chi2Params pars=DefaultChi2) const
Definition: Interface.cxx:386
LArSamples::Interface::data
bool data(const std::vector< unsigned int > &hashes, const EventData &event, std::vector< const Data * > &data) const
Definition: Interface.cxx:752
beamspotnt.varList
list varList
Definition: bin/beamspotnt.py:1108
LArSamples::Interface
Definition: Interface.h:36
Data.h
xAODRootTest.accessors
dictionary accessors
Definition: xAODRootTest.py:67
LArSamples::History::description
TString description(unsigned int verbosity=1) const
Definition: History.cxx:573
skip
bool skip
Definition: TrigGlobEffCorrValidation.cxx:190
PowhegControl_ttFCNC_NLO.params
params
Definition: PowhegControl_ttFCNC_NLO.py:226
LArSamples::Interface::openList
static Interface * openList(const TString &fileList)
Definition: Interface.cxx:47
LArSamples::History::isValid
bool isValid() const
Definition: History.cxx:149
LArSamples::TreeAccessor
Definition: TreeAccessor.h:32
LArSamples::Interface::filter
Interface * filter(const TString &sel, const TString &fileName, const TString &tweaks="") const
Definition: Interface.cxx:346
LArSamples::FilterList::size
unsigned int size() const
Definition: FilterList.h:29
xAOD::iEta
setScale setgFexType iEta
Definition: gFexJetRoI_v1.cxx:74
LArSamples::Interface::begin
HistoryIterator begin(unsigned int pos=0, double eMin=-1, double adcMaxMin=-1) const
Definition: Interface.cxx:171
Interface.h
LArSamples::EventData
Definition: LArCalorimeter/LArCafJobs/LArCafJobs/EventData.h:29
LArSamples::Interface::openWild
static Interface * openWild(const TString &wcName)
Definition: Interface.cxx:54
readCCLHist.float
float
Definition: readCCLHist.py:83
BeamSpotSummary.runCount
string runCount
Definition: BeamSpotSummary.py:50
LArSamples::Interface::Show
bool Show(unsigned int hash, unsigned int verbosity=1) const
Definition: Interface.cxx:568
LArSamples::AbsLArCells::nChannels
virtual unsigned int nChannels() const
Definition: AbsLArCells.h:34
python.CaloScaleNoiseConfig.args
args
Definition: CaloScaleNoiseConfig.py:80
merge
Definition: merge.py:1
LArSamples::Data::energy
double energy() const
Definition: Data.h:113
fitman.k
k
Definition: fitman.py:528
LArSamples::EventData::description
TString description(unsigned int verbosity) const
Definition: EventData.cxx:131
LArSamples::TreeAccessor::open
static TreeAccessor * open(const TString &fileName)
Definition: TreeAccessor.cxx:28
LArSamples::Interface::runData
const RunData * runData(unsigned int i) const
Definition: Interface.h:55
LArSamples::UniformShapeErrorGetter
Definition: UniformShapeErrorGetter.h:17