The tradition of Halloween originated with the ancient Celtic festival of Samhain. During this celebration bonfires were lit and people would wear costumes to ward off ghosts or bad spirits. These Halloween traditions could be traced back 2,000 years. During the late 19th and early 20th centuries, Irish immigrants brought their Halloween traditions with them. It soon blended with the local customs like carving pumpkins and going door to door for treats. Although the idea of Halloween originated in Ireland, the idea of trick or treating originated in Scotland where children would dress up and put on a performance for each house, so they could be rewarded with sweets and other goodies. It can be quite interesting how far along ideas travel through not only time but even across the world.
https://www.forbes.com/sites/brittanyanas/2024/10/29/what-country-is-halloweens-birthplace/