Draw tree branches with random smearing

Hello,

I’ve come across this problem many times and always taken the inelegant solution, and wonder if there’s a nicer way. The issue is that, when you run a Monte Carlo and look at particle energy depositions in a detector, to do the analysis you must often “smear” the edep variable from the output of the MC with a realistic energy resolution (usually gaussian) of your detector. You can do this while filling the histogram, but often the resolution is not exactly known and you want to see how results vary by changing it.

The inelegant way I’ve always handled this is to create a script which loops through the tree entries, reads each edep and fills a histogram manually. However, what I’d really like to do is put that into the draw command directly:

TTree *Events = (TTree*)file->Get("Events");
Events->Draw("gRandom->Gaus( edep, 0.1 * edep)" , "..." );

Which doesn’t work, at least with 5.20. Is there a way to shoot random numbers off of branch values in a draw command right now? If not, I think this feature would be easy to implement, by adding dummy functions into the TMath namespace, e.g.

Double_t TMath::RandGaus(Double_t mu, Double_t sigma) 
{     return gRandom->Gaus(mu,sigma);   }

unless there is something more to determine which functions the TTree::Draw() function can interpret.

Cheers,
~Ben

Hi,
one solution might be to pass a file name (c++ script) to the Draw method of TTree (see: root.cern.ch/root/html518/TTree.html#TTree:Draw). One of the drawbacks is, that you have to write your cuts as a macro in an external file, too.
Cheers, J.

[quote] If not, I think this feature would be easy to implement, by adding dummy functions into the TMath namespace, e.g. [/quote]Yes, and it does not need to be declared in the TMath namespace. You can simply create this function yourself and as long as you generate the dictionary for it, you will be able to access it from TTree::Draw.

Cheers,
Philippe.

Hi,

I think there is a simple solution:

To add a uniform random number to your variable, you can do:

Events->Draw(“edep*0.00001+rndm”);

where I multiplied your original “edep” variable by almost zero, so you can see the random number distribution. N.B. “rndm” is a variable defined by ROOT itself which is a uniform random number between 0 and 1 (see root.cern.ch/root/html/TFormula. … la:Analyze).

Adding a gaussian random number is a little more difficult, since one has to produce it oneself from the uniform random number function:

// Define alias for gaussian random number and then plot
Events->SetAlias(“rng”,“sin(2pirndm)sqrt(-2log(rndm))”);
Events->Draw("_mass0.00001+rng:_mass0.0001+5+3*rng",“1”,“box”);

Regards,
Ian Tomalin

1 Like