Difference between revisions of "Annoted hodtest.C"

From HallCWiki
Jump to: navigation, search
(Annoted hodtest.C)
 
(No difference)

Latest revision as of 11:04, 21 August 2012

Below is a recent copy of the Hall C++ analyzer example driver script hodtest.C with explanations.

{
 
 //
 //  Steering script to test hodoscope decoding
 //

Set run number and filename here

 Int_t RunNumber=50017;
 char* RunFileNamePattern="daq04_%d.log.0";

Put run number in a THcParms (CTP like) variable for later use. Define the file that contains run number dependent parameter definitions (ENGINE database).

 gHcParms->Define("gen_run_number", "Run Number", RunNumber);
 gHcParms->AddString("g_ctp_database_filename", "DBASE/test.database");

Load parameters for the current run number.

 gHcParms->Load(gHcParms->GetString("g_ctp_database_filename"), RunNumber);
 

Load the parameters selected from the run number dependent database.

 // g_ctp_parm_filename and g_decode_map_filename should now be defined
 gHcParms->Load(gHcParms->GetString("g_ctp_parm_filename"));
 

Generate the Hall A style cratemap file (which slots are in use) from the ENGINE style map file. The db_cratemap.dat file is usually pretty static, but this insures that it is correct for the current run.

 // Generate db_cratemap to correspond to map file contents
 char command[100];
 sprintf(command,"./make_cratemap.pl < %s > db_cratemap.dat",gHcParms->GetString("g_decode_map_filename"));
 system(command);
 
 // Load the Hall C style detector map
 gHcDetectorMap=new THcDetectorMap();
 gHcDetectorMap->Load(gHcParms->GetString("g_decode_map_filename"));

Create the HMS spectrometer

 // Set up the equipment to be analyzed.
 THaApparatus* HMS = new THcHallCSpectrometer("H","HMS");
 gHaApps->Add( HMS );

Add the HMS detectors we want analyzed.

 // Add hodoscope
 HMS->AddDetector( new THcHodoscope("hod", "Hodoscope" ));
 HMS->AddDetector( new THcShower("Cal", "Shower" ));
 HMS->AddDetector( new THcDriftChamber("dc", "Drift Chambers" ));

THcAnalyzer contains the event loop. We will likely need our own event loop to take care of pedestal events properly and make sure that any special event types unique to Hall get handled properly.

 // Set up the analyzer - we use the standard one,
 // but this could be an experiment-specific one as well.
 // The Analyzer controls the reading of the data, executes
 // tests/cuts, loops over Acpparatus's and PhysicsModules,
 // and executes the output routines.
 THcAnalyzer* analyzer = new THcAnalyzer;
 
 // A simple event class to be output to the resulting tree.
 // Creating your own descendant of THaEvent is one way of
 // defining and controlling the output.
 THaEvent* event = new THaEvent;
 
 // Define the run(s) that we want to analyze.
 // We just set up one, but this could be many.
 char RunFileName[100];
 sprintf(RunFileName,RunFileNamePattern,RunNumber);
 THaRun* run = new THaRun(RunFileName);

It is OK to start analyzing from event 1 because the histogram definitions have a cut that selects only HMS event types.

 // Eventually need to learn to skip over, or properly analyze
 // the pedestal events
 run->SetEventRange(1,1000000);//  Physics Event number, does not
                               // include scaler or control events
 
 // Define the analysis parameters
 analyzer->SetEvent( event );
 analyzer->SetOutFile( "hodtest.root" );
 analyzer->SetOdefFile("output.def");
 //  analyzer->SetCutFile("cuts_example.def");        // optional
 
 // File to record cuts accounting information
 //  analyzer->SetSummaryFile("summary_example.log"); // optional
 
 analyzer->Process(run);     // start the actual analysis
}