Example #1
0
//________________________________________________________________________________
Syst* MPSys(TString Sys, TString BaseMC, TString filepart, TString filedirunf, TString histoName, TH1F* CurveBase ) {

  //save output directory
  TDirectory* current=gDirectory;

  TFile* fileM =NULL; fileM  = TFile::Open(filedirunf+"unf_"+BaseMC+filepart+"_SYS"+Sys+"M.root","READ");
  TFile* fileP =NULL; fileP  = TFile::Open(filedirunf+"unf_"+BaseMC+filepart+"_SYS"+Sys+"P.root","READ");
  cout <<  "FileM: "  << filedirunf+"unf_"+BaseMC+filepart+"_SYS"+Sys+"M.root" << " ptr: " <<  fileM  << endl;
  cout <<  "FileP: "  << filedirunf+"unf_"+BaseMC+filepart+"_SYS"+Sys+"P.root" << " ptr: " <<  fileP  << endl;
  //if (fileM==0 || fileP==0) return 0;
  if (fileM==0 || fileP==0) cout << "ERROR: NO fileM or NO fileP" <<endl;
  
  TH1F* CurveM = (TH1F*) fileM->FindObjectAny(histoName);
  TH1F* CurveP = (TH1F*) fileP->FindObjectAny(histoName);
  cout <<  "CurveM : "  << CurveM  << " CurveP: " <<  CurveP   << endl;

  Syst* Sys_test = new Syst(Sys, CurveBase, CurveM, CurveP);

  //recall output directory
  current->cd();
  Sys_test->write();
  fileM->Close();  delete fileM; 
  fileP->Close();  delete fileP;
  delete CurveM;   delete CurveP;

  return Sys_test;
}
Example #2
0
void call_fit_chi2(std::string filename)
{

  TFile *inf = new TFile(filename.data());
  std::string remword="_histo.root";
  size_t pos = filename.find(remword);
  std::string forOutput = filename;  
  if(pos!= std::string::npos)
    forOutput.swap(forOutput.erase(pos,remword.length()));   

  std::string histo = forOutput + "MixData";
  cout << "Finding " << histo << endl;
  TH1F *h_data = (TH1F*)inf->FindObjectAny(histo.data());

  histo = forOutput + "MixSig";
  cout << "Finding " << histo << endl;
  TH1F *h_sig  = (TH1F*)inf->FindObjectAny(histo.data());

  histo = forOutput + "MixBkg";
  cout << "Finding " << histo << endl;
  TH1F *h_bkg  = (TH1F*)inf->FindObjectAny(histo.data());

//   TH1F* h_data = (TH1F*)h_sig->Clone();
//   h_data->Reset();
//   h_data->Sumw2();
//   h_data->Add(h_sig,h_bkg,1.0,1.0);
 
  fit_chi2(h_data,h_sig,h_bkg,forOutput);


}
Example #3
0
//--------------------------------------------------------------------------------------------------
void catalogFile(const char *dir, const char *file)
{
  TString fileName = TString(dir) + slash +  + TString(file);
  //printf("Index: %d\n",fileName.Index("castor/cern.ch"));
  if (fileName.Index("castor/cern.ch") != -1)
    fileName = TString("castor:") + fileName;
  if (fileName.Index("pnfs/cmsaf.mit.edu") != -1) {
    fileName = dCacheDoor + fileName;
  }
  if (fileName.Index("mnt/hadoop/cms/store") != -1) {
    fileName.Remove(0,15);
    fileName = hadoopDoor + fileName;
  }
  
  printf("\n Opening: %s\n\n",fileName.Data());
  TFile* f       = TFile::Open(fileName.Data());

  TTree* tree = (TTree*) f->FindObjectAny("Delphes");
  if (tree) {
    printf("0000 %s %d %d\n",fileName.Data(),tree->GetEntries(),tree->GetEntries());
    return;
  }

  TTree* tree    = (TTree*) f->FindObjectAny("Events");
  if (tree)
    printf("XX-CATALOG-XX %s %d\n",fileName.Data(),tree->GetEntries());

  TTree* allTree = (TTree*) f->FindObjectAny("AllEvents");
  if (tree && allTree)
    printf("XX-CATALOG-XX %s %d %d\n",fileName.Data(),tree->GetEntries(),allTree->GetEntries());
}
void PixelMergeSmallFiles(){

    TFile * oFilebDist = new TFile("bDistr2.root", "RECREATE");
    TNtuple* SimEventsGlobal = new TNtuple("SimEventGlob", "SimEventGlob", "EvN:b");
    
    TFile * oFileLinks = new TFile("Links2.root", "RECREATE");
    TNtuple* LinksGlobal = new TNtuple("LinksGlob", "LinksGlob", "EvN:fedid:linkn:nHits");
    
    char FileInNumber[5];
    string FileInPath = "/net/pstore01/d00/scratch/icali/CMSSW_2_1_11/PixelAnalysis/PixelNTuple_hydjet_x2_mb_oldPL_d20081106/";
    string FileInNameRoot= "hydjet_x2_mb_oldPL_d20081106_r0";
    
    Float_t j = 0;    
    for(int FileN = 901; FileN <1801; ++FileN){
    
         sprintf(FileInNumber, "%.5d", FileN);
         string FileInName = FileInPath+FileInNameRoot+FileInNumber+".root";
         TFile *iFile = new TFile((const char*)FileInName.c_str());
         if(!iFile->IsZombie()){
           PixelAnalyzer->cd();
    
           TNtuple *FEDLinks = (TNtuple*)iFile->FindObjectAny("Links");
           TNtuple *SimEvents = (TNtuple*)iFile->FindObjectAny("SimEvent");
    
           Float_t FEDEvN, fedid, linkn, nHits;
           FEDLinks->SetBranchAddress("EventN",&FEDEvN);
           FEDLinks->SetBranchAddress("fedid",&fedid);
           FEDLinks->SetBranchAddress("linkn",&linkn);
           FEDLinks->SetBranchAddress("nHits",&nHits);
           Long64_t FEDLinkLenght =FEDLinks->GetEntries(); 
    
           Float_t SimEvN, b;
           SimEvents->SetBranchAddress("EventN",&SimEvN);
           SimEvents->SetBranchAddress("mult",&b);
           Long64_t SimEventLenght =SimEvents->GetEntries(); 
           
           Long64_t i;
           for(i=0; i < SimEventLenght; ++i){
             SimEvents->GetEntry(i);
             SimEventsGlobal->Fill(i, b);
           } 
           
          Float_t OldEvN= -1;        
          for(i=0; i < FEDLinkLenght; ++i){
             FEDLinks->GetEntry(i);
             if(OldEvN != FEDEvN){
                OldEvN= FEDEvN;
                ++j;
             }
             LinksGlobal->Fill(j, fedid, linkn, nHits);
             
          }
      }
    }
    oFilebDist->Write();
    oFileLinks->Write();
}
TTree * load(std::string iName) { 
  TFile *lFile = new TFile(iName.c_str());
  lFile->cd();
  TTree *lTree  = (TTree*) lFile->FindObjectAny("Tree");
  if(lTree == 0) lTree = (TTree*) lFile->FindObjectAny("Flat"); 
  if(lTree == 0) lTree = (TTree*) lFile->FindObjectAny("TestTree"); 
  if(lTree == 0) lTree = (TTree*) lFile->FindObjectAny("TauCheck"); 
  return lTree;
}
//_______________________________________ 
 int OpenDataThisFile(TString fname ) {
 
 	int success = 0 ;

       // open the ROOT file to process
   TString path ="./data1/moukaddam/SpiceTestSep2014/Calibration/Files/";
   TString inFileName = fname+".root";
   TFile *inFile = new TFile(path + inFileName);
   
   if ( !inFile->IsOpen() )  { //try present directory
   cout << "File doesn't exist in the directory  : " << path << endl ; 
   cout << "Trying the present working directory : ./" << endl ; 
   path ="./";
   inFile = new TFile(path + inFileName);
   }
   
   if ( inFile->IsOpen() ) {
       success = 1 ;
   	   cout << "Opening the root file and grabing the histograms from " << inFile->GetName() << endl ; 
   	   inFile->ls(); 
   }
   else {
   cout << "File is not found.. EXIT!"<< endl;
   exit(-1);
   } 
	   
	 gFolderHistos = (TFolder*)(inFile->FindObjectAny("histos"));
	 
	 return success ;
   }  
Example #7
0
std::map<string, double> getMean(char target[6], char list[20], char part[5], 
				 char ene[6], char ctyp0[10]="Multi",
				 char dir[12]="histo") {

  std::vector<std::string> types = typesOld();
  std::map<string, double> means;
  
  char ofile[100];
  sprintf (ofile, "%s/histo_%s%s_%s_%sGeV.root", dir, target, list, part, ene);
  std::cout << "Input File: " << ofile << "\n";
  TFile *fout = TFile::Open(ofile);
  fout->cd();

  TH1I *hi[20];
  char name[160], title[160], ctype[20];

  for (unsigned int ii=0; ii<=(types.size()); ii++) {
    if      (ii == 0) sprintf (ctype, "All Particles");
    else              sprintf (ctype, "%s", types[ii-1].c_str());

    sprintf (name, "%s%s%s%sGeV(%s)", ctyp0, target, list, ene, ctype);
    hi[ii] = (TH1I*)fout->FindObjectAny(name);
    //    std::cout << "Histo " << ii << " Name " << name << " " << hi[ii] << " " << hi[ii]->GetMean() << "\n";
    
    string a(ctype);
    means[a] = hi[ii]->GetMean();
  }

  //  printMeans(means);

  return means;
}
//------------------------------------------------------------------------------
// getTreeFromFile
//------------------------------------------------------------------------------
TTree* getTreeFromFile(const char* infname, const char* tname)
{
  bool verbose = false;

  if (verbose) {
    cout << "--- Open file " << infname << endl;
  }
  
  TFile* inf = new TFile(infname,"read");
  assert(inf);

  TTree* t = (TTree*)inf->Get(tname);
  
  if (!t) {
    TDirectory *dir = (TDirectory*)inf->FindObjectAny("eleIDdir");
    if (!dir) {
      cout << "Cannot get Directory HwwNtuplerMod from file " << infname << endl;
      assert(dir);
    }
    t = (TTree*)dir->Get(tname);
  }

  if (!t) {
    cout << "Cannot get Tree with name " << tname << " from file " << infname << endl;
  }
  assert(t);


  if (verbose) {
    cout << "---\tRecovered tree " << t->GetName()
	 << " with "<< t->GetEntries() << " entries" << endl;
  }
  
  return t;
}
Example #9
0
void Run( const char *inFileName, const char *outFileName, 
	  const char *dirname, const char *treeName) {  
  char name[500];
  sprintf(name, "%s.root",inFileName);
  TFile *infile = TFile::Open(name);
  TDirectory *dir = (TDirectory*)infile->FindObjectAny(dirname);
  TTree *tree = (TTree*)dir->FindObjectAny(treeName);
  std::cout << tree << " tree with nentries (tracks): " << tree->GetEntries() << std::endl;
  CalibTree t(tree);
  sprintf(name, "%s_%s_%s.root", outFileName, inFileName, dirname);
  std::string outFile(name);
  t.BookHisto(outFile);

  double cvgs[100], itrs[100]; 
  unsigned int k(0);
  for (; k<20; ++k) {
    double cvg = t.Loop(k);
    itrs[k] = k;
    cvgs[k] = cvg;
    //    if (cvg < 0.00001) break;
  }
  TGraph *g_cvg;
  g_cvg = new TGraph(k, itrs, cvgs);
  t.fout->WriteTObject(g_cvg, "g_cvg");
  std::cout << "Finish looping after " << k << " iterations" << std::endl;
}
Example #10
0
void spectrum(char *filename = "example.root")
{
   TFile *infile = new TFile(filename);
   TTree *data = (TTree*) infile->FindObjectAny("data");
   
   TH1F *h[10];
   
   TCanvas *c = new TCanvas("c","",960,480);
   TPad *p = new TPad("p","",0,0,1,1);
   p->Divide(4,2,0.01,0.01);
   p->Draw();

   double norm;
   for (int i=0;i<8;i++)
   { 
      p->cd(i+1);
      p->GetPad(i+1)->SetLogy();
      h[i] = new TH1F(Form("h%d",i),Form("Ch %d",i),60,-0.1,1.1);
//      data->Draw(Form("-min[%d]>>h%d",i,i),"min[0]<min[1]&&min[0]<min[2]&&min[0]<min[3]&&min[0]<min[4]&&min[0]<min[5]&&min[0]<min[6]&&min[0]<min[7]");
      data->Draw(Form("-min[%d]/256./0.86>>h%d",i,i));
      if (i==0) norm = h[i]->GetEntries();
      h[i]->SetTitle(Form("Ch %d",i));
      h[i]->SetXTitle("Pulse height (Volt)");
      h[i]->SetYTitle("#");
      h[i]->SetMarkerSize(0.5);
      h[i]->SetMarkerColor(2);
      h[i]->Sumw2();
      h[i]->Scale(1./norm);
      h[i]->SetAxisRange(1e-7,10,"Y");
      h[i]->Draw("e");
   }
}
//------------------------------------------------------------------------------
// getTreeFromFile
//------------------------------------------------------------------------------
TTree* getTreeFromFile(const char* infname, Bool_t loadFromDir = kTRUE)
{
  bool verbose = false;

  if (verbose) {
    cout << "--- Open file " << infname << endl;
  }
  
  TFile* inf = new TFile(infname,"read");
  assert(inf);

  TTree* t = 0;
  if (loadFromDir) {
    TDirectory *dir = (TDirectory*)inf->FindObjectAny("ElectronValidationMod");
    assert(dir);
    

    t = (TTree*)dir->Get("ElectronIDOptimizationTree");
    assert(t);
  } else {
    t = (TTree*)inf->Get("ElectronIDOptimizationTree");  
  }

  if (verbose) {
    cout << "---\tRecovered tree " << t->GetName()
	 << " with "<< t->GetEntries() << " entries" << endl;
  }
  
  return t;
}
Example #12
0
// get the distribution for the Z pt
TH1F* Z_Pt()
{
	TFile *inclusive = new TFile( "/afs/cern.ch/work/b/bbachu/private/Z_nunu/boosted-combo-pfmetraw-fj200.root");
	TTree *tree = new TTree();
	tree = (TTree*) inclusive->FindObjectAny( "Znunu_signal");
	Int_t event;
	Float_t genVpt;
	Float_t weight;
	Float_t jet1pt;
	Float_t mvamet;
	Int_t nentries = (Int_t) tree->GetEntries();
	//read all entries and fill the hist
	TH1F *hx = new TH1F( "Znunu_signal_genVpt", "Z Pt" , 75, 250, 1000);
	hx->Sumw2();
	tree->SetBranchAddress("weight", &weight);
	tree->SetBranchAddress("genVpt", &genVpt);
	tree->SetBranchAddress("mvamet", &mvamet);
	tree->SetBranchAddress("jet1pt", &jet1pt);
	for ( Int_t i = 0 ; i < nentries ; i++)
	{
		tree->GetEntry(i);
		if ( mvamet < 250) continue;
		if ( jet1pt < 200) continue;
		hx->Fill(genVpt , weight);
	}
return hx;
}
Example #13
0
TH1F* getHisto(string filename, string directoryname, string histoname) {
  TFile *file = new TFile(filename.c_str(),"READ");
  if (!file) {
    cout << "Could not open file " << filename << endl;
    return 0;
  }

  TDirectory *dir = (TDirectory*)file->FindObjectAny(directoryname.c_str());
  if (!dir) {
    cout << "Could not find directory " << directoryname << endl;
    delete file;
    return 0;
  }

  TH1F *hist = (TH1F*)dir->Get(histoname.c_str());
  if (!hist) {
    cout << "Could not find histogram " <<  histoname << " in directory " << directoryname << endl;
    delete dir;
    delete file;
    return 0;
  }

  hist->SetDirectory(0);
  delete dir;
  delete file;
  return hist;

}
Example #14
0
Double_t getNEvents(string filename) {

  //Get Number of Events in the Sample
  TFile *file = new TFile(filename.c_str(),"READ");
  if (!file) {
    cout << "Could not open file " << filename << endl;
    return 0;
  }

  TDirectory *dir = (TDirectory*)file->FindObjectAny("AnaFwkMod");
  if (!dir) {
    cout << "Could not find directory AnaFwkMod"
         << " in file " << filename << endl;
    delete file;
    return 0;
  }

  TH1F *hist = (TH1F*)dir->Get("hDAllEvents");
  if (!hist) {
    cout << "Could not find histogram hDEvents in directory AnaFwkMod"
         << " in file " << filename << endl;
    delete dir;
    delete file;
    return 0;
  }  
  return hist->Integral();
}
Example #15
0
TH1F* Photon_Pt()
{
	TFile *inclusive = new TFile( "/afs/cern.ch/work/b/bbachu/private/Z_nunu/boosted-combo-pfmetraw-fj200.root");
	TTree *tree = new TTree();
	tree = (TTree*) inclusive->FindObjectAny( "Photon_photon_control");
	Int_t event;
	Float_t ptpho;
	Float_t mvamet;
	Float_t jet1pt;
	Float_t weight;
	Int_t nentries = (Int_t) tree->GetEntries();
	//read all entries and fill the hist
	TH1F *hx = new TH1F( "Photon_photon_control_genVpt", "#gamma Pt " , 75 , 250 , 1000);
	hx->Sumw2();
	tree->SetBranchAddress("weight", &weight);
	tree->SetBranchAddress("ptpho", &ptpho);
	tree->SetBranchAddress("mvamet", &mvamet);
	tree->SetBranchAddress("jet1pt", &jet1pt);
	for ( Int_t i = 0 ; i < nentries ; i++)
	{
		//for boosted we need mvamet > 250 and jet1pt >200
		tree->GetEntry(i);
		if ( mvamet < 250) continue;
		if ( jet1pt < 200) continue;
		hx->Fill(ptpho , weight  /* apply efficiency factor */  /* *0.971*/ );
	}
return hx;
}
Example #16
0
void makePlots(std::string fname="runWithGun_Fix.root", 
	       std::string text="Fixed Depth Calculation",
	       std::string prefix="Fix", bool save=false) {
  std::string name[4] = {"ECLL_EB", "ECLL_EBref", "ECLL_EE", "ECLL_EERef"};
  double xrnglo[4] = {1200.0,1200.0,3100.0,3100.0};
  double xrnghi[4] = {1600.0,1600.0,3600.0,3600.0};
  std::string xtitl[4] = {"R_{Cyl} (mm)","R_{Cyl} (mm)","|z| (mm)", "|z| (mm)"};
  std::string ytitl[4] = {"# X_{0} (*100)", "# X_{0} (*100)", "# X_{0} (*100)", 
			  "# X_{0} (*100)"};
  std::string title[4] = {"EB (Normal)", "EB (Reflected)", "EE (Normal)", 
			  "EE (Reflected)"};

  gStyle->SetCanvasBorderMode(0); gStyle->SetCanvasColor(kWhite);
  gStyle->SetPadColor(kWhite);    gStyle->SetFillColor(kWhite);
  gStyle->SetOptStat(11110);
  TFile      *file = new TFile(fname.c_str());
  if (file) {
    char namep[100];
    for (int k=0; k<4; ++k) {
      TH2D* hist(0);
      for (int i=0; i<4; ++i) {
	if (i == 0) sprintf (namep, "%s", name[k].c_str());
	else        sprintf (namep, "%s;%d", name[k].c_str(),i);
	hist = (TH2D*)file->FindObjectAny(name[k].c_str());
	std::cout << namep << " read out at " << hist << std::endl;
	if (hist != 0) {
	  std::cout << "Entries " << hist->GetEntries() << std::endl;
	  if (hist->GetEntries() > 0) break;
	}
      }
      if (hist != 0) {
	sprintf (namep,"%s%s",name[k].c_str(),prefix.c_str());
	TCanvas *pad = new TCanvas(namep,namep,500,500);
	pad->SetRightMargin(0.10); pad->SetTopMargin(0.10);
	hist->GetYaxis()->SetTitle(ytitl[k].c_str());
	hist->GetXaxis()->SetTitle(xtitl[k].c_str());
	hist->SetTitle(title[k].c_str()); 
	hist->GetXaxis()->SetRangeUser(xrnglo[k],xrnghi[k]);
	hist->GetYaxis()->SetTitleOffset(1.4);
	hist->Draw();
	pad->Update();
	TPaveStats* st1 = (TPaveStats*)hist->GetListOfFunctions()->FindObject("stats");
	if (st1 != NULL) {
	  st1->SetY1NDC(0.70); st1->SetY2NDC(0.90);
	  st1->SetX1NDC(0.65); st1->SetX2NDC(0.90);
	}
	TPaveText *txt1 = new TPaveText(0.50,0.60,0.90,0.65,"blNDC");
	txt1->SetFillColor(0);
	txt1->AddText(text.c_str());
	pad->Update();
	if (save) {
	  sprintf (namep, "c_%s%s.gif",name[k].c_str(),prefix.c_str());
	  pad->Print(namep);
	}
      }
    }
  }
}
Example #17
0
void trigAnaCorrelation(char *infile="openhlt-900GeV.root",char *projectTitle = "900GeV",string source="mc")
{
   // Load input
   TFile *inf = new TFile(infile);
   TTree *HltTree =  (TTree*) inf->FindObjectAny("HltTree");
   TFile *outf = new TFile(Form("%s_hist.root",projectTitle),"RECREATE");

   // define event types
   vector<string> evtType;
   vector<string> evtTypeCut;
   evtType.push_back("All"); evtTypeCut.push_back("1==1");
   if (source=="mc") {
     evtType.push_back("Single_Diffr"); evtTypeCut.push_back("(evtType==92||evtType==93)");
     evtType.push_back("Double_Diffr"); evtTypeCut.push_back("(evtType==94)");
     evtType.push_back("Non_Single_Diffr"); evtTypeCut.push_back("(evtType!=92 && evtType!=93)");
     evtType.push_back("Non_Diffr"); evtTypeCut.push_back("(evtType!=92 && evtType!=93 && evtType!=94)");
   }
   else if (source=="data") {
     evtType.push_back("filled_filled"); evtTypeCut.push_back("(BunchCrossing==51||BunchCrossing==2724)");
     evtType.push_back("parasitic"); evtTypeCut.push_back("(BunchCrossing==1830||BunchCrossing==1833)");
     evtType.push_back("single_beam"); evtTypeCut.push_back("(BunchCrossing==3170||BunchCrossing==2276)");
     evtType.push_back("L1_ZeroBias_Ext"); evtTypeCut.push_back("(L1_ZeroBias_Ext)");
   }

   // Print out event type fractions
   cout <<"<pre>"<<endl;
   for (unsigned int i=0; i<evtType.size(); ++i) {
     int nSel = HltTree->GetEntries(evtTypeCut[i].c_str());
     cout <<std::right<<std::setw(20)<<evtType[i] << ": " <<nSel<<endl;
   }
   cout <<"</pre>"<<endl;

   // Calc Efficiencies
   for (unsigned int i=0; i<evtType.size(); ++i) {
     printEff(HltTree,evtTypeCut[i].c_str(),evtType[i].c_str(),projectTitle);
   }

   // Print efficiency results
   cout <<" | "<<setw(20)<<" ";
   for (unsigned int i=0;i<evtType.size();i++) {
      cout <<" | "<<setw(8)<<evtType[i];
   }
   cout <<" | " <<endl;

   for (int i=0;i<(int)triggers->size();i++){
      cout <<" | " <<setw(20)<<(*triggers)[i];
      for (int j=0;j<(int)results->size();j++) {
         double eff=(((*results)[j])[i])[0];
         double effErr=(((*results)[j])[i])[1];
         cout <<" | "<<setw(10)<<fixed<<setprecision(3)<<eff*100.<<"% +-";
         cout        <<setw(10)<<fixed<<setprecision(3)<<effErr*100.<<"% ";
      }
      cout <<" | "<<endl;
   }   

   // save
   outf->Write();
}
Example #18
0
void evtTime()
{
   TFile *inf = new TFile("output.root");
   TTree *data = (TTree*)inf->FindObjectAny("data");
   data->Draw("evtTime","");
   data->SetLineColor(2);
   data->Draw("evtTime","min[0]<-10&&min[1]<-10&&min[2]<-10&&min[3]<-10&&min[4]<-10&&min[5]<-10&&min[6]<-10&&min[7]<-10","same");
   cout <<data->GetEntries("min[0]<-10&&min[1]<-10&&min[2]<-10&&min[3]<-10&&min[4]<-10&&min[5]<-10&&min[6]<-10&&min[7]<-10")<<" / "<<data->GetEntries()<<endl;
}
Example #19
0
TProfile* getPlot(TProfile *h1, char *var, TCut cut, char *filename, char* treeName)
{
  TFile *inf = new TFile(filename);
  TTree *t = (TTree*)inf->FindObjectAny(treeName);
  TProfile * tmp = (TProfile*)h1->Clone();
  tmp->SetName("tmp");
  t->Draw(Form("%s>>tmp",var),cut);  
  return tmp;
}
Example #20
0
void plotMultiplicity(char target[6], char list[20], char ene[6], char part[4],
		      char dir[12]="histo", char g4ver[20]="G4.9.1.p01") {

  setStyle();
  gStyle->SetOptTitle(0);
  
  char name[1024], sym[10];
  if      (part=="pim") sprintf(sym, "#pi^{-}");
  else if (part=="pip") sprintf(sym, "#pi^{+}");
  else                  sprintf(sym, "p");

  std::vector<std::string> typeOld = typesOld();
  int energy = atoi(ene);
  
  char ofile[100];
  sprintf (ofile, "%s/histo_%s%s_%s_%sGeV.root", dir, target, list, part, ene);
  std::cout << "Input file " << ofile << "\n";
  TFile *fout = TFile::Open(ofile);
  fout->cd();

  char name[160], title[160], ctype[20], ytitle[20], cname[160];
  TH1I *hiMulti[20];
  for (unsigned int ii=0; ii<=(typeOld.size()); ii++) {
    if      (ii == 0) sprintf (ctype, "All Particles");
    else              sprintf (ctype, "%s", typeOld[ii-1].c_str());
    sprintf (name, "Multi%s%s%sGeV(%s)", target, list, ene, ctype);
    hiMulti[ii] = (TH1I*)fout->FindObjectAny(name);
    //    std::cout << ii << " (" << ctype << ") " << name << " " << hiMulti[ii] << "\n";
  }

  TCanvas *c[20];
  std::vector<std::string> types = types();
  for (unsigned int ii=0; ii<types.size(); ii++) {
    if      (ii == 0) sprintf (ctype, "All Particles");
    else              sprintf (ctype, "%s", types[ii-1].c_str());
    sprintf (cname, "Multiplicity (%s)", ctype);
    hiMulti[ii]->GetXaxis()->SetTitle(cname);
    hiMulti[ii]->SetMarkerStyle(mstyle[ii]);
    hiMulti[ii]->SetMarkerSize(msiz[ii]);
    hiMulti[ii]->SetMarkerColor(mcolor[ii]);
    hiMulti[ii]->SetLineColor(lcolor[ii]);
    hiMulti[ii]->SetLineStyle(lstyle[ii]);
    hiMulti[ii]->SetLineWidth(lwidth[ii]); 

    sprintf(cname, "c_%s%s_%s_%sGeV_Multiplicity(%s)", target, list, part, 
	    ene, ctype);
    c[ii] = new TCanvas(cname, cname, 800, 500);
    hiMulti[ii]->Draw();

    TLegend *leg = new TLegend(0.35, 0.80, 0.8, 0.87);
    char hdr[160];
    sprintf(hdr, "%s+%s at %s GeV (%s-%s)", sym, target, ene, g4ver, list);
    leg->SetHeader(hdr);  leg->SetFillColor(10); leg->SetMargin(0.45);
    leg->SetTextSize(.036); leg->Draw("same");
  }
}
Example #21
0
void fillTrees(vector<string> &fileName,vector<TTree*> &trees,string treeName)
{
   for (unsigned int i=0; i<fileName.size(); i++){
      TFile *f = new TFile(fileName[i].data());
      TTree *t = (TTree*)f->FindObjectAny(treeName.data());
      if (t==0) cout <<"Error!"<<endl;
      trees.push_back(t);
   }

}
Example #22
0
void loopMpt(
            TString outdir = "./fig/06.21HIN_loop"
             )
{
   TH1::SetDefaultSumw2();
   gSystem->mkdir(outdir,kTRUE);
   
   const int nCentBin = 2;
   int centBins[3] = {0,12,40};

   TString infdataname="../ntout/output-data-Forest2v2v3_saveTrks_v0_icPu5.root";
   TString infmcname = "../ntout/output-hy18dj80_forest2_v0_xsec_icPu5.root";
   
   bool isMC=false;
   
   TString infname=infdataname;
   if (isMC) infname=infmcname;
   
   float minJetPt1=120;
   float minJetPt2=50;
   float sigDPhi=3.1415926*2./3;
   float etamax=2.4;
   TString tag = Form("%s/HisData_icPu5_trkHPCorr_%.0f_%.0f_%.0f_eta%.0f",outdir.Data(),minJetPt1,minJetPt2,sigDPhi*1000,etamax*10);
   if (isMC) tag.ReplaceAll("HisData","HisMc");

   TFile *inf = TFile::Open(infname);
   TTree *nt =(TTree*)inf->FindObjectAny("tgj");
   cout << endl << "# " << endl;
   cout << "# " << infname << ": " << nt->GetEntries() << " events." << endl;
   cout << "# " << endl;

   TString outfname = tag+".root";   
   cout << "Output file: " << outfname << endl;
   TFile* hout = new TFile(outfname,"RECREATE");

   for (int c=0; c<nCentBin; ++c) {
      TString name = Form("%dto%d",centBins[c],centBins[c+1]);
      AnaMPT ana(name);
      ana.isMC = isMC;
      ana.cMin=centBins[c];
      ana.cMax=centBins[c+1];
      ana.minJetPt1 = minJetPt1;
      ana.minJetPt2 = minJetPt2;
      ana.maxJetEta = 1.6;
      ana.sigDPhi = sigDPhi;
      ana.minPt = 0.5;
      ana.maxEta = etamax;
      ana.Init(nt);
      ana.Loop();
//       ana.Loop(5000);
   }
   
   hout->Write();
}
Example #23
0
void doit()
{
   TFile* base = new TFile("f.db","recreate");
   TDirectory* a = base->mkdir("a","First Level Dir");
   a->cd();
   TH1D* ha = new TH1D("ha","ha",10,0,1);
   TDirectory* aa = a->mkdir("aa","Second Level Dira");
   aa->cd();
   TH1D* haa = new TH1D("haa","haa",10,0,1);
   
   a->ls();
   
   printf(" a: created@ %p  found@ %p\n", a,base->FindObjectAny("a"));
   printf("ha: created@ %p  found@ %p\n",ha,base->FindObjectAny("ha"));
   printf("ha: created@ %p  --found@ %p\n",ha,base->FindObjectAny("a/ha"));
#ifdef ClingWorkAroundMissingImplicitAuto
   TDirectory *k = (TDirectory*)base->FindObjectAny("a");
#else
   k = (TDirectory*)base->FindObjectAny("a");
#endif
   printf("ha: created@ %p  found@ %p\n",ha,k->FindObjectAny("ha"));
   
   printf("aa: created@ %p  found@ %p\n",aa,base->FindObjectAny("aa"));
   printf("aa: created@ %p  --found@ %p\n",aa,base->FindObjectAny("a/aa"));
   printf("aa: created@ %p  found@ %p\n",aa,k->FindObjectAny("aa"));
   
   printf("haa: created@ %p  found@ %p\n",haa,base->FindObjectAny("haa"));
   printf("haa: created@ %p  --found@ %p\n",haa,base->FindObjectAny("aa/haa"));
   printf("haa: created@ %p  --found@ %p\n",haa,base->FindObjectAny("a/aa/haa"));
   printf("haa: created@ %p  found@ %p\n",haa,k->FindObjectAny("haa"));
   printf("haa: created@ %p  --found@ %p\n",haa,k->FindObjectAny("aa/haa"));
#ifdef ClingWorkAroundMissingImplicitAuto
   TDirectory *kk = (TDirectory*)k->FindObjectAny("aa");
#else
   kk = (TDirectory*)k->FindObjectAny("aa");
#endif
   printf("haa: created@ %p  found@ %p\n",haa,kk->FindObjectAny("haa"));
   
   base->Write();
   
}
Example #24
0
void doit2()
{
   TFile* base = new TFile("f.db","READ");
   
   TH1D *ha = 0;
   TH1D *haa = 0;
   TDirectory *aa = 0;

#ifdef ClingWorkAroundMissingDynamicScope
   TDirectory *a = (TDirectory*)base->Get("a");
#endif
   a->ls();
   
   printf(" a: created@ %p  found@ %p\n", a,base->FindObjectAny("a"));
   printf("ha: created@ %p  found@ %p\n",ha,base->FindObjectAny("ha"));
   printf("ha: created@ %p  --found@ %p\n",ha,base->FindObjectAny("a/ha"));
#ifdef ClingWorkAroundMissingImplicitAuto
   TDirectory *k = (TDirectory*)base->FindObjectAny("a");
#else
   k = (TDirectory*)base->FindObjectAny("a");
#endif
   printf("ha: created@ %p  found@ %p\n",ha,k->FindObjectAny("ha"));
   
   printf("aa: created@ %p  found@ %p\n",aa,base->FindObjectAny("aa"));
   printf("aa: created@ %p  --found@ %p\n",aa,base->FindObjectAny("a/aa"));
   printf("aa: created@ %p  found@ %p\n",aa,k->FindObjectAny("aa"));
   
   printf("haa: created@ %p  found@ %p\n",haa,base->FindObjectAny("haa"));
   printf("haa: created@ %p  --found@ %p\n",haa,base->FindObjectAny("aa/haa"));
   printf("haa: created@ %p  --found@ %p\n",haa,base->FindObjectAny("a/aa/haa"));
   printf("haa: created@ %p  found@ %p\n",haa,k->FindObjectAny("haa"));
   printf("haa: created@ %p  --found@ %p\n",haa,k->FindObjectAny("aa/haa"));
#ifdef ClingWorkAroundMissingImplicitAuto
   TDirectory *kk = (TDirectory*)k->FindObjectAny("aa");
#else
   kk = (TDirectory*)k->FindObjectAny("aa");
#endif
   printf("haa: created@ %p  found@ %p\n",haa,kk->FindObjectAny("haa"));
   
}
double getMinNLL(double iMass) { 
  std::stringstream pSS; pSS << " /afs/cern.ch/user/p/pharris/public/massscan/cmb+_All_final_1nd/" << iMass << "/out/mlfit.root";
  TFile *lFile = new TFile(pSS.str().c_str());
  if(lFile == 0) return 1000.;
  TTree *lTree = (TTree*) lFile->FindObjectAny("tree_fit_sb");
  if(lTree == 0) return 1000.;
  double lNLL=  0; lTree->SetBranchAddress("nll_min",&lNLL); 
  lTree->GetEntry(0);				
  double lFNLL = lNLL;
  lFile->Close();
  cout << " ===> " << lFNLL << endl;
  return lFNLL;
}
Example #26
0
//--------------------------------------------------------------------------------------------------
// Get Total Number of Events in the sample
//--------------------------------------------------------------------------------------------------
Double_t getNormalizationWeight(string filename, string datasetName) {
  // Get Normalization Weight Factor

  //Get Number of Events in the Sample
  Double_t NEvents = 1;
  TFile *file = new TFile(filename.c_str(),"READ");
  TDirectory *dir = 0;
  TH1F *hist = 0;
  if (!file) {
    cout << "Could not open file " << filename << endl;
  } else {
    
    hist = (TH1F*)file->Get("hDAllEvents");
    if (!hist) {
      dir = (TDirectory*)file->FindObjectAny("AnaFwkMod");
      if (!dir) {
        cout << "Could not find directory AnaFwkMod"
             << " in file " << filename << endl;
        delete file;
      } else {
        
        hist = (TH1F*)dir->Get("hDAllEvents");
        if (!hist) {
          cout << "Could not find histogram hDEvents in directory AnaFwkMod"
               << " in file " << filename << endl;
          delete dir;
          delete file;
        }
      }
    }
  }

  if (hist) {
    NEvents = hist->Integral();
  }

  //Get CrossSection
  Double_t Weight = 1.0;
  if (datasetName.find("data") == string::npos) {
    mithep::SimpleTable xstab("/home/sixie/CMSSW_analysis/src/MitPhysics/data/xs.dat");
    cerr << "Use xs table: " << "$CMSSW_BASE/src/MitPhysics/data/xs.dat" << endl;
    Double_t CrossSection = xstab.Get(datasetName.c_str());
    Weight = CrossSection / NEvents;
    cerr << datasetName << " : " << CrossSection << " " << NEvents << " " << Weight << endl;
  }

//   if (dir) delete dir;
//   if (file) delete file;
  return Weight;

}
Example #27
0
void LoadCutValues(const string cutValuesFile , const string SignalName ) {

  
  TFile *file = new TFile(cutValuesFile.c_str(), "READ");
  file->cd();  


  //loop over final states
  for (int fs = 0; fs <= 2; fs++) {
 
    //loop over 
    string histname = ("OptimalCutAboveValues_"+SignalName+finalstatestring[fs]);
    TH1F *cutAboveValues = (TH1F*)file->FindObjectAny(histname.c_str());
    //get cut values for all variables
    if (cutAboveValues) {
      for (int v=0;v<NVARIABLES;v++) {
        fCutAboveInitialValue[fs][v] = cutAboveValues->GetBinContent(v+1);
      }
    } else {
      cerr << "Warning : cutAboveValues histogram " << histname << " was not found in file " << cutValuesFile << endl;
    }

    histname = ("OptimalCutBelowValues_"+SignalName+finalstatestring[fs]);
    TH1F *cutBelowValues = (TH1F*)file->FindObjectAny(histname.c_str());
    //get cut values for all variables
    if (cutBelowValues) {
      for (int v=0;v<NVARIABLES;v++) {
        fCutBelowInitialValue[fs][v] = cutBelowValues->GetBinContent(v+1);
      }
    } else {
      cerr << "Warning : cutAboveValues histogram " << histname << " was not found in file " << cutValuesFile << endl;
    }
  }




}
Example #28
0
CalibSort::CalibSort(std::string fname, std::string dirnm, std::string prefix,
		     int flag, double mipCut) : fname_(fname), dirnm_(dirnm), 
						prefix_(prefix), flag_(flag),
						mipCut_(mipCut) {
  // if parameter tree is not specified (or zero), connect the file
  // used to generate this class and read the Tree
  TFile      *file = new TFile(fname.c_str());
  TDirectory *dir  = (TDirectory*)file->FindObjectAny(dirnm.c_str());
  std::cout << fname << " file " << file << " " << dirnm << " " << dir 
	    << std::endl;
  TTree      *tree = (TTree*)dir->Get("CalibTree");
  std::cout << "CalibTree " << tree << std::endl;
  Init(tree);
}
Example #29
0
void BackgroundFit() {
    TFile* inputFile = new TFile("0_MuScleFit.root", "READ");
    TH1F* histo = (TH1F*)inputFile->FindObjectAny("hRecBestRes_Mass");
    histo->Rebin(30);
    histo->Scale(1/histo->GetEntries());

    // TF1 * functionToFit = lorentzianFit();
    // TF1 * functionToFit = crystalBallFit();
    // TF1 * functionToFit = powerLawFit();
    // TF1 * functionToFit = lorentzianAndPowerLaw();
    // TF1 * functionToFit = exponentialFit();
    TF1 * functionToFit = lorenzianAndExponentialFit();

    histo->Fit(functionToFit, "M", "", 42, 160);

}
Example #30
0
void	drift_chisq()
{
	int	i;

	events = (TTree*)f.Get("events");

	c1.Divide(2, 2, 0.01, 0.02);
	c2.Divide(2, 2, 0.01, 0.02);

	i = 0;
	c1.cd(++i);
	makehist("t3X", 2);
	c1.cd(++i);
	makehist("t4X", 2);
	c1.cd(++i);
	makehist("t3Y", 2);
	c1.cd(++i);
	makehist("t4Y", 2);

	i = 0;
	c2.cd(++i);
	makehist("t3X", 1);
	c2.cd(++i);
	makehist("t4X", 1);
	c2.cd(++i);
	makehist("t3Y", 1);
	c2.cd(++i);
	makehist("t4Y", 1);

	TText	*t;
	TTree	*info = (TTree*)f.FindObjectAny("info");
	TString	info_str = get_info_str(info);
	c1.cd(0);
	t = new TText(0.005, 0.005, info_str);
	t->SetTextSize(0.02);
	t->Draw();
	c2.cd(0);
	t = new TText(0.005, 0.005, info_str);
	t->SetTextSize(0.02);
	t->Draw();

	c1.Show();
	c2.Show();
}