{ #include #include #include #include #include #include std::cout << " This is the interactive version of script.C\n" << " Creates a root file, produces no eps's.\n" << " The root file created may be overwritten\n" << " by subsequent runs of the interactive analysis.\n" << " ***So save your root file with a different name.***\n"; // On the front end the TDC channels are numbered 1-16. // the ADC channels are numbered 0-11. // The same indexation is used in this script so the 0 // index is always skipped for TDC arrays. // Creates a directory with the run number that contains // all the produced files. // Produces a root file that has // + A Tree with all the tdc and adc information // of events that made it through parse.py // + Histograms of all possible channel differences // + Histogram of good events vs. tdc channel // Produces 3 eps files with plots. // + Ch11-Ch* // + Ch12-Ch* // + Good Events vs. tdc ch. // Produces a text file with channel statistics. (this one not yet.) gROOT->Reset(); gStyle->SetOptStat(1); gStyle->SetOptFit(0011); gStyle->SetCanvasColor(0); #include "Riostream.h" gBenchmark->Start("readtemp"); ////////////////////////////////////////////////////////// // CREATE ROOT FILE (interactive) // ////////////////////////////////////////////////////////// char run[100]; char rootfname[100]; {std::stringstream sstemp; ifstream nametmp; nametmp.open("nametmp"); nametmp >> run; printf("%s\n",run); std::cout << "\n Complete root file name (without the .root extension)\n"; std::cout << "\n " << run; string input; getline (cin,input); sstemp << "rootfiles/" << run << input << "_i.root"; sstemp >> rootfname;} // create a new ROOT file TFile *f = new TFile(rootfname,"RECREATE"); printf("\nCreated:\n%s\n",rootfname); ////////////////////////////////////////////////////////// // THE USER DEFINES THE SET OF CH'S // ////////////////////////////////////////////////////////// std::cout << "\n\n Select up to 4 channels. Don't select more\n" << " than the number required for a valid event.\n\n" << " This script will histogram all possible" << " differences in the selected set\n\n"; std::cout << " How many ch's do you want to histogram? "; int n_ch; cin >> n_ch; int chlist[17]={0}; {ifstream in; in.open("chlist"); int auxch; int ch_so_far=0; while (1 && ch_so_far!=n_ch){ in >> auxch; if (!in.good()) break; if( 1<=auxch<=16 ) { std::cout << "Keep CH" << auxch << "? (y/n)"; char keep; cin >> keep; if (keep=='y'||keep=='Y'){ chlist[auxch]=1; ch_so_far++;} else if(keep=='n'||keep=='N'){} // else {in.seekg(/offset/,ios::cur);} } }} ////////////////////////////////////////////////////////// // CREATE HISTOGRAMS // ////////////////////////////////////////////////////////// // create array of histograms for user def. time diff's. TH1I *h_ud[17][17]; // the histograms are customized (units are ps) {int rangeL = -110000; int rangeH = 110000; int binW = 25; std::cout << "Enter bin width : "; char inp[100]; cin >> inp; if ( atoi(inp) > 0 ){ binW = atoi( inp );} int bins = floor( (rangeH-rangeL)/binW ); for( Int_t i=1 ; i!=17; i++){ for( Int_t j=i+1; j!=17; j++){ if(chlist[i]!=0 && chlist[j]!=0){ char hist_name[100]; {std::stringstream sstemp; sstemp << "i_Ch" << i << "-Ch" << j; sstemp >> hist_name;} char hist_titl[100]; {std::stringstream sstemp; sstemp << "i_Ch" << i << "-Ch" << j << ";time(ps);"; sstemp >> hist_titl;} h_ud[i][j] = new TH1I(hist_name,hist_titl,bins,rangeL,rangeH); } }}} ////////////////////////////////////////////////////////// // READ EVENTS FROM FILE AND FILL HISTOGRAMS // ////////////////////////////////////////////////////////// float t[17]={-1}; float a[17]={-1}; int nevents = 0; ifstream in; in.open("temp"); while (1) { for(int i=1;i!=17;i++){ in >> t[i]; } for(int i=1;i!=17;i++){ in >> a[i-1]; } if (!in.good()) break; // fill user def time diff histograms for( Int_t i=1 ; i!=17; i++){ for( Int_t j=i+1; j!=17; j++){ if(chlist[i]!=0 && chlist[j]!=0){ if( t[i] > 0 && t[j] > 0 ){ (h_ud[i][j])->Fill( t[i]-t[j] );} } }} nevents++; } ////////////////////////////////////////////////////////// // CREATE CANVAS // ////////////////////////////////////////////////////////// // create canvas for user def time diff's { char canv_name[100]; {std::stringstream sstemp; sstemp << "User_Defined_diff's"; sstemp >> canv_name;} TCanvas *canvas_ud = new TCanvas(canv_name,canv_name,1000,1000); canvas_ud->Divide(3,2); } ////////////////////////////////////////////////////////// // DRAW AND PLOT TO EPS'S // ////////////////////////////////////////////////////////// for(int ii=1;ii!=17;ii++){printf("\n%d\n\n",chlist[ii]);} // draw gastof time diff histograms { int h_so_far=1; for( Int_t i=1 ; i!=17; i++){ for( Int_t j=i+1; j!=17; j++){ if(chlist[i]!=0 && chlist[j]!=0){ canvas_ud->cd(h_so_far); (h_ud[i][j])->Draw(); // canvas_ud->Update(); h_so_far++; } }} } printf("%d Events processed\n",nevents); f->Write(); f->Close(); printf(" %d Events",nevents); in.close(); gBenchmark->Show("readtemp"); }