415 def makeAlgs (self, config) :
416
417 selectionPostfix = self.selectionName
418 if selectionPostfix != '' and selectionPostfix[0] != '_' :
419 selectionPostfix = '_' + selectionPostfix
420
421
422 if config.geometry() is LHCPeriod.Run1:
423 raise ValueError ("Can't set up the ElectronWorkingPointSelectionConfig with %s, there must be something wrong!" % config.geometry().value)
424
425 if self.identificationWP is None:
426 raise ValueError ("ElectronWorkingPointSelectionConfig: the identificationWP option must be set")
427 if self.identificationWP == 'NoID' and self.doFSRSelection:
428 raise ValueError ("ElectronWorkingPointSelectionConfig: doFSRSelection requires an ID working point, "
429 "it can't be used with identificationWP='NoID'")
430
431 postfix = self.postfix
432 if postfix is None :
433 postfix = self.selectionName
434 if postfix != '' and postfix[0] != '_' :
435 postfix = '_' + postfix
436
437
438 if self.trackSelection :
439 alg = config.createAlgorithm( 'CP::AsgLeptonTrackSelectionAlg',
440 'ElectronTrackSelectionAlg',
441 reentrant=True )
442 alg.selectionDecoration = 'trackSelection' + postfix + ',as_bits'
443 alg.maxD0Significance = self.maxD0Significance
444 alg.maxDeltaZ0SinTheta = self.maxDeltaZ0SinTheta
445 alg.particles = config.readName (self.containerName)
446 alg.preselection = config.getPreselection (self.containerName, '')
447 config.addSelection (self.containerName, self.selectionName, alg.selectionDecoration,
448 preselection=self.addSelectionToPreselection)
449
450 if 'LH' in self.identificationWP:
451
452
453 alg = config.createAlgorithm( 'CP::AsgSelectionAlg', 'ElectronLikelihoodAlg' )
454 alg.selectionDecoration = 'selectLikelihood' + selectionPostfix + ',as_char'
455 if self.recomputeID:
456
457 config.addPrivateTool( 'selectionTool', 'AsgElectronLikelihoodTool' )
458 alg.selectionTool.primaryVertexContainer = 'PrimaryVertices'
459
460
461 if config.geometry() >= LHCPeriod.Run3:
462 if 'HI' not in self.identificationWP:
463 alg.selectionTool.WorkingPoint = self.identificationWP.
replace(
"BLayer",
"BL") +
'Electron'
464 else:
465 alg.selectionTool.WorkingPoint = self.identificationWP.
replace(
'_HI',
'Electron_HI')
466 elif config.geometry() is LHCPeriod.Run2:
467 alg.selectionTool.WorkingPoint = self.identificationWP.
replace(
"BLayer",
"BL") +
'Electron_Run2'
468 else:
469
470 config.addPrivateTool( 'selectionTool', 'CP::AsgFlagSelectionTool' )
471 dfFlag =
"DFCommonElectronsLH" + self.identificationWP.
split(
'LH')[0]
472 dfFlag = dfFlag.replace("BLayer","BL")
473 alg.selectionTool.selectionFlags = [dfFlag]
474 elif 'SiHit' in self.identificationWP:
475
476 algVeto = config.createAlgorithm( 'CP::AsgSelectionAlg', 'ElectronLikelihoodAlgVeto')
477 algVeto.selectionDecoration = 'selectLikelihoodVeto' + postfix + ',as_char'
478 config.addPrivateTool( 'selectionTool', 'CP::AsgFlagSelectionTool' )
479 algVeto.selectionTool.selectionFlags = ["DFCommonElectronsLHLoose"]
480 algVeto.selectionTool.invertFlags = [True]
481 algVeto.particles = config.readName (self.containerName)
482 algVeto.preselection = config.getPreselection (self.containerName, self.selectionName)
483
484 config.addSelection (self.containerName, self.selectionName, algVeto.selectionDecoration,
485 preselection=self.addSelectionToPreselection)
486
487
488 alg = config.createAlgorithm( 'CP::AsgSelectionAlg', 'ElectronLikelihoodAlg' )
489 alg.selectionDecoration = 'selectSiHit' + selectionPostfix + ',as_char'
490
491 config.addPrivateTool( 'selectionTool', 'CP::AsgMaskSelectionTool' )
492 dfVar = "DFCommonElectronsLHLooseBLIsEMValue"
493 alg.selectionTool.selectionVars = [dfVar]
494 mask = 0x6
495 alg.selectionTool.selectionMasks = [mask]
496 elif 'DNN' in self.identificationWP:
497 if self.chargeIDSelectionRun2:
498 raise ValueError('DNN is not intended to be used with '
499 '`chargeIDSelectionRun2` option as there are '
500 'DNN WPs containing charge flip rejection.')
501
502 alg = config.createAlgorithm( 'CP::AsgSelectionAlg', 'ElectronDNNAlg' )
503 alg.selectionDecoration = 'selectDNN' + selectionPostfix + ',as_char'
504 if self.recomputeID:
505
506 config.addPrivateTool( 'selectionTool', 'AsgElectronSelectorTool' )
507
508 alg.selectionTool.WorkingPoint = self.identificationWP + 'Electron'
509 else:
510
511 config.addPrivateTool( 'selectionTool', 'CP::AsgFlagSelectionTool' )
512 dfFlag =
"DFCommonElectronsDNN" + self.identificationWP.
split(
'DNN')[0]
513 alg.selectionTool.selectionFlags = [dfFlag]
514 elif self.identificationWP == 'NoID':
515 alg = None
516 else:
517 raise ValueError (f"Electron ID working point '{self.identificationWP}' is not recognised!")
518
519 wpDecoration = None
520 if alg is not None:
521 wpDecoration = alg.selectionDecoration
522 alg.particles = config.readName (self.containerName)
523 alg.preselection = config.getPreselection (self.containerName, self.selectionName)
524
525 if not self.doFSRSelection:
526 config.addSelection (self.containerName, self.selectionName, alg.selectionDecoration,
527 preselection=self.addSelectionToPreselection)
528
529
530 if 'SiHit' in self.identificationWP:
531
532 algDec = config.createAlgorithm( 'CP::ElectronSiHitDecAlg', 'ElectronSiHitDecAlg' )
533 selDec = 'siHitEvtHasLeptonPair' + selectionPostfix + ',as_char'
534 algDec.selectionName = selDec.split(",")[0]
535 algDec.ElectronContainer = config.readName (self.containerName)
536 if self.muonsForFSRSelection is not None:
537 algDec.AnalMuonContKey = config.readName (self.muonsForFSRSelection)
538 if self.mainElectronContainer is not None:
539 algDec.AnalElectronContKey = config.readName (self.mainElectronContainer)
540
541 algDec.RequireTwoLeptons = True
542 config.addSelection (self.containerName, self.selectionName, selDec,
543 preselection=self.addSelectionToPreselection)
544
545
546 if self.convSelection is not None:
547
548 if self.identificationWP != 'TightLH':
549 raise ValueError(f"convSelection can only be used with TightLH ID, "
550 f"whereas {self.identificationWP} has been selected. convSelection option will be ignored.")
551
552 allowedValues = ["Veto", "GammaStar", "MatConv"]
553 if self.convSelection not in allowedValues:
554 raise ValueError(f"convSelection has been set to {self.convSelection}, which is not a valid option. "
555 f"convSelection option must be one of {allowedValues}.")
556
557
558 alg = config.createAlgorithm( 'CP::AsgSelectionAlg', 'ElectronAmbiguityTypeAlg' )
559 alg.selectionDecoration = 'selectAmbiguityType' + selectionPostfix + ',as_char'
560 config.addPrivateTool( 'selectionTool', 'CP::AsgNumDecorationSelectionToolUInt8' )
561 alg.selectionTool.decorationName = "ambiguityType"
562 alg.selectionTool.doEqual = True
563 alg.selectionTool.equal = 0
564 alg.particles = config.readName (self.containerName)
565 alg.preselection = config.getPreselection (self.containerName, self.selectionName)
566 config.addSelection (self.containerName, self.selectionName, alg.selectionDecoration,
567 preselection=self.addSelectionToPreselection)
568
569
570 alg = config.createAlgorithm( 'CP::AsgSelectionAlg', 'ElectronDFCommonAddAmbiguityAlg' )
571 alg.selectionDecoration = 'selectDFCommonAddAmbiguity' + selectionPostfix + ',as_char'
572 config.addPrivateTool( 'selectionTool', 'CP::AsgNumDecorationSelectionToolInt' )
573 alg.selectionTool.decorationName = "DFCommonAddAmbiguity"
574 if self.convSelection == "Veto":
575 alg.selectionTool.doMax = True
576 alg.selectionTool.max = 1
577 elif self.convSelection == "GammaStar":
578 alg.selectionTool.doEqual = True
579 alg.selectionTool.equal = 1
580 elif self.convSelection == "MatConv":
581 alg.selectionTool.doEqual = True
582 alg.selectionTool.equal = 2
583 alg.particles = config.readName (self.containerName)
584 alg.preselection = config.getPreselection (self.containerName, self.selectionName)
585 config.addSelection (self.containerName, self.selectionName, alg.selectionDecoration,
586 preselection=self.addSelectionToPreselection)
587
588
589 if self.doFSRSelection :
590
591
592 wpDecorationName = wpDecoration.split(',')[0]
593
594 underscorePos = wpDecorationName.find('_')
595 if underscorePos < 0:
596 underscorePos = len(wpDecorationName)
597 outputDecorationName = wpDecorationName[:underscorePos] + 'FSR' + wpDecorationName[underscorePos:]
598 alg = config.createAlgorithm( 'CP::EgammaFSRForMuonsCollectorAlg', 'EgammaFSRForMuonsCollectorAlg' )
599 alg.wpSelection = wpDecoration
600 alg.selectionDecoration = outputDecorationName
601 alg.ElectronOrPhotonContKey = config.readName (self.containerName)
602 if self.muonsForFSRSelection is not None:
603 alg.MuonContKey = config.readName (self.muonsForFSRSelection)
604
605
606
607 if 'SiHit' in self.identificationWP:
608 alg.vetoFSR = True
609
610
611 config.addSelection (self.containerName, self.selectionName,
612 alg.selectionDecoration + ',as_char',
613 preselection=self.addSelectionToPreselection)
614
615
616 if self.isolationWP != 'NonIso' :
617 alg = config.createAlgorithm( 'CP::EgammaIsolationSelectionAlg',
618 'ElectronIsolationSelectionAlg' )
619 alg.selectionDecoration = 'isolated' + selectionPostfix + ',as_char'
620 config.addPrivateTool( 'selectionTool', 'CP::IsolationSelectionTool' )
621 alg.selectionTool.ElectronWP = self.isolationWP
622 if self.closeByCorrection:
623 alg.selectionTool.IsoDecSuffix = "CloseByCorr"
624 alg.egammas = config.readName (self.containerName)
625 alg.preselection = config.getPreselection (self.containerName, self.selectionName)
626 config.addSelection (self.containerName, self.selectionName, alg.selectionDecoration,
627 preselection=self.addSelectionToPreselection)
628
629 if self.chargeIDSelectionRun2 and config.geometry() >= LHCPeriod.Run3:
630 warnings.warn_explicit(
631 "ECIDS is only available for Run 2 and will not have any"
632 " effect in Run 3.",
633 Run2OnlyFeatureWarning, filename='', lineno=0)
634
635
636 if self.chargeIDSelectionRun2 and config.geometry() < LHCPeriod.Run3:
637 alg = config.createAlgorithm( 'CP::AsgSelectionAlg',
638 'ElectronChargeIDSelectionAlg' )
639 alg.selectionDecoration = 'chargeID' + selectionPostfix + ',as_char'
640 if self.recomputeChargeID:
641
642 config.addPrivateTool( 'selectionTool',
643 'AsgElectronChargeIDSelectorTool' )
644 alg.selectionTool.TrainingFile = \
645 'ElectronPhotonSelectorTools/ChargeID/ECIDS_20180731rel21Summer2018.root'
646 alg.selectionTool.WorkingPoint = 'Loose'
647 alg.selectionTool.CutOnBDT = -0.337671
648 else:
649
650 config.addPrivateTool( 'selectionTool', 'CP::AsgFlagSelectionTool' )
651 alg.selectionTool.selectionFlags = ["DFCommonElectronsECIDS"]
652
653 alg.particles = config.readName (self.containerName)
654 alg.preselection = config.getPreselection (self.containerName, self.selectionName)
655 config.addSelection (self.containerName, self.selectionName, alg.selectionDecoration,
656 preselection=self.addSelectionToPreselection)
657
658
std::string replace(std::string s, const std::string &s2, const std::string &s3)
std::vector< std::string > split(const std::string &s, const std::string &t=":")