Exemplo n.º 1
0
void WriteOCDB(Int_t firstRun=0, Int_t lastRun=IlcCDBRunRange::Infinity())
{
  //Write mapping to OCDB.
  //Run this macro from the same directory where mapping files *.data resides.
  //Author: Boris Polishchuk.

  IlcCDBManager::Instance()->SetDefaultStorage("local://$ILC_ROOT/OCDB");
  IlcCDBStorage* storage = IlcCDBManager::Instance()->GetDefaultStorage();

  IlcCDBId id("PVBAR/Calib/Mapping",firstRun,lastRun);
  IlcCDBMetaData md;

  //Create mapping object.
  const char* mapFiles[20] = {
    "Mod0RCU0.data",
    "Mod0RCU1.data",
    "Mod0RCU2.data",
    "Mod0RCU3.data",
    "Mod1RCU0.data",
    "Mod1RCU1.data",
    "Mod1RCU2.data",
    "Mod1RCU3.data",
    "Mod2RCU0.data",
    "Mod2RCU1.data",
    "Mod2RCU2.data",
    "Mod2RCU3.data",
    "Mod3RCU0.data",
    "Mod3RCU1.data",
    "Mod3RCU2.data",
    "Mod3RCU3.data",
    "Mod4RCU0.data",
    "Mod4RCU1.data",
    "Mod4RCU2.data",
    "Mod4RCU3.data"
  };

  TString path = "./";
  
  path += "Mod";
  TString path2;
  TString path3;
  Int_t iMap = 0;
  IlcAltroMapping* mapping;
  
  TObjArray objMap(20);
  
  for(Int_t iMod = 0; iMod < 5; iMod++) {
    path2 = path;
    path2 += iMod;
    path2 += "RCU";

    for(Int_t iRCU=0; iRCU<4; iRCU++) {
      path3 = path2;
      path3 += iRCU;
      path3 += ".data";
      IlcAltroMapping* mapping = new IlcCaloAltroMapping(path3.Data());
      objMap.AddAt(mapping,iMap);
      iMap++;
    }
  }

  //Put mapping object into OCDB: $ILC_ROOT/OCDB/PVBAR/Calib/Mapping/
  storage->Put(&objMap,id,&md);
}
Exemplo n.º 2
0
void FOEFinder::makeObjMap2(VelocityBuffer & packet){
    int size, x, y;
    double vx, vy, velNorm, distan, avg;
    double tim1, tim2, deltaT;
    double maxValue, normFactor, tmp, r, b , g;
    int wndwSZ;

//   foeX  = 59; foeY = 64;

    size = packet.getSize();

    unsigned long crntTS;
    crntTS = packet.getTs(size - 1);

    //Update map with new arrived values
    for (int cntr = 0; cntr < size; ++cntr) {
       x = packet.getX(cntr) + FILTER_NGHBRHD;
       y = packet.getY(cntr) + FILTER_NGHBRHD;
       vx = packet.getVx(cntr);
       vy = packet.getVy(cntr);

//       velNorm = sqrt(vx*vx + vy*vy) * 10000;
//       objMap(x,y ) = velNorm;

       //velNorm = int ( sqrt(vx*vx + vy*vy) * 100000 + .5 ) + 1;
       velNorm = int( ( 1 / ( sqrt(vx*vx + vy*vy ) + .0000001)) + .5 ) ;
       distan = sqrt( (foeX - x)*(foeX-x) + (foeY - y)*(foeY - y)) ;
       deltaT = (crntTS - objMapTS(x, y) > 50000 ? 0 : .4);
       objMap(x, y) =    (1 - deltaT) *  distan *  velNorm + deltaT * objMap(x, y) ;

       objMapTS(x, y) = packet.getTs(cntr);
   }
    //cout << velNorm << endl;

   //Smoothing
//   for (int cntr = 0; cntr < size; ++cntr) {
//       x = packet.getX(cntr) + FILTER_NGHBRHD;
//       y = packet.getY(cntr) + FILTER_NGHBRHD;

    for (int x = FILTER_NGHBRHD; x < X_DIM + FILTER_NGHBRHD; ++x) {
        for (int y = FILTER_NGHBRHD; y < Y_DIM + FILTER_NGHBRHD; ++y) {

           tim1 = objMapTS(x,y);

           if (crntTS - tim1 > 200000){
               objMap(x,y) = 0;
               continue;
           }
           avg = 0;
           wndwSZ  =0;
           for (int i = -FILTER_NGHBRHD; i <= FILTER_NGHBRHD; ++i) {
               for (int j = -FILTER_NGHBRHD; j <= FILTER_NGHBRHD; ++j) {
                   tim2 = objMapTS(x + i, y + j);
                   deltaT = ( abs(tim1- tim2) > 50000 ? 0 : 1 );
                   tmp = objMap(x + i, y + j) * deltaT;
                   avg += tmp;
                   wndwSZ  += deltaT;
              }
           }
           avg = avg / wndwSZ;
           objMap(x, y) = avg;
      }
    }
   cout << avg << endl;

   //Visualization


   visualizeObjMap( crntTS);

}
Exemplo n.º 3
0
void FOEFinder::visualizeObjMap(  unsigned long crntTS){
    double maxValue, normFactor;
    int tempDepth, deltaT;
    double depthRed, depthGreen, depthBlue;


    yarp::sig::ImageOf<yarp ::sig::PixelRgb>& img=outPort-> prepare();
    img.resize(X_DIM , Y_DIM );
    img.zero();

    maxValue = 2000; //16000; //300;
    normFactor = (255/  maxValue);
    for (int i = 0; i < X_DIM ; ++i) {
        for (int j = 0; j < Y_DIM ; ++j) {

//            deltaT = ( crntTS - objMapTS(i,j) > 200000 ? 0 : 1);
//            objMap(i, j) = objMap(i, j) * deltaT;

            tempDepth = normFactor * objMap(i + FILTER_NGHBRHD ,j + FILTER_NGHBRHD);

            if(tempDepth < 43){
                depthRed = tempDepth * 6;
                depthGreen = 0;
                depthBlue = tempDepth * 6;
            }
            if(tempDepth > 42 && tempDepth < 85){
                depthRed = 255 - (tempDepth - 43) * 6;
                depthGreen = 0;
                depthBlue = 255;
            }
            if(tempDepth > 84 && tempDepth < 128){
                depthRed = 0;
                depthGreen = (tempDepth - 85) * 6;
                depthBlue = 255;
            }
            if(tempDepth > 127 && tempDepth < 169){
                depthRed = 0;
                depthGreen = 255;
                depthBlue = 255 - (tempDepth - 128) * 6;
            }
            if(tempDepth > 168 && tempDepth < 212){
                depthRed = (tempDepth - 169) * 6;
                depthGreen = 255;
                depthBlue = 0;
            }
            if(tempDepth > 211 && tempDepth < 254){
                depthRed = 255;
                depthGreen = 255 - (tempDepth - 212) * 6;
                depthBlue = 0;
            }
            if(tempDepth > 253){
                depthRed = 255;
                depthGreen = 0;
                depthBlue = 0;
            }

            img(i,j) =  yarp::sig::PixelRgb ( depthRed, depthGreen , depthBlue );

        }// end for on y dimention
    }// end for on x dimention




    static const yarp::sig::PixelRgb pr(200,0,0);
    yarp::sig::draw::addCircle(img,pr,foeX,foeY,4);
    outPort -> write();


    ///GRAY-SCALE VISUALIzations
    //   yarp::sig::ImageOf<yarp ::sig::PixelRgb>& img=outPort-> prepare();
    //   img.resize(X_DIM + 2*FILTER_NGHBRHD, Y_DIM + 2*FILTER_NGHBRHD);
    //   img.zero();
    //
    //   maxValue = 15; //16000; //300;
    //   normFactor = (255/  maxValue);
    //   for (int i = 0; i < X_DIM + 2*FILTER_NGHBRHD; ++i) {
    //     for (int j = 0; j < Y_DIM + 2*FILTER_NGHBRHD; ++j) {
    //         deltaT = ( crntTS - objMapTS(i,j) > 100000 ? 0 : 1);
    //         objMap(i, j) = objMap(i, j) * deltaT;
    //
    //         if (objMap(i, j) * deltaT > .00000001 * maxValue){
    //             r = normFactor * objMap(i, j);
    //             img(i,j) =  yarp::sig::PixelRgb ( 0, r , 0 );
    //         }
    //
    //     }
    //
    //   }



    //   normFactor = (255/ (.3 * maxValue));
    //   for (int i = 0; i < X_DIM + 2*FILTER_NGHBRHD; ++i) {
    //      for (int j = 0; j < Y_DIM + 2*FILTER_NGHBRHD; ++j) {
    //
    //          deltaT = ( crntTS - objMapTS(i,j) > 100000 ? 0 : 1);
    //          objMap(i, j) = objMap(i, j) * deltaT;
    //
    //          if (objMap(i, j) * deltaT > .00000001 * maxValue){
    //              // if the value is not too small
    //              if (objMap(i, j)  < .3 * maxValue){
    //                 r = normFactor * objMap(i, j);
    //                 img(i,j) =  yarp::sig::PixelRgb ( r, 0 , 0 );
    //              }else {
    //                  if (objMap(i, j)  < .7 * maxValue){
    //                      b = normFactor * (objMap(i, j)  - .3 * maxValue);
    //                      img(i,j) =  yarp::sig::PixelRgb ( 250, 0 , b );
    //                  }else {
    //                      g = normFactor * (objMap(i, j)  - .7 * maxValue);
    //                      g = (g < 255 ? g : 255);
    //                      img(i,j) =  yarp::sig::PixelRgb ( 250, g , 250 );
    //                  }
    //              }
    //          }
    //
    //       }
    //   }

}
Exemplo n.º 4
0
void FOEFinder::makeObjMap(VelocityBuffer & data){
    int size, x, y;
    double vx, vy, velNorm, distan, leakyCons;
    static unsigned long lastTS = 0;
    unsigned long crntTS;
    double maxValue, sptDrv, normFactor, tmp, r, b , g;

    size = data.getSize();

    maxValue = 0;
    crntTS = data.getTs(0);
    leakyCons = exp( -0.00001 * (crntTS - lastTS) );
    //leak the values
    for (int i = 0; i < X_DIM; ++i) {
       for (int j = 0; j < Y_DIM; ++j) {
           objMap(i,j) = leakyCons * objMap(i,j);
       }
    }


maxValue  = 0; sptDrv = 0;
    for (int cntr = 0; cntr < size; ++cntr) {
        x = data.getX(cntr);
        y = data.getY(cntr);
        vx = data.getVx(cntr);
        vy = data.getVy(cntr);

        velNorm = sqrt(vx*vx + vy*vy) * 10000;
       // distan = sqrt( (foeX - x)*(foeX-x) + (foeY - y)*(foeY - y)) ;
      //  objMap(x, y) =  distan / velNorm;
        objMap(x, y) = velNorm;

        maxValue += objMap(x, y);
        sptDrv += objMap(x, y) * objMap(x, y);
    }
    maxValue = maxValue / size;
    sptDrv = sptDrv / size;
    sptDrv = sptDrv - maxValue * maxValue;
    sptDrv = sqrt(sptDrv);
    cout << maxValue << endl;

    maxValue +=  sptDrv;

    yarp::sig::ImageOf<yarp ::sig::PixelRgb>& img=outPort-> prepare();
    img.resize(X_DIM, Y_DIM);
    img.zero();

    cout << maxValue << " " << sptDrv << endl;

maxValue = 500;
    normFactor = (255/ (.3 * maxValue));
    for (int i = 0; i < X_DIM; ++i) {
       for (int j = 0; j < Y_DIM; ++j) {

           if (objMap(i, j) > .7 * maxValue){
               r = normFactor * (objMap(i, j) - .7 * maxValue);
               img(i,j) =  yarp::sig::PixelRgb ( r, 0 , 0 );
           }else {
               if (objMap(i, j) > .3 * maxValue ){
                   b = normFactor * (objMap(i, j) - .3 * maxValue);
                   img(i,j) =  yarp::sig::PixelRgb ( 0, 0 , b );
               }
               else{
                   g = normFactor * objMap(i, j) ;
                   img(i,j) =  yarp::sig::PixelRgb ( 0, g , 0 );
               }
           }
//        tmp = normFactor * objMap(i,j);
//        img(i,j) = yarp::sig::PixelRgb (tmp,tmp , tmp);
        }
    }

    lastTS = data.getTs(0);



    static const yarp::sig::PixelRgb pr(200,0,0);
    yarp::sig::draw::addCircle(img,pr,foeX,foeY,4);


    outPort -> write();
}