CMS 3D CMS Logo

AlcaBeamSpotHarvester.cc
Go to the documentation of this file.
1 
2 /*
3  * See header file for a description of this class.
4  *
5  * \author L. Uplegger F. Yumiceva - Fermilab
6  */
7 
20 
22 
26 //#include "CondCore/Utilities/bin/cmscond_export_iov.cpp"
27 //#include "CondCore/Utilities/interface/Utilities.h"
28 // #include "FWCore/MessageLogger/interface/JobReport.h"
29 
30 #include <cstring>
31 #include <iostream>
32 
33 using namespace edm;
34 using namespace reco;
35 // using namespace std;
36 
37 //--------------------------------------------------------------------------------------------------
39  : beamSpotOutputBase_(iConfig.getParameter<ParameterSet>("AlcaBeamSpotHarvesterParameters")
40  .getUntrackedParameter<std::string>("BeamSpotOutputBase")),
41  outputrecordName_(iConfig.getParameter<ParameterSet>("AlcaBeamSpotHarvesterParameters")
42  .getUntrackedParameter<std::string>("outputRecordName", "BeamSpotObjectsRcd")),
43  sigmaZValue_(iConfig.getParameter<ParameterSet>("AlcaBeamSpotHarvesterParameters")
44  .getUntrackedParameter<double>("SigmaZValue")),
45  sigmaZCut_(iConfig.getParameter<ParameterSet>("AlcaBeamSpotHarvesterParameters")
46  .getUntrackedParameter<double>("SigmaZCut")),
47  dumpTxt_(
48  iConfig.getParameter<ParameterSet>("AlcaBeamSpotHarvesterParameters").getUntrackedParameter<bool>("DumpTxt")),
49  outTxtFileName_(iConfig.getParameter<ParameterSet>("AlcaBeamSpotHarvesterParameters")
50  .getUntrackedParameter<std::string>("TxtFileName")),
51  theAlcaBeamSpotManager_(iConfig, consumesCollector()) {}
52 
53 //--------------------------------------------------------------------------------------------------
55  // edm::LogInfo("AlcaBeamSpotHarvester")
56  // << "Lumi: " << iEvent.luminosityBlock()
57  // << " Time: " << iEvent.time().unixTime()
58  // << std::endl;
59 }
60 
61 //--------------------------------------------------------------------------------------------------
63 
64 //--------------------------------------------------------------------------------------------------
67  std::map<edm::LuminosityBlockNumber_t, std::pair<edm::Timestamp, reco::BeamSpot>> beamSpotMap =
70  // cond::ExportIOVUtilities utilities;
71 
72  std::string outTxt = Form("%s_Run%d.txt", outTxtFileName_.c_str(), iRun.id().run());
73  std::ofstream outFile;
74  outFile.open(outTxt.c_str(), std::ios::app);
75 
76  if (poolDbService.isAvailable()) {
77  for (AlcaBeamSpotManager::bsMap_iterator it = beamSpotMap.begin(); it != beamSpotMap.end(); it++) {
78  BeamSpotObjects *aBeamSpot = new BeamSpotObjects();
79  aBeamSpot->SetType(it->second.second.type());
80  aBeamSpot->SetPosition(it->second.second.x0(), it->second.second.y0(), it->second.second.z0());
81  if (sigmaZValue_ == -1) {
82  aBeamSpot->SetSigmaZ(it->second.second.sigmaZ());
83  } else {
84  aBeamSpot->SetSigmaZ(sigmaZValue_);
85  }
86  aBeamSpot->Setdxdz(it->second.second.dxdz());
87  aBeamSpot->Setdydz(it->second.second.dydz());
88  aBeamSpot->SetBeamWidthX(it->second.second.BeamWidthX());
89  aBeamSpot->SetBeamWidthY(it->second.second.BeamWidthY());
90  aBeamSpot->SetEmittanceX(it->second.second.emittanceX());
91  aBeamSpot->SetEmittanceY(it->second.second.emittanceY());
92  aBeamSpot->SetBetaStar(it->second.second.betaStar());
93 
94  for (int i = 0; i < 7; ++i) {
95  for (int j = 0; j < 7; ++j) {
96  aBeamSpot->SetCovariance(i, j, it->second.second.covariance(i, j));
97  }
98  }
99 
100  if (sigmaZValue_ > 0) {
101  aBeamSpot->SetCovariance(3, 3, 0.000025);
102  }
103 
104  cond::Time_t thisIOV = 1;
105 
106  beamspot::BeamSpotContainer currentBS;
107 
108  // run based
109  if (beamSpotOutputBase_ == "runbased") {
110  thisIOV = (cond::Time_t)iRun.id().run();
111  }
112  // lumi based
113  else if (beamSpotOutputBase_ == "lumibased") {
114  edm::LuminosityBlockID lu(iRun.id().run(), it->first);
115  thisIOV = (cond::Time_t)(lu.value());
116 
117  currentBS.beamspot = it->second.second;
118  currentBS.run = iRun.id().run();
119  currentBS.beginLumiOfFit = it->first;
120  currentBS.endLumiOfFit = it->first; // endLumi = initLumi
121 
122  std::time_t lumi_t_begin = it->second.first.unixTime();
123  std::time_t lumi_t_end = it->second.first.unixTime(); // begin time == end time
124  strftime(
125  currentBS.beginTimeOfFit, sizeof currentBS.beginTimeOfFit, "%Y.%m.%d %H:%M:%S GMT", gmtime(&lumi_t_begin));
126  strftime(currentBS.endTimeOfFit, sizeof currentBS.endTimeOfFit, "%Y.%m.%d %H:%M:%S GMT", gmtime(&lumi_t_end));
127 
128  currentBS.reftime[0] = lumi_t_begin;
129  currentBS.reftime[1] = lumi_t_end;
130  }
131  if (poolDbService->isNewTagRequest(outputrecordName_)) {
132  edm::LogInfo("AlcaBeamSpotHarvester") << "new tag requested" << std::endl;
133  // poolDbService->createNewIOV<BeamSpotObjects>(aBeamSpot,
134  // poolDbService->beginOfTime(),poolDbService->endOfTime(),"BeamSpotObjectsRcd");
135  // poolDbService->createNewIOV<BeamSpotObjects>(aBeamSpot,
136  // poolDbService->currentTime(),
137  // poolDbService->endOfTime(),"BeamSpotObjectsRcd");
138  poolDbService->writeOne<BeamSpotObjects>(aBeamSpot, thisIOV, outputrecordName_);
139  if (dumpTxt_ && beamSpotOutputBase_ == "lumibased") {
141 
143  if (jr.isAvailable()) {
144  std::map<std::string, std::string> jrInfo;
145  jrInfo["Source"] = std::string("AlcaHarvesting");
146  jrInfo["FileClass"] = std::string("ALCATXT");
147  jr->reportAnalysisFile(outTxt, jrInfo);
148  }
149  }
150  } else {
151  edm::LogInfo("AlcaBeamSpotHarvester") << "no new tag requested, appending IOV" << std::endl;
152  // poolDbService->appendSinceTime<BeamSpotObjects>(aBeamSpot,
153  // poolDbService->currentTime(),"BeamSpotObjectsRcd");
154  poolDbService->writeOne<BeamSpotObjects>(aBeamSpot, thisIOV, outputrecordName_);
155  if (dumpTxt_ && beamSpotOutputBase_ == "lumibased") {
157  }
158  }
159 
160  /*
161  int argc = 15;
162  const char* argv[] = {"endRun"
163  ,"-d","sqlite_file:combined.db"
164  ,"-s","sqlite_file:testbs2.db"
165  ,"-l","sqlite_file:log.db"
166  ,"-i","TestLSBasedBS"
167  ,"-t","TestLSBasedBS"
168  ,"-b","1"
169  ,"-e","10"
170  };
171 
172  edm::LogInfo("AlcaBeamSpotHarvester")
173  << "Running utilities!"
174  << utilities.run(argc,(char**)argv);
175  edm::LogInfo("AlcaBeamSpotHarvester")
176  << "Run utilities!"
177  << std::endl;
178  */
179  }
180  }
181 
182  outFile.close();
183 }
184 
185 //--------------------------------------------------------------------------------------------------
187 
188 //--------------------------------------------------------------------------------------------------
191 }
192 
beamspot::BeamSpotContainer::endTimeOfFit
char endTimeOfFit[32]
Definition: BeamSpotWrite2Txt.h:14
Handle.h
electrons_cff.bool
bool
Definition: electrons_cff.py:366
mps_fire.i
i
Definition: mps_fire.py:428
MessageLogger.h
AlcaBeamSpotHarvester::beamSpotOutputBase_
std::string beamSpotOutputBase_
Definition: AlcaBeamSpotHarvester.h:34
BeamSpotObjects::SetBetaStar
void SetBetaStar(double val)
set beta star
Definition: BeamSpotObjects.h:64
AlcaBeamSpotHarvester::dumpTxt_
bool dumpTxt_
Definition: AlcaBeamSpotHarvester.h:38
edm::LuminosityBlock
Definition: LuminosityBlock.h:50
edm::RunID::run
RunNumber_t run() const
Definition: RunID.h:36
edm::Run
Definition: Run.h:45
LuminosityBlock.h
edm
HLT enums.
Definition: AlignableModifier.h:19
AlcaBeamSpotManager::reset
void reset(void)
Definition: AlcaBeamSpotManager.cc:41
edm::JobReport::reportAnalysisFile
void reportAnalysisFile(std::string const &fileName, std::map< std::string, std::string > const &fileData)
Definition: JobReport.cc:473
AlcaBeamSpotHarvester::endRun
void endRun(const edm::Run &, const edm::EventSetup &)
Definition: AlcaBeamSpotHarvester.cc:65
BeamSpotObjects::SetBeamWidthY
void SetBeamWidthY(double val)
set average transverse beam width Y
Definition: BeamSpotObjects.h:50
beamspot::BeamSpotContainer::reftime
std::time_t reftime[2]
Definition: BeamSpotWrite2Txt.h:17
reco
fixed size matrix
Definition: AlignmentAlgorithmBase.h:45
edm::LogInfo
Log< level::Info, false > LogInfo
Definition: MessageLogger.h:125
edm::Service::isAvailable
bool isAvailable() const
Definition: Service.h:40
beamspot::BeamSpotContainer::beginLumiOfFit
int beginLumiOfFit
Definition: BeamSpotWrite2Txt.h:15
AlcaBeamSpotHarvester::outputrecordName_
std::string outputrecordName_
Definition: AlcaBeamSpotHarvester.h:35
BeamSpotObjects::SetSigmaZ
void SetSigmaZ(double val)
set sigma Z, RMS bunch length
Definition: BeamSpotObjects.h:42
AlcaBeamSpotManager::createWeightedPayloads
void createWeightedPayloads(void)
Definition: AlcaBeamSpotManager.cc:61
AlcaBeamSpotManager::readLumi
void readLumi(const edm::LuminosityBlock &)
Definition: AlcaBeamSpotManager.cc:43
MakerMacros.h
BeamSpotObjects.h
beamspot::BeamSpotContainer::beamspot
reco::BeamSpot beamspot
Definition: BeamSpotWrite2Txt.h:11
PoolDBOutputService.h
beamspot::BeamSpotContainer::endLumiOfFit
int endLumiOfFit
Definition: BeamSpotWrite2Txt.h:16
DEFINE_FWK_MODULE
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
BeamSpot.h
beamspot::dumpBeamSpotTxt
void dumpBeamSpotTxt(std::ofstream &outFile, BeamSpotContainer const &bsContainer)
Definition: BeamSpotWrite2Txt.h:20
Service.h
Run.h
BeamSpotObjects::SetEmittanceY
void SetEmittanceY(double val)
set emittance
Definition: BeamSpotObjects.h:62
AlcaBeamSpotManager::getPayloads
const std::map< edm::LuminosityBlockNumber_t, std::pair< edm::Timestamp, reco::BeamSpot > > & getPayloads(void)
Definition: AlcaBeamSpotManager.h:27
AlcaBeamSpotHarvester.h
AlcaBeamSpotHarvester::theAlcaBeamSpotManager_
AlcaBeamSpotManager theAlcaBeamSpotManager_
Definition: AlcaBeamSpotHarvester.h:41
AlcaBeamSpotHarvester::AlcaBeamSpotHarvester
AlcaBeamSpotHarvester(const edm::ParameterSet &)
Constructor.
Definition: AlcaBeamSpotHarvester.cc:38
edm::LuminosityBlockID
Definition: LuminosityBlockID.h:31
AlcaBeamSpotHarvester::sigmaZValue_
double sigmaZValue_
Definition: AlcaBeamSpotHarvester.h:36
BeamSpotObjects::SetPosition
void SetPosition(double x, double y, double z)
set XYZ position
Definition: BeamSpotObjects.h:36
L1TdeCSCTF_cfi.outFile
outFile
Definition: L1TdeCSCTF_cfi.py:5
AlCaHLTBitMon_QueryRunRegistry.string
string
Definition: AlCaHLTBitMon_QueryRunRegistry.py:256
BeamSpotObjects::SetType
void SetType(int type)
set beam type
Definition: BeamSpotObjects.h:58
edm::ParameterSet
Definition: ParameterSet.h:47
Event.h
BeamSpotObjects::SetEmittanceX
void SetEmittanceX(double val)
set emittance
Definition: BeamSpotObjects.h:60
BeamSpotObjects::SetCovariance
void SetCovariance(int i, int j, double val)
set i,j element of the full covariance matrix 7x7
Definition: BeamSpotObjects.h:56
cond::Time_t
unsigned long long Time_t
Definition: Time.h:14
edm::Service< cond::service::PoolDBOutputService >
iEvent
int iEvent
Definition: GenABIO.cc:224
BeamSpotObjects
Definition: BeamSpotObjects.h:20
edm::EventSetup
Definition: EventSetup.h:58
beamspot::BeamSpotContainer::run
int run
Definition: BeamSpotWrite2Txt.h:12
BeamSpotObjects::Setdxdz
void Setdxdz(double val)
set dxdz slope, crossing angle
Definition: BeamSpotObjects.h:44
AlcaBeamSpotManager::bsMap_iterator
std::map< edm::LuminosityBlockNumber_t, std::pair< edm::Timestamp, reco::BeamSpot > >::iterator bsMap_iterator
Definition: AlcaBeamSpotManager.h:31
FileBlock.h
AlcaBeamSpotHarvester::beginLuminosityBlock
void beginLuminosityBlock(const edm::LuminosityBlock &, const edm::EventSetup &)
Definition: AlcaBeamSpotHarvester.cc:186
std
Definition: JetResolutionObject.h:76
cond::service::PoolDBOutputService::writeOne
Hash writeOne(const T *payload, Time_t time, const std::string &recordName)
Definition: PoolDBOutputService.h:63
BeamSpotObjects::SetBeamWidthX
void SetBeamWidthX(double val)
set average transverse beam width X
Definition: BeamSpotObjects.h:48
EventSetup.h
cond::service::PoolDBOutputService::isNewTagRequest
bool isNewTagRequest(const std::string &recordName)
Definition: PoolDBOutputService.cc:128
AlcaBeamSpotHarvester::beginRun
void beginRun(const edm::Run &, const edm::EventSetup &)
Definition: AlcaBeamSpotHarvester.cc:62
AlcaBeamSpotHarvester::outTxtFileName_
std::string outTxtFileName_
Definition: AlcaBeamSpotHarvester.h:39
beamspot::BeamSpotContainer::beginTimeOfFit
char beginTimeOfFit[32]
Definition: BeamSpotWrite2Txt.h:13
AlcaBeamSpotHarvester::endLuminosityBlock
void endLuminosityBlock(const edm::LuminosityBlock &, const edm::EventSetup &)
Definition: AlcaBeamSpotHarvester.cc:189
beamspot::BeamSpotContainer
Definition: BeamSpotWrite2Txt.h:10
ConsumesCollector.h
JobReport.h
ParameterSet.h
dqmiolumiharvest.j
j
Definition: dqmiolumiharvest.py:66
AlcaBeamSpotHarvester
Definition: AlcaBeamSpotHarvester.h:16
edm::Event
Definition: Event.h:73
BeamSpotObjects::Setdydz
void Setdydz(double val)
set dydz slope, crossing angle in XZ
Definition: BeamSpotObjects.h:46
edm::RunBase::id
RunID const & id() const
Definition: RunBase.h:39
AlcaBeamSpotHarvester::analyze
void analyze(const edm::Event &, const edm::EventSetup &) override
Definition: AlcaBeamSpotHarvester.cc:54