//_____________________________________________________________________________
void THaDetector::MakePrefix()
{
  // Set up name prefix for global variables. Internal function called 
  // during initialization.

  const char* basename = NULL;
  THaApparatus *app = GetApparatus();
  if( app )
    basename = app->GetName();
  THaDetectorBase::MakePrefix( basename );

}
Beispiel #2
0
void replay(Int_t runnumber=0,Int_t all=0,sReplaySetUp ReplaySetUp=DefaultReplay)
{
    //general replay script
    //for detector or physics replay, please use replay_det or physics reply 

    Int_t ReplayMode=ReplaySetUp.ReplayMode;
    char* OutFileFormat=ReplaySetUp.OutFileFormat;
    Int_t DefReplayNum=ReplaySetUp.DefReplayNum;

    cout<<"replay: Init analyzer ..."<<endl;
    THaAnalyzer* analyzer = THaAnalyzer::GetInstance();
    if( analyzer ) {
        analyzer->Close();
    } else {
        analyzer = new THaAnalyzer;
    }


    // step 1: add detectors
    THaBigBite* pB=0;
    if (ReplayMode&(kReplayBigBiteTp+kReplayBigBiteMWDC+kReplayBigBiteOther))
    {
        cout<<"replay: Adding BigBite ..."<<endl;
        pB=new THaBigBite("BB","BigBite"); 
        gHaApps->Add(pB);
    }

    if ((ReplayMode&kReplayPhysics)&&(ReplayMode&kReplayBigBiteMWDC)){
        cout<<"replay: Adding BigBite Golden Track ..."<<endl;
        gHaPhysics->Add( new THaGoldenTrack(
            "BB.gold",
            "Golden (First) track for BigBite", 
            "BB"));
    }

    if (ReplayMode&(kReplayBigBiteTp))
        pB->AddDetector(new THaTriggerPlane("tp","Trigger Plane",pB));

    if (ReplayMode&(kReplayBigBiteMWDC))
        pB->AddDetector(new TreeSearch::MWDC("mwdc","MWDC",pB));

    if (ReplayMode&(kReplayBigBiteOther))
        pB->MountOptics(new THaOpticsAnalytical("optics","BigBite Optics Child Class",pB,"B"));

    /*if (ReplayMode&(kReplayBeam))
    {
    cout<<"replay: Adding Beam ..."<<endl;

    THaApparatus* B = new THaIdealBeam("B","Idea Beam, for Test Only");
    gHaApps->Add( B );

    }*/

    if (ReplayMode&(kReplayDecData))
    {
        cout<<"replay: Adding Decoder Data ..."<<endl;
        gHaApps->Add(new THaDecData("DL","Misc. Decoder Data"));
    }   

    if (ReplayMode&(kReplayHRSL))
    {
        THaApparatus* B = new THaIdealBeam("B","Idea Beam, for Test Only");
        gHaApps->Add( B );

        cout<<"replay: Adding L-arm Helicity"<< endl;
        B->AddDetector( new THaADCHelicity("adchel.L","Beam helicity L-arm") );
        B->AddDetector( new THaADCHelicity("adchel2.L","Beam helicity-2 L-arm") );
        //B->AddDetector( new THaG0Helicity("g0hel.L","Left arm G0 helicity") );	

        cout<<"replay: Adding UnRastered and Rastered Beam ..."<<endl;
        gHaApps->Add(new THaUnRasteredBeam("urb","Unrastered beam"));
        gHaApps->Add(new THaRasteredBeam("rb","Rastered Beam"));

        cout<<"replay: Adding Decoder Data ..."<<endl;
        gHaApps->Add(new THaDecData("DL","Misc. Decoder Data"));

        cout<<"replay: Adding HRS-L ..."<<endl;
        THaApparatus* HRSL = new THaHRS("L","Left HRS");
        gHaApps->Add( HRSL );

        // add detectors that are not in the default config
        HRSL->AddDetector( new THaCherenkov("cer", "Gas Cherenkov counter" ));
        HRSL->AddDetector( new THaShower("prl1", "Pre-shower pion rej." ));
        HRSL->AddDetector( new THaShower("prl2", "Show pion rej." ));

        cout<<"replay: adding Physics modules ..."<<endl;

        gHaPhysics->Add( new THaGoldenTrack("L.gold","Golden track for LHRS", "L") );

        THaPhysicsModule *Rpt_l = new THaReactionPoint(
            "ReactPt_L","Reaction vertex for Left","L","B");
        gHaPhysics->Add( Rpt_l );

        // Correct for using an Extended target
        // This needs information about the Point of interaction (hence a THaVertexModule)
        THaPhysicsModule* TgC_l = new THaExtTarCor("ExTgtCor_L",
            "Corrected for extended target, HRS-L",
            "L","ReactPt_L");
        gHaPhysics->Add( TgC_l );

        // add scalers
        THaScalerGroup* LeftScalers = new THaScalerGroup("Left");
        gHaScalers->Add(LeftScalers);
        // Enable scalers
        analyzer->EnableScalers();

    }

    if (ReplayMode&(kReplayHRSR))
    {
        THaApparatus* B = new THaIdealBeam("B","Idea Beam, for Test Only");
        gHaApps->Add( B );

        cout<<"replay: Adding R-arm Helicity"<< endl;
        B->AddDetector(new THaADCHelicity("adchel.R","Beam helicity R-arm"));
        //B->AddDetector( new THaG0Helicity("g0hel.R","Right arm G0 helicity") );

        cout<<"replay: Adding UnRastered and Rastered Beam ..."<<endl;
        gHaApps->Add(new THaUnRasteredBeam("Rurb","Unrastered beam"));
        gHaApps->Add(new THaRasteredBeam("Rrb","Rastered Beam"));

        cout<<"replay: Adding Decoder Data ..."<<endl;
        gHaApps->Add(new THaDecData("D","Misc. Decoder Data"));
        cout<<"replay: Adding HRS-R ..."<<endl;
        THaApparatus* HRSR = new THaHRS("R","Right HRS");
        gHaApps->Add( HRSR );

        // add detectors that are not in the default config
        HRSR->AddDetector( new THaCherenkov("cer", "Gas Cherenkov counter" ));
        HRSR->AddDetector( new THaShower("ps", "Pre-shower" ));
        HRSR->AddDetector( new THaShower("sh", "Shower" ));

        cout<<"replay: adding Physics modules ..."<<endl;

        gHaPhysics->Add( new THaGoldenTrack("R.gold","Golden track for RHRS", "R") );

        THaPhysicsModule *Rpt_r = new THaReactionPoint(
            "ReactPt_R","Reaction vertex for Left","R","B");
        gHaPhysics->Add( Rpt_r );

        // Correct for using an Extended target
        // This needs information about the Point of interaction 
        //(hence a THaVertexModule)
        THaPhysicsModule* TgC_r = new THaExtTarCor("ExTgtCor_R",
            "Corrected for extended target, HRS-R",
            "R","ReactPt_R");
        gHaPhysics->Add( TgC_r );

        // add scalers
        THaScalerGroup* RightScalers = new THaScalerGroup("Right");
        gHaScalers->Add(RightScalers);
        // Enable scalers
        analyzer->EnableScalers();
    }

    //Step 1.5: load Physics modules
    if (ReplayMode&(kReplayPhysics))
    {

        //The CORRECTED Electron kinematics
        THaPrimaryKine *PriKine=new THaPrimaryKine(
            "PriKine","kinematics of scattering of the primary (beam) particle",
            "ExTgtCor_L","B",.938272029);
        gHaPhysics->Add(PriKine);

        if (ReplayMode&(kReplayBigBiteTp+kReplayBigBiteMWDC+kReplayBigBiteOther)){
            THaSecondaryKine *SecKine=new THaSecondaryKine(
                "SecKine","kinematics of scattering of the primary (beam) particle",
                "BB","PriKine",.938272029);
            gHaPhysics->Add(SecKine);
        }

    }

    if (ReplayMode&(kReplayPhysicsHRSR))
    {
        //The CORRECTED Electron kinematics
        THaPrimaryKine *PriKine_r=new THaPrimaryKine(
            "PriKine_r","kinematics of scattering of the primary (beam) particle",
            "ExTgtCor_R","B",.938272029);
        gHaPhysics->Add(PriKine_r);

        //THaSecondaryKine *SecKine_r=new THaSecondaryKine(
        //    "SecKine_r","kinematics of scattering of the primary (beam) particle",
        //    "R","PriKine_r",.938272029);
        //gHaPhysics->Add(SecKine_r);

    }


    // step 2: setup run information

    int nrun, nev;
    int found = 0;
    const char** path = 0;
    char filename[300],buf[300];  
    FILE *fd;

    while( found==0 ) {
        if (runnumber<=0)
        {
            cout << "\nreplay: Please enter a Run Number (-1 to exit):";
            cin >> nrun;
            fgets(buf,300,stdin);//get the extra '\n' from stdin
            if( nrun<=0 ) break;
        }
        else 
Beispiel #3
0
void replay_asym(Int_t runnumber=0,Int_t all=0,Int_t fstEvt=0,Bool_t QuietRun = kTRUE)
{


  ////////////////////////////////////////
  //   Beams
  ////////////////////////////////////////

  cout<<"replay: Adding Idea Beam"<< endl;

  THaApparatus* B = new THaIdealBeam("B","Idea Beam, for Test Only");
  gHaApps->Add( B );
  
  cout<<"replay: Adding L-arm Helicity"<< endl;
  B->AddDetector( new THaADCHelicity("adchel.L","Beam helicity L-arm") );
  B->AddDetector( new THaADCHelicity("adchel2.L","Beam helicity-2 L-arm") );
  B->AddDetector( new THaG0Helicity("g0hel.L","Left arm G0 helicity") );	
    cout<<"replay: Adding UnRastered and Rastered Beam ..."<<endl;
  gHaApps->Add(new THaUnRasteredBeam("urb","Unrastered beam"));
//   gHaApps->Add(new THaRasteredBeam("rb","Rastered Beam"));
  
  

  ////////////////////////////////////////
  //   LHRS
  ////////////////////////////////////////

  cout<<"replay: Adding HRS-L ..."<<endl;
  THaApparatus* HRSL = new THaHRS("L","Left HRS");
  gHaApps->Add( HRSL );
  
  // add L detectors that are not in the default config
  HRSL->AddDetector( new THaCherenkov("cer", "Gas Cherenkov counter" ));
  HRSL->AddDetector( new THaCherenkov("a1", "A1 Cherenkov counter" ));
  HRSL->AddDetector( new THaShower("prl1", "Pre-shower pion rej." ));
  HRSL->AddDetector( new THaShower("prl2", "Show pion rej." ));

  //cout<<"replay: adding RICH detector ..."<<endl;
  //HRSL->AddDetector( new THaRICH("rich","The RICH")); 
  

  cout<<"replay: adding LHRS track modules ..."<<endl;

  THaPhysicsModule *Rpt_l = new THaReactionPoint("ReactPt_L","Reaction vertex for Left","L","B");
  gHaPhysics->Add( Rpt_l );

  // Correct for using an Extended target
  // This needs information about the Point of interaction (hence a THaVertexModule)
  THaPhysicsModule* TgC_l = new THaExtTarCor("ExTgtCor_L","Corrected for extended target, HRS-L","L","ReactPt_L");
  gHaPhysics->Add( TgC_l );

  ////////////////////////////////////////
  //   Bigbite
  ////////////////////////////////////////

  cout<<"replay: adding BigBite ..."<<endl;
  //Add BigBite 
  THaBigBite* pB=new THaBigBite("BB","BigBite"); 
  gHaApps->Add(pB);
  //THaBBTotalShower* ts=new THaBBTotalShower("ts","BigBite total shower");
  //pB->AddDetector(ts);
  pB->AddDetector(new TreeSearch::MWDC("mwdc","MWDC",pB));
  pB->AddDetector( new THaScintPlaneDet( "s", "BB Scintillator",pB ));
  pB->AddDetector( new THaScintPlaneDet( "sum", "BB Total sum",pB));
  pB->AddDetector( new THaScintPlaneDet( "psum", "BB Preshower sum",pB));
  pB->AddDetector( new THaBBTotalShower( "ts", "BB Total shower",pB));

  cout<<"replay: adding LHRS track modules ..."<<endl;
  pB->MountOptics(new THaOpticsE06010("optics","BigBite Optics Child Class",pB,"urb"));


  ////////////////////////////////////////
  //   Physics
  ////////////////////////////////////////

  cout<<"replay: adding Physics modules ..."<<endl;
  THaPrimaryKine *PriKine=new THaPrimaryKine("PriKine","kinematics of scattering of electron to BB","BB","urb",.939565);
  gHaPhysics->Add(PriKine);

  THaSecondaryKine *SecKinePion=new THaSecondaryKine(
                "SecKinePion","secondary kinematics of scattering pi into HRS",
                "ExTgtCor_L","PriKine", .13957018);
  gHaPhysics->Add(SecKinePion);

  
  ////////////////////////////////////////
  //   Other Modules
  ////////////////////////////////////////

  
  cout<<"replay: Adding Target ..."<<endl;
  THaHe3Target* pT=new THaHe3Target("he3","Hall A Polarized he3 target");
  gHaApps->Add(pT);
  THaSecondaryKine *SecKineHe3=new THaSecondaryKine(
		  "SecKineHe3","Calculate angles of polarized he3 VS electron scattering",
	"he3","PriKine", 0);
  gHaPhysics->Add(SecKineHe3);

  cout<<"replay: Adding Decoder Data ..."<<endl;
  gHaApps->Add(new THaDecData("DL","Misc. Decoder Data"));

  
  
  ////////////////////////////////////////
  //   Scalars
  ////////////////////////////////////////
  // add scalers
  
  gHaScalers->Add(new THaScalerGroup("Left"));
  gHaScalers->Add(new THaScalerGroup("bbite"));
  gHaScalers->Add(new THaScalerGroup("evLeft"));
  gHaScalers->Add(new THaScalerGroup("evbbite"));

  ////////////////////////////////////////
  //   BB Norm Ana
  ////////////////////////////////////////
  char buff[1000]="";
  sprintf(buff,"./summaryfiles/NormAna%d.log",runnumber);
  
  cout<<"replay: Adding BBNormAna & saving result to "<<buff<<endl;
  BBNormAna* norm = new BBNormAna("N","Normalization Analysis",buff,8); 
  gHaPhysics->Add(norm);
  
  ////////////////////////////////////////
  //   Do replay
  ////////////////////////////////////////
  THaAnalyzer* analyzer = THaAnalyzer::GetInstance();
  if( !analyzer ) {
  analyzer = new THaAnalyzer;
  }
  analyzer->EnableBenchmarks();
  analyzer->EnableHelicity();
  analyzer->EnableScalers();
  //analyzer->EnableSlowControl();
  analyzer->SetMarkInterval(20000);

  
  ReplayCore(
	    runnumber,            //run #
	    all,                  //-1=replay all;0=ask for a number
	    -1,                   //defaut replay event num
	    "%s/e06010_asym_%d.root", //output file format
	    "replay_asym.odef",    	//out define
	    "replay_asym.cdef",    	//empty cut define
	    kTRUE,                 	//replay scalar?
	    fstEvt,					//First Event To Replay
		QuietRun				//whether ask user for inputs
	    );
  analyzer->SetMarkInterval(1000);

}
Beispiel #4
0
void compare_dc(Int_t RunNumber=52949, Int_t FirstToReplay=1, Int_t MaxEventToReplay=11000) {

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

    //Int_t RunNumber=52949;
    char* RunFileNamePattern="/cache/mss/hallc/daq04/raw/daq04_%d.log.0";
    gHcParms->Define("gen_run_number", "Run Number", RunNumber);
    gHcParms->AddString("g_ctp_database_filename", "jan05.database");

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

    // g_ctp_parm_filename and g_decode_map_filename should now be defined

    gHcParms->Load(gHcParms->GetString("g_ctp_kinematics_filename"), RunNumber);
    gHcParms->Load(gHcParms->GetString("g_ctp_parm_filename"));
    gHcParms->Load("hcana.param");

    // Constants not in ENGINE PARAM files that we want to be
    // configurable
    //gHcParms->Load(Form("PARAM/%05d/general.param",RunNumber));

    // 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"));

    // Set up the equipment to be analyzed.

    THaApparatus* HMS = new THcHallCSpectrometer("H","HMS");
    gHaApps->Add( HMS );

    // Add hodoscope
    HMS->AddDetector( new THcHodoscope("hod", "Hodoscope" ));
    HMS->AddDetector( new THcShower("cal", "Shower" ));
    HMS->AddDetector( new THcDC("dc", "Drift Chambers" ));
    THcAerogel* aerogel = new THcAerogel("aero", "Aerogel Cerenkov" );
    HMS->AddDetector( aerogel );

    // setup physics
    gHaPhysics->Add( new THaGoldenTrack( "H.gold", "HMS Golden Track", "H" ));
    // 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.


    // 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.
    THaAnalyzer* 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);

    // Eventually need to learn to skip over, or properly analyze
    // the pedestal events
    run->SetEventRange(FirstToReplay,MaxEventToReplay);//  Physics Event number, does not
    // include scaler or control events

    // Define the analysis parameters
    analyzer->SetCountMode( 2 ); // 0 = counter is # of physics triggers
    //1 = counter is # of all decode reads
    //2= counter is event number
    analyzer->SetEvent( event );
    analyzer->SetOutFile(Form("Rootfiles/compare_dc_%05d.root",RunNumber));
    analyzer->SetOdefFile("output_dc.def");
    analyzer->SetCutFile("cuts_dc.def");        // optional

    // File to record cuts accounting information
    //  analyzer->SetSummaryFile("summary_example.log"); // optional

    analyzer->Process(run);     // start the actual analysis
}
Beispiel #5
0
void replay_phys(Int_t runnumber=0,Int_t all=0,Int_t fstEvt=0,Bool_t QuietRun = kTRUE)
{


  ////////////////////////////////////////
  //   Beams
  ////////////////////////////////////////

  cout<<"replay: Adding Idea Beam"<< endl;

  THaApparatus* B = new THaIdealBeam("B","Idea Beam, for Test Only");
  gHaApps->Add( B );
  
  cout<<"replay: Adding L-arm Helicity"<< endl;
  B->AddDetector( new THaADCHelicity("adchel.L","Beam helicity L-arm") );
  B->AddDetector( new THaADCHelicity("adchel2.L","Beam helicity-2 L-arm") );
  B->AddDetector( new THaG0Helicity("g0hel.L","Left arm G0 helicity") );	
    cout<<"replay: Adding UnRastered and Rastered Beam ..."<<endl;
  gHaApps->Add(new THaUnRasteredBeam("urb","Unrastered beam"));
  gHaApps->Add(new THaRasteredBeam("rb","Rastered Beam"));
  
  ////////////////////////////////////////
  //   LHRS
  ////////////////////////////////////////

  cout<<"replay: Adding HRS-L ..."<<endl;
  THaApparatus* HRSL = new THaHRS("L","Left HRS");
  gHaApps->Add( HRSL );
  
  // add L detectors that are not in the default config
  HRSL->AddDetector( new THaCherenkov("cer", "Gas Cherenkov counter" ));
//  HRSL->AddDetector( new THaCherenkov("a1", "A1 Cherenkov counter" ));
  HRSL->AddDetector( new THaShower("prl1", "Pre-shower pion rej." ));
  HRSL->AddDetector( new THaShower("prl2", "Show pion rej." ));

  //cout<<"replay: adding RICH detector ..."<<endl;
  //HRSL->AddDetector( new THaRICH("rich","The RICH")); 
  
  cout<<"replay: adding LHRS track modules ..."<<endl;
  gHaPhysics->Add( new THaGoldenTrack("L.gold","Golden track for LHRS", "L") );

  THaPhysicsModule *Rpt_l = new THaReactionPoint("ReactPt_L","Reaction vertex for Left","L","B");
  gHaPhysics->Add( Rpt_l );

  // Correct for using an Extended target
  // This needs information about the Point of interaction (hence a THaVertexModule)
  THaPhysicsModule* TgC_l = new THaExtTarCor("ExTgtCor_L","Corrected for extended target, HRS-L","L","ReactPt_L");
  gHaPhysics->Add( TgC_l );

  ////////////////////////////////////////
  //   Bigbite
  ////////////////////////////////////////

  cout<<"replay: adding BigBite ..."<<endl;
  //Add BigBite 
  THaBigBite* pB=new THaBigBite("BB","BigBite"); 
  gHaApps->Add(pB);
  //THaBBTotalShower* ts=new THaBBTotalShower("ts","BigBite total shower");
  //pB->AddDetector(ts);
  pB->AddDetector(new TreeSearch::MWDC("mwdc","MWDC",pB));
  pB->AddDetector( new THaScintPlaneDet( "s", "BB Scintillator",pB ));
  pB->AddDetector( new THaScintPlaneDet( "sum", "BB Total sum",pB));
  pB->AddDetector( new THaScintPlaneDet( "psum", "BB Preshower sum",pB));
  pB->AddDetector( new THaBBTotalShower( "ts", "BB Total shower",pB));

  cout<<"replay: adding LHRS track modules ..."<<endl;
  pB->MountOptics(new THaOpticsE06010("optics","BigBite Optics Child Class",pB,"urb"));
  gHaPhysics->Add( new THaGoldenTrack("BB.gold","Golden track for Bigbite", "BB") );

  ////////////////////////////////////////
  //   Other Modules
  ////////////////////////////////////////

  cout<<"replay: Adding Target ..."<<endl;
  THaHe3Target* pT=new THaHe3Target("he3","Hall A Polarized he3 target");
  gHaApps->Add(pT);

  cout<<"replay: Adding Decoder Data ..."<<endl;
  gHaApps->Add(new THaDecData("DL","Misc. Decoder Data"));

  cout<<"replay: Adding A Quick Hack Code to Extract t3[0] ..."<<endl;
  THaApparatus* DL1 = new THaIdealBeam("DL1","Base Apparatus for extract t3[0]");
  gHaApps->Add( DL1 );
  DL1->AddDetector(new THaADCHe3Spin("t3","copy of DL.t3[0], for .odef file",DL1));

  ////////////////////////////////////////
  //   Physics
  ////////////////////////////////////////

  cout<<"replay: adding Physics modules ..."<<endl;
  THaPrimaryKine *PriKine=new THaPrimaryKine("PriKine","kinematics of scattering of electron to BB","BB","urb",.939565);
  gHaPhysics->Add(PriKine);

  THaSecondaryKine *SecKinePion=new THaSecondaryKine(
                "SecKinePion","secondary kinematics of scattering pi into HRS",
                "ExTgtCor_L","PriKine", .13957018);
  gHaPhysics->Add(SecKinePion);

  //////////////////////////////////////////////
  //Do we need the physics of scattering Kaons?
  //////////////////////////////////////////////

  THaSecondaryKine *SecKineKaon=new THaSecondaryKine(
                "SecKineKaon","kinematics of scattering K into HRS",
                "ExTgtCor_L","PriKine", .493667);
  gHaPhysics->Add(SecKineKaon);
  
  
  ////////////////////////////////////////
  //   Scalars
  ////////////////////////////////////////
  // add scalers
  
  gHaScalers->Add(new THaScalerGroup("Left"));
  gHaScalers->Add(new THaScalerGroup("bbite"));
  gHaScalers->Add(new THaScalerGroup("evLeft"));
  gHaScalers->Add(new THaScalerGroup("evbbite"));

  ////////////////////////////////////////
  //   Do replay
  ////////////////////////////////////////

  
  ReplayCore(
	    runnumber,            //run #
	    all,                  //-1=replay all;0=ask for a number
	    100000,                   //defaut replay event num
	    "%s/e06014_phys_%d.root", //output file format
	    "replay_phys.odef",    	//out define
	    "replay_test.cdef",    	//empty cut define
	    kTRUE,                 	//replay scalar?
	    fstEvt,					//First Event To Replay
		QuietRun				//whether ask user for inputs
	    );

}
void replay_farm_L(Int_t runnumber=0,Int_t filesuffix=0,Int_t all=0,Int_t fstEvt=0,Bool_t QuietRun = kTRUE)
{

  THaApparatus* B = new THaIdealBeam("B","Idea Beam, for Test Only");
  gHaApps->Add( B );
  
  cout<<"replay: Adding L-arm Helicity"<< endl;
  B->AddDetector( new THaADCHelicity("adchel.L","Beam helicity L-arm") );
  B->AddDetector( new THaADCHelicity("adchel2.L","Beam helicity-2 L-arm") );
  B->AddDetector( new THaG0Helicity("g0hel.L","Left arm G0 helicity") );	
  
  cout<<"replay: Adding UnRastered and Rastered Beam ..."<<endl;
  gHaApps->Add(new THaUnRasteredBeam("urb","Unrastered beam"));
  gHaApps->Add(new THaRasteredBeam("rb","Rastered Beam"));
  
  cout<<"replay: Adding Decoder Data ..."<<endl;
  gHaApps->Add(new THaDecData("DL","Misc. Decoder Data"));
  
  cout<<"replay: Adding HRS-L ..."<<endl;
  THaApparatus* HRSL = new THaHRS("L","Left HRS");
  gHaApps->Add( HRSL );
  
  // add detectors that are not in the default config
  HRSL->AddDetector( new THaCherenkov("cer", "Gas Cherenkov counter" ));
//  HRSL->AddDetector( new THaCherenkov("a1", "A1 Cherenkov counter" ));
  HRSL->AddDetector( new THaShower("prl1", "Pre-shower pion rej." ));
  HRSL->AddDetector( new THaShower("prl2", "Show pion rej." ));

/*  cout<<"replay: adding RICH detector ..."<<endl;
  HRSL->AddDetector( new THaRICH("rich","The RICH")); 
*/  
  cout<<"replay: adding Physics modules ..."<<endl;
  
  gHaPhysics->Add( new THaGoldenTrack("L.gold","Golden track for LHRS", "L") );
  
  THaPhysicsModule *Rpt_l = new THaReactionPoint(
						 "ReactPt_L","Reaction vertex for Left","L","B");
  gHaPhysics->Add( Rpt_l );
  
  // Correct for using an Extended target
  // This needs information about the Point of interaction (hence a THaVertexModule)
  THaPhysicsModule* TgC_l = new THaExtTarCor("ExTgtCor_L",
					     "Corrected for extended target, HRS-L",
					     "L","ReactPt_L");
  gHaPhysics->Add( TgC_l );
  
  // add scalers
  THaScalerGroup* LeftScalers = new THaScalerGroup("Left");
  gHaScalers->Add(LeftScalers);
  
  FarmReplayCore(
	    runnumber,            //run #
		filesuffix,			  // suffix of data file (e.g. 0 for #.dat.0)
	    all,                  //-1=replay all;0=ask for a number
	    200000,                   //defaut replay event num
	    "%s/e06014_det_L_%d.root", //output file format
	    "replay_det_L.odef",	//out define
	    "replay_det_L.cdef", 	//empty cut define
	    kTRUE,                 	//replay scalar?
	    fstEvt,					//First Event To Replay
		QuietRun				//whether ask user for inputs
	    );
}
Beispiel #7
0
//_____________________________________________________________________________
Int_t THaVDCPlane::ReadDatabase( const TDatime& date )
{
  // Allocate TClonesArray objects and load plane parameters from database

  FILE* file = OpenFile( date );
  if( !file ) return kFileError;

  // Use default values until ready to read from database

  static const char* const here = "ReadDatabase";
  const int LEN = 100;
  char buff[LEN];

  // Build the search tag and find it in the file. Search tags
  // are of form [ <prefix> ], e.g. [ R.vdc.u1 ].
  TString tag(fPrefix); tag.Chop(); // delete trailing dot of prefix
  tag.Prepend("["); tag.Append("]");
  TString line;
  bool found = false;
  while (!found && fgets (buff, LEN, file) != NULL) {
    char* buf = ::Compress(buff);  //strip blanks
    line = buf;
    delete [] buf;
    if( line.EndsWith("\n") ) line.Chop();  //delete trailing newline
    if ( tag == line )
      found = true;
  }
  if( !found ) {
    Error(Here(here), "Database section \"%s\" not found! "
	  "Initialization failed", tag.Data() );
    fclose(file);
    return kInitError;
  }

  //Found the entry for this plane, so read data
  Int_t nWires = 0;    // Number of wires to create
  Int_t prev_first = 0, prev_nwires = 0;
  // Set up the detector map
  fDetMap->Clear();
  do {
    fgets( buff, LEN, file );
    // bad kludge to allow a variable number of detector map lines
    if( strchr(buff, '.') ) // any floating point number indicates end of map
      break;
    // Get crate, slot, low channel and high channel from file
    Int_t crate, slot, lo, hi;
    if( sscanf( buff, "%6d %6d %6d %6d", &crate, &slot, &lo, &hi ) != 4 ) {
      if( *buff ) buff[strlen(buff)-1] = 0; //delete trailing newline
      Error( Here(here), "Error reading detector map line: %s", buff );
      fclose(file);
      return kInitError;
    }
    Int_t first = prev_first + prev_nwires;
    // Add module to the detector map
    fDetMap->AddModule(crate, slot, lo, hi, first);
    prev_first = first;
    prev_nwires = (hi - lo + 1);
    nWires += prev_nwires;
  } while( *buff );  // sanity escape
  // Load z, wire beginning postion, wire spacing, and wire angle
  sscanf( buff, "%15lf %15lf %15lf %15lf", &fZ, &fWBeg, &fWSpac, &fWAngle );
  fWAngle *= TMath::Pi()/180.0; // Convert to radians
  fSinAngle = TMath::Sin( fWAngle );
  fCosAngle = TMath::Cos( fWAngle );

  // Load drift velocity (will be used to initialize crude Time to Distance
  // converter)
  fscanf(file, "%15lf", &fDriftVel);
  fgets(buff, LEN, file); // Read to end of line
  fgets(buff, LEN, file); // Skip line

  // first read in the time offsets for the wires
  float* wire_offsets = new float[nWires];
  int*   wire_nums    = new int[nWires];

  for (int i = 0; i < nWires; i++) {
    int wnum = 0;
    float offset = 0.0;
    fscanf(file, " %6d %15f", &wnum, &offset);
    wire_nums[i] = wnum-1; // Wire numbers in file start at 1
    wire_offsets[i] = offset;
  }


  // now read in the time-to-drift-distance lookup table
  // data (if it exists)
//   fgets(buff, LEN, file); // read to the end of line
//   fgets(buff, LEN, file);
//   if(strncmp(buff, "TTD Lookup Table", 16) == 0) {
//     // if it exists, read the data in
//     fscanf(file, "%le", &fT0);
//     fscanf(file, "%d", &fNumBins);

//     // this object is responsible for the memory management
//     // of the lookup table
//     delete [] fTable;
//     fTable = new Float_t[fNumBins];
//     for(int i=0; i<fNumBins; i++) {
//       fscanf(file, "%e", &(fTable[i]));
//     }
//   } else {
//     // if not, set some reasonable defaults and rewind the file
//     fT0 = 0.0;
//     fNumBins = 0;
//     fTable = NULL;
//     cout<<"Could not find lookup table header: "<<buff<<endl;
//     fseek(file, -strlen(buff), SEEK_CUR);
//   }

  // Define time-to-drift-distance converter
  // Currently, we use the analytic converter.
  // FIXME: Let user choose this via a parameter
  delete fTTDConv;
  fTTDConv = new THaVDCAnalyticTTDConv(fDriftVel);

  //THaVDCLookupTTDConv* ttdConv = new THaVDCLookupTTDConv(fT0, fNumBins, fTable);

  // Now initialize wires (those wires... too lazy to initialize themselves!)
  // Caution: This may not correspond at all to actual wire channels!
  for (int i = 0; i < nWires; i++) {
    THaVDCWire* wire = new((*fWires)[i])
      THaVDCWire( i, fWBeg+i*fWSpac, wire_offsets[i], fTTDConv );
    if( wire_nums[i] < 0 )
      wire->SetFlag(1);
  }
  delete [] wire_offsets;
  delete [] wire_nums;

  // Set location of chamber center (in detector coordinates)
  fOrigin.SetXYZ( 0.0, 0.0, fZ );

  // Read additional parameters (not in original database)
  // For backward compatibility with database version 1, these parameters
  // are in an optional section, labelled [ <prefix>.extra_param ]
  // (e.g. [ R.vdc.u1.extra_param ]) or [ R.extra_param ].  If this tag is
  // not found, a warning is printed and defaults are used.

  tag = "["; tag.Append(fPrefix); tag.Append("extra_param]");
  TString tag2(tag);
  found = false;
  rewind(file);
  while (!found && fgets(buff, LEN, file) != NULL) {
    char* buf = ::Compress(buff);  //strip blanks
    line = buf;
    delete [] buf;
    if( line.EndsWith("\n") ) line.Chop();  //delete trailing newline
    if ( tag == line )
      found = true;
  }
  if( !found ) {
    // Poor man's default key search
    rewind(file);
    tag2 = fPrefix;
    Ssiz_t pos = tag2.Index(".");
    if( pos != kNPOS )
      tag2 = tag2(0,pos+1);
    else
      tag2.Append(".");
    tag2.Prepend("[");
    tag2.Append("extra_param]");
    while (!found && fgets(buff, LEN, file) != NULL) {
      char* buf = ::Compress(buff);  //strip blanks
      line = buf;
      delete [] buf;
      if( line.EndsWith("\n") ) line.Chop();  //delete trailing newline
      if ( tag2 == line )
	found = true;
    }
  }
  if( found ) {
    if( fscanf(file, "%lf %lf", &fTDCRes, &fT0Resolution) != 2) {
      Error( Here(here), "Error reading TDC scale and T0 resolution\n"
	     "Line = %s\nFix database.", buff );
      fclose(file);
      return kInitError;
    }
    fgets(buff, LEN, file); // Read to end of line
    if( fscanf( file, "%d %d %d %d %d %lf %lf", &fMinClustSize, &fMaxClustSpan,
		&fNMaxGap, &fMinTime, &fMaxTime, &fMinTdiff, &fMaxTdiff ) != 7 ) {
      Error( Here(here), "Error reading min_clust_size, max_clust_span, "
	     "max_gap, min_time, max_time, min_tdiff, max_tdiff.\n"
	     "Line = %s\nFix database.", buff );
      fclose(file);
      return kInitError;
    }
    fgets(buff, LEN, file); // Read to end of line
    // Time-to-distance converter parameters
    if( THaVDCAnalyticTTDConv* analytic_conv =
	dynamic_cast<THaVDCAnalyticTTDConv*>(fTTDConv) ) {
      // THaVDCAnalyticTTDConv
      // Format: 4*A1 4*A2 dtime(s)  (9 floats)
      Double_t A1[4], A2[4], dtime;
      if( fscanf(file, "%lf %lf %lf %lf %lf %lf %lf %lf %lf",
		 &A1[0], &A1[1], &A1[2], &A1[3],
		 &A2[0], &A2[1], &A2[2], &A2[3], &dtime ) != 9) {
	Error( Here(here), "Error reading THaVDCAnalyticTTDConv parameters\n"
	       "Line = %s\nExpect 9 floating point numbers. Fix database.",
	       buff );
	fclose(file);
	return kInitError;
      } else {
	analytic_conv->SetParameters( A1, A2, dtime );
      }
    }
//     else if( (... *conv = dynamic_cast<...*>(fTTDConv)) ) {
//       // handle parameters of other TTD converters here
//     }

    fgets(buff, LEN, file); // Read to end of line

    Double_t h, w;

    if( fscanf(file, "%lf %lf", &h, &w) != 2) {
	Error( Here(here), "Error reading height/width parameters\n"
	       "Line = %s\nExpect 2 floating point numbers. Fix database.",
	       buff );
	fclose(file);
	return kInitError;
      } else {
	   fSize[0] = h/2.0;
	   fSize[1] = w/2.0;
      }

    fgets(buff, LEN, file); // Read to end of line
    // Sanity checks
    if( fMinClustSize < 1 || fMinClustSize > 6 ) {
      Error( Here(here), "Invalid min_clust_size = %d, must be betwwen 1 and "
	     "6. Fix database.", fMinClustSize );
      fclose(file);
      return kInitError;
    }
    if( fMaxClustSpan < 2 || fMaxClustSpan > 12 ) {
      Error( Here(here), "Invalid max_clust_span = %d, must be betwwen 1 and "
	     "12. Fix database.", fMaxClustSpan );
      fclose(file);
      return kInitError;
    }
    if( fNMaxGap < 0 || fNMaxGap > 2 ) {
      Error( Here(here), "Invalid max_gap = %d, must be betwwen 0 and 2. "
	     "Fix database.", fNMaxGap );
      fclose(file);
      return kInitError;
    }
    if( fMinTime < 0 || fMinTime > 4095 ) {
      Error( Here(here), "Invalid min_time = %d, must be betwwen 0 and 4095. "
	     "Fix database.", fMinTime );
      fclose(file);
      return kInitError;
    }
    if( fMaxTime < 1 || fMaxTime > 4096 || fMinTime >= fMaxTime ) {
      Error( Here(here), "Invalid max_time = %d. Must be between 1 and 4096 "
	     "and >= min_time = %d. Fix database.", fMaxTime, fMinTime );
      fclose(file);
      return kInitError;
    }
  } else {
    Warning( Here(here), "No database section \"%s\" or \"%s\" found. "
	     "Using defaults.", tag.Data(), tag2.Data() );
    fTDCRes = 5.0e-10;  // 0.5 ns/chan = 5e-10 s /chan
    fT0Resolution = 6e-8; // 60 ns --- crude guess
    fMinClustSize = 3;
    fMaxClustSpan = 7;
    fNMaxGap = 1;
    fMinTime = 800;
    fMaxTime = 2200;
    fMinTdiff = 3e-8;   // 30ns  -> ~20 deg track angle
    //fMaxTdiff = 1.5e-7; // 150ns -> ~60 deg track angle
    fMaxTdiff = 2.0e-7; // 200ns

    if( THaVDCAnalyticTTDConv* analytic_conv =
	dynamic_cast<THaVDCAnalyticTTDConv*>(fTTDConv) ) {
      Double_t A1[4], A2[4], dtime = 4e-9;
      A1[0] = 2.12e-3;
      A1[1] = A1[2] = A1[3] = 0.0;
      A2[0] = -4.2e-4;
      A2[1] = 1.3e-3;
      A2[2] = 1.06e-4;
      A2[3] = 0.0;
      analytic_conv->SetParameters( A1, A2, dtime );
    }
  }

  THaDetectorBase *sdet = GetParent();
  if( sdet )
    fOrigin += sdet->GetOrigin();

  // finally, find the timing-offset to apply on an event-by-event basis
  //FIXME: time offset handling should go into the enclosing apparatus -
  //since not doing so leads to exactly this kind of mess:
  THaApparatus* app = GetApparatus();
  const char* nm = "trg"; // inside an apparatus, the apparatus name is assumed
  if( !app ||
      !(fglTrg = dynamic_cast<THaTriggerTime*>(app->GetDetector(nm))) ) {
    Warning(Here(here),"Trigger-time detector \"%s\" not found. "
	    "Event-by-event time offsets will NOT be used!!",nm);
  }

  fIsInit = true;
  fclose(file);

  return kOK;
}