BIG HUGS
I am so very sorry.
Please try to take consolation that the jerking and the coughing were signs of the very last stages of the dying process when the blood circulation breaks down (we call the jerking 'running to the Rainbow Bridge'). Thankfully, by then Caramel would no longer have been with it. The coughing can sometimes happen when the heart stops.
Unfortunately, when you have never been confronted with it, the natural dying process is much more physical than we imagine with our vague concept of gently drifting away in one's sleep behind closed doors. It can come as a horrible and somewhat traumatising shock.
Please rest assured that Caramel has had - as these things go - a rather smooth and short climb up the Rainbow Bridge; he has not suffered for long and by wrapping him in a towel and keeping him warm but not hot (the breakdown of circulation makes a dying piggy feel cold) and by staying with him, you have done all the right things, so you haven't failed him in any way. He has been able to leave from his familiar surroundings supported by your love.
Please be kind with yourself in the coming days as you grieve. Neither you or a vet could have stopped or prevented his body from closing down. Behind their huge personalities, guinea pigs are ultimately only small animals with a much faster metabolism that in the end will turn against them.
Here is some helpful information if this is your first loss as to what to expect and what you can do for yourself:
Human Bereavement: Grieving, Processing and Support Links for Guinea Pig Owners and Their Children
If Caramel has a mate:
Looking After a Bereaved Guinea Pig
We are here for you if you struggle or get hung up in one of the weird mind loops that can come with human grieving or have any questions about looking after a mate of Caramel's.