The message to railfans is to enjoy the sight of the trains, but at a safe distance, off of railroad property.
While you will see both Union Pacific (UP) and BNSF trains on the tracks, the tracks belong to UP which has a zero-tolerance trespasser policy. Trespassing on the railroad property is illegal and dangerous. Enjoy the trains, but follow the rules and stay safe.
While you're welcome to take all the pictures you like, corporate relations for UP says, "We ask people to stay off the tracks and property so they can stay safe. The UP right of way is usually about 200 feet, stay 200 away from the track and you should be in the clear (plus to get a good shot of the train you probably want to be further back.)"
Some other things to remember while train watching at the Loop or in the Tehachapi area are that freight trains do not travel on a predictable schedule. You should expect a train at every highway-rail intersection and be especially careful at crossings that are not gated. Train tracks are private property; trains have the right of way 100% of the time, over ambulances, fire engines, cars, the police and pedestrians. A train car may extend three feet or more outside the steel rail, which makes the safety zone for pedestrians well beyond the rails themselves.
Modern trains are quieter than ever, with no telltale "clackety-clack on the rails." An approaching train will always be closer and moving faster than you think. Cross tracks only at designated pedestrian or roadway crossings. Observe and obey all warning signs and signals.