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