# Code Crash

**URL:** <https://root-forum.cern.ch/t/code-crash/52579>\
**Category:** Newbie\
**Tags:** root\
**Created:** [December 1, 2022, 3:39pm UTC](https://root-forum.cern.ch/t/code-crash/52579 "2022-12-01T15:39:56Z")\
**Posts on this page:** 4\
**Page:** 2

<div class="post-metadata">

**Author:** ![Harriet\_Kumi](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/harriet_kumi/32/31605_2.png) [@Harriet\_Kumi](https://root-forum.cern.ch/u/Harriet_Kumi)\
**Post date:** [December 9, 2022, 9:47am UTC](https://root-forum.cern.ch/t/code-crash/52579/21 "2022-12-09T09:47:49Z")

</div>

I get you. I am going to change it and see.

---

<div class="post-metadata">

**Author:** ![Harriet\_Kumi](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/harriet_kumi/32/31605_2.png) [@Harriet\_Kumi](https://root-forum.cern.ch/u/Harriet_Kumi)\
**Post date:** [December 9, 2022, 10:30am UTC](https://root-forum.cern.ch/t/code-crash/52579/22 "2022-12-09T10:30:45Z")

</div>

I have seen all my mistakes. There is no need for the 3D array.

---

<div class="post-metadata">

**Author:** ![Harriet\_Kumi](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/harriet_kumi/32/31605_2.png) [@Harriet\_Kumi](https://root-forum.cern.ch/u/Harriet_Kumi)\
**Post date:** [December 22, 2022, 10:45am UTC](https://root-forum.cern.ch/t/code-crash/52579/23 "2022-12-22T10:45:04Z")

</div>

Good Morning,  
Please I have the file van.txt that I want to read. I want to read just the numbers and ignore the units and the headers. I get errors in my code Processing slits.C…  
In file included from input\_line\_8:1:  
/home/harriet/fair\_install/ATTPCROOTv2/build/slits.C:79:20: error: no member named ‘SetPoint’ in 'std::_cxx11::basic\_string’  
eLossCurve-\>SetPoint(eLossCurve_-\>GetN(),ener,dEdx\_elec+dEdx\_nucl);  
~~~~~~~~~~~ ^  
/home/harriet/fair\_install/ATTPCROOTv2/build/slits.C:79:42: error: no member named ‘GetN’ in 'std::_cxx11::basic\_string’  
eLossCurve-\>SetPoint(eLossCurve_-\>GetN(),ener,dEdx\_elec+dEdx\_nucl);  
~~~~~~~~~~~ ^  
/home/harriet/fair\_install/ATTPCROOTv2/build/slits.C:99:2: error: expected expression  
else{  
^  
this is my code and the file. Thank you.

```auto
void slits(std::string file, Int_t pdg){
// std::ifstream elossfile;
   std::string elossFileName_;
   std::string maxKinEnergy_;
   std::string eLossFiles_ ;
   std::string *eLossCurve_=new std::string();
   std::string eLossCurves_;
   elossFileName_ = file;

  // eLossFile_.exceptions(std::ifstream::failbit | std::ifstream::badbit);

  Float_t ener = 0;
  TString enerUnit = "";
  Float_t dEdx_elec = 0;
  Float_t dEdx_nucl = 0;
  Float_t range = 0;
  TString rangeUnit = "";
  Float_t lonStra = 0;
  TString lonStraUnit = "";
  Float_t latStra = 0;
  TString latStraUnit = "";

  std::ifstream* elossfile = new std::ifstream();
  TGraph* elosscurve = new TGraph();

  try {

    elossfile->open("van.txt",ios::in);

    if ((elossfile->peek() == std::ifstream::traits_type::eof())) {

      std::cout << " Error: Energy loss file not found! Exiting..."
                << "\n";
      std::exit(EXIT_FAILURE);
    }

    //eLossFile_.clear();
    //eLossFile_.seekg(0);

    std::cout << " Processing energy loss data file " << elossFileName_ << "\n";
    std::string line;

    for (auto i = 0; i < 3; ++i) {
      std::getline(*elossfile,line);
      std::cout << line << "\n";
    }

    while (std::getline(*elossfile, line)) {

      std::istringstream data(line);
      data >> ener >> enerUnit >> dEdx_elec >> dEdx_nucl >> range >> rangeUnit >> lonStra >> lonStraUnit >> latStra >> latStraUnit ;
      if(enerUnit.Contains("keV"))
        ener/=1000.0;

      std::cout<<ener<<" "<<enerUnit.Data()<<" "<<dEdx_elec<<" "<<dEdx_nucl<<" "<<range<<" "<<rangeUnit.Data()<<" "<<lonStra<<" "<<lonStraUnit.Data()<<" "<<latStra<<" "<<latStraUnit<<"\n";

      if (ener > maxKinEnergy_)
        maxKinEnergy_ = ener;

      eLossCurve_->SetPoint(eLossCurve_->GetN(),ener,dEdx_elec+dEdx_nucl);
      elosscurve->SetPoint(elosscurve->GetN(),ener,dEdx_elec+dEdx_nucl);
      //std::cout<<eLossCurve_->GetN()<<" "<<elosscurve->GetN()<<"\n";//NB: eLossCurve_ only valid if only one AtFitter::AtGenfit object is created.
         if(elossfile->eof()) break;
    }

     std::cout<<" Maximum kinetic energy for energy loss :"<<maxKinEnergy_<<"\n";
     std::cout<<" PDG (Pass by AtFitter constructor) "<<pdg<<"\n"; 
eLossFiles_.push_back(elossfile);

     if(eLossCurves_.find(pdg) == eLossCurves_.end())
       {
         std::cout<<" Adding energy loss map for : "<<pdg<<"\n";         
         eLossCurves_.insert({pdg,elosscurve});
         std::cout<<" Number of tables : "<<eLossCurves_.size()<<"\n";

       }

        else{
             std::cout<<" Warning! Key found in map : "<<pdg<<"\n";
       }

     //std::cout<<" Sanity check "<<"\n";
    // Sanity check
     //for(auto i = 0 ; i<1000 ; ++i)
     //{
     //std::cout<<" Energy : "<<i/10.0<<" - dE/dx : "<<eLossCurve_->Eval(i/10.0)<<" - dE/dx (density) :"<<gasMediumDensity_*eLossCurve_->Eval(i/10.0)<<"\n";
     //std::cout<<" Energy (Curves) : "<<i/10.0<<" - dE/dx : "<<elosscurve->Eval(i/10.0)<<" - dE/dx (density) :"<<gasMediumDensity_*elosscurve->Eval(i/10.0)<<"\n";
     //}

  } catch (...) {

  }

  
}

```

[van.txt](https://root-forum.cern.ch/uploads/short-url/q7tLfJNZMsaPbMlpDMGX6ZC7hvh.txt) (7.7 KB)

---

<div class="post-metadata">

**Author:** ![couet](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/couet/32/12037_2.png) [@couet](https://root-forum.cern.ch/u/couet)\
**Post date:** [January 5, 2023, 10:57am UTC](https://root-forum.cern.ch/t/code-crash/52579/24 "2023-01-05T10:57:51Z")

</div>

Your TGraph is `elosscurve` not `eLossCurve_`

[Previous page](https://root-forum.cern.ch/t/code-crash/52579.md?page=1)
