Commit 20941aa33fa5a710c11c36341ac0155b9269a696

Authored by Marcel Hohmann
1 parent 96aee71d

ClusterSize not saving correctly

DualTrackTagger/include/DualTrackTaggerModule.h
... ... @@ -35,6 +35,20 @@
35 35  
36 36  
37 37 namespace Belle2 {
  38 +
  39 +
  40 + class DualTrackTaggerCluster {
  41 + public:
  42 + DualTrackTaggerCluster() {};
  43 + virtual ~DualTrackTaggerCluster() {};
  44 + void addToCluster(Particle *p);
  45 + int size();
  46 + Particle* getParticle(int i);
  47 + void saveClusterSizeToParticleExtraInfo();
  48 + private:
  49 + std::vector<Particle*> m_ClusterParticles;
  50 + };
  51 +
38 52 /** This module selects and tags possible dual tracks as per the cuts outlined
39 53 * in Belle Note #1079 section 4.1.
40 54 * Currently works only for Belle data (with BelleFlag = True) converted via
... ... @@ -58,17 +72,19 @@ namespace Belle2 {
58 72 virtual void endRun() override;
59 73  
60 74 virtual void terminate() override;
61   - protected:
62 75  
  76 + protected:
63 77  
64 78 private:
  79 +
  80 + /** Compares two particles as per the cuts outlined in BN#1079 sec 4.1.
  81 + Returns true if the particles meet the cuts. False if they do not. */
  82 + virtual bool compareTracks(Particle* p1, Particle* p2); // Made public so cluster class can access.
  83 +
65 84 /** Loops through all particles in event adding those below a Pt threshold
66 85 to \code m_candidateParticles \endcode */
67 86 virtual void identifyPotentialDuplicateTracks(Particle* p);
68 87  
69   - /** Compares two particles as per the cuts outlined in BN#1079 sec 4.1.
70   - Returns true if the particles meet the cuts. False if they do not. */
71   - virtual bool compareTracks(Particle* p1, Particle* p2);
72 88  
73 89 /** Loops through candidate tracks to compare and tag tracks if required */
74 90 virtual void loopTracks();
... ... @@ -80,6 +96,9 @@ namespace Belle2 {
80 96 /** Calculates BN#1079 sec 4.1 chi2 */
81 97 virtual double chi2(Particle* p);
82 98  
  99 + virtual bool matchesAllParticlesInCluster(Particle *p, DualTrackTaggerCluster *c);
  100 +
  101 + virtual void addToClusters(Particle *p);
83 102  
84 103 // ---------------- Functions related to Histos ------------
85 104  
... ... @@ -100,6 +119,8 @@ namespace Belle2 {
100 119  
101 120 StoreArray<Particle> m_particles; // all particles in event
102 121  
  122 + std::vector<DualTrackTaggerCluster*> m_clusters;
  123 +
103 124 // statistics - currently unused.
104 125 long int total_particles;
105 126 long int lowPt_particles;
... ... @@ -133,5 +154,6 @@ namespace Belle2 {
133 154 TEfficiency *h_effFalsePosPt;
134 155  
135 156 };
  157 +
136 158 }
137 159 #endif
... ...
DualTrackTagger/src/DualTrackTaggerModule.cc
... ... @@ -87,6 +87,9 @@
87 87 void DualTrackTaggerModule::terminate()
88 88 {
89 89 finalizeHistograms();
  90 + for (DualTrackTaggerCluster *c : m_clusters) {
  91 + c -> saveClusterSizeToParticleExtraInfo();
  92 + }
90 93 //std::cout << "FINAL STATISTICS:" << total_particles << " | " << lowPt_particles << std::endl;
91 94 //std::cout << "FINAL STATISTICS:" << total_events << std::endl;
92 95 //std::cout << "FINAL STATISTICS:" << (float)total_particles / total_events << " | " << (float)lowPt_particles / total_events << std::endl;
... ... @@ -266,11 +269,23 @@
266 269 v_MCIndex.push_back(temp_pair);
267 270 }
268 271  
269   - } // loop through StoreArray Particles
  272 + } // loop through Particles
270 273  
271 274 for (auto pair : v_MCIndex) {
272 275 h_genParticleIndexMulti -> Fill(pair.second);
273 276 }
  277 +
  278 + // save multiplicity for each particle
  279 + for (unsigned int iParticle = 0; iParticle < nParticles; iParticle++) {
  280 + Particle* p = m_allParticlesInList[iParticle];
  281 +
  282 + for (auto pair : v_MCIndex) {
  283 + if (Variable::genParticleIndex(p) == pair.first) {
  284 + p -> addExtraInfo("genParticleIndexMultiplicity",pair.second);
  285 + }
  286 + }
  287 +
  288 + } // loop through particles
274 289 }
275 290  
276 291 void DualTrackTaggerModule::fillHistograms(Particle *p1, Particle *p2, bool taggedDuplicate)
... ... @@ -336,6 +351,64 @@
336 351 m_histoFile -> Close();
337 352 }
338 353  
339   - //void DualTrackTaggerModule::GroupParticles()
340   - //{
341   - //}
  354 +void DualTrackTaggerModule::addToClusters(Particle* p)
  355 +{
  356 + bool addedToACluster = false;
  357 +
  358 + for (DualTrackTaggerCluster *cluster : m_clusters) {
  359 + if (matchesAllParticlesInCluster(p, cluster)) {
  360 + cluster->addToCluster(p);
  361 + addedToACluster = true;
  362 + break;
  363 + }
  364 + }
  365 +
  366 + if (!addedToACluster) {
  367 + DualTrackTaggerCluster *tempCluster;
  368 + tempCluster->addToCluster(p);
  369 + m_clusters.push_back(tempCluster);
  370 + }
  371 +}
  372 +
  373 +
  374 +bool DualTrackTaggerModule::matchesAllParticlesInCluster(Particle* p, DualTrackTaggerCluster *c)
  375 +{
  376 + bool returnBool = true;
  377 + for (int i = 0; i < c->size(); i++) {
  378 + // if 1 pair fails set to false
  379 + if (!compareTracks(p, c->getParticle(i))) {
  380 + returnBool = false;
  381 + }
  382 + }
  383 + return returnBool;
  384 +}
  385 +
  386 +
  387 + // ---------- Cluster functions -------------
  388 +
  389 +void DualTrackTaggerCluster::addToCluster(Particle* p)
  390 +{
  391 + m_ClusterParticles.push_back(p);
  392 +}
  393 +
  394 +int DualTrackTaggerCluster::size()
  395 +{
  396 + return m_ClusterParticles.size();
  397 +}
  398 +
  399 +Particle* DualTrackTaggerCluster::getParticle(int i)
  400 +{
  401 + return m_ClusterParticles[i];
  402 +}
  403 +
  404 +void DualTrackTaggerCluster::saveClusterSizeToParticleExtraInfo()
  405 +{
  406 + int clusterSize = m_ClusterParticles.size();
  407 + for (Particle *p : m_ClusterParticles) {
  408 + if (!p->hasExtraInfo("ClusterSize")) {
  409 + p -> addExtraInfo("ClusterSize",clusterSize);
  410 + } else { // in case the particle is in two clusters
  411 + p -> setExtraInfo("ClusterSize", 0.5*(clusterSize + p->getExtraInfo("ClusterSize")));
  412 + }
  413 + }
  414 +}
... ...