Go to the documentation of this file.00001
00002
00003 #include <iostream>
00004 #include <fstream>
00005 #include <sstream>
00006 #include <cstring>
00007 #include <string>
00008 #include <vector>
00009 #include <memory>
00010
00011 #include <boost/shared_ptr.hpp>
00012
00013 #include <TClass.h>
00014
00015 #include "FWCore/Utilities/interface/Exception.h"
00016 #include "FWCore/Framework/interface/ESProducer.h"
00017 #include "FWCore/Framework/interface/EventSetupRecordIntervalFinder.h"
00018 #include "FWCore/Framework/interface/MakerMacros.h"
00019 #include "FWCore/Framework/interface/SourceFactory.h"
00020 #include "FWCore/ParameterSet/interface/ParameterSet.h"
00021 #include "FWCore/ParameterSet/interface/FileInPath.h"
00022 #include "FWCore/MessageLogger/interface/MessageLogger.h"
00023
00024 #include "CondFormats/DataRecord/interface/BeamSpotObjectsRcd.h"
00025 #include "CondFormats/BeamSpotObjects/interface/BeamSpotObjects.h"
00026
00027 class BeamSpotFakeConditions : public edm::ESProducer, public edm::EventSetupRecordIntervalFinder {
00028 public:
00029 typedef boost::shared_ptr<BeamSpotObjects> ReturnType;
00030 BeamSpotFakeConditions(const edm::ParameterSet ¶ms);
00031 virtual ~BeamSpotFakeConditions();
00032 ReturnType produce(const BeamSpotObjectsRcd &record);
00033 private:
00034 void setIntervalFor(const edm::eventsetup::EventSetupRecordKey &key,const edm::IOVSyncValue &syncValue,edm::ValidityInterval &oValidity);
00035 edm::FileInPath inputFilename_;
00036 bool getDataFromFile_;
00037 double x,y,z,sigmaZ,dxdz,dydz,beamWidthX,beamWidthY,emittanceX,emittanceY,betastar;
00038 std::string tag;
00039 double cov[7][7];
00040 int type;
00041
00042 };
00043
00044 BeamSpotFakeConditions::BeamSpotFakeConditions(const edm::ParameterSet ¶ms)
00045 {
00046 setWhatProduced(this);
00047 findingRecord<BeamSpotObjectsRcd>();
00048 getDataFromFile_ = params.getParameter<bool>("getDataFromFile");
00049 if (getDataFromFile_) {
00050 inputFilename_ = params.getParameter<edm::FileInPath>("InputFilename");
00051 std::ifstream fasciiFile(inputFilename_.fullPath().c_str() );
00052 fasciiFile >> tag >> type;
00053 fasciiFile >> tag >> x;
00054 fasciiFile >> tag >> y;
00055 fasciiFile >> tag >> z;
00056 fasciiFile >> tag >> sigmaZ;
00057 fasciiFile >> tag >> dxdz;
00058 fasciiFile >> tag >> dydz;
00059 fasciiFile >> tag >> beamWidthX;
00060 fasciiFile >> tag >> beamWidthY;
00061 fasciiFile >> tag >> cov[0][0] >> cov[0][1] >> cov[0][2]>> cov[0][3] >> cov[0][4]>> cov[0][5] >> cov[0][6]
00062 ;
00063 fasciiFile >> tag >> cov[1][0] >> cov[1][1] >> cov[1][2] >> cov[1][3]>> cov[1][4] >> cov[1][5]>> cov[1][6]
00064 ;
00065 fasciiFile >> tag >> cov[2][0] >> cov[2][1] >> cov[2][2] >> cov[2][3]>> cov[2][4] >> cov[2][5]>> cov[2][6
00066 ];
00067 fasciiFile >> tag >> cov[3][0] >> cov[3][1] >> cov[3][2] >> cov[3][3]>> cov[3][4] >> cov[3][5]>> cov[3][6
00068 ];
00069 fasciiFile >> tag >> cov[4][0] >> cov[4][1] >> cov[4][2] >> cov[4][3]>> cov[4][4] >> cov[4][5]>> cov[4][6]
00070 ;
00071 fasciiFile >> tag >> cov[5][0] >> cov[5][1] >> cov[5][2] >> cov[5][3]>> cov[5][4] >> cov[5][5]>> cov[5][6]
00072 ;
00073 fasciiFile >> tag >> cov[6][0] >> cov[6][1] >> cov[6][2] >> cov[6][3]>> cov[6][4] >> cov[6][5]>> cov[6][6]
00074 ;
00075 fasciiFile >> tag >> emittanceX;
00076 fasciiFile >> tag >> emittanceY;
00077 fasciiFile >> tag >> betastar;
00078
00079 }
00080
00081 else {
00082 x = params.getParameter<double>( "X0" );
00083 y = params.getParameter<double>( "Y0" );
00084 z = params.getParameter<double>( "Z0" );
00085 dxdz = params.getParameter<double>( "dxdz" );
00086 dydz = params.getParameter<double>( "dydz" );
00087 sigmaZ = params.getParameter<double>( "sigmaZ" );
00088 beamWidthX = params.getParameter<double>( "widthX" );
00089 beamWidthY = params.getParameter<double>( "widthY" );
00090 emittanceX = params.getParameter<double>( "emittanceX" );
00091 emittanceY = params.getParameter<double>( "emittanceY" );
00092 betastar = params.getParameter<double>( "betaStar" );
00093
00094
00095 for (int i=0; i<7; i++ ) {
00096 for (int j=0; j<7; j++) cov[i][j] = 0.0;
00097 }
00098
00099
00100 cov[0][0] = pow( params.getParameter<double>( "errorX0" ), 2 );
00101 cov[1][1] = pow( params.getParameter<double>( "errorY0" ), 2 );
00102 cov[2][2] = pow( params.getParameter<double>( "errorZ0" ), 2 );
00103 cov[3][3] = pow( params.getParameter<double>( "errorSigmaZ" ), 2 );
00104 cov[4][4] = pow( params.getParameter<double>( "errordxdz" ), 2 );
00105 cov[5][5] = pow( params.getParameter<double>( "errordydz" ), 2 );
00106 cov[6][6] = pow( params.getParameter<double>( "errorWidth" ), 2 );
00107
00108 }
00109 }
00110
00111 BeamSpotFakeConditions::~BeamSpotFakeConditions(){}
00112
00113 BeamSpotFakeConditions::ReturnType
00114 BeamSpotFakeConditions::produce(const BeamSpotObjectsRcd &record){
00115
00116
00117 BeamSpotObjects *adummy = new BeamSpotObjects();
00118
00119 adummy->SetPosition( x, y , z );
00120 adummy->SetSigmaZ( sigmaZ);
00121 adummy->Setdxdz( dxdz );
00122 adummy->Setdydz( dydz );
00123 adummy->SetBeamWidthX( beamWidthX );
00124 adummy->SetBeamWidthY( beamWidthY );
00125 for (int i=0; i<7; i++ ) {
00126 for (int j=0; j<7; j++) {
00127
00128 adummy->SetCovariance( i, j, cov[i][j] );
00129 }
00130 }
00131 adummy->SetEmittanceX( emittanceX );
00132 adummy->SetEmittanceY( emittanceY );
00133 adummy->SetBetaStar( betastar);
00134
00135 return ReturnType(adummy);
00136 }
00137
00138 void BeamSpotFakeConditions::setIntervalFor(const edm::eventsetup::EventSetupRecordKey &key,
00139 const edm::IOVSyncValue &syncValue,
00140 edm::ValidityInterval &oValidity){
00141 oValidity = edm::ValidityInterval(edm::IOVSyncValue::beginOfTime(),
00142 edm::IOVSyncValue::endOfTime());
00143 }
00144
00145 DEFINE_FWK_EVENTSETUP_SOURCE(BeamSpotFakeConditions);