void MainWindow::openFile() { int i; QString qstr; if(_filename.empty()) { qstr = QFileDialog::getOpenFileName(this,"Choose ROOT file","/","*.root"); _filename = qstr.toStdString(); } else { qstr = QFileDialog::getOpenFileName(this,"Choose ROOT file",QString::fromStdString(_filename),"*.root"); _filename = qstr.toStdString(); } if(_filename.empty()) { return; } setWindowTitle(QString::fromStdString("AmViewer (" + _filename + ")")); TFile *f = new TFile(_filename.c_str()); f->ReadAll(); TAmRun *amRun = NULL; amRun = AMBER::GetRunFromFile(f); // will use this as indicator for whether or not in 'analysis mode' in other parts of program _state->recon_tree = NULL; if(amRun == NULL) { // Means that this is a root file which contains candidate events. So we're in 'analysis mode' _analysisDrop->setEnabled(true); _saveMenu->setEnabled(true); _state->recon_tree = (TTree*)f->Get("recon_tree"); // cast might be superfluous _state->amevTree = (TAmEvTree*)f->Get("candidate_tree"); int totalEvents = _state->amevTree->GetEntries(); // clear tree widget _eventList->clear(); // create a dynamic array based on upper bound of number of runs QTreeWidgetItem *run_source[totalEvents]; // variables for putting events under the correct run number unsigned int prev_run = 0; int j = 0; QTreeWidgetItem *event; stringstream out,out2; string runtitle; for(i=0; i<totalEvents; i++) { // OK, SHIT. REMEMBER eventNum is the number according to the FILE **not** AMBER _state->eventNum = i; _state->update_recon(); if(_state->run_num == prev_run) { event = new QTreeWidgetItem(run_source[j-1]); out.str(""); out2.str(""); out << setprecision(8) << setw(8) << _state->event_num; out2 << i; event->setText(0,QString::fromStdString(out.str())); event->setText(1,QString::fromStdString(out2.str())); prev_run = _state->run_num; } else { run_source[j] = new QTreeWidgetItem(_eventList); out.str(""); out << setprecision(8) << setw(8) << _state->run_num; runtitle = "Run" + out.str(); run_source[j]->setText(0,QString::fromStdString(runtitle)); event = new QTreeWidgetItem(run_source[j]); out.str(""); out2.str(""); out << setprecision(8) << setw(8) << _state->event_num; out2 << i; event->setText(0,QString::fromStdString(out.str())); event->setText(1,QString::fromStdString(out2.str())); j++; prev_run = _state->run_num; } } _eventList->sortItems(0,Qt::AscendingOrder); //maybe check that 2nd arg _eventList->setColumnHidden(1,true); _eventList->setHeaderLabel("Candidate Events"); connect(_eventList,SIGNAL(itemClicked(QTreeWidgetItem*,int)),this,SLOT(getEvent(QTreeWidgetItem*))); // make an info window, if one doesn't exist if(_infoWindow==NULL) { _infoWindow = new InfoWindow(_state); } }
int main(int argc, char** argv) { // first read in AMBER calibrations ifstream calibfile("amcalibration.dat"); double amcalib[16][3]; for(int i=0; i<16; i++) { calibfile >> amcalib[i][0] >> amcalib[i][1] >> amcalib[i][2]; } calibfile.close(); TFile *f = new TFile(argv[1]); f->ReadAll(); TAmRun *amRun = NULL; amRun = AMBER::GetRunFromFile(f); //if(amRun == NULL) { //cout << "Incorrect filetype. Please select an AMBER candidate file as input." << endl; //return 1; //} TTree *recon_tree = (TTree*)f->Get("recon_tree"); TAmEvTree *amev_tree = (TAmEvTree*)f->Get("candidate_tree"); gFile = NULL; int total_events = amev_tree->GetEntries(); // stuff we're gonna need to grab AMBER events later in the loop TAmEvent *amev = new TAmEvent; amev_tree->SetBranchStatus("*",1); amev_tree->SetBranchAddress("event",&amev); // whole lotta crap relevant to the reconstruction tree double phi; double theta; double psi; double time; double entry_time; double exit_time; double entry_gcmsq; double exit_gcmsq; double los_dist; double impact_param; double ntanks; unsigned int run_num; unsigned int event_num; double time_delta; double offset[17]; double timecross[17]; double phimin, phimax; double thetamin, thetamax; double psimin, psimax; double timemin, timemax; double time_deltamin, time_deltamax; double entry_gcmsqmin, entry_gcmsqmax; double exit_gcmsqmin, exit_gcmsqmax; double los_distmin, los_distmax; double impact_parammin, impact_parammax; int ntanksmin, ntanksmax; double alt, northing, easting; double energy; double p_lo_C[17]; double gcmsq_entry_C[17]; double gcmsq_exit_C[17]; p_lo_C[0] = 0; recon_tree->SetBranchAddress("phi",&phi); recon_tree->SetBranchAddress("theta",&theta); recon_tree->SetBranchAddress("psi",&psi); recon_tree->SetBranchAddress("time",&time); recon_tree->SetBranchAddress("offsetC3",&offset[3]); recon_tree->SetBranchAddress("offsetC1",&offset[1]); recon_tree->SetBranchAddress("offsetC4",&offset[4]); recon_tree->SetBranchAddress("offsetC2",&offset[2]); recon_tree->SetBranchAddress("entry_time",&entry_time); recon_tree->SetBranchAddress("exit_time",&exit_time); recon_tree->SetBranchAddress("entry_gcmsq",&entry_gcmsq); recon_tree->SetBranchAddress("exit_gcmsq",&exit_gcmsq); recon_tree->SetBranchAddress("los_dist",&los_dist); recon_tree->SetBranchAddress("impact_param",&impact_param); recon_tree->SetBranchAddress("ntanks",&ntanks); recon_tree->SetBranchAddress("timecrossC3",&timecross[3]); recon_tree->SetBranchAddress("timecrossC1",&timecross[1]); recon_tree->SetBranchAddress("timecrossC4",&timecross[4]); recon_tree->SetBranchAddress("timecrossC2",&timecross[2]); recon_tree->SetBranchAddress("offsetC11",&offset[11]); recon_tree->SetBranchAddress("offsetC12",&offset[12]); recon_tree->SetBranchAddress("offsetC13",&offset[13]); recon_tree->SetBranchAddress("offsetC14",&offset[14]); recon_tree->SetBranchAddress("offsetC15",&offset[15]); recon_tree->SetBranchAddress("offsetC16",&offset[16]); recon_tree->SetBranchAddress("offsetC5",&offset[5]); recon_tree->SetBranchAddress("offsetC6",&offset[6]); recon_tree->SetBranchAddress("offsetC7",&offset[7]); recon_tree->SetBranchAddress("offsetC8",&offset[8]); recon_tree->SetBranchAddress("offsetC9",&offset[9]); recon_tree->SetBranchAddress("offsetC10",&offset[10]); recon_tree->SetBranchAddress("timecrossC11",&timecross[11]); recon_tree->SetBranchAddress("timecrossC12",&timecross[12]); recon_tree->SetBranchAddress("timecrossC13",&timecross[13]); recon_tree->SetBranchAddress("timecrossC14",&timecross[14]); recon_tree->SetBranchAddress("timecrossC15",&timecross[15]); recon_tree->SetBranchAddress("timecrossC16",&timecross[16]); recon_tree->SetBranchAddress("timecrossC5",&timecross[5]); recon_tree->SetBranchAddress("timecrossC6",&timecross[6]); recon_tree->SetBranchAddress("timecrossC7",&timecross[7]); recon_tree->SetBranchAddress("timecrossC8",&timecross[8]); recon_tree->SetBranchAddress("timecrossC9",&timecross[9]); recon_tree->SetBranchAddress("timecrossC10",&timecross[10]); recon_tree->SetBranchAddress("run_num",&run_num); recon_tree->SetBranchAddress("event_num",&event_num); recon_tree->SetBranchAddress("alt",&alt); recon_tree->SetBranchAddress("northing",&northing); recon_tree->SetBranchAddress("easting",&easting); recon_tree->SetBranchAddress("energy",&energy); recon_tree->SetBranchAddress("p_lo_C3",&p_lo_C[3]); recon_tree->SetBranchAddress("p_lo_C1",&p_lo_C[1]); recon_tree->SetBranchAddress("p_lo_C4",&p_lo_C[4]); recon_tree->SetBranchAddress("p_lo_C2",&p_lo_C[2]); recon_tree->SetBranchAddress("p_lo_C11",&p_lo_C[11]); recon_tree->SetBranchAddress("p_lo_C12",&p_lo_C[12]); recon_tree->SetBranchAddress("p_lo_C13",&p_lo_C[13]); recon_tree->SetBranchAddress("p_lo_C14",&p_lo_C[14]); recon_tree->SetBranchAddress("p_lo_C15",&p_lo_C[15]); recon_tree->SetBranchAddress("p_lo_C16",&p_lo_C[16]); recon_tree->SetBranchAddress("p_lo_C5",&p_lo_C[5]); recon_tree->SetBranchAddress("p_lo_C6",&p_lo_C[6]); recon_tree->SetBranchAddress("p_lo_C7",&p_lo_C[7]); recon_tree->SetBranchAddress("p_lo_C8",&p_lo_C[8]); recon_tree->SetBranchAddress("p_lo_C9",&p_lo_C[9]); recon_tree->SetBranchAddress("p_lo_C10",&p_lo_C[10]); recon_tree->SetBranchAddress("gcmsq_entry_C3",&gcmsq_entry_C[3]); recon_tree->SetBranchAddress("gcmsq_entry_C1",&gcmsq_entry_C[1]); recon_tree->SetBranchAddress("gcmsq_entry_C4",&gcmsq_entry_C[4]); recon_tree->SetBranchAddress("gcmsq_entry_C2",&gcmsq_entry_C[2]); recon_tree->SetBranchAddress("gcmsq_entry_C11",&gcmsq_entry_C[11]); recon_tree->SetBranchAddress("gcmsq_entry_C12",&gcmsq_entry_C[12]); recon_tree->SetBranchAddress("gcmsq_entry_C13",&gcmsq_entry_C[13]); recon_tree->SetBranchAddress("gcmsq_entry_C14",&gcmsq_entry_C[14]); recon_tree->SetBranchAddress("gcmsq_entry_C15",&gcmsq_entry_C[15]); recon_tree->SetBranchAddress("gcmsq_entry_C16",&gcmsq_entry_C[16]); recon_tree->SetBranchAddress("gcmsq_entry_C5",&gcmsq_entry_C[5]); recon_tree->SetBranchAddress("gcmsq_entry_C6",&gcmsq_entry_C[6]); recon_tree->SetBranchAddress("gcmsq_entry_C7",&gcmsq_entry_C[7]); recon_tree->SetBranchAddress("gcmsq_entry_C8",&gcmsq_entry_C[8]); recon_tree->SetBranchAddress("gcmsq_entry_C9",&gcmsq_entry_C[9]); recon_tree->SetBranchAddress("gcmsq_entry_C10",&gcmsq_entry_C[10]); recon_tree->SetBranchAddress("gcmsq_exit_C3",&gcmsq_exit_C[3]); recon_tree->SetBranchAddress("gcmsq_exit_C1",&gcmsq_exit_C[1]); recon_tree->SetBranchAddress("gcmsq_exit_C4",&gcmsq_exit_C[4]); recon_tree->SetBranchAddress("gcmsq_exit_C2",&gcmsq_exit_C[2]); recon_tree->SetBranchAddress("gcmsq_exit_C11",&gcmsq_exit_C[11]); recon_tree->SetBranchAddress("gcmsq_exit_C12",&gcmsq_exit_C[12]); recon_tree->SetBranchAddress("gcmsq_exit_C13",&gcmsq_exit_C[13]); recon_tree->SetBranchAddress("gcmsq_exit_C14",&gcmsq_exit_C[14]); recon_tree->SetBranchAddress("gcmsq_exit_C15",&gcmsq_exit_C[15]); recon_tree->SetBranchAddress("gcmsq_exit_C16",&gcmsq_exit_C[16]); recon_tree->SetBranchAddress("gcmsq_exit_C5",&gcmsq_exit_C[5]); recon_tree->SetBranchAddress("gcmsq_exit_C6",&gcmsq_exit_C[6]); recon_tree->SetBranchAddress("gcmsq_exit_C7",&gcmsq_exit_C[7]); recon_tree->SetBranchAddress("gcmsq_exit_C8",&gcmsq_exit_C[8]); recon_tree->SetBranchAddress("gcmsq_exit_C9",&gcmsq_exit_C[9]); recon_tree->SetBranchAddress("gcmsq_exit_C10",&gcmsq_exit_C[10]); // set up file output ofstream outfile; outfile.open("dataset.out", ios::out | ios::app); // now we start looping through the candidate file cout << "Total events in file: " << total_events << endl; for(int i = 0; i < total_events; i++) { cout << i << endl; amev_tree->GetEntry(i); recon_tree->GetEntry(i); for(int j = 1; j <= 16; j++) { //cout << i << " " << j << endl; if(timecross[j] != 0) { TH1F* h_raw = fetchChannelData(amev,j,amcalib); TH1F* h_filt = gaussianFilter(h_raw,timecross[j]); int size = h_raw->GetEntries(); double mu = estimateMu(h_filt,offset[j],p_lo_C[j],size); // this is the part where you dump to ascii outfile << mu << " " << p_lo_C[j] << " " << pow(10,0.1*p_lo_C[j])/1000 << " " << energy << " " << j << endl; // and then clean up delete h_raw; delete h_filt; } } } f->Close(); outfile.close(); return 0; }
// Function sets up and reads in data from the temperature files and AMBER housekeeping AmFitter::AmFitter(char* temps_name) { int horn_id; for(int i=0; i<N_HSK; i++) { _blacklist[i] = 0; } string tempnamestr(temps_name); if(tempnamestr == "C1H_temps.out") { horn_id = 0; } if(tempnamestr == "C2H_temps.out") { horn_id = 8; } if(tempnamestr == "C3H_temps.out") { horn_id = 16; } if(tempnamestr == "C4H_temps.out") { horn_id = 24; } if(tempnamestr == "C5_temps.out") { horn_id = 4; } if(tempnamestr == "C6_temps.out") { horn_id = 5; } if(tempnamestr == "C7_temps.out") { horn_id = 6; } if(tempnamestr == "C8_temps.out") { horn_id = 12; } if(tempnamestr == "C9_temps.out") { horn_id = 13; } if(tempnamestr == "C10_temps.out") { horn_id = 14; } if(tempnamestr == "C11_temps.out") { horn_id = 20; } if(tempnamestr == "C12_temps.out") { horn_id = 21; } if(tempnamestr == "C13_temps.out") { horn_id = 22; } if(tempnamestr == "C14_temps.out") { horn_id = 28; } if(tempnamestr == "C15_temps.out") { horn_id = 29; } if(tempnamestr == "C16_temps.out") { horn_id = 30; } cout << "horn id: " << horn_id << endl; // open temperature file, load into arrays and create interpolation ifstream temps_input(temps_name); double toss1,toss2,toss3,toss4; int i,j; for(i=0;i<1;i++) { temps_input >> toss1; //cout << toss1 << endl; for(j=0;j<215;j++) { temps_input >> time_arr[i][j] >> toss2 >> toss3 >> temp_arr[i][j] >> toss4; } } // set up interpolation for(i=0;i<1;i++) { _acc[i] = gsl_interp_accel_alloc(); _spline[i] = gsl_spline_alloc(gsl_interp_cspline,215); gsl_spline_init(_spline[i],time_arr[i],temp_arr[i],215); } // read in list of root files to use for fit string filename[N_HSK]; ifstream flist("rootfiles.list"); for(i=0;i<N_HSK;i++) { getline(flist,filename[i]); cout << filename[i] << endl; if(filename[i].find('#') != string::npos) { i--; cout << "Line ignored in list" << endl; } } // open AMBER housekeeping files, set histogram pointers for(i=0;i<N_HSK;i++) { TFile* f = new TFile(filename[i].c_str()); f->ReadAll(); TAmHskTree* amhsk = AMBER::GetHousekeepingFromFile(f); _amhsk_hist[i] = amhsk->GetPercentRfpRaw(0.0,100.0,(AMBER::eChannelId) horn_id); cout << setprecision(10) << "Starts at: " << _amhsk_hist[i]->GetXaxis()->GetBinCenter(1) << endl; // how many days is the offset from "orginal" day? int d_int; double day_diff = (_amhsk_hist[i]->GetXaxis()->GetBinCenter(1) - 1331618356/*_amhsk_hist[0]->GetXaxis()->GetBinCenter(1)*/)/86400; d_int = (int) (day_diff+0.5); //cout << day_diff << " " << d_int << " " << fabs(day_diff-d_int) << endl; if(i>=0) { if( fabs(day_diff-d_int) < 0.01 ) { _n_days[i] = d_int; } else { cout << "Error: " << filename[i] << ": Not an integer number of day offset from 'original' file" << endl; cout << "File is this many days off from last: "; cout << (_amhsk_hist[i]->GetXaxis()->GetBinCenter(1) - _amhsk_hist[i-1]->GetXaxis()->GetBinCenter(1))/86400 << endl; exit(EXIT_FAILURE); } } //else { //n_days[0] = 0; //} //cout << "I worked!" << endl; //delete f; f->Close(); } //for(int k=0; k<N_HSK; k++) { // cout << _n_days[k] << endl; //} }