David O. Kennedy's book Plants and the Human Brain (ISBN-13: 978-0199914012)
Explains some of the current theories for how plants make make their profile of secondary metabolites.
They have a toolbox of enzymes that produce small groups of closely related compounds, with one compound typically peaking. Then the plant can adjust which compounds in the cocktail to be dominating often through a few generations. Another example, epigentics can adjust the ratios of the different co-enzymes resulting in some products formed at a higher rate. The plant wont have to wait for the genes to mutate, it already has an enormous library of blueprints to sort out a competitive factory layout. Which to some degree is transferred to the next generation, so the offspring wont have to start from scratch.
As an example, the Echinopsis family of cacti has among others a family of mescaline related compounds. If for example the cactus needs to adjust feeding and reproduction behavior of local herbivorous insects, to use them as efficient pollinators without suffering too much bite marks. Then the cactus will adjust the cocktail to get the most of the local insect population, still each compound has several uses and side effects good and bad. So from this it doesn't take many generations to change the local makeup, on top of this the local populations exchange genetics through hybridization with related species to import any useful adaptions. Hybrids have a really tough time competing, with its low rate of reproductive offspring, leading to only a few of their genes to live on in the long run.
This might explain the confusing classification of trichocereus species, it can be a real challenge to find a genetic representative of a cactus species today, imagine 50 years ago. E. Pachanoi is notorious for when it comes to random alkaloid profile, but that could just reflect flexibility.
Because of the blurry classifications of species I wouldn't trust the oldest cactus screenings, chemical testing methods are another chapter. Many plant families, especially cacti and cannabis, are very flexible when it comes to adjusting the profile of secondary metabolites to local conditions. Alkaloids aren't necessarily their first choice, again those large columnar cacti might need to make staggering amounts of phenolics to deal with UV. If they can use cheaper derivatives of those phenolics for the job, why make expensive enzymes to produce high amounts of alkaloids? They will cost plenty of amines and minerals to produce both the enzymes themselves and the products.