Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010 #include "Calibration/TkAlCaRecoProducers/interface/AlcaBeamSpotHarvester.h"
00011 #include "FWCore/Framework/interface/Event.h"
00012 #include "FWCore/Framework/interface/Run.h"
00013 #include "FWCore/Framework/interface/LuminosityBlock.h"
00014 #include "FWCore/Framework/interface/FileBlock.h"
00015 #include "FWCore/Framework/interface/EventSetup.h"
00016 #include "DataFormats/Common/interface/Handle.h"
00017 #include "FWCore/Framework/interface/ESHandle.h"
00018 #include "FWCore/Framework/interface/MakerMacros.h"
00019 #include "FWCore/ParameterSet/interface/ParameterSet.h"
00020 #include "FWCore/MessageLogger/interface/MessageLogger.h"
00021
00022 #include "DataFormats/BeamSpot/interface/BeamSpot.h"
00023
00024 #include "CondFormats/BeamSpotObjects/interface/BeamSpotObjects.h"
00025 #include "FWCore/ServiceRegistry/interface/Service.h"
00026 #include "CondCore/DBOutputService/interface/PoolDBOutputService.h"
00027
00028
00029
00030
00031 #include <iostream>
00032
00033 using namespace edm;
00034 using namespace reco;
00035
00036
00037
00038 AlcaBeamSpotHarvester::AlcaBeamSpotHarvester(const edm::ParameterSet& iConfig) :
00039 beamSpotOutputBase_ (iConfig.getParameter<ParameterSet>("AlcaBeamSpotHarvesterParameters").getUntrackedParameter<std::string>("BeamSpotOutputBase")),
00040 outputrecordName_ (iConfig.getParameter<ParameterSet>("AlcaBeamSpotHarvesterParameters").getUntrackedParameter<std::string>("outputRecordName", "BeamSpotObjectsRcd")),
00041 sigmaZValue_ (iConfig.getParameter<ParameterSet>("AlcaBeamSpotHarvesterParameters").getUntrackedParameter<double>("SigmaZValue")),
00042 theAlcaBeamSpotManager_(iConfig) {
00043 }
00044
00045
00046 AlcaBeamSpotHarvester::~AlcaBeamSpotHarvester(){}
00047
00048
00049 void AlcaBeamSpotHarvester::beginJob() {}
00050
00051
00052 void AlcaBeamSpotHarvester::endJob() {}
00053
00054
00055 void AlcaBeamSpotHarvester::analyze(const edm::Event& iEvent, const edm::EventSetup&) {
00056
00057
00058
00059
00060 }
00061
00062
00063 void AlcaBeamSpotHarvester::beginRun(const edm::Run&, const edm::EventSetup&){
00064 theAlcaBeamSpotManager_.reset();
00065 }
00066
00067
00068 void AlcaBeamSpotHarvester::endRun(const edm::Run& iRun, const edm::EventSetup&){
00069 theAlcaBeamSpotManager_.createWeightedPayloads();
00070 std::map<edm::LuminosityBlockNumber_t,reco::BeamSpot> beamSpotMap = theAlcaBeamSpotManager_.getPayloads();
00071 Service<cond::service::PoolDBOutputService> poolDbService;
00072
00073 if(poolDbService.isAvailable() ) {
00074 for(AlcaBeamSpotManager::bsMap_iterator it=beamSpotMap.begin(); it!=beamSpotMap.end();it++){
00075 BeamSpotObjects *aBeamSpot = new BeamSpotObjects();
00076 aBeamSpot->SetType(it->second.type());
00077 aBeamSpot->SetPosition(it->second.x0(),it->second.y0(),it->second.z0());
00078 if(sigmaZValue_ == -1){
00079 aBeamSpot->SetSigmaZ(it->second.sigmaZ());
00080 }
00081 else{
00082 aBeamSpot->SetSigmaZ(sigmaZValue_);
00083 }
00084 aBeamSpot->Setdxdz(it->second.dxdz());
00085 aBeamSpot->Setdydz(it->second.dydz());
00086 aBeamSpot->SetBeamWidthX(it->second.BeamWidthX());
00087 aBeamSpot->SetBeamWidthY(it->second.BeamWidthY());
00088 aBeamSpot->SetEmittanceX(it->second.emittanceX());
00089 aBeamSpot->SetEmittanceY(it->second.emittanceY());
00090 aBeamSpot->SetBetaStar(it->second.betaStar() );
00091
00092 for (int i=0; i<7; ++i) {
00093 for (int j=0; j<7; ++j) {
00094 aBeamSpot->SetCovariance(i,j,it->second.covariance(i,j));
00095 }
00096 }
00097
00098 if(sigmaZValue_ > 0){
00099 aBeamSpot->SetCovariance(3,3,0.000025);
00100 }
00101
00102 cond::Time_t thisIOV = 1;
00103
00104
00105
00106
00107 if (beamSpotOutputBase_ == "runbased" ) {
00108 thisIOV = (cond::Time_t) iRun.id().run();
00109 }
00110
00111 else if (beamSpotOutputBase_ == "lumibased" ) {
00112 edm::LuminosityBlockID lu(iRun.id().run(),it->first);
00113 thisIOV = (cond::Time_t)(lu.value());
00114 }
00115 if (poolDbService->isNewTagRequest(outputrecordName_) ) {
00116 edm::LogInfo("AlcaBeamSpotHarvester")
00117 << "new tag requested" << std::endl;
00118
00119
00120
00121 poolDbService->writeOne<BeamSpotObjects>(aBeamSpot, thisIOV, outputrecordName_);
00122 }
00123 else {
00124 edm::LogInfo("AlcaBeamSpotHarvester")
00125 << "no new tag requested, appending IOV" << std::endl;
00126
00127 poolDbService->writeOne<BeamSpotObjects>(aBeamSpot, thisIOV, outputrecordName_);
00128 }
00129
00130
00131
00132
00133
00134
00135
00136
00137
00138
00139
00140
00141
00142
00143
00144
00145
00146
00147
00148
00149
00150
00151
00152 }
00153
00154
00155
00156
00157 }
00158 }
00159
00160
00161 void AlcaBeamSpotHarvester::beginLuminosityBlock(const edm::LuminosityBlock&, const edm::EventSetup&) {}
00162
00163
00164 void AlcaBeamSpotHarvester::endLuminosityBlock(const edm::LuminosityBlock& iLumi, const edm::EventSetup&) {
00165 theAlcaBeamSpotManager_.readLumi(iLumi);
00166 }
00167
00168
00169 DEFINE_FWK_MODULE(AlcaBeamSpotHarvester);