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