示例#1
0
int main(int argc, char* argv[])
{

   TString filename("snippet.dat");

   ofstream *debugfile = 0;
#ifdef DEBUG
   debugfile = new ofstream;
   debugfile->open ("oodecoder1.txt");
   *debugfile << "Debug of OO decoder\n\n";
#endif

   THaCodaFile datafile(filename);
   THaEvData *evdata = new CodaDecoder();

   evdata->SetDebug(1);
   evdata->SetDebugFile(debugfile);

// Initialize root and output
  TROOT fadcana("fadcroot","Hall A FADC analysis, 1st version");
  TFile hfile("fadc.root","RECREATE","FADC data");

  h1 = new TH1F("h1","snapshot 1",1020,-5,505);
  h2 = new TH1F("h2","snapshot 2",1020,-5,505);
  h3 = new TH1F("h3","snapshot 3",1020,-5,505);
  h4 = new TH1F("h4","snapshot 4",1020,-5,505);
  h5 = new TH1F("h5","snapshot 5",1020,-5,505);
  hinteg = new TH1F("hinteg","Integral of ADC",1000,50000,120000);

  // Loop over events
  int NUMEVT=22;
  Int_t jnum=1;
  for (int iev=0; iev<NUMEVT; iev++) {
    int status = datafile.codaRead();
    if (status != S_SUCCESS) {
      if ( status == EOF) {
	if (debugfile) *debugfile << "Normal end of file.  Bye bye." << endl;
      } else {
	if (debugfile) *debugfile << hex << "ERROR: codaRread status = " << status << endl;
      }
      exit(1);
    } else {

      UInt_t *data = datafile.getEvBuffer();
      dump(data, debugfile);

      if (debugfile) *debugfile << "\nAbout to Load Event "<<endl;
      evdata->LoadEvent( data );
      if (debugfile) *debugfile << "\nFinished with Load Event "<<endl;

      if (evdata->GetEvType() == MYTYPE) {
	process (jnum, evdata, debugfile);
	jnum++;
      }

    }
  }

  hfile.Write();
  hfile.Close();


}
示例#2
0
int main(int argc, char* argv[])
{
  // Initialize the analysis clock
  clock_t t;
  t = clock();

  // Define the data file to be analyzed
  TString filename("snippet.dat");

  // Define the analysis debug output
  ofstream *debugfile = new ofstream;;
  debugfile->open ("tstfadc_main_debug.txt");
  
  // Initialize the CODA decoder
  THaCodaFile datafile(filename);
  THaEvData *evdata = new CodaDecoder();

  // Initialize the evdata debug output
  evdata->SetDebug(1);
  evdata->SetDebugFile(debugfile);

  // Initialize root and output
  TROOT fadcana("tstfadcroot", "Hall C analysis");
  hfile = new TFile("tstfadc.root", "RECREATE", "fadc module data");

  // Loop over events
  cout << "***************************************" << endl;
  cout << NUMEVENTS << " events will be processed" << endl;
  cout << "***************************************" << endl;
  uint32_t iievent = 1;
  //for(uint32_t ievent = 0; ievent < NUMEVENTS; ievent++) {
  for(uint32_t ievent = 0; ievent < iievent; ievent++) {
    // Read in data file
    int status = datafile.codaRead();
    if (status == S_SUCCESS) {
      UInt_t *data = datafile.getEvBuffer();
      evdata->LoadEvent(data);

      if (debugfile) *debugfile << "****************" << endl;
      if (debugfile) *debugfile << "Event Number = " << evdata->GetEvNum() << endl;
      if (debugfile) *debugfile << "****************\n" << endl;

      // Loop over slots
      for(uint32_t islot = SLOTMIN; islot < NUMSLOTS; islot++) {
      	//if (evdata->GetNumRaw(CRATE5, islot) != 0) {
	//if (evdata->GetNumRaw(CRATE10, islot) != 0) {
	if (evdata->GetNumRaw(CRATE12, islot) != 0) {
	  Fadc250Module *fadc = NULL;
	  //fadc = dynamic_cast <Fadc250Module*> (evdata->GetModule(CRATE5, islot));   // Bryan's setup
	  //fadc = dynamic_cast <Fadc250Module*> (evdata->GetModule(CRATE10, islot));  // Alex's setup
	  fadc = dynamic_cast <Fadc250Module*> (evdata->GetModule(CRATE12, islot));    // Mark's setup
	  if (fadc != NULL) {
	    //fadc->CheckDecoderStatus();
	    if (debugfile) *debugfile << "\n///////////////////////////////\n"
				      << "Results for crate " 
				      << fadc->GetCrate() << ", slot " 
				      << fadc->GetSlot() << endl;
				      
	    if (debugfile) *debugfile << hex << "fadc pointer = " << fadc << "\n" << dec 
				      << "///////////////////////////////\n" << endl;
	    
	    // Loop over channels
	    for (uint32_t chan = 0; chan < NADCCHAN; chan++) {
	      // Initilize variables
	      Int_t  fadc_mode, num_fadc_events, num_fadc_samples;
	      Bool_t raw_mode; 
	      fadc_mode = num_fadc_events = num_fadc_samples = raw_mode = 0;
	      // Acquire the FADC mode
	      fadc_mode = fadc->GetFadcMode(); fadc_mode_const = fadc_mode;
	      if (debugfile) *debugfile << "Channel " << chan << " is in FADC Mode " << fadc_mode << endl;
	      raw_mode  = ((fadc_mode == 1) || (fadc_mode == 8) || (fadc_mode == 10));
	      // Generate FADC plots
	      GeneratePlots(fadc_mode, islot, chan);

	      // Acquire the number of FADC events
	      num_fadc_events = fadc->GetNumFadcEvents(chan);
	      // If in raw mode, acquire the number of FADC samples
	      if (raw_mode) {
		num_fadc_samples = 0;
		num_fadc_samples = fadc->GetNumFadcSamples(chan, ievent);
	      }
	      if (num_fadc_events > 0) {
	      	for (Int_t jevent = 0; jevent < num_fadc_events; jevent++) {
		  // Debug output
		  if ((fadc_mode == 1 || fadc_mode == 8) && num_fadc_samples > 0) 
		    if (debugfile) *debugfile << "FADC EMULATED PI DATA = " << fadc->GetEmulatedPulseIntegralData(chan) << endl;
		  if (fadc_mode == 7 || fadc_mode == 8 || fadc_mode == 9 || fadc_mode == 10) {
		    if (fadc_mode != 8) {if (debugfile) *debugfile << "FADC PI DATA = " << fadc->GetPulseIntegralData(chan, jevent) << endl;}
		    if (debugfile) *debugfile << "FADC PT DATA = " << fadc->GetPulseTimeData(chan, jevent) << endl;
		    if (debugfile) *debugfile << "FADC PPED DATA = " << fadc->GetPulsePedestalData(chan, jevent) << endl;
		    if (debugfile) *debugfile << "FADC PPEAK DATA = " << fadc->GetPulsePeakData(chan, jevent) << endl;
		  }
		  // Fill histos
	      	  if ((fadc_mode == 1 || fadc_mode == 8) && num_fadc_samples > 0) h_pinteg[islot][chan]->Fill(fadc->GetEmulatedPulseIntegralData(chan));
		  else if (fadc_mode == 7 || fadc_mode == 8 || fadc_mode == 9 || fadc_mode == 10) {
		    if (fadc_mode != 8) {h_pinteg[islot][chan]->Fill(fadc->GetPulseIntegralData(chan, jevent));}
		    h_ptime[islot][chan]->Fill(fadc->GetPulseTimeData(chan, jevent));
		    h_pped[islot][chan]->Fill(fadc->GetPulsePedestalData(chan, jevent));
		    h_ppeak[islot][chan]->Fill(fadc->GetPulsePeakData(chan, jevent));
		  }
		  // Raw sample events
	      	  if (raw_mode && num_fadc_samples > 0) {
		    // Debug output
	      	    if (debugfile) *debugfile << "NUM FADC SAMPLES = " << num_fadc_samples << endl;
	      	    if (debugfile) *debugfile << "=============================" << endl;
		    // Populate raw sample plots
	      	    if (ievent < NUMRAWEVENTS) {
	      	      // Acquire the raw samples vector and populate graphs
	      	      raw_samples_vector[islot][chan] = fadc->GetPulseSamplesVector(chan);
	      	      for (Int_t sample_num = 0; sample_num < Int_t (raw_samples_vector[islot][chan].size()); sample_num++) 
	      	      	g_psamp_event[islot][chan][ievent]->SetPoint(sample_num, sample_num + 1, Int_t (raw_samples_vector[islot][chan][sample_num]));
	      	      mg_psamp[islot][chan]->Add(g_psamp_event[islot][chan][ievent], "ACP");
	      	    }  // NUMRAWEVENTS condition
	      	  }  // Raw mode condition
	      	}  //  FADC event loop
	      }  // Number of FADC events condition
	    }  //FADC channel loop
	  }  // FADC module found condition
	  else 
	    if (debugfile) *debugfile << "FADC MODULE NOT FOUND!!!" << endl;
	}  // Number raw words condition
      }  // Slot loop
    }  // CODA file read status condition
    if (iievent % 1000 == 0)
      //if (iievent % 1 == 0)
      cout << iievent << " events have been processed" << endl;
    iievent++;
    if (status == EOF) break;
  }  // Event loop 

  // Populate waveform graphs and multigraphs and write to root file
  TRandom3 *rand = new TRandom3();
  for(uint32_t islot = 3; islot < NUMSLOTS; islot++) {
    for (uint32_t chan = 0; chan < NADCCHAN; chan++) {
      for( uint32_t ievent = 0; ievent < NUMRAWEVENTS; ievent++) {
	// Raw sample plots
	if (g_psamp_event[islot][chan][ievent] != NULL) {
	  UInt_t rand_int = 1 + rand->Integer(9);
	  hfile->cd(Form("/mode_%d_data/slot_%d/chan_%d/raw_samples", fadc_mode_const, islot, chan));
	  c_psamp[islot][chan]->cd(ievent + 1);
	  g_psamp_event[islot][chan][ievent]->Draw("ACP");
	  g_psamp_event[islot][chan][ievent]->SetTitle(Form("FADC Mode %d Pulse Peak Data Slot %d Channel %d Event %d", fadc_mode_const, islot, chan, ievent));
	  g_psamp_event[islot][chan][ievent]->GetXaxis()->SetTitle("Sample Number");
	  g_psamp_event[islot][chan][ievent]->GetYaxis()->SetTitle("Sample Value");
	  g_psamp_event[islot][chan][ievent]->SetLineColor(rand_int);
	  g_psamp_event[islot][chan][ievent]->SetMarkerColor(rand_int);
	  g_psamp_event[islot][chan][ievent]->SetMarkerStyle(20);
	  g_psamp_event[islot][chan][ievent]->SetDrawOption("ACP");
	}  // Graph condition
      }  // Raw event loop
      // Write the canvas to file
      if (c_psamp[islot][chan] != NULL) c_psamp[islot][chan]->Write();
      // Write the multigraphs to file
      if (mg_psamp[islot][chan] != NULL) {
        hfile->cd(Form("/mode_%d_data/slot_%d/chan_%d", fadc_mode_const, islot, chan));
        mg_psamp[islot][chan]->Draw("ACP");
        //mg_psamp[islot][chan]->SetTitle(Form("%d Raw Events of FADC Mode %d Pulse Peak Data Slot %d Channel %d", NUMRAWEVENTS, fadc_mode_const, islot, chan));
        //mg_psamp[islot][chan]->GetXaxis()->SetTitle("Sample Number");
        //mg_psamp[islot][chan]->GetYaxis()->SetTitle("Sample Value");
        mg_psamp[islot][chan]->Write(); 
      }  // Mulitgraph condition
    }  // Channel loop
  }  // Slot loop

  cout << "***************************************" << endl;
  cout << iievent - 1 << " events were processed" << endl;
  cout << "***************************************" << endl;
  
  // Write and clode the data file
  hfile->Write();
  hfile->Close();

  // Calculate the analysis rate
  t = clock() - t;
  printf ("The analysis took %.1f seconds \n", ((float) t) / CLOCKS_PER_SEC);
  printf ("The analysis event rate is %.1f Hz \n", (iievent - 1) / (((float) t) / CLOCKS_PER_SEC));

}  // main()