# Global coordinates in \[DetectorHistogrammer\]

**URL:** <https://allpix-squared-forum.web.cern.ch/t/global-coordinates-in-detectorhistogrammer/470>\
**Category:** Uncategorized\
**Created:** [July 31, 2023, 2:56pm UTC](https://allpix-squared-forum.web.cern.ch/t/global-coordinates-in-detectorhistogrammer/470 "2023-07-31T14:56:43Z")\
**Posts on this page:** 15\
**Page:** 1

<div class="post-metadata">

**Author:** ![pietrodelta7](https://allpix-squared-forum.web.cern.ch/letter_avatar_proxy/v4/letter/p/51bf81/32.png) [@pietrodelta7](https://allpix-squared-forum.web.cern.ch/u/pietrodelta7)\
**Post date:** [July 31, 2023, 2:56pm UTC](https://allpix-squared-forum.web.cern.ch/t/global-coordinates-in-detectorhistogrammer/470/1 "2023-07-31T14:56:44Z")

</div>

Hi all,

I was wondering if there is a way to reconfigure [DetectorHistogrammer] to output the hits in global coordinates instead of local ones. Thanks in advance for any advice you can provide.

Cheers,  
Pietro

---

<div class="post-metadata">

**Author:** ![pschutze](https://allpix-squared-forum.web.cern.ch/letter_avatar_proxy/v4/letter/p/45deac/32.png) [@pschutze](https://allpix-squared-forum.web.cern.ch/u/pschutze)\
**Post date:** [August 1, 2023, 11:11am UTC](https://allpix-squared-forum.web.cern.ch/t/global-coordinates-in-detectorhistogrammer/470/2 "2023-08-01T11:11:37Z")

</div>

Dear @pietrodelta7 ,

which output are you referring to? The hitmap (graph) is available in both local and global coordinates. Or are you talking about the log output?

Thanks and cheers  
Paul

---

<div class="post-metadata">

**Author:** ![pietrodelta7](https://allpix-squared-forum.web.cern.ch/letter_avatar_proxy/v4/letter/p/51bf81/32.png) [@pietrodelta7](https://allpix-squared-forum.web.cern.ch/u/pietrodelta7)\
**Post date:** [August 1, 2023, 12:32pm UTC](https://allpix-squared-forum.web.cern.ch/t/global-coordinates-in-detectorhistogrammer/470/3 "2023-08-01T12:32:01Z")

</div>

Hi @pschutze ,

thanks for your reply. Exactly, I mean the hitmap, but in the root file I only get the ones in local coordinates (see picture).

 ![image](https://allpix-squared-forum.web.cern.ch/uploads/default/original/1X/46ba528a6d68f350aca7951bec069858c3fca5e3.png)

Is there a way to extract the histogram in global coordinates from the root file or do I have to re-run them with a special option?

Thanks again.

---

<div class="post-metadata">

**Author:** ![hwennlof](https://allpix-squared-forum.web.cern.ch/letter_avatar_proxy/v4/letter/h/3ab097/32.png) [@hwennlof](https://allpix-squared-forum.web.cern.ch/u/hwennlof)\
**Post date:** [August 1, 2023, 1:15pm UTC](https://allpix-squared-forum.web.cern.ch/t/global-coordinates-in-detectorhistogrammer/470/4 "2023-08-01T13:15:21Z")

</div>

Hi!

Oh, this is a funny bug, thanks for pointing it out! It turns out that we’re doing it wrong (old copy-paste error) when we merge histograms that may have been filled in parallel.  
Due to this, we get two copies of the local hitmap;

```auto
    auto hit_map_global_histogram = hit_map_local->Merge();
    auto hit_map_local_histogram = hit_map_local->Merge();

```

It’s fixed in merge request [!1054](https://gitlab.cern.ch/allpix-squared/allpix-squared/-/merge_requests/1054)  
Turns out the title and axis labels were also wrong, but all good now.  
 ![image](https://allpix-squared-forum.web.cern.ch/uploads/default/original/1X/2a616701886a6b1276d3af307674ae7983f42105.png)

You can extract it from the local histogram by shifting the axes according to the global positions of your sensors (local coordinate (0,0) is in the [centre of the bottom-left pixel of the sensor](https://allpix-squared.docs.cern.ch/docs/05_geometry_detectors/01_geometry/#coordinate-systems)), but I’m afraid there’s no easier way.  
If you have saved the PixelHit objects using [ROOTObjectWriter], you can get the global positions by using the GetPixel() function, and then [getGlobalCenter()](https://allpix-squared.docs.cern.ch/reference/classes/classallpix_1_1pixel/#function-getglobalcenter) on the Pixel objects.

Kind regards,  
Håkan

---

<div class="post-metadata">

**Author:** ![pietrodelta7](https://allpix-squared-forum.web.cern.ch/letter_avatar_proxy/v4/letter/p/51bf81/32.png) [@pietrodelta7](https://allpix-squared-forum.web.cern.ch/u/pietrodelta7)\
**Post date:** [August 1, 2023, 1:23pm UTC](https://allpix-squared-forum.web.cern.ch/t/global-coordinates-in-detectorhistogrammer/470/5 "2023-08-01T13:23:45Z")

</div>

Hi @hwennlof ,

thank you very much for the clarification! Is there an ETA on when the fix is going to be released?

And another (maybe trivial) question: how can I update my Allpix install? (I’m using Ubuntu) Do I have to build everything again from scratch?

Cheers,  
Pietro

---

<div class="post-metadata">

**Author:** ![hwennlof](https://allpix-squared-forum.web.cern.ch/letter_avatar_proxy/v4/letter/h/3ab097/32.png) [@hwennlof](https://allpix-squared-forum.web.cern.ch/u/hwennlof)\
**Post date:** [August 1, 2023, 1:37pm UTC](https://allpix-squared-forum.web.cern.ch/t/global-coordinates-in-detectorhistogrammer/470/6 "2023-08-01T13:37:21Z")

</div>

Hi @pietrodelta7,

The ETA is tricky to know, I will try to poke a merge request reviewer to get it done quickly. If you have Allpix Squared installed locally though, it will be faster to fix this particular issue by hand on your local copy.

There are two lines of code that need changing, in `DetectorHistogrammerModule.cpp`:

 ![image](https://allpix-squared-forum.web.cern.ch/uploads/default/original/1X/9a4dfea88f34d883b507ba570dd534120aabea5e.png)  
The right hand side of this image is the corrected code.

After it has been changed, you can just go to your `build` directory for Allpix Squared and do `make install`, and it will be sorted! No need to rebuild from scratch, and with a change as uncomplicated as this, recompilation should only take a few seconds.

Kind regards,  
Håkan

---

<div class="post-metadata">

**Author:** ![pietrodelta7](https://allpix-squared-forum.web.cern.ch/letter_avatar_proxy/v4/letter/p/51bf81/32.png) [@pietrodelta7](https://allpix-squared-forum.web.cern.ch/u/pietrodelta7)\
**Post date:** [August 1, 2023, 1:39pm UTC](https://allpix-squared-forum.web.cern.ch/t/global-coordinates-in-detectorhistogrammer/470/7 "2023-08-01T13:39:28Z")

</div>

Awesome, thank you again @hwennlof !

---

<div class="post-metadata">

**Author:** ![pietrodelta7](https://allpix-squared-forum.web.cern.ch/letter_avatar_proxy/v4/letter/p/51bf81/32.png) [@pietrodelta7](https://allpix-squared-forum.web.cern.ch/u/pietrodelta7)\
**Post date:** [August 1, 2023, 2:34pm UTC](https://allpix-squared-forum.web.cern.ch/t/global-coordinates-in-detectorhistogrammer/470/8 "2023-08-01T14:34:05Z")

</div>

Hi again @hwennlof and @pschutze ,

sadly I am still having dificulties with the DetectorHistogrammer module. It reports the same bin centers for all the chips on a 2x5 grid. It seems it is taking only the coordinates from one silicon chip (the one in the middle) placing the coordinate origin at the center of it and copying them for the rest of chips.

As a consequence, the histogramms are not propoerly shown (see pictures).

 ![image](https://allpix-squared-forum.web.cern.ch/uploads/default/original/1X/47bfa6c1722182e20bb93075ed455423e519ba81.png)  
 ![image](https://allpix-squared-forum.web.cern.ch/uploads/default/original/1X/6c928c8961c3b2fdb25c99a54a4457e06fe12599.png)

For context: the chips are almost 1cmx1cm and are separated by 0.6mm gaps.

---

<div class="post-metadata">

**Author:** ![hwennlof](https://allpix-squared-forum.web.cern.ch/letter_avatar_proxy/v4/letter/h/3ab097/32.png) [@hwennlof](https://allpix-squared-forum.web.cern.ch/u/hwennlof)\
**Post date:** [August 2, 2023, 8:08am UTC](https://allpix-squared-forum.web.cern.ch/t/global-coordinates-in-detectorhistogrammer/470/9 "2023-08-02T08:08:19Z")

</div>

Hi @pietrodelta7 ,

I see! That makes sense with how the histogram is currently defined. I didn’t notice because all my detectors were relatively neatly in a row in my test case ([this example](https://gitlab.cern.ch/allpix-squared/allpix-squared/-/tree/master/examples/eudet_telescope), slightly modified to shift one of the sensors by 400 µm in the y direction).

Would you mind sharing your geometry file, just so we get a good idea of the positioning of the sensors, so that we can build a good test case for this issue?  
We are working on a solution, and I think we will have it sorted soon so that the histogram ranges are defined by the global position of the individual sensors.

Kind regards,  
Håkan

---

<div class="post-metadata">

**Author:** ![pietrodelta7](https://allpix-squared-forum.web.cern.ch/letter_avatar_proxy/v4/letter/p/51bf81/32.png) [@pietrodelta7](https://allpix-squared-forum.web.cern.ch/u/pietrodelta7)\
**Post date:** [August 2, 2023, 8:10am UTC](https://allpix-squared-forum.web.cern.ch/t/global-coordinates-in-detectorhistogrammer/470/10 "2023-08-02T08:10:19Z")

</div>

HI @hwennlof ,

Thanks for the reply! Attached the geometry file.  
[geometry.conf](https://allpix-squared-forum.web.cern.ch/uploads/short-url/ouaTMJfwcPb1JYrzCTC4U3eUuDu.conf) (1.8 KB)

---

<div class="post-metadata">

**Author:** ![pietrodelta7](https://allpix-squared-forum.web.cern.ch/letter_avatar_proxy/v4/letter/p/51bf81/32.png) [@pietrodelta7](https://allpix-squared-forum.web.cern.ch/u/pietrodelta7)\
**Post date:** [August 2, 2023, 12:24pm UTC](https://allpix-squared-forum.web.cern.ch/t/global-coordinates-in-detectorhistogrammer/470/11 "2023-08-02T12:24:34Z")

</div>

Hi @hwennlof ,

I tested the latest proposal for modification on GitLab. The global histograms are now shown, but the matrix with the counts has now 90x90 entries although my pixel grid has 48x48 pixels. Is that on purpose?

Thanks again for the help.

---

<div class="post-metadata">

**Author:** ![pschutze](https://allpix-squared-forum.web.cern.ch/letter_avatar_proxy/v4/letter/p/45deac/32.png) [@pschutze](https://allpix-squared-forum.web.cern.ch/u/pschutze)\
**Post date:** [August 2, 2023, 1:19pm UTC](https://allpix-squared-forum.web.cern.ch/t/global-coordinates-in-detectorhistogrammer/470/12 "2023-08-02T13:19:25Z")

</div>

Dear @pietrodelta7 ,

what do you mean by “matrix with the counts”. Do you mean the number of bins?  
In global coordinates, the hitmap of a sensor projected onto an x-y surface (that’s what is shown here) does not necessarily benefit from having a number of bins equal to the number of pixels. For a non-rotated sensor, this might be helpful, but imagine a sensor that is rotated, maybe even around more than just one axis. In this case the bins of the histogram would not overlap with the pixels anymore.  
Hence, the answer is that it is not on purpose, but also there’s no strong reason for changing this in my eyes.

Cheers  
Paul

---

<div class="post-metadata">

**Author:** ![pietrodelta7](https://allpix-squared-forum.web.cern.ch/letter_avatar_proxy/v4/letter/p/51bf81/32.png) [@pietrodelta7](https://allpix-squared-forum.web.cern.ch/u/pietrodelta7)\
**Post date:** [August 2, 2023, 1:29pm UTC](https://allpix-squared-forum.web.cern.ch/t/global-coordinates-in-detectorhistogrammer/470/13 "2023-08-02T13:29:43Z")

</div>

Hi @pschutze ,

I meant the matrix with the counts per histogram bin (the “color” on the hitmap).

I understand what you mean. I guess the functionality of a histogram does not align fully with my application in this case, thanks for helping me realize it. What I hoped to extract from the histogramm was a tuple with three coordinates: (pixelcenter\_x, pixelcenter\_y, pixel\_hits). For my application it is very important to have only one entry per pixel, since sometimes I need to manipulate the information collected by each pixel.

This won’t be possible taking the information of the histogramm since, as you pointed out, the bins have to be resized to account for the rotation.

---

<div class="post-metadata">

**Author:** ![pschutze](https://allpix-squared-forum.web.cern.ch/letter_avatar_proxy/v4/letter/p/45deac/32.png) [@pschutze](https://allpix-squared-forum.web.cern.ch/u/pschutze)\
**Post date:** [August 2, 2023, 1:35pm UTC](https://allpix-squared-forum.web.cern.ch/t/global-coordinates-in-detectorhistogrammer/470/14 "2023-08-02T13:35:24Z")

</div>

Dear @pietrodelta7 ,

I understand, yes. For your use case I would recommend using either the `ROOTObjectWriter` ([ROOTObjectWriter | Allpix Squared](https://allpix-squared.docs.cern.ch/docs/08_modules/rootobjectwriter/)) or the `TextWriter` ([TextWriter | Allpix Squared](https://allpix-squared.docs.cern.ch/docs/08_modules/textwriter/)) module to write the raw data to file and perform a quick analysis on the data. You will find objects called `PixelHit` ([Object Types | Allpix Squared](https://allpix-squared.docs.cern.ch/docs/07_objects/01_object_types/#pixelhit)) that contain all the information you need.

You can find an example on how to read the data files in our [repository](https://gitlab.cern.ch/allpix-squared/allpix-squared/-/tree/master/tools/root_analysis_macros) - you can e.g. write python scripts or ROOT macros.

Cheers  
Paul

---

<div class="post-metadata">

**Author:** ![pietrodelta7](https://allpix-squared-forum.web.cern.ch/letter_avatar_proxy/v4/letter/p/51bf81/32.png) [@pietrodelta7](https://allpix-squared-forum.web.cern.ch/u/pietrodelta7)\
**Post date:** [August 2, 2023, 1:45pm UTC](https://allpix-squared-forum.web.cern.ch/t/global-coordinates-in-detectorhistogrammer/470/15 "2023-08-02T13:45:07Z")

</div>

Thanks for all the support!
