30 DataMixingEMDigiWorker::DataMixingEMDigiWorker() {}
34 : label_(ps.getParameter<
std::
string>(
"Label"))
70 LogInfo(
"DataMixingEMDigiWorker") <<
"===============> adding MC signals for " <<
e.id();
80 LogDebug(
"DataMixingEMDigiWorker") <<
"total # EB digis: " << EBDigis->
size();
105 LogDebug(
"DataMixingEMDigiWorker") <<
"total # EE digis: " << EEDigis->
size();
129 LogDebug(
"DataMixingEMDigiWorker") <<
"total # ES digis: " << ESDigis->
size();
151 unsigned int eventNr,
154 LogInfo(
"DataMixingEMDigiWorker") <<
"\n===============> adding pileups from event " <<
ep->id()
155 <<
" for bunchcrossing " << bcr;
162 std::shared_ptr<Wrapper<EBDigiCollection>
const> EBDigisPTR =
166 const EBDigiCollection *EBDigis = const_cast<EBDigiCollection *>(EBDigisPTR->product());
168 LogDebug(
"DataMixingEMDigiWorker") <<
"total # EB digis: " << EBDigis->
size();
185 std::shared_ptr<Wrapper<EEDigiCollection>
const> EEDigisPTR =
189 const EEDigiCollection *EEDigis = const_cast<EEDigiCollection *>(EEDigisPTR->product());
191 LogDebug(
"DataMixingEMDigiWorker") <<
"total # EE digis: " << EEDigis->
size();
206 std::shared_ptr<Wrapper<ESDigiCollection>
const> ESDigisPTR =
210 const ESDigiCollection *ESDigis = const_cast<ESDigiCollection *>(ESDigisPTR->product());
212 LogDebug(
"DataMixingEMDigiWorker") <<
"total # ES digis: " << ESDigis->
size();
242 int gain_consensus = 0;
250 EBDigiMap::const_iterator iEBchk;
253 currentID = iEB->first;
255 if (currentID == formerID) {
269 unsigned int sizenew = (iEB->second).
size();
270 unsigned int sizeold = EB_old.
size();
272 unsigned int max_samp =
std::max(sizenew, sizeold);
278 int sw_gain_consensus = 0;
280 for (
unsigned int isamp = 0; isamp < max_samp; isamp++) {
281 if (isamp < sizenew) {
282 gain_new = (iEB->second)[isamp].
gainId();
283 adc_new = (iEB->second)[isamp].
adc();
288 if (isamp < sizeold) {
289 gain_old = EB_old[isamp].gainId();
290 adc_old = EB_old[isamp].adc();
295 const std::vector<float> pedeStals =
GetPedestals(ES, currentID);
296 const std::vector<float> gainRatios =
GetGainRatios(ES, currentID);
298 if (adc_new > 0 && adc_old > 0) {
299 if (gain_old == gain_new) {
300 gain_consensus = gain_old;
303 if (gain_old < gain_new) {
305 float ratio = gainRatios[gain_new - 1] / gainRatios[gain_old - 1];
306 adc_old = (
int)round((adc_old - pedeStals[gain_old - 1]) /
ratio + pedeStals[gain_new - 1]);
307 gain_consensus = gain_new;
309 float ratio = gainRatios[gain_old - 1] / gainRatios[gain_new - 1];
310 adc_new = (
int)round((adc_new - pedeStals[gain_new - 1]) /
ratio + pedeStals[gain_old - 1]);
311 gain_consensus = gain_old;
317 adc_sum = adc_new + adc_old - (
int)round(pedeStals[gain_consensus - 1]);
320 if (adc_sum > 4096) {
321 if (gain_consensus < 3) {
322 double ratio = gainRatios[gain_consensus] / gainRatios[gain_consensus - 1];
323 adc_sum = (
int)round((adc_sum - pedeStals[gain_consensus - 1]) /
ratio + pedeStals[gain_consensus]);
324 sw_gain_consensus = ++gain_consensus;
331 if (gain_consensus < sw_gain_consensus) {
332 double ratio = gainRatios[sw_gain_consensus - 1] / gainRatios[gain_consensus - 1];
333 adc_sum = (
int)round((adc_sum - pedeStals[gain_consensus - 1]) /
ratio + pedeStals[sw_gain_consensus - 1]);
334 gain_consensus = sw_gain_consensus;
345 EBdigis->push_back(formerID, EB_old.
frame().
begin());
348 formerID = currentID;
349 EB_old = iEB->second;
354 EBdigis->push_back(currentID, (iEB->second).frame().begin());
363 EEDigiMap::const_iterator iEEchk;
366 currentID = iEE->first;
368 if (currentID == formerID) {
371 unsigned int sizenew = (iEE->second).
size();
372 unsigned int sizeold = EE_old.
size();
374 unsigned int max_samp =
std::max(sizenew, sizeold);
380 for (
unsigned int isamp = 0; isamp < max_samp; isamp++) {
381 if (isamp < sizenew) {
382 gain_new = (iEE->second)[isamp].
gainId();
383 adc_new = (iEE->second)[isamp].
adc();
388 if (isamp < sizeold) {
389 gain_old = EE_old[isamp].gainId();
390 adc_old = EE_old[isamp].adc();
395 const std::vector<float> pedeStals =
GetPedestals(ES, currentID);
396 const std::vector<float> gainRatios =
GetGainRatios(ES, currentID);
398 if (adc_new > 0 && adc_old > 0) {
399 if (gain_old == gain_new) {
400 gain_consensus = gain_old;
403 if (gain_old < gain_new) {
405 float ratio = gainRatios[gain_new - 1] / gainRatios[gain_old - 1];
406 adc_old = (
int)round((adc_old - pedeStals[gain_old - 1]) /
ratio + pedeStals[gain_new - 1]);
407 gain_consensus = gain_new;
409 float ratio = gainRatios[gain_old - 1] / gainRatios[gain_new - 1];
410 adc_new = (
int)round((adc_new - pedeStals[gain_new - 1]) /
ratio + pedeStals[gain_old - 1]);
411 gain_consensus = gain_old;
417 adc_sum = adc_new + adc_old - (
int)round(pedeStals[gain_consensus - 1]);
420 if (adc_sum > 4096) {
421 if (gain_consensus < 3) {
422 double ratio = gainRatios[gain_consensus] / gainRatios[gain_consensus - 1];
423 adc_sum = (
int)round((adc_sum - pedeStals[gain_consensus - 1]) /
ratio + pedeStals[gain_consensus]);
435 EEdigis->push_back(formerID, EE_old.
frame().
begin());
438 formerID = currentID;
439 EE_old = iEE->second;
444 EEdigis->push_back(currentID, (iEE->second).frame().begin());
453 ESDigiMap::const_iterator iESchk;
456 currentID = iES->first;
458 if (currentID == formerID) {
461 unsigned int sizenew = (iES->second).
size();
462 unsigned int sizeold = ES_old.
size();
464 unsigned int max_samp =
std::max(sizenew, sizeold);
470 for (
unsigned int isamp = 0; isamp < max_samp; isamp++) {
471 if (isamp < sizenew) {
472 adc_new = (iES->second)[isamp].
adc();
473 rawdat = (iES->second)[isamp].raw();
478 if (isamp < sizeold) {
479 adc_old = ES_old[isamp].adc();
480 rawdat = ES_old[isamp].raw();
486 adc_sum = adc_new + adc_old;
489 data = adc_sum + (rawdat & 0xF000);
495 ESdigis->push_back(ES_old);
498 formerID = currentID;
499 ES_old = iES->second;
504 ESdigis->push_back(iES->second);
515 LogInfo(
"DataMixingEMDigiWorker") <<
"total # EB Merged digis: " << EBdigis->size();
516 LogInfo(
"DataMixingEMDigiWorker") <<
"total # EE Merged digis: " << EEdigis->size();
517 LogInfo(
"DataMixingEMDigiWorker") <<
"total # ES Merged digis: " << ESdigis->size();
530 std::vector<float> pedeStals(3);
540 pedIter = pedMap.
find(detid);
541 if (pedIter != pedMap.
end()) {
543 pedeStals[0] = aped.mean_x12;
544 pedeStals[1] = aped.mean_x6;
545 pedeStals[2] = aped.mean_x1;
547 edm::LogError(
"DataMixingMissingInput") <<
"Cannot find pedestals";
557 std::vector<float> gainRatios(3);