#include #include "TH1.h" void get_data_from_file(Char_t filename[], Int_t &tvivo, Int_t &treal, Int_t &ch_lo, Int_t &ch_hi,TH1F *&histo) /****************************** Legge il file, scrivendo il tempo vivo, reale, il canale piu' basso (0) e quello piu' alto (ultimo - 1, perche' non considera l'ultimo canale, perche' e' pieno di saturati) ******************************/ { char buffer[80],sample[80],data[80]; ifstream file (filename); // read header file.getline (buffer,200); // Skip 1st line file.getline (sample,200); // read comment for (int i=0;i<5;++i) file.getline (&buffer[0],200); //skip 5 lines file.getline (data,200); // read date file.getline (buffer,200); // skip 1 line file.getline (buffer,200); // read leave and real time istrstream line(buffer); line >> tvivo; line >> treal; file.getline (buffer,200); // skip this line file.getline (buffer,200); // read channels istrstream line(buffer); line >> ch_lo; //ch_lo = 0 line >> ch_hi; //ch_hi = 2047 --ch_hi; //ch_hi = 2046 /*Il numero di canali totali e' ch_hi-ch_lo+1 ma l'ultimo e' ignorato perche' contiene solo le saturazioni. Dati da 0 a 2047, canali da 0 a 2046*/ histo = new TH1F(data,sample,(ch_hi-ch_lo)+1,ch_lo,ch_hi); for (int i=ch_lo;i<=ch_hi;++i) { int counts; file.getline (buffer,200); // read channels istrstream line(buffer); line >> counts; histo->Fill((double)i,(double)counts); } file.getline (&buffer[0],200); istrstream line_sat(buffer); int saturazione; line_sat >> saturazione; cout << "Saturazione ignorata: " << saturazione << " (" << (double)saturazione/histo->GetSum()*100 << "%)" << endl; }