25 beamSpotOutputBase_(iConfig.getParameter<
ParameterSet>(
"AlcaBeamSpotHarvesterParameters").getUntrackedParameter<
std::
string>(
"BeamSpotOutputBase")),
26 beamSpotModuleName_(iConfig.getParameter<
ParameterSet>(
"AlcaBeamSpotHarvesterParameters").getUntrackedParameter<
std::
string>(
"BeamSpotModuleName")),
27 beamSpotLabel_ (iConfig.getParameter<
ParameterSet>(
"AlcaBeamSpotHarvesterParameters").getUntrackedParameter<
std::
string>(
"BeamSpotLabel")),
28 sigmaZCut_ (iConfig.getParameter<
ParameterSet>(
"AlcaBeamSpotHarvesterParameters").getUntrackedParameter<double>(
"SigmaZCut"))
53 std::pair<edm::Timestamp,reco::BeamSpot> time_bs (iLumi.
beginTime(), *beamSpotHandle);
56 aBeamSpot = beamSpotHandle.
product();
60 << *aBeamSpot << std::endl;
66 <<
" BS is not valid!" << std::endl;
73 vector<bsMap_iterator> listToErase;
76 listToErase.push_back(it);
79 for(vector<bsMap_iterator>::iterator it=listToErase.begin(); it !=listToErase.end(); it++){
100 map<LuminosityBlockNumber_t,std::pair<edm::Timestamp, BeamSpot>> tmpBeamSpotMap_;
101 bool docreate =
true;
102 bool endOfRun =
false;
104 bool foundShift =
false;
116 <<
"Iteration: " << iteration <<
" size: " <<
beamSpotMap_.size() <<
"\n" 117 <<
"Lumi: " << currentBS->first <<
"\n" 118 << currentBS->second.second
119 <<
"\n" << nextBS->first <<
"\n" << nextBS->second.second
123 << nextNextBS->first <<
"\n" << nextNextBS->second.second
134 <<
"Reached lumi " << currentBS->first
135 <<
" now close payload because end of data has been reached.";
146 if (countlumi == maxNlumis -1){
148 <<
"close payload because maximum lumi sections accumulated within run ";
158 <<
"Checking checking!" << endl;
160 pair<float,float> adelta1;
161 pair<float,float> adelta2;
162 pair<float,float> adelta;
163 pair<float,float> adelta1dxdz;
164 pair<float,float> adelta2dxdz;
165 pair<float,float> adelta1dydz;
166 pair<float,float> adelta2dydz;
167 pair<float,float> adelta1widthX;
168 pair<float,float> adelta2widthX;
169 pair<float,float> adelta1widthY;
170 pair<float,float> adelta2widthY;
171 pair<float,float> adelta1z0;
172 pair<float,float> adelta1sigmaZ;
175 float min_limit = 0.0025;
178 limit = currentBS->second.second.BeamWidthX()/2.;
179 if(limit < min_limit){
183 currentBSObj = currentBS->second.second;
184 nextBSObj = nextBS->second.second;
188 adelta2 = pair<float,float>(0.,1.e9);
189 if (nextNextBS->second.second.type() != -1){
190 adelta2 =
delta(nextBS->second.second.x0(), nextBSObj.
x0Error(), nextNextBS->second.second.x0(), nextNextBS->second.second.x0Error());
192 bool deltaX = (
deltaSig(adelta1.first,adelta1.second) > 3.5 && adelta1.first >=
limit)?
true:
false;
194 if( !deltaX && adelta1.first*adelta2.first > 0. && fabs(adelta1.first+adelta2.first) >=
limit){
196 <<
" positive, " << (adelta1.first+adelta2.first) <<
" limit=" << limit << endl;
199 else if( deltaX && adelta1.first*adelta2.first < 0 && adelta2.first != 0 && fabs(adelta1.first/adelta2.first) > 0.33 && fabs(adelta1.first/adelta2.first) < 3){
201 <<
" negative, " << adelta1.first/adelta2.first << endl;
208 adelta2dxdz = pair<float,float>(0.,1.e9);
210 adelta2dydz = pair<float,float>(0.,1.e9);
212 adelta2widthX = pair<float,float>(0.,1.e9);
214 adelta2widthY = pair<float,float>(0.,1.e9);
220 adelta2 = pair<float,float>(0.,1.e9);
222 adelta2 =
delta(nextBSObj.
y0(), nextBSObj.
y0Error(), nextNextBS->second.second.y0(), nextNextBS->second.second.y0Error());
223 adelta2dxdz =
delta(nextBSObj.
dxdz(), nextBSObj.
dxdzError(), nextNextBS->second.second.dxdz(), nextNextBS->second.second.dxdzError());
224 adelta2dydz =
delta(nextBSObj.
dydz(), nextBSObj.
dydzError(), nextNextBS->second.second.dydz(), nextNextBS->second.second.dydzError());
225 adelta2widthX =
delta(nextBSObj.
BeamWidthX(), nextBSObj.
BeamWidthXError(), nextNextBS->second.second.BeamWidthX(), nextNextBS->second.second.BeamWidthXError());
226 adelta2widthY =
delta(nextBSObj.
BeamWidthY(), nextBSObj.
BeamWidthYError(), nextNextBS->second.second.BeamWidthY(), nextNextBS->second.second.BeamWidthYError());
229 bool deltaY = (
deltaSig(adelta1.first,adelta1.second) > 3.5 && adelta1.first >=
limit)?
true:
false;
231 if( !deltaY && adelta1.first*adelta2.first > 0. && fabs(adelta1.first+adelta2.first) >=
limit){
233 <<
" positive, " << (adelta1.first+adelta2.first) <<
" limit=" << limit << endl;
236 else if( deltaY && adelta1.first*adelta2.first < 0 && adelta2.first != 0 && fabs(adelta1.first/adelta2.first) > 0.33 && fabs(adelta1.first/adelta2.first) < 3){
238 <<
" negative, " << adelta1.first/adelta2.first << endl;
243 limit = currentBSObj.
sigmaZ()/2.;
244 bool deltaZ = (
deltaSig(adelta1z0.first,adelta1z0.second) > 3.5 && fabs(adelta1z0.first) >=
limit)?
true:
false;
246 bool deltasigmaZ = (
deltaSig(adelta.first,adelta.second) > 5.0)?
true:
false;
247 bool deltadxdz =
false;
248 bool deltadydz =
false;
249 bool deltawidthX =
false;
250 bool deltawidthY =
false;
255 deltadxdz = (
deltaSig(adelta.first,adelta.second) > 5.0)?
true:
false;
256 if(deltadxdz && (adelta1dxdz.first*adelta2dxdz.first) < 0 && adelta2dxdz.first != 0 && fabs(adelta1dxdz.first/adelta2dxdz.first) > 0.33 && fabs(adelta1dxdz.first/adelta2dxdz.first) < 3){
261 deltadydz = (
deltaSig(adelta.first,adelta.second) > 5.0)?
true:
false;
262 if(deltadydz && (adelta1dydz.first*adelta2dydz.first) < 0 && adelta2dydz.first != 0 && fabs(adelta1dydz.first/adelta2dydz.first) > 0.33 && fabs(adelta1dydz.first/adelta2dydz.first) < 3){
267 deltawidthX = (
deltaSig(adelta.first,adelta.second) > 5.0)?
true:
false;
268 if(deltawidthX && (adelta1widthX.first*adelta2widthX.first) < 0 && adelta2widthX.first != 0 && fabs(adelta1widthX.first/adelta2widthX.first) > 0.33 && fabs(adelta1widthX.first/adelta2widthX.first) < 3){
273 deltawidthY = (
deltaSig(adelta.first,adelta.second) > 5.0)?
true:
false;
274 if(deltawidthY && (adelta1widthY.first*adelta2widthY.first) < 0 && adelta2widthY.first != 0 && fabs(adelta1widthY.first/adelta2widthY.first) > 0.33 && fabs(adelta1widthY.first/adelta2widthY.first) < 3){
279 if (deltaX || deltaY || deltaZ || deltasigmaZ || deltadxdz || deltadydz || deltawidthX || deltawidthY){
283 <<
"close payload because of movement in" 287 <<
", sigmaZ=" << deltasigmaZ
288 <<
", dxdz=" << deltadxdz
289 <<
", dydz=" << deltadydz
290 <<
", widthX=" << deltawidthX
291 <<
", widthY=" << deltawidthY
297 std::pair<edm::Timestamp,reco::BeamSpot> thepair;
299 thepair = std::make_pair( currentBS->second.first,
weight(firstBS,nextBS));
300 tmpBeamSpotMap_[firstBS->first] = thepair;
304 thepair = std::make_pair( nextBS->second.first, nextBSObj);
305 tmpBeamSpotMap_[nextBS->first] = thepair;
308 else if(!foundShift && !endOfRun){
309 thepair = std::make_pair( currentBS->second.first,
weight(firstBS,nextBS));
310 tmpBeamSpotMap_[firstBS->first] = thepair;
313 thepair = std::make_pair( currentBS->second.first,
weight(firstBS,
beamSpotMap_.end()));
314 tmpBeamSpotMap_[firstBS->first] = thepair;
322 if (!docreate) ++countlumi;
351 double sigmaZ,sigmaZError = 0;
352 double dxdz,dxdzError = 0;
353 double dydz,dydzError = 0;
354 double widthX,widthXError = 0;
355 double widthY,widthYError = 0;
357 <<
"Weighted BeamSpot will span lumi " 358 << begin->first <<
" to " << end->first
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;
384 BeamSpot weightedBeamSpot(bsPosition,sigmaZ,dxdz,dydz,widthX,error,type);
387 <<
"Weighted BeamSpot will be:" <<
'\n' 390 return weightedBeamSpot;
396 if (meanError < 1
e-8){
397 tmpError = 1/(valError*valError);
401 tmpError = 1/(meanError*meanError) + 1/(valError*valError);
402 mean = mean/(meanError*meanError) + val/(valError*valError);
404 mean = mean/tmpError;
405 meanError =
sqrt(1/tmpError);
410 return pair<float,float>(x - nextX,
sqrt(
pow(xError,2) +
pow(nextXError,2)) );
416 return fabs(num/den);
419 return float(LONG_MAX);
math::Error< dimension >::type CovarianceMatrix
double z0() const
z coordinate
double sigmaZ0Error() const
error on sigma z
std::string beamSpotOutputBase_
edm::InputTag beamSpotTag_
edm::EDGetTokenT< reco::BeamSpot > beamSpotToken_
AlcaBeamSpotManager(void)
bool getByToken(EDGetToken token, Handle< PROD > &result) const
double dydzError() const
error on dydz
math::XYZPoint Point
point in the space
Timestamp const & beginTime() const
std::map< edm::LuminosityBlockNumber_t, std::pair< edm::Timestamp, reco::BeamSpot > > beamSpotMap_
unsigned int LuminosityBlockNumber_t
std::map< edm::LuminosityBlockNumber_t, std::pair< edm::Timestamp, reco::BeamSpot > >::iterator bsMap_iterator
std::string beamSpotModuleName_
LuminosityBlockNumber_t luminosityBlock() const
double dydz() const
dydz slope
void setBeamWidthY(double v)
double dxdzError() const
error on dxdz
reco::BeamSpot weight(const bsMap_iterator &begin, const bsMap_iterator &end)
double BeamWidthX() const
beam width X
virtual ~AlcaBeamSpotManager(void)
double BeamWidthYError() const
error on beam width Y, assume error in X = Y
double BeamWidthXError() const
error on beam width X, assume error in X = Y
double z0Error() const
error on z
double dxdz() const
dxdz slope
void createWeightedPayloads(void)
double x0Error() const
error on x
double y0Error() const
error on y
void readLumi(const edm::LuminosityBlock &)
T const * product() const
std::string beamSpotLabel_
double sigmaZ() const
sigma z
double BeamWidthY() const
beam width Y
double y0() const
y coordinate
std::pair< float, float > delta(const float &x, const float &xError, const float &nextX, const float &nextXError)
Power< A, B >::type pow(const A &a, const B &b)
float deltaSig(const float &num, const float &den)
double x0() const
x coordinate