CMS 3D CMS Logo

CTPPSInterpolatedOpticalFunctionsESSource.cc
Go to the documentation of this file.
1 // authors: Jan Kaspar (jan.kaspar@gmail.com)
2 
8 
10 
14 
18 
19 
21 {
22  public:
25 
26  static void fillDescriptions(edm::ConfigurationDescriptions &descriptions);
27 
28  std::shared_ptr<LHCInterpolatedOpticalFunctionsSetCollection> produce(const CTPPSInterpolatedOpticsRcd&);
29 
30  private:
32 
35  std::shared_ptr<LHCInterpolatedOpticalFunctionsSetCollection> currentData_;
36 };
37 
38 //----------------------------------------------------------------------------------------------------
39 //----------------------------------------------------------------------------------------------------
40 
42  lhcInfoLabel_(iConfig.getParameter<std::string>("lhcInfoLabel")),
45 {
47 }
48 
49 //----------------------------------------------------------------------------------------------------
50 
52 {
54 
55  desc.add<std::string>("lhcInfoLabel", "")
56  ->setComment("label of the LHCInfo record");
57 
58  descriptions.add("ctppsInterpolatedOpticalFunctionsESSource", desc);
59 }
60 
61 //----------------------------------------------------------------------------------------------------
62 
63 std::shared_ptr<LHCInterpolatedOpticalFunctionsSetCollection> CTPPSInterpolatedOpticalFunctionsESSource::produce(const CTPPSInterpolatedOpticsRcd& iRecord)
64 {
65  // get the input data
67  iRecord.getRecord<CTPPSOpticsRcd>().get(hOFColl);
68 
69  edm::ESHandle<LHCInfo> hLHCInfo;
70  iRecord.getRecord<LHCInfoRcd>().get(lhcInfoLabel_, hLHCInfo);
71 
72  // is there anything to do?
74  return currentData_;
75 
76  // is crossing angle reasonable (LHCInfo is correctly filled in DB)?
77  if (hLHCInfo->crossingAngle() == 0.)
78  {
79  edm::LogInfo("CTPPSInterpolatedOpticalFunctionsESSource") << "Invalid crossing angle, no optical functions produced.";
80 
81  currentDataValid_ = false;
83  currentData_ = std::make_shared<LHCInterpolatedOpticalFunctionsSetCollection>();
84 
85  return currentData_;
86  }
87 
88  // set new crossing angle
90  edm::LogInfo("CTPPSInterpolatedOpticalFunctionsESSource") << "Crossing angle has changed to " << currentCrossingAngle_ << ".";
91 
92  // is input optics available ?
93  if (hOFColl->empty())
94  {
95  edm::LogInfo("CTPPSInterpolatedOpticalFunctionsESSource") << "No input optics available, no optical functions produced.";
96 
97  currentDataValid_ = false;
98  currentData_ = std::make_shared<LHCInterpolatedOpticalFunctionsSetCollection>();
99 
100  return currentData_;
101  }
102 
103  // regular case with single-xangle input
104  if (hOFColl->size() == 1)
105  {
106  const auto &it = hOFColl->begin();
107 
108  // does the input xangle correspond to the actual one?
109  if (fabs(currentCrossingAngle_ - it->first) > 1e-6)
110  throw cms::Exception("CTPPSInterpolatedOpticalFunctionsESSource") << "Cannot interpolate: input given only for xangle "
111  << it->first << " while interpolation requested for " << currentCrossingAngle_ << ".";
112 
113  currentData_ = std::make_shared<LHCInterpolatedOpticalFunctionsSetCollection>();
114  for (const auto &rp_p : it->second)
115  {
116  const auto rpId = rp_p.first;
117  LHCInterpolatedOpticalFunctionsSet iof(rp_p.second);
118  iof.initializeSplines();
119  currentData_->emplace(rpId, std::move(iof));
120  }
121 
122  currentDataValid_ = true;
123  }
124 
125  // regular case with multi-xangle input
126  if (hOFColl->size() > 1)
127  {
128  // find the closest xangle points for interpolation
129  auto it1 = hOFColl->begin();
130  auto it2 = std::next(it1);
131 
132  if (currentCrossingAngle_ > it1->first)
133  {
134  for (; it1 != hOFColl->end(); ++it1)
135  {
136  it2 = std::next(it1);
137 
138  if (it2 == hOFColl->end())
139  {
140  it2 = it1;
141  it1 = std::prev(it1);
142  break;
143  }
144 
145  if (it1->first <= currentCrossingAngle_ && currentCrossingAngle_ < it2->first)
146  break;
147  }
148  }
149 
150  const auto &xangle1 = it1->first;
151  const auto &xangle2 = it2->first;
152 
153  const auto &ofs1 = it1->second;
154  const auto &ofs2 = it2->second;
155 
156  // do the interpoaltion RP by RP
157  currentData_ = std::make_shared<LHCInterpolatedOpticalFunctionsSetCollection>();
158  for (const auto &rp_p : ofs1)
159  {
160  const auto rpId = rp_p.first;
161  const auto &rp_it2 = ofs2.find(rpId);
162  if (rp_it2 == ofs2.end())
163  throw cms::Exception("CTPPSInterpolatedOpticalFunctionsESSource") << "RP mismatch between ofs1 and ofs2.";
164 
165  const auto &of1 = rp_p.second;
166  const auto &of2 = rp_it2->second;
167 
168  const size_t num_xi_vals1 = of1.getXiValues().size();
169  const size_t num_xi_vals2 = of2.getXiValues().size();
170 
171  if (num_xi_vals1 != num_xi_vals2)
172  throw cms::Exception("CTPPSInterpolatedOpticalFunctionsESSource") << "Size mismatch between ofs1 and ofs2.";
173 
174  const size_t num_xi_vals = num_xi_vals1;
175 
177  iof.m_z = of1.getScoringPlaneZ();
179  iof.m_xi_values.resize(num_xi_vals);
180 
181  for (size_t fi = 0; fi < of1.getFcnValues().size(); ++fi)
182  {
183  iof.m_fcn_values[fi].resize(num_xi_vals);
184 
185  for (size_t pi = 0; pi < num_xi_vals; ++pi)
186  {
187  double xi = of1.getXiValues()[pi];
188  double xi_control = of2.getXiValues()[pi];
189 
190  if (fabs(xi - xi_control) > 1e-6)
191  throw cms::Exception("CTPPSInterpolatedOpticalFunctionsESSource") << "Xi mismatch between ofs1 and ofs2.";
192 
193  iof.m_xi_values[pi] = xi;
194 
195  double v1 = of1.getFcnValues()[fi][pi];
196  double v2 = of2.getFcnValues()[fi][pi];
197  iof.m_fcn_values[fi][pi] = v1 + (v2 - v1) / (xangle2 - xangle1) * (currentCrossingAngle_ - xangle1);
198  }
199  }
200 
201  iof.initializeSplines();
202 
203  currentDataValid_ = true;
204  currentData_->emplace(rpId, std::move(iof));
205  }
206  }
207 
208  return currentData_;
209 }
210 
211 //----------------------------------------------------------------------------------------------------
212 
auto setWhatProduced(T *iThis, const es::Label &iLabel={})
Definition: ESProducer.h:124
std::shared_ptr< LHCInterpolatedOpticalFunctionsSetCollection > currentData_
std::shared_ptr< LHCInterpolatedOpticalFunctionsSetCollection > produce(const CTPPSInterpolatedOpticsRcd &)
const Double_t pi
float const crossingAngle() const
Definition: LHCInfo.cc:176
std::vector< double > m_xi_values
void initializeSplines()
builds splines from m_*_values fields
ParameterDescriptionBase * add(U const &iLabel, T const &value)
#define DEFINE_FWK_EVENTSETUP_MODULE(type)
Definition: ModuleFactory.h:60
std::vector< std::vector< double > > m_fcn_values
length unit cm
Set of optical functions corresponding to one scoring plane along LHC, including splines for interpol...
void add(std::string const &label, ParameterSetDescription const &psetDescription)
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
double m_z
position of the scoring plane, in LHC/TOTEM convention, cm
def move(src, dest)
Definition: eostools.py:511