24 : beamSpotOutputBase_(iConfig.getParameter<
ParameterSet>(
"AlcaBeamSpotHarvesterParameters")
25 .getUntrackedParameter<
std::
string>(
"BeamSpotOutputBase")),
26 beamSpotModuleName_(iConfig.getParameter<
ParameterSet>(
"AlcaBeamSpotHarvesterParameters")
27 .getUntrackedParameter<
std::
string>(
"BeamSpotModuleName")),
28 beamSpotLabel_(iConfig.getParameter<
ParameterSet>(
"AlcaBeamSpotHarvesterParameters")
29 .getUntrackedParameter<
std::
string>(
"BeamSpotLabel")),
30 sigmaZCut_(iConfig.getParameter<
ParameterSet>(
"AlcaBeamSpotHarvesterParameters")
31 .getUntrackedParameter<double>(
"SigmaZCut")) {
49 std::pair<edm::Timestamp, reco::BeamSpot> time_bs(iLumi.
beginTime(), *beamSpotHandle);
52 aBeamSpot = beamSpotHandle.
product();
54 LogInfo(
"AlcaBeamSpotManager") << *aBeamSpot << std::endl;
57 LogInfo(
"AlcaBeamSpotManager") <<
" BS is not valid!" << std::endl;
63 vector<bsMap_iterator> listToErase;
66 listToErase.push_back(it);
69 for (vector<bsMap_iterator>::iterator it = listToErase.begin(); it != listToErase.end(); it++) {
91 map<LuminosityBlockNumber_t, std::pair<edm::Timestamp, BeamSpot>> tmpBeamSpotMap_;
93 bool endOfRun =
false;
95 bool foundShift =
false;
106 <<
"Lumi: " << currentBS->first <<
"\n"
107 << currentBS->second.second <<
"\n"
108 << nextBS->first <<
"\n"
109 << nextBS->second.second << endl;
111 LogInfo(
"AlcaBeamSpotManager") << nextNextBS->first <<
"\n" << nextNextBS->second.second << endl;
119 LogInfo(
"AlcaBeamSpotManager") <<
"Reached lumi " << currentBS->first
120 <<
" now close payload because end of data has been reached.";
131 if (countlumi == maxNlumis - 1) {
132 LogInfo(
"AlcaBeamSpotManager") <<
"close payload because maximum lumi "
133 "sections accumulated within run ";
142 LogInfo(
"AlcaBeamSpotManager") <<
"Checking checking!" << endl;
144 pair<float, float> adelta1;
145 pair<float, float> adelta2;
146 pair<float, float> adelta;
147 pair<float, float> adelta1dxdz;
148 pair<float, float> adelta2dxdz;
149 pair<float, float> adelta1dydz;
150 pair<float, float> adelta2dydz;
151 pair<float, float> adelta1widthX;
152 pair<float, float> adelta2widthX;
153 pair<float, float> adelta1widthY;
154 pair<float, float> adelta2widthY;
155 pair<float, float> adelta1z0;
156 pair<float, float> adelta1sigmaZ;
159 float min_limit = 0.0025;
162 limit = currentBS->second.second.BeamWidthX() / 2.;
163 if (
limit < min_limit) {
167 currentBSObj = currentBS->second.second;
168 nextBSObj = nextBS->second.second;
172 adelta2 = pair<float, float>(0., 1.e9);
173 if (nextNextBS->second.second.type() != -1) {
174 adelta2 =
delta(nextBS->second.second.x0(),
176 nextNextBS->second.second.x0(),
177 nextNextBS->second.second.x0Error());
179 bool deltaX = (
deltaSig(adelta1.first, adelta1.second) > 3.5 && adelta1.first >=
limit) ?
true :
false;
181 if (!deltaX && adelta1.first * adelta2.first > 0. && fabs(adelta1.first + adelta2.first) >=
limit) {
183 <<
" positive, " << (adelta1.first + adelta2.first) <<
" limit=" <<
limit << endl;
185 }
else if (deltaX && adelta1.first * adelta2.first < 0 && adelta2.first != 0 &&
186 fabs(adelta1.first / adelta2.first) > 0.33 && fabs(adelta1.first / adelta2.first) < 3) {
187 LogInfo(
"AlcaBeamSpotManager") <<
" negative, " << adelta1.first / adelta2.first << endl;
194 adelta2dxdz = pair<float, float>(0., 1.e9);
196 adelta2dydz = pair<float, float>(0., 1.e9);
201 adelta2widthX = pair<float, float>(0., 1.e9);
206 adelta2widthY = pair<float, float>(0., 1.e9);
213 adelta2 = pair<float, float>(0., 1.e9);
216 nextBSObj.
y0(), nextBSObj.
y0Error(), nextNextBS->second.second.y0(), nextNextBS->second.second.y0Error());
219 nextNextBS->second.second.dxdz(),
220 nextNextBS->second.second.dxdzError());
223 nextNextBS->second.second.dydz(),
224 nextNextBS->second.second.dydzError());
227 nextNextBS->second.second.BeamWidthX(),
228 nextNextBS->second.second.BeamWidthXError());
231 nextNextBS->second.second.BeamWidthY(),
232 nextNextBS->second.second.BeamWidthYError());
234 bool deltaY = (
deltaSig(adelta1.first, adelta1.second) > 3.5 && adelta1.first >=
limit) ?
true :
false;
236 if (!deltaY && adelta1.first * adelta2.first > 0. && fabs(adelta1.first + adelta2.first) >=
limit) {
238 <<
" positive, " << (adelta1.first + adelta2.first) <<
" limit=" <<
limit << endl;
240 }
else if (deltaY && adelta1.first * adelta2.first < 0 && adelta2.first != 0 &&
241 fabs(adelta1.first / adelta2.first) > 0.33 && fabs(adelta1.first / adelta2.first) < 3) {
242 LogInfo(
"AlcaBeamSpotManager") <<
" negative, " << adelta1.first / adelta2.first << endl;
249 (
deltaSig(adelta1z0.first, adelta1z0.second) > 3.5 && fabs(adelta1z0.first) >=
limit) ?
true :
false;
252 bool deltasigmaZ = (
deltaSig(adelta.first, adelta.second) > 5.0) ?
true :
false;
253 bool deltadxdz =
false;
254 bool deltadydz =
false;
255 bool deltawidthX =
false;
256 bool deltawidthY =
false;
260 deltadxdz = (
deltaSig(adelta.first, adelta.second) > 5.0) ?
true :
false;
261 if (deltadxdz && (adelta1dxdz.first * adelta2dxdz.first) < 0 && adelta2dxdz.first != 0 &&
262 fabs(adelta1dxdz.first / adelta2dxdz.first) > 0.33 && fabs(adelta1dxdz.first / adelta2dxdz.first) < 3) {
267 deltadydz = (
deltaSig(adelta.first, adelta.second) > 5.0) ?
true :
false;
268 if (deltadydz && (adelta1dydz.first * adelta2dydz.first) < 0 && adelta2dydz.first != 0 &&
269 fabs(adelta1dydz.first / adelta2dydz.first) > 0.33 && fabs(adelta1dydz.first / adelta2dydz.first) < 3) {
277 deltawidthX = (
deltaSig(adelta.first, adelta.second) > 5.0) ?
true :
false;
278 if (deltawidthX && (adelta1widthX.first * adelta2widthX.first) < 0 && adelta2widthX.first != 0 &&
279 fabs(adelta1widthX.first / adelta2widthX.first) > 0.33 &&
280 fabs(adelta1widthX.first / adelta2widthX.first) < 3) {
288 deltawidthY = (
deltaSig(adelta.first, adelta.second) > 5.0) ?
true :
false;
289 if (deltawidthY && (adelta1widthY.first * adelta2widthY.first) < 0 && adelta2widthY.first != 0 &&
290 fabs(adelta1widthY.first / adelta2widthY.first) > 0.33 &&
291 fabs(adelta1widthY.first / adelta2widthY.first) < 3) {
295 if (deltaX || deltaY || deltaZ || deltasigmaZ || deltadxdz || deltadydz || deltawidthX || deltawidthY) {
298 LogInfo(
"AlcaBeamSpotManager") <<
"close payload because of movement in"
299 <<
" X=" << deltaX <<
", Y=" << deltaY <<
", Z=" << deltaZ
300 <<
", sigmaZ=" << deltasigmaZ <<
", dxdz=" << deltadxdz
301 <<
", dydz=" << deltadydz <<
", widthX=" << deltawidthX
302 <<
", widthY=" << deltawidthY << endl;
306 std::pair<edm::Timestamp, reco::BeamSpot> thepair;
308 thepair = std::make_pair(currentBS->second.first,
weight(firstBS, nextBS));
309 tmpBeamSpotMap_[firstBS->first] = thepair;
313 thepair = std::make_pair(nextBS->second.first, nextBSObj);
314 tmpBeamSpotMap_[nextBS->first] = thepair;
316 }
else if (!foundShift && !endOfRun) {
317 thepair = std::make_pair(currentBS->second.first,
weight(firstBS, nextBS));
318 tmpBeamSpotMap_[firstBS->first] = thepair;
320 thepair = std::make_pair(currentBS->second.first,
weight(firstBS,
beamSpotMap_.end()));
321 tmpBeamSpotMap_[firstBS->first] = thepair;
340 std::pair<edm::Timestamp, reco::BeamSpot> thepair(
beamSpotMap_.begin()->second.first,
351 double x, xError = 0;
352 double y, yError = 0;
353 double z, zError = 0;
354 double sigmaZ, sigmaZError = 0;
355 double dxdz, dxdzError = 0;
356 double dydz, dydzError = 0;
357 double widthX, widthXError = 0;
358 double widthY, widthYError = 0;
359 LogInfo(
"AlcaBeamSpotManager") <<
"Weighted BeamSpot will span lumi " <<
begin->first <<
" to " <<
end->first << endl;
363 weight(
x, xError, it->second.second.x0(), it->second.second.x0Error());
364 weight(
y, yError, it->second.second.y0(), it->second.second.y0Error());
365 weight(
z, zError, it->second.second.z0(), it->second.second.z0Error());
366 weight(
sigmaZ, sigmaZError, it->second.second.sigmaZ(), it->second.second.sigmaZ0Error());
367 weight(
dxdz, dxdzError, it->second.second.dxdz(), it->second.second.dxdzError());
368 weight(
dydz, dydzError, it->second.second.dydz(), it->second.second.dydzError());
369 weight(
widthX, widthXError, it->second.second.BeamWidthX(), it->second.second.BeamWidthXError());
370 weight(
widthY, widthYError, it->second.second.BeamWidthY(), it->second.second.BeamWidthYError());
377 error(0, 0) = xError * xError;
378 error(1, 1) = yError * yError;
379 error(2, 2) = zError * zError;
380 error(3, 3) = sigmaZError * sigmaZError;
381 error(4, 4) = dxdzError * dxdzError;
382 error(5, 5) = dydzError * dydzError;
383 error(6, 6) = widthXError * widthXError;
386 LogInfo(
"AlcaBeamSpotManager") <<
"Weighted BeamSpot will be:" <<
'\n' << weightedBeamSpot << endl;
387 return weightedBeamSpot;
393 if (meanError < 1
e-8) {
394 tmpError = 1 / (valError * valError);
397 tmpError = 1 / (meanError * meanError) + 1 / (valError * valError);
398 mean =
mean / (meanError * meanError) +
val / (valError * valError);
401 meanError =
sqrt(1 / tmpError);
408 const float &nextXError) {
409 return pair<float, float>(
x - nextX,
sqrt(
pow(xError, 2) +
pow(nextXError, 2)));
415 return fabs(
num / den);
417 return float(LONG_MAX);