Nostack option on THStack

I’m trying to plot two histograms on the same canvas, but the second histogram is stacked on the first one. I’m not sure where I can add the option “nostack”, so any help is appreciated!

if not self.rootFile.GetDirectory( id ):
      self.rootFile.mkdir( id )
self.rootFile.cd( id )
self.histoDict[ id ] = {}

self.histoDict[ id ][ "DVHIn" ][ "ShowAllDVHIn" ] = THStack( "nostack", "DVH Comparison" )
self.histoDict[ id ][ "DVHIn" ][ "ShowAllDVHIn" ].Add( self.histoDict[ id ][ "DVHIn" ][ "PlannedDVHIn" ] )
self.histoDict[ id ][ "DVHIn" ][ "ShowAllDVHIn" ].Add( self.histoDict[ id ][ "DVHIn" ][ "DeliveredDVHInAll" ] )
self.histoDict[ id ][ "DVHIn" ][ "ShowAllDVHIn" ].Write( "nostack" )

“nostack” is an option you give to the Draw() method when you draw the stack.

But you can set a default drawing option, can’t you :question: :wink:

Instead of drawing the stack, I’m writing it into a rootfile directory, hence I used Write() instead of Draw(). Is it still possible to define a “nostack” option here?

Where can I set this default option?

No: root.cern.ch/doc/master/THStack … tml#l00422

So, it’s a deficiency of the THStack class (that you cannot “SetOption” as with another TH), isn’t it :question: :wink:
Maybe it would be a good idea to add “THStack::SetOption” :exclamation: :-k

Yes THStack does not have the SetOption() method. It is a “TH” I agree, but not like the others which are histograms. THStack is a collection of histograms… so it is a bit different.

So then is there a way to set the “nostack” option without using the Draw() command?

The “nostack” is just a “current” drawing option (you can draw it using this or another option) -> THStack is exactly the same.

With the current drawing option, the second histogram is plotted as a sum of the two histograms, which is not what I intended. How do I change the drawing option such that the two histograms are plotted as they are, so that I can compare them?

Thanks!

Try (see the THStack Class Reference):
SomeStack->Draw(“nostack”);
SomeStack->Draw(“nostackb”);

[quote=“Pepe Le Pew”]Try (see the THStack Class Reference):
SomeStack->Draw(“nostack”);
SomeStack->Draw(“nostackb”);[/quote]

I’m trying to write the stack into a rootfile directory, but Write( “nostack” ) doesn’t seem to work. Does the option only work with Draw()?

When you say:
SomeStack->Write(“SomeName”);
you will get your stack saved in your ROOT file with a new name “SomeName” (so it has nothing to do with a drawing option, you just “rename” your stack).

[quote=“Pepe Le Pew”]When you say:
SomeStack->Write(“SomeName”);
you will get your stack saved in your ROOT file with a new name “SomeName” (so it has nothing to do with a drawing option, you just “rename” your stack).[/quote]

Yup that is exactly what happens, which is why I’m looking for another way to specify the “nostack” option without using the Draw() command. Is there such a way?