1. Roast the onions and peppers: Preheat the oven to 450°. Spread the sliced onions on one ungreased baking sheet, and place the peppers on another. Put both baking sheets into the hot oven. Roast the onions, stirring once or twice, for 25 to 30 minutes, until they are browning and soft. Take out the peppers after 20 to 25 minutes, when the skin is blistering and swelling. Let the vegetables cool. Lower the oven temperature to 375°.
2. Make the masa dough: In a large bowl, combine the masa harina, butter, and 1 teaspoon salt. With your hand, incorporate the butter by squeezing the dough through your fingers. Add the water slowly, stirring and squeezing with your hand. Mix until the ingredients are blended.
3. Assemble the pie: Remove the skin from the peppers, split them open, and discard the seeds. Cut them into strips, if you like, or leave them in one piece. Mash the beans with a potato masher, or blend them in a food processor, leaving a bit of texture. Press the dough into a 9-by-9-inch baking pan. Spread the beans evenly over the dough. Lay the peppers on the beans. Dot with goat cheese, then cover the cheese with the onions. Cover the pan with foil. Bake the tamale pie for 40 minutes.
4. While the pie is baking, make the sauce: In a dry saucepan, heat the chili powder and cumin seeds over medium heat, shaking the pan constantly. After about 1 minute, when the seeds have begun to release their aroma, add the tomatoes and the garlic. If you are using the ancho chile, remove it from the water, chop it fine, and add it to the tomato sauce. Simmer the tomato sauce for 25 minutes, stirring once or twice. Toward the end of the simmering, add the cayenne, sugar, and salt and pepper to taste.
5. When the pie has finished baking, cut it into 4 pieces. Spoon a little of the tomato sauce on each of 4 plates, and place each piece on the sauce. Garnish with the scallions, and serve.
Variations: This dish can be dressed up with other garnishes—dollops of sour cream, chopped cilantro, toasted pumpkin seeds, and lime wedges.