ROOT Version: 6.26 Platform: Not Provided Compiler: Not Provided
So, I have a dataframe of a tree with a branch ‘ACR’ holding C array. I want array of indices of ACR in each event, which pass the certain cut.
E.g. given the cut ACR < 5, I want indices of all the elements of ACR which have value less than 5. Or a masking array (array of true/false) might also work.
What will be type of “mask” in above example.
I want to apply some functions on indices returned in mask for each entry.
So I will be using RDataFrame.ForEach(), with ForEach calling a function
only on the elements where mask is true. So, the ‘F’ object of ForEach
has to be passed data type of mask. I tried this thing on ROOT terminal
and got the following result, which is surprising. I expected type to be
RVec<Bool_t>.
root [0] auto rdf = ROOT::RDataFrame("EventParameters","/home/chinmay/DataComparison2022/09Nov2022/Z05_35_G21k_2.6_6.75_8.0/P014_Z05_35_G21k_2p6_6p75_8p0.root")
(ROOT::RDataFrame &) A data frame built on top of the EventParameters dataset.
root [1] auto filterCol = rdf.Define("filterCol","HillasParsHighGain.NumSaturatedCells < 3")
(ROOT::RDF::RInterface<ROOT::Detail::RDF::RLoopManager, void> &) @0x7f28522270d0
root [2] filterCol.GetColumnType("filterCol")
(std::string) "bool"
root [3]
HillasParsHighGain.NumSaturatedCells is a C-array of integers with variable length in above case.
(It is a member of a class, dictionary for which is generated using rootcling)
For technical reasons it’s going to be an RVec<int> rather than an RVec<bool>, but it will have the contents you expect (0 for filtered out elements, 1 for accepted elements) and you can use the mask to copy the selected elements out of RVecs with the same size as the mask, e.g. ACR[ACR < 5] returns a new RVec with just the elements of ACR that are smaller than 5.
Indeed that’s surprising. The expected behavior is something like this:
Okay. So surprisingly GetColumnType("HillasParsHighGain.NumSaturatedCells") returns (std::string) "UInt_t". However the definition of the class is as follows
class HillasParameters : public TObject
{
public:
/* ==================== LIFECYCLE ======================================= */
HillasParameters () ; /* constructor */
void Init(Int_t pixels) ;
virtual ~HillasParameters () ;
void Reset() ;
HillasParameters& operator = (const HillasParameters& hpars) ;
/* ==================== ACCESSORS ======================================= */
/* ==================== MUTATORS ======================================= */
Bool_t finite ; ///< If parameter values are finite
Int_t pixels ; ///< Number of pixels
// Int_t profiles ; ///< Number of profiles
Int_t N_Pix ; ///< Number of pixels in image
Int_t Hit_Pix ; ///< Number of pixels in image
Float_t Size ; ///< size of the event
Float_t MeanX ; ///< <x>
Float_t MeanY ; ///< <y>
Float_t MeanXY ; ///< <xy>
Float_t MeanX2 ; ///< <xsquare>
Float_t MeanY2 ; ///< <ysquare>
Float_t Dist ; ///< distance of the centroid of the image from center
Float_t Frac2 ; ///< distance of the centroid of the image from center
Float_t Length ; ///< Length of the image
Float_t Width ; ///< Width of the image
Float_t Azwidth ; ///< Width of the image
Float_t Asym ; ///< Asymmetry of the image
Float_t Miss ; ///< Miss of the image
Float_t Slope ; ///< Slope of the image axis
Float_t Angle_Xaxis ; ///< Angle of image axis w.r.t. camera X-axis
Float_t Alpha ; ///< Alpha of the image
Float_t Leakage1 ; ///< leakage1 : Fraction of size in outermost ring of camera
Float_t Leakage2 ; ///< leakage2 : Fraction of size in outermost 2 rings of camera
///< array of contents in each pixel in cleaned image
Float_t *Cleaned_Image ; //[pixels]
UInt_t *NumSaturatedCells ; //[pixels]
Bool_t *HitPattern ; //[pixels]
///< array of contents in each pixel in cleaned image
// Float_t *Profile_MeanX ; //[profiles]
///< array of contents in each pixel in cleaned image
// Float_t *Profile_MeanY ; //[profiles]
///endcond{CLASSIMP}
ClassDef(HillasParameters,1) ;
///endcond
}; /* ----- end of class HillasParameters ----- */
HillasParsHighGain is the main branch which is of the type ‘HillasParameters’. Why NumSaturatedCells is shown to be UInt_t ?
I’m not sure. What does tree->Print() say? If it disagrees with RDF this is a bug and it would be great if you could share the input file so we can debug and fix the problem.
It seems that RDF gets type of variable length C-type array members of classes wrong. Recently, I changed my I/O code so as to replace variable C-type array branches in TTree by std::vectors branches.
RDF gets the data type wrong in case of C-array branch, while it gets it right in case of branch holding std::vector.