00001 #include "CommonTools/TrackerMap/interface/TrackerMap.h"
00002 #include "CommonTools/TrackerMap/interface/TmModule.h"
00003 #include "FWCore/ParameterSet/interface/ParameterSet.h"
00004 #include "FWCore/ParameterSet/interface/FileInPath.h"
00005 #include "CondFormats/SiStripObjects/interface/FedChannelConnection.h"
00006 #include "CommonTools/TrackerMap/interface/TmApvPair.h"
00007 #include <fstream>
00008 #include <vector>
00009 #include <iostream>
00010 #include <sstream>
00011 #include "TCanvas.h"
00012 #include "TPolyLine.h"
00013 #include "TStyle.h"
00014 #include "TColor.h"
00015 #include "TROOT.h"
00016
00017 using namespace std;
00018
00019
00020
00021
00022
00023
00024
00025 TrackerMap::TrackerMap(const edm::ParameterSet & tkmapPset,const edm::ESHandle<SiStripFedCabling> tkFed) {
00026
00027 psetAvailable=true;
00028 xsize=340;ysize=200;
00029 title=" ";
00030 jsPath="";
00031 jsfilename="CommonTools/TrackerMap/data/trackermap.txt";
00032 infilename="CommonTools/TrackerMap/data/tracker.dat";
00033 saveAsSingleLayer=false;
00034 if(tkmapPset.exists("trackermaptxtPath")){
00035 jsPath=tkmapPset.getUntrackedParameter<std::string>("trackermaptxtPath",""
00036 );
00037 jsfilename=jsPath+"trackermap.txt";
00038 cout << jsfilename << endl;
00039 infilename=tkmapPset.getUntrackedParameter<std::string>("trackerdatPath","")+"tracker.dat";
00040 cout << infilename << endl;
00041 ncrates=0;
00042 enableFedProcessing=tkmapPset.getUntrackedParameter<bool>("loadFedCabling",false);
00043 } else cout << "no parameters found" << endl;
00044
00045 init();
00046
00047 if(enableFedProcessing){
00048 const vector<unsigned short> feds = tkFed->feds();
00049 cout<<"SiStripFedCabling has "<< feds.size()<<" active FEDS"<<endl;
00050 int num_board=0;
00051 int num_crate;
00052 for(vector<unsigned short>::const_iterator ifed = feds.begin();ifed<feds.end();ifed++){
00053 const std::vector<FedChannelConnection> theconn = tkFed->connections( *ifed );
00054 int num_conn=0;
00055 for(std::vector<FedChannelConnection>::const_iterator iconn = theconn.begin();iconn<theconn.end();iconn++){
00056
00057 if( iconn->fedId()== sistrip::invalid_ ||
00058 iconn->detId() == sistrip::invalid_ ||
00059 iconn->detId() == sistrip::invalid32_ ||
00060 iconn->apvPairNumber() == sistrip::invalid_ ||
00061 iconn->nApvPairs() == sistrip::invalid_ ) {
00062 continue;
00063 }
00064
00065 TmModule *imod = imoduleMap[iconn->detId()];
00066 int key = iconn->fedId()*1000+iconn->fedCh();
00067 TmApvPair* apvpair = apvMap[key];
00068 if(apvpair!=0)cout << "Fed "<< iconn->fedId() << " channel " << iconn->fedCh() << " seem to be already loaded!"<<endl;
00069 else
00070 {
00071 num_conn++;
00072 if(num_conn==1){
00073 if(fedMap[iconn->fedId()]==0){num_crate=num_board/18+1;fedMap[iconn->fedId()]=num_crate;num_board++;}
00074 }
00075 apvpair = new TmApvPair(key,num_crate);
00076 apvpair->mod=imod;
00077 apvpair->mpos=iconn->apvPairNumber();
00078 apvMap[key] = apvpair;
00079 apvModuleMap.insert(make_pair(iconn->detId(),apvpair));
00080 stringstream s;
00081 iconn->print(s);
00082 apvpair->text=s.str();
00083 }
00084 }
00085 }
00086 ncrates=num_crate;
00087 cout << num_crate << " crates used "<< endl;
00088
00089 std::map<int , TmModule *>::iterator i_mod;
00090 for( i_mod=imoduleMap.begin();i_mod !=imoduleMap.end(); i_mod++){
00091 TmModule * mod= i_mod->second;
00092 if(mod!=0) {
00093 ostringstream outs,outs1;
00094 outs << " connected to ";
00095 outs1 << "(";
00096
00097 int idmod=mod->idex;
00098 int nchan=0;
00099 multimap<const int, TmApvPair*>::iterator pos;
00100 for (pos = apvModuleMap.lower_bound(idmod);
00101 pos != apvModuleMap.upper_bound(idmod); ++pos) {
00102 TmApvPair* apvpair = pos->second;
00103 if(apvpair!=0){
00104 outs << apvpair->mpos << " " <<apvpair->getFedId() << "/"<<apvpair->getFedCh()<<" ";
00105 outs1 << apvpair->idex+apvpair->crate*1000000<<",";
00106 nchan++;
00107 }
00108
00109 }
00110 outs<< "("<<nchan<<")";
00111 mod->name=mod->name + outs.str();
00112 string s = outs1.str(); s.erase(s.end()-1,s.end());
00113 mod->capvids=s+")";
00114 }
00115 }
00116 }
00117 }
00118
00119
00120 TrackerMap::TrackerMap(const edm::ParameterSet & tkmapPset) {
00121 psetAvailable=true;
00122 xsize=340;ysize=200;
00123 title=" ";
00124 jsfilename="CommonTools/TrackerMap/data/trackermap.txt";
00125 infilename="CommonTools/TrackerMap/data/tracker.dat";
00126 enableFedProcessing=false;ncrates=0;
00127 saveAsSingleLayer=false;
00128 if(tkmapPset.exists("trackermaptxtPath")){
00129 jsfilename=tkmapPset.getUntrackedParameter<std::string>("trackermaptxtPath","")+"trackermap.txt";
00130 cout << jsfilename << endl;
00131 infilename=tkmapPset.getUntrackedParameter<std::string>("trackerdatPath","")+"tracker.dat";
00132 cout << infilename << endl;
00133 } else cout << "no parameters found" << endl;
00134 init();
00135 }
00136
00137 TrackerMap::TrackerMap(string s,int xsize1,int ysize1) {
00138 psetAvailable=false;
00139 xsize=xsize1;ysize=ysize1;
00140 title=s;
00141 jsfilename="CommonTools/TrackerMap/data/trackermap.txt";
00142 infilename="CommonTools/TrackerMap/data/tracker.dat";
00143 enableFedProcessing=false;
00144 saveAsSingleLayer=false;
00145 init();
00146 }
00147
00148 void TrackerMap::init() {
00149
00150 int ntotmod=0;
00151 ix=0;iy=0;
00152 firstcall = true;
00153 minvalue=0.; maxvalue=minvalue;
00154 posrel=true;
00155 palette = 1;
00156 printflag=false;
00157 temporary_file=false;
00158
00159 ndet = 3;
00160 npart = 3;
00161
00162
00163 for (int subdet=1; subdet < ndet+1; subdet++){
00164 for (int detpart=1; detpart < npart+1; detpart++){
00165 int nlayers = getlayerCount(subdet,detpart);
00166 for(int layer=1; layer < nlayers+1; layer++){
00167 int nrings = getringCount(subdet,detpart,layer);
00168
00169 int layer_g = nlayer(subdet,detpart,layer);
00170 ntotRing[layer_g-1]=nrings;
00171 firstRing[layer_g-1]=1;
00172 if(subdet==3 && detpart!=2) firstRing[layer_g-1]= 8-nrings;
00173 for (int ring=firstRing[layer_g-1]; ring < ntotRing[layer_g-1]+firstRing[layer_g-1];ring++){
00174 int nmodules = getmoduleCount(subdet,detpart,layer,ring);
00175 int key;
00176 TmModule *smodule;
00177 for(int module=1; module < nmodules+1; module++){
00178 smodule = new TmModule(module,ring,layer_g);
00179 key=layer_g*100000+ring*1000+module;
00180 smoduleMap[key]=smodule;
00181 ntotmod++;
00182 }
00183 if(isRingStereo(key))for(int module=1; module < nmodules+1; module++){
00184 smodule = new TmModule(module+100,ring,layer_g);
00185 int key=layer_g*100000+ring*1000+module+100;
00186 smoduleMap[key]=smodule;
00187 ntotmod++;
00188 }
00189 }
00190 }
00191 }
00192 }
00193 build();
00194 }
00195
00196 TrackerMap::~TrackerMap() {
00197 }
00198 void TrackerMap::drawModule(TmModule * mod, int key,int nlay, bool print_total, ofstream * svgfile){
00199
00200 double phi,r,dx,dy, dy1;
00201 double xp[4],yp[4],xp1,yp1;
00202 double vhbot,vhtop,vhapo;
00203 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};
00204 double xt1,yt1,xs1=0.,ys1=0.,xt2,yt2,xs2,ys2,pv1,pv2;
00205 int green = 0;
00206 int red = 0;
00207 int blue = 0;
00208 double xd[4],yd[4];
00209 int np = 4;
00210
00211 int numod=0;
00212 phi = phival(mod->posx,mod->posy);
00213 r = sqrt(mod->posx*mod->posx+mod->posy*mod->posy);
00214 vhbot = mod->width;
00215 vhtop=mod->width;
00216 vhapo=mod->length;
00217 if(nlay < 31){
00218 vhbot = mod->widthAtHalfLength/2.-(mod->width/2.-mod->widthAtHalfLength/2.);
00219 vhtop=mod->width/2.;
00220 vhapo=mod->length/2.;
00221 if(nlay >12 && nlay <19){
00222 if(posrel)r = r+r;
00223 xp[0]=r-vhtop;yp[0]=-vhapo;
00224 xp[1]=r+vhtop;yp[1]=-vhapo;
00225 xp[2]=r+vhtop;yp[2]=vhapo;
00226 xp[3]=r-vhtop;yp[3]=vhapo;
00227 }else{
00228 if(posrel)r = r + r/3.;
00229 xp[0]=r-vhapo;yp[0]=-vhbot;
00230 xp[1]=r+vhapo;yp[1]=-vhtop;
00231 xp[2]=r+vhapo;yp[2]=vhtop;
00232 xp[3]=r-vhapo;yp[3]=vhbot;
00233 }
00234 for(int j=0;j<4;j++){
00235 xp1 = xp[j]*cos(phi)-yp[j]*sin(phi);
00236 yp1 = xp[j]*sin(phi)+yp[j]*cos(phi);
00237 xp[j] = xp1;yp[j]=yp1;
00238 }
00239 } else {
00240 numod=mod->idModule;if(numod>100)numod=numod-100;
00241 int vane = mod->ring;
00242 if(posrel){
00243 dx = vhapo;
00244 phi=M_PI;
00245 xt1=rmedio[nlay-31]; yt1=-vhtop/2.;
00246 xs1 = xt1*cos(phi)-yt1*sin(phi);
00247 ys1 = xt1*sin(phi)+yt1*cos(phi);
00248 xt2=rmedio[nlay-31]; yt2=vhtop/2.;
00249 xs2 = xt2*cos(phi)-yt2*sin(phi);
00250 ys2 = xt2*sin(phi)+yt2*cos(phi);
00251 dy=phival(xs2,ys2)-phival(xs1,ys1);
00252 dy1 = dy;
00253 if(nlay==31)dy1=0.39;
00254 if(nlay==32)dy1=0.23;
00255 if(nlay==33)dy1=0.16;
00256 xp[0]=vane*(dx+dx/8.);yp[0]=numod*(dy1);
00257 xp[1]=vane*(dx+dx/8.)+dx;yp[1]=numod*(dy1);
00258 xp[2]=vane*(dx+dx/8.)+dx;yp[2]=numod*(dy1)+dy;
00259 xp[3]=vane*(dx+dx/8.);yp[3]=numod*(dy1)+dy;
00260 }else{
00261 xt1=r; yt1=-vhtop/2.;
00262 xs1 = xt1*cos(phi)-yt1*sin(phi);
00263 ys1 = xt1*sin(phi)+yt1*cos(phi);
00264 xt2=r; yt2=vhtop/2.;
00265 xs2 = xt2*cos(phi)-yt2*sin(phi);
00266 ys2 = xt2*sin(phi)+yt2*cos(phi);
00267 pv1=phival(xs1,ys1);
00268 pv2=phival(xs2,ys2);
00269 if(fabs(pv1-pv2)>M_PI && numod==1)pv1=pv1-2.*M_PI;
00270 if(fabs(pv1-pv2)>M_PI && numod!=1)pv2=pv2+2.*M_PI;
00271 xp[0]=mod->posz-vhapo/2.;yp[0]=4.2*pv1;
00272 xp[1]=mod->posz+vhapo/2.;yp[1]=4.2*pv1;
00273 xp[2]=mod->posz+vhapo/2. ;yp[2]=4.2*pv2;
00274 xp[3]=mod->posz-vhapo/2.;yp[3]=4.2*pv2;
00275 }
00276 }
00277 if(isRingStereo(key))
00278 {
00279 np = 3;
00280 if(mod->idModule>100 ){for(int j=0;j<3;j++){
00281 xd[j]=xdpixel(xp[j]);yd[j]=ydpixel(yp[j]);
00282 }
00283 }else {
00284 xd[0]=xdpixel(xp[2]);yd[0]=ydpixel(yp[2]);
00285 xd[1]=xdpixel(xp[3]);yd[1]=ydpixel(yp[3]);
00286 xd[2]=xdpixel(xp[0]);yd[2]=ydpixel(yp[0]);
00287 }
00288 } else {
00289 for(int j=0;j<4;j++){
00290 xd[j]=xdpixel(xp[j]);yd[j]=ydpixel(yp[j]);
00291 }
00292 }
00293 char buffer [20];
00294 sprintf(buffer,"%X",mod->idex);
00295
00296 if(mod->red < 0){
00297 int color = getcolor(mod->value,palette);
00298 red=(color>>16)&0xFF;
00299 green=(color>>8)&0xFF;
00300 blue=(color)&0xFF;
00301
00302 if(!print_total)mod->value=mod->value*mod->count;
00303
00304 if(mod->count > 0)
00305 if(temporary_file) *svgfile << red << " " << green << " " << blue << " "; else
00306 *svgfile <<"<svg:polygon detid=\""<<mod->idex<<"\" count=\""<<mod->count <<"\" value=\""<<mod->value<<"\" id=\""<<key<<"\" capvids=\""<<mod->capvids<<"\" onclick=\"showData(evt);\" onmouseover=\"showData(evt);\" onmouseout=\"showData(evt);\" MESSAGE=\""<<mod->text<<"\" POS=\""<<mod->name<<" \" fill=\"rgb("<<red<<","<<green<<","<<blue<<")\" points=\"";
00307 else
00308 if(temporary_file) *svgfile << 255 << " " << 255 << " " << 255 << " "; else
00309 *svgfile <<"<svg:polygon detid=\""<<mod->idex<<"\" count=\""<<mod->count <<"\" value=\""<<mod->value<<"\" id=\""<<key<<"\" capvids=\""<<mod->capvids<<"\" onclick=\"showData(evt);\" onmouseover=\"showData(evt);\" onmouseout=\"showData(evt);\" MESSAGE=\""<<mod->text<<"\" POS=\""<<mod->name<<" \" fill=\"white\" points=\"";
00310 if(temporary_file) *svgfile << np << " ";
00311 for(int k=0;k<np;k++){
00312 if(temporary_file)*svgfile << xd[k] << " " << yd[k] << " " ; else
00313 *svgfile << xd[k] << "," << yd[k] << " " ;
00314 }
00315 if(temporary_file)*svgfile << endl; else *svgfile <<"\" />" <<endl;
00316 } else {
00317 if(mod->red>255)mod->red=255;
00318 if(mod->green>255)mod->green=255;
00319 if(mod->blue>255)mod->blue=255;
00320 if(temporary_file) *svgfile << mod->red << " " << mod->green << " " << mod->blue << " "; else
00321 *svgfile <<"<svg:polygon detid=\""<<mod->idex<<"\" count=\""<<mod->count <<"\" value=\""<<mod->value<<"\" id=\""<<key<<"\" capvids=\""<<mod->capvids<<"\" onclick=\"showData(evt);\" onmouseover=\"showData(evt);\" onmouseout=\"showData(evt);\" MESSAGE=\""<<mod->text<<"\" POS=\""<<mod->name<<" \" fill=\"rgb("<<mod->red<<","<<mod->green<<","<<mod->blue<<")\" points=\"";
00322 if(temporary_file) *svgfile << np << " ";
00323 for(int k=0;k<np;k++){
00324 if(temporary_file)*svgfile << xd[k] << " " << yd[k] << " " ; else
00325 *svgfile << xd[k] << "," << yd[k] << " " ;
00326 }
00327 if(temporary_file)*svgfile << endl; else *svgfile <<"\" />" <<endl;
00328 }
00329
00330 }
00331
00332
00333
00334
00335 void TrackerMap::save(bool print_total,float minval, float maxval,std::string s,int width, int height){
00336 std::string filetype=s,outputfilename=s;
00337 vector<TPolyLine*> vp;
00338 filetype.erase(0,filetype.find(".")+1);
00339 outputfilename.erase(outputfilename.begin()+outputfilename.find("."),outputfilename.end());
00340 temporary_file=true;
00341 if(filetype=="svg")temporary_file=false;
00342
00343 ostringstream outs;
00344 minvalue=minval; maxvalue=maxval;
00345 outs << outputfilename << ".coor";
00346 savefile = new ofstream(outs.str().c_str(),ios::out);
00347 if(!print_total){
00348 for (int layer=1; layer < 44; layer++){
00349 for (int ring=firstRing[layer-1]; ring < ntotRing[layer-1]+firstRing[layer-1];ring++){
00350 for (int module=1;module<200;module++) {
00351 int key=layer*100000+ring*1000+module;
00352 TmModule * mod = smoduleMap[key];
00353 if(mod !=0 && !mod->notInUse()){
00354 mod->value = mod->value / mod->count;
00355 }
00356 }
00357 }
00358 }
00359 }
00360 if(minvalue>=maxvalue){
00361 minvalue=9999999.;
00362 maxvalue=-9999999.;
00363 for (int layer=1; layer < 44; layer++){
00364 for (int ring=firstRing[layer-1]; ring < ntotRing[layer-1]+firstRing[layer-1];ring++){
00365 for (int module=1;module<200;module++) {
00366 int key=layer*100000+ring*1000+module;
00367 TmModule * mod = smoduleMap[key];
00368 if(mod !=0 && !mod->notInUse()){
00369 if (minvalue > mod->value)minvalue=mod->value;
00370 if (maxvalue < mod->value)maxvalue=mod->value;
00371 }
00372 }
00373 }
00374 }
00375 }
00376 if(!temporary_file){
00377 *savefile << "<?xml version=\"1.0\" standalone=\"no\" ?>"<<endl;
00378 *savefile << "<svg xmlns=\"https://www.w3.org/2000/svg\""<<endl;
00379 *savefile << "xmlns:svg=\"https://www.w3.org/2000/svg\" "<<endl;
00380 *savefile << "xmlns:xlink=\"https://www.w3.org/1999/xlink\">"<<endl;
00381 *savefile << "<svg:svg id=\"mainMap\" x=\"0\" y=\"0\" viewBox=\"0 0 3000 1600"<<"\" width=\""<<width<<"\" height=\""<<height<<"\">"<<endl;
00382 *savefile << "<svg:rect fill=\"lightblue\" stroke=\"none\" x=\"0\" y=\"0\" width=\"3000\" height=\"1600\" /> "<<endl;
00383 *savefile << "<svg:g id=\"tracker\" transform=\"translate(10,1500) rotate(270)\" style=\"fill:none;stroke:black;stroke-width:0;\"> "<<endl;
00384 }
00385 for (int layer=1; layer < 44; layer++){
00386 nlay=layer;
00387 defwindow(nlay);
00388 for (int ring=firstRing[layer-1]; ring < ntotRing[layer-1]+firstRing[layer-1];ring++){
00389 for (int module=1;module<200;module++) {
00390 int key=layer*100000+ring*1000+module;
00391 TmModule * mod = smoduleMap[key];
00392 if(mod !=0 && !mod->notInUse()){
00393 drawModule(mod,key,layer,print_total,savefile);
00394 }
00395 }
00396 }
00397 }
00398 if(!temporary_file){
00399 *savefile << "</svg:g>"<<endl;
00400 *savefile << " <svg:text id=\"Title\" class=\"normalText\" x=\"300\" y=\"0\">"<<title<<"</svg:text>"<<endl;
00401 }
00402 if(printflag)drawPalette(savefile);
00403 if(!temporary_file){
00404 *savefile << "</svg:svg>"<<endl;
00405 *savefile << "</svg>"<<endl;
00406 }
00407 savefile->close();
00408
00409 const char * command1;
00410 string tempfilename = outputfilename + ".coor";
00411 if(filetype=="svg"){
00412 string command = "mv "+tempfilename +" " +outputfilename + ".svg";
00413 command1=command.c_str();
00414 cout << "Executing " << command1 << endl;
00415 system(command1);
00416 }
00417 if (temporary_file){
00418 int red,green,blue,npoints,colindex,ncolor;
00419 double x[4],y[4];
00420 ifstream tempfile(tempfilename.c_str(),ios::in);
00421 TCanvas *MyC = new TCanvas("MyC", "TrackerMap",width,height);
00422 gPad->SetFillColor(38);
00423
00424 gPad->Range(0,0,3000,1600);
00425
00426
00427 ncolor=0;
00428 typedef std::map<int,int> ColorList;
00429 ColorList colorList;
00430 ColorList::iterator pos;
00431 TColor *col;
00432 while(!tempfile.eof()) {
00433 tempfile >> red >> green >> blue >> npoints;
00434 colindex=red+green*1000+blue*1000000;
00435 pos=colorList.find(colindex);
00436 if(pos == colorList.end()){ colorList[colindex]=ncolor+100; col =gROOT->GetColor(ncolor+100);
00437 if(col) col->SetRGB((Double_t)(red/255.),(Double_t)(green/255.),(Double_t)(blue/255.)); else TColor *c = new TColor(ncolor+100,(Double_t)(red/255.),(Double_t)(green/255.),(Double_t)(blue/255.));ncolor++;}
00438 for (int i=0;i<npoints;i++){
00439 tempfile >> x[i] >> y[i];
00440 }
00441 }
00442 if(ncolor>0 && ncolor<10000){
00443 Int_t colors[10000];
00444 for(int i=0;i<ncolor;i++){colors[i]=i+100;}
00445 gStyle->SetPalette(ncolor,colors);
00446 }
00447 tempfile.clear();
00448 tempfile.seekg(0,ios::beg);
00449 cout << "created palette with " << ncolor << " colors" << endl;
00450 while(!tempfile.eof()) {
00451 tempfile >> red >> green >> blue >> npoints;
00452 for (int i=0;i<npoints;i++){
00453 tempfile >> x[i] >> y[i];
00454 }
00455 colindex=red+green*1000+blue*1000000;
00456 pos=colorList.find(colindex);
00457 if(pos != colorList.end()){
00458 TPolyLine* pline = new TPolyLine(npoints,y,x);
00459 vp.push_back(pline);
00460 pline->SetFillColor(colorList[colindex]);
00461 pline->SetLineWidth(0);
00462 pline->Draw("f");
00463 }
00464 }
00465 MyC->Update();
00466 if(filetype=="png"){
00467 std::cout << "printing " << std::endl;
00468 string filename = outputfilename + ".png";
00469 MyC->Print(filename.c_str());
00470 }
00471 if(filetype=="jpg"){
00472 string filename = outputfilename + ".jpg";
00473 MyC->Print(filename.c_str());
00474 }
00475 if(filetype=="pdf"){
00476 string filename = outputfilename + ".pdf";
00477 MyC->Print(filename.c_str());
00478 }
00479 string command = "rm "+tempfilename ;
00480 command1=command.c_str();
00481 cout << "Executing " << command1 << endl;
00482 system(command1);
00483 MyC->Clear();
00484 delete MyC;
00485 for(vector<TPolyLine*>::iterator pos1=vp.begin();pos1!=vp.end();pos1++){
00486 delete (*pos1);}
00487
00488 }
00489
00490
00491 }
00492 void TrackerMap::drawApvPair(int crate, int numfed_incrate, bool print_total, TmApvPair* apvPair,ofstream * svgfile,bool useApvPairValue)
00493 {
00494 double xp[4],yp[4];
00495 int color;
00496 int green = 0;
00497 int red = 0;
00498 int blue = 0;
00499 double xd[4],yd[4];
00500 int np = 4;
00501 double boxinitx=0., boxinity=0.;
00502 double dx=.9,dy=.9;
00503 int numfedch_incolumn = 12;
00504 int numfedch_inrow = 8;
00505 int numfed_incolumn = 5;
00506 int numfed_inrow = 4;
00507 boxinitx=boxinitx+(numfed_incolumn-(numfed_incrate-1)/numfed_inrow)*14.;
00508 boxinity=boxinity+(numfed_inrow-(numfed_incrate-1)%numfed_inrow)*9.;
00509 boxinity=boxinity+numfedch_inrow-(apvPair->getFedCh()/numfedch_incolumn);
00510 boxinitx = boxinitx+numfedch_incolumn-(int)(apvPair->getFedCh()%numfedch_incolumn);
00511
00512 xp[0]=boxinitx;yp[0]=boxinity;
00513 xp[1]=boxinitx+dx;yp[1]=boxinity;
00514 xp[2]=boxinitx+dx;yp[2]=boxinity + dy;
00515 xp[3]=boxinitx;yp[3]=boxinity + dy;
00516 for(int j=0;j<4;j++){
00517 xd[j]=xdpixelc(xp[j]);yd[j]=ydpixelc(yp[j]);
00518
00519 }
00520
00521 char buffer [20];
00522 sprintf(buffer,"%X",apvPair->mod->idex);
00523 string s = apvPair->mod->name;
00524 s.erase(s.begin()+s.find("connected"),s.end());
00525
00526 if(useApvPairValue){
00527 if(apvPair->red < 0){
00528 if(apvPair->count > 0) {
00529 color = getcolor(apvPair->value,palette);
00530 red=(color>>16)&0xFF;
00531 green=(color>>8)&0xFF;
00532 blue=(color)&0xFF;
00533 if(!print_total)apvPair->value=apvPair->value*apvPair->count;
00534 if(temporary_file)*svgfile << red << " " << green << " " << blue << " ";
00535 else *svgfile <<"<svg:polygon detid=\""<<apvPair->idex<<"\" count=\""<<apvPair->count <<"\" value=\""<<apvPair->value<<"\" id=\""<<apvPair->idex+crate*1000000<<"\" cmodid=\""<<apvPair->mod->getKey()<<"\" onclick=\"showData(evt);\" onmouseover=\"showData(evt);\" onmouseout=\"showData(evt);\" MESSAGE=\"""\" POS=\"Fed/Ch "<<apvPair->getFedId()<<"/"<<apvPair->getFedCh()<<" connected to "<<s<<" Id "<<buffer<<" \" fill=\"rgb("<<red<<","<<green<<","<<blue<<")\" points=\"";
00536 } else {
00537 if(temporary_file)*svgfile << 255 << " " << 255 << " " << 255 << " ";
00538 else *svgfile <<"<svg:polygon detid=\""<<apvPair->idex<<"\" count=\""<<apvPair->count <<"\" value=\""<<apvPair->value<<"\" id=\""<<apvPair->idex+crate*1000000<<"\" cmodid=\""<<apvPair->mod->getKey()<<"\" onclick=\"showData(evt);\" onmouseover=\"showData(evt);\" onmouseout=\"showData(evt);\" MESSAGE=\"""\" POS=\"Fed/Ch "<<apvPair->getFedId()<<"/"<<apvPair->getFedCh()<<" connected to "<<s<<" Id "<<buffer<<" \" fill=\"white\" points=\"";
00539 }
00540 } else {
00541 if(apvPair->red>255)apvPair->red=255;
00542 if(apvPair->green>255)apvPair->green=255;
00543 if(apvPair->blue>255)apvPair->blue=255;
00544 if(temporary_file)*svgfile << apvPair->red << " " << apvPair->green << " " << apvPair->blue << " ";
00545 else *svgfile <<"<svg:polygon detid=\""<<apvPair->idex<<"\" count=\""<<apvPair->count <<"\" value=\""<<apvPair->value<<"\" id=\""<<apvPair->idex+crate*1000000<<"\" cmodid=\""<<apvPair->mod->getKey()<<"\" onclick=\"showData(evt);\" onmouseover=\"showData(evt);\" onmouseout=\"showData(evt);\" MESSAGE=\"""\" POS=\"Fed/Ch "<<apvPair->getFedId()<<"/"<<apvPair->getFedCh()<<" connected to "<<s<<" Id "<<buffer<<" \" fill=\"rgb("<<apvPair->red<<","<<apvPair->green<<","<<apvPair->blue<<")\" points=\"";
00546 }
00547 }else{
00548 if(apvPair->mod->red < 0){
00549 if(apvPair->mod->count > 0) {
00550 color = getcolor(apvPair->mod->value,palette);
00551 red=(color>>16)&0xFF;
00552 green=(color>>8)&0xFF;
00553 blue=(color)&0xFF;
00554 if(temporary_file)*svgfile << red << " " << green << " " << blue << " ";
00555 else *svgfile <<"<svg:polygon detid=\""<<apvPair->idex<<"\" count=\""<<apvPair->count <<"\" value=\""<<apvPair->value<<"\" id=\""<<apvPair->idex+crate*1000000<<"\" cmodid=\""<<apvPair->mod->getKey()<<"\" onclick=\"showData(evt);\" onmouseover=\"showData(evt);\" onmouseout=\"showData(evt);\" MESSAGE=\"""\" POS=\"Fed/Ch "<<apvPair->getFedId()<<"/"<<apvPair->getFedCh()<<" connected to "<<s<<" Id "<<buffer<<" \" fill=\"rgb("<<red<<","<<green<<","<<blue<<")\" points=\"";
00556 } else {
00557 if(temporary_file)*svgfile << 255 << " " << 255 << " " << 255 << " ";
00558 else *svgfile <<"<svg:polygon detid=\""<<apvPair->idex<<"\" count=\""<<apvPair->count <<"\" value=\""<<apvPair->value<<"\" id=\""<<apvPair->idex+crate*1000000<<"\" cmodid=\""<<apvPair->mod->getKey()<<"\" onclick=\"showData(evt);\" onmouseover=\"showData(evt);\" onmouseout=\"showData(evt);\" MESSAGE=\"""\" POS=\"Fed/Ch "<<apvPair->getFedId()<<"/"<<apvPair->getFedCh()<<" connected to "<<s<<" Id "<<buffer<<" \" fill=\"white\" points=\"";
00559 }
00560 } else {
00561 if(apvPair->mod->red>255)apvPair->mod->red=255;
00562 if(apvPair->mod->green>255)apvPair->mod->green=255;
00563 if(apvPair->mod->blue>255)apvPair->mod->blue=255;
00564 if(temporary_file)*svgfile << apvPair->mod->red << " " << apvPair->mod->green << " " << apvPair->mod->blue << " ";
00565 else *svgfile <<"<svg:polygon detid=\""<<apvPair->idex<<"\" count=\""<<apvPair->count <<"\" value=\""<<apvPair->value<<"\" id=\""<<apvPair->idex+crate*1000000<<"\" cmodid=\""<<apvPair->mod->getKey()<<"\" onclick=\"showData(evt);\" onmouseover=\"showData(evt);\" onmouseout=\"showData(evt);\" MESSAGE=\"""\" POS=\"Fed/Ch "<<apvPair->getFedId()<<"/"<<apvPair->getFedCh()<<" connected to "<<s<<" Id "<<buffer<<" \" fill=\"rgb("<<apvPair->mod->red<<","<<apvPair->mod->green<<","<<apvPair->mod->blue<<")\" points=\"";
00566 }
00567 }
00568 if(temporary_file)*svgfile << np << " ";
00569 for(int k=0;k<np;k++){
00570 if(temporary_file)*svgfile << xd[k] << " " << yd[k] << " " ;
00571 else *svgfile << xd[k] << "," << yd[k] << " " ;
00572 }
00573 if(temporary_file)*svgfile << endl;
00574 else *svgfile <<"\" />" <<endl;
00575 }
00576
00577 void TrackerMap::save_as_fedtrackermap(bool print_total,float minval, float maxval,std::string s,int width, int height){
00578 if(enableFedProcessing){
00579 std::string filetype=s,outputfilename=s;
00580 vector<TPolyLine*> vp;
00581 filetype.erase(0,filetype.find(".")+1);
00582 outputfilename.erase(outputfilename.begin()+outputfilename.find("."),outputfilename.end());
00583 temporary_file=true;
00584 if(filetype=="xml"||filetype=="svg")temporary_file=false;
00585 ostringstream outs;
00586 minvalue=minval; maxvalue=maxval;
00587 outs << outputfilename << ".coor";
00588 if(temporary_file)savefile = new ofstream(outs.str().c_str(),ios::out);
00589 std::map<int , TmApvPair *>::iterator i_apv;
00590 std::map<int , int>::iterator i_fed;
00591
00592 bool useApvPairValue=false;
00593 for( i_apv=apvMap.begin();i_apv !=apvMap.end(); i_apv++){
00594 TmApvPair * apvPair= i_apv->second;
00595 if(apvPair!=0) {
00596 TmModule * apv_mod = apvPair->mod;
00597 if(apv_mod !=0 && !apv_mod->notInUse()){
00598 if(apvPair->count > 0 || apvPair->red!=-1) { useApvPairValue=true; break;}
00599 }
00600 }
00601 }
00602 if(!print_total){
00603 for( i_apv=apvMap.begin();i_apv !=apvMap.end(); i_apv++){
00604 TmApvPair * apvPair= i_apv->second;
00605 if(apvPair!=0) {
00606 TmModule * apv_mod = apvPair->mod;
00607 if(apv_mod !=0 && !apv_mod->notInUse()){
00608 if(useApvPairValue) apvPair->value = apvPair->value / apvPair->count;
00609 else if(apvPair->mpos==0)apv_mod->value = apv_mod->value / apv_mod->count;
00610 }
00611 }
00612 }
00613 }
00614 if(minvalue>=maxvalue){
00615
00616 minvalue=9999999.;
00617 maxvalue=-9999999.;
00618 for(i_apv=apvMap.begin();i_apv !=apvMap.end(); i_apv++){
00619 TmApvPair * apvPair= i_apv->second;
00620 if(apvPair!=0) {
00621 TmModule * apv_mod = apvPair->mod;
00622 if( apv_mod !=0 && !apv_mod->notInUse()){
00623 if(useApvPairValue){
00624 if (minvalue > apvPair->value)minvalue=apvPair->value;
00625 if (maxvalue < apvPair->value)maxvalue=apvPair->value;
00626 } else {
00627 if (minvalue > apv_mod->value)minvalue=apv_mod->value;
00628 if (maxvalue < apv_mod->value)maxvalue=apv_mod->value;
00629 }
00630 }
00631 }
00632 }
00633 }
00634 if(filetype=="svg"){
00635 saveAsSingleLayer=false;
00636 ostringstream outs;
00637 outs << outputfilename<<".svg";
00638 savefile = new ofstream(outs.str().c_str(),ios::out);
00639 *savefile << "<?xml version=\"1.0\" standalone=\"no\" ?>"<<endl;
00640 *savefile << "<svg xmlns=\"https://www.w3.org/2000/svg\""<<endl;
00641 *savefile << "xmlns:svg=\"https://www.w3.org/2000/svg\" "<<endl;
00642 *savefile << "xmlns:xlink=\"https://www.w3.org/1999/xlink\">"<<endl;
00643 *savefile << "<svg:svg id=\"mainMap\" x=\"0\" y=\"0\" viewBox=\"0 0 3000 1600"<<"\" width=\""<<width<<"\" height=\""<<height<<"\">"<<endl;
00644 *savefile << "<svg:rect fill=\"lightblue\" stroke=\"none\" x=\"0\" y=\"0\" width=\"3000\" height=\"1600\" /> "<<endl;
00645 *savefile << "<svg:g id=\"fedtrackermap\" transform=\"translate(10,1500) rotate(270)\" style=\"fill:none;stroke:black;stroke-width:0;\"> "<<endl;
00646 }
00647 for (int crate=1; crate < (ncrates+1); crate++){
00648 if(filetype=="xml"){
00649 saveAsSingleLayer=true;
00650 ostringstream outs;
00651 outs << outputfilename<<"crate" <<crate<< ".xml";
00652 savefile = new ofstream(outs.str().c_str(),ios::out);
00653 *savefile << "<?xml version=\"1.0\" standalone=\"no\"?>"<<endl;
00654 *savefile << "<svg xmlns=\"https://www.w3.org/2000/svg\""<<endl;
00655 *savefile << "xmlns:svg=\"https://www.w3.org/2000/svg\""<<endl;
00656 *savefile << "xmlns:xlink=\"https://www.w3.org/1999/xlink\" >"<<endl;
00657 *savefile << "<script type=\"text/ecmascript\" xlink:href=\"crate.js\" />"<<endl;
00658 *savefile << "<svg id=\"mainMap\" x=\"0\" y=\"0\" viewBox=\"0 0 500 500\" width=\"700\" height=\"700\" onload=\"TrackerCrate.init()\">"<<endl;
00659 *savefile << "<rect fill=\"lightblue\" stroke=\"none\" x=\"0\" y=\"0\" width=\"700\" height=\"700\" />"<<endl;
00660 *savefile << "<g id=\"crate\" transform=\" translate(150,500) rotate(270) scale(1.,1.)\" > "<<endl;
00661 }
00662 ncrate=crate;
00663 defcwindow(ncrate);
00664 int numfed_incrate=0;
00665 for (i_fed=fedMap.begin();i_fed != fedMap.end(); i_fed++){
00666 if(i_fed->second == crate){
00667 int fedId = i_fed->first;
00668 numfed_incrate++;
00669 for (int nconn=0;nconn<96;nconn++){
00670 int key = fedId*1000+nconn;
00671 TmApvPair * apvPair= apvMap[key];
00672 if(apvPair !=0){
00673 TmModule * apv_mod = apvPair->mod;
00674 if(apv_mod !=0 && !apv_mod->notInUse()){
00675 drawApvPair(crate,numfed_incrate,print_total,apvPair,savefile,useApvPairValue);
00676 }
00677 }
00678 }
00679 }
00680 }
00681 if(!temporary_file){
00682 if(filetype=="xml"){
00683 *savefile << "</g> </svg> <text id=\"currentElementText\" x=\"40\" y=\"30\"> " << endl;
00684 *savefile << "<tspan id=\"line1\" x=\"40\" y=\"30\"> </tspan> " << endl;
00685 *savefile << "<tspan id=\"line2\" x=\"40\" y=\"60\"> </tspan> " << endl;
00686 *savefile << " </text> </svg>" << endl;
00687 savefile->close();
00688 saveAsSingleLayer=false;
00689 }
00690 }
00691 }
00692 if(filetype=="svg"){
00693 *savefile << "</g> </svg> </svg> " << endl;
00694 savefile->close();
00695 }
00696 if(!print_total && !useApvPairValue){
00697
00698 for( i_apv=apvMap.begin();i_apv !=apvMap.end(); i_apv++){
00699 TmApvPair * apvPair= i_apv->second;
00700 if(apvPair!=0) {
00701 TmModule * apv_mod = apvPair->mod;
00702 if(apv_mod !=0 && apvPair->mpos==0 && !apv_mod->notInUse()){
00703 apv_mod->value = apv_mod->value * apv_mod->count;
00704 }
00705 }
00706 }
00707 }
00708
00709 if(temporary_file){
00710 if(printflag)drawPalette(savefile);
00711 savefile->close();
00712
00713 const char * command1;
00714 string tempfilename = outputfilename + ".coor";
00715 int red,green,blue,npoints,colindex,ncolor;
00716 double x[4],y[4];
00717 ifstream tempfile(tempfilename.c_str(),ios::in);
00718 TCanvas *MyC = new TCanvas("MyC", "TrackerMap",width,height);
00719 gPad->SetFillColor(38);
00720
00721 gPad->Range(0,0,3000,1600);
00722
00723
00724 ncolor=0;
00725 typedef std::map<int,int> ColorList;
00726 ColorList colorList;
00727 ColorList::iterator pos;
00728 TColor *col;
00729 while(!tempfile.eof()) {
00730 tempfile >> red >> green >> blue >> npoints;
00731 colindex=red+green*1000+blue*1000000;
00732 pos=colorList.find(colindex);
00733 if(pos == colorList.end()){
00734 colorList[colindex]=ncolor+100;
00735 col =gROOT->GetColor(ncolor+100);
00736 if(col)
00737 col->SetRGB((Double_t)(red/255.),(Double_t)(green/255.),(Double_t)(blue/255.));
00738 else
00739 TColor *c = new TColor(ncolor+100,(Double_t)(red/255.),(Double_t)(green/255.),(Double_t)(blue/255.));
00740 ncolor++;
00741 }
00742 for (int i=0;i<npoints;i++){
00743 tempfile >> x[i] >> y[i];
00744 }
00745 }
00746 if(ncolor>0 && ncolor<10000){
00747 Int_t colors[10000];
00748 for(int i=0;i<ncolor;i++){colors[i]=i+100;}
00749 gStyle->SetPalette(ncolor,colors);
00750 }
00751 tempfile.clear();
00752 tempfile.seekg(0,ios::beg);
00753 cout << "created palette with " << ncolor << " colors" << endl;
00754 while(!tempfile.eof()) {
00755 tempfile >> red >> green >> blue >> npoints;
00756 for (int i=0;i<npoints;i++){
00757 tempfile >> x[i] >> y[i];
00758 }
00759 colindex=red+green*1000+blue*1000000;
00760 pos=colorList.find(colindex);
00761 if(pos != colorList.end()){
00762 TPolyLine* pline = new TPolyLine(npoints,y,x);
00763 vp.push_back(pline);
00764 pline->SetFillColor(colorList[colindex]);
00765 pline->SetLineWidth(0);
00766 pline->Draw("f");
00767 }
00768 }
00769 MyC->Update();
00770 std::cout << "Filetype " << filetype << std::endl;
00771 if(filetype=="png"){
00772 string filename = outputfilename + ".png";
00773 MyC->Print(filename.c_str());
00774 }
00775 if(filetype=="jpg"){
00776 string filename = outputfilename + ".jpg";
00777 MyC->Print(filename.c_str());
00778 }
00779 if(filetype=="pdf"){
00780 string filename = outputfilename + ".pdf";
00781 MyC->Print(filename.c_str());
00782 }
00783 string command = "rm "+tempfilename ;
00784 command1=command.c_str();
00785 cout << "Executing " << command1 << endl;
00786 system(command1);
00787 MyC->Clear();
00788 delete MyC;
00789 for(vector<TPolyLine*>::iterator pos1=vp.begin();pos1!=vp.end();pos1++){
00790 delete (*pos1);}
00791
00792
00793 }
00794 }
00795 }
00796
00797
00798
00799
00800 void TrackerMap::print(bool print_total, float minval, float maxval, string outputfilename){
00801 temporary_file=false;
00802 ostringstream outs;
00803 minvalue=minval; maxvalue=maxval;
00804 outs << outputfilename << ".xml";
00805 svgfile = new ofstream(outs.str().c_str(),ios::out);
00806 jsfile = new ifstream(edm::FileInPath(jsfilename).fullPath().c_str(),ios::in);
00807
00808
00809 string line;
00810 while (getline( *jsfile, line ))
00811 {
00812 *svgfile << line << endl;
00813 }
00814
00815 if(!print_total){
00816 for (int layer=1; layer < 44; layer++){
00817 for (int ring=firstRing[layer-1]; ring < ntotRing[layer-1]+firstRing[layer-1];ring++){
00818 for (int module=1;module<200;module++) {
00819 int key=layer*100000+ring*1000+module;
00820 TmModule * mod = smoduleMap[key];
00821 if(mod !=0 && !mod->notInUse()){
00822 mod->value = mod->value / mod->count;
00823 }
00824 }
00825 }
00826 }
00827 }
00828 if(minvalue>=maxvalue){
00829 minvalue=9999999.;
00830 maxvalue=-9999999.;
00831 for (int layer=1; layer < 44; layer++){
00832 for (int ring=firstRing[layer-1]; ring < ntotRing[layer-1]+firstRing[layer-1];ring++){
00833 for (int module=1;module<200;module++) {
00834 int key=layer*100000+ring*1000+module;
00835 TmModule * mod = smoduleMap[key];
00836 if(mod !=0 && !mod->notInUse()){
00837 if (minvalue > mod->value)minvalue=mod->value;
00838 if (maxvalue < mod->value)maxvalue=mod->value;
00839 }
00840 }
00841 }
00842 }
00843 }
00844 for (int layer=1; layer < 44; layer++){
00845 nlay=layer;
00846 defwindow(nlay);
00847 for (int ring=firstRing[layer-1]; ring < ntotRing[layer-1]+firstRing[layer-1];ring++){
00848 for (int module=1;module<200;module++) {
00849 int key=layer*100000+ring*1000+module;
00850 TmModule * mod = smoduleMap[key];
00851 if(mod !=0 && !mod->notInUse()){
00852 drawModule(mod,key,layer,print_total,svgfile);
00853 }
00854 }
00855 }
00856 }
00857 *svgfile << "</svg:g></svg:svg>"<<endl;
00858 *svgfile << " <svg:text id=\"Title\" class=\"normalText\" x=\"300\" y=\"0\">"<<title<<"</svg:text>"<<endl;
00859 if(printflag)drawPalette(svgfile);
00860 *svgfile << "</svg:svg>"<<endl;
00861 *svgfile << "</body></html>"<<endl;
00862 svgfile->close();
00863
00864 }
00865
00866 void TrackerMap::drawPalette(ofstream * svgfile){
00867 int color,red, green, blue;
00868 float val=minvalue;
00869 int paletteLength = 250;
00870 float dval = (maxvalue-minvalue)/(float)paletteLength;
00871 for(int i=0;i<paletteLength;i++){
00872 color = getcolor(val,palette);
00873 red=(color>>16)&0xFF;
00874 green=(color>>8)&0xFF;
00875 blue=(color)&0xFF;
00876 if(!temporary_file)*svgfile <<"<svg:rect x=\""<<i<<"\" y=\"0\" width=\"1\" height=\"20\" fill=\"rgb("<<red<<","<<green<<","<<blue<<")\" />\n";
00877 if(i%50 == 0){
00878 if(!temporary_file)*svgfile <<"<svg:rect x=\""<<i<<"\" y=\"10\" width=\"1\" height=\"10\" fill=\"black\" />\n";
00879 if(i%100==0&&!temporary_file)*svgfile << " <svg:text class=\"normalText\" x=\""<<i<<"\" y=\"30\">" <<val<<"</svg:text>"<<endl;
00880 }
00881 val = val + dval;
00882 }
00883 }
00884 void TrackerMap::fillc_fed_channel(int fedId,int fedCh, int red, int green, int blue )
00885 {
00886 int key = fedId*1000+fedCh;
00887 TmApvPair* apvpair = apvMap[key];
00888
00889 if(apvpair!=0){
00890 apvpair->red=red; apvpair->green=green; apvpair->blue=blue;
00891 return;
00892 }
00893 cout << "*** error in FedTrackerMap fillc method ***";
00894 }
00895
00896 void TrackerMap::fill_fed_channel(int idmod, float qty )
00897 {
00898 multimap<const int, TmApvPair*>::iterator pos;
00899 for (pos = apvModuleMap.lower_bound(idmod);
00900 pos != apvModuleMap.upper_bound(idmod); ++pos) {
00901 TmApvPair* apvpair = pos->second;
00902 if(apvpair!=0){
00903 apvpair->value=apvpair->value+qty;
00904 apvpair->count++;
00905 }
00906 }
00907 return;
00908 cout << "*** error in FedTrackerMap fill by module method ***";
00909 }
00910
00911 void TrackerMap::fill_current_val_fed_channel(int fedId, int fedCh, float current_val )
00912 {
00913 int key = fedId*1000+fedCh;
00914 TmApvPair* apvpair = apvMap[key];
00915
00916 if(apvpair!=0) apvpair->value=current_val;
00917 else
00918 cout << "*** error in FedTrackerMap fill_current_val method ***";
00919 }
00920
00921 int TrackerMap::module(int fedId, int fedCh)
00922 {
00923 int key = fedId*1000+fedCh;
00924 TmApvPair* apvpair = apvMap[key];
00925 if(apvpair!=0){
00926 return(apvpair->mod->idex);
00927 }
00928 return(0);
00929 cout << "*** error in FedTrackerMap module method ***";
00930 }
00931 void TrackerMap::fill_fed_channel(int fedId, int fedCh, float qty )
00932 {
00933 int key = fedId*1000+fedCh;
00934 TmApvPair* apvpair = apvMap[key];
00935 if(apvpair!=0){
00936 apvpair->value=apvpair->value+qty;
00937 apvpair->count++;
00938 return;
00939 }
00940 cout << "*** error inFedTrackerMap fill method ***";
00941 }
00942 void TrackerMap::fillc(int idmod, int red, int green, int blue ){
00943
00944 TmModule * mod = imoduleMap[idmod];
00945 if(mod!=0){
00946 mod->red=red; mod->green=green; mod->blue=blue;
00947 return;
00948 }
00949 cout << "**************************error in fill method **************";
00950 }
00951 void TrackerMap::fillc(int layer, int ring, int nmod, int red, int green, int blue ){
00952
00953 int key = layer*10000+ring*1000+nmod;
00954 TmModule * mod = smoduleMap[key];
00955
00956 if(mod!=0){
00957 mod->red=red; mod->green=green; mod->blue=blue;
00958 return;
00959 }
00960 cout << "**************************error in fill method **************";
00961 }
00962
00963 void TrackerMap::fill_current_val(int idmod, float current_val ){
00964
00965 TmModule * mod = imoduleMap[idmod];
00966 if(mod!=0) mod->value=current_val;
00967 else cout << "**error in fill_current_val method ***";
00968 }
00969
00970 void TrackerMap::fill(int idmod, float qty ){
00971
00972 TmModule * mod = imoduleMap[idmod];
00973 if(mod!=0){
00974 mod->value=mod->value+qty;
00975 mod->count++;
00976 return;
00977 }
00978 cout << "**************************error in fill method **************";
00979 }
00980
00981 void TrackerMap::fill(int layer, int ring, int nmod, float qty){
00982
00983 int key = layer*100000+ring*1000+nmod;
00984 TmModule * mod = smoduleMap[key];
00985 if(mod!=0){
00986 mod->value=mod->value+qty;
00987 mod->count++;
00988 }
00989 else cout << "**************************error in SvgModuleMap **************";
00990 }
00991
00992 void TrackerMap::setText(int idmod, string s){
00993
00994 TmModule * mod = imoduleMap[idmod];
00995 if(mod!=0){
00996 mod->text=s;
00997 }
00998 else cout << "**************************error in IdModuleMap **************";
00999 }
01000
01001
01002 void TrackerMap::setText(int layer, int ring, int nmod, string s){
01003
01004 int key = layer*100000+ring*1000+nmod;
01005 TmModule * mod = smoduleMap[key];
01006 if(mod!=0){
01007 mod->text=s;
01008 }
01009 else cout << "**************************error in SvgModuleMap **************";
01010 }
01011
01012
01013 void TrackerMap::build(){
01014
01015
01016 int nmods, pix_sil, fow_bar, ring, nmod, layer;
01017 unsigned int idex;
01018 float posx, posy, posz, length, width, thickness, widthAtHalfLength;
01019 int iModule=0,old_layer=0, ntotMod =0;
01020 string name,dummys;
01021 ifstream infile(edm::FileInPath(infilename).fullPath().c_str(),ios::in);
01022 while(!infile.eof()) {
01023 infile >> nmods >> pix_sil >> fow_bar >> layer >> ring >> nmod >> posx >> posy
01024 >> posz>> length >> width >> thickness
01025 >> widthAtHalfLength >> idex ;
01026 getline(infile,dummys);
01027 getline(infile,name);
01028 if(old_layer!=layer){old_layer=layer;iModule=0;}
01029 iModule++;
01030 ntotMod++;
01031 int key=layer*100000+ring*1000+nmod;
01032 TmModule * mod = smoduleMap[key];
01033
01034 imoduleMap[idex]=mod;
01035
01036 if(mod==0) cout << "error in module "<<key <<endl;
01037 else
01038 {
01039 mod->posx = posx;
01040 mod->posy = posy;
01041 mod->setUsed();
01042 mod->value=0;
01043 mod->count=0;
01044 mod->posz = posz;
01045 mod->length = length;
01046 mod->width = width;
01047 mod->thickness = thickness;
01048 mod->widthAtHalfLength = widthAtHalfLength;
01049 mod->idex = idex;
01050 mod->name = name;
01051 }
01052 }
01053 infile.close();
01054 number_modules = ntotMod-1;
01055 }
01056 int TrackerMap::getcolor(float value,int palette){
01057 int red,green,blue;
01058 if(palette==1){
01059 float delta=(maxvalue-minvalue);
01060 float x =(value-minvalue);
01061 red = (int) ( x<(delta/2) ? 0 : ( x > ((3./4.)*delta) ? 255 : 255/(delta/4) * (x-(2./4.)*delta) ) );
01062 green= (int) ( x<delta/4 ? (x*255/(delta/4)) : ( x > ((3./4.)*delta) ? 255-255/(delta/4) *(x-(3./4.)*delta) : 255 ) );
01063 blue = (int) ( x<delta/4 ? 255 : ( x > ((1./2.)*delta) ? 0 : 255-255/(delta/4) * (x-(1./4.)*delta) ) );
01064 }
01065 if (palette==2){
01066 green = (int)((value-minvalue)/(maxvalue-minvalue)*256.);
01067 if (green > 255) green=255;
01068 red = 255; blue=0;green=255-green;
01069 }
01070 return(blue|(green<<8)|(red<<16));
01071 }
01072 void TrackerMap::printonline(){
01073
01074 std::ofstream * ofilename;
01075 std::ifstream * ifilename;
01076 std::ostringstream ofname;
01077 std::string ifname;
01078 string line;
01079 bool print_total = true;
01080 float minval = 0.;
01081 float maxval = 0.;
01082 string outputfilename="dqmtmap";
01083 ifilename=findfile("viewerHeader.xhtml");
01084 ofname << outputfilename << "viewer.xhtml";
01085 ofilename = new ofstream(ofname.str().c_str(),ios::out);
01086 while (getline( *ifilename, line )) { *ofilename << line << endl; }
01087 *ofilename <<" var tmapname=\"" <<outputfilename << "\""<<endl;
01088 *ofilename <<" var ncrates=" <<ncrates << ";"<<endl;
01089 ifilename=findfile("viewerTrailer.xhtml");
01090 while (getline( *ifilename, line )) { *ofilename << line << endl; }
01091 ofname.str("");
01092 ifilename=findfile("viewer.css");
01093 ofname << "viewer.css";
01094 ofilename = new ofstream(ofname.str().c_str(),ios::out);
01095 while (getline( *ifilename, line )) { *ofilename << line << endl; }
01096 ofname.str("");
01097 ifilename=findfile("viewer.js");
01098 ofname << "viewer.js";
01099 ofilename = new ofstream(ofname.str().c_str(),ios::out);
01100 while (getline( *ifilename, line )) { *ofilename << line << endl; }
01101 ofname.str("");
01102 ifilename=findfile("crate.js");
01103 ofname << "crate.js";
01104 ofilename = new ofstream(ofname.str().c_str(),ios::out);
01105 while (getline( *ifilename, line )) { *ofilename << line << endl; }
01106 ofname.str("");
01107 ifilename=findfile("layer.js");
01108 ofname << "layer.js";
01109 ofilename = new ofstream(ofname.str().c_str(),ios::out);
01110 while (getline( *ifilename, line )) { *ofilename << line << endl; }
01111
01112 ostringstream outs,outs1,outs2;
01113 outs << outputfilename<<".png";
01114 save(true,0.,0.,outs.str(),3000,1600);
01115 temporary_file=false;
01116 printlayers(true,0.,0.,outputfilename);
01117
01118
01119 ofstream * txtfile;
01120 for (int layer=1; layer < 44; layer++){
01121 ostringstream outs;
01122 outs << outputfilename <<"layer"<<layer<< ".html";
01123 txtfile = new ofstream(outs.str().c_str(),ios::out);
01124 *txtfile << "<html><head></head> <body>" << endl;
01125 for (int ring=firstRing[layer-1]; ring < ntotRing[layer-1]+firstRing[layer-1];ring++){
01126 for (int module=1;module<200;module++) {
01127 int key=layer*100000+ring*1000+module;
01128 TmModule * mod = smoduleMap[key];
01129 if(mod !=0 && !mod->notInUse()){
01130 int idmod=mod->idex;
01131 int nchan=0;
01132 *txtfile << "<a name="<<idmod<<"><pre>"<<endl;
01133 multimap<const int, TmApvPair*>::iterator pos;
01134 for (pos = apvModuleMap.lower_bound(idmod);
01135 pos != apvModuleMap.upper_bound(idmod); ++pos) {
01136 TmApvPair* apvpair = pos->second;
01137 if(apvpair!=0){
01138 nchan++;
01139 *txtfile << apvpair->text << endl;
01140 }
01141
01142 }
01143 *txtfile << "</pre><h3>"<< mod->name<<"</h3>"<<endl;
01144 }
01145 }
01146 }
01147 *txtfile << "</body></html>" << endl;
01148 txtfile->close();
01149 }
01150 if(enableFedProcessing){
01151 outs1 << outputfilename<<"fed.png";
01152 save_as_fedtrackermap(true,0.,0.,outs1.str(),6000,3200);
01153 outs2 << outputfilename<<".xml";
01154 save_as_fedtrackermap(true,0.,0.,outs2.str(),3000,1600);
01155
01156 std::map<int , int>::iterator i_fed;
01157 ofstream * txtfile;
01158 for (int crate=1; crate < (ncrates+1); crate++){
01159 ostringstream outs;
01160 outs << outputfilename <<"crate"<<crate<< ".html";
01161 txtfile = new ofstream(outs.str().c_str(),ios::out);
01162 *txtfile << "<html><head></head> <body>" << endl;
01163 for (i_fed=fedMap.begin();i_fed != fedMap.end(); i_fed++){
01164 if(i_fed->second == crate){
01165 int fedId = i_fed->first;
01166 for (int nconn=0;nconn<96;nconn++){
01167 int key = fedId*1000+nconn;
01168 TmApvPair * apvPair= apvMap[key];
01169 if(apvPair !=0){
01170 int idmod=apvPair->idex;
01171 *txtfile << "<a name="<<idmod<<"><pre>"<<endl;
01172 *txtfile << apvPair->text << endl;
01173 ostringstream outs;
01174 outs << "fedchannel " <<apvPair->getFedId() << "/"<<apvPair->getFedCh()<<" connects to module " << apvPair->mod->idex ;
01175 *txtfile << "</pre><h3>"<< outs.str()<<"</h3>"<<endl;
01176 }
01177 }
01178 }
01179 }
01180 *txtfile << "</body></html>" << endl;
01181 txtfile->close();
01182 }
01183 }
01184 }
01185 void TrackerMap::printall(bool print_total, float minval, float maxval, string outputfilename){
01186
01187 std::ofstream * ofilename;
01188 std::ifstream * ifilename;
01189 std::ostringstream ofname;
01190 std::string ifname;
01191 string line;
01192 ifilename=findfile("viewerHeader.xhtml");
01193 ofname << outputfilename << "viewer.xhtml";
01194 ofilename = new ofstream(ofname.str().c_str(),ios::out);
01195 while (getline( *ifilename, line )) { *ofilename << line << endl; }
01196 *ofilename <<" var tmapname=\"" <<outputfilename << "\""<<endl;
01197 *ofilename <<" var ncrates=" <<ncrates << ";"<<endl;
01198 ifilename=findfile("viewerTrailer.xhtml");
01199 while (getline( *ifilename, line )) { *ofilename << line << endl; }
01200 ofname.str("");
01201 ifilename=findfile("viewer.css");
01202 ofname << "viewer.css";
01203 ofilename = new ofstream(ofname.str().c_str(),ios::out);
01204 while (getline( *ifilename, line )) { *ofilename << line << endl; }
01205 ofname.str("");
01206 ifilename=findfile("viewer.js");
01207 ofname << "viewer.js";
01208 ofilename = new ofstream(ofname.str().c_str(),ios::out);
01209 while (getline( *ifilename, line )) { *ofilename << line << endl; }
01210 ofname.str("");
01211 ifilename=findfile("crate.js");
01212 ofname << "crate.js";
01213 ofilename = new ofstream(ofname.str().c_str(),ios::out);
01214 while (getline( *ifilename, line )) { *ofilename << line << endl; }
01215 ofname.str("");
01216 ifilename=findfile("layer.js");
01217 ofname << "layer.js";
01218 ofilename = new ofstream(ofname.str().c_str(),ios::out);
01219 while (getline( *ifilename, line )) { *ofilename << line << endl; }
01220
01221 ostringstream outs,outs1,outs2;
01222 outs << outputfilename<<".png";
01223 save(true,0.,0.,outs.str(),3000,1600);
01224 temporary_file=false;
01225 printlayers(true,0.,0.,outputfilename);
01226
01227
01228 ofstream * txtfile;
01229 for (int layer=1; layer < 44; layer++){
01230 ostringstream outs;
01231 outs << outputfilename <<"layer"<<layer<< ".html";
01232 txtfile = new ofstream(outs.str().c_str(),ios::out);
01233 *txtfile << "<html><head></head> <body>" << endl;
01234 for (int ring=firstRing[layer-1]; ring < ntotRing[layer-1]+firstRing[layer-1];ring++){
01235 for (int module=1;module<200;module++) {
01236 int key=layer*100000+ring*1000+module;
01237 TmModule * mod = smoduleMap[key];
01238 if(mod !=0 && !mod->notInUse()){
01239 int idmod=mod->idex;
01240 int nchan=0;
01241 *txtfile << "<a name="<<idmod<<"><pre>"<<endl;
01242 multimap<const int, TmApvPair*>::iterator pos;
01243 for (pos = apvModuleMap.lower_bound(idmod);
01244 pos != apvModuleMap.upper_bound(idmod); ++pos) {
01245 TmApvPair* apvpair = pos->second;
01246 if(apvpair!=0){
01247 nchan++;
01248 *txtfile << apvpair->text << endl;
01249 }
01250
01251 }
01252 *txtfile << "</pre><h3>"<< mod->name<<"</h3>"<<endl;
01253 }
01254 }
01255 }
01256 *txtfile << "</body></html>" << endl;
01257 txtfile->close();
01258 }
01259 if(enableFedProcessing){
01260 outs1 << outputfilename<<"fed.png";
01261 save_as_fedtrackermap(true,0.,0.,outs1.str(),6000,3200);
01262 outs2 << outputfilename<<".xml";
01263 save_as_fedtrackermap(true,0.,0.,outs2.str(),3000,1600);
01264
01265 std::map<int , int>::iterator i_fed;
01266 ofstream * txtfile;
01267 for (int crate=1; crate < (ncrates+1); crate++){
01268 ostringstream outs;
01269 outs << outputfilename <<"crate"<<crate<< ".html";
01270 txtfile = new ofstream(outs.str().c_str(),ios::out);
01271 *txtfile << "<html><head></head> <body>" << endl;
01272 for (i_fed=fedMap.begin();i_fed != fedMap.end(); i_fed++){
01273 if(i_fed->second == crate){
01274 int fedId = i_fed->first;
01275 for (int nconn=0;nconn<96;nconn++){
01276 int key = fedId*1000+nconn;
01277 TmApvPair * apvPair= apvMap[key];
01278 if(apvPair !=0){
01279 int idmod=apvPair->idex;
01280 *txtfile << "<a name="<<idmod<<"><pre>"<<endl;
01281 *txtfile << apvPair->text << endl;
01282 ostringstream outs;
01283 outs << "fedchannel " <<apvPair->getFedId() << "/"<<apvPair->getFedCh()<<" connects to module " << apvPair->mod->idex ;
01284 *txtfile << "</pre><h3>"<< outs.str()<<"</h3>"<<endl;
01285 }
01286 }
01287 }
01288 }
01289 *txtfile << "</body></html>" << endl;
01290 txtfile->close();
01291 }
01292 }
01293 }
01294 std::ifstream * TrackerMap::findfile(string filename) {
01295 std::ifstream * ifilename;
01296 std::string ifname;
01297 if(jsPath!=""){
01298 ifname=jsPath+filename;
01299 ifilename = new ifstream(edm::FileInPath(ifname).fullPath().c_str(),ios::in);
01300 if(!ifilename){
01301 ifname="CommonTools/TrackerMap/data/"+filename;
01302 ifilename = new ifstream(edm::FileInPath(ifname).fullPath().c_str(),ios::in);
01303 }
01304 }else {
01305 ifname="CommonTools/TrackerMap/data/"+filename;
01306 ifilename = new ifstream(edm::FileInPath(ifname).fullPath().c_str(),ios::in);
01307 }
01308 if(!ifilename)cout << "File " << filename << " missing" << endl;
01309 return ifilename;
01310 }
01311 void TrackerMap::printlayers(bool print_total, float minval, float maxval, string outputfilename){
01312 ofstream * xmlfile;
01313 saveAsSingleLayer=true;
01314 if(!print_total){
01315 for (int layer=1; layer < 44; layer++){
01316 for (int ring=firstRing[layer-1]; ring < ntotRing[layer-1]+firstRing[layer-1];ring++){
01317 for (int module=1;module<200;module++) {
01318 int key=layer*100000+ring*1000+module;
01319 TmModule * mod = smoduleMap[key];
01320 if(mod !=0 && !mod->notInUse()){
01321 mod->value = mod->value / mod->count;
01322 }
01323 }
01324 }
01325 }
01326 }
01327 if(minvalue>=maxvalue){
01328 minvalue=9999999.;
01329 maxvalue=-9999999.;
01330 for (int layer=1; layer < 44; layer++){
01331 for (int ring=firstRing[layer-1]; ring < ntotRing[layer-1]+firstRing[layer-1];ring++){
01332 for (int module=1;module<200;module++) {
01333 int key=layer*100000+ring*1000+module;
01334 TmModule * mod = smoduleMap[key];
01335 if(mod !=0 && !mod->notInUse()){
01336 if (minvalue > mod->value)minvalue=mod->value;
01337 if (maxvalue < mod->value)maxvalue=mod->value;
01338 }
01339 }
01340 }
01341 }
01342 }
01343 for (int layer=1; layer < 44; layer++){
01344 ostringstream outs;
01345 outs << outputfilename <<"layer"<<layer<< ".xml";
01346 xmlfile = new ofstream(outs.str().c_str(),ios::out);
01347 *xmlfile << "<?xml version=\"1.0\" standalone=\"no\"?>"<<endl;
01348 *xmlfile << "<svg xmlns=\"https://www.w3.org/2000/svg\""<<endl;
01349 *xmlfile << "xmlns:svg=\"https://www.w3.org/2000/svg\""<<endl;
01350 *xmlfile << "xmlns:xlink=\"https://www.w3.org/1999/xlink\" >"<<endl;
01351 *xmlfile << "<script type=\"text/ecmascript\" xlink:href=\"layer.js\" />"<<endl;
01352 *xmlfile << "<svg id=\"mainMap\" x=\"0\" y=\"0\" viewBox=\"0 0 500 500\" width=\"700\" height=\"700\" onload=\"TrackerLayer.init()\">"<<endl;
01353 if(layer<31)*xmlfile << "<g id=\"layer\" transform=\" translate(0,400) rotate(270) scale(1.,2.)\" > "<<endl;
01354 else *xmlfile << "<g id=\"layer\" transform=\" translate(0,400) rotate(270) scale(1.,1.)\" > "<<endl;
01355 *xmlfile << "<rect fill=\"lightblue\" stroke=\"none\" x=\"0\" y=\"0\" width=\"700\" height=\"700\" />"<<endl;
01356 nlay=layer;
01357 defwindow(nlay);
01358 for (int ring=firstRing[layer-1]; ring < ntotRing[layer-1]+firstRing[layer-1];ring++){
01359 for (int module=1;module<200;module++) {
01360 int key=layer*100000+ring*1000+module;
01361 TmModule * mod = smoduleMap[key];
01362 if(mod !=0 && !mod->notInUse()){
01363 drawModule(mod,key,layer,print_total,xmlfile);
01364 }
01365 }
01366 }
01367 *xmlfile << "</g> </svg> <text id=\"currentElementText\" x=\"40\" y=\"30\">" << endl;
01368 *xmlfile << "<tspan id=\"line1\" x=\"40\" y=\"30\"> </tspan> " << endl;
01369 *xmlfile << "<tspan id=\"line2\" x=\"40\" y=\"60\"> </tspan> " << endl;
01370 *xmlfile << "<tspan id=\"line3\" x=\"40\" y=\"90\"> </tspan> " << endl;
01371 *xmlfile << " </text> </svg>" << endl;
01372 xmlfile->close();
01373 }
01374 saveAsSingleLayer=false;
01375 }