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 alg.selectionTool.WorkingPoint = self.identificationWP + 'Electron'
486 else:
487
488 config.addPrivateTool( 'selectionTool', 'CP::AsgFlagSelectionTool' )
489 dfFlag =
"DFCommonElectronsDNN" + self.identificationWP.
split(
'DNN')[0]
490 alg.selectionTool.selectionFlags = [dfFlag]
491 elif self.identificationWP == 'NoID':
492 alg = None
493 else:
494 raise ValueError (f"Electron ID working point '{self.identificationWP}' is not recognised!")
495
496 if alg is not None:
497 alg.particles = config.readName (self.containerName)
498 alg.preselection = config.getPreselection (self.containerName, self.selectionName)
499
500 if not self.doFSRSelection:
501 config.addSelection (self.containerName, self.selectionName, alg.selectionDecoration,
502 preselection=self.addSelectionToPreselection)
503
504
505 if 'SiHit' in self.identificationWP:
506
507 algDec = config.createAlgorithm( 'CP::ElectronSiHitDecAlg', 'ElectronSiHitDecAlg' )
508 selDec = 'siHitEvtHasLeptonPair' + selectionPostfix + ',as_char'
509 algDec.selectionName = selDec.split(",")[0]
510 algDec.ElectronContainer = config.readName (self.containerName)
511 if self.muonsForFSRSelection is not None:
512 algDec.AnalMuonContKey = config.readName (self.muonsForFSRSelection)
513 if self.mainElectronContainer is not None:
514 algDec.AnalElectronContKey = config.readName (self.mainElectronContainer)
515
516 algDec.RequireTwoLeptons = True
517 config.addSelection (self.containerName, self.selectionName, selDec,
518 preselection=self.addSelectionToPreselection)
519
520
521 if self.convSelection is not None:
522
523 if self.identificationWP != 'TightLH':
524 raise ValueError(f"convSelection can only be used with TightLH ID, "
525 f"whereas {self.identificationWP} has been selected. convSelection option will be ignored.")
526
527 allowedValues = ["Veto", "GammaStar", "MatConv"]
528 if self.convSelection not in allowedValues:
529 raise ValueError(f"convSelection has been set to {self.convSelection}, which is not a valid option. "
530 f"convSelection option must be one of {allowedValues}.")
531
532
533 alg = config.createAlgorithm( 'CP::AsgSelectionAlg', 'ElectronAmbiguityTypeAlg' )
534 alg.selectionDecoration = 'selectAmbiguityType' + selectionPostfix + ',as_char'
535 config.addPrivateTool( 'selectionTool', 'CP::AsgNumDecorationSelectionToolUInt8' )
536 alg.selectionTool.decorationName = "ambiguityType"
537 alg.selectionTool.doEqual = True
538 alg.selectionTool.equal = 0
539 alg.particles = config.readName (self.containerName)
540 alg.preselection = config.getPreselection (self.containerName, self.selectionName)
541 config.addSelection (self.containerName, self.selectionName, alg.selectionDecoration,
542 preselection=self.addSelectionToPreselection)
543
544
545 alg = config.createAlgorithm( 'CP::AsgSelectionAlg', 'ElectronDFCommonAddAmbiguityAlg' )
546 alg.selectionDecoration = 'selectDFCommonAddAmbiguity' + selectionPostfix + ',as_char'
547 config.addPrivateTool( 'selectionTool', 'CP::AsgNumDecorationSelectionToolInt' )
548 alg.selectionTool.decorationName = "DFCommonAddAmbiguity"
549 if self.convSelection == "Veto":
550 alg.selectionTool.doMax = True
551 alg.selectionTool.max = 1
552 elif self.convSelection == "GammaStar":
553 alg.selectionTool.doEqual = True
554 alg.selectionTool.equal = 1
555 elif self.convSelection == "MatConv":
556 alg.selectionTool.doEqual = True
557 alg.selectionTool.equal = 2
558 alg.particles = config.readName (self.containerName)
559 alg.preselection = config.getPreselection (self.containerName, self.selectionName)
560 config.addSelection (self.containerName, self.selectionName, alg.selectionDecoration,
561 preselection=self.addSelectionToPreselection)
562
563
564 if self.doFSRSelection :
565
566
567 wpDecoration = alg.selectionDecoration
568 wpDecorationName = wpDecoration.split(',')[0]
569
570 underscorePos = wpDecorationName.index('_')
571 outputDecorationName = wpDecorationName[:underscorePos] + 'FSR' + wpDecorationName[underscorePos:]
572 alg = config.createAlgorithm( 'CP::EgammaFSRForMuonsCollectorAlg', 'EgammaFSRForMuonsCollectorAlg' )
573 alg.wpSelection = wpDecoration
574 alg.selectionDecoration = outputDecorationName
575 alg.ElectronOrPhotonContKey = config.readName (self.containerName)
576 if self.muonsForFSRSelection is not None:
577 alg.MuonContKey = config.readName (self.muonsForFSRSelection)
578
579
580
581 if 'SiHit' in self.identificationWP:
582 alg.vetoFSR = True
583
584
585 config.addSelection (self.containerName, self.selectionName,
586 alg.selectionDecoration + ',as_char',
587 preselection=self.addSelectionToPreselection)
588
589
590 if self.isolationWP != 'NonIso' :
591 alg = config.createAlgorithm( 'CP::EgammaIsolationSelectionAlg',
592 'ElectronIsolationSelectionAlg' )
593 alg.selectionDecoration = 'isolated' + selectionPostfix + ',as_char'
594 config.addPrivateTool( 'selectionTool', 'CP::IsolationSelectionTool' )
595 alg.selectionTool.ElectronWP = self.isolationWP
596 if self.closeByCorrection:
597 alg.selectionTool.IsoDecSuffix = "CloseByCorr"
598 alg.egammas = config.readName (self.containerName)
599 alg.preselection = config.getPreselection (self.containerName, self.selectionName)
600 config.addSelection (self.containerName, self.selectionName, alg.selectionDecoration,
601 preselection=self.addSelectionToPreselection)
602
603 if self.chargeIDSelectionRun2 and config.geometry() >= LHCPeriod.Run3:
604 warnings.warn_explicit(
605 "ECIDS is only available for Run 2 and will not have any"
606 " effect in Run 3.",
607 Run2OnlyFeatureWarning, filename='', lineno=0)
608
609
610 if self.chargeIDSelectionRun2 and config.geometry() < LHCPeriod.Run3:
611 alg = config.createAlgorithm( 'CP::AsgSelectionAlg',
612 'ElectronChargeIDSelectionAlg' )
613 alg.selectionDecoration = 'chargeID' + selectionPostfix + ',as_char'
614 if self.recomputeChargeID:
615
616 config.addPrivateTool( 'selectionTool',
617 'AsgElectronChargeIDSelectorTool' )
618 alg.selectionTool.TrainingFile = \
619 'ElectronPhotonSelectorTools/ChargeID/ECIDS_20180731rel21Summer2018.root'
620 alg.selectionTool.WorkingPoint = 'Loose'
621 alg.selectionTool.CutOnBDT = -0.337671
622 else:
623
624 config.addPrivateTool( 'selectionTool', 'CP::AsgFlagSelectionTool' )
625 alg.selectionTool.selectionFlags = ["DFCommonElectronsECIDS"]
626
627 alg.particles = config.readName (self.containerName)
628 alg.preselection = config.getPreselection (self.containerName, self.selectionName)
629 config.addSelection (self.containerName, self.selectionName, alg.selectionDecoration,
630 preselection=self.addSelectionToPreselection)
631
632
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=":")