Code Crash

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

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

1 Like

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.

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 (7.7 KB)

Your TGraph is elosscurve not eLossCurve_