Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2023-10-25 09:32:51

0001 import FWCore.ParameterSet.Config as cms
0002 import FWCore.PythonUtilities.LumiList as LumiList
0003 from Alignment.OfflineValidation.TkAlAllInOneTool.defaultInputFiles_cff import filesDefaultMC_NoPU
0004 
0005 from FWCore.ParameterSet.VarParsing import VarParsing
0006 
0007 import json
0008 import os
0009 
0010 ##Define process
0011 process = cms.Process("OfflineValidator")
0012 
0013 ##Argument parsing
0014 options = VarParsing()
0015 options.register("config", "", VarParsing.multiplicity.singleton, VarParsing.varType.string , "AllInOne config")
0016 
0017 options.parseArguments()
0018 
0019 ##Read in AllInOne config in JSON format
0020 if options.config == "":
0021     config = {"validation": {},
0022               "alignment": {}}
0023 else:
0024     with open(options.config, "r") as configFile:
0025         config = json.load(configFile)
0026 
0027 print(config)
0028 
0029 ##Read filenames from given TXT file and define input source
0030 readFiles = []
0031 
0032 if "dataset" in config["validation"]:
0033     with open(config["validation"]["dataset"], "r") as datafiles:
0034         for fileName in datafiles.readlines():
0035             readFiles.append(fileName.replace("\n", ""))
0036 
0037     ##Define input source
0038     process.source = cms.Source("PoolSource",
0039                                 fileNames = cms.untracked.vstring(readFiles),
0040                                 skipEvents = cms.untracked.uint32(0)
0041                             )
0042 else:
0043     print(">>>>>>>>>> DMR_cfg.py: msg%-i: config not specified! Loading default MC simulation -> filesDefaultMC_NoPU!")
0044     process.source = cms.Source("PoolSource",
0045                                 fileNames = filesDefaultMC_NoPU,
0046                                 skipEvents = cms.untracked.uint32(0)
0047                             )
0048 
0049 ##Get good lumi section
0050 if "goodlumi" in config["validation"]:
0051     if os.path.isfile(config["validation"]["goodlumi"]):
0052         goodLumiSecs = cms.untracked.VLuminosityBlockRange(LumiList.LumiList(filename = config["validation"]["goodlumi"]).getCMSSWString().split(','))
0053 
0054     else:
0055         print("Does not exist: {}. Continue without good lumi section file.")
0056         goodLumiSecs = cms.untracked.VLuminosityBlockRange()
0057 
0058 else:
0059     goodLumiSecs = cms.untracked.VLuminosityBlockRange()
0060 
0061 process.source.lumisToProcess = goodLumiSecs
0062 
0063 ##default set to 1 for unit tests
0064 process.maxEvents = cms.untracked.PSet(
0065     input = cms.untracked.int32(config["validation"].get("maxevents", 1))
0066 )
0067 
0068 ##Bookeeping
0069 process.options = cms.untracked.PSet(
0070    wantSummary = cms.untracked.bool(False),
0071    Rethrow = cms.untracked.vstring("ProductNotFound"),
0072    fileMode  =  cms.untracked.string('NOMERGE'),
0073 )
0074 
0075 process.load("FWCore.MessageLogger.MessageLogger_cfi")
0076 process.MessageLogger = cms.Service("MessageLogger",
0077        destinations   = cms.untracked.vstring('cerr'),
0078        cerr       = cms.untracked.PSet(
0079                     threshold = cms.untracked.string('ERROR')
0080         )
0081 
0082 )
0083 
0084 ##Basic modules
0085 process.load("RecoVertex.BeamSpotProducer.BeamSpot_cff")
0086 process.load("Configuration.Geometry.GeometryDB_cff")
0087 process.load('Configuration.StandardSequences.Services_cff')
0088 process.load("Configuration.StandardSequences.MagneticField_cff")
0089 
0090 ##Track fitting
0091 import Alignment.CommonAlignment.tools.trackselectionRefitting as trackselRefit
0092 process.seqTrackselRefit = trackselRefit.getSequence(process,
0093                                                      config["validation"].get("trackcollection", "generalTracks"),
0094                                                      isPVValidation = False, 
0095                                                      TTRHBuilder = config["validation"].get("tthrbuilder", "WithAngleAndTemplate"),
0096                                                      usePixelQualityFlag=config["validation"].get("usePixelQualityFlag", True),
0097                                                      openMassWindow = False,
0098                                                      cosmicsDecoMode = True,
0099                                                      cosmicsZeroTesla=config["validation"].get("cosmicsZeroTesla", False),
0100                                                      momentumConstraint = None,
0101                                                      cosmicTrackSplitting = False,
0102                                                      use_d0cut = True,
0103 )
0104 
0105 #Global tag
0106 process.load("Configuration.StandardSequences.FrontierConditions_GlobalTag_cff")
0107 from Configuration.AlCa.GlobalTag import GlobalTag
0108 process.GlobalTag = GlobalTag(process.GlobalTag, config["alignment"].get("globaltag", "auto:phase1_2017_realistic"))
0109 
0110 ##Load conditions if wished
0111 if "conditions" in config["alignment"]:
0112     from CalibTracker.Configuration.Common.PoolDBESSource_cfi import poolDBESSource
0113 
0114     for condition in config["alignment"]["conditions"]:
0115         setattr(process, "conditionsIn{}".format(condition), poolDBESSource.clone(
0116              connect = cms.string(str(config["alignment"]["conditions"][condition]["connect"])),
0117              toGet = cms.VPSet(
0118                         cms.PSet(
0119                                  record = cms.string(str(condition)),
0120                                  tag = cms.string(str(config["alignment"]["conditions"][condition]["tag"]))
0121                         )
0122                      )
0123             )
0124         )
0125 
0126         setattr(process, "prefer_conditionsIn{}".format(condition), cms.ESPrefer("PoolDBESSource", "conditionsIn{}".format(condition)))
0127 
0128 ##Filter good events
0129 process.oneGoodVertexFilter = cms.EDFilter("VertexSelector",
0130                                            src = cms.InputTag(config["validation"].get("vertexcollection", "offlinePrimaryVertices")),
0131                                            cut = cms.string("!isFake && ndof > 4 && abs(z) <= 15 && position.Rho <= 2"),
0132                                            filter = cms.bool(True),
0133 )
0134 process.FilterGoodEvents=cms.Sequence(process.oneGoodVertexFilter)
0135 
0136 process.noScraping= cms.EDFilter("FilterOutScraping",
0137                                  src=cms.untracked.InputTag(config["validation"].get("trackcollection", "generalTracks")),
0138                                  applyfilter = cms.untracked.bool(True),
0139                                  debugOn = cms.untracked.bool(False),
0140                                  numtrack = cms.untracked.uint32(10),
0141                                  thresh = cms.untracked.double(0.25),
0142 )
0143 
0144 ##Offline validation analyzer
0145 from Alignment.OfflineValidation.trackerOfflineValidation_cfi import trackerOfflineValidation as _trackerOfflineValidation
0146 process.TrackerOfflineValidation = _trackerOfflineValidation.clone(
0147     useInDqmMode              = False,
0148     moduleDirectoryInOutput   = "",
0149     Tracks                    = "FinalTrackRefitter",
0150     trajectoryInput           = "FinalTrackRefitter",  # Only needed in DQM mode
0151     localCoorHistosOn         = False,
0152     moduleLevelHistsTransient = config["validation"].get("moduleLevelHistsTransient", False),
0153     moduleLevelProfiles       = config["validation"].get("moduleLevelProfiles", True),
0154     stripYResiduals           = config["validation"].get("stripYResiduals", False),
0155     useFwhm                   = True,
0156     useFit                    = False,
0157     useOverflowForRMS         = False,
0158     maxTracks                 = config["validation"].get("maxtracks", 1),
0159     chargeCut                 = config["validation"].get("chargecut", 0),
0160 
0161     # Normalized X Residuals, normal local coordinates (Strip)
0162     TH1NormXResStripModules = dict(Nbinx = 100, xmin = -5.0, xmax = 5.0),
0163 
0164     # X Residuals, normal local coordinates (Strip)
0165     TH1XResStripModules = dict(Nbinx = 100, xmin = -0.5, xmax = 0.5),
0166 
0167     # Normalized X Residuals, native coordinates (Strip)
0168     TH1NormXprimeResStripModules = dict(Nbinx = 120, xmin = -3.0, xmax = 3.0),
0169 
0170     # X Residuals, native coordinates (Strip)
0171     TH1XprimeResStripModules = dict(Nbinx = 5000, xmin = -0.05, xmax = 0.05),
0172 
0173     # Normalized Y Residuals, native coordinates (Strip -> hardly defined)
0174     TH1NormYResStripModules = dict(Nbinx = 120, xmin = -3.0, xmax = 3.0),
0175 
0176     # -> very broad distributions expected
0177     TH1YResStripModules = dict(Nbinx = 5000, xmin = -11.0, xmax = 11.0),
0178 
0179     # Normalized X residuals normal local coordinates (Pixel)
0180     TH1NormXResPixelModules = dict(Nbinx = 100, xmin = -5.0, xmax = 5.0),
0181 
0182     # X residuals normal local coordinates (Pixel)
0183     TH1XResPixelModules = dict(Nbinx = 100, xmin = -0.5, xmax = 0.5),
0184 
0185     # Normalized X residuals native coordinates (Pixel)
0186     TH1NormXprimeResPixelModules = dict(Nbinx = 120, xmin = -3.0, xmax = 3.0),
0187 
0188     # X residuals native coordinates (Pixel)
0189     TH1XprimeResPixelModules = dict(Nbinx = 5000, xmin = -0.05, xmax = 0.05),
0190 
0191     # Normalized Y residuals native coordinates (Pixel)
0192     TH1NormYResPixelModules = dict(Nbinx = 120, xmin = -3.0, xmax = 3.0),
0193 
0194     # Y residuals native coordinates (Pixel)
0195     TH1YResPixelModules = dict(Nbinx = 5000, xmin = -0.05, xmax = 0.05),
0196 
0197     # X Residuals vs reduced local coordinates (Strip)
0198     TProfileXResStripModules = dict(Nbinx = 34, xmin = -1.02, xmax = 1.02),
0199 
0200     # X Residuals vs reduced local coordinates (Strip)
0201     TProfileYResStripModules = dict(Nbinx = 34, xmin = -1.02, xmax = 1.02),
0202 
0203     # X Residuals vs reduced local coordinates (Pixel)
0204     TProfileXResPixelModules = dict(Nbinx = 17, xmin = -1.02, xmax = 1.02),
0205 
0206     # X Residuals vs reduced local coordinates (Pixel)
0207     TProfileYResPixelModules = dict(Nbinx = 17, xmin = -1.02, xmax = 1.02)
0208 )
0209 
0210 ##Output file
0211 process.TFileService = cms.Service("TFileService",
0212         fileName = cms.string("{}/DMR.root".format(config.get("output", os.getcwd()))),
0213         closeFileFast = cms.untracked.bool(True),
0214 )
0215 
0216 seqTrackerOfflineValidation = cms.Sequence(process.TrackerOfflineValidation)
0217 
0218 ##Let all sequences run
0219 process.p = cms.Path(process.seqTrackselRefit*seqTrackerOfflineValidation)