Example #1
0
//--------------------------------------------------------------------------------------------------
void runFlatMonoJet(const char *fileset    = "0000",
		    const char *skim       = "noskim",
		    const char *dataset    = "s12-wjets-ptw100-v7a", 
		    const char *book       = "t2mit/filefi/031",
		    const char *catalogDir = "/home/cmsprod/catalog",
		    const char *outputName = "MonoJet_August13",
		    int         nEvents    = 100)
{
  //------------------------------------------------------------------------------------------------
  // some parameters get passed through the environment
  //------------------------------------------------------------------------------------------------
  char json[1024], overlap[1024];
  float overlapCut = -1;
  
  if (gSystem->Getenv("MIT_PROD_JSON"))
    sprintf(json,   "%s",gSystem->Getenv("MIT_PROD_JSON"));
  else {
    sprintf(json, "%s", "~");
  } 
  
  TString jsonFile = TString("/home/cmsprod/cms/json/") + TString(json);
  std::cout<<"JSON "<<jsonFile<<std::endl;
  Bool_t  isData   = ( (jsonFile.CompareTo("/home/cmsprod/cms/json/~") != 0) );
    
  std::cout<<"*********** Is data?? **********"<<isData<<std::endl;

  if (gSystem->Getenv("MIT_PROD_OVERLAP")) {
    sprintf(overlap,"%s",gSystem->Getenv("MIT_PROD_OVERLAP"));
    if (EOF == sscanf(overlap,"%f",&overlapCut)) {
      printf(" Overlap was not properly defined. EXIT!\n");
      return;
    }
  }
  else {
     sprintf(overlap,"%s", "-1.0");
    //printf(" OVERLAP file was not properly defined. EXIT!\n");
    //return;
  } 

  printf("\n Initialization worked \n");

  //------------------------------------------------------------------------------------------------
  // some global setups
  //------------------------------------------------------------------------------------------------
  using namespace mithep;
  gDebugMask  = Debug::kGeneral;
  gDebugLevel = 3;

  //------------------------------------------------------------------------------------------------
  // set up information
  //------------------------------------------------------------------------------------------------
  RunLumiSelectionMod *runLumiSel = new RunLumiSelectionMod;      
  runLumiSel->SetAcceptMC(!isData);
  runLumiSel->SetAbortIfNotAccepted(kFALSE);   // accept all events if there is no valid JSON file

  // only select on run- and lumisection numbers when valid json file present
  if ((jsonFile.CompareTo("/home/cmsprod/cms/json/~") != 0) &&
      (jsonFile.CompareTo("/home/cmsprod/cms/json/-") != 0)   ) {
    runLumiSel->AddJSONFile(jsonFile.Data());
  }
  if ((jsonFile.CompareTo("/home/cmsprod/cms/json/-") == 0)   ) {
    printf("\n WARNING -- Looking at data without JSON file: always accept.\n\n");
  }

  printf("\n Run lumi worked\n");

  // Generator info
  GeneratorMod *generatorMod = new GeneratorMod;
  generatorMod->SetPrintDebug(kFALSE);
  generatorMod->SetPtLeptonMin(0.0);
  generatorMod->SetEtaLeptonMax(2.7);
  generatorMod->SetPtPhotonMin(0.0);
  generatorMod->SetEtaPhotonMax(2.7);
  generatorMod->SetPtRadPhotonMin(0.0);
  generatorMod->SetEtaRadPhotonMax(2.7);
  generatorMod->SetIsData(isData);
  generatorMod->SetFillHist(!isData);
  generatorMod->SetApplyISRFilter(kFALSE);
  generatorMod->SetApplyVVFilter(kFALSE);
  generatorMod->SetApplyVGFilter(kFALSE);
  generatorMod->SetFilterBTEvents(kFALSE);

  //-----------------------------------------------------------------------------------------------------------
  // HLT information : trigger not applied (neither for data nor for MC, store info to apply selection offline
  //-----------------------------------------------------------------------------------------------------------
  HLTMod *hltModP = new HLTMod("HLTModP");

  // monojet triggers
  TString monoJetTriggers[12] = {"HLT_MonoCentralPFJet80_PFMETnoMu105_NHEF0p95_v4", "HLT_MonoCentralPFJet80_PFMETnoMu105_NHEF0p95_v3", "HLT_MonoCentralPFJet80_PFMETnoMu105_NHEF0p95_v1", "HLT_MonoCentralPFJet80_PFMETnoMu95_NHEF0p95_v5", "HLT_MonoCentralPFJet80_PFMETnoMu95_NHEF0p95_v4", "HLT_MonoCentralPFJet80_PFMETnoMu95_NHEF0p95_v3", "HLT_MonoCentralPFJet80_PFMETnoMu95_NHEF0p95_v2","HLT_MET120_HBHENoiseCleaned_v6", "HLT_MET120_HBHENoiseCleaned_v5", "HLT_MET120_HBHENoiseCleaned_v4", "HLT_MET120_HBHENoiseCleaned_v3", "HLT_MET120_HBHENoiseCleaned_v2"};
  for (int i=0; i<12; i++) {
    hltModP->AddTrigger(monoJetTriggers[i],0,999999); //jet 85 , met 90
    hltModP->AddTrigger(TString("!"+monoJetTriggers[i]),0,999999); //jet 85 , met 90
  }

  // VBF triggers
  TString vbfTriggers[12] = {"HLT_DiPFJet40_PFMETnoMu65_MJJ800VBF_AllJets_v9", "HLT_DiPFJet40_PFMETnoMu65_MJJ800VBF_AllJets_v8", "HLT_DiPFJet40_PFMETnoMu65_MJJ800VBF_AllJets_v6", "HLT_DiPFJet40_PFMETnoMu65_MJJ800VBF_AllJets_v5", "HLT_DiPFJet40_PFMETnoMu65_MJJ800VBF_AllJets_v4", "HLT_DiPFJet40_PFMETnoMu65_MJJ800VBF_AllJets_v3", "HLT_DiPFJet40_PFMETnoMu65_MJJ800VBF_AllJets_v2"};
  for (int i=0; i<12; i++) {
    hltModP->AddTrigger(vbfTriggers[i],0,999999); //jet 85 , met 90
    hltModP->AddTrigger(TString("!"+vbfTriggers[i]),0,999999); //jet 85 , met 90
  }

  hltModP->SetBitsName("HLTBits");
  hltModP->SetTrigObjsName("MyHltPhotObjs");
  hltModP->SetAbortIfNotAccepted(isData);
  hltModP->SetPrintTable(kFALSE); // set to true to print HLT table

  //------------------------------------------------------------------------------------------------
  // split pfcandidates to PFPU and PFnoPU
  //------------------------------------------------------------------------------------------------
  SeparatePileUpMod* SepPUMod = new SeparatePileUpMod;
  //  SepPUMod->SetUseAllVerteces(kFALSE);
  // SepPUMod->SetVertexName("OutVtxCiC");
  SepPUMod->SetPFNoPileUpName("pfnopileupcands");
  SepPUMod->SetPFPileUpName("pfpileupcands");
  SepPUMod->SetCheckClosestZVertex(kFALSE);
  
  //------------------------------------------------------------------------------------------------
  // select events with a good primary vertex
  //------------------------------------------------------------------------------------------------
  GoodPVFilterMod *goodPVFilterMod = new GoodPVFilterMod;
  goodPVFilterMod->SetMinVertexNTracks(0);
  goodPVFilterMod->SetMinNDof         (4.0);
  goodPVFilterMod->SetMaxAbsZ         (24.0);
  goodPVFilterMod->SetMaxRho          (2.0);
  goodPVFilterMod->SetIsMC(!isData);
  goodPVFilterMod->SetVertexesName("PrimaryVertexes");
  
  //------------------------------------------------------------------------------------------------
  // object id and cleaning sequence
  //------------------------------------------------------------------------------------------------
  //-----------------------------------
  // Lepton Selection 
  //-----------------------------------
  ElectronIDMod* eleIdMod = new ElectronIDMod;
  eleIdMod->SetPtMin(10.);  
  eleIdMod->SetEtaMax(2.5);
  eleIdMod->SetApplyEcalFiducial(true);
  eleIdMod->SetIDType("VBTFWorkingPoint95Id");  
  eleIdMod->SetIsoType("PFIso");
  eleIdMod->SetApplyConversionFilterType1(kTRUE);
  eleIdMod->SetApplyConversionFilterType2(kFALSE);
  eleIdMod->SetChargeFilter(kFALSE);
  eleIdMod->SetApplyD0Cut(kTRUE);
  eleIdMod->SetApplyDZCut(kTRUE);
  eleIdMod->SetWhichVertex(0);
  eleIdMod->SetNExpectedHitsInnerCut(0);  
  eleIdMod->SetGoodElectronsName("GoodElectronsBS");
  eleIdMod->SetRhoType(RhoUtilities::CMS_RHO_RHOKT6PFJETS); 

  MuonIDMod* muonIdGammaGamma = new MuonIDMod;
  // base kinematics
  muonIdGammaGamma->SetPtMin(10.);
  muonIdGammaGamma->SetEtaCut(2.4);
  // base ID
  muonIdGammaGamma->SetIDType("NoId");
  muonIdGammaGamma->SetClassType("GlobalorTracker");
  muonIdGammaGamma->SetWhichVertex(0); // this is a 'hack'.. but hopefully good enough...
  muonIdGammaGamma->SetD0Cut(0.02);
  muonIdGammaGamma->SetDZCut(0.5);
  muonIdGammaGamma->SetIsoType("PFIsoBetaPUCorrected"); //h
  muonIdGammaGamma->SetPFIsoCut(0.2); //h
  muonIdGammaGamma->SetOutputName("HggLeptonTagMuons");
  muonIdGammaGamma->SetPFNoPileUpName("pfnopileupcands");
  muonIdGammaGamma->SetPFPileUpName("pfpileupcands");
  muonIdGammaGamma->SetPVName(Names::gkPVBeamSpotBrn); 

  MuonIDMod *muonIdWW = new MuonIDMod;
  muonIdWW->SetOutputName("HWWMuons");
  muonIdWW->SetIntRadius(0.0);
  muonIdWW->SetClassType("GlobalTracker");
  muonIdWW->SetIDType("WWMuIdV4");
  muonIdWW->SetIsoType("IsoRingsV0_BDTG_Iso");
  muonIdWW->SetApplyD0Cut(kTRUE);
  muonIdWW->SetApplyDZCut(kTRUE);
  muonIdWW->SetWhichVertex(0);
  muonIdWW->SetRhoType(RhoUtilities::CMS_RHO_RHOKT6PFJETS);
  muonIdWW->SetPtMin(10.);
  muonIdWW->SetEtaCut(2.4);

  //MuonIDMod *muonId = muonIdWW;
  MuonIDMod *muonId = muonIdGammaGamma;
  
  ElectronCleaningMod *electronCleaning = new ElectronCleaningMod;
  electronCleaning->SetCleanMuonsName(muonId->GetOutputName());
  electronCleaning->SetGoodElectronsName(eleIdMod->GetOutputName());
  electronCleaning->SetCleanElectronsName("CleanElectrons");

  MergeLeptonsMod *merger = new MergeLeptonsMod;
  merger->SetMuonsName(muonId->GetOutputName());
  merger->SetElectronsName(electronCleaning->GetOutputName());
  merger->SetMergedName("MergedLeptons");

  //-----------------------------------
  // Photon Regression + ID 
  //-----------------------------------
  PhotonMvaMod *photreg = new PhotonMvaMod;
  photreg->SetRegressionVersion(3);
  photreg->SetRegressionWeights(std::string((gSystem->Getenv("CMSSW_BASE") + TString("/src/MitPhysics/data/gbrv3ph_52x.root")).Data()));
  photreg->SetOutputName("GoodPhotonsRegr");
  photreg->SetApplyShowerRescaling(kTRUE);
  photreg->SetMinNumPhotons(0);
  photreg->SetIsData(isData);

  PhotonIDMod *photonIDMod = new PhotonIDMod;
  photonIDMod->SetPtMin(0.0);
  photonIDMod->SetOutputName("GoodPhotons");
  photonIDMod->SetIDType("BaseLineCiCPFNoPresel");
  photonIDMod->SetIsoType("NoIso");
  photonIDMod->SetApplyElectronVeto(kTRUE);
  photonIDMod->SetApplyPixelSeed(kTRUE);
  photonIDMod->SetApplyConversionId(kTRUE);
  photonIDMod->SetApplyFiduciality(kTRUE);       
  photonIDMod->SetIsData(isData);
  photonIDMod->SetPhotonsFromBranch(kFALSE);
  photonIDMod->SetInputName(photreg->GetOutputName());
  //get the photon with regression energy  
  photonIDMod->DoMCSmear(kTRUE);
  photonIDMod->DoDataEneCorr(kTRUE);
  //------------------------------------------Energy smear and scale--------------------------------------------------------------
  photonIDMod->SetMCSmearFactors2012HCP(0.0111,0.0111,0.0107,0.0107,0.0155,0.0194,0.0295,0.0276,0.037,0.0371);
  photonIDMod->AddEnCorrPerRun2012HCP(190645,190781,0.9964,0.9964,1.0020,1.0020,0.9893,1.0028,0.9871,0.9937,0.9839,0.9958);
  photonIDMod->AddEnCorrPerRun2012HCP(190782,191042,1.0024,1.0024,1.0079,1.0079,0.9923,1.0058,0.9911,0.9977,0.9886,1.0005);
  photonIDMod->AddEnCorrPerRun2012HCP(191043,193555,0.9935,0.9935,0.9991,0.9991,0.9861,0.9997,0.9894,0.9960,0.9864,0.9982);
  photonIDMod->AddEnCorrPerRun2012HCP(193556,194150,0.9920,0.9920,0.9976,0.9976,0.9814,0.9951,0.9896,0.9962,0.9872,0.9990);
  photonIDMod->AddEnCorrPerRun2012HCP(194151,194532,0.9925,0.9925,0.9981,0.9981,0.9826,0.9963,0.9914,0.9980,0.9874,0.9993);
  photonIDMod->AddEnCorrPerRun2012HCP(194533,195113,0.9927,0.9927,0.9983,0.9983,0.9844,0.9981,0.9934,0.9999,0.9878,0.9996);
  photonIDMod->AddEnCorrPerRun2012HCP(195114,195915,0.9929,0.9929,0.9984,0.9984,0.9838,0.9974,0.9942,1.0007,0.9878,0.9997);
  photonIDMod->AddEnCorrPerRun2012HCP(195916,198115,0.9919,0.9919,0.9975,0.9975,0.9827,0.9964,0.9952,1.0017,0.9869,0.9987);
  photonIDMod->AddEnCorrPerRun2012HCP(198116,199803,0.9955,0.9955,1.0011,1.0011,0.9859,0.9995,0.9893,0.9959,0.9923,1.0041);
  photonIDMod->AddEnCorrPerRun2012HCP(199804,200048,0.9967,0.9967,1.0023,1.0023,0.9870,1.0006,0.9893,0.9959,0.9937,1.0055);
  photonIDMod->AddEnCorrPerRun2012HCP(200049,200151,0.9980,0.9980,1.0036,1.0036,0.9877,1.0012,0.9910,0.9976,0.9980,1.0097);
  photonIDMod->AddEnCorrPerRun2012HCP(200152,200490,0.9958,0.9958,1.0013,1.0013,0.9868,1.0004,0.9922,0.9988,0.9948,1.0065);
  photonIDMod->AddEnCorrPerRun2012HCP(200491,200531,0.9979,0.9979,1.0035,1.0035,0.9876,1.0012,0.9915,0.9981,0.9979,1.0096);
  photonIDMod->AddEnCorrPerRun2012HCP(200532,201656,0.9961,0.9961,1.0017,1.0017,0.9860,0.9996,0.9904,0.9970,0.9945,1.0063);
  photonIDMod->AddEnCorrPerRun2012HCP(201657,202305,0.9969,0.9969,1.0025,1.0025,0.9866,1.0002,0.9914,0.9980,0.9999,1.0116);
  photonIDMod->AddEnCorrPerRun2012HCP(202305,203002,0.9982,0.9982,1.0038,1.0038,0.9872,1.0008,0.9934,1.0000,1.0018,1.0135);
  photonIDMod->AddEnCorrPerRun2012HCP(203003,203984,1.0006,1.0006,1.0061,1.0061,0.9880,1.0017,0.9919,0.9988,0.9992,1.0104);     
  photonIDMod->AddEnCorrPerRun2012HCP(203985,205085,0.9993,0.9993,1.0048,1.0048,0.9903,1.0040,0.9928,0.9997,0.9987,1.0099);     
  photonIDMod->AddEnCorrPerRun2012HCP(205086,205310,1.0004,1.0004,1.0059,1.0059,0.9901,1.0037,0.9987,1.0055,1.0091,1.0202);     
  photonIDMod->AddEnCorrPerRun2012HCP(205311,206207,1.0000,1.0000,1.0055,1.0055,0.9891,1.0028,0.9948,1.0017,1.0032,1.0144);     
  photonIDMod->AddEnCorrPerRun2012HCP(206208,206483,1.0003,1.0003,1.0058,1.0058,0.9895,1.0032,0.9921,0.9989,1.0056,1.0167);     
  photonIDMod->AddEnCorrPerRun2012HCP(206484,206597,1.0005,1.0005,1.0060,1.0060,0.9895,1.0032,0.9968,1.0036,1.0046,1.0158);     
  photonIDMod->AddEnCorrPerRun2012HCP(206598,206896,1.0006,1.0006,1.0061,1.0061,0.9881,1.0017,0.9913,0.9982,1.0050,1.0162);     
  photonIDMod->AddEnCorrPerRun2012HCP(206897,207220,1.0006,1.0006,1.0061,1.0061,0.9884,1.0021,0.9909,0.9978,1.0053,1.0165);     
  photonIDMod->AddEnCorrPerRun2012HCP(207221,208686,1.0006,1.0006,1.0061,1.0061,0.9894,1.0030,0.9951,1.0020,1.0060,1.0172);     
  //---------------------------------shower shape scale--------------------------------------------------------------------------------
  photonIDMod->SetDoShowerShapeScaling(kTRUE);
  photonIDMod->SetShowerShapeType("2012ShowerShape");
  photonIDMod->Set2012HCP(kTRUE);

  PFTauIDMod *pftauIDMod = new PFTauIDMod;
  pftauIDMod->SetPFTausName("HPSTaus");
  pftauIDMod->SetIsLooseId(kFALSE);

  PhotonCleaningMod *photonCleaningMod = new PhotonCleaningMod;
  photonCleaningMod->SetCleanElectronsName(electronCleaning->GetOutputName());
  photonCleaningMod->SetGoodPhotonsName(photonIDMod->GetOutputName());
  photonCleaningMod->SetCleanPhotonsName("CleanPhotons");

  PFTauCleaningMod *pftauCleaningMod = new PFTauCleaningMod;
  pftauCleaningMod->SetGoodPFTausName(pftauIDMod->GetGoodPFTausName());
  pftauCleaningMod->SetCleanMuonsName(muonId->GetOutputName());

  PublisherMod<PFJet,Jet> *pubJet = new PublisherMod<PFJet,Jet>("JetPub");
  pubJet->SetInputName("AKt5PFJets");
  pubJet->SetOutputName("PubAKt5PFJets");

  JetCorrectionMod *jetCorr = new JetCorrectionMod;
  if(isData){ 
    jetCorr->AddCorrectionFromFile(std::string((gSystem->Getenv("CMSSW_BASE") + TString("/src/MitPhysics/data/Summer13_V1_DATA_L1FastJet_AK5PF.txt")).Data())); 
    jetCorr->AddCorrectionFromFile(std::string((gSystem->Getenv("CMSSW_BASE") + TString("/src/MitPhysics/data/Summer13_V1_DATA_L2Relative_AK5PF.txt")).Data())); 
    jetCorr->AddCorrectionFromFile(std::string((gSystem->Getenv("CMSSW_BASE") + TString("/src/MitPhysics/data/Summer13_V1_DATA_L3Absolute_AK5PF.txt")).Data())); 
    jetCorr->AddCorrectionFromFile(std::string((gSystem->Getenv("CMSSW_BASE") + TString("/src/MitPhysics/data/Summer13_V1_DATA_L2L3Residual_AK5PF.txt")).Data()));
  }                                                                                      
  else {                                                                                 
    jetCorr->AddCorrectionFromFile(std::string((gSystem->Getenv("CMSSW_BASE") + TString("/src/MitPhysics/data/Summer13_V1_MC_L1FastJet_AK5PF.txt")).Data())); 
    jetCorr->AddCorrectionFromFile(std::string((gSystem->Getenv("CMSSW_BASE") + TString("/src/MitPhysics/data/Summer13_V1_MC_L2Relative_AK5PF.txt")).Data())); 
    jetCorr->AddCorrectionFromFile(std::string((gSystem->Getenv("CMSSW_BASE") + TString("/src/MitPhysics/data/Summer13_V1_MC_L3Absolute_AK5PF.txt")).Data())); 
  }
  jetCorr->SetInputName(pubJet->GetOutputName());
  jetCorr->SetCorrectedName("CorrectedJets");    

  JetIDMod *theJetID = new JetIDMod;
  theJetID->SetInputName(jetCorr->GetOutputName());
  theJetID->SetPtCut(30.0);
  theJetID->SetEtaMaxCut(4.7);
  theJetID->SetJetEEMFractionMinCut(0.00);
  theJetID->SetOutputName("GoodJets");
  theJetID->SetApplyBetaCut(kFALSE);
  theJetID->SetApplyMVACut(kTRUE);

  JetCleaningMod *theJetCleaning = new JetCleaningMod;
  theJetCleaning->SetCleanElectronsName(electronCleaning->GetOutputName());
  theJetCleaning->SetCleanMuonsName(muonId->GetOutputName());
  theJetCleaning->SetCleanPhotonsName(photonCleaningMod->GetOutputName());
  theJetCleaning->SetApplyPhotonRemoval(kTRUE);
  theJetCleaning->SetGoodJetsName(theJetID->GetOutputName());
  theJetCleaning->SetCleanJetsName("CleanJets");
        
  MetCorrectionMod *metCorrT0T1Shift = new MetCorrectionMod;
  metCorrT0T1Shift->SetInputName("PFMet");
  metCorrT0T1Shift->SetJetsName(pubJet->GetOutputName());    
  metCorrT0T1Shift->SetCorrectedJetsName(jetCorr->GetOutputName());    
  metCorrT0T1Shift->SetCorrectedName("PFMetT0T1Shift");   
  metCorrT0T1Shift->ApplyType0(kTRUE);   
  metCorrT0T1Shift->ApplyType1(kTRUE);   
  metCorrT0T1Shift->ApplyShift(kTRUE);   
  metCorrT0T1Shift->IsData(isData);
  metCorrT0T1Shift->SetPrint(kFALSE);

  MonoJetTreeWriter *jetplusmettree = new MonoJetTreeWriter("MonoJetTreeWriter");
  jetplusmettree->SetTriggerObjectsName(hltModP->GetOutputName());
  jetplusmettree->SetMetName(metCorrT0T1Shift->GetOutputName()); //corrected met
  jetplusmettree->SetMetFromBranch(kFALSE);
  jetplusmettree->SetPhotonsFromBranch(kFALSE);
  jetplusmettree->SetPhotonsName(photonCleaningMod->GetOutputName());
  jetplusmettree->SetElectronsFromBranch(kFALSE);
  jetplusmettree->SetElectronsName(electronCleaning->GetOutputName());
  jetplusmettree->SetMuonsFromBranch(kFALSE);
  jetplusmettree->SetMuonsName(muonId->GetOutputName());
  jetplusmettree->SetTausFromBranch(kFALSE);
  jetplusmettree->SetTausName(pftauCleaningMod->GetOutputName());
  jetplusmettree->SetJetsFromBranch(kFALSE);
  jetplusmettree->SetJetsName(theJetCleaning->GetOutputName());
  jetplusmettree->SetPVFromBranch(kFALSE);
  jetplusmettree->SetPVName(goodPVFilterMod->GetOutputName());
  jetplusmettree->SetLeptonsName(merger->GetOutputName());
  jetplusmettree->SetIsData(isData);
  jetplusmettree->SetProcessID(0);
  jetplusmettree->SetFillNtupleType(0);


  //------------------------------------------------------------------------------------------------
  // making analysis chain
  //------------------------------------------------------------------------------------------------
  // this is how it always starts
  runLumiSel->Add(generatorMod);
  generatorMod->Add(goodPVFilterMod);
  goodPVFilterMod->Add(hltModP);

  // photon regression
  hltModP->Add(photreg);
  // simple object id modules
  photreg          ->Add(SepPUMod); 
  SepPUMod         ->Add(muonId);
  muonId           ->Add(eleIdMod);
  eleIdMod	   ->Add(electronCleaning);
  electronCleaning ->Add(merger);
  merger           ->Add(photonIDMod);
  photonIDMod	   ->Add(photonCleaningMod);
  photonCleaningMod->Add(pftauIDMod);
  pftauIDMod       ->Add(pftauCleaningMod);
  pftauCleaningMod ->Add(pubJet);
  pubJet           ->Add(jetCorr);
  jetCorr          ->Add(metCorrT0T1Shift);
  metCorrT0T1Shift ->Add(theJetID);
  theJetID         ->Add(theJetCleaning);
  theJetCleaning   ->Add(jetplusmettree);

  //------------------------------------------------------------------------------------------------
  // setup analysis
  //------------------------------------------------------------------------------------------------
  Analysis *ana = new Analysis;
  ana->SetUseHLT(kTRUE);
  ana->SetKeepHierarchy(kTRUE);
  ana->SetSuperModule(runLumiSel);
  ana->SetPrintScale(100);
  if (nEvents >= 0) ana->SetProcessNEvents(nEvents);
  
  //------------------------------------------------------------------------------------------------
  // organize input
  //------------------------------------------------------------------------------------------------
  Catalog *c = new Catalog(catalogDir);
  TString skimdataset = TString(dataset)+TString("/") +TString(skim);
  Dataset *d = NULL;
  TString bookstr = book;
  if (TString(skim).CompareTo("noskim") == 0) {
    d = c->FindDataset(bookstr,dataset,fileset, true); // chaching on
    //d = c->FindDataset(bookstr,dataset,fileset, false); // chaching off
  }
  else {
    d = c->FindDataset(bookstr,skimdataset.Data(),fileset, true);
    //d = c->FindDataset(bookstr,skimdataset.Data(),fileset, false);
  }
  ana->AddDataset(d);
  //ana->AddFile("/mnt/hadoop/cms/store/user/paus/filefi/032/r12a-met-j22-v1/C4AC0AB8-BA82-E211-B238-003048678FF4.root");
  

  //------------------------------------------------------------------------------------------------
  // organize output
  //------------------------------------------------------------------------------------------------
  TString rootFile = TString(outputName);
  rootFile += TString("_") + TString(dataset) + TString("_") + TString(skim);
  if (TString(fileset) != TString(""))
    rootFile += TString("_") + TString(fileset);
  rootFile += TString(".root");
  ana->SetOutputName(rootFile.Data());
  //ana->SetCacheSize(64*1024*1024);
  ana->SetCacheSize(0);

  //------------------------------------------------------------------------------------------------
  // Say what we are doing
  //------------------------------------------------------------------------------------------------
  printf("\n==== PARAMETER SUMMARY FOR THIS JOB ====\n");
  printf("\n JSON file: %s\n  and overlap cut: %f (%s)\n",jsonFile.Data(),overlapCut,overlap);
  printf("\n Rely on Catalog: %s\n",catalogDir);
  printf("  -> Book: %s  Dataset: %s  Skim: %s  Fileset: %s <-\n",book,dataset,skim,fileset);
  printf("\n Root output: %s\n\n",rootFile.Data());  
  printf("\n========================================\n");

  //------------------------------------------------------------------------------------------------
  // run the analysis after successful initialisation
  //------------------------------------------------------------------------------------------------
  ana->Run(!gROOT->IsBatch());

  return;
}
Example #2
0
//--------------------------------------------------------------------------------------------------
void runEMU(const char *fileset    = "0000",
	  const char *skim       = "noskim",
	  const char *dataset    = "p10-pj15-v36",
	  const char *book       = "local/filefi/016",
	  const char *catalogDir = "/home/cmsprod/catalog",
	  const char *outputName = "htt",
	  int         nEvents    = 1000)
{
  printf("\n==== Enter macro  ====\n");

  //------------------------------------------------------------------------------------------------
  // some parameters get passed through the environment
  //------------------------------------------------------------------------------------------------
  char json[1024], overlap[1024], src[1024];
  float overlapCut = -1;


  if (gSystem->Getenv("MIT_PROD_JSON"))
    sprintf(json,   "%s",gSystem->Getenv("MIT_PROD_JSON"));
  else {
    printf(" JSON file was not properly defined. EXIT!\n");
    return;
  } 
  TString jsonFile = TString("/home/cmsprod/json/") + TString(json);
  Bool_t  isData   = (jsonFile.CompareTo("/home/cmsprod/json/~") != 0);

  if (gSystem->Getenv("MIT_PROD_OVERLAP")) {
    sprintf(overlap,"%s",gSystem->Getenv("MIT_PROD_OVERLAP"));
    if (EOF == sscanf(overlap,"%f",&overlapCut)) {
      printf(" Overlap was not properly defined. EXIT!\n");
      return;
    }
  }
  else {
    printf(" OVERLAP file was not properly defined. EXIT!\n");
    return;
  } 

  if (gSystem->Getenv("src"))
    sprintf(src,   "%s",gSystem->Getenv("src"));
  else {
    printf(" src dir not defined. EXIT!\n");
    return;
  } 

  printf("\n Initialization worked. \n\n");

  //------------------------------------------------------------------------------------------------
  // some global setups
  //------------------------------------------------------------------------------------------------
  using namespace std;
  using namespace mithep;
  gDebugMask  = Debug::kAnalysis;
  gDebugLevel = 1;

  //------------------------------------------------------------------------------------------------
  // set up information
  //------------------------------------------------------------------------------------------------ 
  Bool_t applyISRFilter = kFALSE;
  Bool_t applyMllGenCut = kFALSE;

  RunLumiSelectionMod *runLumiSel = new RunLumiSelectionMod;
  runLumiSel->SetAcceptMC(kTRUE);                          // Monte Carlo events are always accepted

  // if([json is not ~] and [json is not -])
  if ((jsonFile.CompareTo("/home/cmsprod/json/~") != 0) &&    //if not MC and 
      (jsonFile.CompareTo("/home/cmsprod/json/-") != 0)   ) { //if json file not absent
    runLumiSel->AddJSONFile(jsonFile.Data());
  }
  if ((jsonFile.CompareTo("/home/cmsprod/json/-") == 0)   ) {
    printf("\n WARNING -- Looking at data without JSON file: always accept.\n\n");
    runLumiSel->SetAbortIfNotAccepted(kFALSE);   // accept all events if there is no valid JSON file
  }

  printf("\n Run lumi worked. \n\n");

  //GeneratorMod
  GeneratorMod *generatorMod = new GeneratorMod;
  generatorMod->SetPrintDebug(kFALSE);
  generatorMod->SetPtLeptonMin(0.0);
  generatorMod->SetEtaLeptonMax(2.7);
  generatorMod->SetPtPhotonMin(15.0);
  generatorMod->SetEtaPhotonMax(2.7);
  generatorMod->SetPtRadPhotonMin(10.0);
  generatorMod->SetEtaRadPhotonMax(2.7);
  generatorMod->SetIsData(isData); 
  generatorMod->SetFillHist(!isData);
  if(applyMllGenCut == kTRUE){
    generatorMod->SetPdgIdCut(23);
    generatorMod->SetMassMinCut( 0.);
    generatorMod->SetMassMaxCut(50.);
  }
  generatorMod->SetApplyISRFilter(applyISRFilter);

  //------------------------------------------------------------------------------------------------
  // HLT information
  //------------------------------------------------------------------------------------------------
  HLTMod *hltMod = new HLTMod;
  if (isData) {
//   valentina:
//     hltMod->AddTrigger("HLT_Mu17_Ele8_CaloIdL_v1",150000,161176);
//     hltMod->AddTrigger("HLT_Mu8_Ele17_CaloIdL_v1",150000,161176);
//     hltMod->AddTrigger("HLT_Mu17_Ele8_CaloIdL_v2",161179,999999);
//     hltMod->AddTrigger("HLT_Mu8_Ele17_CaloIdL_v2",161179,999999);
    hltMod->AddTrigger("HLT_Mu9",132440,147119);
    hltMod->AddTrigger("HLT_Mu15",147120,9999999);
  }
  else {
    hltMod->AddTrigger("HLT_Mu9");
    hltMod->AddTrigger("HLT_Mu15");
//     hltMod->AddTrigger("HLT_Ele10_SW_L1R_v2");
  }
  hltMod->SetTrigObjsName("MyHltObjs");
  hltMod->SetAbortIfNotAccepted(kTRUE);
//   hltMod->SetPrintTable(kTRUE);
  //------------------------------------------------------------------------------------------------
  // select events with a good primary vertex
  //------------------------------------------------------------------------------------------------
  GoodPVFilterMod *goodPVFilterMod = new GoodPVFilterMod;
  goodPVFilterMod->SetMinVertexNTracks(0);
  goodPVFilterMod->SetMinNDof(4);  // should be 4
  goodPVFilterMod->SetMaxAbsZ(24.0);
  goodPVFilterMod->SetMaxRho(2.0);

  //------------------------------------------------------------------------------------------------
  // Publisher Modules
  //------------------------------------------------------------------------------------------------
  PublisherMod<PFJet,Jet> *pubPFJet = new PublisherMod<PFJet,Jet>("JetPub");
  pubPFJet->SetInputName("AKt5PFJets");
  pubPFJet->SetOutputName("PubAKt5PFJets");

  PublisherMod<Met,Met> *pubTCMet = new PublisherMod<Met,Met>("MetTCPub");
  pubTCMet->SetInputName("TCMet");
  pubTCMet->SetOutputName("PubTCMet");

  PublisherMod<PFMet,Met> *pubPFMet = new PublisherMod<PFMet,Met>("MetPFPub");
  pubPFMet->SetInputName("PFMet");
  pubPFMet->SetOutputName("PubPFMet");

  PublisherMod<CaloMet> *pubCaloMet = new PublisherMod<CaloMet>("CaloMetPub");
  //  pubCaloMet->SetName("CaloMetPub");
  pubCaloMet->SetInputName("CorMuonMet");
  pubCaloMet->SetOutputName("pubCaloMet");

  //------------------------------------------------------------------------------------------------
  // Apply Jet Corrections
  //------------------------------------------------------------------------------------------------
  JetCorrectionMod *jetCorr = new JetCorrectionMod;
  jetCorr->SetInputName(pubPFJet->GetOutputName());
  jetCorr->SetCorrectedName("CorrectedJets");//corrected jets are PF jets!
  jetCorr->ApplyL1FastJetCorrection(); // <<==== apply default L1 correction
  string path(string(src)+"/MitPhysics/data/");
  jetCorr->AddCorrectionFromFile(path+string("START38_V13_AK5PF_L2Relative.txt"));
  jetCorr->AddCorrectionFromFile(path+string("START38_V13_AK5PF_L3Absolute.txt"));
  if(isData) {
    jetCorr->AddCorrectionFromFile(path+string("START38_V13_AK5PF_L2L3Residual.txt"));
  }
  //------------------------------------------------------------------------------------------------
  // Apply Met Corrections
  //------------------------------------------------------------------------------------------------
  CaloMetCorrectionMod *metCaloCorr = new CaloMetCorrectionMod;
  metCaloCorr->SetInputName(pubCaloMet->GetOutputName());
  metCaloCorr->SetCorrectedJetsName(jetCorr->GetOutputName());
  metCaloCorr->SetOutputName("pubCaloCorrectedMet");

  //------------------------------------------------------------------------------------------------
  // object id and cleaning sequence
  //------------------------------------------------------------------------------------------------
  MuonIDMod           *muonId        = new MuonIDMod;
  muonId->SetClassType("Global"); // def is "Global"
  muonId->SetIDType("WWMuId");  // def is "WWMuId"
  muonId->SetIsoType("TrackCaloSliding"); // this is def
  muonId->SetApplyD0Cut(kTRUE);  // def is 1
  muonId->SetPtMin(15.0); // def is 10
  muonId->SetEtaCut(2.4); // def is 2.4

  ElectronIDMod       *electronId    = new ElectronIDMod;
  electronId->SetIDType("CustomTight"); // def is "CustomTight"
  electronId->SetIsoType("TrackJuraSliding"); // this is default
  electronId->SetApplyConversionFilterType1(kTRUE); // default is 1
  electronId->SetApplyConversionFilterType2(kFALSE); // default is 0
  electronId->SetChargeFilter(kTRUE); // def is 1
  electronId->SetApplyD0Cut(kTRUE); // def is 1
  electronId->SetNExpectedHitsInnerCut(0); // def is 999
  electronId->SetPtMin(15.0); // def is 10
  electronId->SetEtaMax(2.5); // def is 2.5

  PhotonIDMod         *photonId      = new PhotonIDMod;

  PFTauIDMod          *pfTauId        = new PFTauIDMod;
  pfTauId->SetIsHPSSel(kTRUE);
  pfTauId->SetPtMin(20.0);

  JetIDMod            *pfJetId       = new JetIDMod;
  pfJetId->SetInputName(jetCorr->GetOutputName());
  pfJetId->SetPtCut(20.0); // def is 35
  pfJetId->SetEtaMaxCut(5.0); // def is 5
  pfJetId->SetJetEEMFractionMinCut(0.01); // def is 0.01
  pfJetId->SetOutputName("GoodPFJets");

  ElectronCleaningMod *electronCleaning     = new ElectronCleaningMod;
  PhotonCleaningMod   *photonCleaning       = new PhotonCleaningMod;
  PFTauCleaningMod    *pfTauCleaning        = new PFTauCleaningMod;
  JetCleaningMod      *pfJetCleaning      = new JetCleaningMod;
  pfJetCleaning->SetGoodJetsName(pfJetId->GetOutputName());
  pfJetCleaning->SetCleanJetsName("CleanPFJets");

  //------------------------------------------------------------------------------------------------
  // merge modules
  //------------------------------------------------------------------------------------------------
  MergeLeptonsMod *mergeLeptonsMod = new MergeLeptonsMod;
  mergeLeptonsMod->SetMuonsName    (muonId->GetOutputName());
  mergeLeptonsMod->SetElectronsName(electronCleaning->GetOutputName());

  //------------------------------------------------------------------------------------------------
  // acceptance modules (gen -> reco)
  //------------------------------------------------------------------------------------------------
  //------------------------------------------------------------------------------------------------
  // id efficiency modules (reco -> id)
  //------------------------------------------------------------------------------------------------
  //------------------------------------------------------------------------------------------------
  // analysis modules
  //------------------------------------------------------------------------------------------------
  EMUAnalysis2 *analysisModEMU = new EMUAnalysis2;
  analysisModEMU->SetTrigObjsName  (hltMod           -> GetOutputName());
  analysisModEMU->SetMuonName      (muonId           -> GetOutputName());
  analysisModEMU->SetElecName      (electronCleaning -> GetOutputName());
  analysisModEMU->SetJetName       (pfJetCleaning    -> GetOutputName());
//   analysisModEMU->SetHistNamePref  ("hXXXXX");

  //------------------------------------------------------------------------------------------------
  // making analysis chain
  //------------------------------------------------------------------------------------------------
  // just in case we have run lumi sel
  if ((jsonFile.CompareTo("/home/cmsprod/json/~") != 0) &&
      (jsonFile.CompareTo("/home/cmsprod/json/-") != 0)   )
    runLumiSel->Add(generatorMod);

  generatorMod      ->Add(hltMod);
  hltMod            ->Add(goodPVFilterMod);
  goodPVFilterMod   ->Add(muonId);
  muonId            ->Add(electronId);
  electronId        ->Add(photonId);
  photonId          ->Add(pubPFJet);
  pubPFJet          ->Add(pubTCMet); 
  pubTCMet          ->Add(pubPFMet);
  pubPFMet          ->Add(pubCaloMet);
  pubCaloMet        ->Add(pfTauId);
  pfTauId           ->Add(jetCorr);
  jetCorr           ->Add(metCaloCorr);
  metCaloCorr       ->Add(pfJetId);
  pfJetId           ->Add(electronCleaning);
  electronCleaning  ->Add(photonCleaning);
  photonCleaning    ->Add(pfTauCleaning);
  pfTauCleaning     ->Add(pfJetCleaning);
  pfJetCleaning     ->Add(mergeLeptonsMod);

  mergeLeptonsMod   ->Add(analysisModEMU);

  //------------------------------------------------------------------------------------------------
  // setup analysis
  //------------------------------------------------------------------------------------------------

  Analysis *ana = new Analysis;
  ana->SetUseHLT(kTRUE);
  ana->SetKeepHierarchy(kTRUE);
  if (nEvents >= 0)
    ana->SetProcessNEvents(nEvents);
  if ((jsonFile.CompareTo("/home/cmsprod/json/~") != 0) &&
      (jsonFile.CompareTo("/home/cmsprod/json/-") != 0)   )
    ana->SetSuperModule(runLumiSel);
  else
    ana->SetSuperModule(generatorMod);
  ana->SetPrintScale(100);

  //------------------------------------------------------------------------------------------------
  // organize input
  //------------------------------------------------------------------------------------------------
  Catalog *c = new Catalog(catalogDir);
  TString skimdataset = TString(dataset)+TString("/") +TString(skim);
  Dataset *d = NULL;
  if (TString(skim).CompareTo("noskim") == 0)
    d = c->FindDataset(book,dataset,fileset);
  else 
    d = c->FindDataset(book,skimdataset.Data(),fileset);
  ana->AddDataset(d);
  //ana->AddFile("root://castorcms//castor/cern.ch/user/p/paus/filler/011/s09-ttbar-7-mc3/*.root");
  //ana->AddFile("hgg-skim_r10a-eg-pr-v4_noskim_0000_000.root");
  //ana->AddFile("hgg-skim_p10-h110gg-gf-v26_noskim_0000_000.root");

  //------------------------------------------------------------------------------------------------
  // organize output
  //------------------------------------------------------------------------------------------------
  TString rootFile = TString(outputName);
  rootFile += TString("_") + TString(dataset) + TString("_") + TString(skim);
  if (TString(fileset) != TString(""))
    rootFile += TString("_") + TString(fileset);
  rootFile += TString(".root");
  ana->SetOutputName(rootFile.Data());
//  use current directory:
//  ana->SetOutputName((TString(outputName)+TString(".root")).Data());
  ana->SetCacheSize(64*1024*1024);

  //------------------------------------------------------------------------------------------------
  // Say what we are doing
  //------------------------------------------------------------------------------------------------
  printf("\n==== PARAMETER SUMMARY FOR THIS JOB ====\n");
  printf("\n JSON file: %s\n  and overlap cut: %f (%s)\n",jsonFile.Data(),overlapCut,overlap);
  printf("\n Rely on Catalog: %s\n",catalogDir);
  printf("  -> Book: %s  Dataset: %s  Skim: %s  Fileset: %s <-\n",book,dataset,skim,fileset);
  printf("\n Root output: %s\n\n",rootFile.Data());  
  printf("\n========================================\n");

  //------------------------------------------------------------------------------------------------
  // run the analysis after successful initialisation
  //------------------------------------------------------------------------------------------------
  ana->Run(!gROOT->IsBatch());

  return;
}
Example #3
0
//--------------------------------------------------------------------------------------------------
void runMonoJetSkim(const char *fileset    = "0000",
		    const char *skim       = "noskim",
		    const char *dataset    = "s12-zjets-ptz100-v7a",
		    const char *book       = "t2mit/filefi/032",
		    const char *catalogDir = "/home/cmsprod/catalog",
		    const char *outputLabel = "monojet",
		    int         nEvents    = 1000)
{
  //------------------------------------------------------------------------------------------------
  // json parameters get passed through the environment
  // for MC, the value must be "~"
  //------------------------------------------------------------------------------------------------
  TString json(gSystem->Getenv("MIT_PROD_JSON"));
  if (json.Length() == 0) {
    printf(" JSON file was not properly defined. EXIT!\n");
    return;
  }

  TString jsonFile = TString("/home/cmsprod/cms/json/") + json;
  Bool_t  isData   = (json != "~");

  TString MitData(gSystem->Getenv("MIT_DATA"));
  if(MitData.Length() == 0){
    MitData = gSystem->Getenv("CMSSW_BASE");
    MitData += "/src/MitPhysics/data";
  }

  printf("\n Initialization worked: \n\n");
  printf("   JSON   : %s (file: %s)\n",  json.Data(), jsonFile.Data());
  printf("   isData : %d\n\n",isData);

  //------------------------------------------------------------------------------------------------
  // some global setups
  //------------------------------------------------------------------------------------------------
  using namespace mithep;
  gDebugMask  = Debug::kGeneral;
  gDebugLevel = 3;

  //------------------------------------------------------------------------------------------------
  // set up information
  //------------------------------------------------------------------------------------------------
  RunLumiSelectionMod *runLumiSel = new RunLumiSelectionMod;
  runLumiSel->SetAcceptMC(kTRUE);                          // Monte Carlo events are always accepted

  // only select on run- and lumisection numbers when valid json file present
  if ((jsonFile.CompareTo("/home/cmsprod/cms/json/~") != 0) &&
      (jsonFile.CompareTo("/home/cmsprod/cms/json/-") != 0)   ) {
    printf("\n Jason file added: %s \n\n",jsonFile.Data());
    runLumiSel->AddJSONFile(jsonFile.Data());
  }
  if ((jsonFile.CompareTo("/home/cmsprod/cms/json/-") == 0)   ) {
    printf("\n WARNING -- Looking at data without JSON file: always accept.\n\n");
    runLumiSel->SetAbortIfNotAccepted(kFALSE);   // accept all events if there is no valid JSON file
  }
  printf("\n Run lumi worked. \n\n");

  // Generator info
  GeneratorMod *generatorMod = new GeneratorMod;
  generatorMod->SetPrintDebug(kFALSE);
  generatorMod->SetPtLeptonMin(0.0);
  generatorMod->SetEtaLeptonMax(2.7);
  generatorMod->SetPtPhotonMin(0.0);
  generatorMod->SetEtaPhotonMax(2.7);
  generatorMod->SetPtRadPhotonMin(0.0);
  generatorMod->SetEtaRadPhotonMax(2.7);
  generatorMod->SetIsData(isData);
  generatorMod->SetFillHist(! isData);
  generatorMod->SetApplyISRFilter(kFALSE);
  generatorMod->SetApplyVVFilter(kFALSE);
  generatorMod->SetApplyVGFilter(kFALSE);
  generatorMod->SetFilterBTEvents(kFALSE);

  //-----------------------------------------------------------------------------------------------------------
  // HLT information : trigger not applied (neither for data nor for MC, store info to apply selection offline
  //-----------------------------------------------------------------------------------------------------------
  HLTMod *hltModP = new HLTMod("HLTModP");

  // monojet triggers
  const int nMjtTrigs = 12;
  TString monoJetTriggers[nMjtTrigs] = { "HLT_MonoCentralPFJet80_PFMETnoMu105_NHEF0p95_v4",
					 "HLT_MonoCentralPFJet80_PFMETnoMu105_NHEF0p95_v3",
					 "HLT_MonoCentralPFJet80_PFMETnoMu105_NHEF0p95_v1",
					 "HLT_MonoCentralPFJet80_PFMETnoMu95_NHEF0p95_v5",
					 "HLT_MonoCentralPFJet80_PFMETnoMu95_NHEF0p95_v4",
					 "HLT_MonoCentralPFJet80_PFMETnoMu95_NHEF0p95_v3",
					 "HLT_MonoCentralPFJet80_PFMETnoMu95_NHEF0p95_v2",
					 "HLT_MET120_HBHENoiseCleaned_v6",
					 "HLT_MET120_HBHENoiseCleaned_v5",
					 "HLT_MET120_HBHENoiseCleaned_v4",
					 "HLT_MET120_HBHENoiseCleaned_v3",
					 "HLT_MET120_HBHENoiseCleaned_v2" };

  for (int i=0; i<nMjtTrigs; i++)
    hltModP->AddTrigger(TString("!+"+monoJetTriggers[i]),0,999999);

  // VBF triggers
  const int nVbfTrigs = 7;
  TString vbfTriggers[nVbfTrigs] = { "HLT_DiPFJet40_PFMETnoMu65_MJJ800VBF_AllJets_v9",
				     "HLT_DiPFJet40_PFMETnoMu65_MJJ800VBF_AllJets_v8",
				     "HLT_DiPFJet40_PFMETnoMu65_MJJ800VBF_AllJets_v6",
				     "HLT_DiPFJet40_PFMETnoMu65_MJJ800VBF_AllJets_v5",
				     "HLT_DiPFJet40_PFMETnoMu65_MJJ800VBF_AllJets_v4",
				     "HLT_DiPFJet40_PFMETnoMu65_MJJ800VBF_AllJets_v3",
				     "HLT_DiPFJet40_PFMETnoMu65_MJJ800VBF_AllJets_v2" };

  for (int i=0; i<nVbfTrigs; i++)
    hltModP->AddTrigger((TString("!+")+vbfTriggers[i]).Data(),0,999999);

  hltModP->SetBitsName("HLTBits");
  hltModP->SetTrigObjsName("MyHltPhotObjs");
  hltModP->SetAbortIfNotAccepted(isData);
  hltModP->SetPrintTable(kFALSE);

  //------------------------------------------------------------------------------------------------
  // split pfcandidates to PFPU and PFnoPU
  //------------------------------------------------------------------------------------------------
  SeparatePileUpMod* SepPUMod = new SeparatePileUpMod;
  SepPUMod->SetPFNoPileUpName("pfnopileupcands");
  SepPUMod->SetPFPileUpName("pfpileupcands");
  SepPUMod->SetCheckClosestZVertex(kFALSE);
  
  //------------------------------------------------------------------------------------------------
  // select events with a good primary vertex
  //------------------------------------------------------------------------------------------------
  GoodPVFilterMod *goodPvMod = new GoodPVFilterMod;
  goodPvMod->SetMinVertexNTracks(0);
  goodPvMod->SetMinNDof(4.0);
  goodPvMod->SetMaxAbsZ(24.0);
  goodPvMod->SetMaxRho(2.0);
  goodPvMod->SetIsMC(!isData);
  goodPvMod->SetVertexesName("PrimaryVertexes");
  
  //------------------------------------------------------------------------------------------------
  // object id and cleaning sequence
  //------------------------------------------------------------------------------------------------

  //-----------------------------------
  // Lepton Selection 
  //-----------------------------------
  ElectronIDMod* eleIdMod = new ElectronIDMod;
  eleIdMod->SetPtMin(10.);  
  eleIdMod->SetEtaMax(2.5);
  eleIdMod->SetApplyEcalFiducial(true);
  eleIdMod->SetIDType(mithep::ElectronTools::kVBTFWorkingPoint95Id);
  eleIdMod->SetIsoType(mithep::ElectronTools::kPFIso);
  eleIdMod->SetApplyConversionFilterType1(kTRUE);
  eleIdMod->SetApplyConversionFilterType2(kFALSE);
  eleIdMod->SetChargeFilter(kFALSE);
  eleIdMod->SetApplyD0Cut(kTRUE);
  eleIdMod->SetApplyDZCut(kTRUE);
  eleIdMod->SetWhichVertex(-1);
  eleIdMod->SetGoodElectronsName("GoodElectronsBS");
  eleIdMod->SetRhoAlgo(mithep::PileupEnergyDensity::kKt6PFJets);

  MuonIDMod *muonId = new MuonIDMod;
  muonId->SetOutputName("GoodMuons");
  muonId->SetIntRadius(0.0);
  muonId->SetClassType("GlobalTracker");
  muonId->SetIDType("WWMuIdV4");
  muonId->SetIsoType("IsoRingsV0_BDTG_Iso");
  muonId->SetApplyD0Cut(kTRUE);
  muonId->SetApplyDZCut(kTRUE);
  muonId->SetWhichVertex(0);
  muonId->SetRhoAlgo(mithep::PileupEnergyDensity::kKt6PFJets);
  muonId->SetPtMin(10.);
  muonId->SetEtaCut(2.4);

  ElectronCleaningMod *electronCleaning = new ElectronCleaningMod;
  electronCleaning->SetCleanMuonsName(muonId->GetOutputName());
  electronCleaning->SetGoodElectronsName(eleIdMod->GetOutputName());
  electronCleaning->SetCleanElectronsName("CleanElectrons");

  MergeLeptonsMod *merger = new MergeLeptonsMod;
  merger->SetMuonsName(muonId->GetOutputName());
  merger->SetElectronsName(electronCleaning->GetOutputName());
  merger->SetMergedName("MergedLeptons");

  //-----------------------------------
  // Photon Regression + ID 
  //-----------------------------------
  PhotonMvaMod *photonReg = new PhotonMvaMod;
  photonReg->SetRegressionVersion(3);
  photonReg->SetRegressionWeights((MitData+TString("/gbrv3ph_52x.root")).Data());
  photonReg->SetOutputName("GoodPhotonsRegr");
  photonReg->SetApplyShowerRescaling(kTRUE);
  photonReg->SetMinNumPhotons(0);
  photonReg->SetIsData(isData);

  PhotonIDMod *photonIDMod = new PhotonIDMod;
  photonIDMod->SetPtMin(0.0);
  photonIDMod->SetOutputName("GoodPhotons");
  photonIDMod->SetIDType("BaseLineCiCPFNoPresel");
  photonIDMod->SetIsoType("NoIso");
  photonIDMod->SetApplyElectronVeto(kTRUE);
  photonIDMod->SetApplyPixelSeed(kTRUE);
  photonIDMod->SetApplyConversionId(kTRUE);
  photonIDMod->SetApplyFiduciality(kTRUE);       
  photonIDMod->SetIsData(isData);
  photonIDMod->SetPhotonsFromBranch(kFALSE);
  photonIDMod->SetInputName(photonReg->GetOutputName());
  //get the photon with regression energy  
  photonIDMod->DoMCSmear(kTRUE);
  photonIDMod->DoDataEneCorr(kTRUE);
  //---------------------------------shower shape scale--------------------------------------------------------------------------------
  photonIDMod->SetDoShowerShapeScaling(kTRUE);
  photonIDMod->SetShowerShapeType("2012ShowerShape");

  PFTauIDMod *pfTauIDMod = new PFTauIDMod;
  pfTauIDMod->SetPFTausName("HPSTaus");
  pfTauIDMod->SetIsLooseId(kFALSE);

  PhotonCleaningMod *photonCleaningMod = new PhotonCleaningMod;
  photonCleaningMod->SetCleanElectronsName(electronCleaning->GetOutputName());
  photonCleaningMod->SetGoodPhotonsName(photonIDMod->GetOutputName());
  photonCleaningMod->SetCleanPhotonsName("CleanPhotons");

  PFTauCleaningMod *pfTauCleaningMod = new PFTauCleaningMod;
  pfTauCleaningMod->SetGoodPFTausName(pfTauIDMod->GetGoodPFTausName());
  pfTauCleaningMod->SetCleanMuonsName(muonId->GetOutputName());

  PublisherMod<PFJet,Jet> *pubJet = new PublisherMod<PFJet,Jet>("JetPub");
  pubJet->SetInputName("AKt5PFJets");
  pubJet->SetOutputName("PubAKt5PFJets");

  JetCorrectionMod *jetCorr = new JetCorrectionMod;
  if (isData){ 
    jetCorr->AddCorrectionFromFile((MitData+TString("/Summer13_V1_DATA_L1FastJet_AK5PF.txt")).Data()); 
    jetCorr->AddCorrectionFromFile((MitData+TString("/Summer13_V1_DATA_L2Relative_AK5PF.txt")).Data()); 
    jetCorr->AddCorrectionFromFile((MitData+TString("/Summer13_V1_DATA_L3Absolute_AK5PF.txt")).Data()); 
    jetCorr->AddCorrectionFromFile((MitData+TString("/Summer13_V1_DATA_L2L3Residual_AK5PF.txt")).Data());
  }                                                                                      
  else {                                                                                 
    jetCorr->AddCorrectionFromFile((MitData+TString("/Summer13_V1_MC_L1FastJet_AK5PF.txt")).Data()); 
    jetCorr->AddCorrectionFromFile((MitData+TString("/Summer13_V1_MC_L2Relative_AK5PF.txt")).Data()); 
    jetCorr->AddCorrectionFromFile((MitData+TString("/Summer13_V1_MC_L3Absolute_AK5PF.txt")).Data()); 
  }
  jetCorr->SetInputName(pubJet->GetOutputName());
  jetCorr->SetCorrectedName("CorrectedJets");    

  JetIDMod *jetID = new JetIDMod;
  jetID->SetInputName(jetCorr->GetOutputName());
  jetID->SetPtCut(30.0);
  jetID->SetEtaMaxCut(4.7);
  jetID->SetJetEEMFractionMinCut(0.00);
  jetID->SetOutputName("GoodJets");
  jetID->SetApplyBetaCut(kFALSE);
  jetID->SetApplyMVACut(kTRUE);

  JetCleaningMod *jetCleaning = new JetCleaningMod;
  jetCleaning->SetCleanElectronsName(electronCleaning->GetOutputName());
  jetCleaning->SetCleanMuonsName(muonId->GetOutputName());
  jetCleaning->SetCleanPhotonsName(photonCleaningMod->GetOutputName());
  jetCleaning->SetApplyPhotonRemoval(kTRUE);
  jetCleaning->SetGoodJetsName(jetID->GetOutputName());
  jetCleaning->SetCleanJetsName("CleanJets");
        
  MetCorrectionMod *metCorrT0T1Shift = new MetCorrectionMod;
  metCorrT0T1Shift->SetInputName("PFMet");
  metCorrT0T1Shift->SetJetsName(pubJet->GetOutputName());    
  metCorrT0T1Shift->SetCorrectedJetsName(jetCorr->GetOutputName());    
  metCorrT0T1Shift->SetCorrectedName("PFMetT0T1Shift");   
  metCorrT0T1Shift->ApplyType0(kTRUE);   
  metCorrT0T1Shift->ApplyType1(kTRUE);   
  metCorrT0T1Shift->ApplyShift(kTRUE);   
  metCorrT0T1Shift->IsData(isData);
  metCorrT0T1Shift->SetPrint(kFALSE);

  //------------------------------------------------------------------------------------------------
  // select events
  //------------------------------------------------------------------------------------------------
  float minLeadingJetEt = 100.;
  float maxJetEta       = 4.7;
  float minMet          = 160.;

  MonoJetAnalysisMod *monojetSel = new MonoJetAnalysisMod("MonoJetSelector");
  monojetSel->SetInputMetName(metCorrT0T1Shift->GetOutputName());
  monojetSel->SetMetFromBranch(kFALSE);
  monojetSel->SetJetsName(jetCleaning->GetOutputName());
  monojetSel->SetJetsFromBranch(kFALSE);
  monojetSel->SetElectronsName(electronCleaning->GetOutputName());
  monojetSel->SetElectronsFromBranch(kFALSE);
  monojetSel->SetMuonsName(muonId->GetOutputName());
  monojetSel->SetMuonsFromBranch(kFALSE);
  monojetSel->SetTausName(pfTauCleaningMod->GetOutputName());
  monojetSel->SetTausFromBranch(kFALSE);
  monojetSel->SetLeptonsName(merger->GetOutputName());
  monojetSel->SetCategoriesName("MonoJetEventCategories");

  // Jet + MET (signal region)
  unsigned iCat = 0;
  monojetSel->SetMinNumLeptons(iCat, 0);
  monojetSel->SetMaxNumLeptons(iCat, 0);
  monojetSel->SetMinNumTaus(iCat, 0);
  monojetSel->SetMaxNumTaus(iCat, 0);
  monojetSel->SetMinNumJets(iCat, 1);
  monojetSel->SetMaxNumJets(iCat, 1);
  monojetSel->SetMinNumGenNeutrinos(iCat, 0);
  monojetSel->SetMinJetEt(iCat, minLeadingJetEt);
  monojetSel->SetMaxJetEta(iCat, maxJetEta);
  monojetSel->SetMinMetEt(iCat, minMet);
  monojetSel->SetMinEmulMetEt(iCat, 0.);
  monojetSel->SetMinChargedHadronFrac(iCat, 0.2); 
  monojetSel->SetMaxNeutralHadronFrac(iCat, 0.7);
  monojetSel->SetMaxNeutralEmFrac(iCat, 0.7);

  // Dilepton (Z->ll)
  iCat = 1;
  monojetSel->SetMinNumLeptons(iCat, 2);
  monojetSel->SetMaxNumLeptons(iCat, 2);
  monojetSel->SetMinNumTaus(iCat, 0);
  monojetSel->SetMaxNumTaus(iCat, 0);
  monojetSel->SetMinNumJets(iCat, 1);
  monojetSel->SetMaxNumJets(iCat, 1);
  monojetSel->SetMinNumGenNeutrinos(iCat, 0);
  monojetSel->SetMinJetEt(iCat, minLeadingJetEt);
  monojetSel->SetMaxJetEta(iCat, maxJetEta);
  monojetSel->SetMinMetEt(iCat, 0.);
  monojetSel->SetMinEmulMetEt(iCat, minMet);
  monojetSel->SetMinChargedHadronFrac(iCat, 0.2); 
  monojetSel->SetMaxNeutralHadronFrac(iCat, 0.7);
  monojetSel->SetMaxNeutralEmFrac(iCat, 0.7);
  
  // Single lepton (W->lnu)
  iCat = 2;
  monojetSel->SetMinNumLeptons(iCat, 1);
  monojetSel->SetMaxNumLeptons(iCat, 1);
  monojetSel->SetMinNumTaus(iCat, 0);
  monojetSel->SetMaxNumTaus(iCat, 0);
  monojetSel->SetMinNumJets(iCat, 1);
  monojetSel->SetMaxNumJets(iCat, 1);
  monojetSel->SetMinNumGenNeutrinos(iCat, 0);
  monojetSel->SetMinJetEt(iCat, minLeadingJetEt);
  monojetSel->SetMaxJetEta(iCat, maxJetEta);
  monojetSel->SetMinMetEt(iCat, minMet);
  monojetSel->SetMinEmulMetEt(iCat, 0.);
  monojetSel->SetMinChargedHadronFrac(iCat, 0.2); 
  monojetSel->SetMaxNeutralHadronFrac(iCat, 0.7);
  monojetSel->SetMaxNeutralEmFrac(iCat, 0.7);

  // if dataset is Z MC, skim based on the existence of neutrinos
  if(TString(dataset).Contains("zjets")){
    iCat = 3;
    monojetSel->SetMinNumLeptons(iCat, 0);
    monojetSel->SetMaxNumLeptons(iCat, 0);
    monojetSel->SetMinNumTaus(iCat, 0);
    monojetSel->SetMaxNumTaus(iCat, 0);
    monojetSel->SetMinNumJets(iCat, 1);
    monojetSel->SetMaxNumJets(iCat, 1);
    // this is what makes this module special
    monojetSel->SetMinNumGenNeutrinos(iCat, 2);
    monojetSel->SetMinJetEt(iCat, minLeadingJetEt);
    monojetSel->SetMaxJetEta(iCat, maxJetEta);
    monojetSel->SetMinMetEt(iCat, minMet);
    monojetSel->SetMinEmulMetEt(iCat, 0.);
    monojetSel->SetMinChargedHadronFrac(iCat, 0.2); 
    monojetSel->SetMaxNeutralHadronFrac(iCat, 0.7);
    monojetSel->SetMaxNeutralEmFrac(iCat, 0.7);
  }

  //------------------------------------------------------------------------------------------------
  // making the analysis chain
  //------------------------------------------------------------------------------------------------
  // this is how it always starts
  runLumiSel       ->Add(generatorMod);
  generatorMod     ->Add(goodPvMod);
  goodPvMod        ->Add(hltModP);
  // photon regression
  hltModP          ->Add(photonReg);
  // simple object id modules
  photonReg        ->Add(SepPUMod); 
  SepPUMod         ->Add(muonId);
  muonId           ->Add(eleIdMod);
  eleIdMod	   ->Add(electronCleaning);
  electronCleaning ->Add(merger);
  merger           ->Add(photonIDMod);
  photonIDMod	   ->Add(photonCleaningMod);
  photonCleaningMod->Add(pfTauIDMod);
  pfTauIDMod       ->Add(pfTauCleaningMod);
  pfTauCleaningMod ->Add(pubJet);
  pubJet           ->Add(jetCorr);
  jetCorr          ->Add(metCorrT0T1Shift);
  metCorrT0T1Shift ->Add(jetID);
  jetID            ->Add(jetCleaning);
  jetCleaning      ->Add(monojetSel);

  //------------------------------------------------------------------------------------------------
  // setup analysis
  //------------------------------------------------------------------------------------------------
  Analysis *ana = new Analysis;
  ana->SetUseCacher(1);
  ana->SetUseHLT(kTRUE);
  ana->SetKeepHierarchy(kTRUE);
  ana->SetSuperModule(runLumiSel);
  ana->SetPrintScale(100);
  if (nEvents >= 0)
    ana->SetProcessNEvents(nEvents);

  //------------------------------------------------------------------------------------------------
  // organize input
  //------------------------------------------------------------------------------------------------
  Catalog *c = new Catalog(catalogDir);
  TString skimDataset = TString(dataset)+TString("/") +TString(skim);
  Dataset *d = NULL;
  if (TString(skim).CompareTo("noskim") == 0)
    d = c->FindDataset(book,dataset,fileset, 1); // 1 to use smartcache
  else
    d = c->FindDataset(book,skimDataset.Data(),fileset, 1);
  ana->AddDataset(d);
  ana->SetCacheSize(0);

  //------------------------------------------------------------------------------------------------
  // skim output
  //------------------------------------------------------------------------------------------------
  TString outputName = TString(outputLabel);
  outputName += TString("_") + TString(dataset) + TString("_") + TString(skim);
  if (TString(fileset) != TString(""))
    outputName += TString("_") + TString(fileset);
  
  OutputMod *skimOutput = new OutputMod;
  skimOutput->Drop("*");
  skimOutput->Keep("HLT*");
  skimOutput->Keep("MC*");
  skimOutput->Keep("PileupInfo");
  skimOutput->Keep("Rho");
  skimOutput->Keep("EvtSelData");
  skimOutput->Keep("BeamSpot");
  skimOutput->Keep("PrimaryVertexes");
  skimOutput->Keep("PFMet");
  skimOutput->Keep("AKt5PFJets");
  skimOutput->Keep("Electrons");
  skimOutput->Keep("Muons");
  skimOutput->Keep("HPSTaus");
  skimOutput->Keep("Photons");
  // TODO find some object that is named and can hold bit mask info
  skimOutput->AddNewBranch(monojetSel->GetCategoriesName());

  skimOutput->SetMaxFileSize(10 * 1024); // 10 GB - should never exceed
  skimOutput->SetFileName(outputName);
  skimOutput->SetPathName(".");

  monojetSel->Add(skimOutput);

  //------------------------------------------------------------------------------------------------
  // Say what we are doing
  //------------------------------------------------------------------------------------------------
  printf("\n==== PARAMETER SUMMARY FOR THIS JOB ====\n");
  printf("\n JSON file: %s\n",jsonFile.Data());
  printf("\n Rely on Catalog: %s\n",catalogDir);
  printf("  -> Book: %s  Dataset: %s  Skim: %s  Fileset: %s <-\n",book,dataset,skim,fileset);
  printf("\n========================================\n");

  //------------------------------------------------------------------------------------------------
  // run the analysis after successful initialisation
  //------------------------------------------------------------------------------------------------
  ana->Run(false);

  delete ana; // all modules deleted recursively

  // rename the output file so that condor can see it
  gSystem->Rename("./" + outputName + "_000.root", "./" + outputName + ".root");

  return;
}
Example #4
0
//--------------------------------------------------------------------------------------------------
void runBavanti(const char *fileset    = "0000",
		const char *skim       = "noskim",
		const char *dataset    = "r12b-smu-j22-v1",
		const char *book       = "t2mit/filefi/032",
		const char *catalogDir = "/home/cmsprod/catalog",
		const char *outputName = "boostedv",
		int         nEvents    = 1000)
{
  //------------------------------------------------------------------------------------------------
  // some parameters get passed through the environment
  //------------------------------------------------------------------------------------------------
  TString cataDir  = Utils::GetCatalogDir(catalogDir);
  TString mitData  = Utils::GetEnv("MIT_DATA");
  TString json     = Utils::GetEnv("MIT_PROD_JSON");
  TString jsonFile = Utils::GetJsonFile("/home/cmsprod/cms/json");

  Bool_t  isData   = (json.CompareTo("~") != 0);
  printf("\n Initialization worked. Data?: %d\n\n",isData);

  //------------------------------------------------------------------------------------------------
  // some global setups
  //------------------------------------------------------------------------------------------------
  // debugging config
  using namespace mithep;
  gDebugMask  = (Debug::EDebugMask) (Debug::kGeneral | Debug::kTreeIO);
  gDebugLevel = 3;

  // Caching and how
  Int_t local = 1, cacher = 1;

  // local =   0 - as is,
  //           1 - /mt/hadoop  (MIT:SmartCache - preload one-by-one)
  //           2 - /mnt/hadoop (MIT:SmartCache - preload complete fileset)
  //           3 - ./          (xrdcp          - preload one-by-one)
  // cacher =  0 - no file by file caching
  //           1 - file by file caching on

  //------------------------------------------------------------------------------------------------
  // set up information for master module
  //------------------------------------------------------------------------------------------------
  RunLumiSelectionMod *runLumiSel = new RunLumiSelectionMod;
  runLumiSel->SetAcceptMC(kTRUE);                          // Monte Carlo events are always accepted
  
  // only select on run- and lumisection numbers when valid json file present
  if (json.CompareTo("~") != 0 && json.CompareTo("-") != 0) {
    printf(" runBoostedV() - adding jsonFile: %s\n",jsonFile.Data());
    runLumiSel->AddJSONFile(jsonFile.Data());
  }
  if (json.CompareTo("-") == 0) {
    printf("\n WARNING -- Looking at data without JSON file: always accept.\n\n");
    runLumiSel->SetAbortIfNotAccepted(kFALSE);   // accept all events if there is no valid JSON file
  }
  printf("\n Run lumi worked. \n\n");

  //------------------------------------------------------------------------------------------------
  // setup analysis
  //------------------------------------------------------------------------------------------------
  Analysis *ana = new Analysis;
  ana->SetUseCacher(cacher);
  ana->SetUseHLT(kTRUE);
  ana->SetKeepHierarchy(kTRUE);
  ana->SetSuperModule(runLumiSel);
  ana->SetPrintScale(100);
  if (nEvents >= 0)
    ana->SetProcessNEvents(nEvents);

  //------------------------------------------------------------------------------------------------
  // organize input
  //------------------------------------------------------------------------------------------------
  Catalog *c = new Catalog(cataDir.Data());
  TString skimdataset = TString(dataset)+TString("/") +TString(skim);
  Dataset *d = NULL;
  TString bookstr = book;
  if (TString(skim).CompareTo("noskim") == 0)
    d = c->FindDataset(bookstr,dataset,fileset,local);
  else 
    d = c->FindDataset(bookstr,skimdataset.Data(),fileset,local);
  ana->AddDataset(d);

  //------------------------------------------------------------------------------------------------
  // organize output
  //------------------------------------------------------------------------------------------------
  TString rootFile = TString(outputName);
  rootFile += TString("_") + TString(dataset) + TString("_") + TString(skim);
  if (TString(fileset) != TString(""))
    rootFile += TString("_") + TString(fileset);
  ana->SetOutputName(rootFile + TString(".root"));
  ana->SetCacheSize(0);

  //------------------------------------------------------------------------------------------------
  // select events with a good primary vertex
  //------------------------------------------------------------------------------------------------
  GoodPVFilterMod *goodPvFilterMod = new GoodPVFilterMod;
  goodPvFilterMod->SetMinVertexNTracks(0);
  goodPvFilterMod->SetMinNDof(4.0);
  goodPvFilterMod->SetMaxAbsZ(24.0);
  goodPvFilterMod->SetMaxRho(2.0);
  goodPvFilterMod->SetIsMC(!isData);
  goodPvFilterMod->SetVertexesName("PrimaryVertexes");

  //------------------------------------------------------------------------------------------------
  // object id and cleaning sequence
  //------------------------------------------------------------------------------------------------

  MuonIDMod *muonId = new MuonIDMod;
  muonId->SetOutputName("CleanMuons");
  muonId->SetIntRadius(0.0);
  muonId->SetClassType("GlobalTracker");
  muonId->SetIDType("WWMuIdV4");
  muonId->SetIsoType("IsoRingsV0_BDTG_Iso");
  muonId->SetApplyD0Cut(kTRUE);
  muonId->SetApplyDZCut(kTRUE);
  muonId->SetWhichVertex(0);
  muonId->SetRhoType(RhoUtilities::CMS_RHO_RHOKT6PFJETS);
  muonId->SetPtMin(10.);
  muonId->SetEtaCut(2.4);

  //------------------------------------------------------------------------------------------------
  // save the interesting collection using the skim modules and the output module
  //------------------------------------------------------------------------------------------------
  SkimMod<Track> *skmGlobalMuonTracks = new SkimMod<Track>;
  skmGlobalMuonTracks->SetBranchName("GlobalMuonTracks");
  skmGlobalMuonTracks->SetColFromBranch(kTRUE);
  skmGlobalMuonTracks->SetColMarkFilter(kTRUE);
  skmGlobalMuonTracks->SetPublishArray(kFALSE);

  SkimMod<Track> *skmStandaloneMuonTracks = new SkimMod<Track>;
  skmStandaloneMuonTracks->SetBranchName("StandaloneMuonTracks");
  skmStandaloneMuonTracks->SetColFromBranch(kTRUE);
  skmStandaloneMuonTracks->SetColMarkFilter(kTRUE);
  skmStandaloneMuonTracks->SetPublishArray(kFALSE);

  SkimMod<Track> *skmStandaloneMuonTracksWVtxConstraint = new SkimMod<Track>;
  skmStandaloneMuonTracksWVtxConstraint->SetBranchName("StandaloneMuonTracksWVtxConstraint");
  skmStandaloneMuonTracksWVtxConstraint->SetColFromBranch(kTRUE);
  skmStandaloneMuonTracksWVtxConstraint->SetColMarkFilter(kTRUE);
  skmStandaloneMuonTracksWVtxConstraint->SetPublishArray(kFALSE);

  SkimMod<Track> *skmTracks = new SkimMod<Track>;
  skmTracks->SetBranchName("Tracks");
  skmTracks->SetColFromBranch(kTRUE);
  skmTracks->SetColMarkFilter(kTRUE);
  skmTracks->SetPublishArray(kFALSE);

  SkimMod<Muon> *skmMuons = new SkimMod<Muon>;
  skmMuons->SetBranchName("Muons");
  skmMuons->SetColFromBranch(kTRUE);
  skmMuons->SetColMarkFilter(kTRUE);
  skmMuons->SetPublishArray(kTRUE);

  OutputMod *outMod1 = new OutputMod;
  outMod1->Drop("*");
  outMod1->Keep("Muons");
  outMod1->Keep("GlobalMuonTracks");
  outMod1->Keep("StandaloneMuonTracks");
  outMod1->Keep("StandaloneMuonTracksWVtxConstraint");
  outMod1->Keep("Tracks");
  outMod1->SetKeepTamBr(kTRUE);
  outMod1->SetFileName("bambu");

  OutputMod *outMod2 = new OutputMod;
  outMod2->Drop("*");
  outMod2->AddNewBranch(TString("SkmMuons"));
  outMod2->AddNewBranch(TString("SkmGlobalMuonTracks"));
  outMod1->AddNewBranch(TString("SkmStandaloneMuonTracks"));
  outMod1->AddNewBranch(TString("SkmStandaloneMuonTracksWVtxConstraint"));
  outMod2->AddNewBranch(TString("SkmTracks"));
  outMod2->SetKeepTamBr(kFALSE);
  outMod2->SetFileName("bavanti");

  //------------------------------------------------------------------------------------------------
  // making analysis chain
  //------------------------------------------------------------------------------------------------
  runLumiSel                           ->Add(goodPvFilterMod);
  //goodPvFilterMod                      ->Add(skmGlobalMuonTracks);
  goodPvFilterMod                      ->Add(muonId);
  muonId                               ->Add(skmGlobalMuonTracks);
  skmGlobalMuonTracks                  ->Add(skmStandaloneMuonTracks);
  skmStandaloneMuonTracks              ->Add(skmStandaloneMuonTracksWVtxConstraint);
  skmStandaloneMuonTracksWVtxConstraint->Add(skmTracks);
  skmTracks                            ->Add(skmMuons);
  skmMuons                             ->Add(outMod1);
  outMod1                              ->Add(outMod2);
  
  //muonId             ->Add(outMod1);
  //muonId             ->Add(skmMuons);
  //skmMuons           ->Add(outMod1);
  //muonId             ->Add(skmMuons);
  //skmMuons           ->Add(skmGlobalMuonTracks);
  //skmGlobalMuonTracks->Add(outMod1);
  //outMod1            ->Add(outMod2);
  //------------------------------------------------------------------------------------------------
  // Say what we are doing
  //------------------------------------------------------------------------------------------------
  printf("\n==== PARAMETER SUMMARY FOR THIS JOB ====\n");
  printf("\n JSON file: %s\n",jsonFile.Data());
  printf("\n Rely on Catalog: %s\n",cataDir.Data());
  printf("  -> Book: %s  Dataset: %s  Skim: %s  Fileset: %s <-\n",book,dataset,skim,fileset);
  printf("\n Root output:   %s\n",rootFile.Data());  
  printf("\n========================================\n");

  //------------------------------------------------------------------------------------------------
  // run the analysis after successful initialisation
  //------------------------------------------------------------------------------------------------
  ana->Run(!gROOT->IsBatch());

  return;
}
//--------------------------------------------------------------------------------------------------
void executeComputeElectronFakeRateMod(const char *fileset  = "",
                                       const char *skim         = "noskim",
                                       const char *dataset    = "s8-ttbar-id9",
                                       const char *book       = "mit/filler/006",
                                       const char *catalogDir = "/home/mitprod/catalog",
                                       const char *outputName = "ComputeElectronFakeRateMod",
                                       Int_t       sampletype = 0, 
                                       int         nEvents    = -1)
{
  //------------------------------------------------------------------------------------------------
  // some global setups
  //------------------------------------------------------------------------------------------------
  using namespace mithep;
  gDebugMask  = Debug::kAnalysis;
  gDebugLevel = 3;

  string mctype = "";
  Bool_t VetoTriggerJet = false;
  Bool_t VetoGenLeptons = true;
  if (sampletype == 10) {
    VetoTriggerJet = true;
    VetoGenLeptons = false;
  }

  if (sampletype == 20) {
    VetoGenLeptons = false;
  }

  if (sampletype == 3 || string(dataset) == "s8-wjets-mg-id11" )
    mctype = "kMCTypeVLightJets";
  if (sampletype == 4 || string(dataset) == "s8-vqq-mg-id11")
    mctype = "kMCTypeVQQ";
  if (sampletype == 5 || string(dataset) == "f8-wc-mg-id11")
    mctype = "kMCTypeWc";

  //------------------------------------------------------------------------------------------------
  // generator information
  //------------------------------------------------------------------------------------------------
  GeneratorMod *generatorMod = new GeneratorMod;
  //generatorMod->SetFillHist(kTRUE);

  PartonFlavorHistoryMod *partonFlavorHistoryMod = new PartonFlavorHistoryMod;
  partonFlavorHistoryMod->SetMCSampleType(mctype.c_str());
  partonFlavorHistoryMod->SetApplyPartonFlavorFilter(kTRUE);

  //------------------------------------------------------------------------------------------------
  // HLT information
  //------------------------------------------------------------------------------------------------
//   HLTMod *hltmod = new HLTMod;
//   hltmod->SetPrintTable(kTRUE);
//   hltmod->AddTrigger("HLT_IsoEle15_L1I");
//   hltmod->AddTrigger("HLT_Ele15_SW_L1R");
//   hltmod->AddTrigger("HLT_IsoEle15_LW_L1I");
//   hltmod->AddTrigger("HLT_IsoEle18_L1R");
//   hltmod->AddTrigger("HLT_Ele15_LW_L1R");
//   hltmod->AddTrigger("HLT_LooseIsoEle15_LW_L1R");
//   hltmod->AddTrigger("HLT_IsoMu15");
//   hltmod->AddTrigger("HLT_Mu15");
//   hltmod->SetTrigObjsName("myhltobjs");

  HLTMod *hltmod_Jet30 = new HLTMod;
  hltmod_Jet30->SetName("HLTMod_Jet30");
  hltmod_Jet30->SetPrintTable(kFALSE);
  hltmod_Jet30->AddTrigger("HLT_Jet30");
  hltmod_Jet30->SetTrigObjsName("myhltobjs_Jet30");

  HLTMod *hltmod_Jet50 = new HLTMod;
  hltmod_Jet50->SetName("HLTMod_Jet50");
  hltmod_Jet50->SetPrintTable(kFALSE);
  hltmod_Jet50->AddTrigger("HLT_Jet50");
  hltmod_Jet50->SetTrigObjsName("myhltobjs_Jet50");

  HLTMod *hltmod_Jet80 = new HLTMod;
  hltmod_Jet80->SetName("HLTMod_Jet80");
  hltmod_Jet80->SetPrintTable(kFALSE);
  hltmod_Jet80->AddTrigger("HLT_Jet80");
  hltmod_Jet80->SetTrigObjsName("myhltobjs_Jet80");

  HLTMod *hltmod_Jet110 = new HLTMod;
  hltmod_Jet110->SetName("HLTMod_Jet110");
  hltmod_Jet110->SetPrintTable(kFALSE);
  hltmod_Jet110->AddTrigger("HLT_Jet110");
  hltmod_Jet110->SetTrigObjsName("myhltobjs_Jet110");

  HLTMod *hltmod_Photon15 = new HLTMod;
  hltmod_Photon15->SetName("HLTMod_Photon15");
  hltmod_Photon15->SetPrintTable(kFALSE);
  hltmod_Photon15->AddTrigger("HLT_Photon15_L1R");
  hltmod_Photon15->SetTrigObjsName("myhltobjs_Photon15");

  HLTMod *hltmod_Photon25 = new HLTMod;
  hltmod_Photon25->SetName("HLTMod_Photon25");
  hltmod_Photon25->SetPrintTable(kFALSE);
  hltmod_Photon25->AddTrigger("HLT_Photon25_L1R");
  hltmod_Photon25->SetTrigObjsName("myhltobjs_Photon25");


  //------------------------------------------------------------------------------------------------
  // publisher Mod
  //------------------------------------------------------------------------------------------------
  PublisherMod<CaloJet,Jet> *pubJet = new PublisherMod<CaloJet,Jet>("JetPub");
  pubJet->SetInputName("SisCone5Jets");
  pubJet->SetOutputName("PubSisCone5Jets");

  PublisherMod<CaloMet,Met> *pubMet = new PublisherMod<CaloMet,Met>("MetPub");
  pubMet->SetInputName("SisCone5Met");
  pubMet->SetOutputName(ModNames::gkCleanCaloMetName);

  //------------------------------------------------------------------------------------------------
  // object id and cleaning sequence
  //------------------------------------------------------------------------------------------------
  MuonIDMod           *muonID           = new MuonIDMod;  
  muonID->SetIDType("Loose");
  muonID->SetIsoType("TrackCaloSliding"); 
  ElectronIDMod       *electronID       = new ElectronIDMod;
  electronID->SetIDType(TString("Tight"));
  electronID->SetIsoType(TString("TrackJuraSliding"));
  electronID->SetApplyConversionFilter(kTRUE);

  PhotonIDMod         *photonID       = new PhotonIDMod;
  photonID->SetIDType(TString("Custom"));
  photonID->SetIsoType(TString("CombinedIso"));
  photonID->SetPtMin(20.0);

  JetIDMod            *jetID            = new JetIDMod;
  jetID->SetInputName(pubJet->GetOutputName());
  jetID->SetUseCorrection(kTRUE);
  jetID->SetPtCut(35.0);

  ElectronCleaningMod *electronCleaning = new ElectronCleaningMod;
  PhotonCleaningMod   *photonCleaning   = new PhotonCleaningMod;
  JetCleaningMod      *jetCleaning      = new JetCleaningMod;

  MergeLeptonsMod *mergeLeptonsMod = new MergeLeptonsMod;

  //------------------------------------------------------------------------------------------------
  // generate fakeable objects
  //------------------------------------------------------------------------------------------------
  GenerateFakeableObjectsMod *generateFakeableObjectsMod = new GenerateFakeableObjectsMod;
  generateFakeableObjectsMod->SetName("GenerateFakeableObjectsMod");
  generateFakeableObjectsMod->SetElectronFOType("GsfPlusSC");
  generateFakeableObjectsMod->SetMuonFOType("IsoTrack");
  generateFakeableObjectsMod->SetVetoTriggerJet(VetoTriggerJet);
  generateFakeableObjectsMod->SetVetoGenLeptons(VetoGenLeptons);
  generateFakeableObjectsMod->SetVetoCleanLeptons(kFALSE);
  generateFakeableObjectsMod->SetElectronFakeableObjectsName("GsfPlusSCElectronFakeableObjects");
  generateFakeableObjectsMod->SetMuonFakeableObjectsName("IsoTrackMuonFakeableObjects");

  GenerateFakeableObjectsMod *generateFakeableObjectsMod_Reco = new GenerateFakeableObjectsMod;
  generateFakeableObjectsMod_Reco->SetName("GenerateFakeableObjectsMod_Reco");
  generateFakeableObjectsMod_Reco->SetElectronFOType("Reco");
  generateFakeableObjectsMod_Reco->SetMuonFOType("Global");
  generateFakeableObjectsMod_Reco->SetVetoTriggerJet(VetoTriggerJet);
  generateFakeableObjectsMod_Reco->SetVetoGenLeptons(VetoGenLeptons);
  generateFakeableObjectsMod_Reco->SetVetoCleanLeptons(kFALSE);
  generateFakeableObjectsMod_Reco->SetElectronFakeableObjectsName("RecoElectronFakeableObjects");
  generateFakeableObjectsMod_Reco->SetMuonFakeableObjectsName("GlobalMuonFakeableObjects");

  GenerateFakeableObjectsMod *generateFakeableObjectsMod_Jet30 = new GenerateFakeableObjectsMod;
  generateFakeableObjectsMod_Jet30->SetName("GenerateFakeableObjectsMod_Jet30");
  generateFakeableObjectsMod_Jet30->SetElectronFOType("GsfPlusSC");
  generateFakeableObjectsMod_Jet30->SetMuonFOType("IsoTrack");
  generateFakeableObjectsMod_Jet30->SetTriggerName("HLTMod_Jet30");
  generateFakeableObjectsMod_Jet30->SetTriggerObjectsName("myhltobjs_Jet30");
  generateFakeableObjectsMod_Jet30->SetVetoTriggerJet(VetoTriggerJet);
  generateFakeableObjectsMod_Jet30->SetVetoGenLeptons(VetoGenLeptons);
  generateFakeableObjectsMod_Jet30->SetVetoCleanLeptons(kFALSE);
  generateFakeableObjectsMod_Jet30->SetElectronFakeableObjectsName("GsfPlusSCElectronFakeableObjects_Jet30");
  generateFakeableObjectsMod_Jet30->SetMuonFakeableObjectsName("IsoTrackMuonFakeableObjects_Jet30");

  GenerateFakeableObjectsMod *generateFakeableObjectsMod_Jet50 = new GenerateFakeableObjectsMod;
  generateFakeableObjectsMod_Jet50->SetName("GenerateFakeableObjectsMod_Jet50");
  generateFakeableObjectsMod_Jet50->SetElectronFOType("GsfPlusSC");
  generateFakeableObjectsMod_Jet50->SetMuonFOType("IsoTrack");
  generateFakeableObjectsMod_Jet50->SetTriggerName("HLTMod_Jet50");
  generateFakeableObjectsMod_Jet50->SetTriggerObjectsName("myhltobjs_Jet50");
  generateFakeableObjectsMod_Jet50->SetVetoTriggerJet(VetoTriggerJet);
  generateFakeableObjectsMod_Jet50->SetVetoGenLeptons(VetoGenLeptons);
  generateFakeableObjectsMod_Jet50->SetVetoCleanLeptons(kFALSE);
  generateFakeableObjectsMod_Jet50->SetElectronFakeableObjectsName("GsfPlusSCElectronFakeableObjects_Jet50");
  generateFakeableObjectsMod_Jet50->SetMuonFakeableObjectsName("IsoTrackMuonFakeableObjects_Jet50");

  GenerateFakeableObjectsMod *generateFakeableObjectsMod_Jet80 = new GenerateFakeableObjectsMod;
  generateFakeableObjectsMod_Jet80->SetName("GenerateFakeableObjectsMod_Jet80");
  generateFakeableObjectsMod_Jet80->SetElectronFOType("GsfPlusSC");
  generateFakeableObjectsMod_Jet80->SetMuonFOType("IsoTrack");
  generateFakeableObjectsMod_Jet80->SetTriggerName("HLTMod_Jet80");
  generateFakeableObjectsMod_Jet80->SetTriggerObjectsName("myhltobjs_Jet80");
  generateFakeableObjectsMod_Jet80->SetVetoTriggerJet(VetoTriggerJet);
  generateFakeableObjectsMod_Jet80->SetVetoGenLeptons(VetoGenLeptons);
  generateFakeableObjectsMod_Jet80->SetVetoCleanLeptons(kFALSE);
  generateFakeableObjectsMod_Jet80->SetElectronFakeableObjectsName("GsfPlusSCElectronFakeableObjects_Jet80");
  generateFakeableObjectsMod_Jet80->SetMuonFakeableObjectsName("IsoTrackMuonFakeableObjects_Jet80");

  GenerateFakeableObjectsMod *generateFakeableObjectsMod_Jet110 = new GenerateFakeableObjectsMod;
  generateFakeableObjectsMod_Jet110->SetName("GenerateFakeableObjectsMod_Jet110");
  generateFakeableObjectsMod_Jet110->SetElectronFOType("GsfPlusSC");
  generateFakeableObjectsMod_Jet110->SetMuonFOType("IsoTrack");
  generateFakeableObjectsMod_Jet110->SetTriggerName("HLTMod_Jet110");
  generateFakeableObjectsMod_Jet110->SetTriggerObjectsName("myhltobjs_Jet110");
  generateFakeableObjectsMod_Jet110->SetVetoTriggerJet(VetoTriggerJet);
  generateFakeableObjectsMod_Jet110->SetVetoGenLeptons(VetoGenLeptons);
  generateFakeableObjectsMod_Jet110->SetVetoCleanLeptons(kFALSE);
  generateFakeableObjectsMod_Jet110->SetElectronFakeableObjectsName("GsfPlusSCElectronFakeableObjects_Jet110");
  generateFakeableObjectsMod_Jet110->SetMuonFakeableObjectsName("IsoTrackMuonFakeableObjects_Jet110");

  GenerateFakeableObjectsMod *generateFakeableObjectsMod_Reco_Jet30 = new GenerateFakeableObjectsMod;
  generateFakeableObjectsMod_Reco_Jet30->SetName("GenerateFakeableObjectsMod_Reco_Jet30");
  generateFakeableObjectsMod_Reco_Jet30->SetElectronFOType("Reco");
  generateFakeableObjectsMod_Reco_Jet30->SetMuonFOType("Global");
  generateFakeableObjectsMod_Reco_Jet30->SetTriggerName("HLTMod_Jet30");
  generateFakeableObjectsMod_Reco_Jet30->SetTriggerObjectsName("myhltobjs_Jet30");
  generateFakeableObjectsMod_Reco_Jet30->SetVetoTriggerJet(VetoTriggerJet);
  generateFakeableObjectsMod_Reco_Jet30->SetVetoGenLeptons(VetoGenLeptons);
  generateFakeableObjectsMod_Reco_Jet30->SetVetoCleanLeptons(kFALSE);
  generateFakeableObjectsMod_Reco_Jet30->SetElectronFakeableObjectsName("RecoElectronFakeableObjects_Jet30");
  generateFakeableObjectsMod_Reco_Jet30->SetMuonFakeableObjectsName("GlobalMuonFakeableObjects_Jet30");

  GenerateFakeableObjectsMod *generateFakeableObjectsMod_Reco_Jet50 = new GenerateFakeableObjectsMod;
  generateFakeableObjectsMod_Reco_Jet50->SetName("GenerateFakeableObjectsMod_Reco_Jet50");
  generateFakeableObjectsMod_Reco_Jet50->SetElectronFOType("Reco");
  generateFakeableObjectsMod_Reco_Jet50->SetMuonFOType("Global");
  generateFakeableObjectsMod_Reco_Jet50->SetTriggerName("HLTMod_Jet50");
  generateFakeableObjectsMod_Reco_Jet50->SetTriggerObjectsName("myhltobjs_Jet50");
  generateFakeableObjectsMod_Reco_Jet50->SetVetoTriggerJet(VetoTriggerJet);
  generateFakeableObjectsMod_Reco_Jet50->SetVetoGenLeptons(VetoGenLeptons);
  generateFakeableObjectsMod_Reco_Jet50->SetVetoCleanLeptons(kFALSE);
  generateFakeableObjectsMod_Reco_Jet50->SetElectronFakeableObjectsName("RecoElectronFakeableObjects_Jet50");
  generateFakeableObjectsMod_Reco_Jet50->SetMuonFakeableObjectsName("GlobalMuonFakeableObjects_Jet50");

  GenerateFakeableObjectsMod *generateFakeableObjectsMod_Reco_Jet80 = new GenerateFakeableObjectsMod;
  generateFakeableObjectsMod_Reco_Jet80->SetName("GenerateFakeableObjectsMod_Reco_Jet80");
  generateFakeableObjectsMod_Reco_Jet80->SetElectronFOType("Reco");
  generateFakeableObjectsMod_Reco_Jet80->SetMuonFOType("Global");
  generateFakeableObjectsMod_Reco_Jet80->SetTriggerName("HLTMod_Jet80");
  generateFakeableObjectsMod_Reco_Jet80->SetTriggerObjectsName("myhltobjs_Jet80");
  generateFakeableObjectsMod_Reco_Jet80->SetVetoTriggerJet(VetoTriggerJet);
  generateFakeableObjectsMod_Reco_Jet80->SetVetoGenLeptons(VetoGenLeptons);
  generateFakeableObjectsMod_Reco_Jet80->SetVetoCleanLeptons(kFALSE);
  generateFakeableObjectsMod_Reco_Jet80->SetElectronFakeableObjectsName("RecoElectronFakeableObjects_Jet80");
  generateFakeableObjectsMod_Reco_Jet80->SetMuonFakeableObjectsName("GlobalMuonFakeableObjects_Jet80");

  GenerateFakeableObjectsMod *generateFakeableObjectsMod_Reco_Jet110 = new GenerateFakeableObjectsMod;
  generateFakeableObjectsMod_Reco_Jet110->SetName("GenerateFakeableObjectsMod_Reco_Jet110");
  generateFakeableObjectsMod_Reco_Jet110->SetElectronFOType("Reco");
  generateFakeableObjectsMod_Reco_Jet110->SetMuonFOType("Global");
  generateFakeableObjectsMod_Reco_Jet110->SetTriggerName("HLTMod_Jet110");
  generateFakeableObjectsMod_Reco_Jet110->SetTriggerObjectsName("myhltobjs_Jet110");
  generateFakeableObjectsMod_Reco_Jet110->SetVetoTriggerJet(VetoTriggerJet);
  generateFakeableObjectsMod_Reco_Jet110->SetVetoGenLeptons(VetoGenLeptons);
  generateFakeableObjectsMod_Reco_Jet110->SetVetoCleanLeptons(kFALSE);
  generateFakeableObjectsMod_Reco_Jet110->SetElectronFakeableObjectsName("RecoElectronFakeableObjects_Jet110");
  generateFakeableObjectsMod_Reco_Jet110->SetMuonFakeableObjectsName("GlobalMuonFakeableObjects_Jet110");


  //------------------------------------------------------------------------------------------------
  // analyses modules
  //------------------------------------------------------------------------------------------------
  ComputeElectronFakeRateMod *analysisMod = new ComputeElectronFakeRateMod;
  analysisMod->SetName("ComputeElectronFakeRateMod");
  analysisMod->SetVetoTriggerJet(VetoTriggerJet);
  analysisMod->SetVetoGeneratorLeptons(VetoGenLeptons);
  analysisMod->SetElectronFakeableObjectsName("GsfPlusSCElectronFakeableObjects");
  analysisMod->SetMetName(pubMet->GetOutputName());
  analysisMod->SetSampleType(sampletype);

  ComputeElectronFakeRateMod *analysisMod_Reco = new ComputeElectronFakeRateMod;
  analysisMod_Reco->SetName("ComputeElectronFakeRateMod_Reco");
  analysisMod_Reco->SetVetoTriggerJet(VetoTriggerJet);
  analysisMod_Reco->SetVetoGeneratorLeptons(VetoGenLeptons);
  analysisMod_Reco->SetElectronFakeableObjectsName("RecoElectronFakeableObjects");
  analysisMod_Reco->SetMetName(pubMet->GetOutputName());
  analysisMod_Reco->SetSampleType(sampletype);

  ComputeElectronFakeRateMod *analysisMod_Jet30 = new ComputeElectronFakeRateMod;
  analysisMod_Jet30->SetName("ComputeElectronFakeRateMod_Jet30");
  analysisMod_Jet30->SetTriggerName("HLT_Jet30");
  analysisMod_Jet30->SetTriggerObjectsName("myhltobjs_Jet30");
  analysisMod_Jet30->SetVetoTriggerJet(VetoTriggerJet);
  analysisMod_Jet30->SetVetoGeneratorLeptons(VetoGenLeptons);
  analysisMod_Jet30->SetElectronFakeableObjectsName("GsfPlusSCElectronFakeableObjects_Jet30");
  analysisMod_Jet30->SetMetName(pubMet->GetOutputName());
  analysisMod_Jet30->SetSampleType(sampletype);

  ComputeElectronFakeRateMod *analysisMod_Jet50 = new ComputeElectronFakeRateMod;
  analysisMod_Jet50->SetName("ComputeElectronFakeRateMod_Jet50");
  analysisMod_Jet50->SetTriggerName("HLT_Jet50");
  analysisMod_Jet50->SetTriggerObjectsName("myhltobjs_Jet50");
  analysisMod_Jet50->SetVetoTriggerJet(VetoTriggerJet);
  analysisMod_Jet50->SetVetoGeneratorLeptons(VetoGenLeptons);
  analysisMod_Jet50->SetElectronFakeableObjectsName("GsfPlusSCElectronFakeableObjects_Jet50");
  analysisMod_Jet50->SetMetName(pubMet->GetOutputName());
  analysisMod_Jet50->SetSampleType(sampletype);

  ComputeElectronFakeRateMod *analysisMod_Jet80 = new ComputeElectronFakeRateMod;
  analysisMod_Jet80->SetName("ComputeElectronFakeRateMod_Jet80");
  analysisMod_Jet80->SetTriggerName("HLT_Jet80");
  analysisMod_Jet80->SetTriggerObjectsName("myhltobjs_Jet80");
  analysisMod_Jet80->SetVetoTriggerJet(VetoTriggerJet);
  analysisMod_Jet80->SetVetoGeneratorLeptons(VetoGenLeptons);
  analysisMod_Jet80->SetElectronFakeableObjectsName("GsfPlusSCElectronFakeableObjects_Jet80");
  analysisMod_Jet80->SetMetName(pubMet->GetOutputName());
  analysisMod_Jet80->SetSampleType(sampletype);

  ComputeElectronFakeRateMod *analysisMod_Jet110 = new ComputeElectronFakeRateMod;
  analysisMod_Jet110->SetName("ComputeElectronFakeRateMod_Jet110");
  analysisMod_Jet110->SetTriggerName("HLT_Jet110");
  analysisMod_Jet110->SetTriggerObjectsName("myhltobjs_Jet110");
  analysisMod_Jet110->SetVetoTriggerJet(VetoTriggerJet);
  analysisMod_Jet110->SetVetoGeneratorLeptons(VetoGenLeptons);
  analysisMod_Jet110->SetElectronFakeableObjectsName("GsfPlusSCElectronFakeableObjects_Jet110");
  analysisMod_Jet110->SetMetName(pubMet->GetOutputName());
  analysisMod_Jet110->SetSampleType(sampletype);

  ComputeElectronFakeRateMod *analysisMod_Reco_Jet30 = new ComputeElectronFakeRateMod;
  analysisMod_Reco_Jet30->SetName("ComputeElectronFakeRateMod_Reco_Jet30");
  analysisMod_Reco_Jet30->SetTriggerName("HLT_Jet30");
  analysisMod_Reco_Jet30->SetTriggerObjectsName("myhltobjs_Jet30");
  analysisMod_Reco_Jet30->SetVetoTriggerJet(VetoTriggerJet);
  analysisMod_Reco_Jet30->SetVetoGeneratorLeptons(VetoGenLeptons);
  analysisMod_Reco_Jet30->SetElectronFakeableObjectsName("RecoElectronFakeableObjects_Jet30");
  analysisMod_Reco_Jet30->SetMetName(pubMet->GetOutputName());
  analysisMod_Reco_Jet30->SetSampleType(sampletype);

  ComputeElectronFakeRateMod *analysisMod_Reco_Jet50 = new ComputeElectronFakeRateMod;
  analysisMod_Reco_Jet50->SetName("ComputeElectronFakeRateMod_Reco_Jet50");
  analysisMod_Reco_Jet50->SetTriggerName("HLT_Jet50");
  analysisMod_Reco_Jet50->SetTriggerObjectsName("myhltobjs_Jet50");
  analysisMod_Reco_Jet50->SetVetoTriggerJet(VetoTriggerJet);
  analysisMod_Reco_Jet50->SetVetoGeneratorLeptons(VetoGenLeptons);
  analysisMod_Reco_Jet50->SetElectronFakeableObjectsName("RecoElectronFakeableObjects_Jet50");
  analysisMod_Reco_Jet50->SetMetName(pubMet->GetOutputName());
  analysisMod_Reco_Jet50->SetSampleType(sampletype);

  ComputeElectronFakeRateMod *analysisMod_Reco_Jet80 = new ComputeElectronFakeRateMod;
  analysisMod_Reco_Jet80->SetName("ComputeElectronFakeRateMod_Reco_Jet80");
  analysisMod_Reco_Jet80->SetTriggerName("HLT_Jet80");
  analysisMod_Reco_Jet80->SetTriggerObjectsName("myhltobjs_Jet80");
  analysisMod_Reco_Jet80->SetVetoTriggerJet(VetoTriggerJet);
  analysisMod_Reco_Jet80->SetVetoGeneratorLeptons(VetoGenLeptons);
  analysisMod_Reco_Jet80->SetElectronFakeableObjectsName("RecoElectronFakeableObjects_Jet80");
  analysisMod_Reco_Jet80->SetMetName(pubMet->GetOutputName());
  analysisMod_Reco_Jet80->SetSampleType(sampletype);

  ComputeElectronFakeRateMod *analysisMod_Reco_Jet110 = new ComputeElectronFakeRateMod;
  analysisMod_Reco_Jet110->SetName("ComputeElectronFakeRateMod_Reco_Jet110");
  analysisMod_Reco_Jet110->SetTriggerName("HLT_Jet110");
  analysisMod_Reco_Jet110->SetTriggerObjectsName("myhltobjs_Jet110");
  analysisMod_Reco_Jet110->SetVetoTriggerJet(VetoTriggerJet);
  analysisMod_Reco_Jet110->SetVetoGeneratorLeptons(VetoGenLeptons);
  analysisMod_Reco_Jet110->SetElectronFakeableObjectsName("RecoElectronFakeableObjects_Jet110");
  analysisMod_Reco_Jet110->SetMetName(pubMet->GetOutputName());
  analysisMod_Reco_Jet110->SetSampleType(sampletype);

  ComputeElectronFakeRateMod *analysisMod_Photon15 = new ComputeElectronFakeRateMod;
  analysisMod_Photon15->SetName("ComputeElectronFakeRateMod_Photon15");
  analysisMod_Photon15->SetTriggerName("HLT_Photon15_L1R");
  analysisMod_Photon15->SetTriggerObjectsName("myhltobjs_Photon15");
  analysisMod_Photon15->SetVetoTriggerJet(VetoTriggerJet);
  analysisMod_Photon15->SetVetoGeneratorLeptons(VetoGenLeptons);
  analysisMod_Photon15->SetElectronFakeableObjectsName("GsfPlusSCElectronFakeableObjects");
  analysisMod_Photon15->SetMetName(pubMet->GetOutputName());
  analysisMod_Photon15->SetSampleType(sampletype);

  ComputeElectronFakeRateMod *analysisMod_Photon25 = new ComputeElectronFakeRateMod;
  analysisMod_Photon25->SetName("ComputeElectronFakeRateMod_Photon25");
  analysisMod_Photon25->SetTriggerName("HLT_Photon25_L1R");
  analysisMod_Photon25->SetTriggerObjectsName("myhltobjs_Photon25");
  analysisMod_Photon25->SetVetoTriggerJet(VetoTriggerJet);
  analysisMod_Photon25->SetVetoGeneratorLeptons(VetoGenLeptons);
  analysisMod_Photon25->SetElectronFakeableObjectsName("GsfPlusSCElectronFakeableObjects");
  analysisMod_Photon25->SetMetName(pubMet->GetOutputName());
  analysisMod_Photon25->SetSampleType(sampletype);

  ComputeElectronFakeRateMod *analysisMod_Reco_Photon15 = new ComputeElectronFakeRateMod;
  analysisMod_Reco_Photon15->SetName("ComputeElectronFakeRateMod_Reco_Photon15");
  analysisMod_Reco_Photon15->SetTriggerName("HLT_Photon15_L1R");
  analysisMod_Reco_Photon15->SetTriggerObjectsName("myhltobjs_Photon15");
  analysisMod_Reco_Photon15->SetVetoTriggerJet(VetoTriggerJet);
  analysisMod_Reco_Photon15->SetVetoGeneratorLeptons(VetoGenLeptons);
  analysisMod_Reco_Photon15->SetElectronFakeableObjectsName("RecoElectronFakeableObjects");
  analysisMod_Reco_Photon15->SetMetName(pubMet->GetOutputName());
  analysisMod_Reco_Photon15->SetSampleType(sampletype);

  ComputeElectronFakeRateMod *analysisMod_Reco_Photon25 = new ComputeElectronFakeRateMod;
  analysisMod_Reco_Photon25->SetName("ComputeElectronFakeRateMod_Reco_Photon25");
  analysisMod_Reco_Photon25->SetTriggerName("HLT_Photon25_L1R");
  analysisMod_Reco_Photon25->SetTriggerObjectsName("myhltobjs_Photon25");
  analysisMod_Reco_Photon25->SetVetoTriggerJet(VetoTriggerJet);
  analysisMod_Reco_Photon25->SetVetoGeneratorLeptons(VetoGenLeptons);
  analysisMod_Reco_Photon25->SetElectronFakeableObjectsName("RecoElectronFakeableObjects");
  analysisMod_Reco_Photon25->SetMetName(pubMet->GetOutputName());
  analysisMod_Reco_Photon25->SetSampleType(sampletype);

  //------------------------------------------------------------------------------------------------
  // making analysis chain
  //------------------------------------------------------------------------------------------------

  if (sampletype == 3 ||sampletype == 4 || sampletype == 5 
      || string(dataset) == "s8-wjets-mg-id11" || string(dataset) == "s8-vqq-mg-id11"
    ) {
    generatorMod->Add(partonFlavorHistoryMod);
    partonFlavorHistoryMod->Add(pubJet);
  } else {
    generatorMod->Add(pubJet);    
  }

  pubJet->Add(pubMet);
  pubMet->Add(muonID);
  muonID->Add(electronID);
  electronID->Add(photonID);
  photonID->Add(jetID);
  jetID->Add(electronCleaning);
  electronCleaning->Add(photonCleaning);
  photonCleaning->Add(jetCleaning);
  jetCleaning->Add(mergeLeptonsMod);

  //For W+Jet samples
  if (sampletype == 3 || sampletype == 4 || sampletype == 5 || sampletype == 1 ) {

    mergeLeptonsMod->Add(generateFakeableObjectsMod);
    generateFakeableObjectsMod->Add(analysisMod);
        
    mergeLeptonsMod->Add(generateFakeableObjectsMod_Reco);
    generateFakeableObjectsMod_Reco->Add(analysisMod_Reco);
        
  } else if (sampletype == 20) {
    //For photon trigger samples
    mergeLeptonsMod->Add(hltmod_Photon15);
    hltmod_Photon15->Add(generateFakeableObjectsMod);
    generateFakeableObjectsMod->Add(analysisMod_Photon15);
    hltmod_Photon15->Add(generateFakeableObjectsMod_Reco);
    generateFakeableObjectsMod_Reco->Add(analysisMod_Reco_Photon15);

//     mergeLeptonsMod->Add(hltmod_Photon25);
//     hltmod_Photon25->Add(generateFakeableObjectsMod);
//     generateFakeableObjectsMod->Add(analysisMod_Photon25);
//     hltmod_Photon25->Add(generateFakeableObjectsMod_Reco);
//     generateFakeableObjectsMod_Reco->Add(analysisMod_Reco_Photon25);

  } else if (sampletype == 10) {
    //For Jet Trigger samples
    mergeLeptonsMod->Add(hltmod_Jet30);
    hltmod_Jet30->Add(generateFakeableObjectsMod_Jet30);      
    generateFakeableObjectsMod_Jet30->Add(analysisMod_Jet30);
    hltmod_Jet30->Add(generateFakeableObjectsMod_Reco_Jet30);
    generateFakeableObjectsMod_Reco_Jet30->Add(analysisMod_Reco_Jet30);

    mergeLeptonsMod->Add(hltmod_Jet50);
    hltmod_Jet50->Add(generateFakeableObjectsMod_Jet50);      
    generateFakeableObjectsMod_Jet50->Add(analysisMod_Jet50);
    hltmod_Jet50->Add(generateFakeableObjectsMod_Reco_Jet50);
    generateFakeableObjectsMod_Reco_Jet50->Add(analysisMod_Reco_Jet50);

    mergeLeptonsMod->Add(hltmod_Jet80);
     hltmod_Jet80->Add(generateFakeableObjectsMod_Jet80);      
    generateFakeableObjectsMod_Jet80->Add(analysisMod_Jet80);
    hltmod_Jet80->Add(generateFakeableObjectsMod_Reco_Jet80);
    generateFakeableObjectsMod_Reco_Jet80->Add(analysisMod_Reco_Jet80);

    mergeLeptonsMod->Add(hltmod_Jet110);    
    hltmod_Jet110->Add(generateFakeableObjectsMod_Jet110); 
    generateFakeableObjectsMod_Jet110->Add(analysisMod_Jet110);
    hltmod_Jet110->Add(generateFakeableObjectsMod_Reco_Jet110);
    generateFakeableObjectsMod_Reco_Jet110->Add(analysisMod_Reco_Jet110);
  } 

  //------------------------------------------------------------------------------------------------
  // setup analysis
  //------------------------------------------------------------------------------------------------
  Analysis *ana = new Analysis;
  ana->SetUseHLT(kTRUE);
  ana->SetKeepHierarchy(kTRUE);
  if (nEvents >= 0)
    ana->SetProcessNEvents(nEvents);
  ana->SetSuperModule(generatorMod);
  //ana->SetSkipFirstNEvents(47500);

  //------------------------------------------------------------------------------------------------
  // organize input
  //------------------------------------------------------------------------------------------------
  printf("\nRely on Catalog: %s\n",catalogDir);
  printf("  -> Book: %s  Dataset: %s  Skim: %s  Fileset: %s <-\n\n",book,dataset,skim,fileset);
  Catalog *c = new Catalog(catalogDir);
  TString skimdataset = TString(dataset)+TString("/") +TString(skim);
  Dataset *d = NULL;
  if (TString(skim).CompareTo("noskim") == 0)
    d = c->FindDataset(book,dataset,fileset);
  else 
    d = c->FindDataset(book,skimdataset.Data(),fileset);
  ana->AddDataset(d);

  //------------------------------------------------------------------------------------------------
  // organize output
  //------------------------------------------------------------------------------------------------
  TString rootFile = TString(outputName);
  rootFile += TString("_") + TString(dataset) + TString("_") + TString(skim);
  if (TString(fileset) != TString(""))
    rootFile += TString("_") + TString(fileset);
  rootFile += TString(".root");
  printf("\nRoot output: %s\n\n",rootFile.Data());  
  ana->SetOutputName(rootFile.Data());

  //------------------------------------------------------------------------------------------------
  // run the analysis after successful initialisation
  //------------------------------------------------------------------------------------------------
  ana->Run(!gROOT->IsBatch());  


  if (sampletype == 10) {
    cout << "HLTMod Jet30: Accepted " << hltmod_Jet30->GetNAccepted() 
         << " of " << hltmod_Jet30->GetNEvents() << " events" << endl;
    cout << "HLTMod Jet50: Accepted " << hltmod_Jet50->GetNAccepted() 
         << " of " << hltmod_Jet50->GetNEvents() << " events" << endl;
    cout << "HLTMod Jet80: Accepted " << hltmod_Jet80->GetNAccepted() 
         << " of " << hltmod_Jet80->GetNEvents() << " events" << endl;
    cout << "HLTMod Jet110: Accepted " << hltmod_Jet110->GetNAccepted() 
         << " of " << hltmod_Jet110->GetNEvents() << " events" << endl;
  }

  if (sampletype == 20) {
    cout << "HLTMod Photon15: Accepted " << hltmod_Photon15->GetNAccepted() 
         << " of " << hltmod_Photon15->GetNEvents() << " events" << endl;
    cout << "HLTMod Photon25: Accepted " << hltmod_Photon25->GetNAccepted() 
         << " of " << hltmod_Photon25->GetNEvents() << " events" << endl;
  }

  return;
}
//--------------------------------------------------------------------------------------------------
void runBavantiBoostedV_Synch
                       (const char *fileset    = "0000",
                        const char *skim       = "noskim",
                        //const char *dataset    = "s12-ttj-sl-v1-v7c",     
                        const char *dataset    = "GJets_HT-400ToInf_8TeV-madgraph+Summer12_DR53X-PU_S10_START53_V7A-v1+AODSIM",                        
                        const char *book       = "t2mit/filefi/032",
                        const char *catalogDir = "/home/cmsprod/catalog",
                        const char *outputName = "boostedv",
                        int         nEvents    = 10)
{
  //------------------------------------------------------------------------------------------------
  // some parameters get passed through the environment
  //------------------------------------------------------------------------------------------------
  TString cataDir  = getCatalogDir(catalogDir);
  TString mitData  = Utils::GetEnv("MIT_DATA");
  TString json     = Utils::GetEnv("MIT_PROD_JSON");
  TString jsonFile = getJsonFile("/home/cmsprod/cms/json");
  Bool_t  isData   = (json.CompareTo("~") != 0);
  // only for synchrionization purposes
  isData = kFALSE;
  printf("\n Initialization worked. Data?: %d\n\n",isData);

  //------------------------------------------------------------------------------------------------
  // some global setups
  //------------------------------------------------------------------------------------------------
  // debugging config
  using namespace mithep;
  gDebugMask  = (Debug::EDebugMask) (Debug::kGeneral | Debug::kTreeIO);
  gDebugLevel = 3;


  // Caching and how
  Int_t local = 1, cacher = 1;

  // local =   0 - as is,
  //           1 - /mt/hadoop  (MIT:SmartCache - preload one-by-one)
  //           2 - /mnt/hadoop (MIT:SmartCache - preload complete fileset)
  //           3 - ./          (xrdcp          - preload one-by-one)
  // cacher =  0 - no file by file caching
  //           1 - file by file caching on

  //------------------------------------------------------------------------------------------------
  // set up information for master module
  //------------------------------------------------------------------------------------------------
  RunLumiSelectionMod *runLumiSel = new RunLumiSelectionMod;
  runLumiSel->SetAcceptMC(kTRUE);                          // Monte Carlo events are always accepted
  
  // only select on run- and lumisection numbers when valid json file present
  if (json.CompareTo("~") != 0 && json.CompareTo("-") != 0) {
    printf(" runBoostedV() - adding jsonFile: %s\n",jsonFile.Data());
    runLumiSel->AddJSONFile(jsonFile.Data());
  }
  if (json.CompareTo("-") == 0) {
    printf("\n WARNING -- Looking at data without JSON file: always accept.\n\n");
    runLumiSel->SetAbortIfNotAccepted(kFALSE);   // accept all events if there is no valid JSON file
  }
  printf("\n Run lumi worked. \n\n");

  //------------------------------------------------------------------------------------------------
  // setup analysis
  //------------------------------------------------------------------------------------------------
  Analysis *ana = new Analysis;
  ana->SetUseCacher(cacher);
  ana->SetUseHLT(kTRUE);
  ana->SetKeepHierarchy(kTRUE);
  ana->SetSuperModule(runLumiSel);
  ana->SetPrintScale(100);
  if (nEvents >= 0)
    ana->SetProcessNEvents(nEvents);

  //------------------------------------------------------------------------------------------------
  // organize input
  //------------------------------------------------------------------------------------------------
  Catalog *c = new Catalog(cataDir.Data());
  TString skimdataset = TString(dataset)+TString("/") +TString(skim);
  Dataset *d = NULL;
  TString bookstr = book;
  if (TString(skim).CompareTo("noskim") == 0)
    d = c->FindDataset(bookstr,dataset,fileset,local);
  else 
    d = c->FindDataset(bookstr,skimdataset.Data(),fileset,local);
  ana->AddDataset(d);
  
  //------------------------------------------------------------------------------------------------
  // organize output
  //------------------------------------------------------------------------------------------------
  TString rootFile = TString(outputName);
  rootFile += TString("_") + TString(dataset) + TString("_") + TString(skim);
  if (TString(fileset) != TString(""))
    rootFile += TString("_") + TString(fileset);
  TString ntupleFile = rootFile + TString("_ntuple");
  rootFile += TString(".root");
  ana->SetOutputName(rootFile.Data());
  ana->SetCacheSize(0);

  //------------------------------------------------------------------------------------------------
  // HLT information
  //------------------------------------------------------------------------------------------------
  HLTMod *hltModP = new HLTMod("HLTModP");
  hltModP->SetBitsName("HLTBits");
  hltModP->SetTrigObjsName("HltObjsMonoJet");
  hltModP->SetAbortIfNotAccepted(isData);
  hltModP->SetPrintTable(kFALSE);

  // monojet triggers
  const int nMjtTrigs = 12;
  TString monoJetTriggers[nMjtTrigs] = { "HLT_MonoCentralPFJet80_PFMETnoMu105_NHEF0p95_v4",
                                         "HLT_MonoCentralPFJet80_PFMETnoMu105_NHEF0p95_v3",
                                         "HLT_MonoCentralPFJet80_PFMETnoMu105_NHEF0p95_v1",
                                         "HLT_MonoCentralPFJet80_PFMETnoMu95_NHEF0p95_v5",
                                         "HLT_MonoCentralPFJet80_PFMETnoMu95_NHEF0p95_v4",
                                         "HLT_MonoCentralPFJet80_PFMETnoMu95_NHEF0p95_v3",
                                         "HLT_MonoCentralPFJet80_PFMETnoMu95_NHEF0p95_v2",
                                         "HLT_MET120_HBHENoiseCleaned_v6",
                                         "HLT_MET120_HBHENoiseCleaned_v5",
                                         "HLT_MET120_HBHENoiseCleaned_v4",
                                         "HLT_MET120_HBHENoiseCleaned_v3",
                                         "HLT_MET120_HBHENoiseCleaned_v2"};

  for (int i=0; i<nMjtTrigs; i++)
    hltModP->AddTrigger(TString("!+"+monoJetTriggers[i]),0,999999);

  // top semileptonic triggers
  const int nTopTrigs = 14;
  TString topTriggers[nTopTrigs] = { "HLT_IsoMu15_v2",
                                     "HLT_IsoMu24_v2",
                                     "HLT_IsoMu17_v6",
                                     "HLT_IsoMu17_v8",
                                     "HLT_IsoMu17_v9",
                                     "HLT_IsoMu17_eta2p1_v1",
                                     "HLT_IsoMu24_v8", 
                                     "HLT_IsoMu24_eta2p1_v3", 
                                     "HLT_IsoMu24_eta2p1_v6", 
                                     "HLT_IsoMu24_eta2p1_v7", 
                                     "HLT_IsoMu24_eta2p1_v12", 
                                     "HLT_IsoMu24_eta2p1_v13", 
                                     "HLT_IsoMu24_eta2p1_v14", 
                                     "HLT_IsoMu24_eta2p1_v15"};

  for (int i=0; i<nTopTrigs; i++)
    hltModP->AddTrigger(TString("!+"+topTriggers[i]),0,999999);

  // photon triggers
  const int nPhotonTrigs = 6;
  TString photonTriggers[nPhotonTrigs] = { "HLT_Photon135_v4",
                                           "HLT_Photon135_v5",
                                           "HLT_Photon135_v6",
                                           "HLT_Photon135_v7",
                                           "HLT_Photon150_v3",
                                           "HLT_Photon150_v4"};

  for (int i=0; i<nPhotonTrigs; i++)
    hltModP->AddTrigger(TString("!+"+photonTriggers[i]),0,999999);

  // VBF triggers
  const int nVbfTrigs = 7;
  TString vbfTriggers[nVbfTrigs] = { "HLT_DiPFJet40_PFMETnoMu65_MJJ800VBF_AllJets_v9",
                                     "HLT_DiPFJet40_PFMETnoMu65_MJJ800VBF_AllJets_v8",
                                     "HLT_DiPFJet40_PFMETnoMu65_MJJ800VBF_AllJets_v6",
                                     "HLT_DiPFJet40_PFMETnoMu65_MJJ800VBF_AllJets_v5",
                                     "HLT_DiPFJet40_PFMETnoMu65_MJJ800VBF_AllJets_v4",
                                     "HLT_DiPFJet40_PFMETnoMu65_MJJ800VBF_AllJets_v3",
                                     "HLT_DiPFJet40_PFMETnoMu65_MJJ800VBF_AllJets_v2" };

  for (int i=0; i<nVbfTrigs; i++)
    hltModP->AddTrigger((TString("!+")+vbfTriggers[i]).Data(),0,999999);

  //------------------------------------------------------------------------------------------------
  // split pfcandidates to PFPU and PFnoPU
  //------------------------------------------------------------------------------------------------
  SeparatePileUpMod* sepPuMod = new SeparatePileUpMod;
  //sepPuMod->SetUseAllVerteces(kFALSE);
  //sepPuMod->SetVertexName("OutVtxCiC");
  sepPuMod->SetPFNoPileUpName("pfnopileupcands");
  sepPuMod->SetPFPileUpName("pfpileupcands");
  sepPuMod->SetCheckClosestZVertex(kFALSE);

  //------------------------------------------------------------------------------------------------
  // select events with a good primary vertex
  //------------------------------------------------------------------------------------------------
  GoodPVFilterMod *goodPVFilterMod = new GoodPVFilterMod;
  goodPVFilterMod->SetMinVertexNTracks(0);
  goodPVFilterMod->SetMinNDof(4.0);
  goodPVFilterMod->SetMaxAbsZ(24.0);
  goodPVFilterMod->SetMaxRho(2.0);
  goodPVFilterMod->SetIsMC(!isData);
  goodPVFilterMod->SetVertexesName("PrimaryVertexes");

  //------------------------------------------------------------------------------------------------
  // object id and cleaning sequence
  //------------------------------------------------------------------------------------------------

  //-----------------------------------
  // Lepton Selection
  //-----------------------------------
  ElectronIDMod* eleIdMod = new ElectronIDMod;
  eleIdMod->SetPtMin(10.);
  eleIdMod->SetEtaMax(2.5);
  eleIdMod->SetApplyEcalFiducial(kTRUE);
  eleIdMod->SetIDType("VBTFWorkingPoint95Id");
  eleIdMod->SetIsoType("PFIso");
  eleIdMod->SetApplyConversionFilterType1(kTRUE);
  eleIdMod->SetApplyConversionFilterType2(kFALSE);
  eleIdMod->SetChargeFilter(kFALSE);
  eleIdMod->SetApplyD0Cut(kTRUE);
  eleIdMod->SetApplyDZCut(kTRUE);
  eleIdMod->SetWhichVertex(0);
  eleIdMod->SetNExpectedHitsInnerCut(0);
  eleIdMod->SetGoodElectronsName("GoodElectronsBS");
  eleIdMod->SetRhoType(RhoUtilities::CMS_RHO_RHOKT6PFJETS);

  MuonIDMod *muonIdIsoMod = new MuonIDMod;
  muonIdIsoMod->SetOutputName("HWWMuons");
  muonIdIsoMod->SetIntRadius(0.0);
  muonIdIsoMod->SetClassType("GlobalTracker");
  muonIdIsoMod->SetIDType("WWMuIdV4");
  muonIdIsoMod->SetIsoType("IsoRingsV0_BDTG_Iso");
  muonIdIsoMod->SetApplyD0Cut(kTRUE);
  muonIdIsoMod->SetD0Cut(0.02);
  muonIdIsoMod->SetApplyDZCut(kTRUE);
  muonIdIsoMod->SetDZCut(0.1);
  muonIdIsoMod->SetWhichVertex(0);
  muonIdIsoMod->SetRhoType(RhoUtilities::CMS_RHO_RHOKT6PFJETS);
  muonIdIsoMod->SetPtMin(10.);
  muonIdIsoMod->SetEtaCut(2.4);

  MuonIDMod *muonIdLooseMod = new MuonIDMod;
  muonIdLooseMod->SetOutputName("POGMuons");
  muonIdLooseMod->SetClassType("GlobalTracker");
  muonIdLooseMod->SetIDType("NoId");
  muonIdLooseMod->SetIsoType("NoIso");
  muonIdLooseMod->SetApplyD0Cut(true);
  muonIdLooseMod->SetD0Cut(0.2);
  muonIdLooseMod->SetApplyDZCut(true);
  muonIdLooseMod->SetDZCut(0.5);
  muonIdLooseMod->SetPtMin(10.);
  muonIdLooseMod->SetEtaCut(2.4);
  
  ElectronCleaningMod *electronCleaning = new ElectronCleaningMod;
  electronCleaning->SetCleanMuonsName(muonIdLooseMod->GetOutputName());
  electronCleaning->SetGoodElectronsName(eleIdMod->GetOutputName());
  electronCleaning->SetCleanElectronsName("CleanElectrons");

  MergeLeptonsMod *merger = new MergeLeptonsMod;
  merger->SetMuonsName(muonIdLooseMod->GetOutputName());
  merger->SetElectronsName(electronCleaning->GetOutputName());
  merger->SetMergedName("MergedLeptons");

  //-----------------------------------
  // Photon Egamma Medium ID
  //-----------------------------------
  PhotonIDMod *photonIdMod = new PhotonIDMod;
  photonIdMod->SetPtMin(10.0);
  photonIdMod->SetOutputName("GoodPhotons");
  photonIdMod->SetIDType("EgammaMedium");
  photonIdMod->SetIsoType("NoIso");
  photonIdMod->SetApplyElectronVeto(kTRUE);
  photonIdMod->SetApplyPixelSeed(kFALSE);
  photonIdMod->SetApplyConversionId(kFALSE);
  photonIdMod->SetApplyFiduciality(kTRUE);
  photonIdMod->SetIsData(isData);
  photonIdMod->SetPhotonsFromBranch(kTRUE);

  PhotonCleaningMod *photonCleaningMod = new PhotonCleaningMod;
  photonCleaningMod->SetCleanElectronsName(electronCleaning->GetOutputName());
  photonCleaningMod->SetGoodPhotonsName(photonIdMod->GetOutputName());
  photonCleaningMod->SetCleanPhotonsName("CleanPhotons");

  PFTauIDMod *pftauIdMod = new PFTauIDMod;
  pftauIdMod->SetPFTausName("HPSTaus");
  pftauIdMod->SetIsLooseId(kTRUE);
  pftauIdMod->SetIsHPSSel(kTRUE); // to get >= 5_3_14 samples running
  pftauIdMod->SetPtMin(15); // to loosen the WP
  
  PFTauCleaningMod *pftauCleaningMod = new PFTauCleaningMod;
  pftauCleaningMod->SetGoodPFTausName(pftauIdMod->GetGoodPFTausName());
  pftauCleaningMod->SetCleanMuonsName(muonIdLooseMod->GetOutputName());
  pftauCleaningMod->SetCleanElectronsName(electronCleaning->GetOutputName());

  PublisherMod<PFJet,Jet> *pubJet = new PublisherMod<PFJet,Jet>("JetPub");
  pubJet->SetInputName("AKt4PFJets");
  pubJet->SetOutputName("PubAKt4PFJets");
  
  FastJetMod *pubFastJet = new FastJetMod;
  pubFastJet->SetPfCandidatesName("pfnopileupcands");
  pubFastJet->SetPfCandidatesFromBranch(kFALSE);
  pubFastJet->SetConeSize(0.8);

  JetCorrectionMod *jetCorr = new JetCorrectionMod;
  if (isData){ 
    jetCorr->AddCorrectionFromFile((mitData+TString("/Summer13_V1_DATA_L1FastJet_AK5PF.txt")).Data()); 
    jetCorr->AddCorrectionFromFile((mitData+TString("/Summer13_V1_DATA_L2Relative_AK5PF.txt")).Data()); 
    jetCorr->AddCorrectionFromFile((mitData+TString("/Summer13_V1_DATA_L3Absolute_AK5PF.txt")).Data()); 
    jetCorr->AddCorrectionFromFile((mitData+TString("/Summer13_V1_DATA_L2L3Residual_AK5PF.txt")).Data());
  }                                                                                      
  else {                                                                                 
    jetCorr->AddCorrectionFromFile((mitData+TString("/Summer13_V1_MC_L1FastJet_AK5PF.txt")).Data()); 
    jetCorr->AddCorrectionFromFile((mitData+TString("/Summer13_V1_MC_L2Relative_AK5PF.txt")).Data()); 
    jetCorr->AddCorrectionFromFile((mitData+TString("/Summer13_V1_MC_L3Absolute_AK5PF.txt")).Data()); 
  }
  jetCorr->SetInputName(pubJet->GetOutputName());
  jetCorr->SetCorrectedName("CorrectedJets");    

  JetCorrectionMod *fatJetCorr = new JetCorrectionMod;
  if (isData){ 
    fatJetCorr->AddCorrectionFromFile((mitData+TString("/FT53_V21A_AN6_L1FastJet_AK7PFchs.txt")).Data()); 
    fatJetCorr->AddCorrectionFromFile((mitData+TString("/FT53_V21A_AN6_L2Relative_AK7PFchs.txt")).Data()); 
    fatJetCorr->AddCorrectionFromFile((mitData+TString("/FT53_V21A_AN6_L3Absolute_AK7PFchs.txt")).Data()); 
    fatJetCorr->AddCorrectionFromFile((mitData+TString("/FT53_V21A_AN6_L2L3Residual_AK7PFchs.txt")).Data());
  }                                                                                      
  else {                                                                                 
    fatJetCorr->AddCorrectionFromFile((mitData+TString("/FT53_V21A_AN6_L1FastJet_AK7PFchs.txt")).Data()); 
    fatJetCorr->AddCorrectionFromFile((mitData+TString("/FT53_V21A_AN6_L2Relative_AK7PFchs.txt")).Data()); 
    fatJetCorr->AddCorrectionFromFile((mitData+TString("/FT53_V21A_AN6_L3Absolute_AK7PFchs.txt")).Data()); 
  }
  fatJetCorr->SetInputName(pubFastJet->GetOutputJetsName());
  fatJetCorr->SetCorrectedName("CorrectedFatJets");    
        
  JetIDMod *jetId = new JetIDMod;
  jetId->SetInputName(jetCorr->GetOutputName());
  jetId->SetPtCut(30.0);
  jetId->SetEtaMaxCut(2.5);
  jetId->SetJetEEMFractionMinCut(0.00);
  jetId->SetOutputName("GoodJets");
  jetId->SetApplyBetaCut(kFALSE);
  jetId->SetApplyMVACut(kTRUE);

  JetIDMod *fatJetId = new JetIDMod;
  fatJetId->SetInputName(fatJetCorr->GetOutputName());
  fatJetId->SetPtCut(30.0);
  fatJetId->SetEtaMaxCut(2.5);
  fatJetId->SetJetEEMFractionMinCut(0.00);
  fatJetId->SetOutputName("GoodFatJets");
  fatJetId->SetApplyBetaCut(kFALSE);
  fatJetId->SetApplyMVACut(kFALSE);
  fatJetId->SetApplyMVACHS(kFALSE);

  JetCleaningMod *jetCleaning = new JetCleaningMod;
  jetCleaning->SetCleanElectronsName(electronCleaning->GetOutputName());
  jetCleaning->SetCleanMuonsName(muonIdIsoMod->GetOutputName());
  jetCleaning->SetCleanPhotonsName(photonCleaningMod->GetOutputName());
  jetCleaning->SetApplyPhotonRemoval(kTRUE);
  jetCleaning->SetApplyTauRemoval(kFALSE);
  jetCleaning->SetGoodJetsName(jetId->GetOutputName());
  jetCleaning->SetCleanJetsName("CleanJets");

  JetCleaningMod *fatJetCleaning = new JetCleaningMod;
  fatJetCleaning->SetCleanElectronsName(electronCleaning->GetOutputName());
  fatJetCleaning->SetCleanMuonsName(muonIdIsoMod->GetOutputName());
  fatJetCleaning->SetCleanPhotonsName(photonCleaningMod->GetOutputName());
  fatJetCleaning->SetMinDeltaRToElectron(0.5);
  fatJetCleaning->SetMinDeltaRToMuon(0.5);
  fatJetCleaning->SetMinDeltaRToPhoton(0.5);
  fatJetCleaning->SetApplyPhotonRemoval(kTRUE);
  fatJetCleaning->SetApplyTauRemoval(kFALSE);  
  fatJetCleaning->SetGoodJetsName(fatJetId->GetOutputName());
  fatJetCleaning->SetCleanJetsName("CleanFatJets");

  //------------------------------------------------------------------------------------------------
  // select events with a monojet topology
  //------------------------------------------------------------------------------------------------
  BoostedVAnalysisMod *jetplusmet = new BoostedVAnalysisMod("MonoJetSelector");
  jetplusmet->SetFatJetsName(fatJetCleaning->GetOutputName()); //identified fat jets
  jetplusmet->SetFatJetsFromBranch(kFALSE);
  jetplusmet->SetJetsName(jetCleaning->GetOutputName()); //identified jets
  jetplusmet->SetJetsFromBranch(kFALSE);
  jetplusmet->SetElectronsName(electronCleaning->GetOutputName());
  jetplusmet->SetElectronsFromBranch(kFALSE);
  jetplusmet->SetMuonsName(muonIdLooseMod->GetOutputName());
  jetplusmet->SetMuonsFromBranch(kFALSE);
  jetplusmet->SetPhotonsName(photonCleaningMod->GetOutputName());
  jetplusmet->SetPhotonsFromBranch(kFALSE);
  jetplusmet->ApplyResolvedPresel(kTRUE); 
  jetplusmet->ApplyTopPresel(kFALSE); 
  jetplusmet->ApplyWlepPresel(kTRUE);
  jetplusmet->ApplyZeePresel(kTRUE);
  jetplusmet->ApplyZmmPresel(kTRUE);
  jetplusmet->ApplyMetPresel(kTRUE);
  jetplusmet->ApplyVbfPresel(kFALSE);
  jetplusmet->ApplyGjetPresel(kTRUE);
  jetplusmet->SetMinFatJetPt(200);
  jetplusmet->SetMinTagJetPt(110);
  jetplusmet->SetMinMet(150);    
  jetplusmet->SetMinPhotonPt(160);    
  jetplusmet->SkipEvents(kFALSE);    

  //------------------------------------------------------------------------------------------------
  // prepare the extended MVA met 
  //------------------------------------------------------------------------------------------------
  FillerXlMet *extendedMetFiller = new FillerXlMet();
  extendedMetFiller->SetIsData(isData);
  extendedMetFiller->SetJetsFromBranch(kFALSE);
  extendedMetFiller->SetJetsName(pubJet->GetOutputName());
  extendedMetFiller->SetMuonsFromBranch(kTRUE);
  //extendedMetFiller->SetMuonsName(muonIdLooseMod->GetOutputName());
  extendedMetFiller->SetElectronsFromBranch(kTRUE);
  //extendedMetFiller->SetElectronsName(electronCleaning->GetOutputName());
  extendedMetFiller->SetTausFromBranch(kTRUE);
  extendedMetFiller->SetTausName("HPSTaus");
  extendedMetFiller->SetPhotonsFromBranch(kTRUE);
  //extendedMetFiller->SetPhotonsName(photonCleaningMod->GetOutputName());
  extendedMetFiller->SetPVFromBranch(kFALSE);
  extendedMetFiller->SetPVName(goodPVFilterMod->GetOutputName());
  extendedMetFiller->SetXlMetName("PFMetMVA");     

  //------------------------------------------------------------------------------------------------
  // prepare the extended jets with QG/color pull information
  //------------------------------------------------------------------------------------------------
  FillerXlJets *boostedJetsFiller = new FillerXlJets;  
  boostedJetsFiller->SetJetsName(jetCleaning->GetOutputName());
  boostedJetsFiller->SetJetsFromBranch(kFALSE);
  
  //------------------------------------------------------------------------------------------------
  // prepare the extended jets with substructure information
  //------------------------------------------------------------------------------------------------
  FillerXlFatJets *boostedFatJetsFiller = new FillerXlFatJets;  
  boostedFatJetsFiller->FillTopSubJets(kFALSE);
  boostedFatJetsFiller->SetJetsName(fatJetCleaning->GetOutputName());
  boostedFatJetsFiller->SetJetsFromBranch(kFALSE);
  boostedFatJetsFiller->SetConeSize(0.8);      

  //------------------------------------------------------------------------------------------------
  // prepare the reduced isolated particles
  //------------------------------------------------------------------------------------------------
  FillerXsIsoParticles *boostedXsIsoParticlesFiller = new FillerXsIsoParticles;  
  boostedXsIsoParticlesFiller->FillXsMuons(kTRUE);
  boostedXsIsoParticlesFiller->FillXsElectrons(kTRUE);
  boostedXsIsoParticlesFiller->FillXsTaus(kTRUE);
  boostedXsIsoParticlesFiller->FillXsPhotons(kTRUE);
  boostedXsIsoParticlesFiller->SetMuonsName(muonIdLooseMod->GetOutputName());
  boostedXsIsoParticlesFiller->SetMuonsFromBranch(kFALSE);
  boostedXsIsoParticlesFiller->SetIsoMuonsName(muonIdIsoMod->GetOutputName());
  boostedXsIsoParticlesFiller->SetIsoMuonsFromBranch(kFALSE);
  boostedXsIsoParticlesFiller->SetElectronsName(eleIdMod->GetOutputName());
  boostedXsIsoParticlesFiller->SetElectronsFromBranch(kFALSE);
  boostedXsIsoParticlesFiller->SetTausName(pftauCleaningMod->GetOutputName());
  boostedXsIsoParticlesFiller->SetTausFromBranch(kFALSE);
  boostedXsIsoParticlesFiller->SetPhotonsName(photonCleaningMod->GetOutputName());
  boostedXsIsoParticlesFiller->SetPhotonsFromBranch(kFALSE);

  //------------------------------------------------------------------------------------------------
  // keep the skimmed collections for further usage
  //------------------------------------------------------------------------------------------------
  //SkimMod<PFCandidate> *skmPFCandidates = new SkimMod<PFCandidate>;
  //skmPFCandidates->SetBranchName(Names::gkPFCandidatesBrn);
  //skmPFCandidates->SetPublishArray(kTRUE);

  SkimJetsMod *skmJets = new SkimJetsMod;
  skmJets->SetBranchName(jetCleaning->GetOutputName());
  skmJets->SetColFromBranch(kFALSE);
  skmJets->SetColMarkFilter(kFALSE);
  skmJets->SetPublishArray(kTRUE);

  SkimMod<TriggerObject> *skmTrigger = new SkimMod<TriggerObject>;
  skmTrigger->SetBranchName(hltModP->GetOutputName());
  skmTrigger->SetColFromBranch(kFALSE);
  skmTrigger->SetColMarkFilter(kFALSE);
  skmTrigger->SetPublishArray(kTRUE);
    
  //------------------------------------------------------------------------------------------------
  // save all this in an output ntuple
  //------------------------------------------------------------------------------------------------
  OutputMod *outMod = new OutputMod;
  outMod->SetUseBrDep(kFALSE);
  outMod->SetKeepTamBr(kFALSE);
  outMod->SetFileName(ntupleFile);
  outMod->SetMaxFileSize(4096);
  outMod->Drop("*");
  outMod->Keep(Names::gkMCEvtInfoBrn);
  outMod->Keep(Names::gkMCPartBrn);
  outMod->Keep(Names::gkPVBeamSpotBrn);
  outMod->Keep(Names::gkPileupInfoBrn);
  outMod->Keep(Names::gkPileupEnergyDensityBrn);
  outMod->Keep("PFMet");
  outMod->AddNewBranch("XlEvtSelData");
  //outMod->AddNewBranch(TString("Skm") + Names::gkPFCandidatesBrn);
  outMod->AddNewBranch(TString("Skm") + hltModP->GetOutputName());
  outMod->AddNewBranch("PFMetMVA");
  outMod->AddNewBranch("XlJets");
  outMod->AddNewBranch("XlFatJets");
  outMod->AddNewBranch("XlSubJets");
  outMod->AddNewBranch("XsMuons");
  outMod->AddNewBranch("XsElectrons");
  outMod->AddNewBranch("XsTaus");
  outMod->AddNewBranch("XsPhotons");
  
  //------------------------------------------------------------------------------------------------
  // making analysis chain
  //------------------------------------------------------------------------------------------------
  runLumiSel                 ->Add(goodPVFilterMod);
  goodPVFilterMod            ->Add(hltModP);
  hltModP                    ->Add(sepPuMod);
  sepPuMod                   ->Add(muonIdIsoMod);
  muonIdIsoMod               ->Add(muonIdLooseMod);
  muonIdLooseMod             ->Add(eleIdMod);
  eleIdMod                   ->Add(electronCleaning);
  electronCleaning           ->Add(merger);
  merger                     ->Add(photonIdMod);
  photonIdMod                ->Add(photonCleaningMod);
  photonCleaningMod          ->Add(pftauIdMod);
  pftauIdMod                 ->Add(pftauCleaningMod);
  pftauCleaningMod           ->Add(pubJet);
  pubJet                     ->Add(jetCorr);
  jetCorr                    ->Add(jetId);
  jetId                      ->Add(jetCleaning);
  jetCleaning                ->Add(pubFastJet);
  pubFastJet                 ->Add(fatJetCorr);
  fatJetCorr                 ->Add(fatJetId);
  fatJetId                   ->Add(fatJetCleaning);
  fatJetCleaning             ->Add(jetplusmet);
  jetplusmet                 ->Add(extendedMetFiller);
  extendedMetFiller          ->Add(boostedJetsFiller);
  boostedJetsFiller          ->Add(boostedFatJetsFiller);
  boostedFatJetsFiller       ->Add(boostedXsIsoParticlesFiller);
  boostedXsIsoParticlesFiller->Add(skmJets);
  skmJets                    ->Add(skmTrigger);
  skmTrigger                 ->Add(outMod);
  
  //------------------------------------------------------------------------------------------------
  // Say what we are doing
  //------------------------------------------------------------------------------------------------
  printf("\n==== PARAMETER SUMMARY FOR THIS JOB ====\n");
  printf("\n JSON file: %s\n",jsonFile.Data());
  printf("\n Rely on Catalog: %s\n",cataDir.Data());
  printf("  -> Book: %s  Dataset: %s  Skim: %s  Fileset: %s <-\n",book,dataset,skim,fileset);
  printf("\n Root output:   %s\n",rootFile.Data());  
  printf("\n Ntuple output: %s\n\n",(ntupleFile + TString(".root")).Data());  
  printf("\n========================================\n");

  //------------------------------------------------------------------------------------------------
  // run the analysis after successful initialisation
  //------------------------------------------------------------------------------------------------
  ana->Run(!gROOT->IsBatch());

  return;
}
//--------------------------------------------------------------------------------------------------
void executeComputeElectronFakeRateMod(const char *fileset  = "",
                        const char *dataset    = "s8-ttbar-id9",
                        const char *book       = "mit/filler/006",
                        const char *catalogDir = "/home/mitprod/catalog",
                        const char *outputName = "JetChargeCorrelationStudy",
                        int         nEvents    = -1)
{
  //------------------------------------------------------------------------------------------------
  // some global setups
  //------------------------------------------------------------------------------------------------
  using namespace mithep;
  gDebugMask  = Debug::kAnalysis;
  gDebugLevel = 3;

  //------------------------------------------------------------------------------------------------
  // generator information
  //------------------------------------------------------------------------------------------------
  GeneratorMod *generatorMod = new GeneratorMod;
  generatorMod->SetFillHist(kTRUE);

  //------------------------------------------------------------------------------------------------
  // HLT information
  //------------------------------------------------------------------------------------------------
  HLTMod *hltmod = new HLTMod;
  hltmod->SetPrintTable(kTRUE);
  hltmod->AddTrigger("HLT_IsoEle15_L1I");
  hltmod->AddTrigger("HLT_Ele15_SW_L1R");
  hltmod->AddTrigger("HLT_IsoEle15_LW_L1I");
  hltmod->AddTrigger("HLT_IsoEle18_L1R");
  hltmod->AddTrigger("HLT_Ele15_LW_L1R");
  hltmod->AddTrigger("HLT_LooseIsoEle15_LW_L1R");
  hltmod->AddTrigger("HLT_IsoMu15");
  hltmod->AddTrigger("HLT_Mu15");
  hltmod->SetTrigObjsName("myhltobjs");

  //------------------------------------------------------------------------------------------------
  // object id and cleaning sequence
  //------------------------------------------------------------------------------------------------
  MuonIDMod           *muonID           = new MuonIDMod;  
  muonID->SetIDType("Loose");
  muonID->SetIsoType("TrackCaloSliding"); 
  ElectronIDMod       *electronID       = new ElectronIDMod;
  electronID->SetIDType(TString("Tight"));
  electronID->SetIsoType(TString("TrackJuraSliding"));
  PhotonIDMod         *photonID       = new PhotonIDMod;
  photonID->SetIDType(TString("Tight"));
  photonID->SetPtMin(20.0);
  JetIDMod            *jetID            = new JetIDMod;
  jetID->SetInputName(TString("SisCone5Jets"));
  jetID->SetUseCorrection(kTRUE);
  jetID->SetPtCut(35.0);
  ElectronCleaningMod *electronCleaning = new ElectronCleaningMod;
  PhotonCleaningMod   *photonCleaning   = new PhotonCleaningMod;
  JetCleaningMod      *jetCleaning      = new JetCleaningMod;

  //------------------------------------------------------------------------------------------------
  // merge modules
  //------------------------------------------------------------------------------------------------
  //MergeLeptonsMod *mergeLeptonsMod = new MergeLeptonsMod;

  //------------------------------------------------------------------------------------------------
  // analyses modules
  //------------------------------------------------------------------------------------------------
  JetChargeCorrelationStudyMod *analysisMod = new JetChargeCorrelationStudyMod;
  analysisMod->SetVetoGeneratorLeptons(kTRUE);
  //------------------------------------------------------------------------------------------------
  // making analysis chain
  //------------------------------------------------------------------------------------------------
  hltmod->Add(muonID);
  generatorMod->Add(muonID);
  muonID->Add(electronID);
  electronID->Add(photonID);
  photonID->Add(jetID);
  jetID->Add(electronCleaning);
  electronCleaning->Add(photonCleaning);
  photonCleaning->Add(jetCleaning);
  jetCleaning->Add(analysisMod);

  //------------------------------------------------------------------------------------------------
  // setup analysis
  //------------------------------------------------------------------------------------------------
  Analysis *ana = new Analysis;
  ana->SetUseHLT(kFALSE);
  ana->SetKeepHierarchy(kTRUE);
  if (nEvents >= 0)
    ana->SetProcessNEvents(nEvents);
  //ana->SetSuperModule(muonID);
  ana->SetSuperModule(generatorMod);

  //------------------------------------------------------------------------------------------------
  // organize input
  //------------------------------------------------------------------------------------------------
  printf("\nRely on Catalog: %s\n",catalogDir);
  printf("  -> Book: %s  Dataset: %s  Fileset: %s <-\n\n",book,dataset,fileset);
  Catalog *c = new Catalog(catalogDir);
  Dataset *d = c->FindDataset(book,dataset,fileset);
  ana->AddDataset(d);

  //------------------------------------------------------------------------------------------------
  // organize output
  //------------------------------------------------------------------------------------------------
  TString rootFile = TString(outputName);
  rootFile += TString("_") + TString(dataset);
  if (TString(fileset) != TString(""))
    rootFile += TString("_") + TString(fileset);
  rootFile += TString(".root");
  printf("\nRoot output: %s\n\n",rootFile.Data());  
  ana->SetOutputName(rootFile.Data());

  //------------------------------------------------------------------------------------------------
  // run the analysis after successful initialisation
  //------------------------------------------------------------------------------------------------
  ana->Run(!gROOT->IsBatch());  

  return;
}
Example #8
0
//--------------------------------------------------------------------------------------------------
void runFlatMonoJet(const char *fileset    = "0000",
                const char *skim       = "noskim",
                const char *dataset    = "s12-zjets-ptz70-100-v7c",
                const char *book       = "t2mit/filefi/032",
                const char *catalogDir = "/home/cmsprod/catalog",
                const char *outputName = "MonoJet_August13",
                int         nEvents    = 100)
{
  //------------------------------------------------------------------------------------------------
  // some parameters get passed through the environment
  //------------------------------------------------------------------------------------------------
  TString cataDir  = getCatalogDir(catalogDir);
  TString mitData  = mithep::Utils::GetEnv("MIT_DATA");
  TString json     = mithep::Utils::GetEnv("MIT_PROD_JSON");
  TString jsonFile = getJsonFile("/home/cmsprod/cms/json");
  Bool_t  isData   = (json.CompareTo("~") != 0);
  printf("\n Initialization worked. Data?: %d\n\n",isData);  

  std::cout<<"*********** Is data?? **********"<<isData<<std::endl;

  //------------------------------------------------------------------------------------------------
  // some global setups
  //------------------------------------------------------------------------------------------------
  using namespace mithep;
  gDebugMask  = (Debug::EDebugMask) (Debug::kGeneral | Debug::kTreeIO);
  gDebugLevel = 3;

  // Caching and how
  Int_t local = 1, cacher = 1;

  // local =   0 - as is,
  //           1 - /mnt/hadoop (MIT:SmartCache - preload one-by-one)
  //           2 - /mnt/hadoop (MIT:SmartCache - preload complete fileset)
  //           3 - ./          (xrdcp          - preload one-by-one)
  // cacher =  0 - no file by file caching
  //           1 - file by file caching on

  //------------------------------------------------------------------------------------------------
  // set up information
  //------------------------------------------------------------------------------------------------
  RunLumiSelectionMod *runLumiSel = new RunLumiSelectionMod;
  runLumiSel->SetAcceptMC(!isData);
  runLumiSel->SetAbortIfNotAccepted(kFALSE);   // accept all events if there is no valid JSON file

  // only select on run- and lumisection numbers when valid json file present
  if (json.CompareTo("~") != 0 && json.CompareTo("-") != 0) {
    printf(" runBoostedV() - adding jsonFile: %s\n",jsonFile.Data());
    runLumiSel->AddJSONFile(jsonFile.Data());
  }
  if (json.CompareTo("-") == 0) {
    printf("\n WARNING -- Looking at data without JSON file: always accept.\n\n");
    runLumiSel->SetAbortIfNotAccepted(kFALSE);   // accept all events if there is no valid JSON file
  }
  printf("\n Run lumi worked. \n\n");

  // Generator info
  GeneratorMod *generatorMod = new GeneratorMod;
  generatorMod->SetPrintDebug(kFALSE);
  generatorMod->SetPtLeptonMin(0.0);
  generatorMod->SetEtaLeptonMax(2.7);
  generatorMod->SetPtPhotonMin(0.0);
  generatorMod->SetEtaPhotonMax(2.7);
  generatorMod->SetPtRadPhotonMin(0.0);
  generatorMod->SetEtaRadPhotonMax(2.7);
  generatorMod->SetIsData(isData);
  generatorMod->SetFillHist(!isData);
  generatorMod->SetApplyISRFilter(kFALSE);
  generatorMod->SetApplyVVFilter(kFALSE);
  generatorMod->SetApplyVGFilter(kFALSE);
  generatorMod->SetFilterBTEvents(kFALSE);

  //-----------------------------------------------------------------------------------------------------------
  // HLT information : trigger not applied (neither for data nor for MC, store info to apply selection offline
  //-----------------------------------------------------------------------------------------------------------
  HLTMod *hltModP = new HLTMod("HLTModP");

  // monojet triggers
  const int nMjtTrigs = 12;
  TString monoJetTriggers[nMjtTrigs] = { "HLT_MonoCentralPFJet80_PFMETnoMu105_NHEF0p95_v4",
                                         "HLT_MonoCentralPFJet80_PFMETnoMu105_NHEF0p95_v3",
                                         "HLT_MonoCentralPFJet80_PFMETnoMu105_NHEF0p95_v1",
                                         "HLT_MonoCentralPFJet80_PFMETnoMu95_NHEF0p95_v5",
                                         "HLT_MonoCentralPFJet80_PFMETnoMu95_NHEF0p95_v4",
                                         "HLT_MonoCentralPFJet80_PFMETnoMu95_NHEF0p95_v3",
                                         "HLT_MonoCentralPFJet80_PFMETnoMu95_NHEF0p95_v2",
                                         "HLT_MET120_HBHENoiseCleaned_v6",
                                         "HLT_MET120_HBHENoiseCleaned_v5",
                                         "HLT_MET120_HBHENoiseCleaned_v4",
                                         "HLT_MET120_HBHENoiseCleaned_v3",
                                         "HLT_MET120_HBHENoiseCleaned_v2" };

  for (int i=0; i<nMjtTrigs; i++)
    hltModP->AddTrigger(TString("!+"+monoJetTriggers[i]),0,999999);

  // VBF triggers
  const int nVbfTrigs = 7;
  TString vbfTriggers[nVbfTrigs] = { "HLT_DiPFJet40_PFMETnoMu65_MJJ800VBF_AllJets_v9",
                                     "HLT_DiPFJet40_PFMETnoMu65_MJJ800VBF_AllJets_v8",
                                     "HLT_DiPFJet40_PFMETnoMu65_MJJ800VBF_AllJets_v6",
                                     "HLT_DiPFJet40_PFMETnoMu65_MJJ800VBF_AllJets_v5",
                                     "HLT_DiPFJet40_PFMETnoMu65_MJJ800VBF_AllJets_v4",
                                     "HLT_DiPFJet40_PFMETnoMu65_MJJ800VBF_AllJets_v3",
                                     "HLT_DiPFJet40_PFMETnoMu65_MJJ800VBF_AllJets_v2" };

  for (int i=0; i<nVbfTrigs; i++)
    hltModP->AddTrigger((TString("!+")+vbfTriggers[i]).Data(),0,999999);

  hltModP->SetBitsName("HLTBits");
  hltModP->SetTrigObjsName("MyHltPhotObjs");
  hltModP->SetAbortIfNotAccepted(isData);
  hltModP->SetPrintTable(kFALSE);

  //------------------------------------------------------------------------------------------------
  // split pfcandidates to PFPU and PFnoPU
  //------------------------------------------------------------------------------------------------
  SeparatePileUpMod* SepPUMod = new SeparatePileUpMod;
  //  SepPUMod->SetUseAllVerteces(kFALSE);
  // SepPUMod->SetVertexName("OutVtxCiC");
  SepPUMod->SetPFNoPileUpName("pfnopileupcands");
  SepPUMod->SetPFPileUpName("pfpileupcands");
  SepPUMod->SetCheckClosestZVertex(kFALSE);

  //------------------------------------------------------------------------------------------------
  // select events with a good primary vertex
  //------------------------------------------------------------------------------------------------
  GoodPVFilterMod *goodPVFilterMod = new GoodPVFilterMod;
  goodPVFilterMod->SetMinVertexNTracks(0);
  goodPVFilterMod->SetMinNDof         (4.0);
  goodPVFilterMod->SetMaxAbsZ         (24.0);
  goodPVFilterMod->SetMaxRho          (2.0);
  goodPVFilterMod->SetIsMC(!isData);
  goodPVFilterMod->SetVertexesName("PrimaryVertexes");

  //------------------------------------------------------------------------------------------------
  // object id and cleaning sequence
  //------------------------------------------------------------------------------------------------
  //-----------------------------------
  // Lepton Selection
  //-----------------------------------
  ElectronIDMod* eleIdMod = new ElectronIDMod;
  eleIdMod->SetPtMin(10.);
  eleIdMod->SetEtaMax(2.5);
  eleIdMod->SetApplyEcalFiducial(kTRUE);
  eleIdMod->SetIDType("CustomLoose");
  eleIdMod->SetIsoType("PFIso_HggLeptonTag2012HCP");
  eleIdMod->SetPFNoPileUpName("pfnopileupcands");
  eleIdMod->SetApplyConversionFilterType1(kTRUE);
  eleIdMod->SetApplyConversionFilterType2(kFALSE);
  eleIdMod->SetChargeFilter(kFALSE);
  eleIdMod->SetApplyD0Cut(kTRUE);
  eleIdMod->SetApplyDZCut(kTRUE);
  eleIdMod->SetWhichVertex(0);
  eleIdMod->SetNExpectedHitsInnerCut(0);
  eleIdMod->SetGoodElectronsName("GoodElectronsBS");
  eleIdMod->SetRhoType(RhoUtilities::CMS_RHO_RHOKT6PFJETS);

  MuonIDMod *muonIdWW = new MuonIDMod;
  muonIdWW->SetOutputName("HWWMuons");
  muonIdWW->SetIntRadius(0.0);
  muonIdWW->SetClassType("GlobalTracker");
  muonIdWW->SetIDType("WWMuIdV4");
  muonIdWW->SetIsoType("IsoRingsV0_BDTG_Iso");
  muonIdWW->SetApplyD0Cut(kTRUE);
  muonIdWW->SetApplyDZCut(kTRUE);
  muonIdWW->SetWhichVertex(0);
  muonIdWW->SetRhoType(RhoUtilities::CMS_RHO_RHOKT6PFJETS);
  muonIdWW->SetPtMin(10.);
  muonIdWW->SetEtaCut(2.4);

  MuonIDMod *muonIdPOG = new MuonIDMod;
  muonIdPOG->SetOutputName("POGMuons");
  muonIdPOG->SetClassType("GlobalTracker");
  muonIdPOG->SetIDType("NoId");
  muonIdPOG->SetApplyD0Cut(true);
  muonIdPOG->SetD0Cut(0.2);
  muonIdPOG->SetApplyDZCut(true);
  muonIdPOG->SetDZCut(0.5);
  //muonIdPOG->SetIsoType("PFIsoBetaPUCorrected");
  //muonIdPOG->SetPFNoPileUpName("pfnopileupcands");
  //muonIdPOG->SetPFPileUpName("pfpileupcands");
  muonIdPOG->SetIsoType("NoIso");
  muonIdPOG->SetPtMin(10.);
  muonIdPOG->SetEtaCut(2.4);

  MuonIDMod* muonIdIso = new MuonIDMod;
  muonIdIso->SetOutputName("IsolatedPOGMuons");
  muonIdIso->SetClassType("GlobalorTracker");
  muonIdIso->SetIDType("NoId");
  muonIdIso->SetApplyD0Cut(true);
  muonIdIso->SetD0Cut(0.2);
  muonIdIso->SetApplyDZCut(true);
  muonIdIso->SetDZCut(0.5);
  muonIdIso->SetIsoType("PFIsoBetaPUCorrected"); //h
  muonIdIso->SetPFNoPileUpName("pfnopileupcands");
  muonIdIso->SetPFPileUpName("pfpileupcands");
  muonIdIso->SetPtMin(10.);
  muonIdIso->SetEtaCut(2.4);

  MuonIDMod *muonId = muonIdPOG;
  //MuonIDMod *muonId = muonIdIso;

  ElectronCleaningMod *electronCleaning = new ElectronCleaningMod;
  electronCleaning->SetCleanMuonsName(muonId->GetOutputName());
  electronCleaning->SetGoodElectronsName(eleIdMod->GetOutputName());
  electronCleaning->SetCleanElectronsName("CleanElectrons");

  MergeLeptonsMod *merger = new MergeLeptonsMod;
  merger->SetMuonsName(muonId->GetOutputName());
  merger->SetElectronsName(electronCleaning->GetOutputName());
  merger->SetMergedName("MergedLeptons");

//-----------------------------------
  // Photon Regression + ID
  //-----------------------------------
  PhotonMvaMod *photreg = new PhotonMvaMod;
  photreg->SetRegressionVersion(3);
  photreg->SetRegressionWeights(std::string(
    (gSystem->Getenv("MIT_DATA") + TString("/gbrv3ph_52x.root")).Data()
    ));
  photreg->SetOutputName("GoodPhotonsRegr");
  photreg->SetApplyShowerRescaling(kTRUE);
  photreg->SetMinNumPhotons(0);
  photreg->SetIsData(isData);

  PhotonIDMod *photonIDMod = new PhotonIDMod;
  photonIDMod->SetPtMin(15.0);
  photonIDMod->SetOutputName("GoodPhotons");
  photonIDMod->SetIDType("MITMVAId");
  photonIDMod->SetBdtCutBarrel(0.02);
  photonIDMod->SetBdtCutEndcap(0.1);
  photonIDMod->SetIdMVAType("2013FinalIdMVA_8TeV");
  photonIDMod->SetApplyElectronVeto(kTRUE);
  photonIDMod->SetApplyFiduciality(kTRUE);
  photonIDMod->SetIsData(isData);
  photonIDMod->SetPhotonsFromBranch(kFALSE);
  photonIDMod->SetInputName(photreg->GetOutputName());

  PFTauIDMod *pftauIDMod = new PFTauIDMod;
  pftauIDMod->SetPFTausName("HPSTaus");
  pftauIDMod->SetIsLooseId(kFALSE);
  pftauIDMod->SetIsHPSSel(kTRUE); // to get >= 5_3_14 samples running

  PhotonCleaningMod *photonCleaningMod = new PhotonCleaningMod;
  photonCleaningMod->SetCleanElectronsName(electronCleaning->GetOutputName());
  photonCleaningMod->SetGoodPhotonsName(photonIDMod->GetOutputName());
  photonCleaningMod->SetCleanPhotonsName("CleanPhotons");

  PFTauCleaningMod *pftauCleaningMod = new PFTauCleaningMod;
  pftauCleaningMod->SetGoodPFTausName(pftauIDMod->GetGoodPFTausName());
  pftauCleaningMod->SetCleanMuonsName(muonId->GetOutputName());

  PublisherMod<PFJet,Jet> *pubJet = new PublisherMod<PFJet,Jet>("JetPub");
  pubJet->SetInputName("AKt5PFJets");
  pubJet->SetOutputName("PubAKt5PFJets");

  JetCorrectionMod *jetCorr = new JetCorrectionMod;
  if(isData){
    jetCorr->AddCorrectionFromFile(std::string((gSystem->Getenv("CMSSW_BASE") + TString("/src/MitPhysics/data/Summer13_V1_DATA_L1FastJet_AK5PF.txt")).Data()));
    jetCorr->AddCorrectionFromFile(std::string((gSystem->Getenv("CMSSW_BASE") + TString("/src/MitPhysics/data/Summer13_V1_DATA_L2Relative_AK5PF.txt")).Data()));
    jetCorr->AddCorrectionFromFile(std::string((gSystem->Getenv("CMSSW_BASE") + TString("/src/MitPhysics/data/Summer13_V1_DATA_L3Absolute_AK5PF.txt")).Data()));
    jetCorr->AddCorrectionFromFile(std::string((gSystem->Getenv("CMSSW_BASE") + TString("/src/MitPhysics/data/Summer13_V1_DATA_L2L3Residual_AK5PF.txt")).Data()));
  }
  else {
    jetCorr->AddCorrectionFromFile(std::string((gSystem->Getenv("CMSSW_BASE") + TString("/src/MitPhysics/data/Summer13_V1_MC_L1FastJet_AK5PF.txt")).Data()));
    jetCorr->AddCorrectionFromFile(std::string((gSystem->Getenv("CMSSW_BASE") + TString("/src/MitPhysics/data/Summer13_V1_MC_L2Relative_AK5PF.txt")).Data()));
    jetCorr->AddCorrectionFromFile(std::string((gSystem->Getenv("CMSSW_BASE") + TString("/src/MitPhysics/data/Summer13_V1_MC_L3Absolute_AK5PF.txt")).Data()));
  }
  jetCorr->SetInputName(pubJet->GetOutputName());
  jetCorr->SetCorrectedName("CorrectedJets");

  JetIDMod *jetID = new JetIDMod;
  jetID->SetInputName(jetCorr->GetOutputName());
  jetID->SetPtCut(30.0);
  jetID->SetEtaMaxCut(4.7);
  jetID->SetJetEEMFractionMinCut(0.00);
  jetID->SetOutputName("GoodJets");
  jetID->SetApplyBetaCut(kFALSE);
  jetID->SetApplyMVACut(kTRUE);

  JetCleaningMod *jetCleaning = new JetCleaningMod;
  jetCleaning->SetCleanElectronsName(electronCleaning->GetOutputName());
  jetCleaning->SetCleanMuonsName(muonIdIso->GetOutputName()); // clean up isolated muons (instead of the loose ones)
  jetCleaning->SetCleanPhotonsName(photonCleaningMod->GetOutputName());
  jetCleaning->SetApplyPhotonRemoval(kTRUE);
  jetCleaning->SetGoodJetsName(jetID->GetOutputName());
  jetCleaning->SetCleanJetsName("CleanJets");

  MetCorrectionMod *metCorrT0T1Shift = new MetCorrectionMod;
  metCorrT0T1Shift->SetInputName("PFMet");
  metCorrT0T1Shift->SetJetsName(pubJet->GetOutputName());
  metCorrT0T1Shift->SetCorrectedJetsName(jetCorr->GetOutputName());
  metCorrT0T1Shift->SetCorrectedName("PFMetT0T1Shift");
  metCorrT0T1Shift->ApplyType0(kTRUE);
  metCorrT0T1Shift->ApplyType1(kTRUE);
  metCorrT0T1Shift->ApplyShift(kTRUE);
  metCorrT0T1Shift->IsData(isData);
  metCorrT0T1Shift->SetPrint(kFALSE);

  MonoJetTreeWriter *jetplusmettree = new MonoJetTreeWriter("MonoJetTreeWriter");
  jetplusmettree->SetTriggerObjectsName(hltModP->GetOutputName());
  jetplusmettree->SetMetName(metCorrT0T1Shift->GetOutputName()); //corrected met
  jetplusmettree->SetMetFromBranch(kFALSE);
  jetplusmettree->SetPhotonsFromBranch(kFALSE);
  jetplusmettree->SetPhotonsName(photonCleaningMod->GetOutputName());
  jetplusmettree->SetElectronsFromBranch(kFALSE);
  jetplusmettree->SetElectronsName(electronCleaning->GetOutputName());
  jetplusmettree->SetMuonsFromBranch(kFALSE);
  jetplusmettree->SetMuonsName(muonId->GetOutputName());
  jetplusmettree->SetTausFromBranch(kFALSE);
  jetplusmettree->SetTausName(pftauCleaningMod->GetOutputName());
  jetplusmettree->SetJetsFromBranch(kFALSE);
  jetplusmettree->SetJetsName(jetCleaning->GetOutputName());
  jetplusmettree->SetRawJetsName(pubJet->GetOutputName());
  jetplusmettree->SetPVFromBranch(kFALSE);
  jetplusmettree->SetPVName(goodPVFilterMod->GetOutputName());
  jetplusmettree->SetLeptonsName(merger->GetOutputName());
  jetplusmettree->SetIsData(isData);
  jetplusmettree->SetProcessID(0);
  jetplusmettree->SetFillNtupleType(0);

  //------------------------------------------------------------------------------------------------
  // making analysis chain
  //------------------------------------------------------------------------------------------------
  // this is how it always starts
  runLumiSel->Add(generatorMod);
  generatorMod->Add(goodPVFilterMod);
  goodPVFilterMod->Add(hltModP);
  // photon regression
  hltModP->Add(photreg);
  // simple object id modules
  photreg          ->Add(SepPUMod);
  SepPUMod         ->Add(muonId);
  muonId           ->Add(eleIdMod);
  eleIdMod         ->Add(electronCleaning);
  electronCleaning ->Add(merger);
  merger           ->Add(photonIDMod);
  photonIDMod      ->Add(photonCleaningMod);
  photonCleaningMod->Add(pftauIDMod);
  pftauIDMod       ->Add(pftauCleaningMod);
  pftauCleaningMod ->Add(pubJet);
  pubJet           ->Add(jetCorr);
  jetCorr          ->Add(metCorrT0T1Shift);
  metCorrT0T1Shift ->Add(jetID);
  jetID            ->Add(muonIdIso);
  muonIdIso        ->Add(jetCleaning);
  jetCleaning      ->Add(jetplusmettree);
  
  //------------------------------------------------------------------------------------------------
  // setup analysis
  //------------------------------------------------------------------------------------------------
  Analysis *ana = new Analysis;
  ana->SetUseCacher(cacher);
  ana->SetUseHLT(kTRUE);
  ana->SetKeepHierarchy(kTRUE);
  ana->SetSuperModule(runLumiSel);
  ana->SetPrintScale(100);
  if (nEvents >= 0)
    ana->SetProcessNEvents(nEvents);

  //------------------------------------------------------------------------------------------------
  // organize input
  //------------------------------------------------------------------------------------------------
  TString skimdataset = TString(dataset)+TString("/") +TString(skim);
  TString bookstr = book;
  Catalog *c = new Catalog(cataDir.Data());
  Dataset *d = NULL;
  if (TString(skim).CompareTo("noskim") == 0)
    d = c->FindDataset(bookstr,dataset,fileset,local);
  else
    d = c->FindDataset(bookstr,skimdataset.Data(),fileset,local);
  ana->AddDataset(d);
  //ana->AddFile("/mnt/hadoop/cms/store/user/paus/filefi/032/r12a-met-j22-v1/C4AC0AB8-BA82-E211-B238-003048678FF4.root");

  //------------------------------------------------------------------------------------------------
  // organize output
  //------------------------------------------------------------------------------------------------
  TString rootFile = TString(outputName);
  rootFile += TString("_") + TString(dataset) + TString("_") + TString(skim);
  if (TString(fileset) != TString(""))
    rootFile += TString("_") + TString(fileset);
  rootFile += TString(".root");
  ana->SetOutputName(rootFile.Data());
  ana->SetCacheSize(0);

  //------------------------------------------------------------------------------------------------
  // Say what we are doing
  //------------------------------------------------------------------------------------------------
  printf("\n==== PARAMETER SUMMARY FOR THIS JOB ====\n");
  printf("\n JSON file: %s\n",jsonFile.Data());
  printf("\n Rely on Catalog: %s\n",cataDir.Data());
  printf("  -> Book: %s  Dataset: %s  Skim: %s  Fileset: %s <-\n",book,dataset,skim,fileset);
  printf("\n Root output: %s\n\n",rootFile.Data());
  printf("\n========================================\n");

  //------------------------------------------------------------------------------------------------
  // run the analysis after successful initialisation
  //------------------------------------------------------------------------------------------------
  ana->Run(kFALSE);

  return;
}
Example #9
0
//--------------------------------------------------------------------------------------------------
void runHgg(const char *fileset    = "0000",
            const char *skim       = "noskim",
	    const char *dataset = "f11--h123gg-gf-v14b-pu",
            //const char *dataset = "r11a-pho-j16-v1",   
            const char *book       = "local/filefi/025",
            const char *catalogDir = "/home/cmsprod/catalog",
            const char *outputName = "hgg",
            int         nEvents    = 2000)
{
  //------------------------------------------------------------------------------------------------
  // some parameters get passed through the environment
  //------------------------------------------------------------------------------------------------
  char json[1024], overlap[1024];
  float overlapCut = -1;

  if (gSystem->Getenv("MIT_PROD_JSON"))
    sprintf(json,   "%s",gSystem->Getenv("MIT_PROD_JSON"));
  else {
    sprintf(json, "%s", "~");
    //printf(" JSON file was not properly defined. EXIT!\n");
    //return;
  } 

  TString jsonFile = TString("/home/mingyang/cms/json/") + TString(json);
  //TString jsonFile = TString("/home/mingyang/cms/json/") + TString("Cert_136033-149442_7TeV_Dec22ReReco_Collisions10_JSON_v4.txt");
  Bool_t  isData   = ( (jsonFile.CompareTo("/home/mingyang/cms/json/~") != 0) );
  
  if (gSystem->Getenv("MIT_PROD_OVERLAP")) {
    sprintf(overlap,"%s",gSystem->Getenv("MIT_PROD_OVERLAP"));
    if (EOF == sscanf(overlap,"%f",&overlapCut)) {
      printf(" Overlap was not properly defined. EXIT!\n");
      return;
    }
  }
  else {
     sprintf(overlap,"%s", "-1.0");
    //printf(" OVERLAP file was not properly defined. EXIT!\n");
    //return;
  } 

  printf("\n Initialization worked. \n\n");

  //------------------------------------------------------------------------------------------------
  // some global setups
  //------------------------------------------------------------------------------------------------
  using namespace mithep;
  gDebugMask  = Debug::kGeneral;
  gDebugLevel = 3;

  //------------------------------------------------------------------------------------------------
  // set up information
  //------------------------------------------------------------------------------------------------
  RunLumiSelectionMod *runLumiSel = new RunLumiSelectionMod;
  runLumiSel->SetAcceptMC(kTRUE);                          // Monte Carlo events are always accepted

  MCProcessSelectionMod *mcselmod = new MCProcessSelectionMod;
  
  MVASystematicsMod *sysMod = new MVASystematicsMod;
  sysMod->SetMCR9Scale(1.0035, 1.0035);  
  sysMod->SetIsData(isData);
  
  // only select on run- and lumisection numbers when valid json file present
  if ((jsonFile.CompareTo("/home/mingyang/cms/json/~") != 0) &&
      (jsonFile.CompareTo("/home/mingyang/cms/json/-") != 0)   ) {
    runLumiSel->AddJSONFile(jsonFile.Data());
  }
  if ((jsonFile.CompareTo("/home/mingyang/cms/json/-") == 0)   ) {
    printf("\n WARNING -- Looking at data without JSON file: always accept.\n\n");
    runLumiSel->SetAbortIfNotAccepted(kFALSE);   // accept all events if there is no valid JSON file
  }

  printf("\n Run lumi worked. \n\n");

  //------------------------------------------------------------------------------------------------
  // HLT information
  //------------------------------------------------------------------------------------------------
  HLTMod *hltModM = new HLTMod("HLTModM");
  hltModM->AddTrigger("HLT_Mu9");
  hltModM->AddTrigger("HLT_Mu11");
  hltModM->AddTrigger("HLT_Mu15_v1");
  hltModM->SetTrigObjsName("MyHltMuonObjs");
  hltModM->SetAbortIfNotAccepted(kFALSE);

  HLTMod *hltModE = new HLTMod("HLTModE");
//   hltModE->AddTrigger("HLT_Photon10_L1R",132440,137028);
//   hltModE->AddTrigger("HLT_Photon15_Cleaned_L1R",138564,140401);
//   hltModE->AddTrigger("HLT_Ele15_SW_CaloEleId_L1R",141956,144114);
//   hltModE->AddTrigger("HLT_Ele17_SW_CaloEleId_L1R",144115,147145);
//   hltModE->AddTrigger("HLT_Ele17_SW_TightEleId_L1R",147146,148102);
//   hltModE->AddTrigger("HLT_Ele27_SW_TightCaloEleIdTrack_L1R_v1",147146,148102);  
//   hltModE->AddTrigger("HLT_Ele22_SW_TighterCaloIdIsol_L1R_v1",148103,159999);  
//   hltModE->AddTrigger("HLT_Ele22_SW_TighterCaloIdIsol_L1R_v2",148103,159999);  
//   hltModE->AddTrigger("HLT_Ele17_CaloIdL_CaloIsoVL_Ele8_CaloIdL_CaloIsoVL_v1",160000,999999);
//   hltModE->AddTrigger("HLT_Ele17_CaloIdL_CaloIsoVL_Ele8_CaloIdL_CaloIsoVL_v2",160000,999999);
//   hltModE->AddTrigger("HLT_Ele17_CaloIdL_CaloIsoVL_Ele8_CaloIdL_CaloIsoVL_v3",160000,999999);
//   hltModE->AddTrigger("HLT_Ele15_LW_L1R",1,1);
//   hltModE->AddTrigger("HLT_Ele17_SW_CaloEleId_L1R",1,1);
//   hltModE->AddTrigger("HLT_Ele22_SW_TighterCaloIdIsol_L1R_v2",1,1);


  hltModE->AddTrigger("HLT_Ele17_CaloIdL_CaloIsoVL_Ele8_CaloIdL_CaloIsoVL_v1",150000,161176);
  hltModE->AddTrigger("HLT_Ele17_CaloIdL_CaloIsoVL_Ele8_CaloIdL_CaloIsoVL_v2",161179,163261);
  hltModE->AddTrigger("HLT_Ele17_CaloIdL_CaloIsoVL_Ele8_CaloIdL_CaloIsoVL_v3",163262,164237);
  hltModE->AddTrigger("HLT_Ele17_CaloIdL_CaloIsoVL_Ele8_CaloIdL_CaloIsoVL_v4",165085,165888);
  hltModE->AddTrigger("HLT_Ele17_CaloIdL_CaloIsoVL_Ele8_CaloIdL_CaloIsoVL_v5",165900,166967);
  hltModE->AddTrigger("HLT_Ele17_CaloIdL_CaloIsoVL_Ele8_CaloIdL_CaloIsoVL_v6",166968,170053);
  hltModE->AddTrigger("HLT_Ele17_CaloIdT_CaloIsoVL_TrkIdVL_TrkIsoVL_Ele8_CaloIdT_CaloIsoVL_TrkIdVL_TrkIsoVL_v6",170054,170759);
  hltModE->AddTrigger("HLT_Ele17_CaloIdT_CaloIsoVL_TrkIdVL_TrkIsoVL_Ele8_CaloIdT_CaloIsoVL_TrkIdVL_TrkIsoVL_v7",170760,173198);
  hltModE->AddTrigger("HLT_Ele17_CaloIdT_CaloIsoVL_TrkIdVL_TrkIsoVL_Ele8_CaloIdT_CaloIsoVL_TrkIdVL_TrkIsoVL_v8",173199,178380);
  hltModE->AddTrigger("HLT_Ele17_CaloIdT_CaloIsoVL_TrkIdVL_TrkIsoVL_Ele8_CaloIdT_CaloIsoVL_TrkIdVL_TrkIsoVL_v9",178381,179889);
  hltModE->AddTrigger("HLT_Ele17_CaloIdT_CaloIsoVL_TrkIdVL_TrkIsoVL_Ele8_CaloIdT_CaloIsoVL_TrkIdVL_TrkIsoVL_v10",179890,999999);
  hltModE->SetTrigObjsName("MyHltElecObjs");
  hltModE->SetAbortIfNotAccepted(isData);

  HLTMod *hltModES = new HLTMod("HLTModES");
  hltModES->AddTrigger("HLT_Ele27_CaloIdVT_CaloIsoT_TrkIdT_TrkIsoT_v*",160000,999999);
  hltModES->AddTrigger("HLT_Ele27_CaloIdVT_CaloIsoT_TrkIdT_TrkIsoT_v2",160000,999999);
  hltModES->AddTrigger("HLT_Ele27_CaloIdVT_CaloIsoT_TrkIdT_TrkIsoT_v3",160000,999999);
  hltModES->AddTrigger("HLT_Ele25_WP80_PFMT40_v*",160000,999999);
  hltModES->AddTrigger("HLT_Ele27_WP80_PFMT50_v*",160000,999999);
  hltModES->SetTrigObjsName("MyHltElecSObjs");
  hltModES->SetAbortIfNotAccepted(isData);
  
  HLTMod *hltModP = new HLTMod("HLTModP");
  
  hltModP->AddTrigger("HLT_Photon26_CaloIdL_IsoVL_Photon18_CaloIdL_IsoVL_v*",160000,161176);
  
  hltModP->AddTrigger("HLT_Photon26_CaloIdL_IsoVL_Photon18_CaloIdL_IsoVL_v*",161216,165633);
  hltModP->AddTrigger("HLT_Photon26_CaloIdL_IsoVL_Photon18_R9Id_v*",161216,165633);
  hltModP->AddTrigger("HLT_Photon26_R9Id_Photon18_CaloIdL_IsoVL_v*",161216,165633);
  hltModP->AddTrigger("HLT_Photon20_R9Id_Photon18_R9Id_v*",161216,165633);

  hltModP->AddTrigger("HLT_Photon26_CaloIdL_IsoVL_Photon18_CaloIdL_IsoVL_v*",165970,173198);
  hltModP->AddTrigger("HLT_Photon26_CaloIdL_IsoVL_Photon18_R9Id_v*",165970,173198);
  hltModP->AddTrigger("HLT_Photon26_R9Id_Photon18_CaloIdL_IsoVL_v*",165970,173198);
  hltModP->AddTrigger("HLT_Photon26_R9Id_Photon18_R9Id_v*",165970,173198);
  hltModP->AddTrigger("HLT_Photon36_CaloIdL_IsoVL_Photon22_CaloIdL_IsoVL_v*",165970,173198);
  hltModP->AddTrigger("HLT_Photon36_R9Id_Photon22_CaloIdL_IsoVL_v*",165970,173198);
  hltModP->AddTrigger("HLT_Photon36_R9Id_Photon22_R9Id_v*",165970,173198);
  
  hltModP->AddTrigger("HLT_Photon36_CaloId_IsoVL_Photon22_R9Id_v*",165970,166967);
  hltModP->AddTrigger("HLT_Photon36_CaloIdL_IsoVL_Photon22_R9Id_v*",167039,173198);
  
  hltModP->AddTrigger("HLT_Photon26_CaloIdXL_IsoXL_Photon18_CaloIdXL_IsoXL_v*",173236,178380);
  hltModP->AddTrigger("HLT_Photon26_CaloIdXL_IsoXL_Photon18_R9Id_v*",173236,178380);
  hltModP->AddTrigger("HLT_Photon26_R9Id_Photon18_CaloIdXL_IsoXL_v*",173236,178380);
  hltModP->AddTrigger("HLT_Photon26_R9Id_Photon18_R9Id_v*",173236,178380);
  hltModP->AddTrigger("HLT_Photon36_CaloIdL_IsoVL_Photon22_CaloIdL_IsoVL_v*",173236,178380);
  hltModP->AddTrigger("HLT_Photon36_CaloIdL_IsoVL_Photon22_R9Id_v*",173236,178380);
  hltModP->AddTrigger("HLT_Photon36_R9Id_Photon22_CaloIdL_IsoVL_v*",173236,178380);
  hltModP->AddTrigger("HLT_Photon36_R9Id_Photon22_R9Id_v*",173236,178380);
  
  hltModP->AddTrigger("HLT_Photon26_CaloIdXL_IsoXL_Photon18_CaloIdXL_IsoXL_Mass60_v*",178420,999999);
  hltModP->AddTrigger("HLT_Photon26_CaloIdXL_IsoXL_Photon18_R9IdT_Mass60_v*",178420,999999);
  hltModP->AddTrigger("HLT_Photon26_R9IdT_Photon18_CaloIdXL_IsoXL_Mass60_v*",178420,999999);
  hltModP->AddTrigger("HLT_Photon26_R9IdT_Photon18_R9IdT_Mass60_v*",178420,999999);
  hltModP->AddTrigger("HLT_Photon36_CaloIdL_IsoVL_Photon22_CaloIdL_IsoVL_v*",178420,999999);
  hltModP->AddTrigger("HLT_Photon36_CaloIdL_IsoVL_Photon22_R9Id_v*",178420,999999);
  hltModP->AddTrigger("HLT_Photon36_R9Id_Photon22_CaloIdL_IsoVL_v*",178420,999999);
  hltModP->AddTrigger("HLT_Photon36_R9Id_Photon22_R9Id_v*",178420,999999);
    
  hltModP->SetTrigObjsName("MyHltPhotObjs");
  hltModP->SetAbortIfNotAccepted(isData);
 
  //------------------------------------------------------------------------------------------------
  // select events with a good primary vertex
  //------------------------------------------------------------------------------------------------
  GoodPVFilterMod *goodPVFilterMod = new GoodPVFilterMod;
  goodPVFilterMod->SetMinVertexNTracks(0);
  goodPVFilterMod->SetMinNDof         (4.0);
  goodPVFilterMod->SetMaxAbsZ         (24.0);
  goodPVFilterMod->SetMaxRho          (2.0);
  goodPVFilterMod->SetAbortIfNotAccepted(kFALSE);
  goodPVFilterMod->SetIsMC(!isData);

  GoodPVFilterMod *goodPVFilterModE = new GoodPVFilterMod("GoodPVFilterModE");
  goodPVFilterModE->SetOutputName("GoodVertexesE");
  goodPVFilterModE->SetMinVertexNTracks(0);
  goodPVFilterModE->SetMinNDof         (4.0);
  goodPVFilterModE->SetMaxAbsZ         (24.0);
  goodPVFilterModE->SetMaxRho          (2.0);  
  goodPVFilterModE->SetIsMC(!isData);
  
  GoodPVFilterMod *goodPVFilterModES = new GoodPVFilterMod("GoodPVFilterModES");
  goodPVFilterModES->SetOutputName("GoodVertexesES");
  goodPVFilterModES->SetMinVertexNTracks(0);
  goodPVFilterModES->SetMinNDof         (4.0);
  goodPVFilterModES->SetMaxAbsZ         (24.0);
  goodPVFilterModES->SetMaxRho          (2.0);    
  

  //------------------------------------------------------------------------------------------------
  // object id and cleaning sequence
  //------------------------------------------------------------------------------------------------
  MuonIDMod *muonId = new MuonIDMod;  
  muonId->SetClassType ("Global");
  muonId->SetIDType    ("ZMuId");
  muonId->SetIsoType   ("TrackCaloSliding");
  muonId->SetApplyD0Cut(kTRUE);

  ElectronIDMod *elecId = new ElectronIDMod;
  elecId->SetVertexName(goodPVFilterModE->GetOutputName());
  elecId->SetIDType                    ("VBTFWorkingPointLowPtId");
  elecId->SetIsoType                   ("PFIso");
  elecId->SetNExpectedHitsInnerCut     (0);
  elecId->SetEtaMax(999.);
  elecId->SetChargeFilter(kFALSE);
  elecId->SetApplySpikeRemoval(kFALSE);
  elecId->SetApplyEcalFiducial(kTRUE);
  elecId->SetApplyEcalSeeded(kTRUE);
  elecId->SetPtMin(20.0);
  
  ElectronIDMod *elecIdS = new ElectronIDMod("ElectronIDModS");
  elecIdS->SetVertexName(goodPVFilterModES->GetOutputName());
  elecIdS->SetIDType                    ("VBTFWorkingPoint70Id");
  elecIdS->SetIsoType                   ("VBTFWorkingPoint70Iso");
  elecIdS->SetNExpectedHitsInnerCut     (0);
  elecIdS->SetEtaMax(999.);
  elecIdS->SetChargeFilter(kFALSE);
  elecIdS->SetApplySpikeRemoval(kFALSE);
  elecIdS->SetApplyEcalFiducial(kTRUE);
  elecIdS->SetApplyEcalSeeded(kTRUE);
  elecIdS->SetPtMin(20.0);
  elecIdS->SetOutputName("GoodElectronsS");
  
  PublisherMod<PFJet,Jet> *pubJet = new PublisherMod<PFJet,Jet>("JetPub");
  pubJet->SetInputName("AKt5PFJets");
  pubJet->SetOutputName("PubAKt5PFJets");
  
  PublisherMod<PFJet,Jet> *pubJetOpen = new PublisherMod<PFJet,Jet>("JetPubOpen");
  pubJetOpen->SetInputName("AKt5PFJets");
  pubJetOpen->SetOutputName("PubAKt5PFJetsOpen");  

  JetCorrectionMod *jetCorr = new JetCorrectionMod;
  jetCorr->AddCorrectionFromFile(std::string((gSystem->Getenv("CMSSW_BASE") + TString("/src/MitPhysics/data/START42_V12_AK5PF_L1FastJet.txt")).Data())); 
  jetCorr->AddCorrectionFromFile(std::string((gSystem->Getenv("CMSSW_BASE") + TString("/src/MitPhysics/data/START42_V12_AK5PF_L2Relative.txt")).Data())); 
  jetCorr->AddCorrectionFromFile(std::string((gSystem->Getenv("CMSSW_BASE") + TString("/src/MitPhysics/data/START42_V12_AK5PF_L3Absolute.txt")).Data())); 
  if(isData){ 
    jetCorr->AddCorrectionFromFile(std::string((gSystem->Getenv("CMSSW_BASE") + TString("/src/MitPhysics/data/START42_V12_AK5PF_L2L3Residual.txt")).Data())); 
  }
  jetCorr->SetInputName(pubJet->GetOutputName());
  jetCorr->SetCorrectedName("CorrectedJets");

  Bool_t excludedoubleprompt = kFALSE;
  if (TString(dataset).Contains("-pj")) {
    mcselmod->ExcludeProcess(18);
    mcselmod->ExcludeProcess(114);
    excludedoubleprompt = kTRUE;
  }

  if (TString(dataset).Contains("-qcd2em") || TString(dataset).Contains("-qcd-2em")) {
    excludedoubleprompt = kTRUE;
  }
  
  PhotonMvaMod *photreg = new PhotonMvaMod;
  photreg->SetOutputName("GoodPhotonsRegr");
  photreg->SetIsData(isData);

    
  PhotonPairSelector         *photcic = new PhotonPairSelector("PhotonPairSelectorCiC");
  photcic->SetOutputName("GoodPhotonsCIC");
  photcic->SetPhotonSelType("CiCSelection");
  photcic->SetVertexSelType("CiCMVASelection");
  photcic->DoMCSmear(kTRUE);
  photcic->DoDataEneCorr(kTRUE);
  photcic->SetPhotonsFromBranch(kFALSE);
  photcic->SetInputPhotonsName(photreg->GetOutputName());
  photcic->SetMCSmearFactors(0.0089, 0.0089, 0.0109, 0.0156, 0.0203,0.0303,0.0326,0.0318,0.0331);
  photcic->AddEnCorrPerRun(160000,167913,0.9905,0.9905,0.9971,0.9976,1.0094,0.9994,1.0044,0.9968,1.0079);
  photcic->AddEnCorrPerRun(170249,172619,0.9909,0.9909,0.9975,0.9994,1.0112,0.9962,1.0012,0.9962,1.0072);
  photcic->AddEnCorrPerRun(172620,173692,0.9909,0.9909,0.9975,0.9977,1.0096,0.9963,1.0013,0.9947,1.0057);
  photcic->AddEnCorrPerRun(175860,177139,0.9911,0.9911,0.9977,0.9990,1.0109,0.9922,0.9973,0.9967,1.0077);
  photcic->AddEnCorrPerRun(177140,178421,0.9910,0.9910,0.9975,0.9987,1.0105,0.9921,0.9972,0.9975,1.0085);
  photcic->AddEnCorrPerRun(178424,999999,0.9903,0.9903,0.9969,0.9976,1.0095,0.9889,0.9940,0.9976,1.0086);
  photcic->SetDoMCR9Scaling(kTRUE);
  photcic->SetMCR9Scale(1.0048, 1.00492);
  photcic->SetDoMCErrScaling(kTRUE);
  photcic->SetMCErrScale(1.07, 1.045);    
  photcic->SetIsData(isData);

  PhotonPairSelector         *photcicnoeleveto = new PhotonPairSelector("PhotonPairSelectorCiCNoEleVeto");
  photcicnoeleveto->SetOutputName("GoodPhotonsCICNoEleVeto");
  photcicnoeleveto->SetPhotonSelType("CiCSelection");
  photcicnoeleveto->SetVertexSelType("CiCMVASelection");
  photcicnoeleveto->DoMCSmear(kTRUE);
  photcicnoeleveto->DoDataEneCorr(kTRUE);
  photcicnoeleveto->SetPhotonsFromBranch(kFALSE);
  photcicnoeleveto->SetInputPhotonsName(photreg->GetOutputName());
  photcicnoeleveto->SetMCSmearFactors(0.0089, 0.0089, 0.0109, 0.0156, 0.0203,0.0303,0.0326,0.0318,0.0331);
  photcicnoeleveto->AddEnCorrPerRun(160000,167913,0.9905,0.9905,0.9971,0.9976,1.0094,0.9994,1.0044,0.9968,1.0079);
  photcicnoeleveto->AddEnCorrPerRun(170249,172619,0.9909,0.9909,0.9975,0.9994,1.0112,0.9962,1.0012,0.9962,1.0072);
  photcicnoeleveto->AddEnCorrPerRun(172620,173692,0.9909,0.9909,0.9975,0.9977,1.0096,0.9963,1.0013,0.9947,1.0057);
  photcicnoeleveto->AddEnCorrPerRun(175860,177139,0.9911,0.9911,0.9977,0.9990,1.0109,0.9922,0.9973,0.9967,1.0077);
  photcicnoeleveto->AddEnCorrPerRun(177140,178421,0.9910,0.9910,0.9975,0.9987,1.0105,0.9921,0.9972,0.9975,1.0085);
  photcicnoeleveto->AddEnCorrPerRun(178424,999999,0.9903,0.9903,0.9969,0.9976,1.0095,0.9889,0.9940,0.9976,1.0086);
  photcicnoeleveto->SetDoMCR9Scaling(kTRUE);
  photcicnoeleveto->SetMCR9Scale(1.0048, 1.00492);
  photcicnoeleveto->SetDoMCErrScaling(kTRUE);
  photcicnoeleveto->SetMCErrScale(1.07, 1.045);    
  photcicnoeleveto->SetApplyEleVeto(kFALSE);
  photcicnoeleveto->SetIsData(isData);
  
  
  PhotonPairSelector         *photpresel = new PhotonPairSelector("PhotonPairSelectorPresel");
  photpresel->SetOutputName("GoodPhotonsPresel");
  photpresel->SetPhotonSelType("MITSelection");
  photpresel->SetVertexSelType("CiCMVASelection");
  photpresel->DoMCSmear(kTRUE);
  photpresel->DoDataEneCorr(kTRUE);
  photpresel->SetPhotonsFromBranch(kFALSE);
  photpresel->SetInputPhotonsName(photreg->GetOutputName());
  //photpresel->SetMCSmearFactors(0.0045, 0.0084, 0.0109, 0.0156, 0.0203,0.0303,0.0326,0.0318,0.0331);
  photpresel->SetMCSmearFactors(0.0067,0.0077,0.0096,0.0141,0.0196,0.0268,0.0279,0.0293,0.0301);//ming:smear(sigE/E)
  //photpresel->AddEnCorrPerRun(160000,167913,0.9905,0.9905,0.9971,0.9976,1.0094,0.9994,1.0044,0.9968,1.0079);
  //photpresel->AddEnCorrPerRun(170249,172619,0.9909,0.9909,0.9975,0.9994,1.0112,0.9962,1.0012,0.9962,1.0072);
  //photpresel->AddEnCorrPerRun(172620,173692,0.9909,0.9909,0.9975,0.9977,1.0096,0.9963,1.0013,0.9947,1.0057);
  //photpresel->AddEnCorrPerRun(175860,177139,0.9911,0.9911,0.9977,0.9990,1.0109,0.9922,0.9973,0.9967,1.0077);
  //photpresel->AddEnCorrPerRun(177140,178421,0.9910,0.9910,0.9975,0.9987,1.0105,0.9921,0.9972,0.9975,1.0085);
  //photpresel->AddEnCorrPerRun(178424,999999,0.9903,0.9903,0.9969,0.9976,1.0095,0.9889,0.9940,0.9976,1.0086); 
  photpresel->AddEnCorrPerRun(160431,167913,0.9941,0.9941,1.0004,0.9916,1.0045,1.0033,1.0082,0.9958,1.0064);//ming:Emc/Edata
  photpresel->AddEnCorrPerRun(170000,172619,0.9954,0.9954,1.0016,0.9937,1.0066,0.9976,1.0025,0.9940,1.0046);
  photpresel->AddEnCorrPerRun(172620,173692,0.9955,0.9955,1.0017,0.9929,1.0058,0.9986,1.0035,0.9923,1.0029);
  photpresel->AddEnCorrPerRun(175830,177139,0.9958,0.9958,1.0021,0.9944,1.0073,0.9968,1.0017,0.9933,1.004);
  photpresel->AddEnCorrPerRun(177140,178421,0.9962,0.9962,1.0025,0.9946,1.0075,0.9960,1.0010,0.9944,1.005);
  photpresel->AddEnCorrPerRun(178424,180252,0.9961,0.9961,1.0024,0.9942,1.0071,0.9921,0.9970,0.9953,1.0059); 
  photpresel->SetDoMCR9Scaling(kTRUE);
  photpresel->SetMCR9Scale(1.0035, 1.0035);  
  photpresel->SetDoMCSigIEtaIEtaScaling(kTRUE);
  photpresel->SetDoMCWidthScaling(kTRUE);  
  photpresel->SetDoMCErrScaling(kTRUE);
  photpresel->SetMCErrScale(1.07, 1.045);    
  photpresel->SetIsData(isData);

  PhotonPairSelector         *photpreselinverteleveto = new PhotonPairSelector("PhotonPairSelectorPreselInvertEleVeto");
  photpreselinverteleveto->SetOutputName("GoodPhotonsPreselInvertEleVeto");
  photpreselinverteleveto->SetPhotonSelType("MITSelection");
  photpreselinverteleveto->SetVertexSelType("CiCMVASelection");
  photpreselinverteleveto->DoMCSmear(kTRUE);
  photpreselinverteleveto->DoDataEneCorr(kTRUE);
  photpreselinverteleveto->SetPhotonsFromBranch(kFALSE);
  photpreselinverteleveto->SetInputPhotonsName(photreg->GetOutputName());
  photpreselinverteleveto->SetMCSmearFactors(0.0045, 0.0084, 0.0109, 0.0156, 0.0203,0.0303,0.0326,0.0318,0.0331);
  photpreselinverteleveto->AddEnCorrPerRun(160000,167913,0.9905,0.9905,0.9971,0.9976,1.0094,0.9994,1.0044,0.9968,1.0079);
  photpreselinverteleveto->AddEnCorrPerRun(170249,172619,0.9909,0.9909,0.9975,0.9994,1.0112,0.9962,1.0012,0.9962,1.0072);
  photpreselinverteleveto->AddEnCorrPerRun(172620,173692,0.9909,0.9909,0.9975,0.9977,1.0096,0.9963,1.0013,0.9947,1.0057);
  photpreselinverteleveto->AddEnCorrPerRun(175860,177139,0.9911,0.9911,0.9977,0.9990,1.0109,0.9922,0.9973,0.9967,1.0077);
  photpreselinverteleveto->AddEnCorrPerRun(177140,178421,0.9910,0.9910,0.9975,0.9987,1.0105,0.9921,0.9972,0.9975,1.0085);
  photpreselinverteleveto->AddEnCorrPerRun(178424,999999,0.9903,0.9903,0.9969,0.9976,1.0095,0.9889,0.9940,0.9976,1.0086); 
  photpreselinverteleveto->SetDoMCR9Scaling(kTRUE);
  photpreselinverteleveto->SetMCR9Scale(1.0035, 1.0035);
  photpreselinverteleveto->SetDoMCSigIEtaIEtaScaling(kTRUE);
  photpreselinverteleveto->SetDoMCWidthScaling(kTRUE);  
  photpreselinverteleveto->SetDoMCErrScaling(kTRUE);
  photpreselinverteleveto->SetMCErrScale(1.07, 1.045);    
  photpreselinverteleveto->SetApplyEleVeto(kFALSE);
  photpreselinverteleveto->SetInvertElectronVeto(kTRUE);
  photpreselinverteleveto->SetIsData(isData);  
  
  PhotonPairSelector         *photpreselnosmear = new PhotonPairSelector("PhotonPairSelectorPreselNoSmear");
  photpreselnosmear->SetOutputName("GoodPhotonsPreselNoSmear");
  photpreselnosmear->SetPhotonSelType("MITSelection");
  photpreselnosmear->SetVertexSelType("CiCMVASelection");
  photpreselnosmear->SetPhotonsFromBranch(kFALSE);
  photpreselnosmear->SetInputPhotonsName(photreg->GetOutputName());
  photpreselnosmear->SetIsData(isData);  
  
  
  PhotonTreeWriter *phottreecic = new PhotonTreeWriter("PhotonTreeWriterCiC");
  phottreecic->SetPhotonsFromBranch(kFALSE);
  phottreecic->SetInputPhotonsName(photcic->GetOutputName());
  phottreecic->SetEnableJets(kTRUE);
  phottreecic->SetPFJetsFromBranch(kFALSE);
  phottreecic->SetPFJetName(jetCorr->GetOutputName());
  phottreecic->SetExcludeDoublePrompt(excludedoubleprompt);
  phottreecic->SetIsData(isData);

  PhotonTreeWriter *phottreecicnoeleveto = new PhotonTreeWriter("PhotonTreeWriterCiCNoEleVeto");
  phottreecicnoeleveto->SetPhotonsFromBranch(kFALSE);
  phottreecicnoeleveto->SetInputPhotonsName(photcicnoeleveto->GetOutputName());
  phottreecicnoeleveto->SetEnableJets(kTRUE);
  phottreecicnoeleveto->SetPFJetsFromBranch(kFALSE);
  phottreecicnoeleveto->SetPFJetName(jetCorr->GetOutputName());
  phottreecicnoeleveto->SetApplyElectronVeto(kFALSE);
  phottreecicnoeleveto->SetExcludeDoublePrompt(excludedoubleprompt);
  phottreecicnoeleveto->SetIsData(isData);  
  
  PhotonTreeWriter *phottreepresel = new PhotonTreeWriter("PhotonTreeWriterPresel");
  phottreepresel->SetPhotonsFromBranch(kFALSE);
  phottreepresel->SetInputPhotonsName(photpresel->GetOutputName());
  phottreepresel->SetEnableJets(kTRUE);
  phottreepresel->SetPFJetsFromBranch(kFALSE);
  phottreepresel->SetPFJetName(jetCorr->GetOutputName());  
  phottreepresel->SetExcludeDoublePrompt(excludedoubleprompt);  
  phottreepresel->SetIsData(isData);  
  
  PhotonTreeWriter *phottreepreselinverteleveto = new PhotonTreeWriter("PhotonTreeWriterPreselInvertEleVeto");
  phottreepreselinverteleveto->SetPhotonsFromBranch(kFALSE);
  phottreepreselinverteleveto->SetInputPhotonsName(photpreselinverteleveto->GetOutputName());
  phottreepreselinverteleveto->SetEnableJets(kTRUE);
  phottreepreselinverteleveto->SetPFJetsFromBranch(kFALSE);
  phottreepreselinverteleveto->SetPFJetName(jetCorr->GetOutputName());  
  phottreepreselinverteleveto->SetApplyElectronVeto(kFALSE);  
  phottreepreselinverteleveto->SetExcludeDoublePrompt(excludedoubleprompt);    
  phottreepreselinverteleveto->SetIsData(isData); 
  
  PhotonTreeWriter *phottreepreselnosmear = new PhotonTreeWriter("PhotonTreeWriterPreselNoSmear");
  phottreepreselnosmear->SetPhotonsFromBranch(kFALSE);
  phottreepreselnosmear->SetInputPhotonsName(photpreselnosmear->GetOutputName());
  phottreepreselnosmear->SetEnableJets(kTRUE);
  phottreepreselnosmear->SetPFJetsFromBranch(kFALSE);
  phottreepreselnosmear->SetPFJetName(jetCorr->GetOutputName());  
  phottreepreselnosmear->SetExcludeDoublePrompt(excludedoubleprompt);  
  phottreepreselnosmear->SetIsData(isData);    
  
  
  PhotonIDMod         *photidcic = new PhotonIDMod("PhotonIDModPresel");
  photidcic->SetPtMin(25.0);
  photidcic->SetOutputName("GoodPhotonsPreselid");
  photidcic->SetOutputName("MITSelection");
  photidcic->SetApplyElectronVeto(kTRUE);
  photidcic->SetIsData(isData);

  PhotonTreeWriter *phottreesingle = new PhotonTreeWriter("PhotonTreeWriterSingle");
  phottreesingle->SetWriteDiphotonTree(kFALSE);
  phottreesingle->SetPhotonsFromBranch(kFALSE);
  phottreesingle->SetInputPhotonsName(photidcic->GetOutputName());  
  phottreesingle->SetIsData(isData);
  
  PhotonTreeWriter *phottreeE = new PhotonTreeWriter("PhotonTreeWriterE");
  phottreeE->SetGoodElectronsFromBranch(kFALSE);
  phottreeE->SetGoodElectronName(elecId->GetOutputName());  
  phottreeE->SetLoopOnGoodElectrons(kTRUE);
  phottreeE->SetApplyElectronVeto(kFALSE);
  phottreeE->SetIsData(isData);

  PhotonTreeWriter *phottreeES = new PhotonTreeWriter("PhotonTreeWriterES");
  phottreeES->SetWriteDiphotonTree(kFALSE);
  phottreeES->SetGoodElectronsFromBranch(kFALSE);
  phottreeES->SetGoodElectronName(elecIdS->GetOutputName());  
  phottreeES->SetLoopOnGoodElectrons(kTRUE);
  phottreeES->SetApplyElectronVeto(kFALSE);
  phottreeES->SetIsData(isData);  
  

  //------------------------------------------------------------------------------------------------
  // making analysis chain
  //------------------------------------------------------------------------------------------------
  // this is how it always starts
  runLumiSel      ->Add(mcselmod);
    
  if (TString(dataset).Contains("-h")) {    
    mcselmod        ->Add(sysMod);
  }
  
  // high level trigger is always first
  //mcselmod         ->Add(hltModE);
  //mcselmod         ->Add(hltModES);
  mcselmod         ->Add(hltModP);

  hltModP         ->Add(goodPVFilterMod);
  //hltModE         ->Add(goodPVFilterModE);
  //hltModES        ->Add(goodPVFilterModES);
  
  //goodPVFilterMod ->Add(muonId);
  goodPVFilterMod->Add(photreg);
  photreg->Add(pubJet);
  pubJet->Add(jetCorr);
  
  // simple object id modules
  //goodPVFilterModE ->Add(elecId);
  //goodPVFilterModES ->Add(elecIdS);

  
  //jetCorr          ->Add(photcic);
  //jetCorr          ->Add(photcicnoeleveto);  
  jetCorr          ->Add(photpresel);  
  //jetCorr          ->Add(photpreselinverteleveto);  
  //jetCorr          ->Add(photpreselnosmear);  

  //photcic         ->Add(phottreecic);
  //photcicnoeleveto         ->Add(phottreecicnoeleveto);
  photpresel    ->Add(phottreepresel);
  //photpreselinverteleveto    ->Add(phottreepreselinverteleveto);
  //photpreselnosmear    ->Add(phottreepreselnosmear);


  //jetCorr          ->Add(photidcic);
  //photidcic       ->Add(phottreesingle);
  
  //elecId->Add(phottreeE);
  //elecIdS->Add(phottreeES);
  

  TFile::SetOpenTimeout(0);
  TFile::SetCacheFileDir("./rootfilecache",kTRUE,kTRUE);
  TFile::SetReadaheadSize(128*1024*1024);
  
  //------------------------------------------------------------------------------------------------
  // setup analysis
  //------------------------------------------------------------------------------------------------
  Analysis *ana = new Analysis;
  ana->SetUseHLT(kTRUE);
  ana->SetKeepHierarchy(kTRUE);
  ana->SetSuperModule(runLumiSel);
  ana->SetPrintScale(100);
  if (nEvents >= 0)
    ana->SetProcessNEvents(nEvents);

  //------------------------------------------------------------------------------------------------
  // organize input
  //------------------------------------------------------------------------------------------------
  Catalog *c = new Catalog(catalogDir);
  TString skimdataset = TString(dataset)+TString("/") +TString(skim);
  Dataset *d = NULL;
  TString bookstr = book;
  //if (TString(dataset).Contains("s11-h")) bookstr.ReplaceAll("local","t2mit");
  if (TString(skim).CompareTo("noskim") == 0)
    d = c->FindDataset(bookstr,dataset,fileset);
  else 
    d = c->FindDataset(bookstr,skimdataset.Data(),fileset);
  ana->AddDataset(d);
  //ana->AddFile("/mnt/hadoop/cmsprod/filefi/025/r11b-pho-n30-v1/4863E9D1-BC1C-E111-99BA-001A92810AF4.root");

  //------------------------------------------------------------------------------------------------
  // organize output
  //------------------------------------------------------------------------------------------------
  TString rootFile = TString(outputName);
  rootFile += TString("_") + TString(dataset) + TString("_") + TString(skim);
  if (TString(fileset) != TString(""))
    rootFile += TString("_") + TString(fileset);
  rootFile += TString(".root");
  ana->SetOutputName(rootFile.Data());
  //ana->SetCacheSize(64*1024*1024);
  ana->SetCacheSize(0);
  
  //------------------------------------------------------------------------------------------------
  // Say what we are doing
  //------------------------------------------------------------------------------------------------
  printf("\n==== PARAMETER SUMMARY FOR THIS JOB ====\n");
  printf("\n JSON file: %s\n  and overlap cut: %f (%s)\n",jsonFile.Data(),overlapCut,overlap);
  printf("\n Rely on Catalog: %s\n",catalogDir);
  printf("  -> Book: %s  Dataset: %s  Skim: %s  Fileset: %s <-\n",book,dataset,skim,fileset);
  printf("\n Root output: %s\n\n",rootFile.Data());  
  printf("\n========================================\n");

  //------------------------------------------------------------------------------------------------
  // run the analysis after successful initialisation
  //------------------------------------------------------------------------------------------------
  ana->Run(!gROOT->IsBatch());

  return;
}