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