Select on char when using TTree Draw() function

Dear All,

I’m trying to draw an 2D histogram from a TTree and I would like to select names of materials, which is a branch containing char.

I’ve tried using:
tree->Draw(“Conductivity:Temp”,“‘ARMCO Iron RRR~13’)”)

But then it does not select the ‘ARMCO Iron RRR~13’ only, it actually draws the data from all the Materials in the tree.

Is there a way I can select on strings?


Please read tips for efficient and successful posting and posting code

ROOT Version: Not Provided
Platform: Not Provided
Compiler: Not Provided

I think this mean that TTree::Draw does not calculate correct the selection.

Check the result of:

tree->Scan("‘ARMCO Iron RRR~13’)")
tree->Scan("\"ARMCO Iron RRR~13\")")


Dear @pcanal,

Thanks for your answer. That does not seem to make a difference, they both result in all entries being displayed.


I have a small working example here:

#include <iostream>
#include "TPad.h"
#include "TTree.h"
#include "TH2.h"

TH2F* get2DHisto (const char* file, const char* material, const char* property) 
	TTree* myTree = new TTree();
	myTree->ReadFile(Form("../csvdata/%s.csv", file));
	myTree->Draw(Form("%s:Temp", property), Form("'%s')", material) );

	TH2F* returnHist = (TH2F*)gPad->GetPrimitive("Graph");
	return returnHist;
}//end TTree readFileToTree

void fitter()
	const char* fName = "TwoMetals";
    TH2F* thermalConductivity = get2DHisto(fName, "Beryllium", "Conductivity");

And a small version of the file, with only two metals can be found here:

I can’t upload it here because csv is not allowed.


I see the Material is a C-string column. In this case you need:

myTree->Draw(Form("%s:Temp", property), Form("strstr(Material,\"%s\")", material) );


PS. Strangely TTree::Draw seems to simply ignore what is written after the work Material in your original version.

Thank you very much, that was the solution :slight_smile:

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.