File indexing completed on 2024-10-25 05:06:16
0001 #include "CommonTools/TrackerMap/interface/TrackerMap.h"
0002 #include "CommonTools/TrackerMap/interface/TmModule.h"
0003 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0004 #include "FWCore/ParameterSet/interface/FileInPath.h"
0005 #include "CondFormats/SiStripObjects/interface/FedChannelConnection.h"
0006 #include "CalibFormats/SiStripObjects/interface/SiStripFecCabling.h"
0007 #include "CalibFormats/SiStripObjects/interface/SiStripDetCabling.h"
0008 #include "DataFormats/TrackerCommon/interface/TrackerTopology.h"
0009 #include "CommonTools/TrackerMap/interface/TmApvPair.h"
0010 #include "CommonTools/TrackerMap/interface/TmCcu.h"
0011 #include "CommonTools/TrackerMap/interface/TmPsu.h"
0012 #include <fstream>
0013 #include <vector>
0014 #include <iostream>
0015 #include <sstream>
0016 #include "TCanvas.h"
0017 #include "TPolyLine.h"
0018 #include "TStyle.h"
0019 #include "TColor.h"
0020 #include "TROOT.h"
0021 #include "TGaxis.h"
0022 #include "TLatex.h"
0023 #include "TArrow.h"
0024 #include "TLegend.h"
0025 #include "TH1F.h"
0026 #include "TH2Poly.h"
0027 #include "TGraph.h"
0028 #include "TPaletteAxis.h"
0029
0030
0031
0032
0033
0034
0035
0036 TrackerMap::TrackerMap(const edm::ParameterSet &tkmapPset,
0037 const SiStripFedCabling *tkFed,
0038 const TrackerTopology *const topology) {
0039 psetAvailable = true;
0040 xsize = 340;
0041 ysize = 200;
0042
0043 title = " ";
0044 jsPath = "";
0045 jsfilename = "CommonTools/TrackerMap/data/trackermap.txt";
0046 infilename = "CommonTools/TrackerMap/data/tracker.dat";
0047 saveAsSingleLayer = false;
0048 tkMapLog = false;
0049
0050 jsPath = tkmapPset.getUntrackedParameter<std::string>("trackermaptxtPath", "CommonTools/TrackerMap/data/");
0051 jsfilename = jsPath + "trackermap.txt";
0052 std::cout << jsfilename << std::endl;
0053 infilename =
0054 tkmapPset.getUntrackedParameter<std::string>("trackerdatPath", "CommonTools/TrackerMap/data/") + "tracker.dat";
0055 std::cout << infilename << std::endl;
0056 saveWebInterface = tkmapPset.getUntrackedParameter<bool>("saveWebInterface", false);
0057 saveGeoTrackerMap = tkmapPset.getUntrackedParameter<bool>("saveGeoTrackerMap", true);
0058 ncrates = 0;
0059 firstcrate = 0;
0060 enableFedProcessing = tkmapPset.getUntrackedParameter<bool>("loadFedCabling", false);
0061 if (tkFed == nullptr && enableFedProcessing) {
0062 enableFedProcessing = false;
0063 std::cout << "ERROR:fed trackermap requested but no valid fedCabling is available!!!" << std::endl;
0064 }
0065 nfeccrates = 0;
0066 enableFecProcessing = tkmapPset.getUntrackedParameter<bool>("loadFecCabling", false);
0067 if (tkFed == nullptr && enableFecProcessing) {
0068 enableFecProcessing = false;
0069 std::cout << "ERROR:fec trackermap requested but no valid fedCabling is available!!!" << std::endl;
0070 }
0071
0072 npsuracks = 0;
0073 enableLVProcessing = tkmapPset.getUntrackedParameter<bool>("loadLVCabling", false);
0074
0075 enableHVProcessing = tkmapPset.getUntrackedParameter<bool>("loadHVCabling", false);
0076
0077 tkMapLog = tkmapPset.getUntrackedParameter<bool>("logScale", false);
0078
0079
0080 init();
0081
0082 if (enableFedProcessing) {
0083 auto feds = tkFed->fedIds();
0084 std::cout << "SiStripFedCabling has " << feds.size() << " active FEDS" << std::endl;
0085
0086
0087 for (std::vector<unsigned short>::const_iterator ifed = feds.begin(); ifed < feds.end(); ifed++) {
0088 auto theconn = tkFed->fedConnections(*ifed);
0089 int num_conn = 0;
0090 for (auto iconn = theconn.begin(); iconn < theconn.end(); iconn++) {
0091 if (iconn->fedId() == sistrip::invalid_ || iconn->detId() == sistrip::invalid_ ||
0092 iconn->detId() == sistrip::invalid32_ || iconn->apvPairNumber() == sistrip::invalid_ ||
0093 iconn->nApvPairs() == sistrip::invalid_) {
0094 continue;
0095 }
0096
0097 TmModule *imod = imoduleMap[iconn->detId()];
0098 int key = iconn->fedId() * 1000 + iconn->fedCh();
0099 TmApvPair *apvpair = apvMap[key];
0100 if (apvpair != nullptr)
0101 std::cout << "Fed " << iconn->fedId() << " channel " << iconn->fedCh() << " seem to be already loaded!"
0102 << std::endl;
0103 else {
0104 num_conn++;
0105 if (num_conn == 1) {
0106
0107 if (fedMap[iconn->fedId()] == 0) {
0108 fedMap[iconn->fedId()] = iconn->fedCrate();
0109 }
0110 if (slotMap[iconn->fedId()] == 0) {
0111 slotMap[iconn->fedId()] = iconn->fedSlot();
0112 }
0113 if (ncrates == 0 || ncrates < iconn->fedCrate())
0114 ncrates = iconn->fedCrate();
0115 if (firstcrate == 0 || firstcrate > iconn->fedCrate())
0116 firstcrate = iconn->fedCrate();
0117 }
0118
0119
0120 apvpair = new TmApvPair(key, iconn->fedCrate());
0121 apvpair->mod = imod;
0122 apvpair->mpos = iconn->apvPairNumber();
0123 apvMap[key] = apvpair;
0124 apvModuleMap.insert(std::make_pair(iconn->detId(), apvpair));
0125 std::stringstream s;
0126 iconn->print(s);
0127 apvpair->text = s.str();
0128 }
0129 }
0130 }
0131
0132 std::cout << "from " << firstcrate << " to " << ncrates << " crates used " << std::endl;
0133
0134 std::map<int, TmModule *>::iterator i_mod;
0135 for (i_mod = imoduleMap.begin(); i_mod != imoduleMap.end(); i_mod++) {
0136 TmModule *mod = i_mod->second;
0137 if (mod != nullptr) {
0138 std::ostringstream outs, outs1;
0139 outs << " connected to ";
0140 outs1 << "(";
0141
0142 int idmod = mod->idex;
0143 int nchan = 0;
0144 std::multimap<const int, TmApvPair *>::iterator pos;
0145 for (pos = apvModuleMap.lower_bound(idmod); pos != apvModuleMap.upper_bound(idmod); ++pos) {
0146 TmApvPair *apvpair = pos->second;
0147 if (apvpair != nullptr) {
0148 outs << apvpair->mpos << " " << apvpair->getFedId() << "/" << apvpair->getFedCh() << " ";
0149 outs1 << apvpair->idex + apvpair->crate * 1000000 << ",";
0150 nchan++;
0151 }
0152 }
0153 outs << "(" << nchan << ")";
0154 mod->name = mod->name + outs.str();
0155 std::string s = outs1.str();
0156 s.erase(s.end() - 1, s.end());
0157 mod->capvids = s + ")";
0158 }
0159 }
0160 }
0161
0162 if (enableFecProcessing) {
0163 int nccu;
0164 int nmod;
0165 int crate, slot, ring, addr, pos;
0166 SiStripFecCabling *fecCabling_;
0167 fecCabling_ = new SiStripFecCabling(*tkFed);
0168 std::string Ccufilename = tkmapPset.getUntrackedParameter<std::string>("trackerdatPath", "") + "cculist.txt";
0169 std::ifstream Ccufile(edm::FileInPath(Ccufilename).fullPath().c_str(), std::ios::in);
0170 std::string dummys;
0171 while (!Ccufile.eof()) {
0172 Ccufile >> crate >> slot >> ring >> addr >> pos;
0173 getline(Ccufile, dummys);
0174 int key = crate * 10000000 + slot * 100000 + ring * 1000 + addr;
0175 TmCcu *ccu = ccuMap[key];
0176 if (ccu == nullptr) {
0177 ccu = new TmCcu(crate, slot, ring, addr);
0178 ccu->mpos = pos, ccuMap[key] = ccu;
0179 }
0180 }
0181
0182 for (std::vector<SiStripFecCrate>::const_iterator icrate = fecCabling_->crates().begin();
0183 icrate != fecCabling_->crates().end();
0184 icrate++) {
0185 for (std::vector<SiStripFec>::const_iterator ifec = icrate->fecs().begin(); ifec != icrate->fecs().end();
0186 ifec++) {
0187 for (std::vector<SiStripRing>::const_iterator iring = ifec->rings().begin(); iring != ifec->rings().end();
0188 iring++) {
0189 nccu = 0;
0190 for (std::vector<SiStripCcu>::const_iterator iccu = iring->ccus().begin(); iccu != iring->ccus().end();
0191 iccu++) {
0192 nccu++;
0193 nmod = 0;
0194 int key =
0195 icrate->fecCrate() * 10000000 + ifec->fecSlot() * 100000 + iring->fecRing() * 1000 + iccu->ccuAddr();
0196 int layer = 0;
0197 TmCcu *ccu = ccuMap[key];
0198 for (std::vector<SiStripModule>::const_iterator imod = iccu->modules().begin();
0199 imod != iccu->modules().end();
0200 imod++) {
0201 nmod++;
0202 TmModule *imod1 = imoduleMap[imod->detId()];
0203 layer = imod1->layer;
0204 fecModuleMap.insert(std::make_pair(ccu, imod1));
0205 if (imod1 != nullptr)
0206 imod1->CcuId = key;
0207 }
0208 if (ccu == nullptr)
0209 std::cout << key << " This ccu seems to have not been stored! " << std::endl;
0210 else {
0211 ccu->nmod = nmod;
0212 ccu->layer = layer;
0213 }
0214 }
0215 }
0216 }
0217 }
0218
0219 std::map<int, TmCcu *>::iterator i_ccu;
0220 std::multimap<TmCcu *, TmModule *>::iterator it;
0221 std::pair<std::multimap<TmCcu *, TmModule *>::iterator, std::multimap<TmCcu *, TmModule *>::iterator> ret;
0222 nccu = 0;
0223 for (i_ccu = ccuMap.begin(); i_ccu != ccuMap.end(); i_ccu++) {
0224 TmCcu *ccu = i_ccu->second;
0225 nccu++;
0226 if (ccu != nullptr) {
0227 std::ostringstream outs;
0228 std::ostringstream outs1;
0229 outs << "CCU " << ccu->idex << " connected to fec,ring " << ccu->getCcuSlot() << "," << ccu->getCcuRing()
0230 << " in crate " << ccu->getCcuCrate() << " at position " << ccu->mpos << " with " << ccu->nmod
0231 << " modules: ";
0232 outs1 << "(";
0233 ret = fecModuleMap.equal_range(ccu);
0234 for (it = ret.first; it != ret.second; ++it) {
0235 outs << (*it).second->idex << " ";
0236 outs1 << (*it).second->getKey() << ",";
0237 }
0238 outs1 << ")";
0239 ccu->text = outs.str();
0240 ccu->cmodid = outs1.str();
0241
0242 }
0243 }
0244 nfeccrates = 4;
0245 std::cout << nccu << " ccu stored in " << nfeccrates << " crates" << std::endl;
0246
0247 delete fecCabling_;
0248 }
0249
0250
0251 if (enableLVProcessing || enableHVProcessing) {
0252 SiStripDetCabling *detCabling = nullptr;
0253 if (enableFedProcessing)
0254 detCabling = new SiStripDetCabling(*tkFed, topology);
0255
0256 int npsu = 0;
0257 int nmod, nmodHV2, nmodHV3;
0258 int modId1, dcuId;
0259 int dcs, branch, crate, board;
0260 int rack = 0;
0261 std::string channelstr1;
0262 short int channel;
0263 std::string psinfo;
0264 std::string psIdinfo;
0265 int rack_order[54] = {0, 1, 0, 2, 0, 3, 0, 4, 0, 5, 6, 0, 7, 8, 0, 9, 10, 0,
0266 11, 12, 0, 13, 14, 0, 15, 0, 0, 0, 0, 0, 0, 16, 0, 17, 18, 0,
0267 19, 20, 0, 21, 0, 22, 0, 23, 0, 24, 25, 0, 26, 27, 0, 28, 0, 29};
0268
0269
0270
0271 std::string LVfilename =
0272 tkmapPset.getUntrackedParameter<std::string>("trackerdatPath", "CommonTools/TrackerMap/data/") + "psdcumap.dat";
0273
0274
0275 std::ifstream LVfile(edm::FileInPath(LVfilename).fullPath().c_str(), std::ios::in);
0276
0277 std::cout << LVfilename << std::endl;
0278
0279
0280
0281
0282
0283
0284
0285
0286
0287
0288
0289
0290
0291
0292
0293
0294
0295 while (!LVfile.eof()) {
0296 LVfile >> modId1 >> dcuId >> psIdinfo >> psinfo;
0297
0298 if (detCabling && detCabling->getConnections(modId1).empty())
0299 continue;
0300
0301
0302 std::string dcsinfo = psinfo.substr(39, 1);
0303 std::string branchinfo = psinfo.substr(57, 2);
0304 std::string crateinfo = psinfo.substr(69, 1);
0305 std::string boardinfo = psinfo.substr(80, 2);
0306 std::string channelinfo = psinfo.substr(90, 3);
0307
0308 dcs = atoi(dcsinfo.c_str());
0309 branch = atoi(branchinfo.c_str());
0310 crate = atoi(crateinfo.c_str()) + 1;
0311 board = atoi(boardinfo.c_str()) + 1;
0312 rack = (branch + 1) + (dcs - 1) * 6;
0313 rack = rack_order[rack];
0314 channel = atoi(channelinfo.c_str());
0315
0316 int key = rack * 1000 + crate * 100 + board;
0317
0318 TmPsu *psu = psuMap[key];
0319 TmModule *imod = imoduleMap[modId1];
0320 if (psu == nullptr) {
0321 psu = new TmPsu(dcs, branch, rack, crate, board);
0322 psuMap[key] = psu;
0323 psu->psId = psIdinfo;
0324 }
0325
0326 psuModuleMap.insert(std::make_pair(psu, imod));
0327 if (imod != nullptr) {
0328 imod->PsuId = psIdinfo;
0329 imod->psuIdex = psu->idex;
0330 imod->HVchannel = channel;
0331 }
0332 }
0333
0334
0335 std::map<int, TmPsu *>::iterator ipsu;
0336 std::multimap<TmPsu *, TmModule *>::iterator it;
0337 std::pair<std::multimap<TmPsu *, TmModule *>::iterator, std::multimap<TmPsu *, TmModule *>::iterator> ret;
0338 npsu = 0;
0339
0340 for (ipsu = psuMap.begin(); ipsu != psuMap.end(); ipsu++) {
0341 TmPsu *psu = ipsu->second;
0342 npsu++;
0343
0344 if (psu != nullptr) {
0345 std::ostringstream outs;
0346 std::ostringstream outs1;
0347
0348 std::ostringstream outs3;
0349 std::ostringstream outs4;
0350
0351 std::ostringstream outs5;
0352 std::ostringstream outs6;
0353
0354 outs << "PSU " << psu->psId << " connected to Mainframe " << psu->getPsuDcs() << " BranchController "
0355 << psu->getPsuBranch() << " (Rack " << psu->getPsuRack() << "), crate " << psu->getPsuCrate()
0356 << " in position " << psu->getPsuBoard() << " with modules: ";
0357 outs1 << "(";
0358
0359 if (enableHVProcessing) {
0360 outs3 << "PSU " << psu->psId << " connected to Mainframe " << psu->getPsuDcs() << " BranchController "
0361 << psu->getPsuBranch() << " (Rack " << psu->getPsuRack() << "),crate " << psu->getPsuCrate()
0362 << " in position " << psu->getPsuBoard() << " and HV channel 002 with modules: ";
0363 outs4 << "(";
0364
0365 outs5 << "PSU " << psu->psId << " connected to Mainframe " << psu->getPsuDcs() << " BranchController "
0366 << psu->getPsuBranch() << " (Rack " << psu->getPsuRack() << "), crate " << psu->getPsuCrate()
0367 << " in position " << psu->getPsuBoard() << " and HV channel 002 with modules: ";
0368 outs6 << "(";
0369 }
0370
0371 ret = psuModuleMap.equal_range(psu);
0372 nmod = 0;
0373 nmodHV2 = 0;
0374 nmodHV3 = 0;
0375 for (it = ret.first; it != ret.second; ++it) {
0376 nmod++;
0377 outs << (*it).second->idex << ", ";
0378 outs1 << (*it).second->getKey() << ",";
0379
0380 if (enableHVProcessing) {
0381 if ((*it).second->HVchannel == 2) {
0382 nmodHV2++;
0383 outs3 << (*it).second->idex << ", ";
0384 outs4 << (*it).second->getKey() << ",";
0385 } else if ((*it).second->HVchannel == 3) {
0386 nmodHV3++;
0387 outs5 << (*it).second->idex << ", ";
0388 outs6 << (*it).second->getKey() << ",";
0389 }
0390 }
0391 }
0392
0393 outs1 << ")";
0394 psu->nmod = nmod;
0395 outs << "(" << psu->nmod << ")";
0396 psu->text = outs.str();
0397 psu->cmodid_LV = outs1.str();
0398 if (enableHVProcessing) {
0399 outs4 << ")";
0400 outs6 << ")";
0401 psu->nmodHV2 = nmodHV2;
0402 psu->nmodHV3 = nmodHV3;
0403 outs3 << "(" << psu->nmodHV2 << ")";
0404 outs5 << "(" << psu->nmodHV3 << ")";
0405 psu->textHV2 = outs3.str();
0406 psu->textHV3 = outs5.str();
0407 psu->cmodid_HV2 = outs4.str();
0408 psu->cmodid_HV3 = outs6.str();
0409 }
0410 }
0411 }
0412
0413 npsuracks = 29;
0414 std::cout << npsu << " psu stored in " << npsuracks << " racks" << std::endl;
0415 }
0416 }
0417
0418 TrackerMap::TrackerMap(const edm::ParameterSet &tkmapPset) {
0419 psetAvailable = true;
0420 xsize = 340;
0421 ysize = 200;
0422 title = " ";
0423 jsfilename = "CommonTools/TrackerMap/data/trackermap.txt";
0424 infilename = "CommonTools/TrackerMap/data/tracker.dat";
0425 enableFedProcessing = true;
0426 ncrates = 0;
0427 firstcrate = 0;
0428 saveAsSingleLayer = false;
0429 tkMapLog = tkmapPset.getUntrackedParameter<bool>("logScale", false);
0430 saveWebInterface = tkmapPset.getUntrackedParameter<bool>("saveWebInterface", false);
0431 saveGeoTrackerMap = tkmapPset.getUntrackedParameter<bool>("saveGeoTrackerMap", true);
0432
0433 jsfilename = tkmapPset.getUntrackedParameter<std::string>("trackermaptxtPath", "CommonTools/TrackerMap/data/") +
0434 "trackermap.txt";
0435 std::cout << jsfilename << std::endl;
0436 infilename =
0437 tkmapPset.getUntrackedParameter<std::string>("trackerdatPath", "CommonTools/TrackerMap/data/") + "tracker.dat";
0438 std::cout << infilename << std::endl;
0439
0440 init();
0441 }
0442
0443 TrackerMap::TrackerMap(std::string s, int xsize1, int ysize1) {
0444 psetAvailable = false;
0445 xsize = xsize1;
0446 ysize = ysize1;
0447 title = s;
0448 jsfilename = "CommonTools/TrackerMap/data/trackermap.txt";
0449 infilename = "CommonTools/TrackerMap/data/tracker.dat";
0450 saveWebInterface = false;
0451 saveGeoTrackerMap = true;
0452 tkMapLog = false;
0453 jsPath = "CommonTools/TrackerMap/data/";
0454 enableFedProcessing = false;
0455 enableFecProcessing = false;
0456 enableLVProcessing = false;
0457 enableHVProcessing = false;
0458 saveAsSingleLayer = false;
0459 init();
0460 }
0461
0462 void TrackerMap::reset() {
0463 std::map<int, TmModule *>::iterator i_mod;
0464 for (i_mod = imoduleMap.begin(); i_mod != imoduleMap.end(); i_mod++) {
0465 TmModule *mod = i_mod->second;
0466 mod->count = 0;
0467 mod->value = 0;
0468 mod->red = -1;
0469 }
0470 }
0471
0472 void TrackerMap::init() {
0473 ix = 0;
0474 iy = 0;
0475 firstcall = true;
0476 minvalue = 0.;
0477 maxvalue = minvalue;
0478 posrel = true;
0479 palette = 1;
0480 printflag = true;
0481 addPixelFlag = false;
0482 onlyPixelFlag = false;
0483 temporary_file = false;
0484 gminvalue = 0.;
0485 gmaxvalue = 0.;
0486
0487 int constexpr ndet = 3;
0488 int constexpr npart = 3;
0489
0490
0491 for (int subdet = 1; subdet < ndet + 1; subdet++) {
0492 for (int detpart = 1; detpart < npart + 1; detpart++) {
0493 int nlayers = getlayerCount(subdet, detpart);
0494 for (int layer = 1; layer < nlayers + 1; layer++) {
0495 int nrings = getringCount(subdet, detpart, layer);
0496
0497 int layer_g = nlayer(subdet, detpart, layer);
0498 ntotRing[layer_g - 1] = nrings;
0499 firstRing[layer_g - 1] = 1;
0500 if (subdet == 3 && detpart != 2)
0501 firstRing[layer_g - 1] = 8 - nrings;
0502 for (int ring = firstRing[layer_g - 1]; ring < ntotRing[layer_g - 1] + firstRing[layer_g - 1];
0503 ring++) {
0504 int nmodules = getmoduleCount(subdet, detpart, layer, ring);
0505 int key = 0;
0506 TmModule *smodule;
0507 for (int module = 1; module < nmodules + 1; module++) {
0508 smodule = new TmModule(module, ring, layer_g);
0509 key = layer_g * 100000 + ring * 1000 + module;
0510 smoduleMap[key] = smodule;
0511 }
0512 if (isRingStereo(key))
0513 for (int module = 1; module < nmodules + 1; module++) {
0514 smodule = new TmModule(module + 100, ring, layer_g);
0515 int key = layer_g * 100000 + ring * 1000 + module + 100;
0516 smoduleMap[key] = smodule;
0517 }
0518 }
0519 }
0520 }
0521 }
0522 build();
0523 }
0524
0525 TrackerMap::~TrackerMap() {
0526 for (int layer = 1; layer < 44; layer++) {
0527 for (int ring = firstRing[layer - 1]; ring < ntotRing[layer - 1] + firstRing[layer - 1]; ring++) {
0528 for (int module = 1; module < 200; module++) {
0529 int key = layer * 100000 + ring * 1000 + module;
0530 TmModule *mod = smoduleMap[key];
0531 if (mod != nullptr)
0532 delete mod;
0533 }
0534 }
0535 }
0536
0537
0538
0539
0540
0541
0542 std::map<int, TmApvPair *>::iterator i_apv;
0543 for (i_apv = apvMap.begin(); i_apv != apvMap.end(); i_apv++) {
0544 TmApvPair *apvPair = i_apv->second;
0545 delete apvPair;
0546 }
0547
0548 std::map<int, TmCcu *>::iterator i_ccu;
0549 for (i_ccu = ccuMap.begin(); i_ccu != ccuMap.end(); i_ccu++) {
0550 TmCcu *ccu = i_ccu->second;
0551 delete ccu;
0552 }
0553
0554 std::map<int, TmPsu *>::iterator ipsu;
0555 for (ipsu = psuMap.begin(); ipsu != psuMap.end(); ipsu++) {
0556 TmPsu *psu = ipsu->second;
0557 delete psu;
0558 }
0559 }
0560
0561 void TrackerMap::drawModule(TmModule *mod, int key, int mlay, bool print_total, std::ofstream *svgfile) {
0562
0563 nlay = mlay;
0564 double phi, r, dx, dy, dy1;
0565 double xp[4], yp[4], xp1, yp1;
0566 double vhbot, vhtop, vhapo;
0567 double rmedio[] = {0.041, 0.0701, 0.0988, 0.255, 0.340, 0.430, 0.520, 0.610, 0.696, 0.782, 0.868, 0.965, 1.080};
0568 double xt1, yt1, xs1 = 0., ys1 = 0., xt2, yt2, xs2, ys2, pv1, pv2;
0569 int green = 0;
0570 int red = 0;
0571 int blue = 0;
0572 double xd[4], yd[4];
0573 int np = 4;
0574
0575 int numod = 0;
0576 phi = phival(mod->posx, mod->posy);
0577 r = sqrt(mod->posx * mod->posx + mod->posy * mod->posy);
0578 vhtop = mod->width;
0579 vhapo = mod->length;
0580 if (mlay < 31) {
0581 vhbot = mod->widthAtHalfLength / 2. - (mod->width / 2. - mod->widthAtHalfLength / 2.);
0582 vhtop = mod->width / 2.;
0583 vhapo = mod->length / 2.;
0584 if (mlay > 12 && mlay < 19) {
0585 if (posrel)
0586 r = r + r;
0587 xp[0] = r - vhtop;
0588 yp[0] = -vhapo;
0589 xp[1] = r + vhtop;
0590 yp[1] = -vhapo;
0591 xp[2] = r + vhtop;
0592 yp[2] = vhapo;
0593 xp[3] = r - vhtop;
0594 yp[3] = vhapo;
0595 } else {
0596 if (posrel)
0597 r = r + r / 3.;
0598 xp[0] = r - vhapo;
0599 yp[0] = -vhbot;
0600 xp[1] = r + vhapo;
0601 yp[1] = -vhtop;
0602 xp[2] = r + vhapo;
0603 yp[2] = vhtop;
0604 xp[3] = r - vhapo;
0605 yp[3] = vhbot;
0606 }
0607 for (int j = 0; j < 4; j++) {
0608 xp1 = xp[j] * cos(phi) - yp[j] * sin(phi);
0609 yp1 = xp[j] * sin(phi) + yp[j] * cos(phi);
0610 xp[j] = xp1;
0611 yp[j] = yp1;
0612 }
0613 } else {
0614 numod = mod->idModule;
0615 if (numod > 100)
0616 numod = numod - 100;
0617 int vane = mod->ring;
0618 if (posrel) {
0619 dx = vhapo;
0620 phi = M_PI;
0621 xt1 = rmedio[mlay - 31];
0622 yt1 = -vhtop / 2.;
0623 xs1 = xt1 * cos(phi) - yt1 * sin(phi);
0624 ys1 = xt1 * sin(phi) + yt1 * cos(phi);
0625 xt2 = rmedio[mlay - 31];
0626 yt2 = vhtop / 2.;
0627 xs2 = xt2 * cos(phi) - yt2 * sin(phi);
0628 ys2 = xt2 * sin(phi) + yt2 * cos(phi);
0629 dy = phival(xs2, ys2) - phival(xs1, ys1);
0630 dy1 = dy;
0631 if (mlay == 31)
0632 dy1 = 0.39;
0633 if (mlay == 32)
0634 dy1 = 0.23;
0635 if (mlay == 33)
0636 dy1 = 0.16;
0637 xp[0] = vane * (dx + dx / 8.);
0638 yp[0] = numod * (dy1);
0639 xp[1] = vane * (dx + dx / 8.) + dx;
0640 yp[1] = numod * (dy1);
0641 xp[2] = vane * (dx + dx / 8.) + dx;
0642 yp[2] = numod * (dy1) + dy;
0643 xp[3] = vane * (dx + dx / 8.);
0644 yp[3] = numod * (dy1) + dy;
0645 } else {
0646 xt1 = r;
0647 yt1 = -vhtop / 2.;
0648 xs1 = xt1 * cos(phi) - yt1 * sin(phi);
0649 ys1 = xt1 * sin(phi) + yt1 * cos(phi);
0650 xt2 = r;
0651 yt2 = vhtop / 2.;
0652 xs2 = xt2 * cos(phi) - yt2 * sin(phi);
0653 ys2 = xt2 * sin(phi) + yt2 * cos(phi);
0654 pv1 = phival(xs1, ys1);
0655 pv2 = phival(xs2, ys2);
0656 if (fabs(pv1 - pv2) > M_PI && numod == 1)
0657 pv1 = pv1 - 2. * M_PI;
0658 if (fabs(pv1 - pv2) > M_PI && numod != 1)
0659 pv2 = pv2 + 2. * M_PI;
0660 xp[0] = mod->posz - vhapo / 2.;
0661 yp[0] = 4.2 * pv1;
0662 xp[1] = mod->posz + vhapo / 2.;
0663 yp[1] = 4.2 * pv1;
0664 xp[2] = mod->posz + vhapo / 2.;
0665 yp[2] = 4.2 * pv2;
0666 xp[3] = mod->posz - vhapo / 2.;
0667 yp[3] = 4.2 * pv2;
0668 }
0669 }
0670 if (isRingStereo(key)) {
0671 np = 3;
0672 if (mod->idModule > 100) {
0673 for (int j = 0; j < 3; j++) {
0674 xd[j] = xdpixel(xp[j]);
0675 yd[j] = ydpixel(yp[j]);
0676 }
0677 } else {
0678 xd[0] = xdpixel(xp[2]);
0679 yd[0] = ydpixel(yp[2]);
0680 xd[1] = xdpixel(xp[3]);
0681 yd[1] = ydpixel(yp[3]);
0682 xd[2] = xdpixel(xp[0]);
0683 yd[2] = ydpixel(yp[0]);
0684 }
0685 } else {
0686 for (int j = 0; j < 4; j++) {
0687 xd[j] = xdpixel(xp[j]);
0688 yd[j] = ydpixel(yp[j]);
0689 }
0690 }
0691 char buffer[20];
0692 sprintf(buffer, "%X", mod->idex);
0693
0694
0695 float vals = mod->value;
0696 if (std::isnan(vals))
0697 vals = 0;
0698 std::string nams = mod->name;
0699
0700
0701
0702
0703 nams.erase(std::remove_if(nams.begin(), nams.end(), [](char c) { return std::islower(c); }), nams.end());
0704 size_t found = nams.find('/');
0705 if (found != std::string::npos) {
0706 nams.erase(found, nams.length() - found);
0707 } else {
0708 found = nams.find(')');
0709 nams.erase(found + 1, nams.length() - found);
0710 }
0711 found = nams.find(") ");
0712 while (found != std::string::npos) {
0713 nams.erase(found + 1, 4);
0714 found = nams.find(") ", found);
0715 }
0716 found = nams.find(" -");
0717 while (found != std::string::npos) {
0718 nams.erase(found, 2);
0719 found = nams.find(" -", found);
0720 }
0721 found = nams.find(" ");
0722 while (found != std::string::npos) {
0723 nams.erase(found, 2);
0724 found = nams.find(" ", found);
0725 }
0726 found = nams.find(" ");
0727 while (found != std::string::npos) {
0728 nams.erase(found, 1);
0729 found = nams.find(" ", found);
0730 }
0731 std::replace_if(nams.begin(), nams.end(), [](char c) { return c == ' '; }, '_');
0732
0733 if (mod->red < 0) {
0734 int color = getcolor(mod->value, palette);
0735 red = (color >> 16) & 0xFF;
0736 green = (color >> 8) & 0xFF;
0737 blue = (color) & 0xFF;
0738
0739 if (!print_total)
0740 mod->value = mod->value * mod->count;
0741
0742 if (mod->count > 0)
0743 if (temporary_file)
0744
0745 *svgfile << nams << " " << vals << " " << red << " " << green << " " << blue << " ";
0746 else
0747 *svgfile
0748 << "<svg:polygon detid=\"" << mod->idex << "\" count=\"" << mod->count << "\" value=\"" << mod->value
0749 << "\" id=\"" << key << "\" capvids=\"" << mod->capvids << "\" lv=\"" << mod->psuIdex << "\" hv=\""
0750 << mod->psuIdex * 10 + mod->HVchannel << "\" fec=\"" << mod->CcuId
0751 << "\" onclick=\"showData(evt);\" onmouseover=\"showData(evt);\" onmouseout=\"showData(evt);\" MESSAGE=\""
0752 << mod->text << "\" POS=\"" << mod->name << " \" fill=\"rgb(" << red << "," << green << "," << blue
0753 << ")\" points=\"";
0754 else if (temporary_file)
0755 *svgfile << nams << " " << vals << " " << 255 << " " << 255 << " " << 255 << " ";
0756 else
0757 *svgfile
0758 << "<svg:polygon detid=\"" << mod->idex << "\" count=\"" << mod->count << "\" value=\"" << mod->value
0759 << "\" id=\"" << key << "\" capvids=\"" << mod->capvids << "\" lv=\"" << mod->psuIdex << "\" hv=\""
0760 << mod->psuIdex * 10 + mod->HVchannel << "\" fec=\"" << mod->CcuId
0761 << "\" onclick=\"showData(evt);\" onmouseover=\"showData(evt);\" onmouseout=\"showData(evt);\" MESSAGE=\""
0762 << mod->text << "\" POS=\"" << mod->name << " \" fill=\"white\" points=\"";
0763 if (temporary_file)
0764 *svgfile << np << " ";
0765 for (int k = 0; k < np; k++) {
0766 if (temporary_file)
0767 *svgfile << xd[k] << " " << yd[k] << " ";
0768 else
0769 *svgfile << xd[k] << "," << yd[k] << " ";
0770 }
0771 if (temporary_file)
0772 *svgfile << std::endl;
0773 else
0774 *svgfile << "\" />" << std::endl;
0775 } else {
0776 if (mod->red > 255)
0777 mod->red = 255;
0778 if (mod->green > 255)
0779 mod->green = 255;
0780 if (mod->blue > 255)
0781 mod->blue = 255;
0782 if (temporary_file)
0783 *svgfile << nams << " " << vals << " " << mod->red << " " << mod->green << " " << mod->blue << " ";
0784 else
0785 *svgfile
0786 << "<svg:polygon detid=\"" << mod->idex << "\" count=\"" << mod->count << "\" value=\"" << mod->value
0787 << "\" id=\"" << key << "\" capvids=\"" << mod->capvids << "\" lv=\"" << mod->psuIdex << "\" hv=\""
0788 << mod->psuIdex * 10 + mod->HVchannel << "\" fec=\"" << mod->CcuId
0789 << "\" onclick=\"showData(evt);\" onmouseover=\"showData(evt);\" onmouseout=\"showData(evt);\" MESSAGE=\""
0790 << mod->text << "\" POS=\"" << mod->name << " \" fill=\"rgb(" << mod->red << "," << mod->green << ","
0791 << mod->blue << ")\" points=\"";
0792 if (temporary_file)
0793 *svgfile << np << " ";
0794 for (int k = 0; k < np; k++) {
0795 if (temporary_file)
0796 *svgfile << xd[k] << " " << yd[k] << " ";
0797 else
0798 *svgfile << xd[k] << "," << yd[k] << " ";
0799 }
0800 if (temporary_file)
0801 *svgfile << std::endl;
0802 else
0803 *svgfile << "\" />" << std::endl;
0804 }
0805 }
0806 void TrackerMap::setRange(float min, float max) {
0807 gminvalue = min;
0808 gmaxvalue = max;
0809 if (tkMapLog) {
0810 gminvalue = pow(10., min);
0811 gmaxvalue = pow(10., max);
0812 }
0813 }
0814
0815 std::pair<float, float> TrackerMap::getAutomaticRange() {
0816 float minval, maxval;
0817 minval = 9999999.;
0818 maxval = -9999999.;
0819 for (int layer = 1; layer < 44; layer++) {
0820 for (int ring = firstRing[layer - 1]; ring < ntotRing[layer - 1] + firstRing[layer - 1]; ring++) {
0821 for (int module = 1; module < 200; module++) {
0822 int key = layer * 100000 + ring * 1000 + module;
0823 TmModule *mod = smoduleMap[key];
0824 if (mod != nullptr && !mod->notInUse() && mod->count > 0) {
0825 if (minval > mod->value)
0826 minval = mod->value;
0827 if (maxval < mod->value)
0828 maxval = mod->value;
0829 }
0830 }
0831 }
0832 }
0833 if (tkMapLog) {
0834 minval = log(minval) / log(10);
0835 maxval = log(maxval) / log(10);
0836 }
0837 return std::make_pair(minval, maxval);
0838 }
0839
0840
0841
0842
0843 void TrackerMap::save(bool print_total, float minval, float maxval, std::string s, int width, int height) {
0844 printflag = true;
0845 bool rangefound = true;
0846 if (saveGeoTrackerMap) {
0847 std::string filetype = s, outputfilename = s;
0848 std::vector<TPolyLine *> vp;
0849 TGaxis *axis = nullptr;
0850 size_t found = filetype.find_last_of('.');
0851 filetype = filetype.substr(found + 1);
0852 found = outputfilename.find_last_of('.');
0853 outputfilename = outputfilename.substr(0, found);
0854
0855 temporary_file = true;
0856
0857
0858
0859
0860
0861 if (filetype == "svg")
0862 temporary_file = false;
0863 std::ostringstream outs;
0864 minvalue = minval;
0865 maxvalue = maxval;
0866 outs << outputfilename << ".coor";
0867 savefile = new std::ofstream(outs.str().c_str(), std::ios::out);
0868 if (!print_total) {
0869 for (int layer = 1; layer < 44; layer++) {
0870 for (int ring = firstRing[layer - 1]; ring < ntotRing[layer - 1] + firstRing[layer - 1]; ring++) {
0871 for (int module = 1; module < 200; module++) {
0872 int key = layer * 100000 + ring * 1000 + module;
0873 TmModule *mod = smoduleMap[key];
0874 if (mod != nullptr && !mod->notInUse()) {
0875 mod->value = mod->value / mod->count;
0876 }
0877 }
0878 }
0879 }
0880 }
0881
0882 if (minvalue >= maxvalue) {
0883 minvalue = 9999999.;
0884 maxvalue = -9999999.;
0885 rangefound = false;
0886 for (int layer = 1; layer < 44; layer++) {
0887 for (int ring = firstRing[layer - 1]; ring < ntotRing[layer - 1] + firstRing[layer - 1]; ring++) {
0888 for (int module = 1; module < 200; module++) {
0889 int key = layer * 100000 + ring * 1000 + module;
0890 TmModule *mod = smoduleMap[key];
0891 if (mod != nullptr && !mod->notInUse() && mod->count > 0) {
0892 rangefound = true;
0893 if (minvalue > mod->value)
0894 minvalue = mod->value;
0895 if (maxvalue < mod->value)
0896 maxvalue = mod->value;
0897 }
0898 }
0899 }
0900 }
0901 }
0902 if ((title.find("QTestAlarm") != std::string::npos) || (maxvalue == minvalue) || !rangefound)
0903 printflag = false;
0904 if (!temporary_file) {
0905 *savefile << "<?xml version=\"1.0\" standalone=\"no\" ?>" << std::endl;
0906 *savefile << "<svg xmlns=\"http://www.w3.org/2000/svg\"" << std::endl;
0907 *savefile << "xmlns:svg=\"http://www.w3.org/2000/svg\" " << std::endl;
0908 *savefile << "xmlns:xlink=\"http://www.w3.org/1999/xlink\">" << std::endl;
0909 *savefile << "<svg:svg id=\"mainMap\" x=\"0\" y=\"0\" viewBox=\"0 0 3100 1600"
0910 << "\" width=\"" << width << "\" height=\"" << height << "\">" << std::endl;
0911 *savefile << "<svg:rect fill=\"lightblue\" stroke=\"none\" x=\"0\" y=\"0\" width=\"3100\" height=\"1600\" /> "
0912 << std::endl;
0913 *savefile << "<svg:g id=\"tracker\" transform=\"translate(10,1500) rotate(270)\" "
0914 "style=\"fill:none;stroke:black;stroke-width:0;\"> "
0915 << std::endl;
0916 }
0917 for (int layer = 1; layer < 44; layer++) {
0918
0919 defwindow(layer);
0920 for (int ring = firstRing[layer - 1]; ring < ntotRing[layer - 1] + firstRing[layer - 1]; ring++) {
0921 for (int module = 1; module < 200; module++) {
0922 int key = layer * 100000 + ring * 1000 + module;
0923 TmModule *mod = smoduleMap[key];
0924 if (mod != nullptr && !mod->notInUse()) {
0925 drawModule(mod, key, layer, print_total, savefile);
0926 }
0927 }
0928 }
0929 }
0930
0931 if (!temporary_file) {
0932 *savefile << "</svg:g>" << std::endl;
0933 *savefile << " <svg:text id=\"Title\" class=\"normalText\" x=\"300\" y=\"0\">" << title << "</svg:text>"
0934 << std::endl;
0935 }
0936
0937 if (printflag) {
0938 if (onlyPixelFlag) {
0939 drawPalette(savefile, -30);
0940 } else {
0941 drawPalette(savefile);
0942 }
0943 }
0944 if (!temporary_file) {
0945 *savefile << "</svg:svg>" << std::endl;
0946 *savefile << "</svg>" << std::endl;
0947 }
0948 savefile->close();
0949 delete savefile;
0950
0951 const char *command1;
0952 std::string tempfilename = outputfilename + ".coor";
0953 if (filetype == "svg") {
0954 std::string command = "mv " + tempfilename + " " + outputfilename + ".svg";
0955 command1 = command.c_str();
0956 std::cout << "Executing " << command1 << std::endl;
0957 system(command1);
0958 }
0959
0960 if (temporary_file) {
0961
0962 float content;
0963 std::string named;
0964
0965 int red, green, blue, npoints, colindex, ncolor;
0966 double x[4], y[4];
0967 std::ifstream tempfile(tempfilename.c_str(), std::ios::in);
0968 TCanvas *MyC = new TCanvas("MyC", "TrackerMap", width, height);
0969 gPad->SetFillColor(38);
0970
0971 if (addPixelFlag) {
0972 gPad->Range(0, 0, 3800, 1600);
0973 } else if (onlyPixelFlag) {
0974 gPad->Range(-100, 0, 800, 1600);
0975 } else {
0976 gPad->Range(800, 0, 3800, 1600);
0977 }
0978
0979
0980 ncolor = 0;
0981 typedef std::map<int, int> ColorList;
0982 ColorList colorList;
0983 ColorList::iterator pos;
0984 TColor *col, *c;
0985 std::cout << "tempfilename " << tempfilename << std::endl;
0986 while (!tempfile.eof()) {
0987 tempfile >> named >> content >> red >> green >> blue >> npoints;
0988 colindex = red + green * 1000 + blue * 1000000;
0989 pos = colorList.find(colindex);
0990 if (pos == colorList.end()) {
0991 colorList[colindex] = ncolor + 100;
0992 col = gROOT->GetColor(ncolor + 100);
0993 if (col)
0994 col->SetRGB((Double_t)(red / 255.), (Double_t)(green / 255.), (Double_t)(blue / 255.));
0995 else
0996 c = new TColor(ncolor + 100, (Double_t)(red / 255.), (Double_t)(green / 255.), (Double_t)(blue / 255.));
0997 vc.push_back(c);
0998 ncolor++;
0999 }
1000 for (int i = 0; i < npoints; i++) {
1001 tempfile >> x[i] >> y[i];
1002 }
1003 }
1004
1005 if (ncolor > 0 && ncolor < 10000) {
1006 Int_t colors[10000];
1007 for (int i = 0; i < ncolor; i++) {
1008 colors[i] = i + 100;
1009 }
1010 gStyle->SetPalette(ncolor, colors);
1011 }
1012
1013 tempfile.clear();
1014 tempfile.seekg(0, std::ios::beg);
1015 std::cout << "created palette with " << ncolor << " colors" << std::endl;
1016
1017
1018 TH2Poly *StripMap = new TH2Poly("StripSummary", "", 775, 3600, 0, 1350);
1019 StripMap->SetFloat(true);
1020 StripMap->GetXaxis()->SetTitle("");
1021 StripMap->GetYaxis()->SetTitle("");
1022 StripMap->SetStats(false);
1023 int siterator = 0;
1024
1025 while (!tempfile.eof()) {
1026 siterator++;
1027
1028 tempfile >> named >> content >> red >> green >> blue >> npoints;
1029
1030 for (int i = 0; i < npoints; i++) {
1031 tempfile >> x[i] >> y[i];
1032 }
1033 colindex = red + green * 1000 + blue * 1000000;
1034 pos = colorList.find(colindex);
1035 if (pos != colorList.end()) {
1036 TPolyLine *pline = new TPolyLine(npoints, y, x);
1037 vp.push_back(pline);
1038 pline->SetFillColor(colorList[colindex]);
1039
1040 TGraph *bin = new TGraph(npoints, y, x);
1041
1042 if ((siterator >= 1 && siterator <= 3608) || (siterator >= 4281 && siterator <= 7888) ||
1043 (siterator >= 8657 && siterator <= 16588)) {
1044 bin->SetName(named.c_str());
1045 StripMap->AddBin(bin);
1046 StripMap->Fill(named.c_str(), content);
1047 }
1048
1049 pline->SetLineWidth(0);
1050 pline->Draw("f");
1051 }
1052 }
1053 if (printflag) {
1054 float lminvalue = minvalue;
1055 float lmaxvalue = maxvalue;
1056 if (tkMapLog) {
1057 lminvalue = log(minvalue) / log(10);
1058 lmaxvalue = log(maxvalue) / log(10);
1059 }
1060 if (onlyPixelFlag) {
1061 axis = new TGaxis(-30, 36, -30, 1530, lminvalue, lmaxvalue, 510, "+L");
1062 } else {
1063 axis = new TGaxis(3660, 36, 3660, 1530, lminvalue, lmaxvalue, 510, "+L");
1064 }
1065 axis->SetLabelSize(0.02);
1066 axis->Draw();
1067 }
1068 TLatex l;
1069 l.SetTextSize(0.03);
1070 l.DrawLatex(950, 1330, "TID");
1071 l.DrawLatex(2300, 1330, "TEC");
1072 l.DrawLatex(300, 1330, "FPIX");
1073 l.DrawLatex(20, 560, "BPIX L1");
1074 l.DrawLatex(500, 385, "BPIX L2");
1075 l.DrawLatex(500, 945, "BPIX L3");
1076 l.SetTextSize(0.04);
1077 std::string fulltitle = title;
1078 if (tkMapLog && (fulltitle.find("Log10 scale") == std::string::npos))
1079 fulltitle += ": Log10 scale";
1080 if (onlyPixelFlag) {
1081 l.DrawLatex(30, 1500, fulltitle.c_str());
1082 } else {
1083 l.DrawLatex(850, 1500, fulltitle.c_str());
1084 }
1085 if (onlyPixelFlag) {
1086 l.DrawLatex(380, 40, "-z");
1087 } else {
1088 l.DrawLatex(1730, 40, "-z");
1089 }
1090 if (onlyPixelFlag) {
1091 l.DrawLatex(380, 1330, "+z");
1092 } else {
1093 l.DrawLatex(1730, 1360, "+z");
1094 }
1095 l.DrawLatex(1085, 330, "TIB L1");
1096 l.DrawLatex(1085, 1000, "TIB L2");
1097 l.DrawLatex(1585, 330, "TIB L3");
1098 l.DrawLatex(1585, 1000, "TIB L4");
1099 l.DrawLatex(2085, 330, "TOB L1");
1100 l.DrawLatex(2085, 1000, "TOB L2");
1101 l.DrawLatex(2585, 330, "TOB L3");
1102 l.DrawLatex(2585, 1000, "TOB L4");
1103 l.DrawLatex(3085, 330, "TOB L5");
1104 l.DrawLatex(3085, 1000, "TOB L6");
1105 TArrow arx(3448, 1190, 3448, 1350, 0.01, "|>");
1106 l.DrawLatex(3460, 1350, "x");
1107 TArrow ary(3448, 1190, 3312, 1190, 0.01, "|>");
1108 l.DrawLatex(3312, 1210, "y");
1109 TArrow arz(3485, 373, 3485, 676, 0.01, "|>");
1110 l.DrawLatex(3510, 667, "z");
1111 TArrow arphi(3485, 511, 3037, 511, 0.01, "|>");
1112 l.DrawLatex(3023, 520, "#Phi");
1113 arx.SetLineWidth(3);
1114 ary.SetLineWidth(3);
1115 arz.SetLineWidth(3);
1116 arphi.SetLineWidth(3);
1117 if (onlyPixelFlag) {
1118 arx.SetX1(570);
1119 arx.SetX2(570);
1120 arx.SetY1(1190);
1121 arx.SetY2(1350);
1122 l.DrawLatex(570 + 12, 1190 + 160, "x");
1123 ary.SetX1(570);
1124 ary.SetX2(570 - 160);
1125 ary.SetY1(1190);
1126 ary.SetY2(1190);
1127 l.DrawLatex(570 - 160, 1190 + 30, "y");
1128 arz.SetX1(380);
1129 arz.SetX2(380);
1130 arz.SetY1(683 - 100);
1131 arz.SetY2(683 + 100);
1132 l.DrawLatex(380 + 15, 683 + 100 - 9, "z");
1133 arphi.SetX1(380);
1134 arphi.SetX2(380 - 390);
1135 arphi.SetY1(683);
1136 arphi.SetY2(683);
1137 l.DrawLatex(380 - 390 - 14, 683 + 9, "#Phi");
1138 }
1139 arx.Draw();
1140 ary.Draw();
1141 arz.Draw();
1142 arphi.Draw();
1143 TLegend *MyL = buildLegend();
1144
1145 if (title.find("QTestAlarm") != std::string::npos) {
1146 MyL->Draw();
1147 }
1148 MyC->Update();
1149 if (filetype == "png") {
1150 std::string filename = outputfilename + ".png";
1151 std::cout << "printing " << filename << std::endl;
1152 MyC->Print(filename.c_str());
1153 }
1154 if (filetype == "jpg") {
1155 std::string filename = outputfilename + ".jpg";
1156 MyC->Print(filename.c_str());
1157 }
1158 if (filetype == "pdf") {
1159 std::string filename = outputfilename + ".pdf";
1160 MyC->Print(filename.c_str());
1161 }
1162 std::string command = "rm " + tempfilename;
1163 command1 = command.c_str();
1164 std::cout << "Executing " << command1 << std::endl;
1165 system(command1);
1166 MyC->Clear();
1167 delete MyC;
1168 delete MyL;
1169
1170
1171 TCanvas *MyT = new TCanvas("MyT", "MyT", 3500, 1500);
1172
1173 StripMap->SetLineColor(kBlack);
1174 StripMap->SetLineWidth(0);
1175 StripMap->Draw("AL COLZ");
1176 MyT->Update();
1177
1178
1179 gStyle->SetPalette(kRainBow);
1180 TPaletteAxis *realPalette = (TPaletteAxis *)StripMap->GetListOfFunctions()->FindObject("palette");
1181 realPalette->SetX1NDC(0.92);
1182 realPalette->SetX2NDC(0.94);
1183 realPalette->SetY1NDC(0.02);
1184 realPalette->SetY2NDC(0.91);
1185 gPad->SetRightMargin(0.08);
1186 gPad->SetLeftMargin(0.01);
1187 gPad->SetTopMargin(0.09);
1188 gPad->SetBottomMargin(0.02);
1189 gPad->Update();
1190
1191
1192 TLatex l2;
1193 l2.SetTextSize(0.06);
1194 std::string runnumber;
1195 for (char c : title)
1196 if (std::isdigit(c))
1197 runnumber.push_back(c);
1198 std::string striptitle = "Run " + runnumber + ": Strip " + outputfilename;
1199 l2.DrawLatex(800, 1380, striptitle.c_str());
1200 l2.SetTextSize(0.05);
1201 l2.DrawLatex(1200, 40, "-z");
1202 l2.DrawLatex(1200, 1300, "+z");
1203 l2.DrawLatex(1085, 310, "TIB L1");
1204 l2.DrawLatex(1085, 1000, "TIB L2");
1205 l2.DrawLatex(1585, 310, "TIB L3");
1206 l2.DrawLatex(1585, 1000, "TIB L4");
1207 l2.DrawLatex(2085, 310, "TOB L1");
1208 l2.DrawLatex(2085, 1000, "TOB L2");
1209 l2.DrawLatex(2585, 310, "TOB L3");
1210 l2.DrawLatex(2585, 1000, "TOB L4");
1211 l2.DrawLatex(3085, 310, "TOB L5");
1212 l2.DrawLatex(3085, 1000, "TOB L6");
1213 l2.DrawLatex(3460, 1320, "x");
1214 l2.DrawLatex(3315, 1210, "y");
1215 l2.DrawLatex(3510, 667, "z");
1216 l2.DrawLatex(3023, 530, "#Phi");
1217 arx.SetY2(1320);
1218 ary.SetX2(3320);
1219 arz.SetX1(3490);
1220 arz.SetX2(3490);
1221 arphi.SetX1(3490);
1222 arx.Draw();
1223 ary.Draw();
1224 arz.Draw();
1225 arphi.Draw();
1226 MyT->Update();
1227
1228 std::string filename = outputfilename + ".root";
1229 MyT->Print(filename.c_str());
1230 delete MyT;
1231
1232 if (printflag)
1233 delete axis;
1234 for (std::vector<TPolyLine *>::iterator pos1 = vp.begin(); pos1 != vp.end(); pos1++) {
1235 delete (*pos1);
1236 }
1237 }
1238 }
1239 return;
1240 }
1241 void TrackerMap::drawApvPair(
1242 int crate, int numfed_incrate, bool print_total, TmApvPair *apvPair, std::ofstream *svgfile, bool useApvPairValue) {
1243 double xp[4], yp[4];
1244 int color;
1245 int green = 0;
1246 int red = 0;
1247 int blue = 0;
1248 double xd[4], yd[4];
1249 int np = 4;
1250 double boxinitx = 0., boxinity = 0.;
1251 double dx = .9, dy = .9;
1252
1253
1254
1255
1256
1257
1258 boxinitx = boxinitx + (NUMFED_INCOLUMN - 1 - (numfed_incrate - 1) / NUMFED_INROW) * (NUMFEDCH_INCOLUMN + 2);
1259 boxinity = boxinity + (NUMFED_INROW - 1 - (numfed_incrate - 1) % NUMFED_INROW) * (NUMFEDCH_INROW + 1);
1260 boxinity = boxinity + NUMFEDCH_INROW - (apvPair->getFedCh() / NUMFEDCH_INCOLUMN);
1261 boxinitx = boxinitx + NUMFEDCH_INCOLUMN - (int)(apvPair->getFedCh() % NUMFEDCH_INCOLUMN);
1262
1263 xp[0] = boxinitx;
1264 yp[0] = boxinity;
1265 xp[1] = boxinitx + dx;
1266 yp[1] = boxinity;
1267 xp[2] = boxinitx + dx;
1268 yp[2] = boxinity + dy;
1269 xp[3] = boxinitx;
1270 yp[3] = boxinity + dy;
1271 for (int j = 0; j < 4; j++) {
1272 xd[j] = xdpixelc(xp[j]);
1273 yd[j] = ydpixelc(yp[j]);
1274
1275 }
1276
1277 char buffer[20];
1278 sprintf(buffer, "%X", apvPair->mod->idex);
1279 std::string s = apvPair->mod->name;
1280 s.erase(s.begin() + s.find("connected"), s.end());
1281
1282 if (useApvPairValue) {
1283 if (apvPair->red < 0) {
1284 if (apvPair->count > 0) {
1285 float vals = apvPair->value;
1286 std::string nams = "nams_apv";
1287
1288 color = getcolor(apvPair->value, palette);
1289 red = (color >> 16) & 0xFF;
1290 green = (color >> 8) & 0xFF;
1291 blue = (color) & 0xFF;
1292 if (!print_total)
1293 apvPair->value = apvPair->value * apvPair->count;
1294 if (temporary_file)
1295 *svgfile << nams << " " << vals << " " << red << " " << green << " " << blue << " ";
1296 else
1297 *svgfile
1298 << "<svg:polygon detid=\"" << apvPair->idex << "\" count=\"" << apvPair->count << "\" value=\""
1299 << apvPair->value << "\" id=\"" << apvPair->idex + crate * 1000000 << "\" cmodid=\""
1300 << apvPair->mod->getKey()
1301 << "\" onclick=\"showData(evt);\" onmouseover=\"showData(evt);\" onmouseout=\"showData(evt);\" MESSAGE=\""
1302 "\" POS=\"Fed/Ch "
1303 << apvPair->getFedId() << "/" << apvPair->getFedCh() << " connected to " << s << " Id " << buffer
1304 << " \" fill=\"rgb(" << red << "," << green << "," << blue << ")\" points=\"";
1305 } else {
1306 if (temporary_file)
1307 *svgfile << 0 << " " << 0 << " " << 255 << " " << 255 << " " << 255 << " ";
1308 else
1309 *svgfile
1310 << "<svg:polygon detid=\"" << apvPair->idex << "\" count=\"" << apvPair->count << "\" value=\""
1311 << apvPair->value << "\" id=\"" << apvPair->idex + crate * 1000000 << "\" cmodid=\""
1312 << apvPair->mod->getKey()
1313 << "\" onclick=\"showData(evt);\" onmouseover=\"showData(evt);\" onmouseout=\"showData(evt);\" MESSAGE=\""
1314 "\" POS=\"Fed/Ch "
1315 << apvPair->getFedId() << "/" << apvPair->getFedCh() << " connected to " << s << " Id " << buffer
1316 << " \" fill=\"white\" points=\"";
1317 }
1318 } else {
1319 if (apvPair->red > 255)
1320 apvPair->red = 255;
1321 if (apvPair->green > 255)
1322 apvPair->green = 255;
1323 if (apvPair->blue > 255)
1324 apvPair->blue = 255;
1325 if (temporary_file)
1326 *svgfile << 0 << " " << 0 << " " << apvPair->red << " " << apvPair->green << " " << apvPair->blue << " ";
1327 else
1328 *svgfile
1329 << "<svg:polygon detid=\"" << apvPair->idex << "\" count=\"" << apvPair->count << "\" value=\""
1330 << apvPair->value << "\" id=\"" << apvPair->idex + crate * 1000000 << "\" cmodid=\""
1331 << apvPair->mod->getKey()
1332 << "\" onclick=\"showData(evt);\" onmouseover=\"showData(evt);\" onmouseout=\"showData(evt);\" MESSAGE=\""
1333 "\" POS=\"Fed/Ch "
1334 << apvPair->getFedId() << "/" << apvPair->getFedCh() << " connected to " << s << " Id " << buffer
1335 << " \" fill=\"rgb(" << apvPair->red << "," << apvPair->green << "," << apvPair->blue << ")\" points=\"";
1336 }
1337 } else {
1338 if (apvPair->mod->red < 0) {
1339 if (apvPair->mod->count > 0) {
1340 float vals = apvPair->mod->value;
1341 std::string nams = "nams_apv2";
1342
1343 color = getcolor(apvPair->mod->value, palette);
1344 red = (color >> 16) & 0xFF;
1345 green = (color >> 8) & 0xFF;
1346 blue = (color) & 0xFF;
1347 if (temporary_file)
1348 *svgfile << nams << " " << vals << " " << red << " " << green << " " << blue << " ";
1349 else
1350 *svgfile
1351 << "<svg:polygon detid=\"" << apvPair->idex << "\" count=\"" << apvPair->count << "\" value=\""
1352 << apvPair->value << "\" id=\"" << apvPair->idex + crate * 1000000 << "\" cmodid=\""
1353 << apvPair->mod->getKey()
1354 << "\" onclick=\"showData(evt);\" onmouseover=\"showData(evt);\" onmouseout=\"showData(evt);\" MESSAGE=\""
1355 "\" POS=\"Fed/Ch "
1356 << apvPair->getFedId() << "/" << apvPair->getFedCh() << " connected to " << s << " Id " << buffer
1357 << " \" fill=\"rgb(" << red << "," << green << "," << blue << ")\" points=\"";
1358 } else {
1359 if (temporary_file)
1360 *svgfile << 0 << " " << 0 << " " << 255 << " " << 255 << " " << 255 << " ";
1361 else
1362 *svgfile
1363 << "<svg:polygon detid=\"" << apvPair->idex << "\" count=\"" << apvPair->count << "\" value=\""
1364 << apvPair->value << "\" id=\"" << apvPair->idex + crate * 1000000 << "\" cmodid=\""
1365 << apvPair->mod->getKey()
1366 << "\" onclick=\"showData(evt);\" onmouseover=\"showData(evt);\" onmouseout=\"showData(evt);\" MESSAGE=\""
1367 "\" POS=\"Fed/Ch "
1368 << apvPair->getFedId() << "/" << apvPair->getFedCh() << " connected to " << s << " Id " << buffer
1369 << " \" fill=\"white\" points=\"";
1370 }
1371 } else {
1372 if (apvPair->mod->red > 255)
1373 apvPair->mod->red = 255;
1374 if (apvPair->mod->green > 255)
1375 apvPair->mod->green = 255;
1376 if (apvPair->mod->blue > 255)
1377 apvPair->mod->blue = 255;
1378 if (temporary_file)
1379 *svgfile << 0 << " " << 0 << " " << apvPair->mod->red << " " << apvPair->mod->green << " " << apvPair->mod->blue
1380 << " ";
1381 else
1382 *svgfile
1383 << "<svg:polygon detid=\"" << apvPair->idex << "\" count=\"" << apvPair->count << "\" value=\""
1384 << apvPair->value << "\" id=\"" << apvPair->idex + crate * 1000000 << "\" cmodid=\""
1385 << apvPair->mod->getKey()
1386 << "\" onclick=\"showData(evt);\" onmouseover=\"showData(evt);\" onmouseout=\"showData(evt);\" MESSAGE=\""
1387 "\" POS=\"Fed/Ch "
1388 << apvPair->getFedId() << "/" << apvPair->getFedCh() << " connected to " << s << " Id " << buffer
1389 << " \" fill=\"rgb(" << apvPair->mod->red << "," << apvPair->mod->green << "," << apvPair->mod->blue
1390 << ")\" points=\"";
1391 }
1392 }
1393 if (temporary_file)
1394 *svgfile << np << " ";
1395 for (int k = 0; k < np; k++) {
1396 if (temporary_file)
1397 *svgfile << xd[k] << " " << yd[k] << " ";
1398 else
1399 *svgfile << xd[k] << "," << yd[k] << " ";
1400 }
1401 if (temporary_file)
1402 *svgfile << std::endl;
1403 else
1404 *svgfile << "\" />" << std::endl;
1405 }
1406 void TrackerMap::drawCcu(
1407 int crate, int numfec_incrate, bool print_total, TmCcu *ccu, std::ofstream *svgfile, bool useCcuValue) {
1408 double xp[4], yp[4];
1409 int color;
1410 int green = 0;
1411 int red = 0;
1412 int blue = 0;
1413 double xd[4], yd[4];
1414 int np = 4;
1415 double boxinitx = 0., boxinity = 0.;
1416 double dx = .9, dy = .9;
1417 int numccu_incolumn = 8;
1418 int numccu_inrow = 15;
1419 int numfec_incolumn = 5;
1420 int numfec_inrow = 4;
1421 boxinitx = boxinitx + (numfec_incolumn - (numfec_incrate - 1) / numfec_inrow) * 14.;
1422 boxinity = boxinity + (numfec_inrow - (numfec_incrate - 1) % numfec_inrow) * 16.;
1423 boxinity = boxinity + numccu_inrow - ccu->mpos;
1424 boxinitx = boxinitx + numccu_incolumn - (int)(ccu->getCcuRing() % numccu_incolumn);
1425
1426 xp[0] = boxinitx;
1427 yp[0] = boxinity;
1428 xp[1] = boxinitx + dx;
1429 yp[1] = boxinity;
1430 xp[2] = boxinitx + dx;
1431 yp[2] = boxinity + dy;
1432 xp[3] = boxinitx;
1433 yp[3] = boxinity + dy;
1434 for (int j = 0; j < 4; j++) {
1435 xd[j] = xdpixelfec(xp[j]);
1436 yd[j] = ydpixelfec(yp[j]);
1437
1438 }
1439
1440 char buffer[20];
1441 sprintf(buffer, "%X", ccu->idex);
1442
1443
1444 std::string s = ccu->text;
1445 s.erase(s.begin() + s.find("connected"), s.end());
1446
1447 if (ccu->red < 0) {
1448 if (ccu->count > 0) {
1449 float vals = ccu->value;
1450 std::string nams = "nams_ccu";
1451
1452 color = getcolor(ccu->value, palette);
1453 red = (color >> 16) & 0xFF;
1454 green = (color >> 8) & 0xFF;
1455 blue = (color) & 0xFF;
1456 if (!print_total)
1457 ccu->value = ccu->value * ccu->count;
1458 if (temporary_file)
1459 *svgfile << nams << " " << vals << " " << red << " " << green << " " << blue << " ";
1460 else
1461 *svgfile
1462 << "<svg:polygon detid=\"" << ccu->idex << "\" count=\"" << ccu->count << "\" value=\"" << ccu->value
1463 << "\" id=\"" << ccu->idex + crate * 1000000 << "\" cmodid=\"" << ccu->cmodid << "\" layer=\"" << ccu->layer
1464 << "\" onclick=\"showData(evt);\" onmouseover=\"showData(evt);\" onmouseout=\"showData(evt);\" MESSAGE=\""
1465 "\" POS=\"Slot/Ring"
1466 << ccu->getCcuSlot() << "/" << ccu->getCcuRing() << " connected to " << s << " Id " << buffer
1467 << " \" fill=\"rgb(" << red << "," << green << "," << blue << ")\" points=\"";
1468 } else {
1469 if (temporary_file)
1470 *svgfile << 0 << " " << 0 << " " << 255 << " " << 255 << " " << 255 << " ";
1471 else
1472 *svgfile
1473 << "<svg:polygon detid=\"" << ccu->idex << "\" count=\"" << ccu->count << "\" value=\"" << ccu->value
1474 << "\" id=\"" << ccu->idex + crate * 1000000 << "\" cmodid=\"" << ccu->cmodid << "\" layer=\""
1475 << ccu->layer
1476 << "\" onclick=\"showData(evt);\" onmouseover=\"showData(evt);\" onmouseout=\"showData(evt);\" MESSAGE=\""
1477 "\" POS=\"Slot/Ring "
1478 << ccu->getCcuSlot() << "/" << ccu->getCcuRing() << " connected to " << s << " Id " << buffer
1479 << " \" fill=\"white\" points=\"";
1480 }
1481 } else {
1482 if (ccu->red > 255)
1483 ccu->red = 255;
1484 if (ccu->green > 255)
1485 ccu->green = 255;
1486 if (ccu->blue > 255)
1487 ccu->blue = 255;
1488 if (temporary_file)
1489 *svgfile << 0 << " " << 0 << " " << ccu->red << " " << ccu->green << " " << ccu->blue << " ";
1490 else
1491 *svgfile
1492 << "<svg:polygon detid=\"" << ccu->idex << "\" count=\"" << ccu->count << "\" value=\"" << ccu->value
1493 << "\" id=\"" << ccu->idex + crate * 1000000 << "\" cmodid=\"" << ccu->cmodid << "\" layer=\"" << ccu->layer
1494 << "\" onclick=\"showData(evt);\" onmouseover=\"showData(evt);\" onmouseout=\"showData(evt);\" MESSAGE=\""
1495 "\" POS=\"Slot/Ring "
1496 << ccu->getCcuSlot() << "/" << ccu->getCcuRing() << " connected to " << s << " Id " << buffer
1497 << " \" fill=\"rgb(" << ccu->red << "," << ccu->green << "," << ccu->blue << ")\" points=\"";
1498 }
1499 if (temporary_file)
1500 *svgfile << np << " ";
1501 for (int k = 0; k < np; k++) {
1502 if (temporary_file)
1503 *svgfile << xd[k] << " " << yd[k] << " ";
1504 else
1505 *svgfile << xd[k] << "," << yd[k] << " ";
1506 }
1507 if (temporary_file)
1508 *svgfile << std::endl;
1509 else
1510 *svgfile << "\" />" << std::endl;
1511 }
1512 void TrackerMap::drawPsu(
1513 int rack, int numcrate_inrack, bool print_total, TmPsu *psu, std::ofstream *svgfile, bool usePsuValue) {
1514 double xp[4], yp[4];
1515 int color;
1516 int green = 0;
1517 int red = 0;
1518 int blue = 0;
1519 double xd[4], yd[4];
1520 int np = 4;
1521 double boxinitx = 0., boxinity = 0.;
1522 double dx = .9, dy = .9;
1523
1524 boxinitx = boxinitx + (NUMPSUCRATE_INCOLUMN - psu->getPsuCrate()) * 1.5;
1525 boxinity = boxinity + (NUMPSUCH_INROW - psu->getPsuBoard());
1526
1527 xp[0] = boxinitx;
1528 yp[0] = boxinity;
1529 xp[1] = boxinitx + dx;
1530 yp[1] = boxinity;
1531 xp[2] = boxinitx + dx;
1532 yp[2] = boxinity + dy;
1533 xp[3] = boxinitx;
1534 yp[3] = boxinity + dy;
1535
1536 for (int j = 0; j < 4; j++) {
1537 xd[j] = xdpixelpsu(xp[j]);
1538 yd[j] = ydpixelpsu(yp[j]);
1539
1540 }
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553 char buffer[20];
1554 sprintf(buffer, "%X", psu->idex);
1555 std::string s = psu->text;
1556 s.erase(s.begin() + s.find("connected"), s.end());
1557
1558 if (psu->red < 0) {
1559 if (psu->count > 0) {
1560 float vals = psu->value;
1561 std::string nams = "nams_psu";
1562
1563 color = getcolor(psu->value, palette);
1564 red = (color >> 16) & 0xFF;
1565 green = (color >> 8) & 0xFF;
1566 blue = (color) & 0xFF;
1567 if (!print_total)
1568 psu->value = psu->value * psu->count;
1569 if (temporary_file)
1570 *svgfile << nams << " " << vals << " " << red << " " << green << " " << blue << " ";
1571 else
1572 *svgfile
1573 << "<svg:polygon detid=\"" << psu->idex << "\" count=\"" << psu->count << "\" value=\"" << psu->value
1574 << "\" id=\"" << psu->idex << "\" cmodid=\"" << psu->cmodid_LV
1575 << "\" onclick=\"showData(evt);\" onmouseover=\"showData(evt);\" onmouseout=\"showData(evt);\" MESSAGE=\""
1576 "\" POS=\"easyCrate/easyBoard "
1577 << psu->getPsuCrate() << "/" << psu->getPsuBoard() << " connected to " << s << " \" fill=\"rgb(" << red
1578 << "," << green << "," << blue << ")\" points=\"";
1579 } else {
1580 if (temporary_file)
1581 *svgfile << 0 << " " << 0 << " " << 255 << " " << 255 << " " << 255 << " ";
1582 else
1583 *svgfile
1584 << "<svg:polygon detid=\"" << psu->idex << "\" count=\"" << psu->count << "\" value=\"" << psu->value
1585 << "\" id=\"" << psu->idex << "\" cmodid=\"" << psu->cmodid_LV
1586 << "\" onclick=\"showData(evt);\" onmouseover=\"showData(evt);\" onmouseout=\"showData(evt);\" MESSAGE=\""
1587 "\" POS=\"easyCrate/easyBoard "
1588 << psu->getPsuCrate() << "/" << psu->getPsuBoard() << " connected to " << s
1589 << " \" fill=\"white\" points=\"";
1590 }
1591 }
1592
1593 else {
1594 if (psu->red > 255)
1595 psu->red = 255;
1596 if (psu->green > 255)
1597 psu->green = 255;
1598 if (psu->blue > 255)
1599 psu->blue = 255;
1600 if (temporary_file)
1601 *svgfile << 0 << " " << 0 << " " << psu->red << " " << psu->green << " " << psu->blue << " ";
1602 else
1603 *svgfile
1604 << "<svg:polygon detid=\"" << psu->idex << "\" count=\"" << psu->count << "\" value=\"" << psu->value
1605 << "\" id=\"" << psu->idex << "\" cmodid=\"" << psu->cmodid_LV
1606 << "\" onclick=\"showData(evt);\" onmouseover=\"showData(evt);\" onmouseout=\"showData(evt);\" MESSAGE=\""
1607 "\" POS=\"easyCrate/easyBoard "
1608 << psu->getPsuCrate() << "/" << psu->getPsuBoard() << " connected to " << s << " \" fill=\"rgb(" << psu->red
1609 << "," << psu->green << "," << psu->blue << ")\" points=\"";
1610 }
1611
1612 if (temporary_file)
1613 *svgfile << np << " ";
1614 for (int k = 0; k < np; k++) {
1615 if (temporary_file)
1616 *svgfile << xd[k] << " " << yd[k] << " ";
1617 else
1618 *svgfile << xd[k] << "," << yd[k] << " ";
1619 }
1620 if (temporary_file)
1621 *svgfile << std::endl;
1622 else
1623 *svgfile << "\" />" << std::endl;
1624 }
1625
1626 void TrackerMap::drawHV2(
1627 int rack, int numcrate_inrack, bool print_total, TmPsu *psu, std::ofstream *svgfile, bool usePsuValue) {
1628 double xp[4], yp[4];
1629 int color;
1630 int greenHV2 = 0;
1631 int redHV2 = 0;
1632 int blueHV2 = 0;
1633 double xd[4], yd[4];
1634 int np = 4;
1635 double boxinitx = 35, boxinity = 12;
1636 double dx = 1.1, dy = 1.3;
1637
1638 boxinitx = boxinitx + (5 - psu->getPsuCrate()) * 5;
1639 boxinity = boxinity + (18 - psu->getPsuBoard()) * 1.75;
1640
1641 xp[0] = boxinitx;
1642 yp[0] = boxinity;
1643 xp[1] = boxinitx + dx;
1644 yp[1] = boxinity;
1645 xp[2] = boxinitx + dx;
1646 yp[2] = boxinity + dy;
1647 xp[3] = boxinitx;
1648 yp[3] = boxinity + dy;
1649
1650 for (int j = 0; j < 4; j++) {
1651 xd[j] = xdpixelpsu(xp[j]);
1652 yd[j] = ydpixelpsu(yp[j]);
1653
1654 }
1655
1656 char buffer[20];
1657 sprintf(buffer, "%X", psu->idex);
1658 std::string s = psu->textHV2;
1659 s.erase(s.begin() + s.find("connected"), s.end());
1660
1661 if (psu->redHV2 < 0) {
1662
1663 if (psu->valueHV2 > 0) {
1664 float vals = psu->valueHV2;
1665 std::string nams = "nams_hv2";
1666
1667 color = getcolor(psu->valueHV2, palette);
1668 redHV2 = (color >> 16) & 0xFF;
1669 greenHV2 = (color >> 8) & 0xFF;
1670 blueHV2 = (color) & 0xFF;
1671 if (!print_total)
1672 psu->valueHV2 = psu->valueHV2 * psu->countHV2;
1673 if (temporary_file)
1674 *svgfile << nams << " " << vals << " " << redHV2 << " " << greenHV2 << " " << blueHV2 << " ";
1675 else
1676 *svgfile
1677 << "<svg:polygon detid=\"" << psu->idex << "\" count=\"" << psu->countHV2 << "\" value=\"" << psu->valueHV2
1678 << "\" id=\"" << psu->idex * 10 + 2 << "\" cmodid=\"" << psu->cmodid_HV2
1679 << "\" onclick=\"showData(evt);\" onmouseover=\"showData(evt);\" onmouseout=\"showData(evt);\" MESSAGE=\""
1680 "\" POS=\"easyCrate/easyBoard "
1681 << psu->getPsuCrate() << "/" << psu->getPsuBoard() << " connected to " << s << " \" fill=\"rgb(" << redHV2
1682 << "," << greenHV2 << "," << blueHV2 << ")\" points=\"";
1683 } else {
1684 if (temporary_file)
1685 *svgfile << 0 << " " << 0 << " " << 255 << " " << 255 << " " << 255 << " ";
1686 else
1687 *svgfile
1688 << "<svg:polygon detid=\"" << psu->idex << "\" count=\"" << psu->countHV2 << "\" value=\"" << psu->valueHV2
1689 << "\" id=\"" << psu->idex * 10 + 2 << "\" cmodid=\"" << psu->cmodid_HV2
1690 << "\" onclick=\"showData(evt);\" onmouseover=\"showData(evt);\" onmouseout=\"showData(evt);\" MESSAGE=\""
1691 "\" POS=\"easyCrate/easyBoard "
1692 << psu->getPsuCrate() << "/" << psu->getPsuBoard() << " connected to " << s
1693 << " \" fill=\"white\" points=\"";
1694 }
1695 }
1696
1697 else {
1698 if (psu->redHV2 > 255)
1699 psu->redHV2 = 255;
1700 if (psu->greenHV2 > 255)
1701 psu->greenHV2 = 255;
1702 if (psu->blueHV2 > 255)
1703 psu->blueHV2 = 255;
1704 if (temporary_file)
1705 *svgfile << 0 << " " << 0 << " " << psu->redHV2 << " " << psu->greenHV2 << " " << psu->blueHV2 << " ";
1706 else
1707 *svgfile
1708 << "<svg:polygon detid=\"" << psu->idex << "\" count=\"" << psu->countHV2 << "\" value=\"" << psu->valueHV2
1709 << "\" id=\"" << psu->idex * 10 + 2 << "\" cmodid=\"" << psu->cmodid_HV2
1710 << "\" onclick=\"showData(evt);\" onmouseover=\"showData(evt);\" onmouseout=\"showData(evt);\" MESSAGE=\""
1711 "\" POS=\"easyCrate/easyBoard "
1712 << psu->getPsuCrate() << "/" << psu->getPsuBoard() << " connected to " << s << " \" fill=\"rgb("
1713 << psu->redHV2 << "," << psu->greenHV2 << "," << psu->blueHV2 << ")\" points=\"";
1714 }
1715
1716 if (temporary_file)
1717 *svgfile << np << " ";
1718 for (int k = 0; k < np; k++) {
1719 if (temporary_file)
1720 *svgfile << xd[k] << " " << yd[k] << " ";
1721 else
1722 *svgfile << xd[k] << "," << yd[k] << " ";
1723 }
1724 if (temporary_file)
1725 *svgfile << std::endl;
1726 else
1727 *svgfile << "\" />" << std::endl;
1728 }
1729
1730 void TrackerMap::drawHV3(
1731 int rack, int numcrate_inrack, bool print_total, TmPsu *psu, std::ofstream *svgfile, bool usePsuValue) {
1732 double xp[4], yp[4];
1733 int color;
1734 int greenHV3 = 0;
1735 int redHV3 = 0;
1736 int blueHV3 = 0;
1737 double xd[4], yd[4];
1738 int np = 4;
1739 double boxinitx = 36.5, boxinity = 12;
1740 double dx = 1.1, dy = 1.3;
1741
1742 boxinitx = boxinitx + (5 - psu->getPsuCrate()) * 5;
1743 boxinity = boxinity + (18 - psu->getPsuBoard()) * 1.75;
1744
1745 xp[0] = boxinitx;
1746 yp[0] = boxinity;
1747 xp[1] = boxinitx + dx;
1748 yp[1] = boxinity;
1749 xp[2] = boxinitx + dx;
1750 yp[2] = boxinity + dy;
1751 xp[3] = boxinitx;
1752 yp[3] = boxinity + dy;
1753
1754 for (int j = 0; j < 4; j++) {
1755 xd[j] = xdpixelpsu(xp[j]);
1756 yd[j] = ydpixelpsu(yp[j]);
1757
1758 }
1759
1760 char buffer[20];
1761 sprintf(buffer, "%X", psu->idex);
1762 std::string s = psu->textHV3;
1763 s.erase(s.begin() + s.find("connected"), s.end());
1764
1765 if (psu->redHV3 < 0) {
1766 if (psu->valueHV3 > 0) {
1767 float vals = psu->valueHV3;
1768 std::string nams = "nams_hv3";
1769
1770 color = getcolor(psu->valueHV3, palette);
1771 redHV3 = (color >> 16) & 0xFF;
1772 greenHV3 = (color >> 8) & 0xFF;
1773 blueHV3 = (color) & 0xFF;
1774 if (!print_total)
1775 psu->valueHV3 = psu->valueHV3 * psu->countHV3;
1776 if (temporary_file)
1777 *svgfile << nams << " " << vals << " " << redHV3 << " " << greenHV3 << " " << blueHV3 << " ";
1778 else
1779 *svgfile
1780 << "<svg:polygon detid=\"" << psu->idex << "\" count=\"" << psu->countHV3 << "\" value=\"" << psu->valueHV3
1781 << "\" id=\"" << psu->idex * 10 + 3 << "\" cmodid=\"" << psu->cmodid_HV3
1782 << "\" onclick=\"showData(evt);\" onmouseover=\"showData(evt);\" onmouseout=\"showData(evt);\" MESSAGE=\""
1783 "\" POS=\"easyCrate/easyBoard"
1784 << psu->getPsuCrate() << "/" << psu->getPsuBoard() << " connected to " << s << " \" fill=\"rgb(" << redHV3
1785 << "," << greenHV3 << "," << blueHV3 << ")\" points=\"";
1786 } else {
1787 if (temporary_file)
1788 *svgfile << 0 << " " << 255 << " " << 255 << " " << 255 << " ";
1789 else
1790 *svgfile
1791 << "<svg:polygon detid=\"" << psu->idex << "\" count=\"" << psu->countHV3 << "\" value=\"" << psu->valueHV3
1792 << "\" id=\"" << psu->idex * 10 + 3 << "\" cmodid=\"" << psu->cmodid_HV3
1793 << "\" onclick=\"showData(evt);\" onmouseover=\"showData(evt);\" onmouseout=\"showData(evt);\" MESSAGE=\""
1794 "\" POS=\"easyCrate/easyBoard "
1795 << psu->getPsuCrate() << "/" << psu->getPsuBoard() << " connected to " << s
1796 << " \" fill=\"white\" points=\"";
1797 }
1798 }
1799
1800 else {
1801 if (psu->redHV3 > 255)
1802 psu->redHV3 = 255;
1803 if (psu->greenHV3 > 255)
1804 psu->greenHV3 = 255;
1805 if (psu->blueHV3 > 255)
1806 psu->blueHV3 = 255;
1807 if (temporary_file)
1808 *svgfile << 0 << " " << 0 << " " << psu->redHV3 << " " << psu->greenHV3 << " " << psu->blueHV3 << " ";
1809 else
1810 *svgfile
1811 << "<svg:polygon detid=\"" << psu->idex << "\" count=\"" << psu->countHV3 << "\" value=\"" << psu->valueHV3
1812 << "\" id=\"" << psu->idex * 10 + 3 << "\" cmodid=\"" << psu->cmodid_HV3
1813 << "\" onclick=\"showData(evt);\" onmouseover=\"showData(evt);\" onmouseout=\"showData(evt);\" MESSAGE=\""
1814 "\" POS=\"easyCrate/easyBoard "
1815 << psu->getPsuCrate() << "/" << psu->getPsuBoard() << " connected to " << s << " \" fill=\"rgb("
1816 << psu->redHV3 << "," << psu->greenHV3 << "," << psu->blueHV3 << ")\" points=\"";
1817 }
1818
1819 if (temporary_file)
1820 *svgfile << np << " ";
1821 for (int k = 0; k < np; k++) {
1822 if (temporary_file)
1823 *svgfile << xd[k] << " " << yd[k] << " ";
1824 else
1825 *svgfile << xd[k] << "," << yd[k] << " ";
1826 }
1827 if (temporary_file)
1828 *svgfile << std::endl;
1829 else
1830 *svgfile << "\" />" << std::endl;
1831 }
1832
1833 void TrackerMap::save_as_fectrackermap(
1834 bool print_total, float minval, float maxval, std::string s, int width, int height) {
1835 if (enableFecProcessing) {
1836 std::string filetype = s, outputfilename = s;
1837 std::vector<TPolyLine *> vp;
1838 TGaxis *axis = nullptr;
1839 size_t found = filetype.find_last_of('.');
1840 filetype = filetype.substr(found + 1);
1841 found = outputfilename.find_last_of('.');
1842 outputfilename = outputfilename.substr(0, found);
1843 temporary_file = true;
1844 if (filetype == "xml" || filetype == "svg")
1845 temporary_file = false;
1846 std::ostringstream outs;
1847 minvalue = minval;
1848 maxvalue = maxval;
1849 outs << outputfilename << ".coor";
1850 if (temporary_file)
1851 savefile = new std::ofstream(outs.str().c_str(), std::ios::out);
1852 std::map<int, TmCcu *>::iterator i_ccu;
1853 std::multimap<TmCcu *, TmModule *>::iterator it;
1854 std::pair<std::multimap<TmCcu *, TmModule *>::iterator, std::multimap<TmCcu *, TmModule *>::iterator> ret;
1855
1856 bool useCcuValue = false;
1857
1858 for (i_ccu = ccuMap.begin(); i_ccu != ccuMap.end(); i_ccu++) {
1859 TmCcu *ccu = i_ccu->second;
1860 if (ccu != nullptr) {
1861 if (ccu->count > 0 || ccu->red != -1) {
1862 useCcuValue = true;
1863 break;
1864 }
1865 }
1866 }
1867
1868 if (!useCcuValue)
1869 for (i_ccu = ccuMap.begin(); i_ccu != ccuMap.end(); i_ccu++) {
1870 TmCcu *ccu = i_ccu->second;
1871 if (ccu != nullptr) {
1872 ret = fecModuleMap.equal_range(ccu);
1873 for (it = ret.first; it != ret.second; ++it) {
1874 if ((*it).second->count > 0) {
1875 ccu->value = ccu->value + (*it).second->value;
1876 ccu->count++;
1877 }
1878 }
1879 if (ccu->count > 0)
1880 ccu->value = ccu->value / ccu->count;
1881 if (ccu->nmod == 0) {
1882 ccu->red = 0;
1883 ccu->green = 0;
1884 ccu->blue = 0;
1885 }
1886 }
1887 }
1888
1889 if (title.find("QTestAlarm") != std::string::npos) {
1890 for (i_ccu = ccuMap.begin(); i_ccu != ccuMap.end(); i_ccu++) {
1891 TmCcu *ccu = i_ccu->second;
1892 if (ccu != nullptr) {
1893 ret = fecModuleMap.equal_range(ccu);
1894 ccu->red = 0;
1895 ccu->green = 255;
1896 ccu->blue = 0;
1897 for (it = ret.first; it != ret.second; ++it) {
1898 if (!((*it).second->red == 0 && (*it).second->green == 255 && (*it).second->blue == 0) &&
1899 !((*it).second->red == 255 && (*it).second->green == 255 && (*it).second->blue == 255)) {
1900 ccu->red = 255;
1901 ccu->green = 0;
1902 ccu->blue = 0;
1903 }
1904 }
1905 }
1906 }
1907 }
1908
1909 if (!print_total) {
1910 for (i_ccu = ccuMap.begin(); i_ccu != ccuMap.end(); i_ccu++) {
1911 TmCcu *ccu = i_ccu->second;
1912 if (ccu != nullptr) {
1913 if (useCcuValue)
1914 ccu->value = ccu->value / ccu->count;
1915 }
1916 }
1917 }
1918
1919 if (minvalue >= maxvalue) {
1920 minvalue = 9999999.;
1921 maxvalue = -9999999.;
1922 for (i_ccu = ccuMap.begin(); i_ccu != ccuMap.end(); i_ccu++) {
1923 TmCcu *ccu = i_ccu->second;
1924 if (ccu != nullptr && ccu->count > 0) {
1925 if (minvalue > ccu->value)
1926 minvalue = ccu->value;
1927 if (maxvalue < ccu->value)
1928 maxvalue = ccu->value;
1929 }
1930 }
1931 }
1932
1933 if (filetype == "svg") {
1934 saveAsSingleLayer = false;
1935 std::ostringstream outs;
1936 outs << outputfilename << ".svg";
1937 savefile = new std::ofstream(outs.str().c_str(), std::ios::out);
1938 *savefile << "<?xml version=\"1.0\" standalone=\"no\" ?>" << std::endl;
1939 *savefile << "<svg xmlns=\"http://www.w3.org/2000/svg\"" << std::endl;
1940 *savefile << "xmlns:svg=\"http://www.w3.org/2000/svg\" " << std::endl;
1941 *savefile << "xmlns:xlink=\"http://www.w3.org/1999/xlink\">" << std::endl;
1942 *savefile << "<svg:svg id=\"mainMap\" x=\"0\" y=\"0\" viewBox=\"0 0 3000 1600"
1943 << "\" width=\"" << width << "\" height=\"" << height << "\">" << std::endl;
1944 *savefile << "<svg:rect fill=\"lightblue\" stroke=\"none\" x=\"0\" y=\"0\" width=\"3000\" height=\"1600\" /> "
1945 << std::endl;
1946 *savefile << "<svg:g id=\"fedtrackermap\" transform=\"translate(10,1500) rotate(270)\" "
1947 "style=\"fill:none;stroke:black;stroke-width:0;\"> "
1948 << std::endl;
1949 }
1950 for (int crate = 1; crate < (nfeccrates + 1); crate++) {
1951 if (filetype == "xml") {
1952 saveAsSingleLayer = true;
1953 std::ostringstream outs;
1954 outs << outputfilename << "feccrate" << crate << ".xml";
1955 savefile = new std::ofstream(outs.str().c_str(), std::ios::out);
1956 *savefile << "<?xml version=\"1.0\" standalone=\"no\"?>" << std::endl;
1957 *savefile << "<svg xmlns=\"http://www.w3.org/2000/svg\"" << std::endl;
1958 *savefile << "xmlns:svg=\"http://www.w3.org/2000/svg\"" << std::endl;
1959 *savefile << "xmlns:xlink=\"http://www.w3.org/1999/xlink\" >" << std::endl;
1960 *savefile << "<script type=\"text/ecmascript\" xlink:href=\"feccrate.js\" />" << std::endl;
1961 *savefile << "<svg id=\"mainMap\" x=\"0\" y=\"0\" viewBox=\"0 0 500 500\" width=\"700\" height=\"700\" "
1962 "onload=\"TrackerCrate.init()\">"
1963 << std::endl;
1964 *savefile << "<rect fill=\"lightblue\" stroke=\"none\" x=\"0\" y=\"0\" width=\"700\" height=\"700\" />"
1965 << std::endl;
1966 *savefile << "<g id=\"crate\" transform=\" translate(280,580) rotate(270) scale(.7,.8)\" > " << std::endl;
1967 }
1968
1969 deffecwindow(crate);
1970
1971 for (i_ccu = ccuMap.begin(); i_ccu != ccuMap.end(); i_ccu++) {
1972 TmCcu *ccu = i_ccu->second;
1973 if (ccu != nullptr) {
1974 if (ccu->getCcuCrate() == crate) {
1975 drawCcu(crate, ccu->getCcuSlot() - 2, print_total, ccu, savefile, useCcuValue);
1976 }
1977 }
1978 }
1979
1980 if (!temporary_file) {
1981 if (filetype == "xml") {
1982 *savefile << "</g> </svg> <text id=\"currentElementText\" x=\"40\" y=\"30\"> " << std::endl;
1983 *savefile << "<tspan id=\"line1\" x=\"40\" y=\"30\"> </tspan> " << std::endl;
1984 *savefile << "<tspan id=\"line2\" x=\"40\" y=\"60\"> </tspan> " << std::endl;
1985 *savefile << " </text> </svg>" << std::endl;
1986 savefile->close();
1987 saveAsSingleLayer = false;
1988 }
1989 }
1990 }
1991 if (filetype == "svg") {
1992 *savefile << "</g> </svg> </svg> " << std::endl;
1993 savefile->close();
1994 }
1995 if (!print_total && !useCcuValue) {
1996
1997 for (i_ccu = ccuMap.begin(); i_ccu != ccuMap.end(); i_ccu++) {
1998 TmCcu *ccu = i_ccu->second;
1999 if (ccu != nullptr) {
2000 ccu->value = ccu->value * ccu->count;
2001 }
2002 }
2003 }
2004 if (temporary_file) {
2005 if (printflag && !saveWebInterface)
2006 drawPalette(savefile);
2007 savefile->close();
2008
2009 float content;
2010 std::string named;
2011 const char *command1;
2012 std::string tempfilename = outputfilename + ".coor";
2013 int red, green, blue, npoints, colindex, ncolor;
2014 double x[4], y[4];
2015 std::ifstream tempfile(tempfilename.c_str(), std::ios::in);
2016 TCanvas *MyC = new TCanvas("MyC", "TrackerMap", width, height);
2017 gPad->SetFillColor(38);
2018
2019 if (saveWebInterface)
2020 gPad->Range(0, 0, 3700, 1600);
2021 else
2022 gPad->Range(0, 0, 3800, 1600);
2023
2024
2025 ncolor = 0;
2026 typedef std::map<int, int> ColorList;
2027 ColorList colorList;
2028 ColorList::iterator pos;
2029 TColor *col, *c;
2030 while (!tempfile.eof()) {
2031 tempfile >> named >> content >> red >> green >> blue >> npoints;
2032 colindex = red + green * 1000 + blue * 1000000;
2033 pos = colorList.find(colindex);
2034 if (pos == colorList.end()) {
2035 colorList[colindex] = ncolor + 100;
2036 col = gROOT->GetColor(ncolor + 100);
2037 if (col)
2038 col->SetRGB((Double_t)(red / 255.), (Double_t)(green / 255.), (Double_t)(blue / 255.));
2039 else {
2040 c = new TColor(ncolor + 100, (Double_t)(red / 255.), (Double_t)(green / 255.), (Double_t)(blue / 255.));
2041 vc.push_back(c);
2042 }
2043 ncolor++;
2044 }
2045 for (int i = 0; i < npoints; i++) {
2046 tempfile >> x[i] >> y[i];
2047 }
2048 }
2049 if (ncolor > 0 && ncolor < 10000) {
2050 Int_t colors[10000];
2051 for (int i = 0; i < ncolor; i++) {
2052 colors[i] = i + 100;
2053 }
2054 gStyle->SetPalette(ncolor, colors);
2055 }
2056 tempfile.clear();
2057 tempfile.seekg(0, std::ios::beg);
2058 std::cout << "created palette with " << ncolor << " colors" << std::endl;
2059 while (!tempfile.eof()) {
2060 tempfile >> named >> content >> red >> green >> blue >> npoints;
2061 for (int i = 0; i < npoints; i++) {
2062 tempfile >> x[i] >> y[i];
2063 }
2064 colindex = red + green * 1000 + blue * 1000000;
2065 pos = colorList.find(colindex);
2066 if (pos != colorList.end()) {
2067 TPolyLine *pline = new TPolyLine(npoints, y, x);
2068 vp.push_back(pline);
2069 pline->SetFillColor(colorList[colindex]);
2070 pline->SetLineWidth(0);
2071 pline->Draw("f");
2072 }
2073 }
2074 if (printflag && !saveWebInterface) {
2075 float lminvalue = minvalue;
2076 float lmaxvalue = maxvalue;
2077 if (tkMapLog) {
2078 lminvalue = log(minvalue) / log(10);
2079 lmaxvalue = log(maxvalue) / log(10);
2080 }
2081 axis = new TGaxis(3660, 36, 3660, 1530, lminvalue, lmaxvalue, 510, "+L");
2082 axis->SetLabelSize(0.02);
2083 axis->Draw();
2084 }
2085
2086 if (!saveWebInterface) {
2087 TLatex l;
2088 l.SetTextSize(0.05);
2089 std::string fulltitle = title;
2090 if (tkMapLog && (fulltitle.find("Log10 scale") == std::string::npos))
2091 fulltitle += ": Log10 scale";
2092 l.DrawLatex(50, 1530, fulltitle.c_str());
2093 }
2094 MyC->Update();
2095 std::cout << "Filetype " << filetype << std::endl;
2096 if (filetype == "png") {
2097 std::string filename = outputfilename + ".png";
2098 MyC->Print(filename.c_str());
2099 }
2100 if (filetype == "jpg") {
2101 std::string filename = outputfilename + ".jpg";
2102 MyC->Print(filename.c_str());
2103 }
2104 if (filetype == "pdf") {
2105 std::string filename = outputfilename + ".pdf";
2106 MyC->Print(filename.c_str());
2107 }
2108 std::string command = "rm " + tempfilename;
2109 command1 = command.c_str();
2110 std::cout << "Executing " << command1 << std::endl;
2111 system(command1);
2112 MyC->Clear();
2113 delete MyC;
2114 if (printflag && !saveWebInterface)
2115 delete axis;
2116 for (std::vector<TPolyLine *>::iterator pos1 = vp.begin(); pos1 != vp.end(); pos1++) {
2117 delete (*pos1);
2118 }
2119
2120 }
2121 }
2122 }
2123 void TrackerMap::save_as_HVtrackermap(
2124 bool print_total, float minval, float maxval, std::string s, int width, int height) {
2125 if (enableHVProcessing) {
2126 std::string filetype = s, outputfilename = s;
2127 std::vector<TPolyLine *> vp;
2128 TGaxis *axis = nullptr;
2129 size_t found = filetype.find_last_of('.');
2130 filetype = filetype.substr(found + 1);
2131 found = outputfilename.find_last_of('.');
2132 outputfilename = outputfilename.substr(0, found);
2133
2134 temporary_file = true;
2135
2136 if (filetype == "xml" || filetype == "svg")
2137 temporary_file = false;
2138
2139 std::ostringstream outs;
2140 minvalue = minval;
2141 maxvalue = maxval;
2142 outs << outputfilename << ".coor";
2143 if (temporary_file)
2144 savefile = new std::ofstream(outs.str().c_str(), std::ios::out);
2145
2146 std::map<int, TmPsu *>::iterator ipsu;
2147 std::multimap<TmPsu *, TmModule *>::iterator it;
2148 std::pair<std::multimap<TmPsu *, TmModule *>::iterator, std::multimap<TmPsu *, TmModule *>::iterator> ret;
2149
2150 bool usePsuValue = false;
2151
2152 for (ipsu = psuMap.begin(); ipsu != psuMap.end(); ipsu++) {
2153 TmPsu *psu = ipsu->second;
2154 if (psu != nullptr) {
2155 if (psu->countHV2 > 0 || psu->redHV2 != -1 || psu->countHV3 > 0 || psu->redHV3 != -1) {
2156 usePsuValue = true;
2157 break;
2158 }
2159 }
2160 }
2161
2162 if (!usePsuValue) {
2163
2164 for (ipsu = psuMap.begin(); ipsu != psuMap.end(); ipsu++) {
2165 TmPsu *psu = ipsu->second;
2166 if (psu != nullptr) {
2167 ret = psuModuleMap.equal_range(psu);
2168 int nconn1 = 0;
2169 int nconn2 = 0;
2170 for (it = ret.first; it != ret.second; ++it) {
2171 if ((*it).second->HVchannel == 2 && (*it).second->count > 0) {
2172 nconn1++;
2173 psu->valueHV2 = psu->valueHV2 + (*it).second->value;
2174 }
2175 if ((*it).second->HVchannel == 3 && (*it).second->count > 0) {
2176 nconn2++;
2177 psu->valueHV3 = psu->valueHV3 + (*it).second->value;
2178 }
2179 }
2180 if (psu->nmodHV2 != 0 && nconn1 > 0) {
2181 psu->valueHV2 = psu->valueHV2 / psu->nmodHV2;
2182 psu->countHV2 = 1;
2183 }
2184 if (psu->nmodHV3 != 0 && nconn2 > 0) {
2185 psu->valueHV3 = psu->valueHV3 / psu->nmodHV3;
2186 psu->countHV3 = 1;
2187 }
2188 }
2189 }
2190 }
2191
2192 if (title.find("QTestAlarm") != std::string::npos) {
2193 for (ipsu = psuMap.begin(); ipsu != psuMap.end(); ipsu++) {
2194 TmPsu *psu = ipsu->second;
2195 if (psu != nullptr) {
2196 ret = psuModuleMap.equal_range(psu);
2197 psu->redHV2 = 0;
2198 psu->greenHV2 = 255;
2199 psu->blueHV2 = 0;
2200 psu->redHV3 = 0;
2201 psu->greenHV3 = 255;
2202 psu->blueHV3 = 0;
2203 for (it = ret.first; it != ret.second; ++it) {
2204 if ((*it).second->HVchannel == 2) {
2205 if (!((*it).second->red == 0 && (*it).second->green == 255 && (*it).second->blue == 0) &&
2206 !((*it).second->red == 255 && (*it).second->green == 255 && (*it).second->blue == 255)) {
2207 psu->redHV2 = 255;
2208 psu->greenHV2 = 0;
2209 psu->blueHV2 = 0;
2210 }
2211 }
2212 if ((*it).second->HVchannel == 3) {
2213 if (!((*it).second->red == 0 && (*it).second->green == 255 && (*it).second->blue == 0) &&
2214 !((*it).second->red == 255 && (*it).second->green == 255 && (*it).second->blue == 255)) {
2215 psu->redHV3 = 255;
2216 psu->greenHV3 = 0;
2217 psu->blueHV3 = 0;
2218 }
2219 }
2220 }
2221 }
2222 }
2223 }
2224
2225 if (!print_total) {
2226 for (ipsu = psuMap.begin(); ipsu != psuMap.end(); ipsu++) {
2227 TmPsu *psu = ipsu->second;
2228 if (psu != nullptr) {
2229 if (usePsuValue) {
2230 psu->valueHV2 = psu->valueHV2 / psu->countHV2;
2231 psu->valueHV3 = psu->valueHV3 / psu->countHV3;
2232 }
2233 }
2234 }
2235 }
2236
2237 if (minvalue >= maxvalue) {
2238 minvalue = 9999999.;
2239 maxvalue = -9999999.;
2240
2241 for (ipsu = psuMap.begin(); ipsu != psuMap.end(); ipsu++) {
2242 TmPsu *psu = ipsu->second;
2243 if (psu != nullptr && psu->countHV2 > 0 && psu->countHV3 > 0) {
2244 if (minvalue > psu->valueHV2 || minvalue > psu->valueHV3)
2245 minvalue = std::min(psu->valueHV2, psu->valueHV3);
2246 if (maxvalue < psu->valueHV2 || maxvalue < psu->valueHV3)
2247 maxvalue = std::max(psu->valueHV2, psu->valueHV3);
2248 }
2249 }
2250 }
2251
2252 if (filetype == "svg") {
2253 saveAsSingleLayer = false;
2254 std::ostringstream outs;
2255 outs << outputfilename << ".svg";
2256 savefile = new std::ofstream(outs.str().c_str(), std::ios::out);
2257 *savefile << "<?xml version=\"1.0\" standalone=\"no\" ?>" << std::endl;
2258 *savefile << "<svg xmlns=\"http://www.w3.org/2000/svg\"" << std::endl;
2259 *savefile << "xmlns:svg=\"http://www.w3.org/2000/svg\" " << std::endl;
2260 *savefile << "xmlns:xlink=\"http://www.w3.org/1999/xlink\">" << std::endl;
2261 *savefile << "<svg:svg id=\"mainMap\" x=\"0\" y=\"0\" viewBox=\"0 0 3000 1600"
2262 << "\" width=\"" << width << "\" height=\"" << height << "\">" << std::endl;
2263 *savefile << "<svg:rect fill=\"lightblue\" stroke=\"none\" x=\"0\" y=\"0\" width=\"3000\" height=\"1600\" /> "
2264 << std::endl;
2265 *savefile << "<svg:g id=\"HVtrackermap\" transform=\"translate(10,1500) rotate(270)\" "
2266 "style=\"fill:none;stroke:black;stroke-width:0;\"> "
2267 << std::endl;
2268 }
2269
2270 for (int irack = 1; irack < (npsuracks + 1); irack++) {
2271 if (filetype == "xml") {
2272 saveAsSingleLayer = true;
2273 std::ostringstream outs;
2274 outs << outputfilename << "HVrack" << irack << ".xml";
2275 savefile = new std::ofstream(outs.str().c_str(), std::ios::out);
2276 *savefile << "<?xml version=\"1.0\" standalone=\"no\"?>" << std::endl;
2277 *savefile << "<svg xmlns=\"http://www.w3.org/2000/svg\"" << std::endl;
2278 *savefile << "xmlns:svg=\"http://www.w3.org/2000/svg\"" << std::endl;
2279 *savefile << "xmlns:xlink=\"http://www.w3.org/1999/xlink\" >" << std::endl;
2280 *savefile << "<script type=\"text/ecmascript\" xlink:href=\"rackhv.js\" />" << std::endl;
2281 *savefile << "<svg id=\"mainMap\" x=\"0\" y=\"0\" viewBox=\"0 0 500 500\" width=\"700\" height=\"700\" "
2282 "onload=\"TrackerRackhv.init()\">"
2283 << std::endl;
2284 *savefile << "<rect fill=\"lightblue\" stroke=\"none\" x=\"0\" y=\"0\" width=\"700\" height=\"700\" />"
2285 << std::endl;
2286 *savefile << "<g id=\"rackhv\" transform=\" translate(150,500) rotate(270) scale(1.,1.)\" > " << std::endl;
2287 }
2288
2289
2290 defpsuwindow(irack);
2291 for (ipsu = psuMap.begin(); ipsu != psuMap.end(); ipsu++) {
2292 TmPsu *psu = ipsu->second;
2293 if (psu->getPsuRack() == irack) {
2294 drawHV2(irack, psu->getPsuCrate(), print_total, psu, savefile, usePsuValue);
2295 drawHV3(irack, psu->getPsuCrate(), print_total, psu, savefile, usePsuValue);
2296 }
2297 }
2298
2299 if (!temporary_file) {
2300 if (filetype == "xml") {
2301 *savefile << "</g> </svg> <text id=\"currentElementText\" x=\"40\" y=\"30\"> " << std::endl;
2302 *savefile << "<tspan id=\"line1\" x=\"40\" y=\"30\"> </tspan> " << std::endl;
2303 *savefile << "<tspan id=\"line2\" x=\"40\" y=\"60\"> </tspan> " << std::endl;
2304 *savefile << " </text> </svg>" << std::endl;
2305 savefile->close();
2306 saveAsSingleLayer = false;
2307 }
2308 }
2309 }
2310 if (filetype == "svg") {
2311 *savefile << "</g> </svg> </svg> " << std::endl;
2312 savefile->close();
2313 }
2314
2315
2316 if (!print_total && !usePsuValue) {
2317 for (ipsu = psuMap.begin(); ipsu != psuMap.end(); ipsu++) {
2318 TmPsu *psu = ipsu->second;
2319 if (psu != nullptr) {
2320 psu->valueHV2 = psu->valueHV2 * psu->countHV2;
2321 psu->valueHV3 = psu->valueHV3 * psu->countHV3;
2322 }
2323 }
2324 }
2325
2326 if (temporary_file) {
2327 if (printflag && !saveWebInterface)
2328 drawPalette(savefile);
2329 savefile->close();
2330
2331 float content;
2332 std::string named;
2333 const char *command1;
2334 std::string tempfilename = outputfilename + ".coor";
2335 int red, green, blue, npoints, colindex, ncolor;
2336 double x[4], y[4];
2337 std::ifstream tempfile(tempfilename.c_str(), std::ios::in);
2338 TCanvas *MyC = new TCanvas("MyC", "TrackerMap", width, height);
2339 gPad->SetFillColor(38);
2340
2341 if (saveWebInterface)
2342 gPad->Range(0, 0, 3700, 1600);
2343 else
2344 gPad->Range(0, 0, 3800, 1600);
2345
2346
2347 ncolor = 0;
2348 typedef std::map<int, int> ColorList;
2349 ColorList colorList;
2350 ColorList::iterator pos;
2351 TColor *col, *c;
2352 while (!tempfile.eof()) {
2353 tempfile >> named >> content >> red >> green >> blue >> npoints;
2354 colindex = red + green * 1000 + blue * 1000000;
2355 pos = colorList.find(colindex);
2356 if (pos == colorList.end()) {
2357 colorList[colindex] = ncolor + 100;
2358 col = gROOT->GetColor(ncolor + 100);
2359 if (col)
2360 col->SetRGB((Double_t)(red / 255.), (Double_t)(green / 255.), (Double_t)(blue / 255.));
2361 else {
2362 c = new TColor(ncolor + 100, (Double_t)(red / 255.), (Double_t)(green / 255.), (Double_t)(blue / 255.));
2363 vc.push_back(c);
2364 }
2365 ncolor++;
2366 }
2367 for (int i = 0; i < npoints; i++) {
2368 tempfile >> x[i] >> y[i];
2369 }
2370 }
2371 if (ncolor > 0 && ncolor < 10000) {
2372 Int_t colors[10000];
2373 for (int i = 0; i < ncolor; i++) {
2374 colors[i] = i + 100;
2375 }
2376 gStyle->SetPalette(ncolor, colors);
2377 }
2378 tempfile.clear();
2379 tempfile.seekg(0, std::ios::beg);
2380 std::cout << "created palette with " << ncolor << " colors" << std::endl;
2381 while (!tempfile.eof()) {
2382 tempfile >> named >> content >> red >> green >> blue >> npoints;
2383 for (int i = 0; i < npoints; i++) {
2384 tempfile >> x[i] >> y[i];
2385 }
2386 colindex = red + green * 1000 + blue * 1000000;
2387 pos = colorList.find(colindex);
2388 if (pos != colorList.end()) {
2389 TPolyLine *pline = new TPolyLine(npoints, y, x);
2390 vp.push_back(pline);
2391 pline->SetFillColor(colorList[colindex]);
2392 pline->SetLineWidth(0);
2393 pline->Draw("f");
2394 }
2395 }
2396 if (printflag && !saveWebInterface) {
2397 float lminvalue = minvalue;
2398 float lmaxvalue = maxvalue;
2399 if (tkMapLog) {
2400 lminvalue = log(minvalue) / log(10);
2401 lmaxvalue = log(maxvalue) / log(10);
2402 }
2403 axis = new TGaxis(3660, 36, 3660, 1530, lminvalue, lmaxvalue, 510, "+L");
2404 axis->SetLabelSize(0.02);
2405 axis->Draw();
2406 }
2407
2408 if (!saveWebInterface) {
2409 TLatex l;
2410 l.SetTextSize(0.05);
2411 std::string fulltitle = title;
2412 if (tkMapLog && (fulltitle.find("Log10 scale") == std::string::npos))
2413 fulltitle += ": Log10 scale";
2414 l.DrawLatex(50, 1530, fulltitle.c_str());
2415 }
2416 MyC->Update();
2417 std::cout << "Filetype " << filetype << std::endl;
2418 if (filetype == "png") {
2419 std::string filename = outputfilename + ".png";
2420 MyC->Print(filename.c_str());
2421 }
2422 if (filetype == "jpg") {
2423 std::string filename = outputfilename + ".jpg";
2424 MyC->Print(filename.c_str());
2425 }
2426 if (filetype == "pdf") {
2427 std::string filename = outputfilename + ".pdf";
2428 MyC->Print(filename.c_str());
2429 }
2430 std::string command = "rm " + tempfilename;
2431 command1 = command.c_str();
2432 std::cout << "Executing " << command1 << std::endl;
2433 system(command1);
2434 MyC->Clear();
2435 delete MyC;
2436 if (printflag && !saveWebInterface)
2437 delete axis;
2438 for (std::vector<TPolyLine *>::iterator pos1 = vp.begin(); pos1 != vp.end(); pos1++) {
2439 delete (*pos1);
2440 }
2441
2442 }
2443 }
2444 }
2445
2446 void TrackerMap::save_as_psutrackermap(
2447 bool print_total, float minval, float maxval, std::string s, int width, int height) {
2448 if (enableLVProcessing) {
2449 printflag = true;
2450 bool rangefound = true;
2451 std::string filetype = s, outputfilename = s;
2452 std::vector<TPolyLine *> vp;
2453 TGaxis *axis = nullptr;
2454
2455 size_t found = filetype.find_last_of('.');
2456 filetype = filetype.substr(found + 1);
2457 found = outputfilename.find_last_of('.');
2458 outputfilename = outputfilename.substr(0, found);
2459
2460 temporary_file = true;
2461
2462 if (filetype == "xml" || filetype == "svg")
2463 temporary_file = false;
2464
2465 std::ostringstream outs;
2466 minvalue = minval;
2467 maxvalue = maxval;
2468 outs << outputfilename << ".coor";
2469 if (temporary_file)
2470 savefile = new std::ofstream(outs.str().c_str(), std::ios::out);
2471
2472 std::map<int, TmPsu *>::iterator ipsu;
2473 std::multimap<TmPsu *, TmModule *>::iterator it;
2474 std::pair<std::multimap<TmPsu *, TmModule *>::iterator, std::multimap<TmPsu *, TmModule *>::iterator> ret;
2475
2476
2477 bool usePsuValue = false;
2478
2479 for (ipsu = psuMap.begin(); ipsu != psuMap.end(); ipsu++) {
2480 TmPsu *psu = ipsu->second;
2481 if (psu != nullptr) {
2482 if (psu->count > 0 || psu->red != -1) {
2483 usePsuValue = true;
2484 break;
2485 }
2486 }
2487 }
2488
2489 if (!usePsuValue) {
2490 for (ipsu = psuMap.begin(); ipsu != psuMap.end(); ipsu++) {
2491 TmPsu *psu = ipsu->second;
2492 if (psu != nullptr) {
2493 ret = psuModuleMap.equal_range(psu);
2494 int nconn = 0;
2495 for (it = ret.first; it != ret.second; ++it) {
2496 if ((*it).second->count > 0) {
2497 nconn++;
2498 psu->value = psu->value + (*it).second->value;
2499 }
2500 }
2501 if (nconn > 0) {
2502 psu->value = psu->value / psu->nmod;
2503 psu->count = 1;
2504 }
2505 }
2506 }
2507 }
2508
2509 if (title.find("QTestAlarm") != std::string::npos) {
2510 for (ipsu = psuMap.begin(); ipsu != psuMap.end(); ipsu++) {
2511 TmPsu *psu = ipsu->second;
2512 if (psu != nullptr) {
2513 ret = psuModuleMap.equal_range(psu);
2514
2515 psu->red = -1;
2516 int nconn = 0;
2517 for (it = ret.first; it != ret.second; ++it) {
2518 if (!((*it).second->red == 0 && (*it).second->green == 255 && (*it).second->blue == 0) &&
2519 !((*it).second->red == 255 && (*it).second->green == 255 && (*it).second->blue == 255)) {
2520 nconn++;
2521 psu->value++;
2522 }
2523 }
2524 if (nconn > 0) {
2525 psu->value = psu->value / psu->nmod;
2526 psu->count = 1;
2527 }
2528 }
2529 }
2530 }
2531
2532 if (!print_total) {
2533 for (ipsu = psuMap.begin(); ipsu != psuMap.end(); ipsu++) {
2534 TmPsu *psu = ipsu->second;
2535 if (psu != nullptr) {
2536 if (usePsuValue)
2537 psu->value = psu->value / psu->count;
2538 }
2539 }
2540 }
2541
2542 if (minvalue >= maxvalue) {
2543 minvalue = 9999999.;
2544 maxvalue = -9999999.;
2545 rangefound = false;
2546 for (ipsu = psuMap.begin(); ipsu != psuMap.end(); ipsu++) {
2547 TmPsu *psu = ipsu->second;
2548 if (psu != nullptr && psu->count > 0) {
2549 rangefound = true;
2550 if (minvalue > psu->value)
2551 minvalue = psu->value;
2552 if (maxvalue < psu->value)
2553 maxvalue = psu->value;
2554 }
2555 }
2556 }
2557 if ((maxvalue == minvalue) || !rangefound)
2558 printflag = false;
2559
2560 if (filetype == "svg") {
2561 saveAsSingleLayer = false;
2562 std::ostringstream outs;
2563 outs << outputfilename << ".svg";
2564 savefile = new std::ofstream(outs.str().c_str(), std::ios::out);
2565 *savefile << "<?xml version=\"1.0\" standalone=\"no\" ?>" << std::endl;
2566 *savefile << "<svg xmlns=\"http://www.w3.org/2000/svg\"" << std::endl;
2567 *savefile << "xmlns:svg=\"http://www.w3.org/2000/svg\" " << std::endl;
2568 *savefile << "xmlns:xlink=\"http://www.w3.org/1999/xlink\">" << std::endl;
2569 *savefile << "<svg:svg id=\"mainMap\" x=\"0\" y=\"0\" viewBox=\"0 0 3000 1600"
2570 << "\" width=\"" << width << "\" height=\"" << height << "\">" << std::endl;
2571 *savefile << "<svg:rect fill=\"lightblue\" stroke=\"none\" x=\"0\" y=\"0\" width=\"3000\" height=\"1600\" /> "
2572 << std::endl;
2573 *savefile << "<svg:g id=\"psutrackermap\" transform=\"translate(10,1500) rotate(270)\" "
2574 "style=\"fill:none;stroke:black;stroke-width:0;\"> "
2575 << std::endl;
2576 }
2577
2578 for (int irack = 1; irack < (npsuracks + 1); irack++) {
2579 if (filetype == "xml") {
2580 saveAsSingleLayer = true;
2581 std::ostringstream outs;
2582 outs << outputfilename << "psurack" << irack << ".xml";
2583 savefile = new std::ofstream(outs.str().c_str(), std::ios::out);
2584 *savefile << "<?xml version=\"1.0\" standalone=\"no\"?>" << std::endl;
2585 *savefile << "<svg xmlns=\"http://www.w3.org/2000/svg\"" << std::endl;
2586 *savefile << "xmlns:svg=\"http://www.w3.org/2000/svg\"" << std::endl;
2587 *savefile << "xmlns:xlink=\"http://www.w3.org/1999/xlink\" >" << std::endl;
2588 *savefile << "<script type=\"text/ecmascript\" xlink:href=\"rack.js\" />" << std::endl;
2589 *savefile << "<svg id=\"mainMap\" x=\"0\" y=\"0\" viewBox=\"0 0 500 500\" width=\"700\" height=\"700\" "
2590 "onload=\"TrackerCrate.init()\">"
2591 << std::endl;
2592 *savefile << "<rect fill=\"lightblue\" stroke=\"none\" x=\"0\" y=\"0\" width=\"700\" height=\"700\" />"
2593 << std::endl;
2594 *savefile << "<g id=\"rack\" transform=\" translate(150,500) rotate(270) scale(1.,1.)\" > " << std::endl;
2595 }
2596
2597
2598 defpsuwindow(irack);
2599 for (ipsu = psuMap.begin(); ipsu != psuMap.end(); ipsu++) {
2600 TmPsu *psu = ipsu->second;
2601 if (psu->getPsuRack() == irack) {
2602 drawPsu(irack, psu->getPsuCrate(), print_total, psu, savefile, usePsuValue);
2603 }
2604 }
2605
2606 if (!temporary_file) {
2607 if (filetype == "xml") {
2608 *savefile << "</g> </svg> <text id=\"currentElementText\" x=\"40\" y=\"30\"> " << std::endl;
2609 *savefile << "<tspan id=\"line1\" x=\"40\" y=\"30\"> </tspan> " << std::endl;
2610 *savefile << "<tspan id=\"line2\" x=\"40\" y=\"60\"> </tspan> " << std::endl;
2611 *savefile << " </text> </svg>" << std::endl;
2612 savefile->close();
2613 saveAsSingleLayer = false;
2614 }
2615 }
2616 }
2617 if (filetype == "svg") {
2618 *savefile << "</g> </svg> </svg> " << std::endl;
2619 savefile->close();
2620 }
2621
2622
2623 if (!print_total && !usePsuValue) {
2624 for (ipsu = psuMap.begin(); ipsu != psuMap.end(); ipsu++) {
2625 TmPsu *psu = ipsu->second;
2626 if (psu != nullptr) {
2627 psu->value = psu->value * psu->count;
2628 }
2629 }
2630 }
2631
2632 int rangex = YPSUOFFSET + (YPSURSIZE + YPSUOFFSET) * NUMPSURACK_INROW + 300;
2633 int rangey = XPSUOFFSET + (XPSURSIZE + XPSUOFFSET) * NUMPSURACK_INCOLUMN + 300;
2634
2635 if (temporary_file) {
2636 if (printflag && !saveWebInterface)
2637 drawPalette(savefile, rangex - 140, rangey - 100);
2638 savefile->close();
2639
2640 float content;
2641 std::string named;
2642 const char *command1;
2643 std::string tempfilename = outputfilename + ".coor";
2644 int red, green, blue, npoints, colindex, ncolor;
2645 double x[4], y[4];
2646 std::ifstream tempfile(tempfilename.c_str(), std::ios::in);
2647 TCanvas *MyC = new TCanvas("MyC", "TrackerMap", width, height);
2648 gPad->SetFillColor(38);
2649
2650
2651 std::cout << " range x " << rangex << std::endl;
2652 std::cout << " range y " << rangey << std::endl;
2653 gPad->Range(0, 0, rangex, rangey);
2654
2655
2656 ncolor = 0;
2657 typedef std::map<int, int> ColorList;
2658 ColorList colorList;
2659 ColorList::iterator pos;
2660 TColor *col, *c;
2661 while (!tempfile.eof()) {
2662 tempfile >> named >> content >> red >> green >> blue >> npoints;
2663 colindex = red + green * 1000 + blue * 1000000;
2664 pos = colorList.find(colindex);
2665 if (pos == colorList.end()) {
2666 colorList[colindex] = ncolor + 100;
2667 col = gROOT->GetColor(ncolor + 100);
2668 if (col)
2669 col->SetRGB((Double_t)(red / 255.), (Double_t)(green / 255.), (Double_t)(blue / 255.));
2670 else
2671 c = new TColor(ncolor + 100, (Double_t)(red / 255.), (Double_t)(green / 255.), (Double_t)(blue / 255.));
2672 vc.push_back(c);
2673 ncolor++;
2674 }
2675 for (int i = 0; i < npoints; i++) {
2676 tempfile >> x[i] >> y[i];
2677 }
2678 }
2679 if (ncolor > 0 && ncolor < 10000) {
2680 Int_t colors[10000];
2681 for (int i = 0; i < ncolor; i++) {
2682 colors[i] = i + 100;
2683 }
2684 gStyle->SetPalette(ncolor, colors);
2685 }
2686 tempfile.clear();
2687 tempfile.seekg(0, std::ios::beg);
2688 std::cout << "created palette with " << ncolor << " colors" << std::endl;
2689 while (!tempfile.eof()) {
2690 tempfile >> named >> content >> red >> green >> blue >> npoints;
2691 for (int i = 0; i < npoints; i++) {
2692 tempfile >> x[i] >> y[i];
2693 }
2694 colindex = red + green * 1000 + blue * 1000000;
2695 pos = colorList.find(colindex);
2696 if (pos != colorList.end()) {
2697 TPolyLine *pline = new TPolyLine(npoints, y, x);
2698 vp.push_back(pline);
2699 pline->SetFillColor(colorList[colindex]);
2700 pline->SetLineWidth(0);
2701 pline->Draw("f");
2702 }
2703 }
2704 if (printflag && !saveWebInterface) {
2705 float lminvalue = minvalue;
2706 float lmaxvalue = maxvalue;
2707 if (tkMapLog) {
2708 lminvalue = log(minvalue) / log(10);
2709 lmaxvalue = log(maxvalue) / log(10);
2710 }
2711 axis = new TGaxis(rangex - 140, 34, rangex - 140, rangey - 106, lminvalue, lmaxvalue, 510, "+L");
2712 axis->SetLabelSize(0.02);
2713 axis->Draw();
2714 }
2715
2716 if (!saveWebInterface) {
2717 TLatex l;
2718 l.SetTextSize(0.05);
2719 std::string fulltitle = title;
2720 if (tkMapLog && (fulltitle.find("Log10 scale") == std::string::npos))
2721 fulltitle += ": Log10 scale";
2722 l.DrawLatex(50, rangey - 200, fulltitle.c_str());
2723 }
2724 MyC->Update();
2725 std::cout << "Filetype " << filetype << std::endl;
2726 if (filetype == "png") {
2727 std::string filename = outputfilename + ".png";
2728 MyC->Print(filename.c_str());
2729 }
2730 if (filetype == "jpg") {
2731 std::string filename = outputfilename + ".jpg";
2732 MyC->Print(filename.c_str());
2733 }
2734 if (filetype == "pdf") {
2735 std::string filename = outputfilename + ".pdf";
2736 MyC->Print(filename.c_str());
2737 }
2738 std::string command = "rm " + tempfilename;
2739 command1 = command.c_str();
2740 std::cout << "Executing " << command1 << std::endl;
2741 system(command1);
2742 MyC->Clear();
2743 delete MyC;
2744 if (printflag && !saveWebInterface)
2745 delete axis;
2746 for (std::vector<TPolyLine *>::iterator pos1 = vp.begin(); pos1 != vp.end(); pos1++) {
2747 delete (*pos1);
2748 }
2749
2750 }
2751 }
2752 }
2753
2754 void TrackerMap::save_as_fedtrackermap(
2755 bool print_total, float minval, float maxval, std::string s, int width, int height) {
2756 if (enableFedProcessing) {
2757 printflag = true;
2758 bool rangefound = true;
2759 std::string filetype = s, outputfilename = s;
2760 std::vector<TPolyLine *> vp;
2761 TGaxis *axis = nullptr;
2762
2763 size_t found = filetype.find_last_of('.');
2764 filetype = filetype.substr(found + 1);
2765 found = outputfilename.find_last_of('.');
2766 outputfilename = outputfilename.substr(0, found);
2767
2768 temporary_file = true;
2769 if (filetype == "xml" || filetype == "svg")
2770 temporary_file = false;
2771 std::ostringstream outs;
2772 minvalue = minval;
2773 maxvalue = maxval;
2774 outs << outputfilename << ".coor";
2775 if (temporary_file)
2776 savefile = new std::ofstream(outs.str().c_str(), std::ios::out);
2777 std::map<int, TmApvPair *>::iterator i_apv;
2778 std::map<int, int>::iterator i_fed;
2779
2780 bool useApvPairValue = false;
2781 for (i_apv = apvMap.begin(); i_apv != apvMap.end(); i_apv++) {
2782 TmApvPair *apvPair = i_apv->second;
2783 if (apvPair != nullptr) {
2784 TmModule *apv_mod = apvPair->mod;
2785 if (apv_mod != nullptr && !apv_mod->notInUse()) {
2786 if (apvPair->count > 0 || apvPair->red != -1) {
2787 useApvPairValue = true;
2788 break;
2789 }
2790 }
2791 }
2792 }
2793 if (!print_total) {
2794 for (i_apv = apvMap.begin(); i_apv != apvMap.end(); i_apv++) {
2795 TmApvPair *apvPair = i_apv->second;
2796 if (apvPair != nullptr) {
2797 TmModule *apv_mod = apvPair->mod;
2798 if (apv_mod != nullptr && !apv_mod->notInUse()) {
2799 if (useApvPairValue)
2800 apvPair->value = apvPair->value / apvPair->count;
2801 else if (apvPair->mpos == 0 && apv_mod->count > 0)
2802 apv_mod->value = apv_mod->value / apv_mod->count;
2803 }
2804 }
2805 }
2806 }
2807 if (minvalue >= maxvalue) {
2808 minvalue = 9999999.;
2809 maxvalue = -9999999.;
2810 rangefound = false;
2811 for (i_apv = apvMap.begin(); i_apv != apvMap.end(); i_apv++) {
2812 TmApvPair *apvPair = i_apv->second;
2813 if (apvPair != nullptr) {
2814 TmModule *apv_mod = apvPair->mod;
2815 if (apv_mod != nullptr && !apv_mod->notInUse()) {
2816 if (useApvPairValue) {
2817 rangefound = true;
2818 if (minvalue > apvPair->value)
2819 minvalue = apvPair->value;
2820 if (maxvalue < apvPair->value)
2821 maxvalue = apvPair->value;
2822 } else {
2823 if (apv_mod->count > 0) {
2824 rangefound = true;
2825 if (minvalue > apv_mod->value)
2826 minvalue = apv_mod->value;
2827 if (maxvalue < apv_mod->value)
2828 maxvalue = apv_mod->value;
2829 }
2830 }
2831 }
2832 }
2833 }
2834 }
2835 if ((title.find("QTestAlarm") != std::string::npos) || (maxvalue == minvalue) || !rangefound)
2836 printflag = false;
2837
2838 if (filetype == "svg") {
2839 saveAsSingleLayer = false;
2840 std::ostringstream outs;
2841 outs << outputfilename << ".svg";
2842 savefile = new std::ofstream(outs.str().c_str(), std::ios::out);
2843 *savefile << "<?xml version=\"1.0\" standalone=\"no\" ?>" << std::endl;
2844 *savefile << "<svg xmlns=\"http://www.w3.org/2000/svg\"" << std::endl;
2845 *savefile << "xmlns:svg=\"http://www.w3.org/2000/svg\" " << std::endl;
2846 *savefile << "xmlns:xlink=\"http://www.w3.org/1999/xlink\">" << std::endl;
2847 *savefile << "<svg:svg id=\"mainMap\" x=\"0\" y=\"0\" viewBox=\"0 0 3000 1600"
2848 << "\" width=\"" << width << "\" height=\"" << height << "\">" << std::endl;
2849 *savefile << "<svg:rect fill=\"lightblue\" stroke=\"none\" x=\"0\" y=\"0\" width=\"3000\" height=\"1600\" /> "
2850 << std::endl;
2851 *savefile << "<svg:g id=\"fedtrackermap\" transform=\"translate(10,1500) rotate(270)\" "
2852 "style=\"fill:none;stroke:black;stroke-width:0;\"> "
2853 << std::endl;
2854 }
2855 for (int crate = firstcrate; crate < (ncrates + 1); crate++) {
2856 if (filetype == "xml") {
2857 saveAsSingleLayer = true;
2858 std::ostringstream outs;
2859 outs << outputfilename << "crate" << crate << ".xml";
2860 savefile = new std::ofstream(outs.str().c_str(), std::ios::out);
2861 *savefile << "<?xml version=\"1.0\" standalone=\"no\"?>" << std::endl;
2862 *savefile << "<svg xmlns=\"http://www.w3.org/2000/svg\"" << std::endl;
2863 *savefile << "xmlns:svg=\"http://www.w3.org/2000/svg\"" << std::endl;
2864 *savefile << "xmlns:xlink=\"http://www.w3.org/1999/xlink\" >" << std::endl;
2865 *savefile << "<script type=\"text/ecmascript\" xlink:href=\"crate.js\" />" << std::endl;
2866 *savefile << "<svg id=\"mainMap\" x=\"0\" y=\"0\" viewBox=\"0 0 500 500\" width=\"700\" height=\"700\" "
2867 "onload=\"TrackerCrate.init()\">"
2868 << std::endl;
2869 *savefile << "<rect fill=\"lightblue\" stroke=\"none\" x=\"0\" y=\"0\" width=\"700\" height=\"700\" />"
2870 << std::endl;
2871 *savefile << "<g id=\"crate\" transform=\" translate(150,500) rotate(270) scale(1.,1.)\" > " << std::endl;
2872 }
2873
2874 defcwindow(crate);
2875 int numfed_incrate = 0;
2876 for (i_fed = fedMap.begin(); i_fed != fedMap.end(); i_fed++) {
2877 if (i_fed->second == crate) {
2878 int fedId = i_fed->first;
2879
2880 numfed_incrate = slotMap[fedId];
2881
2882
2883
2884
2885
2886
2887
2888
2889
2890
2891
2892
2893
2894
2895
2896 for (int nconn = 0; nconn < 96; nconn++) {
2897 int key = fedId * 1000 + nconn;
2898 TmApvPair *apvPair = apvMap[key];
2899 if (apvPair != nullptr) {
2900 TmModule *apv_mod = apvPair->mod;
2901 if (apv_mod != nullptr && !apv_mod->notInUse()) {
2902 drawApvPair(crate, numfed_incrate, print_total, apvPair, savefile, useApvPairValue);
2903 }
2904 }
2905 }
2906 }
2907 }
2908 if (!temporary_file) {
2909 if (filetype == "xml") {
2910 *savefile << "</g> </svg> <text id=\"currentElementText\" x=\"40\" y=\"30\"> " << std::endl;
2911 *savefile << "<tspan id=\"line1\" x=\"40\" y=\"30\"> </tspan> " << std::endl;
2912 *savefile << "<tspan id=\"line2\" x=\"40\" y=\"60\"> </tspan> " << std::endl;
2913 *savefile << " </text> </svg>" << std::endl;
2914 savefile->close();
2915 delete savefile;
2916 saveAsSingleLayer = false;
2917 }
2918 }
2919 }
2920 if (filetype == "svg") {
2921
2922 [[clang::suppress]] * savefile << "</g> </svg> </svg> " << std::endl;
2923 savefile->close();
2924 delete savefile;
2925 }
2926 if (!print_total && !useApvPairValue) {
2927
2928 for (i_apv = apvMap.begin(); i_apv != apvMap.end(); i_apv++) {
2929 TmApvPair *apvPair = i_apv->second;
2930 if (apvPair != nullptr) {
2931 TmModule *apv_mod = apvPair->mod;
2932 if (apv_mod != nullptr && apvPair->mpos == 0 && !apv_mod->notInUse()) {
2933 apv_mod->value = apv_mod->value * apv_mod->count;
2934 }
2935 }
2936 }
2937 }
2938
2939 int rangex = YFEDOFFSET + (YFEDCSIZE + YFEDOFFSET) * NUMFEDCRATE_INROW + 300;
2940 int rangey = XFEDOFFSET + (XFEDCSIZE + XFEDOFFSET) * NUMFEDCRATE_INCOLUMN + 300;
2941
2942 if (temporary_file) {
2943 if (printflag && !saveWebInterface)
2944
2945 [[clang::suppress]]
2946 drawPalette(savefile, rangex - 140, rangey - 100);
2947 [[clang::suppress]] savefile->close();
2948 [[clang::suppress]] delete savefile;
2949
2950 float content;
2951 std::string named;
2952 const char *command1;
2953 std::string tempfilename = outputfilename + ".coor";
2954 int red, green, blue, npoints, colindex, ncolor;
2955 double x[4], y[4];
2956 std::ifstream tempfile(tempfilename.c_str(), std::ios::in);
2957 TCanvas *MyC = new TCanvas("MyC", "TrackerMap", width, height);
2958 gPad->SetFillColor(38);
2959
2960
2961 std::cout << " range x " << rangex << std::endl;
2962 std::cout << " range y " << rangey << std::endl;
2963 gPad->Range(0, 0, rangex, rangey);
2964
2965
2966 ncolor = 0;
2967 typedef std::map<int, int> ColorList;
2968 ColorList colorList;
2969 ColorList::iterator pos;
2970 TColor *col, *c;
2971 while (!tempfile.eof()) {
2972 tempfile >> named >> content >> red >> green >> blue >> npoints;
2973 colindex = red + green * 1000 + blue * 1000000;
2974 pos = colorList.find(colindex);
2975 if (pos == colorList.end()) {
2976 colorList[colindex] = ncolor + 100;
2977 col = gROOT->GetColor(ncolor + 100);
2978 if (col)
2979 col->SetRGB((Double_t)(red / 255.), (Double_t)(green / 255.), (Double_t)(blue / 255.));
2980 else
2981 c = new TColor(ncolor + 100, (Double_t)(red / 255.), (Double_t)(green / 255.), (Double_t)(blue / 255.));
2982 vc.push_back(c);
2983 ncolor++;
2984 }
2985 for (int i = 0; i < npoints; i++) {
2986 tempfile >> x[i] >> y[i];
2987 }
2988 }
2989 if (ncolor > 0 && ncolor < 10000) {
2990 Int_t colors[10000];
2991 for (int i = 0; i < ncolor; i++) {
2992 colors[i] = i + 100;
2993 }
2994 gStyle->SetPalette(ncolor, colors);
2995 }
2996 tempfile.clear();
2997 tempfile.seekg(0, std::ios::beg);
2998 std::cout << "created palette with " << ncolor << " colors" << std::endl;
2999 while (!tempfile.eof()) {
3000 tempfile >> named >> content >> red >> green >> blue >> npoints;
3001 for (int i = 0; i < npoints; i++) {
3002 tempfile >> x[i] >> y[i];
3003 }
3004 colindex = red + green * 1000 + blue * 1000000;
3005 pos = colorList.find(colindex);
3006 if (pos != colorList.end()) {
3007 TPolyLine *pline = new TPolyLine(npoints, y, x);
3008 vp.push_back(pline);
3009 pline->SetFillColor(colorList[colindex]);
3010 pline->SetLineWidth(0);
3011 pline->Draw("f");
3012 }
3013 }
3014 if (printflag && !saveWebInterface) {
3015 float lminvalue = minvalue;
3016 float lmaxvalue = maxvalue;
3017 if (tkMapLog) {
3018 lminvalue = log(minvalue) / log(10);
3019 lmaxvalue = log(maxvalue) / log(10);
3020 }
3021 axis = new TGaxis(rangex - 140, 34, rangex - 140, rangey - 106, lminvalue, lmaxvalue, 510, "+L");
3022 axis->SetLabelSize(0.02);
3023 axis->Draw();
3024 }
3025
3026 if (!saveWebInterface) {
3027 TLatex l;
3028 l.SetTextSize(0.05);
3029 std::string fulltitle = title;
3030 if (tkMapLog && (fulltitle.find("Log10 scale") == std::string::npos))
3031 fulltitle += ": Log10 scale";
3032 l.DrawLatex(50, rangey - 200, fulltitle.c_str());
3033 }
3034 MyC->Update();
3035 std::cout << "Filetype " << filetype << std::endl;
3036 if (filetype == "png") {
3037 std::string filename = outputfilename + ".png";
3038 MyC->Print(filename.c_str());
3039 }
3040 if (filetype == "jpg") {
3041 std::string filename = outputfilename + ".jpg";
3042 MyC->Print(filename.c_str());
3043 }
3044 if (filetype == "pdf") {
3045 std::string filename = outputfilename + ".pdf";
3046 MyC->Print(filename.c_str());
3047 }
3048 std::string command = "rm " + tempfilename;
3049 command1 = command.c_str();
3050 std::cout << "Executing " << command1 << std::endl;
3051 system(command1);
3052 MyC->Clear();
3053 delete MyC;
3054 if (printflag && !saveWebInterface)
3055 delete axis;
3056 for (std::vector<TPolyLine *>::iterator pos1 = vp.begin(); pos1 != vp.end(); pos1++) {
3057 delete (*pos1);
3058 }
3059
3060 }
3061 }
3062 }
3063
3064 void TrackerMap::load(std::string inputfilename) {
3065 inputfile = new std::ifstream(inputfilename.c_str(), std::ios::in);
3066 std::string line, value;
3067 int ipos, ipos1, ipos2, id = 0, val = 0;
3068 int nline = 0;
3069 while (getline(*inputfile, line)) {
3070 ipos1 = line.find("value=\"");
3071 if (ipos1 > 0) {
3072 value = line.substr(ipos1 + 7, 10);
3073 ipos = value.find('\"');
3074 value = value.substr(0, ipos);
3075 val = atoi(value.c_str());
3076 }
3077 ipos2 = line.find("detid=\"");
3078 if (ipos2 > 0) {
3079 value = line.substr(ipos2 + 7, 10);
3080 ipos = value.find('\"');
3081 value = value.substr(0, ipos);
3082 id = atoi(value.c_str());
3083 }
3084 if (ipos1 > 0 && ipos2 > 0 && val > 0)
3085 this->fill(id, val);
3086 if (ipos1 > 0 && ipos2 > 0)
3087 nline++;
3088
3089 }
3090 std::cout << nline << " modules found in this svg file " << std::endl;
3091 inputfile->close();
3092 delete inputfile;
3093 }
3094
3095
3096
3097
3098 void TrackerMap::print(bool print_total, float minval, float maxval, std::string outputfilename) {
3099 temporary_file = false;
3100 std::ostringstream outs;
3101 minvalue = minval;
3102 maxvalue = maxval;
3103 outs << outputfilename << ".xml";
3104 svgfile = new std::ofstream(outs.str().c_str(), std::ios::out);
3105 jsfile = new std::ifstream(edm::FileInPath(jsfilename).fullPath().c_str(), std::ios::in);
3106
3107
3108 std::string line;
3109 while (getline(*jsfile, line)) {
3110 *svgfile << line << std::endl;
3111 }
3112 jsfile->close();
3113 delete jsfile;
3114
3115 if (!print_total) {
3116 for (int layer = 1; layer < 44; layer++) {
3117 for (int ring = firstRing[layer - 1]; ring < ntotRing[layer - 1] + firstRing[layer - 1]; ring++) {
3118 for (int module = 1; module < 200; module++) {
3119 int key = layer * 100000 + ring * 1000 + module;
3120 TmModule *mod = smoduleMap[key];
3121 if (mod != nullptr && !mod->notInUse()) {
3122 mod->value = mod->value / mod->count;
3123 }
3124 }
3125 }
3126 }
3127 }
3128 if (minvalue >= maxvalue) {
3129 minvalue = 9999999.;
3130 maxvalue = -9999999.;
3131 for (int layer = 1; layer < 44; layer++) {
3132 for (int ring = firstRing[layer - 1]; ring < ntotRing[layer - 1] + firstRing[layer - 1]; ring++) {
3133 for (int module = 1; module < 200; module++) {
3134 int key = layer * 100000 + ring * 1000 + module;
3135 TmModule *mod = smoduleMap[key];
3136 if (mod != nullptr && !mod->notInUse()) {
3137 if (minvalue > mod->value)
3138 minvalue = mod->value;
3139 if (maxvalue < mod->value)
3140 maxvalue = mod->value;
3141 }
3142 }
3143 }
3144 }
3145 }
3146 for (int layer = 1; layer < 44; layer++) {
3147
3148 defwindow(layer);
3149 for (int ring = firstRing[layer - 1]; ring < ntotRing[layer - 1] + firstRing[layer - 1]; ring++) {
3150 for (int module = 1; module < 200; module++) {
3151 int key = layer * 100000 + ring * 1000 + module;
3152 TmModule *mod = smoduleMap[key];
3153 if (mod != nullptr && !mod->notInUse()) {
3154 drawModule(mod, key, layer, print_total, svgfile);
3155 }
3156 }
3157 }
3158 }
3159 *svgfile << "</svg:g></svg:svg>" << std::endl;
3160 *svgfile << " <svg:text id=\"Title\" class=\"normalText\" x=\"300\" y=\"0\">" << title << "</svg:text>" << std::endl;
3161 if (printflag)
3162 drawPalette(svgfile);
3163 *svgfile << "</svg:svg>" << std::endl;
3164 *svgfile << "</body></html>" << std::endl;
3165 svgfile->close();
3166 delete svgfile;
3167 }
3168
3169 void TrackerMap::drawPalette(std::ofstream *svgfile, int xoffset, int yoffset) {
3170 std::cout << "preparing the palette" << std::endl;
3171
3172 int color, red, green, blue;
3173 float val = minvalue;
3174 int paletteLength = 250;
3175 int width = 50 * (yoffset - 40) / 1500;
3176 float dval = (maxvalue - minvalue) / (float)paletteLength;
3177 bool rtkMapLog = tkMapLog;
3178 if (tkMapLog)
3179 tkMapLog = false;
3180 float step = float(yoffset - 40) / float(paletteLength);
3181 for (int i = 1; i < paletteLength + 1; i++) {
3182 color = getcolor(val, palette);
3183 red = (color >> 16) & 0xFF;
3184 green = (color >> 8) & 0xFF;
3185 blue = (color) & 0xFF;
3186
3187
3188
3189
3190
3191
3192
3193
3194
3195
3196 if (!temporary_file)
3197 *svgfile << "<svg:rect x=\"3610\" y=\"" << (1550 - 6 * i) << "\" width=\"50\" height=\"6\" fill=\"rgb(" << red
3198 << "," << green << "," << blue << ")\" />\n";
3199 else
3200 *svgfile << 0 << " " << 0 << " " << red << " " << green << " " << blue << " 4 " << int(step * i) + 34 << " "
3201 << xoffset - width << ". " <<
3202 int(step * i) + 34 << " " << xoffset << ". " <<
3203 int(step * (i - 1)) + 34 << " " << xoffset << ". " <<
3204 int(step * (i - 1)) + 34 << " " << xoffset - width << ". " << std::endl;
3205
3206 if (i % 50 == 0) {
3207 if (!temporary_file)
3208 *svgfile << "<svg:rect x=\"3610\" y=\"" << (1550 - 6 * i)
3209 << "\" width=\"50\" height=\"1\" fill=\"black\" />\n";
3210 if (i % 50 == 0 && !temporary_file)
3211 *svgfile << " <svg:text class=\"normalText\" x=\"3660\" y=\"" << (1560 - 6 * i) << "\">" << val
3212 << "</svg:text>" << std::endl;
3213 }
3214 val = val + dval;
3215 }
3216 tkMapLog = rtkMapLog;
3217 }
3218 void TrackerMap::fillc_fed_channel(int fedId, int fedCh, int red, int green, int blue) {
3219 int key = fedId * 1000 + fedCh;
3220 TmApvPair *apvpair = apvMap[key];
3221
3222 if (apvpair != nullptr) {
3223 apvpair->red = red;
3224 apvpair->green = green;
3225 apvpair->blue = blue;
3226 return;
3227 }
3228 std::cout << "*** error in FedTrackerMap fillc method ***";
3229 }
3230
3231 void TrackerMap::fill_fed_channel(int idmod, float qty) {
3232 std::multimap<const int, TmApvPair *>::iterator pos;
3233 for (pos = apvModuleMap.lower_bound(idmod); pos != apvModuleMap.upper_bound(idmod); ++pos) {
3234 TmApvPair *apvpair = pos->second;
3235 if (apvpair != nullptr) {
3236 apvpair->value = apvpair->value + qty;
3237 apvpair->count++;
3238 }
3239 }
3240 return;
3241 std::cout << "*** error in FedTrackerMap fill by module method ***";
3242 }
3243
3244 void TrackerMap::fill_current_val_fed_channel(int fedId, int fedCh, float current_val) {
3245 int key = fedId * 1000 + fedCh;
3246 TmApvPair *apvpair = apvMap[key];
3247
3248 if (apvpair != nullptr) {
3249 apvpair->value = current_val;
3250 apvpair->count = 1;
3251 apvpair->red = -1;
3252 } else
3253 std::cout << "*** error in FedTrackerMap fill_current_val method ***";
3254 }
3255
3256 void TrackerMap::fillc_fec_channel(int crate, int slot, int ring, int addr, int red, int green, int blue) {
3257 int key = crate * 10000000 + slot * 100000 + ring * 1000 + addr;
3258
3259 TmCcu *ccu = ccuMap[key];
3260
3261 if (ccu != nullptr) {
3262 ccu->red = red;
3263 ccu->green = green;
3264 ccu->blue = blue;
3265 return;
3266 }
3267 std::cout << "*** error in FecTrackerMap fillc method ***";
3268 }
3269
3270 void TrackerMap::fill_fec_channel(int crate, int slot, int ring, int addr, float qty) {
3271 int key = crate * 10000000 + slot * 100000 + ring * 1000 + addr;
3272 TmCcu *ccu = ccuMap[key];
3273 if (ccu != nullptr) {
3274 ccu->count++;
3275 ccu->value = ccu->value + qty;
3276 return;
3277 }
3278
3279 std::cout << "*** error in FecTrackerMap fill by module method ***";
3280 }
3281
3282 void TrackerMap::fillc_lv_channel(int rack, int crate, int board, int red, int green, int blue) {
3283 int key = rack * 1000 + crate * 100 + board;
3284
3285 TmPsu *psu = psuMap[key];
3286
3287 if (psu != nullptr) {
3288 psu->red = red;
3289 psu->green = green;
3290 psu->blue = blue;
3291 return;
3292 }
3293 std::cout << "*** error in LVTrackerMap fillc method ***";
3294 }
3295
3296 void TrackerMap::fill_lv_channel(int rack, int crate, int board, float qty) {
3297 int key = rack * 1000 + crate * 100 + board;
3298 TmPsu *psu = psuMap[key];
3299 if (psu != nullptr) {
3300 psu->count++;
3301 psu->value = psu->value + qty;
3302 return;
3303 }
3304
3305 std::cout << "*** error in LVTrackerMap fill by module method ***";
3306 }
3307
3308 void TrackerMap::fillc_hv_channel2(int rack, int crate, int board, int red, int green, int blue) {
3309 int key = rack * 1000 + crate * 100 + board;
3310
3311 TmPsu *psu = psuMap[key];
3312
3313 if (psu != nullptr) {
3314 psu->redHV2 = red;
3315 psu->greenHV2 = green;
3316 psu->blueHV2 = blue;
3317 return;
3318 }
3319 std::cout << "*** error in HVTrackerMap (channel 2) fillc method ***";
3320 }
3321 void TrackerMap::fillc_hv_channel3(int rack, int crate, int board, int red, int green, int blue) {
3322 int key = rack * 1000 + crate * 100 + board;
3323
3324 TmPsu *psu = psuMap[key];
3325
3326 if (psu != nullptr) {
3327 psu->redHV3 = red;
3328 psu->greenHV3 = green;
3329 psu->blueHV3 = blue;
3330 return;
3331 }
3332 std::cout << "*** error in HVTrackerMap (channel 3) fillc method ***";
3333 }
3334
3335 void TrackerMap::fill_hv_channel2(int rack, int crate, int board, float qty) {
3336 int key = rack * 1000 + crate * 100 + board;
3337 TmPsu *psu = psuMap[key];
3338 if (psu != nullptr) {
3339 psu->countHV2++;
3340 psu->valueHV2 = psu->valueHV2 + qty;
3341 return;
3342 }
3343
3344 std::cout << "*** error in HVTrackerMap fill by module method ***";
3345 }
3346 void TrackerMap::fill_hv_channel3(int rack, int crate, int board, float qty) {
3347 int key = rack * 1000 + crate * 100 + board;
3348 TmPsu *psu = psuMap[key];
3349 if (psu != nullptr) {
3350 psu->countHV3++;
3351 psu->valueHV3 = psu->valueHV3 + qty;
3352 return;
3353 }
3354
3355 std::cout << "*** error in HVTrackerMap fill by module method ***";
3356 }
3357
3358 int TrackerMap::module(int fedId, int fedCh) {
3359 int key = fedId * 1000 + fedCh;
3360 TmApvPair *apvpair = apvMap[key];
3361 if (apvpair != nullptr) {
3362 return (apvpair->mod->idex);
3363 }
3364 return (0);
3365 }
3366 void TrackerMap::fill_fed_channel(int fedId, int fedCh, float qty) {
3367 int key = fedId * 1000 + fedCh;
3368 TmApvPair *apvpair = apvMap[key];
3369 if (apvpair != nullptr) {
3370 apvpair->value = apvpair->value + qty;
3371 apvpair->count++;
3372 return;
3373 }
3374 std::cout << "*** error inFedTrackerMap fill method ***";
3375 }
3376
3377 void TrackerMap::fillc(int idmod, int red, int green, int blue) {
3378 TmModule *mod = imoduleMap[idmod];
3379 if (mod != nullptr) {
3380 mod->red = red;
3381 mod->green = green;
3382 mod->blue = blue;
3383 return;
3384 }
3385 std::cout << "**************************error in fill method **************module " << idmod << std::endl;
3386 }
3387 void TrackerMap::fillc(int layer, int ring, int nmod, int red, int green, int blue) {
3388 int key = layer * 10000 + ring * 1000 + nmod;
3389 TmModule *mod = smoduleMap[key];
3390
3391 if (mod != nullptr) {
3392 mod->red = red;
3393 mod->green = green;
3394 mod->blue = blue;
3395 return;
3396 }
3397 std::cout << "**************************error in fill method **************" << std::endl;
3398 }
3399
3400 void TrackerMap::fillc_all_blank() {
3401 std::map<const int, TmModule *>::iterator imod;
3402 for (imod = imoduleMap.begin(); imod != imoduleMap.end(); imod++) {
3403 fillc(imod->first, 255, 255, 255);
3404 }
3405 }
3406
3407 void TrackerMap::fill_all_blank() {
3408 std::map<const int, TmModule *>::iterator imod;
3409 for (imod = imoduleMap.begin(); imod != imoduleMap.end(); imod++) {
3410 fill_current_val(imod->first, 0);
3411 }
3412 }
3413
3414 void TrackerMap::fill_current_val(int idmod, float current_val) {
3415 TmModule *mod = imoduleMap[idmod];
3416 if (mod != nullptr) {
3417 mod->value = current_val;
3418 mod->count = 1;
3419 mod->red = -1;
3420 } else
3421 std::cout << "**error in fill_current_val method ***module " << idmod << std::endl;
3422 }
3423
3424 void TrackerMap::fill(int idmod, float qty) {
3425 TmModule *mod = imoduleMap[idmod];
3426 if (mod != nullptr) {
3427 mod->value = mod->value + qty;
3428 mod->count++;
3429 return;
3430 } else {
3431 TmModule *mod1 = imoduleMap[idmod + 1];
3432 TmModule *mod2 = imoduleMap[idmod + 2];
3433 if (mod1 != nullptr && mod2 != nullptr) {
3434 mod1->value = mod1->value + qty;
3435 mod1->count++;
3436 mod2->value = mod2->value + qty;
3437 mod2->count++;
3438 return;
3439 }
3440 }
3441 std::cout << "**************************error in fill method **************module " << idmod << std::endl;
3442 }
3443
3444 void TrackerMap::fill(int layer, int ring, int nmod, float qty) {
3445 int key = layer * 100000 + ring * 1000 + nmod;
3446 TmModule *mod = smoduleMap[key];
3447 if (mod != nullptr) {
3448 mod->value = mod->value + qty;
3449 mod->count++;
3450 } else
3451 std::cout << "**************************error in SvgModuleMap **************";
3452 }
3453
3454 void TrackerMap::setText(int idmod, std::string s) {
3455 TmModule *mod = imoduleMap[idmod];
3456 if (mod != nullptr) {
3457 mod->text = s;
3458 } else
3459 std::cout << "**************************error in IdModuleMap **************";
3460 }
3461
3462 void TrackerMap::setText(int layer, int ring, int nmod, std::string s) {
3463 int key = layer * 100000 + ring * 1000 + nmod;
3464 TmModule *mod = smoduleMap[key];
3465 if (mod != nullptr) {
3466 mod->text = s;
3467 } else
3468 std::cout << "**************************error in SvgModuleMap **************";
3469 }
3470
3471 void TrackerMap::build() {
3472
3473
3474 int nmods, pix_sil, fow_bar, ring, nmod, layer;
3475 unsigned int idex;
3476 float posx, posy, posz, length, width, thickness, widthAtHalfLength;
3477 int old_layer = 0, ntotMod = 0;
3478 std::string name, dummys;
3479 std::ifstream infile(edm::FileInPath(infilename).fullPath().c_str(), std::ios::in);
3480 while (!infile.eof()) {
3481 infile >> nmods >> pix_sil >> fow_bar >> layer >> ring >> nmod >> posx >> posy >> posz >> length >> width >>
3482 thickness >> widthAtHalfLength >> idex;
3483 getline(infile, dummys);
3484 getline(infile, name);
3485 if (old_layer != layer) {
3486 old_layer = layer;
3487 }
3488 ntotMod++;
3489 int key = layer * 100000 + ring * 1000 + nmod;
3490 TmModule *mod = smoduleMap[key];
3491
3492 imoduleMap[idex] = mod;
3493
3494 if (mod == nullptr)
3495 std::cout << "error in module " << key << std::endl;
3496 else {
3497 mod->posx = posx;
3498 mod->posy = posy;
3499 mod->setUsed();
3500 mod->value = 0;
3501 mod->count = 0;
3502 mod->posz = posz;
3503 mod->length = length;
3504 mod->width = width;
3505 mod->thickness = thickness;
3506 mod->widthAtHalfLength = widthAtHalfLength;
3507 mod->idex = idex;
3508 mod->name = name;
3509 }
3510 }
3511 infile.close();
3512 number_modules = ntotMod - 1;
3513 }
3514 int TrackerMap::getcolor(float value, int palette) {
3515 int red, green, blue;
3516 float lminvalue, lmaxvalue;
3517 lminvalue = minvalue;
3518 lmaxvalue = maxvalue;
3519 if (tkMapLog) {
3520 lminvalue = log(minvalue) / log(10);
3521 lmaxvalue = log(maxvalue) / log(10);
3522 value = log(value) / log(10);
3523 }
3524
3525 red = 0;
3526 green = 0;
3527 blue = 0;
3528 if (palette == 1) {
3529 float delta = (lmaxvalue - lminvalue);
3530 float x = (value - lminvalue);
3531 if (value < lminvalue) {
3532 red = 0;
3533 green = 0;
3534 blue = 255;
3535 }
3536 if (value > lmaxvalue) {
3537 red = 255;
3538 green = 0;
3539 blue = 0;
3540 }
3541 if (value >= lminvalue && value <= lmaxvalue) {
3542 red = (int)(x < (delta / 2) ? 0 : (x > ((3. / 4.) * delta) ? 255 : 255 / (delta / 4) * (x - (2. / 4.) * delta)));
3543 green =
3544 (int)(x < delta / 4 ? (x * 255 / (delta / 4))
3545 : (x > ((3. / 4.) * delta) ? 255 - 255 / (delta / 4) * (x - (3. / 4.) * delta) : 255));
3546 blue = (int)(x < delta / 4 ? 255
3547 : (x > ((1. / 2.) * delta) ? 0 : 255 - 255 / (delta / 4) * (x - (1. / 4.) * delta)));
3548 }
3549 }
3550 if (palette == 2) {
3551 green = (int)((value - lminvalue) / (lmaxvalue - lminvalue) * 256.);
3552 if (green > 255)
3553 green = 255;
3554 red = 255;
3555 blue = 0;
3556 green = 255 - green;
3557 }
3558
3559 return (blue | (green << 8) | (red << 16));
3560 }
3561 void TrackerMap::printonline() {
3562
3563 std::ofstream *ofilename;
3564 std::ifstream *ifilename;
3565 std::ostringstream ofname;
3566 std::string ifname;
3567 std::string command;
3568 std::string line;
3569 std::string outputfilename = "dqmtmap";
3570 ifilename = findfile("viewerHeader.xhtml");
3571 ofname << outputfilename << "viewer.html";
3572 ofilename = new std::ofstream(ofname.str().c_str(), std::ios::out);
3573 while (getline(*ifilename, line)) {
3574 *ofilename << line << std::endl;
3575 }
3576 *ofilename << " var tmapname=\"" << outputfilename << "\"" << std::endl;
3577 *ofilename << " var tmaptitle=\"" << title << "\"" << std::endl;
3578 *ofilename << " var ncrates=" << ncrates << ";" << std::endl;
3579 *ofilename << " var nfeccrates=" << nfeccrates << ";" << std::endl;
3580 *ofilename << " var npsuracks=" << npsuracks << ";" << std::endl;
3581
3582 ifilename->close();
3583 delete ifilename;
3584
3585 ifilename = findfile("viewerTrailer.xhtml");
3586 while (getline(*ifilename, line)) {
3587 *ofilename << line << std::endl;
3588 }
3589 ofilename->close();
3590 delete ofilename;
3591 command = "sed -i \"s/XtmapnameX/" + outputfilename + "/g\" " + ofname.str();
3592 std::cout << "Executing " << command << std::endl;
3593 system(command.c_str());
3594 command = "sed -i \"s/XtmaptitleX/" + title + "/g\" " + ofname.str();
3595 std::cout << "Executing " << command << std::endl;
3596 system(command.c_str());
3597 ofname.str("");
3598 ifilename->close();
3599 delete ifilename;
3600
3601 ifilename = findfile("jqviewer.js");
3602 ofname << "jqviewer.js";
3603 ofilename = new std::ofstream(ofname.str().c_str(), std::ios::out);
3604 while (getline(*ifilename, line)) {
3605 *ofilename << line << std::endl;
3606 }
3607 ofname.str("");
3608 ofilename->close();
3609 delete ofilename;
3610 ifilename->close();
3611 delete ifilename;
3612
3613 ifilename = findfile("crate.js");
3614 ofname << "crate.js";
3615 ofilename = new std::ofstream(ofname.str().c_str(), std::ios::out);
3616 while (getline(*ifilename, line)) {
3617 *ofilename << line << std::endl;
3618 }
3619 ofname.str("");
3620 ofilename->close();
3621 delete ofilename;
3622 ifilename->close();
3623 delete ifilename;
3624
3625 ifilename = findfile("feccrate.js");
3626 ofname << "feccrate.js";
3627 ofilename = new std::ofstream(ofname.str().c_str(), std::ios::out);
3628 while (getline(*ifilename, line)) {
3629 *ofilename << line << std::endl;
3630 }
3631 ofname.str("");
3632 ofilename->close();
3633 delete ofilename;
3634 ifilename->close();
3635 delete ifilename;
3636
3637 ifilename = findfile("layer.js");
3638 ofname << "layer.js";
3639 ofilename = new std::ofstream(ofname.str().c_str(), std::ios::out);
3640 while (getline(*ifilename, line)) {
3641 *ofilename << line << std::endl;
3642 }
3643 ofname.str("");
3644 ofilename->close();
3645 delete ofilename;
3646 ifilename->close();
3647 delete ifilename;
3648
3649 ifilename = findfile("rack.js");
3650 ofname << "rack.js";
3651 ofilename = new std::ofstream(ofname.str().c_str(), std::ios::out);
3652 while (getline(*ifilename, line)) {
3653 *ofilename << line << std::endl;
3654 }
3655 ofname.str("");
3656 ofilename->close();
3657 delete ofilename;
3658 ifilename->close();
3659 delete ifilename;
3660 ofname.str("");
3661
3662 ifilename = findfile("rackhv.js");
3663 ofname << "rackhv.js";
3664 ofilename = new std::ofstream(ofname.str().c_str(), std::ios::out);
3665 while (getline(*ifilename, line)) {
3666 *ofilename << line << std::endl;
3667 }
3668 ofname.str("");
3669 ofilename->close();
3670 delete ofilename;
3671 ifilename->close();
3672 delete ifilename;
3673
3674 std::ostringstream outs, outs1, outs2;
3675 outs << outputfilename << ".png";
3676 save(true, gminvalue, gmaxvalue, outs.str(), 3000, 1600);
3677 temporary_file = false;
3678 printlayers(true, gminvalue, gmaxvalue, outputfilename);
3679
3680
3681 std::ofstream *txtfile;
3682 for (int layer = 1; layer < 44; layer++) {
3683 std::ostringstream outs;
3684 outs << outputfilename << "layer" << layer << ".html";
3685 txtfile = new std::ofstream(outs.str().c_str(), std::ios::out);
3686 *txtfile << "<html><head></head> <body>" << std::endl;
3687 for (int ring = firstRing[layer - 1]; ring < ntotRing[layer - 1] + firstRing[layer - 1]; ring++) {
3688 for (int module = 1; module < 200; module++) {
3689 int key = layer * 100000 + ring * 1000 + module;
3690 TmModule *mod = smoduleMap[key];
3691 if (mod != nullptr && !mod->notInUse()) {
3692 int idmod = mod->idex;
3693 *txtfile << "<a name=" << idmod << "><pre>" << std::endl;
3694 std::multimap<const int, TmApvPair *>::iterator pos;
3695 for (pos = apvModuleMap.lower_bound(idmod); pos != apvModuleMap.upper_bound(idmod); ++pos) {
3696 TmApvPair *apvpair = pos->second;
3697 if (apvpair != nullptr) {
3698 *txtfile << apvpair->text << std::endl;
3699 }
3700 }
3701 *txtfile << "</pre><h3>" << mod->name << "</h3>" << std::endl;
3702 }
3703 }
3704 }
3705 *txtfile << "</body></html>" << std::endl;
3706 txtfile->close();
3707 delete txtfile;
3708 }
3709 if (enableFedProcessing) {
3710 outs1 << outputfilename << "fed.png";
3711 save_as_fedtrackermap(true, gminvalue, gmaxvalue, outs1.str(), 6000, 3200);
3712 outs2 << outputfilename << ".xml";
3713 save_as_fedtrackermap(true, gminvalue, gmaxvalue, outs2.str(), 3000, 1600);
3714
3715 std::map<int, int>::iterator i_fed;
3716 std::ofstream *txtfile;
3717 for (int crate = firstcrate; crate < (ncrates + 1); crate++) {
3718 std::ostringstream outs;
3719 outs << outputfilename << "crate" << crate << ".html";
3720 txtfile = new std::ofstream(outs.str().c_str(), std::ios::out);
3721 *txtfile << "<html><head></head> <body>" << std::endl;
3722 for (i_fed = fedMap.begin(); i_fed != fedMap.end(); i_fed++) {
3723 if (i_fed->second == crate) {
3724 int fedId = i_fed->first;
3725 for (int nconn = 0; nconn < 96; nconn++) {
3726 int key = fedId * 1000 + nconn;
3727 TmApvPair *apvPair = apvMap[key];
3728 if (apvPair != nullptr) {
3729 int idmod = apvPair->idex;
3730 *txtfile << "<a name=" << idmod << "><pre>" << std::endl;
3731 *txtfile << apvPair->text << std::endl;
3732 std::ostringstream outs;
3733 outs << "fedchannel " << apvPair->getFedId() << "/" << apvPair->getFedCh() << " connects to module "
3734 << apvPair->mod->idex;
3735 *txtfile << "</pre><h3>" << outs.str() << "</h3>" << std::endl;
3736 }
3737 }
3738 }
3739 }
3740 *txtfile << "</body></html>" << std::endl;
3741 txtfile->close();
3742 delete txtfile;
3743 }
3744 }
3745 if (enableFecProcessing) {
3746 std::ostringstream outs1, outs2;
3747 outs1 << outputfilename << "fec.png";
3748 save_as_fectrackermap(true, gminvalue, gmaxvalue, outs1.str(), 6000, 3200);
3749 outs2 << outputfilename << ".xml";
3750 save_as_fectrackermap(true, gminvalue, gmaxvalue, outs2.str(), 3000, 1600);
3751
3752 std::ofstream *txtfile;
3753 std::map<int, TmCcu *>::iterator i_ccu;
3754 std::multimap<TmCcu *, TmModule *>::iterator it;
3755 std::pair<std::multimap<TmCcu *, TmModule *>::iterator, std::multimap<TmCcu *, TmModule *>::iterator> ret;
3756 for (int crate = 1; crate < (nfeccrates + 1); crate++) {
3757 std::ostringstream outs;
3758 outs << outputfilename << "feccrate" << crate << ".html";
3759 txtfile = new std::ofstream(outs.str().c_str(), std::ios::out);
3760 *txtfile << "<html><head></head> <body>" << std::endl;
3761 for (i_ccu = ccuMap.begin(); i_ccu != ccuMap.end(); i_ccu++) {
3762 TmCcu *ccu = i_ccu->second;
3763 if (ccu != nullptr && ccu->getCcuCrate() == crate) {
3764 int idmod = ccu->idex;
3765 *txtfile << "<a name=" << idmod << "><pre>" << std::endl;
3766 *txtfile << ccu->text << std::endl;
3767 std::ostringstream outs;
3768 if (ccu->nmod == 0)
3769 outs << "ccu is in position" << ccu->mpos << "in ring but doesn't seem to have any module connected";
3770 else {
3771 outs << "ccu is in position " << ccu->mpos << " in ring and connects " << ccu->nmod << " modules"
3772 << std::endl;
3773 ret = fecModuleMap.equal_range(ccu);
3774 for (it = ret.first; it != ret.second; ++it) {
3775 outs << (*it).second->idex << " " << (*it).second->name << " value= " << (*it).second->value << "\n\n";
3776 }
3777
3778 *txtfile << "</pre><h4>" << outs.str() << "</h4>" << std::endl;
3779 }
3780 }
3781 }
3782 *txtfile << "</body></html>" << std::endl;
3783 txtfile->close();
3784 delete txtfile;
3785 }
3786 }
3787 if (enableLVProcessing) {
3788 std::ostringstream outs3, outs4;
3789 outs3 << outputfilename << "psu.png";
3790 save_as_psutrackermap(true, gminvalue, gmaxvalue, outs3.str(), 6000, 3200);
3791
3792 outs4 << outputfilename << ".xml";
3793 save_as_psutrackermap(true, gminvalue, gmaxvalue, outs4.str(), 3000, 1600);
3794
3795
3796 std::ofstream *txtfile;
3797 std::map<int, TmPsu *>::iterator ipsu;
3798 std::multimap<TmPsu *, TmModule *>::iterator it;
3799 std::pair<std::multimap<TmPsu *, TmModule *>::iterator, std::multimap<TmPsu *, TmModule *>::iterator> ret;
3800 for (int rack = 1; rack < (npsuracks + 1); rack++) {
3801 std::ostringstream outs;
3802
3803 outs << outputfilename << "psurack" << rack << ".html";
3804 txtfile = new std::ofstream(outs.str().c_str(), std::ios::out);
3805 *txtfile << "<html><head></head> <body>" << std::endl;
3806 for (ipsu = psuMap.begin(); ipsu != psuMap.end(); ipsu++) {
3807 TmPsu *psu = ipsu->second;
3808 if (psu != nullptr && psu->getPsuRack() == rack) {
3809 *txtfile << "<a name=" << psu->idex << "><pre>" << std::endl;
3810 *txtfile << psu->text << std::endl;
3811 std::ostringstream outs;
3812 if (psu->nmod == 0)
3813 outs << "Ps is in position" << psu->getPsuBoard()
3814 << "in crate but doesn't seem to have any module connected";
3815 else {
3816 outs << "PS is in position " << psu->getPsuBoard() << " in crate and connects to " << psu->nmod
3817 << " modules. " << std::endl;
3818
3819 ret = psuModuleMap.equal_range(psu);
3820 for (it = ret.first; it != ret.second; ++it) {
3821 outs << (*it).second->idex << " " << (*it).second->name << " value= " << (*it).second->value << " <br>"
3822 << std::endl;
3823 }
3824 *txtfile << "</pre><h4>" << outs.str() << "</h4>" << std::endl;
3825 }
3826 }
3827 }
3828 *txtfile << "</body></html>" << std::endl;
3829 txtfile->close();
3830 delete txtfile;
3831 }
3832 }
3833
3834 if (enableHVProcessing) {
3835 std::ostringstream outs5, outs6;
3836 outs5 << outputfilename << "hv.png";
3837 save_as_HVtrackermap(true, gminvalue, gmaxvalue, outs5.str(), 6000, 3200);
3838
3839 outs6 << outputfilename << ".xml";
3840 save_as_HVtrackermap(true, gminvalue, gmaxvalue, outs6.str(), 3000, 1600);
3841
3842
3843 std::ofstream *txtfile;
3844 std::map<int, TmPsu *>::iterator ipsu;
3845 std::multimap<TmPsu *, TmModule *>::iterator it;
3846 std::pair<std::multimap<TmPsu *, TmModule *>::iterator, std::multimap<TmPsu *, TmModule *>::iterator> ret;
3847 for (int rack = 1; rack < (npsuracks + 1); rack++) {
3848 std::ostringstream outs;
3849
3850 outs << outputfilename << "HVrack" << rack << ".html";
3851 txtfile = new std::ofstream(outs.str().c_str(), std::ios::out);
3852 *txtfile << "<html><head></head> <body>" << std::endl;
3853 for (ipsu = psuMap.begin(); ipsu != psuMap.end(); ipsu++) {
3854 TmPsu *psu = ipsu->second;
3855 if (psu != nullptr && psu->getPsuRack() == rack) {
3856 *txtfile << "<a name=" << psu->idex << "><pre>" << std::endl;
3857 *txtfile << psu->textHV2 << std::endl;
3858 std::ostringstream outsHV2;
3859 if (psu->nmodHV2 == 0)
3860 outsHV2 << "HV Channel002 is in position" << psu->getPsuBoard()
3861 << "in crate but doesn't seem to have any module connected";
3862 else {
3863 outsHV2 << "HV Channel002 is in position " << psu->getPsuBoard() << " in crate and connects to "
3864 << psu->nmodHV2 << " modules. "
3865 << " <br>" << std::endl;
3866
3867 ret = psuModuleMap.equal_range(psu);
3868 for (it = ret.first; it != ret.second; ++it) {
3869 if ((*it).second->HVchannel == 2) {
3870 outsHV2 << (*it).second->idex << " " << (*it).second->name << " value= " << (*it).second->value
3871 << " <br>" << std::endl;
3872 }
3873 }
3874 *txtfile << "</pre><h4>" << outsHV2.str() << "</h4>" << std::endl;
3875 }
3876
3877 *txtfile << psu->textHV3 << std::endl;
3878 std::ostringstream outsHV3;
3879 if (psu->nmodHV3 == 0)
3880 outsHV3 << "HV Channel003 is in position" << psu->getPsuBoard()
3881 << "in crate but doesn't seem to have any module connected";
3882 else {
3883 outsHV3 << "HV Channel003 is in position " << psu->getPsuBoard() << " in crate and connects to "
3884 << psu->nmodHV3 << " modules. "
3885 << " <br>" << std::endl;
3886
3887 ret = psuModuleMap.equal_range(psu);
3888 for (it = ret.first; it != ret.second; ++it) {
3889 if ((*it).second->HVchannel == 3) {
3890 outsHV3 << (*it).second->idex << " " << (*it).second->name << " value= " << (*it).second->value
3891 << " <br>" << std::endl;
3892 }
3893 }
3894 *txtfile << "</pre><h4>" << outsHV3.str() << "</h4>" << std::endl;
3895 }
3896 }
3897 }
3898 *txtfile << "</body></html>" << std::endl;
3899 txtfile->close();
3900 delete txtfile;
3901 }
3902 }
3903 }
3904 void TrackerMap::printall(bool print_total, float minval1, float maxval1, std::string s, int width, int height) {
3905
3906 float minval, maxval;
3907 minval = minval1;
3908 maxval = maxval1;
3909 if (tkMapLog && (minval < maxval)) {
3910 minval = pow(10., minval1);
3911 maxval = pow(10., maxval1);
3912 }
3913 std::string filetype = s, outputfilename = s;
3914 if (saveWebInterface) {
3915 width = 6000;
3916 height = 3200;
3917 } else {
3918 size_t found = filetype.find_last_of('.');
3919 filetype = filetype.substr(found + 1);
3920 found = outputfilename.find_last_of('.');
3921 outputfilename = outputfilename.substr(0, found);
3922 }
3923 std::ofstream *ofilename;
3924 std::ifstream *ifilename;
3925 std::ostringstream ofname;
3926 std::string ifname;
3927 std::string line;
3928 std::string command;
3929 if (saveWebInterface) {
3930 ifilename = findfile("viewerHeader.xhtml");
3931 ofname << outputfilename << "viewer.html";
3932 ofilename = new std::ofstream(ofname.str().c_str(), std::ios::out);
3933 while (getline(*ifilename, line)) {
3934 *ofilename << line << std::endl;
3935 }
3936 *ofilename << " var tmapname=\"" << outputfilename << "\"" << std::endl;
3937 *ofilename << " var tmaptitle=\"" << title << "\"" << std::endl;
3938 *ofilename << " var ncrates=" << ncrates << ";" << std::endl;
3939 *ofilename << " var nfeccrates=" << nfeccrates << ";" << std::endl;
3940 *ofilename << " var npsuracks=" << npsuracks << ";" << std::endl;
3941 ifilename->close();
3942 delete ifilename;
3943 ifilename = findfile("viewerTrailer.xhtml");
3944 while (getline(*ifilename, line)) {
3945 *ofilename << line << std::endl;
3946 }
3947 ofilename->close();
3948 delete ofilename;
3949 ifilename->close();
3950 delete ifilename;
3951 command = "sed -i \"s/XtmapnameX/" + outputfilename + "/g\" " + ofname.str();
3952 std::cout << "Executing " << command << std::endl;
3953 system(command.c_str());
3954 command = "sed -i \"s/XtmaptitleX/" + title + "/g\" " + ofname.str();
3955 std::cout << "Executing " << command << std::endl;
3956 system(command.c_str());
3957 ofname.str("");
3958
3959 ifilename = findfile("jqviewer.js");
3960 ofname << "jqviewer.js";
3961 ofilename = new std::ofstream(ofname.str().c_str(), std::ios::out);
3962 while (getline(*ifilename, line)) {
3963 *ofilename << line << std::endl;
3964 }
3965 ofilename->close();
3966 delete ofilename;
3967 ifilename->close();
3968 delete ifilename;
3969
3970 ofname.str("");
3971 ifilename = findfile("crate.js");
3972 ofname << "crate.js";
3973 ofilename = new std::ofstream(ofname.str().c_str(), std::ios::out);
3974 while (getline(*ifilename, line)) {
3975 *ofilename << line << std::endl;
3976 }
3977 ofilename->close();
3978 delete ofilename;
3979 ifilename->close();
3980 delete ifilename;
3981
3982 ofname.str("");
3983 ifilename = findfile("feccrate.js");
3984 ofname << "feccrate.js";
3985 ofilename = new std::ofstream(ofname.str().c_str(), std::ios::out);
3986 while (getline(*ifilename, line)) {
3987 *ofilename << line << std::endl;
3988 }
3989 ofilename->close();
3990 delete ofilename;
3991 ifilename->close();
3992 delete ifilename;
3993
3994 ofname.str("");
3995 ifilename = findfile("rack.js");
3996 ofname << "rack.js";
3997 ofilename = new std::ofstream(ofname.str().c_str(), std::ios::out);
3998 while (getline(*ifilename, line)) {
3999 *ofilename << line << std::endl;
4000 }
4001 ofilename->close();
4002 delete ofilename;
4003 ifilename->close();
4004 delete ifilename;
4005
4006 ofname.str("");
4007 ifilename = findfile("rackhv.js");
4008 ofname << "rackhv.js";
4009 ofilename = new std::ofstream(ofname.str().c_str(), std::ios::out);
4010 while (getline(*ifilename, line)) {
4011 *ofilename << line << std::endl;
4012 }
4013 ofilename->close();
4014 delete ofilename;
4015 ifilename->close();
4016 delete ifilename;
4017
4018 ofname.str("");
4019 ifilename = findfile("layer.js");
4020 ofname << "layer.js";
4021 ofilename = new std::ofstream(ofname.str().c_str(), std::ios::out);
4022 while (getline(*ifilename, line)) {
4023 *ofilename << line << std::endl;
4024 }
4025 ofilename->close();
4026 delete ofilename;
4027 ifilename->close();
4028 delete ifilename;
4029
4030 command = "scp -r ../../DQM/TrackerCommon/test/jquery/ .";
4031 std::cout << "Executing " << command << std::endl;
4032 system(command.c_str());
4033 command = "scp -r ../../CommonTools/TrackerMap/data/images/ .";
4034 std::cout << "Executing " << command << std::endl;
4035 system(command.c_str());
4036 }
4037
4038 std::ostringstream outs;
4039 outs << outputfilename << ".png";
4040 if (saveWebInterface)
4041 save(true, minval, maxval, outs.str(), 3000, 1600);
4042 else {
4043 if (saveGeoTrackerMap)
4044 save(true, minval, maxval, s, width, height);
4045 }
4046 if (saveWebInterface) {
4047 std::ostringstream outs;
4048 outs << outputfilename << ".png";
4049 temporary_file = false;
4050 printlayers(true, minval, maxval, outputfilename);
4051
4052
4053 std::ofstream *txtfile;
4054 for (int layer = 1; layer < 44; layer++) {
4055 std::ostringstream outs;
4056 outs << outputfilename << "layer" << layer << ".html";
4057 txtfile = new std::ofstream(outs.str().c_str(), std::ios::out);
4058 *txtfile << "<html><head></head> <body>" << std::endl;
4059 for (int ring = firstRing[layer - 1]; ring < ntotRing[layer - 1] + firstRing[layer - 1]; ring++) {
4060 for (int module = 1; module < 200; module++) {
4061 int key = layer * 100000 + ring * 1000 + module;
4062 TmModule *mod = smoduleMap[key];
4063 if (mod != nullptr && !mod->notInUse()) {
4064 int idmod = mod->idex;
4065 *txtfile << "<a name=" << idmod << "><pre>" << std::endl;
4066 std::multimap<const int, TmApvPair *>::iterator pos;
4067 for (pos = apvModuleMap.lower_bound(idmod); pos != apvModuleMap.upper_bound(idmod); ++pos) {
4068 TmApvPair *apvpair = pos->second;
4069 if (apvpair != nullptr) {
4070 *txtfile << apvpair->text << std::endl;
4071 }
4072 }
4073 *txtfile << "</pre><h3>" << mod->name << "</h3>" << std::endl;
4074 }
4075 }
4076 }
4077 *txtfile << "</body></html>" << std::endl;
4078 txtfile->close();
4079 delete txtfile;
4080 }
4081 }
4082 if (enableFedProcessing) {
4083 std::ostringstream outs1, outs2;
4084 if (saveWebInterface)
4085 outs1 << outputfilename << "fed.png";
4086 else
4087 outs1 << outputfilename << "fed." << filetype;
4088 save_as_fedtrackermap(true, 0., 0., outs1.str(), width, height);
4089 if (saveWebInterface) {
4090 outs2 << outputfilename << ".xml";
4091 save_as_fedtrackermap(true, 0., 0., outs2.str(), 3000, 1600);
4092
4093 std::map<int, int>::iterator i_fed;
4094 std::ofstream *txtfile;
4095 for (int crate = firstcrate; crate < (ncrates + 1); crate++) {
4096 std::ostringstream outs;
4097 outs << outputfilename << "crate" << crate << ".html";
4098 txtfile = new std::ofstream(outs.str().c_str(), std::ios::out);
4099 *txtfile << "<html><head></head> <body>" << std::endl;
4100 for (i_fed = fedMap.begin(); i_fed != fedMap.end(); i_fed++) {
4101 if (i_fed->second == crate) {
4102 int fedId = i_fed->first;
4103 for (int nconn = 0; nconn < 96; nconn++) {
4104 int key = fedId * 1000 + nconn;
4105 TmApvPair *apvPair = apvMap[key];
4106 if (apvPair != nullptr) {
4107 int idmod = apvPair->idex;
4108 *txtfile << "<a name=" << idmod << "><pre>" << std::endl;
4109 *txtfile << apvPair->text << std::endl;
4110 std::ostringstream outs;
4111 outs << "fedchannel " << apvPair->getFedId() << "/" << apvPair->getFedCh() << " connects to module "
4112 << apvPair->mod->idex;
4113 *txtfile << "</pre><h3>" << outs.str() << "</h3>" << std::endl;
4114 }
4115 }
4116 }
4117 }
4118 *txtfile << "</body></html>" << std::endl;
4119 txtfile->close();
4120 delete txtfile;
4121 }
4122 }
4123 }
4124 if (enableFecProcessing) {
4125 std::ostringstream outs1, outs2;
4126 if (saveWebInterface)
4127 outs1 << outputfilename << "fec.png";
4128 else
4129 outs1 << outputfilename << "fec." << filetype;
4130 save_as_fectrackermap(true, 0., 0., outs1.str(), width, height);
4131 if (saveWebInterface) {
4132 outs2 << outputfilename << ".xml";
4133 save_as_fectrackermap(true, 0., 0., outs2.str(), 3000, 1600);
4134
4135 std::ofstream *txtfile;
4136 std::map<int, TmCcu *>::iterator i_ccu;
4137 std::multimap<TmCcu *, TmModule *>::iterator it;
4138 std::pair<std::multimap<TmCcu *, TmModule *>::iterator, std::multimap<TmCcu *, TmModule *>::iterator> ret;
4139 for (int crate = 1; crate < (nfeccrates + 1); crate++) {
4140 std::ostringstream outs;
4141 outs << outputfilename << "feccrate" << crate << ".html";
4142 txtfile = new std::ofstream(outs.str().c_str(), std::ios::out);
4143 *txtfile << "<html><head></head> <body>" << std::endl;
4144 for (i_ccu = ccuMap.begin(); i_ccu != ccuMap.end(); i_ccu++) {
4145 TmCcu *ccu = i_ccu->second;
4146 if (ccu != nullptr && ccu->getCcuCrate() == crate) {
4147 int idmod = ccu->idex;
4148 *txtfile << "<a name=" << idmod << "><pre>" << std::endl;
4149 *txtfile << ccu->text << std::endl;
4150 std::ostringstream outs;
4151 if (ccu->nmod == 0)
4152 outs << "ccu is in position" << ccu->mpos << "in ring but doesn't seem to have any module connected";
4153 else {
4154 outs << "ccu is in position " << ccu->mpos << " in ring and connects " << ccu->nmod << " modules"
4155 << std::endl;
4156 ret = fecModuleMap.equal_range(ccu);
4157 for (it = ret.first; it != ret.second; ++it) {
4158 outs << (*it).second->idex << " " << (*it).second->name << " value= " << (*it).second->value << "\n\n";
4159 }
4160
4161 *txtfile << "</pre><h4>" << outs.str() << "</h4>" << std::endl;
4162 }
4163 }
4164 }
4165 *txtfile << "</body></html>" << std::endl;
4166 txtfile->close();
4167 }
4168 }
4169 }
4170 if (enableLVProcessing) {
4171 std::ostringstream outs3, outs4;
4172 if (saveWebInterface)
4173 outs3 << outputfilename << "psu.png";
4174 else
4175 outs3 << outputfilename << "psu." << filetype;
4176 save_as_psutrackermap(true, 0., 0., outs3.str(), width, height);
4177 if (saveWebInterface) {
4178 outs4 << outputfilename << ".xml";
4179 save_as_psutrackermap(true, 0., 0., outs4.str(), 3000, 1600);
4180
4181
4182 std::ofstream *txtfile;
4183 std::map<int, TmPsu *>::iterator ipsu;
4184 std::multimap<TmPsu *, TmModule *>::iterator it;
4185 std::pair<std::multimap<TmPsu *, TmModule *>::iterator, std::multimap<TmPsu *, TmModule *>::iterator> ret;
4186 for (int rack = 1; rack < (npsuracks + 1); rack++) {
4187 std::ostringstream outs;
4188
4189 outs << outputfilename << "psurack" << rack << ".html";
4190 txtfile = new std::ofstream(outs.str().c_str(), std::ios::out);
4191 *txtfile << "<html><head></head> <body>" << std::endl;
4192 for (ipsu = psuMap.begin(); ipsu != psuMap.end(); ipsu++) {
4193 TmPsu *psu = ipsu->second;
4194 if (psu != nullptr && psu->getPsuRack() == rack) {
4195 *txtfile << "<a name=" << psu->idex << "><pre>" << std::endl;
4196 *txtfile << psu->text << std::endl;
4197 std::ostringstream outs;
4198 if (psu->nmod == 0)
4199 outs << "Ps is in position" << psu->getPsuBoard()
4200 << "in crate but doesn't seem to have any module connected";
4201 else {
4202 outs << "PS is in position " << psu->getPsuBoard() << " in crate and connects to " << psu->nmod
4203 << " modules. " << std::endl;
4204
4205 ret = psuModuleMap.equal_range(psu);
4206 for (it = ret.first; it != ret.second; ++it) {
4207 outs << (*it).second->idex << " " << (*it).second->name << " value= " << (*it).second->value << " <br>"
4208 << std::endl;
4209 }
4210 *txtfile << "</pre><h4>" << outs.str() << "</h4>" << std::endl;
4211 }
4212 }
4213 }
4214 *txtfile << "</body></html>" << std::endl;
4215 txtfile->close();
4216 }
4217 }
4218 }
4219
4220 if (enableHVProcessing) {
4221 std::ostringstream outs5, outs6;
4222 if (saveWebInterface)
4223 outs5 << outputfilename << "hv.png";
4224 else
4225 outs5 << outputfilename << "hv." << filetype;
4226 save_as_HVtrackermap(true, 0., 0., outs5.str(), width, height);
4227 if (saveWebInterface) {
4228 outs6 << outputfilename << ".xml";
4229 save_as_HVtrackermap(true, 0., 0., outs6.str(), 3000, 1600);
4230
4231
4232 std::ofstream *txtfile;
4233 std::map<int, TmPsu *>::iterator ipsu;
4234 std::multimap<TmPsu *, TmModule *>::iterator it;
4235 std::pair<std::multimap<TmPsu *, TmModule *>::iterator, std::multimap<TmPsu *, TmModule *>::iterator> ret;
4236 for (int rack = 1; rack < (npsuracks + 1); rack++) {
4237 std::ostringstream outs;
4238
4239 outs << outputfilename << "HVrack" << rack << ".html";
4240 txtfile = new std::ofstream(outs.str().c_str(), std::ios::out);
4241 *txtfile << "<html><head></head> <body>" << std::endl;
4242 for (ipsu = psuMap.begin(); ipsu != psuMap.end(); ipsu++) {
4243 TmPsu *psu = ipsu->second;
4244 if (psu != nullptr && psu->getPsuRack() == rack) {
4245 *txtfile << "<a name=" << psu->idex << "><pre>" << std::endl;
4246 *txtfile << psu->textHV2 << std::endl;
4247 std::ostringstream outsHV2;
4248 if (psu->nmodHV2 == 0)
4249 outsHV2 << "HV Channel002 is in position" << psu->getPsuBoard()
4250 << "in crate but doesn't seem to have any module connected";
4251 else {
4252 outsHV2 << "HV Channel002 is in position " << psu->getPsuBoard() << " in crate and connects to "
4253 << psu->nmodHV2 << " modules. "
4254 << " <br>" << std::endl;
4255
4256 ret = psuModuleMap.equal_range(psu);
4257 for (it = ret.first; it != ret.second; ++it) {
4258 if ((*it).second->HVchannel == 2) {
4259 outsHV2 << (*it).second->idex << " " << (*it).second->name << " value= " << (*it).second->value
4260 << " <br>" << std::endl;
4261 }
4262 }
4263 *txtfile << "</pre><h4>" << outsHV2.str() << "</h4>" << std::endl;
4264 }
4265
4266 *txtfile << psu->textHV3 << std::endl;
4267 std::ostringstream outsHV3;
4268 if (psu->nmodHV3 == 0)
4269 outsHV3 << "HV Channel003 is in position" << psu->getPsuBoard()
4270 << "in crate but doesn't seem to have any module connected";
4271 else {
4272 outsHV3 << "HV Channel003 is in position " << psu->getPsuBoard() << " in crate and connects to "
4273 << psu->nmodHV3 << " modules. "
4274 << " <br>" << std::endl;
4275
4276 ret = psuModuleMap.equal_range(psu);
4277 for (it = ret.first; it != ret.second; ++it) {
4278 if ((*it).second->HVchannel == 3) {
4279 outsHV3 << (*it).second->idex << " " << (*it).second->name << " value= " << (*it).second->value
4280 << " <br>" << std::endl;
4281 }
4282 }
4283 *txtfile << "</pre><h4>" << outsHV3.str() << "</h4>" << std::endl;
4284 }
4285 }
4286 }
4287 *txtfile << "</body></html>" << std::endl;
4288 txtfile->close();
4289 }
4290 }
4291 }
4292 }
4293
4294 std::ifstream *TrackerMap::findfile(std::string filename) {
4295 std::ifstream *ifilename;
4296 std::string ifname;
4297 if (!jsPath.empty()) {
4298 ifname = jsPath + filename;
4299 ifilename = new std::ifstream(edm::FileInPath(ifname).fullPath().c_str(), std::ios::in);
4300 if (!ifilename) {
4301 ifname = "CommonTools/TrackerMap/data/" + filename;
4302 ifilename = new std::ifstream(edm::FileInPath(ifname).fullPath().c_str(), std::ios::in);
4303 }
4304 } else {
4305 ifname = "CommonTools/TrackerMap/data/" + filename;
4306 ifilename = new std::ifstream(edm::FileInPath(ifname).fullPath().c_str(), std::ios::in);
4307 }
4308 if (!ifilename)
4309 std::cout << "File " << filename << " missing" << std::endl;
4310 return ifilename;
4311 }
4312 void TrackerMap::printlayers(bool print_total, float minval, float maxval, std::string outputfilename) {
4313 std::ofstream *xmlfile;
4314 saveAsSingleLayer = true;
4315 if (!print_total) {
4316 for (int layer = 1; layer < 44; layer++) {
4317 for (int ring = firstRing[layer - 1]; ring < ntotRing[layer - 1] + firstRing[layer - 1]; ring++) {
4318 for (int module = 1; module < 200; module++) {
4319 int key = layer * 100000 + ring * 1000 + module;
4320 TmModule *mod = smoduleMap[key];
4321 if (mod != nullptr && !mod->notInUse()) {
4322 mod->value = mod->value / mod->count;
4323 }
4324 }
4325 }
4326 }
4327 }
4328 if (minvalue >= maxvalue) {
4329 minvalue = 9999999.;
4330 maxvalue = -9999999.;
4331 for (int layer = 1; layer < 44; layer++) {
4332 for (int ring = firstRing[layer - 1]; ring < ntotRing[layer - 1] + firstRing[layer - 1]; ring++) {
4333 for (int module = 1; module < 200; module++) {
4334 int key = layer * 100000 + ring * 1000 + module;
4335 TmModule *mod = smoduleMap[key];
4336 if (mod != nullptr && !mod->notInUse()) {
4337 if (minvalue > mod->value)
4338 minvalue = mod->value;
4339 if (maxvalue < mod->value)
4340 maxvalue = mod->value;
4341 }
4342 }
4343 }
4344 }
4345 }
4346 for (int layer = 1; layer < 44; layer++) {
4347 std::ostringstream outs;
4348 outs << outputfilename << "layer" << layer << ".xml";
4349 xmlfile = new std::ofstream(outs.str().c_str(), std::ios::out);
4350 *xmlfile << "<?xml version=\"1.0\" standalone=\"no\"?>" << std::endl;
4351 *xmlfile << "<svg xmlns=\"http://www.w3.org/2000/svg\"" << std::endl;
4352 *xmlfile << "xmlns:svg=\"http://www.w3.org/2000/svg\"" << std::endl;
4353 *xmlfile << "xmlns:xlink=\"http://www.w3.org/1999/xlink\" >" << std::endl;
4354 *xmlfile << "<script type=\"text/ecmascript\" xlink:href=\"layer.js\" />" << std::endl;
4355 *xmlfile << "<svg id=\"mainMap\" x=\"0\" y=\"0\" viewBox=\"0 0 500 500\" width=\"700\" height=\"700\" "
4356 "onload=\"TrackerLayer.init()\">"
4357 << std::endl;
4358 if (layer < 31)
4359 *xmlfile << "<g id=\"layer\" transform=\" translate(0,400) rotate(270) scale(1.,1.)\" > " << std::endl;
4360 else
4361 *xmlfile << "<g id=\"layer\" transform=\" translate(0,400) rotate(270) scale(1.,0.8)\" > " << std::endl;
4362 *xmlfile << "<rect fill=\"lightblue\" stroke=\"none\" x=\"0\" y=\"0\" width=\"700\" height=\"700\" />" << std::endl;
4363 *xmlfile << "<svg:polygon id=\"fed\" mapAttribute=\"fed\" points=\"250,40 250,10 230,10 230,40\" "
4364 "onclick=\"chooseMap(evt);\" onmouseover=\"chooseMap(evt);\" onmouseout=\"chooseMap(evt);\" "
4365 "fill=\"rgb(0,127,255)\"/>"
4366 << std::endl;
4367 *xmlfile << "<svg:polygon id=\"fec\" mapAttribute=\"fec\" points=\"228,40 228,10 208,10 208,40\" "
4368 "onclick=\"chooseMap(evt);\" onmouseover=\"chooseMap(evt);\" onmouseout=\"chooseMap(evt);\" "
4369 "fill=\"rgb(0,127,255)\"/>"
4370 << std::endl;
4371 *xmlfile << "<svg:polygon id=\"lv\" mapAttribute=\"lv\" points=\"206,40 206,10 186,10 186,40\" "
4372 "onclick=\"chooseMap(evt);\" onmouseover=\"chooseMap(evt);\" onmouseout=\"chooseMap(evt);\" "
4373 "fill=\"rgb(0,127,255)\"/>"
4374 << std::endl;
4375 *xmlfile << "<svg:polygon id=\"hv\" mapAttribute=\"hv\" points=\"184,40 184,10 164,10 164,40\" "
4376 "onclick=\"chooseMap(evt);\" onmouseover=\"chooseMap(evt);\" onmouseout=\"chooseMap(evt);\" "
4377 "fill=\"rgb(0,127,255)\"/>"
4378 << std::endl;
4379 *xmlfile << "<svg:polygon id=\"plot\" mapAttribute=\"plot\" points=\"155,45 155,5 135,5 135,45\" "
4380 "onclick=\"chooseMap(evt);\" onmouseover=\"chooseMap(evt);\" onmouseout=\"chooseMap(evt);\" "
4381 "fill=\"rgb(200,0,0)\"/>"
4382 << std::endl;
4383
4384
4385 defwindow(layer);
4386 for (int ring = firstRing[layer - 1]; ring < ntotRing[layer - 1] + firstRing[layer - 1]; ring++) {
4387 for (int module = 1; module < 200; module++) {
4388 int key = layer * 100000 + ring * 1000 + module;
4389 TmModule *mod = smoduleMap[key];
4390 if (mod != nullptr && !mod->notInUse()) {
4391 drawModule(mod, key, layer, print_total, xmlfile);
4392 }
4393 }
4394 }
4395 *xmlfile << "</g> </svg> <text id=\"currentElementText\" x=\"40\" y=\"30\">" << std::endl;
4396 *xmlfile << "<tspan id=\"line1\" x=\"40\" y=\"30\"> </tspan> " << std::endl;
4397 *xmlfile << "<tspan id=\"line2\" x=\"40\" y=\"60\"> </tspan> " << std::endl;
4398 *xmlfile << "<tspan id=\"line3\" x=\"40\" y=\"90\"> </tspan> " << std::endl;
4399 *xmlfile << "<tspan id=\"line4\" x=\"40\" y=\"120\"> </tspan> " << std::endl;
4400 if (layer > 33) {
4401 *xmlfile << "<tspan mapAttribute=\"fed\" onclick=\"chooseMap(evt);\" onmouseover=\"chooseMap(evt);\" "
4402 "onmouseout=\"chooseMap(evt);\" x=\"15\" y=\"228\" font-size=\"12\" font-family=\"arial\" "
4403 "fill=\"white\">FED</tspan> "
4404 << std::endl;
4405 *xmlfile << "<tspan mapAttribute=\"fec\" onclick=\"chooseMap(evt);\" onmouseover=\"chooseMap(evt);\" "
4406 "onmouseout=\"chooseMap(evt);\" x=\"15\" y=\"258\" font-size=\"12\" font-family=\"arial\" "
4407 "fill=\"white\">FEC</tspan> "
4408 << std::endl;
4409 *xmlfile << "<tspan mapAttribute=\"lv\" onclick=\"chooseMap(evt);\" onmouseover=\"chooseMap(evt);\" "
4410 "onmouseout=\"chooseMap(evt);\" x=\"18\" y=\"289\" font-size=\"12\" font-family=\"arial\" "
4411 "fill=\"white\">LV</tspan> "
4412 << std::endl;
4413 *xmlfile << "<tspan mapAttribute=\"hv\" onclick=\"chooseMap(evt);\" onmouseover=\"chooseMap(evt);\" "
4414 "onmouseout=\"chooseMap(evt);\" x=\"18\" y=\"319\" font-size=\"12\" font-family=\"arial\" "
4415 "fill=\"white\">HV</tspan> "
4416 << std::endl;
4417 *xmlfile << "<tspan mapAttribute=\"plot\" onclick=\"chooseMap(evt);\" onmouseover=\"chooseMap(evt);\" "
4418 "onmouseout=\"chooseMap(evt);\" x=\"12\" y=\"360\" font-size=\"12\" font-family=\"arial\" "
4419 "fill=\"white\">PLOT</tspan> "
4420 << std::endl;
4421 } else {
4422 *xmlfile << "<tspan mapAttribute=\"fed\" onclick=\"chooseMap(evt);\" onmouseover=\"chooseMap(evt);\" "
4423 "onmouseout=\"chooseMap(evt);\" x=\"21\" y=\"228\" font-size=\"12\" font-family=\"arial\" "
4424 "fill=\"white\">FED</tspan> "
4425 << std::endl;
4426 *xmlfile << "<tspan mapAttribute=\"fec\" onclick=\"chooseMap(evt);\" onmouseover=\"chooseMap(evt);\" "
4427 "onmouseout=\"chooseMap(evt);\" x=\"21\" y=\"258\" font-size=\"12\" font-family=\"arial\" "
4428 "fill=\"white\">FEC</tspan> "
4429 << std::endl;
4430 *xmlfile << "<tspan mapAttribute=\"lv\" onclick=\"chooseMap(evt);\" onmouseover=\"chooseMap(evt);\" "
4431 "onmouseout=\"chooseMap(evt);\" x=\"24\" y=\"289\" font-size=\"12\" font-family=\"arial\" "
4432 "fill=\"white\">LV</tspan> "
4433 << std::endl;
4434 *xmlfile << "<tspan mapAttribute=\"hv\" onclick=\"chooseMap(evt);\" onmouseover=\"chooseMap(evt);\" "
4435 "onmouseout=\"chooseMap(evt);\" x=\"24\" y=\"319\" font-size=\"12\" font-family=\"arial\" "
4436 "fill=\"white\">HV</tspan> "
4437 << std::endl;
4438 *xmlfile << "<tspan mapAttribute=\"plot\" onclick=\"chooseMap(evt);\" onmouseover=\"chooseMap(evt);\" "
4439 "onmouseout=\"chooseMap(evt);\" x=\"17\" y=\"360\" font-size=\"12\" font-family=\"arial\" "
4440 "fill=\"white\">PLOT</tspan> "
4441 << std::endl;
4442 }
4443 *xmlfile << " </text> </svg>" << std::endl;
4444 xmlfile->close();
4445 delete xmlfile;
4446 }
4447 saveAsSingleLayer = false;
4448 }
4449
4450 TLegend *TrackerMap::buildLegend() {
4451 if (legInfos_.empty()) {
4452 legInfos_.reserve(8);
4453
4454 legInfos_.push_back(new TPolyLine(0));
4455 legInfos_.back()->SetFillColor(kGreen);
4456 legInfos_.push_back(new TPolyLine(0));
4457 legInfos_.back()->SetFillColor(kBlue - 9);
4458 legInfos_.push_back(new TPolyLine(0));
4459 legInfos_.back()->SetFillColor(kRed + 2);
4460 legInfos_.push_back(new TPolyLine(0));
4461 legInfos_.back()->SetFillColor(kPink - 9);
4462 legInfos_.push_back(new TPolyLine(0));
4463 legInfos_.back()->SetFillColor(kOrange + 2);
4464 legInfos_.push_back(new TPolyLine(0));
4465 legInfos_.back()->SetFillColor(kYellow);
4466 legInfos_.push_back(new TPolyLine(0));
4467 legInfos_.back()->SetFillColor(kRed + 1);
4468 legInfos_.push_back(new TPolyLine(0));
4469 legInfos_.back()->SetFillColor(kViolet - 5);
4470 legKeys_ = {"Good Modules",
4471 "Excluded FED",
4472 "FED errors",
4473 "# Clusters",
4474 "# Digis",
4475 "PCL bad",
4476 "# Clusters & Digis",
4477 "DCS Error"};
4478 }
4479
4480 TLegend *myL = new TLegend(0.56, 0.87, 0.95, 0.99);
4481 myL->SetNColumns(2);
4482 myL->SetBorderSize(0);
4483 myL->SetFillColor(38);
4484 for (unsigned int i = 0; i < legInfos_.size(); i++) {
4485 myL->AddEntry((TObject *)legInfos_[i], legKeys_[i].c_str(), "f");
4486 }
4487
4488 return myL;
4489 }