Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Help for beginners #703

Closed
saraheno opened this issue Sep 8, 2020 · 126 comments
Closed

Help for beginners #703

saraheno opened this issue Sep 8, 2020 · 126 comments
Labels

Comments

@saraheno
Copy link

saraheno commented Sep 8, 2020

Hi all,
I am trying to use dd4hep to do some studies on a crystal dual readout calorimeter. I successfully followed the installation instructions at https://dd4hep.web.cern.ch/dd4hep/page/installation/ on my SLC6 machine, thanks to Andre's help. It compiled correctly.

I see that there is a folder called "examples" and in this an example called "SimpleDetector". This sounds great. I think I may have even copied all the examples over to the build area constructed in the previous step and maybe compiled them.

However, I now have no idea what to do. How can I

  • display the geometry of the simple detector?
  • run some single particles through this to GEANT
    Also, when I look at DD4hepManual, I am a bit confused. When I run GEANT, I know how to add code in SteppingAction.cc etc to access the information created by GEANT. Do I use similar codes to access the information in this case? Are there specific names that should be used? When I look at the code in SimpleDetector, it looks mostly like geometry defining code.

I guess what I'm missing is exactly how to run this and get useful output. is run_sitracking_SimpleCLIC.xml related to this? If so, how do I use it?

Best
Sarah Eno

@petricm
Copy link

petricm commented Sep 8, 2020

Dear @saraheno,

display the geometry of the simple detector?

The examples in the examples folder you need to compile to make them work.

cd ../examples/
mkdir build
cd build
cmake -DBoost_NO_BOOST_CMAKE=ON  ..
make install -j4

However if you just want to showcase how things work you don't need to do this, simply take as a guide the DDDetectors folder. Execute:

geoDisplay DDDetectors/compact/SiD.xml

and a event display should open up (if you want good functionality of this you need to do this locally and not over ssh -X ).

run some single particles through this to GEANT

For this best use ddsim

ddsim --compactFile=DDDetectors/compact/SiD.xml --runType=batch -G -N=2 --outputFile=testSid.root --gun.position "0.0 0.0 1.0*cm" --gun.direction "1.0 0.0 1.0" --gun.energy 100*GeV --part.userParticleHandler=''

to see all possible options do ddsim --help

When I run GEANT, I know how to add code in SteppingAction.cc etc to access the information created by GEANT.

If you want a custom stepping you can refer to this examples: https://github.com/iLCSoft/lcgeo/blob/master/plugins/TPCSDAction.cpp and this should be paired with proper configuration file like this one https://github.com/iLCSoft/lcgeo/blob/master/example/steeringFile.py#L19

Do I use similar codes to access the information in this case?

There are several predefined actions in DD4hep to get users going so you don't necessarily need to write your own like

##  set the default tracker action 
SIM.action.tracker = "Geant4TrackerWeightedAction" 

##  set the default calorimeter action 
SIM.action.calo = "Geant4ScintillatorCalorimeterAction"

this should be a good starting point. If you use these you output file should have all the necessary information for further processing in most cases. Inspect the output file from the ddsim examples

Are there specific names that should be used?

not really, or maybe I don't get this question.

As a bottom line, to get started firstly use the examples in DDDetectors and later see how you can build you own geometry by exploring the examples folder.

@saraheno
Copy link
Author

saraheno commented Sep 8, 2020

Thanks, Unfortunately, I am still having problems with the build.
I first cloned https://github.com/AIDASoft/DD4hep
then I cc'd down into DD4hep and I followed the instructions at https://dd4hep.web.cern.ch/dd4hep/page/installation/
mkdir build && cd build/ $ cmake -DDD4HEP_USE_GEANT4=ON -DBoost_NO_BOOST_CMAKE=ON -DDD4HEP_USE_LCIO=ON -DBUILD_TESTING=ON -DGeant4_DIR=$G4INSTALL/lib/Geant4-10.4.0 -DROOT_DIR=$ROOTSYS .. $ make -j4 $ make install

that worked fine. As you can see, in these instructions, you make a "build" area in the DD4hep area. When I cd down into that build area, I see it did not pull over the "examples". So I copy this by hand
cp -r ../examples .``

I then try cd'ing down into this new examples area and doing the commands you list, including making a new build subdirectory in this new examples area. The full cmake command is
``cmake -DDD4HEP_USE_GEANT4=ON -DBoost_NO_BOOST_CMAKE=ON -DDD4HEP_USE_LCIO=ON -DBUILD_TESTING=ON -DGeant4_DIR=$G4INSTALL/lib/Geant4-10.4.0 -DROOT_DIR=$ROOTSYS .. > haha.txt

I attach the dump showing the error during the compile below
haha.txt

@andresailer
Copy link
Member

I think you need to first

source bin/thisdd4hep.sh

before running cmake for the examples. Because at the moment the DD4hep from the LCG installation is found, which is quite a bit older.

-- |++> Check for DD4hep_DDCORE_LIBRARY: /cvmfs/sft.cern.ch/lcg/views/LCG_96b/x86_64-slc6-gcc8-opt/lib/libDDCore.so -- ok

For the examples the idea is to create a build folder in that directory. DD4hep/examples/build
(In principle it shouldn't matter where the build folder is created, as long as cmake is pointed to the CMakeLists.txt of examples, but we never really test the out-of-source buildfolder)

You can also build the examples along the rest of DD4hep by enabling in the main DD4hep/build folder

cmake <ALL_THE_OTHER_OPTIONS> -DDD4HEP_BUILD_EXAMPLES=ON <And So On>

@saraheno
Copy link
Author

saraheno commented Sep 9, 2020

Thanks. It did compile with these commands

git clone https://github.com/AIDASoft/DD4hep.git
cd DD4hep
COMPILER_VERSION=gcc8 LCG_RELEASE=LCG_96b source .dd4hep-ci.d/init_x86_64.sh
source bin/thisdd4hep.sh
cd examples
mkdir build
cd build
cmake -DDD4HEP_USE_GEANT4=ON -DBoost_NO_BOOST_CMAKE=ON -DDD4HEP_USE_LCIO=ON -DBUILD_TESTING=ON -DGeant4_DIR=$G4INSTALL/lib/Geant4-10.4.0 -DROOT_DIR=$ROOTSYS ..
make
make install

But now I'm a bit confused about your example commands. You give two:
geoDisplay DDDetectors/compact/SiD.xml
ddsim --compactFile=DDDetectors/compact/SiD.xml --runType=batch -G -N=2 --outputFile=testSid.root --gun.position "0.0 0.0 1.0cm" --gun.direction "1.0 0.0 1.0" --gun.energy 100GeV --part.userParticleHandler=

but both of these look like I would run them from the DD4hep directory, not the DD4hep/examples/build area, because DDDetectors is only in DD4hep and not in DD4hep/examples/build. Also, I did look at SiD.xml with geodisplay and it is a pretty fancy detector. I was hoping "SimpleDetector" was something like the B4a example in GEANT? something truly simple? If I cd back into DD4hep/examples then I do see some xml files like ./SimpleDetector/compact/Simple_ILD.xml. But when I try to geodisplay this, it crashes with - No factory with name Create AirTube

Is there a truly simple example I can study?

@andresailer
Copy link
Member

For any of the commands it doesn't matter from which directory they are executed, as long as the relative path to the XML file is correct. The executables and libraries all have to be in the PATH or LD_LIBRARY_PATH.
For the example there are also this<PackageName>.sh scripts created that have to be sourced , otherwise the required libraries are not in the LD_LIBRARY_PATH

@saraheno
Copy link
Author

saraheno commented Sep 9, 2020

That's true, Andre. I guess this was a round about way of pointing out that the commands were not for the actual examples. Is there a simple example? If so, what is the corresponding xml file?

@saraheno
Copy link
Author

saraheno commented Sep 9, 2020

also, when I look at the command to run a few particle gun events, it seems to be truncated? Should

--part.userParticleHandler=

have something after the equals sign?

@andresailer
Copy link
Member

Just an empty string --part.userParticleHandler=""

@saraheno
Copy link
Author

saraheno commented Sep 9, 2020

Thanks Andre. Will somebody else answer my question about the existence of a truly simple example? Not a full ILC detector?

@petricm
Copy link

petricm commented Sep 9, 2020

You have two options:

  1. Comments out the lines in this file https://github.com/AIDASoft/DD4hep/blob/master/DDDetectors/compact/SiD.xml#L69-L92 and you can make the the SiD.xml as simple as you wish (Recommended).
  2. you use the SimpleDetector from examples but it to first order the same as commenting out sub-detectors out from the SiD.xml example

@saraheno
Copy link
Author

saraheno commented Sep 9, 2020

Thanks Mark and Andre. I hate to bother you with these beginning questions, but I cannot seem to find the right documentation.

The geoDisplay is fun, and has lots of fun display options. But for some reason I cannot figure out how to zoom. When I put my mouse on the display screen, it is easy to rotate the detector. But ctrl-+ doesn't work for zooming and I cannot seem to find a zoom on the menu on the left.

@petricm
Copy link

petricm commented Sep 9, 2020

mouse scroll should work

@saraheno
Copy link
Author

saraheno commented Sep 9, 2020

Thanks. This tool seems pretty good. When I do the run command:

 ddsim --compactFile=SiD.xml --runType=batch -G -N=10 --outputFile=testSid.root --gun.position "0.0 0.0 1.0*cm" --gun.direction "1.0 1.0 0.0" --gun.energy "100*GeV" --part.userParticleHandler="" --gun.particle "pi-"

I see hits in the siliconvertex detector when I look at testSid.root, but not in any of the other detector elements. Is this the expected behavior?

@saraheno
Copy link
Author

Just wanted to check in again before I try to debug it. Should this example only produce hits (in testSid.root) for the barrel vertex detector? No hits in the barrel tracker and barrel calorimeter? Or am I still doing something wrong?

@andresailer
Copy link
Member

The barrel calorimeters and trackers do not seem to work properly. The endcaps do record hits.

@MarkusFrankATcernch
Copy link
Contributor

MarkusFrankATcernch commented Sep 14, 2020

Just for your information: I ran the standard SiD example:

python <dd4hep-installation>/examples/DDG4/examples/SiDSim.py

for a couple of events and got hits in all subdetectors (endcaps and barrel).
This should exclude basic errors in DDG4. Is it possible that with this gun-direction you simply miss the barrels?

@andresailer
Copy link
Member

I shoot with uniform distribution.
If I comment the tracker (barrel) in the SiD.xml I get hits in the calorimeter barrels (using ddsim).

@andresailer
Copy link
Member

Using ddsim and looking at /tracking/verbose 1 in the geant4 shell I see that particles are killed if this line isn't commented

sdet.setAttributes(description,assembly,x_det.regionStr(),x_det.limitsStr(),x_det.visStr());

   52      214     17.3     10.1   1.9e+03    0.107    0.502       215 av_6_impr_1_TheLayer1_pv_0 Transportation
   53      214     17.3     10.1         0  1.9e+03        0       215 TrackerBarrelSupports_layer0_slice2_2 UserSpecialCut

I don't understand why this doesn't affect SidSim.py but only ddsim

@andresailer
Copy link
Member

This limit kills the primary particle

<limit name="track_length_max" particles="*" value="5.0" unit="mm" />

Still don't understand why this doesn't affect SidSim.py but only ddsim

@andresailer
Copy link
Member

The difference is that in ddsim we activate the step limiters

# add the G4StepLimiterPhysics to activate the max step limits in volumes
ph = DDG4.PhysicsList(kernel, 'Geant4PhysicsList/Myphysics')
ph.addPhysicsConstructor(str('G4StepLimiterPhysics'))
_phys.add(ph)

@MarkusFrankATcernch
Copy link
Contributor

This means that somehow this region definition is incorrect...

@andresailer
Copy link
Member

andresailer commented Sep 14, 2020

Yes, we should probably drop the track_length_max and time_max

andresailer added a commit to andresailer/DD4hep that referenced this issue Sep 14, 2020
…t to do

See AIDASoft#703
The track length max kills particles with tracks longer than that
andresailer added a commit to andresailer/DD4hep that referenced this issue Sep 14, 2020
…t to do

See AIDASoft#703
The track length max kills particles with tracks longer than that
andresailer added a commit to andresailer/DD4hep that referenced this issue Sep 15, 2020
…t to do

See AIDASoft#703
The track length max kills particles with tracks longer than that
@andresailer
Copy link
Member

@saraheno
If you remove these lines you should get hits in all the sub-detectors

<limit name="track_length_max" particles="*" value="5.0" unit="mm" />
<limit name="time_max" particles="*" value="5.0" unit="ns" />

Are you still looking for a simple detector otherwise, or any other issue?

andresailer added a commit that referenced this issue Sep 16, 2020
…t to do

See #703
The track length max kills particles with tracks longer than that
@saraheno
Copy link
Author

saraheno commented Sep 18, 2020 via email

@saraheno
Copy link
Author

nevermind. I have it figured out.

@saraheno
Copy link
Author

I have been working to put some information I need for the dual readout into DDG4. In the "truth" "contrib, I wanted to add the particle beta, so I added
https://github.com/saraheno/DD4hep/blob/f08159b1e87239d4330e793cc82ddbca706d09de/DDG4/include/DDG4/Geant4Data.h#L150

and

https://github.com/saraheno/DD4hep/blob/f08159b1e87239d4330e793cc82ddbca706d09de/DDG4/src/Geant4Data.cpp#L75
(and some similar lines in the header etc)

and I wanted to count scintillator photons so I added

https://github.com/saraheno/DD4hep/blob/f08159b1e87239d4330e793cc82ddbca706d09de/DDG4/include/DDG4/Geant4Data.h#L295

and

https://github.com/saraheno/DD4hep/blob/f08159b1e87239d4330e793cc82ddbca706d09de/DDG4/plugins/Geant4SDActions.cpp#L338

(and some similar lines.

I am having a hard time, though, figuring out how to get this into the root output file. I assume this is related to Geant4Output2root::fill. https://github.com/saraheno/DD4hep/blob/9d0302c83a6a5b3db112d8bf02f3616cde2d9658/DDG4/src/Geant4Output2ROOT.cpp#L90

But I do not see how/where the structure of the hit class is found by the code so it can store it properly... it seems to be storing the old information without the new data (because I guess somehow I need to tell root I added this data)?

@MarkusFrankATcernch
Copy link
Contributor

The minimum you need is a ROOT dictionary of your new class. This should be sufficient.
ROOT knows the C++ typeid of the hit in the container from the type of the first entry and looks for the
corresponding dictionary and uses the information of the dictionary to save the data.

However, I have one question:

Why did you not consequently also add a new hit-class corresponding to the detector:
typedef Geant4SensitiveAction Geant4DualCalorimeterAction;
like it was done for e.g. Geant4Calorimeter.
I am not a friend of "extending" existing classes for specialized sensitive detector actions.
Sooner or later this kicks back.
If you add a merge request, please change this.

@saraheno
Copy link
Author

saraheno commented Oct 28, 2020 via email

@MarkusFrankATcernch
Copy link
Contributor

You have to define the classes for which a dictionary is supposed to be generated in
DDG4/include/DDG4/DDG4Dict.h

You can add your new class simply at line 103. Just copy the 4 lines of the Geant4Calorimeter, paste them below and change
Geant4Calorimeter to Geant4DualCalorimeter. You will also need to include the new header file if necessary.
Then rebuild. Make will re-generate the ROOT dictionaries and compile them....

@saraheno
Copy link
Author

saraheno commented Nov 2, 2020

Hi Markus,
Before moving to the new class, I tried just adding the variable to the dictionary of the old class, just to make sure I knew what I was doing before going through the trouble of making a new class. However, it did not work (and I did redo the make command). You can see my attempt at: https://github.com/saraheno/DD4hep/blob/c683ceee06f48917f2a964286c168c305e912836/DDG4/include/DDG4/DDG4Dict.h#L155

I do not see more variables in the ntuple
image

Any idea what I am doing wrong?

@MarkusFrankATcernch
Copy link
Contributor

Can you re-do the following commands:

   ------------------------------------------------------------------
  | Welcome to ROOT 6.20/04                        https://root.cern |
  | (c) 1995-2020, The ROOT Team; conception: R. Brun, F. Rademakers |
  | Built for linuxx8664gcc on Apr 01 2020, 08:28:48                 |
  | From tags/v6-20-04@v6-20-04                                      |
  | Try '.help', '.demo', '.license', '.credits', '.quit'/'.q'       |
   ------------------------------------------------------------------

root [0] gSystem->Load("libDDG4Plugins.so")
(int) 0
root [1] .class ::dd4hep::sim::Geant4Calorimeter::Hit
Class ::dd4hep::sim::Geant4Calorimeter::Hit not found
root [2] .class dd4hep::sim::Geant4Calorimeter::Hit
===========================================================================
class dd4hep::sim::Geant4Calorimeter::Hit
SIZE: 96 FILE: Geant4Data.h LINE: 272
Base classes: --------------------------------------------------------
0x0        public dd4hep::sim::Geant4HitData
List of member variables --------------------------------------------------
Geant4Data.h    275 0x28       public: dd4hep::Position position, size = 24
DisplacementVector3D.h  -1   0x0        private: class ROOT::Math::Cartesian3D<double> fCoordinates __attribute__((annotate(R"ATTRDUMP(internal coordinate system)ATTRDUMP"))), size = 24
Cartesian3D.h    -1      0x0        private: double fX __attribute__((annotate(R"ATTRDUMP(x coordinate)ATTRDUMP")))
Cartesian3D.h    -1      0x8        private: double fY __attribute__((annotate(R"ATTRDUMP(y coordinate)ATTRDUMP")))
Cartesian3D.h    -1      0x10       private: double fZ __attribute__((annotate(R"ATTRDUMP(z coordinate)ATTRDUMP")))
Geant4Data.h    277 0x40       public: dd4hep::sim::Geant4HitData::Contributions truth, size = 24
Geant4Data.h    279 0x58       public: double energyDeposit
List of member functions :---------------------------------------------------
filename     line:size busy function type and name
(compiled)     (NA):(NA) 0 public: Hit();
(compiled)     (NA):(NA) 0 public: Hit(const dd4hep::Position &cell_pos);
(compiled)     (NA):(NA) 0 public: virtual ~Hit() noexcept;
root [3] gROOT->GetClass("dd4hep::sim::Geant4Calorimeter::Hit")->GetStreamerInfo()->ls()

StreamerInfo for class: dd4hep::sim::Geant4Calorimeter::Hit, checksum=0x5d733fe1
  dd4hep::sim::Geant4HitData BASE            offset=  0 type= 0                     
  ROOT::Math::DisplacementVector3D<ROOT::Math::Cartesian3D<double>,ROOT::Math::DefaultCoordinateSystemTag> position        offset= 40 type=62                     
  vector<dd4hep::sim::Geant4HitData::MonteCarloContrib> truth           offset= 64 type=300 ,stl=1, ctype=61,                     
  double         energyDeposit   offset= 88 type= 8                     
   i= 0, dd4hep::sim::Geant4HitData type=  0, offset=  0, len=1, method=0
   i= 1, position        type= 62, offset= 40, len=1, method=0
   i= 2, truth           type=300, offset= 64, len=1, method=0
   i= 3, energyDeposit   type=  8, offset= 88, len=1, method=0
root [4] ```

If your new variables do not show up, you have not rebuilt properly / there are still not rebuilt libraries in the path.

@saraheno
Copy link
Author

saraheno commented Nov 3, 2020

the new data does show up that way
image
but still does not show up when looking at the root tuple in TBrowser

image

@MarkusFrankATcernch
Copy link
Contributor

try to first
gSystem->Load("libDDG4Plugins.so")
TFile::Open(".....")
TBrowser b

so that the dictionaries are present in the browser as well.

@saraheno
Copy link
Author

saraheno commented Nov 3, 2020

unfortunately that did not help

image

@saraheno
Copy link
Author

saraheno commented Nov 4, 2020

Hi all,
I've been trying to write up a little document that might help young graduate students and very senior faculty get started with being able to edit detectors. I've put it at: https://docs.google.com/document/d/1J1Qx08Ozn8g4XEAypybaJbVPWNe5J576tK-5u2ouMt4/edit#. Maybe it would be useful for others.

@MarkusFrankATcernch
Copy link
Contributor

I first have to finish some stuff for CMS. I will afterwards have a look into the business into adding variables to hit classes.
Sorry.

@saraheno
Copy link
Author

saraheno commented Nov 4, 2020 via email

@petricm
Copy link

petricm commented Nov 6, 2020

We would be very happy if you would be willing to integrate the instructions for beginners into our webpage here https://dd4hep.web.cern.ch/dd4hep/page/beginners-guide/

To do this, you need to fork this repository https://gitlab.cern.ch/CLICdp/DetectorSoftware/DD4hep-website/
and edit the file content/page/beginners-guide.md and then make a merge request on gitlab.

@saraheno
Copy link
Author

saraheno commented Nov 6, 2020 via email

@petricm
Copy link

petricm commented Nov 6, 2020

My tutorial contains many images. Do I create a folder in the "page" area
and put them in there?

You put the image under static/img maybe crete a subfolder there. Then you include an image as

{{< figure src="/img/detectors/LHCb.png" width="500pt" caption="Visualisation of the LHCb detector in DD4hep" >}}

and the location of this image in the repo is static/img/detectors/LHCb.png

And I have to admit I'm not exactly sure what
language is used in the .md files... is it html? twiki? what kind of line
do I put in to point to an image?

The languge is called markdown, see here https://guides.github.com/features/mastering-markdown/ for examples. It's simpler then HTML and easier to type

The only thing not mentioned in this is code highlighting

{{< highlight sh >}}
$ mkdir build && cd build/
$ cmake -DDD4HEP_USE_GEANT4=ON -DBoost_NO_BOOST_CMAKE=ON -DDD4HEP_USE_LCIO=ON -DBUILD_TESTING=ON -DGeant4_DIR=$G4INSTALL/lib/Geant4-10.4.0 -DROOT_DIR=$ROOTSYS ..
$ make -j4
$ make install
{{< /highlight >}}

this is how to highligh sh there is a complete list of code highlighters here https://gohugo.io/content-management/syntax-highlighting/

And one more thing, markdown is the language that is used here on GitHub, any styling we have done in this issues thread is with markdown.

@saraheno
Copy link
Author

saraheno commented Nov 9, 2020

when I look at existing files in this area, I see text like you described for including the figures, but that is the problem: I see this text, not the figures. for example in https://gitlab.cern.ch/eno/DD4hep-website/-/blob/master/content/page/showcases.md I see text for including figures, not figures? How do I get it to show correctly?

@petricm
Copy link

petricm commented Nov 9, 2020

The figures will only be visible once the webpage is converted to HTML with hugo, to do this:

@saraheno
Copy link
Author

saraheno commented Nov 9, 2020

I managed to install hugo, but when I run it, it does not seem to be correctly picking up the pictures. Can you see what is wrong with my .md file sytax?

https://gitlab.cern.ch/eno/DD4hep-website/-/blob/master/content/page/beginners-guide.md

@saraheno
Copy link
Author

so I wonder if the reason my extension to Geant4Calorimeter::Hit is ending up in the root output is due to this line

Geant4HitCollection* coll = dynamic_cast<Geant4HitCollection*>(collection);

Here is it cast as a Geant4HitCollection
and it is stored in

fill(hc_nam, coll->vector_type(), &hits);

is the fill smart enough to do a cast to find out if it is a Geant4Tracker::Hit or a Geant4Calorimeter:Hit and store the appropriate data? Maybe I need different "saveCollections" for tracker and calorimeter if I want extended information in the calorimeter?

@MarkusFrankATcernch
Copy link
Contributor

MarkusFrankATcernch commented Nov 13, 2020

The cast should be OK.
ROOT is clever enough to be able to handle polymorph pointer containers.
However, if I remember correctly, the browser does not show elements which are not contained in the base class.
These elements though should still be written to the data file.
I think this is what happens.

Try this script (save a check_branch.C). Edit file- and branch names according to your data,
You can also print values of your newly added entries. in Geant4Calorimeter::Hit to verify the stuff got written.

#include <DDG4/Geant4Data.h>
#include <TFile.h>
#include <TBranch.h>
#include <TTree.h>
#include <iostream>

void check_branch()   {
  typedef std::vector<dd4hep::sim::Geant4Tracker::Hit*> TrHits;
  typedef std::vector<dd4hep::sim::Geant4Calorimeter::Hit*> CalHits;
  TrHits* ptracker_hits = new TrHits();
  CalHits* pcalo_hits = new CalHits();
  TFile* f=TFile::Open("CLICSiD_2020-11-10_14-34.root");
  TTree* t=(TTree*)f->Get("EVENT");
  t->Print();
  TBranch* b_tr=t->GetBranch("SiTrackerForwardHits");
  b_tr->SetAddress(&ptracker_hits);
  int num_evt;

  num_evt = b_tr->GetEntries();
  if ( num_evt > 0 )   {
    int nbyte = b_tr->GetEntry(0);
    std::cout << "Tracker hits: " << nbyte << " bytes " << ptracker_hits->size()  << std::endl;
    for(size_t i=0; i<std::min(ptracker_hits->size(),10UL); ++i)    {
      dd4hep::sim::Geant4Tracker::Hit* hit = ptracker_hits->at(i);
      std::cout << "Hit " << (int)i
		<< " type: " << typeid(*hit).name()
		<< " deposit:" << hit->energyDeposit
		<< endl;
    }
  }

  TBranch* b_cal=t->GetBranch("EcalBarrelHits");
  b_cal->SetAddress(&pcalo_hits);
  num_evt = b_cal->GetEntries();
  if ( num_evt > 0 )   {
    int nbyte = b_cal->GetEntry(0);
    std::cout << "Calo hits: " << nbyte << " bytes " << pcalo_hits->size()  << std::endl;
    for(size_t i=0; i<std::min(pcalo_hits->size(),10UL); ++i)    {
      dd4hep::sim::Geant4Calorimeter::Hit* hit = pcalo_hits->at(i);
      std::cout << "Hit " << (int)i
		<< " type: " << typeid(*hit).name()
		<< " deposit:" << hit->energyDeposit
		<< endl;*............................................................................*
    }
  }
}

Then:

   ------------------------------------------------------------------
  | Welcome to ROOT 6.20/04                        https://root.cern |
  | (c) 1995-2020, The ROOT Team; conception: R. Brun, F. Rademakers |
  | Built for linuxx8664gcc on Apr 01 2020, 08:28:48                 |
  | From tags/v6-20-04@v6-20-04                                      |
  | Try '.help', '.demo', '.license', '.credits', '.quit'/'.q'       |
   ------------------------------------------------------------------

root [0]   gSystem->Load("libDDG4Plugins.so");
root [1] .X ../../DD4hep/examples/DDG4/examples/initAClick.C+
.....
/SW/DD4hep_head_dbg.root_v6.20.04.g4_10.06.p01_MT/DD4hep/lib/libDDG4.so
(int) 0
root [2] .X ../check_branch.C+
Info in <TUnixSystem::ACLiC>: creating shared library /dd4hep/DD4hep_head_dbg.root_v6.20.04.g4_10.06.p01_MT/build/examples/./../check_branch_C.so
warning: Please remove the deprecated flag -g
......
Tracker hits: 2562 bytes 12
Hit 0 type: N6dd4hep3sim13Geant4Tracker3HitE deposit:0.0119253
Hit 1 type: N6dd4hep3sim13Geant4Tracker3HitE deposit:0.0190136
Hit 2 type: N6dd4hep3sim13Geant4Tracker3HitE deposit:0
Hit 3 type: N6dd4hep3sim13Geant4Tracker3HitE deposit:0
Hit 4 type: N6dd4hep3sim13Geant4Tracker3HitE deposit:0
Hit 5 type: N6dd4hep3sim13Geant4Tracker3HitE deposit:0
Hit 6 type: N6dd4hep3sim13Geant4Tracker3HitE deposit:0.0260849
Hit 7 type: N6dd4hep3sim13Geant4Tracker3HitE deposit:0.0306054
Hit 8 type: N6dd4hep3sim13Geant4Tracker3HitE deposit:0
Hit 9 type: N6dd4hep3sim13Geant4Tracker3HitE deposit:0
Calo hits: 3290050 bytes 10502
Hit 0 type: N6dd4hep3sim17Geant4Calorimeter3HitE deposit:0.232466
Hit 1 type: N6dd4hep3sim17Geant4Calorimeter3HitE deposit:0.101582
Hit 2 type: N6dd4hep3sim17Geant4Calorimeter3HitE deposit:0.107285
Hit 3 type: N6dd4hep3sim17Geant4Calorimeter3HitE deposit:0.113386
Hit 4 type: N6dd4hep3sim17Geant4Calorimeter3HitE deposit:0.115735
Hit 5 type: N6dd4hep3sim17Geant4Calorimeter3HitE deposit:0.254945
Hit 6 type: N6dd4hep3sim17Geant4Calorimeter3HitE deposit:0.216533
Hit 7 type: N6dd4hep3sim17Geant4Calorimeter3HitE deposit:0.129965
Hit 8 type: N6dd4hep3sim17Geant4Calorimeter3HitE deposit:0.142332
Hit 9 type: N6dd4hep3sim17Geant4Calorimeter3HitE deposit:0.116001
root [3] .q
...

@saraheno
Copy link
Author

I don't think I can create a pull request for my fork of DD4hep-website at https://gitlab.cern.ch/eno/DD4hep-website because I do not have permission. However, people have already found my tutorial on this thread and are using it from my google doc version, so maybe it would be good if you guys somehow pulled it?

@andresailer
Copy link
Member

@saraheno I just gave you the necessary permissions to create a PR in gitlab, I think

@saraheno
Copy link
Author

Thanks. According to https://docs.github.com/en/free-pro-team@latest/github/collaborating-with-issues-and-pull-requests/creating-a-pull-request-from-a-fork I should see some icon to request the pull. but I do not see this (see screen shot below). I did restart my browser just in case that was the reason. Could this be because I made my fork before I had permissions?

image

@andresailer
Copy link
Member

That documentation is for gitHUB, not gitLAB.
Click on the "+" next to the search field
image

@MarkusFrankATcernch
Copy link
Contributor

@saraheno Once merged, please have a look at
#742
I cranced up the example DDG4_MySensDet. This is doing exactly what you intend:

  • Defining a used defined hit class
  • Filling it in a dedicated sensitive detector
  • writing the data to root.
    I also added a small program to read back the generated data. See the PR comments.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants