CMS 3D CMS Logo

ProtonProducer.cc
Go to the documentation of this file.
1 // -*- C++ -*-
2 //
3 // Package: PhysicsTools/NanoAOD
4 // Class: ProtonProducer
5 //
10 //
11 // Original Author: Justin Williams
12 // Created: 04 Jul 2019 15:27:53 GMT
13 //
14 //
15 
16 // system include files
17 #include <memory>
18 #include <map>
19 #include <string>
20 #include <vector>
21 #include <iostream>
22 
23 // user include files
26 
29 
32 
34 
37 
43 
45 public:
48  mayConsume<reco::ForwardProtonCollection>(ps.getParameter<edm::InputTag>("tagRecoProtonsMulti"))),
50  mayConsume<reco::ForwardProtonCollection>(ps.getParameter<edm::InputTag>("tagRecoProtonsSingle"))),
51  tokenTracksLite_(mayConsume<std::vector<CTPPSLocalTrackLite>>(ps.getParameter<edm::InputTag>("tagTrackLite"))),
52  storeSingleRPProtons_(ps.getParameter<bool>("storeSingleRPProtons")) {
53  produces<edm::ValueMap<int>>("arm");
54  produces<nanoaod::FlatTable>("ppsTrackTable");
56  produces<edm::ValueMap<int>>("protonRPId");
57  }
58  ~ProtonProducer() override {}
59 
60  // ------------ method called to produce the data ------------
61  void produce(edm::StreamID id, edm::Event &iEvent, const edm::EventSetup &iSetup) const override {
62  // Get Forward Proton handle
64  iEvent.getByToken(tokenRecoProtonsMultiRP_, hRecoProtonsMultiRP);
65 
66  edm::Handle<reco::ForwardProtonCollection> hRecoProtonsSingleRP;
67  iEvent.getByToken(tokenRecoProtonsSingleRP_, hRecoProtonsSingleRP);
68 
69  // Get PPS Local Track handle
71  iEvent.getByToken(tokenTracksLite_, ppsTracksLite);
72 
73  // book output variables for protons
74  std::vector<int> multiRP_arm;
75 
76  // book output variables for tracks
77  std::vector<float> trackX, trackY, trackTime, trackTimeUnc;
78  std::vector<int> multiRPProtonIdx, decRPId, rpType;
79  std::vector<int> singleRPProtonIdx, singleRP_protonRPId;
80 
82  // process single-RP protons
83  {
84  const auto &num_proton = hRecoProtonsSingleRP->size();
85  singleRP_protonRPId.reserve(num_proton);
86 
87  for (const auto &proton : *hRecoProtonsSingleRP) {
88  CTPPSDetId rpId((*proton.contributingLocalTracks().begin())->rpId());
89  unsigned int rpDecId = rpId.arm() * 100 + rpId.station() * 10 + rpId.rp();
90  singleRP_protonRPId.push_back(rpDecId);
91  }
92  }
93 
94  // process multi-RP protons
95  {
96  const auto &num_proton = hRecoProtonsMultiRP->size();
97  multiRP_arm.reserve(num_proton);
98 
99  for (const auto &proton : *hRecoProtonsMultiRP) {
100  multiRP_arm.push_back((proton.pz() < 0.) ? 1 : 0);
101  }
102  }
103 
104  // process local tracks
105  for (unsigned int tr_idx = 0; tr_idx < ppsTracksLite->size(); ++tr_idx) {
106  const auto &tr = ppsTracksLite->at(tr_idx);
107 
108  bool found = false;
109 
110  CTPPSDetId rpId(tr.rpId());
111  unsigned int rpDecId = rpId.arm() * 100 + rpId.station() * 10 + rpId.rp();
112 
113  signed int singleRP_idx = -1;
114  for (unsigned int p_idx = 0; p_idx < hRecoProtonsSingleRP->size(); ++p_idx) {
115  const auto &proton = hRecoProtonsSingleRP->at(p_idx);
116 
117  for (const auto &ref : proton.contributingLocalTracks()) {
118  if (ref.key() == tr_idx) {
119  singleRP_idx = p_idx;
120  found = true;
121  }
122  }
123  }
124 
125  signed int multiRP_idx = -1;
126  for (unsigned int p_idx = 0; p_idx < hRecoProtonsMultiRP->size(); ++p_idx) {
127  const auto &proton = hRecoProtonsMultiRP->at(p_idx);
128 
129  for (const auto &ref : proton.contributingLocalTracks()) {
130  if (ref.key() == tr_idx) {
131  multiRP_idx = p_idx;
132  found = true;
133  }
134  }
135  }
136 
137  if (found) {
138  singleRPProtonIdx.push_back(singleRP_idx);
139  multiRPProtonIdx.push_back(multiRP_idx);
140  decRPId.push_back(rpDecId);
141  rpType.push_back(rpId.subdetId());
142  trackX.push_back(tr.x());
143  trackY.push_back(tr.y());
144  trackTime.push_back(tr.time());
145  trackTimeUnc.push_back(tr.timeUnc());
146  }
147  }
148  }
149 
150  else {
151  for (unsigned int p_idx = 0; p_idx < hRecoProtonsMultiRP->size(); ++p_idx) {
152  const auto &proton = hRecoProtonsMultiRP->at(p_idx);
153  multiRP_arm.push_back((proton.pz() < 0.) ? 1 : 0);
154 
155  for (const auto &ref : proton.contributingLocalTracks()) {
156  multiRPProtonIdx.push_back(p_idx);
157  CTPPSDetId rpId(ref->rpId());
158  unsigned int rpDecId = rpId.arm() * 100 + rpId.station() * 10 + rpId.rp();
159  decRPId.push_back(rpDecId);
160  rpType.push_back(rpId.subdetId());
161  trackX.push_back(ref->x());
162  trackY.push_back(ref->y());
163  trackTime.push_back(ref->time());
164  trackTimeUnc.push_back(ref->timeUnc());
165  }
166  }
167  }
168 
169  // update proton tables
170  std::unique_ptr<edm::ValueMap<int>> multiRP_armV(new edm::ValueMap<int>());
171  edm::ValueMap<int>::Filler fillermultiArm(*multiRP_armV);
172  fillermultiArm.insert(hRecoProtonsMultiRP, multiRP_arm.begin(), multiRP_arm.end());
173  fillermultiArm.fill();
174 
175  std::unique_ptr<edm::ValueMap<int>> protonRPIdV(new edm::ValueMap<int>());
176  edm::ValueMap<int>::Filler fillerID(*protonRPIdV);
177  if (storeSingleRPProtons_) {
178  fillerID.insert(hRecoProtonsSingleRP, singleRP_protonRPId.begin(), singleRP_protonRPId.end());
179  fillerID.fill();
180  }
181 
182  // build track table
183  auto ppsTab = std::make_unique<nanoaod::FlatTable>(trackX.size(), "PPSLocalTrack", false);
184  ppsTab->addColumn<int>("multiRPProtonIdx", multiRPProtonIdx, "local track - proton correspondence");
186  ppsTab->addColumn<int>("singleRPProtonIdx", singleRPProtonIdx, "local track - proton correspondence");
187  ppsTab->addColumn<float>("x", trackX, "local track x", 16);
188  ppsTab->addColumn<float>("y", trackY, "local track y", 13);
189  ppsTab->addColumn<float>("time", trackTime, "local track time", 16);
190  ppsTab->addColumn<float>("timeUnc", trackTimeUnc, "local track time uncertainty", 13);
191  ppsTab->addColumn<int>("decRPId", decRPId, "local track detector dec id");
192  ppsTab->addColumn<int>("rpType", rpType, "strip=3, pixel=4, diamond=5, timing=6");
193  ppsTab->setDoc("ppsLocalTrack variables");
194 
195  // save output
196  iEvent.put(std::move(multiRP_armV), "arm");
197  iEvent.put(std::move(ppsTab), "ppsTrackTable");
199  iEvent.put(std::move(protonRPIdV), "protonRPId");
200  }
201 
202  // ------------ method fills 'descriptions' with the allowed parameters for the module ------------
205  desc.add<edm::InputTag>("tagRecoProtonsMulti")->setComment("multiRP proton collection");
206  desc.add<edm::InputTag>("tagRecoProtonsSingle")->setComment("singleRP proton collection");
207  desc.add<edm::InputTag>("tagTrackLite")->setComment("pps local tracks lite collection");
208  desc.add<bool>("storeSingleRPProtons")->setComment("flag to store singleRP protons and associated tracks");
209  descriptions.add("ProtonProducer", desc);
210  }
211 
212 protected:
217 };
218 
edm::StreamID
Definition: StreamID.h:30
CTPPSLocalTrackLite
Local (=single RP) track with essential information only.
Definition: CTPPSLocalTrackLite.h:18
electrons_cff.bool
bool
Definition: electrons_cff.py:366
edm::helper::Filler::insert
void insert(const H &h, I begin, I end)
Definition: ValueMap.h:53
ProtonProducer::storeSingleRPProtons_
const bool storeSingleRPProtons_
Definition: ProtonProducer.cc:216
CTPPSPixelLocalTrack.h
edm::EDGetTokenT< reco::ForwardProtonCollection >
edm
HLT enums.
Definition: AlignableModifier.h:19
ProtonProducer::tokenTracksLite_
const edm::EDGetTokenT< std::vector< CTPPSLocalTrackLite > > tokenTracksLite_
Definition: ProtonProducer.cc:215
HLT_FULL_cff.InputTag
InputTag
Definition: HLT_FULL_cff.py:89301
edm::helper::Filler::fill
void fill()
Definition: ValueMap.h:65
edm::ParameterSetDescription
Definition: ParameterSetDescription.h:52
CTPPSLocalTrackLite.h
reco
fixed size matrix
Definition: AlignmentAlgorithmBase.h:46
EffectiveAreas.h
newFWLiteAna.found
found
Definition: newFWLiteAna.py:118
edm::Handle
Definition: AssociativeIterator.h:50
MakerMacros.h
DEFINE_FWK_MODULE
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
edm::ConfigurationDescriptions::add
void add(std::string const &label, ParameterSetDescription const &psetDescription)
Definition: ConfigurationDescriptions.cc:57
edm::EDConsumerBase::mayConsume
EDGetTokenT< ProductType > mayConsume(edm::InputTag const &tag)
Definition: EDConsumerBase.h:179
ProtonProducer::~ProtonProducer
~ProtonProducer() override
Definition: ProtonProducer.cc:58
ProtonProducer::tokenRecoProtonsSingleRP_
const edm::EDGetTokenT< reco::ForwardProtonCollection > tokenRecoProtonsSingleRP_
Definition: ProtonProducer.cc:214
ProtonProducer::fillDescriptions
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
Definition: ProtonProducer.cc:203
ForwardProtonFwd.h
edm::global::EDProducer
Definition: EDProducer.h:32
edm::ConfigurationDescriptions
Definition: ConfigurationDescriptions.h:28
reco::ForwardProtonCollection
std::vector< ForwardProton > ForwardProtonCollection
Collection of ForwardProton objects.
Definition: ForwardProtonFwd.h:25
edm::ParameterSet
Definition: ParameterSet.h:47
Event.h
ForwardProton.h
CTPPSDetId
Base class for CTPPS detector IDs.
Definition: CTPPSDetId.h:31
iEvent
int iEvent
Definition: GenABIO.cc:224
trackerHitRTTI::vector
Definition: trackerHitRTTI.h:21
edm::EventSetup
Definition: EventSetup.h:58
ProtonProducer::ProtonProducer
ProtonProducer(edm::ParameterSet const &ps)
Definition: ProtonProducer.cc:46
ProtonProducer
Definition: ProtonProducer.cc:44
FlatTable.h
ProtonProducer::tokenRecoProtonsMultiRP_
const edm::EDGetTokenT< reco::ForwardProtonCollection > tokenRecoProtonsMultiRP_
Definition: ProtonProducer.cc:213
ValueMap.h
profile_2016_postTS2_cff.rpId
rpId
Definition: profile_2016_postTS2_cff.py:21
submitPVResolutionJobs.desc
string desc
Definition: submitPVResolutionJobs.py:251
eostools.move
def move(src, dest)
Definition: eostools.py:511
std
Definition: JetResolutionObject.h:76
Frameworkfwd.h
edm::ValueMap< int >
protons_cff.decRPId
decRPId
Definition: protons_cff.py:56
CTPPSDetId.h
edm::helper::Filler
Definition: ValueMap.h:22
ParameterSet.h
EDProducer.h
edm::Event
Definition: Event.h:73
StreamID.h
edm::InputTag
Definition: InputTag.h:15
ProtonProducer::produce
void produce(edm::StreamID id, edm::Event &iEvent, const edm::EventSetup &iSetup) const override
Definition: ProtonProducer.cc:61