Example #1
0
void run(TString runNumber)
{
    TStopwatch timer;
    timer.Start();

    const Int_t nModules = 200;

    TString dirIn1 = "/Volumes/Data/kresan/s438/data/";
    TString dirIn2 = "/Volumes/Data/kresan/s438/tcal/";
    TString dirOut = "/Volumes/Data/kresan/s438/tcal/";
    TString inputFileName1 = dirIn1 + runNumber + "_tcal.root";             // name of input file
    TString inputFileName2 = dirIn2 + runNumber + "_tcal_1.root";           // name of input file
    TString parFileName    = dirIn1 + "params_" + runNumber + "_tcal.root"; // name of parameter file
    TString outputFileName = dirOut + runNumber + "_tcal_temp.root";             // name of output file

    // Create analysis run -------------------------------------------------------
    Int_t nFiles;
    if (0 == runNumber.CompareTo("r122"))
    {
        nFiles = 22;
    }
    else if (0 == runNumber.CompareTo("r126"))
    {
        nFiles = 2;
    }

    // Create analysis run -------------------------------------------------------
    FairRunAna* run = new FairRunAna();
    run->SetInputFile(inputFileName1.Data());
    run->AddFriend(inputFileName2.Data());
    for (Int_t i = 1; i < nFiles; i++)
    {
        inputFileName1 = dirIn1 + runNumber + "_tcal_";
        inputFileName1 += i;
        inputFileName1 += ".root";
        run->AddFile(inputFileName1.Data());
    }
    run->SetOutputFile(outputFileName.Data());
    // ---------------------------------------------------------------------------

    // ----- Runtime DataBase info -----------------------------------------------
    FairRuntimeDb* rtdb = run->GetRuntimeDb();
    FairParRootFileIo* parIo1 = new FairParRootFileIo();
    parIo1->open(parFileName);
    rtdb->setFirstInput(parIo1);
    rtdb->setOutput(parIo1);

    // Set the SQL IO as second input
    FairParTSQLIo* inp = new FairParTSQLIo();
    inp->SetVerbosity(1);
    inp->open();
    rtdb->setFirstInput(inp);

    rtdb->saveOutput();
    // ---------------------------------------------------------------------------

    // Time calibration ----------------------------------------------------------
    R3BLandTcal* landTcal = new R3BLandTcal("LandTcal", 1);
    landTcal->SetNofModules(nModules, 40);
    run->AddTask(landTcal);

    R3BLosTcal* losTcal = new R3BLosTcal("LosTcal", 1);
    losTcal->SetNofModules(20);
    run->AddTask(losTcal);
    // ---------------------------------------------------------------------------

    // Initialize ----------------------------------------------------------------
    run->Init();
    FairLogger::GetLogger()->SetLogScreenLevel("INFO");
    // ---------------------------------------------------------------------------

    // Run -----------------------------------------------------------------------
    run->Run(0, 100000);
    // ---------------------------------------------------------------------------

    timer.Stop();
    Double_t rtime = timer.RealTime();
    Double_t ctime = timer.CpuTime();
    cout << endl << endl;
    cout << "Macro finished succesfully." << endl;
    cout << "Output file is " << outputFileName << endl;
    cout << "Parameter file is " << parFileName << endl;
    cout << "Real time " << rtime << " s, CPU time " << ctime << "s" << endl << endl;
}
void comparison_cov_firstpar(int nevts=0, TString Path=""){

  TDatabasePDG::Instance()-> AddParticle("pbarpSystem","pbarpSystem", 1.9, kFALSE, 0.1, 0,"", 88888);

  TStopwatch timer;

  //Output File
  TString outPath = Path;
  TString OutputFile = "cov_output.root";

  //Input simulation Files
  TString DigiFile  = Path + "digi_complete.root";
  TString RecoFile  = Path + "reco_complete.root";
  TString inPIDFile = Path + "pid_complete.root";
  TString inParFile = Path + "simparams.root";
  TString PIDParFile = TString( gSystem->Getenv("VMCWORKDIR")) + "/macro/params/all.par";


  //Initialization
  FairLogger::GetLogger()->SetLogToFile(kFALSE);
  FairRunAna* RunAna = new FairRunAna();
  FairRuntimeDb* rtdb = RunAna->GetRuntimeDb();
  RunAna->SetInputFile(inPIDFile);

  //setup parameter database
  FairParRootFileIo* parIo = new FairParRootFileIo();
  parIo->open(inParFile);
  FairParAsciiFileIo* parIoPID = new FairParAsciiFileIo();
  parIoPID->open(PIDParFile.Data(),"in");

  rtdb->setFirstInput(parIo);
  rtdb->setSecondInput(parIoPID);
  rtdb->setOutput(parIo);

  RunAna->AddFriend(DigiFile);
  RunAna->AddFriend(RecoFile);
  RunAna->SetOutputFile(OutputFile);
  RunAna->Init();


  // data reader Object
  PndAnalysis* theAnalysis = new PndAnalysis();
  if (nevts==0) nevts = theAnalysis->GetEntries();

  RhoCandList piminus, proton;


  TMatrixD CovPion(5,5);
  TMatrixD CovProton(5,5);

	int evt=-1;
	while (theAnalysis->GetEvent() && ++evt<nevts){
		cout << "evt: " << evt << endl;

		TString PidSelection = "PidAlgoIdealCharged";//"PidAlgoMvd;PidAlgoStt;PidAlgoDrc";


		//***Selection with no PID info
		theAnalysis->FillList(piminus, "PionAllMinus", PidSelection);
		theAnalysis->FillList(proton, "ProtonAllPlus", PidSelection);


		//Get piminus

		for (int j=0; j<piminus.GetLength(); ++j){

			bool truth = theAnalysis->McTruthMatch(piminus[j]);

			if(truth){

				TMatrixD piCov(7,7);
				piCov = piminus[j]->Cov7();


				FairTrackParP paramFirst = theAnalysis->GetFirstPar(piminus[j]);

				double cov[15];
				paramFirst.GetCov(cov);

				for (int i=0; i<15; i++){
					if(TMath::Abs(cov[i]<1e-6)) cov[i]=0;
				}

				CovPion[0][0] = cov[0];
				CovPion[0][1] = cov[1];
				CovPion[0][2] = cov[2];
				CovPion[0][3] = cov[3];
				CovPion[0][4] = cov[4];

				CovPion[1][1] = cov[5];
				CovPion[1][2] = cov[6];
				CovPion[1][3] = cov[7];
				CovPion[1][4] = cov[8];

				CovPion[2][2] = cov[9];
				CovPion[2][3] = cov[10];
				CovPion[2][4] = cov[11];

				CovPion[3][3] = cov[12];
				CovPion[3][4] = cov[13];

				CovPion[4][4] = cov[14];

				for (int i=0; i<5; i++){
					for(int j=0; j<5; j++){
						CovPion[j][i]=CovPion[i][j];
					}
				}

				cout << "Covariance matrix for pion: " << endl;

				for(int i=0; i<7; i++){
					for(int j=0; j<7; j++){
						if(TMath::Abs(piCov[i][j])<1e-6) piCov[i][j]=0;
					}
				}
				piCov.Print();

				cout << "First Par Covariance matrix for pion: " << endl;
				CovPion.Print();

			}

			//Get proton

			for (int j=0; j<proton.GetLength(); ++j){

				bool truth = theAnalysis->McTruthMatch(proton[j]);

				if(truth){
					TMatrixD protCov = proton[j]->Cov7();

					FairTrackParP paramFirst = theAnalysis->GetFirstPar(proton[j]);

					double cov[15];
					paramFirst.GetCov(cov);

					for (int i=0; i<15; i++){
						if(TMath::Abs(cov[i]<1e-6)) cov[i]=0;
					}

					CovProton[0][0] = cov[0];
					CovProton[0][1] = cov[1];
					CovProton[0][2] = cov[2];
					CovProton[0][3] = cov[3];
					CovProton[0][4] = cov[4];

					CovProton[1][1] = cov[5];
					CovProton[1][2] = cov[6];
					CovProton[1][3] = cov[7];
					CovProton[1][4] = cov[8];

					CovProton[2][2] = cov[9];
					CovProton[2][3] = cov[10];
					CovProton[2][4] = cov[11];

					CovProton[3][3] = cov[12];
					CovProton[3][4] = cov[13];

					CovProton[4][4] = cov[14];

					for (int i=0; i<5; i++){
						for(int j=0; j<5; j++){
							CovProton[j][i]=CovProton[i][j];
						}
					}

					cout << "Covariance matrix for proton: " << endl;

					for(int i=0; i<7; i++){
						for(int j=0; j<7; j++){
							if(TMath::Abs(protCov[i][j])<1e-6) protCov[i][j]=0;
						}
					}
					protCov.Print();

					cout << "First Par Covariance matrix for proton: " << endl;
					CovProton.Print();
				}
			}

		}
	}
}