Example #1
0
int main (int argc, char ** argv)
{

	///Check if all nedeed arguments to parse are there
	if(argc != 2) {
		std::cerr << ">>>>> FastCalibrator::usage: " << argv[0] << " configFileName" << std::endl ;
		return 1;
	}

	std::string configFileName = argv[1];
	boost::shared_ptr<edm::ParameterSet> parameterSet = edm::readConfig(configFileName);
	edm::ParameterSet Options = parameterSet -> getParameter<edm::ParameterSet>("Options");
	parameterSet.reset();

	std::string inputList = "NULL";
	if(Options.existsAs<std::string>("inputList"))
		inputList = Options.getParameter<std::string>("inputList");
	else {
		std::cout << " Exit from code, no input list found" << std::endl;
		std::exit(EXIT_FAILURE);
	}

	std::string inputFileDeadXtal = "NULL";
	if(Options.existsAs<std::string>("inputFileDeadXtal"))
		inputFileDeadXtal = Options.getParameter<std::string>("inputFileDeadXtal");
	else {
		std::cout << " No input File Dead Xtal found! " << std::endl;
	}

	std::string inputTree = "NULL";
	if(Options.existsAs<std::string>("inputTree"))
		inputTree = Options.getParameter<std::string>("inputTree");
	else {
		std::cout << " Exit from code, no input tree found" << std::endl;
		std::exit(EXIT_FAILURE);
	}

	std::string jsonFileName = "NULL";
	if(Options.existsAs<std::string>("jsonFileName"))
		jsonFileName = Options.getParameter<std::string>("jsonFileName");
	else {
		std::cout << " Exit from code, no jsonFile found" << std::endl;
		std::exit(EXIT_FAILURE);
	}

	std::map<int, std::vector<std::pair<int, int> > > jsonMap;
	jsonMap = readJSONFile(jsonFileName);

	std::string miscalibMap = "NULL";
	if(Options.existsAs<std::string>("miscalibMap"))
		miscalibMap = Options.getParameter<std::string>("miscalibMap");
	else {
		std::cout << " no miscalib map found" << std::endl;
	}

	bool isMiscalib = false;
	if(Options.existsAs<bool>("isMiscalib"))
		isMiscalib = Options.getParameter<bool>("isMiscalib");

	bool isSaveEPDistribution = false;
	if(Options.existsAs<bool>("isSaveEPDistribution"))
		isSaveEPDistribution = Options.getParameter<bool>("isSaveEPDistribution");

	bool isMCTruth = false;
	if(Options.existsAs<bool>("isMCTruth"))
		isMCTruth = Options.getParameter<bool>("isMCTruth");

	bool isEPselection = false;
	if(Options.existsAs<bool>("isEPselection"))
		isEPselection = Options.getParameter<bool>("isEPselection");

	bool isPtCut = false;
	if(Options.existsAs<bool>("isPtCut"))
		isPtCut = Options.getParameter<bool>("isPtCut");

	double PtMin = 0.;
	if(Options.existsAs<double>("PtMin"))
		PtMin = Options.getParameter<double>("PtMin");

	bool isfbrem = false;
	if(Options.existsAs<bool>("isfbrem"))
		isfbrem = Options.getParameter<bool>("isfbrem");

	double fbremMax = 100.;
	if(Options.existsAs<double>("fbremMax"))
		fbremMax = Options.getParameter<double>("fbremMax");

	bool isR9selection = false;
	if(Options.existsAs<bool>("isR9selection"))
		isR9selection = Options.getParameter<bool>("isR9selection");

	double R9Min = -1.;
	if(Options.existsAs<double>("R9Min"))
		R9Min = Options.getParameter<double>("R9Min");

	int miscalibMethod = 1;
	if(Options.existsAs<double>("miscalibMethod"))
		miscalibMethod = Options.getParameter<double>("miscalibMethod");

	std::string inputMomentumScale = "NULL";
	if(Options.existsAs<std::string>("inputMomentumScale"))
		inputMomentumScale = Options.getParameter<std::string>("inputMomentumScale");

	std::string typeEB = "NULL";
	if(Options.existsAs<std::string>("typeEB"))
		typeEB = Options.getParameter<std::string>("typeEB");

	std::string typeEE = "NULL";
	if(Options.existsAs<std::string>("typeEE"))
		typeEE = Options.getParameter<std::string>("typeEE");
	int nRegionsEE = GetNRegionsEE(typeEE);

	std::string outputPath = "output/Oct22_Run2012ABC_Cal_Dic2012/";
	if(Options.existsAs<std::string>("outputPath"))
		outputPath = Options.getParameter<std::string>("outputPath");
	system(("mkdir -p " + outputPath).c_str());

	std::string outputFile = "FastCalibrator_Oct22_Run2012ABC_Cal_Dic2012";
	if(Options.existsAs<std::string>("outputFile"))
		outputFile = Options.getParameter<std::string>("outputFile");

	int numberOfEvents = -1;
	if(Options.existsAs<int>("numberOfEvents"))
		numberOfEvents = Options.getParameter<int>("numberOfEvents");

	int useZ = 1;
	if(Options.existsAs<int>("useZ"))
		useZ = Options.getParameter<int>("useZ");

	int useW = 1;
	if(Options.existsAs<int>("useW"))
		useW = Options.getParameter<int>("useW");

	int splitStat = 0;
	if(Options.existsAs<int>("splitStat"))
		splitStat = Options.getParameter<int>("splitStat");

	int nLoops = 20;
	if(Options.existsAs<int>("nLoops"))
		nLoops = Options.getParameter<int>("nLoops");

	bool isDeadTriggerTower = false;
	if(Options.existsAs<bool>("isDeadTriggerTower"))
		isDeadTriggerTower = Options.getParameter<bool>("isDeadTriggerTower");


	/// Acquistion input ntuples
	TChain * tree = new TChain (inputTree.c_str());
	FillChain(*tree, inputList);

	/// open calibration momentum graph
	TFile* f4 = new TFile((inputMomentumScale + "_" + typeEB + "_" + typeEE + ".root").c_str());
	std::vector<TGraphErrors*> g_EoC_EE;

	for(int i = 0; i < nRegionsEE; ++i) {
		TString Name = Form("g_EoC_EE_%d", i);
		g_EoC_EE.push_back( (TGraphErrors*)(f4->Get(Name)) );
	}

	///Use the whole sample statistics if numberOfEvents < 0
	if ( numberOfEvents < 0 ) numberOfEvents = tree->GetEntries();


	/// run in normal mode: full statistics
	if ( splitStat == 0 ) {

		TString name ;
		TString name_tmp;

		if(isMiscalib == true && useZ == 1 && isR9selection == true && isEPselection == false && isfbrem == false && isPtCut == false )
			name_tmp = Form ("%s_WZ_R9_miscalib_EE", outputFile.c_str());
		else if(isMiscalib == true && useZ == 1 && isR9selection == false && isEPselection == false && isfbrem == true && isPtCut == false )
			name_tmp = Form ("%s_WZ_Fbrem_miscalib_EE", outputFile.c_str());
		else if(isMiscalib == true && useZ == 1 && isR9selection == true && isEPselection == false && isfbrem == false && isPtCut == true )
			name_tmp = Form ("%s_WZ_PT_miscalib_EE", outputFile.c_str());
		else if(isMiscalib == true && useZ == 1 && isR9selection == true && isEPselection == true && isfbrem == false && isPtCut == false )
			name_tmp = Form ("%s_WZ_EP_miscalib_EE", outputFile.c_str());
		else if(isMiscalib == true && useZ == 1 && isEPselection == false && isR9selection == false && isPtCut == false && isfbrem == false  )
			name_tmp = Form ("%s_WZ_noEP_miscalib_EE", outputFile.c_str());

		else if(isMiscalib == false && useZ == 1 && isR9selection == true && isEPselection == false && isfbrem == false && isPtCut == false )
			name_tmp = Form ("%s_WZ_R9_EE", outputFile.c_str());
		else if(isMiscalib == false && useZ == 1 && isR9selection == false && isEPselection == false && isfbrem == true && isPtCut == false )
			name_tmp = Form ("%s_WZ_Fbrem_EE", outputFile.c_str());
		else if(isMiscalib == false && useZ == 1 && isR9selection == true && isEPselection == false && isfbrem == false && isPtCut == true )
			name_tmp = Form ("%s_WZ_PT_EE", outputFile.c_str());
		else if(isMiscalib == false && useZ == 1 && isR9selection == true && isEPselection == true && isfbrem == false && isPtCut == false )
			name_tmp = Form ("%s_WZ_EP_EE", outputFile.c_str());
		else if(isMiscalib == false && useZ == 1 && isEPselection == false && isR9selection == false && isPtCut == false && isfbrem == false  )
			name_tmp = Form ("%s_WZ_noEP_EE", outputFile.c_str());



		else if(isMiscalib == true && useZ == 0 && isR9selection == true && isEPselection == false && isfbrem == false && isPtCut == false )
			name_tmp = Form ("%s_W_R9_miscalib_EE", outputFile.c_str());
		else if(isMiscalib == true && useZ == 0 && isR9selection == false && isEPselection == false && isfbrem == true && isPtCut == false )
			name_tmp = Form ("%s_W_Fbrem_miscalib_EE", outputFile.c_str());
		else if(isMiscalib == true && useZ == 0 && isR9selection == true && isEPselection == false && isfbrem == false && isPtCut == true )
			name_tmp = Form ("%s_W_PT_miscalib_EE", outputFile.c_str());
		else if(isMiscalib == true && useZ == 0 && isR9selection == true && isEPselection == true && isfbrem == false && isPtCut == false )
			name_tmp = Form ("%s_W_EP_miscalib_EE", outputFile.c_str());
		else if(isMiscalib == true && useZ == 0 && isEPselection == false && isR9selection == false && isPtCut == false && isfbrem == false  )
			name_tmp = Form ("%s_W_noEP_miscalib_EE", outputFile.c_str());

		else if(isMiscalib == false && useZ == 0 && isR9selection == true && isEPselection == false && isfbrem == false && isPtCut == false )
			name_tmp = Form ("%s_WZ_R9_EE", outputFile.c_str());
		else if(isMiscalib == false && useZ == 0 && isR9selection == false && isEPselection == false && isfbrem == true && isPtCut == false )
			name_tmp = Form ("%s_W_Fbrem_EE", outputFile.c_str());
		else if(isMiscalib == false && useZ == 0 && isR9selection == true && isEPselection == false && isfbrem == false && isPtCut == true )
			name_tmp = Form ("%s_W_PT_EE", outputFile.c_str());
		else if(isMiscalib == false && useZ == 0 && isR9selection == true && isEPselection == true && isfbrem == false && isPtCut == false )
			name_tmp = Form ("%s_W_EP_EE", outputFile.c_str());
		else if(isMiscalib == false && useZ == 0 && isEPselection == false && isR9selection == false && isPtCut == false && isfbrem == false  )
			name_tmp = Form ("%s_W_noEP_EE", outputFile.c_str());
		else {
			std::cout << " Option not considered --> exit " << std::endl;
			return -1 ;
		}

		name = Form("%s%s.root", outputPath.c_str(), name_tmp.Data());
		TFile *f1 = new TFile(name, "RECREATE");

		TString outEPDistribution = "Weight_" + name;

		TString DeadXtal = Form("%s", inputFileDeadXtal.c_str());


		if(isSaveEPDistribution == true) {
			FastCalibratorEE analyzer(tree, g_EoC_EE, typeEE, outEPDistribution);
			analyzer.bookHistos(nLoops);
			analyzer.AcquireDeadXtal(DeadXtal, isDeadTriggerTower);
			analyzer.Loop(numberOfEvents, useZ, useW, splitStat, nLoops, isMiscalib, isSaveEPDistribution, isEPselection, isR9selection, R9Min, isfbrem, fbremMax, isPtCut, PtMin, isMCTruth, jsonMap, miscalibMethod, miscalibMap);
			analyzer.saveHistos(f1);
		} else {
			FastCalibratorEE analyzer(tree, g_EoC_EE, typeEE);
			analyzer.bookHistos(nLoops);
			analyzer.AcquireDeadXtal(DeadXtal, isDeadTriggerTower);
			analyzer.Loop(numberOfEvents, useZ, useW, splitStat, nLoops, isMiscalib, isSaveEPDistribution, isEPselection, isR9selection, R9Min, isfbrem, fbremMax, isPtCut, PtMin, isMCTruth, jsonMap, miscalibMethod, miscalibMap);
			analyzer.saveHistos(f1);
		}

	}

	/// run in even-odd mode: half statistics
	else if ( splitStat == 1 ) {

		/// Prepare the outputs
		TString name;
		TString name2;

		if(isMiscalib == true && useZ == 1 && isR9selection == true && isEPselection == false && isfbrem == false && isPtCut == false) {
			name  = Form ("%s_WZ_R9_miscalib_EE_even.root", outputFile.c_str());
			name2 = Form ("%s_WZ_R9_miscalib_EE_odd.root", outputFile.c_str());
		} else if(isMiscalib == true && useZ == 1 && isR9selection == false && isEPselection == true && isfbrem == false && isPtCut == false) {
			name  = Form ("%s_WZ_EP_miscalib_EE_even.root", outputFile.c_str());
			name2 = Form ("%s_WZ_EP_miscalib_EE_odd.root", outputFile.c_str());
		} else if(isMiscalib == true && useZ == 1 && isR9selection == true && isEPselection == false && isfbrem == true && isPtCut == false) {
			name  = Form ("%s_WZ_Fbrem_miscalib_EE_even.root", outputFile.c_str());
			name2 = Form ("%s_WZ_Fbrem_miscalib_EE_odd.root", outputFile.c_str());
		} else if(isMiscalib == true && useZ == 1 && isR9selection == true && isEPselection == false && isfbrem == false && isPtCut == true) {
			name  = Form ("%s_WZ_PT_miscalib_EE_even.root", outputFile.c_str());
			name2 = Form ("%s_WZ_PT_miscalib_EE_odd.root", outputFile.c_str());
		} else if(isMiscalib == true && useZ == 1 && isR9selection == false && isEPselection == false && isfbrem == false && isPtCut == false) {
			name  = Form ("%s_WZ_noEP_miscalib_EE_even.root", outputFile.c_str());
			name2 = Form ("%s_WZ_noEP_miscalib_EE_odd.root", outputFile.c_str());
		}


		else if(isMiscalib == false && useZ == 1 && isR9selection == true && isEPselection == false && isfbrem == false && isPtCut == false) {
			name  = Form ("%s_WZ_R9_EE_even.root", outputFile.c_str());
			name2 = Form ("%s_WZ_R9_EE_odd.root", outputFile.c_str());
		} else if(isMiscalib == false && useZ == 1 && isR9selection == false && isEPselection == true && isfbrem == false && isPtCut == false) {
			name  = Form ("%s_WZ_EP_EE_even.root", outputFile.c_str());
			name2 = Form ("%s_WZ_EP_EE_odd.root", outputFile.c_str());
		} else if(isMiscalib == false && useZ == 1 && isR9selection == false && isEPselection == false && isfbrem == true && isPtCut == false) {
			name  = Form ("%s_WZ_Fbrem_EE_even.root", outputFile.c_str());
			name2 = Form ("%s_WZ_Fbrem_EE_odd.root", outputFile.c_str());
		} else if(isMiscalib == false && useZ == 1 && isR9selection == false && isEPselection == false && isfbrem == false && isPtCut == true) {
			name  = Form ("%s_WZ_PT_EE_even.root", outputFile.c_str());
			name2 = Form ("%s_WZ_PT_EE_odd.root", outputFile.c_str());
		} else if(isMiscalib == false && useZ == 1 && isR9selection == false && isEPselection == false && isfbrem == false && isPtCut == false) {
			name  = Form ("%s_WZ_noEP_EE_even.root", outputFile.c_str());
			name2 = Form ("%s_WZ_noEP_EE_odd.root", outputFile.c_str());
		}


		else if(isMiscalib == true && useZ == 0 && isR9selection == true && isEPselection == false && isfbrem == false && isPtCut == false) {
			name  = Form ("%s_W_R9_miscalib_EE_even.root", outputFile.c_str());
			name2 = Form ("%s_W_R9_miscalib_EE_odd.root", outputFile.c_str());
		}

		else if(isMiscalib == true && useZ == 0 && isR9selection == false && isEPselection == true && isfbrem == false && isPtCut == false) {
			name  = Form ("%s_W_EP_miscalib_EE_even.root", outputFile.c_str());
			name2 = Form ("%s_W_EP_miscalib_EE_odd.root", outputFile.c_str());
		} else if(isMiscalib == true && useZ == 0 && isR9selection == false && isEPselection == false && isfbrem == true && isPtCut == false) {
			name  = Form ("%s_W_Fbrem_miscalib_EE_even.root", outputFile.c_str());
			name2 = Form ("%s_W_Fbrem_miscalib_EE_odd.root", outputFile.c_str());
		} else if(isMiscalib == true && useZ == 0 && isR9selection == false && isEPselection == false && isfbrem == false && isPtCut == true) {
			name  = Form ("%s_W_PT_miscalib_EE_even.root", outputFile.c_str());
			name2 = Form ("%s_W_PT_miscalib_EE_odd.root", outputFile.c_str());
		} else if(isMiscalib == true && useZ == 0 && isR9selection == false && isEPselection == false && isfbrem == false && isPtCut == false) {
			name  = Form ("%s_W_noEP_miscalib_EE_even.root", outputFile.c_str());
			name2 = Form ("%s_W_noEP_miscalib_EE_odd.root", outputFile.c_str());
		}

		else if(isMiscalib == false && useZ == 0 && isR9selection == true && isEPselection == false && isfbrem == false && isPtCut == false) {
			name  = Form ("%s_W_R9_EE_even.root", outputFile.c_str());
			name2 = Form ("%s_W_R9_EE_odd.root", outputFile.c_str());
		}


		else if(isMiscalib == false && useZ == 0 && isR9selection == true && isEPselection == false && isfbrem == false && isPtCut == false) {
			name  = Form ("%s_W_EP_EB_even.root", outputFile.c_str());
			name2 = Form ("%s_W_EP_EB_odd.root", outputFile.c_str());
		} else if(isMiscalib == false && useZ == 0 && isR9selection == false && isEPselection == true && isfbrem == false && isPtCut == false) {
			name  = Form ("%s_W_EP_EB_even.root", outputFile.c_str());
			name2 = Form ("%s_W_EP_EB_odd.root", outputFile.c_str());
		} else if(isMiscalib == false && useZ == 0 && isR9selection == false && isEPselection == false && isfbrem == true && isPtCut == false) {
			name  = Form ("%s_W_Fbrem_EB_even.root", outputFile.c_str());
			name2 = Form ("%s_W_Fbrem_EB_odd.root", outputFile.c_str());
		} else if(isMiscalib == false && useZ == 0 && isR9selection == false && isEPselection == false && isfbrem == false && isPtCut == true) {
			name  = Form ("%s_W_PT_EB_even.root", outputFile.c_str());
			name2 = Form ("%s_W_PT_EB_odd.root", outputFile.c_str());
		} else if(isMiscalib == false && useZ == 0 && isR9selection == true && isEPselection == false && isfbrem == false && isPtCut == false) {
			name  = Form ("%s_W_noEP_EB_even.root", outputFile.c_str());
			name2 = Form ("%s_W_noEP_EB_odd.root", outputFile.c_str());
		} else {
			std::cout << " Option not considered --> exit " << std::endl;
			return -1 ;
		}

		TFile *outputName1 = new TFile(outputPath + name, "RECREATE");
		TFile *outputName2 = new TFile(outputPath + name2, "RECREATE");

		TString DeadXtal = Form("%s", inputFileDeadXtal.c_str());

		/// Run on odd
		FastCalibratorEE analyzer_even(tree, g_EoC_EE, typeEE);
		analyzer_even.bookHistos(nLoops);
		analyzer_even.AcquireDeadXtal(DeadXtal, isDeadTriggerTower);
		analyzer_even.Loop(numberOfEvents, useZ, useW, splitStat, nLoops, isMiscalib, isSaveEPDistribution, isEPselection, isR9selection, R9Min, isfbrem, fbremMax, isPtCut, PtMin, isMCTruth, jsonMap, miscalibMethod, miscalibMap);
		analyzer_even.saveHistos(outputName1);

		/// Run on even
		FastCalibratorEE analyzer_odd(tree, g_EoC_EE, typeEE);
		analyzer_odd.bookHistos(nLoops);
		analyzer_odd.AcquireDeadXtal(DeadXtal, isDeadTriggerTower);
		analyzer_odd.Loop(numberOfEvents, useZ, useW, splitStat * (-1), nLoops, isMiscalib, isSaveEPDistribution, isEPselection, isR9selection, R9Min, isfbrem, fbremMax, isPtCut, PtMin, isMCTruth, jsonMap, miscalibMethod, miscalibMap);
		analyzer_odd.saveHistos(outputName2);

	}

	delete tree;
	return 0;
}
int main (int argc, char ** argv) 
{
    
  ///Check if all nedeed arguments to parse are there
  if(argc != 2)
  {
    std::cerr << ">>>>> FastCalibrator::usage: " << argv[0] << " configFileName" << std::endl ;
    return 1;
  }
    
  /// Parse the config file
  parseConfigFile (argv[1]) ;
 
//   std::string inputFile       = gConfigParser -> readStringOption("Input::inputFile");
  std::string inputList       = gConfigParser -> readStringOption("Input::inputList");

  std::string inputTree       = gConfigParser -> readStringOption("Input::inputTree");

  std::string inputFileDeadXtal ="NULL" ;
  try {
        inputFileDeadXtal = gConfigParser -> readStringOption("Input::inputFileDeadXtal");
   }
   catch ( char const* exceptionString ){
   std::cerr << " exception = " << exceptionString << std::endl;

   }
  bool isMiscalib = gConfigParser -> readBoolOption("Input::isMiscalib");
  bool isSaveEPDistribution = gConfigParser -> readBoolOption("Input::isSaveEPDistribution");
  bool isEPselection = gConfigParser -> readBoolOption("Input::isEPselection");
  bool isR9selection = gConfigParser -> readBoolOption("Input::isR9selection");
  bool isMCTruth = gConfigParser -> readBoolOption("Input::isMCTruth");

  std::string outputFile      = gConfigParser -> readStringOption("Output::outputFile");

 
  
  int numberOfEvents       = gConfigParser -> readIntOption("Options::numberOfEvents");
  int useZ                 = gConfigParser -> readIntOption("Options::useZ");
  int useW                 = gConfigParser -> readIntOption("Options::useW");
  int splitStat            = gConfigParser -> readIntOption("Options::splitStat");
  int nLoops               = gConfigParser -> readIntOption("Options::nLoops");
  
  /// open ntupla of data or MC
  TChain * albero = new TChain (inputTree.c_str());
  FillChain(*albero,inputList); 
  
  ///Use the whole sample statistics if numberOfEvents < 0
  if ( numberOfEvents < 0 ) numberOfEvents = albero->GetEntries(); 
  

  /// run in normal mode: full statistics
  if ( splitStat == 0 ) {
   
    TString name ;
    TString name_tmp;
    if(isMiscalib == true && useZ == 1 && isR9selection ==true ) name_tmp = Form ("%s_Z_R9_miscalib",outputFile.c_str());
    if(isMiscalib == true && useZ == 1 && isEPselection ==true ) name_tmp = Form ("%s_Z_EP_miscalib",outputFile.c_str());
    if(isMiscalib == true && useZ == 1 && isEPselection ==false && isR9selection==false ) name_tmp =Form ("%s_Z_noEP_miscalib",outputFile.c_str());
    
    if(isMiscalib == false && useZ == 1 && isR9selection ==true ) name_tmp = Form ("%s_Z_R9",outputFile.c_str());
    if(isMiscalib == false && useZ == 1 && isEPselection ==true ) name_tmp = Form ("%s_Z_EP",outputFile.c_str());
    if(isMiscalib == false && useZ == 1 && isEPselection ==false && isR9selection==false ) name_tmp =Form ("%s_Z_noEP",outputFile.c_str());
    

    if(isMiscalib == true && useZ == 0 && isR9selection ==true ) name_tmp = Form ("%s_R9_miscalib",outputFile.c_str());
    if(isMiscalib == true && useZ == 0 && isEPselection ==true ) name_tmp = Form ("%s_EP_miscalib",outputFile.c_str());
    if(isMiscalib == true && useZ == 0 && isEPselection ==false && isR9selection==false ) name_tmp =Form ("%s_noEP_miscalib",outputFile.c_str());
    
    
    if(isMiscalib == false && useZ == 0 && isR9selection ==true ) name_tmp = Form ("%s_R9",outputFile.c_str());
    if(isMiscalib == false && useZ == 0 && isEPselection ==true ) name_tmp = Form ("%s_EP",outputFile.c_str());
    if(isMiscalib == false && useZ == 0 && isEPselection ==false && isR9selection==false ) name_tmp =Form ("%s_noEP",outputFile.c_str());
         
    name = Form("%s.root",name_tmp.Data());
    TFile *f1 = new TFile(name,"RECREATE");

    TString outEPDistribution = "Weight_"+name;
    
    TString DeadXtal = Form("%s",inputFileDeadXtal.c_str());    

    if(isSaveEPDistribution == true)
    {
     FastCalibratorEB_MVA analyzer(albero,outEPDistribution);
     analyzer.bookHistos(nLoops);
     analyzer.AcquireDeadXtal(DeadXtal);
     analyzer.Loop(numberOfEvents, useZ, useW, splitStat, nLoops, isMiscalib,isSaveEPDistribution,isEPselection,isR9selection,isMCTruth);
     analyzer.saveHistos(f1);
    }
    else
    {
     FastCalibratorEB_MVA analyzer(albero);
     analyzer.bookHistos(nLoops);
     analyzer.AcquireDeadXtal(DeadXtal);
     analyzer.Loop(numberOfEvents, useZ, useW, splitStat, nLoops, isMiscalib,isSaveEPDistribution,isEPselection,isR9selection,isMCTruth);
     analyzer.saveHistos(f1);
    }
   
  }

  /// run in even-odd mode: half statistics
  else if ( splitStat == 1 ) {
    
    /// Prepare the outputs
    std::string evenFile = "Even_" + outputFile;
    std::string oddFile = "Odd_" + outputFile;
    TString name;
    TString name2;
    
    if(isMiscalib == true && useZ == 1 && isR9selection==true)
    { name = Form ("%s_Z_R9_miscalib.root",evenFile.c_str());
      name2 = Form ("%s_Z_R9_miscalib.root",oddFile.c_str());
    }
    
    if(isMiscalib == true && useZ == 1 && isEPselection==true)
    { name = Form ("%s_Z_EP_miscalib.root",evenFile.c_str());
      name2 = Form ("%s_Z_EP_miscalib.root",oddFile.c_str());
    }
    if(isMiscalib == true && useZ == 1 && isR9selection==false && isEPselection==false)
    { name = Form ("%s_Z_noEP_miscalib.root",evenFile.c_str());
      name2 = Form ("%s_Z_noEP_miscalib.root",oddFile.c_str());
    }



    if(isMiscalib == false && useZ == 1 && isR9selection==true)
    { name = Form ("%s_Z_R9.root",evenFile.c_str());
      name2 = Form ("%s_Z_R9.root",oddFile.c_str());
    }
    
    if(isMiscalib == false && useZ == 1 && isEPselection==true)
    { name = Form ("%s_Z_EP.root",evenFile.c_str());
      name2 = Form ("%s_Z_EP.root",oddFile.c_str());
    }
    if(isMiscalib == false && useZ == 1 && isR9selection==false && isEPselection==false)
    { name = Form ("%s_Z_noEP.root",evenFile.c_str());
      name2 = Form ("%s_Z_noEP.root",oddFile.c_str());
    }
    

    if(isMiscalib == true && useZ == 0 && isR9selection==true)
    { name = Form ("%s_R9_miscalib.root",evenFile.c_str());
      name2 = Form ("%s_R9_miscalib.root",oddFile.c_str());
    }
    
    if(isMiscalib == true && useZ == 0 && isEPselection==true)
    { name = Form ("%s_EP_miscalib.root",evenFile.c_str());
      name2 = Form ("%s_EP_miscalib.root",oddFile.c_str());
    }
    if(isMiscalib == true && useZ == 0 && isR9selection==false && isEPselection==false)
    { name = Form ("%s_noEP_miscalib.root",evenFile.c_str());
      name2 = Form ("%s_noEP_miscalib.root",oddFile.c_str());
    }

    
    if(isMiscalib == false && useZ == 0 && isR9selection==true)
    { name = Form ("%s_R9.root",evenFile.c_str());
      name2 = Form ("%s_R9.root",oddFile.c_str());
    }
    
    if(isMiscalib == false && useZ == 0 && isEPselection==true)
    { name = Form ("%s_EP.root",evenFile.c_str());
      name2 = Form ("%s_EP.root",oddFile.c_str());
    }
    if(isMiscalib == false && useZ == 0 && isR9selection==false && isEPselection==false)
    { name = Form ("%s_noEP.root",evenFile.c_str());
      name2 = Form ("%s_noEP.root",oddFile.c_str());
    }

    TFile *f1 = new TFile(name,"RECREATE");
    TFile *f2 = new TFile(name2,"RECREATE");

    TString DeadXtal = Form("%s",inputFileDeadXtal.c_str());
     
    /// Run on odd
    FastCalibratorEB_MVA analyzer_even(albero);
    analyzer_even.bookHistos(nLoops);
    analyzer_even.AcquireDeadXtal(DeadXtal);
    analyzer_even.Loop(numberOfEvents, useZ, useW, splitStat, nLoops,isMiscalib,isSaveEPDistribution,isEPselection,isR9selection,isMCTruth);
    analyzer_even.saveHistos(f1);
  
    /// Run on even
    FastCalibratorEB_MVA analyzer_odd(albero);
    analyzer_odd.bookHistos(nLoops);
    analyzer_odd.AcquireDeadXtal(DeadXtal);
    analyzer_odd.Loop(numberOfEvents, useZ, useW, splitStat*(-1), nLoops,isMiscalib,isSaveEPDistribution,isEPselection,isR9selection,isMCTruth);
    analyzer_odd.saveHistos(f2);
    
  }

  delete albero;
  return 0;
}