CMS 3D CMS Logo

List of all members | Classes | Public Member Functions | Private Member Functions | Private Attributes
CTPPSProtonReconstructionEfficiencyEstimatorMC Class Reference
Inheritance diagram for CTPPSProtonReconstructionEfficiencyEstimatorMC:
edm::one::EDAnalyzer<> edm::one::EDAnalyzerBase edm::EDConsumerBase

Classes

struct  PlotGroup
 

Public Member Functions

 CTPPSProtonReconstructionEfficiencyEstimatorMC (const edm::ParameterSet &)
 
- Public Member Functions inherited from edm::one::EDAnalyzer<>
 EDAnalyzer ()=default
 
SerialTaskQueueglobalLuminosityBlocksQueue () final
 
SerialTaskQueueglobalRunsQueue () final
 
bool wantsGlobalLuminosityBlocks () const final
 
bool wantsGlobalRuns () const final
 
- Public Member Functions inherited from edm::one::EDAnalyzerBase
void callWhenNewProductsRegistered (std::function< void(BranchDescription const &)> const &func)
 
 EDAnalyzerBase ()
 
ModuleDescription const & moduleDescription () const
 
bool wantsStreamLuminosityBlocks () const
 
bool wantsStreamRuns () const
 
 ~EDAnalyzerBase () override
 
- Public Member Functions inherited from edm::EDConsumerBase
std::vector< ConsumesInfoconsumesInfo () const
 
void convertCurrentProcessAlias (std::string const &processName)
 Convert "@currentProcess" in InputTag process names to the actual current process name. More...
 
 EDConsumerBase ()
 
 EDConsumerBase (EDConsumerBase const &)=delete
 
 EDConsumerBase (EDConsumerBase &&)=default
 
ESProxyIndex const * esGetTokenIndices (edm::Transition iTrans) const
 
ProductResolverIndexAndSkipBit indexFrom (EDGetToken, BranchType, TypeID const &) const
 
void itemsMayGet (BranchType, std::vector< ProductResolverIndexAndSkipBit > &) const
 
void itemsToGet (BranchType, std::vector< ProductResolverIndexAndSkipBit > &) const
 
std::vector< ProductResolverIndexAndSkipBit > const & itemsToGetFrom (BranchType iType) const
 
void labelsForToken (EDGetToken iToken, Labels &oLabels) const
 
void modulesWhoseProductsAreConsumed (std::vector< ModuleDescription const * > &modules, ProductRegistry const &preg, std::map< std::string, ModuleDescription const * > const &labelsToDesc, std::string const &processName) const
 
EDConsumerBase const & operator= (EDConsumerBase const &)=delete
 
EDConsumerBaseoperator= (EDConsumerBase &&)=default
 
bool registeredToConsume (ProductResolverIndex, bool, BranchType) const
 
bool registeredToConsumeMany (TypeID const &, BranchType) const
 
ProductResolverIndexAndSkipBit uncheckedIndexFrom (EDGetToken) const
 
void updateLookup (BranchType iBranchType, ProductResolverIndexHelper const &, bool iPrefetchMayGet)
 
void updateLookup (eventsetup::ESRecordsToProxyIndices const &)
 
virtual ~EDConsumerBase () noexcept(false)
 

Private Member Functions

void analyze (const edm::Event &, const edm::EventSetup &) override
 
void endJob () override
 

Private Attributes

std::string lhcInfoLabel_
 
std::string outputFile_
 
std::map< unsigned int, std::map< unsigned int, PlotGroup > > plots_
 
std::map< unsigned int, unsigned int > rpDecId_far_
 
std::map< unsigned int, unsigned int > rpDecId_near_
 
unsigned int rpId_45_F_
 
unsigned int rpId_45_N_
 
unsigned int rpId_56_F_
 
unsigned int rpId_56_N_
 
edm::EDGetTokenT< edm::HepMCProducttokenHepMCAfterSmearing_
 
edm::EDGetTokenT< std::map< int, edm::DetSetVector< CTPPSPixelRecHit > > > tokenPixelRecHitsPerParticle_
 
edm::EDGetTokenT< reco::ForwardProtonCollectiontokenRecoProtonsMultiRP_
 
edm::EDGetTokenT< std::map< int, edm::DetSetVector< TotemRPRecHit > > > tokenStripRecHitsPerParticle_
 
edm::EDGetTokenT< CTPPSLocalTrackLiteCollectiontracksToken_
 
unsigned int verbosity_
 

Additional Inherited Members

- Public Types inherited from edm::one::EDAnalyzerBase
typedef EDAnalyzerBase ModuleType
 
- Public Types inherited from edm::EDConsumerBase
typedef ProductLabels Labels
 
- Static Public Member Functions inherited from edm::one::EDAnalyzerBase
static const std::string & baseType ()
 
static void fillDescriptions (ConfigurationDescriptions &descriptions)
 
static void prevalidate (ConfigurationDescriptions &descriptions)
 
- Protected Member Functions inherited from edm::EDConsumerBase
template<typename ProductType , BranchType B = InEvent>
EDGetTokenT< ProductType > consumes (edm::InputTag const &tag)
 
EDGetToken consumes (const TypeToGet &id, edm::InputTag const &tag)
 
template<BranchType B>
EDGetToken consumes (TypeToGet const &id, edm::InputTag const &tag)
 
ConsumesCollector consumesCollector ()
 Use a ConsumesCollector to gather consumes information from helper functions. More...
 
template<typename ProductType , BranchType B = InEvent>
void consumesMany ()
 
void consumesMany (const TypeToGet &id)
 
template<BranchType B>
void consumesMany (const TypeToGet &id)
 
template<typename ESProduct , typename ESRecord , Transition Tr = Transition::Event>
auto esConsumes ()
 
template<typename ESProduct , typename ESRecord , Transition Tr = Transition::Event>
auto esConsumes (ESInputTag const &tag)
 
template<typename ProductType , BranchType B = InEvent>
EDGetTokenT< ProductType > mayConsume (edm::InputTag const &tag)
 
EDGetToken mayConsume (const TypeToGet &id, edm::InputTag const &tag)
 
template<BranchType B>
EDGetToken mayConsume (const TypeToGet &id, edm::InputTag const &tag)
 

Detailed Description

Definition at line 39 of file CTPPSProtonReconstructionEfficiencyEstimatorMC.cc.

Constructor & Destructor Documentation

CTPPSProtonReconstructionEfficiencyEstimatorMC::CTPPSProtonReconstructionEfficiencyEstimatorMC ( const edm::ParameterSet iConfig)
explicit

Definition at line 95 of file CTPPSProtonReconstructionEfficiencyEstimatorMC.cc.

References np, plots_, rpDecId_far_, rpDecId_near_, rpId_45_F_, rpId_45_N_, rpId_56_F_, and rpId_56_N_.

98  consumes<edm::HepMCProduct>(iConfig.getParameter<edm::InputTag>("tagHepMCAfterSmearing"))),
100  iConfig.getParameter<edm::InputTag>("tagStripRecHitsPerParticle"))),
102  iConfig.getParameter<edm::InputTag>("tagPixelRecHitsPerParticle"))),
103  tracksToken_(consumes<CTPPSLocalTrackLiteCollection>(iConfig.getParameter<edm::InputTag>("tagTracks"))),
105  consumes<reco::ForwardProtonCollection>(iConfig.getParameter<InputTag>("tagRecoProtonsMultiRP"))),
106  lhcInfoLabel_(iConfig.getParameter<std::string>("lhcInfoLabel")),
107 
108  rpId_45_N_(iConfig.getParameter<unsigned int>("rpId_45_N")),
109  rpId_45_F_(iConfig.getParameter<unsigned int>("rpId_45_F")),
110  rpId_56_N_(iConfig.getParameter<unsigned int>("rpId_56_N")),
111  rpId_56_F_(iConfig.getParameter<unsigned int>("rpId_56_F")),
112 
113  outputFile_(iConfig.getParameter<string>("outputFile")),
114 
115  verbosity_(iConfig.getUntrackedParameter<unsigned int>("verbosity", 0))
116 {
119 
122 
123  // book plots
124  for (unsigned int arm = 0; arm < 2; ++arm) {
125  for (unsigned int np = 1; np <= 5; ++np)
126  plots_[arm][np] = PlotGroup();
127  }
128 }
T getParameter(std::string const &) const
T getUntrackedParameter(std::string const &, T const &) const
std::map< unsigned int, std::map< unsigned int, PlotGroup > > plots_
EDGetTokenT< ProductType > consumes(edm::InputTag const &tag)
edm::EDGetTokenT< reco::ForwardProtonCollection > tokenRecoProtonsMultiRP_
edm::EDGetTokenT< std::map< int, edm::DetSetVector< CTPPSPixelRecHit > > > tokenPixelRecHitsPerParticle_
int np
Definition: AMPTWrapper.h:33
edm::EDGetTokenT< std::map< int, edm::DetSetVector< TotemRPRecHit > > > tokenStripRecHitsPerParticle_

Member Function Documentation

void CTPPSProtonReconstructionEfficiencyEstimatorMC::analyze ( const edm::Event iEvent,
const edm::EventSetup iSetup 
)
overrideprivate

Definition at line 132 of file CTPPSProtonReconstructionEfficiencyEstimatorMC.cc.

References CTPPSDetId::arm(), LHCInfo::energy(), edm::EventSetup::get(), edm::Event::getByToken(), edm::HepMCProduct::GetEvent(), info(), lhcInfoLabel_, eostools::move(), AlCaHLTBitMon_ParallelJobs::p, plots_, createTree::pp, CTPPSDetId::rp(), rpDecId_far_, rpDecId_near_, year_2016_postTS2_cff::rpId, CTPPSDetId::sdTrackingPixel, CTPPSDetId::sdTrackingStrip, reco::ForwardProton::sector45, reco::ForwardProton::sector56, CTPPSDetId::station(), DetId::subdetId(), tokenHepMCAfterSmearing_, tokenPixelRecHitsPerParticle_, tokenRecoProtonsMultiRP_, tokenStripRecHitsPerParticle_, l1t::tracks, tracksToken_, verbosity_, and hybridSuperClusters_cfi::xi.

132  {
133  std::ostringstream os;
134 
135  // get conditions
136  edm::ESHandle<LHCInfo> hLHCInfo;
137  iSetup.get<LHCInfoRcd>().get(lhcInfoLabel_, hLHCInfo);
138 
139  // get input
140  edm::Handle<edm::HepMCProduct> hHepMCAfterSmearing;
141  iEvent.getByToken(tokenHepMCAfterSmearing_, hHepMCAfterSmearing);
142  HepMC::GenEvent *hepMCEventAfterSmearing = (HepMC::GenEvent *)hHepMCAfterSmearing->GetEvent();
143 
145  iEvent.getByToken(tokenStripRecHitsPerParticle_, hStripRecHitsPerParticle);
146 
148  iEvent.getByToken(tokenPixelRecHitsPerParticle_, hPixelRecHitsPerParticle);
149 
151  iEvent.getByToken(tracksToken_, tracks);
152 
153  Handle<reco::ForwardProtonCollection> hRecoProtonsMultiRP;
154  iEvent.getByToken(tokenRecoProtonsMultiRP_, hRecoProtonsMultiRP);
155 
156  // buffer for particle information
157  struct ParticleInfo {
158  unsigned int arm = 2;
159  double xi = 0.;
160  std::map<unsigned int, unsigned int> recHitsPerRP;
161  bool inAcceptanceNear = false, inAcceptanceFar = false, inAcceptance = false;
162  };
163 
164  std::map<int, ParticleInfo> particleInfo; // barcode --> info
165 
166  // process HepMC
167  for (auto it = hepMCEventAfterSmearing->particles_begin(); it != hepMCEventAfterSmearing->particles_end(); ++it) {
168  const auto &part = *it;
169 
170  // accept only stable non-beam protons
171  if (part->pdg_id() != 2212)
172  continue;
173 
174  if (part->status() != 1)
175  continue;
176 
177  if (part->is_beam())
178  continue;
179 
180  const auto &mom = part->momentum();
181 
182  if (mom.e() < 4500.)
183  continue;
184 
186 
187  info.arm = (mom.z() > 0.) ? 0 : 1;
188 
189  const double p_nom = hLHCInfo->energy();
190  info.xi = (p_nom - mom.rho()) / p_nom;
191 
192  particleInfo[part->barcode()] = std::move(info);
193  }
194 
195  // check acceptance
196  for (const auto &pp : *hStripRecHitsPerParticle) {
197  const auto barcode = pp.first;
198 
199  for (const auto &ds : pp.second) {
200  CTPPSDetId detId(ds.detId());
201  CTPPSDetId rpId = detId.getRPId();
202  particleInfo[barcode].recHitsPerRP[rpId] += ds.size();
203  }
204  }
205 
206  for (const auto &pp : *hPixelRecHitsPerParticle) {
207  const auto barcode = pp.first;
208 
209  for (const auto &ds : pp.second) {
210  CTPPSDetId detId(ds.detId());
211  CTPPSDetId rpId = detId.getRPId();
212  particleInfo[barcode].recHitsPerRP[rpId] += ds.size();
213  }
214  }
215 
216  std::map<unsigned int, bool> isStripRPNear, isStripRPFar;
217 
218  for (auto &pp : particleInfo) {
219  if (verbosity_)
220  os << "* barcode=" << pp.first << ", arm=" << pp.second.arm << ", xi=" << pp.second.xi << std::endl;
221 
222  for (const auto &rpp : pp.second.recHitsPerRP) {
223  CTPPSDetId rpId(rpp.first);
224  unsigned int needed_rec_hits = 1000;
225  if (rpId.subdetId() == CTPPSDetId::sdTrackingStrip)
226  needed_rec_hits = 6;
227  if (rpId.subdetId() == CTPPSDetId::sdTrackingPixel)
228  needed_rec_hits = 3;
229 
230  unsigned int rpDecId = rpId.arm() * 100 + rpId.station() * 10 + rpId.rp();
231 
232  if (rpId.subdetId() == CTPPSDetId::sdTrackingStrip) {
233  if (rpDecId == rpDecId_near_[rpId.arm()])
234  isStripRPNear[rpId.arm()] = true;
235  if (rpDecId == rpDecId_far_[rpId.arm()])
236  isStripRPFar[rpId.arm()] = true;
237  }
238 
239  if (rpp.second >= needed_rec_hits) {
240  if (rpDecId == rpDecId_near_[rpId.arm()])
241  pp.second.inAcceptanceNear = true;
242  if (rpDecId == rpDecId_far_[rpId.arm()])
243  pp.second.inAcceptanceFar = true;
244  }
245 
246  if (verbosity_)
247  os << " RP " << rpDecId << ": " << rpp.second << " hits" << std::endl;
248  }
249 
250  pp.second.inAcceptance = pp.second.inAcceptanceNear && pp.second.inAcceptanceFar;
251 
252  if (verbosity_)
253  os << " inAcceptance: near=" << pp.second.inAcceptanceNear << ", far=" << pp.second.inAcceptanceFar << ", global=" << pp.second.inAcceptance << std::endl;
254  }
255 
256  // count particles in acceptance
257  struct ArmCounter {
258  unsigned int near = 0, far = 0, global = 0;
259  };
260  std::map<unsigned int, ArmCounter> nParticlesInAcceptance;
261  for (auto &pp : particleInfo) {
262  auto &counter = nParticlesInAcceptance[pp.second.arm];
263  if (pp.second.inAcceptanceNear)
264  counter.near++;
265  if (pp.second.inAcceptanceFar)
266  counter.far++;
267  if (pp.second.inAcceptance)
268  counter.global++;
269  }
270 
271  // count reconstructed tracks
272  std::map<unsigned int, ArmCounter> nReconstructedTracks;
273  for (const auto &tr : *tracks) {
274  CTPPSDetId rpId(tr.getRPId());
275  unsigned int rpDecId = rpId.arm() * 100 + rpId.station() * 10 + rpId.rp();
276 
277  if (rpDecId == rpDecId_near_[rpId.arm()])
278  nReconstructedTracks[rpId.arm()].near++;
279  if (rpDecId == rpDecId_far_[rpId.arm()])
280  nReconstructedTracks[rpId.arm()].far++;
281  }
282 
283  // count reconstructed protons
284  std::map<unsigned int, unsigned int> nReconstructedProtons;
285  for (const auto &pr : *hRecoProtonsMultiRP) {
286  if (!pr.validFit())
287  continue;
288 
289  unsigned int arm = 2;
290  if (pr.lhcSector() == reco::ForwardProton::LHCSector::sector45)
291  arm = 0;
292  if (pr.lhcSector() == reco::ForwardProton::LHCSector::sector56)
293  arm = 1;
294 
295  nReconstructedProtons[arm]++;
296  }
297 
298  // fill plots
299  for (unsigned int arm = 0; arm < 2; arm++) {
300  const auto &npa = nParticlesInAcceptance[arm];
301  const auto &nrt = nReconstructedTracks[arm];
302 
303  if (verbosity_)
304  os << "* arm " << arm << ": nRecoProtons="
305  << nReconstructedProtons[arm] << " (tracks near=" << nReconstructedTracks[arm].near << ", far=" << nReconstructedTracks[arm].far
306  << "), nAcc=" << npa.global << " (near=" << npa.near << ", far=" << npa.far << ")" << std::endl;
307 
308  // skip event if no track in global acceptance
309  if (npa.global < 1)
310  continue;
311 
312  const auto &p = plots_[arm][npa.global];
313 
314  p.h_n_part_acc_nr->Fill(npa.near);
315  p.h_n_part_acc_fr->Fill(npa.far);
316 
317  // skip events with some local reconstruction inefficiency
318  if (nrt.near != npa.near || nrt.far != npa.far)
319  continue;
320 
321  const double eff = double(nReconstructedProtons[arm]) / npa.global;
322 
323  if (verbosity_)
324  os << " eff=" << eff << std::endl;
325 
326  for (auto &pp : particleInfo) {
327  if (pp.second.arm != arm || !pp.second.inAcceptance)
328  continue;
329 
330  p.p_eff_vs_xi->Fill(pp.second.xi, eff);
331  }
332  }
333 
334  if (verbosity_)
335  edm::LogInfo("CTPPSProtonReconstructionEfficiencyEstimatorMC") << os.str();
336 }
static const TGPicture * info(bool iBackgroundIsBlack)
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:517
std::map< unsigned int, std::map< unsigned int, PlotGroup > > plots_
edm::EDGetTokenT< reco::ForwardProtonCollection > tokenRecoProtonsMultiRP_
edm::EDGetTokenT< std::map< int, edm::DetSetVector< CTPPSPixelRecHit > > > tokenPixelRecHitsPerParticle_
CTPPSDetId getRPId() const
Definition: CTPPSDetId.h:78
const HepMC::GenEvent * GetEvent() const
Definition: HepMCProduct.h:38
part
Definition: HCALResponse.h:20
Base class for CTPPS detector IDs.
Definition: CTPPSDetId.h:32
T get() const
Definition: EventSetup.h:71
float const energy() const
Definition: LHCInfo.cc:192
edm::EDGetTokenT< std::map< int, edm::DetSetVector< TotemRPRecHit > > > tokenStripRecHitsPerParticle_
def move(src, dest)
Definition: eostools.py:511
void CTPPSProtonReconstructionEfficiencyEstimatorMC::endJob ( void  )
overrideprivatevirtual

Reimplemented from edm::one::EDAnalyzerBase.

Definition at line 340 of file CTPPSProtonReconstructionEfficiencyEstimatorMC.cc.

References DEFINE_FWK_MODULE, outputFile_, and plots_.

340  {
341  auto f_out = std::make_unique<TFile>(outputFile_.c_str(), "recreate");
342 
343  for (const auto &ait : plots_) {
344  char buf[100];
345  sprintf(buf, "arm%u", ait.first);
346  TDirectory *d_arm = f_out->mkdir(buf);
347 
348  for (const auto &npit : ait.second) {
349  sprintf(buf, "%u", npit.first);
350  TDirectory *d_np = d_arm->mkdir(buf);
351  gDirectory = d_np;
352 
353  npit.second.write();
354  }
355  }
356 }
std::map< unsigned int, std::map< unsigned int, PlotGroup > > plots_

Member Data Documentation

std::string CTPPSProtonReconstructionEfficiencyEstimatorMC::lhcInfoLabel_
private

Definition at line 56 of file CTPPSProtonReconstructionEfficiencyEstimatorMC.cc.

Referenced by analyze().

std::string CTPPSProtonReconstructionEfficiencyEstimatorMC::outputFile_
private

Definition at line 63 of file CTPPSProtonReconstructionEfficiencyEstimatorMC.cc.

Referenced by endJob().

std::map<unsigned int, std::map<unsigned int, PlotGroup> > CTPPSProtonReconstructionEfficiencyEstimatorMC::plots_
private
std::map<unsigned int, unsigned int> CTPPSProtonReconstructionEfficiencyEstimatorMC::rpDecId_far_
private
std::map<unsigned int, unsigned int> CTPPSProtonReconstructionEfficiencyEstimatorMC::rpDecId_near_
private
unsigned int CTPPSProtonReconstructionEfficiencyEstimatorMC::rpId_45_F_
private
unsigned int CTPPSProtonReconstructionEfficiencyEstimatorMC::rpId_45_N_
private
unsigned int CTPPSProtonReconstructionEfficiencyEstimatorMC::rpId_56_F_
private
unsigned int CTPPSProtonReconstructionEfficiencyEstimatorMC::rpId_56_N_
private
edm::EDGetTokenT<edm::HepMCProduct> CTPPSProtonReconstructionEfficiencyEstimatorMC::tokenHepMCAfterSmearing_
private

Definition at line 47 of file CTPPSProtonReconstructionEfficiencyEstimatorMC.cc.

Referenced by analyze().

edm::EDGetTokenT<std::map<int, edm::DetSetVector<CTPPSPixelRecHit> > > CTPPSProtonReconstructionEfficiencyEstimatorMC::tokenPixelRecHitsPerParticle_
private

Definition at line 50 of file CTPPSProtonReconstructionEfficiencyEstimatorMC.cc.

Referenced by analyze().

edm::EDGetTokenT<reco::ForwardProtonCollection> CTPPSProtonReconstructionEfficiencyEstimatorMC::tokenRecoProtonsMultiRP_
private

Definition at line 54 of file CTPPSProtonReconstructionEfficiencyEstimatorMC.cc.

Referenced by analyze().

edm::EDGetTokenT<std::map<int, edm::DetSetVector<TotemRPRecHit> > > CTPPSProtonReconstructionEfficiencyEstimatorMC::tokenStripRecHitsPerParticle_
private

Definition at line 49 of file CTPPSProtonReconstructionEfficiencyEstimatorMC.cc.

Referenced by analyze().

edm::EDGetTokenT<CTPPSLocalTrackLiteCollection> CTPPSProtonReconstructionEfficiencyEstimatorMC::tracksToken_
private

Definition at line 52 of file CTPPSProtonReconstructionEfficiencyEstimatorMC.cc.

Referenced by analyze().

unsigned int CTPPSProtonReconstructionEfficiencyEstimatorMC::verbosity_
private

Definition at line 65 of file CTPPSProtonReconstructionEfficiencyEstimatorMC.cc.

Referenced by analyze().