Exemplo n.º 1
0
void DrawEmpirical(const char* filename="Empirical.root", 
		   Bool_t fmd=true)
{
  gStyle->SetOptTitle(0);

  TFile* file = TFile::Open(filename, "READ");
  if (!file) return;

  Double_t yr = 0.3;
  TCanvas* c  = new TCanvas("c","c", 1000,1000);
  TPad*    p1 = new TPad("p1","p1",0,0,1,yr);
  TPad*    p2 = new TPad("p2","p2",0,yr,1,1);
  c->cd(); p1->Draw();
  c->cd(); p2->Draw();
  
  gDirectory->cd("Forward");
  THStack* r = DrawOne(p1, yr, false, gDirectory, "ratios");  
  THStack* e = DrawOne(p2, yr, true, gDirectory, "empirical");

  r->SetMinimum(0.945);
  r->SetMaximum(1.055);
  r->GetXaxis()->SetTitle("#it{#eta}");
  r->GetYaxis()->SetTitle("Ratio to mean");
  e->SetMinimum(0.005);
  e->GetYaxis()->SetTitle("#it{E_{c}}(#it{#eta})");
  TIter nextE(e->GetHists());
  TIter nextR(r->GetHists());
  TH1*  hist = 0;
  Color_t cols[]  = { kRed+2, kGreen+2, kBlue+2, kMagenta+2, 0 };
  Color_t *ptr    = cols;
  Style_t stys[]  = { 20, 21, 22, 23 };
  Style_t* sty    = stys;
  while (*ptr) { 
    hist = static_cast<TH1*>(nextE()); 
    hist->SetMarkerColor(*ptr);
    hist->SetMarkerSize(2);
    hist->SetMarkerStyle(*sty);
    hist = static_cast<TH1*>(nextR()); 
    hist->SetMarkerColor(*ptr);
    hist->SetMarkerSize(2);
    hist->SetMarkerStyle(*sty);
    ptr++;
    sty++;
  }


  TLegend* l = p2->BuildLegend(0.35, .2, .65, .8);
  l->SetFillColor(0);
  l->SetFillStyle(0);
  l->SetBorderSize(0);

  c->Modified();
  c->Update();
  c->cd();
  c->Print("empirical.png");
  
}
Exemplo n.º 2
0
void WaveStripe::update(){
	mutex.lock();
	amplitudesLeftFront.insert(amplitudesLeftFront.end(),amplitudesLeftBack.begin(),amplitudesLeftBack.end());
	amplitudesRightFront.insert(amplitudesRightFront.end(),amplitudesRightBack.begin(),amplitudesRightBack.end());
	amplitudesLeftBack.clear();
	amplitudesRightBack.clear();
	mutex.unlock();
	if(amplitudesLeftFront.size()>1024){
		amplitudesLeftFront.erase(amplitudesLeftFront.begin(),amplitudesLeftFront.begin()+(amplitudesLeftFront.size()-1024));
		amplitudesRightFront.erase(amplitudesRightFront.begin(),amplitudesRightFront.begin()+(amplitudesRightFront.size()-1024));
	}
	for(u_int i = 0; i<amplitudesLeftFront.size();i++){
		amplitudesLeftFront[i]*=.95;
		amplitudesRightFront[i]*=.95;
	}
	for(int i=0; i<((int)amplitudesLeftFront.size())-1;i++){
		ofVec3f current(i*thickness,amplitudesLeftFront[amplitudesLeftFront.size()-i]*ampFactor,0);
		ofVec3f currentR(i*thickness,amplitudesRightFront[amplitudesRightFront.size()-i]*ampFactor,0);
		ofVec3f next((i+1)*thickness,amplitudesLeftFront[amplitudesLeftFront.size()-(i+1)]*ampFactor,0);
		ofVec3f nextR((i+1)*thickness,amplitudesRightFront[amplitudesRightFront.size()-(i+1)]*ampFactor,0);
		ofVec3f up(0, 1, 0);

		ofVec3f dir = (next - current).normalize();			// normalized direction vector from p0 to p1
		ofVec3f right = dir.cross(up).normalize();	// right vector
		right *= thickness;//thisThickness;
		dir = (nextR - currentR).normalize();
		ofVec3f rightR = dir.cross(up).normalize();	// right vector
		rightR *= thickness;//thisThickness;


		mesh.getVertices()[i*2] = mesh.getVertices()[i*2]*.8 + (current - right)*.2;
		mesh.getVertices()[i*2+1] = mesh.getVertices()[i*2+1]*.8 + (currentR + rightR)*.2;
	}
	if(mesh.getVertices().size()>2){
		*(mesh.getVertices().end()-2) = *(mesh.getVertices().end()-4);
		*(mesh.getVertices().end()-1) = *(mesh.getVertices().end()-3);
	}

}
Exemplo n.º 3
0
    u_int nextR(u_int posn, fxStr const& delimiters) const
	{ return nextR(posn, (char*)delimiters, delimiters.slength-1); }
Exemplo n.º 4
0
bool TissueState::addCell(const CellIndex id, const Pixel firstP, const PixelFrame &OriginalFrame) {
  // create cell, already now for computation of geometric quantities...
  Cell *c = new Cell(id);

  // **** first, check if cell has to be ignored (i.e. at least one bond pixel is a margin pixel) ****
  // go around cell perimeter in ccw direction
  Pixel p(firstP);
  Vector2D lastR(p.toVector());
  int direction = 6; // ==Down; this is right like this, because in TissueState::parseFromTrackedCellsFile a cell is started when a cell pixel was found *above* firstP
  do {
    if(p.isOnMargin()) {
      // cell has to be ignored 
      _ignoredCells.insert(id);
//      delete c; // delete cell again
//      return true;
    }
    std::vector<CellIndex> neighbors;
    direction = p.getLastCommonNeighboringBondPixelInCwOrientation(neighbors, id, direction);
    if(direction<0) {
      return false;
    }
    p.goTo(direction);
    // compute quantities
    Vector2D r(p.toVector());
    double areaTerm = lastR.x()*r.y() - lastR.y()*r.x();
    c->area += areaTerm;
    c->r += (r+lastR)*areaTerm;
    
    lastR = r;
  } while(p!=firstP);

  // finish computations
  c->area *= 0.5;
  c->r /= 6*c->area;

  // add cell to map
  _cells[id] = c;
  
  // **** second, compute cell elongation (needs computed cell center) ****
  // go around cell perimeter in ccw direction
  p = firstP;
  direction = 6; // ==Down; this is right like this, because in TissueState::parseFromTrackedCellsFile a cell is started when a cell pixel was found *above* firstP
  c->elongation.set(0,0);
  c->polarityR=c->polarityG=c->polarityB=c->elongation;
  c->intIntensityR=c->intIntensityG=c->intIntensityB=0;
  Vector2D r(p.toVector());
  Vector2D diff(r-c->r);
  double rLen=diff.norm(), rPhi=diff.angle();
  // for polarity:
  PixelValue oldData = OriginalFrame.data(p.position());
  unsigned char oldDataR=(oldData>>16)&0xFF, oldDataG=(oldData>>8)&0xFF, oldDataB=oldData&0xFF;
  do {
    std::vector<CellIndex> neighbors;
    direction = p.getLastCommonNeighboringBondPixelInCwOrientation(neighbors, id, direction);
    if(direction<0) {
      return false;
    }
    p.goTo(direction);

    // compute cell elongation
    double l = PixelFrame::NNeighborDistance[direction];
    Vector2D nextR(p.toVector());
    diff = nextR-c->r;
    double nextRLen=diff.norm(), nextRPhi=diff.angle();
    double deltaPhi = nextRPhi-rPhi;
    deltaPhi -= 2*M_PI*round(deltaPhi/2/M_PI);
    double rPhiMinusAlpha = M_PI + (nextR-r).angle();
    double sinAlpha = sin(rPhi-rPhiMinusAlpha);
    
    c->elongation += rLen*rLen*sinAlpha*sinAlpha*(
               nematicFromAngleAndNorm(rPhiMinusAlpha, l/(rLen*sinAlpha) - 2*deltaPhi)
              +nematicFromAngleAndNorm(rPhiMinusAlpha+0.25*M_PI, 2*log(rLen/nextRLen))
            );
    
    // polarity, separately for each color channel (R, G, B)
    PixelValue data = OriginalFrame.data(p.position());
    unsigned char dataR=(data>>16)&0xFF, dataG=(data>>8)&0xFF, dataB=data&0xFF;
    c->polarityR += nematicFromAngleAndNorm(rPhi+0.5*deltaPhi, deltaPhi*0.5*(dataR+oldDataR));
    c->intIntensityR += deltaPhi*0.5*(dataR+oldDataR);
    c->polarityG += nematicFromAngleAndNorm(rPhi+0.5*deltaPhi, deltaPhi*0.5*(dataG+oldDataG));
    c->intIntensityG += deltaPhi*0.5*(dataR+oldDataG);
    c->polarityB += nematicFromAngleAndNorm(rPhi+0.5*deltaPhi, deltaPhi*0.5*(dataB+oldDataB));
    c->intIntensityB += deltaPhi*0.5*(dataR+oldDataB);
    
    r = nextR;
    rLen = nextRLen;
    rPhi = nextRPhi;
    oldDataR = dataR;
    oldDataG = dataG;
    oldDataB = dataB;
  } while(p!=firstP);
  
  c->elongation /= 2*c->area;

  // **** third, go around again and create structures ****
  // go around cell perimeter
  int countFirstP = 0;
  p = firstP;
  std::vector<CellIndex> oldNeighbors;
  int oldDirection = -1;
  Vertex *curVertex = NULL;
  DirectedBond *curDirectedBond = NULL;
  double curBondLength = 0.0;
  do {
    // check neighboring cells and next direction
    std::vector<CellIndex> curNeighbors;
    int curDirection = p.getLastCommonNeighboringBondPixelInCwOrientation(curNeighbors, id, (oldDirection>=0)?oldDirection:6);
    if(curDirection<0) {
      return false;
    }
    
    bool isVertex = false;
    Pixel vertexP(p), enterP(p), leaveP(p);
    
    // -- check for thick vertex --
    std::set<Pixel> thickVertex;
    p.addToThickVertex(thickVertex);
    if(thickVertex.size()>1) {
//      if(thickVertex.size()>4) {
//        std::cout << "TissueState::addCell: thick vertex too big on pixel " << p.positionString() << ", direction " << oldDirection << ", for cell id " << std::hex << id << "." << std::endl;
//        return false;
//      }
      for(std::set<Pixel>::iterator it=thickVertex.begin(); it!=thickVertex.end(); ++it) {
        if(*it<vertexP) {
          vertexP = *it;
        }
      }

      isVertex = true;
      // go to last pixel end of thick vertex
      do {
        Pixel testP(p);
        testP.goTo(curDirection);
        if(thickVertex.count(testP)==0) {
          break;
        }
        p = testP;
//        curBondLength += PixelFrame::NNeighborDistance[curDirection]; // NOTE: thick vertices don't count in for bon length in order for both bonds of a conjugated pair to have the same length
        curDirection = p.getLastCommonNeighboringBondPixelInCwOrientation(curNeighbors, id, curDirection);
        if(curDirection<0) {
          return false;
        }
      } while(true);
      leaveP = p;
//      std::cout << "TissueState::addCell: thick vertex at " << p.positionString() << ", size " << thickVertex.size() << ", for cell id " << std::hex << id << std::dec << ", vertex " << vertexP.positionString() << ", old direction " << oldDirection << ", new direction " << curDirection <<  "." << std::endl;
    } else {
      // start with most probable case:
      if(curNeighbors.size()==2) {
        // consistency check
        if((oldNeighbors.size()>0) && (oldNeighbors.size()<3) && !compareCyclicLists(oldNeighbors, curNeighbors)) {
          std::cout << "TissueState::addCell: change of neighbor set, but no thick vertex at pixel " << p.positionString() << " for cell id " << std::hex << id << std::endl;
          return false;
        }
        // boundary between two cells
      } else if(curNeighbors.size()>2) {
        // vertex
        isVertex = true;
      } else if(curNeighbors.size()==1) {
        std::cout << "TissueState::addCell: Only one neighbor of pixel " << p.positionString() << " for cell id " << std::hex << id << std::endl;
        return false;
      } else if(curNeighbors.size()==0) {
        std::cout << "TissueState::addCell: No neighbors of pixel " << p.positionString() << " for cell id " << std::hex << id << std::endl;
        return false;
      }
    }

    if(isVertex) {
      // check, if come from valid direction
      if(oldDirection>=0) {
        // first, get pointer to vertex
        // check, if in map
        if(_vertexMap.count(vertexP)==0) {
          // no -> create
          curVertex = newVertex(vertexP.toVector());
          _vertexMap[vertexP] = curVertex;
        } else {
          curVertex = _vertexMap[vertexP];
        }

        // -- check out conjugated bond of previous bond --
        pair<Pixel, int> pixelAndDirectionConj(enterP, PixelFrame::oppositeDirection(oldDirection));
        DirectedBond *oldConjugatedBond = NULL;
        // old conjugated bond already there?
        if(_directedBondMap.count(pixelAndDirectionConj)>0) {
          oldConjugatedBond = _directedBondMap[pixelAndDirectionConj];
        } else {
          // no -> create
          oldConjugatedBond = newBond();
          _directedBondMap[pixelAndDirectionConj] = oldConjugatedBond;
        }

        // -- check out previous bond --
        // previous bond there?
        if(curDirectedBond) {
          // wire with cur vertex
          curDirectedBond->leftVertex = curVertex;
          // conjugated bond already there?
          if(oldConjugatedBond) {
            curDirectedBond->conjBond = oldConjugatedBond;
            oldConjugatedBond->conjBond = curDirectedBond;
          }
          // set length
          curDirectedBond->length = curBondLength;
        }

        // -- check out next bond --
        pair<Pixel, int> pixelAndDirection(leaveP, curDirection);
        if(_directedBondMap.count(pixelAndDirection)==0) {
          // new bond does not yet exist -> create
          curDirectedBond = newBond();
          _directedBondMap[pixelAndDirection] = curDirectedBond;
        } else {
          curDirectedBond = _directedBondMap[pixelAndDirection];
        }
        curBondLength = 0.0;
        
        // - add to cell -
        if(curDirectedBond->cell) {
          // cell already set?
          if(curDirectedBond->cell==c) {
            // right cell -> we're done!
            break;
          } else {
            // wrong cell
            std::cout << "TissueState::addCell: Bond already exists, but wrong cell at pixel " << p.positionString();
            std::cout << std::hex << " with cur cell id " << (*curNeighbors.begin()) << " and cell id in bond " << curDirectedBond->cell->id << std::endl;
            return false;
          }
        } else {
          // add
          curDirectedBond->cell = c;
          c->bonds.push_back(curDirectedBond);
        }

        // - add new bond (if appropriate) and (if appropriate) old conjugate bond to vertex -
        // have to add old conj. bond to vertex?
        if(!oldConjugatedBond->rightVertex) {
          // have to add new bond to vertex?
          if(!curDirectedBond->rightVertex) {
            // have to insert both into curVertex
            // first insert curBond at end
            curDirectedBond->rightVertex = curVertex;
            curVertex->bonds.insert(curVertex->bonds.end(), curDirectedBond);
            // then old conj bond
            oldConjugatedBond->rightVertex = curVertex;
            curVertex->bonds.insert(curVertex->bonds.end(), oldConjugatedBond);
          } else {
            // have to insert old conj. after new bond
            std::vector<DirectedBond *>::iterator it = std::find(curVertex->bonds.begin(), curVertex->bonds.end(), curDirectedBond);
            if(it!=curVertex->bonds.end()) {
              // found -> insert old conj. bond after -> in ccw direction
              oldConjugatedBond->rightVertex = curVertex;
              ++it;
              curVertex->bonds.insert(it, oldConjugatedBond);
            } else {
              // not found, although new bond was there, before
              std::cout << "TissueState::addCell: New bond was there before, but did not find it in vertex at pixel " << p.positionString() << " for cell id " << std::hex << c->id << std::endl;
              return false;
            }
          }
        } else {
          if(!curDirectedBond->rightVertex) {
            // find old conj. bond in vertex
            std::vector<DirectedBond *>::iterator it = std::find(curVertex->bonds.begin(), curVertex->bonds.end(), oldConjugatedBond);
            if(it!=curVertex->bonds.end()) {
              // found -> insert new bond before -> in cw direction
              curDirectedBond->rightVertex = curVertex;
              curVertex->bonds.insert(it, curDirectedBond);
            } else {
              // not found, although ocb was there, before
              std::cout << "TissueState::addCell: Old conjugated bond was there before, but did not find it in vertex at pixel " << p.positionString() << " for cell id " << std::hex << c->id << std::endl;
              return false;
            }
          } else {
            // both bonds are already connected!
          }
        }
      }
    }
    
    // next pixel
    p.goTo(curDirection);
    curBondLength += PixelFrame::NNeighborDistance[curDirection];
    if(p==firstP) {
      ++countFirstP;
      if(countFirstP>1) {
        // running in a circle, here
        // create artificial vertex and directed bond:
        curVertex = newVertex(firstP.toVector());
        curDirectedBond = newBond();
        curDirectedBond->rightVertex=curDirectedBond->leftVertex=curVertex;
        curDirectedBond->cell = c;
        c->bonds.push_back(curDirectedBond);
        curVertex->bonds.push_back(curDirectedBond);
        break;
      }
    }
    
    // keep old neighbors in mind
    oldNeighbors.swap(curNeighbors);
    // keep old directions in mind
    oldDirection = curDirection;
  } while(true);
  
  return true;
}