Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-02-14 13:27:17

0001 #include "Fireworks/Core/src/fwPaletteExtra.h"
0002 
0003 #include "TROOT.h"
0004 #include "TColor.h"
0005 #include "TMath.h"
0006 
0007 namespace fireworks {
0008 
0009   //static unsigned int rSize = 17;
0010 
0011   struct PaletteExtraTopBottomIndices {
0012     float (*colVals)[3];
0013     bool whiteBg;
0014     FWColorManager::EPalette id;
0015     PaletteExtraTopBottomIndices(float (*iColors)[3], bool iIsWhiteBg, FWColorManager::EPalette iId)
0016         : colVals(iColors), whiteBg(iIsWhiteBg), id(iId){};
0017 
0018     void set(int i, Color_t cidx) {
0019       if (whiteBg) {
0020         //if (id == FWColorManager::kFall || id == FWColorManager::kArctic)
0021         const TColor* c = gROOT->GetColor(cidx);
0022         colVals[i][0] = c->GetRed();
0023         colVals[i][1] = c->GetGreen();
0024         colVals[i][2] = c->GetBlue();
0025         if (id != FWColorManager::kPurple)
0026           TColor::HLStoRGB(
0027               c->GetHue(), 1.2 * c->GetLight(), c->GetSaturation(), colVals[i][0], colVals[i][1], colVals[i][2]);
0028 
0029         /*
0030 
0031          cidx = TColor::GetColorBright(cidx);
0032         TColor* cb = gROOT->GetColor(cidx);
0033          colVals[i+rSize][0] = cb->GetRed();
0034          colVals[i+rSize][1] = cb->GetGreen();
0035          colVals[i+rSize][2] = cb->GetBlue();
0036          */
0037 
0038       } else {
0039         const TColor* c = gROOT->GetColor(cidx);
0040         colVals[i][0] = c->GetRed();
0041         colVals[i][1] = c->GetGreen();
0042         colVals[i][2] = c->GetBlue();
0043         /*
0044          cidx = TColor::GetColorDark(cidx);
0045  const TColor * cd = gROOT->GetColor(cidx);
0046          colVals[i+rSize][0] = cd->GetRed();
0047          colVals[i+rSize][1] = cd->GetGreen();
0048          colVals[i+rSize][2] = cd->GetBlue();
0049          */
0050       }
0051     }
0052 
0053     //______________________________________________________________________________
0054 
0055     void InitArctic() {
0056       // set muon geometry gray
0057       set(0, kYellow + 2);
0058       set(1, kMagenta - 3);
0059       set(2, kCyan + 3);
0060       set(3, kAzure + 7);
0061       set(4, kAzure + 8);
0062 
0063       set(5, kAzure + 3);  // jets, met
0064       set(6, kAzure - 3);
0065       set(7, kOrange + 7);
0066       set(8, kAzure);  // jets, met
0067       set(9, kBlue - 1);
0068       set(10, kBlue - 7);
0069       set(11, kTeal - 1);
0070       set(12, kTeal - 7);
0071       set(13, kCyan - 7);
0072       set(14, kAzure + 10);
0073       // set(16, kOrange);
0074     }
0075 
0076     //______________________________________________________________________________
0077 
0078     void InitFall() {
0079       set(0, kYellow - 4);  //vertices, jets
0080       set(1, kRed + 1);
0081       set(2, kMagenta + 3);
0082       set(3, kGreen + 2);
0083       set(4, kBlue + 2);
0084       set(5, kOrange - 5);  //hcal
0085       set(6, kOrange - 8);
0086       set(7, kMagenta - 1);
0087       set(8, kRed - 2);   // muon, ecal, met
0088       set(9, kCyan + 2);  // tracks
0089 
0090       int j = 2;
0091       for (int i = 10; i < 15; ++i) {
0092         set(i, kRed - j);
0093         j++;
0094       }
0095     }
0096 
0097     void InitSpring() {
0098       set(0, kRed);  // jet
0099       set(1, kOrange - 2);
0100       set(2, kRed - 7);
0101       set(3, kPink + 2);
0102       set(4, kOrange - 7);
0103       set(5, kSpring + 5);  //hcal
0104 
0105       set(6, kSpring);
0106       set(7, kMagenta);     // electrons
0107       set(8, kSpring + 4);  //ecal, muons
0108       set(9, kGreen + 2);
0109       set(10, kSpring + 3);
0110       set(11, kGreen - 5);
0111       set(12, kGreen - 6);
0112       set(13, kGreen - 7);
0113       set(14, kTeal - 5);
0114     }
0115 
0116     void InitPurple() {
0117       set(0, kGreen - 7);
0118       set(1, kRed + 1);
0119       set(2, kMagenta + 3);
0120       set(3, kCyan + 2);
0121       set(4, kBlue + 2);
0122       set(5, kViolet - 5);
0123       set(6, kViolet - 6);
0124       set(7, kViolet - 7);
0125       set(8, kGray + 1);  //ecal, muo
0126       set(9, kPink - 8);  //tracks
0127       set(10, kBlue - 8);
0128       set(11, kBlue - 4);
0129       set(12, kBlue - 2);
0130       set(13, kViolet + 8);
0131       set(14, kViolet + 10);
0132     }
0133   };
0134 
0135   void GetColorValuesForPaletteExtra(float (*iColors)[3],
0136                                      unsigned int iSize,
0137                                      FWColorManager::EPalette id,
0138                                      bool isWhiteBg) {
0139     PaletteExtraTopBottomIndices p(iColors, isWhiteBg, id);
0140     switch (id) {
0141       case FWColorManager::kArctic:
0142         p.InitArctic();
0143         break;
0144       case FWColorManager::kFall:
0145         p.InitFall();
0146         break;
0147       case FWColorManager::kSpring:
0148         p.InitSpring();
0149         break;
0150 
0151       case FWColorManager::kPurple:
0152         p.InitPurple();
0153         break;
0154       default:
0155         break;
0156     }
0157 
0158     iSize = iSize / 2;
0159     unsigned int lastIdx = iSize - 2;
0160     if (isWhiteBg) {
0161       for (unsigned int i = 0; i < lastIdx; ++i) {
0162         float s = 1.2;
0163         float r = TMath::Min(1.f, s * iColors[i][0]);
0164         float g = TMath::Min(1.f, s * iColors[i][1]);
0165         float b = TMath::Min(1.f, s * iColors[i][2]);
0166 
0167         iColors[i][0] = r;
0168         iColors[i][1] = g;
0169         iColors[i][2] = b;
0170 
0171         float value = 1.7;
0172         r = TMath::Power(r, (2.5 - value) / 2.5);
0173         g = TMath::Power(g, (2.5 - value) / 2.5);
0174         b = TMath::Power(b, (2.5 - value) / 2.5);
0175         /*
0176          s = 1.2;
0177          r = TMath::Min(1.f,s* iColors[i][0]);
0178          g = TMath::Min(1.f,s *iColors[i][1]);
0179          b = TMath::Min(1.f,s *iColors[i][2]);
0180          */
0181 
0182         r = TMath::Min(1.f, r);
0183         g = TMath::Min(1.f, g);
0184         b = TMath::Min(1.f, b);
0185 
0186         iColors[i + iSize][0] = r;
0187         iColors[i + iSize][1] = g;
0188         iColors[i + iSize][2] = b;
0189       }
0190     } else {
0191       for (unsigned int i = 0; i < lastIdx; ++i) {
0192         //   TColor* c = gROOT->GetColor(i);
0193         float s = 0.4;
0194         float r = s * iColors[i][0];
0195         float g = s * iColors[i][1];
0196         float b = s * iColors[i][2];
0197 
0198         // printf("[%d] (%.1f, %.1f, %.1f) => ", i,  r, g, b);
0199         float value = -0.5;
0200         r = TMath::Power(r, (2.5 - value) / 2.5);
0201         g = TMath::Power(g, (2.5 - value) / 2.5);
0202         b = TMath::Power(b, (2.5 - value) / 2.5);
0203 
0204         // printf(" (%.1f, %.1f, %.1f) \n", r, g, b);
0205         //TColor::HLStoRGB(c->GetHue(), c->GetSaturation(), c->GetLight()*0.8, r, g, b);
0206         iColors[i + iSize][0] = r;
0207         iColors[i + iSize][1] = g;
0208         iColors[i + iSize][2] = b;
0209       }
0210     }
0211   }
0212 
0213 }  // namespace fireworks