Esempio n. 1
0
// return the future n requests following
// this pattern
//
// the input n is the number of requests you want to predict
// startStride is how many stride this future request should start from.
vector<Request>
RequestPattern::futureRequests( int n , int startStride )
{
    // let me handle the simple case first
    // one offset pattern and one length pattern
    assert( length.chain.size() == 1 && length.chain[0].cnt > 0 );

    vector<Request> freq; // future requests put here

    // handle the case of only one request in the pattern
    if ( offset.seq.size() == 0
            || ( offset.seq.size() * offset.cnt <= 1 ) )
    {
        assert(length.chain.size() > 0);
        freq.push_back( Request(offset.init + length.chain[0].init,
                                length.chain[0].init * n) );
        return freq;
    }

    off_t off_stride_sum = sumVector(offset.seq);
    PatternUnit mylen = length.chain[0]; // for short
    off_t len_stride_sum = sumVector(mylen.seq);
    int i;
    int offseqsize = offset.seq.size();
    int lenseqsize = mylen.seq.size();


    int round = ((startStride-1) * n) / offseqsize;
    int remain = ((startStride-1) * n) % offseqsize;

    off_t off_add = off_stride_sum * round;
    off_t len_add = len_stride_sum * round;
    for ( i = 0 ; i < remain ; i++ ) {
        off_add += offset.seq[ i % offseqsize ];
        len_add += mylen.seq[ i% lenseqsize ];
    }

    off_t base_off = offset.init + off_stride_sum * offset.cnt + off_add;
    off_t base_len = mylen.init + len_stride_sum * mylen.cnt + len_add;
    
    freq.push_back( Request(base_off, base_len) );


    if ( offseqsize == 0 || lenseqsize == 0 )
        return freq;

    off_t curoff = base_off;
    off_t curlen = base_len;
    for ( i = 0 ; i < n-1 ; i++ ) {
        curoff = curoff + offset.seq[ i % offseqsize ];
        curlen = curlen + mylen.seq[ i % lenseqsize ];
        freq.push_back( Request(curoff, curlen) );
    }
    return freq;
}
Esempio n. 2
0
int main()
{
	clock_t t1, t2, t3, t4, t5, t6;
	char a[50], b[50], c[50];

	printf("Hi, v1.7\n");
	printf("Running algorithm for task: ");
	printf((task)?"4+\n":"1-3\n");
	printf("Dividing result by 1024 is: ");
	printf((div_1024)?"ON\n":"OFF\n");
	////////////////
	//test case 1 //
	////////////////
	printf("gen vector 1, ");
	generateVector(x1, N1, S1);
	printf("sum vector 1\n");
	float y1=0.0;
	if (task) {t1 = times(NULL); y1 = sumVector_cos_custom(x1, N1); t2 = times(NULL);}
	else {t1 = times(NULL); y1 = sumVector(x1, N1); t2 = times(NULL);}
	gcvt(t2-t1, 10, a);
	alt_putstr("Time = "); alt_putstr(a); alt_putstr("; ");
	printf("Result = %f\n", ((div_1024)?y1/1024:y1));

	////////////////
	//test case 2 //
	////////////////
	printf("gen vector 2, ");
	generateVector(x2, N2, S2);
	printf("sum vector 2\n");
	float y2=0.0;
	if (task) {t3 = times(NULL); y2 = sumVector_cos_custom(x2, N2); t4 = times(NULL);}
	else {t3 = times(NULL); y2 = sumVector(x2, N2); t4 = times(NULL);}
	gcvt(t4-t3, 10, b);
	alt_putstr("Time = "); alt_putstr(b); alt_putstr("; ");
	printf("Result = %f\n", ((div_1024)?y2/1024:y2));

	////////////////
	//test case 3 //
	////////////////
	printf("gen vector 3, ");
	generateVector(x3, N3, S3);
	printf("sum vector 3\n");
	float y3=0.0;
	if (task) {t5 = times(NULL); y3 = sumVector_cos_custom(x3, N3); t6 = times(NULL);}
	else {t5 = times(NULL); y3 = sumVector(x3, N3); t6 = times(NULL);}
	gcvt(t6-t5, 10, c);
	alt_putstr("Time = "); alt_putstr(c); alt_putstr("; ");
	printf("Result = %f\n", ((div_1024)?y3/1024:y3));


	return 0;
}
Esempio n. 3
0
int main()
{
	printf("Task 2! \n");

	float x[N];
	float y;

	generateVector(x);

	// timing
	char buf[50];
	clock_t exec_t1, exec_t2;

	exec_t1 = times(NULL); // get system time before starting the process

	// code START
	y = sumVector (x, N);

	//code END

	exec_t2 = times(NULL); // get system time after finishing the process
	gcvt((exec_t2 - exec_t1), 10, buf);
	// gcvt convert a number to a string with decimal including a point, gcvt(value,number of digits,buffer)
	// buffer 8,9 character longer than number, this is the memory block that stores the number
	alt_putstr("proc time = "); 	alt_putstr(buf);	alt_putstr("ticks\n");
	//printf could be used if memory is enough
	int i;
	for (i=0; i<10; i++)
		y = y/2.0;
	gcvt((int)y, 10, buf);
	alt_putstr("Result (divided by 1014) = "); alt_putstr(buf);
	return 0;
}
Esempio n. 4
0
SignalSource makeAmplitudeFrequency(const SignalSource &signal, bool positivePart, int64_t step)
{
    double size_d = 0.0;
    for (auto val : signal) {
        size_d = positivePart ? qMax(size_d, val) : qMin(size_d, val);
    }

    auto size = static_cast<int64_t>(positivePart ? size_d : -size_d);
    QVector<double> result(size);
    for (auto val : signal) {
        int64_t val_t = trunc(val);
        int64_t index = -1;
        if (val_t > 0 && positivePart) {
            index = val_t - 1;
        } else if (val_t < 0 && !positivePart) {
            index = size + val_t - 1;
        }

        if (index >= 0 && index < result.size()) {
            result[index] = result[index] + 1;
        } else {
//            qDebug() << "Wrong index " << index;
        }
    }

    int64_t stepCounter = 0;
    int64_t sum = 0;
    QVector<double> compressedResult;
    for (int64_t i = 0; i < result.size(); i++) {
        stepCounter++;
        sum += result[i];
        if (stepCounter == step) {
            QVector<double> sumVector(step, sum);
            compressedResult.append(sumVector);
            stepCounter = 0;
            sum = 0;
        }
    }

    return compressedResult;
}
Esempio n. 5
0
vector<double> PageRankEsparso::metodoPotencia() {
	int n = A.size();
	// creo el x aleatorio
	vector<double> x(n, 0);
	for (int i = 0; i < n; i++) {
		x[i] = random_in_range(1,50);
	}
	// creo el v aleatorio
	vector<double> v(n, double(1)/double(n));

	vector<double> y = x;
	double delta = INFINITY;
	double last_delta;
	do {
		x = y;
		y = scaleVector(multiplyEsparso(A, x), teletransportacion);
		double w = norma1(x) - norma1(y);
		y = sumVector(y, scaleVector(v, w));
		last_delta = delta;
		delta = phi(y) / phi(x);
	} while (fabs(delta - last_delta) > precision);

	return scaleVector(y, 1/norma1(y));
}
void MinimumStatistics::process(double *amp){
	int i = 0;
	int j = 0;
	for (i = 0; i< fftsize; i++){
		power[i] = amp[i] * amp[i];
	}
	// eq9
	double tmp = (sumVector(fftsize, P_lambda)/sumVector(fftsize, power) - 1);
	double alpha_c_lambda_tilde = 1.0 / (tmp * tmp + 1.0);

	// eq10
	if (alpha_c_lambda_tilde > 0.7){
		tmp = alpha_c_lambda_tilde;
	}else{
		tmp = 0.7;
	}
	alpha_c_lambda = alpha_c_lambda * 0.7 + 0.3 * tmp;

	// eq11
	for(i = 0; i < fftsize; i++){
		tmp = (P_lambda[i] / sn2_lambda[i] - 1.0);
		alpha_lambda_hat[i] = (alpha_max / alpha_c_lambda) / (tmp * tmp + 1);
	}

	// eq12
	double snr = sumVector(fftsize, P_lambda) / sumVector(fftsize, sn2_lambda);
	tmp = powf(snr, snrexp);
	if (tmp > 0.3){
		tmp = 0.3;
	}
	for(i = 0; i < fftsize; i++){
		if (alpha_lambda_hat[i] < tmp){
			alpha_lambda_hat[i] = tmp;
		}
	}

	// eq4 smoothed periodgram
	for(i = 0; i < fftsize; i++){
		P_lambda[i] = alpha_lambda_hat[i] * P_lambda[i] + (1.0 - alpha_lambda_hat[i]) * power[i];
	}

	for(i = 0; i < fftsize; i++){
		// eq20
		tmp = alpha_lambda_hat[i] * alpha_lambda_hat[i];
		if (tmp > beta_max){
			tmp = beta_max;
		}
		eP_lambda[i] = tmp * eP_lambda[i] + (1.0 - tmp) * P_lambda[i];
		eP2_lambda[i] = tmp * eP2_lambda[i] + (1.0 - tmp) * P_lambda[i] * P_lambda[i];

		// eq22
		tmp = eP2_lambda[i] - eP_lambda[i] * eP_lambda[i];

		// eq23
		tmp = tmp / (sn2_lambda[i] * sn2_lambda[i] * 2.0);
		if (tmp > 0.5){
			tmp = 0.5;
		}
		if (tmp < qeqimin/(counter + 1)){
			tmp = qeqimin/(counter + 1);
		}
		Qeq_lambda_inverse[i] = tmp;
	}
	double eQ_lambda = sumVector(fftsize, Qeq_lambda_inverse) / fftsize;
	double Bc_lambda = 1.0 + av * sqrtf(eQ_lambda);

	// eq 16
	for(i = 0; i < fftsize; i++){
		// for overall window of length D
		tmp = (1.0 / Qeq_lambda_inverse[i] - 2 * M) / (1.0 - M);
		Bmin_lambda[i] = 1.0 + (D - 1) * 2.0 / tmp;
		// for subwindow U of length V
		tmp = (1.0 / Qeq_lambda_inverse[i] - 2 * M2) / (1.0 - M2);
		Bmin_lambda_sub[i] = 1.0 + (V - 1) * 2.0 / tmp;
	}

	// calc actmin,
	resetVector(fftsize, k_mod, 0); // reset to 0
	for(i = 0; i < fftsize; i++){
		// if (P * Bmin * Bc < actmin)
		tmp = P_lambda[i] * Bmin_lambda[i] * Bc_lambda;
		if (actmin_lambda[i] > tmp){
			actmin_lambda[i] = tmp;
			actmin_lambda_sub[i] = P_lambda[i] * Bmin_lambda_sub[i] * Bc_lambda;
			k_mod[i] = 1;
		}
	}

	if(0 < subwc && subwc < V-1){
		for(i = 0; i < fftsize; i++){
			// sample is NOT the fisrt or the last; middle of buffer allows a local minimum
			if (lmin_flag_lambda[i] + k_mod[i] >= 1){
				lmin_flag_lambda[i] = 1;
			}else{
				lmin_flag_lambda[i] = 0;
			}
			if ( Pmin_u_lambda[i] > actmin_lambda_sub[i]){
				Pmin_u_lambda[i] = actmin_lambda_sub[i];
			}
		}
		memcpy(sn2_lambda, Pmin_u_lambda, sizeof(double) * fftsize);
		subwc++;
	}else if(subwc >= V - 1){
		// store actmin_lamnda, note actbuf is NOT cyclic!
		ibuf = ibuf % U;
		memcpy(actbuf[ibuf], actmin_lambda, sizeof(double) * fftsize);
		ibuf++;

		// calc noise_slope_max
		double noise_slope_max;
		if(eQ_lambda < 0.03){
			noise_slope_max = 8.0;
		}else if(eQ_lambda < 0.05){
			noise_slope_max = 4.0;
		}else if(eQ_lambda < 0.06){
			noise_slope_max = 2.0;
		}else{
			noise_slope_max = 1.2;
		}

		// sample IS the last; end of buffer lets finishing subwindow process and a buffer switch
		for(i = 0; i < fftsize; i++){
			if (lmin_flag_lambda[i] - k_mod[i] >= 0){
				lmin_flag_lambda[i] = 1;
			}else{
				lmin_flag_lambda[i] = 0;
			}
			// find Pmin_u, the minimum of the last U stored value of actmin
			Pmin_u_lambda[i] = clear_max;
			for(j = 0; j < U; j++){
				if (Pmin_u_lambda[i] > actbuf[j][i]){
					Pmin_u_lambda[i] = actbuf[j][i];
				}
			}
			// replace all previously stored values of actmin by actminsub
			if (lmin_flag_lambda[i] == 1 && actmin_lambda_sub[i] < noise_slope_max * Pmin_u_lambda[i] && Pmin_u_lambda[i] < actmin_lambda_sub[i]){
				Pmin_u_lambda[i] = actmin_lambda_sub[i];
				for(j = 0; j < U; j++){
					actbuf[j][i] = Pmin_u_lambda[i];
				}
			}

		}
		resetVector(fftsize, lmin_flag_lambda, 0);
		resetVector(fftsize, actmin_lambda, clear_max);
		subwc = 0;
	}else{
		subwc++;
	}
	counter++;
}
Esempio n. 7
0
int main() {


  DrawTools::setStyle();

  std::vector<std::string> runs;
  runs.push_back( "BTF_229_20140501-155939_beam" ); // 0
  runs.push_back( "BTF_231_20140501-163742_beam" ); // 1
  runs.push_back( "BTF_233_20140501-171741_beam" ); // 2
  runs.push_back( "BTF_237_20140501-183950_beam" ); // 3
  runs.push_back( "BTF_235_20140501-175948_beam" ); // 4
  runs.push_back( "BTF_239_20140501-191908_beam" ); // 5
  runs.push_back( "BTF_241_20140501-200053_beam" ); // 6
  runs.push_back( "BTF_243_20140501-203838_beam" ); // 7


  std::string outputdir = "BGOCalibration/";
  std::string mkdir_command = "mkdir -p " + outputdir;
  system(mkdir_command.c_str());


  std::vector<TH1D*> rawHistos;
  std::vector<TH1D*> calibHistos;
  std::vector<float> calibConstants;
  float yMax = 0.;

  for( unsigned i=0; i<runs.size(); ++i ) {
    TH1D* h1_raw = fitSingleChannelBGO( outputdir, "raw", runs[i], i, 1. );
    rawHistos.push_back(h1_raw);
    TF1* thisFunc = (TF1*)(h1_raw->GetListOfFunctions()->FindObject(Form("gaussian_%s", runs[i].c_str())));
    calibConstants.push_back(thisFunc->GetParameter(1));
    float thisMax = h1_raw->GetMaximum()/h1_raw->Integral();
    if( thisMax>yMax )
      yMax = thisMax;
  }


  float calibAve = sumVector(calibConstants)/calibConstants.size();


  std::string constantsFileName = outputdir + "/constants.txt";
  ofstream ofs(constantsFileName.c_str());

  for( unsigned i=0; i<runs.size(); ++i ) {
    float thisCalib = calibAve/calibConstants[i];
    calibHistos.push_back(fitSingleChannelBGO( outputdir, "calib", runs[i], i, thisCalib ));
    ofs << i << "\t" << thisCalib << std::endl;
  }

  ofs.close();

  drawHistos( outputdir, rawHistos,   "rawSpectra"  , yMax );
  drawHistos( outputdir, calibHistos, "calibSpectra", yMax );


  std::cout << std::endl;
  std::cout << "-> Calibration constants saved in: " << constantsFileName << std::endl;

  std::cout << "Calibration average for BGO: " << calibAve << std::endl;


  std::string run_cef3 = "BTF_227_20140501-151233_beam";
  TH1D* h1_cef3 = fitCeF3( outputdir, "cef3_raw", run_cef3 );
  TF1* f1_cef3 = (TF1*)(h1_cef3->GetListOfFunctions()->FindObject(Form("gaussian_%s", run_cef3.c_str())));

  std::cout << "BGO/CeF3 relative calibration: " << calibAve/f1_cef3->GetParameter(1) << std::endl;
  
  return 0;

}
int main( int argc, char* argv[] ) {


  std::string runName = "precalib_BGO_pedestal_noSource";
  if( argc>1 ) {
    std::string runName_str(argv[1]);
    runName = runName_str;
  }

  std::string tag = "V00";
  if( argc>2 ) {
    std::string tag_str(argv[2]);
    tag = tag_str;
  }

  TString runName_tstr(runName);
  bool isOnlyRunNumber = !(runName_tstr.BeginsWith("BTF_"));


  TChain* tree = new TChain("recoTree");
  if( isOnlyRunNumber ) {
    std::cout << "-> We believe you are passing the program only the run number!" << std::endl;
    std::cout << "-> So for instance you are passing '246' for run 'BTF_246_20140501-212512_beam'" << std::endl;
    std::cout << "(if this is not the case this means TROUBLE)" << std::endl;
    std::cout << "-> Will look for runs matching run number: " << runName << std::endl;
    tree->Add(Form("analysisTrees_%s/Reco_BTF_%s_*beam.root/recoTree", tag.c_str(), runName.c_str()) );
    if( tree->GetEntries()==0 ) {
      std::cout << "WARNING! Didn't find any events matching run: " << runName << std::endl;
      std::cout << "Exiting" << std::endl;
      exit(1913);
    }
  } else {
    std::string fileName = "analysisTrees_"+tag+"/Reco_" + runName + ".root";
    TFile* file = TFile::Open(fileName.c_str());
    if( file==0 ) {
      std::cout << "ERROR! Din't find file " << fileName << std::endl;
      std::cout << "Exiting." << std::endl;
      exit(11);
    }
    tree = (TChain*)file->Get("recoTree");
  }

  UInt_t evtNumber;
  tree->SetBranchAddress( "evtNumber", &evtNumber );
  UInt_t adcData[40];
  tree->SetBranchAddress( "adcData", adcData );
  UInt_t adcBoard[40];
  tree->SetBranchAddress( "adcBoard", adcBoard );
  UInt_t adcChannel[40];
  tree->SetBranchAddress( "adcChannel", adcChannel );


  unsigned int runNumber;
  int nHodoFibersX;
  int nHodoFibersY;
  int nHodoClustersX;
  int nHodoClustersY;
  float cef3_corr[CEF3_CHANNELS];
  float bgo_corr[BGO_CHANNELS];
  float scintFront;
  float pos_hodoClustX[HODOX_CHANNELS];
  float pos_hodoClustY[HODOY_CHANNELS];
  int nFibres_hodoClustX[HODOX_CHANNELS];
  int nFibres_hodoClustY[HODOY_CHANNELS];
  float xBeam, yBeam;
  bool isSingleEle_scintFront;
  bool cef3_ok;
  bool cef3_corr_ok;
  bool bgo_ok;
  bool bgo_corr_ok;

  tree->SetBranchAddress( "runNumber", &runNumber );

  tree->SetBranchAddress( "scintFront", &scintFront );
  tree->SetBranchAddress( "cef3_corr", cef3_corr );
  tree->SetBranchAddress( "bgo_corr", bgo_corr );

  tree->SetBranchAddress( "nHodoFibersX", &nHodoFibersX );
  tree->SetBranchAddress( "nHodoFibersY", &nHodoFibersY );
  tree->SetBranchAddress( "nHodoClustersX", &nHodoClustersX );
  tree->SetBranchAddress( "pos_hodoClustX", pos_hodoClustX );
  tree->SetBranchAddress( "nFibres_hodoClustX", nFibres_hodoClustX );
  tree->SetBranchAddress( "nHodoClustersY", &nHodoClustersY );
  tree->SetBranchAddress( "pos_hodoClustY", pos_hodoClustY );
  tree->SetBranchAddress( "nFibres_hodoClustY", nFibres_hodoClustY );
  tree->SetBranchAddress( "scintFront", &scintFront );
  tree->SetBranchAddress( "isSingleEle_scintFront", &isSingleEle_scintFront );
  tree->SetBranchAddress( "xBeam", &xBeam );
  tree->SetBranchAddress( "yBeam", &yBeam );

  tree->SetBranchAddress( "cef3_ok", &cef3_ok );
  tree->SetBranchAddress( "cef3_corr_ok", &cef3_corr_ok );
  tree->SetBranchAddress( "bgo_ok", &bgo_ok );
  tree->SetBranchAddress( "bgo_corr_ok", &bgo_corr_ok );

  int nentries = tree->GetEntries();


  if( isOnlyRunNumber ) {
    // modify runname in such a way that it's useful for getBeamPosition and outfile:
    runName = "BTF_" + runName + "_beam";
  }

  std::string outputdir = "SingleElectronSelectionTrees_"+tag;
  system( Form("mkdir -p %s", outputdir.c_str()) );
  std::string outfileName = outputdir + "/SingleEleSelAn_" + runName + ".root";
  TFile* outfile = TFile::Open( outfileName.c_str(), "RECREATE" );

  TTree* outTree = new TTree("singleEleSelTree","singleEleSelTree");

  outTree->Branch( "run", &runNumber, "run/i" );
  outTree->Branch( "scintFront", &scintFront, "scintFront/F" );
  outTree->Branch( "isSingleEle_scintFront", &isSingleEle_scintFront, "isSingleEle_scintFront/O" );
  outTree->Branch( "nHodoClustersX", &nHodoClustersX, "nHodoClustersX/I" );
  outTree->Branch( "nHodoClustersY", &nHodoClustersY, "nHodoClustersY/I" );
  outTree->Branch( "cef3_corr", cef3_corr, "cef3_corr[4]/F" );
  outTree->Branch( "bgo_corr", bgo_corr, "bgo_corr[8]/F" );
  outTree->Branch( "bgo_corr_ok", &bgo_corr_ok, "bgo_corr_ok/O");
  outTree->Branch( "xBeam", &xBeam, "xBeam/F" );
  outTree->Branch( "yBeam", &yBeam, "yBeam/F" );

  TH1D* h1_cef3_corr_tot = new TH1D("cef3_corr_tot", "", 1500, 0., 15000);

  for( unsigned iEntry=0; iEntry<nentries; ++iEntry ) {
    tree->GetEntry(iEntry);
    
    if( iEntry % 10000 == 0 ) std::cout << "Entry: " << iEntry << " / " << nentries << std::endl;
    if( cef3_ok ) {
      
      
      std::vector<float> v_cef3_corr;
      for(unsigned i=0; i<CEF3_CHANNELS; ++i) v_cef3_corr.push_back(cef3_corr[i]);
      
      float eTot_corr = sumVector(v_cef3_corr);

      if( cef3_corr_ok ) {
	h1_cef3_corr_tot->Fill(eTot_corr);
      }
      outTree->Fill();
    }

  }

  FitResults fr_0 = fitSingleHisto( h1_cef3_corr_tot, 0.,0., 1000., 11500. );

  outfile->cd();
  h1_cef3_corr_tot->Write();
  outTree->Write();
  outfile->Close();
  std::cout << "-> Histograms saved in: " << outfile->GetName() << std::endl;



  return 0;

}
Esempio n. 9
0
void StatisticsState::listStats()
{
	SavedGame *save = _game->getSavedGame();

	std::ostringstream ss;
	GameTime *time = save->getTime();
	if (save->getEnding() == END_WIN)
	{
		ss << tr("STR_VICTORY");
	}
	else if (save->getEnding() == END_LOSE)
	{
		ss << tr("STR_DEFEAT");
	}
	else
	{
		ss << tr("STR_STATISTICS");
	}
	ss << Unicode::TOK_NL_SMALL << time->getDayString(_game->getLanguage()) << " " << tr(time->getMonthString()) << " " << time->getYear();
	_txtTitle->setText(ss.str());

	int monthlyScore = sumVector(save->getResearchScores()) / save->getResearchScores().size();
	int64_t totalIncome = sumVector(save->getIncomes());
	int64_t totalExpenses = sumVector(save->getExpenditures());

	int alienBasesDestroyed = 0, xcomBasesLost = 0;
	int missionsWin = 0, missionsLoss = 0, nightMissions = 0;
	int bestScore = -9999, worstScore = 9999;
	for (std::vector<MissionStatistics*>::const_iterator i = save->getMissionStatistics()->begin(); i != save->getMissionStatistics()->end(); ++i)
	{
		if ((*i)->success)
		{
			missionsWin++;
		}
		else
		{
			missionsLoss++;
		}
		bestScore = std::max(bestScore, (*i)->score);
		worstScore = std::min(worstScore, (*i)->score);
		if ((*i)->daylight > 5)
		{
			nightMissions++;
		}
		if ((*i)->isAlienBase() && (*i)->success)
		{
			alienBasesDestroyed++;
		}
		if ((*i)->isBaseDefense() && !(*i)->success)
		{
			xcomBasesLost++;
		}
	}
	// Make sure dummy values aren't left in
	bestScore = (bestScore == -9999) ? 0 : bestScore;
	worstScore = (worstScore == 9999) ? 0 : worstScore;

	std::vector<Soldier*> allSoldiers;
	for (std::vector<Base*>::const_iterator i = save->getBases()->begin(); i != save->getBases()->end(); ++i)
	{
		allSoldiers.insert(allSoldiers.end(), (*i)->getSoldiers()->begin(), (*i)->getSoldiers()->end());
	}
	allSoldiers.insert(allSoldiers.end(), save->getDeadSoldiers()->begin(), save->getDeadSoldiers()->end());
	int soldiersRecruited = allSoldiers.size();
	int soldiersLost = save->getDeadSoldiers()->size();

	int aliensKilled = 0, aliensCaptured = 0, friendlyKills = 0;
	int daysWounded = 0, longestMonths = 0;
	int shotsFired = 0, shotsLanded = 0;
	std::map<std::string, int> weaponKills, alienKills;
	for (std::vector<Soldier*>::iterator i = allSoldiers.begin(); i != allSoldiers.end(); ++i)
	{
		SoldierDiary *diary = (*i)->getDiary();
		aliensKilled += diary->getKillTotal();
		aliensCaptured += diary->getStunTotal();
		daysWounded += diary->getDaysWoundedTotal();
		longestMonths = std::max(longestMonths, diary->getMonthsService());
		std::map<std::string, int> weaponTotal = diary->getWeaponTotal();
		shotsFired += diary->getShotsFiredTotal();
		shotsLanded += diary->getShotsLandedTotal();
		for (std::map<std::string, int>::const_iterator j = weaponTotal.begin(); j != weaponTotal.end(); ++j)
		{
			if (weaponKills.find(j->first) == weaponKills.end())
			{
				weaponKills[j->first] = j->second;
			}
			else
			{
				weaponKills[j->first] += j->second;
			}
		}

		if ((*i)->getDeath() != 0 && (*i)->getDeath()->getCause() != 0)
		{
			const BattleUnitKills *kills = (*i)->getDeath()->getCause();
			if (kills->faction == FACTION_PLAYER)
			{
				friendlyKills++;
			}
			if (!kills->race.empty())
			{
				if (alienKills.find(kills->race) == alienKills.end())
				{
					alienKills[kills->race] = 1;
				}
				else
				{
					alienKills[kills->race] += 1;
				}
			}
		}
	}
	int accuracy = 0;
	if (shotsFired > 0)
	{
		accuracy = 100 * shotsLanded / shotsFired;
	}

	int maxWeapon = 0;
	std::string highestWeapon = "STR_NONE";
	for (std::map<std::string, int>::const_iterator i = weaponKills.begin(); i != weaponKills.end(); ++i)
	{
		if (i->second > maxWeapon)
		{
			maxWeapon = i->second;
			highestWeapon = i->first;
		}
	}
	int maxAlien = 0;
	std::string highestAlien = "STR_NONE";
	for (std::map<std::string, int>::const_iterator i = alienKills.begin(); i != alienKills.end(); ++i)
	{
		if (i->second > maxAlien)
		{
			maxAlien = i->second;
			highestAlien = i->first;
		}
	}

	std::map<std::string, int> ids = save->getAllIds();
	int alienBases = alienBasesDestroyed;
	for (std::vector<AlienBase*>::iterator i = save->getAlienBases()->begin(); i != save->getAlienBases()->end(); ++i)
	{
		if ((*i)->isDiscovered())
		{
			alienBases++;
		}
	}
	int ufosDetected = std::max(0, ids["STR_UFO"] - 1);
	int terrorSites = std::max(0, ids["STR_TERROR_SITE"] - 1);
	int totalCrafts = 0;
	for (std::vector<std::string>::const_iterator i = _game->getMod()->getCraftsList().begin(); i != _game->getMod()->getCraftsList().end(); ++i)
	{
		totalCrafts += std::max(0, ids[*i] - 1);
	}

	int xcomBases = save->getBases()->size() + xcomBasesLost;
	int currentScientists = 0, currentEngineers = 0;
	for (std::vector<Base*>::const_iterator i = save->getBases()->begin(); i != save->getBases()->end(); ++i)
	{
		currentScientists += (*i)->getTotalScientists();
		currentEngineers += (*i)->getTotalEngineers();
	}

	int countriesLost = 0;
	for (std::vector<Country*>::const_iterator i = save->getCountries()->begin(); i != save->getCountries()->end(); ++i)
	{
		if ((*i)->getPact())
		{
			countriesLost++;
		}
	}

	int researchDone = save->getDiscoveredResearch().size();

	std::string difficulty[] = { "STR_1_BEGINNER", "STR_2_EXPERIENCED", "STR_3_VETERAN", "STR_4_GENIUS", "STR_5_SUPERHUMAN" };

	_lstStats->addRow(2, tr("STR_DIFFICULTY").c_str(), tr(difficulty[save->getDifficulty()]).c_str());
	_lstStats->addRow(2, tr("STR_AVERAGE_MONTHLY_RATING").c_str(), Unicode::formatNumber(monthlyScore).c_str());
	_lstStats->addRow(2, tr("STR_TOTAL_INCOME").c_str(), Unicode::formatFunding(totalIncome).c_str());
	_lstStats->addRow(2, tr("STR_TOTAL_EXPENDITURE").c_str(), Unicode::formatFunding(totalExpenses).c_str());
	_lstStats->addRow(2, tr("STR_MISSIONS_WON").c_str(), Unicode::formatNumber(missionsWin).c_str());
	_lstStats->addRow(2, tr("STR_MISSIONS_LOST").c_str(), Unicode::formatNumber(missionsLoss).c_str());
	_lstStats->addRow(2, tr("STR_NIGHT_MISSIONS").c_str(), Unicode::formatNumber(nightMissions).c_str());
	_lstStats->addRow(2, tr("STR_BEST_RATING").c_str(), Unicode::formatNumber(bestScore).c_str());
	_lstStats->addRow(2, tr("STR_WORST_RATING").c_str(), Unicode::formatNumber(worstScore).c_str());
	_lstStats->addRow(2, tr("STR_SOLDIERS_RECRUITED").c_str(), Unicode::formatNumber(soldiersRecruited).c_str());
	_lstStats->addRow(2, tr("STR_SOLDIERS_LOST").c_str(), Unicode::formatNumber(soldiersLost).c_str());
	_lstStats->addRow(2, tr("STR_ALIEN_KILLS").c_str(), Unicode::formatNumber(aliensKilled).c_str());
	_lstStats->addRow(2, tr("STR_ALIEN_CAPTURES").c_str(), Unicode::formatNumber(aliensCaptured).c_str());
	_lstStats->addRow(2, tr("STR_FRIENDLY_KILLS").c_str(), Unicode::formatNumber(friendlyKills).c_str());
	_lstStats->addRow(2, tr("STR_AVERAGE_ACCURACY").c_str(), Unicode::formatPercentage(accuracy).c_str());
	_lstStats->addRow(2, tr("STR_WEAPON_MOST_KILLS").c_str(), tr(highestWeapon).c_str());
	_lstStats->addRow(2, tr("STR_ALIEN_MOST_KILLS").c_str(), tr(highestAlien).c_str());
	_lstStats->addRow(2, tr("STR_LONGEST_SERVICE").c_str(), Unicode::formatNumber(longestMonths).c_str());
	_lstStats->addRow(2, tr("STR_TOTAL_DAYS_WOUNDED").c_str(), Unicode::formatNumber(daysWounded).c_str());
	_lstStats->addRow(2, tr("STR_TOTAL_UFOS").c_str(), Unicode::formatNumber(ufosDetected).c_str());
	_lstStats->addRow(2, tr("STR_TOTAL_ALIEN_BASES").c_str(), Unicode::formatNumber(alienBases).c_str());
	_lstStats->addRow(2, tr("STR_COUNTRIES_LOST").c_str(), Unicode::formatNumber(countriesLost).c_str());
	_lstStats->addRow(2, tr("STR_TOTAL_TERROR_SITES").c_str(), Unicode::formatNumber(terrorSites).c_str());
	_lstStats->addRow(2, tr("STR_TOTAL_BASES").c_str(), Unicode::formatNumber(xcomBases).c_str());
	_lstStats->addRow(2, tr("STR_TOTAL_CRAFT").c_str(), Unicode::formatNumber(totalCrafts).c_str());
	_lstStats->addRow(2, tr("STR_TOTAL_SCIENTISTS").c_str(), Unicode::formatNumber(currentScientists).c_str());
	_lstStats->addRow(2, tr("STR_TOTAL_ENGINEERS").c_str(), Unicode::formatNumber(currentEngineers).c_str());
	_lstStats->addRow(2, tr("STR_TOTAL_RESEARCH").c_str(), Unicode::formatNumber(researchDone).c_str());
}
Esempio n. 10
0
int main( int argc, char* argv[] ) {


  DrawTools::setStyle();

  std::string inputDir = "./analysisTrees";
  std::string runName = "323";
  std::string tag = "V01";

  if( argc == 3 ) {
    std::string runName_str(argv[1]);
    runName = runName_str;
    std::string tag_str(argv[2]);
    tag = tag_str;
  }else if (argc==4){
    std::string inputDir_str(argv[2]);
    inputDir =inputDir_str;
  } else{
    std::cout<<"Usage:"<<std::endl;
    std::cout<<"./calibrateCef3 runNr tag [inputDir]"<<std::endl;
    exit(12345);
  }

  if(tag!="default") inputDir = inputDir + "_"+tag;



  TFile* file = TFile::Open(Form("%s/Reco_%s.root", inputDir.c_str(),runName.c_str()));
  std::cout<<"opening file:"<<file->GetName();


  TTree* tree = (TTree*)file->Get("recoTree");

  std::string outputdir = "CeF3Calibration/";
  std::string mkdir_command = "mkdir -p " + outputdir;
  system( mkdir_command.c_str() );

  std::string ofsName = outputdir +Form( "/constants_%s_%s.txt", runName.c_str(), tag.c_str() );
  ofstream ofs(ofsName.c_str());
  std::string ofsNameU = outputdir + Form( "/constants_uncert_%s_%s.txt", runName.c_str(), tag.c_str() );
  ofstream ofsU(ofsNameU.c_str());



  std::vector<float> cef3_calibration;
  std::vector<float> cef3_calib_uncert;


  for( unsigned i=0; i<4; ++i ) {
    TF1* f1 = fitSingleElectronPeak( outputdir, i, tree );
    float mean  = f1->GetParameter(1);
    float sigma = f1->GetParameter(2);
    float mean_err = f1->GetParError(1);
    std::cout << std::endl;
    std::cout << "Channel " << i << std::endl;
    std::cout << "  Mean       : " << mean << std::endl;
    std::cout << "  Sigma      : " << sigma << std::endl;
    std::cout << "  Resolution : " << sigma/mean << std::endl;

    cef3_calibration.push_back(mean);
    cef3_calib_uncert.push_back(mean_err);
  }


  float cef3CalibrationAverage = sumVector(cef3_calibration)/cef3_calibration.size();

  for(unsigned i=0; i<cef3_calibration.size(); ++i ){
    cef3_calib_uncert[i] = abs(cef3CalibrationAverage-cef3_calibration[i]/4.)/(cef3_calibration[i]*cef3_calibration[i])*cef3_calib_uncert[i];
    ofsU << cef3_calib_uncert[i] << std::endl;

    cef3_calibration[i] = cef3CalibrationAverage/cef3_calibration[i];
    ofs << cef3_calibration[i] << std::endl;
  }



  ofs.close();
  ofsU.close();


  if(checkIntercal == true){
    checkIntercalibration(cef3_calibration, cef3_calib_uncert, outputdir, runName, tag);
  }

  std::cout << "-> Saved constants in: " << ofsName << std::endl;


  checkTotalResolution( outputdir, tree );




  return 0;

}
Esempio n. 11
0
int main( int argc, char* argv[] ) {


  std::string runName = "precalib_BGO_pedestal_noSource";
  if( argc>1 ) {
    std::string runName_str(argv[1]);
    runName = runName_str;
  }

  std::string tag = "V00";
  if( argc>2 ) {
    std::string tag_str(argv[2]);
    tag = tag_str;
  }

  TString runName_tstr(runName);
  bool isOnlyRunNumber = !(runName_tstr.BeginsWith("BTF_"));


  TChain* tree = new TChain("recoTree");
  if( isOnlyRunNumber ) {
    std::cout << "-> We believe you are passing the program only the run number!" << std::endl;
    std::cout << "-> So for instance you are passing '246' for run 'BTF_246_20140501-212512_beam'" << std::endl;
    std::cout << "(if this is not the case this means TROUBLE)" << std::endl;
    std::cout << "-> Will look for runs matching run number: " << runName << std::endl;
    tree->Add(Form("analysisTrees_%s/Reco_BTF_%s_*beam.root/recoTree", tag.c_str(), runName.c_str()) );
    if( tree->GetEntries()==0 ) {
      std::cout << "WARNING! Didn't find any events matching run: " << runName << std::endl;
      std::cout << "Exiting" << std::endl;
      exit(1913);
    }
  } else {
    std::string fileName = "analysisTrees_"+tag+"/Reco_" + runName + ".root";
    TFile* file = TFile::Open(fileName.c_str());
    if( file==0 ) {
      std::cout << "ERROR! Din't find file " << fileName << std::endl;
      std::cout << "Exiting." << std::endl;
      exit(11);
    }
    tree = (TChain*)file->Get("recoTree");
  }





  UInt_t evtNumber;
  tree->SetBranchAddress( "evtNumber", &evtNumber );
  UInt_t adcData[40];
  tree->SetBranchAddress( "adcData", adcData );
  UInt_t adcBoard[40];
  tree->SetBranchAddress( "adcBoard", adcBoard );
  UInt_t adcChannel[40];
  tree->SetBranchAddress( "adcChannel", adcChannel );


  unsigned int runNumber;
  int nHodoFibersX;
  int nHodoFibersY;
  int nHodoClustersX;
  int nHodoClustersY;
  float cef3_corr[CEF3_CHANNELS];
  float bgo_corr[BGO_CHANNELS];
  float scintFront;
  float pos_hodoClustX[HODOX_CHANNELS];
  float pos_hodoClustY[HODOY_CHANNELS];
  int nFibres_hodoClustX[HODOX_CHANNELS];
  int nFibres_hodoClustY[HODOY_CHANNELS];
  float xBeam, yBeam;
  bool isSingleEle_scintFront;
  bool cef3_ok;
  bool cef3_corr_ok;
  bool bgo_ok;
  bool bgo_corr_ok;

  tree->SetBranchAddress( "runNumber", &runNumber );

  tree->SetBranchAddress( "scintFront", &scintFront );
  tree->SetBranchAddress( "cef3_corr", cef3_corr );
  tree->SetBranchAddress( "bgo_corr", bgo_corr );

  tree->SetBranchAddress( "nHodoFibersX", &nHodoFibersX );
  tree->SetBranchAddress( "nHodoFibersY", &nHodoFibersY );
  tree->SetBranchAddress( "nHodoClustersX", &nHodoClustersX );
  tree->SetBranchAddress( "pos_hodoClustX", pos_hodoClustX );
  tree->SetBranchAddress( "nFibres_hodoClustX", nFibres_hodoClustX );
  tree->SetBranchAddress( "nHodoClustersY", &nHodoClustersY );
  tree->SetBranchAddress( "pos_hodoClustY", pos_hodoClustY );
  tree->SetBranchAddress( "nFibres_hodoClustY", nFibres_hodoClustY );
  tree->SetBranchAddress( "scintFront", &scintFront );
  tree->SetBranchAddress( "isSingleEle_scintFront", &isSingleEle_scintFront );
  tree->SetBranchAddress( "xBeam", &xBeam );
  tree->SetBranchAddress( "yBeam", &yBeam );

  tree->SetBranchAddress( "cef3_ok", &cef3_ok );
  tree->SetBranchAddress( "cef3_corr_ok", &cef3_corr_ok );
  tree->SetBranchAddress( "bgo_ok", &bgo_ok );
  tree->SetBranchAddress( "bgo_corr_ok", &bgo_corr_ok );




  int nBins = 500;
  float xMax = 25.*3./2.;


  TH1D* h1_xPos = new TH1D("xPos", "", nBins, -xMax, xMax);
  TH1D* h1_yPos = new TH1D("yPos", "", nBins, -xMax, xMax);
  TH2D* h2_xyPos = new TH2D("xyPos", "", nBins, -xMax, xMax, nBins, -xMax, xMax);

  TH1D* h1_xPos_singleEle = new TH1D("xPos_singleEle", "", nBins, -xMax, xMax);
  TH1D* h1_yPos_singleEle = new TH1D("yPos_singleEle", "", nBins, -xMax, xMax);
  TH2D* h2_xyPos_singleEle = new TH2D("xyPos_singleEle", "", nBins, -xMax, xMax, nBins, -xMax, xMax);

  TH1D* h1_xPos_new = new TH1D("xPos_new", "", nBins, -xMax, xMax);
  TH1D* h1_yPos_new = new TH1D("yPos_new", "", nBins, -xMax, xMax);
  TH2D* h2_xyPos_new = new TH2D("xyPos_new", "", nBins, -xMax, xMax, nBins, -xMax, xMax);

  TH1D* h1_xPos_new_singleEle = new TH1D("xPos_new_singleEle", "", nBins, -xMax, xMax);
  TH1D* h1_yPos_new_singleEle = new TH1D("yPos_new_singleEle", "", nBins, -xMax, xMax);
  TH2D* h2_xyPos_new_singleEle = new TH2D("xyPos_new_singleEle", "", nBins, -xMax, xMax, nBins, -xMax, xMax);


  TH1D* h1_xPos_bgo = new TH1D("xPos_bgo", "", nBins, -xMax, xMax);
  TH1D* h1_yPos_bgo = new TH1D("yPos_bgo", "", nBins, -xMax, xMax);
  TH2D* h2_xyPos_bgo = new TH2D("xyPos_bgo", "", nBins, -xMax, xMax, nBins, -xMax, xMax);

  TH1D* h1_xPos_singleEle_bgo = new TH1D("xPos_singleEle_bgo", "", nBins, -xMax, xMax);
  TH1D* h1_yPos_singleEle_bgo = new TH1D("yPos_singleEle_bgo", "", nBins, -xMax, xMax);
  TH2D* h2_xyPos_singleEle_bgo = new TH2D("xyPos_singleEle_bgo", "", nBins, -xMax, xMax, nBins, -xMax, xMax);

  TH1D* h1_xPos_hodo = new TH1D("xPos_hodo", "", nBins, -xMax, xMax);
  TH1D* h1_yPos_hodo = new TH1D("yPos_hodo", "", nBins, -xMax, xMax);
  TH2D* h2_xyPos_hodo = new TH2D("xyPos_hodo", "", nBins, -xMax, xMax, nBins, -xMax, xMax);

  TH1D* h1_xPos_singleEle_hodo = new TH1D("xPos_singleEle_hodo", "", nBins, -xMax, xMax);
  TH1D* h1_yPos_singleEle_hodo = new TH1D("yPos_singleEle_hodo", "", nBins, -xMax, xMax);
  TH2D* h2_xyPos_singleEle_hodo = new TH2D("xyPos_singleEle_hodo", "", nBins, -xMax, xMax, nBins, -xMax, xMax);

  TH1D* h1_xPos_singleEle_hodoClust = new TH1D("xPos_singleEle_hodoClust", "", nBins, -xMax, xMax);
  TH1D* h1_yPos_singleEle_hodoClust = new TH1D("yPos_singleEle_hodoClust", "", nBins, -xMax, xMax);
  TH2D* h2_xyPos_singleEle_hodoClust = new TH2D("xyPos_singleEle_hodoClust", "", nBins, -xMax, xMax, nBins, -xMax, xMax);

  TH1D* h1_xPos_calo = new TH1D("xPos_calo", "", nBins, -xMax, xMax);
  TH1D* h1_yPos_calo = new TH1D("yPos_calo", "", nBins, -xMax, xMax);
  TH2D* h2_xyPos_calo = new TH2D("xyPos_calo", "", nBins, -xMax, xMax, nBins, -xMax, xMax);

  TH1D* h1_xPos_singleEle_calo = new TH1D("xPos_singleEle_calo", "", nBins, -xMax, xMax);
  TH1D* h1_yPos_singleEle_calo = new TH1D("yPos_singleEle_calo", "", nBins, -xMax, xMax);
  TH2D* h2_xyPos_singleEle_calo = new TH2D("xyPos_singleEle_calo", "", nBins, -xMax, xMax, nBins, -xMax, xMax);

  TH1D* h1_xPos_calo_vs_hodo = new TH1D("xPos_calo_vs_hodo", "", nBins, -xMax, xMax);
  TH1D* h1_yPos_calo_vs_hodo = new TH1D("yPos_calo_vs_hodo", "", nBins, -xMax, xMax);

  TH1D* h1_xPos_calo_vs_beam = new TH1D("xPos_calo_vs_beam", "", nBins, -xMax, xMax);
  TH1D* h1_yPos_calo_vs_beam = new TH1D("yPos_calo_vs_beam", "", nBins, -xMax, xMax);

  TH1D* h1_xPos_calo_vs_hodo_singleElectron = new TH1D("xPos_calo_vs_hodo_singleElectron", "", nBins, -xMax, xMax);
  TH1D* h1_yPos_calo_vs_hodo_singleElectron = new TH1D("yPos_calo_vs_hodo_singleElectron", "", nBins, -xMax, xMax);

  TH1D* h1_xPos_calo_vs_beam_singleElectron = new TH1D("xPos_calo_vs_beam_singleElectron", "", nBins, -xMax, xMax);
  TH1D* h1_yPos_calo_vs_beam_singleElectron = new TH1D("yPos_calo_vs_beam_singleElectron", "", nBins, -xMax, xMax);

  TH1D* h1_xPos_calo_vs_hodo_singleElectron_HR = new TH1D("xPos_calo_vs_hodo_singleElectron_HR", "", nBins, -xMax, xMax);
  TH1D* h1_yPos_calo_vs_hodo_singleElectron_HR = new TH1D("yPos_calo_vs_hodo_singleElectron_HR", "", nBins, -xMax, xMax);

  TH1D* h1_xPos_calo_vs_beam_singleElectron_HR = new TH1D("xPos_calo_vs_beam_singleElectron_HR", "", nBins, -xMax, xMax);
  TH1D* h1_yPos_calo_vs_beam_singleElectron_HR = new TH1D("yPos_calo_vs_beam_singleElectron_HR", "", nBins, -xMax, xMax);


  TH2D* h2_correlation_cef3_hodo_xPos = new TH2D("correlation_cef3_hodo_xPos", "", 100, -12.5, 12.5,  100, -12.5, 12.5);
  TH2D* h2_correlation_cef3_hodo_yPos = new TH2D("correlation_cef3_hodo_yPos", "", 100, -12.5, 12.5,  100, -12.5, 12.5);

  TH2D* h2_correlation_cef3_bgo_xPos = new TH2D("correlation_cef3_bgo_xPos", "", 100, -12.5, 12.5,  100, -12.5, 12.5);
  TH2D* h2_correlation_cef3_bgo_yPos = new TH2D("correlation_cef3_bgo_yPos", "", 100, -12.5, 12.5,  100, -12.5, 12.5);

  TH2D* h2_correlation_hodo_bgo_xPos = new TH2D("correlation_hodo_bgo_xPos", "", 100, -12.5, 12.5,  100, -12.5, 12.5);
  TH2D* h2_correlation_hodo_bgo_yPos = new TH2D("correlation_hodo_bgo_yPos", "", 100, -12.5, 12.5,  100, -12.5, 12.5);


  TH2D* h2_correlation_cef3_hodo_xPos_singleEle = new TH2D("correlation_cef3_hodo_xPos_singleEle", "", 100, -12.5, 12.5,  100, -12.5, 12.5);
  TH2D* h2_correlation_cef3_hodo_yPos_singleEle = new TH2D("correlation_cef3_hodo_yPos_singleEle", "", 100, -12.5, 12.5,  100, -12.5, 12.5);

  TH2D* h2_correlation_cef3_bgo_xPos_singleEle = new TH2D("correlation_cef3_bgo_xPos_singleEle", "", 100, -12.5, 12.5,  100, -12.5, 12.5);
  TH2D* h2_correlation_cef3_bgo_yPos_singleEle = new TH2D("correlation_cef3_bgo_yPos_singleEle", "", 100, -12.5, 12.5,  100, -12.5, 12.5);

  TH2D* h2_correlation_hodo_bgo_xPos_singleEle = new TH2D("correlation_hodo_bgo_xPos_singleEle", "", 100, -12.5, 12.5,  100, -12.5, 12.5);
  TH2D* h2_correlation_hodo_bgo_yPos_singleEle = new TH2D("correlation_hodo_bgo_yPos_singleEle", "", 100, -12.5, 12.5,  100, -12.5, 12.5);



  int nentries = tree->GetEntries();


  if( isOnlyRunNumber ) {
    // modify runname in such a way that it's useful for getBeamPosition and outfile:
    runName = "BTF_" + runName + "_beam";
  }



  std::string outputdir = "PosAnTrees_"+tag;
  system( Form("mkdir -p %s", outputdir.c_str()) );
  std::string outfileName = outputdir + "/PosAn_" + runName + ".root";
  TFile* outfile = TFile::Open( outfileName.c_str(), "RECREATE" );

  TTree* outTree = new TTree("posTree","posTree");
  float xPos_calo_, yPos_calo_;
  float xPos_bgo_, yPos_bgo_;
  float xPos_new_, yPos_new_;
  float xPos_regr2D_, yPos_regr2D_;
  float r02_, r13_;

  outTree->Branch( "isSingleEle_scintFront", &isSingleEle_scintFront, "isSingleEle_scintFront/O" );
  outTree->Branch( "nHodoClustersX", &nHodoClustersX, "nHodoClustersX/I" );
  outTree->Branch( "nHodoClustersY", &nHodoClustersY, "nHodoClustersY/I" );
  outTree->Branch( "cef3_corr", cef3_corr, "cef3_corr[4]/F" );
  outTree->Branch( "r02", &r02_, "r02_/F" );
  outTree->Branch( "r13", &r13_, "r13_/F" );
  outTree->Branch( "xBeam", &xBeam, "xBeam/F" );
  outTree->Branch( "yBeam", &yBeam, "yBeam/F" );
  outTree->Branch( "xPos_bgo", &xPos_bgo_, "xPos_bgo_/F" );
  outTree->Branch( "yPos_bgo", &yPos_bgo_, "yPos_bgo_/F" );
  outTree->Branch( "xPos_calo", &xPos_calo_, "xPos_calo_/F" );
  outTree->Branch( "yPos_calo", &yPos_calo_, "yPos_calo_/F" );
  outTree->Branch( "xPos_new", &xPos_new_, "xPos_new_/F" );
  outTree->Branch( "yPos_new", &yPos_new_, "yPos_new_/F" );
  outTree->Branch( "xPos_regr2D", &xPos_regr2D_, "xPos_regr2D_/F" );
  outTree->Branch( "yPos_regr2D", &yPos_regr2D_, "yPos_regr2D_/F" );

  float diag02_calo_;
  float diag13_calo_;
  outTree->Branch( "diag02_calo", &diag02_calo_, "diag02_calo_/F" );
  outTree->Branch( "diag13_calo", &diag13_calo_, "diag13_calo_/F" );
  float diag02_new_;
  float diag13_new_;
  outTree->Branch( "diag02_new", &diag02_new_, "diag02_new_/F" );
  outTree->Branch( "diag13_new", &diag13_new_, "diag13_new_/F" );
  float diag02_beam_;
  float diag13_beam_;
  outTree->Branch( "diag02_beam", &diag02_beam_, "diag02_beam_/F" );
  outTree->Branch( "diag13_beam", &diag13_beam_, "diag13_beam_/F" );

  
  std::vector<float> xbgo, ybgo;
  for( unsigned i=0; i<BGO_CHANNELS; ++i ) {
    float x,y;
    RunHelper::getBGOCoordinates( i, x, y );
    xbgo.push_back( x );
    ybgo.push_back( y );
  }


  
  



  float cef3_regr[CEF3_CHANNELS];
  //TMVA::Reader* readerRegrX = new TMVA::Reader( "!Color:!Silent" );
  //readerRegrX->AddVariable("cef3_corr[0]/(cef3_corr[0]+cef3_corr[1]+cef3_corr[2]+cef3_corr[3])", &cef3_regr[0] );
  //readerRegrX->AddVariable("cef3_corr[1]/(cef3_corr[0]+cef3_corr[1]+cef3_corr[2]+cef3_corr[3])", &cef3_regr[1] );
  //readerRegrX->AddVariable("cef3_corr[2]/(cef3_corr[0]+cef3_corr[1]+cef3_corr[2]+cef3_corr[3])", &cef3_regr[2] );
  //readerRegrX->AddVariable("cef3_corr[3]/(cef3_corr[0]+cef3_corr[1]+cef3_corr[2]+cef3_corr[3])", &cef3_regr[3] );

  //TMVA::Reader* readerRegrY = new TMVA::Reader( "!Color:!Silent" );
  //readerRegrY->AddVariable("cef3_corr[0]/(cef3_corr[0]+cef3_corr[1]+cef3_corr[2]+cef3_corr[3])", &cef3_regr[0] );
  //readerRegrY->AddVariable("cef3_corr[1]/(cef3_corr[0]+cef3_corr[1]+cef3_corr[2]+cef3_corr[3])", &cef3_regr[1] );
  //readerRegrY->AddVariable("cef3_corr[2]/(cef3_corr[0]+cef3_corr[1]+cef3_corr[2]+cef3_corr[3])", &cef3_regr[2] );
  //readerRegrY->AddVariable("cef3_corr[3]/(cef3_corr[0]+cef3_corr[1]+cef3_corr[2]+cef3_corr[3])", &cef3_regr[3] ); // let try this trick

  //TMVA::Reader* readerRegr2D = new TMVA::Reader( "!Color:!Silent" );
  //readerRegr2D->AddVariable("cef3_corr[0]", &cef3_corr_[0] );
  //readerRegr2D->AddVariable("cef3_corr[1]", &cef3_corr_[1] );
  //readerRegr2D->AddVariable("cef3_corr[2]", &cef3_corr_[2] );
  //readerRegr2D->AddVariable("cef3_corr[3]", &cef3_corr_[3] );
  //readerRegr2D->BookMVA( "MLP", "TMVA/weights/TMVARegression_MLP.weights.xml" );


  std::vector<std::string> methodNames;
  //methodNames.push_back("BDTG");
  ////methodNames.push_back("FDA_MT");
  //methodNames.push_back("LD");
  //methodNames.push_back("MLP");
  ////methodNames.push_back("PDERS");

 
  //
  //std::cout << "-> Booking TMVA Reader" << std::endl;
  //for( unsigned i=0; i<methodNames.size(); ++i ) {
  //  readerRegrX->BookMVA( methodNames[i], Form("TMVA/weights/TMVARegression_%s.weights.xml", methodNames[i].c_str()) ); 
  //  readerRegrY->BookMVA( methodNames[i], Form("TMVA/weights/TMVARegression_%s.weights.xml", methodNames[i].c_str()) ); 
  //}


  std::vector< TH1D* > h1_xPos_regr_vs_calo;
  std::vector< TH1D* > h1_yPos_regr_vs_calo;
  std::vector< TH2D* > h2_xyPos_regr;
  std::vector< TH1D* > h1_xPos_regr_vs_calo_singleEle;
  std::vector< TH1D* > h1_yPos_regr_vs_calo_singleEle;
  std::vector< TH2D* > h2_xyPos_singleEle_regr;
  for( unsigned i=0; i<methodNames.size(); ++i ) {
    TH1D* newHistx = new TH1D( Form("xPos_regr%s_vs_calo", methodNames[i].c_str()), "", nBins, -xMax, xMax);
    h1_xPos_regr_vs_calo.push_back( newHistx );
    TH1D* newHisty = new TH1D( Form("yPos_regr%s_vs_calo", methodNames[i].c_str()), "", nBins, -xMax, xMax);
    h1_yPos_regr_vs_calo.push_back( newHisty );
    TH2D* newHistxy = new TH2D( Form("xyPos_regr%s", methodNames[i].c_str()), "", nBins, -xMax, xMax, nBins, -xMax, xMax);
    h2_xyPos_regr.push_back( newHistxy );
    TH1D* newHistx_singleEle = new TH1D( Form("xPos_regr%s_vs_calo_singleEle", methodNames[i].c_str()), "", nBins, -xMax, xMax);
    h1_xPos_regr_vs_calo_singleEle.push_back( newHistx_singleEle );
    TH1D* newHisty_singleEle = new TH1D( Form("yPos_regr%s_vs_calo_singleEle", methodNames[i].c_str()), "", nBins, -xMax, xMax);
    h1_yPos_regr_vs_calo_singleEle.push_back( newHisty_singleEle );
    TH2D* newHistxy_singleEle = new TH2D( Form("xyPos_singleEle_regr%s", methodNames[i].c_str()), "", nBins, -xMax, xMax, nBins, -xMax, xMax);
    h2_xyPos_singleEle_regr.push_back( newHistxy_singleEle );
  }


  TH2D* h2_xyPos_regr2D = new TH2D("xyPos_regr2D", "", nBins, -xMax, xMax, nBins, -xMax, xMax);
  TH2D* h2_xyPos_singleEle_regr2D = new TH2D("xyPos_singleEle_regr2D", "", nBins, -xMax, xMax, nBins, -xMax, xMax);





  for( unsigned iEntry=0; iEntry<nentries; ++iEntry ) {

    xPos_bgo_ = -999.;
    yPos_bgo_ = -999.;

    xPos_calo_ = -999.;
    yPos_calo_ = -999.;


    tree->GetEntry(iEntry);

    if( iEntry % 5000 == 0 ) std::cout << "Entry: " << iEntry << " / " << nentries << std::endl;

    if( !bgo_corr_ok ) continue;

    r02_ = cef3_corr[0]/cef3_corr[2];
    r13_ = cef3_corr[1]/cef3_corr[3];

    // FIRST GET POSITION FROM HODOSCOPE:


    float xPos_hodo = getMeanposHodo(nHodoClustersX, pos_hodoClustX);
    float yPos_hodo = getMeanposHodo(nHodoClustersY, pos_hodoClustY);



    if( xPos_hodo>-100. )
      h1_xPos_hodo->Fill(xPos_hodo);
    if( yPos_hodo>-100. )
      h1_yPos_hodo->Fill(yPos_hodo);

    if( xPos_hodo>-100. && yPos_hodo>-100. ) 
      h2_xyPos_hodo->Fill(xPos_hodo, yPos_hodo);


    if( isSingleEle_scintFront ) {

      if( xPos_hodo>-100. )
        h1_xPos_singleEle_hodo->Fill(xPos_hodo);
      if( yPos_hodo>-100. )
        h1_yPos_singleEle_hodo->Fill(yPos_hodo);

      if( xPos_hodo>-100. && yPos_hodo>-100. ) 
        h2_xyPos_singleEle_hodo->Fill(xPos_hodo, yPos_hodo);

    }



    std::vector<float> xPosW_bgo;
    std::vector<float> yPosW_bgo;

    std::vector<float> v_bgo_corr;
    for( unsigned i=0; i<BGO_CHANNELS; ++i ) v_bgo_corr.push_back(bgo_corr[i]);

    float eTot_bgo_corr = sumVector(v_bgo_corr);

    if( bgo_ok && bgo_corr_ok ) {

      //   0  1  2
      //   3     4
      //   5  6  7

      xPosW_bgo.push_back(bgo_corr[0]*xbgo[0]);
      xPosW_bgo.push_back(bgo_corr[1]*xbgo[1]);
      xPosW_bgo.push_back(bgo_corr[2]*xbgo[2]);
      xPosW_bgo.push_back(bgo_corr[3]*xbgo[3]);
      xPosW_bgo.push_back(bgo_corr[4]*xbgo[4]);
      xPosW_bgo.push_back(bgo_corr[5]*xbgo[5]);
      xPosW_bgo.push_back(bgo_corr[6]*xbgo[6]);
      xPosW_bgo.push_back(bgo_corr[7]*xbgo[7]);
      
      yPosW_bgo.push_back(bgo_corr[0]*ybgo[0]);
      yPosW_bgo.push_back(bgo_corr[1]*ybgo[1]);
      yPosW_bgo.push_back(bgo_corr[2]*ybgo[2]);
      yPosW_bgo.push_back(bgo_corr[3]*ybgo[3]);
      yPosW_bgo.push_back(bgo_corr[4]*ybgo[4]);
      yPosW_bgo.push_back(bgo_corr[5]*ybgo[5]);
      yPosW_bgo.push_back(bgo_corr[6]*ybgo[6]);
      yPosW_bgo.push_back(bgo_corr[7]*ybgo[7]);
      

      xPos_bgo_ = sumVector( xPosW_bgo )/eTot_bgo_corr;
      yPos_bgo_ = sumVector( yPosW_bgo )/eTot_bgo_corr;
      
      h1_xPos_bgo->Fill( xPos_bgo_ );
      h1_yPos_bgo->Fill( yPos_bgo_ );
      h2_xyPos_bgo->Fill( xPos_bgo_, yPos_bgo_ );

      h2_correlation_hodo_bgo_xPos->Fill( xPos_hodo, xPos_bgo_ );
      h2_correlation_hodo_bgo_yPos->Fill( yPos_hodo, yPos_bgo_ );
      
      if( isSingleEle_scintFront ) {

        h1_xPos_singleEle_bgo->Fill( xPos_bgo_ );
        h1_yPos_singleEle_bgo->Fill( yPos_bgo_ );
        h2_xyPos_singleEle_bgo->Fill( xPos_bgo_, yPos_bgo_ );

        h2_correlation_hodo_bgo_xPos_singleEle->Fill( xPos_hodo, xPos_bgo_ );
        h2_correlation_hodo_bgo_yPos_singleEle->Fill( yPos_hodo, yPos_bgo_ );

      }
      
    }  // if bgo ok



    // THEN USE CeF3 DATA:

    if( cef3_ok ) {


      std::vector<float> v_cef3_corr;
      for(unsigned i=0; i<CEF3_CHANNELS; ++i) v_cef3_corr.push_back(cef3_corr[i]);

      float eTot_corr = sumVector(v_cef3_corr);

      

      if( cef3_corr_ok ) {


        //   0      1
        //          
        //          
        //   3      2


        float position = 12. - 0.696; // using FN's infallible trigonometry

        //std::vector

        std::vector<float> xPosW;
        xPosW.push_back(cef3_corr[0]*(-position));
        xPosW.push_back(cef3_corr[1]*(+position));
        xPosW.push_back(cef3_corr[2]*(+position));
        xPosW.push_back(cef3_corr[3]*(-position));

        std::vector<float> yPosW;
        yPosW.push_back(cef3_corr[0]*(+position));
        yPosW.push_back(cef3_corr[1]*(+position));
        yPosW.push_back(cef3_corr[2]*(-position));
        yPosW.push_back(cef3_corr[3]*(-position));


        getCeF3Position( v_cef3_corr, xPos_new_, yPos_new_ );
        //diag02_new_ = xPos_new_;
        //diag13_new_ = yPos_new_;

        float pi = 3.14159;
        float theta = pi/4.; // 45 degrees 
        TVector2 vnew( xPos_new_, yPos_new_ );
        TVector2 dnew = vnew.Rotate(-theta);
        diag02_new_ = dnew.Y();
        diag13_new_ = dnew.X();


        TVector2 vBeam( xBeam, yBeam );
        TVector2 dBeam = vBeam.Rotate(-theta);
        diag02_beam_ = dBeam.Y();
        diag13_beam_ = dBeam.X();

        float xPos = sumVector(xPosW)/eTot_corr;
        float yPos = sumVector(yPosW)/eTot_corr;

        h1_xPos->Fill( xPos );
        h1_yPos->Fill( yPos );

        h2_xyPos->Fill( xPos, yPos );

        h1_xPos_new->Fill( xPos_new_ );
        h1_yPos_new->Fill( yPos_new_ );

        h2_xyPos_new->Fill( xPos_new_, yPos_new_ );


        // positioning with all 9 calorimeter channels:
        //float xPos_calo = sumVector( xPosW_bgo )/(eTot_bgo_corr + eTot_corr*0.07); // cef3 is in 0,0
        //float yPos_calo = sumVector( yPosW_bgo )/(eTot_bgo_corr + eTot_corr*0.08); // so counts only in denominator
        xPos_calo_ = sumVector( xPosW_bgo )/(eTot_bgo_corr + eTot_corr*0.06); // cef3 is in 0,0
        yPos_calo_ = sumVector( yPosW_bgo )/(eTot_bgo_corr + eTot_corr*0.10); // so counts only in denominator
        //float xPos_calo = sumVector( xPosW_bgo )/(eTot_bgo_corr + eTot_corr*0.791577); // cef3 is in 0,0
        //float yPos_calo = sumVector( yPosW_bgo )/(eTot_bgo_corr + eTot_corr*0.791577); // so counts only in denominator

        TVector2 vcalo( xPos_calo_, yPos_calo_ );
        TVector2 dcalo = vcalo.Rotate(-theta);
        diag02_calo_ = dcalo.Y();
        diag13_calo_ = dcalo.X();

        //xPos_regr2D_ = readerRegr2D->EvaluateRegression( "MLP" )[0];
        //yPos_regr2D_ = readerRegr2D->EvaluateRegression( "MLP" )[1];

        cef3_regr[0] = cef3_corr[0]/(cef3_corr[0]+cef3_corr[1]+cef3_corr[2]+cef3_corr[3]);
        cef3_regr[1] = cef3_corr[1]/(cef3_corr[0]+cef3_corr[1]+cef3_corr[2]+cef3_corr[3]);
        cef3_regr[2] = cef3_corr[2]/(cef3_corr[0]+cef3_corr[1]+cef3_corr[2]+cef3_corr[3]);
        cef3_regr[3] = cef3_corr[3]/(cef3_corr[0]+cef3_corr[1]+cef3_corr[2]+cef3_corr[3]);
  
        if( bgo_ok && bgo_corr_ok ) {

          h1_xPos_calo->Fill( xPos_calo_ );
          h1_yPos_calo->Fill( yPos_calo_ );
          h2_xyPos_calo->Fill( xPos_calo_, yPos_calo_ );

          //for( unsigned i=0; i<methodNames.size(); ++i ) {
          //  Float_t xPos_regr = (readerRegrX->EvaluateRegression( methodNames[i] ))[0];
          //  Float_t yPos_regr = (readerRegrY->EvaluateRegression( methodNames[i] ))[0];
          //  h1_xPos_regr_vs_calo[i]->Fill( xPos_regr-xPos_calo_ );
          //  h1_yPos_regr_vs_calo[i]->Fill( yPos_regr-yPos_calo_ );
          //  h2_xyPos_regr[i]->Fill( xPos_regr, yPos_regr );
          //}
          //h2_xyPos_regr2D->Fill( xPos_regr2D_, yPos_regr2D_ );

          h1_xPos_calo_vs_hodo->Fill( xPos_calo_-xPos_hodo );
          h1_yPos_calo_vs_hodo->Fill( yPos_calo_-yPos_hodo );

          h1_xPos_calo_vs_beam->Fill( xPos_calo_-xBeam );
          h1_yPos_calo_vs_beam->Fill( yPos_calo_-yBeam );

          // CORRELATIONS BETWEEN CALO AND HODO:

          h2_correlation_cef3_bgo_xPos->Fill( xPos, xPos_bgo_ );
          h2_correlation_cef3_bgo_yPos->Fill( yPos, yPos_bgo_ );

        }

        if( isSingleEle_scintFront ) {

          h1_xPos_singleEle->Fill( xPos );
          h1_yPos_singleEle->Fill( yPos );
          h2_xyPos_singleEle->Fill( xPos, yPos );

          h1_xPos_new_singleEle->Fill( xPos_new_ );
          h1_yPos_new_singleEle->Fill( yPos_new_ );
          h2_xyPos_new_singleEle->Fill( xPos_new_, yPos_new_ );

          h1_xPos_calo_vs_hodo_singleElectron->Fill( xPos_calo_-xPos_hodo );
          h1_yPos_calo_vs_hodo_singleElectron->Fill( yPos_calo_-yPos_hodo );

          h1_xPos_calo_vs_beam_singleElectron->Fill( xPos_calo_-xBeam );
          h1_yPos_calo_vs_beam_singleElectron->Fill( yPos_calo_-yBeam );

          if( nHodoClustersX==1 && nHodoClustersY==1 && nFibres_hodoClustX[0]<=2 && nFibres_hodoClustY[0]<=2 ) {

            h1_xPos_calo_vs_hodo_singleElectron_HR->Fill( xPos_calo_-xPos_hodo );
            h1_yPos_calo_vs_hodo_singleElectron_HR->Fill( yPos_calo_-yPos_hodo );
  
            h1_xPos_calo_vs_beam_singleElectron_HR->Fill( xPos_calo_-xBeam );
            h1_yPos_calo_vs_beam_singleElectron_HR->Fill( yPos_calo_-yBeam );

          }


          h2_correlation_cef3_hodo_xPos_singleEle->Fill( xPos, xPos_hodo );
          h2_correlation_cef3_hodo_yPos_singleEle->Fill( yPos, yPos_hodo );

  
          if( bgo_ok && bgo_corr_ok ) {

            h1_xPos_singleEle_calo->Fill( xPos_calo_ );
            h1_yPos_singleEle_calo->Fill( yPos_calo_ );
            h2_xyPos_singleEle_calo->Fill( xPos_calo_, yPos_calo_ );

            //for( unsigned i=0; i<methodNames.size(); ++i ) {
            //  Float_t xPos_regr = (readerRegrX->EvaluateRegression( methodNames[i] ))[0];
            //  Float_t yPos_regr = (readerRegrY->EvaluateRegression( methodNames[i] ))[0];
            //  h1_xPos_regr_vs_calo_singleEle[i]->Fill( xPos_regr-xPos_calo_ );
            //  h1_yPos_regr_vs_calo_singleEle[i]->Fill( yPos_regr-yPos_calo_ );
            //  h2_xyPos_singleEle_regr[i]->Fill( xPos_regr, yPos_regr );
            //}

            //h2_xyPos_singleEle_regr2D->Fill( xPos_regr2D_, yPos_regr2D_ );

            h2_correlation_cef3_bgo_xPos_singleEle->Fill( xPos, xPos_bgo_ );
            h2_correlation_cef3_bgo_yPos_singleEle->Fill( yPos, yPos_bgo_ );

          }

        }

        
        outTree->Fill();


      } // if cef3_ok

    }

  }


  outfile->cd();

  outTree->Write();


  for( unsigned i=0; i<h1_xPos_regr_vs_calo.size(); ++i ) {
    h1_xPos_regr_vs_calo[i]->Write();
    h1_yPos_regr_vs_calo[i]->Write();
    h1_xPos_regr_vs_calo_singleEle[i]->Write();
    h1_yPos_regr_vs_calo_singleEle[i]->Write();
    h2_xyPos_regr[i]->Write();
    h2_xyPos_singleEle_regr[i]->Write();
  }




  h1_xPos->Write();
  h1_yPos->Write();
  h2_xyPos->Write();

  h1_xPos_singleEle->Write();
  h1_yPos_singleEle->Write();
  h2_xyPos_singleEle->Write();

  h1_xPos_new->Write();
  h1_yPos_new->Write();
  h2_xyPos_new->Write();

  h1_xPos_new_singleEle->Write();
  h1_yPos_new_singleEle->Write();
  h2_xyPos_new_singleEle->Write();

  
  
  h1_xPos_bgo->Write();
  h1_yPos_bgo->Write();
  h2_xyPos_bgo->Write();
  

  h1_xPos_hodo->Write();
  h1_yPos_hodo->Write();
  h2_xyPos_hodo->Write();

  
  h1_xPos_calo_vs_hodo->Write();
  h1_yPos_calo_vs_hodo->Write();

  h1_xPos_calo_vs_beam->Write();
  h1_yPos_calo_vs_beam->Write();
  
  h1_xPos_calo_vs_hodo_singleElectron->Write();
  h1_yPos_calo_vs_hodo_singleElectron->Write();

  h1_xPos_calo_vs_beam_singleElectron->Write();
  h1_yPos_calo_vs_beam_singleElectron->Write();
  
  h1_xPos_calo_vs_hodo_singleElectron_HR->Write();
  h1_yPos_calo_vs_hodo_singleElectron_HR->Write();

  h1_xPos_calo_vs_beam_singleElectron_HR->Write();
  h1_yPos_calo_vs_beam_singleElectron_HR->Write();
  

  std::cout << std::endl;

  

  h2_correlation_cef3_hodo_xPos->Write();
  h2_correlation_cef3_hodo_yPos->Write();

  h2_correlation_cef3_bgo_xPos->Write();
  h2_correlation_cef3_bgo_yPos->Write();

  h2_correlation_hodo_bgo_xPos->Write();
  h2_correlation_hodo_bgo_yPos->Write();

  h1_xPos_singleEle_bgo->Write();
  h1_yPos_singleEle_bgo->Write();
  h2_xyPos_singleEle_bgo->Write();
  
  h1_xPos_singleEle_hodo->Write();
  h1_yPos_singleEle_hodo->Write();
  h2_xyPos_singleEle_hodo->Write();

  h1_xPos_singleEle_hodoClust->Write();
  h1_yPos_singleEle_hodoClust->Write();
  h2_xyPos_singleEle_hodoClust->Write();

  h1_xPos_calo->Write();
  h1_yPos_calo->Write();
  h2_xyPos_calo->Write();
  
  h1_xPos_singleEle_calo->Write();
  h1_yPos_singleEle_calo->Write();
  h2_xyPos_singleEle_calo->Write();
  

  h2_correlation_cef3_hodo_xPos_singleEle->Write();
  h2_correlation_cef3_hodo_yPos_singleEle->Write();

  h2_correlation_cef3_bgo_xPos_singleEle->Write();
  h2_correlation_cef3_bgo_yPos_singleEle->Write();

  h2_correlation_hodo_bgo_xPos_singleEle->Write();
  h2_correlation_hodo_bgo_yPos_singleEle->Write();


  outfile->Close();
  std::cout << "-> Histograms saved in: " << outfile->GetName() << std::endl;


  return 0;

}