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;
30  ReturnType produce(const BeamSpotObjectsRcd &record);
31 private:
32  void setIntervalFor(const edm::eventsetup::EventSetupRecordKey &key,const edm::IOVSyncValue &syncValue,edm::ValidityInterval &oValidity) override;
37  double cov[7][7];
38  int type;
39 
40 };
41 
43 {
44  setWhatProduced(this);
45  findingRecord<BeamSpotObjectsRcd>();
46  getDataFromFile_ = params.getParameter<bool>("getDataFromFile");
47  if (getDataFromFile_) {
48  inputFilename_ = params.getParameter<edm::FileInPath>("InputFilename");
49  std::ifstream fasciiFile(inputFilename_.fullPath().c_str() );
50  fasciiFile >> tag >> type;
51  fasciiFile >> tag >> x;
52  fasciiFile >> tag >> y;
53  fasciiFile >> tag >> z;
54  fasciiFile >> tag >> sigmaZ;
55  fasciiFile >> tag >> dxdz;
56  fasciiFile >> tag >> dydz;
57  fasciiFile >> tag >> beamWidthX;
58  fasciiFile >> tag >> beamWidthY;
59  fasciiFile >> tag >> cov[0][0] >> cov[0][1] >> cov[0][2]>> cov[0][3] >> cov[0][4]>> cov[0][5] >> cov[0][6]
60  ;
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  ;
63  fasciiFile >> tag >> cov[2][0] >> cov[2][1] >> cov[2][2] >> cov[2][3]>> cov[2][4] >> cov[2][5]>> cov[2][6
64  ];
65  fasciiFile >> tag >> cov[3][0] >> cov[3][1] >> cov[3][2] >> cov[3][3]>> cov[3][4] >> cov[3][5]>> cov[3][6
66  ];
67  fasciiFile >> tag >> cov[4][0] >> cov[4][1] >> cov[4][2] >> cov[4][3]>> cov[4][4] >> cov[4][5]>> cov[4][6]
68  ;
69  fasciiFile >> tag >> cov[5][0] >> cov[5][1] >> cov[5][2] >> cov[5][3]>> cov[5][4] >> cov[5][5]>> cov[5][6]
70  ;
71  fasciiFile >> tag >> cov[6][0] >> cov[6][1] >> cov[6][2] >> cov[6][3]>> cov[6][4] >> cov[6][5]>> cov[6][6]
72  ;
73  fasciiFile >> tag >> emittanceX;
74  fasciiFile >> tag >> emittanceY;
75  fasciiFile >> tag >> betastar;
76 
77  }
78  // input values by hand
79  else {
80  x = params.getParameter<double>( "X0" );
81  y = params.getParameter<double>( "Y0" );
82  z = params.getParameter<double>( "Z0" );
83  dxdz = params.getParameter<double>( "dxdz" );
84  dydz = params.getParameter<double>( "dydz" );
85  sigmaZ = params.getParameter<double>( "sigmaZ" );
86  beamWidthX = params.getParameter<double>( "widthX" );
87  beamWidthY = params.getParameter<double>( "widthY" );
88  emittanceX = params.getParameter<double>( "emittanceX" );
89  emittanceY = params.getParameter<double>( "emittanceY" );
90  betastar = params.getParameter<double>( "betaStar" );
91 
92  // first set all elements (esp. off-diagonal elements to zero)
93  for (int i=0; i<7; i++ ) {
94  for (int j=0; j<7; j++) cov[i][j] = 0.0;
95  }
96 
97  // we ignore correlations when values are given by hand
98  cov[0][0] = pow( params.getParameter<double>( "errorX0" ), 2 );
99  cov[1][1] = pow( params.getParameter<double>( "errorY0" ), 2 );
100  cov[2][2] = pow( params.getParameter<double>( "errorZ0" ), 2 );
101  cov[3][3] = pow( params.getParameter<double>( "errorSigmaZ" ), 2 );
102  cov[4][4] = pow( params.getParameter<double>( "errordxdz" ), 2 );
103  cov[5][5] = pow( params.getParameter<double>( "errordydz" ), 2 );
104  cov[6][6] = pow( params.getParameter<double>( "errorWidth" ), 2 );
105 
106  }
107 }
108 
110 
113 
114 
115  ReturnType adummy = std::make_unique<BeamSpotObjects>();
116 
117  adummy->SetPosition( x, y , z );
118  adummy->SetSigmaZ( sigmaZ);
119  adummy->Setdxdz( dxdz );
120  adummy->Setdydz( dydz );
121  adummy->SetBeamWidthX( beamWidthX );
122  adummy->SetBeamWidthY( beamWidthY );
123  for (int i=0; i<7; i++ ) {
124  for (int j=0; j<7; j++) {
125 
126  adummy->SetCovariance( i, j, cov[i][j] );
127  }
128  }
129  adummy->SetEmittanceX( emittanceX );
130  adummy->SetEmittanceY( emittanceY );
131  adummy->SetBetaStar( betastar);
132 
133  return adummy;
134 }
135 
137  const edm::IOVSyncValue &syncValue,
138  edm::ValidityInterval &oValidity){
141 }
142 
T getParameter(std::string const &) const
std::unique_ptr< BeamSpotObjects > ReturnType
JetCorrectorParameters::Record record
Definition: classes.h:7
static const IOVSyncValue & endOfTime()
Definition: IOVSyncValue.cc:97
std::pair< Time_t, Time_t > ValidityInterval
Definition: Time.h:19
void setWhatProduced(T *iThis, const es::Label &iLabel=es::Label())
Definition: ESProducer.h:115
void setIntervalFor(const edm::eventsetup::EventSetupRecordKey &key, const edm::IOVSyncValue &syncValue, edm::ValidityInterval &oValidity) override
static const IOVSyncValue & beginOfTime()
#define DEFINE_FWK_EVENTSETUP_SOURCE(type)
Definition: SourceFactory.h:92
BeamSpotFakeConditions(const edm::ParameterSet &params)
std::string fullPath() const
Definition: FileInPath.cc:197
Power< A, B >::type pow(const A &a, const B &b)
Definition: Power.h:40
ReturnType produce(const BeamSpotObjectsRcd &record)