Example #1
0
double* getPscls(std::string infile, int nFiles) {

    TChain *dataCH = NULL;
    dataCH = new TChain(Form("%sJetAnalyzer/t", algo.Data()));
    TChain *dataCH2 = new TChain("hltanalysis/HltTree");
    std::ifstream instr(infile.c_str(), std::ifstream::in);
    std::string filename;
    for(int ifile=0; ifile<nFiles; ifile++) {
        instr >> filename;
        dataCH->Add(filename.c_str());
        dataCH2->Add(filename.c_str());
    }
    dataCH->AddFriend(dataCH2, "hltanalysis/HltTree");
    double ov1, ov2, ov3, ov4;
    ov1 = dataCH->GetEntries("HLT_PAJet20_NoJetID_v1 && HLT_PAJet80_NoJetID_v1");
    ov2 = dataCH->GetEntries("HLT_PAJet40_NoJetID_v1 && HLT_PAJet80_NoJetID_v1");
    ov3 = dataCH->GetEntries("HLT_PAJet60_NoJetID_v1 && HLT_PAJet80_NoJetID_v1");
    ov4 = dataCH->GetEntries("HLT_PAJet80_NoJetID_v1");
    double *pscls = new double[4];
    pscls[0] = ov4/ov1;
    pscls[1] = ov4/ov2;
    pscls[2] = ov4/ov3;
    pscls[3] = 1.;
    return pscls;
}
void scanDiffRecoTracks(std::string eName, std::string eoName,
			std::string branchReg = "recoTracks_*"){
  gSystem->Load("libFWCoreFWLite");
  gROOT->ProcessLine("AutoLibraryLoader::enable();");
  TChain* e = new TChain("Events");
  e->SetScanField(0);

  e->Add(eName.c_str());

  TChain* eo = new TChain("Events");
  eo->SetScanField(0);

  eo->Add(eoName.c_str());
  e->AddFriend(eo, "eo");

  TRegexp regg(branchReg.c_str(), kTRUE);

  TChain* tc = e ;
  TObjArray* tl = tc->GetListOfBranches();
 
  Int_t nBr = tl->GetSize();
  for (int iB=0;iB<nBr;++iB){
    TBranch* br = (TBranch*)(tl->At(iB)); 
    TString ts(br->GetName()); 
    if(ts.Index(regg)>=0){
      std::cout<<ts.Data()<<std::endl;
      tc->Scan(Form("Sum$(%s.obj.pt()>0):Sum$(eo.%s.obj.pt()>0):Sum$(%s.obj.pt()):Sum$(%s.obj.pt())-Sum$(eo.%s.obj.pt())",
 		    ts.Data(), ts.Data(), ts.Data(), ts.Data(), ts.Data()),"", "");
    }
  } //> e.tecoTracks.recoT0.txt

}
Example #3
0
TChain* load (std::string methodName)
{
    TString trainingFileName ("training");
    TString fname0 = pathToData + trainingFileName + TString (".root");
    TString fname1 = trainingFileName + TString ("_prediction__") + methodName + TString (".root");
    TChain* ch = new TChain ("data");
    ch->Add (fname0);
    TChain* fr = new TChain ("data");
    fr->Add (fname1);
    ch->AddFriend (fr,"s");
    ch->Print ("");
    return ch;
}
Example #4
0
int main() 
{
   MySelector *A = new MySelector();

   TChain* ch = new TChain("AK4PFCHS/t");
	TChain* c1 = new TChain("event/t");

 	FILE *input;
	char filename[300];

	int i = 0;

	TString filenames [] = {"../lists/file_list_25ns_76X.txt",
									"../lists/file_list_25ns_76X_test.txt",
									"../lists/ptbinned/file_list_5to10_76X.txt",
									"../lists/ptbinned/file_list_10to15_76X.txt",
									"../lists/ptbinned/file_list_15to30_76X.txt",
									"../lists/ptbinned/file_list_30to50_76X.txt",
									"../lists/ptbinned/file_list_50to80_76X.txt",
									"../lists/ptbinned/file_list_80to120_76X.txt",
									"../lists/ptbinned/file_list_120to170_76X.txt",
									"../lists/ptbinned/file_list_170to300_76X.txt",
									"../lists/ptbinned/file_list_300to470_76X.txt",
									"../lists/ptbinned/file_list_470to600_76X.txt",
									"../lists/ptbinned/file_list_600to800_76X.txt",
									"../lists/ptbinned/file_list_800to1000_76X.txt",
									"../lists/ptbinned/file_list_1000to1400_76X.txt",
									"../lists/ptbinned/file_list_1400to1800_76X.txt",
									"../lists/ptbinned/file_list_1800to2400_76X.txt",
									"../lists/ptbinned/file_list_2400to3200_76X.txt",
									"../lists/ptbinned/file_list_3200toInf_76X.txt"};

	input = fopen( filenames[i], "r" );

	if (input != NULL)
	{ // lets read each line and get the filename from it
		while (fscanf(input,"%s\n",filename) != EOF) 
		{
			printf("%s\n",filename); 
			ch->Add(filename);
			ch->AddFriend(c1,filename);
		}
	}

//	std::cout << "number of events is " << ch->GetEntries() << std::endl;

	ch -> Process(A);

//	std::cout <<"			Analyzed events #" <<  A -> TotalEvents << std::endl;

}
//_____________________________________________________________________________
TChain *CreateAODFriendChain(TString sDataset)
{ 
  if (!sDataset.EndsWith(".txt")) return 0;

  TChain *chain = new TChain("aodTree");
  TChain *cFrid = new TChain("aodTree");

  TString dataFile;
  ifstream dataList(sDataset.Data(), ios::in); 
  while (!dataList.eof()) {
    dataFile.ReadLine(dataList,kFALSE);
    if (!dataFile.EndsWith("AliAOD.root")) continue;
    if (!gSystem->AccessPathName(dataFile.Data())) chain->Add(dataFile.Data());

    dataFile.ReplaceAll("AliAOD.root","AliAOD.VertexingHF.root");
    if (!gSystem->AccessPathName(dataFile.Data())) cFrid->Add(dataFile.Data());
  } dataList.close();

  chain->AddFriend(cFrid);
  return chain;
}
Example #6
0
TChain * compJOO(
    TString infile="hltana_Exp_151058.root",
    TString header="HLT_HIJet90U"
    )
{
  TChain * dj = new TChain("hltanalysis/HltTree");

  dj->Add(infile);
  dj->AddFriend("onl = hltanalysisOnl/HltTree",infile);
  cout << "Trig Total: " << dj->GetEntries() << endl;

  TCut evtSel("HLT_HIJet90U && hiBin*2.5<100");

  TH1D * hJEtIc5pu = plotJEt(dj,evtSel,"recoJetCalPt[0]","hJEtIc5pu",0);
  TH1D * hJEtIc5puOnl = plotJEt(dj,evtSel,"onl.recoJetCalPt[0]","hJEtIc5puOnl",0);

  TCut matEvtSel(evtSel);
  bool doMat = true;
  if (doMat) matEvtSel = evtSel && "abs(onl.recoJetCalEta[0]-recoJetCalEta[0])<0.2";
  TH2D * hJEtOnlIc5pu = plotJEtCorr(dj,matEvtSel,"onl.recoJetCalPt[0]/recoJetCalPt[0]:recoJetCalPt[0]","hJEtOnlIc5pu",";leading E_{T}^{Ic5pu} [GeV];E_{T}^{Ic5pu Online}/E_{T}^{Ic5pu}");

  TCanvas * cJEt = new TCanvas("cJEt","cJEt",500,500);
  CPlot cpJEt("JEt","JEt","leading E_{T}^{Jet}","#");
  cpJEt.SetLogy();
  cpJEt.AddHist1D(hJEtIc5puOnl,"Online Reco","hist",kGreen+2,kOpenSquare);
  cpJEt.AddHist1D(hJEtIc5pu,"Offline Reco","E",kBlack,kFullCircle);
  cpJEt.SetLegend(0.62,0.78,0.94,0.9);
  cpJEt.SetLegendHeader(header);
  cpJEt.Draw(cJEt,false);

  TCanvas * cDEta = new TCanvas("cDEta","cDEta",500,500);
  cDEta->SetLogy();
  dj->Draw("onl.recoJetCalEta[0]-recoJetCalEta[0]>>hDEta",evtSel,"E");
  TCanvas * cDPhi = new TCanvas("cDPhi","cDPhi",500,500);
  cDPhi->SetLogy();
  dj->Draw("onl.recoJetCalPhi[0]-recoJetCalPhi[0]>>hDPhi",evtSel,"E");

  return dj;
}
Example #7
0
void BkgFluctuation(TString infname = "../ntv6_datambv3rand_djcalo_c0to30_offset0.root",
                    TCut myCut = "cent<30", char *title = "",bool drawLegend = false,
                    bool drawSys = true
		    )
{
  gStyle->SetHistLineWidth(2);
  // ===========================================================
  // Get Input
  // ===========================================================
  TChain* t = new TChain("ntjt");
  t->Add(infname);
  t->AddFriend("tcone",infname);
  cout << infname << ": " << t->GetEntries() << endl;
  t->SetAlias("cptsub0Merge0","cpt[0][1]+cpt[0][2]-(cptbg[0][1]+cptbg[0][2])");
  t->SetAlias("cptsub0Merge1","cpt[0][3]-(cptbg[0][3])");
  t->SetAlias("cptsub0Merge2","cpt[0][4]+cpt[0][5]-(cptbg[0][4]+cptbg[0][5])");
  t->SetAlias("cptsub0Merge3","(Sum$(cpt[0])-cpt[0][0])-(Sum$(cptbg[0])-cptbg[0][0])");

  // ===========================================================
  // Analysis Setup
  // ===========================================================
  TH1::SetDefaultSumw2();
   const int nBin = 3;
   double bins[nBin+1] = {1.,4,8,160};  
  TCut evtCut = "nljet>100&&abs(nljetacorr)<1.6&&aljet>50&&abs(aljetacorr)<1.6&&jdphi>2./3*TMath::Pi()&&!maskEvt";
  TCut exclusion = "abs(nljetacorr)>0.8"; //&&abs(aljetacorr)>0.8";
  evtCut = evtCut&&exclusion;
  //Int_t colors[7] = {kBlue, kCyan-3, kYellow+1, kOrange+1, kGreen+2, kMagenta, kRed };
  Int_t colors[7] = {kYellow+2, kGreen+2,kRed };
  
  // ===========================================================
  // Book Histograms
  // ===========================================================
  vector<TH1D*> vhBgSub;
  for (Int_t i=0; i<nBin+1; ++i) {
    vhBgSub.push_back(new TH1D(Form("hBgSub_%d"),";(Sig Cone #Sigma p_{T}) - (Bkg Cone #Sigma p_{T}) (GeV/c);fraction;",50,-300,300));
  }

  Float_t numEvt = t->GetEntries(evtCut&&myCut);
  cout << "Total Sel evt: " << numEvt << endl;
  for (Int_t i=0; i<nBin+1; ++i) {
    TString var(Form("cptsub0Merge%i",i));
    cout << "Sel evt: " << t->GetEntries(evtCut&&myCut&&var) << endl;
    cout << "var: " << t->GetAlias(var) << endl;
    t->Project(vhBgSub[i]->GetName(),var,(evtCut&&myCut&&var)*"weight");
    Float_t mean = vhBgSub[i]->GetMean();
    Float_t rms = vhBgSub[i]->GetRMS();
    cout << "bgsub mean: " << mean << " rms: " << rms << endl;
    vhBgSub[i]->Scale(1./numEvt);
    cout << "Bin " << i << " rms/sqrt(250): " << rms/sqrt(250)
      << " r=0: " << rms/sqrt(250.)*sqrt(fracArea(0))
      << " r=0.8: " << rms/sqrt(250.)*sqrt(fracArea(0.8)) << endl;
  }

  TCanvas * c2 = new TCanvas("c2","c2",600,600);
  c2->SetLogy();
  vhBgSub[nBin]->SetAxisRange(1e-5,5,"Y");
  vhBgSub[nBin]->Draw("E");
  for (Int_t i=0; i<nBin; ++i) {
    vhBgSub[i]->SetLineColor(colors[i]);
    vhBgSub[i]->Draw("same hist");
  }
  vhBgSub[nBin]->Draw("Esame");

  TLegend *leg = new TLegend(0.19,0.70,0.53,0.92);
  leg->SetFillStyle(0);
  leg->SetBorderSize(0);
  leg->SetTextSize(0.035);
  leg->AddEntry(vhBgSub[nBin],"CMS 0-30%","");
  leg->AddEntry(vhBgSub[nBin],"Random Cone (MB Sample)","");
  leg->AddEntry(vhBgSub[nBin],Form("> %.1f GeV/c",bins[0]),"pl");
  for (int i=0;i<nBin;++i) {
    if (i!=nBin-1){
      leg->AddEntry(vhBgSub[i],Form("%.1f - %.1f GeV/c",bins[i],bins[i+1]),"l");
    } else {
      leg->AddEntry(vhBgSub[i],Form("> %.1f GeV/c",bins[i]),"l");
    }
  }
  leg->Draw();
}
Example #8
0
void RateEstimateVpt(TString infile="alldatacleaned.root") //Contains both cleaned and uncleaned data
{
  //TChain * tree = new TChain("icPu5JetAnalyzer_clean/t");
  TChain * tree = new TChain("icPu5JetAnalyzer/t");
  tree->Add(infile);
  //tree->AddFriend("hltanalysis_clean/HltTree",infile);
  tree->AddFriend("hltanalysis/HltTree",infile);
  //  cout << "Total: " << tree->GetEntries() << endl; 

  TCut evtSel("Run==152957&&HLT_HIMinBiasHfOrBSC&&hiBin<40&&abs(jteta[0])<2");


  //Canvas definition and choosing uncorrected and corrected jet pt variables 
  TCanvas *e1 = new TCanvas("e1","Rate Estimate vs. Threshold",200,10,700,500);
  e1->SetLogy();
  TH1D * RJetPt = new TH1D("RJetPt",";Leading Jet p_{T} (GeV/c);count;",300,0,300);
  TH1D * JetPt = new TH1D("JetPt",";Leading Jet p_{T} (GeV/c);count;",300,0,300);
  tree->Draw("rawpt[0]>>RJetPt",evtSel,"goff");
  tree->Draw("jtpt[0]>>JetPt",evtSel,"goff");
  cout << "Integral: " << JetPt->Integral(0,101) << endl;

  //Defines total # of entries for normalization and max rate
  TH1F * h4 = new TH1F("h4","",50,0,300);
  tree->Draw("LumiBlock>>h4",evtSel,"goff");
  Float_t R = 1 ; //Defines Maximum Rate
  Float_t TA = h4->GetEntries();

  //Computes Accept Fraction as a function of pt 
  const Int_t n = 61;
  Float_t x[n], y[n], z[n], w[n], t[n];
  for (Int_t i=0;i<n;i++) {
    x[i] = 300-i*5; 
    y[i] = RJetPt->Integral(x[i],301);
    z[i] = R*y[i]/TA;
    w[i] = JetPt->Integral(x[i],301);
    t[i] = R*w[i]/TA;
    printf(" i %i %f %f %f \n",i,x[i],y[i],z[i]);
  }

  //Defines graphs and axis. 
  gr = new TGraph(n,x,z);
  gs = new TGraph(n,x,t);
  gr->GetYaxis()->SetRangeUser(0.001,5000);

  // Attractive features for graphs
  gr->SetLineColor(kRed);
  gs->SetLineColor(kBlue);
  gr->SetMarkerColor(kRed);
  gr->SetMarkerStyle(kOpenCircle);
  gs->SetMarkerColor(kBlue);
  gs->SetMarkerStyle(kOpenCircle);
  gr->SetTitle("");
  gr->GetXaxis()->SetTitle("Jet Pt Threshold (GeV/c)");
  gr->GetYaxis()->SetTitle("Rate Estimate (Hz)");

  //Draw graphs
  gr->Draw("LAP");
  gs->Draw("LP");

  //Defines Legened
  TLegend *L = new TLegend(0.52292,0.675103,0.932471,0.919831);
  L->SetHeader("AllPhysics, |#eta| < 2, All Centrality" );
  L->SetBorderSize(0);
  L->SetFillStyle(0);
  L->AddEntry(gr,"Uncorrected p_{T}","pl");
  L->AddEntry(gs,"Corrected p_{T}","pl");
  L->Draw();

}
Example #9
0
void analyzePuppi(std::vector<std::string> urls, const char *outname = "eventObjects.root", Long64_t nentries = 20, Int_t firstF = -1, Int_t lastF = -1) {

  // std::vector<std::string> urls = CollectFiles(list);

  // Printf("anaFile: %d",anaFile);
  
  std::cout << "nfiles: " << urls.size() << std::endl;
  for (auto i = urls.begin(); i != urls.end(); ++i)
    std::cout << *i << std::endl;

  size_t firstFile = 0;
  size_t lastFile = urls.size();

  if(firstF>-1) {
    firstFile = (size_t)firstF;
    lastFile = (size_t)lastF;
  }
  std::cout << "firstFile: " << firstFile << "  lastFile: " << lastFile << std::endl;
  
  //add files to chain
  TChain *chain = NULL;
  chain = new TChain("hiEvtAnalyzer/HiTree");
  for(size_t i=firstFile; i<lastFile; i++) chain->Add(urls[i].c_str());
  Printf("hiTree done");
  
  TChain *pfTree = new TChain("pfcandAnalyzer/pfTree");
  for(size_t i=firstFile; i<lastFile; i++) pfTree->Add(urls[i].c_str());
  chain->AddFriend(pfTree);
  Printf("pfTree done");
  
  // TChain *muTree = new TChain("hltMuTree/HLTMuTree");
  // for(size_t i=firstFile; i<lastFile; i++) muTree->Add(urls[i].c_str());
  // chain->AddFriend(muTree);
  // Printf("muTree done");

  //TChain *jetTree = new TChain("akPu3PFJetAnalyzer/t");
  TChain *jetTree = new TChain("akPu2PFJetAnalyzer10/t");
  for(size_t i=firstFile; i<lastFile; i++) jetTree->Add(urls[i].c_str());
  chain->AddFriend(jetTree);
  Printf("jetTree done");

  TChain *genTree = new TChain("HiGenParticleAna/hi");
  for(size_t i=firstFile; i<lastFile; i++) genTree->Add(urls[i].c_str());
  chain->AddFriend(genTree);
  Printf("genTree done");
  
  TList *fEventObjects = new TList();


  //---------------------------------------------------------------
  // producers
  //
  hiEventProducer *p_evt = new hiEventProducer("hiEvtProd");
  p_evt->SetInput(chain);
  p_evt->SetHIEventContName("hiEventContainer");
  p_evt->SetEventObjects(fEventObjects);

  pfParticleProducer *p_pf = new pfParticleProducer("pfPartProd");
  p_pf->SetInput(chain);
  p_pf->SetpfParticlesName("pfParticles");
  p_pf->SetEventObjects(fEventObjects);

  genParticleProducer *p_gen = new genParticleProducer("genParticleProd");
  p_gen->SetInput(chain);
  p_gen->SetGenParticlesName("genParticles");
  p_gen->SetEventObjects(fEventObjects);

  lwJetFromForestProducer *p_PUJet = new lwJetFromForestProducer("lwJetForestProd");
  p_PUJet->SetInput(chain);
  p_PUJet->SetJetContName("aktPUR030");
  p_PUJet->SetEventObjects(fEventObjects);
  p_PUJet->SetRadius(0.3);
  
  //---------------------------------------------------------------
  //analysis modules
  //

  //handler to which all modules will be added
  anaBaseTask *handler = new anaBaseTask("handler","handler");

  //analysis modules which also produce
  anaPuppiProducer *pupProd = new anaPuppiProducer("pupProd","pupProd");
  pupProd->ConnectEventObject(fEventObjects);
  pupProd->SetHiEvtName("hiEventContainer");
  pupProd->SetPFPartName("pfParticles");
  pupProd->SetPuppiPartName("puppiParticles");
  pupProd->SetJetsName("aktPUR030");
  pupProd->SetAddMetricType(anaPuppiProducer::kMass);
  if(doPuppi) handler->Add(pupProd);

  //anti-kt jet finder on reconstructed PUPPI particles ptmin=0
  LWJetProducer *lwjakt = new LWJetProducer("LWJetProducerAKTR030Puppi","LWJetProducerAKTR030Puppi");
  lwjakt->ConnectEventObject(fEventObjects);
  lwjakt->SetJetType(LWJetProducer::kAKT);
  lwjakt->SetRadius(0.3);
  lwjakt->SetGhostArea(0.005);
  lwjakt->SetPtMinConst(0.);
  lwjakt->SetParticlesName("puppiParticles");
  lwjakt->SetJetContName("JetsAKTR030Puppi");
  if(doPuppi) handler->Add(lwjakt);

  //anti-kt jet finder on reconstructed PUPPI particles ptmin=1
  LWJetProducer *lwjaktpt100 = new LWJetProducer("LWJetProducerAKTR030PuppiPtMin100","LWJetProducerAKTR030PuppiPtMin100");
  lwjaktpt100->ConnectEventObject(fEventObjects);
  lwjaktpt100->SetJetType(LWJetProducer::kAKT);
  lwjaktpt100->SetRadius(0.3);
  lwjaktpt100->SetGhostArea(0.005);
  lwjaktpt100->SetPtMinConst(1.);
  lwjaktpt100->SetParticlesName("puppiParticles");
  lwjaktpt100->SetJetContName("JetsAKTR030PuppiPtMin100");
  if(doPuppi) handler->Add(lwjaktpt100);

  //anti-kt jet finder on reconstructed PUPPI particles ptmin=2
  LWJetProducer *lwjaktpt200 = new LWJetProducer("LWJetProducerAKTR030PuppiPtMin200","LWJetProducerAKTR030PuppiPtMin200");
  lwjaktpt200->ConnectEventObject(fEventObjects);
  lwjaktpt200->SetJetType(LWJetProducer::kAKT);
  lwjaktpt200->SetRadius(0.3);
  lwjaktpt200->SetGhostArea(0.005);
  lwjaktpt200->SetPtMinConst(2.);
  lwjaktpt200->SetParticlesName("puppiParticles");
  lwjaktpt200->SetJetContName("JetsAKTR030PuppiPtMin200");
  if(doPuppi) handler->Add(lwjaktpt200);

  //anti-kt jet finder on generated particles
  LWJetProducer *lwjaktGen = new LWJetProducer("LWGenJetProducerAKTR030","LWGenJetProducerAKTR030");
  lwjaktGen->ConnectEventObject(fEventObjects);
  lwjaktGen->SetJetType(LWJetProducer::kAKT);
  lwjaktGen->SetRadius(0.3);
  lwjaktGen->SetGhostArea(0.005);
  lwjaktGen->SetPtMinConst(0.);
  lwjaktGen->SetParticlesName("genParticles");
  lwjaktGen->SetJetContName("GenJetsAKTR030");
  handler->Add(lwjaktGen);
 
  //Initialization of all analysis modules
  anaPuppiParticles *pupAna = new anaPuppiParticles("pupAna","pupAna");
  pupAna->ConnectEventObject(fEventObjects);
  pupAna->SetHiEvtName("hiEventContainer");
  pupAna->SetParticlesName("pfParticles");
  pupAna->SetJetsName("aktPUR030");
  if(doPuppi) handler->Add(pupAna);

  //particle-detector-level jet matching
  anaJetMatching *match = new anaJetMatching("jetMatching","jetMatching");
  match->ConnectEventObject(fEventObjects);
  match->SetHiEvtName("hiEventContainer");
  match->SetJetsNameBase("JetsAKTR030Puppi");
  match->SetJetsNameTag("GenJetsAKTR030");
  if(doPuppi) handler->Add(match);

  anaJetMatching *matchPt100 = new anaJetMatching("jetMatchingPtMin100","jetMatchingPtMin100");
  matchPt100->ConnectEventObject(fEventObjects);
  matchPt100->SetHiEvtName("hiEventContainer");
  matchPt100->SetJetsNameBase("JetsAKTR030PuppiPtMin100");
  matchPt100->SetJetsNameTag("GenJetsAKTR030");
  if(doPuppi) handler->Add(matchPt100);

  anaJetMatching *matchPt200 = new anaJetMatching("jetMatchingPtMin200","jetMatchingPtMin200");
  matchPt200->ConnectEventObject(fEventObjects);
  matchPt200->SetHiEvtName("hiEventContainer");
  matchPt200->SetJetsNameBase("JetsAKTR030PuppiPtMin200");
  matchPt200->SetJetsNameTag("GenJetsAKTR030");
  if(doPuppi) handler->Add(matchPt200);
  
  //---------------------------------------------------------------
  //Event loop
  //---------------------------------------------------------------	  
  Long64_t entries_tot =  chain->GetEntriesFast(); //93064
  if(nentries<0) nentries = chain->GetEntries();
  // Long64_t nentries = 20;//chain->GetEntriesFast();
  Printf("nentries: %lld  tot: %lld",nentries,entries_tot);
  for (Long64_t jentry=0; jentry<nentries;jentry++) {

    //Run producers
    Printf("produce hiEvent");
    p_evt->Run(jentry);   //hi event properties
    Printf("produce pf particles");
    p_pf->Run(jentry);    //pf particles
    Printf("produce gen particles");
    p_gen->Run(jentry);   //generated particles
    Printf("produce PU jets");
    p_PUJet->Run(jentry); //forest jets
	    
    //Execute all analysis tasks
    // handler->ExecuteTask();
  }
    
  fEventObjects->Print();

  TFile *out = new TFile(outname,"RECREATE");
  TList *tasks = handler->GetListOfTasks();
  TIter next(tasks);
  anaBaseTask *obj;
  while ((obj = dynamic_cast<anaBaseTask*>(next()) ))
    if(obj->GetOutput()) obj->GetOutput()->Write(obj->GetName(),TObject::kSingleKey);
  
  out->Write();
  out->Close();
  
}
Example #10
0
TChain* CreateESDChain(const char* aDataDir = "ESDfiles.txt", Int_t aRuns = 20, Int_t offset = 0, Bool_t addFileName = kFALSE, Bool_t addFriend = kFALSE, const char* check = 0)
{
  // creates chain of files in a given directory or file containing a list.
  // In case of directory the structure is expected as:
  // <aDataDir>/<dir0>/AliESDs.root
  // <aDataDir>/<dir1>/AliESDs.root
  // ...
  //
  // if addFileName is true the list only needs to contain the directories that contain the AliESDs.root files
  // if addFriend is true a file AliESDfriends.root is expected in the same directory and added to the chain as friend
  // if check is != 0 the files that work are written back into the textfile with the name check

  if (!aDataDir)
    return 0;

  Long_t id, size, flags, modtime;
  if (gSystem->GetPathInfo(aDataDir, &id, &size, &flags, &modtime))
  {
    printf("%s not found.\n", aDataDir);
    return 0;
  }

  TChain* chain = new TChain("esdTree");
  TChain* chainFriend = 0;
  
  if (addFriend)
    chainFriend = new TChain("esdFriendTree");

  if (flags & 2)
  {
    TString execDir(gSystem->pwd());
    TSystemDirectory* baseDir = new TSystemDirectory(".", aDataDir);
    TList* dirList            = baseDir->GetListOfFiles();
    Int_t nDirs               = dirList->GetEntries();
    gSystem->cd(execDir);

    Int_t count = 0;

    for (Int_t iDir=0; iDir<nDirs; ++iDir)
    {
      TSystemFile* presentDir = (TSystemFile*) dirList->At(iDir);
      if (!presentDir || !presentDir->IsDirectory() || strcmp(presentDir->GetName(), ".") == 0 || strcmp(presentDir->GetName(), "..") == 0)
        continue;

      if (offset > 0)
      {
        --offset;
        continue;
      }

      if (count++ == aRuns)
        break;

      TString presentDirName(aDataDir);
      presentDirName += "/";
      presentDirName += presentDir->GetName();

      chain->Add(presentDirName + "/AliESDs.root/esdTree");
    }
  }
  else
  {
    // Open the input stream
    ifstream in;
    in.open(aDataDir);

    ofstream outfile;
    if (check)
      outfile.open(check);

    Int_t count = 0;

    // Read the input list of files and add them to the chain
    TString line;
    while (in.good())
    {
      in >> line;

      if (line.Length() == 0)
        continue;

      if (offset > 0)
      {
        offset--;
        continue;
      }

      if (count++ == aRuns)
        break;

      TString esdFile(line);

      if (addFileName)
        esdFile += "/AliESDs.root";
        
      TString esdFileFriend(esdFile);
      esdFileFriend.ReplaceAll("AliESDs.root", "AliESDfriends.root");
        
      if (check)
      {
        TFile* file = TFile::Open(esdFile);
        if (!file)
          continue;
        file->Close();
        
        if (chainFriend)
        {
          TFile* file = TFile::Open(esdFileFriend);
          if (!file)
            continue;
          file->Close();
        }
        
        outfile << line.Data() << endl;
        printf("%s\n", line.Data());
      }        
        
        // add esd file
      chain->Add(esdFile);

        // add file
      if (chainFriend)
        chainFriend->Add(esdFileFriend);
    }

    in.close();
    
    if (check)
      outfile.close();
  }
  
  if (chainFriend)
    chain->AddFriend(chainFriend);

  return chain;
}
Example #11
0
void analyzeJES(std::vector<std::string> urls, const char *outname = "eventObjects.root", Long64_t nentries = 20, Int_t firstF = -1, Int_t lastF = -1, Int_t firstEvent = 0) {

  /*
    ptminType: minimum raw pt for particles used by puppi
    0 : 0 GeV
    1 : 1 GeV
    2 : 2 GeV

    jetSignalType: jets used to select jetty region in events
    0 : detector-level jets (akPu4PF)
    1 : particle-level jets (gen jets)
   */


  TString jetName = "aktPuppiR040";
  TString jetTreeName = "akPuppi4PFJetAnalyzer";
  jetName = "aktCsR040";
  jetTreeName = "akCs4PFJetAnalyzer";
  //jetName = "aktVsR040";
  //jetTreeName = "akVs4PFJetAnalyzer";

  std::cout << "analyzing JES for: " << jetName << " tree: " << jetTreeName << std::endl;
   
  std::cout << "nfiles: " << urls.size() << std::endl;
  for (auto i = urls.begin(); i != urls.end(); ++i)
    std::cout << *i << std::endl;

  size_t firstFile = 0;
  size_t lastFile = urls.size();

  if(firstF>-1) {
    firstFile = (size_t)firstF;
    lastFile = std::min((size_t)lastF,lastFile);
  }
  std::cout << "firstFile: " << firstFile << "  lastFile: " << lastFile << std::endl;

  Int_t lastEvent = nentries;
  if(firstEvent>0) {
    lastEvent = firstEvent + nentries;
  }
  std::cout << "firstEvent: " << firstEvent << std::endl;
  
  //add files to chain
  TChain *chain = NULL;
  chain = new TChain("hiEvtAnalyzer/HiTree");
  for(size_t i=firstFile; i<lastFile; i++) chain->Add(urls[i].c_str());
  Printf("hiTree done");
  
  TChain *jetTree = new TChain(Form("%s/t",jetTreeName.Data()));
  for(size_t i=firstFile; i<lastFile; i++) jetTree->Add(urls[i].c_str());
  chain->AddFriend(jetTree);
  Printf("jetTree done");

  TList *fEventObjects = new TList();

  //---------------------------------------------------------------
  // producers
  //
  hiEventProducer *p_evt = new hiEventProducer("hiEvtProd");
  p_evt->SetInput(chain);
  p_evt->SetHIEventContName("hiEventContainer");
  p_evt->SetEventObjects(fEventObjects);

  lwJetFromForestProducer *p_PUJet = new lwJetFromForestProducer("lwJetForestProd");
  p_PUJet->SetInput(chain);
  p_PUJet->SetJetContName(jetName);
  p_PUJet->SetGenJetContName("akt4Gen");
  p_PUJet->SetEventObjects(fEventObjects);
  p_PUJet->SetRadius(0.4);
  
  //---------------------------------------------------------------
  //analysis modules
  //

  //handler to which all modules will be added
  anaBaseTask *handler = new anaBaseTask("handler","handler");

  anaJetEnergyScale *anajesForest = new anaJetEnergyScale("anaJESForest","anaJESForest");
  anajesForest->ConnectEventObject(fEventObjects);
  anajesForest->SetHiEvtName("hiEventContainer");
  anajesForest->SetGenJetsName("akt4Gen");
  anajesForest->SetRecJetsName(jetName);
  anajesForest->SetNCentBins(4);
  anajesForest->SetUseForestMatching(true);
  //anajesForest->SetMaxDistance(0.2);
  handler->Add(anajesForest);

  anaJetEnergyScale *anajesForestQuarks = new anaJetEnergyScale("anaJESForestQuarks","anaJESForestQuarks");
  anajesForestQuarks->ConnectEventObject(fEventObjects);
  anajesForestQuarks->SetHiEvtName("hiEventContainer");
  anajesForestQuarks->SetGenJetsName("akt4Gen");
  anajesForestQuarks->SetRecJetsName(jetName);
  anajesForestQuarks->SetNCentBins(4);
  anajesForestQuarks->SetUseForestMatching(true);
  //anajesForestQuarks->SetMaxDistance(0.2);
  anajesForestQuarks->SetRefPartonFlavor(0,2);
  handler->Add(anajesForestQuarks);

  anaJetEnergyScale *anajesForestGluons = new anaJetEnergyScale("anaJESForestGluons","anaJESForestGluons");
  anajesForestGluons->ConnectEventObject(fEventObjects);
  anajesForestGluons->SetHiEvtName("hiEventContainer");
  anajesForestGluons->SetGenJetsName("akt4Gen");
  anajesForestGluons->SetRecJetsName(jetName);
  anajesForestGluons->SetNCentBins(4);
  anajesForestGluons->SetUseForestMatching(true);
  //anajesForestGluons->SetMaxDistance(0.2);
  anajesForestGluons->SetRefPartonFlavor(21,21);
  handler->Add(anajesForestGluons);
  
  anaJetEnergyScale *anajesForestRaw = new anaJetEnergyScale("anaJESForestRaw","anaJESForestRaw");
  anajesForestRaw->ConnectEventObject(fEventObjects);
  anajesForestRaw->SetHiEvtName("hiEventContainer");
  anajesForestRaw->SetGenJetsName("");
  anajesForestRaw->SetRecJetsName(jetName);
  anajesForestRaw->SetNCentBins(4);
  anajesForestRaw->SetUseForestMatching(true);
  anajesForestRaw->SetUseRawPt(true);
  //handler->Add(anajesForestRaw);

  //particle-detector-level jet matching
  anaJetMatching *match = new anaJetMatching("jetMatching","jetMatching");
  match->ConnectEventObject(fEventObjects);
  match->SetHiEvtName("hiEventContainer");
  //match->SetJetsNameBase(jetName);
  //match->SetJetsNameTag("akt4Gen");
  match->SetJetsNameTag(jetName);
  match->SetJetsNameBase("akt4Gen");
  match->SetMatchingType(0);
  //handler->Add(match);
  
  anaJetEnergyScale *anajes = new anaJetEnergyScale("anaJES","anaJES");
  anajes->ConnectEventObject(fEventObjects);
  anajes->SetHiEvtName("hiEventContainer");
  anajes->SetGenJetsName("akt4Gen");
  anajes->SetRecJetsName(jetName);
  anajes->SetNCentBins(4);
  //handler->Add(anajes);

  anaJetEnergyScale *anajesRaw = new anaJetEnergyScale("anaJESRaw","anaJESRaw");
  anajesRaw->ConnectEventObject(fEventObjects);
  anajesRaw->SetHiEvtName("hiEventContainer");
  anajesRaw->SetGenJetsName("akt4Gen");
  anajesRaw->SetRecJetsName(jetName);
  anajesRaw->SetNCentBins(4);
  anajesRaw->SetUseForestMatching(false);
  anajesRaw->SetUseRawPt(true);
  //handler->Add(anajesRaw);

 
  //---------------------------------------------------------------
  //Event loop
  //---------------------------------------------------------------
  Long64_t entries_tot =  chain->GetEntries(); //93064
  if(nentries<0) lastEvent = chain->GetEntries();
  Printf("nentries: %lld  tot: %lld",nentries,entries_tot);
  for (Long64_t jentry=firstEvent; jentry<lastEvent; ++jentry) {
    if(jentry%10000==0) cout << "entry: "<< jentry << endl;
    //Run producers
    //Printf("produce hiEvent");
    p_evt->Run(jentry);   //hi event properties
    //Printf("produce PU jets");
    p_PUJet->Run(jentry); //forest jets
	    
    //Execute all analysis tasks
    handler->ExecuteTask();
  }
    
  fEventObjects->Print();

  TFile *out = new TFile(outname,"RECREATE");
  TList *tasks = handler->GetListOfTasks();
  TIter next(tasks);
  anaBaseTask *obj;
  while ((obj = dynamic_cast<anaBaseTask*>(next()) ))
    if(obj->GetOutput()) obj->GetOutput()->Write(obj->GetName(),TObject::kSingleKey);
  
  out->Write();
  out->Close();
  
}
Example #12
0
void analyzeZJetMCResponse(std::vector<std::string> urls, const char *outname = "eventObjects.root", Long64_t nentries = 20, Int_t firstF = -1, Int_t lastF = -1, Int_t firstEvent = 0) {

  TString jetName = "aktPuppiR040";
  TString jetTreeName = "akPuppi4PFJetAnalyzer";
  jetName = "aktPuR030"; //"aktCsR040";
  jetTreeName = "akPu3PFJetAnalyzer"; //"akCs4PFJetAnalyzer"; //akCs4PFJetAnalyzer

  std::cout << "analyzing Z-jet response for: " << jetName << " tree: " << jetTreeName << std::endl;
  
  std::cout << "nfiles: " << urls.size() << std::endl;
  for (auto i = urls.begin(); i != urls.end(); ++i)
    std::cout << *i << std::endl;

  size_t firstFile = 0;
  size_t lastFile = urls.size();

  if(firstF>-1) {
    firstFile = (size_t)firstF;
    lastFile = (size_t)lastF;
  }
  std::cout << "firstFile: " << firstFile << "  lastFile: " << lastFile << std::endl;

  Int_t lastEvent = nentries;
  if(firstEvent>0) {
    lastEvent = firstEvent + nentries;
  }
  
  //add files to chain
  TChain *chain = NULL;
  chain = new TChain("hiEvtAnalyzer/HiTree");
  for(size_t i=firstFile; i<lastFile; i++) chain->Add(urls[i].c_str());
  Printf("hiTree done");

  // TChain *hltTree = new TChain("hltanalysis/HltTree");
  // for(size_t i=firstFile; i<lastFile; i++) hltTree->Add(urls[i].c_str());
  // chain->AddFriend(hltTree);
  // Printf("hltTree done");

  // TChain *skimTree = new TChain("skimanalysis/HltTree");
  // for(size_t i=firstFile; i<lastFile; i++) skimTree->Add(urls[i].c_str());
  // chain->AddFriend(skimTree);
  // Printf("skimTree done");

  // TChain *muTree = new TChain("ggHiNtuplizer/EventTree");
  // for(size_t i=firstFile; i<lastFile; i++) muTree->Add(urls[i].c_str());
  // chain->AddFriend(muTree);
  // Printf("muTree done");

  TChain *genTree = new TChain("HiGenParticleAna/hi");
  for(size_t i=firstFile; i<lastFile; i++) genTree->Add(urls[i].c_str());
  //chain->AddFriend(genTree);
  Printf("genTree done: %d",(int)genTree->GetEntries());

  TChain *jetTree = new TChain(Form("%s/t",jetTreeName.Data()));
  for(size_t i=firstFile; i<lastFile; i++) jetTree->Add(urls[i].c_str());
  chain->AddFriend(jetTree);
  Printf("jetTree done");

  TList *fEventObjects = new TList();

  //---------------------------------------------------------------
  // producers
  //
  hiEventProducer *p_evt = new hiEventProducer("hiEvtProd");
  p_evt->SetInput(chain);
  p_evt->SetHIEventContName("hiEventContainer");
  p_evt->SetEventObjects(fEventObjects);

  lwMuonProducer *p_mu = new lwMuonProducer("lwMuonProd");
  p_mu->SetInput(chain);
  p_mu->SetlwMuonsRecoName("lwMuonsReco");
  p_mu->SetlwMuonsGeneName("");
  p_mu->SetEventObjects(fEventObjects);

  genParticleProducer *p_gen = new genParticleProducer("genParticleProd");
  p_gen->SetInput(genTree);
  p_gen->SetGenParticlesName("genParticles");
  p_gen->SetEventObjects(fEventObjects);

  lwJetFromForestProducer *p_PUJet = new lwJetFromForestProducer("lwJetForestProd");
  p_PUJet->SetInput(chain);
  p_PUJet->SetJetContName(jetName);
  p_PUJet->SetGenJetContName("");//akt4Gen");
  p_PUJet->SetEventObjects(fEventObjects);
  p_PUJet->SetRadius(0.4);

  //---------------------------------------------------------------
  //analysis modules
  //

  //handler to which all modules will be added
  anaBaseTask *handler = new anaBaseTask("handler","handler");

  //Z to mumu
  anaZToMuMu *ZToMuMu = new anaZToMuMu("ZToMuMu","ZToMuMu");
  ZToMuMu->ConnectEventObject(fEventObjects);
  ZToMuMu->SetHiEvtName("hiEventContainer");
  ZToMuMu->SetMuonsName("genParticles");
  ZToMuMu->SetCheckPid(true);
  ZToMuMu->SetZsName("zMuMuBosons");
  handler->Add(ZToMuMu);

  anaZJetMCResponse *ZResp = new anaZJetMCResponse("ZJetMCResponse","ZJetMCResponse");
  ZResp->ConnectEventObject(fEventObjects);
  ZResp->SetHiEvtName("hiEventContainer");
  ZResp->SetZsName("zMuMuBosons");
  ZResp->SetJetsName(jetName);
  ZResp->SetNCentBins(3);
  handler->Add(ZResp);


 //---------------------------------------------------------------
  //Event loop
  //---------------------------------------------------------------	  
  Long64_t entries_tot =  chain->GetEntriesFast(); //93064
  if(nentries<0) lastEvent = chain->GetEntries();
  // Long64_t nentries = 20;//chain->GetEntriesFast();
  Printf("nentries: %lld  tot: %lld",nentries,entries_tot);
  for (Long64_t jentry=firstEvent; jentry<lastEvent; ++jentry) {
     if (jentry%10000==0) Printf("Processing event %d  %d",(int)(jentry), (int)(lastEvent));
    //Run producers
    // Printf("produce hiEvent");
    p_evt->Run(jentry);   //hi event properties

    //Printf("produce pf particles");
    p_gen->Run(jentry);   //gen particles
    p_PUJet->Run(jentry); //jets
    
    //Execute all analysis tasks
    handler->ExecuteTask();
  }
    
  fEventObjects->Print();

  TFile *out = new TFile(outname,"RECREATE");
  TList *tasks = handler->GetListOfTasks();
  TIter next(tasks);
  anaBaseTask *obj;
  while ((obj = dynamic_cast<anaBaseTask*>(next()) ))
    if(obj->GetOutput()) obj->GetOutput()->Write(obj->GetName(),TObject::kSingleKey);
  
  out->Write();
  out->Close();
  
}
void plotPFRandomCone(TString str = "forest.root", Int_t nRCPerEvent = 1, int maxEvents = -1) {

  // gStyle->SetOptStat(0000);
  // gStyle->SetOptTitle(0);

  double minEta = -1.5;
  double maxEta = 1.5;
  double minPhi = -TMath::Pi();
  double maxPhi = TMath::Pi();
  double radiusRC = 0.4;
  
  TChain *fChain = new TChain("hiEvtAnalyzer/HiTree");
  TChain *pfTree = new TChain("pfcandAnalyzer/pfTree");
  TChain *skimTree = new TChain("skimanalysis/HltTree");
  TChain *hltTree = new TChain("hltanalysis/HltTree");
  //  TFile *f = TFile::Open(str.Data());
  fChain->Add(str.Data());
  pfTree->Add(str.Data());
  skimTree->Add(str.Data());
  hltTree->Add(str.Data());
  fChain->AddFriend(pfTree);
  fChain->AddFriend(skimTree);
  fChain->AddFriend(hltTree);
  
  if(!fChain) {
    Printf("Couldn't find pfTree. Aborting!");
    return;
  }

  Int_t MinBiasTriggerBit;
  Int_t phfCoincFilter;
  
  Int_t           hiBin;
  TBranch        *b_hiBin;   //!
  fChain->SetBranchAddress("hiBin", &hiBin, &b_hiBin);
  fChain->SetBranchAddress("HLT_HIL1MinimumBiasHF1ANDExpress_v1",&MinBiasTriggerBit);
  fChain->SetBranchAddress("phfCoincFilter3",&phfCoincFilter);
  
  ForestPFs                    fPFs;              //!PFs in tree
  if (fChain->GetBranch("nPFpart"))
    fChain->SetBranchAddress("nPFpart", &fPFs.nPFpart, &fPFs.b_nPFpart);
  if (fChain->GetBranch("pfId"))
    fChain->SetBranchAddress("pfId", fPFs.pfId, &fPFs.b_pfId);
  if (fChain->GetBranch("pfPt"))
    fChain->SetBranchAddress("pfPt", fPFs.pfPt, &fPFs.b_pfPt);
  if (fChain->GetBranch("pfVsPtInitial"))
    fChain->SetBranchAddress("pfVsPtInitial", fPFs.pfVsPt, &fPFs.b_pfVsPt);
  if (fChain->GetBranch("pfEta"))
    fChain->SetBranchAddress("pfEta", fPFs.pfEta, &fPFs.b_pfEta);
  if (fChain->GetBranch("pfPhi"))
    fChain->SetBranchAddress("pfPhi", fPFs.pfPhi, &fPFs.b_pfPhi);

  //Printf("nentries: %d",(Int_t)fChain->GetEntries());

  TList *fOutput =  new TList();
  TH1::SetDefaultSumw2();
  
  TH3D *h2CentPtRCEta = new TH3D("h2CentPtRCEta","h2CentPtRCEta;centrality;p_{T,RC};#eta",100,0,100,250,-50.,200.,60,-6,6);
  fOutput->Add(h2CentPtRCEta);
  TH3D *h2CentPtRCEtaVS = new TH3D("h2CentPtRCEtaVS","h2CentPtRCEtaVS;centrality;p_{T,RC}^{VS};#eta",100,0,100,250,-50.,200.,60,-6,6);
  fOutput->Add(h2CentPtRCEtaVS);

  TH3D *h2MultPtRCEta = new TH3D("h2MultPtRCEta","h2MultPtRCEta;centrality;p_{T,RC};#eta",3000,0,6000,150,-50.,100.,60,-6,6);
  fOutput->Add(h2MultPtRCEta);
  TH3D *h2MultPtRCEtaVS = new TH3D("h2MultPtRCEtaVS","h2MultPtRCEtaVS;centrality;p_{T,RC}^{VS};#eta",3000,0,6000,150,-50.,100.,60,-6,6);
  fOutput->Add(h2MultPtRCEtaVS);
  Printf("histos defined");

  Int_t startEntry = 0;
  Int_t lastEntry = fChain->GetEntries();//100;
  Printf("events in chain: %d",lastEntry);
  if(maxEvents<lastEntry)
    lastEntry = maxEvents;
  Printf("lastEntry: %d",lastEntry);

  TRandom3 *rnd = new TRandom3();
 
  for (int j=startEntry; j<lastEntry; j++) {
    fChain->GetEntry(j);
    if(j%100==0) std::cout << "entry: "<< j << std::endl;
    //if(!MinBiasTriggerBit) continue;
    if(!phfCoincFilter) continue;
    
    double etaRC = rnd->Rndm() * (maxEta - minEta) + minEta;
    double phiRC = rnd->Rndm() * (maxPhi - minPhi) + minPhi;

    double ptRC = 0.;
    double ptRCVS = 0.;
    Int_t pfCount = 0;
    for(Int_t i = 0; i<fPFs.nPFpart; i++) {
      double pt = fPFs.pfPt[i];
      double ptVS = fPFs.pfVsPt[i];
      double phi = fPFs.pfPhi[i];
      double eta = fPFs.pfEta[i];

      double dr = deltaR(phi,phiRC,eta,etaRC);
      if(dr<radiusRC) {
        ptRC+=pt;
        ptRCVS+=ptVS;
      }

      if(abs(eta)<2.) pfCount++;
      
    }
    Double_t cent = (Double_t)hiBin/2.;
    h2CentPtRCEta->Fill(cent,ptRC,etaRC);
    h2CentPtRCEtaVS->Fill(cent,ptRCVS,etaRC);

    h2MultPtRCEta->Fill(pfCount,ptRC,etaRC);
    h2MultPtRCEtaVS->Fill(pfCount,ptRCVS,etaRC);
  }

  TFile *fout = new TFile("RandomCones.root","RECREATE");
  fOutput->Write();
  fout->Write();
  fout->Close();
}
void analyzeZgHistos(std::vector<std::string> urls, const char *outname = "eventObjects.root", Long64_t nentries = 20, Int_t firstF = -1, Int_t lastF = -1, Int_t firstEvent = 0, int activateJetShift = 0) {

  /*
    ptminType: minimum raw pt for particles used by puppi
    0 : 0 GeV
    1 : 1 GeV
    2 : 2 GeV

    jetSignalType: jets used to select jetty region in events
    0 : detector-level jets (akPu4PF)
    1 : particle-level jets (gen jets)
   */

  TString jetSDName = "aktCs4PFSoftDrop";
  TString jetTreeSDName = "akCsSoftDrop4PFJetAnalyzer";//"akCs4PFSoftDropJetAnalyzer";//
  TString jetName = "aktPu4Calo";
  TString jetTreeName = "akPu4CaloJetAnalyzer";

  bool doDRVar = false;

  bool doJetShift = false;
  if(activateJetShift>0) doJetShift = true;
  float jetShift = 0.04;
  if(activateJetShift==1) jetShift = 0.04;
  if(activateJetShift==2) jetShift = -0.04;

  double minptjet = 30.;
  //bool doDijet = false;
  //if(!doDijet) minptjet = 80.;

  std::cout << "analyzing subjets for: " << jetName << " tree: " << jetTreeName << std::endl;
  std::cout << "analyzing subjets for: " << jetSDName << " tree: " << jetTreeSDName << std::endl;
   
  std::cout << "nfiles: " << urls.size() << std::endl;
  for (auto i = urls.begin(); i != urls.end(); ++i)
    std::cout << *i << std::endl;

  size_t firstFile = 0;
  size_t lastFile = urls.size();

  if(firstF>-1) {
    firstFile = (size_t)firstF;
    lastFile = std::min((size_t)lastF,lastFile);
  }
  std::cout << "firstFile: " << firstFile << "  lastFile: " << lastFile << std::endl;

  Int_t lastEvent = nentries;
  if(firstEvent>0) {
    lastEvent = firstEvent + nentries;
  }
  std::cout << "firstEvent: " << firstEvent << std::endl;
  
  //add files to chain
  TChain *chain = NULL;
  chain = new TChain("hiEvtAnalyzer/HiTree");
  for(size_t i=firstFile; i<lastFile; i++) chain->Add(urls[i].c_str());
  Printf("hiTree done");

  TChain *skimTree = new TChain("skimanalysis/HltTree");
  for(size_t i=firstFile; i<lastFile; i++) skimTree->Add(urls[i].c_str());
  chain->AddFriend(skimTree);
  Printf("skimTree done");

  TChain *hltTree = new TChain("hltanalysis/HltTree");
  for(size_t i=firstFile; i<lastFile; i++) hltTree->Add(urls[i].c_str());
  chain->AddFriend(hltTree);
  Printf("hltTree done");

  TChain *jetTreeSD = new TChain(Form("%s/t",jetTreeSDName.Data()));
  for(size_t i=firstFile; i<lastFile; i++) jetTreeSD->Add(urls[i].c_str());
  chain->AddFriend(jetTreeSD);
  Printf("jetTreeSD done");

  TChain *jetTree = new TChain(Form("%s/t",jetTreeName.Data()));
  for(size_t i=firstFile; i<lastFile; i++) jetTree->Add(urls[i].c_str());
  Printf("jetTree done");

  TChain *rhoTree = new TChain("hiFJRhoAnalyzer/t");
  for(size_t i=firstFile; i<lastFile; i++) rhoTree->Add(urls[i].c_str());
  chain->AddFriend(rhoTree);
  
  TList *fEventObjects = new TList();

  //---------------------------------------------------------------
  // producers
  //
  hiEventProducer *p_evt = new hiEventProducer("hiEvtProd");
  p_evt->SetInput(chain);
  p_evt->SetHIEventContName("hiEventContainer");
  p_evt->SetEventObjects(fEventObjects);

  triggerProducer *p_trg = new triggerProducer("trigProd");
  p_trg->SetInput(chain);
  p_trg->SetTriggerMapName("triggerMap");
  p_trg->AddTrigger("HLT_HIPuAK4CaloJet100_Eta5p1_v1");
  p_trg->AddTrigger("HLT_HIPuAK4CaloJet100_Eta5p1_Cent30_100_v1");
  p_trg->SetEventObjects(fEventObjects);

  lwJetFromForestProducer *p_SDJet = new lwJetFromForestProducer("lwJetForestProdSD");
  p_SDJet->SetInput(chain);
  p_SDJet->SetJetContName(jetSDName);
  p_SDJet->SetGenJetContName("");
  p_SDJet->SetEventObjects(fEventObjects);
  p_SDJet->SetMinJetPt(minptjet);
  p_SDJet->SetRadius(0.4);

  lwJetFromForestProducer *p_Jet = new lwJetFromForestProducer("lwJetForestProd");
  p_Jet->SetInput(jetTree);
  p_Jet->SetJetContName(jetName);
  p_Jet->SetGenJetContName("akt4Gen");
  p_Jet->SetEventObjects(fEventObjects);
  p_Jet->SetMinJetPt(minptjet);
  p_Jet->SetRadius(0.4);
  
  //---------------------------------------------------------------
  //analysis modules
  //

  //handler to which all modules will be added
  anaBaseTask *handler = new anaBaseTask("handler","handler");

  anaJetQA *jetQA = new anaJetQA("anaJetQA","anaJetQA");
  jetQA->ConnectEventObject(fEventObjects);
  jetQA->SetJetsName(jetName);
  jetQA->SetTriggerMapName("triggerMap");
  jetQA->AddTriggerSel("HLT_HIPuAK4CaloJet100_Eta5p1_v1");
  jetQA->AddTriggerSel("HLT_HIPuAK4CaloJet100_Eta5p1_Cent30_100_v1");
  handler->Add(jetQA);

  anaJetMatching *match = new anaJetMatching("jetMatching","jetMatching");
  match->ConnectEventObject(fEventObjects);
  match->SetHiEvtName("hiEventContainer");
  match->SetTriggerMapName("triggerMap");
  match->AddTriggerSel("HLT_HIPuAK4CaloJet100_Eta5p1_v1");
  match->AddTriggerSel("HLT_HIPuAK4CaloJet100_Eta5p1_Cent30_100_v1");
  match->SetJetsNameBase(jetName);
  match->SetJetsNameTag(jetSDName);
  match->SetMatchingType(0);
  handler->Add(match);

  anaZgHistos *anazghistos = new anaZgHistos("anaZgHistos","anaZgHistos");
  anazghistos->ConnectEventObject(fEventObjects);
  anazghistos->SetHiEvtName("hiEventContainer");
  anazghistos->DoCollisionEventSel(true);
  anazghistos->DoHBHENoiseFilter(true);
  anazghistos->DoHBHENoiseFilterLoose(true);
  anazghistos->DoPrimaryVertexFilter(true);
  anazghistos->DoClusterCompatibilityFilter(true);
  anazghistos->DoHFCoincFilter(true);
  anazghistos->SetTriggerMapName("triggerMap");
  anazghistos->AddTriggerSel("HLT_HIPuAK4CaloJet100_Eta5p1_v1");
  anazghistos->AddTriggerSel("HLT_HIPuAK4CaloJet100_Eta5p1_Cent30_100_v1");
  anazghistos->SetRhoMax(330.);
  anazghistos->SetJetsName(jetSDName);
  anazghistos->SetJetsRefName(jetName);
  anazghistos->SetNCentBins(4);
  anazghistos->SetJetEtaRange(-1.3,1.3);
  anazghistos->SetDeltaRRange(0.1,999.);
  anazghistos->DoJetShift(doJetShift,jetShift);
  handler->Add(anazghistos);

  anaZgHistos *anazghistosdrSmall = new anaZgHistos("anaZgHistosDrSmall","anaZgHistosDrSmall");
  anazghistosdrSmall->ConnectEventObject(fEventObjects);
  anazghistosdrSmall->SetHiEvtName("hiEventContainer");
  anazghistosdrSmall->DoCollisionEventSel(true);
  anazghistosdrSmall->DoHBHENoiseFilter(true);
  anazghistosdrSmall->DoHBHENoiseFilterLoose(true);
  anazghistosdrSmall->DoPrimaryVertexFilter(true);
  anazghistosdrSmall->DoClusterCompatibilityFilter(true);
  anazghistosdrSmall->DoHFCoincFilter(true);
  anazghistosdrSmall->SetTriggerMapName("triggerMap");
  anazghistosdrSmall->AddTriggerSel("HLT_HIPuAK4CaloJet100_Eta5p1_v1");
  anazghistosdrSmall->AddTriggerSel("HLT_HIPuAK4CaloJet100_Eta5p1_Cent30_100_v1");
  anazghistosdrSmall->SetRhoMax(330.);
  anazghistosdrSmall->SetJetsName(jetSDName);
  anazghistosdrSmall->SetJetsRefName(jetName);
  anazghistosdrSmall->SetNCentBins(4);
  anazghistosdrSmall->SetJetEtaRange(-1.3,1.3);
  anazghistosdrSmall->SetDeltaRRange(0.1,0.2);
  anazghistosdrSmall->DoJetShift(doJetShift,jetShift);
  handler->Add(anazghistosdrSmall);

  anaZgHistos *anazghistosdrLarge = new anaZgHistos("anaZgHistosDrLarge","anaZgHistosDrLarge");
  anazghistosdrLarge->ConnectEventObject(fEventObjects);
  anazghistosdrLarge->SetHiEvtName("hiEventContainer");
  anazghistosdrLarge->DoCollisionEventSel(true);
  anazghistosdrLarge->DoHBHENoiseFilter(true);
  anazghistosdrLarge->DoHBHENoiseFilterLoose(true);
  anazghistosdrLarge->DoPrimaryVertexFilter(true);
  anazghistosdrLarge->DoClusterCompatibilityFilter(true);
  anazghistosdrLarge->DoHFCoincFilter(true);
  anazghistosdrLarge->SetTriggerMapName("triggerMap");
  anazghistosdrLarge->AddTriggerSel("HLT_HIPuAK4CaloJet100_Eta5p1_v1");
  anazghistosdrLarge->AddTriggerSel("HLT_HIPuAK4CaloJet100_Eta5p1_Cent30_100_v1");
  anazghistosdrLarge->SetRhoMax(330.);
  anazghistosdrLarge->SetJetsName(jetSDName);
  anazghistosdrLarge->SetJetsRefName(jetName);
  anazghistosdrLarge->SetNCentBins(4);
  anazghistosdrLarge->SetJetEtaRange(-1.3,1.3);
  anazghistosdrLarge->SetDeltaRRange(0.2,999.);
  anazghistosdrLarge->DoJetShift(doJetShift,jetShift);
  handler->Add(anazghistosdrLarge);

  if(doDRVar) {
    anaZgHistos *anazghistosDRVarDown = new anaZgHistos("anaZgHistosDrVarDown","anaZgHistosDrVarDown");
    anazghistosDRVarDown->ConnectEventObject(fEventObjects);
    anazghistosDRVarDown->SetHiEvtName("hiEventContainer");
    anazghistosDRVarDown->DoCollisionEventSel(true);
    anazghistosDRVarDown->DoHBHENoiseFilter(true);
    anazghistosDRVarDown->DoHBHENoiseFilterLoose(true);
    anazghistosDRVarDown->DoPrimaryVertexFilter(true);
    anazghistosDRVarDown->DoClusterCompatibilityFilter(true);
    anazghistosDRVarDown->DoHFCoincFilter(true);
    anazghistosDRVarDown->SetTriggerMapName("triggerMap");
    anazghistosDRVarDown->AddTriggerSel("HLT_HIPuAK4CaloJet100_Eta5p1_v1");
    anazghistosDRVarDown->AddTriggerSel("HLT_HIPuAK4CaloJet100_Eta5p1_Cent30_100_v1");
    anazghistosDRVarDown->SetRhoMax(330.);
    anazghistosDRVarDown->SetJetsName(jetSDName);
    anazghistosDRVarDown->SetJetsRefName(jetName);
    anazghistosDRVarDown->SetNCentBins(4);
    anazghistosDRVarDown->SetJetEtaRange(-1.3,1.3);
    anazghistosDRVarDown->SetDeltaRRange(0.1*0.85,999.);
    anazghistosDRVarDown->DoJetShift(doJetShift,jetShift);
    handler->Add(anazghistosDRVarDown);

    anaZgHistos *anazghistosDRVarUp = new anaZgHistos("anaZgHistosDrVarUp","anaZgHistosDrVarUp");
    anazghistosDRVarUp->ConnectEventObject(fEventObjects);
    anazghistosDRVarUp->SetHiEvtName("hiEventContainer");
    anazghistosDRVarUp->DoCollisionEventSel(true);
    anazghistosDRVarUp->DoHBHENoiseFilter(true);
    anazghistosDRVarUp->DoHBHENoiseFilterLoose(true);
    anazghistosDRVarUp->DoPrimaryVertexFilter(true);
    anazghistosDRVarUp->DoClusterCompatibilityFilter(true);
    anazghistosDRVarUp->DoHFCoincFilter(true);
    anazghistosDRVarUp->SetTriggerMapName("triggerMap");
    anazghistosDRVarUp->AddTriggerSel("HLT_HIPuAK4CaloJet100_Eta5p1_v1");
    anazghistosDRVarUp->AddTriggerSel("HLT_HIPuAK4CaloJet100_Eta5p1_Cent30_100_v1");
    anazghistosDRVarUp->SetRhoMax(330.);
    anazghistosDRVarUp->SetJetsName(jetSDName);
    anazghistosDRVarUp->SetJetsRefName(jetName);
    anazghistosDRVarUp->SetNCentBins(4);
    anazghistosDRVarUp->SetJetEtaRange(-1.3,1.3);
    anazghistosDRVarUp->SetDeltaRRange(0.1*1.15,999.);
    anazghistosDRVarUp->DoJetShift(doJetShift,jetShift);
    handler->Add(anazghistosDRVarUp);
  }

  //---------------------------------------------------------------
  //Event loop
  //---------------------------------------------------------------
  Long64_t entries_tot =  chain->GetEntries(); //93064
  if(nentries<0) lastEvent = chain->GetEntries();
  Printf("nentries: %lld  tot: %lld",nentries,entries_tot);
  for (Long64_t jentry=firstEvent; jentry<lastEvent; ++jentry) {
    if(jentry%10000==0) cout << "entry: "<< jentry << endl;
    //Run producers
    //Printf("produce hiEvent");
    p_evt->Run(jentry);   //hi event properties
    p_trg->Run(jentry);
    //Printf("produce jets");
    p_SDJet->Run(jentry); //forest SoftDrop jets
    p_Jet->Run(jentry); //forest jets

    //Execute all analysis tasks
    handler->ExecuteTask();
  }
    
  fEventObjects->Print();

  TFile *out = new TFile(outname,"RECREATE");
  TList *tasks = handler->GetListOfTasks();
  TIter next(tasks);
  anaBaseTask *obj;
  while ((obj = dynamic_cast<anaBaseTask*>(next()) ))
    if(obj->GetOutput()) obj->GetOutput()->Write(obj->GetName(),TObject::kSingleKey);
  
  out->Write();
  out->Close();
  
}
Example #15
0
std::pair<TString,TString> TMVAClassification (
    TString infilename,
    AnalysisType analysisType = AnalysisType::DIRECT,
    TString additionalRootFileName = "")
{
    TMVA::Tools::Instance();

    std::string tmstr (now ());
    TString tmstmp (tmstr.c_str ());
   
  
    std::cout << "==> Start TMVAClassification" << std::endl;
    std::cout << "-------------------- open input file ---------------- " << std::endl;
    TString fname = infilename; //pathToData + infilename + TString (".root");
    if (analysisType != AnalysisType::TRANSFORMED)
        fname = pathToData + infilename + TString (".root");
    std::cout << "open file " << std::endl << fname.Data () << std::endl;


    std::cout << "-------------------- get tree ---------------- " << std::endl;
    TString treeName = "data";
    if (analysisType == AnalysisType::TRANSFORMED)
        treeName = "transformed";

    std::cout << "-------------------- create tchain with treeName ---------------- " << std::endl;
    std::cout << treeName << std::endl;
    TChain* tree = new TChain (treeName);
    std::cout << "add file" << std::endl;
    std::cout << fname << std::endl;
    tree->Add (fname);
    TChain* treeFriend (NULL);
    if (additionalRootFileName.Length () > 0)
    {
        std::cout << "-------------------- add additional input file ---------------- " << std::endl;
        std::cout << additionalRootFileName << std::endl;
        treeFriend = new TChain (treeName);
        treeFriend->Add (additionalRootFileName);
        tree->AddFriend (treeFriend,"p");
    }
//    tree->Draw ("mass:prediction");
//    return std::make_pair(TString("hallo"),TString ("nix"));
    TString outfileName;
    if (analysisType == AnalysisType::BACKGROUND)
    {
        outfileName = TString ("BACK_" + infilename) + tmstmp + TString (".root");
    }
    else
        outfileName += TString ( "TMVA__" ) + tmstmp + TString (".root");

    std::cout << "-------------------- open output file ---------------- " << std::endl;
    TFile* outputFile = TFile::Open( outfileName, "RECREATE" );

    std::cout << "-------------------- prepare factory ---------------- " << std::endl;
    TMVA::Factory *factory = new TMVA::Factory( "TMVAClassification", outputFile,
						"AnalysisType=Classification:Transformations=I:!V" );
    std::cout << "-------------------- add variables ---------------- " << std::endl;


    for (auto varname : variableNames)
    {
	factory->AddVariable (varname.c_str (), 'F');
    }

    for (auto varname : spectatorNames)
    {
	factory->AddSpectator (varname.c_str (), 'F');
    }
    
   
    std::cout << "-------------------- add trees ---------------- " << std::endl;
    TCut signalCut ("signal==1");
    TCut backgroundCut ("signal==0");
    if (analysisType == AnalysisType::TRANSFORMED)
    {
        signalCut = "(signal_original==1 && signal_in==0)";
        backgroundCut = "(signal_original==0 && signal_in==0)";
    }
    if (analysisType == AnalysisType::BACKGROUND)
    {
        signalCut     = TString("(signal==0) * (prediction > 0.7)");
        backgroundCut = TString("(signal==0) * (prediction < 0.4)");
    }
    //tree->Draw ("prediction",signalCut);
    //return std::make_pair(TString("hallo"),TString ("nix"));
    factory->AddTree(tree, "Signal", 1.0, baseCut + signalCut, "TrainingTesting");
    factory->AddTree(tree, "Background", 1.0, baseCut + backgroundCut, "TrainingTesting");


    
    TCut mycuts = ""; // for example: TCut mycuts = "abs(var1)<0.5 && abs(var2-0.5)<1";
    TCut mycutb = ""; // for example: TCut mycutb = "abs(var1)<0.5";

    /* // Set individual event weights (the variables must exist in the original TTree) */
    if (analysisType == AnalysisType::BACKGROUND)
    {
        factory->SetSignalWeightExpression ("prediction");
        factory->SetBackgroundWeightExpression ("1");
    }

   
    std::cout << "-------------------- prepare ---------------- " << std::endl;
    factory->PrepareTrainingAndTestTree( mycuts, mycutb,
					 "nTrain_Signal=0:nTrain_Background=0:nTest_Signal=0:nTest_Background=0:SplitMode=Random:NormMode=NumEvents:!V" );


    TString methodName ("");
    if (analysisType == AnalysisType::BACKGROUND)
        methodName = TString ("TONBKG_") + tmstmp;

    if (false)
    {
	// gradient boosting training
        methodName += TString("GBDT");
	factory->BookMethod(TMVA::Types::kBDT, methodName,
			    "NTrees=40:BoostType=Grad:Shrinkage=0.01:MaxDepth=7:UseNvars=6:nCuts=20:MinNodeSize=10");
    }
    if (false)
    {
        methodName += TString("Likelihood");
	factory->BookMethod( TMVA::Types::kLikelihood, methodName,
			     "H:!V:TransformOutput:PDFInterpol=Spline2:NSmoothSig[0]=20:NSmoothBkg[0]=20:NSmoothBkg[1]=10:NSmooth=1:NAvEvtPerBin=50" );
    }
    

    
    if (false)
    {
	TString layoutString ("Layout=TANH|100,LINEAR");

	TString training0 ("LearningRate=1e-1,Momentum=0.0,Repetitions=1,ConvergenceSteps=300,BatchSize=20,TestRepetitions=15,WeightDecay=0.001,Regularization=NONE,DropConfig=0.0+0.5+0.5+0.5,DropRepetitions=1,Multithreading=True");
	TString training1 ("LearningRate=1e-2,Momentum=0.5,Repetitions=1,ConvergenceSteps=300,BatchSize=30,TestRepetitions=7,WeightDecay=0.001,Regularization=L2,Multithreading=True,DropConfig=0.0+0.1+0.1+0.1,DropRepetitions=1");
	TString training2 ("LearningRate=1e-2,Momentum=0.3,Repetitions=1,ConvergenceSteps=300,BatchSize=40,TestRepetitions=7,WeightDecay=0.0001,Regularization=L2,Multithreading=True");
	TString training3 ("LearningRate=1e-3,Momentum=0.1,Repetitions=1,ConvergenceSteps=200,BatchSize=70,TestRepetitions=7,WeightDecay=0.0001,Regularization=NONE,Multithreading=True");

	TString trainingStrategyString ("TrainingStrategy=");
	trainingStrategyString += training0 + "|" + training1 + "|" + training2 + "|" + training3;
      
	TString nnOptions ("!H:V:ErrorStrategy=CROSSENTROPY:VarTransform=G:WeightInitialization=XAVIERUNIFORM");
	nnOptions.Append (":"); nnOptions.Append (layoutString);
	nnOptions.Append (":"); nnOptions.Append (trainingStrategyString);

        methodName += TString("NNgauss");
	factory->BookMethod( TMVA::Types::kNN, methodName, nnOptions ); // NN
    }

    if (false)
    {
	TString layoutString ("Layout=TANH|200,TANH|70,LINEAR");

	TString training0 ("LearningRate=1e-2,Momentum=0.0,Repetitions=1,ConvergenceSteps=300,BatchSize=20,TestRepetitions=15,WeightDecay=0.001,Regularization=NONE,DropConfig=0.0+0.5+0.5+0.5,DropRepetitions=1,Multithreading=True");
	TString training1 ("LearningRate=1e-3,Momentum=0.5,Repetitions=1,ConvergenceSteps=300,BatchSize=30,TestRepetitions=7,WeightDecay=0.001,Regularization=L2,Multithreading=True,DropConfig=0.0+0.1+0.1+0.1,DropRepetitions=1");
	TString training2 ("LearningRate=1e-4,Momentum=0.3,Repetitions=1,ConvergenceSteps=300,BatchSize=40,TestRepetitions=7,WeightDecay=0.0001,Regularization=L2,Multithreading=True");
	TString training3 ("LearningRate=1e-5,Momentum=0.1,Repetitions=1,ConvergenceSteps=200,BatchSize=70,TestRepetitions=7,WeightDecay=0.0001,Regularization=NONE,Multithreading=True");

	TString trainingStrategyString ("TrainingStrategy=");
	trainingStrategyString += training0 + "|" + training1 + "|" + training2 + "|" + training3;
//	trainingStrategyString += training0 + "|" + training2 + "|" + training3;
//	trainingStrategyString += training0 + "|" + training2;

      
	//       TString nnOptions ("!H:V:VarTransform=Normalize:ErrorStrategy=CROSSENTROPY");
	TString nnOptions ("!H:V:ErrorStrategy=CROSSENTROPY:VarTransform=N:WeightInitialization=XAVIERUNIFORM");
	//       TString nnOptions ("!H:V:VarTransform=Normalize:ErrorStrategy=CHECKGRADIENTS");
	nnOptions.Append (":"); nnOptions.Append (layoutString);
	nnOptions.Append (":"); nnOptions.Append (trainingStrategyString);

        methodName = TString("NNnormalized");
        factory->BookMethod( TMVA::Types::kNN, methodName, nnOptions ); // NN
    }


    if (true)
    {
	TString layoutString ("Layout=TANH|100,TANH|50,LINEAR");

	TString training0 ("LearningRate=1e-2,Momentum=0.0,Repetitions=1,ConvergenceSteps=100,BatchSize=20,TestRepetitions=7,WeightDecay=0.001,Regularization=NONE,DropConfig=0.0+0.5+0.5+0.5,DropRepetitions=1,Multithreading=True");
	TString training1 ("LearningRate=1e-3,Momentum=0.0,Repetitions=1,ConvergenceSteps=20,BatchSize=30,TestRepetitions=7,WeightDecay=0.001,Regularization=L2,Multithreading=True,DropConfig=0.0+0.1+0.1+0.1,DropRepetitions=1");
	TString training2 ("LearningRate=1e-4,Momentum=0.0,Repetitions=1,ConvergenceSteps=20,BatchSize=40,TestRepetitions=7,WeightDecay=0.0001,Regularization=L2,Multithreading=True");
	TString training3 ("LearningRate=1e-5,Momentum=0.0,Repetitions=1,ConvergenceSteps=30,BatchSize=70,TestRepetitions=7,WeightDecay=0.0001,Regularization=NONE,Multithreading=True");

	TString trainingStrategyString ("TrainingStrategy=");
	trainingStrategyString += training0 + "|" + training1 + "|" + training2 + "|" + training3;

      
	TString nnOptions ("!H:!V:ErrorStrategy=CROSSENTROPY:VarTransform=P+G:WeightInitialization=XAVIERUNIFORM");
	nnOptions.Append (":"); nnOptions.Append (layoutString);
	nnOptions.Append (":"); nnOptions.Append (trainingStrategyString);

        methodName += TString("NNPG");
	factory->BookMethod( TMVA::Types::kNN, methodName, nnOptions ); // NN
    }
   
   
   
    factory->TrainAllMethods();
//    return std::make_pair(TString("hallo"),TString ("nix"));
    factory->TestAllMethods();
    factory->EvaluateAllMethods();

    //input->Close();
    outputFile->Close();

//    TMVA::TMVAGui (outfileName);
   
    delete factory;
    delete tree;
    switch (analysisType)
    {
    case AnalysisType::BACKGROUND:
        std::cout << "DONE BACKGROUND" << std::endl;
        break;
    case AnalysisType::DIRECT:
        std::cout << "DONE DIRECT" << std::endl;
        break;
    case AnalysisType::TRANSFORMED:
        std::cout << "DONE TRANSFORMED" << std::endl;
        break;
        
    };
    std::cout << "classification, return : " << outfileName << "  ,  " << methodName << std::endl;
    return std::make_pair (outfileName, methodName);
}
Example #16
0
void plotZC(int run, int startEntry, int numEntries) {
  gSystem->Load("libAnitaEvent.so");

  char eventName[FILENAME_MAX];
  char headerName[FILENAME_MAX];
  char hkName[FILENAME_MAX];
  sprintf(eventName,"/unix/anita1/webData/firstDay/run%d/eventFile%d*.root",run,run);
  sprintf(headerName,"/unix/anita1/webData/firstDay/run%d/timedHeadFile%d.root",run,run);
  sprintf(hkName,"/unix/anita1/webData/firstDay/run%d/prettyHkFile%d.root",run,run);

  RawAnitaEvent *event = 0;
  TimedAnitaHeader *header =0;
  PrettyAnitaHk *hk = 0;
  
  TChain *eventChain = new TChain("eventTree");
  eventChain->Add(eventName);
  eventChain->SetBranchAddress("event",&event);

  TFile *fpHead = new TFile(headerName);
  TTree *headTree = (TTree*) fpHead->Get("headTree");
  headTree->SetBranchAddress("header",&header);

  TFile *fpHk = new TFile(hkName);
  TTree *prettyHkTree = (TTree*) fpHk->Get("prettyHkTree");
  prettyHkTree->SetBranchAddress("hk",&hk);


  //Friends only seem to work with TTree::Draw and similar commands
  //if you are manually calling GetEntry (i.e in a loop) you must call
  //the GetEntry for each tree separately.
  eventChain->AddFriend(headTree);
  eventChain->AddFriend(prettyHkTree);


//   TCanvas *canClock = (TCanvas*) gROOT->FindObject("canClock");
//   if(!canClock) {
//     canClock = new TCanvas("canClock","canClock",800,800);
//   }
  char textLabel[180];
  char pngName[180];
  TGraph *gr[9]={0};

  TH1F *histZc = new TH1F("histZc","histZc",1000,-100,100);
  TH1F *histCount = new TH1F("histCount","histCount",10,0,10);
  TH2F *hist2d = new TH2F("hist2d","hist2d",100,0,100,100,0,100);
  TH1F *histMvMax = new TH1F("histMvMax","histMvMax",1000,0,500);
  TH1F *histMvMin = new TH1F("histMvMin","histMvMin",1000,-500,0);
  TH2F *histMv2d = new TH2F("histMv2d","histMv2d",500,-500,0,500,0,500);


  for(int entry=startEntry;entry<startEntry+numEntries;entry++) {
    
    //Stupidly must do this to be perfectly safe  
    eventChain->GetEntry(entry);
    headTree->GetEntry(entry);
    prettyHkTree->GetEntry(entry);
       
       
    UsefulAnitaEvent realEvent(event,WaveCalType::kVTFullJWPlus,hk);
    
    //Just SURF 0 for now.
    Double_t mean=TMath::Mean(realEvent.fNumPoints[8],realEvent.fVolts[8]);

    Int_t countZC[9]={0};

    Double_t zcs[9][10]={0};


    for(int surf=0;surf<9;surf++) {
      int ci=realEvent.getChanIndex(surf,8);
      countZC[surf]=0;
      for(int i=0;i<realEvent.fNumPoints[ci]-1;i++) {
	Double_t mv1=realEvent.fVolts[ci][i]-mean;
	Double_t mv2=realEvent.fVolts[ci][i+1]-mean;
	if(mv1<0 && mv2>0) {
	  //ZC
	  Double_t t1=realEvent.fTimes[ci][i];
	  Double_t t2=realEvent.fTimes[ci][i+1];
	  
	  Double_t zct=t1 + (t2-t1)*(0-mv1)/(mv2-mv1);
	  //	  cerr << surf << "\t" << countZC[surf] << endl;
	  zcs[surf][countZC[surf]]=zct;	
	  countZC[surf]++;

	  histMvMin->Fill(mv1);
	  histMvMax->Fill(mv2);
	  histMv2d->Fill(mv1,mv2);

	}
      } 
    }
    histCount->Fill(countZC[1]);

    Int_t z1=1;
    Int_t z0=1;
    Double_t zcDiff=zcs[1][z1]-zcs[0][z0];
    if(zcDiff>20) {
      z0++;
      zcDiff=zcs[1][z1]-zcs[0][z0];
    }
    if(zcDiff<-20) {
      z1++;
      zcDiff=zcs[1][z1]-zcs[0][z0];
    }

    histZc->Fill(zcs[1][z1]-zcs[0][z0]);
    hist2d->Fill(zcs[1][z1],zcs[0][z0]);
    
  }
  
  TCanvas *can = new TCanvas("can","can");
  can->Divide(1,2);
  can->cd(1);
  histZc->Draw();
  can->cd(2);
  hist2d->Draw();
  
  TCanvas *can2 = new TCanvas("can2","can2");
  can2->Divide(1,3);
  can2->cd(1);
  histMvMin->Draw();
  can2->cd(2);
  histMvMax->Draw();
  can2->cd(3);
  histMv2d->Draw();


}
Example #17
0
void analyzeSubJets(std::vector<std::string> urls, const char *outname = "eventObjects.root", Long64_t nentries = 20, Int_t firstF = -1, Int_t lastF = -1, Int_t firstEvent = 0) {

  /*
    ptminType: minimum raw pt for particles used by puppi
    0 : 0 GeV
    1 : 1 GeV
    2 : 2 GeV

    jetSignalType: jets used to select jetty region in events
    0 : detector-level jets (akPu4PF)
    1 : particle-level jets (gen jets)
  */

  TString jetSDName = "akt4PFSD";
  TString jetTreeSDName = "akSoftDrop4PFJetAnalyzer";
  TString jetSDChName = "akt4PFSDCh";
  TString jetTreeSDChName = "akSoftDropCh4PFJetAnalyzer";
  TString jetSD000Name = "akt4PFSDZCut000";
  TString jetTreeSD000Name = "akSoftDropZCut0004PFJetAnalyzer";
  TString jetName = "akt4PF";
  TString jetTreeName = "ak4PFJetAnalyzer";
  //jetName = "akCs4PFFilter";
  //jetTreeName = "akCs4PFFilterJetAnalyzer";

  double minptjet = 30.;
  bool doDijet = false;
  if(!doDijet) minptjet = 40.;

  std::cout << "analyzing subjets for: " << jetName << " tree: " << jetTreeName << std::endl;
  std::cout << "analyzing subjets for: " << jetSDName << " tree: " << jetTreeSDName << std::endl;
   
  std::cout << "nfiles: " << urls.size() << std::endl;
  for (auto i = urls.begin(); i != urls.end(); ++i)
    std::cout << *i << std::endl;

  size_t firstFile = 0;
  size_t lastFile = urls.size();

  if(firstF>-1) {
    firstFile = (size_t)firstF;
    lastFile = std::min((size_t)lastF,lastFile);
  }
  std::cout << "firstFile: " << firstFile << "  lastFile: " << lastFile << std::endl;

  Int_t lastEvent = nentries;
  if(firstEvent>0) {
    lastEvent = firstEvent + nentries;
  }
  std::cout << "firstEvent: " << firstEvent << std::endl;
  
  //add files to chain
  TChain *chain = NULL;
  chain = new TChain("hiEvtAnalyzer/HiTree");
  for(size_t i=firstFile; i<lastFile; i++) chain->Add(urls[i].c_str());
  Printf("hiTree done");
  
  TChain *jetTreeSD = new TChain(Form("%s/t",jetTreeSDName.Data()));
  for(size_t i=firstFile; i<lastFile; i++) jetTreeSD->Add(urls[i].c_str());
  chain->AddFriend(jetTreeSD);
  Printf("jetTreeSD done");

  TChain *jetTreeSD000 = new TChain(Form("%s/t",jetTreeSD000Name.Data()));
  for(size_t i=firstFile; i<lastFile; i++) jetTreeSD000->Add(urls[i].c_str());
  Printf("jetTreeSD000 done");


//  TChain *jetTreeSDCh = new TChain(Form("%s/t",jetTreeSDChName.Data()));
//  for(size_t i=firstFile; i<lastFile; i++) jetTreeSDCh->Add(urls[i].c_str());
//  Printf("jetTreeSDCh done");

  TChain *jetTree = new TChain(Form("%s/t",jetTreeName.Data()));
  for(size_t i=firstFile; i<lastFile; i++) jetTree->Add(urls[i].c_str());
  Printf("jetTree done");

  TList *fEventObjects = new TList();

  //---------------------------------------------------------------
  // producers
  //
  hiEventProducer *p_evt = new hiEventProducer("hiEvtProd");
  p_evt->SetInput(chain);
  p_evt->SetHIEventContName("hiEventContainer");
  p_evt->SetEventObjects(fEventObjects);

  lwJetFromForestProducer *p_SDJet = new lwJetFromForestProducer("lwJetForestProdSD");
  p_SDJet->SetInput(chain);
  p_SDJet->SetJetContName(jetSDName);
  p_SDJet->SetGenJetContName("akt4Gen");
  p_SDJet->SetEventObjects(fEventObjects);
  p_SDJet->SetMinJetPt(minptjet);
  p_SDJet->SetRadius(0.4);

  lwJetFromForestProducer *p_SD000Jet = new lwJetFromForestProducer("lwJetForestProdSD000");
  p_SD000Jet->SetInput(jetTreeSD000);
  p_SD000Jet->SetJetContName(jetSD000Name);
  p_SD000Jet->SetGenJetContName("akt4Gen000");
  p_SD000Jet->SetEventObjects(fEventObjects);
  p_SD000Jet->SetMinJetPt(minptjet);
  p_SD000Jet->SetRadius(0.4);

/*
  lwJetFromForestProducer *p_SDChJet = new lwJetFromForestProducer("lwJetForestProdSDCh");
  p_SDChJet->SetInput(jetTreeSDCh);
  p_SDChJet->SetJetContName(jetSDChName);
  p_SDChJet->SetGenJetContName("akt4GenCh");
  p_SDChJet->SetEventObjects(fEventObjects);
  p_SDChJet->SetMinJetPt(minptjet);
  p_SDChJet->SetRadius(0.4);
*/

  lwJetFromForestProducer *p_Jet = new lwJetFromForestProducer("lwJetForestProd");
  p_Jet->SetInput(jetTree);
  p_Jet->SetJetContName(jetName);
  p_Jet->SetGenJetContName("");//akt4Gen");
  p_Jet->SetEventObjects(fEventObjects);
  p_Jet->SetMinJetPt(minptjet);
  p_Jet->SetRadius(0.4);
  
  //---------------------------------------------------------------
  //analysis modules
  //

  //handler to which all modules will be added
  anaBaseTask *handler = new anaBaseTask("handler","handler");

  anaJetQA *jetQA = new anaJetQA("anaJetQA","anaJetQA");
  jetQA->ConnectEventObject(fEventObjects);
  jetQA->SetJetsName(jetName);
  handler->Add(jetQA);

  anaJetMatching *match = new anaJetMatching("jetMatching","jetMatching");
  match->ConnectEventObject(fEventObjects);
  match->SetHiEvtName("hiEventContainer");
  match->SetNCentBins(1);
  match->SetJetsNameBase(jetName);
  match->SetJetsNameTag(jetSDName);
  match->SetMatchingType(0);
  handler->Add(match);

  anaJetMatching *match000 = new anaJetMatching("jetMatching000","jetMatching000");
  match000->ConnectEventObject(fEventObjects);
  match000->SetHiEvtName("hiEventContainer");
  match000->SetNCentBins(1);
  match000->SetJetsNameBase(jetName);
  match000->SetJetsNameTag(jetSD000Name);
  match000->SetMatchingType(0);
  match000->SetMatchId(2);
  handler->Add(match000);
  
  anaSubJet *anasubjets = new anaSubJet("anaSubJets","anaSubJets");
  anasubjets->ConnectEventObject(fEventObjects);
  anasubjets->SetHiEvtName("hiEventContainer");
  anasubjets->SetJetsName(jetSDName);
  anasubjets->SetJetsRefName(jetName);
  anasubjets->SetJets000Name(jetSD000Name);
  anasubjets->SetNCentBins(1);
  //anasubjets->SetJetEtaRange(-2.,2.);
  anasubjets->SetJetEtaRange(-1.3,1.3);
  anasubjets->SetDoDijets(doDijet);
  anasubjets->AddLeadingJetPtBin(120.,150.);
  anasubjets->AddLeadingJetPtBin(150.,180.);
  anasubjets->AddLeadingJetPtBin(180.,220.);
  anasubjets->AddLeadingJetPtBin(220.,260.);
  anasubjets->AddLeadingJetPtBin(260.,300.);
  anasubjets->AddLeadingJetPtBin(300.,500.);
  anasubjets->SetPtMinSubleading(30.);
  anasubjets->SetStoreTree(true);
  anasubjets->SetStoreTreeRef(true);//false);
  anasubjets->SetMinPtJetTree(80.);
  handler->Add(anasubjets);

  anaJetMatching *matchRev = new anaJetMatching("jetMatchingReversed","jetMatchingReversed");
  matchRev->ConnectEventObject(fEventObjects);
  matchRev->SetHiEvtName("hiEventContainer");
  matchRev->SetNCentBins(1);
  matchRev->SetJetsNameBase(jetName);
  matchRev->SetJetsNameTag(jetSD000Name);
  matchRev->SetMatchingType(0);
  handler->Add(matchRev);

  anaJetMatching *match000Rev = new anaJetMatching("jetMatching000Reversed","jetMatching000Reversed");
  match000Rev->ConnectEventObject(fEventObjects);
  match000Rev->SetHiEvtName("hiEventContainer");
  match000Rev->SetNCentBins(1);
  match000Rev->SetJetsNameBase(jetName);
  match000Rev->SetJetsNameTag(jetSDName);
  match000Rev->SetMatchingType(0);
  match000Rev->SetMatchId(2);
  handler->Add(match000Rev);
  
  anaSubJet *anasubjetsRev = new anaSubJet("anaSubJetsReversed","anaSubJetsReversed");
  anasubjetsRev->ConnectEventObject(fEventObjects);
  anasubjetsRev->SetHiEvtName("hiEventContainer");
  anasubjetsRev->SetJetsName(jetSD000Name);
  anasubjetsRev->SetJetsRefName(jetName);
  anasubjetsRev->SetJets000Name(jetSDName);
  anasubjetsRev->SetNCentBins(1);
  //anasubjetsRev->SetJetEtaRange(-2.,2.);
  anasubjetsRev->SetJetEtaRange(-1.3,1.3);
  anasubjetsRev->SetDoDijets(doDijet);
  anasubjetsRev->AddLeadingJetPtBin(120.,150.);
  anasubjetsRev->AddLeadingJetPtBin(150.,180.);
  anasubjetsRev->AddLeadingJetPtBin(180.,220.);
  anasubjetsRev->AddLeadingJetPtBin(220.,260.);
  anasubjetsRev->AddLeadingJetPtBin(260.,300.);
  anasubjetsRev->AddLeadingJetPtBin(300.,500.);
  anasubjetsRev->SetPtMinSubleading(30.);
  anasubjetsRev->SetStoreTree(true);
  anasubjetsRev->SetStoreTreeRef(true);//false);
  anasubjetsRev->SetMinPtJetTree(80.);
  handler->Add(anasubjetsRev);

  anaSubJet *anasubjetsGen = new anaSubJet("anasubjetsGen","anasubjetsGen");
  anasubjetsGen->ConnectEventObject(fEventObjects);
  anasubjetsGen->SetHiEvtName("hiEventContainer");
  anasubjetsGen->SetJetsName("akt4Gen"); //ungroomed jets with groomed subjet variables at gen level
  anasubjetsGen->SetJetsRefName(""); //
  anasubjetsGen->SetNCentBins(1);
  anasubjetsGen->SetJetEtaRange(-1.3,1.3);
  //anasubjetsGen->SetJetEtaRange(-2.,2.);
  anasubjetsGen->SetDoDijets(doDijet);
  anasubjetsGen->AddLeadingJetPtBin(120.,150.);
  anasubjetsGen->AddLeadingJetPtBin(150.,180.);
  anasubjetsGen->AddLeadingJetPtBin(180.,220.);
  anasubjetsGen->AddLeadingJetPtBin(220.,260.);
  anasubjetsGen->AddLeadingJetPtBin(260.,300.);
  anasubjetsGen->AddLeadingJetPtBin(300.,500.);
  anasubjetsGen->SetPtMinSubleading(30.);
  anasubjetsGen->SetStoreTree(true);
  anasubjetsGen->SetStoreTreeRef(false);
  anasubjetsGen->SetMinPtJetTree(80.);
  handler->Add(anasubjetsGen);

  anaSubJet *anasubjetsGen000 = new anaSubJet("anasubjetsGen000","anasubjetsGen000");
  anasubjetsGen000->ConnectEventObject(fEventObjects);
  anasubjetsGen000->SetHiEvtName("hiEventContainer");
  anasubjetsGen000->SetJetsName("akt4Gen000"); //ungroomed jets with groomed subjet variables at gen level
  anasubjetsGen000->SetJetsRefName(""); //
  anasubjetsGen000->SetNCentBins(1);
  anasubjetsGen000->SetJetEtaRange(-1.3,1.3);
  //anasubjetsGen000->SetJetEtaRange(-2.,2.);
  anasubjetsGen000->SetDoDijets(doDijet);
  anasubjetsGen000->AddLeadingJetPtBin(120.,150.);
  anasubjetsGen000->AddLeadingJetPtBin(150.,180.);
  anasubjetsGen000->AddLeadingJetPtBin(180.,220.);
  anasubjetsGen000->AddLeadingJetPtBin(220.,260.);
  anasubjetsGen000->AddLeadingJetPtBin(260.,300.);
  anasubjetsGen000->AddLeadingJetPtBin(300.,500.);
  anasubjetsGen000->SetPtMinSubleading(30.);
  anasubjetsGen000->SetStoreTree(true);
  anasubjetsGen000->SetStoreTreeRef(false);
  anasubjetsGen000->SetMinPtJetTree(80.);
  handler->Add(anasubjetsGen000);

  anaSubJet *anasubjetsNoFakes = new anaSubJet("anaSubJetsNoFakes","anaSubJetsNoFakes");
  anasubjetsNoFakes->ConnectEventObject(fEventObjects);
  anasubjetsNoFakes->SetHiEvtName("hiEventContainer");
  anasubjetsNoFakes->SetJetsName(jetSDName);
  anasubjetsNoFakes->SetJetsRefName(jetName);
  anasubjetsNoFakes->SetNCentBins(4);
  anasubjetsNoFakes->SetJetEtaRange(-2.,2.);
  anasubjetsNoFakes->SetMinRefPt(10.);
  //handler->Add(anasubjetsNoFakes);

  //SD with charged hadrons
  anaJetMatching *matchCh = new anaJetMatching("jetMatchingCh","jetMatchingCh");
  matchCh->ConnectEventObject(fEventObjects);
  matchCh->SetHiEvtName("hiEventContainer");
  matchCh->SetNCentBins(1);
  matchCh->SetJetsNameBase(jetName);
  matchCh->SetJetsNameTag(jetSDChName);
  matchCh->SetMatchingType(0);
//  handler->Add(matchCh);
  
  anaSubJet *anasubjetsCh = new anaSubJet("anaSubJetsCh","anaSubJetsCh");
  anasubjetsCh->ConnectEventObject(fEventObjects);
  anasubjetsCh->SetHiEvtName("hiEventContainer");
  anasubjetsCh->SetJetsName(jetSDChName);
  anasubjetsCh->SetJetsRefName(jetName);
  anasubjetsCh->SetNCentBins(1);
  //anasubjetsCh->SetJetEtaRange(-2.,2.);
  anasubjetsCh->SetJetEtaRange(-1.3,1.3);
  anasubjetsCh->SetDoDijets(doDijet);
  anasubjetsCh->AddLeadingJetPtBin(120.,150.);
  anasubjetsCh->AddLeadingJetPtBin(150.,180.);
  anasubjetsCh->AddLeadingJetPtBin(180.,220.);
  anasubjetsCh->AddLeadingJetPtBin(220.,260.);
  anasubjetsCh->AddLeadingJetPtBin(260.,300.);
  anasubjetsCh->AddLeadingJetPtBin(300.,500.);
  anasubjetsCh->SetPtMinSubleading(30.);
  anasubjetsCh->SetStoreTree(true);
  anasubjetsCh->SetStoreTreeRef(true);//false);
  anasubjetsCh->SetMinPtJetTree(80.);
//  handler->Add(anasubjetsCh);

  anaSubJet *anasubjetsGenCh = new anaSubJet("anasubjetsGenCh","anasubjetsGenCh");
  anasubjetsGenCh->ConnectEventObject(fEventObjects);
  anasubjetsGenCh->SetHiEvtName("hiEventContainer");
  anasubjetsGenCh->SetJetsName("akt4GenCh"); //ungroomed jets with groomed subjet variables at gen level
  anasubjetsGenCh->SetJetsRefName(""); //
  anasubjetsGenCh->SetNCentBins(1);
  anasubjetsGenCh->SetJetEtaRange(-1.3,1.3);
  //anasubjetsGenCh->SetJetEtaRange(-2.,2.);
  anasubjetsGenCh->SetDoDijets(doDijet);
  anasubjetsGenCh->AddLeadingJetPtBin(120.,150.);
  anasubjetsGenCh->AddLeadingJetPtBin(150.,180.);
  anasubjetsGenCh->AddLeadingJetPtBin(180.,220.);
  anasubjetsGenCh->AddLeadingJetPtBin(220.,260.);
  anasubjetsGenCh->AddLeadingJetPtBin(260.,300.);
  anasubjetsGenCh->AddLeadingJetPtBin(300.,500.);
  anasubjetsGenCh->SetPtMinSubleading(30.);
  anasubjetsGenCh->SetStoreTree(true);
  anasubjetsGenCh->SetStoreTreeRef(false);
  anasubjetsGenCh->SetMinPtJetTree(80.);
//  handler->Add(anasubjetsGenCh);

  
  //---------------------------------------------------------------
  //Event loop
  //---------------------------------------------------------------
  Long64_t entries_tot =  chain->GetEntries(); //93064
  if(nentries<0) lastEvent = chain->GetEntries();
  Printf("nentries: %lld  tot: %lld",nentries,entries_tot);
  for (Long64_t jentry=firstEvent; jentry<lastEvent; ++jentry) {
    if(jentry%10000==0) cout << "entry: "<< jentry << endl;
    //Run producers
    //Printf("produce hiEvent");
    p_evt->Run(jentry);   //hi event properties
    //Printf("produce jets");
    p_SDJet->Run(jentry); //forest SoftDrop jets
    p_SD000Jet->Run(jentry); //forest SoftDrop jets with zcut=0
    //   p_SDChJet->Run(jentry); //forest SoftDrop jets with charged hadrons
    p_Jet->Run(jentry); //forest jets
	    
    //Execute all analysis tasks
    handler->ExecuteTask();
  }
    
  fEventObjects->Print();

  TFile *out = new TFile(outname,"RECREATE","",8);
  TList *tasks = handler->GetListOfTasks();
  TIter next(tasks);
  anaBaseTask *obj;
  while ((obj = dynamic_cast<anaBaseTask*>(next()) ))
    if(obj->GetOutput()) obj->GetOutput()->Write(obj->GetName(),TObject::kSingleKey);
  
  out->Write();
  out->Close();
  
}
Example #18
0
TChain * scaleResJet(bool doMC=1,
    //TString infile0="dj_Data_MinBias_DijetUnquenched50and80_d20101125to27.root",
    TString infile0="dj_Data_MinBias_DijetUnquenched50_d20101127_MatchedJetGoodTrk1127v2.root",
    //TString infile0="dj_Data_MinBias_DijetUnquenched80_d20101125and1126_MatchedJetGoodTrk1127v2.root",
    //TString infile1="dj_Data_MinBias0to20_DijetUnquenched50_d20101124_StdJetGoodTrk1126.root",
    Float_t centMin=0,
    Float_t centMax=10,
    TString header="McDiJet-DataBackground"
    )
{
  TChain * dj = new TChain("djgen/djTree");

  dj->Add(infile0);
  dj->AddFriend("djcalo = djcalo/djTree",infile0);
  aliases_dijet(dj,1.2,doMC,"djcalo");
  cout << "dj0 Total: " << dj->GetEntries() << endl;

  TFile * fout = new TFile(Form("JES_%.0fto%.0f.root",centMin,centMax),"RECREATE");

  TCut evtSel(Form("cent>=%.0f && cent<%.0f && nlrjet>20 && abs(nljeta)<2 && alrjet>20 && abs(aljeta)<2 && jdphi>TMath::Pi()*5/6",
	centMin,centMax));
  //evtSel = evtSel && "djgen.nljet>0&&djgen.aljet>0" //for now abs eff --- no selection on mc
  TCut evtSelAw = evtSel;// && "alrjet>40";
  
  for (int i=0; i<=nBinRat;++i) {
    binRat[i]=i*3./nBinRat;
    //cout << "nBinRat " << i << ": " << binRat[i] << endl;
  }

  TCanvas * cEt1D = new TCanvas("cEt1D","cEt1D",500,500);
  TH1D * hEtNr = new TH1D("hEtNr","",nBin,bin);
  dj->Draw("nljet>>hEtNr",evtSel);

  TCanvas * cEtNr2D = new TCanvas("cEtNr2D","cEtNr2D",500,550);
  TH2D * hEtNr2D = new TH2D("hEtNr2D",";E_{T}^{GenJet};E_{T}^{CaloJet}",nBin,bin,nBinRat,binRat);
  dj->Draw("nlrjet/nljet:nljet>>hEtNr2D",evtSel,"colz");
  TLine *l45 = new TLine(20,1,300,1);
  l45->SetLineStyle(2);
  l45->Draw();
  cEtNr2D->Print(Form("EtNr2D_%.0fto%.0f.gif",centMin,centMax));
  cEtNr2D->Print(Form("EtNr2D_%.0fto%.0f.pdf",centMin,centMax));

  TCanvas * cEtAw2D = new TCanvas("cEtAw2D","cEtAw2D",500,550);
  TH2D * hEtAw2D = new TH2D("hEtAw2D",";E_{T}^{GenJet};E_{T}^{CaloJet}",nBin,bin,nBinRat,binRat);
  dj->Draw("alrjet/aljet:aljet>>hEtAw2D",evtSelAw,"colz");
  l45->Draw();
  cEtAw2D->Print(Form("EtAw2D_%.0fto%.0f.gif",centMin,centMax));
  cEtAw2D->Print(Form("EtAw2D_%.0fto%.0f.pdf",centMin,centMax));

  TCanvas * cDr = new TCanvas("cDr","cDr",500,550);
  dj->Draw("nlrjdr",evtSel,"hist");
  dj->Draw("alrjdr",evtSelAw,"sameE");
  
  TCanvas * cCent = new TCanvas("cCent","cCent",500,550);
  dj->Draw("cent",evtSel,"hist");
  dj->Draw("cent",evtSelAw,"sameE");

  // 1D Response
  TH2F * hJESNr2D = JES(dj,"nlrjet/nljet:nljet",evtSel,"nlrjdr<0.3","JESNr2D");
  TH1D * hJESNr2D_1 = (TH1D*)gDirectory->Get("hJESNr2D_1");
  TH1D * hJESNr2D_2 = (TH1D*)gDirectory->Get("hJESNr2D_2");
  TH2F * hJESAw2D = JES(dj,"alrjet/aljet:aljet",evtSelAw,"alrjdr<0.3","JESAw2D");
  TH1D * hJESAw2D_1 = (TH1D*)gDirectory->Get("hJESAw2D_1");
  TH1D * hJESAw2D_2 = (TH1D*)gDirectory->Get("hJESAw2D_2");

  // 2D Reponse
  //TH3F * hJESNr3D = JES2D(dj,"nlrjet/nljet:nljet:nljeta",evtSel,"nlrjdr<0.3","JESNr3D");
  //TH3F * hJESAw3D = JES2D(dj,"alrjet/aljet:aljet:aljeta",evtSelAw,"alrjdr<0.3","JESAw3D");

  // Draw
  TCanvas * cJES = new TCanvas("cJES","cJES",500,550);
  CPlot cpJES("JES","JES","E_{T}^{GenJet} [GeV]","E_{T}^{CaloJet}/E_{T}^{GenJet}");
  cpJES.SetYRange(0,1.5);
  cpJES.AddHist1D(hJESNr2D_1,"Leading Jet Reponse","E",kBlack,kFullCircle);
  cpJES.AddHist1D(hJESAw2D_1,"Away Jet Reponse","E",kRed,kFullSquare);
  cpJES.SetLegend(0.54,0.8,0.86,0.92);
  cpJES.SetLegendHeader(Form("Centrality %.0f to %.0f",centMin,centMax));
  cpJES.Draw(cJES,false);
  TLine *l = new TLine(0,1,bin[nBin],1);
  l->SetLineStyle(2);
  l->Draw();
  cJES->Print(Form("JES_%.0fto%.0f.gif",centMin,centMax));
  cJES->Print(Form("JES_%.0fto%.0f.pdf",centMin,centMax));
  
  TCanvas * cJReso = new TCanvas("cJReso","cJReso",500,550);
  CPlot cpJReso("JReso","JReso","E_{T}^{GenJet} [GeV]","#sigma(E_{T}^{Calo}/E_{T}^{GenJet})");
  cpJReso.SetYRange(0,0.4);
  cpJReso.AddHist1D(hJESNr2D_2,"Leading Jet Resolution","E",kBlack,kOpenCircle);
  cpJReso.AddHist1D(hJESAw2D_2,"Away Jet Resolution","E",kRed,kOpenSquare);
  cpJReso.SetLegend(0.54,0.8,0.86,0.92);
  cpJReso.SetLegendHeader(Form("Centrality %.0f to %.0f",centMin,centMax));
  TF1 * fres = new TF1("fres",res,30,1000,0);
  TF1 * fres2 = new TF1("fres2",res2,30,1000,0);
  //hJESNr2D_2->Fit("fReso","","",30,400);
  cpJReso.Draw(cJReso,false);
  //fResoNoBkgVsCalo->SetRange(30,400);
  //fResoNoBkgVsCalo->Draw("same");
  //fResoWBkg->SetParameters(fReso->GetParameter(0),fReso->GetParameter(1),fReso->GetParameter(2));
  //fResoWBkgVsCalo->SetRange(30,400);
  //fResoWBkgVsCalo->SetLineColor(kGreen+2);
  //fResoWBkgVsCalo->Draw("same");
  fres->SetLineStyle(7);
  fres->Draw("same");
  fres2->Draw("same");
  cJReso->Print(Form("JReso_%.0fto%.0f.gif",centMin,centMax));
  cJReso->Print(Form("JReso_%.0fto%.0f.pdf",centMin,centMax));
  
  /*
  TCanvas * cJES2DNr = new TCanvas("cJES2DNr","cJES2DNr",500,550);
  cJES2DNr->SetRightMargin(0.2);
  TProfile2D * hJESNr3D_pyx = (TProfile2D*)hJESNr3D->Project3DProfile("yx");
  hJESNr3D_pyx->SetMinimum(0.8);
  hJESNr3D_pyx->SetMaximum(1.2);
  hJESNr3D_pyx->Draw("colz");
  cJES2DNr->Print(Form("JES2DNr_%.0fto%.0f.gif",centMin,centMax));
  cJES2DNr->Print(Form("JES2DNr_%.0fto%.0f.pdf",centMin,centMax));

  TCanvas * cJES2DAw = new TCanvas("cJES2DAw","cJES2DAw",500,550);
  cJES2DAw->SetRightMargin(0.2);
  TProfile2D * hJESAw3D_pyx = (TProfile2D*)hJESAw3D->Project3DProfile("yx");
  hJESAw3D_pyx->SetMinimum(0.8);
  hJESAw3D_pyx->SetMaximum(1.2);
  hJESAw3D_pyx->Draw("colz");
  cJES2DAw->Print(Form("JES2DAw_%.0fto%.0f.gif",centMin,centMax));
  cJES2DAw->Print(Form("JES2DAw_%.0fto%.0f.pdf",centMin,centMax));
  */

  fout->Write();
  return dj;
}
Example #19
0
void analyzeDijetAj(std::vector<std::string> urls, const char *outname = "eventObjects.root", Long64_t nentries = 20, Int_t firstF = -1, Int_t lastF = -1, Int_t firstEvent = 0) {

  /*
    ptminType: minimum raw pt for particles used by puppi
    0 : 0 GeV
    1 : 1 GeV
    2 : 2 GeV

    jetSignalType: jets used to select jetty region in events
    0 : detector-level jets (akPu4PF)
    1 : particle-level jets (gen jets)
   */

  double ptminjet = 30.;
  TString jetName = "aktCs4PF";
  TString jetTreeName = "akCs4PFJetAnalyzer";
  //jetName = "akCs4PFFilter";
  //jetTreeName = "akCs4PFFilterJetAnalyzer";

  std::cout << "analyzing subjets for: " << jetName << " tree: " << jetTreeName << std::endl;
   
  std::cout << "nfiles: " << urls.size() << std::endl;
  for (auto i = urls.begin(); i != urls.end(); ++i)
    std::cout << *i << std::endl;

  size_t firstFile = 0;
  size_t lastFile = urls.size();

  if(firstF>-1) {
    firstFile = (size_t)firstF;
    lastFile = std::min((size_t)lastF,lastFile);
  }
  std::cout << "firstFile: " << firstFile << "  lastFile: " << lastFile << std::endl;

  Int_t lastEvent = nentries;
  if(firstEvent>0) {
    lastEvent = firstEvent + nentries;
  }
  std::cout << "firstEvent: " << firstEvent << std::endl;
  
  //add files to chain
  TChain *chain = NULL;
  chain = new TChain("hiEvtAnalyzer/HiTree");
  for(size_t i=firstFile; i<lastFile; i++) chain->Add(urls[i].c_str());
  Printf("hiTree done");

  TChain *skimTree = new TChain("skimanalysis/HltTree");
  for(size_t i=firstFile; i<lastFile; i++) skimTree->Add(urls[i].c_str());
  chain->AddFriend(skimTree);
  Printf("skimTree done");

  TChain *hltTree = new TChain("hltanalysis/HltTree");
  for(size_t i=firstFile; i<lastFile; i++) hltTree->Add(urls[i].c_str());
  chain->AddFriend(hltTree);
  Printf("hltTree done");
  
  TChain *jetTree = new TChain(Form("%s/t",jetTreeName.Data()));
  for(size_t i=firstFile; i<lastFile; i++) jetTree->Add(urls[i].c_str());
  chain->AddFriend(jetTree);
  Printf("jetTree done");

  // TChain *csJetTree = new TChain(Form("%s/t","akCs4PFJetAnalyzer"));
  // for(size_t i=firstFile; i<lastFile; i++) csJetTree->Add(urls[i].c_str());
  // chain->AddFriend(csJetTree);
  // Printf("csJetTree done");

  TList *fEventObjects = new TList();

  //---------------------------------------------------------------
  // producers
  //
  hiEventProducer *p_evt = new hiEventProducer("hiEvtProd");
  p_evt->SetInput(chain);
  p_evt->SetHIEventContName("hiEventContainer");
  p_evt->SetEventObjects(fEventObjects);

  triggerProducer *p_trg = new triggerProducer("trigProd");
  p_trg->SetInput(chain);//hltTree);
  p_trg->SetTriggerMapName("triggerMap");
  p_trg->AddTrigger("HLT_HIPuAK4CaloJet100_Eta5p1_v1");
  p_trg->SetEventObjects(fEventObjects);

  lwJetFromForestProducer *p_PUJet = new lwJetFromForestProducer("lwJetForestProd");
  p_PUJet->SetInput(chain);
  p_PUJet->SetJetContName(jetName);
  p_PUJet->SetGenJetContName("");
  p_PUJet->SetEventObjects(fEventObjects);
  p_PUJet->SetRadius(0.4);
  p_PUJet->SetMinJetPt(ptminjet);
  // lwJetFromForestProducer *p_CSJet = new lwJetFromForestProducer("lwJetForestProd");
  // p_CSJet->SetInput(csJetTree);
  // p_CSJet->SetJetContName("aktCs4PF");
  // p_CSJet->SetGenJetContName("");
  // p_CSJet->SetEventObjects(fEventObjects);
  // p_CSJet->SetRadius(0.4);
  
  //---------------------------------------------------------------
  //analysis modules
  //

  //handler to which all modules will be added
  anaBaseTask *handler = new anaBaseTask("handler","handler");

  anaDijetAj *anadijetAj = new anaDijetAj("anaDijetAj","anaDijetAj");
  anadijetAj->ConnectEventObject(fEventObjects);
  anadijetAj->SetHiEvtName("hiEventContainer");
  anadijetAj->DoCollisionEventSel(true);
  anadijetAj->DoHBHENoiseFilter(true);
  anadijetAj->DoHBHENoiseFilterLoose(true);
  anadijetAj->DoPrimaryVertexFilter(true);
  anadijetAj->DoClusterCompatibilityFilter(true);
  anadijetAj->DoHFCoincFilter(true);
  anadijetAj->SetTriggerMapName("triggerMap");
  anadijetAj->AddTriggerSel("HLT_HIPuAK4CaloJet100_Eta5p1_v1");
  anadijetAj->SetJetsName(jetName);
  anadijetAj->SetNCentBins(5);
  anadijetAj->SetJetEtaRange(-1.3,1.3);
  anadijetAj->SetDoDijets(true);
  anadijetAj->AddLeadingJetPtBin(120.,150.);
  anadijetAj->AddLeadingJetPtBin(150.,180.);
  anadijetAj->AddLeadingJetPtBin(180.,220.);
  anadijetAj->AddLeadingJetPtBin(220.,260.);
  anadijetAj->AddLeadingJetPtBin(260.,300.);
  anadijetAj->AddLeadingJetPtBin(300.,500.);
  anadijetAj->SetPtMinSubleading(40.);
  handler->Add(anadijetAj);

  anaDijetAj *anadijetAjMassCut = new anaDijetAj("anaDijetAjMassCut","anaDijetAjMassCut");
  anadijetAjMassCut->ConnectEventObject(fEventObjects);
  anadijetAjMassCut->SetHiEvtName("hiEventContainer");
  anadijetAjMassCut->DoCollisionEventSel(true);
  anadijetAjMassCut->DoHBHENoiseFilter(true);
  anadijetAjMassCut->DoHBHENoiseFilterLoose(true);
  anadijetAjMassCut->DoPrimaryVertexFilter(true);
  anadijetAjMassCut->DoClusterCompatibilityFilter(true);
  anadijetAjMassCut->DoHFCoincFilter(true);
  anadijetAjMassCut->SetTriggerMapName("triggerMap");
  anadijetAjMassCut->AddTriggerSel("HLT_HIPuAK4CaloJet100_Eta5p1_v1");
  anadijetAjMassCut->SetJetsName(jetName);
  anadijetAjMassCut->SetNCentBins(5);
  anadijetAjMassCut->SetJetEtaRange(-1.,3.);
  anadijetAjMassCut->SetDoDijets(true);
  anadijetAjMassCut->AddLeadingJetPtBin(120.,150.);
  anadijetAjMassCut->AddLeadingJetPtBin(150.,180.);
  anadijetAjMassCut->AddLeadingJetPtBin(180.,220.);
  anadijetAjMassCut->AddLeadingJetPtBin(220.,260.);
  anadijetAjMassCut->AddLeadingJetPtBin(260.,300.);
  anadijetAjMassCut->AddLeadingJetPtBin(300.,500.);
  anadijetAjMassCut->SetPtMinSubleading(40.);
  anadijetAjMassCut->SetMinMassLeading(10.);
  handler->Add(anadijetAjMassCut);
  
  //---------------------------------------------------------------
  //Event loop
  //---------------------------------------------------------------
  Long64_t entries_tot =  chain->GetEntries(); //93064
  if(nentries<0) lastEvent = chain->GetEntries();
  Printf("nentries: %lld  tot: %lld",nentries,entries_tot);
  for (Long64_t jentry=firstEvent; jentry<lastEvent; ++jentry) {
    if(jentry%10000==0) cout << "entry: "<< jentry << endl;
    //Run producers
    //Printf("produce hiEvent");
    p_evt->Run(jentry);   //hi event properties
    //Printf("produce PU jets");
    p_PUJet->Run(jentry); //forest jets
    p_trg->Run(jentry);	    

    //Execute all analysis tasks
    handler->ExecuteTask();
  }
    
  fEventObjects->Print();

  TFile *out = new TFile(outname,"RECREATE");
  TList *tasks = handler->GetListOfTasks();
  TIter next(tasks);
  anaBaseTask *obj;
  while ((obj = dynamic_cast<anaBaseTask*>(next()) ))
    if(obj->GetOutput()) obj->GetOutput()->Write(obj->GetName(),TObject::kSingleKey);
  
  out->Write();
  out->Close();
  
}
Example #20
0
void analyzePFCandidates(std::vector<std::string> urls, const char *outname = "eventObjects.root", Long64_t nentries = 20, Int_t firstF = -1, Int_t lastF = -1) {

  // std::vector<std::string> urls = CollectFiles(list);

  // Printf("anaFile: %d",anaFile);
  
  std::cout << "nfiles: " << urls.size() << std::endl;
  for (auto i = urls.begin(); i != urls.end(); ++i)
    std::cout << *i << std::endl;

  size_t firstFile = 0;
  size_t lastFile = urls.size();

  if(firstF>-1) {
    firstFile = (size_t)firstF;
    lastFile = (size_t)lastF;
  }
  std::cout << "firstFile: " << firstFile << "  lastFile: " << lastFile << std::endl;
  
  //add files to chain
  TChain *chain = NULL;
//  chain = new TChain("hiEvtAnalyzer/HiTree");
  //for(size_t i=firstFile; i<lastFile; i++) chain->Add(urls[i].c_str());
  //Printf("hiTree done");
  
  //TChain *pfTree = new TChain("pfcandAnalyzer/pfTree");
  chain = new TChain("pfcandAnalyzer/pfTree");
  //for(size_t i=firstFile; i<lastFile; i++) pfTree->Add(urls[i].c_str());
  for(size_t i=firstFile; i<lastFile; i++) chain->Add(urls[i].c_str());  
  //chain->AddFriend(pfTree);
  Printf("pfTree done");
  
  // TChain *muTree = new TChain("hltMuTree/HLTMuTree");
  // for(size_t i=firstFile; i<lastFile; i++) muTree->Add(urls[i].c_str());
  // chain->AddFriend(muTree);
  // Printf("muTree done");

  TChain *jetTree = new TChain("ak4PFJetAnalyzer/t");//akPu4CaloJetAnalyzer/t");
  for(size_t i=firstFile; i<lastFile; i++) jetTree->Add(urls[i].c_str());
  chain->AddFriend(jetTree);
  Printf("jetTree done");

  TChain *hltTree = new TChain("hltanalysis/HltTree");
  for(size_t i=firstFile; i<lastFile; i++) hltTree->Add(urls[i].c_str());
  chain->AddFriend(hltTree);
  Printf("hltTree done");

  TChain *skimTree = new TChain("skimanalysis/HltTree");
  for(size_t i=firstFile; i<lastFile; i++) skimTree->Add(urls[i].c_str());
  chain->AddFriend(skimTree);
  Printf("skimTree done");
  
  if(doTracks) {
    //    TChain *trackTree = new TChain("anaTrack/trackTree");
    TChain *trackTree = new TChain("ppTrack/trackTree");
    for(size_t i=firstFile; i<lastFile; i++) trackTree->Add(urls[i].c_str());
    chain->AddFriend(trackTree);
    Printf("trackTree done");
  }
  // TChain *genTree = new TChain("HiGenParticleAna/hi");
  // for(size_t i=firstFile; i<lastFile; i++) genTree->Add(urls[i].c_str());
  // chain->AddFriend(genTree);
  // Printf("genTree done");
  
  TList *fEventObjects = new TList();


  //---------------------------------------------------------------
  // producers
  //
  hiEventProducer *p_evt = new hiEventProducer("hiEvtProd");
  p_evt->SetInput(chain);
  p_evt->SetHIEventContName("hiEventContainer");
  p_evt->SetEventObjects(fEventObjects);

  pfParticleProducer *p_pf = new pfParticleProducer("pfPartProd");
  p_pf->SetInput(chain);
  p_pf->SetpfParticlesName("pfParticles");
  p_pf->SetEventObjects(fEventObjects);

  lwJetFromForestProducer *p_PUJet = new lwJetFromForestProducer("lwJetForestProd");
  p_PUJet->SetInput(chain);
  p_PUJet->SetJetContName("akt4PF");
  p_PUJet->SetGenJetContName("akt4Gen");
  p_PUJet->SetEventObjects(fEventObjects);
  p_PUJet->SetRadius(0.4);

  trackProducer *p_trk = new trackProducer("trackProd");
  if(doTracks) {
    p_trk->SetInput(chain);
    p_trk->SetTracksName("tracks");
    p_trk->SetEventObjects(fEventObjects);
  }
  
  //---------------------------------------------------------------
  //analysis modules
  //

  //handler to which all modules will be added
  anaBaseTask *handler = new anaBaseTask("handler","handler");

  anaPFCandidates *anaPFCandJet = new anaPFCandidates("pfCandWithPFJets","pfCandWithPFJets");
  anaPFCandJet->ConnectEventObject(fEventObjects);
//  anaPFCandJet->SetHiEvtName("hiEventContainer");
  anaPFCandJet->SetParticlesName("pfParticles");
  anaPFCandJet->SetJetsName("akt4PF");
  handler->Add(anaPFCandJet);

  anaPFCandidates *anaPF = new anaPFCandidates("pfCand","pfCand");
  anaPF->ConnectEventObject(fEventObjects);
  //anaPF->SetHiEvtName("hiEventContainer");
  anaPF->SetParticlesName("pfParticles");
  anaPF->SetJetsName("akt4Gen");
  handler->Add(anaPF);

  anaPFCandidates *anaTrkCaloJet = new anaPFCandidates("tracksWithCaloJets","tracksWithCaloJets");
  anaTrkCaloJet->ConnectEventObject(fEventObjects);
  //anaTrkCaloJet->SetHiEvtName("hiEventContainer");
  anaTrkCaloJet->SetParticlesName("tracks");
  anaTrkCaloJet->SetJetsName("aktPu4Calo");
  if(doTracks) handler->Add(anaTrkCaloJet);

  anaPFCandidates *anaTrk = new anaPFCandidates("tracksWithGenJet","tracksWithGenJet");
  anaTrk->ConnectEventObject(fEventObjects);
  //anaTrk->SetHiEvtName("hiEventContainer");
  anaTrk->SetParticlesName("tracks");
  anaTrk->SetJetsName("akt4Gen");
  if(doTracks) handler->Add(anaTrk);
  
  //---------------------------------------------------------------
  //Event loop
  //---------------------------------------------------------------	  
  Long64_t entries_tot =  chain->GetEntriesFast(); //93064
  if(nentries<0) nentries = chain->GetEntries();
  // Long64_t nentries = 20;//chain->GetEntriesFast();
  Printf("nentries: %lld  tot: %lld",nentries,entries_tot);
  for (Long64_t jentry=0; jentry<nentries;jentry++) {

    //Run producers
    // Printf("produce hiEvent");
    // p_evt->Run(jentry);   //hi event properties
    //Printf("produce pf particles");
    p_pf->Run(jentry);    //pf particles
    if(doTracks) p_trk->Run(jentry);    //tracks
    p_PUJet->Run(jentry); //jets
    
    //Execute all analysis tasks
    handler->ExecuteTask();
  }
    
  fEventObjects->Print();

  TFile *out = new TFile(outname,"RECREATE");
  TList *tasks = handler->GetListOfTasks();
  TIter next(tasks);
  anaBaseTask *obj;
  while ((obj = dynamic_cast<anaBaseTask*>(next()) ))
    if(obj->GetOutput()) obj->GetOutput()->Write(obj->GetName(),TObject::kSingleKey);
  
  out->Write();
  out->Close();
  
}
void analyzePFvsCaloJetsppData(std::vector<std::string> urls, const char *outname = "eventObjects.root", Long64_t nentries = 20, Int_t firstF = -1, Int_t lastF = -1) {

  // std::vector<std::string> urls = CollectFiles(list);

  // Printf("anaFile: %d",anaFile);
  
  std::cout << "nfiles: " << urls.size() << std::endl;
  for (auto i = urls.begin(); i != urls.end(); ++i)
    std::cout << *i << std::endl;

  size_t firstFile = 0;
  size_t lastFile = urls.size();

  if(firstF>-1) {
    firstFile = (size_t)firstF;
    lastFile = (size_t)lastF;
  }
  std::cout << "firstFile: " << firstFile << "  lastFile: " << lastFile << std::endl;
  
  //add files to chain
  TChain *chain = NULL;
  chain = new TChain("hiEvtAnalyzer/HiTree");
  for(size_t i=firstFile; i<lastFile; i++) chain->Add(urls[i].c_str());
  Printf("hiTree done");

  TChain *hltTree = new TChain("hltanalysis/HltTree");
  for(size_t i=firstFile; i<lastFile; i++) hltTree->Add(urls[i].c_str());
  chain->AddFriend(hltTree);
  Printf("hltTree done");

  TChain *skimTree = new TChain("skimanalysis/HltTree");
  for(size_t i=firstFile; i<lastFile; i++) skimTree->Add(urls[i].c_str());
  chain->AddFriend(skimTree);
  Printf("skimTree done");

  //TChain *pileupTree = new TChain("pileup/tree");
  // for(size_t i=firstFile; i<lastFile; i++) pileupTree->Add(urls[i].c_str());
  //chain->AddFriend(pileupTree);
  
  TChain *pfTree = new TChain("pfcandAnalyzer/pfTree");
  for(size_t i=firstFile; i<lastFile; i++) pfTree->Add(urls[i].c_str());
  chain->AddFriend(pfTree);
  Printf("pfTree done");
  
  // TChain *muTree = new TChain("hltMuTree/HLTMuTree");
  // for(size_t i=firstFile; i<lastFile; i++) muTree->Add(urls[i].c_str());
  // chain->AddFriend(muTree);
  // Printf("muTree done");

  TChain *pfJetTree = new TChain("ak4PFJetAnalyzer/t");
  for(size_t i=firstFile; i<lastFile; i++) pfJetTree->Add(urls[i].c_str());
  chain->AddFriend(pfJetTree);
  Printf("pfJetTree done");

  TChain *caloJetTree = new TChain("ak4CaloJetAnalyzer/t");
  for(size_t i=firstFile; i<lastFile; i++) caloJetTree->Add(urls[i].c_str());
  //chain->AddFriend(caloJetTree);
  Printf("caloJetTree done");

  // TChain *genTree = new TChain("HiGenParticleAna/hi");
  // for(size_t i=firstFile; i<lastFile; i++) genTree->Add(urls[i].c_str());
  // chain->AddFriend(genTree);
  // Printf("genTree done");
  
  TList *fEventObjects = new TList();


  //---------------------------------------------------------------
  // producers
  //
  hiEventProducer *p_evt = new hiEventProducer("hiEvtProd");
  p_evt->SetInput(chain);
  p_evt->SetHIEventContName("hiEventContainer");
  p_evt->SetEventObjects(fEventObjects);

  pfParticleProducer *p_pf = new pfParticleProducer("pfPartProd");
  p_pf->SetInput(chain);
  p_pf->SetpfParticlesName("pfParticles");
  p_pf->SetEventObjects(fEventObjects);

  lwJetFromForestProducer *p_pfJet = new lwJetFromForestProducer("lwJetForestProd");
  p_pfJet->SetInput(pfJetTree);//chain);
  p_pfJet->SetJetContName("akt4PF");
  p_pfJet->SetGenJetContName("");//akt4Gen");
  p_pfJet->SetEventObjects(fEventObjects);
  p_pfJet->SetRadius(0.4);
  
  lwJetFromForestProducer *p_caloJet = new lwJetFromForestProducer("lwJetForestProd");
  p_caloJet->SetInput(caloJetTree);
  p_caloJet->SetJetContName("akt4Calo");
  p_caloJet->SetGenJetContName("");
  p_caloJet->SetEventObjects(fEventObjects);
  p_caloJet->SetRadius(0.4);
  
  //---------------------------------------------------------------
  //analysis modules
  //

  //handler to which all modules will be added
  anaBaseTask *handler = new anaBaseTask("handler","handler");

  anaJetMatching *matchingPFCaloJet = new anaJetMatching("matchingPFCaloJet","matchingPFCaloJet");
  matchingPFCaloJet->ConnectEventObject(fEventObjects);
  matchingPFCaloJet->SetHiEvtName("hiEventContainer");
  matchingPFCaloJet->DoPFJet80(true);
  matchingPFCaloJet->DoExcludePhoton30(true);
  matchingPFCaloJet->SetJetsNameBase("akt4PF");
  matchingPFCaloJet->SetJetsNameTag("akt4Calo");
  matchingPFCaloJet->SetNCentBins(1);
  handler->Add(matchingPFCaloJet);  
  
  anaPFvsCaloJet *anaPFCaloJet = new anaPFvsCaloJet("anaPFvsCaloJet","anaPFvsCaloJet");
  anaPFCaloJet->ConnectEventObject(fEventObjects);
  anaPFCaloJet->SetHiEvtName("hiEventContainer");
  anaPFCaloJet->DoPFJet80(true);
  anaPFCaloJet->DoExcludePhoton30(true);
  anaPFCaloJet->SetPFJetsName("akt4PF");
  anaPFCaloJet->SetCaloJetsName("akt4Calo");
  handler->Add(anaPFCaloJet);

  anaPFvsCaloJet *anaCaloPFJet = new anaPFvsCaloJet("anaCalovsPFJet","anaCalovsPFJet");
  anaCaloPFJet->ConnectEventObject(fEventObjects);
  anaCaloPFJet->SetHiEvtName("hiEventContainer");
  anaCaloPFJet->DoPFJet80(true);
  anaCaloPFJet->DoExcludePhoton30(true);
  anaCaloPFJet->SetPFJetsName("akt4Calo");
  anaCaloPFJet->SetCaloJetsName("akt4PF");
  handler->Add(anaCaloPFJet);

  /*
  //PF-GEN matching
  anaJetMatching *matchingGenPFJet = new anaJetMatching("matchingGenPFJet","matchingGenPFJet");
  matchingGenPFJet->ConnectEventObject(fEventObjects);
  matchingGenPFJet->SetHiEvtName("");
  matchingGenPFJet->SetJetsNameBase("akt4Gen");
  matchingGenPFJet->SetJetsNameTag("akt4PF");
  matchingGenPFJet->SetNCentBins(1);
  handler->Add(matchingGenPFJet);  
  
  anaPFvsCaloJet *anaGenPFJet = new anaPFvsCaloJet("anaGenVsPFJet","anaGenVsPFJet");
  anaGenPFJet->ConnectEventObject(fEventObjects);
  anaGenPFJet->SetHiEvtName("");
  anaGenPFJet->SetPFJetsName("akt4Gen");
  anaGenPFJet->SetCaloJetsName("akt4PF");
  handler->Add(anaGenPFJet);
  */
  
  //---------------------------------------------------------------
  //Event loop
  //---------------------------------------------------------------	  
  Long64_t entries_tot =  chain->GetEntriesFast(); //93064
  if(nentries<0) nentries = chain->GetEntries();
  // Long64_t nentries = 20;//chain->GetEntriesFast();
  Printf("nentries: %lld  tot: %lld",nentries,entries_tot);
  for (Long64_t jentry=0; jentry<nentries;jentry++) {
    if (jentry%10000==0) Printf("Processing event %d  %d",(int)(jentry), (int)(nentries));
    //Run producers
    // Printf("produce hiEvent");
    p_evt->Run(jentry);   //hi event properties

    //Printf("produce pf particles");
    //  p_pf->Run(jentry);    //pf particles
    p_pfJet->Run(jentry); //jets
    p_caloJet->Run(jentry); //jets
    
    //Execute all analysis tasks
    handler->ExecuteTask();
  }
    
  fEventObjects->Print();

  TFile *out = new TFile(outname,"RECREATE");
  TList *tasks = handler->GetListOfTasks();
  TIter next(tasks);
  anaBaseTask *obj;
  while ((obj = dynamic_cast<anaBaseTask*>(next()) ))
    if(obj->GetOutput()) obj->GetOutput()->Write(obj->GetName(),TObject::kSingleKey);
  
  out->Write();
  out->Close();
  
}
Example #22
0
void QAtrainAOD(Bool_t isMC=kFALSE, Int_t iCollisionType=0){

  

  if(gSystem->Getenv("ALIEN_JDL_LPMINTERACTIONTYPE")){
    for (Int_t icoll = 0; icoll < kNSystem; icoll++)
      if (strcmp(gSystem->Getenv("ALIEN_JDL_LPMINTERACTIONTYPE"), CollisionSystem[icoll]) == 0){
        iCollisionType = icoll;
	break;
      }
  }
  printf("--------------------------------------\n");
  if(isMC) printf("Run the AOD QA train for Monte Carlo\n");
  else printf("Run the AOD QA train for data\n");
  printf("Collision System is %s\n",CollisionSystem[iCollisionType]);
  printf("--------------------------------------\n");
 
  UInt_t kTriggerMask =  AliVEvent::kINT7 | AliVEvent::kINT8;
  if(gSystem->Getenv("ALIEN_JDL_LPMANCHORYEAR"))
  {
    Int_t year = atoi(gSystem->Getenv("ALIEN_JDL_LPMANCHORYEAR"));
    if(year <= 2015) 
      kTriggerMask = AliVEvent::kAnyINT;
  }
  // Create manager
  AliAnalysisManager *mgr  = new AliAnalysisManager("QAtrainAOD", "AOD QA train");
  mgr->SetCacheSize(0);
  mgr->SetCommonFileName("QAresults_AOD.root");

  // Input handler
  AliESDInputHandlerRP *esdHandler = new AliESDInputHandlerRP();
  AliAODInputHandler* aodHandler = new AliAODInputHandler();
  mgr->SetInputEventHandler(aodHandler);
  if(isMC){
    AliMCEventHandler* MChandler = new AliMCEventHandler;
    MChandler->SetReadTR(kFALSE);
    mgr->SetMCtruthEventHandler(MChandler);      
  }
  TString macroName="";

  // Physics selection
  gROOT->LoadMacro("$ALICE_PHYSICS/OADB/macros/AddTaskPhysicsSelection.C");
  AliPhysicsSelectionTask* physSelTask = AddTaskPhysicsSelection(isMC);
  mgr->AddStatisticsTask(kTriggerMask);
  AliAnalysisDataContainer *cstatsout = (AliAnalysisDataContainer*)mgr->GetOutputs()->FindObject("cstatsout");
  cstatsout->SetFileName("EventStat_temp_AOD.root");

  // PID response
  gROOT->LoadMacro("$ALICE_ROOT/ANALYSIS/macros/AddTaskPIDResponse.C");
  AliAnalysisTaskSE *setupTask = AddTaskPIDResponse(isMC);
  
  // PIDqa
  gROOT->LoadMacro("$ALICE_ROOT/ANALYSIS/macros/AddTaskPIDqa.C");
  AliAnalysisTaskPIDqa *PIDQA = AddTaskPIDqa();
  PIDQA->SelectCollisionCandidates(AliVEvent::kAny);

  // MultSelection
  gROOT->LoadMacro("$ALICE_PHYSICS/OADB/COMMON/MULTIPLICITY/macros/AddTaskMultSelection.C");
  AliMultSelectionTask *taskMult = AddTaskMultSelection();
  if(isMC){
    if (gSystem->Getenv("CONFIG_PERIOD")){
      TString periodName = gSystem->Getenv("CONFIG_PERIOD");
      taskMult->SetAlternateOADBforEstimators(periodName);
    }
  }
  // Vertex QA
  macroName="$ALICE_PHYSICS/PWGPP/macros/AddTaskCheckVertexAOD.C";
  if(gSystem->Exec(Form("ls %s > /dev/null 2>&1",macroName.Data()))==0){
    gROOT->LoadMacro(macroName.Data());
    Double_t maxMult=500.;
    if(iCollisionType==kPbPb || iCollisionType==kXeXe) maxMult=10000.;
    AliAnalysisTaskCheckVertexAOD *taskVert =  AddTaskCheckVertexAOD("QA",maxMult,AliVEvent::kAnyINT,isMC);
  }else{
    printf("Macro %s not found -> task will not be executed\n",macroName.Data());
  }

  // Track QA
  macroName="$ALICE_PHYSICS/PWGPP/macros/AddTaskCheckAODTracks.C";
  if(gSystem->Exec(Form("ls %s > /dev/null 2>&1",macroName.Data()))==0){
    gROOT->LoadMacro(macroName.Data());
    Bool_t usMCtruthForPID=isMC;
    AliAnalysisTaskCheckAODTracks* taskAODtr = AddTaskCheckAODTracks("QA",isMC,usMCtruthForPID);
    if(iCollisionType==kPbPb || iCollisionType==kXeXe) taskAODtr->SetUpperMultiplicity(10000.);
  }else{
    printf("Macro %s not found -> task will not be executed\n",macroName.Data());
  }


  // HF deltaAOD QA
  macroName="$ALICE_PHYSICS/PWGHF/vertexingHF/macros/AddTaskBasicHFQA.C";
  if(gSystem->Exec(Form("ls %s > /dev/null 2>&1",macroName.Data()))==0){
    gROOT->LoadMacro(macroName.Data());
    AliAnalysisTaskSEHFQA* dqaHF = AddTaskBasicHFQA(AliAnalysisTaskSEHFQA::kD0toKpi,isMC,"QA");
  }else{
    printf("Macro %s not found -> task will not be executed\n",macroName.Data());
  }

  if(isMC){
    macroName="$ALICE_PHYSICS/PWGHF/vertexingHF/macros/AddTaskDmesonMCPerform.C";
    if(gSystem->Exec(Form("ls %s > /dev/null 2>&1",macroName.Data()))==0){
      gROOT->LoadMacro(macroName.Data());
      AliAnalysisTaskDmesonMCPerform* dMCp = AddTaskDmesonMCPerform("QA");
    }else{
      printf("Macro %s not found -> task will not be executed\n",macroName.Data());
    }
  }

  TChain *chainAOD = new TChain("aodTree");
  TChain *chainAODfriend = new TChain("aodTree");
  chainAOD->Add("AliAOD.root");
  chainAODfriend->Add("AliAOD.VertexingHF.root"); 
  chainAOD->AddFriend(chainAODfriend);

  TStopwatch timer;
  timer.Start();
  if (mgr->InitAnalysis()) {                      
    mgr->PrintStatus(); 
    mgr->SetSkipTerminate(kTRUE);
    mgr->StartAnalysis("local", chainAOD);
  }
  gSystem->Exec("rm TreeOfAODTracks.root");
  timer.Print();
}