CMS 3D CMS Logo

List of all members | Public Member Functions | Private Member Functions | Private Attributes
validation.Validation Class Reference
Inheritance diagram for validation.Validation:
vertexPlots.VertexValidation

Public Member Functions

def __init__ (self, fullsimSamples, fastsimSamples, refRelease, refRepository, newRelease, newRepository, newFileModifier=None, selectionName="")
 
def createHtmlReport (self)
 
def doPlots (self, plotter, plotterDrawArgs={}, limitSubFoldersOnlyTo=None, htmlReport=html.HtmlReportDummy(), doFastVsFull=True, doPhase2PU=False)
 
def download (self)
 

Private Member Functions

def _doFastsimFastVsFullPlots (self, limitSubFoldersOnlyTo, htmlReport)
 
def _doPhase2PileupPlots (self, limitSubFoldersOnlyTo, htmlReport)
 
def _doPlots (self, sample, harvestedFile, plotterFolder, dqmSubFolder, htmlReport)
 
def _doPlotsFastFull (self, fastSample, fullSample, plotterFolder, dqmSubFolder, htmlReport)
 
def _doPlotsPileup (self, pu140Sample, pu200Sample, plotterFolder, dqmSubFolder, htmlReport)
 
def _getDirectoryName (self, args, kwargs)
 
def _getRefFileAndSelection (self, sample, plotterFolder, dqmSubFolder, selectionNameBase, valname)
 
def _getSelectionName (self, args, kwargs)
 

Private Attributes

 _fastsimSamples
 
 _fullsimSamples
 
 _newBaseDir
 
 _newFileModifier
 
 _newRelease
 
 _plotter
 
 _plotterDrawArgs
 
 _refRelease
 
 _refRepository
 
 _selectionName
 

Detailed Description

Base class for Tracking/Vertex validation.

Definition at line 683 of file validation.py.

Constructor & Destructor Documentation

◆ __init__()

def validation.Validation.__init__ (   self,
  fullsimSamples,
  fastsimSamples,
  refRelease,
  refRepository,
  newRelease,
  newRepository,
  newFileModifier = None,
  selectionName = "" 
)
Constructor.

Arguments:
fullsimSamples -- List of Sample objects for FullSim samples (may be empty)
fastsimSamples -- List of Sample objects for FastSim samples (may be empty)
refRelease    -- String for reference CMSSW release (can be None for no reference release)
newRepository -- String for directory whete to put new files
newRelease     -- CMSSW release to be validated
refRepository  -- String for directory where reference root files are
newFileModifier -- If given, a function to modify the names of the new files (function takes a string and returns a string)
selectionName  -- If given, use this string as the selection name (appended to GlobalTag for directory names)

Definition at line 685 of file validation.py.

Referenced by vertexPlots.VertexValidation._init__().

685  def __init__(self, fullsimSamples, fastsimSamples, refRelease, refRepository, newRelease, newRepository, newFileModifier=None, selectionName=""):
686  """Constructor.
687 
688  Arguments:
689  fullsimSamples -- List of Sample objects for FullSim samples (may be empty)
690  fastsimSamples -- List of Sample objects for FastSim samples (may be empty)
691  refRelease -- String for reference CMSSW release (can be None for no reference release)
692  newRepository -- String for directory whete to put new files
693  newRelease -- CMSSW release to be validated
694  refRepository -- String for directory where reference root files are
695  newFileModifier -- If given, a function to modify the names of the new files (function takes a string and returns a string)
696  selectionName -- If given, use this string as the selection name (appended to GlobalTag for directory names)
697  """
698  try:
699  self._newRelease = os.environ["CMSSW_VERSION"]
700  except KeyError:
701  print('Error: CMSSW environment variables are not available.', file=sys.stderr)
702  print(' Please run cmsenv', file=sys.stderr)
703  sys.exit()
704 
705  self._fullsimSamples = fullsimSamples
706  self._fastsimSamples = fastsimSamples
707  self._refRelease = refRelease
708  self._refRepository = refRepository
709  self._newRelease = newRelease
710  self._newBaseDir = os.path.join(newRepository, self._newRelease)
711  self._newFileModifier = newFileModifier
712  self._selectionName = selectionName
713 
def __init__(self, dataset, job_number, job_id, job_name, isDA, isMC, applyBOWS, applyEXTRACOND, extraconditions, runboundary, lumilist, intlumi, maxevents, gt, allFromGT, alignmentDB, alignmentTAG, apeDB, apeTAG, bowDB, bowTAG, vertextype, tracktype, refittertype, ttrhtype, applyruncontrol, ptcut, CMSSW_dir, the_dir)
void print(TMatrixD &m, const char *label=nullptr, bool mathematicaFormat=false)
Definition: Utilities.cc:47

Member Function Documentation

◆ _doFastsimFastVsFullPlots()

def validation.Validation._doFastsimFastVsFullPlots (   self,
  limitSubFoldersOnlyTo,
  htmlReport 
)
private

Definition at line 812 of file validation.py.

References validation.Validation._doPlotsFastFull(), validation.Validation._fastsimSamples, validation.Validation._fullsimSamples, validation.Validation._newRelease, validation.Validation._plotter, validation._processPlotsForSample(), and print().

812  def _doFastsimFastVsFullPlots(self, limitSubFoldersOnlyTo, htmlReport):
813  for fast in self._fastsimSamples:
814  correspondingFull = None
815  for full in self._fullsimSamples:
816  if fast.name() != full.name():
817  continue
818  if fast.pileupEnabled():
819  if not full.pileupEnabled():
820  continue
821  if fast.fastsimCorrespondingFullsimPileup() != full.pileupType():
822  continue
823  else:
824  if full.pileupEnabled():
825  continue
826 
827  if correspondingFull is None:
828  correspondingFull = full
829  else:
830  raise Exception("Got multiple compatible FullSim samples for FastSim sample %s %s" % (fast.name(), fast.pileup()))
831  if correspondingFull is None:
832  print("WARNING: Did not find compatible FullSim sample for FastSim sample %s %s, omitting FastSim vs. FullSim comparison" % (fast.name(), fast.pileup()))
833  continue
834 
835  # If we reach here, the harvestedFile must exist
836  harvestedFile = fast.filename(self._newRelease)
837  plotterInstance = self._plotter.readDirs(harvestedFile)
838  htmlReport.beginSample(fast, fastVsFull=True)
839  for plotterFolder, dqmSubFolder in plotterInstance.iterFolders(limitSubFoldersOnlyTo=limitSubFoldersOnlyTo):
840  if not _processPlotsForSample(plotterFolder, fast):
841  continue
842  plotFiles = self._doPlotsFastFull(fast, correspondingFull, plotterFolder, dqmSubFolder, htmlReport)
843  htmlReport.addPlots(plotterFolder, dqmSubFolder, plotFiles)
844 
def _processPlotsForSample(plotterFolder, sample)
Definition: validation.py:464
void print(TMatrixD &m, const char *label=nullptr, bool mathematicaFormat=false)
Definition: Utilities.cc:47

◆ _doPhase2PileupPlots()

def validation.Validation._doPhase2PileupPlots (   self,
  limitSubFoldersOnlyTo,
  htmlReport 
)
private

Definition at line 845 of file validation.py.

References validation.Validation._doPlotsPileup(), validation.Validation._fullsimSamples, validation.Validation._newRelease, validation.Validation._plotter, and validation._processPlotsForSample().

845  def _doPhase2PileupPlots(self, limitSubFoldersOnlyTo, htmlReport):
846  def _stripScenario(name):
847  puindex = name.find("PU")
848  if puindex < 0:
849  return name
850  return name[:puindex]
851 
852  pu140samples = {}
853  for sample in self._fullsimSamples:
854  if sample.pileupNumber() == 140:
855  key = (sample.name(), _stripScenario(sample.scenario()))
856  if key in pu140samples:
857  raise Exception("Duplicate entry for sample %s in scenario %s" % (sample.name(), sample.scenar()))
858  pu140samples[key] = sample
859 
860  for sample in self._fullsimSamples:
861  if sample.pileupNumber() != 200:
862  continue
863  key = (sample.name(), _stripScenario(sample.scenario()))
864  if not key in pu140samples:
865  continue
866 
867  sample_pu140 = pu140samples[key]
868 
869  # If we reach here, the harvestedFile must exist
870  harvestedFile = sample.filename(self._newRelease)
871  plotterInstance = self._plotter.readDirs(harvestedFile)
872  htmlReport.beginSample(sample, pileupComparison="vs. PU140")
873  for plotterFolder, dqmSubFolder in plotterInstance.iterFolders(limitSubFoldersOnlyTo=limitSubFoldersOnlyTo):
874  if not _processPlotsForSample(plotterFolder, sample):
875  continue
876  plotFiles = self._doPlotsPileup(sample_pu140, sample, plotterFolder, dqmSubFolder, htmlReport)
877  htmlReport.addPlots(plotterFolder, dqmSubFolder, plotFiles)
878 
879 
def _processPlotsForSample(plotterFolder, sample)
Definition: validation.py:464

◆ _doPlots()

def validation.Validation._doPlots (   self,
  sample,
  harvestedFile,
  plotterFolder,
  dqmSubFolder,
  htmlReport 
)
private
Do the real plotting work for a given sample and DQM subfolder

Definition at line 922 of file validation.py.

References validation._copySubDir(), validation._findDuplicates(), validation._getGlobalTag(), validation.Validation._getRefFileAndSelection(), validation.Validation._newBaseDir, html.HtmlReport._newBaseDir, validation.Validation._newRelease, validation.Validation._plotterDrawArgs, validation.Validation._refRelease, validation._stripRelease(), join(), genParticles_cff.map, print(), and str.

922  def _doPlots(self, sample, harvestedFile, plotterFolder, dqmSubFolder, htmlReport):
923  """Do the real plotting work for a given sample and DQM subfolder"""
924  # Get GlobalTags
925  newGlobalTag = _getGlobalTag(sample, self._newRelease)
926 
927  # Construct selection string
928  selectionNameBase = "_"+sample.pileup()
929  newSelection = newGlobalTag+selectionNameBase+plotterFolder.getSelectionName(dqmSubFolder)
930  if sample.pileupEnabled():
931  newPu = sample.pileupType(self._newRelease)
932  if newPu != "":
933  newSelection += "_"+newPu
934 
935  valname = "val.{sample}.root".format(sample=sample.name())
936 
937  # Construct reference file and selection string
938  (refValFile, refSelection) = self._getRefFileAndSelection(sample, plotterFolder, dqmSubFolder, selectionNameBase, valname)
939 
940  # Construct new directory name
941  tmp = []
942  if sample.fastsim():
943  tmp.extend(["fastsim", self._newRelease])
944  tmp.extend([newSelection, sample.name()])
945  newsubdir = os.path.join(*tmp)
946  newdir = os.path.join(self._newBaseDir, newsubdir)
947  if not os.path.exists(newdir):
948  os.makedirs(newdir)
949  valnameFullPath = os.path.join(newdir, valname)
950 
951  # Copy the relevant histograms to a new validation root file
952  # TODO: treat the case where dqmSubFolder is empty
953  newValFile = _copySubDir(harvestedFile, valnameFullPath, plotterFolder.getPossibleDQMFolders(), dqmSubFolder.subfolder if dqmSubFolder is not None else None)
954  fileList = []
955 
956  # Do the plots
957  if plotting.verbose:
958  print("Comparing ref and new {sim} {sample} {translatedFolder}".format(
959  sim="FullSim" if not sample.fastsim() else "FastSim",
960  sample=sample.name(), translatedFolder=str(dqmSubFolder.translated) if dqmSubFolder is not None else ""))
961  rootFiles = [refValFile, newValFile]
962  legendLabels = [
963  "%s, %s %s" % (sample.name(), _stripRelease(self._refRelease), refSelection) if self._refRelease is not None else "dummy",
964  "%s, %s %s" % (sample.name(), _stripRelease(self._newRelease), newSelection)
965  ]
966  plotterFolder.create(rootFiles, legendLabels, dqmSubFolder, isPileupSample=sample.pileupEnabled())
967  fileList.extend(plotterFolder.draw(directory=newdir, **self._plotterDrawArgs))
968  # Copy val file only if there were plots
969  if len(fileList) > 0:
970  fileList.append(valnameFullPath)
971 
972  # For tables we just try them all, and see which ones succeed
973  for tableCreator in plotterFolder.getTableCreators():
974  htmlReport.addTable(tableCreator.create(rootFiles, legendLabels, dqmSubFolder))
975 
976  newValFile.Close()
977  if refValFile is not None:
978  refValFile.Close()
979 
980  if len(fileList) == 0:
981  print("No object found in %s" % plotterFolder.getName())
982  return []
983 
984  dups = _findDuplicates(fileList)
985  if len(dups) > 0:
986  print("Plotter produced multiple files with names", ", ".join(dups))
987  print("Typically this is a naming problem in the plotter configuration")
988  sys.exit(1)
989 
990  # Move plots to new directory
991  print("Created plots and %s in %s" % (valname, newdir))
992  return list(map(lambda n: n.replace(newdir, newsubdir), fileList))
993 
def _getGlobalTag(sample, release)
Definition: validation.py:360
def _stripRelease(release)
Definition: validation.py:353
void print(TMatrixD &m, const char *label=nullptr, bool mathematicaFormat=false)
Definition: Utilities.cc:47
static std::string join(char **cmd)
Definition: RemoteFile.cc:19
def _findDuplicates(lst)
Definition: validation.py:1179
def _copySubDir(oldfile, newfile, basenames, dirname)
Definition: validation.py:1130
#define str(s)

◆ _doPlotsFastFull()

def validation.Validation._doPlotsFastFull (   self,
  fastSample,
  fullSample,
  plotterFolder,
  dqmSubFolder,
  htmlReport 
)
private
Do the real plotting work for FastSim vs. FullSim for a given algorithm, quality flag, and sample.

Definition at line 994 of file validation.py.

References validation._findDuplicates(), validation._getGlobalTag(), validation.Validation._newBaseDir, html.HtmlReport._newBaseDir, validation.Validation._newRelease, validation.Validation._plotterDrawArgs, validation._stripRelease(), join(), genParticles_cff.map, print(), and str.

Referenced by validation.Validation._doFastsimFastVsFullPlots().

994  def _doPlotsFastFull(self, fastSample, fullSample, plotterFolder, dqmSubFolder, htmlReport):
995  """Do the real plotting work for FastSim vs. FullSim for a given algorithm, quality flag, and sample."""
996  # Get GlobalTags
997  fastGlobalTag = _getGlobalTag(fastSample, self._newRelease)
998  fullGlobalTag = _getGlobalTag(fullSample, self._newRelease)
999 
1000  # Construct selection string
1001  tmp = plotterFolder.getSelectionName(dqmSubFolder)
1002  fastSelection = fastGlobalTag+"_"+fastSample.pileup()+tmp
1003  fullSelection = fullGlobalTag+"_"+fullSample.pileup()+tmp
1004  if fullSample.pileupEnabled():
1005  fullSelection += "_"+fullSample.pileupType(self._newRelease)
1006  fastSelection += "_"+fastSample.pileupType(self._newRelease)
1007 
1008  # Construct directories for FastSim, FullSim, and for the results
1009  fastdir = os.path.join(self._newBaseDir, "fastsim", self._newRelease, fastSelection, fastSample.name())
1010  fulldir = os.path.join(self._newBaseDir, fullSelection, fullSample.name())
1011  newsubdir = os.path.join("fastfull", self._newRelease, fastSelection, fastSample.name())
1012  newdir = os.path.join(self._newBaseDir, newsubdir)
1013  if not os.path.exists(newdir):
1014  os.makedirs(newdir)
1015 
1016  # Open input root files
1017  valname = "val.{sample}.root".format(sample=fastSample.name())
1018  fastValFilePath = os.path.join(fastdir, valname)
1019  if not os.path.exists(fastValFilePath) and plotting.verbose:
1020  print("FastSim file %s not found" % fastValFilePath)
1021  fullValFilePath = os.path.join(fulldir, valname)
1022  if not os.path.exists(fullValFilePath) and plotting.verbose:
1023  print("FullSim file %s not found" % fullValFilePath)
1024 
1025  fastValFile = ROOT.TFile.Open(fastValFilePath)
1026  fullValFile = ROOT.TFile.Open(fullValFilePath)
1027 
1028  # Do plots
1029  if plotting.verbose:
1030  print("Comparing FullSim and FastSim {sample} {translatedFolder}".format(
1031  sample=fastSample.name(), translatedFolder=str(dqmSubFolder.translated) if dqmSubFolder is not None else ""))
1032  rootFiles = [fullValFile, fastValFile]
1033  legendLabels = [
1034  "FullSim %s, %s %s" % (fullSample.name(), _stripRelease(self._newRelease), fullSelection),
1035  "FastSim %s, %s %s" % (fastSample.name(), _stripRelease(self._newRelease), fastSelection),
1036  ]
1037  plotterFolder.create(rootFiles, legendLabels, dqmSubFolder, isPileupSample=fastSample.pileupEnabled(), requireAllHistograms=True)
1038  fileList = plotterFolder.draw(directory=newdir, **self._plotterDrawArgs)
1039 
1040  # For tables we just try them all, and see which ones succeed
1041  for tableCreator in plotterFolder.getTableCreators():
1042  htmlReport.addTable(tableCreator.create(rootFiles, legendLabels, dqmSubFolder))
1043 
1044  fullValFile.Close()
1045  fastValFile.Close()
1046 
1047  if len(fileList) == 0:
1048  print("No object found in %s" % plotterFolder.getName())
1049  return []
1050 
1051  dups = _findDuplicates(fileList)
1052  if len(dups) > 0:
1053  print("Plotter produced multiple files with names", ", ".join(dups))
1054  print("Typically this is a naming problem in the plotter configuration")
1055  sys.exit(1)
1056 
1057  # Move plots to new directory
1058  print("Created plots in %s" % (newdir))
1059  return list(map(lambda n: n.replace(newdir, newsubdir), fileList))
1060 
def _getGlobalTag(sample, release)
Definition: validation.py:360
def _stripRelease(release)
Definition: validation.py:353
void print(TMatrixD &m, const char *label=nullptr, bool mathematicaFormat=false)
Definition: Utilities.cc:47
static std::string join(char **cmd)
Definition: RemoteFile.cc:19
def _findDuplicates(lst)
Definition: validation.py:1179
#define str(s)

◆ _doPlotsPileup()

def validation.Validation._doPlotsPileup (   self,
  pu140Sample,
  pu200Sample,
  plotterFolder,
  dqmSubFolder,
  htmlReport 
)
private
Do the real plotting work for two pileup scenarios for a given algorithm, quality flag, and sample.

Definition at line 1061 of file validation.py.

References validation._findDuplicates(), validation._getGlobalTag(), validation.Validation._newBaseDir, html.HtmlReport._newBaseDir, validation.Validation._newRelease, validation.Validation._plotterDrawArgs, validation._stripRelease(), join(), genParticles_cff.map, print(), and str.

Referenced by validation.Validation._doPhase2PileupPlots().

1061  def _doPlotsPileup(self, pu140Sample, pu200Sample, plotterFolder, dqmSubFolder, htmlReport):
1062  """Do the real plotting work for two pileup scenarios for a given algorithm, quality flag, and sample."""
1063  # Get GlobalTags
1064  pu140GlobalTag = _getGlobalTag(pu140Sample, self._newRelease)
1065  pu200GlobalTag = _getGlobalTag(pu200Sample, self._newRelease)
1066 
1067  # Construct selection string
1068  tmp = plotterFolder.getSelectionName(dqmSubFolder)
1069  pu140Selection = pu140GlobalTag+"_"+pu140Sample.pileup()+tmp+"_"+pu140Sample.pileupType(self._newRelease)
1070  pu200Selection = pu200GlobalTag+"_"+pu200Sample.pileup()+tmp+"_"+pu200Sample.pileupType(self._newRelease)
1071 
1072  # Construct directories for
1073  pu140dir = os.path.join(self._newBaseDir, pu140Selection, pu140Sample.name())
1074  pu200dir = os.path.join(self._newBaseDir, pu200Selection, pu200Sample.name())
1075  newsubdir = os.path.join("pileup", self._newRelease, pu200Selection, pu200Sample.name())
1076  newdir = os.path.join(self._newBaseDir, newsubdir)
1077  if not os.path.exists(newdir):
1078  os.makedirs(newdir)
1079 
1080  # Open input root files
1081  valname = "val.{sample}.root".format(sample=pu140Sample.name())
1082  pu140ValFilePath = os.path.join(pu140dir, valname)
1083  if not os.path.exists(pu140ValFilePath):
1084  if plotting.verbose:
1085  print("PU140 file %s not found" % pu140ValFilePath)
1086  return []
1087  pu200ValFilePath = os.path.join(pu200dir, valname)
1088  if not os.path.exists(pu200ValFilePath):
1089  if plotting.verbose:
1090  print("PU200 file %s not found" % pu200ValFilePath)
1091  return []
1092 
1093  pu140ValFile = ROOT.TFile.Open(pu140ValFilePath)
1094  pu200ValFile = ROOT.TFile.Open(pu200ValFilePath)
1095 
1096  # Do plots
1097  if plotting.verbose:
1098  print("Comparing PU140 and PU200 {sample} {translatedFolder}".format(
1099  sample=pu200Sample.name(), translatedFolder=str(dqmSubFolder.translated) if dqmSubFolder is not None else ""))
1100  rootFiles = [pu140ValFile, pu200ValFile]
1101  legendLabels = [
1102  "%s, %s %s" % (pu140Sample.name(), _stripRelease(self._newRelease), pu140Selection),
1103  "%s, %s %s" % (pu200Sample.name(), _stripRelease(self._newRelease), pu200Selection),
1104  ]
1105  plotterFolder.create(rootFiles, legendLabels, dqmSubFolder, isPileupSample=pu140Sample.pileupEnabled(), requireAllHistograms=True)
1106  fileList = plotterFolder.draw(directory=newdir, **self._plotterDrawArgs)
1107 
1108  # For tables we just try them all, and see which ones succeed
1109  for tableCreator in plotterFolder.getTableCreators():
1110  htmlReport.addTable(tableCreator.create(rootFiles, legendLabels, dqmSubFolder))
1111 
1112  pu200ValFile.Close()
1113  pu140ValFile.Close()
1114 
1115  if len(fileList) == 0:
1116  print("No object found in %s" % plotterFolder.getName())
1117  return []
1118 
1119  dups = _findDuplicates(fileList)
1120  if len(dups) > 0:
1121  print("Plotter produced multiple files with names", ", ".join(dups))
1122  print("Typically this is a naming problem in the plotter configuration")
1123  sys.exit(1)
1124 
1125  # Move plots to new directory
1126  print("Created plots in %s" % (newdir))
1127  return list(map(lambda n: n.replace(newdir, newsubdir), fileList))
1128 
1129 
def _getGlobalTag(sample, release)
Definition: validation.py:360
def _stripRelease(release)
Definition: validation.py:353
void print(TMatrixD &m, const char *label=nullptr, bool mathematicaFormat=false)
Definition: Utilities.cc:47
static std::string join(char **cmd)
Definition: RemoteFile.cc:19
def _findDuplicates(lst)
Definition: validation.py:1179
#define str(s)

◆ _getDirectoryName()

def validation.Validation._getDirectoryName (   self,
  args,
  kwargs 
)
private

Definition at line 714 of file validation.py.

714  def _getDirectoryName(self, *args, **kwargs):
715  return None
716 

◆ _getRefFileAndSelection()

def validation.Validation._getRefFileAndSelection (   self,
  sample,
  plotterFolder,
  dqmSubFolder,
  selectionNameBase,
  valname 
)
private

Definition at line 880 of file validation.py.

References validation._getGlobalTag(), validation.Validation._refRelease, validation.Validation._refRepository, join(), and print().

Referenced by validation.Validation._doPlots().

880  def _getRefFileAndSelection(self, sample, plotterFolder, dqmSubFolder, selectionNameBase, valname):
881  if self._refRelease is None:
882  return (None, "")
883 
884  refGlobalTag = _getGlobalTag(sample, self._refRelease)
885  def _createRefSelection(selectionName):
886  sel = refGlobalTag+selectionNameBase+selectionName
887  if sample.pileupEnabled():
888  refPu = sample.pileupType(self._refRelease)
889  if refPu != "":
890  sel += "_"+refPu
891  return sel
892  refSelection = _createRefSelection(plotterFolder.getSelectionName(dqmSubFolder))
893 
894  # Construct reference directory name, and open reference file it it exists
895  refValFile = None
896  triedRefValFiles = []
897  tmp = [self._refRepository, self._refRelease]
898  if sample.fastsim():
899  tmp.extend(["fastsim", self._refRelease])
900  for selName in plotterFolder.getSelectionNameIterator(dqmSubFolder):
901  refSel = _createRefSelection(selName)
902  refdir = os.path.join(*(tmp+[refSel, sample.name()]))
903 
904  # Open reference file if it exists
905  refValFilePath = os.path.join(refdir, valname)
906  if os.path.exists(refValFilePath):
907  refSelection = refSel
908  refValFile = ROOT.TFile.Open(refValFilePath)
909  break
910  else:
911  triedRefValFiles.append(refValFilePath)
912  if refValFile is None:
913  if len(triedRefValFiles) == 1:
914  if plotting.verbose:
915  print("Reference file %s not found" % triedRefValFiles[0])
916  else:
917  if plotting.verbose:
918  print("None of the possible reference files %s not found" % ",".join(triedRefValFiles))
919 
920  return (refValFile, refSelection)
921 
def _getGlobalTag(sample, release)
Definition: validation.py:360
void print(TMatrixD &m, const char *label=nullptr, bool mathematicaFormat=false)
Definition: Utilities.cc:47
static std::string join(char **cmd)
Definition: RemoteFile.cc:19

◆ _getSelectionName()

def validation.Validation._getSelectionName (   self,
  args,
  kwargs 
)
private

Definition at line 717 of file validation.py.

References validation.Validation._selectionName.

717  def _getSelectionName(self, *args, **kwargs):
718  return self._selectionName
719 

◆ createHtmlReport()

def validation.Validation.createHtmlReport (   self)

Definition at line 769 of file validation.py.

References validation.Validation._newBaseDir, html.HtmlReport._newBaseDir, and validation.Validation._newRelease.

769  def createHtmlReport(self):
770  return html.HtmlReport(self._newRelease, self._newBaseDir)
771 

◆ doPlots()

def validation.Validation.doPlots (   self,
  plotter,
  plotterDrawArgs = {},
  limitSubFoldersOnlyTo = None,
  htmlReport = html.HtmlReportDummy(),
  doFastVsFull = True,
  doPhase2PU = False 
)
Create validation plots.

Arguments:
plotter       -- plotting.Plotter object that does the plotting

Keyword arguments:
plotterDrawArgs -- Dictionary for additional arguments to Plotter.draw() (default: {})
limitSubFoldersOnlyTo   -- If not None, should be a dictionary from string to an object. The string is the name of a PlotFolder, and the object is PlotFolder-type specific to limit the subfolders to be processed. In general case the object is a list of strings, but e.g. for track iteration plots it is a function taking the algo and quality as parameters.
htmlReport      -- Object returned by createHtmlReport(), in case HTML report generation is desired
doFastVsFull    -- Do FastSim vs. FullSim comparison? (default: True)
doPhase2PU      -- Do Phase2 PU 200 vs. 140 comparison (default: False)

Definition at line 772 of file validation.py.

772  def doPlots(self, plotter, plotterDrawArgs={}, limitSubFoldersOnlyTo=None, htmlReport=html.HtmlReportDummy(), doFastVsFull=True, doPhase2PU=False):
773  """Create validation plots.
774 
775  Arguments:
776  plotter -- plotting.Plotter object that does the plotting
777 
778  Keyword arguments:
779  plotterDrawArgs -- Dictionary for additional arguments to Plotter.draw() (default: {})
780  limitSubFoldersOnlyTo -- If not None, should be a dictionary from string to an object. The string is the name of a PlotFolder, and the object is PlotFolder-type specific to limit the subfolders to be processed. In general case the object is a list of strings, but e.g. for track iteration plots it is a function taking the algo and quality as parameters.
781  htmlReport -- Object returned by createHtmlReport(), in case HTML report generation is desired
782  doFastVsFull -- Do FastSim vs. FullSim comparison? (default: True)
783  doPhase2PU -- Do Phase2 PU 200 vs. 140 comparison (default: False)
784  """
785  self._plotter = plotter
786  self._plotterDrawArgs = plotterDrawArgs
787 
788  # New vs. Ref
789  for sample in self._fullsimSamples+self._fastsimSamples:
790  # Check that the new DQM file exists
791  harvestedFile = sample.filename(self._newRelease)
792  if not os.path.exists(harvestedFile):
793  print("Harvested file %s does not exist!" % harvestedFile)
794  sys.exit(1)
795 
796  plotterInstance = plotter.readDirs(harvestedFile)
797  htmlReport.beginSample(sample)
798  for plotterFolder, dqmSubFolder in plotterInstance.iterFolders(limitSubFoldersOnlyTo=limitSubFoldersOnlyTo):
799  if not _processPlotsForSample(plotterFolder, sample):
800  continue
801  plotFiles = self._doPlots(sample, harvestedFile, plotterFolder, dqmSubFolder, htmlReport)
802  htmlReport.addPlots(plotterFolder, dqmSubFolder, plotFiles)
803 
804  # Fast vs. Full
805  if doFastVsFull:
806  self._doFastsimFastVsFullPlots(limitSubFoldersOnlyTo, htmlReport)
807 
808  # Phase2 PU200 vs. PU 140
809  if doPhase2PU:
810  self._doPhase2PileupPlots(limitSubFoldersOnlyTo, htmlReport)
811 
def _processPlotsForSample(plotterFolder, sample)
Definition: validation.py:464
void print(TMatrixD &m, const char *label=nullptr, bool mathematicaFormat=false)
Definition: Utilities.cc:47

◆ download()

def validation.Validation.download (   self)
Download DQM files. Requires grid certificate and asks your password for it.

Definition at line 720 of file validation.py.

References validation.Validation._fastsimSamples, validation.Validation._fullsimSamples, validation._getRelValUrl(), validation.Validation._newFileModifier, validation.Validation._newRelease, join(), genParticles_cff.map, and print().

720  def download(self):
721  """Download DQM files. Requires grid certificate and asks your password for it."""
722  filenames = [s.filename(self._newRelease) for s in self._fullsimSamples+self._fastsimSamples]
723  if self._newFileModifier is not None:
724  filenames = list(map(self._newFileModifier, filenames))
725  filenames = [f for f in filenames if not os.path.exists(f)]
726  if len(filenames) == 0:
727  print("All files already downloaded")
728  return
729 
730  relvalUrl = _getRelValUrl(self._newRelease)
731  urls = [relvalUrl+f for f in filenames]
732  certfile = os.path.join(os.environ["HOME"], ".globus", "usercert.pem")
733  if not os.path.exists(certfile):
734  print("Certificate file {certfile} does not exist, unable to download RelVal files from {url}".format(certfile=certfile, url=relvalUrl))
735  sys.exit(1)
736  keyfile = os.path.join(os.environ["HOME"], ".globus", "userkey.pem")
737  if not os.path.exists(certfile):
738  print("Private key file {keyfile} does not exist, unable to download RelVal files from {url}".format(keyfile=keyfile, url=relvalUrl))
739  sys.exit(1)
740 
741  # curl --cert-type PEM --cert $HOME/.globus/usercert.pem --key $HOME/.globus/userkey.pem -k -O <url> -O <url>
742  cmd = ["curl", "--cert-type", "PEM", "--cert", certfile, "--key", keyfile, "-k"]
743  for u in urls:
744  cmd.extend(["-O", u])
745  print("Downloading %d files from RelVal URL %s:" % (len(filenames), relvalUrl))
746  print(" "+"\n ".join(filenames))
747  print("Please provide your private key pass phrase when curl asks it")
748  ret = subprocess.call(cmd)
749  if ret != 0:
750  print("Downloading failed with exit code %d" % ret)
751  sys.exit(1)
752 
753  # verify
754  allFine = True
755  for f in filenames:
756  p = subprocess.Popen(["file", f], stdout=subprocess.PIPE)
757  stdout = p.communicate()[0]
758  if p.returncode != 0:
759  print("file command failed with exit code %d" % p.returncode)
760  sys.exit(1)
761  if not "ROOT" in stdout:
762  print("File {f} is not ROOT, please check the correct version, GlobalTag etc. from {url}".format(f=f, url=relvalUrl))
763  allFine = False
764  if os.path.exists(f):
765  os.remove(f)
766  if not allFine:
767  sys.exit(1)
768 
def _getRelValUrl(release)
Definition: validation.py:452
void print(TMatrixD &m, const char *label=nullptr, bool mathematicaFormat=false)
Definition: Utilities.cc:47
static std::string join(char **cmd)
Definition: RemoteFile.cc:19

Member Data Documentation

◆ _fastsimSamples

validation.Validation._fastsimSamples
private

◆ _fullsimSamples

validation.Validation._fullsimSamples
private

◆ _newBaseDir

validation.Validation._newBaseDir
private

◆ _newFileModifier

validation.Validation._newFileModifier
private

Definition at line 711 of file validation.py.

Referenced by validation.Validation.download().

◆ _newRelease

validation.Validation._newRelease
private

◆ _plotter

validation.Validation._plotter
private

◆ _plotterDrawArgs

validation.Validation._plotterDrawArgs
private

◆ _refRelease

validation.Validation._refRelease
private

◆ _refRepository

validation.Validation._refRepository
private

Definition at line 708 of file validation.py.

Referenced by validation.Validation._getRefFileAndSelection().

◆ _selectionName

validation.Validation._selectionName
private

Definition at line 712 of file validation.py.

Referenced by validation.Validation._getSelectionName().