Raspberry Pi 4 Touch Monitor Rotate

Recently I had to develop an application (kiosk system) for/on a Raspberry Pi 4. The special thing about it was that 2 touch monitors were to be connected via HDMI, which had to be rotated 90 degrees to the right. So portrait formats, 2 monitors on top of each other.
Rotating the screen and arranging it on top of each other did not cause any problems, as this is easily possible via the user interface - a "Raspbian Buster with desktop and recommended software" was installed.
To do this, in the "Raspberry -> Preferences -> Screen Configuration" menu, turn the two HDMI monitors to the right, arrange them on top of each other and then save the settings.
The problem with this is that the touch configuration is not automatically rotated, arranged on top of each other and results in a large touch area over 2 monitors.
In order for the touch behavior to work properly, 2 configuration files - /usr/share/X11/xorg.conf.d/40-libinput.conf and /home/pi/.profile - need to be adjusted.

First you have to read out the IDs of the connected monitors. To do this, open a terminal and use the command

xinput list

input. As a result, you get the connected monitors listed with the corresponding IDs. In my case, the monitors had IDs 6 and 7.

Then in the file /usr/share/X11/xorg.conf.d/40-libinput.conf adjust the section "Section InputClass" with the "Identifier libinput touchpad catchall" as follows:

Section "InputClass" 
        Identifier "libinput touchpad catchall" 
        MatchIsTouchscreen "on" 
        Option "CalibrationMatrix" "0 1 0 -1 0 1 0 0 1" 
        MatchDevicePath "/dev/input/event*" 
        Driver "libinput" 
EndSection

This causes the touch surface to rotate.

Finally, insert the subdivision of the touch interface into 2 equal parts at the end of the file /home/pi/.profile, so that it is loaded every time the system is started.

xinput set-prop "6" --type=float "Coordinate Transformation Matrix" 1 0 0 0 0.5 0 0 0 1
xinput set-prop "7" --type=float "Coordinate Transformation Matrix" 1 0 0 0 0.5 0.5 0 0 1