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 #include "FWCore/MessageLogger/interface/JobReport.h"
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 metadataForOfflineDropBox_(iConfig.getParameter<ParameterSet>("metadataOfflineDropBox"))
00044 {
00045 }
00046
00047
00048 AlcaBeamSpotHarvester::~AlcaBeamSpotHarvester(){}
00049
00050
00051 void AlcaBeamSpotHarvester::beginJob() {}
00052
00053
00054 void AlcaBeamSpotHarvester::endJob() {}
00055
00056
00057 void AlcaBeamSpotHarvester::analyze(const edm::Event& iEvent, const edm::EventSetup&) {
00058
00059
00060
00061
00062 }
00063
00064
00065 void AlcaBeamSpotHarvester::beginRun(const edm::Run&, const edm::EventSetup&){
00066 theAlcaBeamSpotManager_.reset();
00067 }
00068
00069
00070 void AlcaBeamSpotHarvester::endRun(const edm::Run& iRun, const edm::EventSetup&){
00071 theAlcaBeamSpotManager_.createWeightedPayloads();
00072 std::map<edm::LuminosityBlockNumber_t,reco::BeamSpot> beamSpotMap = theAlcaBeamSpotManager_.getPayloads();
00073 Service<cond::service::PoolDBOutputService> poolDbService;
00074
00075 if(poolDbService.isAvailable() ) {
00076 for(AlcaBeamSpotManager::bsMap_iterator it=beamSpotMap.begin(); it!=beamSpotMap.end();it++){
00077 BeamSpotObjects *aBeamSpot = new BeamSpotObjects();
00078 aBeamSpot->SetType(it->second.type());
00079 aBeamSpot->SetPosition(it->second.x0(),it->second.y0(),it->second.z0());
00080 if(sigmaZValue_ == -1){
00081 aBeamSpot->SetSigmaZ(it->second.sigmaZ());
00082 }
00083 else{
00084 aBeamSpot->SetSigmaZ(sigmaZValue_);
00085 }
00086 aBeamSpot->Setdxdz(it->second.dxdz());
00087 aBeamSpot->Setdydz(it->second.dydz());
00088 aBeamSpot->SetBeamWidthX(it->second.BeamWidthX());
00089 aBeamSpot->SetBeamWidthY(it->second.BeamWidthY());
00090 aBeamSpot->SetEmittanceX(it->second.emittanceX());
00091 aBeamSpot->SetEmittanceY(it->second.emittanceY());
00092 aBeamSpot->SetBetaStar(it->second.betaStar() );
00093
00094 for (int i=0; i<7; ++i) {
00095 for (int j=0; j<7; ++j) {
00096 aBeamSpot->SetCovariance(i,j,it->second.covariance(i,j));
00097 }
00098 }
00099
00100 if(sigmaZValue_ > 0){
00101 aBeamSpot->SetCovariance(3,3,0.000025);
00102 }
00103
00104 cond::Time_t thisIOV = 1;
00105
00106
00107
00108
00109 if (beamSpotOutputBase_ == "runbased" ) {
00110 thisIOV = (cond::Time_t) iRun.id().run();
00111 }
00112
00113 else if (beamSpotOutputBase_ == "lumibased" ) {
00114 edm::LuminosityBlockID lu(iRun.id().run(),it->first);
00115 thisIOV = (cond::Time_t)(lu.value());
00116 }
00117 if (poolDbService->isNewTagRequest(outputrecordName_) ) {
00118 edm::LogInfo("AlcaBeamSpotHarvester")
00119 << "new tag requested" << std::endl;
00120
00121
00122
00123 poolDbService->writeOne<BeamSpotObjects>(aBeamSpot, thisIOV, outputrecordName_);
00124 }
00125 else {
00126 edm::LogInfo("AlcaBeamSpotHarvester")
00127 << "no new tag requested, appending IOV" << std::endl;
00128
00129 poolDbService->writeOne<BeamSpotObjects>(aBeamSpot, thisIOV, outputrecordName_);
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 edm::Service<edm::JobReport> jr;
00159 if (jr.isAvailable()) {
00160 std::map<std::string, std::string> jrInfo;
00161 jrInfo["Source"] = "AlcaHarvesting";
00162 jrInfo["FileClass"] = "ALCA";
00163
00164
00165 jrInfo["inputtag"] = poolDbService->tag(outputrecordName_);
00166 if(beamSpotOutputBase_ == "runbased") {
00167 jrInfo["Timetype"] = "runnumber";
00168 } else if(beamSpotOutputBase_ == "lumibased") {
00169 jrInfo["Timetype"] = "lumiid";
00170 }
00171 std::vector<std::string> paramKeys = metadataForOfflineDropBox_.getParameterNames();
00172 for(std::vector<std::string>::const_iterator key = paramKeys.begin();
00173 key != paramKeys.end();
00174 ++key) {
00175 jrInfo[*key] = metadataForOfflineDropBox_.getUntrackedParameter<std::string>(*key);
00176 }
00177 std::string filename = poolDbService->session().connectionString();
00178 jr->reportAnalysisFile(filename, jrInfo);
00179 }
00180
00181
00182 }
00183 }
00184
00185
00186 void AlcaBeamSpotHarvester::beginLuminosityBlock(const edm::LuminosityBlock&, const edm::EventSetup&) {}
00187
00188
00189 void AlcaBeamSpotHarvester::endLuminosityBlock(const edm::LuminosityBlock& iLumi, const edm::EventSetup&) {
00190 theAlcaBeamSpotManager_.readLumi(iLumi);
00191 }
00192
00193
00194 DEFINE_FWK_MODULE(AlcaBeamSpotHarvester);