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”,“Material.compare(‘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?
Cheers,
Nikkie
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("Material.compare(‘ARMCO Iron RRR~13’)")
tree->Scan("Material.compare(\"ARMCO Iron RRR~13\")")
Cheers,
Philippe.
Dear @pcanal,
Thanks for your answer. That does not seem to make a difference, they both result in all entries being displayed.
Cheers,
Nikkie
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("Material.compare('%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:
https://cernbox.cern.ch/index.php/s/JxvQiEArUkaEJIb
I can’t upload it here because csv is not allowed.
Cheers,
Nikkie
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) );
Cheers,
Philippe.
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
system
Closed
7
This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.