Exemplo n.º 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;
}
Exemplo n.º 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;
}
Exemplo n.º 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;
}
//--------------------------------------------------------------------------------------------------
void runMonoPhoton(const char *fileset    = "0000",
		   const char *skim       = "noskim",
		   const char *dataset    = "s12-zgllg-v7a", 
		   const char *book       = "cern/filefi/031",
		   const char *catalogDir = "~/scratch0/catalog",
		   const char *outputName = "test/jmet",
		   int         nEvents    = 10000)
{
  //------------------------------------------------------------------------------------------------
  // some parameters get passed through the environment
  //------------------------------------------------------------------------------------------------
  char json[1024], overlap[1024];
  TString jsonFile = "";
  float overlapCut = -1;
  Bool_t  isData = false;

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

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

  //------------------------------------------------------------------------------------------------
  // set up information
  //------------------------------------------------------------------------------------------------
  MCProcessSelectionMod *mcselmod = new MCProcessSelectionMod;
  
  MVASystematicsMod *sysMod = new MVASystematicsMod;
  sysMod->SetMCR9Scale(1.0035, 1.0035);  
  sysMod->SetIsData(isData);
  
  RunLumiSelectionMod *runLumiSel = new RunLumiSelectionMod;      
  runLumiSel->SetAcceptMC(!isData);
  runLumiSel->AddJSONFile(string(getenv("CMSSW_BASE")+string("/src/json/Cert_Current_JSON.txt")));

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

  // Dataset Flags
  bool isDataSinglePh     = false;
  bool isDataPhHad        = false;
  if (TString(dataset).Contains("-pho-") || TString(dataset).Contains("-sph-")) isDataSinglePh = true;
  if (TString(dataset).Contains("-phh-")) isDataPhHad = true;

  // Generator info
  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);
  generatorMod->SetApplyISRFilter(kFALSE);
  generatorMod->SetApplyVVFilter(kFALSE);
  generatorMod->SetApplyVGFilter(kFALSE);
  generatorMod->SetFilterBTEvents(kFALSE);

  //------------------------------------------------------------------------------------------------
  // HLT information
  //------------------------------------------------------------------------------------------------
  HLTMod *hltModP = new HLTMod("HLTModP");
  
  //------------------------------------------------------------------------------------------------
  // Run2011
  //------------------------------------------------------------------------------------------------
  hltModP->AddTrigger("HLT_Photon75_CaloIdVL_v*",160404,165087); 
  hltModP->AddTrigger("HLT_Photon125_v*",165088,163869); 
  hltModP->AddTrigger("HLT_Photon135_v*",167039,190455); 

  //------------------------------------------------------------------------------------------------
  // Run2012
  //------------------------------------------------------------------------------------------------
  if (isData){//DATA
    if (isDataSinglePh){
      hltModP->AddTrigger("HLT_Photon135_v*",190456,193686); 
      hltModP->AddTrigger("HLT_Photon150_v*",193687,199695); 
      hltModP->AddTrigger("HLT_Photon135_v*",199696,209151); 
    }
    else if (isDataPhHad){
      hltModP->AddTrigger("!HLT_Photon135_v*&HLT_Photon70_CaloIdXL_PFMET100_v*",190456,193686); 
      hltModP->AddTrigger("!HLT_Photon150_v*&HLT_Photon70_CaloIdXL_PFMET100_v*",193687,199695); 
      hltModP->AddTrigger("!HLT_Photon135_v*&HLT_Photon70_CaloIdXL_PFMET100_v*",199696,209151); 
    }
    else{
      printf("ERROR, WRONG DATASET IDENTIFICATION FOR: %s\n",dataset);
      return;
    }
  }
  else{//MC
    hltModP->AddTrigger("HLT_Photon135_v*",0,999999); 
    hltModP->AddTrigger("HLT_Photon70_CaloIdXL_PFMET100*",0,999999);
    hltModP->AddTrigger("HLT_MonoCentralPFJet80_PFMETnoMu95_NHEF0p95_v*",0,999999);
    hltModP->AddTrigger("HLT_MonoCentralPFJet80_PFMETnoMu105_NHEF0p95_v*",0,999999);
    hltModP->AddTrigger("HLT_MET120_HBHENoiseCleaned_v*",0,999999);
    hltModP->AddTrigger("HLT_MET120_v10",0,999999);
    hltModP->AddTrigger("!HLT_MET120_v10",0,999999);
  }
    
  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->SetIDType("VBTFWorkingPointLowPtId");
  eleIdMod->SetIsoType("PFIso");
  eleIdMod->SetApplyConversionFilterType1(kTRUE);
  eleIdMod->SetApplyConversionFilterType2(kFALSE);
  eleIdMod->SetChargeFilter(kFALSE);
  eleIdMod->SetApplyD0Cut(kTRUE);
  eleIdMod->SetApplyDZCut(kTRUE);
  eleIdMod->SetWhichVertex(-1);
  eleIdMod->SetNExpectedHitsInnerCut(0);
  eleIdMod->SetGoodElectronsName("GoodElectrons");
  eleIdMod->SetRhoType(RhoUtilities::CMS_RHO_RHOKT6PFJETS);
 
  MuonIDMod* muonIdMod = new MuonIDMod;
  // base kinematics
  muonIdMod -> SetPtMin(10.);
  muonIdMod -> SetEtaCut(2.4);
  // base ID
  muonIdMod -> SetIDType("Tight");
  muonIdMod -> SetWhichVertex(-1); // this is a 'hack'.. but hopefully good enough...
  muonIdMod -> SetD0Cut(0.02);
  muonIdMod -> SetDZCut(0.5);
  muonIdMod -> SetIsoType("PFIsoBetaPUCorrected"); //h
  muonIdMod -> SetPFIsoCut(0.2); //h
  muonIdMod -> SetOutputName("HggLeptonTagMuons");
  muonIdMod -> SetPFNoPileUpName("pfnopileupcands");
  muonIdMod -> SetPFPileUpName("pfpileupcands");
  muonIdMod -> SetPVName(Names::gkPVBeamSpotBrn); 
  
  ElectronCleaningMod *electronCleaning = new ElectronCleaningMod;
  electronCleaning->SetCleanMuonsName(muonIdMod->GetOutputName());
  electronCleaning->SetGoodElectronsName(eleIdMod->GetOutputName());
  electronCleaning->SetCleanElectronsName("CleanElectrons");

  CosmicCleaningMod *cosmicCleaning = new CosmicCleaningMod;
  cosmicCleaning->SetCleanMuonsName(muonIdMod->GetOutputName());
  cosmicCleaning->SetCosmicsName("CosmicMuons");
  cosmicCleaning->SetCleanCosmicsName("CleanCosmics");

  MergeLeptonsMod *merger = new MergeLeptonsMod;
  merger->SetMuonsName(muonIdMod->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(1);
  photreg->SetIsData(isData);
  photreg->SetDoPreselection(kFALSE);

  PhotonIDMod *photonIDMod = new PhotonIDMod;
  photonIDMod->SetPtMin(20.0);
  photonIDMod->SetOutputName("GoodPhotons");
  photonIDMod->SetIDType("BaseLineCiCPFNoPresel");
  photonIDMod->SetIsoType("NoIso");
  photonIDMod->SetApplyElectronVeto(kFALSE);
  photonIDMod->SetApplyPixelSeed(kFALSE);
  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);

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

  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/Summer12_V7_DATA_L1FastJet_AK5PF.txt")).Data())); 
    jetCorr->AddCorrectionFromFile(std::string((gSystem->Getenv("CMSSW_BASE") + TString("/src/MitPhysics/data/Summer12_V7_DATA_L2Relative_AK5PF.txt")).Data())); 
    jetCorr->AddCorrectionFromFile(std::string((gSystem->Getenv("CMSSW_BASE") + TString("/src/MitPhysics/data/Summer12_V7_DATA_L3Absolute_AK5PF.txt")).Data())); 
    jetCorr->AddCorrectionFromFile(std::string((gSystem->Getenv("CMSSW_BASE") + TString("/src/MitPhysics/data/Summer12_V7_DATA_L2L3Residual_AK5PF.txt")).Data())); 
  }
  else {
    jetCorr->AddCorrectionFromFile(std::string((gSystem->Getenv("CMSSW_BASE") + TString("/src/MitPhysics/data/Summer12_V7_MC_L1FastJet_AK5PF.txt")).Data())); 
    jetCorr->AddCorrectionFromFile(std::string((gSystem->Getenv("CMSSW_BASE") + TString("/src/MitPhysics/data/Summer12_V7_MC_L2Relative_AK5PF.txt")).Data())); 
    jetCorr->AddCorrectionFromFile(std::string((gSystem->Getenv("CMSSW_BASE") + TString("/src/MitPhysics/data/Summer12_V7_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(muonIdMod->GetOutputName());
  theJetCleaning->SetCleanPhotonsName(photonCleaningMod->GetOutputName());
  theJetCleaning->SetApplyPhotonRemoval(kTRUE);
  theJetCleaning->SetGoodJetsName(theJetID->GetOutputName());
  theJetCleaning->SetCleanJetsName("CleanJets");
        
  //------------------------------------------------------------------------------------------------
  // select events with photon+MET
  //------------------------------------------------------------------------------------------------
  MonoPhotonAnalysisMod         *phplusmet = new MonoPhotonAnalysisMod("MonoPhotonSelector");
  phplusmet->SetInputPhotonsName(photonCleaningMod->GetOutputName()); //identified photons
  phplusmet->SetInputElectronsName(electronCleaning->GetOutputName()); //identified electrons
  phplusmet->SetInputMuonsName(muonIdMod->GetOutputName()); //muons
  phplusmet->SetPhotonsFromBranch(kFALSE);
  phplusmet->SetElectronsFromBranch(kFALSE);
  phplusmet->SetMuonsFromBranch(kFALSE);
  phplusmet->SetMinNumPhotons(1);
  phplusmet->SetMinNumLeptons(0);
  phplusmet->SetMinPhotonEt(100);
  phplusmet->SetMaxPhotonEta(2.4);
  phplusmet->SetMinMetEt(100);
  
  MonoPhotonAnalysisMod         *dilepton = new MonoPhotonAnalysisMod("MonoPhotonSelector_dilepton");
  dilepton->SetInputPhotonsName(photonCleaningMod->GetOutputName()); //identified photons
  dilepton->SetInputElectronsName(electronCleaning->GetOutputName()); //identified electrons
  dilepton->SetInputMuonsName(muonIdMod->GetOutputName()); //muons
  dilepton->SetPhotonsFromBranch(kFALSE);
  dilepton->SetElectronsFromBranch(kFALSE);
  dilepton->SetMuonsFromBranch(kFALSE);
  dilepton->SetMinNumPhotons(1);
  dilepton->SetMinNumLeptons(2);
  dilepton->SetMinPhotonEt(0);
  dilepton->SetMaxPhotonEta(2.4);
  dilepton->SetMinMetEt(0);

  MonoPhotonAnalysisMod         *phfake = new MonoPhotonAnalysisMod("MonoPhotonSelector_phfake");
  phfake->SetInputPhotonsName(photreg->GetOutputName()); //all photons
  phfake->SetInputElectronsName(electronCleaning->GetOutputName()); //identified electrons
  phfake->SetInputMuonsName(muonIdMod->GetOutputName()); //muons
  phfake->SetPhotonsFromBranch(kFALSE);
  phfake->SetElectronsFromBranch(kFALSE);
  phfake->SetMuonsFromBranch(kFALSE);
  phfake->SetMinNumPhotons(1);
  phfake->SetMinNumLeptons(0);
  phfake->SetMinPhotonEt(100);
  phfake->SetMaxPhotonEta(2.4);
  phfake->SetMinMetEt(0);

  MonoPhotonAnalysisMod         *beamhalo = new MonoPhotonAnalysisMod("MonoPhotonSelector_beamhalo");
  beamhalo->SetInputPhotonsName(photreg->GetOutputName()); //all photons
  beamhalo->SetInputElectronsName(electronCleaning->GetOutputName()); //identified electrons
  beamhalo->SetInputMuonsName(muonIdMod->GetOutputName()); //muons
  beamhalo->SetPhotonsFromBranch(kFALSE);
  beamhalo->SetElectronsFromBranch(kFALSE);
  beamhalo->SetMuonsFromBranch(kFALSE);
  beamhalo->SetMinNumPhotons(1);
  beamhalo->SetMinNumLeptons(0);
  beamhalo->SetMinPhotonEt(100);
  beamhalo->SetMaxPhotonEta(2.4);
  beamhalo->SetMinMetEt(100);

  MonoPhotonTreeWriter *phplusmettree = new MonoPhotonTreeWriter("MonoPhotonTreeWriter");
  phplusmettree->SetPhotonsFromBranch(kFALSE);
  phplusmettree->SetPhotonsName(photonCleaningMod->GetOutputName());
  phplusmettree->SetElectronsFromBranch(kFALSE);
  phplusmettree->SetElectronsName(electronCleaning->GetOutputName());
  phplusmettree->SetMuonsFromBranch(kFALSE);
  phplusmettree->SetMuonsName(muonIdMod->GetOutputName());
  phplusmettree->SetJetsFromBranch(kFALSE);
  phplusmettree->SetJetsName(theJetCleaning->GetOutputName());
  phplusmettree->SetCosmicsFromBranch(kTRUE);
  phplusmettree->SetPVFromBranch(kFALSE);
  phplusmettree->SetPVName(goodPVFilterMod->GetOutputName());
  phplusmettree->SetLeptonsName(merger->GetOutputName());
  phplusmettree->SetHltObjsName(hltModP->GetOutputName());
  phplusmettree->SetIsData(isData);
  phplusmettree->SetProcessID(0);
  phplusmettree->SetFillNtupleType(0);
  
  MonoPhotonTreeWriter *dileptontree = new MonoPhotonTreeWriter("MonoPhotonTreeWriter_dilepton");
  dileptontree->SetPhotonsFromBranch(kFALSE);
  dileptontree->SetPhotonsName(photonCleaningMod->GetOutputName());
  dileptontree->SetElectronsFromBranch(kFALSE);
  dileptontree->SetElectronsName(electronCleaning->GetOutputName());
  dileptontree->SetMuonsFromBranch(kFALSE);
  dileptontree->SetMuonsName(muonIdMod->GetOutputName());
  dileptontree->SetJetsFromBranch(kFALSE);
  dileptontree->SetJetsName(theJetCleaning->GetOutputName());
  dileptontree->SetCosmicsFromBranch(kTRUE);
  dileptontree->SetPVFromBranch(kFALSE);
  dileptontree->SetPVName(goodPVFilterMod->GetOutputName());
  dileptontree->SetLeptonsName(merger->GetOutputName());
  dileptontree->SetHltObjsName(hltModP->GetOutputName());
  dileptontree->SetIsData(isData);
  dileptontree->SetProcessID(0);
  dileptontree->SetFillNtupleType(1);//dilepton

  MonoPhotonTreeWriter *phfaketree = new MonoPhotonTreeWriter("MonoPhotonTreeWriter_phfake");
  phfaketree->SetPhotonsFromBranch(kFALSE);
  phfaketree->SetPhotonsName(photreg->GetOutputName());
  phfaketree->SetElectronsFromBranch(kFALSE);
  phfaketree->SetElectronsName(electronCleaning->GetOutputName());
  phfaketree->SetMuonsFromBranch(kFALSE);
  phfaketree->SetMuonsName(muonIdMod->GetOutputName());
  phfaketree->SetJetsFromBranch(kFALSE);
  phfaketree->SetJetsName(theJetCleaning->GetOutputName());
  phfaketree->SetCosmicsFromBranch(kTRUE);
  phfaketree->SetPVFromBranch(kFALSE);
  phfaketree->SetPVName(goodPVFilterMod->GetOutputName());
  phfaketree->SetLeptonsName(merger->GetOutputName());
  phfaketree->SetHltObjsName(hltModP->GetOutputName());
  phfaketree->SetIsData(isData);
  phfaketree->SetProcessID(0);
  phfaketree->SetFillNtupleType(2);//phfake;

  MonoPhotonTreeWriter *beamhalotree = new MonoPhotonTreeWriter("MonoPhotonTreeWriter_beamhalo");
  beamhalotree->SetPhotonsFromBranch(kFALSE);
  beamhalotree->SetPhotonsName(photreg->GetOutputName());
  beamhalotree->SetElectronsFromBranch(kFALSE);
  beamhalotree->SetElectronsName(electronCleaning->GetOutputName());
  beamhalotree->SetMuonsFromBranch(kFALSE);
  beamhalotree->SetMuonsName(muonIdMod->GetOutputName());
  beamhalotree->SetJetsFromBranch(kFALSE);
  beamhalotree->SetJetsName(theJetCleaning->GetOutputName());
  beamhalotree->SetCosmicsFromBranch(kTRUE);
  beamhalotree->SetPVFromBranch(kFALSE);
  beamhalotree->SetPVName(goodPVFilterMod->GetOutputName());
  beamhalotree->SetLeptonsName(merger->GetOutputName());
  beamhalotree->SetHltObjsName(hltModP->GetOutputName());
  beamhalotree->SetIsData(isData);
  beamhalotree->SetProcessID(0);
  beamhalotree->SetFillNtupleType(3);//beamhalo

  //------------------------------------------------------------------------------------------------
  // making analysis chain
  //------------------------------------------------------------------------------------------------
  // this is how it always starts
  runLumiSel      ->Add(mcselmod);
 
  mcselmod->Add(generatorMod);
  generatorMod->Add(goodPVFilterMod);
  goodPVFilterMod->Add(hltModP);
  // photon regression
  hltModP->Add(photreg);
  // simple object id modules
  photreg          ->Add(SepPUMod); 
  SepPUMod         ->Add(muonIdMod);
  muonIdMod        ->Add(cosmicCleaning);
  cosmicCleaning   ->Add(eleIdMod);
  eleIdMod         ->Add(electronCleaning);
  electronCleaning ->Add(merger);
  merger           ->Add(photonIDMod);
  photonIDMod      ->Add(photonCleaningMod);
  photonCleaningMod->Add(pubJet);
  pubJet           ->Add(jetCorr);
  jetCorr          ->Add(theJetID);
  theJetID         ->Add(theJetCleaning);
   
  // Gamma+met selection
  //theJetCleaning   ->Add(phplusmet);
  //phplusmet        ->Add(phplusmettree);
  theJetCleaning   ->Add(phplusmettree);
  
  // Dilepton selection
  theJetCleaning   ->Add(dilepton);
  dilepton         ->Add(dileptontree);

  // Fake photon selection
  theJetCleaning   ->Add(phfake);
  phfake           ->Add(phfaketree);

  // Beam Halo selection
  theJetCleaning   ->Add(beamhalo);
  beamhalo         ->Add(beamhalotree);

  //------------------------------------------------------------------------------------------------
  // setup analysis
  //------------------------------------------------------------------------------------------------
  Analysis *ana = new Analysis;
  ana->SetUseHLT(kTRUE);
  ana->SetKeepHierarchy(kFALSE);
  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);
  else 
    d = c->FindDataset(bookstr,skimdataset.Data(),fileset,true);
  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");
  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;
}
Exemplo n.º 5
0
//--------------------------------------------------------------------------------------------------
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 runHgg2012HCP(const char *fileset    = "0000",
		   const char *skim       = "noskim",
		   //const char *dataset = "f11--h120gg-gf-v14b-pu",
		   //const char *dataset = "r11a-pho-j16-v1",   
		   //const char *dataset = "meridiani2012-diphoj-v9",
		   //const char *dataset = "s12-h125gg-gf-v9",
		   //const char *dataset = "s12-pj40-2em-v9",
		   //const char *dataset = "s12-diphoj-3-v9",
		   //const char *dataset = "s12-zllm50-v9",
		   //const char *dataset = "f11--h121gg-gf-v14b-pu",
		   //const char *dataset = "r12a-pho-pr-v1",
		   //const char *dataset = "s12-pj40-2em-v9",
		   //const char *dataset = "s12-h125gg-vbf-v7a", 
		   const char *dataset = "s12-h125gg-vh-v7a", 
		   //const char *dataset = "s12-h125gg-gf-v7a", 
		   //const char *dataset = "r12a-pho-j13-v1", 
		   //const char *dataset = "r12b-dph-j13-v1", 
		   const char *book       = "t2mit/filefi/029",
		   const char *catalogDir = "/home/cmsprod/catalog",
		   const char *outputName = "hgg",
		   int         nEvents    = 1000)
{
  //------------------------------------------------------------------------------------------------
  // 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/fabstoec/cms/json/") + TString(json);
  //TString jsonFile = TString("/home/fabstoec/cms/json/") + TString("Cert_136033-149442_7TeV_Dec22ReReco_Collisions10_JSON_v4.txt");
  Bool_t  isData   = ( (jsonFile.CompareTo("/home/fabstoec/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/fabstoec/cms/json/~") != 0) &&
      (jsonFile.CompareTo("/home/fabstoec/cms/json/-") != 0)   ) {
    runLumiSel->AddJSONFile(jsonFile.Data());
  }
  if ((jsonFile.CompareTo("/home/fabstoec/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_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,189999);
  hltModE->AddTrigger("HLT_Ele17_CaloIdT_CaloIsoVL_TrkIdVL_TrkIsoVL_Ele8_CaloIdT_CaloIsoVL_TrkIdVL_TrkIsoVL_v*",190000,999999);
  hltModE->SetTrigObjsName("MyHltElecObjs");
  hltModE->SetAbortIfNotAccepted(isData);

  HLTMod *hltModES = new HLTMod("HLTModES");
  hltModES->AddTrigger("HLT_Ele27_CaloIdVT_CaloIsoT_TrkIdT_TrkIsoT_v*",160000,189999);
  hltModES->AddTrigger("HLT_Ele27_CaloIdVT_CaloIsoT_TrkIdT_TrkIsoT_v2",160000,189999);
  hltModES->AddTrigger("HLT_Ele27_CaloIdVT_CaloIsoT_TrkIdT_TrkIsoT_v3",160000,189999);
  hltModES->AddTrigger("HLT_Ele25_WP80_PFMT40_v*",160000,189999);
  hltModES->AddTrigger("HLT_Ele27_WP80_PFMT50_v*",160000,189999);
  hltModES->AddTrigger("HLT_Ele27_WP80_v*",190000,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,189999);
  hltModP->AddTrigger("HLT_Photon26_CaloIdXL_IsoXL_Photon18_R9IdT_Mass60_v*",178420,189999);
  hltModP->AddTrigger("HLT_Photon26_R9IdT_Photon18_CaloIdXL_IsoXL_Mass60_v*",178420,189999);
  hltModP->AddTrigger("HLT_Photon26_R9IdT_Photon18_R9IdT_Mass60_v*",178420,189999);
  hltModP->AddTrigger("HLT_Photon36_CaloIdL_IsoVL_Photon22_CaloIdL_IsoVL_v*",178420,189999);
  hltModP->AddTrigger("HLT_Photon36_CaloIdL_IsoVL_Photon22_R9Id_v*",178420,189999);
  hltModP->AddTrigger("HLT_Photon36_R9Id_Photon22_CaloIdL_IsoVL_v*",178420,189999);
  hltModP->AddTrigger("HLT_Photon36_R9Id_Photon22_R9Id_v*",178420,189999);

  hltModP->AddTrigger("HLT_Photon26_CaloId10_Iso50_Photon18_CaloId10_Iso50_Mass60_v*",190000,999999); 
  hltModP->AddTrigger("HLT_Photon26_CaloId10_Iso50_Photon18_R9Id85_Mass60_v*",190000,999999); 
  hltModP->AddTrigger("HLT_Photon26_R9Id85_OR_CaloId10_Iso50_Photon18_R9Id85_OR_CaloId10_Iso50_Mass60_v*",190000,999999); 
  hltModP->AddTrigger("HLT_Photon26_R9Id85_OR_CaloId10_Iso50_Photon18_R9Id85_OR_CaloId10_Iso50_Mass70_v*",190000,999999); 
  hltModP->AddTrigger("HLT_Photon26_R9Id85_Photon18_CaloId10_Iso50_Mass60_v*",190000,999999); 
  hltModP->AddTrigger("HLT_Photon26_R9Id85_Photon18_R9Id85_Mass60_v*",190000,999999); 
  hltModP->AddTrigger("HLT_Photon36_CaloId10_Iso50_Photon22_CaloId10_Iso50_v*",190000,999999); 
  hltModP->AddTrigger("HLT_Photon36_CaloId10_Iso50_Photon22_R9Id85_v*",190000,999999); 
  hltModP->AddTrigger("HLT_Photon36_R9Id85_OR_CaloId10_Iso50_Photon22_R9Id85_OR_CaloId10_Iso50_v*",190000,999999); 
  hltModP->AddTrigger("HLT_Photon36_R9Id85_Photon22_CaloId10_Iso50_v*",190000,999999); 
  hltModP->AddTrigger("HLT_Photon36_R9Id85_Photon22_R9Id85_v*",190000,999999); 
    
  hltModP->SetTrigObjsName("MyHltPhotObjs");
  hltModP->SetAbortIfNotAccepted(isData);
  //------------------------------------------------------------------------------------------------
  // 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->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
  //------------------------------------------------------------------------------------------------
  //-----------------------------------
  // Lepton Selection 
  //-----------------------------------
  ElectronIDMod* eleIdMod = new ElectronIDMod;
  eleIdMod -> SetPtMin(20);  
  eleIdMod -> SetEtaMax(2.5);
  eleIdMod -> SetApplyEcalFiducial(true);
  eleIdMod -> SetIDType("Hgg_LeptonTag_2012IdHCP");  
  eleIdMod -> SetElectronMVAWeightsSubdet0Pt10To20(TString((getenv("CMSSW_BASE")+string("/src/MitPhysics/data/ElectronMVAWeights/Electrons_BDTG_NonTrigV0_Cat1.weights.xml"))));
  eleIdMod -> SetElectronMVAWeightsSubdet1Pt10To20(TString((getenv("CMSSW_BASE")+string("/src/MitPhysics/data/ElectronMVAWeights/Electrons_BDTG_NonTrigV0_Cat2.weights.xml"))));  
  eleIdMod -> SetElectronMVAWeightsSubdet2Pt10To20(TString((getenv("CMSSW_BASE")+string("/src/MitPhysics/data/ElectronMVAWeights/Electrons_BDTG_NonTrigV0_Cat3.weights.xml"))));  
  eleIdMod -> SetElectronMVAWeightsSubdet0Pt20ToInf(TString((getenv("CMSSW_BASE")+string("/src/MitPhysics/data/ElectronMVAWeights/Electrons_BDTG_NonTrigV0_Cat4.weights.xml")))); 
  eleIdMod -> SetElectronMVAWeightsSubdet1Pt20ToInf(TString((getenv("CMSSW_BASE")+string("/src/MitPhysics/data/ElectronMVAWeights/Electrons_BDTG_NonTrigV0_Cat5.weights.xml")))); 
  eleIdMod -> SetElectronMVAWeightsSubdet2Pt20ToInf(TString((getenv("CMSSW_BASE")+string("/src/MitPhysics/data/ElectronMVAWeights/Electrons_BDTG_NonTrigV0_Cat6.weights.xml")))); 
  eleIdMod -> SetWhichVertex(-1);
  eleIdMod -> SetD0Cut(0.02);
  eleIdMod -> SetDZCut(0.2); //h  
  eleIdMod -> SetIsoType("PFIso_HggLeptonTag2012HCP"); //h
  eleIdMod -> SetOutputName("HggLeptonTagElectrons");
  eleIdMod -> SetRhoType(RhoUtilities::CMS_RHO_RHOKT6PFJETS);
  eleIdMod -> SetPFNoPileUpName("pfnopileupcands");
  eleIdMod -> SetInvertNExpectedHitsInnerCut(kFALSE);
  eleIdMod -> SetNExpectedHitsInnerCut(1);   
  eleIdMod -> SetApplyConversionFilterType1(kTRUE);
  
  MuonIDMod* muonIdMod = new MuonIDMod;
  // base kinematics
  muonIdMod -> SetPtMin(20.);
  muonIdMod -> SetEtaCut(2.4);
  // base ID
  muonIdMod -> SetIDType("Tight");
  muonIdMod -> SetWhichVertex(-1); // this is a 'hack'.. but hopefully good enough...
  muonIdMod -> SetD0Cut(0.2);
  muonIdMod -> SetDZCut(0.5);
  muonIdMod -> SetIsoType("PFIsoBetaPUCorrected"); //h
  muonIdMod -> SetPFIsoCut(0.2); //h
  muonIdMod -> SetOutputName("HggLeptonTagMuons");
  muonIdMod -> SetPFNoPileUpName("pfnopileupcands");
  muonIdMod -> SetPFPileUpName("pfpileupcands");
  
  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;
  if(isData){ 
    jetCorr->AddCorrectionFromFile(std::string((gSystem->Getenv("CMSSW_BASE") + TString("/src/MitPhysics/data/Summer12_V7_DATA_L1FastJet_AK5PF.txt")).Data())); 
    jetCorr->AddCorrectionFromFile(std::string((gSystem->Getenv("CMSSW_BASE") + TString("/src/MitPhysics/data/Summer12_V7_DATA_L2Relative_AK5PF.txt")).Data())); 
    jetCorr->AddCorrectionFromFile(std::string((gSystem->Getenv("CMSSW_BASE") + TString("/src/MitPhysics/data/Summer12_V7_DATA_L3Absolute_AK5PF.txt")).Data())); 
    jetCorr->AddCorrectionFromFile(std::string((gSystem->Getenv("CMSSW_BASE") + TString("/src/MitPhysics/data/Summer12_V7_DATA_L2L3Residual_AK5PF.txt")).Data())); 
  }
  else {
    jetCorr->AddCorrectionFromFile(std::string((gSystem->Getenv("CMSSW_BASE") + TString("/src/MitPhysics/data/Summer12_V7_MC_L1FastJet_AK5PF.txt")).Data())); 
    jetCorr->AddCorrectionFromFile(std::string((gSystem->Getenv("CMSSW_BASE") + TString("/src/MitPhysics/data/Summer12_V7_MC_L2Relative_AK5PF.txt")).Data())); 
    jetCorr->AddCorrectionFromFile(std::string((gSystem->Getenv("CMSSW_BASE") + TString("/src/MitPhysics/data/Summer12_V7_MC_L3Absolute_AK5PF.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;
  }
  
  Bool_t is25 = kFALSE;
  if (TString(book).Contains("025")) is25 = kTRUE;
  
  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->SetIsData(isData);

  
  PhotonPairSelector         *photcic = new PhotonPairSelector("PhotonPairSelectorCiC");
  photcic->SetOutputName("GoodPhotonsCIC");
  photcic->SetOutputVtxName("OutVtxCiC");        
  photcic->SetPhotonSelType("CiCPFSelection");
  photcic->SetVertexSelType("CiCMVA2012Selection");
  photcic->SetUseSingleLegConversions(kTRUE);
  photcic->DoMCSmear(kTRUE);
  photcic->DoDataEneCorr(kTRUE);
  photcic->SetPhotonsFromBranch(kFALSE);
  photcic->SetInputPhotonsName(photreg->GetOutputName());
  
  //------------------------------------------2012 HCP--------------------------------------------------------------
  photcic->SetMCSmearFactors2012HCP(0.0099,0.0098,0.0113,0.0094,0.0195,0.0198,0.0291,0.0275,0.0325,0.0356);
  //photcic->SetMCSmearFactors2012HCP(0.01,0.011,0.0106,0.0106,0.0186,0.0196,0.0283,0.0267,0.0343,0.0345);
  photcic->AddEnCorrPerRun2012HCP(190645,190781,0.9964,0.9964,1.0020,1.0020,0.9893,1.0028,0.9871,0.9937,0.9839,0.9958);
  photcic->AddEnCorrPerRun2012HCP(190782,191042,1.0024,1.0024,1.0079,1.0079,0.9923,1.0058,0.9911,0.9977,0.9886,1.0005);
  photcic->AddEnCorrPerRun2012HCP(191043,193555,0.9935,0.9935,0.9991,0.9991,0.9861,0.9997,0.9894,0.9960,0.9864,0.9982);
  photcic->AddEnCorrPerRun2012HCP(193556,194150,0.9920,0.9920,0.9976,0.9976,0.9814,0.9951,0.9896,0.9962,0.9872,0.9990);
  photcic->AddEnCorrPerRun2012HCP(194151,194532,0.9925,0.9925,0.9981,0.9981,0.9826,0.9963,0.9914,0.9980,0.9874,0.9993);
  photcic->AddEnCorrPerRun2012HCP(194533,195113,0.9927,0.9927,0.9983,0.9983,0.9844,0.9981,0.9934,0.9999,0.9878,0.9996);
  photcic->AddEnCorrPerRun2012HCP(195114,195915,0.9929,0.9929,0.9984,0.9984,0.9838,0.9974,0.9942,1.0007,0.9878,0.9997);
  photcic->AddEnCorrPerRun2012HCP(195916,198115,0.9919,0.9919,0.9975,0.9975,0.9827,0.9964,0.9952,1.0017,0.9869,0.9987);
  photcic->AddEnCorrPerRun2012HCP(198116,199803,0.9955,0.9955,1.0011,1.0011,0.9859,0.9995,0.9893,0.9959,0.9923,1.0041);
  photcic->AddEnCorrPerRun2012HCP(199804,200048,0.9967,0.9967,1.0023,1.0023,0.9870,1.0006,0.9893,0.9959,0.9937,1.0055);
  photcic->AddEnCorrPerRun2012HCP(200049,200151,0.9980,0.9980,1.0036,1.0036,0.9877,1.0012,0.9910,0.9976,0.9980,1.0097);
  photcic->AddEnCorrPerRun2012HCP(200152,200490,0.9958,0.9958,1.0013,1.0013,0.9868,1.0004,0.9922,0.9988,0.9948,1.0065);
  photcic->AddEnCorrPerRun2012HCP(200491,200531,0.9979,0.9979,1.0035,1.0035,0.9876,1.0012,0.9915,0.9981,0.9979,1.0096);
  photcic->AddEnCorrPerRun2012HCP(200532,201656,0.9961,0.9961,1.0017,1.0017,0.9860,0.9996,0.9904,0.9970,0.9945,1.0063);
  photcic->AddEnCorrPerRun2012HCP(201657,202305,0.9969,0.9969,1.0025,1.0025,0.9866,1.0002,0.9914,0.9980,0.9999,1.0116);
  photcic->AddEnCorrPerRun2012HCP(202305,203002,0.9982,0.9982,1.0038,1.0038,0.9872,1.0008,0.9934,1.0000,1.0018,1.0135);

  //-----------------------------------------------------------------------------------------------------------------
  
  //  photcic->SetDoMCR9Scaling(kTRUE);
  //  photcic->SetMCR9Scale(1.0035, 1.0035);
  photcic->SetDoShowerShapeScaling(kTRUE); 
  photcic->SetShowerShapeType("2012ShowerShape");
  //photcic->SetDoMCErrScaling(kTRUE);
  //photcic->SetMCErrScale(1.07, 1.045); 
  //photcic->SetMCErrScale(1, 1); //ming:scale(sigE/E)
  photcic->SetJetsName(jetCorr->GetOutputName());    
  //photcic->SetRescaledBeamspotWidth(5.0);
  photcic->SetIsData(isData);
  photcic->SetApplyLeptonTag(kTRUE);
  photcic->SetLeptonTagElectronsName("HggLeptonTagElectrons");
  photcic->SetLeptonTagMuonsName("HggLeptonTagMuons");  
  photcic->Set2012HCP(kTRUE);
  
  PhotonPairSelector         *photcicnoeleveto = new PhotonPairSelector("PhotonPairSelectorCiCInvertEleVeto");
  photcicnoeleveto->SetOutputName("GoodPhotonsCICNoEleVeto");
  photcicnoeleveto->SetOutputVtxName("OutVtxCiCInvertEleVeto");      
  photcicnoeleveto->SetPhotonSelType("CiCPFSelection");
  photcicnoeleveto->SetVertexSelType("CiCMVA2012Selection");
  photcicnoeleveto->SetUseSingleLegConversions(kTRUE);
  photcicnoeleveto->DoMCSmear(kTRUE);
  photcicnoeleveto->DoDataEneCorr(kTRUE);
  photcicnoeleveto->SetPhotonsFromBranch(kFALSE);
  photcicnoeleveto->SetInputPhotonsName(photreg->GetOutputName());
  
  //------------------------------------------2012 HCP--------------------------------------------------------------
  photcicnoeleveto->SetMCSmearFactors2012HCP(0.0099,0.0098,0.0113,0.0094,0.0195,0.0198,0.0291,0.0275,0.0325,0.0356);
  //photcicnoeleveto->SetMCSmearFactors2012HCP(0.01,0.011,0.0106,0.0106,0.0186,0.0196,0.0283,0.0267,0.0343,0.0345);
  photcicnoeleveto->AddEnCorrPerRun2012HCP(190645,190781,0.9964,0.9964,1.0020,1.0020,0.9893,1.0028,0.9871,0.9937,0.9839,0.9958);
  photcicnoeleveto->AddEnCorrPerRun2012HCP(190782,191042,1.0024,1.0024,1.0079,1.0079,0.9923,1.0058,0.9911,0.9977,0.9886,1.0005);
  photcicnoeleveto->AddEnCorrPerRun2012HCP(191043,193555,0.9935,0.9935,0.9991,0.9991,0.9861,0.9997,0.9894,0.9960,0.9864,0.9982);
  photcicnoeleveto->AddEnCorrPerRun2012HCP(193556,194150,0.9920,0.9920,0.9976,0.9976,0.9814,0.9951,0.9896,0.9962,0.9872,0.9990);
  photcicnoeleveto->AddEnCorrPerRun2012HCP(194151,194532,0.9925,0.9925,0.9981,0.9981,0.9826,0.9963,0.9914,0.9980,0.9874,0.9993);
  photcicnoeleveto->AddEnCorrPerRun2012HCP(194533,195113,0.9927,0.9927,0.9983,0.9983,0.9844,0.9981,0.9934,0.9999,0.9878,0.9996);
  photcicnoeleveto->AddEnCorrPerRun2012HCP(195114,195915,0.9929,0.9929,0.9984,0.9984,0.9838,0.9974,0.9942,1.0007,0.9878,0.9997);
  photcicnoeleveto->AddEnCorrPerRun2012HCP(195916,198115,0.9919,0.9919,0.9975,0.9975,0.9827,0.9964,0.9952,1.0017,0.9869,0.9987);
  photcicnoeleveto->AddEnCorrPerRun2012HCP(198116,199803,0.9955,0.9955,1.0011,1.0011,0.9859,0.9995,0.9893,0.9959,0.9923,1.0041);
  photcicnoeleveto->AddEnCorrPerRun2012HCP(199804,200048,0.9967,0.9967,1.0023,1.0023,0.9870,1.0006,0.9893,0.9959,0.9937,1.0055);
  photcicnoeleveto->AddEnCorrPerRun2012HCP(200049,200151,0.9980,0.9980,1.0036,1.0036,0.9877,1.0012,0.9910,0.9976,0.9980,1.0097);
  photcicnoeleveto->AddEnCorrPerRun2012HCP(200152,200490,0.9958,0.9958,1.0013,1.0013,0.9868,1.0004,0.9922,0.9988,0.9948,1.0065);
  photcicnoeleveto->AddEnCorrPerRun2012HCP(200491,200531,0.9979,0.9979,1.0035,1.0035,0.9876,1.0012,0.9915,0.9981,0.9979,1.0096);
  photcicnoeleveto->AddEnCorrPerRun2012HCP(200532,201656,0.9961,0.9961,1.0017,1.0017,0.9860,0.9996,0.9904,0.9970,0.9945,1.0063);
  photcicnoeleveto->AddEnCorrPerRun2012HCP(201657,202305,0.9969,0.9969,1.0025,1.0025,0.9866,1.0002,0.9914,0.9980,0.9999,1.0116);
  photcicnoeleveto->AddEnCorrPerRun2012HCP(202305,203002,0.9982,0.9982,1.0038,1.0038,0.9872,1.0008,0.9934,1.0000,1.0018,1.0135);
  
  //-----------------------------------------------------------------------------------------------------------------
  
  //photcicnoeleveto->SetDoMCR9Scaling(kTRUE);
  //photcicnoeleveto->SetMCR9Scale(1.0035, 1.0035);
  photcicnoeleveto->SetDoShowerShapeScaling(kTRUE);
  photcicnoeleveto->SetShowerShapeType("2012ShowerShape");
  //photcicnoeleveto->SetDoMCErrScaling(kTRUE);
  //photcicnoeleveto->SetMCErrScale(1.07, 1.045);    
  //photcicnoeleveto->SetMCErrScale(1, 1);    
  photcicnoeleveto->SetApplyEleVeto(kFALSE);
  photcicnoeleveto->SetInvertElectronVeto(kTRUE);
  photcicnoeleveto->SetJetsName(jetCorr->GetOutputName());  
  //photcicnoeleveto->SetRescaledBeamspotWidth(5.0);
  photcicnoeleveto->SetIsData(isData);
  photcicnoeleveto->SetApplyLeptonTag(kTRUE);
  photcicnoeleveto->SetLeptonTagElectronsName("HggLeptonTagElectrons");
  photcicnoeleveto->SetLeptonTagMuonsName("HggLeptonTagMuons");  
  photcicnoeleveto->Set2012HCP(kTRUE);  
  
  PhotonPairSelector         *photpresel = new PhotonPairSelector("PhotonPairSelectorPresel");
  photpresel->SetOutputName("GoodPhotonsPresel");
  photpresel->SetPhotonSelType("MITPFSelection");
  photpresel->SetVertexSelType("CiCMVA2012Selection");
  photpresel->SetUseSingleLegConversions(kTRUE);
  photpresel->SetIdMVAType("2012IdMVA_globe");
  photpresel->DoMCSmear(kTRUE);
  photpresel->DoDataEneCorr(kTRUE);
  photpresel->SetPhotonsFromBranch(kFALSE);
  photpresel->SetInputPhotonsName(photreg->GetOutputName());
  //------------------------------------------2012 HCP--------------------------------------------------------------
  photpresel->SetMCSmearFactors2012HCP(0.0099,0.0098,0.0113,0.0094,0.0195,0.0198,0.0291,0.0275,0.0325,0.0356);
  //photpresel->SetMCSmearFactors2012HCP(0.01,0.011,0.0106,0.0106,0.0186,0.0196,0.0283,0.0267,0.0343,0.0345);
  photpresel->AddEnCorrPerRun2012HCP(190645,190781,0.9964,0.9964,1.0020,1.0020,0.9893,1.0028,0.9871,0.9937,0.9839,0.9958);
  photpresel->AddEnCorrPerRun2012HCP(190782,191042,1.0024,1.0024,1.0079,1.0079,0.9923,1.0058,0.9911,0.9977,0.9886,1.0005);
  photpresel->AddEnCorrPerRun2012HCP(191043,193555,0.9935,0.9935,0.9991,0.9991,0.9861,0.9997,0.9894,0.9960,0.9864,0.9982);
  photpresel->AddEnCorrPerRun2012HCP(193556,194150,0.9920,0.9920,0.9976,0.9976,0.9814,0.9951,0.9896,0.9962,0.9872,0.9990);
  photpresel->AddEnCorrPerRun2012HCP(194151,194532,0.9925,0.9925,0.9981,0.9981,0.9826,0.9963,0.9914,0.9980,0.9874,0.9993);
  photpresel->AddEnCorrPerRun2012HCP(194533,195113,0.9927,0.9927,0.9983,0.9983,0.9844,0.9981,0.9934,0.9999,0.9878,0.9996);
  photpresel->AddEnCorrPerRun2012HCP(195114,195915,0.9929,0.9929,0.9984,0.9984,0.9838,0.9974,0.9942,1.0007,0.9878,0.9997);
  photpresel->AddEnCorrPerRun2012HCP(195916,198115,0.9919,0.9919,0.9975,0.9975,0.9827,0.9964,0.9952,1.0017,0.9869,0.9987);
  photpresel->AddEnCorrPerRun2012HCP(198116,199803,0.9955,0.9955,1.0011,1.0011,0.9859,0.9995,0.9893,0.9959,0.9923,1.0041);
  photpresel->AddEnCorrPerRun2012HCP(199804,200048,0.9967,0.9967,1.0023,1.0023,0.9870,1.0006,0.9893,0.9959,0.9937,1.0055);
  photpresel->AddEnCorrPerRun2012HCP(200049,200151,0.9980,0.9980,1.0036,1.0036,0.9877,1.0012,0.9910,0.9976,0.9980,1.0097);
  photpresel->AddEnCorrPerRun2012HCP(200152,200490,0.9958,0.9958,1.0013,1.0013,0.9868,1.0004,0.9922,0.9988,0.9948,1.0065);
  photpresel->AddEnCorrPerRun2012HCP(200491,200531,0.9979,0.9979,1.0035,1.0035,0.9876,1.0012,0.9915,0.9981,0.9979,1.0096);
  photpresel->AddEnCorrPerRun2012HCP(200532,201656,0.9961,0.9961,1.0017,1.0017,0.9860,0.9996,0.9904,0.9970,0.9945,1.0063);
  photpresel->AddEnCorrPerRun2012HCP(201657,202305,0.9969,0.9969,1.0025,1.0025,0.9866,1.0002,0.9914,0.9980,0.9999,1.0116);
  photpresel->AddEnCorrPerRun2012HCP(202305,203002,0.9982,0.9982,1.0038,1.0038,0.9872,1.0008,0.9934,1.0000,1.0018,1.0135);
  //-----------------------------------------------------------------------------------------------------------------
  //photpresel->SetDoMCR9Scaling(kTRUE);
  photpresel->SetDoShowerShapeScaling(kTRUE);
  photpresel->SetShowerShapeType("2012ShowerShape");
  //photpresel->SetDoMCErrScaling(kTRUE);
  //photpresel->SetMCErrScale(1.07, 1.045); 
  //photpresel->SetMCErrScale(1, 1); 
  photpresel->SetJetsName(jetCorr->GetOutputName()); 
  //photpresel->SetRescaledBeamspotWidth(5.0);
  photpresel->SetIsData(isData);
  photpresel->SetApplyLeptonTag(kTRUE);
  photpresel->SetLeptonTagElectronsName("HggLeptonTagElectrons");
  photpresel->SetLeptonTagMuonsName("HggLeptonTagMuons");  
  photpresel->Set2012HCP(kTRUE); 

  PhotonPairSelector         *photpreselinverteleveto = new PhotonPairSelector("PhotonPairSelectorPreselInvertEleVeto");
  photpreselinverteleveto->SetOutputName("GoodPhotonsPreselInvertEleVeto");
  photpreselinverteleveto->SetOutputVtxName("OutVtxPreselInvertEleVeto");    
  photpreselinverteleveto->SetPhotonSelType("MITPFSelection");
  photpreselinverteleveto->SetIdMVAType("2012IdMVA_globe");
  photpreselinverteleveto->SetVertexSelType("CiCMVA2012Selection");
  photpreselinverteleveto->SetUseSingleLegConversions(kTRUE);
  photpreselinverteleveto->DoMCSmear(kTRUE);
  photpreselinverteleveto->DoDataEneCorr(kTRUE);
  photpreselinverteleveto->SetPhotonsFromBranch(kFALSE);
  photpreselinverteleveto->SetInputPhotonsName(photreg->GetOutputName());
  //------------------------------------------2012 HCP--------------------------------------------------------------
  photpreselinverteleveto->SetMCSmearFactors2012HCP(0.0099,0.0098,0.0113,0.0094,0.0195,0.0198,0.0291,0.0275,0.0325,0.0356);
  //photpreselinverteleveto->SetMCSmearFactors2012HCP(0.01,0.011,0.0106,0.0106,0.0186,0.0196,0.0283,0.0267,0.0343,0.0345);
  photpreselinverteleveto->AddEnCorrPerRun2012HCP(190645,190781,0.9964,0.9964,1.0020,1.0020,0.9893,1.0028,0.9871,0.9937,0.9839,0.9958);
  photpreselinverteleveto->AddEnCorrPerRun2012HCP(190782,191042,1.0024,1.0024,1.0079,1.0079,0.9923,1.0058,0.9911,0.9977,0.9886,1.0005);
  photpreselinverteleveto->AddEnCorrPerRun2012HCP(191043,193555,0.9935,0.9935,0.9991,0.9991,0.9861,0.9997,0.9894,0.9960,0.9864,0.9982);
  photpreselinverteleveto->AddEnCorrPerRun2012HCP(193556,194150,0.9920,0.9920,0.9976,0.9976,0.9814,0.9951,0.9896,0.9962,0.9872,0.9990);
  photpreselinverteleveto->AddEnCorrPerRun2012HCP(194151,194532,0.9925,0.9925,0.9981,0.9981,0.9826,0.9963,0.9914,0.9980,0.9874,0.9993);
  photpreselinverteleveto->AddEnCorrPerRun2012HCP(194533,195113,0.9927,0.9927,0.9983,0.9983,0.9844,0.9981,0.9934,0.9999,0.9878,0.9996);
  photpreselinverteleveto->AddEnCorrPerRun2012HCP(195114,195915,0.9929,0.9929,0.9984,0.9984,0.9838,0.9974,0.9942,1.0007,0.9878,0.9997);
  photpreselinverteleveto->AddEnCorrPerRun2012HCP(195916,198115,0.9919,0.9919,0.9975,0.9975,0.9827,0.9964,0.9952,1.0017,0.9869,0.9987);
  photpreselinverteleveto->AddEnCorrPerRun2012HCP(198116,199803,0.9955,0.9955,1.0011,1.0011,0.9859,0.9995,0.9893,0.9959,0.9923,1.0041);
  photpreselinverteleveto->AddEnCorrPerRun2012HCP(199804,200048,0.9967,0.9967,1.0023,1.0023,0.9870,1.0006,0.9893,0.9959,0.9937,1.0055);
  photpreselinverteleveto->AddEnCorrPerRun2012HCP(200049,200151,0.9980,0.9980,1.0036,1.0036,0.9877,1.0012,0.9910,0.9976,0.9980,1.0097);
  photpreselinverteleveto->AddEnCorrPerRun2012HCP(200152,200490,0.9958,0.9958,1.0013,1.0013,0.9868,1.0004,0.9922,0.9988,0.9948,1.0065);
  photpreselinverteleveto->AddEnCorrPerRun2012HCP(200491,200531,0.9979,0.9979,1.0035,1.0035,0.9876,1.0012,0.9915,0.9981,0.9979,1.0096);
  photpreselinverteleveto->AddEnCorrPerRun2012HCP(200532,201656,0.9961,0.9961,1.0017,1.0017,0.9860,0.9996,0.9904,0.9970,0.9945,1.0063);
  photpreselinverteleveto->AddEnCorrPerRun2012HCP(201657,202305,0.9969,0.9969,1.0025,1.0025,0.9866,1.0002,0.9914,0.9980,0.9999,1.0116);
  photpreselinverteleveto->AddEnCorrPerRun2012HCP(202305,203002,0.9982,0.9982,1.0038,1.0038,0.9872,1.0008,0.9934,1.0000,1.0018,1.0135);
  //-----------------------------------------------------------------------------------------------------------------
  photpreselinverteleveto->SetShowerShapeType("2012ShowerShape");
  photpreselinverteleveto->SetDoShowerShapeScaling(kTRUE);  
  //photpreselinverteleveto->SetDoMCErrScaling(kTRUE);
  //photpreselinverteleveto->SetMCErrScale(1.07, 1.045);  
  //photpreselinverteleveto->SetMCErrScale(1, 1);  
  photpreselinverteleveto->SetApplyEleVeto(kFALSE);
  photpreselinverteleveto->SetInvertElectronVeto(kTRUE);
  photpreselinverteleveto->SetJetsName(jetCorr->GetOutputName());  
  //photpreselinverteleveto->SetRescaledBeamspotWidth(5.0);   
  photpreselinverteleveto->SetIsData(isData);
  photpreselinverteleveto->SetApplyLeptonTag(kTRUE);
  photpreselinverteleveto->SetLeptonTagElectronsName("HggLeptonTagElectrons");
  photpreselinverteleveto->SetLeptonTagMuonsName("HggLeptonTagMuons");    
  photpreselinverteleveto->Set2012HCP(kTRUE);  
  

   PhotonPairSelector         *photpreselnosmear = new PhotonPairSelector("PhotonPairSelectorPreselNoSmear");
   photpreselnosmear->SetOutputName("GoodPhotonsPreselNoSmear");
   photpreselnosmear->SetPhotonSelType("MITPFSelection");
   photpreselnosmear->SetVertexSelType("CiCMVA2012Selection");
   photpreselnosmear->SetUseSingleLegConversions(kTRUE);  
   photpreselnosmear->SetIdMVAType("2012IdMVA_globe");
   photpreselnosmear->SetShowerShapeType("2012ShowerShape");
   photpreselnosmear->SetDoShowerShapeScaling(kTRUE);  
   photpreselnosmear->SetPhotonsFromBranch(kFALSE);
   photpreselnosmear->SetInputPhotonsName(photreg->GetOutputName());
   photpreselnosmear->SetJetsName(jetCorr->GetOutputName());  
   photpreselnosmear->SetOutputVtxName("OutVtxNoSmear");  
   photpreselnosmear->SetLeadingPtMin(30.);
   photpreselnosmear->SetTrailingPtMin(22.);
   //photpreselnosmear->SetRescaledBeamspotWidth(5.0);      
   photpreselnosmear->SetIsData(isData);  
   photpreselnosmear->SetApplyLeptonTag(kTRUE);
   photpreselnosmear->SetLeptonTagElectronsName("HggLeptonTagElectrons");
   photpreselnosmear->SetLeptonTagMuonsName("HggLeptonTagMuons");
   photpreselnosmear->Set2012HCP(kTRUE); 
   photpreselnosmear->DoMCSmear(kFALSE);
   photpreselnosmear->DoDataEneCorr(kFALSE);
   
   PhotonTreeWriter *phottreecic = new PhotonTreeWriter("PhotonTreeWriterCiC");
   phottreecic->SetPhotonsFromBranch(kFALSE);
   phottreecic->SetInputPhotonsName(photcic->GetOutputName());
   phottreecic->SetEnableJets(kTRUE);
   phottreecic->SetApplyJetId(kTRUE);
   phottreecic->SetPFJetsFromBranch(kFALSE);
   phottreecic->SetPFJetName(jetCorr->GetOutputName());
   phottreecic->SetExcludeDoublePrompt(excludedoubleprompt);
   phottreecic->SetIsData(isData);
   if (is25) phottreecic->SetEnablePFPhotons(kFALSE);
   phottreecic->SetApplyLeptonTag(kTRUE);
   phottreecic->SetLeptonTagElectronsName("HggLeptonTagElectrons");
   phottreecic->SetLeptonTagMuonsName("HggLeptonTagMuons");
   phottreecic->SetApplyVBFTag(kTRUE);
   phottreecic->SetApplyPFMetCorr(kTRUE);
   phottreecic->SetBeamspotWidth(5.0);
   
   PhotonTreeWriter *phottreecicnoeleveto = new PhotonTreeWriter("PhotonTreeWriterCiCInvertEleVeto");
   phottreecicnoeleveto->SetPhotonsFromBranch(kFALSE);
   phottreecicnoeleveto->SetInputPhotonsName(photcicnoeleveto->GetOutputName());
   phottreecicnoeleveto->SetEnableJets(kTRUE);
   phottreecicnoeleveto->SetApplyJetId(kTRUE);  
   phottreecicnoeleveto->SetPFJetsFromBranch(kFALSE);
   phottreecicnoeleveto->SetPFJetName(jetCorr->GetOutputName());
   phottreecicnoeleveto->SetApplyElectronVeto(kFALSE);
   phottreecicnoeleveto->SetExcludeDoublePrompt(excludedoubleprompt);
   phottreecicnoeleveto->SetIsData(isData);  
   if (is25) phottreecicnoeleveto->SetEnablePFPhotons(kFALSE);
   phottreecicnoeleveto->SetApplyLeptonTag(kTRUE);
   phottreecicnoeleveto->SetLeptonTagElectronsName("HggLeptonTagElectrons");
   phottreecicnoeleveto->SetLeptonTagMuonsName("HggLeptonTagMuons");
   phottreecicnoeleveto->SetApplyVBFTag(kTRUE);
   phottreecicnoeleveto->SetApplyPFMetCorr(kTRUE);
   phottreecicnoeleveto->SetBeamspotWidth(5.0);
   
   PhotonTreeWriter *phottreepresel = new PhotonTreeWriter("PhotonTreeWriterPresel");
   phottreepresel->SetPhotonsFromBranch(kFALSE);
   phottreepresel->SetInputPhotonsName(photpresel->GetOutputName());
   phottreepresel->SetEnableJets(kTRUE);
   phottreepresel->SetApplyJetId(kTRUE);    
   phottreepresel->SetPFJetsFromBranch(kFALSE);
   phottreepresel->SetPFJetName(jetCorr->GetOutputName());  
   phottreepresel->SetExcludeDoublePrompt(excludedoubleprompt);  
   phottreepresel->SetIsData(isData);  
   if (is25) phottreepresel->SetEnablePFPhotons(kFALSE);
   phottreepresel->SetApplyLeptonTag(kTRUE);
   phottreepresel->SetLeptonTagElectronsName("HggLeptonTagElectrons");
   phottreepresel->SetLeptonTagMuonsName("HggLeptonTagMuons");
   phottreepresel->SetApplyVBFTag(kTRUE);
   phottreepresel->SetApplyPFMetCorr(kTRUE);
   phottreepresel->SetBeamspotWidth(5.0);
   
  phottreepresel -> SetElectronMVAWeightsSubdet0Pt10To20(TString((getenv("CMSSW_BASE")+string("/src/MitPhysics/data/ElectronMVAWeights/Electrons_BDTG_NonTrigV0_Cat1.weights.xml"))));
  phottreepresel -> SetElectronMVAWeightsSubdet1Pt10To20(TString((getenv("CMSSW_BASE")+string("/src/MitPhysics/data/ElectronMVAWeights/Electrons_BDTG_NonTrigV0_Cat2.weights.xml"))));  
  phottreepresel -> SetElectronMVAWeightsSubdet2Pt10To20(TString((getenv("CMSSW_BASE")+string("/src/MitPhysics/data/ElectronMVAWeights/Electrons_BDTG_NonTrigV0_Cat3.weights.xml"))));  
  phottreepresel -> SetElectronMVAWeightsSubdet0Pt20ToInf(TString((getenv("CMSSW_BASE")+string("/src/MitPhysics/data/ElectronMVAWeights/Electrons_BDTG_NonTrigV0_Cat4.weights.xml")))); 
  phottreepresel -> SetElectronMVAWeightsSubdet1Pt20ToInf(TString((getenv("CMSSW_BASE")+string("/src/MitPhysics/data/ElectronMVAWeights/Electrons_BDTG_NonTrigV0_Cat5.weights.xml")))); 
  phottreepresel -> SetElectronMVAWeightsSubdet2Pt20ToInf(TString((getenv("CMSSW_BASE")+string("/src/MitPhysics/data/ElectronMVAWeights/Electrons_BDTG_NonTrigV0_Cat6.weights.xml")))); 



   PhotonTreeWriter *phottreepreselinverteleveto = new PhotonTreeWriter("PhotonTreeWriterPreselInvertEleVeto");
   phottreepreselinverteleveto->SetPhotonsFromBranch(kFALSE);
   phottreepreselinverteleveto->SetInputPhotonsName(photpreselinverteleveto->GetOutputName());
   phottreepreselinverteleveto->SetEnableJets(kTRUE);
   phottreepreselinverteleveto->SetApplyJetId(kTRUE);    
   phottreepreselinverteleveto->SetPFJetsFromBranch(kFALSE);
   phottreepreselinverteleveto->SetPFJetName(jetCorr->GetOutputName());  
   phottreepreselinverteleveto->SetApplyElectronVeto(kFALSE);  
   phottreepreselinverteleveto->SetExcludeDoublePrompt(excludedoubleprompt);    
   phottreepreselinverteleveto->SetIsData(isData); 
   if (is25) phottreepreselinverteleveto->SetEnablePFPhotons(kFALSE);  
   phottreepreselinverteleveto->SetApplyLeptonTag(kTRUE);
   phottreepreselinverteleveto->SetLeptonTagElectronsName("HggLeptonTagElectrons");
   phottreepreselinverteleveto->SetLeptonTagMuonsName("HggLeptonTagMuons");
   phottreepreselinverteleveto->SetApplyVBFTag(kTRUE);
   phottreepreselinverteleveto->SetApplyPFMetCorr(kTRUE);
   phottreepreselinverteleveto->SetBeamspotWidth(5.0);
  
   PhotonTreeWriter *phottreepreselnosmear = new PhotonTreeWriter("PhotonTreeWriterPreselNoSmear");
   phottreepreselnosmear->SetPhotonsFromBranch(kFALSE);
   phottreepreselnosmear->SetInputPhotonsName(photpreselnosmear->GetOutputName());
   phottreepreselnosmear->SetEnableJets(kTRUE);
   phottreepreselnosmear->SetApplyJetId(kTRUE);  
   phottreepreselnosmear->SetPFJetsFromBranch(kFALSE);
   phottreepreselnosmear->SetPFJetName(jetCorr->GetOutputName());  
   phottreepreselnosmear->SetExcludeDoublePrompt(excludedoubleprompt);  
   phottreepreselnosmear->SetIsData(isData);    
   if (is25) phottreepreselnosmear->SetEnablePFPhotons(kFALSE); 
   phottreepreselnosmear->SetApplyLeptonTag(kTRUE);
   phottreepreselnosmear->SetLeptonTagElectronsName("HggLeptonTagElectrons");
   phottreepreselnosmear->SetLeptonTagMuonsName("HggLeptonTagMuons");
   phottreepreselnosmear->SetApplyVBFTag(kTRUE);
   phottreepreselnosmear->SetApplyPFMetCorr(kTRUE);
   phottreepreselnosmear->SetBeamspotWidth(5.0); 
   
   PhotonIDMod         *photidpresel = new PhotonIDMod("PhotonIDModPresel");
   photidpresel->SetPtMin(25.0);
   photidpresel->SetOutputName("GoodPhotonsPreselid");
   photidpresel->SetIDType("MITPFSelection");
   photidpresel->SetApplyElectronVeto(kTRUE);
   photidpresel->SetIsData(isData);
   
  PhotonIDMod         *photidpreselinvert = new PhotonIDMod("PhotonIDModPreselInvert");
  photidpreselinvert->SetPtMin(25.0);
  photidpreselinvert->SetOutputName("GoodPhotonsPreselidInvert");
  photidpreselinvert->SetIDType("MITPFSelection");
  photidpreselinvert->SetApplyElectronVeto(kFALSE);
  photidpreselinvert->SetInvertElectronVeto(kTRUE);
  photidpreselinvert->SetIsData(isData);  
  
  PhotonTreeWriter *phottreesingle = new PhotonTreeWriter("PhotonTreeWriterSingle");
  phottreesingle->SetWriteDiphotonTree(kFALSE);
  phottreesingle->SetPhotonsFromBranch(kFALSE);
  phottreesingle->SetInputPhotonsName(photidpresel->GetOutputName());  
  phottreesingle->SetEnableJets(kTRUE);
  phottreesingle->SetPFJetsFromBranch(kFALSE);
  phottreesingle->SetPFJetName(jetCorr->GetOutputName());      
  phottreesingle->SetBeamspotWidth(5.0);
  phottreesingle->SetIsData(isData);
  if (is25) phottreesingle->SetEnablePFPhotons(kFALSE);  
  
  PhotonTreeWriter *phottreesingleinvert = new PhotonTreeWriter("PhotonTreeWriterSingleInvert");
  phottreesingleinvert->SetWriteDiphotonTree(kTRUE);
  phottreesingleinvert->SetPhotonsFromBranch(kFALSE);
  phottreesingleinvert->SetInputPhotonsName(photidpreselinvert->GetOutputName());  
  phottreesingleinvert->SetEnableJets(kTRUE);
  phottreesingleinvert->SetPFJetsFromBranch(kFALSE);
  phottreesingleinvert->SetPFJetName(pubJetOpen->GetOutputName());
  phottreesingleinvert->SetApplyElectronVeto(kFALSE);
  phottreesingleinvert->SetBeamspotWidth(5.0);
  phottreesingleinvert->SetIsData(isData);  
  if (is25) phottreesingleinvert->SetEnablePFPhotons(kFALSE);    
  

  //------------------------------------------------------------------------------------------------
  // 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(hltModES);
  //mcselmod         ->Add(hltModE);
  
  if (!TString(dataset).Contains("meridiani")) {      
    mcselmod         ->Add(hltModP);
    hltModP         ->Add(goodPVFilterMod);
  }
  else {
    mcselmod->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(pubJetOpen);
  //pubJetOpen       -> Add(photidpreselinvert);
  //goodPVFilterModES ->Add(elecIdS);
  jetCorr          ->Add(SepPUMod); 
  SepPUMod         ->Add(eleIdMod);
  eleIdMod         ->Add(muonIdMod);
   
//   muonIdMod          ->Add(photcic);
//   muonIdMod          ->Add(photcicnoeleveto);  
//   muonIdMod          ->Add(photpreselinverteleveto);  
//   muonIdMod          ->Add(photpreselnosmear);  

  muonIdMod          ->Add(photpresel);  


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

  photpresel    ->Add(phottreepresel);


  //jetCorr          ->Add(photidpresel);
  //photidpresel       ->Add(phottreesingle);
  
  //photidpreselinvert       ->Add(phottreesingleinvert);  
  //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);

  if (TString(dataset).Contains("meridiani")) {    
    ana->SetUseHLT(kFALSE);
  }
  
  //------------------------------------------------------------------------------------------------
  // 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);

  std::vector<TString> synchFile;

//   synchFile.push_back("26650E45-A902-E211-9523-001D09F29146.root");
//   synchFile.push_back("FC4B4004-6502-E211-B532-BCAEC518FF8A.root");
//   synchFile.push_back("063C9BE3-8F02-E211-9503-001D09F2424A.root");
//   synchFile.push_back("10946F3E-4F02-E211-ACA8-5404A63886BB.root");
//   synchFile.push_back("70EAB2D6-8F02-E211-AD24-001D09F29146.root");
//   synchFile.push_back("50F136D5-8F02-E211-A7E1-001D09F25109.root");
//   synchFile.push_back("ACF83417-6502-E211-8A06-002481E0D90C.root");
//   synchFile.push_back("50F136D5-8F02-E211-A7E1-001D09F25109.root");
//   synchFile.push_back("84D8683B-3702-E211-ACC8-BCAEC53296F3.root");
//   synchFile.push_back("64CF7800-6802-E211-AE29-003048D374CA.root");
//   synchFile.push_back("044DE8D2-8F02-E211-BEF1-00215AEDFD98.root");
//   synchFile.push_back("6A50C106-6002-E211-A8FD-003048F118E0.root");
//   synchFile.push_back("80DCA06C-5002-E211-B0FD-5404A6388692.root");
//   synchFile.push_back("1600BC48-4F02-E211-B8FA-BCAEC518FF6B.root");
//   synchFile.push_back("36E6F661-9002-E211-8ED4-001D09F253D4.root");

  synchFile.push_back("28B1B2DB-AAF5-E111-8D01-E0CB4E4408E3.root");
  synchFile.push_back("1EA891A9-77F8-E111-BD59-003048D2BB90.root");
  synchFile.push_back("38E9A015-F1F8-E111-9654-001D09F28D4A.root");
  synchFile.push_back("DC46A78E-60E0-E111-B65D-001D09F25479.root");
  synchFile.push_back("B490A799-45DD-E111-A676-001D09F2AD4D.root");
  synchFile.push_back("2E00B5D2-C9DD-E111-81B5-0025901D6268.root");

  for( unsigned int iF = 0 ; iF<synchFile.size(); ++iF) {
    ana->AddFile("root://xrootd.cmsaf.mit.edu//store/user/paus/filefi/029/r12c-dph-pr-v2/"+synchFile[iF]);   ///scratch/fabstoec/root/DA2D6D6F-BB95-E111-9564-001A92971B7E.root");
    //ana->AddFile("root://xrootd.cmsaf.mit.edu//store/user/paus/filefi/029/r12b-dph-j13-v1/"+synchFile[iF]);   ///scratch/fabstoec/root/DA2D6D6F-BB95-E111-9564-001A92971B7E.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;
}
Exemplo n.º 7
0
//--------------------------------------------------------------------------------------------------
void runMonoJetSkim(const char *fileset    = "0000",
                    const char *skim       = "noskim",
                    const char *dataset    = "MET+Run2015B-PromptReco-v1+AOD",
                    const char *book       = "t2mit/filefi/041",
                    const char *catalogDir = "/home/cmsprod/catalog",
                    const char *outputLabel = "monojet",
                    int         nEvents    = 1000)
{
  float maxJetEta       = 2.5;
  float minMet          = 100.;
  float minLeadJetPt    = 100.;

  //------------------------------------------------------------------------------------------------
  // 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;
  }

  Bool_t isData = (json != "~");

  TString MitData(gSystem->Getenv("MIT_DATA"));
  if (MitData.Length() == 0) {
    printf(" MIT_DATA was not defined. EXIT!\n");
    return;
  }

  TString jsonDir(gSystem->Getenv("MIT_JSON_DIR"));
  if (jsonDir.Length() == 0) {
    printf(" MIT_JSON_DIR was not defined. EXIT!\n");
    return;
  }

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

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

  //------------------------------------------------------------------------------------------------
  // set up information
  //------------------------------------------------------------------------------------------------
  std::vector<mithep::BaseMod*> modules;

  if (isData) {
    RunLumiSelectionMod* runLumiSel = new RunLumiSelectionMod;

    // only select on run- and lumisection numbers when valid json file present
    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
    }
    else if (json.CompareTo("~") != 0) {
      printf("\n Json file added: %s \n\n", json.Data());
      runLumiSel->AddJSONFile((jsonDir + "/" + json).Data());
    }

    modules.push_back(runLumiSel);
  }

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

  // monojet triggers
  std::vector<TString> triggerNames[MonoJetAnalysisMod::nMonoJetCategories];
  triggerNames[MonoJetAnalysisMod::kSignal].push_back("HLT_PFMETNoMu120_NoiseCleaned_PFMHTNoMu120_IDTight_v*");
  triggerNames[MonoJetAnalysisMod::kSignal].push_back("HLT_PFMETNoMu90_NoiseCleaned_PFMHTNoMu90_IDTight_v*");
  triggerNames[MonoJetAnalysisMod::kSingleMuon].push_back("HLT_PFMETNoMu120_NoiseCleaned_PFMHTNoMu120_IDTight_v*");
  triggerNames[MonoJetAnalysisMod::kSingleMuon].push_back("HLT_PFMETNoMu90_NoiseCleaned_PFMHTNoMu90_IDTight_v*");
  triggerNames[MonoJetAnalysisMod::kSingleMuon].push_back("HLT_IsoMu27_v*");
  triggerNames[MonoJetAnalysisMod::kDimuon].push_back("HLT_PFMETNoMu120_NoiseCleaned_PFMHTNoMu120_IDTight_v*");
  triggerNames[MonoJetAnalysisMod::kDimuon].push_back("HLT_PFMETNoMu90_NoiseCleaned_PFMHTNoMu90_IDTight_v*");
  triggerNames[MonoJetAnalysisMod::kDimuon].push_back("HLT_Mu17_TrkIsoVVL_Mu8_TrkIsoVVL_DZ_v*");
  triggerNames[MonoJetAnalysisMod::kSingleElectron].push_back("HLT_Ele27_eta2p1_WPLoose_Gsf_v*");
  triggerNames[MonoJetAnalysisMod::kDielectron].push_back("HLT_Ele17_Ele12_CaloIdL_TrackIdL_IsoVL_DZ_v*");
  triggerNames[MonoJetAnalysisMod::kPhoton].push_back("HLT_Photon175_v*");

  for (auto& names : triggerNames) {
    for (auto& name : names)
      hltMod->AddTrigger(name);
  }

  hltMod->SetBitsName("HLTBits");
  hltMod->SetTrigObjsName("MonoJetTriggerObjects");
  hltMod->SetAbortIfNotAccepted(isData);
  hltMod->SetAbortIfNoData(kFALSE);

  modules.push_back(hltMod);

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

  modules.push_back(goodPvMod);

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

  modules.push_back(SepPUMod);
 
  //-----------------------------------
  // Lepton Selection 
  //-----------------------------------
  MuonIdMod *vetoMuonIdMod = new MuonIdMod("VetoMuonId");
  vetoMuonIdMod->SetMuonClassType(mithep::MuonTools::kPFGlobalorTracker);
  vetoMuonIdMod->SetIdType(mithep::MuonTools::kNoId);
  vetoMuonIdMod->SetPFNoPileupCandidatesName(SepPUMod->GetPFNoPileUpName());
  vetoMuonIdMod->SetPFPileupCandidatesName(SepPUMod->GetPFPileUpName());
  vetoMuonIdMod->SetIsoType(mithep::MuonTools::kPFIsoBetaPUCorrected);
  vetoMuonIdMod->SetApplyD0Cut(kTRUE);
  vetoMuonIdMod->SetApplyDZCut(kTRUE);
  vetoMuonIdMod->SetWhichVertex(0);
  vetoMuonIdMod->SetPtMin(10.);
  vetoMuonIdMod->SetEtaMax(2.4);
  vetoMuonIdMod->SetOutputName("VetoMuons");

  modules.push_back(vetoMuonIdMod);

  MuonIdMod *muonIdMod = new MuonIdMod("GoodMuonId");
  muonIdMod->SetInputName(vetoMuonIdMod->GetOutputName());
  muonIdMod->SetMuonClassType(mithep::MuonTools::kPFGlobalorTracker);
  muonIdMod->SetIdType(mithep::MuonTools::kMuonPOG2012CutBasedIdTight);
  muonIdMod->SetPFNoPileupCandidatesName(SepPUMod->GetPFNoPileUpName());
  muonIdMod->SetPFPileupCandidatesName(SepPUMod->GetPFPileUpName());
  muonIdMod->SetIsoType(mithep::MuonTools::kPFIsoBetaPUCorrectedTight);
  muonIdMod->SetApplyD0Cut(kTRUE);
  muonIdMod->SetApplyDZCut(kTRUE);
  muonIdMod->SetWhichVertex(0);
  muonIdMod->SetPtMin(20.);
  muonIdMod->SetEtaMax(2.4);
  muonIdMod->SetIsFilterMode(kFALSE);
  muonIdMod->SetOutputName("GoodMuons");

  modules.push_back(muonIdMod);

  ElectronIdMod* vetoEleIdMod = new ElectronIdMod("VetoElectronId");
  vetoEleIdMod->SetPtMin(10.);  
  vetoEleIdMod->SetEtaMax(2.4);
  vetoEleIdMod->SetApplyEcalFiducial(true);
  vetoEleIdMod->SetIdType(mithep::ElectronTools::kPhys14Veto);
  vetoEleIdMod->SetIsoType(mithep::ElectronTools::kPhys14VetoIso);
  vetoEleIdMod->SetConversionsName("Conversions");
  vetoEleIdMod->SetApplyConversionFilterType1(kTRUE);
  vetoEleIdMod->SetApplyConversionFilterType2(kFALSE);
  vetoEleIdMod->SetApplyD0Cut(kTRUE);
  vetoEleIdMod->SetApplyDZCut(kTRUE);
  vetoEleIdMod->SetWhichVertex(0);
  vetoEleIdMod->SetOutputName("VetoElectrons");

  modules.push_back(vetoEleIdMod);

  ElectronIdMod* eleIdMod = new ElectronIdMod("GoodElectronId");
  eleIdMod->SetInputName(vetoEleIdMod->GetOutputName());
  eleIdMod->SetPtMin(20.);
  eleIdMod->SetEtaMax(2.4);
  eleIdMod->SetApplyEcalFiducial(true);
  eleIdMod->SetIdType(mithep::ElectronTools::kPhys14Medium);
  eleIdMod->SetIsoType(mithep::ElectronTools::kPhys14MediumIso);
  eleIdMod->SetConversionsName("Conversions");
  eleIdMod->SetApplyConversionFilterType1(kTRUE);
  eleIdMod->SetApplyConversionFilterType2(kFALSE);
  eleIdMod->SetApplyD0Cut(kTRUE);
  eleIdMod->SetApplyDZCut(kTRUE);
  eleIdMod->SetWhichVertex(0);
  eleIdMod->SetIsFilterMode(kFALSE);
  eleIdMod->SetOutputName("GoodElectrons");

  modules.push_back(eleIdMod);

  //-----------------------------------
  // Photon Id 
  //-----------------------------------

  PhotonIdMod *vetoPhotonIdMod = new PhotonIdMod("VetoPhotonId");
  vetoPhotonIdMod->SetPtMin(15.);
  vetoPhotonIdMod->SetOutputName("VetoPhotons");
  vetoPhotonIdMod->SetIdType(mithep::PhotonTools::kPhys14Loose);
  vetoPhotonIdMod->SetIsoType(mithep::PhotonTools::kPhys14LooseIso);
  vetoPhotonIdMod->SetApplyElectronVeto(kTRUE);

  modules.push_back(vetoPhotonIdMod);

  PhotonIdMod *photonIdMod = new PhotonIdMod("GoodPhotonId");
  photonIdMod->SetInputName(vetoPhotonIdMod->GetOutputName());
  photonIdMod->SetPtMin(minMet);
  photonIdMod->SetOutputName("GoodPhotons");
  photonIdMod->SetIdType(mithep::PhotonTools::kPhys14Medium);
  photonIdMod->SetIsoType(mithep::PhotonTools::kPhys14MediumIso);
  photonIdMod->SetApplyElectronVeto(kTRUE);
  photonIdMod->SetIsFilterMode(kFALSE);

  modules.push_back(photonIdMod);

  PFTauIdMod *pfTauIdMod = new PFTauIdMod;
  pfTauIdMod->SetPtMin(18.);
  pfTauIdMod->SetEtaMax(2.3);
  pfTauIdMod->SetInputName("HPSTaus");
  pfTauIdMod->AddDiscriminator(mithep::PFTau::kDiscriminationByDecayModeFindingNewDMs);
  pfTauIdMod->AddCutDiscriminator(mithep::PFTau::kDiscriminationByRawCombinedIsolationDBSumPtCorr3Hits, 5., kFALSE);
  pfTauIdMod->SetOutputName("LooseTaus");

  modules.push_back(pfTauIdMod);

  PFTauCleaningMod* pfTauCleaningMod = new PFTauCleaningMod;
  pfTauCleaningMod->SetOutputName("LooseCleanTaus");
  pfTauCleaningMod->SetGoodPFTausName(pfTauIdMod->GetOutputName());
  pfTauCleaningMod->SetCleanElectronsName(vetoEleIdMod->GetOutputName());
  pfTauCleaningMod->SetCleanMuonsName(vetoMuonIdMod->GetOutputName());

  modules.push_back(pfTauCleaningMod);

  // in principle can cut here with nTau == 0 but for now passing

  JetCorrectionMod *jetCorr = new JetCorrectionMod;
  if (isData){ 
    jetCorr->AddCorrectionFromFile((MitData+TString("/74X_dataRun2_Prompt_v1_L1FastJet_AK4PFchs.txt")).Data()); 
    jetCorr->AddCorrectionFromFile((MitData+TString("/74X_dataRun2_Prompt_v1_L2Relative_AK4PFchs.txt")).Data()); 
    jetCorr->AddCorrectionFromFile((MitData+TString("/74X_dataRun2_Prompt_v1_L3Absolute_AK4PFchs.txt")).Data()); 
    jetCorr->AddCorrectionFromFile((MitData+TString("/74X_dataRun2_Prompt_v1_L2L3Residual_AK4PFchs.txt")).Data());
  }                                                                                      
  else {                                                                                 
    jetCorr->AddCorrectionFromFile((MitData+TString("/MCRUN2_74_V9_L1FastJet_AK4PFchs.txt")).Data()); 
    jetCorr->AddCorrectionFromFile((MitData+TString("/MCRUN2_74_V9_L2Relative_AK4PFchs.txt")).Data()); 
    jetCorr->AddCorrectionFromFile((MitData+TString("/MCRUN2_74_V9_L3Absolute_AK4PFchs.txt")).Data()); 
  }
  jetCorr->SetInputName("AKt4PFJetsCHS");
  jetCorr->SetCorrectedName("CorrectedJets");    

  modules.push_back(jetCorr);

  JetIdMod *jetId = new JetIdMod;
  jetId->SetInputName(jetCorr->GetOutputName());
  jetId->SetOutputName("GoodJets");
  jetId->SetPtMin(30.0);
  jetId->SetEtaMax(2.5);
  jetId->SetApplyPFLooseId(kTRUE);
  jetId->SetMVATrainingSet(JetIDMVA::k53BDTCHSFullPlusRMS);
  jetId->SetMVACutWP(JetIDMVA::kLoose);
  jetId->SetMVACutsFile(MitData + "/jetIDCuts_121221.dat");
  jetId->SetMVAWeightsFile(MitData + "/TMVAClassification_5x_BDT_chsFullPlusRMS.weights.xml");

  modules.push_back(jetId);

  MetCorrectionMod *type1MetCorr = new MetCorrectionMod;
  type1MetCorr->SetInputName("PFMet");
  type1MetCorr->SetOutputName("PFType1CorrectedMet");
  type1MetCorr->SetJetsName("AKt4PFJets");
  type1MetCorr->SetRhoAlgo(PileupEnergyDensity::kFixedGridFastjetAll);
  type1MetCorr->SetMaxEMFraction(0.9);
  type1MetCorr->SetSkipMuons(kTRUE);
  type1MetCorr->ApplyType0(kFALSE);
  type1MetCorr->ApplyType1(kTRUE);
  type1MetCorr->ApplyShift(kFALSE);
  if (isData) {
    type1MetCorr->AddJetCorrectionFromFile(MitData + "/74X_dataRun2_Prompt_v1_L1FastJet_AK4PF.txt");
    type1MetCorr->AddJetCorrectionFromFile(MitData + "/74X_dataRun2_Prompt_v1_L2Relative_AK4PF.txt");
    type1MetCorr->AddJetCorrectionFromFile(MitData + "/74X_dataRun2_Prompt_v1_L3Absolute_AK4PF.txt");
    type1MetCorr->AddJetCorrectionFromFile(MitData + "/74X_dataRun2_Prompt_v1_L2L3Residual_AK4PF.txt");
  }
  else {
    type1MetCorr->AddJetCorrectionFromFile(MitData + "/MCRUN2_74_V9_L1FastJet_AK4PF.txt");
    type1MetCorr->AddJetCorrectionFromFile(MitData + "/MCRUN2_74_V9_L2Relative_AK4PF.txt");
    type1MetCorr->AddJetCorrectionFromFile(MitData + "/MCRUN2_74_V9_L3Absolute_AK4PF.txt");
  }
  type1MetCorr->IsData(isData);

  modules.push_back(type1MetCorr);

  //------------------------------------------------------------------------------------------------
  // select events
  //------------------------------------------------------------------------------------------------

  MonoJetAnalysisMod *monojetSel = new MonoJetAnalysisMod("MonoJetSelector");
  monojetSel->SetMetName(type1MetCorr->GetOutputName());
  monojetSel->SetJetsName(jetId->GetOutputName());
  monojetSel->SetVetoElectronsName(vetoEleIdMod->GetOutputName());
  monojetSel->SetElectronMaskName(eleIdMod->GetOutputName());
  monojetSel->SetVetoMuonsName(vetoMuonIdMod->GetOutputName());
  monojetSel->SetMuonMaskName(muonIdMod->GetOutputName());
  monojetSel->SetVetoTausName(pfTauCleaningMod->GetOutputName());
  monojetSel->SetVetoPhotonsName(vetoPhotonIdMod->GetOutputName());
  monojetSel->SetPhotonMaskName(photonIdMod->GetOutputName());
  monojetSel->SetCategoryFlagsName("MonoJetEventCategories");

  // Using uniform setup for all categories
  for (unsigned iCat = 0; iCat != MonoJetAnalysisMod::nMonoJetCategories; ++iCat) {
    monojetSel->SetCategoryActive(iCat, kTRUE);
    for (auto& name : triggerNames[iCat])
      monojetSel->AddTriggerName(iCat, name);
    monojetSel->SetMaxNumJets(iCat, 0xffffffff);
    monojetSel->SetMaxJetEta(iCat, maxJetEta);
    monojetSel->SetMinChargedHadronFrac(iCat, 0.2); 
    monojetSel->SetMaxNeutralHadronFrac(iCat, 0.7);
    monojetSel->SetMaxNeutralEmFrac(iCat, 0.7);
    monojetSel->SetIgnoreTrigger(!isData);

    switch (iCat) {
    case MonoJetAnalysisMod::kDielectron:
    case MonoJetAnalysisMod::kDimuon:
      monojetSel->SetMinNumJets(iCat, 0);
      monojetSel->SetMinMetPt(iCat, 0.);
      monojetSel->SetVetoPhotons(iCat, false);
      break;
    default:
      monojetSel->SetMinNumJets(iCat, 1);
      monojetSel->SetMinLeadJetPt(iCat, minLeadJetPt);
      monojetSel->SetMinMetPt(iCat, minMet);
      break;
    }
  }

  modules.push_back(monojetSel);

  //------------------------------------------------------------------------------------------------
  // 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->Keep("*");
  skimOutput->Drop("L1TechBits*");
  skimOutput->Drop("L1AlgoBits*");
  skimOutput->Drop("MCVertexes");
  skimOutput->Drop("PFEcal*SuperClusters");
  skimOutput->Drop("*Tracks");
  skimOutput->Drop("StandaloneMuonTracksWVtxConstraint");
  skimOutput->Drop("PrimaryVertexesBeamSpot");
  skimOutput->Drop("InclusiveSecondaryVertexes");
  skimOutput->Drop("CosmicMuons");
  skimOutput->Drop("MergedElectronsStable");
  skimOutput->Drop("MergedConversions*");
  skimOutput->Drop("AKT8GenJets");
  skimOutput->Drop("AKt4PFJets");
  skimOutput->Drop("DCASig");
  skimOutput->AddNewBranch(type1MetCorr->GetOutputName());
  skimOutput->AddNewBranch(monojetSel->GetCategoryFlagsName());

  skimOutput->SetMaxFileSize(10 * 1024); // 10 GB - should never exceed
  skimOutput->SetFileName(outputName);
  skimOutput->SetPathName(".");
  skimOutput->SetCheckTamBr(false);
  skimOutput->SetKeepTamBr(false);
  skimOutput->SetCheckBrDep(true);
  skimOutput->SetUseBrDep(true);

  skimOutput->AddCondition(monojetSel);

  //------------------------------------------------------------------------------------------------
  // making the analysis chain
  //------------------------------------------------------------------------------------------------
  auto mItr(modules.begin());
  while (true) {
    auto* mod = *(mItr++);
    if (mItr == modules.end())
      break;
    mod->Add(*mItr);
  }

  //------------------------------------------------------------------------------------------------
  // setup analysis
  //------------------------------------------------------------------------------------------------
  Analysis *ana = new Analysis;
  ana->SetUseCacher(1);
  ana->SetUseHLT(kTRUE);
  ana->SetAllowNoHLTTree(kTRUE); // for private MC with no HLT info
  ana->SetKeepHierarchy(kFALSE);
  ana->SetPrintScale(100);
  ana->SetOutputName(outputName + "_hist.root");
  if (nEvents >= 0)
    ana->SetProcessNEvents(nEvents);

  ana->AddSuperModule(modules.front());
  ana->AddOutputMod(skimOutput);

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

  //------------------------------------------------------------------------------------------------
  // Say what we are doing
  //------------------------------------------------------------------------------------------------
  printf("\n==== PARAMETER SUMMARY FOR THIS JOB ====\n");
  printf("\n JSON file: %s\n", json.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");

  std::cout << std::endl;
  std::cout << "+++++ ANALYSIS FLOW +++++" << std::endl;
  ana->PrintModuleTree();
  std::cout << std::endl;
  std::cout << "+++++++++++++++++++++++++" << std::endl;

  //------------------------------------------------------------------------------------------------
  // 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;
}
Exemplo n.º 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;
}
Exemplo n.º 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;
}
Exemplo n.º 10
0
//--------------------------------------------------------------------------------------------------
void runMonoJetTrigger(const char *fileset    = "0000",
		   const char *skim       = "noskim",
		   const char *dataset    = "s12-wglg-v7a", 
		   const char *book       = "t2mit/filefi/029",
		   const char *catalogDir = "/home/cmsprod/catalog",
		   const char *outputName = "gmet",
		   int         nEvents    = 1000)
{
  //------------------------------------------------------------------------------------------------
  // 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/cmsprod/cms/json/") + TString(json);
  //TString jsonFile = TString("/home/cmsprod/cms/json/") + TString("Cert_136033-149442_7TeV_Dec22ReReco_Collisions10_JSON_v4.txt");
  Bool_t  isData   = ( (jsonFile.CompareTo("/home/cmsprod/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");

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

  //------------------------------------------------------------------------------------------------
  // set up information
  //------------------------------------------------------------------------------------------------
  
  MVASystematicsMod *sysMod = new MVASystematicsMod;
  sysMod->SetMCR9Scale(1.0035, 1.0035);  
  sysMod->SetIsData(isData);
  
  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");
//    runLumiSel->SetAbortIfNotAccepted(kFALSE);   // accept all events if there is no valid JSON file
  }

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

  //------------------------------------------------------------------------------------------------
  // HLT information : [TBF]
  //------------------------------------------------------------------------------------------------
  HLTMod *hltModP = new HLTMod("HLTModP");
  
  //------------------------------------------------------------------------------------------------
  // Run2012
  //------------------------------------------------------------------------------------------------

  hltModP->AddTrigger("HLT_IsoMu24_eta2p1_v*",0,999999); 

  //store the relevant objects
  hltModP->AddTrigger("HLT_MET120_HBHENoiseCleaned_v*",0,999999); //met type 87
  hltModP->AddTrigger("!HLT_MET120_HBHENoiseCleaned_v*",0,999999); //met type 87
  hltModP->AddTrigger("HLT_MonoCentralPFJet80_PFMETnoMu95_NHEF0p95_v*",0,999999); //jet 85 , met 90
  hltModP->AddTrigger("!HLT_MonoCentralPFJet80_PFMETnoMu95_NHEF0p95_v*",0,999999); //jet 85 , met 90
  hltModP->AddTrigger("HLT_MonoCentralPFJet80_PFMETnoMu105_NHEF0p95_v*",0,999999); //jet 85 , met 90  
  hltModP->AddTrigger("!HLT_MonoCentralPFJet80_PFMETnoMu105_NHEF0p95_v*",0,999999); //jet 85 , met 90  

  hltModP->SetTrigObjsName("MyHltObjs");
  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("Hgg_LeptonTag_2012IdHCP");  
  eleIdMod -> SetElectronMVAWeightsSubdet0Pt10To20(TString((getenv("CMSSW_BASE")+string("/src/MitPhysics/data/ElectronMVAWeights/ElectronID_BDTG_EGamma2012NonTrigV0_Cat1.weights.xml"))));
  eleIdMod -> SetElectronMVAWeightsSubdet1Pt10To20(TString((getenv("CMSSW_BASE")+string("/src/MitPhysics/data/ElectronMVAWeights/ElectronID_BDTG_EGamma2012NonTrigV0_Cat2.weights.xml"))));  
  eleIdMod -> SetElectronMVAWeightsSubdet2Pt10To20(TString((getenv("CMSSW_BASE")+string("/src/MitPhysics/data/ElectronMVAWeights/ElectronID_BDTG_EGamma2012NonTrigV0_Cat3.weights.xml"))));  
  eleIdMod -> SetElectronMVAWeightsSubdet0Pt20ToInf(TString((getenv("CMSSW_BASE")+string("/src/MitPhysics/data/ElectronMVAWeights/ElectronID_BDTG_EGamma2012NonTrigV0_Cat4.weights.xml")))); 
  eleIdMod -> SetElectronMVAWeightsSubdet1Pt20ToInf(TString((getenv("CMSSW_BASE")+string("/src/MitPhysics/data/ElectronMVAWeights/ElectronID_BDTG_EGamma2012NonTrigV0_Cat5.weights.xml")))); 
  eleIdMod -> SetElectronMVAWeightsSubdet2Pt20ToInf(TString((getenv("CMSSW_BASE")+string("/src/MitPhysics/data/ElectronMVAWeights/ElectronID_BDTG_EGamma2012NonTrigV0_Cat6.weights.xml")))); 
  eleIdMod -> SetWhichVertex(-1);
  eleIdMod -> SetD0Cut(0.02);
  eleIdMod -> SetDZCut(0.2); //h  
  eleIdMod -> SetIsoType("PFIso_HggLeptonTag2012HCP"); //h
  eleIdMod -> SetOutputName("HggLeptonTagElectrons");
  eleIdMod -> SetRhoType(RhoUtilities::CMS_RHO_RHOKT6PFJETS);
  eleIdMod -> SetPFNoPileUpName("pfnopileupcands");
  eleIdMod -> SetInvertNExpectedHitsInnerCut(kFALSE);
  eleIdMod -> SetNExpectedHitsInnerCut(1);   
  eleIdMod -> SetApplyConversionFilterType1(kTRUE);
  eleIdMod -> SetPVName(Names::gkPVBeamSpotBrn);   

  MuonIDMod* muonIdMod = new MuonIDMod;
  // base kinematics
  muonIdMod -> SetPtMin(10.);
  muonIdMod -> SetEtaCut(2.4);
  // base ID
  muonIdMod -> SetIDType("Tight");
  muonIdMod -> SetWhichVertex(-1); // this is a 'hack'.. but hopefully good enough...
  muonIdMod -> SetD0Cut(0.02);
  muonIdMod -> SetDZCut(0.5);
  muonIdMod -> SetIsoType("PFIsoBetaPUCorrected"); //h
  muonIdMod -> SetPFIsoCut(0.2); //h
  muonIdMod -> SetOutputName("HggLeptonTagMuons");
  muonIdMod -> SetPFNoPileUpName("pfnopileupcands");
  muonIdMod -> SetPFPileUpName("pfpileupcands");
  muonIdMod -> SetPVName(Names::gkPVBeamSpotBrn); 
  
  ElectronCleaningMod *electronCleaning = new ElectronCleaningMod;
  electronCleaning->SetCleanMuonsName(muonIdMod->GetOutputName());
  electronCleaning->SetGoodElectronsName(eleIdMod->GetOutputName());
  electronCleaning->SetCleanElectronsName("CleanElectrons");

  MergeLeptonsMod *merger = new MergeLeptonsMod;
  merger->SetMuonsName(muonIdMod->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);

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

  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/Summer12_V7_DATA_L1FastJet_AK5PF.txt")).Data())); 
    jetCorr->AddCorrectionFromFile(std::string((gSystem->Getenv("CMSSW_BASE") + TString("/src/MitPhysics/data/Summer12_V7_DATA_L2Relative_AK5PF.txt")).Data())); 
    jetCorr->AddCorrectionFromFile(std::string((gSystem->Getenv("CMSSW_BASE") + TString("/src/MitPhysics/data/Summer12_V7_DATA_L3Absolute_AK5PF.txt")).Data())); 
    jetCorr->AddCorrectionFromFile(std::string((gSystem->Getenv("CMSSW_BASE") + TString("/src/MitPhysics/data/Summer12_V7_DATA_L2L3Residual_AK5PF.txt")).Data())); 
  }
  else {
    jetCorr->AddCorrectionFromFile(std::string((gSystem->Getenv("CMSSW_BASE") + TString("/src/MitPhysics/data/Summer12_V7_MC_L1FastJet_AK5PF.txt")).Data())); 
    jetCorr->AddCorrectionFromFile(std::string((gSystem->Getenv("CMSSW_BASE") + TString("/src/MitPhysics/data/Summer12_V7_MC_L2Relative_AK5PF.txt")).Data())); 
    jetCorr->AddCorrectionFromFile(std::string((gSystem->Getenv("CMSSW_BASE") + TString("/src/MitPhysics/data/Summer12_V7_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(muonIdMod->GetOutputName());
  theJetCleaning->SetCleanPhotonsName(photonCleaningMod->GetOutputName());
  theJetCleaning->SetApplyPhotonRemoval(kTRUE);
  theJetCleaning->SetGoodJetsName(theJetID->GetOutputName());
  theJetCleaning->SetCleanJetsName("CleanJets");
        
  //------------------------------------------------------------------------------------------------
  // select events with jet+MET
  //------------------------------------------------------------------------------------------------
  MonoJetAnalysisMod         *jetplusmet = new MonoJetAnalysisMod("MonoJetSelector");
  jetplusmet->SetJetsName(theJetCleaning->GetOutputName()); //identified jets
  jetplusmet->SetJetsFromBranch(kFALSE);
  jetplusmet->SetElectronsName(electronCleaning->GetOutputName());
  jetplusmet->SetElectronsFromBranch(kFALSE);
  jetplusmet->SetMuonsName(muonIdMod->GetOutputName());
  jetplusmet->SetMuonsFromBranch(kFALSE);
  jetplusmet->SetLeptonsName(merger->GetOutputName());
  jetplusmet->SetMinNumJets(1);
  jetplusmet->SetMinNumLeptons(0);
  jetplusmet->SetMinJetEt(30);
  jetplusmet->SetMaxJetEta(2.7);
  jetplusmet->SetMinChargedHadronFrac(0.3);
  jetplusmet->SetMaxNeutralHadronFrac(0.7);
  jetplusmet->SetMaxNeutralEmFrac(0.7);
  jetplusmet->SetMinMetEt(30);

  HLTEvtSelMod *hlttree = new HLTEvtSelMod("MonoJetHLTTreeWriter");
  hlttree->SetCleanJetsName(theJetCleaning->GetOutputName());
  hlttree->SetVertexName(goodPVFilterMod->GetOutputName());
  hlttree->SetTrigObjsName(hltModP->GetOutputName());
  
  //------------------------------------------------------------------------------------------------
  // making analysis chain
  //------------------------------------------------------------------------------------------------
  // this is how it always starts
  runLumiSel     ->Add(goodPVFilterMod);
  goodPVFilterMod->Add(hltModP);
  // photon regression
  hltModP->Add(photreg);
  // simple object id modules
  photreg          ->Add(SepPUMod); 
  SepPUMod         ->Add(muonIdMod);
  muonIdMod        ->Add(eleIdMod);
  eleIdMod	   ->Add(electronCleaning);
  electronCleaning ->Add(merger);
  merger           ->Add(photonIDMod);
  photonIDMod	   ->Add(photonCleaningMod);
  photonCleaningMod->Add(pubJet);
  pubJet           ->Add(jetCorr);
  jetCorr          ->Add(theJetID);
  theJetID	   ->Add(theJetCleaning);
   
  // Jet+met selection
  theJetCleaning   ->Add(jetplusmet);
  jetplusmet        ->Add(hlttree);

  //------------------------------------------------------------------------------------------------
  // 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);
  else 
    d = c->FindDataset(bookstr,skimdataset.Data(),fileset, true);
  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");
  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;
}
Exemplo n.º 11
0
//--------------------------------------------------------------------------------------------------
void runHgg_LT(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/fabstoec/cms/json/") + TString(json);
  //TString jsonFile = TString("/home/fabstoec/cms/json/") + TString("Cert_136033-149442_7TeV_Dec22ReReco_Collisions10_JSON_v4.txt");
  Bool_t  isData   = ( (jsonFile.CompareTo("/home/fabstoec/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/fabstoec/cms/json/~") != 0) &&
      (jsonFile.CompareTo("/home/fabstoec/cms/json/-") != 0)   ) {
    runLumiSel->AddJSONFile(jsonFile.Data());
  }
  if ((jsonFile.CompareTo("/home/fabstoec/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 *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);
 
  //-----------------------------------
  // Lepton Selection
  //-----------------------------------
  ElectronIDMod* eleIdMod = new ElectronIDMod;
  eleIdMod -> SetEtMin(20.);
  eleIdMod -> SetEtaMax(2.5);
  eleIdMod -> SetApplyEcalFiducial(true);

  eleIdMod -> SetIDType("Hgg_LeptonTag_WP85Id");

  eleIdMod -> SetVertexName("CiCChosenVtx");
  eleIdMod -> SetWhichVertex(0);
  eleIdMod -> SetD0Cut(0.02);
  eleIdMod -> SetDZCut(0.1);

  eleIdMod -> SetIsoType("CombinedRelativeConeAreaCorrected");
  //                                Barrel   Endcap
  eleIdMod -> SetCombRelativeIsoCut(0.053,   0.042  );
  //eleIdMod -> SetRhoType(RhoUtilities::MIT_RHO_RANDOM_LOW_ETA);
  eleIdMod -> SetRhoType(RhoUtilities::MIT_RHO_VORONOI_HIGH_ETA);

  eleIdMod -> SetOutputName("HggLeptonTagElectrons");

  MuonIDMod* muonIdMod = new MuonIDMod;
  // base kinematics
  muonIdMod -> SetPtMin(20.);
  muonIdMod -> SetEtaCut(2.4);
  // base ID
  muonIdMod -> SetIDType("WMuId");
  // distance to Vtx restriction
  muonIdMod -> SetVertexName("CiCChosenVtx");
  muonIdMod -> SetWhichVertex(0); // this is a 'hack'.. but hopefully good enough...
  muonIdMod -> SetD0Cut(0.02);
  muonIdMod -> SetDZCut(0.1);
  // isolation
  muonIdMod -> SetIsoType("CombinedRelativeConeAreaCorrected");
  muonIdMod -> SetCombRelativeIsoCut(0.1);
  //muonIdMod -> SetRhoType(RhoUtilities::MIT_RHO_RANDOM_LOW_ETA);
  muonIdMod -> SetRhoType(RhoUtilities::MIT_RHO_VORONOI_HIGH_ETA);

  muonIdMod -> SetOutputName("HggLeptonTagMuons");

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

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

  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->SetRhoType(RhoUtilities::MIT_RHO_RANDOM_HIGH_ETA);
  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->SetOutputVtxName("CiCChosenVtx");
  photcic->SetPhotonSelType("CiCSelection");
  photcic->SetVertexSelType("CiCMVASelection");
  photcic->DoMCSmear(kTRUE);
  photcic->DoDataEneCorr(kTRUE);
  photcic->SetPhotonsFromBranch(kFALSE);
  photcic->SetInputPhotonsName(photreg->GetOutputName());
  photcic->SetMCSmearFactors(0.0067,0.0077,0.0096,0.0141,0.0196,0.0268,0.0279,0.0293,0.0301);//ming:smear(sigE/E)
  photcic->AddEnCorrPerRun(160431,167913,0.9941,0.9941,1.0004,0.9916,1.0045,1.0033,1.0082,0.9958,1.0064);//ming:Emc/Edata
  photcic->AddEnCorrPerRun(170000,172619,0.9954,0.9954,1.0016,0.9937,1.0066,0.9976,1.0025,0.9940,1.0046);
  photcic->AddEnCorrPerRun(172620,173692,0.9955,0.9955,1.0017,0.9929,1.0058,0.9986,1.0035,0.9923,1.0029);
  photcic->AddEnCorrPerRun(175830,177139,0.9958,0.9958,1.0021,0.9944,1.0073,0.9968,1.0017,0.9933,1.004);
  photcic->AddEnCorrPerRun(177140,178421,0.9962,0.9962,1.0025,0.9946,1.0075,0.9960,1.0010,0.9944,1.005);
  photcic->AddEnCorrPerRun(178424,180252,0.9961,0.9961,1.0024,0.9942,1.0071,0.9921,0.9970,0.9953,1.0059); 
  photcic->SetDoMCR9Scaling(kTRUE);
  photcic->SetMCR9Scale(1.0048, 1.00492);
  photcic->SetDoMCErrScaling(kTRUE);
  photcic->SetMCErrScale(1.07, 1.045);    
  photcic->SetIsData(isData);

  PhotonPairSelector         *photpresel = new PhotonPairSelector("PhotonPairSelectorPresel");
  photpresel->SetOutputName("GoodPhotonsPresel");
  photpresel->SetOutputVtxName("PreselChosenVtx");
  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);

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

  phottreecic->SetApplyBTag(true);
  phottreecic->SetApplyLeptonTag(true);
  phottreecic->SetLeptonTagElectronsName("HggLeptonTagElectrons");
  phottreecic->SetLeptonTagMuonsName    ("HggLeptonTagMuons");

  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);  
  
  phottreepresel->SetApplyLeptonTag(true);
  phottreepresel->SetLeptonTagElectronsName("HggLeptonTagElectrons");
  phottreepresel->SetLeptonTagMuonsName    ("HggLeptonTagMuons");

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

  hltModP         ->Add(goodPVFilterMod);
  goodPVFilterMod ->Add(photreg);
  photreg         ->Add(pubJet);
  pubJet          ->Add(jetCorr);

  jetCorr         ->Add(photcic);
  photcic         ->Add(eleIdMod);
  eleIdMod        ->Add(muonIdMod);
  muonIdMod       ->Add(phottreecic);

  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;
}