___|  _ \   |  |    |   |_ _|\ \     / ____|
 |     |   |  |  |    |   |  |  \ \   /  __|
 |   | |   | ___ __|  ___ |  |   \ \ /   |
\____|\___/     _|   _|  _|___|   \_/   _____| 

 --- A GOPHER-LIKE INTERFACE FOR HIVE BLOCKCHAIN ---

Particle physics - exercise 1b solution

BY: @mactro | CREATED: June 6, 2018, 5:04 p.m. | VOTES: 305 | PAYOUT: $37.86 | [ VOTE ]

Repository

https://github.com/BFuks/mad5-utopian-exercises

Introduction

This is a description of my solution provided for particle physics exercise by @lemouth

The exercise code is located in two files:

ex1b-mactro.h
ex1b-mactro.cpp

The goal of the exercise was to implement a simplified mechanism of identifying electrons, muons and jets useful for further study. This process consists of three parts:
1. Identifying baseline objects
2. Removal of overlapping objects
3. Identifying signal objects

It is described in length in ATLAS research paper
https://home.cern/sites/home.web.cern.ch/files/image/inline-images/old/lhc_long_1.jpg
[ Image credits CERN ]

Implementation

This exercise was definitely more fun then the previous one, and required more work. I implemented 7 helper functions to get it done:

  std::vector GetBaselineElectrons(const std::vector& candidate_electrons);
  std::vector GetBaselineMuons(const std::vector& candidate_muons);
  std::vector GetBaselineJets(const std::vector& candidate_jets);
  std::vector GetSignalElectrons(const std::vector& baseline_electrons);
  std::vector GetSignalMuons(const std::vector& baseline_muons);
  std::vector GetSignalJets(const std::vector& baseline_jets);

  void RemoveOverlap(std::vector& jets, std::vector& electrons,
                     std::vector& muons);

All functions except RemoveOverlap() create a new vectors of Lepton or Jet format. I saw no real value in keeping vectors containing overlapping objects, so RemoveOverlap() works on the vectors provided as its arguments.

Bodies of all GetSignal... and GetBaseline.. functions look pretty similar:

std::vector test_analysis::GetBaselineElectrons(const std::vector &candidate_electrons) {
  std::vector result;
  for (auto& candidate : candidate_electrons) {
    if(candidate.pt() <= 5.7)
      continue;
    if(candidate.abseta() >= 2.47)
      continue;
    result.push_back(candidate);
  }
  return result;
}

Inside the for loop that iterates over all provided object, we check their properties, and reject those that doesn't match. If all checks are passed, the candidate object is added to result vector. That process could be rewritten as:

    if(candidate.pt() > 5.7 && candidate.abseta() < 2.47)
      result.push_back(candidate);

Which is shorter, but in case there are many checks to be done (which may be the case if we need to implement full procedure in some of the next exercises), then IMO it is easier to read and debug the longer version.

Removing overlap is also pretty straightforward:

  // Second step from Table 3.
  for(auto& electron: electrons) {
    for(auto jet_it = jets.begin(); jet_it != jets.end(); jet_it++) {
      if(jet_it->dr(electron) < 0.2) {
        jets.erase(jet_it);
        // we have to move iterator back after removing the element
        jet_it--;
      }
    }
  }

Outer loop iterates over elements that have a precedence (need to stay in case of overlap), while inner loop checks the elements that may be potentially removed.

The next overlap removal step is implemented in a very similar way, and the rest of the code is printing of the results.

Results

=> progress: [===>                               ]
Initial electrons count: 0, initial muons count: 0, initial jets count: 6
Baseline electrons count: 0, baseline muons count: 0, baseline jets count: 6
After overlap removal:
Baseline electrons count: 0, baseline muons count: 0, baseline jets count: 6
signal electrons count: 0, signal muons count: 0, signal jets count: 5

        => progress: [======>                            ]
Initial electrons count: 0, initial muons count: 0, initial jets count: 6
Baseline electrons count: 0, baseline muons count: 0, baseline jets count: 6
After overlap removal:
Baseline electrons count: 0, baseline muons count: 0, baseline jets count: 6
signal electrons count: 0, signal muons count: 0, signal jets count: 6

        => progress: [==========>                        ]
Initial electrons count: 2, initial muons count: 1, initial jets count: 9
Baseline electrons count: 2, baseline muons count: 1, baseline jets count: 9
After overlap removal:
Baseline electrons count: 1, baseline muons count: 0, baseline jets count: 9
signal electrons count: 1, signal muons count: 0, signal jets count: 8

        => progress: [=============>                     ]
Initial electrons count: 0, initial muons count: 1, initial jets count: 10
Baseline electrons count: 0, baseline muons count: 1, baseline jets count: 10
After overlap removal:
Baseline electrons count: 0, baseline muons count: 0, baseline jets count: 10
signal electrons count: 0, signal muons count: 0, signal jets count: 8

        => progress: [=================>                 ]
Initial electrons count: 0, initial muons count: 0, initial jets count: 8
Baseline electrons count: 0, baseline muons count: 0, baseline jets count: 8
After overlap removal:
Baseline electrons count: 0, baseline muons count: 0, baseline jets count: 8
signal electrons count: 0, signal muons count: 0, signal jets count: 7

        => progress: [====================>              ]
Initial electrons count: 0, initial muons count: 1, initial jets count: 6
Baseline electrons count: 0, baseline muons count: 1, baseline jets count: 6
After overlap removal:
Baseline electrons count: 0, baseline muons count: 0, baseline jets count: 6
signal electrons count: 0, signal muons count: 0, signal jets count: 6

        => progress: [========================>          ]
Initial electrons count: 0, initial muons count: 0, initial jets count: 4
Baseline electrons count: 0, baseline muons count: 0, baseline jets count: 4
After overlap removal:
Baseline electrons count: 0, baseline muons count: 0, baseline jets count: 4
signal electrons count: 0, signal muons count: 0, signal jets count: 4

        => progress: [===========================>       ]
Initial electrons count: 1, initial muons count: 0, initial jets count: 6
Baseline electrons count: 1, baseline muons count: 0, baseline jets count: 6
After overlap removal:
Baseline electrons count: 1, baseline muons count: 0, baseline jets count: 5
signal electrons count: 0, signal muons count: 0, signal jets count: 5

        => progress: [===============================>   ]
Initial electrons count: 0, initial muons count: 0, initial jets count: 10
Baseline electrons count: 0, baseline muons count: 0, baseline jets count: 10
After overlap removal:
Baseline electrons count: 0, baseline muons count: 0, baseline jets count: 10
signal electrons count: 0, signal muons count: 0, signal jets count: 8

        => progress: [==================================>]
Initial electrons count: 1, initial muons count: 0, initial jets count: 7
Baseline electrons count: 1, baseline muons count: 0, baseline jets count: 7
After overlap removal:
Baseline electrons count: 1, baseline muons count: 0, baseline jets count: 6
signal electrons count: 1, signal muons count: 0, signal jets count: 6

        => progress: [===================================]

Possible improvements

  1. I don't know with what number of objects such analysis should deal. Is it tens? Thousands? Or maybe billions? If the number is big, more care should be taken to optimization of the code - the overlap removal procedure seems to be really costly right now.
  2. "Magic numbers" in the code should be replaced by named constants - I actually noticed that writing this article.
  3. Maybe, for better readability, results could be printed only once instead for each data set.
  4. Not an improvement, but question about requirements: @lemouth Are we limited to any specific C++ standard? I'm using C++11, but maybe should give it up?

Previous exercises

https://steemit.com/utopian-io/@mactro/particle-physics-utopian-project-first-exercise

EDIT

I did some fixes according to the comments by @irelandscape and @lemouth. Both fixes are related to overlap removal:

    for(auto jet_it = jets.begin(); jet_it != jets.end();) {
      if(jet_it->dr(electron) < 0.2 && jet_it->true_btag()) {
        jet_it = jets.erase(jet_it);
        // Iterator now points to element after the removed one, and it will be further
        // incremented by the for loop, so we need to move it back.
        jet_it--;
      }
    }

I added the jet_it->true_btag() check that was missing which caused wrong results. I also assign vector erase result to the iterator jet_it = jets.erase(jet_it);. As pointed out by @irelandscape, not doing so is undefined behavior.

Results after the correction:

=> progress: [===>                               ]
Initial electrons count: 0, initial muons count: 0, initial jets count: 6
Baseline electrons count: 0, baseline muons count: 0, baseline jets count: 6
After overlap removal:
Baseline electrons count: 0, baseline muons count: 0, baseline jets count: 6
signal electrons count: 0, signal muons count: 0, signal jets count: 5

        => progress: [======>                            ]
Initial electrons count: 0, initial muons count: 0, initial jets count: 6
Baseline electrons count: 0, baseline muons count: 0, baseline jets count: 6
After overlap removal:
Baseline electrons count: 0, baseline muons count: 0, baseline jets count: 6
signal electrons count: 0, signal muons count: 0, signal jets count: 6

        => progress: [==========>                        ]
Initial electrons count: 2, initial muons count: 1, initial jets count: 9
Baseline electrons count: 2, baseline muons count: 1, baseline jets count: 9
After overlap removal:
Baseline electrons count: 1, baseline muons count: 0, baseline jets count: 9
signal electrons count: 1, signal muons count: 0, signal jets count: 8

        => progress: [=============>                     ]
Initial electrons count: 0, initial muons count: 1, initial jets count: 10
Baseline electrons count: 0, baseline muons count: 1, baseline jets count: 10
After overlap removal:
Baseline electrons count: 0, baseline muons count: 0, baseline jets count: 10
signal electrons count: 0, signal muons count: 0, signal jets count: 8

        => progress: [=================>                 ]
Initial electrons count: 0, initial muons count: 0, initial jets count: 8
Baseline electrons count: 0, baseline muons count: 0, baseline jets count: 8
After overlap removal:
Baseline electrons count: 0, baseline muons count: 0, baseline jets count: 8
signal electrons count: 0, signal muons count: 0, signal jets count: 7

        => progress: [====================>              ]
Initial electrons count: 0, initial muons count: 1, initial jets count: 6
Baseline electrons count: 0, baseline muons count: 1, baseline jets count: 6
After overlap removal:
Baseline electrons count: 0, baseline muons count: 0, baseline jets count: 6
signal electrons count: 0, signal muons count: 0, signal jets count: 6

        => progress: [========================>          ]
Initial electrons count: 0, initial muons count: 0, initial jets count: 4
Baseline electrons count: 0, baseline muons count: 0, baseline jets count: 4
After overlap removal:
Baseline electrons count: 0, baseline muons count: 0, baseline jets count: 4
signal electrons count: 0, signal muons count: 0, signal jets count: 4

        => progress: [===========================>       ]
Initial electrons count: 1, initial muons count: 0, initial jets count: 6
Baseline electrons count: 1, baseline muons count: 0, baseline jets count: 6
After overlap removal:
Baseline electrons count: 0, baseline muons count: 0, baseline jets count: 6
signal electrons count: 0, signal muons count: 0, signal jets count: 6

        => progress: [===============================>   ]
Initial electrons count: 0, initial muons count: 0, initial jets count: 10
Baseline electrons count: 0, baseline muons count: 0, baseline jets count: 10
After overlap removal:
Baseline electrons count: 0, baseline muons count: 0, baseline jets count: 10
signal electrons count: 0, signal muons count: 0, signal jets count: 8

        => progress: [==================================>]
Initial electrons count: 1, initial muons count: 0, initial jets count: 7
Baseline electrons count: 1, baseline muons count: 0, baseline jets count: 7
After overlap removal:
Baseline electrons count: 0, baseline muons count: 0, baseline jets count: 7
signal electrons count: 0, signal muons count: 0, signal jets count: 7

        => progress: [===================================]
TAGS: [ #utopian-io ] [ #cern ] [ #steemstem ] [ #programming ]

Replies

@bitcoindoubler | June 6, 2018, 7:08 p.m. | Votes: 2 | [ VOTE ]

The Truly Evil Side Of Quantum Computer Blockchain Artificial Intelligence that operate in millions of multiple dimensions.

Please go to youtube.com and search for "Anthony Patch"; and also search for the "Kev Baker Show" to grow your
brain cells on this subject. You are whoefully under informed. Not ignorant , just under-informed.

The 4-dimentional Tesseract is the building brick that is the lattice-work of the blockchain architecture for feeding endless iterations of data into artificial intelligence quantum computers that operate in millions of parallel dimensions.

For example the D-Wave Adiabatic quantum computer Model 8192, has 8192 Qubits... the most powerful computer in the world, with virtually unlimited processing power. It will be used by the CERN particle collider in Geneva to "open a portal to another dimension" in the CERN scientists' own words.

TRANSLATION:- They will open a permanent gateway to the bottomless pit, as prophesied in the Holy Bible. CERN is built over an ancient Roman temple dedicated to the worship of Appolion (Satan), and believed to be a portal to the Bottomless Pit.

The CERN particle colliders counter-rotating particle accelerator rings are a giant quantum computer in themselves,
operating on the same quantum principle as the Josephson junction effect. ITS LARGE SIZE ENABLES IT TO OPEN A MUCH MUCH MUCH MUCH BIGGER QUANTUM PORTAL INTO INTO OTHER DIMENSIONS... THE BOTTOMLESS PIT !!!!!

Fact is Stranger than fiction! Do your own research. Go to youtube.com and search for "Anthony Patch"; and also search for the "Kev Baker Show". GROW YOUR BRAIN!!!

666 it's in your face!!! The logo for CERN hadron particle collider that they will use to open The Bottomless Pit.

When the CERN scientists permanently "open a portal to another dimension", Geneva will cease to exist, IT WILL BE DESTROYED, as prophesied by Nostradamus & the Holy Bible.

Anyone living in Geneva... get out while you still can! The D-Wave adiabatic quantum computers use a mathematical version of the Enochian alphabet, the language of Fallen Angels (demons) to communicate with billions of entities (demons) in millions of dimensions to derive its super-fast quantum computations.

It's easier to call me crazy when you are ignorant, and have not done your research.
I dare you to be intellectually honest with yourself and do your own research on quantum computers.

Go to youtube.com and search for "Anthony Patch"; and also search for the "Kev Baker Show". GROW YOUR BRAIN!!!

The Vatican and the Jesuit Order funded CERN for a reason... to open a portal to the Bottomless Pit.

[IMAGE: https://cdn.steemitimages.com/DQmUTpmwdnoswZUdWV1546GqMvMMAKv7GYh33oLrhp66U9L/image.png]

The Pope sits inside the mouth of a giant snake, at the Paul VI Audience Hall. Oddly, there are no crucifixes or crosses present anywhere in the hall or in the architecture.

[IMAGE: https://cdn.steemitimages.com/DQmPbmH8zpxUawZBSkLKsAywNKpBZfJKcqCo4KaoTeyf58N/image.png]

Inside the snakes mouth, the Satan worshiping Jesuit Pope sits in front of a Reptilian sculpture modelling the hordes of hell coming out of the Bottomless Pit. Fact is stranger than fiction!!!

[IMAGE: https://cdn.steemitimages.com/DQmNTH9SUfsccmXsk1xpoLoJhwT9o1pHvVFuWr4nKuWJ1PJ/image.png]

Hidden in plain site... a reptilian head on a human face of the sculpture . The Popes decorum of choice. Fact is stranger than fiction!!!

[IMAGE: https://cdn.steemitimages.com/DQmaEzJU32yXJqoEEm89i5ewmXE9Siq2gL3m1L9SL4kuM9P/image.png]
Pope Francis Doing The Devil Hand Sign?!! This SHOULD Make Your Skin Crawl!! What Will It Take To Wake-up The Sheeple???

These serial killer pedophile satanists' agenda is to recreate hell on earth... their "New World Order"; in which the surviving humans will be farmed as food for their Reptilian overlords, and human children will be used as satanic fodder in their sex magic rituals.

The Pope with autistic children. Vaccine generated autism in children is a big part of the "New World Order" agenda. At the present rate, half of all children will be autistic by 2050.

Normal people (sheeple) have no idea how truly evil the satanic ruling elite really are.
Normal people have no concept of the horrors the satanic ruling elite have planned for them and their children. Fact is
stranger than fiction!!!

It is now an open secret that the The Truly Dark Side Of Quantum Computer Blockchain Artificial Intelligence is that it is controlled by non-human entities.... demons.

For a taste of the mischief of Quantum Computer Controlled A.I., search google for the demonic trouble people have been having with Amazon.com's Alexa A.I. device.
Such as turning on and off the smart TVs, lights, fridges, music systems, all in the middle of the night; sending it's owners confidential messages to random strangers; inappropriate sexual conversation with children; spinning spinner toys by making them spin with no human input - like a Ouija board; Evil laughter coming out of the Alexa AI device; etc. etc.

This is just a small taste of the hell that demonic quantum controlled AI will bring into our dimension. It's what's coming !!!!!!!!!

@irelandscape | June 6, 2018, 7:44 p.m. | Votes: 1 | [ VOTE ]

Hi @mactro, congratulations on finishing successfully the exercise!

I found that the hardest part was to read the relevant section of the paper and make sense of it. Fortunately @lemouth was of great help to answer any question.

My only comment about your code would be to be careful about the following:

        jets.erase(jet_it);
        // we have to move iterator back after removing the element
        jet_it--;

since erase normally invalidates the iterator. The result is unspecified and yield to unexpected behavior (or crash) with some compilers.

Apart from that, great work! :-)

@mactro | June 7, 2018, 6:06 a.m. | Votes: 0 | [ VOTE ]

Good catch, thanks!

@lemouth | June 6, 2018, 9:53 p.m. | Votes: 1 | [ VOTE ]

I will write a review, but later tomorrow or on Friday. Sorry, I am a but pushed for time. There must be something weird somewhere (according to the final screenshot) and for that I need a few hours to investigate the code.

@mactro | June 7, 2018, 6:09 a.m. | Votes: 0 | [ VOTE ]

Can you just write where do I have bad results and what should they be? That way I can probably find a bug myself.

@lemouth | June 7, 2018, 6:16 a.m. | Votes: 0 | [ VOTE ]

You can check @irelandscape code. It gives results in agreement with my code (see here). But I will have a look later today, I promise :)

@mactro | June 7, 2018, 6:46 a.m. | Votes: 0 | [ VOTE ]

OK, found a bug - I wasn't checking the B-tag in overlap removal procedure.

@lemouth | June 7, 2018, 6:52 a.m. | Votes: 0 | [ VOTE ]

Sorry, there is no bug. This was no mandatory. I was too quick in reading the screen output you pasted :)

@irelandscape | June 7, 2018, 6:45 a.m. | Votes: 0 | [ VOTE ]

Your results look OK to me but maybe I've missed something. Don't have much time to review in-depth right now.

@lemouth | June 7, 2018, 6:51 a.m. | Votes: 2 | [ VOTE ]

Here is my review. First of all, sorry about it. There is no bug and I can't just read a screen output correctly. It was easier after running your code on my computer than on the post snippet ;)

Just two minor comments.

1. HELPER FUNCTIONS

Those functions are great, but you may want to move the thresholds in the arguments too, so that you could use the same methods for various objects and various analyses. Of course thus won't change anything.

2. REMOVALS

> I saw no real value in keeping vectors containing overlapping objects, so RemoveOverlap() works on the vectors provided as its arguments.

This is very correct.

@effofex | June 10, 2018, 1:16 p.m. | Votes: 0 | [ VOTE ]

> I don't know with what number of objects such analysis should deal. Is it tens? Thousands? Or maybe billions? If the number is big, more care should be taken to optimization of the code - the overlap removal procedure seems to be really costly right now.

I was wondering about this myself. I'm planning on ignoring the issue until I know that optimization is necessary.

[ BACK TO TRENDING ] [ BACK TO MENU ]
CMD>