Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 12:29:03

0001 //
0002 
0003 #include <iostream>
0004 #include <fstream>
0005 #include <sstream>
0006 #include <cstring>
0007 #include <string>
0008 #include <vector>
0009 #include <memory>
0010 
0011 #include <TClass.h>
0012 
0013 #include "FWCore/Utilities/interface/Exception.h"
0014 #include "FWCore/Framework/interface/ESProducer.h"
0015 #include "FWCore/Framework/interface/EventSetupRecordIntervalFinder.h"
0016 #include "FWCore/Framework/interface/MakerMacros.h"
0017 #include "FWCore/Framework/interface/SourceFactory.h"
0018 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0019 #include "FWCore/ParameterSet/interface/FileInPath.h"
0020 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0021 
0022 #include "CondFormats/DataRecord/interface/BeamSpotObjectsRcd.h"
0023 #include "CondFormats/BeamSpotObjects/interface/BeamSpotObjects.h"
0024 
0025 class BeamSpotFakeConditions : public edm::ESProducer, public edm::EventSetupRecordIntervalFinder {
0026 public:
0027   typedef std::unique_ptr<BeamSpotObjects> ReturnType;
0028   BeamSpotFakeConditions(const edm::ParameterSet &params);
0029   ~BeamSpotFakeConditions() override;
0030   ReturnType produce(const BeamSpotObjectsRcd &record);
0031 
0032 private:
0033   void setIntervalFor(const edm::eventsetup::EventSetupRecordKey &key,
0034                       const edm::IOVSyncValue &syncValue,
0035                       edm::ValidityInterval &oValidity) override;
0036   edm::FileInPath inputFilename_;
0037   bool getDataFromFile_;
0038   double x, y, z, sigmaZ, dxdz, dydz, beamWidthX, beamWidthY, emittanceX, emittanceY, betastar;
0039   std::string tag;
0040   double cov[7][7];
0041   int type;
0042 };
0043 
0044 BeamSpotFakeConditions::BeamSpotFakeConditions(const edm::ParameterSet &params) {
0045   setWhatProduced(this);
0046   findingRecord<BeamSpotObjectsRcd>();
0047   getDataFromFile_ = params.getParameter<bool>("getDataFromFile");
0048   if (getDataFromFile_) {
0049     inputFilename_ = params.getParameter<edm::FileInPath>("InputFilename");
0050     std::ifstream fasciiFile(inputFilename_.fullPath().c_str());
0051     fasciiFile >> tag >> type;
0052     fasciiFile >> tag >> x;
0053     fasciiFile >> tag >> y;
0054     fasciiFile >> tag >> z;
0055     fasciiFile >> tag >> sigmaZ;
0056     fasciiFile >> tag >> dxdz;
0057     fasciiFile >> tag >> dydz;
0058     fasciiFile >> tag >> beamWidthX;
0059     fasciiFile >> tag >> beamWidthY;
0060     fasciiFile >> tag >> cov[0][0] >> cov[0][1] >> cov[0][2] >> cov[0][3] >> cov[0][4] >> cov[0][5] >> cov[0][6];
0061     fasciiFile >> tag >> cov[1][0] >> cov[1][1] >> cov[1][2] >> cov[1][3] >> cov[1][4] >> cov[1][5] >> cov[1][6];
0062     fasciiFile >> tag >> cov[2][0] >> cov[2][1] >> cov[2][2] >> cov[2][3] >> cov[2][4] >> cov[2][5] >> cov[2][6];
0063     fasciiFile >> tag >> cov[3][0] >> cov[3][1] >> cov[3][2] >> cov[3][3] >> cov[3][4] >> cov[3][5] >> cov[3][6];
0064     fasciiFile >> tag >> cov[4][0] >> cov[4][1] >> cov[4][2] >> cov[4][3] >> cov[4][4] >> cov[4][5] >> cov[4][6];
0065     fasciiFile >> tag >> cov[5][0] >> cov[5][1] >> cov[5][2] >> cov[5][3] >> cov[5][4] >> cov[5][5] >> cov[5][6];
0066     fasciiFile >> tag >> cov[6][0] >> cov[6][1] >> cov[6][2] >> cov[6][3] >> cov[6][4] >> cov[6][5] >> cov[6][6];
0067     fasciiFile >> tag >> emittanceX;
0068     fasciiFile >> tag >> emittanceY;
0069     fasciiFile >> tag >> betastar;
0070 
0071   }
0072   // input values by hand
0073   else {
0074     x = params.getParameter<double>("X0");
0075     y = params.getParameter<double>("Y0");
0076     z = params.getParameter<double>("Z0");
0077     dxdz = params.getParameter<double>("dxdz");
0078     dydz = params.getParameter<double>("dydz");
0079     sigmaZ = params.getParameter<double>("sigmaZ");
0080     beamWidthX = params.getParameter<double>("widthX");
0081     beamWidthY = params.getParameter<double>("widthY");
0082     emittanceX = params.getParameter<double>("emittanceX");
0083     emittanceY = params.getParameter<double>("emittanceY");
0084     betastar = params.getParameter<double>("betaStar");
0085 
0086     // first set all elements (esp. off-diagonal elements to zero)
0087     for (int i = 0; i < 7; i++) {
0088       for (int j = 0; j < 7; j++)
0089         cov[i][j] = 0.0;
0090     }
0091 
0092     // we ignore correlations when values are given by hand
0093     cov[0][0] = pow(params.getParameter<double>("errorX0"), 2);
0094     cov[1][1] = pow(params.getParameter<double>("errorY0"), 2);
0095     cov[2][2] = pow(params.getParameter<double>("errorZ0"), 2);
0096     cov[3][3] = pow(params.getParameter<double>("errorSigmaZ"), 2);
0097     cov[4][4] = pow(params.getParameter<double>("errordxdz"), 2);
0098     cov[5][5] = pow(params.getParameter<double>("errordydz"), 2);
0099     cov[6][6] = pow(params.getParameter<double>("errorWidth"), 2);
0100   }
0101 }
0102 
0103 BeamSpotFakeConditions::~BeamSpotFakeConditions() {}
0104 
0105 BeamSpotFakeConditions::ReturnType BeamSpotFakeConditions::produce(const BeamSpotObjectsRcd &record) {
0106   ReturnType adummy = std::make_unique<BeamSpotObjects>();
0107 
0108   adummy->setPosition(x, y, z);
0109   adummy->setSigmaZ(sigmaZ);
0110   adummy->setdxdz(dxdz);
0111   adummy->setdydz(dydz);
0112   adummy->setBeamWidthX(beamWidthX);
0113   adummy->setBeamWidthY(beamWidthY);
0114   for (int i = 0; i < 7; i++) {
0115     for (int j = 0; j < 7; j++) {
0116       adummy->setCovariance(i, j, cov[i][j]);
0117     }
0118   }
0119   adummy->setEmittanceX(emittanceX);
0120   adummy->setEmittanceY(emittanceY);
0121   adummy->setBetaStar(betastar);
0122 
0123   return adummy;
0124 }
0125 
0126 void BeamSpotFakeConditions::setIntervalFor(const edm::eventsetup::EventSetupRecordKey &key,
0127                                             const edm::IOVSyncValue &syncValue,
0128                                             edm::ValidityInterval &oValidity) {
0129   oValidity = edm::ValidityInterval(edm::IOVSyncValue::beginOfTime(), edm::IOVSyncValue::endOfTime());
0130 }
0131 
0132 DEFINE_FWK_EVENTSETUP_SOURCE(BeamSpotFakeConditions);