Skip to content

Commit

Permalink
Merge pull request #22392 from MilanoBicocca-pix/txt_HPBS
Browse files Browse the repository at this point in the history
Print correct timestamp in HP beamspot txt file
  • Loading branch information
cmsbuild committed Mar 5, 2018
2 parents 997d1ea + fb0056f commit 13169f3
Show file tree
Hide file tree
Showing 3 changed files with 97 additions and 89 deletions.
Expand Up @@ -11,7 +11,6 @@
#include "DataFormats/BeamSpot/interface/BeamSpot.h"
#include "FWCore/Framework/interface/LuminosityBlock.h"
#include "FWCore/Framework/interface/ConsumesCollector.h"
//#include "DataFormats/Provenance/interface/LuminosityBlockID.h"
#include <string>
#include <map>
#include <utility>
Expand All @@ -26,16 +25,16 @@ class AlcaBeamSpotManager {
void reset(void);
void readLumi(const edm::LuminosityBlock&);
void createWeightedPayloads(void);
const std::map<edm::LuminosityBlockNumber_t,reco::BeamSpot>& getPayloads(void){return beamSpotMap_;}
const std::map<edm::LuminosityBlockNumber_t,std::pair<edm::Timestamp,reco::BeamSpot> >& getPayloads(void){return beamSpotMap_;}

typedef std::map<edm::LuminosityBlockNumber_t,reco::BeamSpot>::iterator bsMap_iterator;
typedef std::map<edm::LuminosityBlockNumber_t,std::pair<edm::Timestamp,reco::BeamSpot> >::iterator bsMap_iterator;
private:
reco::BeamSpot weight (const bsMap_iterator& begin,
const bsMap_iterator& end);
void weight (double& mean,double& meanError,const double& val,const double& valError);
std::pair<float,float> delta (const float& x, const float& xError, const float& nextX, const float& nextXError);
float deltaSig(const float& num, const float& den);
std::map<edm::LuminosityBlockNumber_t,reco::BeamSpot> beamSpotMap_;
std::map<edm::LuminosityBlockNumber_t,std::pair<edm::Timestamp,reco::BeamSpot> > beamSpotMap_;

std::string beamSpotOutputBase_;
std::string beamSpotModuleName_;
Expand Down
39 changes: 18 additions & 21 deletions Calibration/TkAlCaRecoProducers/plugins/AlcaBeamSpotHarvester.cc
Expand Up @@ -71,36 +71,36 @@ void AlcaBeamSpotHarvester::beginRun(const edm::Run&, const edm::EventSetup&){
//--------------------------------------------------------------------------------------------------
void AlcaBeamSpotHarvester::endRun(const edm::Run& iRun, const edm::EventSetup&){
theAlcaBeamSpotManager_.createWeightedPayloads();
std::map<edm::LuminosityBlockNumber_t,reco::BeamSpot> beamSpotMap = theAlcaBeamSpotManager_.getPayloads();
std::map<edm::LuminosityBlockNumber_t,std::pair<edm::Timestamp,reco::BeamSpot>> beamSpotMap = theAlcaBeamSpotManager_.getPayloads();
Service<cond::service::PoolDBOutputService> poolDbService;
// cond::ExportIOVUtilities utilities;

std::string outTxt = Form("%s_Run%d.txt", outTxtFileName_.c_str(), iRun.id().run());
std::ofstream outFile;
outFile.open(outTxt.c_str());
outFile.open(outTxt.c_str(),std::ios::app);

if(poolDbService.isAvailable() ) {
for(AlcaBeamSpotManager::bsMap_iterator it=beamSpotMap.begin(); it!=beamSpotMap.end();it++){
BeamSpotObjects *aBeamSpot = new BeamSpotObjects();
aBeamSpot->SetType(it->second.type());
aBeamSpot->SetPosition(it->second.x0(),it->second.y0(),it->second.z0());
aBeamSpot->SetType(it->second.second.type());
aBeamSpot->SetPosition(it->second.second.x0(),it->second.second.y0(),it->second.second.z0());
if(sigmaZValue_ == -1){
aBeamSpot->SetSigmaZ(it->second.sigmaZ());
aBeamSpot->SetSigmaZ(it->second.second.sigmaZ());
}
else{
aBeamSpot->SetSigmaZ(sigmaZValue_);
}
aBeamSpot->Setdxdz(it->second.dxdz());
aBeamSpot->Setdydz(it->second.dydz());
aBeamSpot->SetBeamWidthX(it->second.BeamWidthX());
aBeamSpot->SetBeamWidthY(it->second.BeamWidthY());
aBeamSpot->SetEmittanceX(it->second.emittanceX());
aBeamSpot->SetEmittanceY(it->second.emittanceY());
aBeamSpot->SetBetaStar(it->second.betaStar() );
aBeamSpot->Setdxdz(it->second.second.dxdz());
aBeamSpot->Setdydz(it->second.second.dydz());
aBeamSpot->SetBeamWidthX(it->second.second.BeamWidthX());
aBeamSpot->SetBeamWidthY(it->second.second.BeamWidthY());
aBeamSpot->SetEmittanceX(it->second.second.emittanceX());
aBeamSpot->SetEmittanceY(it->second.second.emittanceY());
aBeamSpot->SetBetaStar(it->second.second.betaStar() );

for (int i=0; i<7; ++i) {
for (int j=0; j<7; ++j) {
aBeamSpot->SetCovariance(i,j,it->second.covariance(i,j));
aBeamSpot->SetCovariance(i,j,it->second.second.covariance(i,j));
}
}

Expand All @@ -122,15 +122,15 @@ void AlcaBeamSpotHarvester::endRun(const edm::Run& iRun, const edm::EventSetup&)
edm::LuminosityBlockID lu(iRun.id().run(),it->first);
thisIOV = (cond::Time_t)(lu.value());

currentBS.beamspot = it -> second ;
currentBS.beamspot = it -> second.second;
currentBS.run = iRun.id().run() ;
currentBS.beginLumiOfFit = it->first;
currentBS.endLumiOfFit = it->first;// to fix, for now endLumi = initLumi
currentBS.endLumiOfFit = it->first; // endLumi = initLumi

std::time_t lumi_t_begin = thisIOV; // to fix: meaningless value
std::time_t lumi_t_end = thisIOV; // to fix: meaningless value
std::time_t lumi_t_begin = it -> second.first.unixTime();
std::time_t lumi_t_end = it -> second.first.unixTime(); // begin time == end time
strftime(currentBS.beginTimeOfFit, sizeof currentBS.beginTimeOfFit, "%Y.%m.%d %H:%M:%S GMT", gmtime(&lumi_t_begin));
strftime(currentBS.endTimeOfFit, sizeof currentBS.endTimeOfFit, "%Y.%m.%d %H:%M:%S GMT", gmtime(&lumi_t_end));
strftime(currentBS.endTimeOfFit, sizeof currentBS.endTimeOfFit, "%Y.%m.%d %H:%M:%S GMT", gmtime(&lumi_t_end));

currentBS.reftime[0] = lumi_t_begin;
currentBS.reftime[1] = lumi_t_end;
Expand Down Expand Up @@ -188,9 +188,6 @@ void AlcaBeamSpotHarvester::endRun(const edm::Run& iRun, const edm::EventSetup&)
*/
}




}

outFile.close();
Expand Down

0 comments on commit 13169f3

Please sign in to comment.