Commit 631f99289385f51a775bc7ba2c41b8099cdf1d48

Authored by Marcel Hohmann
1 parent c7d40e2b

Working Tagger

DualTrackTagger/SConscript
1 1 Import('env')
2 2  
3   -env['LIBS'] = ['framework', 'analysis_dataobjects', 'mdst_dataobjects']
  3 +env['LIBS'] = ['framework', 'analysis_dataobjects', 'analysis']
4 4  
5 5 Return('env')
... ...
DualTrackTagger/include/DualTrackTaggerModule.h
1 1 #ifndef DUALTRACKTAGGERMODULE_H
2 2 #define DUALTRACKTAGGERMODULE_H
3 3  
  4 +// Framework
  5 +#include <framework/datastore/StoreArray.h>
4 6 #include <framework/core/Module.h>
5 7  
  8 +// Dataobjects
  9 +#include <analysis/dataobjects/Particle.h>
  10 +#include <analysis/dataobjects/EventExtraInfo.h>
  11 +
  12 +// Variables
  13 +#include <analysis/VariableManager/Variables.h>
  14 +
  15 +// Std C++ includes
  16 +#include <iostream>
  17 +#include <vector>
  18 +
  19 +// Root includes
  20 +#include "TLorentzVector.h"
  21 +#include "TVector3.h"
  22 +#include "TMath.h"
  23 +
  24 +
  25 +
6 26 namespace Belle2 {
7   - /** A module template.
8   - *
9   - * A detailed description of your module.
  27 + /** This module selects and tags possible dual tracks as per the cuts outlined
  28 + * in Belle Note #1079 section 4.1.
  29 + * Currently works only for Belle data (with BelleFlag = True) converted via
  30 + * b2bii.
  31 + * Functionality for Belle 2 and possible improvements for Belle selection
  32 + * (mva?) are planned.
10 33 */
11 34 class DualTrackTaggerModule : public Module {
12 35 public:
13   - /** Constructor, for setting module description and parameters. */
14 36 DualTrackTaggerModule();
15 37  
16   - /** Use to clean up anything you created in the constructor. */
17 38 virtual ~DualTrackTaggerModule();
18 39  
19   - /** Use this to initialize resources or memory your module needs.
20   - *
21   - * Also register any outputs of your module (StoreArrays, StoreObjPtrs, relations) here,
22   - * see the respective class documentation for details.
23   - */
24 40 virtual void initialize() override;
25 41  
26   - /** Called once before a new run begins.
27   - *
28   - * This method gives you the chance to change run dependent constants like alignment parameters, etc.
29   - */
30 42 virtual void beginRun() override;
31 43  
32   - /** Called once for each event.
33   - *
34   - * This is most likely where your module will actually do anything.
35   - */
36 44 virtual void event() override;
37 45  
38   - /** Called once when a run ends.
39   - *
40   - * Use this method to save run information, which you aggregated over the last run.
41   - */
42 46 virtual void endRun() override;
43 47  
44   - /** Clean up anything you created in initialize(). */
45 48 virtual void terminate() override;
46 49 protected:
47   - //definition of input parameters
48 50  
49 51  
50 52 private:
51   - //define your own data members here
52   - virtual void tagDuplicate();
53   - virtual bool compareTracks();
  53 + /** Loops through all particles in event adding those below a Pt threshold
  54 + to \code m_candidateParticles \endcode */
54 55 virtual void identifyPotentialDuplicateTracks();
  56 +
  57 + /** Compares two particles as per the cuts outlined in BN#1079 sec 4.1.
  58 + Returns true if the particles meet the cuts. False if they do not. */
  59 + virtual bool compareTracks(Particle* p1, Particle* p2);
  60 +
  61 + /** Loops through candidate tracks to compare and tag tracks if required */
  62 + virtual void loopTracks();
  63 +
  64 + /** Uses the 'chi2' selection from BN#1079 sec 4.1 to select which of p1,p2
  65 + is the fake track and tags it using extraInfo*/
  66 + virtual void tagDuplicate(Particle* p1, Particle* p2);
  67 +
  68 + /** Calculates BN#1079 sec 4.1 chi2 */
  69 + virtual double chi2(Particle* p);
  70 +
  71 + std::vector<Particle*> m_candidateParticles;
  72 + StoreArray<Particle> m_particles;
  73 +
  74 + bool m_BelleFlag;
55 75 };
56 76 }
57 77 #endif
... ...
DualTrackTagger/src/DualTrackTaggerModule.cc
  1 +// Own Include
1 2 #include <analysis/modules/DualTrackTagger/DualTrackTaggerModule.h>
2 3  
3   -//avoid having to wrap everything in the namespace explicitly
4   -//only permissible in .cc files!
  4 +
  5 +// -- Info --
  6 +// Belle Cuts taken from BN#1079
  7 +
  8 +// ---- TODO ----
  9 +/*
  10 + * Update Belle Cuts (maybe train a BDT?)
  11 + * Add Belle 2 Cuts (retrain same BDT as for Belle?)
  12 + * Remove found duplicate pairs from candidate lists to avoid double tagging and
  13 + increase speed
  14 + * Find new way to tag duplicates to avoid having to add extraInfo to all particles.
  15 +*/
  16 +
5 17 using namespace Belle2;
6 18  
7   -//this line registers the module with the framework and actually makes it available
8   -//in steering files or the the module list (basf2 -m).
9   -//Note that the 'Module' part of the class name is missing, this is also the way it
10   -//will be called in the module list.
11 19 REG_MODULE(DualTrackTagger)
12 20  
13 21 DualTrackTaggerModule::DualTrackTaggerModule() : Module()
14 22 {
15 23 setDescription("Dual Track Tagger Module");
  24 + addParam("BelleFlag",m_BelleFlag,"Used to differentiate Belle (b2bii) data from Belle 2");
16 25  
17   - //add module parameters here [see one of the following tutorials]
18 26 }
19 27  
20 28  
... ... @@ -25,6 +33,7 @@ DualTrackTaggerModule::~DualTrackTaggerModule()
25 33  
26 34 void DualTrackTaggerModule::initialize()
27 35 {
  36 + m_particles.isRequired();
28 37 }
29 38  
30 39 void DualTrackTaggerModule::beginRun()
... ... @@ -33,6 +42,8 @@ void DualTrackTaggerModule::beginRun()
33 42  
34 43 void DualTrackTaggerModule::event()
35 44 {
  45 + identifyPotentialDuplicateTracks();
  46 + loopTracks();
36 47 }
37 48  
38 49 void DualTrackTaggerModule::endRun()
... ... @@ -45,12 +56,101 @@ void DualTrackTaggerModule::terminate()
45 56  
46 57 void DualTrackTaggerModule::identifyPotentialDuplicateTracks()
47 58 {
  59 + // clear candidate particle vector from last event
  60 + m_candidateParticles.clear();
  61 +
  62 +
  63 + // select cut for Belle or Belle 2
  64 + float ptCut;
  65 + if (m_BelleFlag) {
  66 + ptCut = 0.275;
  67 + } else {
  68 + ptCut = 0.275;
  69 + }
  70 +
  71 + // add particles that pass selection to vector.
  72 + const unsigned int nParticles = m_particles.getEntries();
  73 +
  74 + for (unsigned int iParticle = 0; iParticle < nParticles; iParticle++) {
  75 + Particle* p = m_particles[iParticle];
  76 +
  77 + if (!p->hasExtraInfo("DualTrack")) {
  78 + p -> addExtraInfo("DualTrack",0);
  79 + } else {
  80 + p -> setExtraInfo("DualTrack",0); // This should not be needed
  81 + }
  82 +
  83 + if (p->get4Vector().Perp() < ptCut) {
  84 + m_candidateParticles.push_back(p);
  85 + } // ptCut
  86 + } //iParticles
48 87 }
49 88  
50   -bool DualTrackTaggerModule::compareTracks()
  89 +void DualTrackTaggerModule::loopTracks()
51 90 {
  91 + for (Particle* p1 : m_candidateParticles) {
  92 + for (Particle* p2 : m_candidateParticles) {
  93 + if (p1 == p2) continue;
  94 + bool duplicates = compareTracks(p1, p2);
  95 + if (duplicates) {
  96 + tagDuplicate(p1 , p2);
  97 + // TODO - remove duplicate tracks from vector to stop double counting and increase speed
  98 + } // duplicats
  99 + } //p2
  100 + } //p1
  101 +}
  102 +
  103 +bool DualTrackTaggerModule::compareTracks(Particle* p1, Particle* p2)
  104 +{
  105 + if (m_BelleFlag) {
  106 + // momentum cut
  107 + TVector3 deltaP = p1->getMomentum() - p2->getMomentum();
  108 + if (deltaP.Mag() >= 0.1) {
  109 + return false;
  110 + }
  111 +
  112 + //angle cut
  113 + float chargeMultiple = p1->getCharge()*p2->getCharge();
  114 +
  115 + // same charge or neutral
  116 + if (chargeMultiple >= 0) {
  117 + if (p1->getMomentum().Angle(p2->getMomentum()) < 15*TMath::Pi()/180) {
  118 + return true;
  119 + }
  120 + return false;
  121 +
  122 + //opposite charge
  123 + } else if (chargeMultiple < 0) {
  124 + if (p1->getMomentum().Angle(p2->getMomentum()) > 165*TMath::Pi()/180) {
  125 + return true;
  126 + }
  127 + return false;
  128 + }
  129 + return false;
  130 +
  131 + } else { // BELLE 2
  132 + return false;
  133 + } // if else
  134 + return false;
  135 +}
  136 +
  137 +void DualTrackTaggerModule::tagDuplicate(Particle* p1, Particle* p2)
  138 +{
  139 +
  140 + double p1chi2 = chi2(p1);
  141 + double p2chi2 = chi2(p2);
  142 +
  143 + if (p1chi2 > p2chi2) {
  144 + //tagWithExtraInfo(p1);
  145 + p1 -> setExtraInfo("DualTrack",1);
  146 + } else {
  147 + //tagWithExtraInfo(p2);
  148 + p2 -> setExtraInfo("DualTrack",1);
  149 + }
52 150 }
53 151  
54   -void DualTrackTaggerModule::tagDuplicate()
  152 +double DualTrackTaggerModule::chi2(Particle* p)
55 153 {
  154 + float gamma = 5;
  155 + return TMath::Power(gamma*Variable::particleDRho(p),2) + TMath::Power(Variable::particleDZ(p),2);
56 156 }
... ...