void analizewaveforms(int RUNNUMBER, int MAXEVENT, int DRAW, int CHANNELTODRAW, int EVENTTODRAW) { //how to run with no display: root -q -b 'analizewaveforms.C(143,5000,0,2,1)' //how to run with display : root -l 'analizewaveforms.C(143,5000,0,2,1)' char FILENAME[1000]; sprintf(FILENAME,"HistosNtuple%d.root",RUNNUMBER); TFile* RootFile= new TFile(FILENAME,"RECREATE"); cout<<"Creating new file root for histos . . . "<Branch("nrun" , &nrun ,"nrun/I" ); tree->Branch("nwave" , &nwave ,"nwave/I" ); tree->Branch("nevent" , &nevent ,"nevent/I" ); tree->Branch("charge" , &charge ,"charge[2]/F" ); tree->Branch("chargebg" , &chargebg ,"chargebg[2]/F" ); tree->Branch("chargeBG" , &chargeBG ,"chargeBG[2]/F" ); tree->Branch("maxvalue" , &maxvalue ,"maxvalue[nwave]/F" ); ///////////////////////////////// string fileinput ; fstream filePdfstream1 ; fstream filePdfstream2 ; sprintf(FILENAME,"./output%d_dut.dat",RUNNUMBER); filePdfstream1.open(FILENAME , fstream::in); sprintf(FILENAME,"./output%d_trigger.dat",RUNNUMBER); filePdfstream2.open(FILENAME , fstream::in); TH1F * hwave1 ; TH1F * hwave2 ; TH1F * hwavesum1 ; TH1F * hwavesum2 ; int points = 512 ; hwavesum1 = new TH1F("hwavesum1","wavesum1",points,0,points); hwavesum1 -> SetXTitle("Bin"); hwavesum1 -> GetYaxis()->SetTitleSize(0.05); hwavesum1 -> GetXaxis()->SetTitleSize(0.05); hwavesum1 -> SetYTitle("[V]"); hwavesum1 -> SetTitle("DUT"); hwavesum2 = new TH1F("hwavesum2","wavesum2",points,0,points); hwavesum2 -> SetXTitle("Bin"); hwavesum2 -> GetYaxis()->SetTitleSize(0.05); hwavesum2 -> GetXaxis()->SetTitleSize(0.05); hwavesum2 -> SetYTitle("[V]" ); hwavesum2 -> SetTitle ("trigger" ); hwave1 = new TH1F("hwave1","wave1",points,0,points); hwave1 -> SetXTitle("Bin"); hwave1 -> GetYaxis()->SetTitleSize(0.05); hwave1 -> GetXaxis()->SetTitleSize(0.05); hwave1 -> SetYTitle("[V]"); hwave1 -> SetTitle("DUT"); hwave2 = new TH1F("hwave2","wave2",points,0,points); hwave2 -> SetXTitle("Bin"); hwave2 -> GetYaxis()->SetTitleSize(0.05); hwave2 -> GetXaxis()->SetTitleSize(0.05); hwave2 -> SetYTitle("[V]" ); hwave2 -> SetTitle ("Trigger" ); gROOT->Reset(); //gStyle->SetOptStat(1111); //visualizza il box statistico dell'istogramma //gStyle->SetOptFit(1111111); int max_events=0; int stop=0; istringstream ss; float NORM = (BINWIDTH+1)/float(FIRSTBIN-1-BINWIDTH-6+510-FIRSTBIN-BINWIDTH-1+2); while(stop==0 && max_eventsSetOptStat(""); int bin = 0 ; int k_row=0; float VCh1 = 0; std::cout << "Load Input File: Good? " << filePdfstream1.good() << std::endl; //leggo il file riga per riga getline(filePdfstream1,sFileRow); hwave1->Reset(); k_row++; //if(max_events==2) //std::cout << k_row << " " << sFileRow << std::endl; ss=sFileRow; bin=0; do { bin++; ss >> VCh1; //std::cout << bin << " " << sFileRow << " / " << std::endl; //std::cout << bin << " " << VCh1 << std::endl; hwave1 -> SetBinContent(bin,float(VCh1)); hwavesum1 -> Fill (bin,float(VCh1)); hwave1 -> SetBinError (bin, 0.0002); if(bin>249&&bin<271){ if(VCh1>MaxInTheRange1)MaxInTheRange1=VCh1; if(VCh1Draw(); return; } float chargebg1 = hwave1->Integral(BINWIDTH+6,FIRSTBIN-1)+hwave1->Integral(FIRSTBIN+BINWIDTH+1,510); float chargesg1 = hwave1->Integral(FIRSTBIN,FIRSTBIN+BINWIDTH)-chargebg1 * NORM; float chargeBG1 = hwave1->Integral(5,BINWIDTH+5)-chargebg1 * NORM; BaseLine1 = chargebg1 * NORM / (BINWIDTH+1); if(fabs( MinInTheRange1 - BaseLine1) > fabs( MaxInTheRange1 - BaseLine1)) { cout << " Amp Ch1 is Min " << MinInTheRange1 - BaseLine1<Reset(); k_row++; ss=sFileRow; bin=0; do { bin++; ss >> VCh2; //std::cout << bin << " " << sFileRow << " / " << std::endl; //std::cout << k_row<<" " << bin << " " << VCh2 << std::endl; hwave2 -> SetBinContent(bin,float(VCh2)); hwavesum2 -> Fill (bin,float(VCh2)); hwave2 -> SetBinError (bin, 0.0002); if(bin>249&&bin<271){ if(VCh2>MaxInTheRange2)MaxInTheRange2=VCh2; if(VCh2Draw(); return; } float chargebg2 = hwave2->Integral(BINWIDTH+6,FIRSTBIN-1)+hwave2->Integral(FIRSTBIN+BINWIDTH+1,510); float chargesg2 = hwave2->Integral(FIRSTBIN,FIRSTBIN+BINWIDTH)-chargebg2 *NORM; float chargeBG2 = hwave2->Integral(5,BINWIDTH+5)-chargebg2 *NORM; BaseLine2 = chargebg2 * NORM / (BINWIDTH+1); if(fabs( MinInTheRange2 - BaseLine2) > fabs( MaxInTheRange2 - BaseLine2)) { cout << " Amp Ch2 is Min " << MinInTheRange2 - BaseLine2<Fill(); std::cout <<" -------------- "<Write(); RootFile->Write(); RootFile->Close(); }