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 <iostream>
31 #include <cstring>
32 
33 using namespace edm;
34 using namespace reco;
35 //using namespace std;
36 
37 //--------------------------------------------------------------------------------------------------
39  beamSpotOutputBase_ (iConfig.getParameter<ParameterSet>("AlcaBeamSpotHarvesterParameters").getUntrackedParameter<std::string>("BeamSpotOutputBase")),
40  outputrecordName_ (iConfig.getParameter<ParameterSet>("AlcaBeamSpotHarvesterParameters").getUntrackedParameter<std::string>("outputRecordName", "BeamSpotObjectsRcd")),
41  sigmaZValue_ (iConfig.getParameter<ParameterSet>("AlcaBeamSpotHarvesterParameters").getUntrackedParameter<double>("SigmaZValue")),
42  sigmaZCut_ (iConfig.getParameter<ParameterSet>("AlcaBeamSpotHarvesterParameters").getUntrackedParameter<double>("SigmaZCut")),
43  dumpTxt_ (iConfig.getParameter<ParameterSet>("AlcaBeamSpotHarvesterParameters").getUntrackedParameter<bool>("DumpTxt")),
44  outTxtFileName_ (iConfig.getParameter<ParameterSet>("AlcaBeamSpotHarvesterParameters").getUntrackedParameter<std::string>("TxtFileName")),
45  theAlcaBeamSpotManager_(iConfig, consumesCollector()) {
46 }
47 
48 //--------------------------------------------------------------------------------------------------
50 
51 //--------------------------------------------------------------------------------------------------
53 
54 //--------------------------------------------------------------------------------------------------
56 
57 //--------------------------------------------------------------------------------------------------
59 // edm::LogInfo("AlcaBeamSpotHarvester")
60 // << "Lumi: " << iEvent.luminosityBlock()
61 // << " Time: " << iEvent.time().unixTime()
62 // << std::endl;
63 }
64 
65 //--------------------------------------------------------------------------------------------------
68 }
69 
70 //--------------------------------------------------------------------------------------------------
73  std::map<edm::LuminosityBlockNumber_t,reco::BeamSpot> beamSpotMap = theAlcaBeamSpotManager_.getPayloads();
75 // cond::ExportIOVUtilities utilities;
76 
77  std::string outTxt = Form("%s_Run%d.txt", outTxtFileName_.c_str(), iRun.id().run());
78  std::ofstream outFile;
79  outFile.open(outTxt.c_str());
80 
81  if(poolDbService.isAvailable() ) {
82  for(AlcaBeamSpotManager::bsMap_iterator it=beamSpotMap.begin(); it!=beamSpotMap.end();it++){
83  BeamSpotObjects *aBeamSpot = new BeamSpotObjects();
84  aBeamSpot->SetType(it->second.type());
85  aBeamSpot->SetPosition(it->second.x0(),it->second.y0(),it->second.z0());
86  if(sigmaZValue_ == -1){
87  aBeamSpot->SetSigmaZ(it->second.sigmaZ());
88  }
89  else{
90  aBeamSpot->SetSigmaZ(sigmaZValue_);
91  }
92  aBeamSpot->Setdxdz(it->second.dxdz());
93  aBeamSpot->Setdydz(it->second.dydz());
94  aBeamSpot->SetBeamWidthX(it->second.BeamWidthX());
95  aBeamSpot->SetBeamWidthY(it->second.BeamWidthY());
96  aBeamSpot->SetEmittanceX(it->second.emittanceX());
97  aBeamSpot->SetEmittanceY(it->second.emittanceY());
98  aBeamSpot->SetBetaStar(it->second.betaStar() );
99 
100  for (int i=0; i<7; ++i) {
101  for (int j=0; j<7; ++j) {
102  aBeamSpot->SetCovariance(i,j,it->second.covariance(i,j));
103  }
104  }
105 
106  if(sigmaZValue_ > 0){
107  aBeamSpot->SetCovariance(3,3,0.000025);
108  }
109 
110  cond::Time_t thisIOV = 1;
111 
112  beamspot::BeamSpotContainer currentBS;
113 
114 
115  // run based
116  if (beamSpotOutputBase_ == "runbased" ) {
117  thisIOV = (cond::Time_t) iRun.id().run();
118  }
119  // lumi based
120  else if (beamSpotOutputBase_ == "lumibased" ) {
121  edm::LuminosityBlockID lu(iRun.id().run(),it->first);
122  thisIOV = (cond::Time_t)(lu.value());
123 
124  currentBS.beamspot = it -> second ;
125  currentBS.run = iRun.id().run() ;
126  currentBS.beginLumiOfFit = it->first;
127  currentBS.endLumiOfFit = it->first;// to fix, for now endLumi = initLumi
128 
129  std::time_t lumi_t_begin = thisIOV; // to fix: meaningless value
130  std::time_t lumi_t_end = thisIOV; // to fix: meaningless value
131  strftime(currentBS.beginTimeOfFit, sizeof currentBS.beginTimeOfFit, "%Y.%m.%d %H:%M:%S GMT", gmtime(&lumi_t_begin));
132  strftime(currentBS.endTimeOfFit, sizeof currentBS.endTimeOfFit, "%Y.%m.%d %H:%M:%S GMT", gmtime(&lumi_t_end));
133 
134  currentBS.reftime[0] = lumi_t_begin;
135  currentBS.reftime[1] = lumi_t_end;
136 
137  }
138  if (poolDbService->isNewTagRequest(outputrecordName_) ) {
139  edm::LogInfo("AlcaBeamSpotHarvester")
140  << "new tag requested" << std::endl;
141  //poolDbService->createNewIOV<BeamSpotObjects>(aBeamSpot, poolDbService->beginOfTime(),poolDbService->endOfTime(),"BeamSpotObjectsRcd");
142 
143  //poolDbService->createNewIOV<BeamSpotObjects>(aBeamSpot, poolDbService->currentTime(), poolDbService->endOfTime(),"BeamSpotObjectsRcd");
144  poolDbService->writeOne<BeamSpotObjects>(aBeamSpot, thisIOV, outputrecordName_);
145  if (dumpTxt_ && beamSpotOutputBase_ == "lumibased"){
146  beamspot::dumpBeamSpotTxt(outFile, currentBS);
147  }
148  }
149  else {
150  edm::LogInfo("AlcaBeamSpotHarvester")
151  << "no new tag requested, appending IOV" << std::endl;
152  //poolDbService->appendSinceTime<BeamSpotObjects>(aBeamSpot, poolDbService->currentTime(),"BeamSpotObjectsRcd");
153  poolDbService->writeOne<BeamSpotObjects>(aBeamSpot, thisIOV, outputrecordName_);
154  if (dumpTxt_ && beamSpotOutputBase_ == "lumibased"){
155  beamspot::dumpBeamSpotTxt(outFile, currentBS);
156  }
157  }
158 
159 
160 
161 
162 /*
163  int argc = 15;
164  const char* argv[] = {"endRun"
165  ,"-d","sqlite_file:combined.db"
166  ,"-s","sqlite_file:testbs2.db"
167  ,"-l","sqlite_file:log.db"
168  ,"-i","TestLSBasedBS"
169  ,"-t","TestLSBasedBS"
170  ,"-b","1"
171  ,"-e","10"
172  };
173 
174  edm::LogInfo("AlcaBeamSpotHarvester")
175  << "Running utilities!"
176  << utilities.run(argc,(char**)argv);
177  edm::LogInfo("AlcaBeamSpotHarvester")
178  << "Run utilities!"
179  << std::endl;
180 */
181  }
182 
183 
184 
185 
186  }
187 
188  outFile.close();
189 
190 }
191 
192 //--------------------------------------------------------------------------------------------------
194 
195 //--------------------------------------------------------------------------------------------------
198 }
199 
200 
RunID const & id() const
Definition: RunBase.h:39
RunNumber_t run() const
Definition: RunID.h:39
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:17
void beginRun(const edm::Run &, const edm::EventSetup &) override
void SetSigmaZ(double val)
set sigma Z, RMS bunch length
void analyze(const edm::Event &, const edm::EventSetup &) override
void endRun(const edm::Run &, const edm::EventSetup &) override
std::map< edm::LuminosityBlockNumber_t, reco::BeamSpot >::iterator bsMap_iterator
void SetCovariance(int i, int j, double val)
set i,j element of the full covariance matrix 7x7
void Setdydz(double val)
set dydz slope, crossing angle in XZ
AlcaBeamSpotHarvester(const edm::ParameterSet &)
Constructor.
const std::map< edm::LuminosityBlockNumber_t, reco::BeamSpot > & getPayloads(void)
U second(std::pair< T, U > const &p)
void endJob(void) override
int iEvent
Definition: GenABIO.cc:230
unsigned long long Time_t
Definition: Time.h:16
bool isNewTagRequest(const std::string &recordName)
void beginLuminosityBlock(const edm::LuminosityBlock &, const edm::EventSetup &) override
void SetEmittanceX(double val)
set emittance
~AlcaBeamSpotHarvester() override
Destructor.
bool isAvailable() const
Definition: Service.h:46
void writeOne(T *payload, Time_t time, const std::string &recordName, bool withlogging=false)
void Setdxdz(double val)
set dxdz slope, crossing angle
void endLuminosityBlock(const edm::LuminosityBlock &, const edm::EventSetup &) override
void SetBetaStar(double val)
set beta star
void readLumi(const edm::LuminosityBlock &)
void SetType(int type)
set beam type
void SetEmittanceY(double val)
set emittance
void SetBeamWidthX(double val)
set average transverse beam width X
void SetBeamWidthY(double val)
set average transverse beam width Y
void beginJob(void) override
AlcaBeamSpotManager theAlcaBeamSpotManager_
fixed size matrix
HLT enums.
void dumpBeamSpotTxt(std::ofstream &outFile, BeamSpotContainer const &bsContainer)
Definition: Run.h:43
void SetPosition(double x, double y, double z)
set XYZ position