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 684 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 686 of file validation.py.

Referenced by vertexPlots.VertexValidation._init__().

686  def __init__(self, fullsimSamples, fastsimSamples, refRelease, refRepository, newRelease, newRepository, newFileModifier=None, selectionName=""):
687  """Constructor.
688 
689  Arguments:
690  fullsimSamples -- List of Sample objects for FullSim samples (may be empty)
691  fastsimSamples -- List of Sample objects for FastSim samples (may be empty)
692  refRelease -- String for reference CMSSW release (can be None for no reference release)
693  newRepository -- String for directory whete to put new files
694  newRelease -- CMSSW release to be validated
695  refRepository -- String for directory where reference root files are
696  newFileModifier -- If given, a function to modify the names of the new files (function takes a string and returns a string)
697  selectionName -- If given, use this string as the selection name (appended to GlobalTag for directory names)
698  """
699  try:
700  self._newRelease = os.environ["CMSSW_VERSION"]
701  except KeyError:
702  print('Error: CMSSW environment variables are not available.', file=sys.stderr)
703  print(' Please run cmsenv', file=sys.stderr)
704  sys.exit()
705 
706  self._fullsimSamples = fullsimSamples
707  self._fastsimSamples = fastsimSamples
708  self._refRelease = refRelease
709  self._refRepository = refRepository
710  self._newRelease = newRelease
711  self._newBaseDir = os.path.join(newRepository, self._newRelease)
712  self._newFileModifier = newFileModifier
713  self._selectionName = selectionName
714 
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 813 of file validation.py.

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

813  def _doFastsimFastVsFullPlots(self, limitSubFoldersOnlyTo, htmlReport):
814  for fast in self._fastsimSamples:
815  correspondingFull = None
816  for full in self._fullsimSamples:
817  if fast.name() != full.name():
818  continue
819  if fast.pileupEnabled():
820  if not full.pileupEnabled():
821  continue
822  if fast.fastsimCorrespondingFullsimPileup() != full.pileupType():
823  continue
824  else:
825  if full.pileupEnabled():
826  continue
827 
828  if correspondingFull is None:
829  correspondingFull = full
830  else:
831  raise Exception("Got multiple compatible FullSim samples for FastSim sample %s %s" % (fast.name(), fast.pileup()))
832  if correspondingFull is None:
833  print("WARNING: Did not find compatible FullSim sample for FastSim sample %s %s, omitting FastSim vs. FullSim comparison" % (fast.name(), fast.pileup()))
834  continue
835 
836  # If we reach here, the harvestedFile must exist
837  harvestedFile = fast.filename(self._newRelease)
838  plotterInstance = self._plotter.readDirs(harvestedFile)
839  htmlReport.beginSample(fast, fastVsFull=True)
840  for plotterFolder, dqmSubFolder in plotterInstance.iterFolders(limitSubFoldersOnlyTo=limitSubFoldersOnlyTo):
841  if not _processPlotsForSample(plotterFolder, fast):
842  continue
843  plotFiles = self._doPlotsFastFull(fast, correspondingFull, plotterFolder, dqmSubFolder, htmlReport)
844  htmlReport.addPlots(plotterFolder, dqmSubFolder, plotFiles)
845 
def _processPlotsForSample(plotterFolder, sample)
Definition: validation.py:465
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 846 of file validation.py.

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

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

◆ _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 923 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.

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

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

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

◆ _getDirectoryName()

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

Definition at line 715 of file validation.py.

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

◆ _getRefFileAndSelection()

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

Definition at line 881 of file validation.py.

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

Referenced by validation.Validation._doPlots().

881  def _getRefFileAndSelection(self, sample, plotterFolder, dqmSubFolder, selectionNameBase, valname):
882  if self._refRelease is None:
883  return (None, "")
884 
885  refGlobalTag = _getGlobalTag(sample, self._refRelease)
886  def _createRefSelection(selectionName):
887  sel = refGlobalTag+selectionNameBase+selectionName
888  if sample.pileupEnabled():
889  refPu = sample.pileupType(self._refRelease)
890  if refPu != "":
891  sel += "_"+refPu
892  return sel
893  refSelection = _createRefSelection(plotterFolder.getSelectionName(dqmSubFolder))
894 
895  # Construct reference directory name, and open reference file it it exists
896  refValFile = None
897  triedRefValFiles = []
898  tmp = [self._refRepository, self._refRelease]
899  if sample.fastsim():
900  tmp.extend(["fastsim", self._refRelease])
901  for selName in plotterFolder.getSelectionNameIterator(dqmSubFolder):
902  refSel = _createRefSelection(selName)
903  refdir = os.path.join(*(tmp+[refSel, sample.name()]))
904 
905  # Open reference file if it exists
906  refValFilePath = os.path.join(refdir, valname)
907  if os.path.exists(refValFilePath):
908  refSelection = refSel
909  refValFile = ROOT.TFile.Open(refValFilePath)
910  break
911  else:
912  triedRefValFiles.append(refValFilePath)
913  if refValFile is None:
914  if len(triedRefValFiles) == 1:
915  if plotting.verbose:
916  print("Reference file %s not found" % triedRefValFiles[0])
917  else:
918  if plotting.verbose:
919  print("None of the possible reference files %s not found" % ",".join(triedRefValFiles))
920 
921  return (refValFile, refSelection)
922 
def _getGlobalTag(sample, release)
Definition: validation.py:361
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 718 of file validation.py.

References validation.Validation._selectionName.

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

◆ createHtmlReport()

def validation.Validation.createHtmlReport (   self)

Definition at line 770 of file validation.py.

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

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

◆ 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 773 of file validation.py.

773  def doPlots(self, plotter, plotterDrawArgs={}, limitSubFoldersOnlyTo=None, htmlReport=html.HtmlReportDummy(), doFastVsFull=True, doPhase2PU=False):
774  """Create validation plots.
775 
776  Arguments:
777  plotter -- plotting.Plotter object that does the plotting
778 
779  Keyword arguments:
780  plotterDrawArgs -- Dictionary for additional arguments to Plotter.draw() (default: {})
781  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.
782  htmlReport -- Object returned by createHtmlReport(), in case HTML report generation is desired
783  doFastVsFull -- Do FastSim vs. FullSim comparison? (default: True)
784  doPhase2PU -- Do Phase2 PU 200 vs. 140 comparison (default: False)
785  """
786  self._plotter = plotter
787  self._plotterDrawArgs = plotterDrawArgs
788 
789  # New vs. Ref
790  for sample in self._fullsimSamples+self._fastsimSamples:
791  # Check that the new DQM file exists
792  harvestedFile = sample.filename(self._newRelease)
793  if not os.path.exists(harvestedFile):
794  print("Harvested file %s does not exist!" % harvestedFile)
795  sys.exit(1)
796 
797  plotterInstance = plotter.readDirs(harvestedFile)
798  htmlReport.beginSample(sample)
799  for plotterFolder, dqmSubFolder in plotterInstance.iterFolders(limitSubFoldersOnlyTo=limitSubFoldersOnlyTo):
800  if not _processPlotsForSample(plotterFolder, sample):
801  continue
802  plotFiles = self._doPlots(sample, harvestedFile, plotterFolder, dqmSubFolder, htmlReport)
803  htmlReport.addPlots(plotterFolder, dqmSubFolder, plotFiles)
804 
805  # Fast vs. Full
806  if doFastVsFull:
807  self._doFastsimFastVsFullPlots(limitSubFoldersOnlyTo, htmlReport)
808 
809  # Phase2 PU200 vs. PU 140
810  if doPhase2PU:
811  self._doPhase2PileupPlots(limitSubFoldersOnlyTo, htmlReport)
812 
def _processPlotsForSample(plotterFolder, sample)
Definition: validation.py:465
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 721 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().

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

Referenced by validation.Validation._getRefFileAndSelection().

◆ _selectionName

validation.Validation._selectionName
private

Definition at line 713 of file validation.py.

Referenced by validation.Validation._getSelectionName().