Skip to content

convert radiator pointer into shared_ptr instead of constructing new one

When trying to do simulations with non-default radiator parameters I noticed that the parameters I set where always overwritten by the defaults.

For example if I set a radiator with 100 transitions in the run_digi.C:

CbmDigitization run;
CbmTrdRadiator* radiator = new CbmTrdRadiator(true,100, 0.0012, 0.09, "pefoam20", "Kapton");
CbmTrdDigitizer *trddigitizer = new CbmTrdDigitizer(radiator);
run.SetDigitizer(ECbmModuleId::kTrd, trddigitizer);

the number of transitions in the actual digitization run were always reset to the default value of 337.

This seems to happen because the CbmTrdDigitizer expects a shared_ptr<CbmTrdRadiator> and when provided with a normal pointer it will create a new shared one (Line 85f):

CbmTrdDigitizer::CbmTrdDigitizer(CbmTrdRadiator* radiator)
  : CbmTrdDigitizer(std::make_shared<CbmTrdRadiator>(radiator)) {};

The problem is that std::make_shared will invoke the default constructor of CbmTrdRadiator since no parameters are provided, thus overwriting any custom parameters set previously. I think instead of creating a new shared pointer one should convert the normal pointer into a shared pointer to keep the parameters. I am not sure if this should be done by using std::shared_ptr directly or using a static_cast (or some other way?):

//option 1
CbmTrdDigitizer::CbmTrdDigitizer(CbmTrdRadiator* radiator)
    : CbmTrdDigitizer(std::shared_ptr<CbmTrdRadiator>(radiator)) {};

//option 2
CbmTrdDigitizer::CbmTrdDigitizer(CbmTrdRadiator* radiator)
    : CbmTrdDigitizer(static_cast<std::shared_ptr<CbmTrdRadiator>>(radiator)) {};

Both options seem to work in my case, I commited option 1 as it is a bit simpler to read in my opinion.

Merge request reports