collecting block reward and transaction fees
Miners independently create coinbase transaction for block. To create coinbase transaction this transaction should be first in block and have only 1 coinbase input. Coinbase input means that outpoint transaction is 0000000000000000000000000000000000000000000000000000000000000000 and output index is FFFFFFFF. Inputs amount fro transaction calculated like block reward amount according to block height, plus all fee amounts for all other transactions inside block. Miner able to take this total amount on outputs. Miner specify own address and amount of block block reward plus fee reward. In case the miner incorrectly calculates amounts and specify greater than expected, block will be rejected by other nodes. In case miner specify lower block will be accepted, but miner lose money. 

Example in mainnet when miner lose all reward due to an error:

https://bitaps.com/410995608537d591d6ce5ff2a7966fa84f891c5e2269ef85e8ecdb68d5188f9b