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