421def merge_gains(gains1,gains2,gains3,reference_gains,forced_list,geometry_map,writeAllChannels):
422
423 output_gains={}
424
425 n_files_Tile = 0
426 n_files_LowEta_EMEC = 0
427 n_files_HighEta_EMB = 0
428
429
430
431 if gains3 is not None:
432 good_gains=gains3.getGoodGains()
433 print (" Using run ", gains3.run_nr, " run strategy= ", gains3.strategy )
434
435 if gains3.strategy == "GainOne":
436 n_files_Tile = n_files_Tile + 1
437 if gains3.strategy == "GainOneOvEmecFcalLowEta":
438 n_files_LowEta_EMEC = n_files_LowEta_EMEC + 1
439 if gains3.strategy == "GainOneOvEmbFcalHighEta":
440 n_files_HighEta_EMB = n_files_HighEta_EMB + 1
441
442
443 for ppm_channel in good_gains.keys():
444 gain = good_gains[ppm_channel][0]
445 error_code = good_gains[ppm_channel][1]
446 rec_chan = geometry_map.getReceiverfromPPM(ppm_channel,gains3.strategy)
447 output_gains[rec_chan]=[gain,error_code]
448 else:
449 print ("Ignoring File 3, probably not specified" )
450
451
452
453 if gains2 is not None:
454 good_gains=gains2.getGoodGains()
455 print (" Using run ", gains2.run_nr, " run strategy= ", gains2.strategy )
456
457 if gains2.strategy == "GainOne":
458 n_files_Tile = n_files_Tile + 1
459 if gains2.strategy == "GainOneOvEmecFcalLowEta":
460 n_files_LowEta_EMEC = n_files_LowEta_EMEC + 1
461 if gains2.strategy == "GainOneOvEmbFcalHighEta":
462 n_files_HighEta_EMB = n_files_HighEta_EMB + 1
463
464 for ppm_channel in good_gains.keys():
465 gain = good_gains[ppm_channel][0]
466 error_code = good_gains[ppm_channel][1]
467 rec_chan = geometry_map.getReceiverfromPPM(ppm_channel,gains2.strategy)
468 output_gains[rec_chan]=[gain,error_code]
469 else:
470 print ("Ignoring File 2, probably not specified" )
471
472
473
474
475 if gains1 is not None:
476 good_gains=gains1.getGoodGains()
477 print (" Using run ", gains1.run_nr, " run strategy= ", gains1.strategy )
478
479 if gains1.strategy == "GainOne":
480 n_files_Tile = n_files_Tile + 1
481 if gains1.strategy == "GainOneOvEmecFcalLowEta":
482 n_files_LowEta_EMEC = n_files_LowEta_EMEC + 1
483 if gains1.strategy == "GainOneOvEmbFcalHighEta":
484 n_files_HighEta_EMB = n_files_HighEta_EMB + 1
485
486 for ppm_channel in good_gains.keys():
487 gain = good_gains[ppm_channel][0]
488 error_code = good_gains[ppm_channel][1]
489 rec_chan = geometry_map.getReceiverfromPPM(ppm_channel,gains1.strategy)
490 output_gains[rec_chan]=[gain,error_code]
491 else:
492 print ("Ignoring File 1, probably not specified" )
493
494
495
496
497 if forced_list is not None:
498 myfile = open(forced_list,'r')
499 for line in myfile.readlines():
500 line.rstrip()
501 line.lstrip()
502 line_cont = line.split(' ')
503 line_cont = [iii for iii in line_cont if not iii == '']
504 rec_chan = line_cont[0]
505 gain = float(line_cont[1])
506 error_code = 10
507 output_gains[rec_chan]=[gain,error_code]
508 print ("forcing channel ", rec_chan, " to value ", gain )
509 else:
510 print ("Ignoring forced channel list")
511
512
513
514 if writeAllChannels:
515
516 print ("Adding gains for missing channels from Oracle" )
517 missing_channels = geometry_convertor.getMissingReceiverChannels(output_gains.keys())
518 default_gains = reference_gains.getGoodGains()
519 for channel in missing_channels:
520 gain = default_gains[channel]
521 error_code = 100
522 output_gains[channel]=[gain,error_code]
523
524
525
526 if (not n_files_Tile == 1) or (not n_files_LowEta_EMEC == 1) or (not n_files_HighEta_EMB == 1):
527 print ("WARNING! input files do not allow to calibrate all partitions, using defaults where needed" )
528
529 return output_gains
530
531
532