[英]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_jets
和map_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.