Esempio n. 1
0
void fillhist(const char* filename, const char* treename, int process, double scale, TH1* hist) {
    TFile* file = new TFile(filename);
    TTree* tree = (TTree*)file->Get(treename);

    TBranch *bmet    = tree->GetBranch("mumet");
    TBranch *bweight = tree->GetBranch("weight");
    TBranch *bnjets  = tree->GetBranch("njets");
    TBranch *bjjdphi = tree->GetBranch("jetjetdphi");

    double vmet     = 0.0;
    double vweight  = 0.0;
    unsigned vnjets = 0;
    double vjjdphi  = 0.0;

    bmet   ->SetAddress(&vmet);
    bweight->SetAddress(&vweight);
    bnjets ->SetAddress(&vnjets);
    bjjdphi->SetAddress(&vjjdphi);

    for (int i = 0; i < tree->GetEntries(); i++) {
        bmet   ->GetEvent(i);
        bweight->GetEvent(i);
        bnjets ->GetEvent(i);
        bjjdphi->GetEvent(i);

        if (process == 0) vweight *= scale;
        if (process == 1) vweight *= scale * (5.942 * 1.023) / (0.79*(1.0-exp(-0.00910276*(vmet-36.1669))));
        if (process == 2) vweight *= scale * 38.7823/pow(-85.7023 + vmet, 0.667232);
        hist->Fill(vmet, vweight);
    }
}
Esempio n. 2
0
File: portfolio.C Progetto: Y--/root
//---------------------------------------------------------------------------
TArrayF &StockReturn(TFile *f,const TString &name,Int_t sDay,Int_t eDay)
{
  TTree *tDaily = (TTree*)f->Get(name);
  TStockDaily *data = 0;
  tDaily->SetBranchAddress("daily",&data);
  TBranch *b_closeAdj = tDaily->GetBranch("fCloseAdj");
  TBranch *b_date     = tDaily->GetBranch("fDate");

  //read only the "adjusted close" branch for all entries
  const Int_t nrEntries = (Int_t)tDaily->GetEntries();
  TArrayF closeAdj(nrEntries);
  for (Int_t i = 0; i < nrEntries; i++) {
    b_date->GetEntry(i);
    b_closeAdj->GetEntry(i);
    if (data->fDate >= sDay && data->fDate <= eDay)
      closeAdj[i] = data->fCloseAdj/100.;
  }

  TArrayF *r = new TArrayF(nrEntries-1);
  for (Int_t i = 1; i < nrEntries; i++)
//    (*r)[i-1] = closeAdj[i]-closeAdj[i-1];
    (*r)[i-1] = closeAdj[i]/closeAdj[i-1];

  return *r;
}
Esempio n. 3
0
void GetTreeSize(TString FileName, TString TreeName)
{
  TFile *inf          = TFile::Open(FileName);
  TTree *tr           = (TTree*)inf->Get(TreeName);
  TObjArray *branches = (TObjArray*)tr->GetListOfBranches();
  int size(0);
  cout.setf(ios::right);
  int N(branches->GetEntries());
  TH1F *hSize = new TH1F("size","size",N,0,N);
  for(int ib=0;ib<N;ib++) {
    TString name(branches->At(ib)->GetName());
    TBranch *br = (TBranch*)tr->GetBranch(name);
    hSize->Fill(name,br->GetZipBytes()/1e+3); 
    size += br->GetZipBytes();
  } 
  cout<<"Total size: "<<size<<endl;
  for(int ib=0;ib<N;ib++) {
    TString name(branches->At(ib)->GetName());
    TBranch *br = (TBranch*)tr->GetBranch(name);
    float percent = TMath::Ceil(1000*float(br->GetZipBytes())/float(size))/10;
    cout<<ib<<setw(20)<<name<<setw(15)<<br->GetZipBytes()<<" "<<percent<<"%"<<endl;
  }

  TCanvas *can = new TCanvas("TreeSize","TreeSize",1000,400);
  hSize->GetXaxis()->SetTitle("Branch Name");
  hSize->GetXaxis()->SetLabelSize(0.04);
  hSize->GetYaxis()->SetTitle("Size (KB)");
  hSize->SetFillColor(kGray);
  hSize->Draw();
}
Esempio n. 4
0
// This ROOT macro counts the number of protons that stop in the thick silicon detectors
void ProtonCounting(std::string filename) {

  TFile* file = new TFile(filename.c_str(), "READ");

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

  std::vector<std::string>* particleName = 0;
  std::vector<std::string>* volName = 0;
  std::vector<std::string>* ovolName = 0;
  std::vector<int>* stopped = 0;
  
  TBranch* br_particleName = tree->GetBranch("M_particleName");
  TBranch* br_volName = tree->GetBranch("M_volName");
  TBranch* br_ovolName = tree->GetBranch("M_ovolName");
  TBranch* br_stopped = tree->GetBranch("M_stopped");

  br_particleName->SetAddress(&particleName);
  br_volName->SetAddress(&volName);
  br_ovolName->SetAddress(&ovolName);
  br_stopped->SetAddress(&stopped);

  int n_protons = 0;
  int n_protons_right = 0;
  int n_protons_left = 0;
  int n_stopped_muons = 0;
  for (int iEntry = 0; iEntry < tree->GetEntries(); ++iEntry) {

    tree->GetEvent(iEntry);

    for (int iElement = 0; iElement < particleName->size();  ++iElement) {

      if (particleName->at(iElement) == "proton" && volName->at(iElement) == "ESi1" && stopped->at(iElement) == 1 && ovolName->at(iElement) == "Target") {
	++n_protons_right;
	++n_protons;
      }
      else if (particleName->at(iElement) == "proton" && volName->at(iElement) == "ESi2" && stopped->at(iElement) == 1 && ovolName->at(iElement) == "Target") {
	++n_protons_left;
	++n_protons;
      }
      else if (particleName->at(iElement) == "mu-" && volName->at(iElement) == "Target" && stopped->at(iElement) == 1) {
	++n_stopped_muons;
      }
    }
  }

  std::cout << "There were " << n_protons << " protons that reached the thick silicon detectors out of " << n_stopped_muons << " stopped muons (" << tree->GetEntries() << " input muons." << std::endl;
  std::cout << "N_right = " << n_protons_right << ", N_left = " << n_protons_left << std::endl;
  std::cout << "Acceptance = " << (double) n_protons / n_stopped_muons << std::endl;
}
Esempio n. 5
0
Tracks * loadTracks(Int_t Runs, Int_t dataType, Float_t energy) {
   TString sDataType = (dataType == 0) ? "_MC_" : "_data_";
   TString sAbsThick = Form("_%.0fmm", kAbsorbatorThickness);
   TString sEnergy = Form("_%.2fMeV", energy);
   TString fileName = "Data/Tracks/tracks";
   TString sMaterial = getMaterialChar();
   fileName.Append(sDataType);
   fileName.Append(sMaterial);
   fileName.Append(sAbsThick);
   fileName.Append(sEnergy);
   fileName.Append(".root");
   
   TFile *f = new TFile(fileName);
   if (!f) return 0;
   TTree *T = (TTree*) f->Get("T");
   Tracks * tracks = new Tracks();

   T->GetBranch("tracks")->SetAutoDelete(kFALSE);
   T->SetBranchAddress("tracks",&tracks);


   T->GetEntry(0);
   
   cout << "There are " << tracks->GetEntriesFast() << " tracks in " << fileName << ".\n";
   
   return tracks;
}
Esempio n. 6
0
File: hw.C Progetto: geonmo/HepClass
hw()
{
    Float_t data;
    TFile *f=new TFile("data.root");
    TTree* tree = f->Get("mytree");
    TBranch* branch = tree->GetBranch("data");
    branch->SetAddress(&data);

    TH1F* h1 = new TH1F("h1","h1",200,0.0,5.0);
    for(Int_t i= 0 ; i< tree->GetEntries() ; i++) {
	tree->GetEntry(i);
        h1->Fill( data) ;
    }
       
    TF1 *f2 = new TF1("f2", "[0]*x+[1]+gaus(2)", 0.0, 5.0);
    f2->SetParameter(3,3.7);

    TVirtualFitter *min = TVirtualFitter::Fitter(0,2);
    TVirtualFitter::SetDefaultFitter("Minuit");

    TFitResultPtr fitresult = h1->Fit("f2", "MES");
    cout<< "Parameter 0" << fitresult->Parameter(0) << "+-" << fitresult->ParError(0) << endl;
    cout<<  "Parameter 1" <<fitresult->Parameter(1) << "+-" << fitresult->ParError(1) << endl;
    cout << "Chi2 " << fitresult->Chi2() << endl;
    cout << "NDF " << fitresult->Ndf() << endl;
    cout << "Chi2 probability " << fitresult->Prob() << endl;
    TMatrixD covmat(fitresult->GetCovarianceMatrix());
    cout << "Covariance matrix" << endl;
    covmat.Print();
    TCanvas *c1 = new TCanvas("c1", "binned line fit", 600, 600);
    c1->Draw();
    h1->Draw();


}
Esempio n. 7
0
void histogram() {
	// Read data from ASCII file and create histogram/ntuple combo
	ifstream in;
 	in.open("/users/ronnie/git/Journal-Analysis/data.txt");

	Text_t month;
 	Float_t date, day, words;
	TFile *file = new TFile("histogramTest.root", "CREATE");
	TH1F *histo = new TH1F("histo", "writing distribution", 100, 0, 2);
	TTree *Tree = new TTree("ntuple", "data from file");
					
	Tree->ReadFile(Form("/users/ronnie/git/Journal-Analysis/Daily Journals/data.txt"), "month:date:day:words");
	graph = new TGraph(200, &words, &day);
	// Get the total number of words written and print out to CLI
	Tree->Print();
	Int_t numEntries = (Int_t)(Tree->GetEntries());
	TBranch *wordsBranch = Tree->GetBranch("words");
	for(Int_t i = 0; i < numEntries; i++) {
		Tree->GetEntry(i, 0);
	}
	// Draw the Tree (words vs. day) on canvas
	Tree->SetEstimate(Tree->GetEntries());
	Tree->Draw("words:day");
	// Have to loop back through drawn tree to get values and count number of words total
	Float_t numWords = 0.0;
	Double_t *array = Tree->GetV1();
	for (Int_t i = 0; i < numEntries; i++) {
		numWords += array[i];
	}
	cout << numWords << endl;
}
void CheckOutput(){
  //
  //
  //
  TFile * f  = TFile::Open("Filtered.root");
  TTree * highPt = (TTree*)f->Get("highPt");
  TTree * treeV0s = (TTree*)f->Get("V0s");
  //
  // Export variable:
  //
  Double_t ratioHighPtV0Entries=treeV0s->GetEntries()/Double_t(treeV0s->GetEntries()+highPt->GetEntries()+0.000001);
  Double_t ratioHighPtV0Size=treeV0s->GetZipBytes()/Double_t(treeV0s->GetZipBytes()+highPt->GetZipBytes()+0.000001);
  printf("#UnitTest:\tAliAnalysisTaskFiltered\tRatioPtToV0Entries\t%f\n",ratioHighPtV0Entries);
  printf("#UnitTest:\tAliAnalysisTaskFiltered\tRatioPtToV0Size\t%f\n",ratioHighPtV0Size);
  //
  //
  Double_t ratioPointsV0 = 2*treeV0s->GetBranch("friendTrack0.fCalibContainer")->GetZipBytes()/Double_t(0.00001+treeV0s->GetZipBytes());
  Double_t ratioPointsHighPt = highPt->GetBranch("friendTrack.fCalibContainer")->GetZipBytes()/Double_t(0.00001+highPt->GetZipBytes());
  printf("#UnitTest:\tAliAnalysisTaskFiltered\tRatioPointsV0\t%f\n",ratioPointsV0);
  printf("#UnitTest:\tAliAnalysisTaskFiltered\tRatioPointsHighPt\t%f\n",ratioPointsHighPt);
  //
  // a.) Check track correspondence
  //
  Int_t entries= highPt->Draw("(friendTrack.fTPCOut.fP[3]-esdTrack.fIp.fP[3])/sqrt(friendTrack.fTPCOut.fC[9]+esdTrack.fIp.fC[9])","friendTrack.fTPCOut.fP[3]!=0","");
  // here we should check if the tracks
  Double_t pulls=TMath::RMS(entries, highPt->GetV1());
  printf("#UnitTest:\tAliAnalysisTaskFiltered\tFriendPull\t%2.4f\n",pulls);
  printf("#UnitTest:\tAliAnalysisTaskFiltered\tFriendOK\t%d\n",pulls<10);

}
int PlotSignals(char *filename, int plfrom=0, int plto=100, int same=1) {

  bragg_signal signal;

  TFile *fin=new TFile(filename);
  if (!fin->IsOpen()) {
    std::cout << "file not found! " << std::endl;
    return -1;
  }

  TTree *tree = (TTree*)fin->Get("bragg");
  if (!tree) {
    std::cout << "Bragg tree not found! " << std::endl;
    return -2;
  }

  TBranch *br = tree->GetBranch("signals");
  if (!br) {
    std::cout << "Signal branch not found! " << std::endl;
    return -3;
  }

  br->SetAddress(&signal);
  int nev = br->GetEntries();
  std::cout << "Number of events in file : " << nev << std::endl;

  for (int i=plfrom; i<plto; i++) {
    br->GetEntry(i);
    plotSignal(signal,same);  
  }
  
  return 0;
}
Esempio n. 10
0
void drawmerged(Int_t sec, Int_t row, Int_t x1=-1, Int_t x2=-1, Int_t y1=-1, Int_t y2=-1)
{
  /// if you think that there is memory leak -
  /// you are tru but othervise graphic doesn't work
  /// sec=0; row =0;

  TFile * f = new TFile("galice.root");
  TFile * f1= new TFile("ev1/galice.root.digits");
  TFile * f2= new TFile("ev2/galice.root.digits");
  TTree * tree = (TTree*)f->Get("TreeD_75x40_100x60_150x60_0");
  TTree * tree1 = (TTree*)f1->Get("TreeD_75x40_100x60_150x60_0");
  TTree * tree2 = (TTree*)f2->Get("TreeD_75x40_100x60_150x60_0");
  //
  AliSimDigits *dig=0;
  AliSimDigits *dig1=0;
  AliSimDigits *dig2=0;
  //
  tree->GetBranch("Segment")->SetAddress(&dig);
  tree1->GetBranch("Segment")->SetAddress(&dig1);
  tree2->GetBranch("Segment")->SetAddress(&dig2);
  AliTPCParam * param =(AliTPCParam*) f->Get("75x40_100x60");
  if(param){
    delete param;
    param=new AliTPCParamSR();
  }
  else param=(AliTPCParam*) f->Get("75x40_100x60_150x60");
  Int_t index = param->GetIndex(sec,row);
  tree->GetEvent(index);
  tree1->GetEvent(index);
  tree2->GetEvent(index);

  TCanvas * c = new TCanvas(" Test merged digits", "test",600,900);
  c->Divide(1,3);
  //
  c->cd(1);
  AliH2F * his = dig->DrawDigits("cont1",x1,x2,y1,y2);
  his->SetTitle("MergedDigits");
  his->SetName("Merged Digits");
  his->GetXaxis()->SetTitle("time");
  his->GetYaxis()->SetTitle("pad");
  his->DrawClone("cont1");
  //
  c->cd(2);
  AliH2F * his1 =dig1->DrawDigits("cont1",x1,x2,y1,y2); 
  his1->SetTitle("background");
  his1->SetName("background");
  his1->GetXaxis()->SetTitle("time");
  his1->GetYaxis()->SetTitle("pad");
  his1->DrawClone("cont1"); 
  //
  c->cd(3);
  AliH2F * his2 =dig2->DrawDigits("cont1",x1,x2,y1,y2); 
  his2->SetTitle("signal");
  his2->SetName("signal");
  his2->GetXaxis()->SetTitle("time");
  his2->GetYaxis()->SetTitle("pad");
  his2->DrawClone("cont1");  
}
Esempio n. 11
0
int test_event()
{
   TTree *T = (TTree*)gFile->Get("T");
   SillyStlEvent *event = new SillyStlEvent();
   event->foo = 0xfa3;
   TBranch *branch = T->GetBranch("test");
   branch->SetAddress(&event);
   T->GetEvent(0);
   return event->foo.to_ulong() != 0xfa2;
}
Esempio n. 12
0
void h2fast(const char *url , Bool_t draw=kFALSE, Long64_t cachesize=10000000, Int_t learn=1) {
// gEnv->SetValue("TFile.DavixLog", 10);
//  gDebug= 0x02;
   TStopwatch sw;
   TTree* T = NULL;
   sw.Start();
   Long64_t oldb = TFile::GetFileBytesRead();
   TFile *f = TFile::Open(url);
  
   if (!f || f->IsZombie()) {
      printf("File h1big.root does not exist\n");
      exit (-1);
   }
   

//   TTreeCacheUnzip::SetParallelUnzip(TTreeCacheUnzip::kEnable);

   T= (TTree*)f->Get("h42");
   Long64_t nentries = T->GetEntries();
   T->SetCacheSize(cachesize);
   TTreeCache::SetLearnEntries(learn);
   TFileCacheRead *tpf = f->GetCacheRead();
   //tpf->SetEntryRange(0,nentries);
   
   if (draw) T->Draw("rawtr","E33>20");
   else {
      TBranch *brawtr = T->GetBranch("rawtr");
      TBranch *bE33   = T->GetBranch("E33");
      Float_t E33; 
      bE33->SetAddress(&E33);
      for (Long64_t i=0;i<nentries;i++) {
         T->LoadTree(i);
         bE33->GetEntry(i);
         if (E33 > 0) brawtr->GetEntry(i);
      } 
   } 
   if (tpf) tpf->Print();
   printf("Bytes read = %lld\n",TFile::GetFileBytesRead()-oldb);
   printf("Real Time = %7.3f s, CPUtime = %7.3f s\n",sw.RealTime(),sw.CpuTime());
   delete T;
   delete f;
}
Esempio n. 13
0
void kt_test_pico(TString fin="test.root") 
{
  
  gROOT->Reset();
  gROOT->Clear();
  
  // ktJet lib
  if (gClassTable->GetID("ktJet") < 0) {
    cout<<"Load ktJet lib ..."<<endl;
    gSystem->Load("libKtJet.so");
  }

  cout<<endl;
  cout<<" Test STAR pico Dst interface"<<endl;
  cout<<" ----------------------------"<<endl;
  cout<<endl;
  cout<<"Open STAR pico Dst file : "<<fin<<endl;
  cout<<endl;

  TFile *inFile = TFile::Open(fin);
  inFile->cd();
  TTree *outT = inFile->Get("JetTree");

  TStarJetPicoEvent *event = new TStarJetPicoEvent();
  TBranch *branch = outT->GetBranch("PicoJetTree");
  branch->SetAddress(&event);
  
  Int_t ievents = outT->GetEntries();

  cout<<"Number of events = "<<ievents<<endl;

  ktStarPico *mQA=new ktStarPico(true);
  mQA->PrintQACuts();

  for (Int_t i = 0; i<ievents; i++)
    {
      if (i>250) continue;
      
      outT->GetEvent(i);

      mQA->DoQAOnly(event);

    }

  mQA->WriteQAOutputFile("QA_test_out.root");

  //inFile->Close();

  delete mQA;

  cout<<endl;
  cout<<"Done ;-)"<<endl;
  cout<<endl;
}
Esempio n. 14
0
void testgeo(const char* rootfile)
{

  // Clear global scope
  gROOT->Reset();

  // Load the library with class dictionary info
  gSystem->Load("libWCSimRoot.so");

  // Open the file, replace if you've named it something else
  TFile file(rootfile);
  
  // Get the a pointer to the tree from the file
  TTree *gtree = (TTree*)file.Get("wcsimGeoT");
  
  // Get the number of events
  int nevent = gtree->GetEntries();
  printf("geo nevent %d\n",nevent);
  
  // Create a WCSimRootGeom to put stuff from the tree in

  WCSimRootGeom* wcsimrootgeom = new WCSimRootGeom();

  // Set the branch address for reading from the tree
  TBranch *branch = gtree->GetBranch("wcsimrootgeom");
  branch->SetAddress(&wcsimrootgeom);

  // Now loop over "events"  (should be only one for geo tree)
  int ev;
  for (ev=0;ev<nevent; ev++)  {
      // Read the event from the tree into the WCSimRootGeom instance
      gtree->GetEntry(ev);
      printf("Cyl radius %f\n", wcsimrootgeom->GetWCCylRadius());
      printf("Cyl length %f\n", wcsimrootgeom->GetWCCylLength());
      printf("PMT radius %f\n", wcsimrootgeom->GetWCPMTRadius());
      printf("Offset x y z %f %f %f\n", wcsimrootgeom->GetWCOffset(0),
	     wcsimrootgeom->GetWCOffset(1),wcsimrootgeom->GetWCOffset(2));
      int numpmt = wcsimrootgeom->GetWCNumPMT();
      printf("Num PMTs %d\n", numpmt);

      int i;
      for (i=0;i<((numpmt<20)?numpmt:20);i++){
	WCSimRootPMT pmt;
	pmt = wcsimrootgeom->GetPMT(i);
	printf ("pmt %d %d %d\n",i,pmt.GetTubeNo(), pmt.GetCylLoc());
	printf ("position: %f %f %f\n", pmt.GetPosition(0),
		pmt.GetPosition(1),pmt.GetPosition(2));
	printf ("orientation: %f %f %f\n", pmt.GetOrientation(0),
		pmt.GetOrientation(1),pmt.GetOrientation(2));
      }
            
    } // End of loop over events

}
Esempio n. 15
0
AppResult GeneratorReader::beginRun(AppEvent& event) {
    TTree *Events = 0;
    if( event.get("Events",Events) || !Events )
        return AppResult(AppResult::STOP|AppResult::ERROR,"No 'Events' tree found");

    TBranch *inputGen = Events->GetBranch("BNmcparticles_BNproducer_MCstatus3_BEANs.");
    if( !inputGen ) return AppResult(AppResult::STOP|AppResult::ERROR,"No 'BNmcparticles_BNproducer_MCstatus3_BEANs.' branch found");
    inputGen->SetAddress(&__genParticles);

    return AppResult();
}
Esempio n. 16
0
void make_info_table()
{
	char key[MAX_VALUE_LEN];
	char value[MAX_VALUE_LEN];
	TTree *info = (TTree*)_file0->Get("info");

	info->GetBranch("key")->SetAddress(key);
	info->GetBranch("value")->SetAddress(value);

	cout << "<table border=\"0\">" << endl;
	cout << "<tbody>" << endl;
	int count = info->GetEntries();
	for(int i = 0; i < count; i++)
	{
		info->GetEntry(i);
		cout << "<tr><td>" << key << "</td><td>" << value << "</td></tr>" << endl;
	}
	cout << "</tbody>" << endl;
	cout << "</table>" << endl;
}
Esempio n. 17
0
void LegendreMomentShape::Open(const std::string filename)
{
	TFile* file;
	if(!filename.empty())
	{
		std::cout << "Opening " << filename << std::endl;
		file = TFile::Open(filename.c_str());
	}
	else return;
	if(file->IsZombie())
	{
		std::cerr << "No file found. Defaulting to uniform shape." << std::endl;
		delete file;
		return;
	}
	TTree* tree = (TTree*)file->Get("LegendreMomentsTree");
	if(tree == nullptr) throw std::runtime_error("LegendreMomentsTree not found");
	tree->SetBranchAddress("mKK_min",&mKK_min);
	tree->SetBranchAddress("mKK_max",&mKK_max);
	std::string limbranchtitle = tree->GetBranch("c")->GetTitle();
	// Read the index maxima from the name of the branch
	size_t found = 0;
	for(int* maximum: {&l_max, &i_max, &k_max, &j_max})
	{
		found = limbranchtitle.find('[',found+1);
		limbranchtitle.find(']',found);
		*maximum = atoi(limbranchtitle.substr(found+1,1).c_str());
	}
	double**** c = newcoefficients();
		// Set up the 4D array and prepare to read from the tree
	char branchtitle[10]; // the letter "c" + four 2-digit numbers + 1 for luck
	// Seriously I don't expect *any* 2-digit numbers
	for ( int l = 0; l < l_max; l++ )
		for ( int i = 0; i < i_max; i++ )
			for ( int k = 0; k < k_max; k++ )
				for ( int j = 0; j < j_max; j++ )
				{
					sprintf(branchtitle,"c%d%d%d%d",l,i,k,j);
					tree->SetBranchAddress(branchtitle,&c[l][i][k][j]);
				}
	tree->GetEntry(0);
	storecoefficients(c);
	deletecoefficients(c);
	if(coeffs.size() == 0)
	{
		std::cerr << "No coefficients found. Defaulting to uniform shape." << std::endl;
		return;
	}
	printcoefficients();
	delete tree;
	delete file;
	init = false;
}
Esempio n. 18
0
void spectraMaker(std::string file)
{
  Double_t fidCut = 50.;
  
  std::string filePath = "analyzed_files/"+file;

  TFile *fout = new TFile("outputHistsTest.root","RECREATE");
  TH1D *hEreconALL = new TH1D("hEreconALL","Reconstructed Energy Spectra for All events",120,0., 1200.);
  TH1D *hErecon0 = new TH1D("hErecon0","Reconstructed Energy Spectra for All events",120,0., 1200.);
  TH1D *hErecon1 = new TH1D("hErecon1","Reconstructed Energy Spectra for All events",120,0., 1200.);
  TH1D *hErecon23 = new TH1D("hErecon23","Reconstructed Energy Spectra for All events",120,0., 1200.);

  hEreconALL->GetXaxis()->SetTitle("E_{recon} (keV)");
  hErecon0->GetXaxis()->SetTitle("E_{recon} (keV)");
  hErecon1->GetXaxis()->SetTitle("E_{recon} (keV)");
  hErecon23->GetXaxis()->SetTitle("E_{recon} (keV)");
  
  TFile *fin = new TFile(filePath.c_str(),"READ");
  TTree *tin = (TTree*)(fin->Get("SimAnalyzed"));

  //variables to be read in
  Int_t PID, side, type;
  Double_t Erecon;
  Double_t mwpcPosW[3], mwpcPosE[3];
  
  tin->SetBranchAddress("PID",&PID);
  tin->SetBranchAddress("side",&side);
  tin->SetBranchAddress("type",&type);
  tin->SetBranchAddress("Erecon",&Erecon);
  tin->GetBranch("MWPCPosAdjusted")->GetLeaf("MWPCPosAdjE")->SetAddress(mwpcPosE);
  tin->GetBranch("MWPCPosAdjusted")->GetLeaf("MWPCPosAdjW")->SetAddress(mwpcPosW);

  UInt_t nevents = tin->GetEntriesFast();

  for (UInt_t evt=0; evt<nevents; evt++) {
    tin->GetEvent(evt);

    if (PID!=1) continue;
    if ((mwpcPosW[0]*mwpcPosW[0]+mwpcPosW[1]*mwpcPosW[1]>fidCut*fidCut) || (mwpcPosE[0]*mwpcPosE[0]+mwpcPosE[1]*mwpcPosE[1]>fidCut*fidCut)) continue;

    //Fill appropriate histograms if cuts are passed.
    if (type<4) hEreconALL->Fill(Erecon);
    if (type==0) hErecon0->Fill(Erecon);
    else if (type==1) hErecon1->Fill(Erecon);
    else if (type==2 || type==3) hErecon23->Fill(Erecon);  
  }

  fin->Close();

  fout->Write();
  fout->Close();
}
Esempio n. 19
0
int main() {
    // Get a map of the histograms of the Z Masses
    const std::string Tree_HighCut = "ZFinder/Combined Single Reco/Combined Single Reco";
    const std::string Tree_LowCut = "ZFinder/Combined Single Lowered Threshold Reco/Combined Single Lowered Threshold Reco";
    const std::string file_name = "/data/whybee0a/user/gude_2/Data/20150324_SingleElectron_2012ALL/hadded.root";
    // Open the file and load the tree
    TTree* treeH = GetTTree(file_name, Tree_HighCut);
    TBranch* event_infoH = treeH->GetBranch("event_info");
    TLeaf* EVNumbH = event_infoH->GetLeaf("event_number");
    // Pack into a hitogram
    std::set<int> eventnumber;
    std::set<int> eventnumberLow;
    for (int i = 0; i < treeH->GetEntries(); i++) {
        treeH->GetEntry(i);
        if (eventnumber.find(EVNumbH->GetValue()) == eventnumber.end()) {
            eventnumber.insert(EVNumbH->GetValue());
        } else {
            cout << "multiple events numbered :" << EVNumbH->GetValue()<<" in higher cuts" << endl;
        }

    }

    TTree* TreeLow = GetTTree(file_name, Tree_LowCut);
    TBranch* event_infoL = TreeLow->GetBranch("event_info");
    TLeaf* EVNumbLow = event_infoL->GetLeaf("event_number");
    for (int i = 0; i < TreeLow->GetEntries(); i++) {
        TreeLow->GetEntry(i);
        eventnumberLow.insert(EVNumbLow->GetValue());
        if (eventnumberLow.find(EVNumbLow->GetValue()) == eventnumber.end()) {
            eventnumberLow.insert(EVNumbLow->GetValue());
        } else {
cout << "multiple events numbered :" << EVNumbLow->GetValue()<<" in lowered cuts" << endl;
        }

    }

    return EXIT_SUCCESS;
}
Esempio n. 20
0
 void tv3Read2() {
   //second read example illustrating how to read one branch only
   TVector3 *v = 0;
   TFile *f = new TFile("v3.root");
   TTree *T = (TTree*)f->Get("T");
   T->SetBranchAddress("v3",&v);
   TBranch *by = T->GetBranch("fY");
   TH1F *h2 = new TH1F("y","y component of TVector3",100,-5,20);
   Int_t nentries = Int_t(T->GetEntries());
   for (Int_t i=0;i<nentries;i++) {
      by->GetEntry(i);
      h2->Fill(v->y());
   }
   h2->Draw();
}
Esempio n. 21
0
void test3(){
  /// test of the merged digits

  TFile f("galice.root");
  TFile f1("ev1/galice.root.sdigits");
  TFile f2("ev2/galice.root.sdigits");
  TTree * tree = (TTree*)f.Get("TreeD_75x40_100x60_150x60_0");
  TTree * tree1 = (TTree*)f1.Get("TreeS_75x40_100x60_150x60_0");
  TTree * tree2 = (TTree*)f2.Get("TreeS_75x40_100x60_150x60_0");
  //
  AliSimDigits *dig=0;
  AliSimDigits *dig1=0;
  AliSimDigits *dig2=0;
  //  
  tree->GetBranch("Segment")->SetAddress(&dig);
  tree1->GetBranch("Segment")->SetAddress(&dig1);
  tree2->GetBranch("Segment")->SetAddress(&dig2);
  //
  for (Int_t i=0;i<6000;i++){
    tree->GetEvent(i);
    tree1->GetEvent(i);
    tree2->GetEvent(i);
    if ( (dig1->GetID()!=i) || (dig2->GetID()!=i) ) {
      printf("missed segments\n");
    }
    //
    dig->ExpandBuffer();
    dig1->ExpandBuffer();
    dig2->ExpandBuffer();
    //
    Int_t nrows = dig->GetNRows();
    Int_t ncols = dig->GetNCols();
    //
    for (Int_t rows=0;rows<nrows; rows++)
      for (Int_t col=0;col<ncols; col++){
	Int_t d  = dig->GetDigitFast(rows,col);
	Int_t d1 = dig1->GetDigitFast(rows,col)/16;
	Int_t d2 = dig2->GetDigitFast(rows,col)/16;	
	if (abs(d-d1-d2)>4)
	//if (d2>5)
	  printf("%d\t%d\t%d\t%d\t%d\t%d\n",i,rows,col,d,d1,d2);
      }
  }
}
Esempio n. 22
0
void test5(){
  /// compare merged digits with digits obtained hits2sdig->sdigtodig

  TFile f("galice.root");
  TFile f1("ev1/galice.root.dig2");
  TFile f2("ev2/galice.root.dig2");
  TTree * tree = (TTree*)f.Get("TreeD_75x40_100x60_150x60_0");
  TTree * tree1 = (TTree*)f1.Get("TreeD_75x40_100x60_150x60_0");
  TTree * tree2 = (TTree*)f2.Get("TreeD_75x40_100x60_150x60_0");

  AliSimDigits *dig=0;
  AliSimDigits *dig1=0;
  AliSimDigits *dig2=0;
  
  tree->GetBranch("Segment")->SetAddress(&dig);
  tree1->GetBranch("Segment")->SetAddress(&dig1);
  tree2->GetBranch("Segment")->SetAddress(&dig2);




  for (Int_t i=0;i<6000;i++){
    tree->GetEvent(i);
    tree1->GetEvent(i);
    tree2->GetEvent(i);
    dig->ExpandBuffer();
    dig1->ExpandBuffer();
    dig2->ExpandBuffer();
    
    Int_t nrows = dig->GetNRows();
    Int_t ncols = dig->GetNCols();

    for (Int_t rows=0;rows<nrows; rows++)
      for (Int_t col=0;col<ncols; col++){
	Int_t d  = dig->GetDigitFast(rows,col);
	Int_t d1 = dig1->GetDigitFast(rows,col);
	Int_t d2 = dig2->GetDigitFast(rows,col);
	
	if (abs(d-d1-d2)>4)
	//if (d2>5)
	  printf("%d\t%d\t%d\t%d\t%d\t%d\n",i,rows,col,d,d1,d2);
      }
  }
}
Esempio n. 23
0
void drawd(TFile * f, Int_t amp1, Int_t amp2)
{
  TTree * tree = (TTree*)f->Get("TreeD_75x40_100x60_150x60_0");
  AliSimDigits *dig=0;
  tree->GetBranch("Segment")->SetAddress(&dig); 
  TH1F * his = new TH1F("his","his",amp2-amp1,amp1,amp2);
  for (Int_t i=0;i<60;i++){  
    tree->GetEvent(i);   
    dig->ExpandBuffer();
    Int_t nrows = dig->GetNRows();
    Int_t ncols = dig->GetNCols();
    for (Int_t rows=0;rows<nrows; rows++)
      for (Int_t col=0;col<ncols; col++){    
	Int_t d  = dig->GetDigitFast(rows,col);
	his->Fill(d);
      }
  }
  his->Draw();
}
Esempio n. 24
0
int main (int argc, char** argv)
{
  // check number of inpt parameters
  if (argc < 3)
    {
      cerr << argv[0] << " filename branchname" << endl ;
      return 1 ;
    }


   TFile f (argv[1], "update") ;
   TTree *T = (TTree*) f.Get ("HTauTauTree") ;
   TBranch *b = T->GetBranch (argv[2]) ;
   T->GetListOfBranches ()->Remove (b) ;
   T->Write () ;
   f.Close () ;
   
   return 0 ;
}   
void validateTauFakeRateKNN()
{
  TCanvas* canvas = new TCanvas("canvas", "canvas", 1, 1, 800, 600);
  canvas->SetFillColor(10);
  canvas->SetBorderSize(2);
  
  canvas->SetLogy();

  TString inputFilePath = "/data2/friis/FakeRatesHPSXCheck_V2/fakerate_ewkTauIdHPSloose_WplusJets_data_jetNoEta20FullVal/train";
  //TString inputFilePath = "/data2/friis/FakeRatesHPSXCheck_V2/fakerate_ewkTauIdHPSloose_PPmuX_data_jetNoEta20FullVal/train";
  TString inputFileName = "train_FakeRateMethod_output.root";

  TFile* file = TFile::Open(TString(inputFilePath).Append("/").Append(inputFileName));

  TString testTreeName = "TestTree";
  TTree* testTree = (TTree*)file->Get(testTreeName);

  std::string ptName = "Pt";
  std::string etaName = "AbsEta";
//--- Check if fake-rates are parametrized by jetPt or tau Pt
  if ( testTree->GetBranch("JetPt") ) {
    std::cout << "Using Jet variables" << std::endl;
    ptName = "JetPt";
    etaName = "AbsJetEta";
  }

  makePlot(canvas, "validateTauFakeRateKNN_WplusJets_JetPt.png", testTree, ptName, 10, 0., 100.);
  makePlot(canvas, "validateTauFakeRateKNN_WplusJets_JetEta.png", testTree, etaName, 10, -2.5, +2.5);
  makePlot(canvas, "validateTauFakeRateKNN_WplusJets_JetRadius.png", testTree, "JetWidth", 10, -0.01, 0.51);
  //makePlot(canvas, "validateTauFakeRateKNN_QCD_JetPt.png", testTree, ptName, 10, 0., 100.);
  //makePlot(canvas, "validateTauFakeRateKNN_QCD_JetEta.png", testTree, etaName, 10, -2.5, +2.5);
  //makePlot(canvas, "validateTauFakeRateKNN_QCD_JetRadius.png", testTree, "JetWidth", 10, -0.01, 0.51);
  
  delete file;

  delete canvas;
}
Esempio n. 26
0
int reader_wrapper::initFormulas(TString targetbranch) {
  /// don't care about spectators here
  // TODO: does this tree get created in the outfile?
  m_intree->SetBranchStatus("*",1);
  m_outtree = m_intree->CloneTree(-1,"fast");
  int buffer(0);
  for (auto& var : m_variables) {
    var.ttreeformula = new TTreeFormula(Form("local_var_%d",buffer++),var.formula,m_outtree);
    for (size_t v = 0 ; v < var.ttreeformula->GetNcodes() ; ++v) {
      m_branches.insert(var.ttreeformula->GetLeaf(v)->GetBranch());
    }
  }
  m_outtree->SetBranchStatus("*",0);
  for (auto b : m_branches) {
    b->SetStatus(1);
  }
  // check if output branch exists already
  if (nullptr == m_outtree->GetBranch(targetbranch.Data())) {
    m_responseBranch = m_outtree->Branch(targetbranch.Data(),&m_response,(targetbranch + "/F").Data());
    return 0;
  }
  std::cout << "Output branch exists already. Aborting." << std::endl;
  return 4;
}
Esempio n. 27
0
File: tcl.C Progetto: Y--/root
void tclread()
{
// read file generated by tclwrite
// loop on all entries.
// histogram center of lines
   TFile *f = new TFile("tcl.root");
   TTree *T = (TTree*)f->Get("T");
   TH2F *h2 = new TH2F("h2","center of lines",40,0,1,40,0,1);

   TClonesArray *arr = new TClonesArray("TLine");
   T->GetBranch("tcl")->SetAutoDelete(kFALSE);
   T->SetBranchAddress("tcl",&arr);
   Long64_t nentries = T->GetEntries();
   for (Long64_t ev=0;ev<nentries;ev++) {
      arr->Clear();
      T->GetEntry(ev);
      Int_t nlines = arr->GetEntriesFast();
      for (Int_t i=0;i<nlines;i++) {
         TLine *line = (TLine*)arr->At(i);
         h2->Fill(0.5*(line->GetX1()+line->GetX2()), 0.5*(line->GetY1()+line->GetY2()));
      }
   }
   h2->Draw("lego");
}
Esempio n. 28
0
// Main macro function
//--------------------------------------------------------------------------------------------------
void SkimNtuples(const TString input = "skim.input") 
{
  gBenchmark->Start("SkimNtuples");
  
  TString outfilename;          // output of skimming 
  vector<TString> infilenames;  // list input ntuple files to be skimmed
  
  // 
  // parse input file
  //  
  ifstream ifs;
  ifs.open(input.Data()); 
  assert(ifs.is_open());
  string line;
  getline(ifs,line); 
  outfilename = line;
  while(getline(ifs,line)) { infilenames.push_back(line); }
  ifs.close();

  TTree::SetMaxTreeSize(kMaxLong64);
  
  // Don't write TObject part of the objects
  mithep::TEventInfo::Class()->IgnoreTObjectStreamer();
  mithep::TElectron::Class()->IgnoreTObjectStreamer();
  mithep::TDielectron::Class()->IgnoreTObjectStreamer();
  mithep::TMuon::Class()->IgnoreTObjectStreamer();
  mithep::TJet::Class()->IgnoreTObjectStreamer();
  mithep::TPhoton::Class()->IgnoreTObjectStreamer();
  mithep::TVertex::Class()->IgnoreTObjectStreamer();
  
  // Data structures to store info from TTrees
  mithep::TEventInfo *info    = new mithep::TEventInfo();
  TClonesArray *electronArr   = new TClonesArray("mithep::TElectron");
  TClonesArray *dielectronArr = new TClonesArray("mithep::TDielectron");
  TClonesArray *muonArr       = new TClonesArray("mithep::TMuon");
  TClonesArray *pfJetArr      = new TClonesArray("mithep::TJet");
  TClonesArray *photonArr     = new TClonesArray("mithep::TPhoton");
  TClonesArray *pvArr         = new TClonesArray("mithep::TVertex");
  
  UInt_t nInputEvts = 0;
  UInt_t nPassEvts  = 0;
  
  TFile* outfile = new TFile(outfilename, "RECREATE");
  
  //
  // Initialize data trees and structs
  // 
  TTree *outEventTree = new TTree("Events","Events"); 
  outEventTree->Branch("Info",       &info);
  outEventTree->Branch("Electron",   &electronArr);
  outEventTree->Branch("Dielectron", &dielectronArr);
  outEventTree->Branch("Muon",       &muonArr);
  outEventTree->Branch("PFJet",      &pfJetArr);
  outEventTree->Branch("Photon",     &photonArr);
  outEventTree->Branch("PV",         &pvArr);

  for(UInt_t ifile=0; ifile<infilenames.size(); ifile++) {
    cout << "Skimming " << infilenames[ifile] << "..." << endl;
    TFile *infile = new TFile(infilenames[ifile]);
    assert(infile);
    
    TTree *eventTree = (TTree*)infile->Get("Events");
    assert(eventTree);
    
    // Set branch address to structures that will store the info  
    eventTree->SetBranchAddress("Info",       &info);          TBranch *infoBr       = eventTree->GetBranch("Info");
    eventTree->SetBranchAddress("Electron",   &electronArr);   TBranch *electronBr   = eventTree->GetBranch("Electron");
    eventTree->SetBranchAddress("Dielectron", &dielectronArr); TBranch *dielectronBr = eventTree->GetBranch("Dielectron");
    eventTree->SetBranchAddress("Muon",       &muonArr);       TBranch *muonBr       = eventTree->GetBranch("Muon");
    eventTree->SetBranchAddress("PFJet",      &pfJetArr);      TBranch *pfJetBr      = eventTree->GetBranch("PFJet");
    eventTree->SetBranchAddress("Photon",     &photonArr);     TBranch *photonBr     = eventTree->GetBranch("Photon");
    eventTree->SetBranchAddress("PV",         &pvArr);         TBranch *pvBr         = eventTree->GetBranch("PV");
    
    for(UInt_t ientry=0; ientry<eventTree->GetEntries(); ientry++) { 
      infoBr->GetEntry(ientry);

      electronArr->Clear();   electronBr->GetEntry(ientry);
      dielectronArr->Clear(); dielectronBr->GetEntry(ientry);
      muonArr->Clear();       muonBr->GetEntry(ientry);
      pfJetArr->Clear();      pfJetBr->GetEntry(ientry);
      photonArr->Clear();     photonBr->GetEntry(ientry);
      pvArr->Clear();         pvBr->GetEntry(ientry);
      
      nInputEvts++;
            
      Bool_t keep = kFALSE;

      if(dielectronArr->GetEntriesFast() > 0)
        keep = kTRUE;
  
      if(keep) {
        outEventTree->Fill();
        nPassEvts++;
      }
    }
  }
  
  outfile->Write();
  outfile->Close();
  
  delete info;
  delete electronArr;
  delete dielectronArr;
  delete muonArr;
  delete pfJetArr;
  delete photonArr;
  delete pvArr;
    
  std::cout << outfilename << " created!" << std::endl;
  std::cout << " >>> Events processed: " << nInputEvts << std::endl;
  std::cout << " >>>   Events passing: " << nPassEvts << std::endl;
  
  gBenchmark->Show("SkimNtuples");
}  
Esempio n. 29
0
// Commands executed in a GLOBAL scope, e.g. created hitograms aren't erased...
void plot_HF(TString  inputfile="simevent_HF.root",
	     TString outputfile="HF_histo.root",
	     Int_t drawmode = 2,
             TString    reffile="../data/HF_ref.root")
{
  // Option to no-action(0)/draw(1)/save(2) (default = 0) histograms in gif.
  //int doDraw = 0;
   int doDraw = drawmode;

  char * treename = "Events";        //The Title of Tree.
  
  delete gROOT->GetListOfFiles()->FindObject(inputfile);

  TFile * myf  = new TFile(inputfile);
  
  TTree * tree = dynamic_cast<TTree*>(myf->Get("Events"));
  assert(tree != 0);

  TBranch * branchLayer = tree->GetBranch("PHcalValidInfoLayer_g4SimHits_HcalInfoLayer_CaloTest.obj");
  assert(branchLayer != 0);

  TBranch * branchNxN = tree->GetBranch("PHcalValidInfoNxN_g4SimHits_HcalInfoNxN_CaloTest.obj");
  assert(branchNxN != 0);

  TBranch * branchJets = tree->GetBranch( "PHcalValidInfoJets_g4SimHits_HcalInfoJets_CaloTest.obj");  assert(branchJets != 0);

  // Just number of entries (same for all branches)
  int  nent = branchLayer->GetEntries();
  cout << "Entries branchLayer : " << nent << endl;
  nent = branchJets->GetEntries();
  cout << "Entries branchJets  : " << nent << endl;
  nent = branchNxN->GetEntries();
  cout << "Entries branchNxN   : " << nent << endl;

  // Variables from branches
  PHcalValidInfoJets infoJets;
  branchJets->SetAddress( &infoJets); 
  PHcalValidInfoLayer infoLayer;
  branchLayer->SetAddress( &infoLayer); 
  PHcalValidInfoNxN infoNxN;
  branchNxN->SetAddress( &infoNxN); 
  
  //***************************************************************************
  // Histo titles-labels

  const int Nhist1     = 20, Nhist2 = 1;  // N simple and N combined histos
  const int Nhist1spec =  5;              // N special out of Nsimple total 

  TH1F *h;                              // just a pointer
  TH1F *h1[Nhist1];
  TH2F *h2g;                    // +  eta-phi grid -related for all depthes
  
  char *label1[Nhist1];
  char *label2g;
  

  // simple histos  
  label1[0]  = &"rJetHits.gif";
  label1[1]  = &"tJetHits.gif";
  label1[2]  = &"eJetHits.gif";
  label1[3]  = &"ecalJet.gif";
  label1[4]  = &"hcalJet.gif";
  label1[5]  = &"etotJet.gif";
  label1[6]  = &"jetE.gif";
  label1[7]  = &"jetEta.gif";
  label1[8]  = &"jetPhi.gif";
  label1[9]  = &"etaHits.gif";          
  label1[10] = &"phiHits.gif";
  label1[11] = &"eHits.gif";
  label1[12] = &"tHits.gif";
  label1[13] = &"eEcalHF.gif";
  label1[14] = &"eHcalHF.gif";

  // special
  label1[15] = &"tHits_60ns.gif";   
  label1[16] = &"tHits_eweighted.gif"; 
  label1[17] = &"nHits_HF.gif";
  label1[18] = &"elongHF.gif";
  label1[19] = &"eshortHF.gif";

  label2g    = &"Eta-phi_grid_all_depths.gif";


  //***************************************************************************
  //...Book histograms 

  for (Int_t i = 0; i < Nhist1-Nhist1spec; i++) {
    char hname[3]; 
    sprintf(hname,"h%d",i);

    if(i == 4 || i == 7 || i == 8 ) {
      if(i == 7) h1[i] = new TH1F(hname,label1[i],100,-5.,5.);   
      if(i == 8) h1[i] = new TH1F(hname,label1[i],72,-3.1415926,3.1415926);   
      if(i == 4) h1[i] = new TH1F(hname,label1[i],30,0.,150.);  
    }
    else { 
      h1[i] = new TH1F(hname,label1[i],100,1.,0.);  
    }

  }

  // Special : global timing < 60 ns 
  h1[15] = new TH1F("h15",label1[15],60,0.,60.);  
  // Special : timing in the cluster (7x7) enery-weighted
  h1[16] = new TH1F("h16",label1[16],60,0.,60.);  
  // Special : number of HCAL hits
  h1[17] = new TH1F("h17",label1[17],20,0.,20.);  
  // Special : signal in long fibers
  h1[18] = new TH1F("h18",label1[18],50,0.,50.);
  // Special : signal in short fibers
  h1[19] = new TH1F("h19",label1[19],50,0.,50.);

  for (int i = 0;  i < Nhist1; i++) {
     h1[i]->Sumw2();
  }

  // eta-phi grid (for muon samples)
  h2g = new TH2F("Grid",label2g,1000,-5.,5.,576,-3.1415927,3.1415927);

  //***************************************************************************
  //***************************************************************************
  //...Fetch the data and fill the histogram 

  // branches separately - 

  for (int i = 0; i<nent; i++) { 

    // cout << "Ev. " << i << endl;

    // -- get entries
    branchLayer ->GetEntry(i);
    branchNxN   ->GetEntry(i);
    branchJets  ->GetEntry(i);

    // -- Leading Jet
    int nJetHits =  infoJets.njethit();
    //cout << "nJetHits = " << nJetHits << endl; 

    std::vector<float> rJetHits(nJetHits);
    rJetHits = infoJets.jethitr();
    std::vector<float> tJetHits(nJetHits);
    tJetHits = infoJets.jethitt();
    std::vector<float> eJetHits(nJetHits);
    eJetHits = infoJets.jethite();

    float ecalJet = infoJets.ecaljet();
    float hcalJet = infoJets.hcaljet();
    float   hoJet = infoJets.hojet();
    float etotJet = infoJets.etotjet();

    float detaJet = infoJets.detajet();
    float dphiJet = infoJets.dphijet();
    float   drJet = infoJets.drjet();
    float  dijetM = infoJets.dijetm();

    
    for (int j = 0; j < nJetHits; j++) {
      h1[0]->Fill(rJetHits[j]);
      h1[1]->Fill(tJetHits[j]); 
      h1[2]->Fill(eJetHits[j]);
    }
   
    h1[3]->Fill(ecalJet); //
    h1[4]->Fill(hcalJet); //
    h1[5]->Fill(etotJet);


    // All Jets 

    int                nJets  = infoJets.njet();
    std::vector<float> jetE(nJets);
    jetE  = infoJets.jete();
    std::vector<float> jetEta(nJets);
    jetEta = infoJets.jeteta();
    std::vector<float> jetPhi(nJets);
    jetPhi = infoJets.jetphi();

    for (int j = 0; j < nJets; j++) {
      h1[6]->Fill(jetE[j]);
      h1[7]->Fill(jetEta[j]);
      h1[8]->Fill(jetPhi[j]);
    }
 
  
    // CaloHits from PHcalValidInfoLayer  
    
    int                    nHits = infoLayer.nHit();
    std::vector<float>    idHits (nHits);
    idHits = infoLayer.idHit();
    std::vector<float>   phiHits (nHits);
    phiHits = infoLayer.phiHit();
    std::vector<float>   etaHits (nHits);
    etaHits = infoLayer.etaHit();
    std::vector<float> layerHits (nHits);
    layerHits = infoLayer.layerHit();
    std::vector<float>     eHits (nHits);
    eHits = infoLayer.eHit();
    std::vector<float>     tHits (nHits);
    tHits  = infoLayer.tHit();

    int ne = 0, nh = 0; 
    for (int j = 0; j < nHits; j++) {
      int layer = layerHits[j]-1;
      int id    = (int)idHits[j];

      if(id >= 10) {ne++;}
      else {nh++;}

      //      cout << "Hit subdet = " << id  << "  lay = " << layer << endl;
 
      h1[9]->Fill(etaHits[j]);
      h1[10]->Fill(phiHits[j]);
      h1[11]->Fill(eHits[j]);
      h1[12]->Fill(tHits[j]);

      h1[15]->Fill(tHits[j]);
      h1[16]->Fill(tHits[j],eHits[j]);
      
      if(id < 6) { // HCAL only. Depth is needed, not layer !!!
	h2g->Fill(etaHits[j],phiHits[j]);
      }
      

    }
      
    h1[17]->Fill(Float_t(nh));


    // The rest  PHcalValidInfoLayer
    float elongHF  =  infoLayer.elonghf(); 
    float eshortHF =  infoLayer.eshorthf(); 
    float eEcalHF  =  infoLayer.eecalhf(); 
    float eHcalHF  =  infoLayer.ehcalhf(); 

    h1[13]->Fill(eEcalHF);
    h1[14]->Fill(eHcalHF);
 
    h1[18]->Fill(elongHF);
    h1[19]->Fill(eshortHF);

  }

  // cout << "After event cycle " << i << endl;

  //...Prepare the main canva 
  TCanvas *myc = new TCanvas("myc","",800,600);
  gStyle->SetOptStat(1111);   // set stat         :0 - nothing 
  
 
  // Cycle for 1D distributions
  for (int ihist = 0; ihist < Nhist1 ; ihist++) {
    if(h1[ihist]->Integral() > 1.e-30 && h1[ihist]->Integral() < 1.e30 ) { 
      
      h1[ihist]->SetLineColor(45);
      h1[ihist]->SetLineWidth(2); 
      
      if(doDraw == 1) {
	h1[ihist]->Draw("h");
	myc->SaveAs(label1[ihist]);
      }
    }
  }


  // eta-phi grid 
  if(h2g->Integral() > 1.e-30 && h2g->Integral() < 1.e30 ) { 
    
    h2g->SetMarkerColor(41);
    h2g->SetMarkerStyle(20);
    h2g->SetMarkerSize(0.2); 
    h2g->SetLineColor(41);
    h2g->SetLineWidth(2); 
    
    if(doDraw == 1) {	
      h2g->Draw();
      myc->SaveAs(label2g);      
    }
  }
  

  // added by Julia Yarba
  //-----------------------   
  // this is a temporary stuff that I've made
  // to create a reference ROOT histogram file

  if (doDraw == 2) {
    TFile OutFile(outputfile,"RECREATE") ;
    int ih = 0 ;

    for ( ih=0; ih<Nhist1; ih++ )
      { 
	h1[ih]->Write() ;
      }

    OutFile.Write() ;
    OutFile.Close() ;
    cout << outputfile << " histogram file created" << endl ; 
    
    return;
    
  }

  /*
  return;
  */
 

   // now perform Chi2 test for histograms using
   // "reference" and "current" histograms 
   
   
   // open up ref. ROOT file
   //
   TFile RefFile(reffile) ;
   
   // service variables
   //
   TH1F* ref_hist = 0 ;
   int ih = 0 ;
   

   // loop over specials : timing,  nhits, simhits-E  
   //
   for ( ih=15; ih<20; ih++ )
   {
      // service - name of the ref histo
      //
      char ref_hname[4] ;
      sprintf( ref_hname, "h%d", ih ) ;
      
      // retrive ref.histos one by one
      //
      ref_hist = (TH1F*)RefFile.Get( ref_hname ) ;
      
      // check if valid (no-NULL)
      //
      if ( ref_hist == NULL )
      {
         // print warning in case of trouble
	 //
	 cout << "No such ref. histogram" << *ref_hname << endl ; 
      }
      else
      {
         // everything OK - perform Chi2 test
	 //
	Double_t *res;
	Double_t pval = h1[ih]->Chi2Test( ref_hist, "UU",res ) ;
	
	// output Chi2 comparison results
	//
	cout << "[OVAL] : histo " << ih << ", p-value= " << pval << endl ;
      }
   }

   
   // close ref. ROOT file
   //
   RefFile.Close() ;
   
  // at the end, close "current" ROOT tree file
  //
  myf->Close();


  return ;  
}
Esempio n. 30
0
int main(int argc, char*argv[])
{
    //----------------------------------------------------------------------------------------
    /////////////////////////////////////////////  Read Input Parameters  ////////////////////
    //----------------------------------------------------------------------------------------
    if (argc < 2) {printf("******Error in input parameters\n");return 1;}
	

    CommandLine c1;
    c1.parse(argc,argv);
    gROOT->ProcessLine("#include >vector<");

    string InputFileName	= c1.getValue<string>	("InputFileName");
    string OutputFileName	= c1.getValue<string>	("OutputFileName");
    //string OutputFileTag	= c1.getValue<string>	("OutputFileTag");
    int NENTRIES			= c1.getValue<int>		("NEntries");
    double cross			= c1.getValue<double>	("CrossSection");
    double efficiency		= c1.getValue<double>	("Efficiency");
	bool DATA				= c1.getValue<bool>		("DATA");
	double MH2				= c1.getValue<double>	("MH2");
	bool SaveData			= c1.getValue<bool>		("SaveData");
	
	int NJET_MAX=6;
	
    if ( !c1.check() ) return 0;
    c1.print();				// Printing the options
    
    char OutputFileTag[100];
    sprintf(OutputFileTag,"mhc%.0f",sqrt(MH2));
    
    string outputfile = "plots/"+OutputFileName + "_" + OutputFileTag + ".root";
    TFile *outf = new TFile(outputfile.c_str(),"RECREATE");
    //TFile *outf = new TFile(OutputFileName.c_str(),"RECREATE");
    
    cout << "________________________________________________________________\n";
    cout << "\n";
    cout << "time start  " << endl;
    gSystem->Exec("date '+%H:%M:%S'");
    
    //----------------------------------------------------------------------------------------
    ///////////////////////////////////////////////  Histogram Output  ///////////////////////
    //----------------------------------------------------------------------------------------
    // Book histograms
    
    
    TH1 *histJet_pt[3];
    TH1 *histJet_eta[3];
    TH1 *histJet_phi[3];
	char hist_name[100];
	char hist_title[100];
	
    //----------------------------------------------------------------------------------------
    TDirectory *jetdir= outf->mkdir("jets");
    jetdir->cd();
    
    for (int i=0; i<3; i++)
    {
        sprintf(hist_name,"jet_pt%i",i);
        histJet_pt[i] = new TH1F(hist_name, "jet P_{T}", 1000, 0.0, 1000.0);
        
        sprintf(hist_name,"jet_eta%i",i);
        histJet_eta[i] = new TH1F(hist_name, "jet eta", 100, -5.0, 5.0);
        
        sprintf(hist_name,"jet_phi%i",i);
        histJet_phi[i] = new TH1F(hist_name, "jet phi", 100, -5.0, 5.0);
    }
    
    //TH1 *jet_size 		 = new TH1F("jet_size",     "Number of Jets", 10, 0, 10.0);
    TH1 *histJet_btag 	 = new TH1F("histJet_btag", "Number of B-tagged jets", 10, 0, 10.0);
    TH1 *histJet_btag_pt = new TH1F("histJet_btag_pt", "PT of B-tagged jets", 100, 0.0, 500.0);
    TH1 *histJet_btag_eta = new TH1F("histJet_btag_eta", "ETA of B-tagged jets", 100, -5.0, +5.0);

	TH1 *histJet_btag_pt_afterbjet1cut = new TH1F("histJet_btag_pt_afterbjet1cut", "PT of B-tagged jets", 100, 0.0, 500.0);
	TH1 *histJet_btag_eta_afterbjet1cut = new TH1F("histJet_btag_eta_afterbjet1cut", "ETA of B-tagged jets", 100, -5.0, +5.0);

	
	int btag[12]={35,40,45,50,55,60,65,70,80,90,100,110};
	TH1F *histJet_btag_ptbigger[12];
	for (int i=0; i<12; i++)
	{
		sprintf(hist_name,"histJet_btag%i",btag[i]);
		sprintf(hist_title,"Number of B-tagged jets for PT > %i",btag[i]);
		histJet_btag_ptbigger[i] = new TH1F(hist_name, hist_title, 10, 0.0, 10.0);
	}

	TH1 *jet_size_cut8   = new TH1F("jet_size_cut8", "Number of Jets with 30<PT GeV", 10, 0, 10.0);
    TH1 *jet_size_cut9   = new TH1F("jet_size_cut9", "Number of Jets with 15<PT<30 GeV", 10, 0, 10.0);
    TH1 *hist_before_jet_eta = new TH1F("hist_before_jet_eta", "Jet Eta Before cut 9", 100, -5.0, 5.0);
    TH1 *hist_alpha_t	 = new TH1F("hist_alpha_t", "Apha_T PT_2/M12", 100, 0, 5.0);
    
    /* TH1 *jet_size_cut8_35	 = new TH1F("jet_size_cut8_35", "jet size PT > 35", 10, 0, 10);
     TH1 *jet_size_cut8_40	 = new TH1F("jet_size_cut8_40", "jet size PT > 40", 10, 0, 10);
     TH1 *jet_size_cut8_45	 = new TH1F("jet_size_cut8_45", "jet size PT > 45", 10, 0, 10);
     TH1 *jet_size_cut8_50	 = new TH1F("jet_size_cut8_50", "jet size PT > 50", 10, 0, 10);
     
     TH1 *jet_size_cut9_35	 = new TH1F("jet_size_cut9_35", "jet size PT > 35", 10, 0, 10);
     TH1 *jet_size_cut9_40	 = new TH1F("jet_size_cut9_40", "jet size PT > 40", 10, 0, 10);
     TH1 *jet_size_cut9_45	 = new TH1F("jet_size_cut9_45", "jet size PT > 45", 10, 0, 10);
     TH1 *jet_size_cut9_50	 = new TH1F("jet_size_cut9_50", "jet size PT > 50", 10, 0, 10);
     */
    //----------------------------------------------------------------------------------------
    TDirectory *lepdir= outf->mkdir("lepton");
    lepdir->cd();
    
    
    //TH2 *hist_gen_lepton2D		= new TH2I("hist_gen_lepton2D"	, "Number of GEN Leptons ;GEN;SIM", 10, 0, 10.0,10,0,10);
    
    //TH2 *hist_gen_elec_SIM1GEN0	= new TH2F("hist_gen_elec_SIM1GEN0"	, "Number of Elec : GEN=0  and SIM=1 ;PT;ETA", 100, 0, 100,100,-5,+5);
    //TH2 *hist_gen_elec_SIM0GEN1	= new TH2F("hist_gen_elec_SIM0GEN1"	, "Number of Elec : GEN=1  and SIM=0 ;PT;ETA", 100, 0, 100,100,-5,+5);
    
    //TH2 *hist_gen_muon_SIM1GEN0	= new TH2F("hist_gen_muon_SIM1GEN0"	, "Number of Muon : GEN=0  and SIM=1 ;PT;ETA", 100, 0, 100,100,-5,+5);
    //TH2 *hist_gen_muon_SIM0GEN1	= new TH2F("hist_gen_muon_SIM0GEN1"	, "Number of Muon : GEN=1  and SIM=0 ;PT;ETA", 100, 0, 100,100,-5,+5);
    
    //TH1 *hist_gen_elec_pt		= new TH1F("hist_gen_elec_pt"	, "Elec Pt " , 100, 0, 250);
    //TH1 *hist_gen_elec_phi		= new TH1F("hist_gen_elec_phi"	, "Elec Phi ", 100, -5, 5);
    //TH1 *hist_gen_elec_eta		= new TH1F("hist_gen_elec_eta"	, "Elec Eta ", 100, -5, 5);
    
    //TH1 *hist_gen_muon_pt		= new TH1F("hist_gen_muon_pt"  , "Muon Pt " , 100, 0, 250);
    //TH1 *hist_gen_muon_phi		= new TH1F("hist_gen_muon_phi" , "Muon Phi ", 100, -5, 5);
    //TH1 *hist_gen_muon_eta		= new TH1F("hist_gen_muon_eta" , "Muon Eta ", 100, -5, 5);
    
    TH1 *histElec_pt            = new TH1F("elec_pt1"	 , "1st elec P_{T}", 100, 0.0, 500.0);
    TH1 *histElec_phi           = new TH1F("elec_pt1_phi", "1st elec Phi  ", 100, -5.0, 5.0);
    TH1 *histElec_eta           = new TH1F("elec_pt1_eta", "1st elec Eta  ", 100, -5.0, 5.0);
    
    TH1 *histMuon_pt        = new TH1F("muon_pt1"     , "1st mu P_{T}", 100, 0.0, 500.0);
    TH1 *histMuon_phi       = new TH1F("muon_pt1_phi" , "1st mu Phi  ", 100, -5.0, 5.0);
    TH1 *histMuon_eta       = new TH1F("muon_pt1_eta" , "1st mu Eta  ", 100, -5.0, 5.0);
    
    TH1 *histLepton_pt 	= new TH1F("lepton_pt"  , "lepton P_{T} ", 100, 0.0, 500.0);
    TH1 *histLepton_eta	= new TH1F("lepton_eta" , "lepton Eta   ", 100, -5.0, 5.0);
    TH1 *histLepton_phi	= new TH1F("lepton_phi" , "lepton  Phi  ", 100, -5.0, 5.0);
    
    
    //TH1 *hist_gen_elec_deltaR	= new TH1F("hist_gen_elec_deltaR" , "DeltaR Elec Eta ", 1000, 0, 0.1);
    //TH1 *hist_gen_muon_deltaR	= new TH1F("hist_gen_muon_deltaR" , "DeltaR Muon Eta ", 1000, 0, 0.1);
    
    //TH1 *hist_gen_lepton             = new TH1F("hist_gen_lepton"            , "Number of GEN Leptons ;GEN;SIM", 10, 0, 10.0);
    //TH1 *hist_lepton_before_trig     = new TH1F("numb_lepton_before_trig"    , "Number of SIM Leptons PT>20/30(elec/muon)", 10, 0, 10.0);
    //TH1 *hist_lepton_pass_trig       = new TH1F("numb_lepton_pass_trig"      , "Number of SIM Leptons PT>20/30(elec/muon)", 10, 0, 10.0);
    //TH1 *hist_lepton_before_hardphot = new TH1F("hist_lepton_before_hardphot", "Number of SIM Leptons |eta|<2.5 and PT>20/30(elec/muon)", 10, 0, 10.0);
    //TH1 *hist_lepton_before_10gev      = new TH1F("numb_lepton_before_10gev" , "Number of SIM Leptons and PT>10(elec/muon)", 10, 0, 10.0);
    
    TH1 *lepton_invmass = new TH1F("lepton_invmass", "lepton inv mass", 100, 0, 500);
    
    TH2 *bjet_lepton_delta_eta 	= new TH2F("bjet_lepton_delta_eta"   , "Delta Eta between lepton and btagjet ", 100, 0, 250, 100, 0,   +5);
    TH2 *bjet_lepton_delta_phi 	= new TH2F("bjet_lepton_delta_phi"   , "Delta Phi between lepton and btagjet ", 100, 0, 250, 100, 0, +6.3);
    TH2 *bjet_lepton_deltaR     = new TH2F("bjet_lepton_deltaR"      , "Delta R between lepton and btagjet   ", 100, 0, 250, 100, 0,  +10);
    TH1 *hist_qlep_etajet       = new TH1F("hist_qlep_etajet"      , " lepton charge x jet eta  ", 100, -3, 3);
    TH2 *bjet_qeta				= new TH2F("bjet_qeta"      ,"Bjet Eta #cdot  lepton charge   ", 100, 0, 250, 100, 0,  +10);

	sprintf(hist_name,"top inv mass assume mhc=%f.2",sqrt(MH2));
    TH1 *hist_top_inv_mass_mhc 	= new TH1F("top_inv_mass_mhc"   , hist_name, 100, 0, 500);

	sprintf(hist_name,"miss_pz assume mhc=%f.2",sqrt(MH2));
    TH1 *hist_miss_pz_mhc 	= new TH1F("miss_pz_mhc"   ,hist_name, 100, 0, 500);
	
    //----------------------------------------------------------------------------------------
    
    TDirectory *metdir= outf->mkdir("met");
    metdir->cd();
    
    TH1 *histMET_et  = new TH1F("histMET_et" , "MET",  500,  0.0, 500.0);
    TH1 *histMET_eta = new TH1F("histMET_eta", "MET Eta", 100, -5.0, 5.0);
    TH1 *histMET_phi = new TH1F("histMET_phi", "histMET_phi Phi", 100, -5.0, 5.0);
    
    //---------------------------------------------------------------------------------------------------------
    //////////////////////////////////   BRANCHES AND CHAIN OVER INPUT FILES //////////////////////////////////
    //---------------------------------------------------------------------------------------------------------
	

	string inputfile = "../filtered_events_v3/"+InputFileName + ".root";

	TFile *inf  = new TFile(inputfile.c_str());
    TTree *data = (TTree*)inf->Get("DATA");
	
	
    TBranch *b_event = data->GetBranch("eventVar");
    EVENT_VAR event;
    b_event->SetAddress(&event);


    TBranch *b_jet[10];
    JET jet[10];
    char branch_name[10];
    
    for ( int a=0; a<NJET_MAX; a++ )
    {
        sprintf(branch_name,"jet%iVar",a+1);
        b_jet[a]= (TBranch*)data->GetBranch(branch_name);
        b_jet[a]->SetAddress( &jet[a] );
    }

    TBranch *b_lep = (TBranch*)data->GetBranch("mu1Var");
    LEPTON lep;
    b_lep->SetAddress( &lep );
    
    Long64_t numberOfEntries = b_event->GetEntries();

    cout << "Set Branch Addresses" << endl;
    
    //----------------------------------------------------------------------------------------
    /////////////////////////////////////  LOOP  Over the EVENTS  ////////////////////////////
    //----------------------------------------------------------------------------------------

    unsigned entries = 0;
    
    if (NENTRIES==-1) entries=numberOfEntries;
    else entries=NENTRIES;
    
    cout << "Reading TREE: " << numberOfEntries << " events available, \n";
    cout << "\t\t" << NENTRIES << " of them will be analyzed." << endl;
    
    //	int status[500];
    //	int pid[500];
    //	int mother[500];
    
    int event_counter0_after_trigger=0;
    int event_counter1_after_hardlepton=0;
    int event_counter2_after_10gev=0;
    int event_counter3_after_leptonpt55=0;
    int event_counter4_after_met=0;
    int event_counter4_after_alpha_t    =0;
    int event_counter5_after_btag=0;
    int event_counter5a_after_deltaEta=0;
    int event_counter6_after_topinvmass=0;
    int event_counter7_after_leptinvmass=0;
    int event_counter8_after_onejet=0;
    int event_counter9_after_onejet=0;
    int event_counter10_after_jeteta=0;
    int final_counter=0;

    //int part_counter=0;
	//int signal_counter=0;
    //int nevents=0;
    int counter_saved=0;
	int decade = 0;

    
	/////////////////////////////////////////////////////////////////////////////////////////////////////////////
	//___________________________________________________________________________________________________________
	/////////////////////////////////////////////////////////////////////////////////////////////////////////////

    // Loop over all events
    for(Long64_t entry = 0; entry < entries; ++entry)
    {
        //nevents++;
		//progress( entries, entry );
		double progress = 10.0*entry/(1.0*entries);
		int k = TMath::FloorNint(progress);
		if (k > decade) {   cout << 10*k << "%\t"; gSystem->Exec("date '+%H:%M:%S'"); cout << endl;	}
		decade = k;

        // Load selected branches with data from specified event
        for ( unsigned int a =0; a<NJET_MAX; a++ )	b_jet[a]->GetEvent(entry);

		b_event->GetEvent(entry);
        b_lep->GetEvent(entry);
        ////////////////////////////////////////////////////////////////////////////////////
        // 0. TRIGGER EMULATION
        ////////////////////////////////////////////////////////////////////////////////////
		/*
		1. Analysis over the lepton cut for PT > MUONPT_CUT or PT > ELECTRONPT_CUT
         in the central region then if there is a soft lepton get rid of this event.
		2. All THESE events are just for single lepton trigger passed ones.
		*/
		
		////////////////////////////////////////////////////////////////////////////////////
		////////////////////////////////////////////////////////////////////////////////////

        if(lep.ID==11 && lep.PT < 25) continue;
        if(lep.ID==13 && lep.PT < 35) continue;

        if(lep.ID==11)
        {
            histElec_pt->Fill(lep.PT);
            histElec_eta->Fill(lep.Eta);
            histElec_phi->Fill(lep.Phi);
        }
        else
            if(lep.ID==13)
            {
                histMuon_pt->Fill(lep.PT);
                histMuon_eta->Fill(lep.Eta);
                histMuon_phi->Fill(lep.Phi);
            }

        histLepton_pt->Fill(lep.PT);
        histLepton_eta->Fill(lep.Eta);
        histLepton_phi->Fill(lep.Phi);

        //////////////////////////////////////////////////////////
        // KINEMATICAL CUT on Leptons PT
        // filter the event if there is lepton PT>55
        //////////////////////////////////////////////////////////

		//if ( lep.PT  < 50 && lep.PT > 30 ) continue;
		if ( lep.PT > 45 ) continue;

        event_counter3_after_leptonpt55++;

        ////////////////////////////////////////////////////////////////////
        //  MET cut
        ////////////////////////////////////////////////////////////////////

        histMET_et->Fill(event.MET);
        histMET_eta->Fill(event.METEta);
        histMET_phi->Fill(event.METPhi);
		
		// double MET_CUT=40;
		double MET_CUT=55;
        if (event.MET < MET_CUT ) continue;
        event_counter4_after_met++;

        ////////////////////////////////////////////////////////////////////
        //	ALPHA_T FILTER
        ////////////////////////////////////////////////////////////////////
        
        double alpha_t=0;
        double jet_inv_mass12=sqrt(2*jet[0].PT*jet[1].PT*(cosh(jet[0].Eta-jet[1].Eta)-cos(jet[0].Phi-jet[1].Phi)));
        alpha_t=(double)(jet[1].PT)/jet_inv_mass12;
        hist_alpha_t->Fill(alpha_t);
        
        //if( alpha_t > 0.4 ) continue;
        event_counter4_after_alpha_t++;

        ////////////////////////////////////////////////////////////////////
        //	BTAG FILTER
        ////////////////////////////////////////////////////////////////////

        int counter_btag=0;
		for (int j=0; j<12; j++)
		{
			counter_btag=0;
			// filter bjet tagged events
			for (int i=0; i<NJET_MAX; i++)
			{
				if( jet[i].BTag==1 && jet[i].PT > 30 && jet[i].PT < btag[j] ) counter_btag++;
			}
			histJet_btag_ptbigger[j]->Fill(counter_btag);
        }
        
        
        
        
        JET this_bjet;
        counter_btag=0;

		for (int i=0; i<NJET_MAX; i++)
		{
			if( jet[i].PT < 100 && jet[i].BTag==1 )
			{
				histJet_btag_pt->Fill(jet[i].PT);
				histJet_btag_eta->Fill(jet[i].Eta);
				counter_btag++;
				this_bjet=jet[i];
			}
		}
		histJet_btag->Fill(counter_btag);

		if ( counter_btag != 1 ) continue;

		histJet_btag_pt_afterbjet1cut->Fill(this_bjet.PT);
		histJet_btag_eta_afterbjet1cut->Fill(this_bjet.Eta);


		if ( this_bjet.PT <40 ) continue;
        event_counter5_after_btag++;

        
        //////////////////////////////////////////////////////////////////////////////////////
        //////////////////////////////////////////////////////////////////////////////////////
        //counter_saved++;
        //if ( SaveData && (double)cross*200*efficiency < counter_saved ) break;
        //////////////////////////////////////////////////////////////////////////////////////
        //////////////////////////////////////////////////////////////////////////////////////
        

		//////////////////////////////////////////////////////////////////////////////////////
		// BJET-LEPTON ETA DISTRIBUTION
		//////////////////////////////////////////////////////////////////////////////////////

		double deltaR2=pow(abs( (this_bjet.Eta)-(lep.Eta) ),2)+pow(abs( (this_bjet.Phi)-(lep.Phi) ),2);
        double deltaEta=abs( (this_bjet.Eta)-(lep.Eta) );
		bjet_lepton_delta_eta->Fill( lep.PT, deltaEta );
        bjet_lepton_delta_phi->Fill( lep.PT, abs( (this_bjet.Phi)-(lep.Phi) ));
        bjet_lepton_deltaR->Fill( lep.PT, sqrt(deltaR2) );

		hist_qlep_etajet->Fill(lep.Charge * jet[0].Eta);
        bjet_qeta->Fill(this_bjet.PT, lep.Charge * this_bjet.Eta);
    
        if ( deltaEta > 1.5 ) continue;
        event_counter5a_after_deltaEta++;
        
        //////////////////////////////////////////////////////////////////////////////////////
        // TOP INVARIANT MASS
        //////////////////////////////////////////////////////////////////////////////////////

        double miss_pz_mhc=missing_energy_pz(&lep,  &event, MH2);
			
        double top_inv_mass_mhc=top_invariant_mass(&this_bjet, &lep, &event, MH2);
			
		hist_miss_pz_mhc->Fill(miss_pz_mhc);
			
        hist_top_inv_mass_mhc->Fill(top_inv_mass_mhc);
		
        //if ( top_inv_mass_mhc < 230  ) continue;
        event_counter6_after_topinvmass++;

		//////////////////////////////////////////////////////////////////////////////////////
		// LEPTON INVARIANT MASS
		//////////////////////////////////////////////////////////////////////////////////////

		double leptoninvariantmass=lepton_invariant_mass(&lep, &event);
		lepton_invmass->Fill(leptoninvariantmass);

        if ( leptoninvariantmass > 65  ) continue;
        event_counter7_after_leptinvmass++;
        
		//////////////////////////////////////////////////////////////////////////////////////
        //	JET BRANCH
		//////////////////////////////////////////////////////////////////////////////////////
        int numb_hardjet=0;
        
        // eliminate hard jets
        JET this_hardjet;
        for (int i=0; i< NJET_MAX; i++)
        {
            if ( (jet[i].PT)>35 && abs(jet[i].Eta)< 4.9 )
            {
                this_hardjet=jet[i];
                numb_hardjet++;
            }
                
            if (i>2)continue;
            histJet_pt[i]->Fill(jet[i].PT);
            histJet_eta[i]->Fill(jet[i].Eta);
            histJet_phi[i]->Fill(jet[i].Phi);
        }
        jet_size_cut8->Fill(numb_hardjet);
        
        if (numb_hardjet !=1) continue;
        //if (numb_hardjet == 0) continue;
        event_counter8_after_onejet++;
        
        // eliminate soft jets
        JET this_softjet;
        int numb_softjet=0;
        
        for (int i=0; i< NJET_MAX; i++)
        {
            if ( (jet[i].PT)>15 && (jet[i].PT)<35 && abs(jet[i].Eta)< 4.9 )
            {
                numb_softjet++;
                this_softjet=jet[i];
            }
        }
		
        jet_size_cut9->Fill(numb_softjet);
        
		//if (numb_softjet!=1) continue;
        event_counter9_after_onejet++;
        
        // eliminate jets with central pseudorapidity distributions
        hist_before_jet_eta->Fill(this_hardjet.Eta);
		//if ( abs(this_hardjet.Eta) < 2.5 ) continue;
        event_counter10_after_jeteta++;
        
        final_counter++;
		
    }	//end of event loop
    
    ////////////////////////////////////////////////////////////////////////////////////////////////////////////////
    ////////////////////////////////////////////////////////////////////////////////////////////////////////////////
    
    TVectorD *crossdata = (TVectorD*)inf->Get("cross");
    TVectorD *effdata   = (TVectorD*)inf->Get("eff");
    TVectorD *neve      = (TVectorD*)inf->Get("neve");
    
    double nevents  =  (*neve)[0];

	//double test=(*crossdata)[0];

//	outf->cd();
//	TVectorD cross1(1);
//	cross1[0] = cross;
//	cross1.Write("cross");
//	
//	TVectorD eff1(12);
//	eff1[0]  =  (*effdata)[0];
//	eff1[1]  =  (double)event_counter3_after_leptonpt55/nevents;
//	eff1[2]  =  (double)event_counter4_after_met/nevents;
//	eff1[3]  =  (double)event_counter4_after_alpha_t/nevents;
//	eff1[4]  =  (double)event_counter5_after_btag/nevents;
//	eff1[5]  =  (double)event_counter5a_after_deltaEta/nevents;
//	eff1[6]  =  (double)event_counter6_after_topinvmass/nevents;
//	eff1[7]  =  (double)event_counter7_after_leptinvmass/nevents;
//	eff1[8]  =  (double)event_counter8_after_onejet/nevents;
//	eff1[9]  =  (double)event_counter9_after_onejet/nevents;
//	eff1[10] =  (double)event_counter10_after_jeteta/nevents;
//	eff1[11] =  (double)final_counter/nevents;
//	eff1.Write("eff");
	
    //---------------------------------------------------------------------------------------------------------
    ////////////////////////////////  Saving the histograms into output  //////////////////////////////////////////
    //---------------------------------------------------------------------------------------------------------
    // end of event loop
    
    cout << "nevents : " << nevents << endl;
    
    cout << "_____________________________________________________________________" << endl;
    cout << " 0  event after trigger     : "    << event_counter0_after_trigger     << "\t" << (double)event_counter0_after_trigger/nevents		<< "\t" << (double)event_counter0_after_trigger/nevents*cross*1000      << endl;
    cout << " 1  event after hard lepton : "    << event_counter1_after_hardlepton  << "\t" << (double)event_counter1_after_hardlepton/nevents  << "\t" << (double)event_counter1_after_hardlepton/nevents*cross*1000   << endl;
    cout << " 2  event after 10gev       : "    << event_counter2_after_10gev       << "\t" << (double)event_counter2_after_10gev/nevents       << "\t" << (double)event_counter2_after_10gev/nevents*cross*1000        << endl;
    cout << " 3  event after Lep(PT)>55  : "    << event_counter3_after_leptonpt55  << "\t" << (double)event_counter3_after_leptonpt55/nevents  << "\t" << (double)event_counter3_after_leptonpt55/nevents*cross*1000   << endl;
    cout << " 4  event after met > 50    : "    << event_counter4_after_met         << "\t" << (double)event_counter4_after_met/nevents         << "\t" << (double)event_counter4_after_met/nevents*cross*1000          << endl;
    cout << " 4  event after alp_t > 0.5 : "    << event_counter4_after_alpha_t     << "\t" << (double)event_counter4_after_alpha_t/nevents     << "\t" << (double)event_counter4_after_alpha_t/nevents*cross*1000      << endl;
    cout << " 5  event after btag = 1    : "    << event_counter5_after_btag        << "\t" << (double)event_counter5_after_btag/nevents        << "\t" << (double)event_counter5_after_btag/nevents*cross*1000         << endl;
    cout << " 5a event after delta Eta   : "    << event_counter5a_after_deltaEta   << "\t" << (double)event_counter5a_after_deltaEta/nevents   << "\t" << (double)event_counter5a_after_deltaEta/nevents*cross*1000    << endl;
    cout << " 6  event after topinvmass  : "    << event_counter6_after_topinvmass  << "\t" << (double)event_counter6_after_topinvmass/nevents  << "\t" << (double)event_counter6_after_topinvmass/nevents*cross*1000   << endl;
    cout << " 7  event after leptinvmass : "    << event_counter7_after_leptinvmass << "\t" << (double)event_counter7_after_leptinvmass/nevents << "\t" << (double)event_counter7_after_leptinvmass/nevents*cross*1000  << endl;
    cout << " 8  event after numb_jet =1 : "    << event_counter8_after_onejet      << "\t" << (double)event_counter8_after_onejet/nevents      << "\t" << (double)event_counter8_after_onejet/nevents*cross*1000       << endl;
    cout << " 9  event after numb_jet =1 : "    << event_counter9_after_onejet      << "\t" << (double)event_counter9_after_onejet/nevents      << "\t" << (double)event_counter9_after_onejet/nevents*cross*1000       << endl;
    cout << " 10 event after jet_eta>2.5 : "    << event_counter10_after_jeteta     << "\t" << (double)event_counter10_after_jeteta/nevents     << "\t" << (double)event_counter10_after_jeteta/nevents*cross*1000      << endl;
    cout << " 10 final counter           : "    << final_counter                    << "\t" << (double)final_counter/nevents                    << endl;

    cout << "_____________________________________________________________________" << endl;
	cout << " ntuple create eff : "<< (*effdata)[0];
	cout << "    analyze event eff : " << (double)final_counter/nevents;
	cout << "    final eff " << (*effdata)[0]*final_counter/nevents << endl;
    cout << " number of expct events L=1fb^-1  : "    << "\t" << (double)final_counter/nevents*(*effdata)[0]*cross*1000 ;
    cout << "\t" << InputFileName.c_str() << endl;
    
    
    //myfile.close();
    outf->Write();
    outf->Close();
    
    //end of main loop
}