简体   繁体   English

我在填充这个向量对时做错了什么?

[英]What I'm doing wrong filling this vector of pair?

If I do: 如果我做:

vector<string> vec_jets;

double values[] = {
    transEnergy(map_jets, "jet1"),
    transEnergy(map_jets, "jet2"),
    transEnergy(map_jets, "jet3"),
    transEnergy(map_jets, "jet4"),
    transEnergy(map_jets, "jet5"),
    transEnergy(map_jets, "jet6"),
    transEnergy(map_jets, "jet7") };

for( int j = 1; j <= Njets; j++){
  oss << "jet" << j;
  vec_jets.push_back( oss.str() );
  oss.str("");
}

vector<pair<string,double> > jets_pt( vec_jets.size() );

// for( int k = 0; k < Njets; k++ ){ 
  // if( jet_preselection(map_jets,map_leps,vec_jets[k],jets_emfr[k]) )

        transform(
            vec_jets.begin(),
            vec_jets.end(), 
            values,
            jets_pt.begin(),
            make_pair<string,double>
        );

//    }  

I have the output I want, which is, for example 我有我想要的输出,例如

jet1 32.4717

But, if I uncomment the for loop and the if condition, it seems that the vector is not filled anymore, if I ask to cout it, I get only 0 always. 但是,如果我取消对for循环和if条件的注释,则似乎不再填充矢量,如果我要求对其进行提示,则总是只能得到0

The function in the if statement is just a bool if语句中的函数只是一个布尔值

bool jet_preselection(
    map<string, TLorentzVector> map_jets,
    map<string, TLorentzVector> map_leps,
    string vec_jets,
    double jet_emfr )
{

        return ( map_jets[vec_jets].E()*sin(map_jets[vec_jets].Theta()) > 15 
            && jet_emfr < 0.9
            && fabs(map_jets[vec_jets].PseudoRapidity()) > 2.5
            && ( map_jets[vec_jets].DeltaR(map_leps["lep1"]) > 0.4
                && map_jets[vec_jets].DeltaR(map_leps["lep2"]) > 0.4
                && map_jets[vec_jets].DeltaR(map_leps["lep3"]) > 0.4 );
}

There are a lot of complex interdependancies in your code that make it difficult to diagnose the problem. 您的代码中有许多复杂的相互依赖关系,因此很难诊断问题。 But I can tell you that in: 但是我可以这样告诉你:

bool jet_preselection(map<string, TLorentzVector> map_jets, map<string, TLorentzVector> map_leps, string vec_jets, double jet_emfr)

...you are passing map_jets and map_leps by value rahter than by-reference (preferred) or by-pointer, so that when you call this function a complete copy of those map s is constructed. ...您传递的map_jetsmap_leps 的值比按引用(首选)或按指针的值大,因此,当您调用此函数时,将构建这些map的完整副本。

You may consider changing how you pass these parameters. 您可以考虑更改传递这些参数的方式。 Perhaps passing copies of these maps would change the states of them in such a way so that jet_preselection would fail. 也许传递这些映射的副本会以某种方式更改它们的状态,从而使jet_preselection失败。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 我在这个结构上做错了什么? - What I'm doing wrong with this structure? 在删除某些矢量元素时我做错了什么? - What i am doing wrong in erasing some vector elements? 错误 C2061 语法错误标识符——我不知道我做错了什么 - Error C2061 Syntax Error Identifier -- I don't know what I'm doing wrong 我不明白我在取消分配内存时做错了什么 - I don't understand what I'm doing wrong with my de-allocation of memory “错误:没有用于cin的运算符&gt;&gt;”我无法弄清楚我在做什么错 - “Error: no operator for cin>>” I can't figure out what I'm doing wrong here 我无法掌握LPRECT结构数据,我做错了什么? - I can't get hold of LPRECT structure data, what I'm doing wrong? 我正在尝试使用 std::signal 干净地结束我的多线程程序,我做错了什么? - I'm trying to used std::signal to cleanly end my multithreaded program, what am I doing wrong? 我已经用 pair 类干运行了这个尝试的实现,但它没有给出预期的输出。我做错了什么? - I have dry ran this implementation of tries with pair class but it's not giving expected output.What am i doing wrong? 数组有效,而矢量无效。 我究竟做错了什么? - Array works while vector doesn't. What am i doing wrong? 将带有结构的向量序列化为 a.dat 文件,我做错了什么? - What am I doing wrong with my serializing a vector with structs in it to a .dat file?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM