| Summary: | 2D histogramming inconsistent with histogramming same data from ntuple | ||
|---|---|---|---|
| Product: | Geant4 | Reporter: | Michael Albergo <michaelsalbergo> |
| Component: | analysis | Assignee: | Ivana.Hrivnacova |
| Status: | RESOLVED INVALID | ||
| Severity: | minor | ||
| Priority: | P4 | ||
| Version: | other | ||
| Hardware: | All | ||
| OS: | All | ||
| Attachments: | These are three images. The first is what the Geant4 ROOT histogrammer does. The second is a scatter plot of the correct data. The third is a correct histogram made from the ntuple data. | ||
Could you, please, post the line of the code where you fill this histogram? Thank you, Hi there,
I store the step X,Y,Z and E in a vector and then fill it in the EventAction.cc below (FillH2). The also fill the ntuple columns here, which turn out fine.
for (unsigned int i = 0; i < m_X.size(); i++){
analysisManager->FillH2(eventID , m_X.at(i), m_Y.at(i), m_Energy_inScinti.at(i));
analysisManager->FillNtupleDColumn((eventID), 1, m_X.at(i));
analysisManager->FillNtupleDColumn((eventID), 2, m_Y.at(i));
analysisManager->FillNtupleDColumn((eventID), 3, m_Z.at(i));
analysisManager->FillNtupleDColumn((eventID), 4, m_Energy_inScinti.at(i));
analysisManager->AddNtupleRow((eventID));
analysisManager->AddNtupleRow((eventID));
analysisManager->AddNtupleRow((eventID));
}
Thank you for your help!
Best,
Michael
Thank you; there should be AddNtupleRow() just once, but this has nothing to do with filling H2. Could you, also, let us know your Geant4 version? I'm using 10.0.04 I believe. Thanks! The Geant4 banner containing the version is printed on the screen when you run your program. A fix for applying units to H2 was included in patch-03 to 10.0, so your version should be ok. Could you, please, check the banner, if it prints "geant4-10-00-patch-04"? I will try to test your use case with this version. Upon running my modification of exampleB4a, the first printed lines are:
*************************************************************
Geant4 version Name: geant4-10-04 (08-December-2017)
Copyright : Geant4 Collaboration
Reference : NIM A 506 (2003), 250-303
WWW : http://cern.ch/geant4
*************************************************************
<<< Geant4 Physics List simulation engine: QGSP_BERT 4.0
Using Root
Visualization Manager instantiating with verbosity "warnings (3)"...
Visualization Manager initialising...
Registering graphics systems...
Is this what you were looking for?
Best,
Michael
Thank you. This means that you are using 10.04 and not 10.0.04. The H2 histograms are included in analysis tests; I have added a histogram similar to yours with filling just few values and the histogram viewed in Root looks ok. From your picture, it looks like you apply the "cm" unit on the values which you fill in the histogram (we don't see how you fill the values in the vectors m_X and m_Y): ->FillH2(id, get_length/cm, ...) As you already define your histogram with units, you should fill the values as: ->FillH2(id, get_length, ...) as the unit will be applied by analysis manager. Or, you can define your histogram without units, with min/max values in cm, and then fill the values in cm: ->CreateH2(HistName, "EdepScinti", 32, -50., 50., 32, -50., 50.); ->FillH2(id, get_length/cm, ...) Please, let us know if this fixes your problem. Best regards, Thanks for this advice -- Could you just let me know what you mean by get_length here? Is this a variable I should create, or some known thing given to FillH2(). Best, Michael (In reply to Ivana.Hrivnacova from comment #7) > Thank you. > This means that you are using 10.04 and not 10.0.04. > > The H2 histograms are included in analysis tests; I have added a histogram > similar to yours with filling just few values and the histogram viewed in > Root looks ok. > > From your picture, it looks like you apply the "cm" unit on the values which > you fill in the histogram (we don't see how you fill the values in the > vectors m_X and m_Y): > ->FillH2(id, get_length/cm, ...) > > As you already define your histogram with units, you should fill the values > as: > ->FillH2(id, get_length, ...) > as the unit will be applied by analysis manager. > > Or, you can define your histogram without units, with min/max values in cm, > and then fill the values in cm: > ->CreateH2(HistName, "EdepScinti", 32, -50., 50., 32, -50., 50.); > ->FillH2(id, get_length/cm, ...) > > Please, let us know if this fixes your problem. > > Best regards, Also, where can I access these analysis tests? Sorry, I am a bit new to Geant4. Thanks, Michael By "get_length" I mean whatever length value, as it is taken from Geant4, without applying a unit; for example: G4double length = step->GetStepLength(); The tests are available only in Geant4 development versions; so I cannot point you to this code. An example of a 2D histogram can be found in basic/B5 example. Best regards, Ah thanks for clarifying. I'm filling the histogram with an x location, a y location, and an energy deposition at that point as the weight on the filling. Does that make sense? Is the difference in units between the locations and the energy value an issue? I.e. one is a distance metric and the other an energy metric? I believe I have figured out what was going wrong, and it was the units. Thanks for your help. Just one quick question -- is there a way to set the draw option for the ROOT files for histograms? I'd like them to be drawn with the "COLZ" draw option, but I'm not sure if the analysisManager can do that. Hello, I am glad that the problem is solved. G4AnalysisManager does not provide functions to define the Draw options for histograms. You need to do this setting in your ROOT macro or in your ROOT interactive session. Best regards, |
Created attachment 497 [details] These are three images. The first is what the Geant4 ROOT histogrammer does. The second is a scatter plot of the correct data. The third is a correct histogram made from the ntuple data. I have a simple problem, extracted from example B4a. I have a material made of a square piece of lead and a square scintillator, and I just want to make a histogram of the x,y location of points where energy is deposited in the material. This works fine when I keep the data in ntuples and make the histograms later with the ntuples, but the ROOT files become very large then (about 200GB for 20,000 events). Instead, I figured I could just fill a histogram for each event in geant4 using CreateH2 and FillH2 to save memory. The problem is that the binning of the histogram doesn't seem to display properly. For example, I define the histo by: analysisManager->CreateH2(HistName, "EdepScinti", 32, -50*cm, 50*cm, 32, -50*cm, 50*cm, "cm","cm"); This is 32 bins for both x and y from -50 cm to 50 cm. My detector is 100 cm in size across x and y. For some reason, the 2d histogram is plotting incorrectly (see the TH2D image). If I just plot the histogram from the ntuple data, the data looks as it should (see the scatter plot image) Is this potentially a bug in the H2 implementation in Geant4, or do you perhaps see something that I am doing incorrectly with the definition of my histogram? Thanks kindly for your advice. I really appreciate it. Best, Michael Albergo