CMSSW Configuration in Python Rick Wilkinson June 19, 2008 1.

Slides:



Advertisements
Similar presentations
Chapter 16: Exception Handling C++ Programming: From Problem Analysis to Program Design, Fifth Edition.
Advertisements

Introduction to C Programming
Chapter 8 and 9 Review: Logical Functions and Control Structures Introduction to MATLAB 7 Engineering 161.
IS 1181 IS 118 Introduction to Development Tools VB Chapter 06.
CMSSW Tutorial. Event processing: Event generation (in MC world)Event generation (in MC world) DigitizationDigitization Local reconstructionLocal reconstruction.
Working with JavaScript. 2 Objectives Introducing JavaScript Inserting JavaScript into a Web Page File Writing Output to the Web Page Working with Variables.
CMS Framework “Software bus” model –One executable, “cmsRun, with many plug-in modules Controlled by a configuration file –Controls which data to use,
Linux+ Guide to Linux Certification, Second Edition
CMSSW Configuration Using python JTERM II Tutorial Rick Wilkinson.
CMSSW Configuration Using python Rick Wilkinson. Python configurations u Your cfg, cfi, and cffs will not be supported in CMSSW_2_1_0. u They’ll be replaced.
 2007 Pearson Education, Inc. All rights reserved Introduction to C Programming.
XP 1 Working with JavaScript Creating a Programmable Web Page for North Pole Novelties Tutorial 10.
Usage of the Python Programming Language in the CMS Experiment Rick Wilkinson (Caltech), Benedikt Hegner (CERN) On behalf of CMS Offline & Computing 1.
28-Jun-15 Recognizers. 2 Parsers and recognizers Given a grammar (say, in BNF) and a string, A recognizer will tell whether the string belongs to the.
Guide To UNIX Using Linux Third Edition
Introduction to C Programming
Introduction to Unix (CA263) Introduction to Shell Script Programming By Tariq Ibn Aziz.
C++ fundamentals.
Introduction to JavaScript for Python Programmers
Programming Epson Robots – Part 2 ME 4135 – Fall 2012 Dr. R. Lindeke.
Using Ant to build J2EE Applications Kumar
CS190/295 Programming in Python for Life Sciences: Lecture 1 Instructor: Xiaohui Xie University of California, Irvine.
Programming For Nuclear Engineers Lecture 12 MATLAB (3) 1.
Arc: Programming Options Dr Andy Evans. Programming ArcGIS ArcGIS: Most popular commercial GIS. Out of the box functionality good, but occasionally: You.
1 Chapter One A First Program Using C#. 2 Objectives Learn about programming tasks Learn object-oriented programming concepts Learn about the C# programming.
Introduction to Shell Script Programming
Fortran 1- Basics Chapters 1-2 in your Fortran book.
Introduction to Python
Week 7 Working with the BASH Shell. Objectives  Redirect the input and output of a command  Identify and manipulate common shell environment variables.
1 Functions 1 Parameter, 1 Return-Value 1. The problem 2. Recall the layout 3. Create the definition 4. "Flow" of data 5. Testing 6. Projects 1 and 2.
Programming for Beginners Martin Nelson Elizabeth FitzGerald Lecture 13: An Introduction to C++
XP Tutorial 10New Perspectives on Creating Web Pages with HTML, XHTML, and XML 1 Working with JavaScript Creating a Programmable Web Page for North Pole.
Linux+ Guide to Linux Certification, Third Edition
Oct 15, 2007Sprenkle - CS1111 Objectives Creating your own functions.
Introduction to Exception Handling and Defensive Programming.
Variables and ConstantstMyn1 Variables and Constants PHP stands for: ”PHP: Hypertext Preprocessor”, and it is a server-side programming language. Special.
Chapter 14: Exception Handling. Objectives In this chapter, you will: – Learn what an exception is – Learn how to handle exceptions within a program –
An Object-Oriented Approach to Programming Logic and Design Chapter 3 Using Methods and Parameters.
Overview Intro to functions What are functions? Why use functions? Defining functions Calling functions Documenting functions Top-down design Variable.
XP Tutorial 10New Perspectives on HTML and XHTML, Comprehensive 1 Working with JavaScript Creating a Programmable Web Page for North Pole Novelties Tutorial.
Introduction to CMSSW Framework Concepts Simulation & Reconstruction Liz Sexton-Kennedy January 10, 2008.
Added Benefits Easier to debug –Can dump configurations or add inline printouts –Can validate files by compiling Can use command-line arguments, environmental.
Programming with Java © 2002 The McGraw-Hill Companies, Inc. All rights reserved. 1 McGraw-Hill/Irwin Chapter 5 Creating Classes.
Argonne Jamboree January 2010 Esteban Fullana AOD example analysis.
Testing OO software. State Based Testing State machine: implementation-independent specification (model) of the dynamic behaviour of the system State:
Introduction to Python Dr. José M. Reyes Álamo. 2 Three Rules of Programming Rule 1: Think before you program Rule 2: A program is a human-readable set.
XP New Perspectives on XML, 2 nd Edition Tutorial 7 1 TUTORIAL 7 CREATING A COMPUTATIONAL STYLESHEET.
Chapter 15: Exception Handling C++ Programming: Program Design Including Data Structures, Fifth Edition.
Programming Fundamentals. Topics to be covered Today Recursion Inline Functions Scope and Storage Class A simple class Constructor Destructor.
Linux+ Guide to Linux Certification, Second Edition
Manipulator example #include int main (void) { double x = ; streamsize prec = cout.precision(); cout
CSE 501N Fall ‘09 03: Class Members 03 September 2009 Nick Leidenfrost.
National Diploma Unit 4 Introduction to Software Development Procedures and Functions.
XP Tutorial 10New Perspectives on HTML, XHTML, and DHTML, Comprehensive 1 Working with JavaScript Creating a Programmable Web Page for North Pole Novelties.
FUNCTIONS (C) KHAERONI, M.SI. OBJECTIVE After this topic, students will be able to understand basic concept of user defined function in C++ to declare.
Linux Administration Working with the BASH Shell.
FILES AND EXCEPTIONS Topics Introduction to File Input and Output Using Loops to Process Files Processing Records Exceptions.
Topics Introduction to Repetition Structures
MET Experience at UF Bobby Scurlock University of Florida
Scripts & Functions Scripts and functions are contained in .m-files
Exceptions and files Taken from notes by Dr. Neil Moore
Chapter 14: Exception Handling
CS190/295 Programming in Python for Life Sciences: Lecture 1
Software Programming J. Holvikivi 2014.
Topics Introduction to File Input and Output
Exceptions and files Taken from notes by Dr. Neil Moore
Topics Introduction to File Input and Output
Review for Midterm 3.
Corresponds with Chapter 5
SPL – PS1 Introduction to C++.
Presentation transcript:

CMSSW Configuration in Python Rick Wilkinson June 19,

Outline Intro to the python language Work our way through a typical job config – Input, modules & services, execution paths, output Available Tools Not going to refer back to old configs 2

Introduction to Python Widely-used scripting language Object-oriented Nice syntax Lots of extensions Interfaces with C++ (boost::python) In transition now – Phasing out the old custom config language Will be the only config supported in upcoming CMSSW_2_1_0 3

More About Python No C++-style memory management needed Things are usually passed by reference – Except native numbers and strings – Be careful about changes that could affect others Control flow based on indentation – No “endif” statements, for example Comments use ‘#’ You can validate that your config file works python yourfile.py 4

CMS Python Types Most of the objects you’ll create will be of a CMS-specific type You’ll build up composite objects by adding other objects as constructor arguments import FWCore.ParameterSet.Config as cms jets = cms.EDProducer(“JetReco”, coneSize = cms.double(0.4), debug = cms.untracked.bool(True) ) 5

CMS Python Types DATA TYPESCOMPOSITESEXECUTIONMODULESMODIFIERS int32vint32ProcessEDProduceruntracked uint32vuint32SequenceEDAnalyzerESPrefer int64vint64PathEDFilter uint64vuint64EndPathESProducer doublevdoubleScheduleESSource boolvstringSequencePlace holder Source stringVPSetSecSource PSetVInputTagLooper InputTagVEventIDService EventIDOutputModule FileInPath 6

Python Modules (Not to be confused with framework modules!) A python file that is meant to be included by other files Lives in your Subsystem/Package/python/ area, or a subdirectory of it Filename conventions – _cfi.py: Definition of a single framework object – _cff.py: A “fragment” of configuration commands To make your module visible to other python modules: – Be sure your SCRAM environment is set up – Go to your python area once and ‘ scramv1 build ’ – No need to re-build after each change 7

Configuration files Controls the final job to be run Contains a cms.Process object named “ process ” Filename convention :_cfg.py Usually lives in python or test subdirectory Can be run by cmsRun cmsRun HLTExample_cfg.py 8

The Process object Process process = cms.Process(“JPsiAnalysis”) An input source process.source = cms.Source(“FlatRandomPtGunSource”, …) Some modules process.photons = cms.EDProducer(“PhotonProducer”, …) Some services process.add_(cms.ESSource(“XMLIdealGeometryESSource”,…)) Some execution paths process.p1 = cms.Path(process.localreco + process.globalreco) Maybe one or more output modules process.diMuonStream = cms.EDAnalyzer(“PoolOutputModule”, …) 9

How to Import Objects (I) To fetch all objects from some other module into this namespace: from Configuration.StandardSequences.Digi_cff import * Fetches all objects from: Configuration/StandardSequences/python/Digi_cff.py Fetches references, not copies – So any changes you make affect it everywhere! Or you can just pick out a single object from Configuration.StandardSequences.Reconstruction_cff import btagging 10

How to Import Objects (II) import Configuration.StandardSequences.RawToDigi_cff as unpacker Keeps python module object, which acts like a namespace – Safer & faster Again, imports a reference, so changes affect everywhere unpacker.ecalDigis.DoRegional = False process.ecalDigis = unpacker.ecalDigis 11

How To Import Objects (III) To load everything from a python module into your process object, you can say: process.load(“Configuration.StandardSequences.Sim_cff”) 12

cloning To make a copy of another module, and adding modifications: import ElectroWeakAnalysis.ZReco.zToMuMu_cfi as zmumu_cfi zToMuMuGolden = zmumu_cfi.zToMuMu.clone( massMin = cms.double(40) ) 13

Copying all the parameters from a PSet Give the external PSet’s name as a constructor argument after the framework module’s name before the named parameters KtJetParameters = cms.PSet( strategy = cms.string(“Best”) ) ktCaloJets = cms.EDProducer(“KtCaloJetProducer”, KtJetParameters, coneSize = cms.double(0.7) ) 14

Getting Parameters in C++ Your module will be passed an edm::ParameterSet in its constructor Values from the configuration can be retrieved in your C++ program using: double ptCut = pset.getParameter (“ptCut”); vector weights = pset.getParameter >(“weights”); 15

Modules EDProducer – Add objects into the events EDAnalyzer – Analyze objects from the event EDFilter – Can stop an execution path EDLooper – For multi-pass looping over events OutputModule – Write events to a file, and can specify filters 16

Framework Services Examples of Framework Services are: – Geometry, Calibration, MessageLogger Types are: – ESSource Provides data which has an Interval Of Validity (IOV) – ESProducer Creates products when IOV changes – Service Not IOV-dependent, e.g., MessageLogger 17

Execution Paths Sequence: a series of modules or sequences, used as components for paths. trDigi = cms.Sequence(siPixelDigis + siStripDigis) Path: Defines which modules and sequences to be run p1 = cms.Path(pdigi * reconstruction) Endpath: a list of analyzers or output modules to be run after all paths have been run. outpath = cms.EndPath(FEVT) Schedule: if not specified, defaults to all the paths present plus all the endpaths present process.schedule = cms.Schedule(process.p1 + process.outpath) 18

Sequence Operators + means ‘follows’ – Use when the previous module’s input isn’t required * means ‘depends on’ – Use when the module depends on a product created by the previous EDProducer. – Enforced by the configuration processor – Has precedence over ‘+’ Elements can be grouped using (), so (ecalRecHits + hcalRecHits) * caloTowers means that caloTowers needs both ecalRecHits and HcalRecHits, but ecal and hcal don’t depend on each other 19

Filters in paths When an EDFilter is in a path, returning “false” will cause the path to terminate. Two operators, ~ and -, can modify this: – ‘~’ Means “not”. The path will only continue if filter returns false. – ‘-’ means to ignore the result of the filter, and proceed regardless. jet500_1000 = cms.Path( ~jet1000filter + jet500filter + jetAnalysis ) Generic Filters exist in PhysicsTools/Utilities 20

tracked/untracked tracked parameters – Will be saved in the event data “provenance” – Cannot be “optional” If asked for and not found, will throw exception untracked parameters – For parameters which don’t affect results Debug level, for instance – Can have default values So they’re used for “optional” parameters, but not really considered safe practice 21

InputTags Used for fetching event data products – Most commonly by edm::Event::getByLabel() tagname = cms.InputTag(“label:instance:process”) tagname = cms.InputTag(label, instance, process) Label: the name of the producer which produced it Instance (optional): When a producer makes more than one product rpcHits = cms.InputTag(“g4SimHits”,”MuonRPCHits”) cscHits = cms.InputTag(“g4SimHits”,”MuonCSCHits”) Process (optional): The name of the job which created the data. Useful for when RECO and HLT make the same products. 22

Modifying Parameters You’re free to reach inside any parameter and change it from SimG4Core.Application.g4SimHits_cfi import * g4SimHits.UseMagneticField = False process.source.PGunParameters.PartID = [13,-13] If the right-hand side of the expression is a CMS type, a new parameter can be created # this line will fail, because of typos. Usually safer. g4SimHits.useMagmeticFeeld = False # this line will create a new variable with misspelled name g4SimHits.useMagmeticFeeld = cms.bool(False) 23

Putting it all together Your final cfg.py file typically includes: – A process – An input source Often a PoolSource, PythiaSource, or ParticleGunSource – Possibly a source of conditions Either FakeConditions_cff.py or FrontierConditions_GlobalTag_cff.py – One or more cff.py or cfi.py files Ideally from either Configuration/StandardSequences or your Analysis group – An OutputModule which chooses EventContent – Paths and an Endpath For examples, see Configuration/Examples area 24

Translating Old Config Files In FWCore/ParameterSet/python, you’ll find – translate.py Creates a python file based on your config file Creates any included files which may be needed – comments.py Transfers comments from old file edmTestCfgTranslation – Translates your config. – Tests whether the resulting ParameterSets match

Sample import FWCore.ParameterSet.Config as cms process = cms.Process(“SIM”) # Input source process.source = cms.Source("PoolSource", fileNames = cms.untracked.vstring('file:gen.root') ) # Modules process.load(“Configuration.StandardSequences.VtxSmearedGauss_cff”) process.load(“SimG4Core.Application.g4SimHits_cfi”) process.g4SimHits.UseMagneticField = False # Output process.load(“Configuration.EventContent.EventContent_cff”) process.FEVT = cms.OutputModule("PoolOutputModule", process.FEVTSIMEventContent, fileName = cms.untracked.string('sim.root') ) # Execution paths process.p1 = cms.Path(process.VtxSmeared+process.g4SimHits)

edmPythonTree Gives an indented dump of which files are included by which files Based on old config versions by Karoly Banicz & Sue Anne Koay  edmPythonTree RecoExample_GlobalTag_cfg.py + RecoExample_GlobalTag_cfg.py + Configuration/StandardSequences/python/Services_cff.py + SimGeneral/HepPDTESSource/python/pythiapdt_cfi.py +Configuration/StandardSequences/python/SimulationRandomNumberGeneratorSeeds_cff.py + IOMC/RandomEngine/python/IOMC_cff.py + Configuration/StandardSequences/python/Geometry_cff.py + Geometry/CMSCommonData/python/cmsIdealGeometryXML_cfi.py + Geometry/TrackerNumberingBuilder/python/trackerNumberingGeometry_cfi.py + Geometry/TrackerGeometryBuilder/python/trackerGeometry_cfi.py + Geometry/MuonNumbering/python/muonNumberingInitialization_cfi.py 27

edmPythonSearch Provides a ‘grep’-like syntax to search for identifiers within included files > edmPythonSearch minPt Reconstruction_cff.py RecoTracker/Configuration/python/RecoTracker_cff.py: newTrajectoryFilter.filterPset.minPt = 0.3 TrackingTools/TrajectoryFiltering/python/TrajectoryFilter_cff.py: minPt = cms.double(0.9), TrackingTools/TrajectoryFiltering/python/TrajectoryFilter_cff.py: minPt = cms.double(1.0), … 28

Closing Thoughts You probably won’t have to start writing config files or C++ modules from scratch – Find a similar example – Copy it and modify it Hopefully, this talk showed you: – What concepts CMSSW jobs use – Where you need to look to customize your jobs – What practices we consider “best” Most important: knowing who to ask! 29