CMS 3D CMS Logo

BeamSpotFakeConditions.cc
Go to the documentation of this file.
1 //
2 
3 #include <iostream>
4 #include <fstream>
5 #include <sstream>
6 #include <cstring>
7 #include <string>
8 #include <vector>
9 #include <memory>
10 
11 #include <TClass.h>
12 
21 
24 
26 public:
27  typedef std::unique_ptr<BeamSpotObjects> ReturnType;
29  ~BeamSpotFakeConditions() override;
31 
32 private:
34  const edm::IOVSyncValue &syncValue,
35  edm::ValidityInterval &oValidity) override;
40  double cov[7][7];
41  int type;
42 };
43 
45  setWhatProduced(this);
46  findingRecord<BeamSpotObjectsRcd>();
47  getDataFromFile_ = params.getParameter<bool>("getDataFromFile");
48  if (getDataFromFile_) {
49  inputFilename_ = params.getParameter<edm::FileInPath>("InputFilename");
50  std::ifstream fasciiFile(inputFilename_.fullPath().c_str());
51  fasciiFile >> tag >> type;
52  fasciiFile >> tag >> x;
53  fasciiFile >> tag >> y;
54  fasciiFile >> tag >> z;
55  fasciiFile >> tag >> sigmaZ;
56  fasciiFile >> tag >> dxdz;
57  fasciiFile >> tag >> dydz;
58  fasciiFile >> tag >> beamWidthX;
59  fasciiFile >> tag >> beamWidthY;
60  fasciiFile >> tag >> cov[0][0] >> cov[0][1] >> cov[0][2] >> cov[0][3] >> cov[0][4] >> cov[0][5] >> cov[0][6];
61  fasciiFile >> tag >> cov[1][0] >> cov[1][1] >> cov[1][2] >> cov[1][3] >> cov[1][4] >> cov[1][5] >> cov[1][6];
62  fasciiFile >> tag >> cov[2][0] >> cov[2][1] >> cov[2][2] >> cov[2][3] >> cov[2][4] >> cov[2][5] >> cov[2][6];
63  fasciiFile >> tag >> cov[3][0] >> cov[3][1] >> cov[3][2] >> cov[3][3] >> cov[3][4] >> cov[3][5] >> cov[3][6];
64  fasciiFile >> tag >> cov[4][0] >> cov[4][1] >> cov[4][2] >> cov[4][3] >> cov[4][4] >> cov[4][5] >> cov[4][6];
65  fasciiFile >> tag >> cov[5][0] >> cov[5][1] >> cov[5][2] >> cov[5][3] >> cov[5][4] >> cov[5][5] >> cov[5][6];
66  fasciiFile >> tag >> cov[6][0] >> cov[6][1] >> cov[6][2] >> cov[6][3] >> cov[6][4] >> cov[6][5] >> cov[6][6];
67  fasciiFile >> tag >> emittanceX;
68  fasciiFile >> tag >> emittanceY;
69  fasciiFile >> tag >> betastar;
70 
71  }
72  // input values by hand
73  else {
74  x = params.getParameter<double>("X0");
75  y = params.getParameter<double>("Y0");
76  z = params.getParameter<double>("Z0");
77  dxdz = params.getParameter<double>("dxdz");
78  dydz = params.getParameter<double>("dydz");
79  sigmaZ = params.getParameter<double>("sigmaZ");
80  beamWidthX = params.getParameter<double>("widthX");
81  beamWidthY = params.getParameter<double>("widthY");
82  emittanceX = params.getParameter<double>("emittanceX");
83  emittanceY = params.getParameter<double>("emittanceY");
84  betastar = params.getParameter<double>("betaStar");
85 
86  // first set all elements (esp. off-diagonal elements to zero)
87  for (int i = 0; i < 7; i++) {
88  for (int j = 0; j < 7; j++)
89  cov[i][j] = 0.0;
90  }
91 
92  // we ignore correlations when values are given by hand
93  cov[0][0] = pow(params.getParameter<double>("errorX0"), 2);
94  cov[1][1] = pow(params.getParameter<double>("errorY0"), 2);
95  cov[2][2] = pow(params.getParameter<double>("errorZ0"), 2);
96  cov[3][3] = pow(params.getParameter<double>("errorSigmaZ"), 2);
97  cov[4][4] = pow(params.getParameter<double>("errordxdz"), 2);
98  cov[5][5] = pow(params.getParameter<double>("errordydz"), 2);
99  cov[6][6] = pow(params.getParameter<double>("errorWidth"), 2);
100  }
101 }
102 
104 
106  ReturnType adummy = std::make_unique<BeamSpotObjects>();
107 
108  adummy->setPosition(x, y, z);
109  adummy->setSigmaZ(sigmaZ);
110  adummy->setdxdz(dxdz);
111  adummy->setdydz(dydz);
112  adummy->setBeamWidthX(beamWidthX);
113  adummy->setBeamWidthY(beamWidthY);
114  for (int i = 0; i < 7; i++) {
115  for (int j = 0; j < 7; j++) {
116  adummy->setCovariance(i, j, cov[i][j]);
117  }
118  }
119  adummy->setEmittanceX(emittanceX);
120  adummy->setEmittanceY(emittanceY);
121  adummy->setBetaStar(betastar);
122 
123  return adummy;
124 }
125 
127  const edm::IOVSyncValue &syncValue,
128  edm::ValidityInterval &oValidity) {
130 }
131 
auto setWhatProduced(T *iThis, const es::Label &iLabel={})
Definition: ESProducer.h:163
std::unique_ptr< BeamSpotObjects > ReturnType
std::string fullPath() const
Definition: FileInPath.cc:161
static const IOVSyncValue & endOfTime()
Definition: IOVSyncValue.cc:82
std::pair< Time_t, Time_t > ValidityInterval
Definition: Time.h:17
void setIntervalFor(const edm::eventsetup::EventSetupRecordKey &key, const edm::IOVSyncValue &syncValue, edm::ValidityInterval &oValidity) override
static const IOVSyncValue & beginOfTime()
Definition: IOVSyncValue.cc:88
#define DEFINE_FWK_EVENTSETUP_SOURCE(type)
Definition: SourceFactory.h:92
BeamSpotFakeConditions(const edm::ParameterSet &params)
Power< A, B >::type pow(const A &a, const B &b)
Definition: Power.h:29
ReturnType produce(const BeamSpotObjectsRcd &record)