IT IS not often the heads of government and the courts come together in the same room in Scotland. The separation of political and judicial power, one of the mainstays of the nation's democracy, means the first minister and lord president are rarely in each other's company However, in the coming weeks, Alex Salmond will be legally obliged to confer with Lord Hamilton on the selection of three new judges.

Together, they will pore over a list sent to Salmond on Tuesday by the Judicial Appointments Board, recommending who should be awarded the scarlet robe, known colloquially at court as the "red jersey". Their decision will then be forwarded to the Queen for final approval.

The rarity of the encounter emphasises its importance, as judges are at the heart of Scotland's establishment. Their decisions not only reflect the civil and criminal law, they also contribute to it, establishing precedents that affect the lives of thousands.

In 2001, Lord Abernethy's acquittal of a student accused of rape because there was no evidence of force, despite the woman repeatedly saying no, threw the country's rape laws into chaos. Although a later review rejected this interpretation, it is only now that legislation is passing through Holyrood to reform Scotland's antiquated sexual offence laws.

***Yet in spite of their power, precious little is known of the men and women in wigs who earn some of the largest salaries in the public sector. On the eve of a momentous decision for Salmond and Scotland's legal system, a Sunday Herald investigation of the 35 judges in post on January 1 this year reveals the country's bench to be deeply unrepresentative of Scotland in terms of race, gender, and class.

While appointments must be made on merit - no-one would argue for incompetent judges - the investigation shows how the Scottish bench invites a perception that is a self-perpetuating and well-guarded clique likely to deter applicants with the "wrong" background.

Earlier this year, amid much media approval, three female Scottish judges made history by sitting together on the same civil case. What was less well publicised by the Scottish Court Service was that the trio constituted almost the entire female judiciary of the nation.

Only four women - Ladies Paton, Dorrian, Smith and Clark - wear the scarlet robe, compared with 31 men at the start of the year, a paltry 11%.

Other areas of public life, such as politics and less elite parts of the law, have managed to address equally striking gender inequality, but never the Scottish bench.

According to Sex And Power, an index produced by the Equality and Human Rights Commission, female appointments to the bench lag significantly behind other areas of public life. Women filled 32% of all public appointments in 2007-2008, covering 26% of all head-teacher posts in secondary schools and 21% of university principals. A third of MSPs are women.

In the law in Scotland, there has been progress in terms of women taking up the profession. Half of this autumn's trainee advocates are women, compared with one in 20 in the 1990s, but on present form, there is little prospect of this being mirrored on the bench. In the past six years, only two of the 14 judges appointed have been female.

The legal establishment's record in appointing ethnic minority judges is also poor, as not a single member of the bench is black or Asian, and two Jewish judges, Lord Caplan and Lady Cosgrove, have now retired.

"We need to work towards a truly representative judiciary," said a spokesperson for the Equality and Human Rights Commission. "How many disabled people, people from the LGBT lesbian, gay, bisexual, and transgender community or from different race or faith groups sit on the bench? What are the barriers that prevent these groups from progressing in our legal system? Our judiciary needs to become more reflective of Scottish society."

***The living arrangements of the 35 judges also point to a caste far removed from those appearing before them in the dock. Although the court of session, which hears civil and appeal cases, is in the capital, the high court, which hears the most serious criminal trials, moves around the country.

Yet public records show that 89% of the "senators of the College of Justice" live in the Lothians, 83% in the capital itself, and 71% in just four plush Edinburgh postcodes. Twelve judges, or 34%, live in the New Town area, and five in the Grange. Another five, or 14%, have an EH4 1 code, which covers the most affluent parts of Edinburgh's west end, while 8% stay in Trinity. Not a single judge lives in Glasgow, Dundee, Aberdeen or any other Scottish city.

The most recent Scottish Index of Multiple Deprivation, which two years ago divided the country into 6505 small neighbourhoods and ranked them according to poverty and affluence, confirms the extent to which the country's judges and their families are physically cut off from most of Scotland.

The second-least deprived neighbourhood in Scotland - area 6504 on the index - consists of a handful of streets and just under 800 people, but they include no less than five judges: Lords Carloway, Kingarth, Turnbull, Uist and Nimmo Smith all live within a few yards of each other in the west end of Edinburgh, near the Dean Bridge Two judges live three doors apart on Ann Street, regarded as the city's most desirable address. The average house price in area 6504 last year was £488,143 - more than three times the national average. The pattern is repeated across the judiciary.

The most affluent 1% of Scotland on the index is home to 13 judges, or 37% of the total. The richest 5% is home to 20 judges, or 57% of the bench. By contrast, the poorest 5% of Scotland's council wards produce 25% of the prison population.

***Wealth, of course, is a factor. On the lowest rung of the judicial pay ladder, remuneration for the 21 senators of the College of Justice currently sitting in the court of session's Outer House is £170,200. Above them, the 11 judges of the Inner House, who hear appeals, each earn £193,800.

The country's most senior judge, the lord president, earns £211,000, while his deputy, the lord justice clerk, earns £203,800. Lord McGhie, chair of the Scottish Land Court, who makes up the 35th member of Scotland's judiciary, is a relative pauper on £136,500. All told, the combined bill for judges' salaries this year will exceed £6 million.

A survey of the senators' schooling suggests judges have a similar upbringing, as well as similar tastes in property later in life. While only 4.5% of children in Scotland attend private schools, 71% of judges were educated in the independent sector. A third attended either George Watson's College, Edinburgh Academy or Glenalmond in Perthshire.

Sometimes the clubbishness is quite literal. Membership of the exclusive New Club, a lynchpin of the Edinburgh establishment, appears de rigeur amongst senators, with 43% of judges listed as members in Who's Who.

The patterns becomes even more vivid at the highest levels of the judiciary.

While four members of the 35-strong bench are female, only one woman currently sits in the Inner House, equivalent to 9% of the total. Similarly, while 71% of all judges live in just four Edinburgh postcode sectors, such as EH3 6 and EH4 1, the percentage jumps to 90% for the Inner House. Attendance at independent schools also increases for Inner House judges, from 71% to 82%.

The creation in 2002 of the JAB, which advises ministers on the selection of judges, appears to have made little progress in modernising the bench. Set up to make the appointments system more transparent, the board's recommendations have helped appoint 14 judges. Of these fourteen, two (15%) are women - a slight improvement on the overall figure of 11% - while four (29%) attended state schools, the same figures for judges overall.

Both the board and the wider legal profession acknowledge that a problem exists. Neil Stevenson, head of diversity at the Law Society of Scotland, said: "It is vital that membership of the judiciary is diverse and reflects modern Scotland and that the system of appointing judges is open and transparent.

"The society is working with the JAB and others to examine the barriers that might exist - or that people perceive exist - about becoming a judge or sheriff. We want to ensure that Scottish solicitors are supported and encouraged to apply to become a judge, if that is their career choice."

It is against this backdrop that the three vacancies to the bench have taken on an added significance. Two of the vacancies are the result of recent deaths - Lord Macfadyen and Lord Johnston - while the third has arisen through the forthcoming retiral of Lord McEwan. Applications for a red jersey are supposed to be secret, but in the gossipy world of the Scottish legal system, a handful of favourites have already emerged.

These include Gordon Jackson, the former Labour MSP for Glasgow Govan, and the QCs Valerie Stacey and Paul Cullen. As Glasgow residents, Jackson and Stacey buck the trend for living in the capital - although both have houses in the exclusive Pollokshields area.

Cullen, a member of the New Club, lives in Edinburgh's Morningside. Another name being mentioned is sheriff Ian Peebles.

There is a growing consensus that increasing diversity on the bench is a worthwhile goal, although not everybody signs up to this ambition. Lord McCluskey, a retired judge, said he was sceptical of the arguments for diversity. "It isn't just a case of saying we should appoint three women to the bench," he said. "If I am going to be in hospital for an operation on my brain, I don't want the surgeon to be picked by reason of diversity. I don't want a one-eyed woman from Jamaica. Merit is the only consideration."