Why is this not working? It keeps giving me an error:
/afs/cern.ch/user/a/aayilara/CMSSW_4_2_5/src/Demo/DemoAnalyzer2/src/DemoAnalyzer2.cc:410: error: invalid types ‘double[int]’ for array subscript
Before I put in the ‘if’ loop, it would write 1 data and then keep over-writing until only the last data remained. I have 768 events here as invmass values, I need all of them into the text file
I improved it slightly, but now it just gives me a long list of numbers with no spaces. I don’t know how to get the data from the invmass equation into an array for me to access:
int invmassarray [] = { invmass, };declares a fix size array of exactly one element but then for (unsigned int i=0; i<800; i++)
{
myfile << invmassarray[i];
}
tries to store 800 elements in the array … leading to disaster.
humm … I am confused. In order to make sense the snippet of code need to read data from the file:[code]double invmass= sqrt(pow((e0->energy()+e1->energy()),2.)-pow((e0->px()+e1->px()),2.)-pow((e0->py()+e1->py()),2.)-pow((e0->pz()+e1->pz()),2.));
std::vector<int> invmassarray;
if ( preshower > 0 && preshower2 > 0)
{
h_Zmass->Fill(invmass);
//h_Zmass->Fit("gaus");
LogInfo("Demo")<<"Invariant Mass"<<invmass;
ifstream myfile ("invmass.txt");
if (myfile.is_open())
{
for (unsigned int i=0; i<800; i++)
{
int readtmp;
myfile >> readtmp;
invmassarray.push_back(readtmp);
}
myfile.close();
}
}[/code]If the intent is to write to the file ... then I have not clue [b]what[/b] you are trying to write (i.e. where does the data come from) ....
This line gives calculated values. I have plotted invmass in a histogram and I get a gaussian distribution with around 768 events. Now I want all invmass values put into the array (invmassarray), so that I can write the array to a text file and then play with those values. Basically I need some way of getting the values I calculate, into a text file.
invmass -> invmassarray -> textfile -> read invmass values
[b]The data that I want to write to the file comes from invmass.[/b]
This line gives calculated values. I have plotted invmass in a histogram and I get a gaussian distribution with around 768 events. Now I want all invmass values put into the array (invmassarray), so that I can write the array to a text file and then play with those values. Basically I need some way of getting the values I calculate, into a text file.