float ReconstructionMCMatching::DrQ2(Interpretation& i){
    float dr=999;
    if(q2.Pt()>0.01 && i.Q2().Pt()>0.01){
	dr=q2.DeltaR(i.Q2());
    }
    return dr;
}
float ReconstructionMCMatching::DrBLep(Interpretation& i){
    float dr=999;
    if(b_lep.Pt()>0.01 && i.BLep().Pt()>0.01){
	dr=b_lep.DeltaR(i.BLep());
    }
    return dr;
}
float ReconstructionMCMatching::DrH(Interpretation& i){
    float dr=999;
    if(higgs.Pt()>0.01 && i.Higgs().Pt()>0.01){
	dr=higgs.DeltaR(i.Higgs());
    }
    return dr;
}
float ReconstructionMCMatching::DrTopHad(Interpretation& i){
    float dr=999;
    if(top_had.Pt()>0.01 && i.TopHad().Pt()>0.01){
	dr=top_had.DeltaR(i.TopHad());
    }
    return dr;
}
float ReconstructionMCMatching::DrNu(Interpretation& i){
    float dr=999;
    if(nu.Pt()>0.01 && i.Nu().Pt()>0.01){
	dr=nu.DeltaR(i.Nu());
    }
    return dr;
}
bool ReconstructionMCMatching::MatchBHad(Interpretation& i){
  if(setupMC==0){
    cerr << "need to setup mc matching first!" << endl;
    return false;
  }
  bool matchBhad=b_had.E()>1.&&i.BHad().E()>1.&&b_had.DeltaR(i.BHad())<maxdr;  
  //  cout << "dr bhad " << b_had.DeltaR(i.BHad()) << endl;
  return matchBhad;
}
bool ReconstructionMCMatching::MatchBLep(Interpretation& i){
  if(setupMC==0){
    cerr << "need to setup mc matching first!" << endl;
    return false;
  }
  //  cout << "dr blep " << b_lep.DeltaR(i.BLep()) << endl;
  bool matchBlep=b_lep.E()>1.&&i.BLep().E()>1.&&b_lep.DeltaR(i.BLep())<maxdr;
  return matchBlep;
}
bool ReconstructionMCMatching::MatchH(Interpretation& i){
  if(setupMC<2){
    cerr << "need to setup mc matching (incl Higgs) first!" << endl;
    return false;
  }
  bool matchH=b1.E()>1.&&b2.E()>1.&&i.B1().E()>1.&&i.B2().E()>1.
    && ( (b1.DeltaR(i.B1())<maxdr && b2.DeltaR(i.B2())<maxdr) || (b1.DeltaR(i.B2())<maxdr && b2.DeltaR(i.B1())<maxdr) );
  return matchH;
}
bool ReconstructionMCMatching::MatchWHad(Interpretation& i){
  if(setupMC==0){
    cerr << "need to setup mc matching first!" << endl;
    return false;
  }
  bool matchWhad=q1.E()>1.&&q2.E()>1.&&i.Q1().E()>1.&&i.Q2().E()>1.
		   && 
    ( (q1.DeltaR(i.Q1())<maxdr && q2.DeltaR(i.Q2())<maxdr) || (q1.DeltaR(i.Q2())<maxdr && q2.DeltaR(i.Q1())<maxdr) );
  //  cout << "1 " << q1.DeltaR(i.Q1()) << ", " <<  q2.DeltaR(i.Q2()) << " 2 " << q2.DeltaR(i.Q1()) << ", " <<  q1.DeltaR(i.Q2()) << endl;
  //  cout << "q1 pt " << i.Q1().Pt() << " q2 pt " << i.Q2().Pt()  << " blep pt " << i.BLep().Pt()   << " bhad pt " << i.BHad().Pt() << " nu pz " << i.Nu().Pz() << endl;
  //  if(matchWhad)   cout << "matched" << endl;
  //  else cout << "not matched" << endl;
  return matchWhad;
}
Ejemplo n.º 10
0
void ConsistencyAtom::anticipateLearning(RegistryPtr& registry,const InterpretationConstPtr& assigned,NogoodContainerPtr& nogoods,
		vector<string>& expressions,vector<ID>& atomIds,vector<OrdinaryAtom> &sumData,int domainMinValue,int domainMaxValue,string& globalConstraintName,string& globalConstraintValue,Interpretation& toCheck)
{
	pm.updateMask();
	Interpretation::TrueBitIterator it, it_end;
	boost::tie(it, it_end) = pm.mask()->trueBits();
	//iterate over all Ordinary ground atom (expr and not_expr)
	for(;it!=it_end;it++)
	{
		//if the atom is not assigned, add atom to lists in order to check consistency
		if(assigned->getFact(*it))
		{
			continue;
		}
		const OrdinaryAtom& atom=pm.mask()->getAtomToBit(it);

		if (atom.tuple[0]==exprAuxID && (!cspGraphLearning || !cpVariables.getFact(*it) || toCheck.getFact(*it))) {
			expressions.push_back(getExpressionFromID(registry,atom,false));
			atomIds.push_back(registry->ogatoms.getIDByTuple(atom.tuple));
		}
		else if (atom.tuple[0]==not_exprAuxID && (!cspGraphLearning ||!cpVariables.getFact(*it) || toCheck.getFact(*it))) {
			expressions.push_back(getExpressionFromID(registry,atom,true));
			atomIds.push_back(registry->ogatoms.getIDByTuple(atom.tuple));
		}


		GecodeSolver* solver = new GecodeSolver(registry,sumData,domainMinValue, domainMaxValue, globalConstraintName, globalConstraintValue, simpleParser);
		solver->propagate(expressions);

		Gecode::Search::Options opt;
		Gecode::BAB<GecodeSolver> solutions(solver,opt);

		//if the solution is not consistent  try to learn nogoods
		if (solutions.next()==NULL)
		{
			GecodeSolver* otherSolver = new GecodeSolver(registry,sumData, domainMinValue,domainMaxValue, globalConstraintName, globalConstraintValue, simpleParser);
			//try to learn no goods
			backwardlearningProcessor->learnNogoods(nogoods,expressions,atomIds,otherSolver);
			delete otherSolver;
		}
		delete solver;
		expressions.pop_back();
		atomIds.pop_back();
	}


}
int ReconstructionMCMatching::MatchNWHad(Interpretation& i){
  if(setupMC<1){
    cerr << "need to setup mc matching (incl Higgs) first!" << endl;
    return false;
  }
  int nQ=0;
  if(q1.E()>1.&&q2.E()>1.&&i.Q1().E()>1.&&i.Q2().E()>1.){
    if(q1.DeltaR(i.Q1())<maxdr || q2.DeltaR(i.Q1())<maxdr) nQ++;
    if(q1.DeltaR(i.Q2())<maxdr || q2.DeltaR(i.Q2())<maxdr) nQ++;
  }
  return nQ++;
}
int ReconstructionMCMatching::MatchNH(Interpretation& i){
  if(setupMC<2){
    cerr << "need to setup mc matching (incl Higgs) first!" << endl;
    return false;
  }
  int nQ=0;
  if(b1.E()>1.&&b2.E()>1.&&i.B1().E()>1.&&i.B2().E()>1.){
    if(b1.DeltaR(i.B1())<maxdr || b2.DeltaR(i.B1())<maxdr) nQ++;
    if(b1.DeltaR(i.B2())<maxdr || b2.DeltaR(i.B2())<maxdr) nQ++;
  }
  return nQ;
}
float ReconstructionMCMatching::SumDrTTH(Interpretation& i){
  if(setupMC<2){
    cerr << "need to setup mc matching (incl Higgs) first!" << endl;
    return false;
  }
  float sumDr=0;
  sumDr+=b_had.DeltaR(i.BHad());
  sumDr+=q1.DeltaR(i.Q1());
  sumDr+=q2.DeltaR(i.Q2());
  sumDr+=b_lep.DeltaR(i.BLep());
  sumDr+=lep.DeltaR(i.Lep());
  sumDr+=nu.DeltaR(i.Nu());
  sumDr+=b1.DeltaR(i.B1());
  sumDr+=b2.DeltaR(i.B1());

  return sumDr;
}
float ReconstructionQuality::TTWBBChi2(Interpretation& i){
  if(i.HasTag("TTWBBChi2")) return i.GetTag("TTWBBChi2");
  float tag=TTWBBChi2(i.TopHad_M(),i.TopLep_M(),i.WHad_M(),i.Higgs_M());
  i.SetTag("TTWBBChi2",tag);
  return tag;
}
float ReconstructionQuality::TTHBB_ME(Interpretation& i){
  if(i.HasTag("TTHBB_ME")) return i.GetTag("TTHBB_ME");
  float tag=me.GetTTHBBMEsq(i.TopHad(),i.TopLep(),i.B1(),i.B2());
  i.SetTag("TTHBB_ME",tag);
  return tag;
}
float ReconstructionQuality::TTWishLikelihood(Interpretation& i){
  if(i.HasTag("TTWishLikelihood")) return i.GetTag("TTWishLikelihood");
  float tag=TTWishLikelihood(i.TopHad_M(),i.TopLep_M(),i.WHad_M());
  i.SetTag("TTWishLikelihood",tag);
  return tag;
}
Ejemplo n.º 17
0
void ConsistencyAtom::retrieve(const Query& query, Answer& answer, NogoodContainerPtr nogoods) throw (PluginError)
{
	Interpretation toCheck;
	RegistryPtr registry = getRegistry();
	std::vector<std::string> expressions;
	std::vector<OrdinaryAtom> sumData;
	int domainMaxValue;
	int domainMinValue;
	bool definedDomain=false;
	std::string globalConstraintName = "";
	std::string globalConstraintValue = "";

	std::pair<Interpretation::TrueBitIterator, Interpretation::TrueBitIterator>
		trueAtoms ;
	InterpretationConstPtr toUse;
	if(query.assigned!=NULL)
	{
		trueAtoms= query.assigned->trueBits();
		toUse=query.assigned;
	}
	else
	{
		toUse=query.interpretation;
		trueAtoms= query.interpretation->trueBits();
	}


	vector<ID> atomIds;
	if(!idSaved)
		storeID(registry);

	// Iterate over all input interpretation
	for (Interpretation::TrueBitIterator it = trueAtoms.first; it != trueAtoms.second; it++) {
		const OrdinaryAtom &atom = toUse->getAtomToBit(it);
		Term name = registry->terms.getByID(atom.tuple[0]);
		if(!query.interpretation->getFact(*it)){
			continue;
		}
		string expr="";

		if (atom.tuple[0]==exprAuxID) {
			expressions.push_back(getExpressionFromID(registry,atom,false));
			ID atomID=registry->ogatoms.getIDByTuple(atom.tuple);
			atomIds.push_back(atomID);
			if(cspGraphLearning && possibleConflictCpVariable.find(atomID)!=possibleConflictCpVariable.end())
			{
				set< Interpretation* > s=possibleConflictCpVariable.at(atomID);
				for( set<Interpretation*>::iterator it=s.begin();it!=s.end();++it)
				{
					toCheck.add(**it);
				}
			}
		}
		else if (atom.tuple[0]==not_exprAuxID) {
			expressions.push_back(getExpressionFromID(registry,atom,true));
			ID atomID=registry->ogatoms.getIDByTuple(atom.tuple);
			atomIds.push_back(atomID);
			// if the atom doesn't contain ASP variables insert all atom that are possible conflict
			if(cspGraphLearning && possibleConflictCpVariable.find(atomID)!=possibleConflictCpVariable.end())
			{
				set< Interpretation* > s=possibleConflictCpVariable.at(atomID);
				for( set<Interpretation*>::iterator it=s.begin();it!=s.end();++it)
				{
					toCheck.add(**it);
				}
			}
		}
		else if (atom.tuple[0]==domainAuxID) {
			definedDomain=true;
			domainMinValue=atom.tuple[1].address;
			domainMaxValue=atom.tuple[2].address;;
		}
		else if (atom.tuple[0]==maximizeAuxID ||atom.tuple[0]==minimizeAuxID) {
			globalConstraintName = name.symbol;
			globalConstraintValue = removeQuotes(registry->terms.getByID(atom.tuple[1]).symbol);
		}
		else { // this predicate received as input to sum aggregate function
			sumData.push_back(atom);
		}
	}

	if(!definedDomain)
		throw dlvhex::PluginError("No domain specified");

//	 Call gecode solver
	GecodeSolver* solver = new GecodeSolver(registry,sumData,domainMinValue, domainMaxValue, globalConstraintName, globalConstraintValue, simpleParser);
	solver->propagate(expressions);

	Gecode::Search::Options opt;
	Gecode::BAB<GecodeSolver> solutions(solver,opt);

	// If there's at least one solution, then data is consistent
	if (solutions.next()) {
		Tuple out;
		answer.get().push_back(out);
		if(cspAnticipateLearning && query.assigned!=NULL)
			anticipateLearning(registry,query.assigned,nogoods,expressions,atomIds,sumData,domainMinValue,domainMaxValue,globalConstraintName,globalConstraintValue,toCheck);
	}
	else if (nogoods != 0){ // otherwise we need to learn IIS from it
		GecodeSolver* otherSolver = new GecodeSolver(registry,sumData, domainMinValue,domainMaxValue, globalConstraintName, globalConstraintValue, simpleParser);
		learningProcessor->learnNogoods(nogoods, expressions, atomIds, otherSolver);
		delete otherSolver;
	}
	delete solver;
}