The American tradition of "trick-or-treating" probably dates back to the early All Souls' Day parades in England. During the festivities, poor citizens would beg for food and families would give them pastries called "soul cakes" in return for their promise to pray for the family's dead relatives.
The distribution of soul cakes was encouraged by the church as a way to replace the ancient practice of leaving food and wine for the returning spirits on Halloween night. The practice, which was referred to as "going a-souling" was eventually taken up by children who would visit the houses in their neighborhood and be given ale, food, and money.
The tradition of dressing in costumes and masks on Halloween finds its roots in both European and Celtic history. On Halloween, when it was believed that ghosts came back to the earthly realm, people thought they would encounter the ghosts if they left their homes. Therefore, to avoid being seen by these ghosts, people would wear masks when they left their homes after dark so that the ghosts would mistake them for fellow spirits.