CMS 3D CMS Logo

PPSDirectSimulationData.cc
Go to the documentation of this file.
2 
9 
10 #include "TFile.h"
11 
12 #include <iostream>
13 #include <string>
14 
16  : empiricalAperture45_(""),
17  empiricalAperture56_(""),
18 
19  timeResolutionDiamonds45_(""),
20  timeResolutionDiamonds56_("") {}
21 
23 
24 // Getters
27 
30 
31 std::map<unsigned int, PPSDirectSimulationData::FileObject> &PPSDirectSimulationData::getEfficienciesPerRP() {
32  return efficienciesPerRP_;
33 }
34 std::map<unsigned int, PPSDirectSimulationData::FileObject> &PPSDirectSimulationData::getEfficienciesPerPlane() {
35  return efficienciesPerPlane_;
36 };
37 
38 // Setters
41 
44 
45 std::map<unsigned int, std::unique_ptr<TH2F>> PPSDirectSimulationData::loadEffeciencyHistogramsPerRP() const {
46  std::map<unsigned int, std::unique_ptr<TH2F>> result;
47 
48  for (const auto &it : efficienciesPerRP_)
49  result[it.first] = loadObject(it.second.first, it.second.second);
50 
51  return result;
52 }
53 
54 std::map<unsigned int, std::unique_ptr<TH2F>> PPSDirectSimulationData::loadEffeciencyHistogramsPerPlane() const {
55  std::map<unsigned int, std::unique_ptr<TH2F>> result;
56 
57  for (const auto &it : efficienciesPerPlane_) {
58  CTPPSDetId rpId(it.first);
59 
60  if (rpId.subdetId() == CTPPSDetId::sdTrackingStrip) {
61  for (unsigned int pl = 0; pl < 10; ++pl) {
62  TotemRPDetId plId(rpId.arm(), rpId.station(), rpId.rp(), pl);
63  result[plId] = loadObject(it.second.first, replace(it.second.second, "<detid>", std::to_string(pl)));
64  }
65  }
66 
67  if (rpId.subdetId() == CTPPSDetId::sdTrackingPixel) {
68  for (unsigned int pl = 0; pl < 6; ++pl) {
69  CTPPSPixelDetId plId(rpId.arm(), rpId.station(), rpId.rp(), pl);
70  result[plId] = loadObject(it.second.first, replace(it.second.second, "<detid>", std::to_string(pl)));
71  }
72  }
73 
74  if (rpId.subdetId() == CTPPSDetId::sdTimingDiamond) {
75  for (unsigned int pl = 0; pl < 4; ++pl) {
76  CTPPSDiamondDetId plId(rpId.arm(), rpId.station(), rpId.rp(), pl);
77  result[plId] = loadObject(it.second.first, replace(it.second.second, "<detid>", std::to_string(pl)));
78  }
79  }
80  }
81 
82  return result;
83 }
84 
85 std::unique_ptr<TH2F> PPSDirectSimulationData::loadObject(const std::string &file, const std::string &object) {
86  edm::FileInPath fip(file.c_str());
87  TFile *f_in = TFile::Open(fip.fullPath().c_str());
88  if (!f_in)
89  throw cms::Exception("PPS") << "Cannot open file '" << fip.fullPath() << "'.";
90 
91  TH2F *o_in = (TH2F *)f_in->Get(object.c_str());
92  if (!o_in)
93  throw cms::Exception("PPS") << "Cannot load object '" << object << "' from file '" << fip.fullPath() << "'.";
94 
95  // disassociate histogram from the file
96  o_in->SetDirectory(nullptr);
97 
98  delete f_in;
99 
100  return std::unique_ptr<TH2F>(o_in);
101 }
102 
104  size_t start_pos = 0;
105  while ((start_pos = input.find(from, start_pos)) != std::string::npos) {
106  input.replace(start_pos, from.length(), to);
107  start_pos += to.length();
108  }
109  return input;
110 }
PPSDirectSimulationData::getTimeResolutionDiamonds56
const std::string & getTimeResolutionDiamonds56() const
Definition: PPSDirectSimulationData.cc:29
PPSDirectSimulationData::getTimeResolutionDiamonds45
const std::string & getTimeResolutionDiamonds45() const
Definition: PPSDirectSimulationData.cc:28
input
static const std::string input
Definition: EdmProvDump.cc:48
PPSDirectSimulationData::loadEffeciencyHistogramsPerPlane
std::map< unsigned int, std::unique_ptr< TH2F > > loadEffeciencyHistogramsPerPlane() const
Definition: PPSDirectSimulationData.cc:54
PPSDirectSimulationData::efficienciesPerPlane_
std::map< unsigned int, FileObject > efficienciesPerPlane_
Definition: PPSDirectSimulationData.h:44
PPSDirectSimulationData::loadEffeciencyHistogramsPerRP
std::map< unsigned int, std::unique_ptr< TH2F > > loadEffeciencyHistogramsPerRP() const
Definition: PPSDirectSimulationData.cc:45
PPSDirectSimulationData::empiricalAperture45_
std::string empiricalAperture45_
Definition: PPSDirectSimulationData.h:38
PPSDirectSimulationData::getEfficienciesPerPlane
std::map< unsigned int, FileObject > & getEfficienciesPerPlane()
Definition: PPSDirectSimulationData.cc:34
CTPPSPixelDetId.h
to
PPSDirectSimulationData::PPSDirectSimulationData
PPSDirectSimulationData()
Definition: PPSDirectSimulationData.cc:15
PPSDirectSimulationData::empiricalAperture56_
std::string empiricalAperture56_
Definition: PPSDirectSimulationData.h:39
PPSDirectSimulationData::setEmpiricalAperture45
void setEmpiricalAperture45(std::string s)
Definition: PPSDirectSimulationData.cc:39
PPSDirectSimulationData::~PPSDirectSimulationData
~PPSDirectSimulationData()
Definition: PPSDirectSimulationData.cc:22
FileInPath.h
edm::FileInPath
Definition: FileInPath.h:64
CTPPSDetId::sdTrackingStrip
Definition: CTPPSDetId.h:44
alignCSCRings.s
s
Definition: alignCSCRings.py:92
CTPPSDetId::sdTimingDiamond
Definition: CTPPSDetId.h:44
PPSDirectSimulationData::efficienciesPerRP_
std::map< unsigned int, FileObject > efficienciesPerRP_
Definition: PPSDirectSimulationData.h:44
PPSDirectSimulationData::loadObject
static std::unique_ptr< TH2F > loadObject(const std::string &file, const std::string &object)
Definition: PPSDirectSimulationData.cc:85
CTPPSDetId::sdTrackingPixel
Definition: CTPPSDetId.h:44
AlCaHLTBitMon_QueryRunRegistry.string
string
Definition: AlCaHLTBitMon_QueryRunRegistry.py:256
CTPPSDiamondDetId.h
PPSDirectSimulationData::setEmpiricalAperture56
void setEmpiricalAperture56(std::string s)
Definition: PPSDirectSimulationData.cc:40
PPSDirectSimulationData::setTimeResolutionDiamonds56
void setTimeResolutionDiamonds56(std::string s)
Definition: PPSDirectSimulationData.cc:43
CTPPSDiamondDetId
Detector ID class for CTPPS Timing Diamond detectors. Bits [19:31] : Assigend in CTPPSDetId Calss Bit...
Definition: CTPPSDiamondDetId.h:24
CTPPSDetId
Base class for CTPPS detector IDs.
Definition: CTPPSDetId.h:31
FrontierConditions_GlobalTag_cff.file
file
Definition: FrontierConditions_GlobalTag_cff.py:13
CTPPSPixelDetId
Definition: CTPPSPixelDetId.h:16
PPSDirectSimulationData::timeResolutionDiamonds56_
std::string timeResolutionDiamonds56_
Definition: PPSDirectSimulationData.h:42
PPSDirectSimulationData.h
PPSDirectSimulationData::getEfficienciesPerRP
std::map< unsigned int, FileObject > & getEfficienciesPerRP()
Definition: PPSDirectSimulationData.cc:31
profile_2016_postTS2_cff.rpId
rpId
Definition: profile_2016_postTS2_cff.py:21
PPSDirectSimulationData::setTimeResolutionDiamonds45
void setTimeResolutionDiamonds45(std::string s)
Definition: PPSDirectSimulationData.cc:42
Exception
Definition: hltDiff.cc:245
TotemRPDetId.h
PPSDirectSimulationData::replace
static std::string replace(std::string input, const std::string &from, const std::string &to)
Definition: PPSDirectSimulationData.cc:103
CTPPSDetId.h
Exception.h
PPSDirectSimulationData::timeResolutionDiamonds45_
std::string timeResolutionDiamonds45_
Definition: PPSDirectSimulationData.h:41
PPSDirectSimulationData::getEmpiricalAperture56
const std::string & getEmpiricalAperture56() const
Definition: PPSDirectSimulationData.cc:26
mps_fire.result
result
Definition: mps_fire.py:311
PPSDirectSimulationData::getEmpiricalAperture45
const std::string & getEmpiricalAperture45() const
Definition: PPSDirectSimulationData.cc:25
TotemRPDetId
Detector ID class for TOTEM Si strip detectors.
Definition: TotemRPDetId.h:29