예제 #1
0
파일: Tree.cpp 프로젝트: SAKUJ0/ams-acsoft
/********************* 
 * BRANCHES
 * *******************
 */
void Tree::selectBranches()
{
   //Deactivate all branches (used branches activated below)
   tree->SetBranchStatus("*", 0);

   TBranch *branch;

   //Timestamp
   branch = tree->GetBranch("Time");
   branch->SetStatus(1);
   branch->SetAddress(&branchTime);
   
   //ECal energy
   branch = tree->GetBranch("EcalEnergy");
   branch->SetStatus(1);
   branch->SetAddress(&branchEcalEnergy);

   //Rigidity
   branch = tree->GetBranch("TrackerRigidity");
   branch->SetStatus(1);
   branch->SetAddress(&branchTrackerRigidity);

   //Ecal BDT
   branch = tree->GetBranch("EcalBDT");
   branch->SetStatus(1);
   branch->SetAddress(&branchEcalBDT);

}
예제 #2
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);
    }
}
예제 #3
0
void make_scan_results()
{
  TFile *f = TFile::Open("scan_results.root", "UPDATE");

  f->Delete("SR;*");

  T = new TTree("SR", "Scanning results");

  TClonesArray* ts = new TClonesArray("IlcESDtrack", 32);
  TBranch * tb = T->Branch("T", &ts);
  delete ts;

  IlcMultiplicity *ms = 0;
  TBranch *mb = T->Branch("M", &ms);

  for (Int_t v = 0; v < 3; ++v)
  {
    vvv[v].vert   = 0;
    vvv[v].branch = T->Branch(vvv[v].bname, &vvv[v].vert);
  }

  for (Int_t i=0; i<=9999; ++i)
  {
    TString name;

    name.Form("Tracks_%04d", i);
    ts = (TClonesArray*) f->Get(name);
    if (ts == 0)
      continue;

    name.Form("Tracklets_%04d", i);
    ms = (IlcMultiplicity*) f->Get(name);
    if (ms == 0)
      Error("make_scan_results", "'%s' not found.", name.Data());

    tb->SetAddress(&ts);
    mb->SetAddress(&ms);

    for (Int_t v = 0; v < 3; ++v)
    {
      name.Form("%s_%04d", vvv[v].oname, i);
      vvv[v].vert = (IlcESDVertex*) f->Get(name);
      if (vvv[v].vert == 0)
        Error("make_scan_results", "'%s' not found.", name.Data());
      vvv[v].branch->SetAddress(&vvv[v].vert);
    }

    T->Fill();

    delete ts;
    delete ms;
    for (Int_t v = 0; v < 3; ++v) delete vvv[v].vert;
  }

  T->Write();

  f->Close();
  delete f;
}
예제 #4
0
void pulseHeights(Int_t board=112, TString file="latest.root", 
		  Int_t xmin=300, Int_t xmax=50){

  TFile *f = new TFile(file);
  // create a pointer to an event object for reading the branch values.
  TBEvent *event = new TBEvent();
  TTree *t1041 = (TTree*) f->Get("t1041");
  TBranch *bevent = t1041->GetBranch("tbevent");
  bevent->SetAddress(&event);
  
  TH1F *hpulse[32];
  for (int i=0; i<32; i++){
    TString name;
    name.Form("h%d_%2d",board,i);
    hpulse[i]=new TH1F(name,name,xmax-xmin,xmin,xmax);
  }


  // loop over events
  for (Int_t i=0; i< t1041->GetEntries(); i++) {
    t1041->GetEntry(i);
    // loop over PADE channels
    for (Int_t j=0; j<event->NPadeChan(); j++){
      if (event->GetPadeChan(j).GetBoardID() != board) continue;
      int chan=event->GetPadeChan(j).GetChannelID();
      hpulse[chan]->Fill(event->GetPadeChan(j).GetMax());
    }
  }
  
}
예제 #5
0
파일: hw.C 프로젝트: 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();


}
예제 #6
0
/// Open new data file
bool DDG4EventHandler::Open(const std::string&, const std::string& name)   {
    if ( m_file.first ) m_file.first->Close();
    m_hasFile = false;
    m_hasEvent = false;
    TFile* f = TFile::Open(name.c_str());
    if ( f && !f->IsZombie() )  {
        m_file.first = f;
        TTree* t = (TTree*)f->Get("EVENT");
        if ( t )   {
            TObjArray* br = t->GetListOfBranches();
            m_file.second = t;
            m_entry = -1;
            m_branches.clear();
            for(Int_t i=0; i<br->GetSize(); ++i)  {
                TBranch* b = (TBranch*)br->At(i);
                if ( !b ) continue;
                m_branches[b->GetName()] = make_pair(b,(void*)0);
                printout(INFO,"DDG4EventHandler::open","+++ Branch %s has %ld entries.",b->GetName(),b->GetEntries());
            }
            for(Int_t i=0; i<br->GetSize(); ++i)  {
                TBranch* b = (TBranch*)br->At(i);
                if ( !b ) continue;
                b->SetAddress(&m_branches[b->GetName()].second);
            }
            m_hasFile = true;
            return true;
        }
        throw runtime_error("+++ Failed to access tree EVENT in ROOT file:"+name);
    }
    throw runtime_error("+++ Failed to open ROOT file:"+name);
}
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;
}
예제 #8
0
파일: dqmPlots.C 프로젝트: ShashlikTB/T1041
void displaySingleChannelWaveforms(TString fdat, int board, int channel) {

  gStyle->SetOptStat(0);

  TFile *f = new TFile(fdat);
  if (f->IsZombie()){
    cout << "Cannot open file: " << fdat << endl;
    return;
  }

  TBEvent *event = new TBEvent();
  TTree *t1041 = (TTree*)f->Get("t1041"); 
  TBranch *bevent = t1041->GetBranch("tbevent");
  bevent->SetAddress(&event);

  TCanvas * canv = new TCanvas("canv", "canv", 2000, 2000);
  canv->cd();

  TH1F * dummy = new TH1F("dummy", "dummy", 120, 0, 120);
  dummy->GetYaxis()->SetRangeUser(0, 2500);
  dummy->Draw();
        
  vector<TH1F*> waves;

  TH1F * wave = new TH1F("wave", "wave", 120, 0, 120);

  int nplots = 0;

  for (Int_t i = 0; i < t1041->GetEntries(); i++) {
    t1041->GetEntry(i);
    
    for (int j = 0; j < event->NPadeChan(); j++){
      PadeChannel pch = event->GetPadeChan(j);
      
      if((int)pch.GetBoardID() != board || (int)pch.GetChannelID() != channel) continue;
      
      pch.GetHist(wave);
      
      nplots++;
      TH1F * wavecopy = (TH1F*)wave->Clone("wave_"+TString(Form("%d", nplots)));
      waves.push_back(wavecopy);
      
    }
    
  }
  
  int nBigPeaks = 0;
  for(unsigned int ui = 0; ui < waves.size(); ui++) {
    if(waves[ui]->GetMaximum() > 400) {
      waves[ui]->SetLineColor(nBigPeaks+2);
      nBigPeaks++;
    }
    waves[ui]->Draw("same");
  }
  
}
예제 #9
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;
}
예제 #10
0
파일: testgeo.C 프로젝트: brettviren/WbLS
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

}
예제 #11
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();
}
예제 #12
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;
}
예제 #13
0
파일: inspector.C 프로젝트: DHTC-Tools/UC3
 mTree(TTree *t){
     name=t->GetName();
     entries=(long)t->GetEntries();
     totSize=t->GetZipBytes();
     leaves=t->GetListOfBranches()->GetEntriesFast();
     for (int i=0; i<leaves; i++) {
         TBranch* branch = (TBranch*)t->GetListOfBranches()->UncheckedAt(i);
         branch->SetAddress(0);
         // cout <<i<<"\t"<<branch->GetName()<<"\t BS: "<< branch->GetBasketSize()<<"\t size: "<< branch->GetTotalSize()<< "\ttotbytes: "<<branch->GetTotBytes() << endl;
         branchSizes.insert(std::pair<string,long>(branch->GetName(),branch->GetZipBytes())); 
     }
 }
예제 #14
0
파일: dumpDDG4.C 프로젝트: AIDASoft/DD4hep
int dumpDDG4(const char* fname, int event_num)  {
  TFile* data = TFile::Open(fname);
  if ( !data || data->IsZombie() )   {
    printf("+  File seems to not exist. Exiting\n");
    usage();
    return -1;
  }
  TTree* tree = (TTree*)data->Get("EVENT");
  for(int event=0, num=tree->GetEntries(); event<num; ++event)  {
    TObjArray* arr = tree->GetListOfBranches();
    if ( event_num>= 0 ) event = event_num;
    for(int j=0, nj=arr->GetEntries(); j<nj; ++j)   {
      TBranch* b = (TBranch*)arr->At(j);
      typedef vector<void*> _E;
      _E* e = 0;
      b->SetAddress(&e);
      int nbytes = b->GetEvent(event);
      if ( nbytes > 0 )   {
        if ( e->empty() )    {
          continue;
        }
        string br_name = b->GetName();
        string cl_name = b->GetClassName();
        if ( cl_name.find("dd4hep::sim::Geant4Tracker::Hit") != string::npos )  {
          typedef vector<Geant4Tracker::Hit*> _H;
          printHits(br_name,(_H*)e);
        }
        else if ( cl_name.find("dd4hep::sim::Geant4Calorimeter::Hit") != string::npos )  {
          typedef vector<Geant4Calorimeter::Hit*> _H;
          printHits(br_name,(_H*)e);
        }
        else if ( cl_name.find("dd4hep::sim::Geant4Particle") != string::npos )  {
          typedef vector<Geant4Particle*> _H;
          ::printf("%s\n+    Particle Dump of event %8d  [%8d bytes]        +\n%s\n",
                   line,event,nbytes,line);
          printParticles(br_name,(_H*)e);
        }
      }
    }
    if ( event_num >= 0 ) break;
  }
  delete data;
  return 0;
}
예제 #15
0
Float_t KVINDRAPulserDataTree::GetMean(const Char_t* param, Int_t run)
{
	// Return mean value of pulser/laser for given parameter and run.
	// For detectors, param should be name of an acquisition parameter
	// e.g. CI_0201_PG, CSI_1301_L, etc.
	// For pin laser diodes, param should be name of associated acquisition parameter
	// with either '_laser' or '_gene' appended
	// e.g. PILA_05_PG_laser, SI_PIN1_PG_gene
	//
	// Returns -1.0 if no data available for this parameter/run.

	if( !fArb ) return -1.0;

	//find corresponding branch
	TBranch *br = fArb->GetBranch(param);
	if( !br ){
		//no branch found - wrong name given ?
		Error("GetMean", "No branch found with name %s", param);
		return -1.0;
	}
	//enable branch
	fArb->SetBranchStatus(param, 1);
	//connect variable to branch
	Float_t value = -1.0;
	br->SetAddress(&value);
	//read entry corresponding to run
	Int_t bytes = fArb->GetEntryWithIndex(run);
	if( bytes < 0 ){
		//unknown run number
		Error("GetMean", "Unknown run %d", run);
		return -1.0;
	}
	//disable branch
	fArb->SetBranchStatus(param, 0);

	return value;
}
예제 #16
0
파일: dqmPlots.C 프로젝트: ShashlikTB/T1041
void displayAllBigPeaks(TString fdat) {

  gStyle->SetOptStat(0);

  TFile *f = new TFile(fdat);
  if (f->IsZombie()){
    cout << "Cannot open file: " << fdat << endl;
    return;
  }

  TBEvent *event = new TBEvent();
  TTree *t1041 = (TTree*)f->Get("t1041"); 
  TBranch *bevent = t1041->GetBranch("tbevent");
  bevent->SetAddress(&event);

  vector<TH1F*> waves_112, waves_113, waves_115, waves_116;

  TH1F * wave = new TH1F("wave", "wave", 120, 0, 120);

  int nplots = 0;

  for (Int_t i = 0; i < t1041->GetEntries(); i++) {
    t1041->GetEntry(i);
    
    for (int j = 0; j < event->NPadeChan(); j++){
      PadeChannel pch = event->GetPadeChan(j);
      
      pch.GetHist(wave);

      if(wave->GetMaximum() < 800) continue;
      
      nplots++;
      TH1F * wavecopy = (TH1F*)wave->Clone("wave_"+TString(Form("%d", nplots)));

      int board = (int)pch.GetBoardID();

      if(board == 112) waves_112.push_back(wavecopy);
      else if(board == 113) waves_113.push_back(wavecopy);
      else if(board == 115) waves_115.push_back(wavecopy);
      else if(board == 116) waves_116.push_back(wavecopy);
      
    }
    
  }

  TCanvas * canv = new TCanvas("canv", "canv", 2000, 2000);
  canv->Divide(2,2);

  canv->cd(1);
  
  TH1F * dummy_112 = new TH1F("dummy_112", "Board 112", 120, 0, 120);
  dummy_112->GetYaxis()->SetRangeUser(90, 2200);
  dummy_112->Draw();

  for(unsigned int ui = 0; ui < waves_112.size(); ui++) {

    if(waves_112[ui]->GetMaximum() > 1500) {
      waves_112[ui]->SetLineColor(kRed);
      //waves_112[ui]->SetLineWidth(3);
    }
    else {
      waves_112[ui]->SetLineColor(kBlack);
    }

    waves_112[ui]->Draw("same");
  }

  canv->cd(2);

  TH1F * dummy_113 = new TH1F("dummy_113", "Board 113", 120, 0, 120);
  dummy_113->GetYaxis()->SetRangeUser(90, 2200);
  dummy_113->Draw();

  for(unsigned int ui = 0; ui < waves_113.size(); ui++) {

    if(waves_113[ui]->GetMaximum() > 1500) {
      waves_113[ui]->SetLineColor(kRed);
      //waves_113[ui]->SetLineWidth(3);
    }
    else {
      waves_113[ui]->SetLineColor(kBlack);
    }

    waves_113[ui]->Draw("same");
  }

  canv->cd(3);

  TH1F * dummy_115 = new TH1F("dummy_115", "Board 115", 120, 0, 120);
  dummy_115->GetYaxis()->SetRangeUser(90, 2200);
  dummy_115->Draw();

  for(unsigned int ui = 0; ui < waves_115.size(); ui++) {

    if(waves_115[ui]->GetMaximum() > 1500) {
      waves_115[ui]->SetLineColor(kRed);
      //waves_115[ui]->SetLineWidth(3);
    }
    else {
      waves_115[ui]->SetLineColor(kBlack);
    }

    waves_115[ui]->Draw("same");
  }
  
  canv->cd(4);

  TH1F * dummy_116 = new TH1F("dummy_116", "Board 116", 120, 0, 120);
  dummy_116->GetYaxis()->SetRangeUser(90, 2200);
  dummy_116->Draw();

  for(unsigned int ui = 0; ui < waves_116.size(); ui++) {

    if(waves_116[ui]->GetMaximum() > 1500) {
      waves_116[ui]->SetLineColor(kRed);
      //waves_116[ui]->SetLineWidth(3);
    }
    else {
      waves_116[ui]->SetLineColor(kBlack);
    }

    waves_116[ui]->Draw("same");
  }

  canv->SaveAs("AllBigPeaks.gif");
  
}
예제 #17
0
int main(int argc, char* argv[]){
  using namespace muon_pog;


  if (argc < 3) 
    {
      std::cout << "Usage : "
		<< argv[0] << " PATH_TO_INPUT_FILE PAT_TO_CONFIG_FILE(s)\n";
      exit(100);
    }

  // Input root file
  TString fileName = argv[1];

  std::cout << "[" << argv[0] << "] Processing file " << fileName.Data() << std::endl;
  
  std::vector<Plotter> plotters;
  for (int iConfig = 2; iConfig < argc; ++iConfig)
    {
        std::cout << "[" << argv[0] << "] Using config file " << argv[iConfig] << std::endl;
	plotters.push_back(std::string(argv[iConfig]));
    }
  
  // Set it to kTRUE if you do not run interactively
  gROOT->SetBatch(kTRUE); 

  // Initialize Root application
  TRint* app = new TRint("CMS Root Application", &argc, argv);

  //setTDRStyle(); what to do here?
   
  // Initialize pointers to summary and full event structure
 
  muon_pog::Event* ev = new muon_pog::Event();
  TTree* tree;
  TBranch* evBranch;

  // Open file, get tree, set branches

  TFile* inputFile = TFile::Open(fileName,"READONLY");
  tree = (TTree*)inputFile->Get("MUONPOGTREE");
  if (!tree) inputFile->GetObject("MuonPogTree/MUONPOGTREE",tree);

  evBranch = tree->GetBranch("event");
  evBranch->SetAddress(&ev);

  system("mkdir -p results");
  
  TFile* outputFile = TFile::Open("results/results.root","RECREATE"); // CB find a better name for output file  

  for (auto & plotter : plotters)
    plotter.book(outputFile);
      
  // Watch number of entries
  int nEntries = tree->GetEntriesFast();
  std::cout << "[" << argv[0] << "] Number of entries = " << nEntries << std::endl;

  int nFilteredEvents = 0;
  
  for (Long64_t iEvent=0; iEvent<nEntries; ++iEvent) 
    {
      if (tree->LoadTree(iEvent)<0) break;

      evBranch->GetEntry(iEvent);

      for (auto & plotter : plotters)
	plotter.fill(ev->muons, ev->hlt);

    }

  outputFile->Write();
  
  if (!gROOT->IsBatch()) app->Run();

  return 0;
}
예제 #18
0
파일: plot_HF.C 프로젝트: Andrej-CMS/cmssw
// 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 ;  
}
예제 #19
0
void Plotter_sbatb2(){

  
  Int_t mA=248;
  TString strmA = "248";
  Int_t mH=500;
  TString strmH = "500";

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

  gStyle->SetPadLeftMargin(0.1191275);
  gStyle->SetPadRightMargin(0.05944056);
  gStyle->SetPadTopMargin(0.05944056);
  gStyle->SetPadBottomMargin(0.1206294);

  gStyle->SetTitleSize(0.04, "XYZ");
  gStyle->SetTitleXOffset(1.1);
  gStyle->SetTitleYOffset(1.45);
  gStyle->SetPalette(1);
  gStyle->SetNdivisions(505);
  gStyle->SetLabelSize(0.04,"XYZ");



  // Getting the limits from combine root files 

  TString file_path_sig1 = "/home/fynu/amertens/storage/CMSSW/CMSSW_6_1_1/src/HiggsAnalysis/CombinedLimit/python/v1_MH_"+strmH+"_Asymptotic_Unblind_Combined_/higgsCombineTest.Asymptotic.mA"+strmA+".root";

  Double_t limit;

  TGraph2D* myTGraph_ratio = new TGraph2D(10);
  myTGraph_ratio->SetName("Ratio CMSSW/Delphes");
  myTGraph_ratio->SetTitle("Ratio CMSSW/Delphes");
  myTGraph_ratio->SetPoint(0,35,142,0.411);
  myTGraph_ratio->SetPoint(1,10,200,0.838);
  myTGraph_ratio->SetPoint(2,110,200,0.796);
  myTGraph_ratio->SetPoint(3,30,329,0.826);
  myTGraph_ratio->SetPoint(4,70,329,0.897);
  myTGraph_ratio->SetPoint(5,70,575,0.955);
  myTGraph_ratio->SetPoint(6,70,875,0.907);
  myTGraph_ratio->SetPoint(7,142,329,0.925);
  myTGraph_ratio->SetPoint(8,142,875,0.927);
  myTGraph_ratio->SetPoint(9,378,575,0.891);
  myTGraph_ratio->SetPoint(10,378,875,0.911);
  myTGraph_ratio->SetPoint(11,575,875,0.890);
  myTGraph_ratio->SetPoint(12,761,875,0.849);
  myTGraph_ratio->SetPoint(13,50,1200,0.9);
  myTGraph_ratio->SetPoint(14,1200,1200,0.85);

  Double_t ratio = myTGraph_ratio->Interpolate(mA,mH);

  pathDelphesEff = "/home/fynu/amertens/storage/THDM/eff_v1/"+strmH+"_"+strmA+".root";
  DelphesFile = TFile(pathDelphesEff);
  TGraph2D* myG2D = DelphesFile.Get("Graph2D");
  Double_t eff = myG2D->Interpolate(int(mA),int(mH));

  Double_t lumi = 19.7;
  cout << "efficiency : " << eff << " ratio : " << ratio << endl;
  Double_t LumiEff = eff*ratio*lumi;

  TFile* f_Sig1 = new TFile(file_path_sig1);
  TTree* tree_Sig1 = (TTree*) f_Sig1->Get("limit");

  TBranch *branch  = tree_Sig1->GetBranch("limit");
  branch->SetAddress(&limit);

  branch->GetEntry(5);
  Double_t limit_obs = limit /(0.067*LumiEff);
  branch->GetEntry(0);
  Double_t limit_m2 = limit /(0.067*LumiEff);
  branch->GetEntry(1);
  Double_t limit_m1 = limit /(0.067*LumiEff);
  branch->GetEntry(2);
  Double_t limit_exp = limit /(0.067*LumiEff);
  branch->GetEntry(3);
  Double_t limit_p1 = limit /(0.067*LumiEff);
  branch->GetEntry(4);
  Double_t limit_p2 = limit /(0.067*LumiEff);

  // Limit vs TanBeta cosba
  TString Xsec_path = "/home/fynu/amertens/Delphes/delphes/condor/xsec_H_ZA_ll_bb_tautau_tanb_cosba_"+strmH+"_"+strmA+".root";
  TFile *f4 = new TFile(Xsec_path);
  TCanvas* C_tbcba = new TCanvas("C_tbcba","C_tbcba",600,600);

  gPad->SetGrid();

  C_tbcba->SetLogy(true);
  //C_tbcba->SetRightMargin(0.17);

  TH2D* h_tbcba = f4->Get("h_HZbbXsec");

  TGraph* g_obs = getContourFilledX(h_tbcba, C_tbcba, 3, 1,3645, limit_obs);
  TGraph* g_exp = getContourFilledX(h_tbcba, C_tbcba, 3, 7,0, limit_exp);


  Double_t contours[6];
  contours[0] = limit_m2;
  contours[1] = limit_m1;
  contours[2] = limit_exp;
  contours[3] = limit_p1;
  contours[4] = limit_p2;
  h_tbcba->SetContour(5, contours);

  TH2D* finalPlot_tbcba = h_tbcba;

  Int_t colors[] = {kYellow, kGreen, kGreen, kYellow, kWhite}; // #colors >= #levels - 1
  gStyle->SetPalette((sizeof(colors)/sizeof(Int_t)), colors);

  DrawThis();

  finalPlot_tbcba->Draw("cont list same");

  cout << "limits : " << limit_m2 << endl;
  cout << "limits : " << limit_m1 << endl;
  cout << "limits : " << limit_exp << endl;
  cout << "limits : " << limit_p1 << endl;
  cout << "limits : " << limit_p2 << endl;

  cout << "limits obs : " << limit_obs << endl;

   

//  TGraph* g_obs = getContourFilledX(finalPlot_tbcba, C_tbcba, 3, 1,3004, limit_obs);
//  TGraph* g_exp = getContourFilledX(finalPlot_tbcba, C_tbcba, 3, 7,4000, limit_exp);

  g_obs->Draw("CL F same");
  g_exp->Draw("CL F same");

  DrawMasses("M_{H} = 330 GeV", "M_{A} = 100 GeV");

  TGraph* g_yellow = new TGraph();
  g_yellow->SetFillColor(kYellow);
  TGraph* g_green = new TGraph();
  g_green->SetFillColor(kGreen);



  TLegend* leg = new TLegend(0.7,0.5,0.9,0.7);
  //leg->SetHeader("#splitline{THDM type II}{#splitline{M_{H} = 378}{M_{A} = 216}}");
  leg->SetLineColor(0);
  leg->SetFillColor(0);
  leg->AddEntry(g_obs,"Obs. Excl.","F");
  leg->AddEntry(g_exp,"Exp. Excl.","l");  
  leg->AddEntry(g_green,"1-sigma","F");
  leg->AddEntry(g_yellow,"2-sigma","F");
  leg->Draw();

  gPad->RedrawAxis("g"); // for "grid lines"

}
예제 #20
0
rdEEevent(int neve=300,  TString Tname0="/star/u/eemcdb/dataFeb11/run00006.eeTree", int flag=0, float Emax=40.) {
    TString Tname0="../sim2003/mc_eve2";
    gSystem->Load("StRoot/StEEmcUtil/EEevent/libEEevent.so");

    //  gStyle->SetPalette(1,0);
    gStyle->SetOptStat(111111);

    TString Tname;
    Tname=Tname0;

    printf("read upto %d events from file=%s.root\n",neve,Tname.Data());
    TFile *f = new TFile(Tname+".root");
    assert(f->IsOpen());
    TTree *t4 = (TTree*)f->Get("EEtree");
    assert(t4);
    // create a pointer to an event object. This will be used
    // to read the branch values.
    EEeventDst *event = new EEeventDst();

    //if (gROOT->IsBatch()) return;  new TBrowser();  t4->StartViewer();  return;
    TBranch *br = t4->GetBranch("EEdst");
    br->SetAddress(&event);
    Int_t nevent = (Int_t)t4->GetEntries();
    for (Int_t ie=0; ie<nevent; ie++) {
        if(ie>=neve) break;
        printf("\niEve=%d  ---------- \n",ie);
        int i;

        //read this branch only
        br->GetEntry(ie);
        event->print();

        int nSec=event->Sec->GetEntries();
        printf("%d sectors with data\n",nSec);

        int is;
        for(is=0; is<nSec; is++) {
            EEsectorDst *sec=(EEsectorDst*)event->Sec->At(is);
            //      sec->print();
            TClonesArray *hitA=sec->getTwHits();
            assert(hitA);
            int ih;
            for(ih=0; ih<hitA->GetEntries(); ih++) {
                char sub;
                int eta;
                float ener;
                EEtwHitDst *hit=(EEtwHitDst*)hitA->At(ih);
                hit->get(sub,eta,ener);
                if(ie<5) printf("    ih=%d sec=%d sub=%c etaBin=%d ener=%f\n",ih, sec->getID(), sub, eta,ener);
                //	hit->print();
            }

        }


    }

#if 0

    // allocate memory for needed branches
    TClonesArray *secA=new TClonesArray("EEsectorDst",1000);
    TBranch *BRsec = t4->GetBranch("Sec");   // set the branch address
    BRsec->SetAddress(&secA);

    int eveID=0;
    TBranch *BRid = t4->GetBranch("ID");
    BRid->SetAddress(&eveID);

    Int_t nevent = (Int_t)t4->GetEntries();
    printf("Total events in TTree=%d\n",nevent);


    // ...........  LOOP OVER EVENTS ............

    for (Int_t ie=0; ie<nevent; ie++) {
        if(ie>=neve) break;
        int i;

        //read this branch only
        BRid->GetEntry(ie);
        BRsec->GetEntry(ie);

        if(ie%1==0) printf("\n\iEve=%d  nSec=%d with data \n",ie,secA->GetEntries());

        //    if(ie%1==0) printf("\n\iEve=%d eveID=%d, eveType=%d, nSec=%d with data :\n",ie,eveID,eveType,secA->GetEntries());
        if(ie%1==0) printf("\n\iEve=%d eveID=%d, nSec=%d with data :\n",ie,eveID,secA->GetEntries());


        int is;
        for(is=0; is<secA->GetEntries(); is++) {
            EEsectorDst *sec=(EEsectorDst*)secA->At(is);
            if(ie<1) sec->print();

            TClonesArray *hitA;
            int ih;

            TClonesArray *hitAA[]= {sec->getPre1Hits(),sec->getPre2Hits(),sec->getTwHits(),sec->getPostHits(),sec->getSmdUHits(),sec->getSmdVHits()};
            int iz;
            for(iz=0; iz<4; iz++) { // over tower/pre/post
                hitA=hitAA[iz];
                if(ie<1)    printf("  sectorID=%d  iz=%d nHit=%d :\n",sec->getID(),iz,hitA->GetEntries());
            }// end of loop over pre1/2/Tw/Post


            for(iz=4; iz<6; iz++) { // over SMD U/V
                hitA=hitAA[iz];
                if(ie<1) printf("  sectorID=%d  iz=%d nHit=%d :\n",sec->getID(),iz,hitA->GetEntries());
                for(ih=0; ih<hitA->GetEntries(); ih++) {
                    EEsmdHitDst *hit2=(EEsmdHitDst*)hitA->At(ih);
                    int strip;
                    float ener;
                    hit2->get(strip,ener);
                    if(ie<1) printf("    ih=%d strip=%d etaBin=%d ener=%f\n",ih, sec->getID(), strip,ener);
                    hit->print();
                }
            }// end of loop over pre1/2/Tw/Post


        }// end of loop over sector

    }
#endif
    printf("\n\nTotal events in B TTree=%d\n",nevent);


}
예제 #21
0
파일: ReadImpacts.C 프로젝트: alisw/AliRoot
ReadImpacts(Int_t nEvents=1,char* file="galice.root")
{

  // Script reads PHOS impacts and prints them
  // Impacts are exacts values of the track coming to EMC, CPV or PPSD
  // and was stored to separate branches of TreeH by AliPHOSvImpacts
  //
  // Yuri Kharlov 4 June 2001

  f = new TFile(file,"readonly");
  (AliRun*)gAlice=(AliRun*)f->Get("gAlice");
  AliPHOSvImpacts *  fPHOS  = (AliPHOSvImpacts *)gAlice->GetDetector("PHOS") ;
  AliPHOSGeometry *  fGeom  = AliPHOSGeometry::GetInstance(fPHOS->GetGeometry()->
                                                           GetName(),
                                                           fPHOS->GetGeometry()->GetTitle() ) ;
  Int_t nPHOSModules = fGeom->GetNModules();
  Int_t nCPVModules  = fGeom->GetNCPVModules();
  Int_t nPPSDModules = fGeom->GetNPPSDModules();

  TBranch * branchEMCimpacts;
  TBranch * branchCPVimpacts;
  TBranch * branchPPSDimpacts;
  TList * fEmcImpacts ;
  TList * fCpvImpacts ;
  TList * fPpsdImpacts ;

  // Loop over events
  for (Int_t iEvent=0; iEvent<nEvents; iEvent++) {
    printf("===========> Event %5d <====================\n",iEvent);
    gAlice->GetEvent(iEvent) ;
    
    // Get branches EMC, CPV and PPSD impacts
    if (! (branchEMCimpacts =gAlice->TreeH()->GetBranch("PHOSEmcImpacts")) )  return 1;
    if (! (branchCPVimpacts =gAlice->TreeH()->GetBranch("PHOSCpvImpacts")) )  return 1;
    if (! (branchPPSDimpacts=gAlice->TreeH()->GetBranch("PHOSPpsdImpacts")) ) return 1;
    
    // Loop over primary tracks
    for (itrack=0; itrack < gAlice->GetNtrack(); itrack++){
      // Set addresses of impacts
      branchEMCimpacts ->SetAddress(&fEmcImpacts) ;
      branchCPVimpacts ->SetAddress(&fCpvImpacts) ;
      branchPPSDimpacts->SetAddress(&fPpsdImpacts) ;
      branchEMCimpacts ->GetEntry(itrack,0);
      branchCPVimpacts ->GetEntry(itrack,0);
      branchPPSDimpacts->GetEntry(itrack,0);
      
      TClonesArray  *impacts;
      AliPHOSImpact *impact;
      Int_t iModule;

      // Do loop over EMC modules
      for (iModule=0; iModule<nPHOSModules; iModule++) {
	impacts = (TClonesArray *)fEmcImpacts->At(iModule);
	// Do loop over impacts in the module
	for (Int_t iImpact=0; iImpact<impacts->GetEntries(); iImpact++) {
	  impact=(AliPHOSImpact*)impacts->At(iImpact);
	  printf("EMC  module %d: ",iModule);
	  impact->Print();
	}
      }

      // Do loop over CPV modules
      for (iModule=0; iModule<nCPVModules; iModule++) {
	impacts = (TClonesArray *)fCpvImpacts->At(iModule);
	// Do loop over impacts in the module
	for (Int_t iImpact=0; iImpact<impacts->GetEntries(); iImpact++) {
	  impact=(AliPHOSImpact*)impacts->At(iImpact);
	  printf("CPV  module %d: ",iModule);
	  impact->Print();
	}
      }

      // Do loop over PPSD modules
      for (iModule=0; iModule<nPPSDModules; iModule++) {
	impacts = (TClonesArray *)fPpsdImpacts->At(iModule);
	// Do loop over impacts in the module
	for (Int_t iImpact=0; iImpact<impacts->GetEntries(); iImpact++) {
	  impact=(AliPHOSImpact*)impacts->At(iImpact);
	  printf("PPSD Module %d: ",iModule);
	  impact->Print();
	}
      }

    }
  }
}
예제 #22
0
void LaserCalib(TTreeSRedirector & cstream, TTree * chain, Float_t tmin, Float_t tmax, Float_t fraction){
  ///

  const Double_t kMaxDelta=10;
  AliTPCParamSR param;
  param.Update();
  TFile fce("TPCsignal.root");
  TTree   * treece =(TTree*)fce.Get("Signalce");
  if (chain) treece=chain;
  //
  TBranch * brsector  = treece->GetBranch("Sector");
  TBranch * brpad     = treece->GetBranch("Pad");
  TBranch * brrow     = treece->GetBranch("Row");
  TBranch * brTimeStamp = treece->GetBranch("TimeStamp");
  //
  TBranch * brtime    = treece->GetBranch("Time");
  TBranch * brrms     = treece->GetBranch("RMS06");
  TBranch * brmax     = treece->GetBranch("Max");
  TBranch * brsum     = treece->GetBranch("Qsum");

  Int_t sector, pad, row=0;
  Double_t time=0, rms=0, qMax=0, qSum=0;
  UInt_t  timeStamp=0;
  brsector->SetAddress(&sector);
  brrow->SetAddress(&row);
  brpad->SetAddress(&pad);
  brTimeStamp->SetAddress(&timeStamp);
  
  brtime->SetAddress(&time);
  brrms->SetAddress(&rms);
  brmax->SetAddress(&qMax);
  brsum->SetAddress(&qSum);


  brsector->GetEntry(0);
  //
  Int_t firstSector  = sector;
  Int_t lastSector   = sector;
  Int_t fentry = 0;
  Int_t lentry = 0;
  //
  // find time offset for differnt events
  //
  Int_t count = 0;
  Double_t padTimes[500000];
  TRobustEstimator restim;
  Double_t meanS[72], sigmaS[72];
  Int_t   firstS[72], lastS[72];
  Double_t   sectorsID[72];
  for (Int_t isector=0;isector<72; isector++){
    firstS[isector]=-1; 
    lastS[isector] =-1;
  };
  TH1F  hisT("hisT","hisT",100,tmin,tmax);
  treece->Draw("Time>>hisT","");
  Float_t cbin = hisT.GetBinCenter(hisT.GetMaximumBin());

  for (Int_t ientry=0; ientry<treece->GetEntriesFast(); ientry++){
    treece->GetEvent(ientry);
    //
    if (sector!=lastSector && sector==firstSector){
      //if (sector!=lastSector){
      lentry = ientry;
      TTimeStamp stamp(timeStamp);
      stamp.Print();
      printf("\nEvent\t%d\tFirst\t%d\tLast\t%d\t%d\n",count, fentry, lentry, lentry-fentry);
      //
      //
      Int_t ngood=0;      
      for (Int_t ientry2=fentry; ientry2<lentry; ientry2++){
	//	brtime->GetEvent(ientry2);
	//  brsector->GetEvent(ientry2);
	treece->GetEvent(ientry2);
	if (time>tmin&&time<tmax && TMath::Abs(time-cbin)<kMaxDelta){
	  padTimes[ngood]=time;
	  ngood++;	
	  if (firstS[sector]<0)  firstS[sector]= ngood;
	  if (firstS[sector]>=0) lastS[sector] = ngood;
	}	
      }
      //
      //
      Double_t mean,sigma;
      restim.EvaluateUni(ngood,padTimes,mean, sigma,int(float(ngood)*fraction));
      printf("Event\t%d\t%f\t%f\n",count, mean, sigma);
      for (Int_t isector=0; isector<72; isector++){
	sectorsID[isector]=sector;
	if (firstS[isector]>=0 &&lastS[isector]>=0 && lastS[isector]>firstS[isector] ){
	  Int_t ngoodS = lastS[isector]-firstS[isector];
	  restim.EvaluateUni(ngoodS, &padTimes[firstS[isector]],meanS[isector], 
			     sigmaS[isector],int(float(ngoodS)*fraction));
	}
      }
      TGraph  graphM(72,sectorsID,meanS);
      TGraph  graphS(72,sectorsID,sigmaS);
      cstream<<"TimeS"<<
	"CBin="<<cbin<<
	"Event="<<count<<
	"GM="<<&graphM<<
	"GS="<<&graphS<<
	"\n";
      

      for (Int_t ientry2=fentry; ientry2<lentry-1; ientry2++){
	treece->GetEvent(ientry2);
	Double_t x      = param.GetPadRowRadii(sector,row);
	Int_t    maxpad = AliTPCROC::Instance()->GetNPads(sector,row);
	Double_t y = (pad - 2.5 - 0.5*maxpad)*param.GetPadPitchWidth(sector);
	Double_t alpha = TMath::DegToRad()*(10.+20.*(sector%18));	
	Double_t gx = x*TMath::Cos(alpha)-y*TMath::Sin(alpha);
	Double_t gy = y*TMath::Cos(alpha)+x*TMath::Sin(alpha);
	
	Int_t npadS = lastS[sector]-firstS[sector];
	cstream<<"Time"<<
	  "Event="<<count<<
	  "TimeStamp="<<timeStamp<<
	  "CBin="<<cbin<<
	  "x="<<x<<
	  "y="<<y<<
	  "gx="<<gx<<
	  "gy="<<gy<<
	  "Sector="<<sector<<
	  "Row="<<row<<
	  "Pad="<<pad<<
	  "Time="<<time<<
	  "RMS="<<rms<<
	  "Time0="<<mean<<
	  "Sigma0="<<sigma<< 
	  "TimeS0="<<meanS[sector]<<
	  "SigmaS0="<<sigmaS[sector]<<
	  "npad0="<<ngood<<
	  "npadS="<<npadS<<
	  "Max="<<qMax<<
	  "Sum="<<qSum<<
	  "\n";
      }
      treece->GetEvent(ientry);
      fentry = ientry;
      count++;      
      for (Int_t isector=0;isector<72; isector++){
	firstS[isector]=-1; 
	lastS[isector] =-1;
      }
    }
    lastSector=sector;
  }
}
예제 #23
0
// inputs data file and event in file to display (default is to integrate all)
void calDisplay(TString fdat, int ndisplay=-1){

  gStyle->SetOptStat(0);

  TFile *f = new TFile(fdat);
  if (f->IsZombie()){
    cout << "Cannot open file: " << fdat << endl;
    return;
  }
  
  Bool_t singleEvent=ndisplay>=0;
  Mapper *mapper=Mapper::Instance();

  // Histograms of ADC counts
  TH2F *hModU=new TH2F("hModU","Modules UpSteam RO;X [mm]; Y [mm]",
		       4,MIN_EDGE_X,MAX_EDGE_X,4,MIN_EDGE_Y,MAX_EDGE_Y);
  TH2F *hModD=new TH2F("hModD","Modules DownStream RO;X [mm]; Y [mm]",
		       4,MIN_EDGE_X,MAX_EDGE_X,4,MIN_EDGE_Y,MAX_EDGE_Y);
  TH2F *hChanU=new TH2F("hChanU","Channels UpStream RO;X [mm]; Y [mm]",
			8,MIN_EDGE_X,MAX_EDGE_X,8,MIN_EDGE_Y,MAX_EDGE_Y);
  TH2F *hChanD=new TH2F("hChanD","Channels DownStream RO;X [mm]; Y [mm]",
			8,MIN_EDGE_X,MAX_EDGE_X,8,MIN_EDGE_Y,MAX_EDGE_Y);

  hModU->SetMinimum(0);
  hModD->SetMinimum(0);
  hChanU->SetMinimum(0);
  hChanD->SetMinimum(0);
  hChanU->GetXaxis()->SetNdivisions(8,0);
  hChanU->GetYaxis()->SetNdivisions(8,0);
  hChanD->GetXaxis()->SetNdivisions(8,0);
  hChanD->GetYaxis()->SetNdivisions(8,0);

  if (singleEvent){
    hModU->SetMaximum(MAXADC*4);
    hModD->SetMaximum(MAXADC*4);
    hChanU->SetMaximum(MAXADC);
    hChanU->SetMaximum(MAXADC);
  }
  
  // histograms of timing 
  TH2F * hModD_time = (TH2F*)hModU->Clone("hModD_time");
  TH2F * hModU_time = (TH2F*)hModU->Clone("hModU_time");
  TH2F * hChanD_time = (TH2F*)hModU->Clone("hChanD_time");
  TH2F * hChanU_time = (TH2F*)hModU->Clone("hChanU_time");

  TBEvent *event = new TBEvent();
  TTree *t1041 = (TTree*)f->Get("t1041");
  TBranch *bevent = t1041->GetBranch("tbevent");
  bevent->SetAddress(&event);

  Int_t start=0; Int_t end=t1041->GetEntries();
  

  if (singleEvent && ndisplay<t1041->GetEntries() ) {
    start=ndisplay;
    end=ndisplay+1;
  }
  
  int nEntries=0;
  for (Int_t i=start; i<end; i++) {
    t1041->GetEntry(i);
    for (Int_t j = 0; j < event->NPadeChan(); j++){
      PadeChannel pch = event->GetPadeChan(j);
      double ped,sig;
      pch.GetPedestal(ped,sig);
      UShort_t max = pch.GetMax()-ped;
      Int_t maxTime = pch.GetPeak();
      if (max>MAXADC) continue;    // skip channels with bad adc readings (should be RARE)
      //max-=pch.GetPedestal();

      int channelID=pch.GetChannelID();   // boardID*100+channelNum in PADE
      int moduleID,fiberID;
      mapper->ChannelID2ModuleFiber(channelID,moduleID,fiberID);  // get module and fiber IDs

      double x,y;
      mapper->ModuleXY(moduleID,x,y);
      if (moduleID<0) {
	hModU->Fill(x, y, max);
	hModU_time->Fill(x, y, maxTime);
      }
      else {
	hModD->Fill(x, y, max);
	hModD_time->Fill(x, y, maxTime);
      }
      
      mapper->FiberXY(fiberID, x, y);
      if (moduleID<0) {
	hChanU->Fill(x, y, max);
	hChanU_time->Fill(x, y, maxTime);
      }
      else {
	hChanD->Fill(x, y, max);
	hChanD_time->Fill(x, y, maxTime);
      }

    }
    nEntries++;
  }

  hModD->Scale(1./nEntries);
  hModU->Scale(1./nEntries);
  hChanD->Scale(1./nEntries);
  hChanU->Scale(1./nEntries);
  
  hModD_time->Scale(1./nEntries);
  hModU_time->Scale(1./nEntries);
  hChanD_time->Scale(1./nEntries);
  hChanU_time->Scale(1./nEntries);


  // fetch module and channel maps
  TH2I *hmModU=new TH2I();
  mapper->GetModuleMap(hmModU,-1);
  TH2I *hmModD=new TH2I();
  mapper->GetModuleMap(hmModD,1);
  TH2I *hmChanU=new TH2I();
  mapper->GetChannelMap(hmChanU,-1);
  TH2I *hmChanD=new TH2I();
  mapper->GetChannelMap(hmChanD,1);


  TCanvas *c1=new TCanvas("c1","Average Peak Height",800,800);
  c1->Divide(2,2);

  c1->cd(1);
  hModD->Draw("colz");
  hmModD->Draw("text same");
  c1->cd(2);
  hModU->Draw("colz");
  hmModU->Draw("text same");
  c1->cd(3)->SetGrid();
  hChanD->Draw("colz");
  hmChanD->Draw("text same");
  c1->cd(4)->SetGrid();
  hChanU->Draw("colz");
  hmChanU->Draw("text same");
 
  return;   // skip timing



  TCanvas * c2 = new TCanvas("c2", "Average Peak Timing", 800, 800);
  c2->Divide(2, 2);

  c2->cd(1);
  hModD_time->Draw("colz");
  c2->cd(2);
  hModU_time->Draw("colz");
  c2->cd(3)->SetGrid();
  hChanD_time->Draw("colz");
  c2->cd(4)->SetGrid();
  hChanU_time->Draw("colz");
  //  drawChannelMap(c2);
  c2->Update();
}
예제 #24
0
void CountTrackableMCs(TH1F *hAllMC, Bool_t onlyPrims,Bool_t onlyPion) {
  
  gSystem->Load("libITSUpgradeBase");
  gSystem->Load("libITSUpgradeSim");

 // open run loader and load gAlice, kinematics and header
  AliRunLoader* runLoader = AliRunLoader::Open("galice.root");
  if (!runLoader) {
    Error("Check kine", "getting run loader from file %s failed",
          "galice.root");
    return;
  }
  runLoader->LoadHeader();
  runLoader->LoadKinematics();
  runLoader->LoadTrackRefs();

  AliLoader *dl = runLoader->GetDetectorLoader("ITS");

  //Trackf
  TTree *trackRefTree = 0x0; 
  TClonesArray *trackRef = new TClonesArray("AliTrackReference",1000);

  //  TH1F *hRef = new TH1F("","",100,0,100);
  TH1F *hR = new TH1F("","",100,0,100);
  if (hAllMC==0) hAllMC = new TH1F("","",100,0.1,2);
  Float_t ptmin = hAllMC->GetBinCenter(1)-hAllMC->GetBinWidth(1)/2;
  Float_t ptmax = hAllMC->GetBinCenter(hAllMC->GetNbinsX())+hAllMC->GetBinWidth(hAllMC->GetNbinsX())/2;
  //  Int_t nAllMC = 0;

  // Detector geometry
  TArrayD rmin(0);   TArrayD rmax(0); 
  GetDetectorRadii(&rmin,&rmax);
  TArrayI nLaySigs(rmin.GetSize());

  printf("Counting trackable MC tracks ...\n");
  
  for(Int_t iEv =0; iEv<runLoader->GetNumberOfEvents(); iEv++){
    Int_t nTrackableTracks = 0;
    runLoader->GetEvent(iEv);
    AliStack* stack = runLoader->Stack();  
    printf("+++ event %i (of %d) +++++++++++++++++++++++  # total MCtracks: %d \n",iEv,runLoader->GetNumberOfEvents()-1,stack->GetNtrack());

    trackRefTree=runLoader->TreeTR();
    TBranch *br = trackRefTree->GetBranch("TrackReferences");
    if(!br) {
      printf("no TR branch available , exiting \n");
      return;
    }
    br->SetAddress(&trackRef);

    // init the trackRef tree 
    trackRefTree=runLoader->TreeTR();
    trackRefTree->SetBranchAddress("TrackReferences",&trackRef);
 
    // Count trackable MC tracks
    for (Int_t iMC=0; iMC<stack->GetNtrack(); iMC++) {

      TParticle* particle = stack->Particle(iMC); 
      if (TMath::Abs(particle->Eta())>etaCut) continue;
      if (onlyPrims && !stack->IsPhysicalPrimary(iMC)) continue;
      if (onlyPion && TMath::Abs(particle->GetPdgCode())!=211) continue;


      Bool_t isTrackable = 0;
      nLaySigs.Reset(0);
 
      trackRefTree->GetEntry(stack->TreeKEntry(iMC));
      Int_t nref=trackRef->GetEntriesFast();
      for(Int_t iref =0; iref<nref; iref++){
	AliTrackReference *trR = (AliTrackReference*)trackRef->At(iref);
	if(!trR) continue;
	if(trR->DetectorId()!=AliTrackReference::kITS) continue;
	Float_t radPos = trR->R();
	hR->Fill(radPos);
	for (Int_t il=0; il<rmin.GetSize();il++) {
	  if (radPos>=rmin.At(il)-0.1 && radPos<=rmax.At(il)+0.1) {
	    //	    cout<<"  in Layer "<<il<<" "<<radPos;
	    nLaySigs.AddAt(1.,il);
	    //	    cout<<" "<<nLaySigs.At(il)<<endl;
	  }
	}
      }

      if (nLaySigs.GetSum()>=3) {
	isTrackable =1;
	//	cout<<nLaySigs.GetSum()<<endl;
      }
      
      if (isTrackable) {
	Double_t ptMC = particle->Pt();
	//	Double_t etaMC = particle->Eta();
	//	if (ptMC>ptmin&&ptMC<ptmax) {nTrackableTracks++;hAllMC->Fill(ptMC);}
	if (ptMC>ptmin) {nTrackableTracks++;hAllMC->Fill(ptMC);}

      }

      
    } // entries tracks MC
    printf(" -> trackable MC tracks: %d (%d)\n",nTrackableTracks,hAllMC->GetEntries());
  }//entries Events
  

  hR->DrawCopy();
  hAllMC->DrawCopy();
  runLoader->UnloadHeader();
  runLoader->UnloadKinematics();
  delete runLoader;

}
예제 #25
0
void RunPidGetterQAEff()
{
        
    TString PidFrameworkDir = "/lustre/nyx/cbm/users/klochkov/soft/PidFramework/";
    gSystem->Load( PidFrameworkDir + "build/libPid");  
    
    gStyle->SetOptStat(0000);

    TFile *f2 = new TFile("pid_0.root");    
    TTree *PidTree = (TTree*) f2->Get("PidTree");

    TofPidGetter *getter = new TofPidGetter();
    TBranch *PidGet = PidTree->GetBranch("TofPidGetter");
    PidGet->SetAddress(&getter);

    PidGet->GetEntry(0);
    Float_t ret[3];
        
    TProfile *hEffP  = new  TProfile ("hEffP", "", 100, 0, 10);
    TProfile *hEffPi = new  TProfile ("hEffPi", "", 100, 0, 6);
    TProfile *hEffK  = new  TProfile ("hEffK", "", 100, 0, 5);

    TProfile *hEffPSigma  = new  TProfile ("hEffPSigma", "", 100, 0, 10);
    TProfile *hEffPiSigma = new  TProfile ("hEffPiSigma", "", 100, 0, 6);
    TProfile *hEffKSigma  = new  TProfile ("hEffKSigma", "", 100, 0, 5);

    TProfile2D *hEffPtYP  = new  TProfile2D ("hEffPtYP", "", 100,   -2.5, 2.5, 100, 0, 4);
    TProfile2D *hEffPtYK  = new  TProfile2D ("hEffPtYK", "", 100,   -2.5, 2.5, 100, 0, 4);
    TProfile2D *hEffPtYPi  = new  TProfile2D ("hEffPtYPi", "", 100, -2.5, 2.5, 100, 0, 4);

    TString InTreeFileName = "/lustre/nyx/cbm/users/dblau/cbm/mc/UrQMD/AuAu/10AGeV/sis100_electron/SC_ON/2016_09_01/tree/11111.root";
    TFile *InFile = new TFile(InTreeFileName);    
    TTree *InTree = (TTree*) InFile->Get("fDataTree");
    DataTreeEvent* DTEvent;
    InTree -> SetBranchAddress("DTEvent",&DTEvent);

    int nevents = 100000;//InTree->GetEntries();
    int outputstep = 100;
    std::cout << "Entries = " << nevents << std::endl;

    for (int j=0;j<nevents;j++)
    {
        if ( (j+1) % outputstep == 0) std::cout << j+1 << "/" << nevents <<  "\r" << std::flush;
        InTree->GetEntry(j);
        
        Int_t Nmc[3] = {100,100,100};
        Int_t Ntof[3] = {0,0,0};
        Int_t PdgCode[3] = {2212, 212, 211};
        Double_t sigmas [3] = {0,0,0};
                
        for (int i=0;i<DTEvent->GetNTracks(); i++)
        {
            
            TLorentzVector v;
            
            DataTreeTrack* track = DTEvent -> GetTrack(i);
            DataTreeMCTrack* mctrack = DTEvent -> GetMCTrack(i);
            Double_t p = mctrack->GetPt() * TMath::CosH( mctrack->GetEta() );
            if (track->GetTOFHitId() < 0)
            {
                if (mctrack->GetPdgId() == 2212  )  
                {
                    v.SetPtEtaPhiM (track->GetPt(0), track->GetEta(0), track->GetPhi(0), 0.9386);
                    hEffP->Fill ( p, 0 );
                    hEffPSigma->Fill ( p, 0 );
                    hEffPtYP -> Fill( v.Rapidity() - 1.52, v.Pt(), 0 );
                }
                
                if (mctrack->GetPdgId() == 321  )  
                {
                    v.SetPtEtaPhiM (track->GetPt(0), track->GetEta(0), track->GetPhi(0), 0.5);
                    hEffK->Fill ( p, 0 );
                    hEffKSigma->Fill ( p,  0 ); 
                    hEffPtYK -> Fill( v.Rapidity() - 1.52, v.Pt(), 0 );
                }
                
                if (mctrack->GetPdgId() == 211  )  
                {
                    v.SetPtEtaPhiM (track->GetPt(0), track->GetEta(0), track->GetPhi(0), 0.14);
                    hEffPi->Fill ( p, 0 );
                    hEffPiSigma->Fill ( p,  0);  
                    hEffPtYPi -> Fill( v.Rapidity() - 1.52, v.Pt(),  0 );
                }
                continue;
            }
//             
            DataTreeTOFHit* toftrack = DTEvent -> GetTOFHit(track->GetTOFHitId());
            p = toftrack->GetP();
            Double_t m2 = toftrack->GetMass2 ();
            
            Bool_t cut = toftrack->GetBeta() > 0.1 && ( track->GetChiSq(0)/track->GetNDF(0) < 3 ) && p > 1.0 ;
            if ( !cut ) continue;
            
            getter->GetBayesProbability (m2, p, ret);
            sigmas[0] = getter->GetSigmaProton (m2, p);
            sigmas[1] = getter->GetSigmaKaon (m2, p);
            sigmas[2] = getter->GetSigmaPion (m2, p);
            
    //             std::cout << "pdg = " << mctrack->GetPdgId() << " p = " << p << " Sp = " << sigmas[0] << " Sk = " << sigmas[1]<< " Spi = " << sigmas[2] << std::endl;
            
            if (mctrack->GetPdgId() == 2212  )  
            {
                v.SetPtEtaPhiM (track->GetPt(0), track->GetEta(0), track->GetPhi(0), 0.9386);
                hEffP->Fill ( p, ret[0] > 0.9 );
                hEffPSigma->Fill ( p,  sigmas[0] < 3&& sigmas[1] > 2 && sigmas[2] > 2 );
                hEffPtYP -> Fill( v.Rapidity() - 1.52, v.Pt(),  ret[0] > 0.9 );
            }
            
            if (mctrack->GetPdgId() == 321  )  
            {
                v.SetPtEtaPhiM (track->GetPt(0), track->GetEta(0), track->GetPhi(0), 0.5);
                hEffK->Fill ( p, ret[1] > 0.9 );
                hEffKSigma->Fill ( p,  sigmas[1] < 3&& sigmas[2] > 2 && sigmas[0] > 2 ); 
                hEffPtYK -> Fill(  v.Rapidity() - 1.52, v.Pt(),  ret[1] > 0.9 );
            }
            
            if (mctrack->GetPdgId() == 211  )  
            {
                v.SetPtEtaPhiM (track->GetPt(0), track->GetEta(0), track->GetPhi(0), 0.14);
                hEffPi->Fill ( p, ret[2] > 0.9 );
                hEffPiSigma->Fill ( p, sigmas[2] < 3&& sigmas[0] > 2 && sigmas[1] > 2 );  
                hEffPtYPi -> Fill( v.Rapidity() - 1.52, v.Pt(),  ret[2] > 0.9  );
            }
        }
    }

    hEffP       -> SetMarkerStyle(21);      hEffP       -> SetMarkerColor(kRed);     hEffP       -> SetLineColor(kRed); 
    hEffPi      -> SetMarkerStyle(21);      hEffPi      -> SetMarkerColor(kRed);     hEffPi      -> SetLineColor(kRed); 
    hEffK       -> SetMarkerStyle(21);      hEffK       -> SetMarkerColor(kRed);     hEffK       -> SetLineColor(kRed); 
    hEffPSigma  -> SetMarkerStyle(22);      hEffPSigma  -> SetMarkerColor(kBlue);    hEffPSigma  -> SetLineColor(kBlue);
    hEffPiSigma -> SetMarkerStyle(22);      hEffPiSigma -> SetMarkerColor(kBlue);    hEffPiSigma -> SetLineColor(kBlue);
    hEffKSigma  -> SetMarkerStyle(22);      hEffKSigma  -> SetMarkerColor(kBlue);    hEffKSigma  -> SetLineColor(kBlue);

    hEffP->GetXaxis()->SetTitle( "p, GeV/c" );
    hEffP->GetYaxis()->SetTitle(  "Efficiency"  );    
    hEffP->GetYaxis()->SetRangeUser(0.0, 1.);

    hEffK->GetXaxis()->SetTitle( "p, GeV/c" );
    hEffK->GetYaxis()->SetTitle(  "Efficiency"  );    
    hEffK->GetYaxis()->SetRangeUser(0.0, 1.);

    hEffPi->GetXaxis()->SetTitle( "p, GeV/c" );
    hEffPi->GetYaxis()->SetTitle(  "Efficiency"  );    
    hEffPi->GetYaxis()->SetRangeUser(0.0, 1.);
    
    hEffPtYP->GetYaxis()->SetTitle( "p_{T}, GeV/c" );
    hEffPtYP->GetXaxis()->SetTitle(  "Rapidity"  );
    hEffPtYK->GetYaxis()->SetTitle( "p_{T}, GeV/c" );
    hEffPtYK->GetXaxis()->SetTitle(  "Rapidity"  );
    hEffPtYPi->GetYaxis()->SetTitle( "p_{T}, GeV/c" );
    hEffPtYPi->GetXaxis()->SetTitle(  "Rapidity"  );
    
    TCanvas *c1 = new TCanvas ("c1", "c1", 1400, 700);
    c1->Divide(3,1);

    c1->cd(1);
    hEffP->Draw();
    hEffPSigma->Draw("same");
    c1->cd(2);
    hEffK->Draw();
    hEffKSigma->Draw("same");
    c1->cd(3);
    hEffPi->Draw();
    hEffPiSigma->Draw("same");

//     c1->cd(4);
//     getter->GetProtonSigma()->Draw();
//     getter->GetKaonSigma()->Draw("same");
//     getter->GetPionSigma()->Draw("same");
// 
//     c1->cd(5);
//     getter->GetProtonA()->Draw();
//     getter->GetKaonA()->Draw("same");
//     getter->GetPionA()->Draw("same");
// 
//     c1->cd(6);
//     getter->GetProtonM2()->Draw();
//     getter->GetKaonM2()->Draw("same");
//     getter->GetPionM2()->Draw("same");    
    
    TCanvas *c2 = new TCanvas ("c2", "c2", 1400, 700);
    
    c2->Divide(3,1);
    c2->cd(1);
    hEffPtYP->Draw("colz");

    c2->cd(2);
    hEffPtYK->Draw("colz");
    
    c2->cd(3);
    hEffPtYPi->Draw("colz");
    
   
    c1->SaveAs("Canvas_Eff_p_all.root");
    c1->SaveAs("Canvas_Eff_p_all.C");
    c1->SaveAs("Canvas_Eff_p_all.png");
   
    c2->SaveAs("Canvas_Eff_pT_Y_all.root");
    c2->SaveAs("Canvas_Eff_pT_Y_all.C");
    c2->SaveAs("Canvas_Eff_pT_Y_all.png");
   
}
void skim(std::string var, TTree *fullTree, TTree *newTree, std::string cutstr, bool isWeighted , bool reweighted, bool addDiMuSel, bool addMuSel, bool addPhoSel){


  std::cout << fullTree->GetName() << " -> " <<  newTree->GetName() << " " << cutstr.c_str() << std::endl;
  fullTree->Draw(">>cutlist",cutstr.c_str());
  TEventList *keep_points = (TEventList*)gDirectory->Get("cutlist");
  int nEntries = fullTree->GetEntries();

  float x,x_orig;
  float mvametPhi, metRaw;
  float mvametPhiCor ;// corected phis for deltaPhi(met,jet) cut (// NOT to be used in calculation of MT!)
  float weight, weight_wpt, weight_in, weight_in_pu; 
  float catvar1,catvar2,catvar3,catvar4,catvar5,catvar6;   // These are empty, do as we want with them 
  float tau1,tau2;
  float dimuM, mt;	// used for the W/Z selection
  int passVBF;
  unsigned int njets;
  unsigned int nphotons;
  float phopt, phoeta;
  // Why do we use these?
  float metBasicPhi, metBasic;

 
  // Used for reweighting if needed
  ROOT::Math::LorentzVector<ROOT::Math::PxPyPzE4D<double> > *genZ  = new ROOT::Math::LorentzVector<ROOT::Math::PxPyPzE4D<double> >();
  TBranch *brgenZ ;

  // W/Z selection for leptions
  ROOT::Math::LorentzVector<ROOT::Math::PxPyPzE4D<double> > *lepV   = new ROOT::Math::LorentzVector<ROOT::Math::PxPyPzE4D<double> >();
  ROOT::Math::LorentzVector<ROOT::Math::PxPyPzE4D<double> > *lep2V  = new ROOT::Math::LorentzVector<ROOT::Math::PxPyPzE4D<double> >();

  TBranch *brlep   = fullTree->GetBranch("lep1");
  TBranch *brlep_2 = fullTree->GetBranch("lep2");
  brlep->SetAddress(&lepV);
  brlep_2->SetAddress(&lep2V);

  // Check VBF selection 
  ROOT::Math::LorentzVector<ROOT::Math::PxPyPzE4D<double> > *jetV   = new ROOT::Math::LorentzVector<ROOT::Math::PxPyPzE4D<double> >();
  ROOT::Math::LorentzVector<ROOT::Math::PxPyPzE4D<double> > *jet2V  = new ROOT::Math::LorentzVector<ROOT::Math::PxPyPzE4D<double> >();

  // Also need these for second jet veto 
  TBranch *brjet   = fullTree->GetBranch("jet1");
  TBranch *brjet_2 = fullTree->GetBranch("jet2");
  brjet->SetAddress(&jetV);
  brjet_2->SetAddress(&jet2V);


  // if addPhoSel add the two photons
  ROOT::Math::LorentzVector<ROOT::Math::PxPyPzE4D<double> > *pho1V  = new ROOT::Math::LorentzVector<ROOT::Math::PxPyPzE4D<double> >();
  ROOT::Math::LorentzVector<ROOT::Math::PxPyPzE4D<double> > *pho2V  = new ROOT::Math::LorentzVector<ROOT::Math::PxPyPzE4D<double> >();
  TBranch *brpho_1 ;
  TBranch *brpho_2 ;
  if (addPhoSel){
    brpho_1 = fullTree->GetBranch("pho1");
    brpho_2 = fullTree->GetBranch("pho2");    
    brpho_1->SetAddress(&pho1V);
    brpho_2->SetAddress(&pho2V);
  }


  // mu/dimu ?
  std::string origVar = var;
  if (addMuSel)   var+="CorW";
  if (addDiMuSel) var+="CorZ";

  // Add Output branches to our very skimmed down tree.
  //TTree *newTree = new TTree(newname.c_str(),newname.c_str());

  newTree->Branch("mvamet",&x,"mvamet/Float_t");
  newTree->Branch("mvamet_orig",&x_orig,"mvamet_orig/Float_t");
  newTree->Branch("weight",&weight,"weight/Float_t");
  newTree->Branch("weight_wpt",&weight_wpt,"weight_wpt/Float_t");
  newTree->Branch("metRaw",&metRaw,"metRaw/Float_t"); // useful to keep this
  newTree->Branch("jet1mprune",&catvar1,"jet1mprume/Float_t");
  newTree->Branch("jet1mtrim",&catvar2,"jet1mtrim/Float_t");
  newTree->Branch("jet1tau2o1",&catvar3,"jet1tau12o1/Float_t");
  newTree->Branch("jpt",&catvar4,"jpt/Float_t");
  newTree->Branch("jet1eta",&catvar6,"jet1eta/Float_t");
  newTree->Branch("jet1QGtag",&catvar5,"jet1QGtag/Float_t");
  newTree->Branch("passVBF",&passVBF,"passVBF/Int_t");
  newTree->Branch("njets",&njets,"njets/Int_t");

  if (addDiMuSel) {	
    newTree->Branch("dimu_m",&dimuM,"dimu_m/Float_t");
  }
  if (addMuSel) {	
    newTree->Branch("mt",&mt,"mt/Float_t");
  }
  if (addPhoSel) {	
    newTree->Branch("phopt",&phopt,"phopt/Float_t");
    newTree->Branch("phoeta",&phoeta,"phoeta/Float_t");
  }

  fullTree->SetBranchAddress(var.c_str(),&x);
  if (addDiMuSel || addMuSel) fullTree->SetBranchAddress(origVar.c_str(),&x_orig);
  fullTree->SetBranchAddress(Form("%sPhi",var.c_str()),&mvametPhiCor);
  if (addDiMuSel || addMuSel) fullTree->SetBranchAddress(Form("%sPhi",origVar.c_str()),&mvametPhi);
  if (isWeighted) fullTree->SetBranchAddress("weight",&weight_in);
  fullTree->SetBranchAddress("metRaw",&metRaw);
  fullTree->SetBranchAddress("njets",&njets);
  fullTree->SetBranchAddress("nphotons",&nphotons);


  if (isWeighted) fullTree->SetBranchAddress("puWeight",&weight_in_pu);
  //fullTree->SetBranchAddress("jet1mprune",&catvar1);
  //fullTree->SetBranchAddress("jet1mtrim" ,&catvar2);
  //fullTree->SetBranchAddress("jet1tau2" ,&tau2);
  //fullTree->SetBranchAddress("jet1tau1" ,&tau1);
  //fullTree->SetBranchAddress("jet1QGtag",&catvar5);
  //fullTree->SetBranchAddress("jet1"     ,&jet);
   
  if ( reweighted){

    	std::cout << "Reweighting For Photon Efficiency! " << std::endl;
  }

  std::cout << " Filling Skim tree " << newTree->GetName() << std::endl;

  for (int evt=0;evt<nEntries;evt++){
    if ( !(keep_points->Contains(evt)) ) continue;

    fullTree->GetEntry(evt);

    TLorentzVector jet, jet2;
    jet.SetPtEtaPhiM(jetV->Pt(),jetV->Eta(),jetV->Phi(),jetV->M());
    jet2.SetPtEtaPhiM(jet2V->Pt(),jet2V->Eta(),jet2V->Phi(),jet2V->M());
 
    if (addDiMuSel){
      TLorentzVector lep, lep2;
      lep.SetPxPyPzE(lepV->Px(),lepV->Py(),lepV->Pz(),lepV->E());
      lep2.SetPxPyPzE(lep2V->Px(),lep2V->Py(),lep2V->Pz(),lep2V->E());
      dimuM = TMath::Sqrt(2*(lep.E()*lep2.E()-(lep.Px()*lep2.Px()+lep.Py()*lep2.Py()+lep.Pz()*lep2.Pz()))); 
      if ( dimuM < 61 || dimuM > 121 ) continue;     
    }

    if (addMuSel){
      TLorentzVector lep;
      lep.SetPxPyPzE(lepV->Px(),lepV->Py(),lepV->Pz(),lepV->E());
      mt = TMath::Sqrt(2*x_orig*lep.Pt()*(1-TMath::Cos(deltaphi(mvametPhi,lep.Phi()))));  // used original metphi and met to calculate mt
      if ( mt < 50 || mt > 100 ) continue;     
    }

    if (addPhoSel){
      double pho2eta = TMath::Abs(pho2V->Eta());
      if (nphotons>1 && pho2V->Pt() > 100 && (pho2eta<1.4442 || ( pho2eta > 1.566 && pho2eta<2.5))) continue;
      TLorentzVector pho;
      pho.SetPxPyPzE(pho1V->Px(),pho1V->Py(),pho1V->Pz(),pho1V->E());
      x_orig = x;
      double metphocor = computeMET(x,mvametPhiCor,pho);  
      double metphophicor = computeMETPhi(x,mvametPhiCor,pho);  
      x = metphocor;    // Set the variables to the corrected ones now
      mvametPhiCor = metphophicor;
      phopt = pho.Pt();
      phoeta = pho.Eta();
    }
    // Back to regular selection
    // Add MET and second Jet balance cuts !!!
    if (jet2.Pt() > 30){
      if  (deltaphi(jet.Phi(),jet2.Phi()) >= 2) continue;
    }
    if ( deltaphi(jet.Phi(),mvametPhiCor)<2 ) continue;  // this will always be the corrected Phi 
    
    // Weights/Reweightsi
    if (isWeighted) weight = weight_in*weight_in_pu*luminosity;
    else  weight = 1.;
    if (reweighted && isWeighted) { 
        //float genpt = genZ->Pt();
	double phpt  = phopt;
	double pheta = TMath::Abs(phoeta);
    	if (
	    phpt<reweightpheff->GetXaxis()->GetXmax() && phpt > reweightpheff->GetXaxis()->GetXmin()
  	 && pheta<reweightpheff->GetYaxis()->GetXmax() && pheta > reweightpheff->GetYaxis()->GetXmin() 	
	   ) {
	  weight_wpt = weight*reweightpheff->GetBinContent(reweightpheff->FindBin(phpt,pheta));
	} else {
	  weight_wpt = weight;
	}
    } else {
	weight_wpt = weight;
    }
    catvar3 = tau2/tau1;  // make the sub-structure variable
    catvar4 = jet.Pt();
    catvar6 = jet.Eta();

    // Now check the VBF selection (added as a flag)
    // pt>50, eta <4.7, eta1*eta2 < 0 , delta(Eta) > 4.2, Mjj > 1100, deltaPhi < 1.0
    passVBF=0;
    if (jet2.Pt() > 50 && TMath::Abs(jet2.Eta()) < 4.7 ) {
      double j1eta = jet.Eta();
      double j2eta = jet2.Eta();
      if( j1eta*j2eta <0  && deltaphi(jet.Phi(),jet2.Phi()) < 1.0 && (jet+jet2).M() > 1100 && TMath::Abs(j1eta-j2eta) > 4.2) {
	passVBF=1;
      }
    }
    newTree->Fill();
  }
  std::cout << " Finished skim " << std::endl;
}
예제 #27
0
파일: dqmPlots.C 프로젝트: ShashlikTB/T1041
// inputs data file and event in file to display (default is to integrate all)
void dqmDisplay(TString fdat, int ndisplay = -1){

  gStyle->SetOptStat(0);

  TFile *f = new TFile(fdat);
  if (f->IsZombie()){
    cout << "Cannot open file: " << fdat << endl;
    return;
  }

  TBEvent *event = new TBEvent();
  TTree *t1041 = (TTree*)f->Get("t1041"); 
  TBranch *bevent = t1041->GetBranch("tbevent");
  bevent->SetAddress(&event);

  Bool_t singleEvent = (ndisplay >= 0);

  Mapper * mapper = Mapper::Instance();

  TH2F * hModU = (TH2F*)moduleHistogram(true, "RO", threshold, 2500, singleEvent);
  TH2F * hModD = (TH2F*)moduleHistogram(false, "RO", threshold, 2500, singleEvent);
  TH2F * hChanU = (TH2F*)channelHistogram(true, "RO", threshold, 2500, singleEvent);
  TH2F * hChanD = (TH2F*)channelHistogram(false, "RO", threshold, 2500, singleEvent);

  TH2F * hModU_time = (TH2F*)moduleHistogram(true, "Timing", 0, -1, singleEvent);
  TH2F * hModD_time = (TH2F*)moduleHistogram(false, "Timing", 0, -1, singleEvent);
  TH2F * hChanU_time = (TH2F*)channelHistogram(true, "Timing", 0, -1, singleEvent);
  TH2F * hChanD_time = (TH2F*)channelHistogram(false, "Timing", 0, -1, singleEvent);

  int nPerMod = t1041->GetEntries() / 16;
  int nPerFiber = t1041->GetEntries() / 64;

  TH2F * hModU_nhits = (TH2F*)moduleHistogram(true, "nHits", nPerMod * .85, nPerMod * 1.1, singleEvent);
  TH2F * hModD_nhits = (TH2F*)moduleHistogram(false, "nHits", nPerMod * .85, nPerMod * 1.1, singleEvent);
  TH2F * hChanU_nhits = (TH2F*)channelHistogram(true, "nHits", nPerFiber * .25, nPerFiber * 1.1, singleEvent);
  TH2F * hChanD_nhits = (TH2F*)channelHistogram(false, "nHits", nPerFiber * .25, nPerFiber * 1.1, singleEvent);

  TH2F * hModU_ntriggers = (TH2F*)moduleHistogram(true, "nTriggers", nPerMod * .95, nPerMod * 1.3, singleEvent);
  TH2F * hModD_ntriggers = (TH2F*)moduleHistogram(false, "nTriggers", nPerMod * .95, nPerMod * 1.3, singleEvent);
  TH2F * hChanU_ntriggers = (TH2F*)channelHistogram(true, "nTriggers", nPerFiber * .95, nPerFiber * 1.3, singleEvent);
  TH2F * hChanD_ntriggers = (TH2F*)channelHistogram(false, "nTriggers", nPerFiber * .95, nPerFiber * 1.3, singleEvent);

  Int_t start = 0; 
  Int_t end = t1041->GetEntries();

  if (singleEvent) {
    start = ndisplay;
    end = ndisplay + 1;
  }

  for (Int_t i=start; i < end; i++) {
    t1041->GetEntry(i);
    for (Int_t j = 0; j < event->NPadeChan(); j++){
      PadeChannel pch = event->GetPadeChan(j);

      UShort_t max = pch.GetMax();
      Int_t maxTime = pch.GetPeak();
      if (max>MAXADC) continue;    // skip channels with bad adc readings (should be RARE)

      int channelID=pch.GetChannelID();   // boardID*100+channelNum in PADE
      int moduleID,fiberID;
      mapper->ChannelID2ModuleFiber(channelID,moduleID,fiberID);  // get module and fiber IDs

      float xm,ym,xf,yf;
      mapper->ModuleXY(moduleID,xm,ym);
      mapper->FiberXY(fiberID, xf, yf);
	    
      if(moduleID < 0) {
	hModU_ntriggers->Fill(xm, ym);
	hChanU_ntriggers->Fill(xf, yf);
      }
      else {
	hModD_ntriggers->Fill(xm, ym);
	hChanD_ntriggers->Fill(xf, yf);
      }
      if(max <= threshold) continue;


      if (moduleID < 0) {
	hModU->Fill(xm, ym, max);
	hModU_time->Fill(xm, ym, maxTime);
	hModU_nhits->Fill(xm, ym);

	hChanU->Fill(xf, yf, max);
	hChanU_time->Fill(xf, yf, maxTime);
	hChanU_nhits->Fill(xf, yf);
      }
      else {
	hModD->Fill(xm, ym, max);
	hModD_time->Fill(xm, ym, maxTime);
	hModD_nhits->Fill(xm, ym);

	hChanD->Fill(xf, yf, max);
	hChanD_time->Fill(xf, yf, maxTime);
	hChanD_nhits->Fill(xf, yf);
      }
      
    }

  }

  hModD->Divide(hModD_nhits);
  hModU->Divide(hModU_nhits);
  hChanD->Divide(hChanD_nhits);
  hChanU->Divide(hChanU_nhits);

  hModD_time->Divide(hModD_nhits);
  hModU_time->Divide(hModU_nhits);
  hChanD_time->Divide(hChanD_nhits);
  hChanU_time->Divide(hChanU_nhits);

  drawCalorimeterPlot("AvgPeakHeight", 
		      hModU, hModD, hChanU, hChanD,
		      t1041->GetEntries(), ndisplay);

  drawCalorimeterPlot("AvgPeakTiming",
		      hModU_time, hModD_time, hChanU_time, hChanD_time,
		      t1041->GetEntries(), ndisplay);

  drawCalorimeterPlot("NHits", 
		      hModU_nhits, hModD_nhits, hChanU_nhits, hChanD_nhits,
		      t1041->GetEntries(), ndisplay);

  drawCalorimeterPlot("NTriggers",
		      hModU_ntriggers, hModD_ntriggers, hChanU_ntriggers, hChanD_ntriggers,
		      t1041->GetEntries(), ndisplay);

}
예제 #28
0
// Simple example of reading a generated Root file
void verification_HitsChargeTime(char *filename=NULL, char *filename2, bool verbose=false)
{
  // Clear global scope
  //gROOT->Reset();
  
  gStyle->SetOptStat(0);
  gStyle->SetCanvasColor(0);
  gStyle->SetTitleColor(1);
  gStyle->SetStatColor(0);
  gStyle->SetFrameFillColor(0);
  gStyle->SetPadColor(0);
  gStyle->SetPadTickX(1);
  gStyle->SetPadTickY(1);
  gStyle->SetTitleSize(0.04);
  gStyle->SetCanvasBorderMode(0);
  gStyle->SetFrameBorderMode(0);
  gStyle->SetFrameLineWidth(2);
  gStyle->SetPadBorderMode(0);
  gStyle->SetPalette(1);
  gStyle->SetTitleAlign(23);
  gStyle->SetTitleX(.5);
  gStyle->SetTitleY(0.99);
  gStyle->SetTitleBorderSize(0);
  gStyle->SetTitleFillColor(0);
  gStyle->SetHatchesLineWidth(2);
  gStyle->SetLineWidth(1.5);
  gStyle->SetTitleFontSize(0.07);
  gStyle->SetLabelSize(0.05,"X");
  gStyle->SetLabelSize(0.05,"Y");
  gStyle->SetTitleSize(0.04,"X");
  gStyle->SetTitleSize(0.04,"Y");
  gStyle->SetTitleBorderSize(0);
  gStyle->SetCanvasBorderMode(0);
  
  
  // Load the library with class dictionary info
  // (create with "gmake shared")
  char* wcsimdirenv;
  wcsimdirenv = getenv ("WCSIMDIR");
  if(wcsimdirenv !=  NULL){
    gSystem->Load("${WCSIMDIR}/libWCSimRoot.so");
  }else{
    gSystem->Load("../libWCSimRoot.so");
  }

  TFile *f;
  // Open the file
  if (filename==NULL){
    f = new TFile("wcsimtest.root","read");
    filename = "wcsimtest.root";
  }else{
    f = new TFile(filename,"read");
  }
  if (!f->IsOpen()){
    cout << "Error, could not open input file: " << filename << endl;
    return -1;
  }
  
  TFile *f2;
  // Open the file
  if (filename2==NULL){
    f2 = new TFile("../../WCSim_clean/verification-test-scripts/wcsimtest.root","read");
    filename2 = "../../WCSim_clean/verification-test-scripts/wcsimtest.root";
  }else{
    f2 = new TFile(filename2,"read");
  }
  if (!f2->IsOpen()){
    cout << "Error, could not open input file: " << filename2 << endl;
    return -1;
  }
  
 
  TTree  *wcsimT = f->Get("wcsimT");
  int nevent = wcsimT->GetEntries();
  WCSimRootEvent *wcsimrootsuperevent = new WCSimRootEvent();
  wcsimT->SetBranchAddress("wcsimrootevent",&wcsimrootsuperevent);

  // Force deletion to prevent memory leak when issuing multiple
  // calls to GetEvent()
  wcsimT->GetBranch("wcsimrootevent")->SetAutoDelete(kTRUE);

  wcsimT->GetEvent(0); 

  // In the default vis.mac, only one event is run.  I suspect you could loop over more events, if they existed.
  WCSimRootTrigger *wcsimrootevent = wcsimrootsuperevent->GetTrigger(0);
  cout << "Stats for the first event in your version of WCSim using " << filename << endl;
  cout << "Number of tube hits " << wcsimrootevent->GetNumTubesHit() << endl;

  cout << "Number of digitized tube hits " << wcsimrootevent->GetNumDigiTubesHit() << endl;
  cout << "Number of photoelectron hit times " << wcsimrootevent->GetCherenkovHitTimes()->GetEntries() << endl;

  //Save these to compare with the clean version of the code. 

  int num_tubes =  wcsimrootevent->GetNumTubesHit();
  int num_digi_tubes = wcsimrootevent->GetNumDigiTubesHit();
  int hit_times = wcsimrootevent->GetCherenkovHitTimes()->GetEntries();
 

  // Create a WCSimRootEvent to put stuff from the tree in

  WCSimRootEvent* wcsimrootsuperevent = new WCSimRootEvent();

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

  // Force deletion to prevent memory leak 
  wcsimT->GetBranch("wcsimrootevent")->SetAutoDelete(kTRUE);


   // start with the main "subevent", as it contains most of the info
  // and always exists.
  WCSimRootTrigger* wcsimrootevent;

  TH1F *h1 = new TH1F("PMT Hits", "# Digitized Hits", 500, 0, 3000);
  TH1F *time = new TH1F("Average time", "Average time", 600, 900, 2000);
  TH1F *pe = new TH1F("Q/# Digitzed PMT", "Average Charge", 200, 0, 5);
 
  
  // Now loop over events
  for (int ev=0; ev<nevent; ev++)
  {
    // Read the event from the tree into the WCSimRootEvent instance
    wcsimT->GetEntry(ev);      
    wcsimrootevent = wcsimrootsuperevent->GetTrigger(0);
    if(verbose){
      printf("********************************************************");
      printf("Evt, date %d %d\n", wcsimrootevent->GetHeader()->GetEvtNum(),
	     wcsimrootevent->GetHeader()->GetDate());
      printf("Mode %d\n", wcsimrootevent->GetMode());
      printf("Number of subevents %d\n",
	     wcsimrootsuperevent->GetNumberOfSubEvents());
      
      printf("Vtxvol %d\n", wcsimrootevent->GetVtxvol());
      printf("Vtx %f %f %f\n", wcsimrootevent->GetVtx(0),
	     wcsimrootevent->GetVtx(1),wcsimrootevent->GetVtx(2));
    }
    
    for (int index = 0 ; index < wcsimrootsuperevent->GetNumberOfEvents(); index++) 
      { 
	int ncherenkovdigihits = wcsimrootevent->GetNcherenkovdigihits();
	h1->Fill(ncherenkovdigihits);
	
	
	
	float totalq = 0.;
	float totalt = 0.;
	// Loop through elements in the TClonesArray of WCSimRootCherenkovHits
	for (int i=0; i< ncherenkovdigihits; i++)
	  {
	    TObject *Digi = (wcsimrootevent->GetCherenkovDigiHits())->At(i);
	    WCSimRootCherenkovDigiHit *wcsimrootcherenkovdigihit = 
	      dynamic_cast<WCSimRootCherenkovDigiHit*>(Digi);
	    
	    int tubeNumber     =  (wcsimrootcherenkovdigihit->GetT(),wcsimrootcherenkovdigihit->GetTubeId());
	    float q = wcsimrootcherenkovdigihit->GetQ();
	    float t = wcsimrootcherenkovdigihit->GetT();
	    totalq+=q;
	    totalt+=t;
	  }
	float av_time = totalt/ncherenkovdigihits;
	float av_q = totalq/ncherenkovdigihits;
      }
    pe->Fill(av_q);  
    time->Fill(av_time);
    // reinitialize super event between loops.
    wcsimrootsuperevent->ReInitialize();
  }// End of loop over events

TTree  *wcsimT2 = f2->Get("wcsimT");
  int nevent2 = wcsimT2->GetEntries();
  WCSimRootEvent *wcsimrootsuperevent = new WCSimRootEvent();
  wcsimT2->SetBranchAddress("wcsimrootevent",&wcsimrootsuperevent);

  // Force deletion to prevent memory leak when issuing multiple
  // calls to GetEvent()
  wcsimT2->GetBranch("wcsimrootevent")->SetAutoDelete(kTRUE);

  wcsimT2->GetEvent(0); 

  // In the default vis.mac, only one event is run.  I suspect you could loop over more events, if they existed.
  WCSimRootTrigger *wcsimrootevent = wcsimrootsuperevent->GetTrigger(0);

  cout << "***********************************************************" << endl;
  cout << "Stats for the first event of WCSim version on GitHub using "<< filename2 << endl;
  cout << "Number of tube hits " << wcsimrootevent->GetNumTubesHit() << endl;

  cout << "Number of digitized tube hits " << wcsimrootevent->GetNumDigiTubesHit() << endl;
  cout << "Number of photoelectron hit times " << wcsimrootevent->GetCherenkovHitTimes()->GetEntries() << endl;

  cout <<  "***********************************************************" << endl;
  if (abs(num_tubes- wcsimrootevent->GetNumTubesHit())>1.0e-6){cout << "FIRST EVENT TEST FAILED: Number of hit tubes do not match" << endl;}
  else {cout << "FIRST EVENT TEST PASSED: Number of hit tubes matches" << endl;}
  if (abs(num_digi_tubes-wcsimrootevent->GetNumDigiTubesHit())>1.0e-6){cout << "FIRST EVENT TEST FAILED: Number of digitized tubes do not match" << endl; }
  else {cout << "FIRST EVENT TEST PASSED: Number of digitized tubes matches" << endl; }
  if (abs(hit_times-(wcsimrootevent->GetCherenkovHitTimes()->GetEntries()))> 1.0e-6){cout << "FIRST EVENT TEST FAILED: Number of hit times do not match" << endl;}
  else {cout << "FIRST EVENT TEST PASSED: Number of hit times matches" << endl;}


  // Create a WCSimRootEvent to put stuff from the tree in

  WCSimRootEvent* wcsimrootsuperevent = new WCSimRootEvent();

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

  // Force deletion to prevent memory leak 
  wcsimT2->GetBranch("wcsimrootevent")->SetAutoDelete(kTRUE);


   // start with the main "subevent", as it contains most of the info
  // and always exists.
  WCSimRootTrigger* wcsimrootevent;

  TH1F *h2 = new TH1F("PMT Hits 2", "Digitized Hits", 500, 0, 3000);
  TH1F *time2 = new TH1F("Average time 2", "Average time", 600, 900, 2000);
  TH1F *pe2 = new TH1F("Q/# Digitzed PMT 2", "Q/# Digitzed PMT", 200, 0, 5);
 
  
  // Now loop over events
  for (int ev=0; ev<nevent; ev++)
  {
    // Read the event from the tree into the WCSimRootEvent instance
    wcsimT2->GetEntry(ev);      
    wcsimrootevent = wcsimrootsuperevent->GetTrigger(0);
  
    if(verbose){
      printf("********************************************************");
      printf("Evt, date %d %d\n", wcsimrootevent->GetHeader()->GetEvtNum(),
	     wcsimrootevent->GetHeader()->GetDate());
      printf("Mode %d\n", wcsimrootevent->GetMode());
      printf("Number of subevents %d\n",
	     wcsimrootsuperevent->GetNumberOfSubEvents());
      
      printf("Vtxvol %d\n", wcsimrootevent->GetVtxvol());
      printf("Vtx %f %f %f\n", wcsimrootevent->GetVtx(0),
	     wcsimrootevent->GetVtx(1),wcsimrootevent->GetVtx(2));
    }
    
    for (int index = 0 ; index < wcsimrootsuperevent->GetNumberOfEvents(); index++) 
      { 
	int ncherenkovdigihits = wcsimrootevent->GetNcherenkovdigihits();
	h2->Fill(ncherenkovdigihits);

	
	float totalq = 0.;
	float totalt = 0.;
	// Loop through elements in the TClonesArray of WCSimRootCherenkovHits
	for (int i=0; i< ncherenkovdigihits; i++)
	  {
	    TObject *Digi = (wcsimrootevent->GetCherenkovDigiHits())->At(i);
	    WCSimRootCherenkovDigiHit *wcsimrootcherenkovdigihit = 
	      dynamic_cast<WCSimRootCherenkovDigiHit*>(Digi);
	    
	    int tubeNumber     =  (wcsimrootcherenkovdigihit->GetT(),wcsimrootcherenkovdigihit->GetTubeId());
	    float q = wcsimrootcherenkovdigihit->GetQ();
	    float t = wcsimrootcherenkovdigihit->GetT();
	    totalq+=q;
	    totalt+=t;
	  }
	float av_time = totalt/ncherenkovdigihits;
	float av_q = totalq/ncherenkovdigihits;
      }
    pe2->Fill(av_q);  
    time2->Fill(av_time);
    // reinitialize super event between loops.
    wcsimrootsuperevent->ReInitialize();
  }// End of loop over events

	Double_t ks_hits = h1->KolmogorovTest(h2);
	Double_t ks_charge = pe->KolmogorovTest(pe2);
	Double_t ks_time = time->KolmogorovTest(time2);
	cout << "***********************************************************" << endl;
	cout << "ks test for # of digitized hits: " << ks_hits << endl;
	cout << "ks test for average charge: " << ks_charge << endl;
	cout << "ks test for average time: " << ks_time << endl;

  //  TCanvas c1("c1"); 
  float win_scale = 0.75;
  int n_wide(2);
  int n_high(2);
  TCanvas* c1 = new TCanvas("c1", "Test Plots", 500*n_wide*win_scale, 500*n_high*win_scale);
  c1->Draw();
  c1->Divide(2,2);
  c1->cd(1); 
  h2->SetLineColor(kRed);
  h1->Draw();
  c1->cd(1); h2->Draw("SAME");

 TLegend *leg = new TLegend(0.2,0.7,0.55,0.85, "");
 leg->SetFillColor(0);
 leg->SetBorderSize(0);
 leg->AddEntry(h1,filename, "l");
 leg->AddEntry(h2,filename2, "l");
 leg->Draw();
 
 c1->cd(2);
 pe->GetXaxis()->SetTitle("Total Charge / # digitized hits");
 pe->Draw();
 pe2->SetLineColor(kRed);
 c1->cd(2); pe2->Draw("SAME");
 c1->cd(3); 
 time->GetXaxis()->SetTitle("Total Time / # digitized hits (ns)");  
 time->Draw();
 time2->SetLineColor(kRed);
 c1->cd(3); time2->Draw("SAME");
  

}
예제 #29
0
void Plot_EE_mu_maps_2(){

	gROOT->SetStyle("Plain");
	gStyle->SetPalette(1);
	gStyle->SetOptStat(0);

//	TFile *outf = new TFile("/shome/haweber/ECAL/Laser/Analysis/Plots/20121126_EEmustd.root", "RECREATE");
	TFile *outf = new TFile("/shome/haweber/ECAL/DataLaser/20121116_EEmustd.root", "RECREATE");

	TFile *file = TFile::Open("/shome/haweber/ECAL/DataLaser/ana_rad_ecal_v3.root");
	TTree *tree = (TTree*)file->Get("EE");

	TH2D *mu_ECAL_EEp_russ = new TH2D("mu_ECAL_EEp_russ", "mu_ECAL_EEp_russ", 101, 0, 101, 101, 0, 101);
	TH2D *mu_ECAL_EEp_chin = new TH2D("mu_ECAL_EEp_chin", "mu_ECAL_EEp_chin", 101, 0, 101, 101, 0, 101);
	TH2D *mu_ECAL_EEm_russ = new TH2D("mu_ECAL_EEm_russ", "mu_ECAL_EEm_russ", 101, 0, 101, 101, 0, 101);
	TH2D *mu_ECAL_EEm_chin = new TH2D("mu_ECAL_EEm_chin", "mu_ECAL_EEm_chin", 101, 0, 101, 101, 0, 101);

	TH2D *mu_SIC_EEp_russ  = new TH2D("mu_SIC_EEp_russ",  "mu_SIC_EEp_russ",  101, 0, 101, 101, 0, 101);
	TH2D *mu_SIC_EEp_chin  = new TH2D("mu_SIC_EEp_chin",  "mu_SIC_EEp_chin",  101, 0, 101, 101, 0, 101);
	TH2D *mu_SIC_EEm_russ  = new TH2D("mu_SIC_EEm_russ",  "mu_SIC_EEm_russ",  101, 0, 101, 101, 0, 101);
	TH2D *mu_SIC_EEm_chin  = new TH2D("mu_SIC_EEm_chin",  "mu_SIC_EEm_chin",  101, 0, 101, 101, 0, 101);


	TH2D *mu_std_EEp       = new TH2D("mu_std_EEp",       "mu_std_EEp",       101, 0, 101, 101, 0, 101);
	TH2D *mu_std_EEm       = new TH2D("mu_std_EEm",       "mu_std_EEm",       101, 0, 101, 101, 0, 101);
	TH2D *mu_SIC_EEp       = new TH2D("mu_SIC_EEp",       "mu_SIC_EEp",       101, 0, 101, 101, 0, 101);
	TH2D *mu_SIC_EEm       = new TH2D("mu_SIC_EEm",       "mu_SIC_EEm",       101, 0, 101, 101, 0, 101);

	TH2D *VPT_gainqe_EEp   = new TH2D("VPT_gainqe_EEp",   "VPT_gainqe_EEp",   101, 0, 101, 101, 0, 101);
	TH2D *VPT_gainqe_EEm   = new TH2D("VPT_gainqe_EEm",   "VPT_gainqe_EEm",   101, 0, 101, 101, 0, 101);
	TH2D *VPT_gain_EEp     = new TH2D("VPT_gain_EEp",     "VPT_gain_EEp",     101, 0, 101, 101, 0, 101);
	TH2D *VPT_gain_EEm     = new TH2D("VPT_gain_EEm",     "VPT_gain_EEm",     101, 0, 101, 101, 0, 101);
	TH2D *VPT_qe_EEp       = new TH2D("VPT_qe_EEp",       "VPT_qe_EEp",       101, 0, 101, 101, 0, 101);
	TH2D *VPT_qe_EEm       = new TH2D("VPT_qe_EEm",       "VPT_qe_EEm",       101, 0, 101, 101, 0, 101);

	TH2D *EEp_producer     = new TH2D("EEp_producer",     "EEp_producer",     101, 0, 101, 101, 0, 101);
	TH2D *EEm_producer     = new TH2D("EEm_producer",     "EEm_producer",     101, 0, 101, 101, 0, 101);

	int nev;
	TString variable, var;
	TString selection, sel;

   	Long64_t nentries = tree->GetEntriesFast();
	cout << "Tree contains "<< nentries << " entries" << endl;

	int ix,iy,iz;
	double mu_ECAL, mu_SIC;
	float vpt_gain, vpt_qe, vpt_pg;
	int producer;
	TBranch *xx     = tree->GetBranch("ix");
	TBranch *yy     = tree->GetBranch("iy");
	TBranch *zz     = tree->GetBranch("iz");
	TBranch *muECAL = tree->GetBranch("mu_ECAL");
	TBranch *muSIC  = tree->GetBranch("mu_SIC");
	TBranch *prod   = tree->GetBranch("producer");
	TBranch *gain   = tree->GetBranch("vpt_gain");
	TBranch *qe     = tree->GetBranch("vpt_qe");
	TBranch *pg     = tree->GetBranch("vpt_pg");
	xx    ->SetAddress(&ix);
	yy    ->SetAddress(&iy);
	zz    ->SetAddress(&iz);
	muECAL->SetAddress(&mu_ECAL);
	muSIC ->SetAddress(&mu_SIC);
	prod  ->SetAddress(&producer);
	gain  ->SetAddress(&vpt_gain);
	qe    ->SetAddress(&vpt_qe);
	pg    ->SetAddress(&vpt_pg);

   	Long64_t nbytes = 0, nb = 0;
   	    for (Long64_t jentry=0; jentry<nentries;jentry++) {
      		//Long64_t ientry = tree->LoadTree(jentry);
      		//if (ientry < 0) break;
		//if(jentry%(nentries/25)==0) cout << "Processing event " << jentry << endl;
		nb = tree->GetEntry(jentry);   nbytes += nb;

	//	int iX = ix;
	//	int iY = iy;
	//	int iZ = iz;
	//	if(mu_ECAL>0){
	//	cout << "ix " << iX << " iy " << iY << " iz " << iZ << endl;
	//	cout << "mustd " << mu_ECAL << " muSIC " << mu_SIC << " producer " << producer << endl;
	//	}
		int bin = mu_ECAL_EEp_russ->FindBin(ix,iy);

		if(mu_ECAL>=0 && iz==1 && producer==1){//EE+, russian
			if(mu_ECAL_EEp_russ->GetBinContent(bin)>0) cout << "mu_ECAL: bin " << bin << " (ix,iy,iz=" << ix <<","<<iy<<","<<iz<<") was filled with " << mu_ECAL_EEp_russ->GetBinContent(bin) << " and now is filled with " << mu_ECAL << endl;
			mu_ECAL_EEp_russ->SetBinContent(bin, mu_ECAL);
		}
		if(mu_ECAL>=0 && iz==-1 && producer==1){//EE-, russian
			if(mu_ECAL_EEm_russ->GetBinContent(bin)>0) cout << "mu_ECAL: bin " << bin << " (ix,iy,iz=" << ix <<","<<iy<<","<<iz<<") was filled with " << mu_ECAL_EEm_russ->GetBinContent(bin) << " and now is filled with " << mu_ECAL << endl;
			mu_ECAL_EEm_russ->SetBinContent(bin, mu_ECAL);
		}
		if(mu_ECAL>=0 && iz==1 && producer==2){//EE+, chinese
			if(mu_ECAL_EEp_chin->GetBinContent(bin)>0) cout << "mu_ECAL: bin " << bin << " (ix,iy,iz=" << ix <<","<<iy<<","<<iz<<") was filled with " << mu_ECAL_EEp_chin->GetBinContent(bin) << " and now is filled with " << mu_ECAL << endl;
			mu_ECAL_EEp_chin->SetBinContent(bin, mu_ECAL);
		}
		if(mu_ECAL>=0 && iz==-1 && producer==2){//EE-, chinese
			if(mu_ECAL_EEm_chin->GetBinContent(bin)>0) cout << "mu_ECAL: bin " << bin << " (ix,iy,iz=" << ix <<","<<iy<<","<<iz<<") was filled with " << mu_ECAL_EEm_chin->GetBinContent(bin) << " and now is filled with " << mu_ECAL << endl;
			mu_ECAL_EEm_chin->SetBinContent(bin, mu_ECAL);
		}
		if(mu_SIC>=0 && iz==1 && producer==1){//EE+, russian
			if(mu_SIC_EEp_russ->GetBinContent(bin)>0) cout << "mu_SIC: bin " << bin << " (ix,iy,iz=" << ix <<","<<iy<<","<<iz<<") was filled with " << mu_SIC_EEp_russ->GetBinContent(bin) << " and now is filled with " << mu_SIC << endl;
			mu_SIC_EEp_russ->SetBinContent(bin, mu_SIC);
		}
		if(mu_SIC>=0 && iz==-1 && producer==1){//EE-, russian
			if(mu_SIC_EEm_russ->GetBinContent(bin)>0) cout << "mu_SIC: bin " << bin << " (ix,iy,iz=" << ix <<","<<iy<<","<<iz<<") was filled with " << mu_SIC_EEm_russ->GetBinContent(bin) << " and now is filled with " << mu_SIC << endl;
			mu_SIC_EEm_russ->SetBinContent(bin, mu_SIC);
		}
		if(mu_SIC>=0 && iz==1 && producer==2){//EE+, chinese
			if(mu_SIC_EEp_chin->GetBinContent(bin)>0) cout << "mu_SIC: bin " << bin << " (ix,iy,iz=" << ix <<","<<iy<<","<<iz<<") was filled with " << mu_SIC_EEp_chin->GetBinContent(bin) << " and now is filled with " << mu_SIC << endl;
			mu_SIC_EEp_chin->SetBinContent(bin, mu_SIC);
		}
		if(mu_SIC>=0 && iz==-1 && producer==2){//EE-, chinese
			if(mu_SIC_EEm_chin->GetBinContent(bin)>0) cout << "mu_SIC: bin " << bin << " (ix,iy,iz=" << ix <<","<<iy<<","<<iz<<") was filled with " << mu_SIC_EEm_chin->GetBinContent(bin) << " and now is filled with " << mu_SIC << endl;
			mu_SIC_EEm_chin->SetBinContent(bin, mu_SIC);
		}
		if(iz==1 && (producer==1||producer==2)){
			if(EEp_producer->GetBinContent(bin)>0) cout << "producer: bin " << bin << " (ix,iy,iz=" << ix <<","<<iy<<","<<iz<<") was filled with " << EEp_producer->GetBinContent(bin) << " and now is filled with " << producer << endl;
			EEp_producer->SetBinContent(bin, producer);
		}
		if(iz==-1 && (producer==1||producer==2)){
			if(EEm_producer->GetBinContent(bin)>0) cout << "producer: bin " << bin << " (ix,iy,iz=" << ix <<","<<iy<<","<<iz<<") was filled with " << EEm_producer->GetBinContent(bin) << " and now is filled with " << producer << endl;
			EEm_producer->SetBinContent(bin, producer);
		}

		if(vpt_pg>=0 && iz==1){
			if(VPT_gainqe_EEp->GetBinContent(bin)>0) cout << __LINE__ << ": bin " << bin << " (ix,iy,iz=" << ix <<","<<iy<<","<<iz<<") was filled with " << VPT_gainqe_EEp->GetBinContent(bin) << " and now is filled with " << vpt_pg << endl;
			VPT_gainqe_EEp->SetBinContent(bin, vpt_pg);
		}
		if(vpt_pg>=0 && iz==-1){
			if(VPT_gainqe_EEm->GetBinContent(bin)>0) cout << __LINE__ << ": bin " << bin << " (ix,iy,iz=" << ix <<","<<iy<<","<<iz<<") was filled with " << VPT_gainqe_EEm->GetBinContent(bin) << " and now is filled with " << vpt_pg << endl;
			VPT_gainqe_EEm->SetBinContent(bin, vpt_pg);
		}
		if(vpt_qe>=0 && iz==1){
			if(VPT_qe_EEp->GetBinContent(bin)>0) cout << __LINE__ << ": bin " << bin << " (ix,iy,iz=" << ix <<","<<iy<<","<<iz<<") was filled with " << VPT_qe_EEp->GetBinContent(bin) << " and now is filled with " << vpt_qe << endl;
			VPT_qe_EEp->SetBinContent(bin, vpt_qe);
		}
		if(vpt_qe>=0 && iz==-1){
			if(VPT_qe_EEm->GetBinContent(bin)>0) cout << __LINE__ << ": bin " << bin << " (ix,iy,iz=" << ix <<","<<iy<<","<<iz<<") was filled with " << VPT_qe_EEm->GetBinContent(bin) << " and now is filled with " << vpt_qe << endl;
			VPT_qe_EEm->SetBinContent(bin, vpt_qe);
		}
		if(vpt_gain>=0 && iz==1){
			if(VPT_gain_EEp->GetBinContent(bin)>0) cout << __LINE__ << ": bin " << bin << " (ix,iy,iz=" << ix <<","<<iy<<","<<iz<<") was filled with " << VPT_gain_EEp->GetBinContent(bin) << " and now is filled with " << vpt_gain << endl;
			VPT_gain_EEp->SetBinContent(bin, vpt_gain);
		}
		if(vpt_gain>=0 && iz==-1){
			if(VPT_gain_EEm->GetBinContent(bin)>0) cout << __LINE__ << ": bin " << bin << " (ix,iy,iz=" << ix <<","<<iy<<","<<iz<<") was filled with " << VPT_gain_EEm->GetBinContent(bin) << " and now is filled with " << vpt_gain << endl;
			VPT_gain_EEm->SetBinContent(bin, vpt_gain);
		}
	   }

	mu_std_EEp->Add(mu_ECAL_EEp_russ,1);
	mu_std_EEp->Add(mu_ECAL_EEp_chin,1);
	mu_std_EEm->Add(mu_ECAL_EEm_russ,1);
	mu_std_EEm->Add(mu_ECAL_EEm_chin,1);
	mu_SIC_EEp->Add(mu_SIC_EEp_russ, 1);
	mu_SIC_EEp->Add(mu_SIC_EEp_chin, 1);
	mu_SIC_EEm->Add(mu_SIC_EEm_russ, 1);
	mu_SIC_EEm->Add(mu_SIC_EEm_chin, 1);

	mu_std_EEp->SetMaximum(2.); mu_std_EEp->GetZaxis()->SetRangeUser(0.,2.);
	mu_std_EEm->SetMaximum(2.); mu_std_EEm->GetZaxis()->SetRangeUser(0.,2.);
	mu_SIC_EEp->SetMaximum(2.); mu_SIC_EEp->GetZaxis()->SetRangeUser(0.,2.);
	mu_SIC_EEm->SetMaximum(2.); mu_SIC_EEm->GetZaxis()->SetRangeUser(0.,2.);

	TString outputdir = "/shome/haweber/ECAL/Laser/Analysis/Plots";

	if(mu_ECAL_EEp_russ->GetEntries()>0){
	TCanvas *can1 = new TCanvas("can1", "mu_ECAL_EEp_russ", 0, 0, 900, 700);
	can1->cd();
	mu_ECAL_EEp_russ->Draw("COLZ");
	//Util::PrintNoEPS(can1, can1->GetTitle(), outputdir);
	Util::PrintEPS(can1, can1->GetTitle(), outputdir);
	} if(mu_ECAL_EEp_chin->GetEntries()>0){
	TCanvas *can2 = new TCanvas("can2", "mu_ECAL_EEp_chin", 0, 0, 900, 700);
	can2->cd();
	mu_ECAL_EEp_chin->Draw("COLZ");
	//Util::PrintNoEPS(can2, can2->GetTitle(), outputdir);
	Util::PrintEPS(can2, can2->GetTitle(), outputdir);
	} if(mu_ECAL_EEm_russ->GetEntries()>0){
	TCanvas *can3 = new TCanvas("can3", "mu_ECAL_EEm_russ", 0, 0, 900, 700);
	can3->cd();
	mu_ECAL_EEm_russ->Draw("COLZ");
	//Util::PrintNoEPS(can3, can3->GetTitle(), outputdir);
	Util::PrintEPS(can3, can3->GetTitle(), outputdir);
	} if(mu_ECAL_EEm_chin->GetEntries()>0){
	TCanvas *can4 = new TCanvas("can4", "mu_ECAL_EEm_chin", 0, 0, 900, 700);
	can4->cd();
	mu_ECAL_EEm_chin->Draw("COLZ");
	//Util::PrintNoEPS(can4, can4->GetTitle(), outputdir);
	Util::PrintEPS(can4, can4->GetTitle(), outputdir);
	} if(mu_SIC_EEp_russ->GetEntries()>0){
	TCanvas *can5 = new TCanvas("can5", "mu_SIC_EEp_russ", 0, 0, 900, 700);
	can5->cd();
	mu_SIC_EEp_russ->Draw("COLZ");
	//Util::PrintNoEPS(can5, can5->GetTitle(), outputdir);
	Util::PrintEPS(can5, can5->GetTitle(), outputdir);
	} if(mu_SIC_EEp_chin->GetEntries()>0){
	TCanvas *can6 = new TCanvas("can6", "mu_SIC_EEp_chin", 0, 0, 900, 700);
	can6->cd();
	mu_SIC_EEp_chin->Draw("COLZ");
	//Util::PrintNoEPS(can6, can6->GetTitle(), outputdir);
	Util::PrintEPS(can6, can6->GetTitle(), outputdir);	
	} if(mu_SIC_EEm_russ->GetEntries()>0){
	TCanvas *can7 = new TCanvas("can7", "mu_SIC_EEm_russ", 0, 0, 900, 700);
	can7->cd();
	mu_SIC_EEm_russ->Draw("COLZ");
	//Util::PrintNoEPS(can7, can7->GetTitle(), outputdir);
	Util::PrintEPS(can7, can7->GetTitle(), outputdir);
	} if(mu_SIC_EEm_chin->GetEntries()>0){
	TCanvas *can8 = new TCanvas("can8", "mu_SIC_EEm_chin", 0, 0, 900, 700);
	can8->cd();
	mu_SIC_EEm_chin->Draw("COLZ");
	//Util::PrintNoEPS(can8, can8->GetTitle(), outputdir);
	Util::PrintEPS(can8, can8->GetTitle(), outputdir);
	}

	TCanvas *c1 = new TCanvas("c1", "mu_SIC_EEm_chin", 0, 0, 900, 700);
	c1->cd();
	mu_std_EEp->Draw("COLZ");
	//Util::PrintNoEPS(c1, mu_std_EEp->GetTitle(), outputdir);
	Util::PrintEPS(c1, mu_std_EEp->GetTitle(), outputdir);
//	c1->Clear();
	TCanvas *c2 = new TCanvas("c2", "mu_SIC_EEm_chin", 0, 0, 900, 700);
	c2->cd();
	mu_std_EEm->Draw("COLZ");
	//Util::PrintNoEPS(c2, mu_std_EEm->GetTitle(), outputdir);
	Util::PrintEPS(c2, mu_std_EEm->GetTitle(), outputdir);
//	c2->Clear();
	TCanvas *c3 = new TCanvas("c3", "mu_SIC_EEm_chin", 0, 0, 900, 700);
	c3->cd();
	mu_SIC_EEp->Draw("COLZ");
	//Util::PrintNoEPS(c3, mu_SIC_EEp->GetTitle(), outputdir);
	Util::PrintEPS(c3, mu_SIC_EEp->GetTitle(), outputdir);
//	c3->Clear();
	TCanvas *c4 = new TCanvas("c4", "mu_SIC_EEm_chin", 0, 0, 900, 700);
	c4->cd();
	mu_SIC_EEm->Draw("COLZ");
	//Util::PrintNoEPS(c4, mu_SIC_EEm->GetTitle(), outputdir);
	Util::PrintEPS(c4, mu_SIC_EEm->GetTitle(), outputdir);

	TCanvas *c5 = new TCanvas("c5", "VPT_gainqe_EEp", 0, 0, 900, 700);
	c5->cd();
	VPT_gainqe_EEp->Draw("COLZ");
	//Util::PrintNoEPS(c5, VPT_gainqe_EEp->GetTitle(), outputdir);
	Util::PrintEPS(c5, VPT_gainqe_EEp->GetTitle(), outputdir);
	TCanvas *c6 = new TCanvas("c6", "VPT_gainqe_EEm", 0, 0, 900, 700);
	c6->cd();
	VPT_gainqe_EEm->Draw("COLZ");
	//Util::PrintNoEPS(c6, VPT_gainqe_EEm->GetTitle(), outputdir);
	Util::PrintEPS(c6, VPT_gainqe_EEm->GetTitle(), outputdir);
	TCanvas *c7 = new TCanvas("c7", "VPT_gain_EEp", 0, 0, 900, 700);
	c7->cd();
	VPT_gain_EEp->Draw("COLZ");
	//Util::PrintNoEPS(c7, VPT_gain_EEp->GetTitle(), outputdir);
	Util::PrintEPS(c7, VPT_gain_EEp->GetTitle(), outputdir);
	TCanvas *c8 = new TCanvas("c8", "VPT_gain_EEm", 0, 0, 900, 700);
	c8->cd();
	VPT_gain_EEm->Draw("COLZ");
	//Util::PrintNoEPS(c8, VPT_gain_EEm->GetTitle(), outputdir);
	Util::PrintEPS(c8, VPT_gain_EEm->GetTitle(), outputdir);
	TCanvas *c9 = new TCanvas("c9", "VPT_qe_EEp", 0, 0, 900, 700);
	c9->cd();
	VPT_qe_EEp->Draw("COLZ");
	//Util::PrintNoEPS(c9, VPT_qe_EEp->GetTitle(), outputdir);
	Util::PrintEPS(c9, VPT_qe_EEp->GetTitle(), outputdir);
	TCanvas *c0 = new TCanvas("c0", "VPT_qe_EEm", 0, 0, 900, 700);
	c0->cd();
	VPT_qe_EEp->Draw("COLZ");
	//Util::PrintNoEPS(c0, VPT_qe_EEm->GetTitle(), outputdir);
	Util::PrintEPS(c0, VPT_qe_EEm->GetTitle(), outputdir);
//	c4->Clear();
	
	outf			->cd();
	mu_ECAL_EEp_russ	->Write();
	mu_ECAL_EEp_chin	->Write();
	mu_ECAL_EEm_russ	->Write();
	mu_ECAL_EEm_chin	->Write();
	mu_SIC_EEp_russ		->Write();
	mu_SIC_EEp_chin		->Write();
	mu_SIC_EEm_russ		->Write();
	mu_SIC_EEm_chin		->Write();
	EEp_producer		->Write();
	EEm_producer		->Write();
	mu_std_EEp		->Write();
	mu_std_EEm		->Write();
	mu_SIC_EEp		->Write();
	mu_SIC_EEm		->Write();
	VPT_gainqe_EEp		->Write();
	VPT_gainqe_EEm		->Write();
	VPT_gain_EEp		->Write();
	VPT_gain_EEm		->Write();
	VPT_qe_EEp		->Write();
	VPT_qe_EEm		->Write();
	cout << "saved histograms in: " << outf->GetName() << endl;
	outf->Close();

	PlotEtaProfile();

} 
예제 #30
0
//  -------------------------------------------------------------------------
//
//   ----- General Macro for R3B CALIFA Data Display
//         Author: Hector Alvarez <*****@*****.**>
//         Last Update: 26/09/14
//         Comments:
//         THAT IS A TEMPLATE FOR OTHER DISPLAY/ANALYSIS MACRO. COPY AND USE.
//         CAN DISPLAY RAWHITs OR CRYSTALHITs 
//	
//  -------------------------------------------------------------------------
//
//   Usage: 
//      > root -l 
//      ROOT> .L plot.C
//      ROOT> plot("inputFile")
//     
//     where inputFile is the input file :) 
//     Define histograms and fill them in the loop!
//  -------------------------------------------------------------------------
void plot(TString inputFile="") {

  gROOT->SetStyle("Default");
  //gStyle->SetOptTitle(0);
  gStyle->SetOptStat(0);
  gStyle->SetOptFit(0);
  
  TFile *file1 = TFile::Open(inputFile);
  
  //HISTOGRAMS DEFINITION
  TH1F* hEnergy = new TH1F("hEnergy","Energy",1000,0,2000);
  TH2F* hEnergyvsID = new TH2F("hEnergyvsID","EnergyvsID",500,0,2500,128,0,127);
  TH2F* hTimevsID = new TH2F("hTimevsID","TimevsID",500,1450000000000,1460000000000,128,0,127);
  TH2F* hEnergyvsTime = new TH2F("hEnergyvsTime","EnergyvsTime",500,0,2500,500,1450000000000,1650000000000);



  TTree* caloTree = (TTree*)file1->Get("cbmsim");
 
  //Raw Hits (input)
  TClonesArray* rawHitCA;  
  R3BCaloRawHit** rawHit;
  rawHitCA = new TClonesArray("R3BCaloRawHit",5);
  TBranch *branchRawHit = caloTree->GetBranch("CaloRawHit");
  if(branchRawHit) branchRawHit->SetAddress(&rawHitCA);
  
  //Crystal Hits
  TClonesArray* crystalHitCA;  
  R3BCaloCrystalHit** crystalHit;
  crystalHitCA = new TClonesArray("R3BCaloCrystalHit",5);
  TBranch *branchCrystalHit = caloTree->GetBranch("CaloCrystalHit");
  if(branchCrystalHit) branchCrystalHit->SetAddress(&crystalHitCA);
  
  Long64_t nevents = caloTree->GetEntries();
  Int_t rawHitsPerEvent =0;
  Int_t crystalHitsPerEvent =0;
  
  for(Int_t i=0;i<nevents;i++){
    if(i%100000 == 0) printf("Event:%i\n",i);
    
    rawHitCA->Clear();
    crystalHitCA->Clear();

    caloTree->GetEvent(i);
    rawHitsPerEvent = rawHitCA->GetEntries(); 
    crystalHitsPerEvent = crystalHitCA->GetEntries(); 
    
    if(rawHitsPerEvent>0) {
      rawHit = new R3BCaloRawHit*[rawHitsPerEvent];
      for(Int_t j=0;j<rawHitsPerEvent;j++){
	//rawHit[j] = new R3BCaloRawHit;
	rawHit[j] = (R3BCaloRawHit*) rawHitCA->At(j);      
      }
    }
    if(crystalHitsPerEvent>0) {
      crystalHit = new R3BCaloCrystalHit*[crystalHitsPerEvent];
      for(Int_t j=0;j<crystalHitsPerEvent;j++){
	//crystalHit[j] = new R3BCaloCrystalHit;
	crystalHit[j] = (R3BCaloCrystalHit*) crystalHitCA->At(j);      
      }
    }
    
    //filling info
    if(rawHitsPerEvent>0) {
      for(Int_t h=0;h<rawHitsPerEvent;h++){
	hEnergy->Fill(rawHit[h]->GetEnergy());
	hEnergyvsID->Fill(rawHit[h]->GetEnergy(),rawHit[h]->GetCrystalId());
	hTimevsID->Fill(rawHit[h]->GetTime(),rawHit[h]->GetCrystalId());
	hEnergyvsTime->Fill(rawHit[h]->GetEnergy(),rawHit[h]->GetTime());
      }
    }    
    if(crystalHitsPerEvent>0) {
      for(Int_t h=0;h<crystalHitsPerEvent;h++){
	hEnergy->Fill(crystalHit[h]->GetEnergy());
      }
    }  

    
    if(rawHitsPerEvent) delete [] rawHit;
    if(crystalHitsPerEvent) delete [] crystalHit;
    
  }
  
  TCanvas* c1 = new TCanvas("Info","Info",0,0,780,1200);
	c1->SetFillColor(0);
	c1->SetFrameFillColor(0);
	c1->Divide(2,2);
	//MC TRACK CANVAS
	c1->cd(1);
	hEnergy->Draw();
	c1->cd(2);
	hEnergyvsID->Draw("COLZ");
	c1->cd(3);
	hEnergyvsTime->Draw("COLZ");
	c1->cd(4);
	hTimevsID->Draw("COLZ");
}