bool
FilterGraph::setInput(Speakers _spk)
{
  dropChain();

  return queryInput(_spk) && start.setInput(_spk) && buildChain(node_start);
}
Exemple #2
0
bool IkSolver::buildChain(const Bone *parent, const Bone &b, const Bone &target, std::vector<const Bone*> &chain) const
{
	bool found = false;

	if (&b == &target)
		found = true;
	else
	{
		for (int i = 0; i < (int)b.joints.size(); ++i)
		{
			Bone &bn = *b.joints[i].to;
			if (&bn != parent)
			{
				if (buildChain(&b, bn, target, chain))
				{
					found = true;
					break;
				}
			}
		}
		
	}

	if (found)
		chain.push_back(&b);

	return found;
}
Exemple #3
0
    int solve(vector<int> scores){
        int vertexCnt = scores.size() + 1;
        if(vertexCnt == 2){
            return scores[0];
        }

        vector<Node> graph(vertexCnt);
        buildChain(graph);

        int maxDegree = vertexCnt - 1;
        int currentMaxDegree = 2;
        int currentMaxScore = calcScore(scores, graph);

        while(currentMaxDegree < maxDegree){
            vector<Node*> exceptions;
            Node* nextAddedTarget = findNode(graph, currentMaxDegree);
            while(nextAddedTarget != NULL){
                exceptions.push_back(nextAddedTarget);
                Node* nextDepartedTarget = findNotConnected1DegreeNode(graph, exceptions);
                if(nextDepartedTarget != NULL){
                    departNode(graph, nextDepartedTarget);
                    connectNode(nextAddedTarget, nextDepartedTarget);
                    currentMaxScore = max(currentMaxScore, calcScore(scores, graph));
                    nextAddedTarget = findNode(graph, currentMaxDegree);
                }else{
                    break;
                }
            }
            currentMaxDegree++;
        }
        return currentMaxScore;
    }
Exemple #4
0
void IkSolver::iterateIk()
{
	if (ikChain.size() == 0)
		buildChain(*rootBone, *effectorBone, ikChain);

	// perform basic CCD
	stepIk();

	// need the bone transforms to be valid again afterwards for consistency
	updateBoneTransforms();
}
Exemple #5
0
void IkSolver::solveIk(int maxIterations, double threshold)
{
	if (ikChain.size() == 0)
		buildChain(*rootBone, *effectorBone, ikChain);

	for (int i = 0; i < maxIterations; ++i)
	{
		// perform basic CCD
		stepIk();

		// need the bone transforms to be valid again afterwards for consistency
		updateBoneTransforms();

		vec3d delta = getEffectorPos() - getTargetPos();
		if (abs(dot(delta,delta)) < threshold*threshold)
			break;
	}
}
Exemple #6
0
void IkSolver::setRootBone(const Bone &bone)
{
	// early out if we're not changing anything
	if (rootBone == &bone) return;

	// clear the existing IK chain
	ikChain.clear();

	// form a chain between the old root and the new root
	std::vector<const Bone*> chain;
	buildChain(bone, *rootBone, chain);

	// rebuild the rotation values along the chain
	// this is required because the rotation values are specified relative to the parent bone,
	// and the parent bone is dependent on which bone is root
	std::vector<const Bone*>::const_iterator it = chain.begin();
	while (it != chain.end())
	{
		const Bone &b = **it;
		BoneState &bs = boneStates[b.id];
		
		++it;
		if (it != chain.end())
		{
			const Bone &nb = **it;
			BoneState &nbs = boneStates[nb.id];
			bs.rot = transpose(nbs.rot);
		}
		else
			bs.rot = minor(bs.boneToWorld);
	}

	// set the new root, and its correct position
	rootBone = &bone;
	rootPos = boneStates[bone.id].boneToWorld.translation();
	
	updateBoneTransforms();
}
Exemple #7
0
bool IkSolver::buildChain(const Bone &from, const Bone &to, std::vector<const Bone*> &chain) const
{
	assert(chain.size() == 0);
	return buildChain(0, from, to, chain);
}
TH2F* fillTemplate(int sampleIndex,bool isLowMass,int updown){
  TChain* bkgMC = new TChain("SelectedTree");
  buildChain(bkgMC,sampleIndex);

  cout << "Chain for " << sampleIndex << " " << isLowMass << " " << updown << " " << bkgMC->GetEntries() << endl;
  bkgMC->ls();

  float mass,w,phjj,pvbf,Djet,phjj_old,pvbf_old;
  Short_t njets;
  int processID;
  int CRflag;
  string channel;

  bkgMC->SetBranchAddress("ZZMass",&mass);
  bkgMC->SetBranchAddress("NJets30",&njets);
  /*bkgMC->SetBranchAddress("DiJetDEta",&deta);
  if(updown==0 || updown==2 || updown==3){
    bkgMC->SetBranchAddress("DiJetMass",&mJJ);
  }else if(updown==1){
    bkgMC->SetBranchAddress("DiJetMassPlus",&mJJ);
  }else if(updown==-1){
    bkgMC->SetBranchAddress("DiJetMassMinus",&mJJ);
    }*/
  //if(sampleIndex!=4){
  if(updown==0 || updown==2 || updown==3){
    bkgMC->SetBranchAddress("pvbf_VAJHU_old",&pvbf);
    bkgMC->SetBranchAddress("phjj_VAJHU_old",&phjj);
  }
  else if(updown==1){
    bkgMC->SetBranchAddress("pvbf_VAJHU_old_up",&pvbf);
    bkgMC->SetBranchAddress("phjj_VAJHU_old_up",&phjj);
  }
  else if(updown==-1){
    bkgMC->SetBranchAddress("pvbf_VAJHU_old_dn",&pvbf);
    bkgMC->SetBranchAddress("phjj_VAJHU_old_dn",&phjj);
  }
    //}
  bkgMC->SetBranchAddress("MC_weight",&w);
  bkgMC->SetBranchAddress("genProcessId",&processID);
  if(sampleIndex==4){
    bkgMC->SetBranchAddress("CRflag",&CRflag);
    //bkgMC->SetBranchAddress("pvbf_VAJHU_old",&pvbf_old);
    //bkgMC->SetBranchAddress("phjj_VAJHU_",&phjj_old);
  }

  TH2F* bkgHist;
  if(!isLowMass){
    bkgHist = new TH2F("bkgHisto","bkgHisto",int((highMzz-180.)/mBinSize+0.5),180,highMzz,50,0,1);
  }
  else{
    bkgHist = new TH2F("bkgHisto","bkgHisto",int((180-100)/mBinSize+0.5),100,180,50,0,1);
  }

  //bkgHist->Sumw2();

  //int percent=0;

  //Fill histogram
  for(int i=0; i<bkgMC->GetEntries(); i++){
    bkgMC->GetEntry(i);
    if (i%50000==0){
      cout << "event: " << i << "/" << bkgMC->GetEntries() <<endl;
    }
    //cout<<pvbf<<" "<<phjj;
    if((sampleIndex==4 && (test_bit(CRflag,5) || test_bit(CRflag,7) || test_bit(CRflag,9) || test_bit(CRflag,11))) || sampleIndex!=4){
      if (mass<100 || (sampleIndex!=4 && (njets<2 || phjj==-1. || pvbf==-1.)) || (sampleIndex==4 && (phjj==-1. || pvbf==-1.))) continue;
      //if(updown!=0) Fisher = 0.18*fabs(deta) + 0.000192*mJJ;
      //if(sampleIndex!=4){
      Djet=pvbf/(pvbf+phjj);
      /*}
	else{
	Djet=pvbf_old/(pvbf_old+phjj_old);
	}*/
      //cout<<mass<<" "<<sampleIndex<<" "<<phjj<<" "<<pvbf<<" "<<Djet;
      bkgHist->Fill(mass,Djet,w);
    }
    //cout<<endl;
  }

  /*int nXbins=bkgHist->GetNbinsX();
  int nYbins=bkgHist->GetNbinsY();
  int nBins=0;
  int nBinstot=0;

  for(int i=1; i<=nXbins; i++){
    for(int j=1; j<=nYbins; j++){
      if(bkgHist->GetBinContent(i,j)!=0.) nBinstot++;
      if(bkgHist->GetBinContent(i,j)<0.){
	//cout<<bkgHist->GetXaxis()->GetBinCenter(i)<<" "<<bkgHist->GetYaxis()->GetBinCenter(j)<<endl;
	nBins++;
	bkgHist->SetBinContent(i,j,0.);
      }
    }
  }
  cout<<"Fraction of negative bins: "<<float(nBins)/float(nBinstot)<<endl;*/

  return bkgHist;
}
bool
FilterGraph::processInternal(bool rebuild)
{
  Speakers spk;
  Chunk chunk;

  int node = prev[node_end];

  while ( node != node_end )
  {
    /////////////////////////////////////////////////////
    // find full filter

    if ( filter[node]->isEmpty() )
    {
      // we need more data from upstream.
      node = prev[node];
      continue;
    }

    /////////////////////////////////////////////////////
    // filter is full so getOutput() must always
    // report format of next output chunk

    spk = filter[node]->getOutput();

    /////////////////////////////////////////////////////
    // Rebuild the filter chain

    if ( spk != filter[next[node]]->getInput() )
    {
      // Rebuild the chain according to format changes
      // during normal data flow.
      //
      // If format was changed it means that flushing was
      // send before (see format change rules) and we may
      // rebuild the chain right now
      if ( ! buildChain(node) )
        return false;
    }
    else if ( node_state[next[node]] == ns_rebuild )
    {
      // Rebuild the chain after flushing.
      // We have flushed downstream and may rebuild it now.
      if ( ! buildChain(node) )
        return false;
    }
    else if ( rebuild && node_state[node] == ns_dirty )
    {
      // We should rebuild graph according to changes in
      // get_next() call ONLY when we do it from the top
      // of the chain, i.e. 'rebuild' flag should be set
      // in process() and clear in get_chunk() call.
      // (otherwise partially changed graph is possible)
      //
      // If chain changes without format change we must
      // flush downstream before rebuilding the chain.
      if ( next[node] != getNext(node, spk) )
        node_state[next[node]] = ns_flush;
      else
        node_state[node] = ns_ok;
    }

    /////////////////////////////////////////////////////
    // process data downstream

    if ( node_state[next[node]] == ns_flush )
    {
      // flush downstream
      chunk.setEmpty(spk, false, 0, true);

      if ( ! filter[next[node]]->process(&chunk) )
        return false;

      node_state[next[node]] = ns_rebuild;
    }
    else
    {
      // process data
      if ( ! filter[node]->getChunk(&chunk) )
        return false;

      if ( ! filter[next[node]]->process(&chunk) )
        return false;

    }

    node = next[node];
  }

  return true;
}