// ------------------------------------------
PyObject *LinkServiceBinder::getOneLink(PyObject *self, PyObject *args) {
    __PYTHON_EXCEPTION_GUARD_BEGIN_;
    // Nearly the same as getAllLinks. Only that it returns PyObject for LinkPtr
    // directly
    LinkServicePtr o;

    if (!python_cast<LinkServicePtr>(self, &msType, &o))
        __PY_CONVERR_RET;

    int flavor = 0, src, dst;
    PyObject *objflav;

    if (PyArg_ParseTuple(args, "Oii", &objflav, &src, &dst)) {
        if (!getFlavor(objflav, o, flavor))
            return NULL;

        const Link *res = o->getOneLink(flavor, src, dst);
        if (res)
            return LinkBinder::create(*res);

        // not found? return none
        __PY_NONE_RET;
    } else {
        // Invalid parameters
        PyErr_SetString(
            PyExc_TypeError,
            "Expected three integer parameters: flavor, src and dst!");
        return NULL;
    }
    __PYTHON_EXCEPTION_GUARD_END_;
}
Example #2
0
void GCodeExport::finalize(int maxObjectHeight, int moveSpeed, const char* endCode)
{
    writeFanCommand(0);
    writeRetraction();
    setZ(maxObjectHeight + 5000);
    writeMove(getPositionXY(), moveSpeed, 0);
    writeCode(endCode);
    log("Print time: %d\n", int(getTotalPrintTime()));
    log("Filament: %d\n", int(getTotalFilamentUsed(0)));
    log("Filament2: %d\n", int(getTotalFilamentUsed(1)));
    
    if (getFlavor() == GCODE_FLAVOR_ULTIGCODE)
    {
        char numberString[16];
        sprintf(numberString, "%d", int(getTotalPrintTime()));
        replaceTagInStart("<__TIME__>", numberString);
        sprintf(numberString, "%d", int(getTotalFilamentUsed(0)));
        replaceTagInStart("<FILAMENT>", numberString);
        sprintf(numberString, "%d", int(getTotalFilamentUsed(1)));
        replaceTagInStart("<FILAMEN2>", numberString);
    }
}
// ------------------------------------------
PyObject *LinkServiceBinder::getFieldsDesc(PyObject *self, PyObject *args) {
    __PYTHON_EXCEPTION_GUARD_BEGIN_;
    LinkServicePtr o;

    if (!python_cast<LinkServicePtr>(self, &msType, &o))
        __PY_CONVERR_RET;

    PyObject *objflav;
    int flavor = 0;

    if (PyArg_ParseTuple(args, "O", &objflav)) {
        if (!getFlavor(objflav, o, flavor))
            return NULL;

        // wrap the returned StringIterator into StringIteratorBinder, return
        const DataFields& res = o->getFieldDesc(flavor);
        return DataFieldsBinder::create(res);
    }

    // Invalid parameters
    PyErr_SetString(PyExc_TypeError, "Expected a string or integer argument!");
    return NULL;
    __PYTHON_EXCEPTION_GUARD_END_;
}
void fillPlots ( CollectionPtr & jets, 
		 CollectionPtr & core_jets, 
		 CollectionPtr & partons,
		 CollectionPtr & hgceeClusters,
		 CollectionPtr & hgchefClusters,
		 CollectionPtr & hgchebClusters,
		 likelihoodGetter & l, 
		 int index,
		 std::vector<TH1F*> quark_th1, std::vector<TH1F*> gluon_th1,
		 std::vector<TH2F*> quark_th2, std::vector<TH2F*> gluon_th2 ){

  int n_jets = jets -> GetSize();

  std::vector<double> likelihood_variables;

  for (int i = 0; i < n_jets; ++i){

    Jet jet = jets -> GetConstituent<Jet>(i);
    CollectionPtr all_core_jets     = core_jets;
    CollectionPtr matched_core_jets = core_jets -> SkimByRequireDRMatch<PFCoreJet, PFPrunedJet>( jet, 0.3 ) ;
    
    rechit_type my_type = NO_TYPE;
    int my_index = -1;
    jet.getLeadClusterTypeAndIndex(my_type, my_index);    
    double clusterLength = -1.;
    double clusterVolume = -1.;
    if ( my_type == NO_TYPE ) continue;

    if ( my_type == HGCEE ){
      HGCEECluster c(*hgceeClusters, my_index);
      clusterLength = c.getLength();
      clusterVolume = c.getVolume();
    }

    else if ( my_type == HGCHEF ){
      HGCHEFCluster c(*hgchefClusters, my_index);
      clusterLength = c.getLength();
      clusterVolume = c.getVolume();
    }

    else {
      HGCHEBCluster c(*hgchebClusters, my_index);
      clusterLength = c.getLength();
      clusterVolume = c.getVolume();
    }

    double core_over_total_pt = -1.;
    double lead_core_jet_dr   = -1.;
    double n_core_jets        = matched_core_jets -> GetSize();
    if ( n_core_jets > 0 ){
      PFCoreJet lead_core_jet = matched_core_jets -> GetLeadPtObject<PFCoreJet> ();
      double core_pt = lead_core_jet.Pt();
      core_over_total_pt = core_pt / jet.Pt();
      lead_core_jet_dr   = jet.DeltaR( &lead_core_jet );
    }
    
    int flavor = getFlavor ( jet , partons );
    if ( flavor == -1 ) continue;
    bool isQuarkJet ( flavor == 1 );
    bool isGluonJet ( flavor == 0 );


    likelihood_variables.clear();

    double weighted_depth = jet.getWeightedDepth();
    double weighted_depth_noEE = jet.getWeightedDepthNoEE();

    double profile[n_radii];
    jet.getProfile(n_radii, radii, profile);

    double profile50 = jet.getProfileRadius(n_radii, radii, profile, 0.5);
    double profile90 = jet.getProfileRadius(n_radii, radii, profile, 0.9);
    double profile95 = jet.getProfileRadius(n_radii, radii, profile, 0.95);
    double profile99 = jet.getProfileRadius(n_radii, radii, profile, 0.99);

    likelihood_variables.push_back ( jet.TrimmedNSubjets(index) );
    likelihood_variables.push_back ( jet.getWidth()   );
    likelihood_variables.push_back ( jet.getNPFCandidates() );
    likelihood_variables.push_back ( jet.getPTD() );
    likelihood_variables.push_back ( jet.NSubJettiness() );
    likelihood_variables.push_back ( jet.TrimmedMass(index) * 1000. );
    likelihood_variables.push_back ( profile50 );
    likelihood_variables.push_back ( core_over_total_pt );
    likelihood_variables.push_back ( lead_core_jet_dr );

    double ee_energy     = jet.getEEEnergy();
    double ee015_energy  = jet.getEEEnergy(0, 15);
    double ee1631_energy = jet.getEEEnergy(16, 31);
    double hef_energy    = jet.getHEFEnergy();
    double heb_energy    = jet.getHEBEnergy();
    double all_energy    = ee_energy + hef_energy + heb_energy;

    double hef11_energy  = jet.getHEFEnergy(1, 1);
    double hef22_energy  = jet.getHEFEnergy(2, 2);
    double hef34_energy  = jet.getHEFEnergy(3, 4);
    double hef56_energy  = jet.getHEFEnergy(5, 6);
    double hef712_energy = jet.getHEFEnergy(7,12);

    double likelihood  = l.getLikelihood ( likelihood_variables );

    if ( isQuarkJet ){

      quark_th1[0] -> Fill ( jet.NSubJettiness() );
      quark_th1[1] -> Fill ( jet.TrimmedMass(index) * 1000. );
      quark_th1[2] -> Fill ( jet.TrimmedNSubjets(index) );
      quark_th1[3] -> Fill ( jet.getNPFCandidates() );
      quark_th1[4] -> Fill ( jet.getWidth() );
      quark_th1[5] -> Fill ( jet.getChargedWidth() );
      quark_th1[6] -> Fill ( jet.getNeutralWidth() );
      quark_th1[7] -> Fill ( weighted_depth );
      quark_th1[8] -> Fill ( weighted_depth_noEE );
      quark_th1[9] -> Fill ( jet.getPTD() );
      quark_th1[10] -> Fill ( likelihood );
      quark_th1[11] -> Fill ( ee_energy / all_energy );
      quark_th1[12] -> Fill ( ee015_energy / all_energy );
      quark_th1[13] -> Fill ( ee1631_energy / all_energy );
      quark_th1[14]-> Fill ( heb_energy / all_energy );
      quark_th1[15]-> Fill ( hef_energy / all_energy );
      quark_th1[16]-> Fill ( hef11_energy / all_energy );
      quark_th1[17]-> Fill ( hef22_energy / all_energy );
      quark_th1[18]-> Fill ( hef34_energy / all_energy );
      quark_th1[19]-> Fill ( hef56_energy / all_energy );
      quark_th1[20]-> Fill ( hef712_energy / all_energy );
      for (int i_radius = 0; i_radius < n_radii; ++i_radius){
	quark_th1[21] -> Fill(radii[i_radius], profile[i_radius]);
      }
      quark_th1[22] -> Fill ( profile50 );
      quark_th1[23] -> Fill ( profile90 );
      quark_th1[24] -> Fill ( profile95 );
      quark_th1[25] -> Fill ( profile99 );
      quark_th1[26] -> Fill ( n_core_jets        );
      quark_th1[27] -> Fill ( lead_core_jet_dr   );
      quark_th1[28] -> Fill ( core_over_total_pt );
      quark_th1[29] -> Fill ( clusterVolume );
      quark_th1[30] -> Fill ( clusterLength );
      
      quark_th2[0] -> Fill ( jet.Pt(), weighted_depth );
      quark_th2[1] -> Fill ( jet.Pt(), jet.getMaxRHDepth());
      quark_th2[2] -> Fill ( jet.getNPFCandidates(), jet.TrimmedNSubjets(index) );
    }

    if ( isGluonJet ){
      
      gluon_th1[0] -> Fill ( jet.NSubJettiness() );
      gluon_th1[1] -> Fill ( jet.TrimmedMass(index) * 1000. );
      gluon_th1[2] -> Fill ( jet.TrimmedNSubjets(index) );
      gluon_th1[3] -> Fill ( jet.getNPFCandidates() );
      gluon_th1[4] -> Fill ( jet.getWidth() );
      gluon_th1[5] -> Fill ( jet.getChargedWidth() );
      gluon_th1[6] -> Fill ( jet.getNeutralWidth() );
      gluon_th1[7] -> Fill ( weighted_depth );
      gluon_th1[8] -> Fill ( weighted_depth_noEE );
      gluon_th1[9] -> Fill ( jet.getPTD() );
      gluon_th1[10] -> Fill ( likelihood );
      gluon_th1[11] -> Fill ( ee_energy / all_energy );

      gluon_th1[12] -> Fill ( ee015_energy / all_energy );
      gluon_th1[13] -> Fill ( ee1631_energy / all_energy );
      gluon_th1[14]-> Fill ( heb_energy / all_energy );
      gluon_th1[15]-> Fill ( hef_energy / all_energy );
      gluon_th1[16]-> Fill ( hef11_energy / all_energy );
      gluon_th1[17]-> Fill ( hef22_energy / all_energy );
      gluon_th1[18]-> Fill ( hef34_energy / all_energy );
      gluon_th1[19]-> Fill ( hef56_energy / all_energy );
      gluon_th1[20]-> Fill ( hef712_energy / all_energy );
      for (int i_radius = 0; i_radius < n_radii; ++i_radius){
	gluon_th1[21] -> Fill(radii[i_radius], profile[i_radius]);
      }
      gluon_th1[22] -> Fill ( profile50 );
      gluon_th1[23] -> Fill ( profile90 );
      gluon_th1[24] -> Fill ( profile95 );
      gluon_th1[25] -> Fill ( profile99 );
      gluon_th1[26] -> Fill ( n_core_jets        );
      gluon_th1[27] -> Fill ( lead_core_jet_dr   );
      gluon_th1[28] -> Fill ( core_over_total_pt );
      gluon_th1[29] -> Fill ( clusterVolume );
      gluon_th1[30] -> Fill ( clusterLength );

      gluon_th2[0] -> Fill ( jet.Pt(), weighted_depth );
      gluon_th2[1] -> Fill ( jet.Pt(), jet.getMaxRHDepth());
      gluon_th2[2] -> Fill ( jet.getNPFCandidates(), jet.TrimmedNSubjets(index) );

      
    }
  }
}
// ------------------------------------------
PyObject *LinkServiceBinder::getRelation(PyObject *self, PyObject *args) {
    __PYTHON_EXCEPTION_GUARD_BEGIN_;
    PyObject *result = NULL;
    LinkServicePtr o;

    if (!python_cast<LinkServicePtr>(self, &msType, &o))
        __PY_CONVERR_RET;

    PyObject *object;
    if (!PyArg_ParseTuple(args, "O", &object)) {
        PyErr_SetString(PyExc_TypeError,
                        "Expected an integer or string argument!");
        return NULL;
    }

    // two possibilities here : name or flavor
#ifdef IS_PY3K
    if (PyBytes_Check(object)) {
        char *str = PyBytes_AsString(object);
#else
    if (PyString_Check(object)) {
        char *str = PyString_AsString(object);
#endif
        RelationPtr rel = o->getRelation(str);

        if (!rel) {
            PyErr_Format(PyExc_ValueError, "Relation not found by name %s",
                         str);
        } else
            result = RelationBinder::create(rel);

        return result;
    } else if (PyLong_Check(object)) {
        long id = PyLong_AsLong(object);
        RelationPtr rel = o->getRelation(static_cast<int>(id));

        if (!rel) {
            PyErr_Format(PyExc_ValueError, "Relation not found by id %ld", id);
        } else
            result = RelationBinder::create(rel);

        return result;
    } else {
        // Invalid parameters
        PyErr_SetString(PyExc_TypeError,
                        "Expected an integer or string argument!");
        return NULL;
    }
    __PYTHON_EXCEPTION_GUARD_END_;
}

// ------------------------------------------
PyObject *LinkServiceBinder::getAllLinks(PyObject *self, PyObject *args) {
    __PYTHON_EXCEPTION_GUARD_BEGIN_;
    LinkServicePtr o;

    if (!python_cast<LinkServicePtr>(self, &msType, &o))
        __PY_CONVERR_RET;

    int flavor = 0, src, dst;
    PyObject *objflav;

    // let the third parameter be either string or integer
    // if it's a string, we first have to parse the string to get flavor id

    if (PyArg_ParseTuple(args, "Oii", &objflav, &src, &dst)) {
#ifdef IS_PY3K
        if (PyBytes_Check(objflav)) {
            char *str = PyBytes_AsString(objflav);
#else
        if (PyString_Check(objflav)) {
            char *str = PyString_AsString(objflav);
#endif
            flavor = o->nameToFlavor(str);
        } else if (PyLong_Check(objflav)) {
            flavor = PyLong_AsLong(objflav);
        } else {
            PyErr_SetString(
                PyExc_TypeError,
                "Invalid type given for flavor: expected string or integer");
            return NULL;
        }

        LinkQueryResultPtr res = o->getAllLinks(flavor, src, dst);

        return LinkQueryResultBinder::create(res);
    } else {
        // Invalid parameters
        PyErr_SetString(PyExc_TypeError,
                        "Expected three parameters: flavor, src and dst!");
        return NULL;
    }
    __PYTHON_EXCEPTION_GUARD_END_;
}

// ------------------------------------------
bool LinkServiceBinder::getFlavor(PyObject *src, LinkServicePtr &obj,
                                  int &flavor) {
    __PYTHON_EXCEPTION_GUARD_BEGIN_;
#ifdef IS_PY3K
    if (PyBytes_Check(src)) {
        char *str = PyBytes_AsString(src);
#else
    if (PyString_Check(src)) {
        char *str = PyString_AsString(src);
#endif
        flavor = obj->nameToFlavor(str);
        return true;
    } else if (PyLong_Check(src)) {
        flavor = PyLong_AsLong(src);
        return true;
    } else {
        PyErr_SetString(
            PyExc_TypeError,
            "Invalid type given for flavor: expected string or integer");
        return false;
    }
    __PYTHON_EXCEPTION_GUARD_END_RVAL(false);
}

// ------------------------------------------
PyObject *LinkServiceBinder::getAllInherited(PyObject *self, PyObject *args) {
    __PYTHON_EXCEPTION_GUARD_BEGIN_;
    LinkServicePtr o;

    if (!python_cast<LinkServicePtr>(self, &msType, &o))
        __PY_CONVERR_RET;

    int flavor = 0, src, dst;
    PyObject *objflav;

    // let the third parameter be either string or integer
    // if it's a string, we first have to parse the string to get flavor id

    if (PyArg_ParseTuple(args, "Oii", &objflav, &src, &dst)) {
        if (!getFlavor(objflav, o, flavor))
            return NULL;

        LinkQueryResultPtr res = o->getAllInherited(flavor, src, dst);

        return LinkQueryResultBinder::create(res);
    } else {
        // Invalid parameters
        PyErr_SetString(PyExc_TypeError,
                        "Expected three parameters: flavor, src and dst!");
        return NULL;
    }
    __PYTHON_EXCEPTION_GUARD_END_;
}