Convert a TH2F histogram to TH1F from the command line

Try:

TH1D *h_px = h->ProjectionX();
h_px->Draw();