Which or that?
Writing Hub for Innopolis UniversityTwo approaches exist here: an American one and a British one.
American way
Ask yourself if you can lose the clause without losing the original message.
You can't?
Awesome, use that and no comma.

You can?
Great, then use which and a comma.

Remember to never use that for people. Use who instead.
British way
Ask yourself if you can lose the clause without losing the original message.
You can't?
Outstanding, use either which or that. No comma.

You can use that both for people and for things. Avoid that in formal writing.
You can?
Terrific, use which and a comma, the same as in the American way.
References
Allen, S. (n.d.). Which vs. That: How to Choose. Retrieved from https://www.grammarly.com/blog/which-vs-that/
Hewings, M. (2013). Advanced Grammar in Use. 3rd edition. Cambridge, UK: Cambridge University Press.
Murphy, R. (2005). English Grammar in Use. 3rd edition. Cambridge, UK: Cambridge University Press.
The Institute of Electrical and Electronics Engineers (IEEE). (2020). IEEE Editorial Style Manual for Authors. Retrieved from http://journals.ieeeauthorcenter.ieee.org/wp-content/uploads/sites/7/IEEE-Editorial-Style-Manual_081920.pdf