Skip to content

Commit 5e3b77f

Browse files
Add parameters description
1 parent e4cb98a commit 5e3b77f

File tree

2 files changed

+36
-2
lines changed

2 files changed

+36
-2
lines changed

README.md

+17
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,20 @@ scram b -j 8
3535
<li> <strong>test/</strong>: which contains cfg files to run the sequences defined in the python/ folder.</li>
3636
</ul>
3737

38+
### EDAnalyzer plugin
39+
40+
(to be completed)
41+
42+
### Configuration cfi files and parameters
43+
44+
Parameters are values that are defined "per sequence" and serve to configure how the code should run. For example, if we want to run the same EDAnalyzer for both data and Monte Carlo we may need to know if the generation variables can be accesed or not as if we try to access them in data we may likely get an error. This could be done via parameters.
45+
46+
Each parameter as a variable that is declared in the EDAnalyzer constructor as a private variable that can be used when the code is running. For example, to indicate if we are running on data samples we have can define a bool variable ```isData```:
47+
48+
49+
50+
### Configuration cfg files
51+
3852
## How to run
3953

4054
This example runs with a file of the 2023 NoBPTX dataset that may need to be accessed throught xrootd. Make sure that you have a valid proxy before running and do at least once:
@@ -54,6 +68,9 @@ cmsRun test/runNtuplizer_cfg.py
5468

5569
In this section (to be completed) there are several examples of how modify the existing analyzer.
5670

71+
### How to add a parameter
72+
73+
5774
### How to add new variables of an existing collection
5875

5976
1) We first need to declare a new variable that will act as a container for the value we want to store e.g. the number of displacedGlobalMuon tracks ```ndgl```. It is defined in the constructor of the EDAnalyzer as a private variable (although it could be also a global variable):

plugins/ntuplizer.cc

+19-2
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,8 @@ class ntuplizer : public edm::one::EDAnalyzer<edm::one::SharedResources> {
7070
// --- Variables
7171
//
7272

73+
bool isData = false;
74+
7375
// Event
7476
Int_t event = 0;
7577
Int_t lumiBlock = 0;
@@ -97,6 +99,7 @@ class ntuplizer : public edm::one::EDAnalyzer<edm::one::SharedResources> {
9799
Int_t dmu_isDSA[200] = {0};
98100
Int_t dmu_isDGL[200] = {0};
99101
Int_t dmu_isDTK[200] = {0};
102+
Float_t dmu_dsa_pt[200] = {0.};
100103

101104
//
102105
// --- Output
@@ -117,6 +120,7 @@ ntuplizer::ntuplizer(const edm::ParameterSet& iConfig) {
117120

118121
counts = new TH1F("counts", "", 1, 0, 1);
119122

123+
isData = consumes<edm::View<reco::Track> > (parameters.getParameter<edm::InputTag>("displacedGlobalCollection"));
120124
dglToken = consumes<edm::View<reco::Track> > (parameters.getParameter<edm::InputTag>("displacedGlobalCollection"));
121125
dsaToken = consumes<edm::View<reco::Track> > (parameters.getParameter<edm::InputTag>("displacedStandAloneCollection"));
122126
dmuToken = consumes<edm::View<pat::Muon> > (parameters.getParameter<edm::InputTag>("displacedMuonCollection"));
@@ -134,12 +138,15 @@ void ntuplizer::beginJob() {
134138

135139
std::cout << "Begin Job" << std::endl;
136140

141+
// Init the file and the TTree
137142
output_filename = parameters.getParameter<std::string>("nameOfOutput");
138143
file_out = new TFile(output_filename.c_str(), "RECREATE");
139-
140144
tree_out = new TTree("Events", "Events");
141145

142-
// Tree branches
146+
// Analyzer parameters
147+
isData = parameters.getParameter<bool>("isData");
148+
149+
// TTree branches
143150
tree_out->Branch("event", &event, "event/I");
144151
tree_out->Branch("lumiBlock", &lumiBlock, "lumiBlock/I");
145152
tree_out->Branch("run", &run, "run/I");
@@ -163,6 +170,7 @@ void ntuplizer::beginJob() {
163170
tree_out->Branch("dmu_isDSA", dmu_isDSA, "dmu_isDSA[ndmu]/I");
164171
tree_out->Branch("dmu_isDGL", dmu_isDGL, "dmu_isDGL[ndmu]/I");
165172
tree_out->Branch("dmu_isDTK", dmu_isDTK, "dmu_isDTK[ndmu]/I");
173+
tree_out->Branch("dmu_dsa_pt", dmu_dsa_pt, "dmu_dsa_pt[ndmu]/F");
166174

167175

168176
}
@@ -213,6 +221,7 @@ void ntuplizer::analyze(const edm::Event& iEvent, const edm::EventSetup& iSetup)
213221
dgl_pt[ndgl] = dgl.pt();
214222
dgl_eta[ndgl] = dgl.eta();
215223
dgl_phi[ndgl] = dgl.phi();
224+
dgl_nhits[ndgl] = dgl.hitPattern().numberOfValidHits();
216225
ndgl++;
217226
}
218227

@@ -223,6 +232,7 @@ void ntuplizer::analyze(const edm::Event& iEvent, const edm::EventSetup& iSetup)
223232
dsa_pt[ndsa] = dsa.pt();
224233
dsa_eta[ndsa] = dsa.eta();
225234
dsa_phi[ndsa] = dsa.phi();
235+
dsa_nhits[ndsa] = dsa.hitPattern().numberOfValidHits();
226236
ndsa++;
227237
}
228238

@@ -236,6 +246,13 @@ void ntuplizer::analyze(const edm::Event& iEvent, const edm::EventSetup& iSetup)
236246
dmu_isDGL[ndmu] = dmuon.isGlobalMuon();
237247
dmu_isDSA[ndmu] = dmuon.isStandAloneMuon();
238248
dmu_isDTK[ndmu] = dmuon.isTrackerMuon();
249+
250+
// Access the DSA track associated to the displacedMuon
251+
if ( dmuon.isStandAloneMuon() ) {
252+
const reco::Track* outerTrack = (dmuon.standAloneMuon()).get();
253+
dmu_dsa_pt[ndmu] = outerTrack->pt();
254+
}
255+
239256
ndmu++;
240257
}
241258

0 commit comments

Comments
 (0)