TWiki
>
Main Web
>
TWikiUsers
>
HalilGamsizkan
>
CMSSWCheatSheet
(2016-07-05,
HalilGamsizkan
)
(raw view)
E
dit
A
ttach
P
DF
---+ Cheatsheet: [[CMS.WorkBook][CMSSW]] Analysis a la Framework An unofficial information dump page for CMSSW. In below there's older and newer information together, I tried to separate them whenever I can. [[CMSPublic.WorkBook][CMSSW]] %TOC% ---++Accessing physics objects ---+++Electrons (PAT/MiniAOD) |Wiki pages|CMSPublic.WorkBookPATDataFormats#PatElectron, CMSPublic.WorkBookElectronAnalysis | |Add to buildfile|=<use name="DataFormats/PatCandidates"/>=| Related error: =undefined reference to `pat::Electron::electronID(std::string const&) const=| |Header file(s)|=#include <DataFormats/PatCandidates/interface/Electron.h>=| |Label|=slimmedElectrons=| |Collection type| =pat::ElectronCollection= (=vector<pat::Electron>=)| |Object reference| [[https://cmssdt.cern.ch/SDT/doxygen/CMSSW_5_3_14/doc/html/d2/d1f/classpat_1_1Electron.html][link]]| |Notes|To see available electron IDs in data, type a wrong ID name in the =electronID= method and framework will list them along with the error message.| %TWISTY{ mode="div" showlink="Show legacy information " hidelink="Hide legacy information " showimgright="%ICONURLPATH{toggleopen-small}%" hideimgright="%ICONURLPATH{toggleclose-small}%" }% ---+++ Generator Particles |Wiki page|CMS.WorkBookGenParticleCandidate| |Add to buildfile|=<use name=SimDataFormats/HepMCProduct>=| |Header file(s)| =#include "DataFormats/Candidate/interface/Candidate.h"= and %BR% =#include "DataFormats/JetReco/interface/GenJet.h"= if you need GEN jets| |Label|=genParticleCandidates=| |Collection type|=CandidateCollection=| |Physics Object| =[[http://cmsdoc.cern.ch/Releases/CMSSW/latest_release/doc/html/d6/de9/classreco_1_1Candidate-members.html][Candidate]]= %BR% [[http://projects.hepforge.org/rivet/code/hepmc/classHepMC_1_1GenParticle.html][GenParticle]]| ---+++Electrons |Wiki page|CMS.WorkBookElectronReco| |Add to buildfile|=<use name=DataFormats/EgammaReco>=| |Header file(s)|=#include "DataFormats/EgammaCandidates/interface/PixelMatchGsfElectron.h"=| |Label|=pixelMatchGsfElectrons=| |Collection type|=PixelMatchGsfElectronCollection=| |Physics Object| [[http://cmsdoc.cern.ch/Releases/CMSSW/latest_release/doc/html/d3/d30/classreco_1_1PixelMatchGsfElectron-members.html][PixelMatchGsfElectron]]| ---+++Photons |Wiki page|CMS.WorkBookPhotonReco| |Add to buildfile|=<use name=DataFormats/EgammaReco>=| |Header file(s)|=#include "DataFormats/EgammaCandidates/interface/Photon.h"=| |Label|=correctedPhotons= or =photons=| |Collection type|=PhotonCollection=| |Physics object|[[http://cmsdoc.cern.ch/Releases/CMSSW/latest_release/doc/html/da/da0/classreco_1_1Photon-members.html][reco::Photon]]| ---+++Jets |Wiki page|CMS.WorkBookJetAnalysis| |Add to buildfile|=<use name=DataFormats/JetReco>=| |Header file(s)|=#include "DataFormats/JetReco/interface/CaloJet.h"= %BR% =#include "DataFormats/JetReco/interface/GenJet.h"=| |Label|Many, e.g. =iterativeCone5CaloJets= %BR% =midPointCone5GenJets=| |Collection type|=CaloJetCollection= %BR% =GenJetCollection=| |Physics object|[[http://cmsdoc.cern.ch/Releases/CMSSW/latest_release/doc/html/d9/d5a/classreco_1_1Jet-members.html][reco::Jet]]| ---+++Muons |Wiki page|CMS.WorkBookMuonAnalysis| |Add to buildfile|=<use name=DataFormats/MuonReco>= %BR% =<use name=RecoMuon/TrackingTools>=| |Header file(s)|=#include "DataFormats/MuonReco/interface/Muon.h"=| |Label|=muons=| |Collection type|=MuonCollection=| | Physics Object | [[http://cmsdoc.cern.ch/Releases/CMSSW/latest_nightly/doc/html/d4/da2/classreco_1_1Muon-members.html][reco::Muon]]| |Example code| [[http://cmssw.cvs.cern.ch/cgi-bin/cmssw.cgi/CMSSW/RecoMuon/GlobalMuonProducer/test/][available]]| See [[https://hypernews.cern.ch/HyperNews/CMS/get/famos/79/1.html][this hypernews thread]] for the muons with fast simulation. ---+++MET |Wiki page| ??? | |Add to buildfile|=<use name=DataFormats/METReco>=| |Header file(s)|[[http://cmslxr.fnal.gov/lxr/source/DataFormats/METReco/interface/CaloMETCollection.h][#include "DataFormats/METReco/interface/CaloMETCollection.h"]]| |Label|=met=| |Collection type|=CaloMETCollection=| | Physics Object | [[http://cmsdoc.cern.ch/Releases/CMSSW/latest_release/doc/html/d5/d85/classreco_1_1CaloMET.html][reco::CaloMET]] | |Example code| Below, or in [[http://cmslxr.fnal.gov/lxr/source/ElectroWeakAnalysis/ZTauTau_DoubleTauJet/src/EWKTauAnalyser.cc#755][SusyAnalyzer]] | |Other | <verbatim> Handle<CaloMETCollection> met; iEvent.getByLabel("met", met); const CaloMET calomet = met->front(); cout << "met px=" << calomet.px() << ", py=" << calomet.py() << endl; </verbatim>| ---+++Vertices |Wiki page|CMS.WorkBookOfflinePrimaryVertexFinding| |Add to buildfile| ??? | |Header file(s)| =#include <DataFormats/VertexReco/interface/Vertex.h>= %BR% =#include <DataFormats/VertexReco/interface/VertexFwd.h>= | |Label|=offlinePrimaryVerticesFromCTFTracks= and =offlinePrimaryVerticesFromRSTracks=| |Collection type|[[http://cmslxr.fnal.gov/lxr/source/DataFormats/VertexReco/interface/VertexFwd.h#011][VertexCollection]]| |Physics object | [[http://cmsdoc.cern.ch/Releases/CMSSW/latest_release/doc/html/da/d95/classreco_1_1Vertex.html][reco::Vertex]] | |Example code|| ---+++ Tracks | Physics Object | [[http://cmsdoc.cern.ch/Releases/CMSSW/latest_release/doc/html/dd/d5b/classreco_1_1Track.html][reco::Track]]| ---+++ !CaloTowers These are combined objects from ECAL cells and HCAL towers, they represent the whole calorimetry and are used for e.g. jet reconstruction. |Wiki page|| |Header file(s)|[[http://cmslxr.fnal.gov/lxr/source/DataFormats/CaloTowers/interface/CaloTowerCollection.h][#include "DataFormats/CaloTowers/interface/CaloTowerCollection.h"]]| |Label|=towerMaker=| |Collection type|=CaloTowerCollection=| |Physics object | [[http://cmsdoc.cern.ch/Releases/CMSSW/latest_release/doc/html/d4/d06/classCaloTower-members.html][CaloTower]]| |Example code|| |Info|[[https://twiki.cern.ch/twiki/bin/view/CMS/WorkBook130JetAnalysis#CaloTower][1]]| <!-- ---+++L1/HLT Trigger |Wiki page|CMS.WorkBook.WorkBookHLTTutorial| |Add to buildfile|=<use name=HLTrigger/HLTcore>=%BR% =<use name=DataFormats/HLTReco>=%BR% =<use name=DataFormats/L1GlobalTrigger>= %BR% =<use name=DataFormats/L1Trigger>=| |Header file(s)|=#include "HLTrigger/HLTanalyzers/interface/HLTInfo.h"=, =#include "DataFormats/Common/interface/TriggerResults.h"=| |Label|=TriggerResults=| |Collection type|[[http://cmsdoc.cern.ch/Releases/CMSSW/latest_release/doc/html/de/d3a/classedm_1_1TriggerResults-members.html][TriggerResults]]| | Physics Object | ??? | |Example code| | --> * More labels, collections and documentation available [[https://twiki.cern.ch/twiki/bin/view/CMS/SWGuideDataFormatTable][here]]. * Namespace documentations: [[http://cmsdoc.cern.ch/Releases/CMSSW/latest_release/doc/html/d1/d57/namespacereco.html][reco]], [[http://cmsdoc.cern.ch/Releases/CMSSW/latest_release/doc/html/da/d1f/namespaceedm.html][edm]]. %ENDTWISTY% ---+++ "Handling" the data [[CMSPublic.SWGuideEDMGetDataFromEvent][Main article]] One accesses the data in the root file thru "handles". Handles types are templated with the collection/data type in the EDM root file. =EdmDumpEvent= prints the collection types in the first column of it's output. In the class definition, define as private the token<verbatim> edm::EDGetTokenT< pat::ElectronCollection > tok_electrons_;</verbatim> In the constructor assign it's value<verbatim> std::string labelElec_("slimmedElectrons"); tok_electrons_ = consumes< pat::ElectronCollection >(edm::InputTag(labelElec_));</verbatim> In the analysis code, handle it<verbatim> Handle<pat::ElectronCollection> elec; iEvent.getByToken( tok_electrons_, elec );</verbatim> %TWISTY{ mode="div" showlink="Show legacy information " hidelink="Hide legacy information " showimgright="%ICONURLPATH{toggleopen-small}%" hideimgright="%ICONURLPATH{toggleclose-small}%" }% Taken from [[https://twiki.cern.ch/twiki/bin/viewfile/CMS/May07PhysicsDaysTutorials?rev=1;filename=TutorialCERN0507dataformats.pdf][Benedikt's presentation]]:<verbatim> # by module and default product label Handle<TrackVector> trackPtr; iEvent.getByLabel("tracker", trackPtr ); # by module and product label Handle<MuonCollection>trackPtr; string muonModule_ = "paramMuons" string muonProduct_ = "ParamGlobalMuons" iEvent.getByLabel(muonModule_, muonProduct_, muons); # by type (what happens if not unique?) vector<Handle<SimHitVector> > allPtr; iEvent.getByType( allPtr ); # by Selector ParameterSelector<int> coneSel("coneSize",5); Handle<JetVector> jetPtr; iEvent.get( coneSel, jetPtr );</verbatim> %ENDTWISTY% ---+++ Looping over particles Handle types are =edm::Handle<CollectionType>= and collection types are usually =std::vector<ObjectType>=. if your product contains objects of type =ObjectType=, contained in collection of type =CollectionType= , and handled by the _variable_ =theHandle=: <verbatim> for (size_t j = 0; j < theHandle->size(); ++ j ) { const ObjectType & particle = (*theHandle)[ j ]; cout << "-> electron" << j << " pT: " << particle.pt() << " eta: " << particle.eta() << " phi: " << particle.phi() << endl; someHisto ->Fill( particle.pt() ); }; </verbatim> Yet another loop using an iterator<verbatim> size_t idx = 0; for( CollectionType::const_iterator cand = theHandle->begin(); cand != theHandle->end(); ++ cand, ++ idx ) { // do something, cand is a pointer to your object cout << "Electron #" << idx << ": pt=" << cand->pt() << endl; }</verbatim> ---++Code snippets/recipes ---+++Filtering events according to hlt path This goes to the cfg file:<verbatim> include "HLTrigger/HLTfilters/data/hltHighLevel.cfi" replace hltHighLevel.HLTPaths = {"CandHLT1SumET"} </verbatim> ---+++Sending a string to your analysis module from cfg file Let's send a filename to our analysis class. Your cfg file should look like zis:<verbatim> module somename = YourAnalysisClass { ... untracked string fname = "somefile.root" ... }</verbatim>and the header of your analysis class:<verbatim> class YourAnalysisClass : public edm::EDAnalyzer{ ... private: ... std::string fname_; ... </verbatim>finally the analysis class constructor:<verbatim> YourAnalysisClass::YourAnalysisClass(const edm::ParameterSet& cfg): fname_ ( cfg.getUntrackedParameter<string>( "fname" ) ) , <further parameters received here> { ... constructor code here... }</verbatim>Alternative way to receive parameters from within constructor: <verbatim> YourAnalysisClass::YourAnalysisClass(const edm::ParameterSet& cfg){ fname = cfg.getUntrackedParameter<string>( "fname" ); ... More constructor code/further parameter receiving code here.. } </verbatim>More information about other types is [[https://twiki.cern.ch/twiki/bin/view/CMS/SWGuideAboutConfigFile#Parameters][here]]. Info about cfg files is [[CMS.WorkBookConfigFileIntro][here]]. ---++ Is a parameter provided in the cfg file? <verbatim> MyAnalyzer::MyAnalyzer(const edm::ParameterSet &conf) { if (conf.exists("some_parameter")) do_something</verbatim> ---++ Does a certain product exist in your root file? <verbatim> Handle<L1GlobalTriggerReadoutRecord> L1GTRR; try {iEvent.getByLabel(l1GTReadoutRecTag_,L1GTRR);} catch (...) {;} if ( L1GTRR.isValid() ) { // exists</verbatim>or<verbatim> edm::Handle<edm::TriggerResults> trh; try {iEvent.getByLabel(triggerInputTag_,trh);} catch( cms::Exception& ex ) { LogWarning("HWWTreeDumper") << "Trigger results: " << triggerInputTag_ << " not found"; } if (!trh.isValid()) throw cms::Exception("ProductNotValid") << "TriggerResults product not valid";</verbatim> ---++ Setting the event generator random number seed Implementation in the =cfg= file is:<verbatim> service = RandomNumberGeneratorService { # This is to initialize the random engine of the source untracked uint32 sourceSeed = 123456789 }</verbatim> ---++ Arsenal There are numerous [[https://twiki.cern.ch/twiki/bin/view/CMS/SWGuidePhysicsTools][useful tools]] available for analyses. Using these tools will usually result in shorter code, and more reliable results; and the most important, If some of your results are just not OK, you can blame the developers on it :) * [[https://twiki.cern.ch/twiki/bin/view/CMS/SWGuideCandidateModules#Candidate_Selectors][Candidate selectors]] allow you to preselect physics objects on the fly, right within the =cfg= file. * [[https://twiki.cern.ch/twiki/bin/view/CMS/SWGuideCandidateModules#ParticleTreeDrawer_Utility][Gen decay tree analysis modules]], [[https://twiki.cern.ch/twiki/bin/view/CMS/SWGuideCandidateModules#ParticleListDrawer_Utility][ParticleListDrawer_Utility]] * [[https://twiki.cern.ch/twiki/bin/view/CMS/SWGuideCandCombiner#CandCombiner_Framework_Modules][Candidate combiner]] reconstructs decayed particles (e.g. mu+mu- -> Z). * [[https://twiki.cern.ch/twiki/bin/view/CMS/SWGuideCandidateModules#Candidate_Matching_Modules][Various matching modules]] * [[https://twiki.cern.ch/twiki/bin/view/CMS/SWGuideGenericIsolation][Isolation]] stuff. * Modules for [[https://twiki.cern.ch/twiki/bin/view/CMS/SWGuideCommonFilterModules][filtering events]]. * [[CMS.SWGuideCommonMathFunctions][Common math functions]] ---++ Locating/Accessing Datasets 1 To [[https://twiki.cern.ch/twiki/bin/view/CMS/WorkBookSetComputerNode#OpenCastorFiles][access root files from CMSSW]], use the following format:<verbatim> source = PoolSource{ untracked vstring fileNames = {'rfio:/castor/cern.ch/path/to/someData.root', 'another file', ... } } </verbatim> Here the =rfio:= prefix means that the file is on CASTOR. For a local file, use the =file:= prefix. 1 Now let's locate where the data is. Browse to the [[http://cmsdbs.cern.ch/DBS2_discovery/][DBS Dataset Discovery Page]] and search for the dataset of your interest. 1 Once you find your dataset, check it's location. If located at =srm.cern.ch= , then you can access it directly from =lxplus= since it's on CASTOR. Click "plain". You'll see a long list of root files in the form:<verbatim> /store/mc/year/month/day/<~dataset name>/<some number>/longnamedfile.root</verbatim> This path translates to CASTOR location =/castor/cern.ch/cms/<location>=. You can pick e.g. individual files this way. ( ="rfio:/castor/cern.ch/cms/store/RelVal/.../somedata.root"= or ="/store/RelVal/.../somedata.root"= ). 1 If you want to access the whoel dataset, click "cff" instead of "plain" on dataset's page. This will show you a =cff= file containing paths and names of all root files belonging to that dataset. Directly include this =cff= file in your =cfg= file. 1 Hint: While working on a single root file which is on CASTOR, copying it to =/tmp/$USER= and then accessing from there may speed up things. ---++Framework messages to file <verbatim> # Keep the logging output to a nice level # include "FWCore/MessageService/data/MessageLogger.cfi" replace MessageLogger.destinations = {"detailedInfo.txt"}</verbatim> ---++Other possibly useful stuff * Event selection using trigger-HLT bits: [[https://twiki.cern.ch/twiki/bin/view/CMS/SWGuideHighLevelTrigger#Event_selection_using_trigger_bi][here]]. * Skipping missing input root files (goes into the [[CMS.SWGuideEDMParametersForModules#PoolSource][PoolSource part]]):<verbatim> untracked bool skipBadFiles = true # skip missing or inaccessible files. Defaults to false</verbatim> Note that this won't prevent crashes with bad root files. * Skipping the first _n_ events in a root file:<verbatim> source = PoolSource { untracked vstring fileNames = { <empty or list of files> } untracked uint32 skipEvents = 21 }</verbatim> Skips the _first 21_ events. Note that the =FirstEvent= / =FirstRun= options may not work the same way. * Throwing exceptions <verbatim> throw cms::Exception("ErrorName") << "Message";</verbatim> FIXME: Add header * [[CMSPublic.SWGuideSkeletonCodeGenerator][Skeleton code generators]] are very useful. * Getting the cross-section of the generated event:<verbatim> Handle<double> genCrossSect; evt.getByLabel( "genEventRunInfo:PreCalculatedCrossSection", genCrossSect);</verbatim> * Useful tool: [[https://twiki.cern.ch/twiki/bin/view/CMS/CMSSWUserTools#addpkg_pl][addpkg]] , checks out packages from CVS. * List of [[http://cmssw.cvs.cern.ch/cgi-bin/cmssw.cgi/CMSSW/PhysicsTools/RecoCandAlgos/plugins/][candidate clone producers]]. * List of clone producers immediately available as [[http://cmssw.cvs.cern.ch/cgi-bin/cmssw.cgi/CMSSW/PhysicsTools/RecoCandAlgos/data/][modules]]. * CMSSW location on AFS (=cern.ch=): =/afs/cern.ch/cms/sw/slc4_ia32_gcc345/cms/cmssw/CMSSW_X_Y_Z=, * Other interesting locations on AFS (header files): * =$CMSSW_ROOT/src/DataFormats/Candidate/interface= * =$CMSSW_ROOT/src/DataFormats/Math/interface= * [[https://twiki.cern.ch/twiki/bin/view/CMS/SWGuideEDProducerAnalysis#Saving_a_Subsample_of_the_AOD_pl][Saving a Subsample of the AOD plus the User Data]] * See which physics objects a root file contains: =EdmDumpEventContent <root file>= * =scramv1 p= is the shorthand for =scramv1 project= . Other shorthands: =r= for =runtime= , =s= for =setup= * I don't know what exactly =scramv1 b --fast= does but I think unless you do not change your buildfiles and add/remove new source files it's safe to use this option which speeds up the compile. ---++ Dropping Products Put into =PoolSource= module block<verbatim> untracked vstring outputCommands = { "keep *", "drop *_*_*_HLT", "keep FEDRawDataCollection_*_*_*" } </verbatim>More info available [[CMS.SWGuideSelectingBranchesForOutput][here]]. ---++ Keeping Products <verbatim> untracked vstring outputCommands = { "drop *", # HepMC event. Famos uses it "keep edmHepMCProduct_source_*_*", "keep edmGenInfoProduct_source_*_*", # or "keep *_source_*_*", # Old gen event format "keep *_genParticleCandidates_*_*", # New gen event format "keep *_genParticles_*_*", # to be removed when no external MC ref's left # Keep trigger results "keep edmTriggerResults_TriggerResults_*_*", # if you chose to save all particles into a collection in PAT layer0, to make it persistent "keep *_*_allJets_*", # Gen jets "keep *_midPointCone5GenJetsNoNuBSM_*_*", # Calo towers "keep *_towerMaker_*_*", # CSA07 Stuff "keep *_genEventWeight_*_*", "keep *_genEventScale_*_*", "keep *_genEventProcID_*_*", "keep *_csa07EventWeightProducer_*_*"}</verbatim> ---++Notes * Keep your buildfiles as clean as possible. Smaller buildfiles, faster compiles. ---++ Useful Links Dump * [[CMS.WorkBookWhichRelease][Which CMSSW version to go?]] * [[CMS.TriggerTables][Trigger Tables, HLT, L1, Menu]] * [[CMS.SWGuideEDMParametersForModules][Module cfg file parameters]] * [[http://cmsdoc.cern.ch/Releases/CMSSW/latest_release/doc/html/index.html][CMSSW reference manual]] * [[http://cmssw.cvs.cern.ch/cgi-bin/cmssw.cgi/CMSSW/][CMSSW CVS (source) code browser]] * [[http://cmslxr.fnal.gov/lxr/][CMSSW CVS search facility]] (LXR) * [[CMS.CMSSW_aptinstaller][Installing CMSSW with apt-get]] * [[http://uncyclopedia.org/wiki/UnNews:Ask_Cthulhu/100407][Cthulhu]] is always there to help you with your whatever problems! %REVINFO%
E
dit
|
A
ttach
|
Watch
|
P
rint version
|
H
istory
: r54
<
r53
<
r52
<
r51
<
r50
|
B
acklinks
|
V
iew topic
|
WYSIWYG
|
M
ore topic actions
Topic revision: r54 - 2016-07-05
-
HalilGamsizkan
Log In
Main
Home
Index
Search
User Search
Changes
Notifications
RSS Feed
Documentation
Support
Webs
Main
Main Archive
Plugins
Sandbox for tests
Public webs
Public webs
ABATBEA
ACPP
ADCgroup
AEGIS
AfricaMap
AgileInfrastructure
ALICE
AliceEbyE
AliceSPD
AliceSSD
AliceTOF
AliFemto
ALPHA
ArdaGrid
ASACUSA
AthenaFCalTBAna
Atlas
AtlasLBNL
AXIALPET
CAE
CALICE
CDS
CENF
CERNSearch
CLIC
Cloud
CloudServices
CMS
Controls
CTA
CvmFS
DB
DefaultWeb
DESgroup
DPHEP
DM-LHC
DSSGroup
EGEE
EgeePtf
ELFms
EMI
ETICS
FIOgroup
FlukaTeam
Frontier
Gaudi
GeneratorServices
GuidesInfo
HardwareLabs
HCC
HEPIX
ILCBDSColl
ILCTPC
IMWG
Inspire
IPv6
IT
ItCommTeam
ITCoord
ITdeptTechForum
ITDRP
ITGT
ITSDC
LAr
LCG
LCGAAWorkbook
Leade
LHCAccess
LHCAtHome
LHCb
LHCgas
LHCONE
LHCOPN
LinuxSupport
Main
Medipix
Messaging
MPGD
NA49
NA61
NA62
NTOF
Openlab
PDBService
Persistency
PESgroup
Plugins
PSAccess
PSBUpgrade
R2Eproject
RCTF
RD42
RFCond12
RFLowLevel
ROXIE
Sandbox
SocialActivities
SPI
SRMDev
SSM
Student
SuperComputing
Support
SwfCatalogue
TMVA
TOTEM
TWiki
UNOSAT
Virtualization
VOBox
WITCH
XTCA
Welcome Guest
Login
or
Register
Cern Search
TWiki Search
Google Search
Main
All webs
Copyright &© 2008-2019 by the contributing authors. All material on this collaboration platform is the property of the contributing authors.
Ideas, requests, problems regarding TWiki?
Send feedback