コード例 #1
0
double singlePointLimit(std::string filename, float tanb, unsigned int LIMIT_TYPE, unsigned int verbosity=0)
{
  /*
    Get the observed, expected and +/-1 ans +/-2 sigma band from limit trees, which are the 
    output of combine
  */
  TString fullpath; fullpath = TString::Format(filename.c_str(), tanb); TFile* file = new TFile(fullpath); 
  if(file->IsZombie()){ if( verbosity>0 ){ std::cout << "> File not found: " << fullpath << std::endl; } return -999.; }
  TTree* tree = (TTree*) file->Get("limit");
  if(!tree){ if( verbosity>0 ){ std::cout << "> Tree not found in file: " << fullpath << std::endl; } return -999.; }
  int nevent = tree->GetEntries();
  if( nevent<=0 ){ if( verbosity>0 ){ std::cout << "> Tree is empty" << std::endl; } return -999.; }

  float type; double value;
  tree->SetBranchAddress("quantileExpected", &type );
  tree->SetBranchAddress("limit"           , &value);
  float target = LimitTypes[LIMIT_TYPE]; double limit = -999;
  for(int idx=0; idx<nevent; ++idx){
    tree->GetEvent(idx);
    if( fabs(type-target)<0.001 ){
      // allow for some tolerance for determination of type
      if( verbosity>1 ){ std::cout << "tanb: " << tanb << " limit (" << limitType(LIMIT_TYPE) << ") = " << value/tanb << " Undivided limit = " << value << std::endl; }
      limit = value/tanb; 
    }
  }
  file->Close();
  return limit;
}
コード例 #2
0
ファイル: muon_rate.C プロジェクト: watchboydetector/watchboy
void muon_rate(std::string fname)
{
  TFile* file=new TFile(fname.c_str());
  TTree* tree =(TTree*)file->Get("data");
  unsigned long long time=0;
  double target_total, veto_total, target_cb, veto_cb;
  tree->SetBranchAddress("time", &time);
  tree->SetBranchAddress("target_total", &target_total);
  tree->SetBranchAddress("veto_total", &veto_total);
  tree->SetBranchAddress("target_cb", &target_cb);
  tree->SetBranchAddress("veto_cb", &veto_cb);

  unsigned long long tlast=0;
  unsigned int entries = tree->GetEntries();
  double adc2us = 4/1000.0;

  TH1F* timing=new TH1F("timing", "timing", 100, 0, 5000);

  for(int i=0; i<entries; i++)
  {
    tree->GetEvent(i);
    if( target_cb < 0.8 && target_total > 1000 )
    {
      timing->Fill(double(time-tlast)*adc2us);
      tlast = time;
    }
  }

  timing->Draw();
}
コード例 #3
0
ファイル: checkDoublecounts.C プロジェクト: frmeier/usercode
void checkDoublecounts(string filename)
{
    // data
    TFile *f = TFile::Open(filename.c_str());
    if (f==0)
    {
	cout << "Problem: File \"" << filename << "\" not found. Exiting..." << endl;
    }
    TTree *tree = (TTree*)f->Get("genevents");
    if (tree==0)
    {
	cout << "Unable to get tree from file. Exitng..." << endl;
    }
    int run, ls, event;
    tree->SetBranchAddress("run",&run);
    tree->SetBranchAddress("LS",&ls);
    tree->SetBranchAddress("event",&event);
    const int nEvents = tree->GetEntries();
    std::map<runlsevent,int> eventmap;
    for (int i = 0; i!=nEvents; i++)
    {
	tree->GetEvent(i);
	eventmap[runlsevent(run,ls,event)]++;
    }
    cout << "nEvents: " << nEvents << " Mapsize: " << eventmap.size() << endl;
    if (nEvents == eventmap.size()) cout << "No doublecounts found" << endl;
    else cout << "OOOOPS!!!! There must be some doublecounts." << endl;
}
コード例 #4
0
ファイル: AliTPCTestMerge.C プロジェクト: alisw/AliRoot
void drawmerged(Int_t sec, Int_t row, Int_t x1=-1, Int_t x2=-1, Int_t y1=-1, Int_t y2=-1)
{
  /// if you think that there is memory leak -
  /// you are tru but othervise graphic doesn't work
  /// sec=0; row =0;

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

  TCanvas * c = new TCanvas(" Test merged digits", "test",600,900);
  c->Divide(1,3);
  //
  c->cd(1);
  AliH2F * his = dig->DrawDigits("cont1",x1,x2,y1,y2);
  his->SetTitle("MergedDigits");
  his->SetName("Merged Digits");
  his->GetXaxis()->SetTitle("time");
  his->GetYaxis()->SetTitle("pad");
  his->DrawClone("cont1");
  //
  c->cd(2);
  AliH2F * his1 =dig1->DrawDigits("cont1",x1,x2,y1,y2); 
  his1->SetTitle("background");
  his1->SetName("background");
  his1->GetXaxis()->SetTitle("time");
  his1->GetYaxis()->SetTitle("pad");
  his1->DrawClone("cont1"); 
  //
  c->cd(3);
  AliH2F * his2 =dig2->DrawDigits("cont1",x1,x2,y1,y2); 
  his2->SetTitle("signal");
  his2->SetName("signal");
  his2->GetXaxis()->SetTitle("time");
  his2->GetYaxis()->SetTitle("pad");
  his2->DrawClone("cont1");  
}
コード例 #5
0
ファイル: runstltest2.C プロジェクト: bbannier/roottest
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;
}
コード例 #6
0
void Write(bool write=false) 
{
   TFile *f    = new TFile("RootRelations.root", "RECREATE", "Root RootRelations test",0);
   TTree *tree = new TTree("T","An example of a ROOT tree");
   Relation1D<int,float>* obj = new Relation1D<int,float>();

   if (gDebug>0) {
      fprintf(stderr,"Relation1D<int,float> is %p\n",obj);
      fprintf(stderr,"DataObject is %p\n",(DataObject*)obj);
      fprintf(stderr,"Relation<int,float> is %p\n",(Relation<int,float>*)obj);
      fprintf(stderr,"m_direct is %p\n",&(obj->m_direct));
      fprintf(stderr,"m_direct.m_entries is %p\n",&(obj->m_direct.m_entries));
   }

   TBranch *b = tree->Branch("B", "Relation1D<int,float>", &obj);

   
   if (write) {
      
      printf("relations' write\n");
      for(int i=0; i < 10; ++i) {

         obj->m_direct.m_entries.push_back(std::pair<int,float>(10*i,i));
         DataTObject *dobj = new ( obj->m_direct.m_tentries[0] ) DataTObject(i*22,i*22/3.0);
         DataTObject *dobj2 = new ( (*(obj->m_direct.m_ptentries))[0] ) DataTObject(i*44,i*44/3.0);
	 if (!dobj || !dobj2) return;

         printf("byte written for entry   #%d: %d\n",i,tree->Fill());

         if (gDebug>0) {
            printf("byte re-read for the same entry: %d %p\n", tree->GetEvent(i), obj); 
         }
	 if (i<0) {
           fprintf(stderr,"the pointer are %p and %p\n",
                   dobj,obj->m_direct.m_tentries.At(0));
         }
         printf("values written for entry #%d: %d, %f, %d, %f, %d, %f\n", i,
                obj->m_direct.m_entries[0].first,
                obj->m_direct.m_entries[0].second,
                ((DataTObject*)obj->m_direct.m_tentries.At(0))->i,
                ((DataTObject*)obj->m_direct.m_tentries.At(0))->j,
                ((DataTObject*)obj->m_direct.m_ptentries->At(0))->i,
                ((DataTObject*)obj->m_direct.m_ptentries->At(0))->j
                ); 

         obj->m_direct.m_entries.clear();
         obj->m_direct.m_tentries.Clear();
      }
      b->Write();
      tree->Write();
      tree->Print();
      f->Write();
   }
   delete f;
};
コード例 #7
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;
}
コード例 #8
0
ファイル: spectraMaker.C プロジェクト: UCNA/ParallelAnalyzer
void spectraMaker(std::string file)
{
  Double_t fidCut = 50.;
  
  std::string filePath = "analyzed_files/"+file;

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

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

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

  UInt_t nevents = tin->GetEntriesFast();

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

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

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

  fin->Close();

  fout->Write();
  fout->Close();
}
コード例 #9
0
TH1* fillHistogram(TTree* testTree, const std::string& varName, const std::string& selection, const std::string& frWeightName,
		   const std::string& histogramName, unsigned numBinsX, double xMin, double xMax)
{
  std::cout << "<fillHistogram>:" << std::endl;
  std::cout << " testTree = " << testTree << std::endl;
  std::cout << " varName = " << varName << std::endl;
  std::cout << " selection = " << selection << std::endl;
  std::cout << " frWeightName = " << frWeightName << std::endl;
  std::cout << " histogramName = " << histogramName << std::endl;

  TH1* histogram = new TH1F(histogramName.data(), histogramName.data(), numBinsX, xMin, xMax);
  histogram->Sumw2();

  TFile* dummyOutputFile = new TFile("dummyOutputFile.root", "RECREATE");

  TTree* selTree = ( selection != "" ) ? testTree->CopyTree(selection.data()) : testTree;
  std::cout << " selTree = " << selTree << std::endl;

  Float_t eventWeight = 1.;
  selTree->SetBranchAddress("weight", &eventWeight);

  Float_t var = 0.;
  selTree->SetBranchAddress(varName.data(), &var);
  
  Float_t frWeight = 1.;
  if ( frWeightName != "" ) {
    std::cout << "--> setting branch-address of fake-rate weight..." << std::endl;
    selTree->SetBranchAddress(frWeightName.data(), &frWeight);
  }

  int numEntries = selTree->GetEntries();
  std::cout << "--> numEntries = " << numEntries << std::endl;
  //if ( maxEntriesToProcess != -1 ) numEntries = TMath::Min(numEntries, maxEntriesToProcess);
  for ( int iEntry = 0 ; iEntry < numEntries; ++iEntry ) {
    selTree->GetEvent(iEntry);  

    //std::cout << "iEntry = " << iEntry << ": var = " << var << ", frWeight = " << frWeight << std::endl;

    if ( frWeightName != "" ) {
      if ( TMath::Abs(frWeight) < 1. ) // some entries have weight O(-100)
                                       // --> indication of technical problem with k-NearestNeighbour tree ?
	histogram->Fill(var, frWeight*eventWeight);
    } else {
      histogram->Fill(var, eventWeight);
    }
  }

  delete dummyOutputFile;

  return histogram;
}
コード例 #10
0
ファイル: ProtonCounting.C プロジェクト: alcap-org/g4sim
// This ROOT macro counts the number of protons that stop in the thick silicon detectors
void ProtonCounting(std::string filename) {

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

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

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

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

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

    tree->GetEvent(iEntry);

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

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

  std::cout << "There were " << n_protons << " protons that reached the thick silicon detectors out of " << n_stopped_muons << " stopped muons (" << tree->GetEntries() << " input muons." << std::endl;
  std::cout << "N_right = " << n_protons_right << ", N_left = " << n_protons_left << std::endl;
  std::cout << "Acceptance = " << (double) n_protons / n_stopped_muons << std::endl;
}
コード例 #11
0
void getGen(const std::string& genNtupleFileName, int run, int ls, int event, Float_t& genX1, Float_t& genX2, Float_t& genPt, Float_t& genEta, Float_t& genPhi, Float_t& genMass)
{
  TFile* genNtupleFile = new TFile(genNtupleFileName.data());
  std::string genNtupleName = "neuralMtautauNtupleProducer/neuralMtautauNtuple";
  TTree* genNtuple = dynamic_cast<TTree*>(genNtupleFile->Get(genNtupleName.data()));
  if ( !genNtuple ) {
    std::cerr << "Failed to find tree with name = " << genNtupleName << " in file = " << genNtupleFileName << " --> aborting !!" << std::endl;
    assert(0);
  }

  Float_t genNtuple_X1, genNtuple_X2, genNtuple_pt, genNtuple_eta, genNtuple_phi, genNtuple_mass;
  genNtuple->SetBranchAddress("genX1", &genNtuple_X1);
  genNtuple->SetBranchAddress("genX2", &genNtuple_X2);
  genNtuple->SetBranchAddress("genDiTauPt", &genNtuple_pt);
  genNtuple->SetBranchAddress("genDiTauEta", &genNtuple_eta);
  genNtuple->SetBranchAddress("genDiTauPhi", &genNtuple_phi);
  genNtuple->SetBranchAddress("genMtautau", &genNtuple_mass);
  
  ULong64_t genNtuple_run, genNtuple_ls, genNtuple_event;
  genNtuple->SetBranchAddress("run", &genNtuple_run);
  genNtuple->SetBranchAddress("lumisection", &genNtuple_ls);
  genNtuple->SetBranchAddress("event", &genNtuple_event);
    
  bool isFound = false;

  int numEvents = genNtuple->GetEntries();
  std::cout << "numEvents = " << numEvents << std::endl;
  for ( int iEvent = 0; iEvent < numEvents; ++iEvent ) {
    genNtuple->GetEvent(iEvent);
    std::cout << "run " << genNtuple_run << ", ls = " << genNtuple_ls << ", event " << genNtuple_event << std::endl;
    if ( genNtuple_run == run && genNtuple_ls == ls && genNtuple_event == event ) {
      genX1   = genNtuple_X1;
      genX2   = genNtuple_X2;
      genPt   = genNtuple_pt;
      genEta  = genNtuple_eta;
      genPhi  = genNtuple_phi;
      genMass = genNtuple_mass;
      isFound = true;
    }
  }

  if ( !isFound ) {
    std::cerr << "Failed to find run# " << run << ", #ls " << ls << ", #event " << event << " in file = " << genNtupleFileName << " --> aborting !!" << std::endl;
    assert(0);
  }

  delete genNtupleFile;
}
コード例 #12
0
void ReadAOD(const char *fileName = "IlcAOD.root") {

  // open input file and get the TTree
  TFile inFile(fileName, "READ");
  if (!inFile.IsOpen()) return;

  TTree *aodTree = (TTree*)inFile.Get("aodTree");

  IlcAODEvent *ev = new IlcAODEvent();
  ev->ReadFromTree(aodTree);

  // loop over events
  Int_t nEvents = aodTree->GetEntries();
  for (Int_t nEv = 0; nEv < nEvents; nEv++) {
    cout << "Event: " << nEv+1 << "/" << nEvents << endl;

    // read events
    aodTree->GetEvent(nEv);

    //print event info
    ev->GetHeader()->Print();

    // loop over tracks
    Int_t nTracks = ev->GetNTracks();
    for (Int_t nTr = 0; nTr < nTracks; nTr++) {
      
      IlcAODTrack *tr = ev->GetTrack(nTr);

      // print track info
      cout << nTr+1 << "/" << nTracks << ": track pt: " << tr->Pt();
      if (tr->GetProdVertex()) {
	cout << ", vertex z of this track: " << tr->GetProdVertex()->GetZ();
      }
      cout << endl;
    }

    // loop over vertices
    Int_t nVtxs = ev->GetNVertices();
    for (Int_t nVtx = 0; nVtx < nVtxs; nVtx++) {
      
      // print track info
      cout << nVtx+1 << "/" << nVtxs << ": vertex z position: " << ev->GetVertex(nVtx)->GetZ() << endl;
    }
  }
  
  return;
}
コード例 #13
0
ファイル: AliPMDesdanal.C プロジェクト: alisw/AliRoot
Int_t AliPMDesdanal() { 
   TStopwatch timer;

   gStyle->SetOptStat(111110);
   gStyle->SetOptFit(1);

//****** File with the ESD
   TFile *ef=TFile::Open("AliESDs.root");
   if (!ef || !ef->IsOpen()) {cerr<<"Can't AliESDs.root !\n"; return 1;}
   AliESDEvent * event = new AliESDEvent;
   TTree* tree = (TTree*) ef->Get("esdTree");
   if (!tree) {cerr<<"no ESD tree found\n"; return 1;};
   event->ReadFromTree(tree);
   Int_t n=0;

//******* The loop over events
   while (tree->GetEvent(n)) {
     cout<<endl<<"Processing event number : "<<n++<<endl;


     Int_t npmdcl=event->GetNumberOfPmdTracks();
     cout<<"Number of PMD tracks : "<<npmdcl<<endl; 

     //****** The loop over PMD clusters
     while (npmdcl--) {
       AliESDPmdTrack *pmdtr = event->GetPmdTrack(npmdcl);
       
       Int_t   det   = pmdtr->GetDetector(); 
       Float_t clsX  = pmdtr->GetClusterX();
       Float_t clsY  = pmdtr->GetClusterY();
       Float_t clsZ  = pmdtr->GetClusterZ();
       Float_t ncell = pmdtr->GetClusterCells();
       Float_t adc   = pmdtr->GetClusterADC();
       Float_t pid   = pmdtr->GetClusterPID();
       
     }
   }

   delete event;

   timer.Stop();
   timer.Print();

   return 0;
}
コード例 #14
0
ファイル: AliTPCTestMerge.C プロジェクト: alisw/AliRoot
void test3(){
  /// test of the merged digits

  TFile f("galice.root");
  TFile f1("ev1/galice.root.sdigits");
  TFile f2("ev2/galice.root.sdigits");
  TTree * tree = (TTree*)f.Get("TreeD_75x40_100x60_150x60_0");
  TTree * tree1 = (TTree*)f1.Get("TreeS_75x40_100x60_150x60_0");
  TTree * tree2 = (TTree*)f2.Get("TreeS_75x40_100x60_150x60_0");
  //
  AliSimDigits *dig=0;
  AliSimDigits *dig1=0;
  AliSimDigits *dig2=0;
  //  
  tree->GetBranch("Segment")->SetAddress(&dig);
  tree1->GetBranch("Segment")->SetAddress(&dig1);
  tree2->GetBranch("Segment")->SetAddress(&dig2);
  //
  for (Int_t i=0;i<6000;i++){
    tree->GetEvent(i);
    tree1->GetEvent(i);
    tree2->GetEvent(i);
    if ( (dig1->GetID()!=i) || (dig2->GetID()!=i) ) {
      printf("missed segments\n");
    }
    //
    dig->ExpandBuffer();
    dig1->ExpandBuffer();
    dig2->ExpandBuffer();
    //
    Int_t nrows = dig->GetNRows();
    Int_t ncols = dig->GetNCols();
    //
    for (Int_t rows=0;rows<nrows; rows++)
      for (Int_t col=0;col<ncols; col++){
	Int_t d  = dig->GetDigitFast(rows,col);
	Int_t d1 = dig1->GetDigitFast(rows,col)/16;
	Int_t d2 = dig2->GetDigitFast(rows,col)/16;	
	if (abs(d-d1-d2)>4)
	//if (d2>5)
	  printf("%d\t%d\t%d\t%d\t%d\t%d\n",i,rows,col,d,d1,d2);
      }
  }
}
コード例 #15
0
ファイル: AliTPCTestMerge.C プロジェクト: alisw/AliRoot
void test5(){
  /// compare merged digits with digits obtained hits2sdig->sdigtodig

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

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




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

    for (Int_t rows=0;rows<nrows; rows++)
      for (Int_t col=0;col<ncols; col++){
	Int_t d  = dig->GetDigitFast(rows,col);
	Int_t d1 = dig1->GetDigitFast(rows,col);
	Int_t d2 = dig2->GetDigitFast(rows,col);
	
	if (abs(d-d1-d2)>4)
	//if (d2>5)
	  printf("%d\t%d\t%d\t%d\t%d\t%d\n",i,rows,col,d,d1,d2);
      }
  }
}
コード例 #16
0
ファイル: AliTPCTestMerge.C プロジェクト: alisw/AliRoot
void drawd(TFile * f, Int_t amp1, Int_t amp2)
{
  TTree * tree = (TTree*)f->Get("TreeD_75x40_100x60_150x60_0");
  AliSimDigits *dig=0;
  tree->GetBranch("Segment")->SetAddress(&dig); 
  TH1F * his = new TH1F("his","his",amp2-amp1,amp1,amp2);
  for (Int_t i=0;i<60;i++){  
    tree->GetEvent(i);   
    dig->ExpandBuffer();
    Int_t nrows = dig->GetNRows();
    Int_t ncols = dig->GetNCols();
    for (Int_t rows=0;rows<nrows; rows++)
      for (Int_t col=0;col<ncols; col++){    
	Int_t d  = dig->GetDigitFast(rows,col);
	his->Fill(d);
      }
  }
  his->Draw();
}
コード例 #17
0
ファイル: JansEvent.C プロジェクト: asmagina1995/roottest
void testJan() {
  {
    B_Parameters *b = new B_Parameters;
    //TObject *o = b;
    //CandidateParameters *c = b;
    //std::cout << (void*)b << " : " << (void*)c << " and " << (void*)o << endl;
    std::cout << b->gamma.minTrackDTheta << std::endl;
    std::cout << b->gamma.uid << std::endl;
    std::cout << b->gamma.GetName() << std::endl;
  }
  TFile* f = new TFile("janbug.root");
  TTree* t; f->GetObject("evtTree2",t);
  JansEvent* j = new JansEvent();
  t->SetBranchAddress("event", &j);
  t->GetEvent(0);
  std::cout << j->bList.GetEntries() << std::endl;
  B_Parameters *b = dynamic_cast<B_Parameters*>(j->bList[0]);
  //std::cout << (void*)j->bList[0] << " vs " << (void*)b << endl;
  std::cout << b->gamma.minTrackDTheta << std::endl;
  std::cout << b->gamma.uid << std::endl;
  std::cout << b->gamma.GetName() << std::endl;
}
コード例 #18
0
void PileUpMaker() {
  // Access data file
  TFile *file = TFile::Open("ZmumuGammaNtuple_Full2012_MuCorr.root");
  TTree *Datatree = (TTree*)file->Get("ZmumuGammaEvent");

  // Set up histogram for data pile up
  TH1F *pileupraw = new TH1F("pileup","",40,0,80);
 
  // Fill pile up distribution
  Int_t nentries = Datatree->GetEntriesFast();
  Int_t nbytes = 0; 
  for (Int_t i=0; i<nentries;i++) {
    nbytes += Datatree->GetEvent(i);
    UInt_t NVertices;
    Datatree->SetBranchAddress("NVertices",&NVertices);
    pileupraw->Fill(float(NVertices)/0.7);
  }

  // Normalize the distribution
  TH1F* PU = (TH1F*)pileupraw->Clone("pileup");
  PU->Scale(1./PU->Integral());

  // Plot both the normalized and unnormalized pile up
  TCanvas *cv = 0;
  cv= new TCanvas("cv","cv",800, 600);
  pileupraw->Draw("");
  cv->SaveAs("DataPU.pdf");

  cv= new TCanvas("cv","cv",800,600);
  PU->Draw("");
  cv->SaveAs("DataPU_normalized.pdf");

  // Save the normalized distribution to a root file for weighting MC
  TFile *file = TFile::Open("2012_PhosphorData_PileUp.root","UPDATE");
  file->cd();
  file->WriteTObject(PU,PU->GetName(),"WriteDelete");
  file->Close();
  delete file;
}
コード例 #19
0
ファイル: make_text.cpp プロジェクト: VitalyVorobyev/B0toD0h0
void make_text(char* ifile,char* ofile){
  TFile file(ifile);
  TTree* tree = (TTree*)file.Get("TEvent");
  const int NTot = tree->GetEntries();
  cout << NTot << " event detected" << endl;
  
  Int_t exp, run, evt;
  Int_t b0f, d0f;
  Double_t bdtg;
  Int_t bin, mc_bin;
  Int_t mc_flv;
  Double_t tag_LH;
  Double_t vt_mc_rec, vt_mc_asc, mc_delta_t;
  Double_t vt_pos_rec, vt_err_rec;
  Int_t vt_ntrk_rec;
  Double_t vt_chi2_rec;
  Int_t vt_ndf_rec;
  Double_t vt_pos_asc, vt_err_asc;
  Int_t vt_ntrk_asc;
  Double_t vt_chi2_asc;
  Int_t vt_ndf_asc;
  Double_t deltae, mbc, costh;
  Int_t nptag;

  tree->SetBranchAddress("exp",&exp);
  tree->SetBranchAddress("run",&run);
  tree->SetBranchAddress("evtn",&evt);
  tree->SetBranchAddress("b0f",&b0f);
  tree->SetBranchAddress("d0f",&d0f);
  tree->SetBranchAddress("bdtgsl",&bdtg);
  tree->SetBranchAddress("bin",&bin);
//  tree->SetBranchAddress("bin_mc",&mc_bin);
//  tree->SetBranchAddress("mc_flv",&mc_flv);
  tree->SetBranchAddress("tag_LH",&tag_LH);
//  tree->SetBranchAddress("z_sig_mc",&vt_mc_rec);
//  tree->SetBranchAddress("z_asc_mc",&vt_mc_asc);
  tree->SetBranchAddress("z_sig",&vt_pos_rec);
  tree->SetBranchAddress("sz_sig",&vt_err_rec);
  tree->SetBranchAddress("ntrk_sig",&vt_ntrk_rec);
  tree->SetBranchAddress("chisq_z_sig",&vt_chi2_rec);
  tree->SetBranchAddress("ndf_z_sig",&vt_ndf_rec);
  tree->SetBranchAddress("z_asc",&vt_pos_asc);
  tree->SetBranchAddress("sz_asc",&vt_err_asc);
  tree->SetBranchAddress("ntrk_asc",&vt_ntrk_asc);
  tree->SetBranchAddress("chisq_z_asc",&vt_chi2_asc);
  tree->SetBranchAddress("ndf_z_asc",&vt_ndf_asc);
  tree->SetBranchAddress("de",&deltae);
  tree->SetBranchAddress("mbc",&mbc);
  tree->SetBranchAddress("costhBcms",&costh);
  tree->SetBranchAddress("nptag",&nptag);

  ofstream output(ofile);
  for(int i=0; i<NTot; i++){
    if(!(i%10000)) cout << i << " events" << endl;
    tree->GetEvent(i);
    output << exp << " ";
    output << run << " ";
    output << evt << " ";
    output << b0f << " ";
    output << d0f << " ";
    output << bdtg << " ";
    output << bin << " ";
//    output << mc_bin << " ";
//    output << mc_flv << " ";
    output << tag_LH << " ";
//    output << vt_mc_rec << " ";
//    output << vt_mc_asc << " ";
    output << vt_pos_rec << " ";
    output << vt_err_rec << " ";
    output << vt_ntrk_rec << " ";
    output << vt_chi2_rec << " ";
    output << vt_ndf_rec << " ";
    output << vt_pos_asc << " ";
    output << vt_err_asc << " ";
    output << vt_ntrk_asc << " ";
    output << vt_chi2_asc << " ";
    output << vt_ndf_asc << " ";
    output << deltae << " ";
    output << mbc << " ";
    output << costh << " ";
    output << nptag;
    output << endl;
  }
  return;  
}
コード例 #20
0
void fitSignalShapeW(int massBin,int id, int channels,int categ, int sample, 
		     /* float lumi, bool doSfLepton, */double rangeLow, double rangeHigh,
		     double bwSigma,
		     double fitValues[9], double fitErrors[9], double covQual[1]){
 // ------ root settings ---------
  gROOT->Reset();  
  gROOT->SetStyle("Plain");
  gStyle->SetPadGridX(kFALSE);
  gStyle->SetPadGridY(kFALSE);
  //gStyle->SetOptStat("kKsSiourRmMen");
  gStyle->SetOptStat("iourme");
  //gStyle->SetOptStat("rme");
  //gStyle->SetOptStat("");
  gStyle->SetOptFit(11);
  gStyle->SetPadLeftMargin(0.14);
  gStyle->SetPadRightMargin(0.06);
  // ------------------------------ 

  ROOT::Math::MinimizerOptions::SetDefaultTolerance( 1.E-7);

  stringstream FileName;
  //Insert the file here
  if(sample==1) FileName <<"root://lxcms03//data3/Higgs/150915/ZH125/ZZ4lAnalysis.root" ;
  else if(sample==2) FileName << "root://lxcms03//data3/Higgs/150915/WplusH125/ZZ4lAnalysis.root";
  else if(sample==3) FileName << "root://lxcms03//data3/Higgs/150915/WminusH125/ZZ4lAnalysis.root";
  else if(sample==4) FileName << "root://lxcms03//data3/Higgs/150915/ttH125/ZZ4lAnalysis.root";
  else {
    cout << "Wrong sample." << endl;
    return;
  }
    

  cout << "Using " << FileName.str() << endl;
  
 
  TFile* ggFile = TFile::Open(FileName.str().c_str()); 

  TTree* ggTree = (TTree*) ggFile->Get("ZZTree/candTree");

  float m4l;
  
  Short_t z1flav, z2flav; 
  float weight;

  Short_t nExtraLeptons;   
  float ZZPt;
  Short_t nJets;
  Short_t nBTaggedJets;
  std::vector<float> * jetpt = 0;
  std::vector<float> * jeteta = 0;
  std::vector<float> * jetphi = 0;
  std::vector<float> * jetmass = 0;
  float jet30pt[10];
  float jet30eta[10];
  float jet30phi[10];
  float jet30mass[10];
  float Fisher;
  
  int  nentries = ggTree->GetEntries();
 
  //--- ggTree part
  ggTree->SetBranchAddress("ZZMass",&m4l);
  ggTree->SetBranchAddress("Z1Flav",&z1flav);
  ggTree->SetBranchAddress("Z2Flav",&z2flav);
  ggTree->SetBranchAddress("genHEPMCweight",&weight);
  ggTree->SetBranchAddress("nExtraLep",&nExtraLeptons);
  ggTree->SetBranchAddress("nCleanedJets",&nJets);
  ggTree->SetBranchAddress("nCleanedJetsPt30BTagged",&nBTaggedJets);
  ggTree->SetBranchAddress("DiJetFisher",&Fisher);
  
  ggTree->SetBranchAddress("JetPt",&jetpt);
  ggTree->SetBranchAddress("JetEta",&jeteta);
  ggTree->SetBranchAddress("JetPhi",&jetphi);
  ggTree->SetBranchAddress("JetMass",&jetmass);
  ggTree->SetBranchAddress("ZZPt",&ZZPt);

  //--- rooFit part
  double xMin,xMax,xInit;
  xInit = (double) massBin;
  xMin = rangeLow;
  xMax = rangeHigh ;
  cout << "Fit range: [" << xMin << " , " << xMax << "]. Init value = " << xInit << endl;
  
  TH1F *hmass = new TH1F("hmass","hmass",200,xMin,xMax);
  //---------  
  RooRealVar x("mass","m_{4l}",xInit,xMin,xMax,"GeV");
  RooRealVar w("myW","myW",1.0,0.,1000.);
  RooArgSet ntupleVarSet(x,w);
  RooDataSet dataset("mass4l","mass4l",ntupleVarSet,WeightVar("myW"));

  for(int k=0; k<nentries; k++){
    ggTree->GetEvent(k);

    int njet30 = 0;
    for (unsigned int ijet = 0; ijet < jetpt->size(); ijet++) { 
      if ( (*jetpt)[ijet] > 30. ) {
	jet30pt[njet30] = (*jetpt)[ijet];      
	jet30eta[njet30] = (*jeteta)[ijet];
	jet30phi[njet30] = (*jetphi)[ijet];
	jet30mass[njet30] = (*jetmass)[ijet];
	njet30++;
      }
    }  
    int Cat = category(nExtraLeptons, ZZPt, m4l, njet30, nBTaggedJets, jet30pt, jet30eta, jet30phi,jet30mass, Fisher); 
    if (categ >= 0 && categ != Cat ) continue;

 
    if(channels==0 && z1flav*z2flav != 28561) continue;
    if(channels==1 && z1flav*z2flav != 14641) continue;
    if (weight <= 0 ) cout << "Warning! Negative weight events" << endl;
    if(channels==2 && z1flav*z2flav != 20449) continue;
    

    ntupleVarSet.setRealValue("mass",m4l);
    ntupleVarSet.setRealValue("myW",weight);
    if(x.getVal()>xMin && x.getVal()<xMax)
      dataset.add(ntupleVarSet, weight);
    hmass->Fill(m4l);

  }
  //---------

  cout << "dataset n entries: " << dataset.sumEntries() << endl;


  TCanvas *c1 = new TCanvas("c1","c1",725,725);


  c1->cd();

  TPad *pad1 = new TPad("pad1","This is pad1",0.05,0.35,0.95,0.97);
  pad1->Draw();
  TPad *pad2 = new TPad("pad2","This is pad2",0.05,0.02,0.95,0.35);
  pad2->Draw();

  //--- double CrystalBall
  RooRealVar mean("bias","mean of gaussian",0,-5.,5.) ;
  RooRealVar sigma("sigma","width of gaussian",1.5,0.,30.); 
  RooRealVar a1("a1","a1",1.46,0.5,5.);
  RooRealVar n1("n1","n1",1.92,0.,10.);   
  RooRealVar a2("a2","a2",1.46,1.,10.);
  RooRealVar n2("n2","n2",20,1.,50.);   
  RooDoubleCB DCBall("DCBall","Double Crystal ball",x,mean,sigma,a1,n1,a2,n2);
  if (channels== 1) mean.setVal(-1.);
  //--- Breit-Wigner
  float bwSigmaMax,bwSigmaMin;
  if(massBin<400) bwSigmaMin=bwSigmaMax=bwSigma;
  else { 
    bwSigmaMin=bwSigma-20.; 
    bwSigmaMax=bwSigma+20.; 
  }
  RooRealVar mean3("mean3","mean3",xInit) ;
  RooRealVar sigma3("sigma3","width3",bwSigma,bwSigmaMin,bwSigmaMax); 
  RooRealVar scale3("scale3","scale3 ",1.); 

  RooRelBWUFParam bw("bw","bw",x,mean3,scale3);
  //Chebyshev-Polynomial
  RooRealVar A1("A1","A1",-1,-3,3.);
  RooRealVar A2("A2","A2",0.5,-3.,3.);
  RooChebychev BkgPDF("BkgPDF","BkgPDF",x ,RooArgList(A1,A2));
  //Fraction
  RooRealVar frac("frac","Fraction for PDF",0.5,0.,1.);

  x.setBins(10000,"fft");
  RooFFTConvPdf model("model","model",x,bw,DCBall);
  

  RooAddPdf totPDF("totPDF","Total PDF ",RooArgList(model,BkgPDF),RooArgList(frac));
  
  RooArgSet* params = totPDF.getParameters(x);
  
  if(sample!=1 && categ!=0 && id!=125){
  if(channels==0 ){params->readFromFile("Ch0_Cat0_paraT.txt");}// Read the Parameter for the Resonance + Bkg(ChebyChev) 

  if(channels==1 ){params->readFromFile("Ch1_Cat0_paraT.txt");}// Read the Parameter for the Resonance + Bkg(ChebyChev)

  if(channels==2 ){params->readFromFile("Ch2_Cat0_paraT.txt");}//  Read the Parameter for the Resonance + Bkg(ChebyChev)
  }
  
  RooFitResult *fitres = (RooFitResult*)totPDF.fitTo(dataset,SumW2Error(1),Range(xMin,xMax),Strategy(2),NumCPU(8),Save(true));

  if (sample==1 && categ==0 && id==125){
 
  mean.setConstant(kTRUE);
  sigma.setConstant(kTRUE);
  a1.setConstant(kTRUE);
  n1.setConstant(kTRUE);
  a2.setConstant(kTRUE);
  n2.setConstant(kTRUE);
  mean3.setConstant(kTRUE);
  sigma3.setConstant(kTRUE);
  scale3.setConstant(kTRUE);
  A1.setConstant(kTRUE);
  A2.setConstant(kTRUE);
  frac.setConstant(kTRUE);

  if(channels==0 ){
  params->readFromFile("Ch0_Cat0_para.txt");  // Read the Parameter for the Resonance as ggH sample
  params->writeToFile("Ch0_Cat0_paraT.txt");} // Writing the Parameter for Full PDF including the Chebyshev-Polynomial

  if(channels==1 )
  {params->readFromFile("Ch1_Cat0_para.txt"); // Read the Parameter for the Resonance as in ggH sample
   params->writeToFile("Ch1_Cat0_paraT.txt");}// Writing the Parameter for Full PDF including the Chebyshev-Polynomial

  if(channels==2 ){
  params->readFromFile("Ch2_Cat0_para.txt"); // Read the Parameter for the Resonance as ggH sample
  params->writeToFile("Ch2_Cat0_paraT.txt");}// Writing the Parameter for Full PDF including the Chebyshev-Polynomial
  }
  
  stringstream frameTitle;
  if(channels==0){frameTitle << "4#mu, m_{H} = "; }
  if(channels==1){frameTitle << "4e, m_{H} = ";}
  if(channels==2){frameTitle << "2e2#mu, m_{H} = ";}
  frameTitle << massBin << " GeV";

  stringstream nameFileRoot;
  nameFileRoot << "fitM" << massBin << ".root";
  TFile *fileplot = TFile::Open(nameFileRoot.str().c_str(), "recreate");

  RooPlot* xframe = x.frame() ;
  xframe->SetTitle("");
  xframe->SetName("m4lplot");
  dataset.plotOn(xframe,DataError(RooAbsData::SumW2), MarkerStyle(kOpenCircle), MarkerSize(1.1) );
  int col;
  if(channels==0) col=kOrange+7;
  if(channels==1) col=kAzure+2;
  if(channels==2) col=kGreen+3;
  totPDF.plotOn(xframe,LineColor(col));


  RooHist* hpull = xframe->pullHist();

  RooPlot* frame3 = x.frame(Title("Pull Distribution")) ;
  frame3->addPlotable(hpull,"P");
  
  // cosmetics
  TLegend *legend = new TLegend(0.20,0.45,0.45,0.60,NULL,"brNDC");
  legend->SetBorderSize(0);
  legend->SetFillColor(0);
  legend->SetTextAlign(12);
  legend->SetTextFont (42);
  legend->SetTextSize (0.03);

  TH1F *dummyPoints = new TH1F("dummyP","dummyP",1,0,1);
  TH1F *dummyLine = new TH1F("dummyL","dummyL",1,0,1);
  dummyPoints->SetMarkerStyle(kOpenCircle);
  dummyPoints->SetMarkerSize(1.1);
  dummyLine->SetLineColor(col);
  
  legend->AddEntry(dummyPoints, "Simulation", "pe");
  legend->AddEntry(dummyLine, "Parametric Model", "l");
  
  TPaveText *text = new TPaveText(0.15,0.90,0.77,0.98,"brNDC");
  text->AddText("CMS Simulation");
  text->SetBorderSize(0);
  text->SetFillStyle(0);
  text->SetTextAlign(12);
  text->SetTextFont(42);
  text->SetTextSize(0.03);

  TPaveText *titlet = new TPaveText(0.15,0.80,0.60,0.85,"brNDC");
  titlet->AddText(frameTitle.str().c_str());
  titlet->SetBorderSize(0);
  titlet->SetFillStyle(0);
  titlet->SetTextAlign(12);
  titlet->SetTextFont(132);
  titlet->SetTextSize(0.045);

  TPaveText *sigmat = new TPaveText(0.15,0.65,0.77,0.78,"brNDC");
  stringstream sigmaval0, sigmaval1, sigmaval2;
  sigmaval0 << fixed;
  sigmaval0 << setprecision(1);
  sigmaval0 << "m_{dCB} = " << mean.getVal() + massBin << " GeV";
  sigmaval1 << fixed;
  sigmaval1 << setprecision(1);
  sigmaval1 << "#sigma_{dCB} = " << sigma.getVal() << " GeV";
  sigmaval2 << fixed;
  sigmaval2 << setprecision(1);
  sigmaval2 << "RMS_{eff} = " << effSigma(hmass) << " GeV";
  
  sigmat->AddText(sigmaval1.str().c_str());
  sigmat->AddText(sigmaval2.str().c_str());
  sigmat->SetBorderSize(0);
  sigmat->SetFillStyle(0);
  sigmat->SetTextAlign(12);
  sigmat->SetTextFont(132);
  sigmat->SetTextSize(0.04);
  
  xframe->GetYaxis()->SetTitleOffset(1.5);

  cout << "EFF RMS = " << effSigma(hmass) << "    RMS = " << hmass->GetRMS() << endl;

  pad1->cd();
  stringstream nameFile, nameFileC, nameFilePng;
  nameFile << "fitM" << massBin << "_channel" << channels<< "_category"<< categ << ".pdf";
  nameFileC << "fitM" << massBin << "_channel" << channels << "_category"<< categ << ".C";
  nameFilePng << "fitM" << massBin << "_channel" << channels << "_category"<< categ << ".png";

  xframe->Draw(); 
  gPad->Update(); legend->Draw(); text->Draw(); sigmat->Draw(); titlet->Draw();

  pad2->cd() ;
  frame3->Draw() ;
  frame3->SetMinimum(-3);
  frame3->SetMaximum(3);

  TLine *line1 = new TLine(105,0,140,0);
  line1->SetLineColor(kRed);
  line1->Draw();
  

  c1->Print(nameFile.str().c_str());
  c1->SaveAs(nameFileC.str().c_str());
  c1->SaveAs(nameFilePng.str().c_str());

  fileplot->cd();
  xframe->Write();
  sigmat->Write();
  hmass->Write();

  fileplot->Close();

  if(fitValues!=0){
    fitValues[0] = a1.getVal();
    fitValues[1] = a2.getVal();
    fitValues[2] = mean.getVal();
    fitValues[3] = mean3.getVal();
    fitValues[4] = n1.getVal();
    fitValues[5] = n2.getVal();
    fitValues[6] = sigma.getVal();
    fitValues[7] = A1.getVal();
    fitValues[8] = A2.getVal();

  }  

  if(fitErrors!=0){
    fitErrors[0] = a1.getError();
    fitErrors[1] = a2.getError();
    fitErrors[2] = mean.getError();
    fitErrors[3] = mean3.getError();
    fitErrors[4] = n1.getError();
    fitErrors[5] = n2.getError();
    fitErrors[6] = sigma.getError();
    fitErrors[7] = A1.getError();
    fitErrors[8] = A2.getError();

  }

  covQual[0] = fitres->covQual();
  
}
コード例 #21
0
void top_extractor_BNNBDT_EqTwoTag_EqThreeJet() {
    
    TFile *f = new TFile(source_file_path);
    
    TTree *t = (TTree *) f->Get("TopologicalVariables");

	Double_t Centrality_AllJets;		t->SetBranchAddress("Centrality_AllJets", &Centrality_AllJets);
	Double_t Cos_Jet1AllJets_AllJets; 	t->SetBranchAddress("Cos_Jet1AllJets_AllJets", &Cos_Jet1AllJets_AllJets);
	Double_t Cos_Jet1Lepton_Lab; 		t->SetBranchAddress("Cos_Jet1Lepton_Lab", &Cos_Jet1Lepton_Lab);
	Double_t Cos_Jet2AllJets_AllJets; 	t->SetBranchAddress("Cos_Jet2AllJets_AllJets", &Cos_Jet2AllJets_AllJets);
	Double_t Cos_Jet2Lepton_Lab; 		t->SetBranchAddress("Cos_Jet2Lepton_Lab", &Cos_Jet2Lepton_Lab);
	Double_t DeltaPhiJet1Jet2; 		t->SetBranchAddress("DeltaPhiJet1Jet2", &DeltaPhiJet1Jet2);
	Double_t DeltaPhiJet1MET; 		t->SetBranchAddress("DeltaPhiJet1MET", &DeltaPhiJet1MET);
	Double_t DeltaPhiJet2MET; 		t->SetBranchAddress("DeltaPhiJet2MET", &DeltaPhiJet2MET);
	Double_t DeltaPhiLeptonMET; 		t->SetBranchAddress("DeltaPhiLeptonMET", &DeltaPhiLeptonMET);
	Double_t DeltaRJet1Jet2; 		t->SetBranchAddress("DeltaRJet1Jet2", &DeltaRJet1Jet2);
	Double_t DeltaRMinLeptonJet; 		t->SetBranchAddress("DeltaRMinLeptonJet", &DeltaRMinLeptonJet);
	Double_t EventWeight; 			t->SetBranchAddress("EventWeight", &EventWeight);
	Double_t H_AllJets; 			t->SetBranchAddress("H_AllJets", &H_AllJets);
	Double_t H_Jet1Jet2; 			t->SetBranchAddress("H_Jet1Jet2", &H_Jet1Jet2);
	Double_t HT_AllJets; 			t->SetBranchAddress("HT_AllJets", &HT_AllJets);
	Double_t HT_AllJetsLeptonMET; 		t->SetBranchAddress("HT_AllJetsLeptonMET", &HT_AllJetsLeptonMET);
	Double_t HT_Jet1Jet2; 			t->SetBranchAddress("HT_Jet1Jet2", &HT_Jet1Jet2);
	Double_t HT_METlep; 			t->SetBranchAddress("HT_METlep", &HT_METlep);
	Double_t InstLumi; 			t->SetBranchAddress("InstLumi", &InstLumi);
	Double_t InvariantMass_AllJets; 	t->SetBranchAddress("InvariantMass_AllJets", &InvariantMass_AllJets);
	Double_t InvariantMass_Jet1Jet2; 	t->SetBranchAddress("InvariantMass_Jet1Jet2", &InvariantMass_Jet1Jet2);
	Double_t Jet1MuonPtRel; 		t->SetBranchAddress("Jet1MuonPtRel", &Jet1MuonPtRel);
	Double_t Jet2MuonPtRel; 		t->SetBranchAddress("Jet2MuonPtRel", &Jet2MuonPtRel);
	Double_t Jet3MuonPtRel; 		t->SetBranchAddress("Jet3MuonPtRel", &Jet3MuonPtRel);
	Double_t Jet4MuonPtRel; 		t->SetBranchAddress("Jet4MuonPtRel", &Jet4MuonPtRel);
	Double_t LeptonDCA; 			t->SetBranchAddress("LeptonDCA", &LeptonDCA);
	Double_t LeptonDCASig; 			t->SetBranchAddress("LeptonDCASig", &LeptonDCASig);
	Double_t LeptonDetEta; 			t->SetBranchAddress("LeptonDetEta", &LeptonDetEta);
	Double_t LeptonDetEtaCFT; 		t->SetBranchAddress("LeptonDetEtaCFT", &LeptonDetEtaCFT);
	Double_t LeptonE; 			t->SetBranchAddress("LeptonE", &LeptonE);
	Double_t LeptonEta; 			t->SetBranchAddress("LeptonEta", &LeptonEta);
	Double_t LeptonPhi; 			t->SetBranchAddress("LeptonPhi", &LeptonPhi);
	Double_t LeptonPt; 			t->SetBranchAddress("LeptonPt", &LeptonPt);
	Double_t METPhi; 			t->SetBranchAddress("METPhi", &METPhi);
	Double_t METPt; 			t->SetBranchAddress("METPt", &METPt);
	Double_t METPx; 			t->SetBranchAddress("METPx", &METPx);
	Double_t METPy; 			t->SetBranchAddress("METPy", &METPy);
	Double_t MetSig; 			t->SetBranchAddress("MetSig", &MetSig);
	Double_t Pt_Jet1Jet2; 			t->SetBranchAddress("Pt_Jet1Jet2", &Pt_Jet1Jet2);
	Double_t PVz; 				t->SetBranchAddress("PVz", &PVz);
	Double_t QTimesEta; 			t->SetBranchAddress("QTimesEta", &QTimesEta);
	Double_t weight_btag; 			t->SetBranchAddress("weight_btag", &weight_btag);
	Double_t weight_btagSF; 		t->SetBranchAddress("weight_btagSF", &weight_btagSF);
	Double_t weight_btagTaga; 		t->SetBranchAddress("weight_btagTaga", &weight_btagTaga);
	Double_t weight_Lumi; 			t->SetBranchAddress("weight_Lumi", &weight_Lumi);
	Double_t weight_Lumi2; 			t->SetBranchAddress("weight_Lumi2", &weight_Lumi2);
	Double_t weight_LeptonDetEta; 		t->SetBranchAddress("weight_LeptonDetEta", &weight_LeptonDetEta);
	Double_t weight_WPt; 			t->SetBranchAddress("weight_WPt", &weight_WPt);
	Double_t weight_VJets; 			t->SetBranchAddress("weight_VJets", &weight_VJets);
	Double_t weight_QCDshape; 		t->SetBranchAddress("weight_QCDshape", &weight_QCDshape);
	Double_t scale_HF; 			t->SetBranchAddress("scale_HF", &scale_HF);
	Double_t scale_MC; 			t->SetBranchAddress("scale_MC", &scale_MC);
	Double_t scale_MC2; 			t->SetBranchAddress("scale_MC2", &scale_MC2);
	Double_t scale_norm; 			t->SetBranchAddress("scale_norm", &scale_norm);
	Double_t weight_EMcorr; 		t->SetBranchAddress("weight_EMcorr", &weight_EMcorr);
	Double_t weight_Muon_ID; 		t->SetBranchAddress("weight_Muon_ID", &weight_Muon_ID);
	Double_t WPt; 				t->SetBranchAddress("WPt", &WPt);
	Double_t WTransverseMass; 		t->SetBranchAddress("WTransverseMass", &WTransverseMass);
	Double_t KS_LeptonPt; 			t->SetBranchAddress("KS_LeptonPt", &KS_LeptonPt);
	Double_t KS_METPt; 			t->SetBranchAddress("KS_METPt", &KS_METPt);
	Double_t KS_WTransverseMass; 		t->SetBranchAddress("KS_WTransverseMass", &KS_WTransverseMass);
	Double_t TrackQPt; 			t->SetBranchAddress("TrackQPt", &TrackQPt);
	Double_t TrackCurvSig; 			t->SetBranchAddress("TrackCurvSig", &TrackCurvSig);
	Double_t QTimesLeptonEta; 		t->SetBranchAddress("QTimesLeptonEta", &QTimesLeptonEta);
	Double_t w_superOR_trig; 		t->SetBranchAddress("w_superOR_trig", &w_superOR_trig);
	Double_t w_singlelep_trig; 		t->SetBranchAddress("w_singlelep_trig", &w_singlelep_trig);
	Double_t w_ljets_trig; 			t->SetBranchAddress("w_ljets_trig", &w_ljets_trig);
	Int_t    Is_W1c; 			t->SetBranchAddress("Is_W1c", &Is_W1c);
	Int_t    Analysis; 			t->SetBranchAddress("Analysis", &Analysis);
	Int_t    EventNumber; 			t->SetBranchAddress("EventNumber", &EventNumber);
	Int_t    MCindex; 			t->SetBranchAddress("MCindex", &MCindex);
	Int_t    FiredLepJetsTrigger; 		t->SetBranchAddress("FiredLepJetsTrigger", &FiredLepJetsTrigger);
	Int_t    FiredSingleLepTrigger; 	t->SetBranchAddress("FiredSingleLepTrigger", &FiredSingleLepTrigger);
	Int_t    Jet1MuonTagCharge; 		t->SetBranchAddress("Jet1MuonTagCharge", &Jet1MuonTagCharge);
	Int_t    Jet1PartonMatch; 		t->SetBranchAddress("Jet1PartonMatch", &Jet1PartonMatch);
	Int_t    Jet2MuonTagCharge; 		t->SetBranchAddress("Jet2MuonTagCharge", &Jet2MuonTagCharge);
	Int_t    Jet2PartonMatch; 		t->SetBranchAddress("Jet2PartonMatch", &Jet2PartonMatch);
	Int_t    Jet3MuonTagCharge; 		t->SetBranchAddress("Jet3MuonTagCharge", &Jet3MuonTagCharge);
	Int_t    Jet3PartonMatch; 		t->SetBranchAddress("Jet3PartonMatch", &Jet3PartonMatch);
	Int_t    Jet4MuonTagCharge; 		t->SetBranchAddress("Jet4MuonTagCharge", &Jet4MuonTagCharge);
	Int_t    Jet4PartonMatch; 		t->SetBranchAddress("Jet4PartonMatch", &Jet4PartonMatch);
	Int_t    LeptonCharge; 			t->SetBranchAddress("LeptonCharge", &LeptonCharge);
	Int_t    LeptonNCFTHits; 		t->SetBranchAddress("LeptonNCFTHits", &LeptonNCFTHits);
	Int_t    LeptonNSMTHits; 		t->SetBranchAddress("LeptonNSMTHits", &LeptonNSMTHits);
	Int_t    NGoodJets; 			t->SetBranchAddress("NGoodJets", &NGoodJets);
	Int_t    NAllPrimaryVertex; 		t->SetBranchAddress("NAllPrimaryVertex", &NAllPrimaryVertex);
	Int_t    NTaggedJets; 			t->SetBranchAddress("NTaggedJets", &NTaggedJets);
	Int_t    RunNumber; 			t->SetBranchAddress("RunNumber", &RunNumber);
	Double_t Jet1E; 			t->SetBranchAddress("Jet1E", &Jet1E);
	Double_t Jet1Pt; 			t->SetBranchAddress("Jet1Pt", &Jet1Pt);
	Double_t Jet1Phi; 			t->SetBranchAddress("Jet1Phi", &Jet1Phi);
	Double_t Jet1Eta; 			t->SetBranchAddress("Jet1Eta", &Jet1Eta);
	Double_t Jet1DetEta; 			t->SetBranchAddress("Jet1DetEta", &Jet1DetEta);
	Double_t Jet1Mass; 			t->SetBranchAddress("Jet1Mass", &Jet1Mass);
	Double_t Jet1BTagNN; 			t->SetBranchAddress("Jet1BTagNN", &Jet1BTagNN);
	Double_t Jet1QTimesEta; 		t->SetBranchAddress("Jet1QTimesEta", &Jet1QTimesEta);
	Double_t Jet1Taggability; 		t->SetBranchAddress("Jet1Taggability", &Jet1Taggability);
	Double_t Jet1Taggability_Error; 	t->SetBranchAddress("Jet1Taggability_Error", &Jet1Taggability_Error);
	Int_t    Jet1HasMU; 			t->SetBranchAddress("Jet1HasMU", &Jet1HasMU);
	Int_t    Jet1Flavor; 			t->SetBranchAddress("Jet1Flavor", &Jet1Flavor);
	Double_t Jet2E; 			t->SetBranchAddress("Jet2E", &Jet2E);
	Double_t Jet2Pt; 			t->SetBranchAddress("Jet2Pt", &Jet2Pt);
	Double_t Jet2Phi; 			t->SetBranchAddress("Jet2Phi", &Jet2Phi);
	Double_t Jet2Eta; 			t->SetBranchAddress("Jet2Eta", &Jet2Eta);
	Double_t Jet2DetEta; 			t->SetBranchAddress("Jet2DetEta", &Jet2DetEta);
	Double_t Jet2Mass; 			t->SetBranchAddress("Jet2Mass", &Jet2Mass);
	Double_t Jet2BTagNN; 			t->SetBranchAddress("Jet2BTagNN", &Jet2BTagNN);
	Double_t Jet2QTimesEta; 		t->SetBranchAddress("Jet2QTimesEta", &Jet2QTimesEta);
	Double_t Jet2Taggability; 		t->SetBranchAddress("Jet2Taggability", &Jet2Taggability);
	Double_t Jet2Taggability_Error; 	t->SetBranchAddress("Jet2Taggability_Error", &Jet2Taggability_Error);
	Int_t    Jet2HasMU; 			t->SetBranchAddress("Jet2HasMU", &Jet2HasMU);
	Int_t    Jet2Flavor; 			t->SetBranchAddress("Jet2Flavor", &Jet2Flavor);
	Double_t Jet3E; 			t->SetBranchAddress("Jet3E", &Jet3E);
	Double_t Jet3Pt; 			t->SetBranchAddress("Jet3Pt", &Jet3Pt);
	Double_t Jet3Phi; 			t->SetBranchAddress("Jet3Phi", &Jet3Phi);
	Double_t Jet3Eta; 			t->SetBranchAddress("Jet3Eta", &Jet3Eta);
	Double_t Jet3DetEta; 			t->SetBranchAddress("Jet3DetEta", &Jet3DetEta);
	Double_t Jet3Mass; 			t->SetBranchAddress("Jet3Mass", &Jet3Mass);
	Double_t Jet3BTagNN; 			t->SetBranchAddress("Jet3BTagNN", &Jet3BTagNN);
	Double_t Jet3Taggability; 		t->SetBranchAddress("Jet3Taggability", &Jet3Taggability);
	Double_t Jet3Taggability_Error; 	t->SetBranchAddress("Jet3Taggability_Error", &Jet3Taggability_Error);
	Int_t    Jet3HasMU; 			t->SetBranchAddress("Jet3HasMU", &Jet3HasMU);
	Int_t    Jet3Flavor; 			t->SetBranchAddress("Jet3Flavor", &Jet3Flavor);
	Double_t Jet4E; 			t->SetBranchAddress("Jet4E", &Jet4E);
	Double_t Jet4Pt; 			t->SetBranchAddress("Jet4Pt", &Jet4Pt);
	Double_t Jet4Phi; 			t->SetBranchAddress("Jet4Phi", &Jet4Phi);
	Double_t Jet4Eta; 			t->SetBranchAddress("Jet4Eta", &Jet4Eta);
	Double_t Jet4DetEta; 			t->SetBranchAddress("Jet4DetEta", &Jet4DetEta);
	Double_t Jet4Mass; 			t->SetBranchAddress("Jet4Mass", &Jet4Mass);
	Double_t Jet4BTagNN; 			t->SetBranchAddress("Jet4BTagNN", &Jet4BTagNN);
	Double_t Jet4Taggability; 		t->SetBranchAddress("Jet4Taggability", &Jet4Taggability);
	Double_t Jet4Taggability_Error; 	t->SetBranchAddress("Jet4Taggability_Error", &Jet4Taggability_Error);
	Int_t    Jet4HasMU; 			t->SetBranchAddress("Jet4HasMU", &Jet4HasMU);
	Int_t    Jet4Flavor; 			t->SetBranchAddress("Jet4Flavor", &Jet4Flavor);
	Double_t MostBLikeJetE; 		t->SetBranchAddress("MostBLikeJetE", &MostBLikeJetE);
	Double_t MostBLikeJetPt; 		t->SetBranchAddress("MostBLikeJetPt", &MostBLikeJetPt);
	Double_t MostBLikeJetPhi; 		t->SetBranchAddress("MostBLikeJetPhi", &MostBLikeJetPhi);
	Double_t MostBLikeJetEta; 		t->SetBranchAddress("MostBLikeJetEta", &MostBLikeJetEta);
	Double_t MostBLikeJetDetEta; 		t->SetBranchAddress("MostBLikeJetDetEta", &MostBLikeJetDetEta);
	Double_t MostBLikeJetBTagNN; 		t->SetBranchAddress("MostBLikeJetBTagNN", &MostBLikeJetBTagNN);
	Double_t MostBLikeJetLeptonDeltaPhi; 	t->SetBranchAddress("MostBLikeJetLeptonDeltaPhi", &MostBLikeJetLeptonDeltaPhi);
	Double_t MostBLikeJetQTimesEta; 	t->SetBranchAddress("MostBLikeJetQTimesEta", &MostBLikeJetQTimesEta);
	//Double_t MostBLikeJetTaggability; 	t->SetBranchAddress("MostBLikeJetTaggability", &MostBLikeJetTaggability);
	//Double_t MostBLikeJetTaggability_Error; t->SetBranchAddress("MostBLikeJetTaggability_Error", &MostBLikeJetTaggability_Error);
	//Int_t    MostBLikeJetHasMU; 		t->SetBranchAddress("MostBLikeJetHasMU", &MostBLikeJetHasMU);
	//Int_t    MostBLikeJetFlavor; 		t->SetBranchAddress("MostBLikeJetFlavor", &MostBLikeJetFlavor);
	Double_t LeadingBTaggedJetPt; 		t->SetBranchAddress("LeadingBTaggedJetPt", &LeadingBTaggedJetPt);
	Double_t LeadingBTaggedJetEta; 		t->SetBranchAddress("LeadingBTaggedJetEta", &LeadingBTaggedJetEta);
	Double_t LeadingBTaggedJetBTagNN; 	t->SetBranchAddress("LeadingBTaggedJetBTagNN", &LeadingBTaggedJetBTagNN);
	Double_t LeadingBTaggedJetLeptonDeltaPhi; t->SetBranchAddress("LeadingBTaggedJetLeptonDeltaPhi", &LeadingBTaggedJetLeptonDeltaPhi);
	Double_t SecondBTaggedJetPt; 		t->SetBranchAddress("SecondBTaggedJetPt", &SecondBTaggedJetPt);
	Double_t SecondBTaggedJetEta; 		t->SetBranchAddress("SecondBTaggedJetEta", &SecondBTaggedJetEta);
	Double_t SecondBTaggedJetBTagNN; 	t->SetBranchAddress("SecondBTaggedJetBTagNN", &SecondBTaggedJetBTagNN);
	Double_t SecondBTaggedJetLeptonDeltaPhi; t->SetBranchAddress("SecondBTaggedJetLeptonDeltaPhi", &SecondBTaggedJetLeptonDeltaPhi);
	Double_t LeadingLightQuarkJetE; 	t->SetBranchAddress("LeadingLightQuarkJetE", &LeadingLightQuarkJetE);
	Double_t LeadingLightQuarkJetPt;	t->SetBranchAddress("LeadingLightQuarkJetPt", &LeadingLightQuarkJetPt);
	Double_t LeadingLightQuarkJetPhi;	t->SetBranchAddress("LeadingLightQuarkJetPhi", &LeadingLightQuarkJetPhi);
	Double_t LeadingLightQuarkJetEta; 	t->SetBranchAddress("LeadingLightQuarkJetEta", &LeadingLightQuarkJetEta);
	Double_t LeadingLightQuarkJetMass; 	t->SetBranchAddress("LeadingLightQuarkJetMass", &LeadingLightQuarkJetMass);
	Double_t LeadingLightQuarkJetBTagNN; 	t->SetBranchAddress("LeadingLightQuarkJetBTagNN", &LeadingLightQuarkJetBTagNN);
	Double_t LeadingLightQuarkJetLeptonDeltaPhi; t->SetBranchAddress("LeadingLightQuarkJetLeptonDeltaPhi", &LeadingLightQuarkJetLeptonDeltaPhi);
	Double_t SecondLightQuarkJetPt; 	t->SetBranchAddress("SecondLightQuarkJetPt", &SecondLightQuarkJetPt);
	Double_t SecondLightQuarkJetPhi; 	t->SetBranchAddress("SecondLightQuarkJetPhi", &SecondLightQuarkJetPhi);
	Double_t SecondLightQuarkJetEta; 	t->SetBranchAddress("SecondLightQuarkJetEta", &SecondLightQuarkJetEta);
	Double_t SecondLightQuarkJetMass; 	t->SetBranchAddress("SecondLightQuarkJetMass", &SecondLightQuarkJetMass);
	Double_t SecondLightQuarkJetBTagNN; 	t->SetBranchAddress("SecondLightQuarkJetBTagNN", &SecondLightQuarkJetBTagNN);
	Double_t SecondLightQuarkJetLeptonDeltaPhi; t->SetBranchAddress("SecondLightQuarkJetLeptonDeltaPhi", &SecondLightQuarkJetLeptonDeltaPhi);
	Int_t    MCkeylength; 			t->SetBranchAddress("MCkeylength", &MCkeylength);
	//Char_t   MCkey[MCkeylength]; 		t->SetBranchAddress("MCkey[MCkeylength]", &MCkey[MCkeylength]);
	Double_t Jet1BTagMVA; 			t->SetBranchAddress("Jet1BTagMVA", &Jet1BTagMVA);
	Double_t Jet2BTagMVA; 			t->SetBranchAddress("Jet2BTagMVA", &Jet2BTagMVA);
	Double_t Jet3BTagMVA; 			t->SetBranchAddress("Jet3BTagMVA", &Jet3BTagMVA);
	Double_t Jet4BTagMVA; 			t->SetBranchAddress("Jet4BTagMVA", &Jet4BTagMVA);
	Double_t LeadingLightQuarkJetBTagMVA; 	t->SetBranchAddress("LeadingLightQuarkJetBTagMVA", &LeadingLightQuarkJetBTagMVA);
	Double_t SecondLightQuarkJetBTagMVA; 	t->SetBranchAddress("SecondLightQuarkJetBTagMVA", &SecondLightQuarkJetBTagMVA);
	Double_t LeadingBTaggedJetBTagMVA; 	t->SetBranchAddress("LeadingBTaggedJetBTagMVA", &LeadingBTaggedJetBTagMVA);
	Double_t SecondBTaggedJetBTagMVA; 	t->SetBranchAddress("SecondBTaggedJetBTagMVA", &SecondBTaggedJetBTagMVA);
	Double_t MostBLikeJetBTagMVA; 		t->SetBranchAddress("MostBLikeJetBTagMVA", &MostBLikeJetBTagMVA);
    
    Int_t nevents = t->GetEntries();
    
    FILE *dest_file;
    dest_file = fopen(destination_path,"w");

	// cout << "ok 1";

    for (Int_t i = 0; i<  nevents; i++) {

	t->GetEvent(i);
// 01	DeltaPhiLeptonMET			BDT+BNN
// 02	LeadingBTaggedJetBTagMVA		BDT+BNN
// 03	LeadingLightQuarkJetBTagMVA		BDT+BNN
// 04	LeadingLightQuarkJetPt			BDT+BNN
// 05	LeptonEta				BDT+BNN
// 06	LeptonPt				BDT+BNN
// 07	METPt					BDT+BNN
// 08	QTimesEta				BDT+BNN
// 09	WTransverseMass				BDT+BNN
// 10	Centrality_AllJets			BDT
// 11	Cos_Jet1Lepton_Lab			BDT
// 12	Cos_Jet2Lepton_Lab			BDT
// 13	DeltaPhiJet1MET				BDT
// 14	DeltaPhiJet2MET				BDT
// 15	DeltaRJet1Jet2				BDT
// 16	DeltaRMinLeptonJet			BDT
// 17	HT_AllJets				BDT
// 18	HT_AllJetsLeptonMET			BDT
// 19	HT_METlep				BDT
// 20	InvariantMass_Jet1Jet2			BDT
// 21	Jet1Mass				BDT
// 22	Jet1QTimesEta				BDT
// 23	Jet2Pt					BDT
// 24	Jet2QTimesEta				BDT
// 25	LeadingLightQuarkJetE			BDT
// 26	LeadingLightQuarkJetMass		BDT
// 27	MostBLikeJetQTimesEta			BDT
// 28	Pt_Jet1Jet2				BDT
// 29	QTimesLeptonEta				BDT
// 30	WPt					BDT
// 31   EwentWeight
	fprintf(dest_file,"%30.20f",DeltaPhiLeptonMET);
	fprintf(dest_file,"%30.20f",LeadingBTaggedJetBTagMVA);
	fprintf(dest_file,"%30.20f",LeadingLightQuarkJetBTagMVA);
	fprintf(dest_file,"%30.20f",LeadingLightQuarkJetPt);
	fprintf(dest_file,"%30.20f",LeptonEta);
	fprintf(dest_file,"%30.20f",LeptonPt);
	fprintf(dest_file,"%30.20f",METPt);
	fprintf(dest_file,"%30.20f",QTimesEta);
	fprintf(dest_file,"%30.20f",WTransverseMass);
	fprintf(dest_file,"%30.20f",Centrality_AllJets);
	fprintf(dest_file,"%30.20f",Cos_Jet1Lepton_Lab);
	fprintf(dest_file,"%30.20f",Cos_Jet2Lepton_Lab);
	fprintf(dest_file,"%30.20f",DeltaPhiJet1MET);
	fprintf(dest_file,"%30.20f",DeltaPhiJet2MET);
	fprintf(dest_file,"%30.20f",DeltaRJet1Jet2);
	fprintf(dest_file,"%30.20f",DeltaRMinLeptonJet);
	fprintf(dest_file,"%30.20f",HT_AllJets);
	fprintf(dest_file,"%30.20f",HT_AllJetsLeptonMET);
	fprintf(dest_file,"%30.20f",HT_METlep);
	fprintf(dest_file,"%30.20f",InvariantMass_Jet1Jet2);
	fprintf(dest_file,"%30.20f",Jet1Mass);
	fprintf(dest_file,"%30.20f",Jet1QTimesEta);
	fprintf(dest_file,"%30.20f",Jet2Pt);
	fprintf(dest_file,"%30.20f",Jet2QTimesEta);
	fprintf(dest_file,"%30.20f",LeadingLightQuarkJetE);
	fprintf(dest_file,"%30.20f",LeadingLightQuarkJetMass);
	fprintf(dest_file,"%30.20f",MostBLikeJetQTimesEta);
	fprintf(dest_file,"%30.20f",Pt_Jet1Jet2);
	fprintf(dest_file,"%30.20f",QTimesLeptonEta);
	fprintf(dest_file,"%30.20f",WPt);
	fprintf(dest_file,"%30.20f\n",EventWeight);
    }
    
    fclose(dest_file);
    
//     dest_file = fopen(destination_path_variables,"w");    
// 
//     TObjArray *arr = t->GetListOfBranches();
//     for (int i = 0; i < arr->GetSize(); i++) {
// 		fprintf(dest_file,"%s\n", arr->At(i)->GetTitle() );
//     }
//     fclose(dest_file);
    
}
コード例 #22
0
ファイル: analyze3D.C プロジェクト: noferini/lessonmaterials
void analyze(Int_t step){

  // TOF propagation factors (TOF efficiencies)
  fEfficiencyPiTOF = new TF1("fEfficiencyPiTOF","(x > 0.3)*0.7",0,10);
  fEfficiencyKaTOF = new TF1("fEfficiencyKaTOF","(x > 0.3)*(x-0.3)*(x<1) + (x>1)*0.7",0,10);
  fEfficiencyPrTOF = new TF1("fEfficiencyPrTOF","(x > 0.3)*(x-0.3)*(x<1) + (x>1)*0.7",0,10);

  // teoretical separation (perfect if equal to the one simualted in sim.C)
  fseparation = new TF1("f","[0]+[1]/x",0,100);
  fseparation->SetParameter(0,0.);
  fseparation->SetParameter(1,7.);
 
  fseparationPiKa = new TF1("fPiKa","[0]+[1]/TMath::Power(x,2.5)",0,100);
  fseparationPiKa->SetParameter(0,2.34);
  fseparationPiKa->SetParameter(1,10);

  fseparationKaPr = new TF1("fKaPr","[0]+[1]/TMath::Power(x,2.5)",0,100);
  fseparationKaPr->SetParameter(0,1);
  fseparationKaPr->SetParameter(1,56);

  // x=p, y=pt/p (normalized at the number of sigma assuming 80 ps resolution)
  fTOFpi = new TF2("fTOFpi","3.7/y*(sqrt(x*x+0.0193210)/x-1)*37.47405725",0.3,10,0.5,1);
  fTOFka = new TF2("fTOFka","3.7/y*(sqrt(x*x+0.243049)/x-1)*37.47405725",0.3,10,0.5,1);
  fTOFpr = new TF2("fTOFpr","3.7/y*(sqrt(x*x+0.879844)/x-1)*37.47405725",0.3,10,0.5,1);


  // x=p, already normalized in number of sigma (sigma assumed 3.5=7% of the MIP)
  fTPCpi = new TF1("fTPCpi",BetheBlochAleph,0,10,6);
  fTPCpi->SetParameter(0,fKp1);
  fTPCpi->SetParameter(1,fKp2);
  fTPCpi->SetParameter(2,fKp3);
  fTPCpi->SetParameter(3,fKp4);
  fTPCpi->SetParameter(4,fKp5);
  fTPCpi->SetParameter(5,0.139);
  fTPCka = new TF1("fTPCka",BetheBlochAleph,0,10,6);
  fTPCka->SetParameter(0,fKp1);
  fTPCka->SetParameter(1,fKp2);
  fTPCka->SetParameter(2,fKp3);
  fTPCka->SetParameter(3,fKp4);
  fTPCka->SetParameter(4,fKp5);
  fTPCka->SetParameter(5,0.493);
  fTPCpr = new TF1("fTPCpr",BetheBlochAleph,0,10,6);
  fTPCpr->SetParameter(0,fKp1);
  fTPCpr->SetParameter(1,fKp2);
  fTPCpr->SetParameter(2,fKp3);
  fTPCpr->SetParameter(3,fKp4);
  fTPCpr->SetParameter(4,fKp5);
  fTPCpr->SetParameter(5,0.938);

  Float_t width = 1.0;
  addshift =0;

  invwidth = 1./width;

  Float_t widthTOF = 1.0;
  addshiftTOF =0;

  invwidthTOF = 1./widthTOF;

  TH1D *priorsPt[6];
  TH1D *newpriorsPt[6];
  TH1D *truePt[6];
  TH1D *allPtPos = new TH1D("allPtP","All positive;p_{T} (GeV/#it{c});N",100,0,10);
  TH1D *allPtNeg = new TH1D("allPtN","All negative;p_{T} (GeV/#it{c});N",100,0,10);

  TH3D *priorsKs[3][3];
  TH3D *newpriorsKs[3][3];
  TH3D *truePidKs[3][3];
  TH3D *trueKs;

  TH2D *priorsPhi[3][3];
  TH2D *newpriorsPhi[3][3];
  TH2D *truePidPhi[3][3];
  TH2D *truePhi;

  TH3D *priorsLc[3][3][3];
  TH3D *newpriorsLc[3][3][3];
  TH3D *truePidLc[3][3][3];
  TH3D *trueLc,*mypidLc;

  TH3D *priorsLcbar[3][3][3];
  TH3D *newpriorsLcbar[3][3][3];
  TH3D *truePidLcbar[3][3][3];
  TH3D *trueLcbar,*mypidLcbar;

  Int_t nbinPtFrKa = 8;
  Int_t nbinPtFrPi = 8;
  Int_t nbinY = 1;
  Int_t nbinpol=nbinPtFrKa*nbinPtFrPi*nbinY;
  Double_t normbin = 1./nbinpol;
  Int_t nbinmlc = 100;
  Int_t nbinptlc = 10;

  const char *spec[3] = {"Pi","Ka","Pr"};

  if(step==0){
    priorsPt[0] = new TH1D("oldpriorsPtPiP","Pion (+) priors;p_{T} (GeV/#it{c});N",100,0,10);
    for(Int_t i=1;i<=100;i++)
      priorsPt[0]->SetBinContent(i,1);
    priorsPt[1] = new TH1D("oldpriorsPtKaP","Kaon (+) priors;p_{T} (GeV/#it{c});N",100,0,10);
    priorsPt[2] = new TH1D("oldpriorsPtPrP","Proton (+) priors;p_{T} (GeV/#it{c});N",100,0,10);
    priorsPt[3] = new TH1D("oldpriorsPtPiM","Pion (-) priors;p_{T} (GeV/#it{c});N",100,0,10);
    priorsPt[4] = new TH1D("oldpriorsPtKaM","Kaon (-) priors;p_{T} (GeV/#it{c});N",100,0,10);
    priorsPt[5] = new TH1D("oldpriorsPtPrM","Proton (-) priors;p_{T} (GeV/#it{c});N",100,0,10);
    priorsPt[1]->Add(priorsPt[0]);
    priorsPt[2]->Add(priorsPt[0]);
    priorsPt[3]->Add(priorsPt[0]);
    priorsPt[4]->Add(priorsPt[0]);
    priorsPt[5]->Add(priorsPt[0]);

    // Ks and phi priors
    for(Int_t i=0; i< 3;i++){
      for(Int_t j=0; j< 3;j++){
	priorsKs[i][j] =  new TH3D(Form("oldpriorsKs%s%s",spec[i],spec[j]),Form("K^{0*} priors for %s-%s;m_{#piK} (GeV/#it{c}^2);p_{T} (GeV/#it{c});N",spec[i],spec[j]),200,0.4,1.4,40,0,10,nbinpol,-1.001,1.001);
	priorsPhi[i][j] =  new TH2D(Form("oldpriorsPhi%s%s",spec[i],spec[j]),Form("#phi priors for %s-%s;m_{KK} (GeV/#it{c}^2);p_{T} (GeV/#it{c});N",spec[i],spec[j]),100,0.98,1.05,40,0,10);


	if(i==0 && j==0){
	  for(Int_t ibx=1;ibx<=200;ibx++)
	    for(Int_t iby=1;iby<=40;iby++){
	      for(Int_t ibz=1;ibz <= nbinpol;ibz++)
		priorsKs[i][j]->SetBinContent(ibx,iby,ibz,1);
	      priorsPhi[i][j]->SetBinContent(ibx,iby,1);
	    }
	}
	else{
	  priorsKs[i][j]->Add(priorsKs[0][0]);
	  priorsPhi[i][j]->Add(priorsPhi[0][0]);
	}

	for(Int_t k=0; k< 3;k++){
	  priorsLc[i][j][k] =  new TH3D(Form("oldpriorsLc%s%s%s",spec[i],spec[j],spec[k]),Form("#Lambda_{c}^{+} priors for %s-%s-%s;m_{#piKp} (GeV/#it{c}^2);p_{T} (GeV/#it{c});N",spec[i],spec[j],spec[k]),nbinmlc,2.1,2.5,nbinptlc,7,27,nbinpol,0,1.);
	  priorsLcbar[i][j][k] =  new TH3D(Form("oldpriorsLcbar%s%s%s",spec[i],spec[j],spec[k]),Form("#overline{#Lambda}_{c}^{-} priors for %s-%s-%s;m_{#piKp} (GeV/#it{c}^2);p_{T} (GeV/#it{c});N",spec[i],spec[j],spec[k]),nbinmlc,2.1,2.5,nbinptlc,7,27,nbinpol,0,1.);
	  if(i==0 && j==0 && k==0){
	    for(Int_t ibx=1;ibx<=nbinmlc;ibx++)
	      for(Int_t iby=1;iby<=nbinptlc;iby++){
		for(Int_t ibz=1;ibz <= nbinpol;ibz++){
		  priorsLc[i][j][k]->SetBinContent(ibx,iby,ibz,1);
		  priorsLcbar[i][j][k]->SetBinContent(ibx,iby,ibz,1);
		}
	      }
	  }
	  else{
	    priorsLc[i][j][k]->Add(priorsLc[0][0][0]);
	    priorsLcbar[i][j][k]->Add(priorsLc[0][0][0]);
	  }
	}
      }
    }
  }
  else{
    TFile *fin = new TFile(Form("step%i.root",step));
    priorsPt[0] = (TH1D *) fin->Get("priorsPtPiP"); 
    priorsPt[0]->SetName("oldpriorsPtPiP");
    priorsPt[1] = (TH1D *) fin->Get("priorsPtKaP"); 
    priorsPt[1]->SetName("oldpriorsPtPiP");
    priorsPt[2] = (TH1D *) fin->Get("priorsPtPrP"); 
    priorsPt[2]->SetName("oldpriorsPtPiP");
    priorsPt[3] = (TH1D *) fin->Get("priorsPtPiM"); 
    priorsPt[3]->SetName("oldpriorsPtPiM");
    priorsPt[4] = (TH1D *) fin->Get("priorsPtKaM"); 
    priorsPt[4]->SetName("oldpriorsPtKaM");
    priorsPt[5] = (TH1D *) fin->Get("priorsPtPrM"); 
    priorsPt[5]->SetName("oldpriorsPtPrM");

    // Ks and phi priors
    for(Int_t i=0; i< 3;i++){
      for(Int_t j=0; j< 3;j++){
	priorsKs[i][j] =  (TH3D *) fin->Get(Form("priorsKs%s%s",spec[i],spec[j]));
	priorsKs[i][j]->SetName(Form("oldpriorsKs%s%s",spec[i],spec[j]));
	priorsPhi[i][j] =  (TH2D *) fin->Get(Form("priorsPhi%s%s",spec[i],spec[j]));
	priorsPhi[i][j]->SetName(Form("oldpriorsPhi%s%s",spec[i],spec[j]));
	for(Int_t k=0; k< 3;k++){
	  priorsLc[i][j][k] =  (TH3D *) fin->Get(Form("priorsLc%s%s%s",spec[i],spec[j],spec[k]));
	  priorsLc[i][j][k]->SetName(Form("oldpriorsLc%s%s%s",spec[i],spec[j],spec[k]));
	  priorsLcbar[i][j][k] =  (TH3D *) fin->Get(Form("priorsLcbar%s%s%s",spec[i],spec[j],spec[k]));
	  priorsLcbar[i][j][k]->SetName(Form("oldpriorsLcbar%s%s%s",spec[i],spec[j],spec[k]));
	}
      }
    }
  }
  
  newpriorsPt[0] = new TH1D("priorsPtPiP","Pion (+) priors;p_{T} (GeV/#it{c});N",100,0,10);
  newpriorsPt[1] = new TH1D("priorsPtKaP","Kaon (+) priors;p_{T} (GeV/#it{c});N",100,0,10);
  newpriorsPt[2] = new TH1D("priorsPtPrP","Proton (+) priors;p_{T} (GeV/#it{c});N",100,0,10);
  newpriorsPt[3] = new TH1D("priorsPtPiM","Pion (-) priors;p_{T} (GeV/#it{c});N",100,0,10);
  newpriorsPt[4] = new TH1D("priorsPtKaM","Kaon (-) priors;p_{T} (GeV/#it{c});N",100,0,10);
  newpriorsPt[5] = new TH1D("priorsPtPrM","Proton (-) priors;p_{T} (GeV/#it{c});N",100,0,10);

  // Ks and phi priors distributions
  for(Int_t i=0; i< 3;i++){
    for(Int_t j=0; j< 3;j++){
      newpriorsKs[i][j] =  new TH3D(Form("priorsKs%s%s",spec[i],spec[j]),Form("K^{0*} priors for %s-%s;m_{#piK} (GeV/#it{c}^2);p_{T} (GeV/#it{c});N",spec[i],spec[j]),200,0.4,1.4,40,0,10,nbinpol,-1.001,1.001);
      newpriorsPhi[i][j] =  new TH2D(Form("priorsPhi%s%s",spec[i],spec[j]),Form("#phi priors for %s-%s;m_{KK} (GeV/#it{c}^2);p_{T} (GeV/#it{c});N",spec[i],spec[j]),100,0.98,1.05,40,0,10);
      for(Int_t k=0; k< 3;k++){
	newpriorsLc[i][j][k] =  new TH3D(Form("priorsLc%s%s%s",spec[i],spec[j],spec[k]),Form("#Lambda_{c}^{+} priors for %s-%s-%s;m_{#piKp} (GeV/#it{c}^2);p_{T} (GeV/#it{c});N",spec[i],spec[j],spec[k]),nbinmlc,2.1,2.5,nbinptlc,7,27,nbinpol,0,1.);
	newpriorsLcbar[i][j][k] =  new TH3D(Form("priorsLcbar%s%s%s",spec[i],spec[j],spec[k]),Form("#overline{#Lambda}_{c}^{-} priors for %s-%s-%s;m_{#piKp} (GeV/#it{c}^2);p_{T} (GeV/#it{c});N",spec[i],spec[j],spec[k]),nbinmlc,2.1,2.5,nbinptlc,7,27,nbinpol,0,1.);
      }
    }
  }
  
  truePt[0]  = new TH1D("truePtPiP","Pion (+) truth;p_{T} (GeV/#it{c});N",100,0,10);
  truePt[1]  = new TH1D("truePtKaP","Kaon (+) truth;p_{T} (GeV/#it{c});N",100,0,10);
  truePt[2]  = new TH1D("truePtPrP","Proton (+) truth;p_{T} (GeV/#it{c});N",100,0,10);
  truePt[3]  = new TH1D("truePtPiM","Pion (-) truth;p_{T} (GeV/#it{c});N",100,0,10);
  truePt[4]  = new TH1D("truePtKaM","Kaon (-) truth;p_{T} (GeV/#it{c});N",100,0,10);
  truePt[5]  = new TH1D("truePtPrM","Proton (-) truth;p_{T} (GeV/#it{c});N",100,0,10);

  // Ks and phi truePid distributions
  for(Int_t i=0; i< 3;i++){
    for(Int_t j=0; j< 3;j++){
      truePidKs[i][j] =  new TH3D(Form("truePidKs%s%s",spec[i],spec[j]),Form("K^{0*} truePid for %s-%s;m_{#piK} (GeV/#it{c}^2);p_{T} (GeV/#it{c});N",spec[i],spec[j]),200,0.4,1.4,40,0,10,nbinpol,-1.001,1.001);
      truePidPhi[i][j] =  new TH2D(Form("truePidPhi%s%s",spec[i],spec[j]),Form("#phi truePid for %s-%s;m_{KK} (GeV/#it{c}^2);p_{T} (GeV/#it{c});N",spec[i],spec[j]),100,0.98,1.05,40,0,10);

      for(Int_t k=0; k< 3;k++){
	truePidLc[i][j][k] =  new TH3D(Form("truePidLc%s%s%s",spec[i],spec[j],spec[k]),Form("#Lambda_{c}^{+} truePid for %s-%s-%s;m_{#piKp} (GeV/#it{c}^2);p_{T} (GeV/#it{c});N",spec[i],spec[j],spec[k]),nbinmlc,2.1,2.5,nbinptlc,7,27,nbinpol,0,1.);
	truePidLcbar[i][j][k] =  new TH3D(Form("truePidLcbar%s%s%s",spec[i],spec[j],spec[k]),Form("#overline{#Lambda}_{c}^{-} truePid for %s-%s-%s;m_{#piKp} (GeV/#it{c}^2);p_{T} (GeV/#it{c});N",spec[i],spec[j],spec[k]),nbinmlc,2.1,2.5,nbinptlc,7,27,nbinpol,0,1.);
      }

    }
  }

  trueKs =  new TH3D(Form("trueKs"),Form("K^{0*} true;m_{#piK} (GeV/#it{c}^2);p_{T} (GeV/#it{c});N"),200,0.4,1.4,40,0,10,nbinpol,-1.001,1.001);
  truePhi =  new TH2D(Form("truePhi"),Form("#phi true;m_{KK} (GeV/#it{c}^2);p_{T} (GeV/#it{c});N"),100,0.98,1.05,40,0,10);

  trueLc =  new TH3D(Form("trueLc"),Form("#Lambda_{c}^{+} true;m_{#piKp} (GeV/#it{c}^2);p_{T} (GeV/#it{c});N"),nbinmlc,2.1,2.5,nbinptlc,7,27,nbinpol,0,1.);
  trueLcbar =  new TH3D(Form("trueLcbar"),Form("#overline{#Lambda}_{c}^{-} true;m_{#piKp} (GeV/#it{c}^2);p_{T} (GeV/#it{c});N"),nbinmlc,2.1,2.5,nbinptlc,7,27,nbinpol,0,1);

  mypidLc =  new TH3D(Form("mypidLc"),Form("#Lambda_{c}^{+} true;m_{#piKp} (GeV/#it{c}^2);p_{T} (GeV/#it{c});N"),nbinmlc,2.1,2.5,nbinptlc,7,27,nbinpol,0,1.);
  mypidLcbar =  new TH3D(Form("mypidLcbar"),Form("#Lambda_{c}^{+} true;m_{#piKp} (GeV/#it{c}^2);p_{T} (GeV/#it{c});N"),nbinmlc,2.1,2.5,nbinptlc,7,27,nbinpol,0,1.);

  // define particle types (particle type array)
  particle::AddParticleType("pi+",0.139,1); // 0
  particle::AddParticleType("pi-",0.139,-1); // 1
  particle::AddParticleType("K+",0.493,1); // 2 
  particle::AddParticleType("K-",0.493,-1); // 3
  particle::AddParticleType("p+",0.938,1); // 4 
  particle::AddParticleType("p-",0.938,-1); // 5
  particle::AddParticleType("K0*",0.896,0,5.05e-02); // 6
  particle::AddParticleType("K0bar*",0.896,0,5.05e-02); // 7
  particle::AddParticleType("Phi",1.02,0,0.00426); // 8
  particle::AddParticleType("Delta++",1.232,2,0.118); // 9 
  particle::AddParticleType("Delta--",1.232,-2,0.118);  // 10
  particle::AddParticleType("Lambdac+",2.28646,1,0.008); // 11
  particle::AddParticleType("Lambdacbar-",2.28646,-1,0.008); // 12
  particle::AddParticleType("Lambda1520",1.5195,-1,0.0000156); // 12

  particle d1("pi+");
  particle d2("K+");
  particle d3("p+");
  particle d4("pi-");
  particle d5("K-");
  particle d6("p-");

  particle prong1;
  particle prong2;
  particle prong3;

  particle polarKs("K0*");
  particle polarLc("Lambdac+");

  Int_t charge[] = {1,-1,1,-1,1,-1,0,0,0,2,-2,1,-1};

  particle ppos[20000];
  particle pneg[20000];

  Float_t weightsPos[20000][3];
  Float_t weightsNeg[20000][3];
  Int_t passMyPIDPos[20000][3];
  Int_t passMyPIDNeg[20000][3];

  Int_t npos=0;
  Int_t nneg=0;

  Float_t signal,signalTOF,signalTPC,pt,pz,phi,ptComb,ptComb3prong,invmass;
  Float_t ptd,pzd,phid;

  Float_t priors[3],prob[3];
  Float_t priors2[3][3],prob2[3][3];
  Float_t priors3[3][3][3],prob3[3][3][3];
      
  Int_t iev=-1,id,mother;
  Int_t cev;
  
  TFile *fout = new TFile(Form("step%i.root",step+1),"RECREATE");
  // TTree *treeKs = new TTree("treeKs","treeKs");
  // Float_t ptPair,massPair,ptD1,ptD2,weightD1[3],weightD2[3],weightFill;
  // Int_t isTrue,isTruePid;
  // treeKs->Branch("ptPair",&ptPair,"ptPair/F");
  // treeKs->Branch("massPair",&massPair,"massPair/F");
  // treeKs->Branch("ptPi",&ptD1,"ptPi/F");
  // treeKs->Branch("ptKa",&ptD2,"ptKa/F");
  // treeKs->Branch("weightPi",weightD1,"wightPi[3]/F");
  // treeKs->Branch("weightKa",weightD2,"wightKa[3]/F");
  // treeKs->Branch("weightFill",&weightFill,"wightFill/F");
  // treeKs->Branch("isTruePid",&isTruePid,"isTruePid/I");
  // treeKs->Branch("isTrue",&isTrue,"isTrue/I");
  TH1F *hcentr = new TH1F("hcentr","",100,0,100);

  FILE *flist = fopen("lista","r");
  char namefile[100];
  Float_t weight1[3],weight2[3],weight3[3];
  Float_t ptPi,ptKa,ptPr;

  TH1F *htemp;

  while(fscanf(flist,"%s",namefile)==1){
    TFile *fin = new TFile(namefile);
    printf("file = %s\n",namefile);
    TList *l = (TList *) fin->Get("TOFpid");
    htemp = (TH1F *) l->At(0);
    if(!hcentr) hcentr = new TH1F(*htemp);
    else hcentr->Add(htemp);
    TTree *t = (TTree *) l->At(1);
    Int_t n = t->GetEntries();
    
    for(Int_t i=0;i < n;i++){
      t->GetEvent(i);

      ptPi = t->GetLeaf("ptPi")->GetValue();
      ptKa = t->GetLeaf("ptPi")->GetValue();
      ptPr = t->GetLeaf("ptPi")->GetValue();
      pt = t->GetLeaf("pt")->GetValue();
      invmass = t->GetLeaf("mass")->GetValue();
      weight1[0] = t->GetLeaf("weightPi")->GetValue(0);
      weight1[1] = t->GetLeaf("weightPi")->GetValue(1);
      weight1[2] = t->GetLeaf("weightPi")->GetValue(2);
      weight2[0] = t->GetLeaf("weightKa")->GetValue(0);
      weight2[1] = t->GetLeaf("weightKa")->GetValue(1);
      weight2[2] = t->GetLeaf("weightKa")->GetValue(2);
      weight3[0] = t->GetLeaf("weightPr")->GetValue(0);
      weight3[1] = t->GetLeaf("weightPr")->GetValue(1);
      weight3[2] = t->GetLeaf("weightPr")->GetValue(2);

      Float_t pt1 = Int_t(ptPi/(ptPi+ptKa+ptPr)*nbinPtFrPi);
      Float_t pt2 = Int_t(ptKa/(ptPi+ptKa+ptPr)*nbinPtFrKa);
      Float_t polar = 0;//TMath::Abs(polarLc.GetY());//ptComb3prong/ptot;//(pt2*nbinpol + pt1)*invpollc;
      polar = ((pt1*nbinPtFrKa + pt2 + polar)*nbinY)*normbin;

      Int_t ibinx = priorsLc[0][0][0]->GetXaxis()->FindBin(invmass);
      Int_t ibiny = priorsLc[0][0][0]->GetYaxis()->FindBin(pt);
      Int_t ibinz = priorsLc[0][0][0]->GetZaxis()->FindBin(polar);
      
      for(Int_t ipr=0;ipr<3;ipr++)
	for(Int_t jpr=0;jpr<3;jpr++)
	  for(Int_t kpr=0;kpr<3;kpr++)
	    priors3[ipr][jpr][kpr] = priorsLc[ipr][jpr][kpr]->GetBinContent(ibinx,ibiny,ibinz);
      
      GetProb3(weight1,weight2,weight3,priors3,prob3);

      for(Int_t ipr=0;ipr<3;ipr++)
	for(Int_t jpr=0;jpr<3;jpr++)
	  for(Int_t kpr=0;kpr<3;kpr++){
	    newpriorsLc[ipr][jpr][kpr]->Fill(invmass,pt,polar,prob3[ipr][jpr][kpr]);
	  }
    }
    t->Delete();
    fin->Close();

  }



  printf("Write output\n");
  fout->cd();
  hcentr->Write();
  //if(step==0) treeKs->Write();
  for(Int_t i=0;i<6;i++){
    newpriorsPt[i]->Write();
    truePt[i]->Write();
  }
  for(Int_t i=0;i<3;i++){
    for(Int_t j=0;j<3;j++){
      priorsPhi[i][j]->Write();
      newpriorsKs[i][j]->Write();
      newpriorsPhi[i][j]->Write();
      truePidKs[i][j]->Write();
      truePidPhi[i][j]->Write();
      for(Int_t k=0;k<3;k++){
       	newpriorsLc[i][j][k]->Write();
	truePidLc[i][j][k]->Write();
	newpriorsLcbar[i][j][k]->Write();
	truePidLcbar[i][j][k]->Write();
      }
    }
  }
  trueKs->Write();
  truePhi->Write();
  trueLc->Write();
  trueLcbar->Write();
  mypidLc->Write();
  mypidLcbar->Write();
  fout->Close();
}
コード例 #23
0
ファイル: striptree.C プロジェクト: zatserkl/root-macros
void process()
{
   Int_t raw[512];   // buffer for input signal and bkg trees
   // buffers for output trees
   Int_t sig[512];
   Int_t cmsig[512];
   Int_t cm[16];

   // pedestal
   const char* fbkg_name = "Raw_Data_FZ320P_05_MSSD_2_250V_K237_Pedestal.dat-events.root";
   TFile* fbkg = TFile::Open(fbkg_name);
   if (!fbkg) cout<< "File not found: " << fbkg <<endl<<exitl;

   TTree* tree = (TTree*) fbkg->Get("etree");
   tree->SetBranchAddress("raw", &raw);

   TH2* h2d = (TH2*) fbkg->Get("h2d");
   new TCanvas;
   h2d->Draw();

   TProfile* profile = (TProfile*) fbkg->Get("profile"); 
   //new TCanvas;
   //profile->Draw();

   Int_t pedestal[512];
   for (int i=0; i<512; i++) {
      // pedestal[i] = profile->GetBinContent(i+1) - 0.5;
      // pedestal[i] = profile->GetBinContent(i+1) + 0.5;
      pedestal[i] = profile->GetBinContent(i+1);
   }

   // cout << "\nPedestals for every channel\n" << endl;
   // for (int i=0; i<512; i++) {
   //    cout << pedestal[i] << " ";
   //    if (i>0 && (i+1)%128==0)
   //       cout << endl;
   // }

   cout<< "processing bkg" <<endl;

   // output file with tree
   const char* obfname = "FZ320P_05_MSSD_2-bkg.root";
   TFile* obfile = TFile::Open(obfname, "recreate");

   TTree* btree = new TTree("btree", "btree");
   btree->Branch("sig", &sig, "sig[512]/I");
   btree->Branch("cmsig", &cmsig, "cmsig[512]/I");
   btree->Branch("cm", &cm, "cm[16]/I");
   btree->SetMarkerStyle(6);
   btree->SetMarkerColor(2);

   for (int jentry=0; jentry<tree->GetEntries(); ++jentry)
   {
      tree->GetEvent(jentry);
      // sig
      for (int i=0; i<512; ++i) {
         sig[i] = raw[i] - pedestal[i];
      }
      // calc common mode
      Int_t group32[32];
      Int_t index32[32];
      for (int igroup=0; igroup<16; ++igroup) {
         for (int istrip=0; istrip<32; ++istrip)   // istrip is number inside group of 32
         {
            group32[istrip] = sig[igroup*32 + istrip];
         }
         // sort array group32 in ascending order
         TMath::Sort(32, group32, index32, kFALSE);
         Int_t median = group32[index32[14]];
         cm[igroup] = median;
      }
      // subtract common mode
      for (int istrip=0; istrip<512; ++istrip) {
         Int_t igroup = istrip/32;
         cmsig[istrip] = sig[istrip] - cm[igroup];
      }
      // Fill sig, cmsig, cm
      btree->Fill();
   }
   obfile->Write();

   /////////////////////////////////////////////////
   //
   // signal tree
   //
   /////////////////////////////////////////////////

   cout<< "processing signal" <<endl;
   
   TChain* chain = new TChain("etree");
   chain->Add("Raw_Data_FZ320P_05_MSSD_250V_K237_Position_1.dat-events.root");
   chain->Add("Raw_Data_FZ320P_05_MSSD_250V_K237_Position_2.dat-events.root");
   chain->Add("Raw_Data_FZ320P_05_MSSD_2_250V_K237_Position_3.dat-events.root");
   chain->Add("Raw_Data_FZ320P_05_MSSD_2_250V_K237_Position_4.dat-events.root");
   chain->SetBranchAddress("raw", &raw);

   // output file with tree
   const char* osfname = "FZ320P_05_MSSD_2-signal.root";
   TFile* osfile = TFile::Open(osfname, "recreate");

   TTree* stree = new TTree("stree", "stree");
   stree->Branch("sig", &sig, "sig[512]/I");
   stree->Branch("cmsig", &cmsig, "cmsig[512]/I");
   stree->Branch("cm", &cm, "cm[16]/I");
   stree->SetMarkerStyle(6);
   stree->SetMarkerColor(2);

   for (int jentry=0; jentry<chain->GetEntries(); ++jentry)
   {
      chain->GetEvent(jentry);
      // sig
      for (int i=0; i<512; ++i) {
         sig[i] = raw[i] - pedestal[i];
      }
      // calc common mode
      Int_t group32[32];
      Int_t index32[32];
      for (int igroup=0; igroup<16; ++igroup) {
         for (int istrip=0; istrip<32; ++istrip)   // istrip is number inside group of 32
         {
            group32[istrip] = sig[igroup*32 + istrip];
         }
         // sort array group32 in ascending order
         TMath::Sort(32, group32, index32, kFALSE);
         Int_t median = group32[index32[14]];
         cm[igroup] = median;
      }
      // subtract common mode
      for (int istrip=0; istrip<512; ++istrip) {
         Int_t igroup = istrip/32;
         cmsig[istrip] = sig[istrip] - cm[igroup];
      }
      // Fill sig, cmsig, cm
      stree->Fill();
   }
   osfile->Write();

   ////////////////////////////////////////////////////////
   //
   // process trees
   //
   ///////////////////////////////////////////////////////

   cout<< "results" <<endl;

   Double_t a, mean, sigma;

   TH1F* h_sigma_bkg = new TH1F("h_sigma_bkg","CM subtr. noise for groups", 16,0,16);
   TH1F* h_mean_sig = new TH1F("h_mean_sig","CM subtr. signal for groups", 16,0,16);
   TH1F* h_SN = new TH1F("h_SN","Signal to Noise Ratio for groups", 16,0,16);

   new TCanvas;
   btree->Draw("cmsig","Iteration$>=0&&Iteration$<32");
   fitgr(0,0, "Q", "goff", btree->GetHistogram());
   pargaus(a,mean,sigma,"htemp");
   //cout<< "mean = " << mean << " sigma = " << sigma <<endl;
   //-- png("FZ320P_05_MSSD_2-bkg-ex");

   new TCanvas;
   // for (int igroup=0; igroup<16; ++igroup) {
   for (int igroup=0; igroup<15; ++igroup) {
      Int_t ch1 = igroup*32;
      Int_t ch2 = (igroup+1)*32;
      btree->Draw("cmsig",Form("Iteration$>=%d&&Iteration$<%d",ch1,ch2),"");
      fitgr(0,0, "", "", btree->GetHistogram());
      pargaus(a,mean,sigma,"htemp");
      // h_sigma_bkg->Fill(igroup, sigma);
      h_sigma_bkg->SetBinContent(igroup+1, sigma);
   }
   new TCanvas;
   h_sigma_bkg->Draw();
   //-- png("FZ320P_05_MSSD_2-bkg-allgroups");

   // signal
   new TCanvas;
   stree->Draw("cmsig","cmsig>8 &&Iteration$>=0&&Iteration$<32");
   //-- png("FZ320P_05_MSSD_2-sig-ex");

   new TCanvas;
   // for (int igroup=0; igroup<16; ++igroup) {
   for (int igroup=0; igroup<15; ++igroup) {
      Int_t ch1 = igroup*32;
      Int_t ch2 = (igroup+1)*32;
      stree->Draw("cmsig",Form("cmsig>8 &&Iteration$>=%d&&Iteration$<%d",ch1,ch2),"");
      gPad->Update();
      gPad->Modified();
      mean = stree->GetHistogram()->GetMean();
      h_mean_sig->SetBinContent(igroup+1, mean);
   }
   new TCanvas;
   h_mean_sig->Draw();
   //-- png("FZ320P_05_MSSD_2-signal-allgroups");

   for (int igroup=0; igroup<16; ++igroup) {
      Double_t signal32 =  h_mean_sig->GetBinContent(igroup+1);
      Double_t noise32 = h_sigma_bkg->GetBinContent(igroup+1);
      Double_t snr = 0;
      if (noise32 > 0) snr = signal32 / noise32;
      h_SN->SetBinContent(igroup+1, snr);
   }
   new TCanvas;
   h_SN->Draw();
   //-- png("FZ320P_05_MSSD_2-SN-allgroups");
}
コード例 #24
0
ファイル: TPCTOFpid.C プロジェクト: ktf/AliPhysics
TPCTOFpid(const Char_t *filename, Int_t evMax = kMaxInt, Int_t startEv = 0)
{
  
  /* include path for ACLic */
  gSystem->AddIncludePath("-I$ALICE_ROOT/include");
  gSystem->AddIncludePath("-I$ALICE_ROOT/TOF");
  /* load libraries */
  gSystem->Load("libANALYSIS");
  gSystem->Load("libANALYSISalice");
  /* build analysis task class */
  gROOT->LoadMacro("AliAnalysisParticle.cxx+g");
  gROOT->LoadMacro("AliAnalysisEvent.cxx+g");
  gROOT->LoadMacro("AliAnalysisTrack.cxx+g");

  /* open file, get tree and connect */
  TFile *filein = TFile::Open(filename);
  TTree *treein = (TTree *)filein->Get("aodTree");
  printf("got \"aodTree\": %d entries\n", treein->GetEntries());
  AliAnalysisEvent *analysisEvent = new AliAnalysisEvent();
  TClonesArray *analysisTrackArray = new TClonesArray("AliAnalysisTrack");
  AliAnalysisTrack *analysisTrack = NULL;
  treein->SetBranchAddress("AnalysisEvent", &analysisEvent);
  treein->SetBranchAddress("AnalysisTrack", &analysisTrackArray);

  /**************************************************************/
  /*** HISTOS ***************************************************/
  /**************************************************************/

  /* run-time binning */
  for (Int_t ibin = 0; ibin < NsigmaBins + 1; ibin++)
    sigmaBin[ibin] = sigmaMin + ibin * sigmaStep;

  /* THnSparse */
  THnSparse *hTPCTOFpid[AliPID::kSPECIES][kNCharges];
  for (Int_t ipart = 0; ipart < AliPID::kSPECIES; ipart++) {
    for (Int_t icharge = 0; icharge< kNCharges; icharge++) {
      hTPCTOFpid[ipart][icharge] = new THnSparseF(Form("hTPCTOFpid_%s_%s", AliPID::ParticleName(ipart), chargeName[icharge]), "", kNHistoParams, NparamsBins);
      for (Int_t iparam = 0; iparam < kNHistoParams; iparam++) {
	hTPCTOFpid[ipart][icharge]->SetBinEdges(iparam, paramBin[iparam]);
      }
    }
  }

  /**************************************************************/
  /**************************************************************/
  /**************************************************************/

  /* TOF PID response */
  AliTOFPIDResponse tofResponse;
  tofResponse.SetTimeResolution(tofReso);
  /* TPC PID response */
  AliTPCPIDResponse *tpcResponse = AliAnalysisTrack::GetTPCResponse();

  /* start stopwatch */
  TStopwatch timer;
  timer.Start();

  /* loop over events */
  Bool_t hastofpid;
  Int_t charge, index;
  UShort_t dedxN;
  Double_t ptpc, dedx, bethe, deltadedx, dedx_sigma, tpcsignal;
  Double_t p, time, time_sigma, timezero, timezero_sigma, tof, tof_sigma, texp, texp_sigma, deltat, deltat_sigma, tofsignal;
  Double_t tpctofsignal;
  Double_t param[kNHistoParams];
  for (Int_t iev = startEv; iev < treein->GetEntries() && iev < evMax; iev++) {
    /* get event */
    treein->GetEvent(iev);
    if (iev % 100 == 0) printf("iev = %d\n", iev);
    /* check vertex */
    if (!analysisEvent->AcceptVertex()) continue;
    /* check collision candidate */
    if (!analysisEvent->IsCollisionCandidate()) continue;
    /* check centrality quality */
    if (analysisEvent->GetCentralityQuality() != 0.) continue;

    /*** ACCEPTED EVENT ***/

    /* apply time-zero TOF correction */
    analysisEvent->ApplyTimeZeroTOFCorrection();

    /* get centrality */
    param[kCentrality] = analysisEvent->GetCentralityPercentile(AliAnalysisEvent::kCentEst_V0M);

    /* loop over tracks */
    for (Int_t itrk = 0; itrk < analysisTrackArray->GetEntries(); itrk++) {
      /* get track */
      analysisTrack = (AliAnalysisTrack *)analysisTrackArray->At(itrk);
      if (!analysisTrack) continue;
      /* check accepted track */
      if (!analysisTrack->AcceptTrack()) continue;
      /* get charge */
      charge = analysisTrack->GetSign() > 0. ? kPositive : kNegative;

      /*** ACCEPTED TRACK ***/
      
      /* check TOF pid */
      if (!analysisTrack->HasTOFPID() || !analysisTrack->HasTPCPID()) continue;
      
      /*** ACCEPTED TRACK WITH TPC+TOF PID ***/

      /* apply expected time correction */
      analysisTrack->ApplyTOFExpectedTimeCorrection();
      
      /* get track info */
      p = analysisTrack->GetP();
      param[kPt] = analysisTrack->GetPt();

      /* get TPC info */
      dedx = analysisTrack->GetTPCdEdx();
      dedxN = analysisTrack->GetTPCdEdxN();
      ptpc = analysisTrack->GetTPCmomentum();
      
      /* get TOF info */
      time = analysisTrack->GetTOFTime();
      time_sigma = tofReso;
      timezero = analysisEvent->GetTimeZeroTOF(p);
      timezero_sigma = analysisEvent->GetTimeZeroTOFSigma(p);
      tof = time - timezero;
      tof_sigma = TMath::Sqrt(time_sigma * time_sigma + timezero_sigma * timezero_sigma);

      /* loop over particle IDs */
      for (Int_t ipart = 0; ipart < AliPID::kSPECIES; ipart++) {
	
	/* check rapidity */
	if (TMath::Abs(analysisTrack->GetY(AliPID::ParticleMass(ipart))) > 0.5) continue;

	/*** ACCEPTED TRACK WITHIN CORRECT RAPIDITY ***/
	
	/* TPC signal */
	bethe = tpcResponse->GetExpectedSignal(ptpc, ipart);
	deltadedx = dedx - bethe;
	dedx_sigma = tpcResponse->GetExpectedSigma(ptpc, dedxN, ipart);
	tpcsignal = deltadedx / dedx_sigma;
	param[kTPCsignal] = tpcsignal;
	
	/* TOF expected time */
	texp = analysisTrack->GetTOFExpTime(ipart);
	texp_sigma = analysisTrack->GetTOFExpTimeSigma(ipart);
	
	/* TOF signal */
	deltat = tof - texp;
	deltat_sigma = TMath::Sqrt(tof_sigma * tof_sigma + texp_sigma * texp_sigma);
	tofsignal = deltat / deltat_sigma;
	param[kTOFsignal] = tofsignal;

	/* TPC+TOF signal */
	tpctofsignal = TMath::Sqrt(tpcsignal * tpcsignal + tofsignal * tofsignal);
	param[kTPCTOFsignal] = tpctofsignal;

	/* fill histo */
	hTPCTOFpid[ipart][charge]->Fill(param);

      } /* end of loop over particle IDs */      
    } /* end of loop over tracks */
  } /* end of loop over events */
  
  /* start stopwatch */
  timer.Stop();
  timer.Print();
  
  /* output */
  TFile *fileout = TFile::Open(Form("TPCTOFpid.%s", filename), "RECREATE");
  for (Int_t ipart = 0; ipart < AliPID::kSPECIES; ipart++) {
    for (Int_t icharge = 0; icharge < kNCharges; icharge++) {
      hTPCTOFpid[ipart][icharge]->Write();
    }
  }
  fileout->Close();
  
}
コード例 #25
0
ファイル: pedestals.cpp プロジェクト: UCNA/ParallelAnalyzer
int main(int argc, char *argv[])
{
  cout.setf(ios::fixed, ios::floatfield);
  cout.precision(12);

  // Open output ntuple
  char tempOut[500];
  sprintf(tempOut, "/extern/UCNA/pedestals_MB/pedestals_%s.root", argv[1]);
  TFile *fileOut = new TFile(tempOut,"RECREATE");

  // Define output histograms
  TH1F *his11 = new TH1F("his11", "", 4000,0.5,4000.5); // East PMT #1
  TH1F *his12 = new TH1F("his12", "", 4000,0.5,4000.5); // East PMT #2
  TH1F *his13 = new TH1F("his13", "", 4000,0.5,4000.5); // East PMT #3
  TH1F *his14 = new TH1F("his14", "", 4000,0.5,4000.5); // East PMT #4
  TH1F *his15 = new TH1F("his15", "", 4000,0.5,4000.5); // West PMT #1
  TH1F *his16 = new TH1F("his16", "", 4000,0.5,4000.5); // West PMT #2
  TH1F *his17 = new TH1F("his17", "", 4000,0.5,4000.5); // West PMT #3
  TH1F *his18 = new TH1F("his18", "", 4000,0.5,4000.5); // West PMT #4

  TH1F *his101 = new TH1F("his101", "", 4000,0.5,4000.5); // Pdc2[0]
  TH1F *his102 = new TH1F("his102", "", 4000,0.5,4000.5); // Pdc2[1]
  TH1F *his103 = new TH1F("his103", "", 4000,0.5,4000.5); // Pdc2[2]
  TH1F *his104 = new TH1F("his104", "", 4000,0.5,4000.5); // Pdc2[3]
  TH1F *his105 = new TH1F("his105", "", 4000,0.5,4000.5); // Pdc2[4]
  TH1F *his106 = new TH1F("his106", "", 4000,0.5,4000.5); // Pdc2[5]
  TH1F *his107 = new TH1F("his107", "", 4000,0.5,4000.5); // Pdc2[6]
  TH1F *his108 = new TH1F("his108", "", 4000,0.5,4000.5); // Pdc2[7]
  TH1F *his109 = new TH1F("his109", "", 4000,0.5,4000.5); // Pdc2[8]
  TH1F *his110 = new TH1F("his110", "", 4000,0.5,4000.5); // Pdc2[9]
  TH1F *his111 = new TH1F("his111", "", 4000,0.5,4000.5); // Pdc2[10]
  TH1F *his112 = new TH1F("his112", "", 4000,0.5,4000.5); // Pdc2[11]
  TH1F *his113 = new TH1F("his113", "", 4000,0.5,4000.5); // Pdc2[12]
  TH1F *his114 = new TH1F("his114", "", 4000,0.5,4000.5); // Pdc2[13]
  TH1F *his115 = new TH1F("his115", "", 4000,0.5,4000.5); // Pdc2[14]
  TH1F *his116 = new TH1F("his116", "", 4000,0.5,4000.5); // Pdc2[15]
  TH1F *his117 = new TH1F("his117", "", 4000,0.5,4000.5); // Pdc2[16]
  TH1F *his118 = new TH1F("his118", "", 4000,0.5,4000.5); // Pdc2[17]
  TH1F *his119 = new TH1F("his119", "", 4000,0.5,4000.5); // Pdc2[18]
  TH1F *his120 = new TH1F("his120", "", 4000,0.5,4000.5); // Pdc2[19]
  TH1F *his121 = new TH1F("his121", "", 4000,0.5,4000.5); // Pdc2[20]
  TH1F *his122 = new TH1F("his122", "", 4000,0.5,4000.5); // Pdc2[21]
  TH1F *his123 = new TH1F("his123", "", 4000,0.5,4000.5); // Pdc2[22]
  TH1F *his124 = new TH1F("his124", "", 4000,0.5,4000.5); // Pdc2[23]
  TH1F *his125 = new TH1F("his125", "", 4000,0.5,4000.5); // Pdc2[24]
  TH1F *his126 = new TH1F("his126", "", 4000,0.5,4000.5); // Pdc2[25]
  TH1F *his127 = new TH1F("his127", "", 4000,0.5,4000.5); // Pdc2[26]
  TH1F *his128 = new TH1F("his128", "", 4000,0.5,4000.5); // Pdc2[27]
  TH1F *his129 = new TH1F("his129", "", 4000,0.5,4000.5); // Pdc2[28]
  TH1F *his130 = new TH1F("his130", "", 4000,0.5,4000.5); // Pdc2[29]
  TH1F *his131 = new TH1F("his131", "", 4000,0.5,4000.5); // Pdc2[30]
  TH1F *his132 = new TH1F("his132", "", 4000,0.5,4000.5); // Pdc2[31]

  TH1F *his201 = new TH1F("his201", "", 4000,0.5,4000.5); // Padc2[0]
  TH1F *his202 = new TH1F("his202", "", 4000,0.5,4000.5); // Padc2[1]
  TH1F *his203 = new TH1F("his203", "", 4000,0.5,4000.5); // Padc2[2]
  TH1F *his204 = new TH1F("his204", "", 4000,0.5,4000.5); // Padc2[3]
  TH1F *his205 = new TH1F("his205", "", 4000,0.5,4000.5); // Padc2[4]
  TH1F *his206 = new TH1F("his206", "", 4000,0.5,4000.5); // Padc2[5]
  TH1F *his207 = new TH1F("his207", "", 4000,0.5,4000.5); // Padc2[6]
  TH1F *his208 = new TH1F("his208", "", 4000,0.5,4000.5); // Padc2[7]
  TH1F *his209 = new TH1F("his209", "", 4000,0.5,4000.5); // Padc2[8]
  TH1F *his210 = new TH1F("his210", "", 4000,0.5,4000.5); // Padc2[9]
  TH1F *his211 = new TH1F("his211", "", 4000,0.5,4000.5); // Padc2[10]
  TH1F *his212 = new TH1F("his212", "", 4000,0.5,4000.5); // Padc2[11]
  TH1F *his213 = new TH1F("his213", "", 4000,0.5,4000.5); // Padc2[12]
  TH1F *his214 = new TH1F("his214", "", 4000,0.5,4000.5); // Padc2[13]
  TH1F *his215 = new TH1F("his215", "", 4000,0.5,4000.5); // Padc2[14]
  TH1F *his216 = new TH1F("his216", "", 4000,0.5,4000.5); // Padc2[15]
  TH1F *his217 = new TH1F("his217", "", 4000,0.5,4000.5); // Padc2[16]
  TH1F *his218 = new TH1F("his218", "", 4000,0.5,4000.5); // Padc2[17]
  TH1F *his219 = new TH1F("his219", "", 4000,0.5,4000.5); // Padc2[18]
  TH1F *his220 = new TH1F("his220", "", 4000,0.5,4000.5); // Padc2[19]
  TH1F *his221 = new TH1F("his221", "", 4000,0.5,4000.5); // Padc2[20]
  TH1F *his222 = new TH1F("his222", "", 4000,0.5,4000.5); // Padc2[21]
  TH1F *his223 = new TH1F("his223", "", 4000,0.5,4000.5); // Padc2[22]
  TH1F *his224 = new TH1F("his224", "", 4000,0.5,4000.5); // Padc2[23]
  TH1F *his225 = new TH1F("his225", "", 4000,0.5,4000.5); // Padc2[24]
  TH1F *his226 = new TH1F("his226", "", 4000,0.5,4000.5); // Padc2[25]
  TH1F *his227 = new TH1F("his227", "", 4000,0.5,4000.5); // Padc2[26]
  TH1F *his228 = new TH1F("his228", "", 4000,0.5,4000.5); // Padc2[27]
  TH1F *his229 = new TH1F("his229", "", 4000,0.5,4000.5); // Padc2[28]
  TH1F *his230 = new TH1F("his230", "", 4000,0.5,4000.5); // Padc2[29]
  TH1F *his231 = new TH1F("his231", "", 4000,0.5,4000.5); // Padc2[30]
  TH1F *his232 = new TH1F("his232", "", 4000,0.5,4000.5); // Padc2[31]
  
  TH1F *his300 = new TH1F("his300", "", 4000,0.5,4000.5); // Pdc30
  TH1F *his301 = new TH1F("his301", "", 4000,0.5,4000.5); // Pdc34

  // Open input ntuple
  char tempIn[500];
  sprintf(tempIn, "/extern/mabrow05/ucna/rawdata/full%s.root", argv[1]);

  TFile *fileIn = new TFile(tempIn, "READ");
  TTree *Tin = (TTree*)(fileIn->Get("h1"));

  // Variables
  Tin->SetBranchAddress("Sis00",  &Sis00);

  Tin->SetBranchAddress("Qadc0",  &Qadc[0]);
  Tin->SetBranchAddress("Qadc1",  &Qadc[1]);
  Tin->SetBranchAddress("Qadc2",  &Qadc[2]);
  Tin->SetBranchAddress("Qadc3",  &Qadc[3]);
  Tin->SetBranchAddress("Qadc4",  &Qadc[4]);
  Tin->SetBranchAddress("Qadc5",  &Qadc[5]);
  Tin->SetBranchAddress("Qadc6",  &Qadc[6]);
  Tin->SetBranchAddress("Qadc7",  &Qadc[7]);

  Tin->SetBranchAddress("Pdc20",  &Pdc2[0]);
  Tin->SetBranchAddress("Pdc21",  &Pdc2[1]);
  Tin->SetBranchAddress("Pdc22",  &Pdc2[2]);
  Tin->SetBranchAddress("Pdc23",  &Pdc2[3]);
  Tin->SetBranchAddress("Pdc24",  &Pdc2[4]);
  Tin->SetBranchAddress("Pdc25",  &Pdc2[5]);
  Tin->SetBranchAddress("Pdc26",  &Pdc2[6]);
  Tin->SetBranchAddress("Pdc27",  &Pdc2[7]);
  Tin->SetBranchAddress("Pdc28",  &Pdc2[8]);
  Tin->SetBranchAddress("Pdc29",  &Pdc2[9]);
  Tin->SetBranchAddress("Pdc210", &Pdc2[10]);
  Tin->SetBranchAddress("Pdc211", &Pdc2[11]);
  Tin->SetBranchAddress("Pdc212", &Pdc2[12]);
  Tin->SetBranchAddress("Pdc213", &Pdc2[13]);
  Tin->SetBranchAddress("Pdc214", &Pdc2[14]);
  Tin->SetBranchAddress("Pdc215", &Pdc2[15]);
  Tin->SetBranchAddress("Pdc216", &Pdc2[16]);
  Tin->SetBranchAddress("Pdc217", &Pdc2[17]);
  Tin->SetBranchAddress("Pdc218", &Pdc2[18]);
  Tin->SetBranchAddress("Pdc219", &Pdc2[19]);
  Tin->SetBranchAddress("Pdc220", &Pdc2[20]);
  Tin->SetBranchAddress("Pdc221", &Pdc2[21]);
  Tin->SetBranchAddress("Pdc222", &Pdc2[22]);
  Tin->SetBranchAddress("Pdc223", &Pdc2[23]);
  Tin->SetBranchAddress("Pdc224", &Pdc2[24]);
  Tin->SetBranchAddress("Pdc225", &Pdc2[25]);
  Tin->SetBranchAddress("Pdc226", &Pdc2[26]);
  Tin->SetBranchAddress("Pdc227", &Pdc2[27]);
  Tin->SetBranchAddress("Pdc228", &Pdc2[28]);
  Tin->SetBranchAddress("Pdc229", &Pdc2[29]);
  Tin->SetBranchAddress("Pdc230", &Pdc2[30]);
  Tin->SetBranchAddress("Pdc231", &Pdc2[31]);

  Tin->SetBranchAddress("Padc0",  &Padc[0]);
  Tin->SetBranchAddress("Padc1",  &Padc[1]);
  Tin->SetBranchAddress("Padc2",  &Padc[2]);
  Tin->SetBranchAddress("Padc3",  &Padc[3]);
  Tin->SetBranchAddress("Padc4",  &Padc[4]);
  Tin->SetBranchAddress("Padc5",  &Padc[5]);
  Tin->SetBranchAddress("Padc6",  &Padc[6]);
  Tin->SetBranchAddress("Padc7",  &Padc[7]);
  Tin->SetBranchAddress("Padc8",  &Padc[8]);
  Tin->SetBranchAddress("Padc9",  &Padc[9]);
  Tin->SetBranchAddress("Padc10", &Padc[10]);
  Tin->SetBranchAddress("Padc11", &Padc[11]);
  Tin->SetBranchAddress("Padc12", &Padc[12]);
  Tin->SetBranchAddress("Padc13", &Padc[13]);
  Tin->SetBranchAddress("Padc14", &Padc[14]);
  Tin->SetBranchAddress("Padc15", &Padc[15]);
  Tin->SetBranchAddress("Padc16", &Padc[16]);
  Tin->SetBranchAddress("Padc17", &Padc[17]);
  Tin->SetBranchAddress("Padc18", &Padc[18]);
  Tin->SetBranchAddress("Padc19", &Padc[19]);
  Tin->SetBranchAddress("Padc20", &Padc[20]);
  Tin->SetBranchAddress("Padc21", &Padc[21]);
  Tin->SetBranchAddress("Padc22", &Padc[22]);
  Tin->SetBranchAddress("Padc23", &Padc[23]);
  Tin->SetBranchAddress("Padc24", &Padc[24]);
  Tin->SetBranchAddress("Padc25", &Padc[25]);
  Tin->SetBranchAddress("Padc26", &Padc[26]);
  Tin->SetBranchAddress("Padc27", &Padc[27]);
  Tin->SetBranchAddress("Padc28", &Padc[28]);
  Tin->SetBranchAddress("Padc29", &Padc[29]);
  Tin->SetBranchAddress("Padc30", &Padc[30]);
  Tin->SetBranchAddress("Padc31", &Padc[31]);

  Tin->SetBranchAddress("S83028", &S83028);

  Tin->SetBranchAddress("Pdc30", &Pdc30);
  Tin->SetBranchAddress("Pdc34", &Pdc34);
  
  int nEvents = Tin->GetEntries();
  cout << "Run " << argv[1] << " ..." << endl;
  cout << "... Processing nEvents = " << nEvents << endl;

  int nEastPed = 0;
  int nWestPed = 0;

  // Loop over events
  for (int i=0; i<nEvents; i++) {
    Tin->GetEvent(i);
    int iSis00 = (int) Sis00;

    bool triggerEast = false;
    bool triggerWest = false;
    bool triggerUCN  = false;

    if (iSis00 == 1) triggerEast = true;
    if (iSis00 == 2) triggerWest = true;
    if (iSis00 == 260 || iSis00 == 516 || iSis00 == 1028 || iSis00 == 2052) triggerUCN = true;

    if (triggerWest || triggerUCN) {
      his11->Fill(Qadc[0]);
      his12->Fill(Qadc[1]);
      his13->Fill(Qadc[2]);
      his14->Fill(Qadc[3]);

      his101->Fill(Pdc2[0]);
      his102->Fill(Pdc2[1]);
      his103->Fill(Pdc2[2]);
      his104->Fill(Pdc2[3]);
      his105->Fill(Pdc2[4]);
      his106->Fill(Pdc2[5]);
      his107->Fill(Pdc2[6]);
      his108->Fill(Pdc2[7]);
      his109->Fill(Pdc2[8]);
      his110->Fill(Pdc2[9]);
      his111->Fill(Pdc2[10]);
      his112->Fill(Pdc2[11]);
      his113->Fill(Pdc2[12]);
      his114->Fill(Pdc2[13]);
      his115->Fill(Pdc2[14]);
      his116->Fill(Pdc2[15]);
      his117->Fill(Pdc2[16]);
      his118->Fill(Pdc2[17]);
      his119->Fill(Pdc2[18]);
      his120->Fill(Pdc2[19]);
      his121->Fill(Pdc2[20]);
      his122->Fill(Pdc2[21]);
      his123->Fill(Pdc2[22]);
      his124->Fill(Pdc2[23]);
      his125->Fill(Pdc2[24]);
      his126->Fill(Pdc2[25]);
      his127->Fill(Pdc2[26]);
      his128->Fill(Pdc2[27]);
      his129->Fill(Pdc2[28]);
      his130->Fill(Pdc2[29]);
      his131->Fill(Pdc2[30]);
      his132->Fill(Pdc2[31]);

      his300->Fill(Pdc30);

      nEastPed++;
    }

    if (triggerEast || triggerUCN) {
      his15->Fill(Qadc[4]);
      his16->Fill(Qadc[5]);
      his17->Fill(Qadc[6]);
      his18->Fill(Qadc[7]);

      his201->Fill(Padc[0]);
      his202->Fill(Padc[1]);
      his203->Fill(Padc[2]);
      his204->Fill(Padc[3]);
      his205->Fill(Padc[4]);
      his206->Fill(Padc[5]);
      his207->Fill(Padc[6]);
      his208->Fill(Padc[7]);
      his209->Fill(Padc[8]);
      his210->Fill(Padc[9]);
      his211->Fill(Padc[10]);
      his212->Fill(Padc[11]);
      his213->Fill(Padc[12]);
      his214->Fill(Padc[13]);
      his215->Fill(Padc[14]);
      his216->Fill(Padc[15]);
      his217->Fill(Padc[16]);
      his218->Fill(Padc[17]);
      his219->Fill(Padc[18]);
      his220->Fill(Padc[19]);
      his221->Fill(Padc[20]);
      his222->Fill(Padc[21]);
      his223->Fill(Padc[22]);
      his224->Fill(Padc[23]);
      his225->Fill(Padc[24]);
      his226->Fill(Padc[25]);
      his227->Fill(Padc[26]);
      his228->Fill(Padc[27]);
      his229->Fill(Padc[28]);
      his230->Fill(Padc[29]);
      his231->Fill(Padc[30]);
      his232->Fill(Padc[31]);

      his301->Fill(Pdc34);

      nWestPed++;
    }

  }

  // Extract mean values of pedestals
  for (int i=0; i<8; i++) {
    pedQadc[i] = 0.;
  }
  

  for (int i=0; i<500; i++) {
    pedQadc[0] += (his11->GetBinCenter(i+1)) * (his11->GetBinContent(i+1));
    pedQadc[1] += (his12->GetBinCenter(i+1)) * (his12->GetBinContent(i+1));
    pedQadc[2] += (his13->GetBinCenter(i+1)) * (his13->GetBinContent(i+1));
    pedQadc[3] += (his14->GetBinCenter(i+1)) * (his14->GetBinContent(i+1));
    pedQadc[4] += (his15->GetBinCenter(i+1)) * (his15->GetBinContent(i+1));
    pedQadc[5] += (his16->GetBinCenter(i+1)) * (his16->GetBinContent(i+1));
    pedQadc[6] += (his17->GetBinCenter(i+1)) * (his17->GetBinContent(i+1));
    pedQadc[7] += (his18->GetBinCenter(i+1)) * (his18->GetBinContent(i+1));

    pedPdc2[0]  += (his101->GetBinCenter(i+1)) * (his101->GetBinContent(i+1));
    pedPdc2[1]  += (his102->GetBinCenter(i+1)) * (his102->GetBinContent(i+1));
    pedPdc2[2]  += (his103->GetBinCenter(i+1)) * (his103->GetBinContent(i+1));
    pedPdc2[3]  += (his104->GetBinCenter(i+1)) * (his104->GetBinContent(i+1));
    pedPdc2[4]  += (his105->GetBinCenter(i+1)) * (his105->GetBinContent(i+1));
    pedPdc2[5]  += (his106->GetBinCenter(i+1)) * (his106->GetBinContent(i+1));
    pedPdc2[6]  += (his107->GetBinCenter(i+1)) * (his107->GetBinContent(i+1));
    pedPdc2[7]  += (his108->GetBinCenter(i+1)) * (his108->GetBinContent(i+1));
    pedPdc2[8]  += (his109->GetBinCenter(i+1)) * (his109->GetBinContent(i+1));
    pedPdc2[9]  += (his110->GetBinCenter(i+1)) * (his110->GetBinContent(i+1));
    pedPdc2[10] += (his111->GetBinCenter(i+1)) * (his111->GetBinContent(i+1));
    pedPdc2[11] += (his112->GetBinCenter(i+1)) * (his112->GetBinContent(i+1));
    pedPdc2[12] += (his113->GetBinCenter(i+1)) * (his113->GetBinContent(i+1));
    pedPdc2[13] += (his114->GetBinCenter(i+1)) * (his114->GetBinContent(i+1));
    pedPdc2[14] += (his115->GetBinCenter(i+1)) * (his115->GetBinContent(i+1));
    pedPdc2[15] += (his116->GetBinCenter(i+1)) * (his116->GetBinContent(i+1));
    pedPdc2[16] += (his117->GetBinCenter(i+1)) * (his117->GetBinContent(i+1));
    pedPdc2[17] += (his118->GetBinCenter(i+1)) * (his118->GetBinContent(i+1));
    pedPdc2[18] += (his119->GetBinCenter(i+1)) * (his119->GetBinContent(i+1));
    pedPdc2[19] += (his120->GetBinCenter(i+1)) * (his120->GetBinContent(i+1));
    pedPdc2[20] += (his121->GetBinCenter(i+1)) * (his121->GetBinContent(i+1));
    pedPdc2[21] += (his122->GetBinCenter(i+1)) * (his122->GetBinContent(i+1));
    pedPdc2[22] += (his123->GetBinCenter(i+1)) * (his123->GetBinContent(i+1));
    pedPdc2[23] += (his124->GetBinCenter(i+1)) * (his124->GetBinContent(i+1));
    pedPdc2[24] += (his125->GetBinCenter(i+1)) * (his125->GetBinContent(i+1));
    pedPdc2[25] += (his126->GetBinCenter(i+1)) * (his126->GetBinContent(i+1));
    pedPdc2[26] += (his127->GetBinCenter(i+1)) * (his127->GetBinContent(i+1));
    pedPdc2[27] += (his128->GetBinCenter(i+1)) * (his128->GetBinContent(i+1));
    pedPdc2[28] += (his129->GetBinCenter(i+1)) * (his129->GetBinContent(i+1));
    pedPdc2[29] += (his130->GetBinCenter(i+1)) * (his130->GetBinContent(i+1));
    pedPdc2[30] += (his131->GetBinCenter(i+1)) * (his131->GetBinContent(i+1));
    pedPdc2[31] += (his132->GetBinCenter(i+1)) * (his132->GetBinContent(i+1));

    pedPadc[0]  += (his201->GetBinCenter(i+1)) * (his201->GetBinContent(i+1));
    pedPadc[1]  += (his202->GetBinCenter(i+1)) * (his202->GetBinContent(i+1));
    pedPadc[2]  += (his203->GetBinCenter(i+1)) * (his203->GetBinContent(i+1));
    pedPadc[3]  += (his204->GetBinCenter(i+1)) * (his204->GetBinContent(i+1));
    pedPadc[4]  += (his205->GetBinCenter(i+1)) * (his205->GetBinContent(i+1));
    pedPadc[5]  += (his206->GetBinCenter(i+1)) * (his206->GetBinContent(i+1));
    pedPadc[6]  += (his207->GetBinCenter(i+1)) * (his207->GetBinContent(i+1));
    pedPadc[7]  += (his208->GetBinCenter(i+1)) * (his208->GetBinContent(i+1));
    pedPadc[8]  += (his209->GetBinCenter(i+1)) * (his209->GetBinContent(i+1));
    pedPadc[9]  += (his210->GetBinCenter(i+1)) * (his210->GetBinContent(i+1));
    pedPadc[10] += (his211->GetBinCenter(i+1)) * (his211->GetBinContent(i+1));
    pedPadc[11] += (his212->GetBinCenter(i+1)) * (his212->GetBinContent(i+1));
    pedPadc[12] += (his213->GetBinCenter(i+1)) * (his213->GetBinContent(i+1));
    pedPadc[13] += (his214->GetBinCenter(i+1)) * (his214->GetBinContent(i+1));
    pedPadc[14] += (his215->GetBinCenter(i+1)) * (his215->GetBinContent(i+1));
    pedPadc[15] += (his216->GetBinCenter(i+1)) * (his216->GetBinContent(i+1));
    pedPadc[16] += (his217->GetBinCenter(i+1)) * (his217->GetBinContent(i+1));
    pedPadc[17] += (his218->GetBinCenter(i+1)) * (his218->GetBinContent(i+1));
    pedPadc[18] += (his219->GetBinCenter(i+1)) * (his219->GetBinContent(i+1));
    pedPadc[19] += (his220->GetBinCenter(i+1)) * (his220->GetBinContent(i+1));
    pedPadc[20] += (his221->GetBinCenter(i+1)) * (his221->GetBinContent(i+1));
    pedPadc[21] += (his222->GetBinCenter(i+1)) * (his222->GetBinContent(i+1));
    pedPadc[22] += (his223->GetBinCenter(i+1)) * (his223->GetBinContent(i+1));
    pedPadc[23] += (his224->GetBinCenter(i+1)) * (his224->GetBinContent(i+1));
    pedPadc[24] += (his225->GetBinCenter(i+1)) * (his225->GetBinContent(i+1));
    pedPadc[25] += (his226->GetBinCenter(i+1)) * (his226->GetBinContent(i+1));
    pedPadc[26] += (his227->GetBinCenter(i+1)) * (his227->GetBinContent(i+1));
    pedPadc[27] += (his228->GetBinCenter(i+1)) * (his228->GetBinContent(i+1));
    pedPadc[28] += (his229->GetBinCenter(i+1)) * (his229->GetBinContent(i+1));
    pedPadc[29] += (his230->GetBinCenter(i+1)) * (his230->GetBinContent(i+1));
    pedPadc[30] += (his231->GetBinCenter(i+1)) * (his231->GetBinContent(i+1));
    pedPadc[31] += (his232->GetBinCenter(i+1)) * (his232->GetBinContent(i+1));

    pedPdc30 += (his300->GetBinCenter(i+1)) * (his300->GetBinContent(i+1));
    pedPdc34 += (his301->GetBinCenter(i+1)) * (his301->GetBinContent(i+1));
  }

  for (int i=0; i<4; i++) {
    pedQadc[i] = pedQadc[i] / ((double) nEastPed);
    //cout << pedQadc[i] << endl;
  }
  for (int i=4; i<8; i++) {
    pedQadc[i] = pedQadc[i] / ((double) nWestPed);
    //cout << pedQadc[i] << endl;
  }
  for (int i=0; i<32; i++) {
    pedPdc2[i] = pedPdc2[i] / ((double) nEastPed);
    pedPadc[i] = pedPadc[i] / ((double) nWestPed);
  }
  pedPdc30 = pedPdc30/((double) nEastPed);
  pedPdc34 = pedPdc34/((double) nWestPed);

  // Write pedestals to file
  char tempPedFile[500];
  sprintf(tempPedFile, "%s/pedestals_%s.dat", getenv("PEDESTALS"),argv[1]);
  ofstream outPedFile(tempPedFile);

  for (int i=0; i<8; i++) {
    outPedFile << argv[1] << " " << pedQadc[i] << endl;
  }
  for (int i=0; i<32; i++) {
    outPedFile << argv[1] << " " << pedPdc2[i] << endl;
  }
  for (int i=0; i<32; i++) {
    outPedFile << argv[1] << " " << pedPadc[i] << endl;
  }
  outPedFile << argv[1] << " " << pedPdc30 << endl;
  outPedFile << argv[1] << " " << pedPdc34 << endl;

  // Write output ntuple
  fileOut->Write();
  fileOut->Close();

  return 0;
}
コード例 #26
0
ファイル: CheckSDDInESD.C プロジェクト: alisw/AliRoot
void CheckSDDInESD(TString filename="AliESDs.root", Int_t optTracks=kAll){


  TFile* esdFile = TFile::Open(filename.Data());
  if (!esdFile || !esdFile->IsOpen()) {
    printf("Error in opening ESD file");
    return;
  }

  AliESDEvent * esd = new AliESDEvent;
  TTree* tree = (TTree*) esdFile->Get("esdTree");
  if (!tree) {
    printf("Error: no ESD tree found");
    return;
  }
  esd->ReadFromTree(tree);
  TH1F* hpt=new TH1F("hpt","",100,0.,10.);
  TH1F* hphi=new TH1F("hphi","",100,-1,1);
  TH1F* hlam=new TH1F("hlam","",100,-2.,2.);
  TH1F* halpha=new TH1F("halpha","",100,-7,7);
  TH1F* hitscl=new TH1F("hitscl","",7,-0.5,6.5);
  TH1F* htpccl=new TH1F("htpccl","",200,-0.5,199.5);
  TH1F* hitsmap=new TH1F("hitsmap","",64,-0.5,63.5);
  TH1F* hclulay=new TH1F("hclulay","",7,-1.5,5.5);

  TH1F* hvx=new TH1F("hvx","",100,-1.,1.);
  TH1F* hvy=new TH1F("hvy","",100,-1.,1.);
  TH1F* hvz=new TH1F("hvz","",100,-20.,20.);
  TH1F* hdedx3=new TH1F("hdedx3","",100,0.,300.);
  TH1F* hdedx4=new TH1F("hdedx4","",100,0.,300.);
  TH1F* hdedx5=new TH1F("hdedx5","",100,0.,300.);
  TH1F* hdedx6=new TH1F("hdedx6","",100,0.,300.);
  TH1F* hStatus=new TH1F("hStatus","",11,-1.5,9.5);


  // -- Local coordinates


  // -- Module histos

  TH1F* hAllPMod  = new TH1F("hAllPmod","Crossing Tracks vs. Module",260,239.5,499.5);
  TH1F* hGoodPMod  = new TH1F("hGoodPmod","PointsAssocToTrack per Module",260,239.5,499.5);
  TH1F* hBadRegMod  = new TH1F("hBadRegmod","Tracks in BadRegion per Module",260,239.5,499.5);
  TH1F* hMissPMod  = new TH1F("hMissPmod","Missing Points per Module",260,239.5,499.5);
  TH1F* hSkippedMod  = new TH1F("hSkippedmod","Tracks in Skipped Module",260,239.5,499.5);
  TH1F* hOutAccMod  = new TH1F("hOutAccmod","Tracks outside zAcc per Module",260,239.5,499.5);
  TH1F* hNoRefitMod  = new TH1F("hNoRefitmod","Points rejected in refit per Module",260,239.5,499.5);

  TH1F* hAllPXloc  = new TH1F("hAllPxloc","Crossing Tracks vs. Xloc",75, -3.75, 3.75);
  TH1F* hGoodPXloc  = new TH1F("hGoodPxloc","PointsAssocToTrack vs. Xloc",75, -3.75, 3.75);
  TH1F* hBadRegXloc  = new TH1F("hBadRegxloc","Tracks in BadRegion vs. Xloc",75, -3.75, 3.75);
  TH1F* hMissPXloc  = new TH1F("hMissPxloc","Missing Points vs. Xloc",75, -3.75, 3.75);
  TH1F* hAllPZloc  = new TH1F("hAllPzloc","Crossing Tracks vs. Zloc",77, -3.85, 3.85);
  TH1F* hGoodPZloc  = new TH1F("hGoodPzloc","PointsAssocToTrack vs. Zloc",77, -3.85, 3.85);
  TH1F* hBadRegZloc  = new TH1F("hBadRegzloc","Tracks in BadRegion vs. Zloc",77, -3.85, 3.85);
  TH1F* hMissPZloc  = new TH1F("hMissPzloc","Missing Points vs. Zloc",77, -3.85, 3.85);
  TH2F* hdEdxVsMod=new TH2F("hdEdxVsMod","dE/dx vs. mod",260,239.5,499.5,100,0.,500.);

  gStyle->SetPalette(1);
  

  for (Int_t iEvent = 0; iEvent < tree->GetEntries(); iEvent++) {
    tree->GetEvent(iEvent);
    if (!esd) {
      printf("Error: no ESD object found for event %d", iEvent);
      return;
    }
    cout<<"-------- Event "<<iEvent<<endl;
    printf(" Tracks # = %d\n",esd->GetNumberOfTracks());
    const AliESDVertex *spdv=esd->GetVertex();
    printf(" SPD Primary Vertex in %f %f %f with %d contributors\n",spdv->GetX(),spdv->GetY(),spdv->GetZ(),spdv->GetNContributors());
    const AliESDVertex *trkv=esd->GetPrimaryVertex();
    printf(" Track Primary Vertex with %d contributors\n",trkv->GetNContributors());
    if(spdv->IsFromVertexer3D()){
      hvx->Fill(spdv->GetX());
      hvy->Fill(spdv->GetY());
      hvz->Fill(spdv->GetZ());
    }
    Double_t itss[4];
    for (Int_t iTrack = 0; iTrack < esd->GetNumberOfTracks(); iTrack++) {
      AliESDtrack* track = esd->GetTrack(iTrack);
      Int_t nITSclus=track->GetNcls(0);
      UChar_t clumap=track->GetITSClusterMap();
      Int_t nPointsForPid=0;
      for(Int_t i=2; i<6; i++){
	if(clumap&(1<<i)) ++nPointsForPid;
      }
      //      track->PropagateTo(4.,5.);
      htpccl->Fill(track->GetNcls(1));
      ULong64_t status=track->GetStatus();
      Bool_t tpcin=0;
      hStatus->Fill(-1.);
      if(status & AliESDtrack::kTPCin){
	tpcin=1;
	hStatus->Fill(0.);
      }
      if(status & AliESDtrack::kTPCout){
	hStatus->Fill(1.);
      }
      if(status & AliESDtrack::kTPCrefit){
	hStatus->Fill(2.);
      }
      Bool_t itsin=0;
      if(status & AliESDtrack::kITSin){
	itsin=1;
	hStatus->Fill(3.);
      }
      if(status & AliESDtrack::kITSout){
	hStatus->Fill(4.);
      }
      if(status & AliESDtrack::kITSrefit){
	hStatus->Fill(5.);
      }
      if(!tpcin && itsin){
	hStatus->Fill(6.);
      }
      if(status & AliESDtrack::kITSpureSA){
	hStatus->Fill(7.);
      }

      if(status & AliESDtrack::kITSrefit){
	if((optTracks==kTPCITS) && !(status & AliESDtrack::kTPCin)) continue;
	if((optTracks==kITSsa) && (status & AliESDtrack::kTPCin)) continue;
	if((optTracks==kITSsa) && (status & AliESDtrack::kITSpureSA)) continue;
	if((optTracks==kITSpureSA) && (status & AliESDtrack::kITSpureSA)) continue;

	 track->GetITSdEdxSamples(itss);
	//	printf("Track %d (label %d) in ITS with %d clusters clumap %d pointspid= %d\n",iTrack,track->GetLabel(),nITSclus,clumap,nPointsForPid);
	//printf("   dedx=%f %f %f %f\n",itss[0],itss[1],itss[2],itss[3]);
	hitscl->Fill(nITSclus);
	hdedx3->Fill(itss[0]);
	hdedx4->Fill(itss[1]);
	hdedx5->Fill(itss[2]);
	hdedx6->Fill(itss[3]);
	hitsmap->Fill(clumap);
	hclulay->Fill(-1.);
	for(Int_t iLay=0;iLay<6;iLay++){
	  if(clumap&1<<iLay) hclulay->Fill(iLay);
	}
	hpt->Fill(track->Pt());
	hphi->Fill(TMath::ASin(track->GetSnp()));
	hlam->Fill(TMath::ATan(track->GetTgl()));
	halpha->Fill(track->GetAlpha());
	Int_t iMod,status;
	Float_t xloc,zloc;
	for(Int_t iLay=2; iLay<=3; iLay++){
	  Bool_t ok=track->GetITSModuleIndexInfo(iLay,iMod,status,xloc,zloc);
	  if(ok){
	    iMod+=240;
	    hAllPMod->Fill(iMod);
	    hAllPXloc->Fill(xloc);
	    hAllPZloc->Fill(zloc);
	    if(status==1){
	      hGoodPMod->Fill(iMod);
	      hGoodPXloc->Fill(xloc);
	      hGoodPZloc->Fill(zloc);
	      if(track->Pt()>1.) hdEdxVsMod->Fill(iMod,itss[iLay-2]);
	    }
	    else if(status==2){ 
	      hBadRegMod->Fill(iMod);
	      hBadRegXloc->Fill(xloc);
	      hBadRegZloc->Fill(zloc);
	    }
	    else if(status==3) hSkippedMod->Fill(iMod);
	    else if(status==4) hOutAccMod->Fill(iMod);
	    else if(status==5){
	      hMissPMod->Fill(iMod);
	      hMissPXloc->Fill(xloc);
	      hMissPZloc->Fill(zloc);
	    }
	    else if(status==6) hNoRefitMod->Fill(iMod);
	  }
	}
      }
    }
  }
  Float_t norm=hclulay->GetBinContent(1);
  if(norm<1.) norm=1.;
  hclulay->Scale(1./norm);
  gStyle->SetLineWidth(2);

  TCanvas* c1=new TCanvas("c1","Track quantities",900,900);
  c1->Divide(2,2);
  c1->cd(1);
  htpccl->Draw();
  htpccl->GetXaxis()->SetTitle("Clusters in TPC ");
  c1->cd(2);
  hitscl->Draw();
  hitscl->GetXaxis()->SetTitle("Clusters in ITS ");
  c1->cd(3);
  hclulay->Draw();
  hclulay->GetXaxis()->SetRange(2,7);
  hclulay->GetXaxis()->SetTitle("# ITS Layer");
  hclulay->GetYaxis()->SetTitle("Fraction of tracks with point in Layer x");
  c1->cd(4);

  TCanvas* c2=new TCanvas("c2","dedx per Layer",900,900);
  c2->Divide(2,2);
  c2->cd(1);
  hdedx3->Draw();
  hdedx3->GetXaxis()->SetTitle("dE/dx Lay3");
  c2->cd(2);
  hdedx4->Draw();
  hdedx4->GetXaxis()->SetTitle("dE/dx Lay4");
  c2->cd(3);
  hdedx5->Draw();
  hdedx5->GetXaxis()->SetTitle("dE/dx Lay5");
  c2->cd(4);
  hdedx6->Draw();
  hdedx6->GetXaxis()->SetTitle("dE/dx Lay6");

  hdEdxVsMod->SetStats(0);
  TCanvas* cdedx=new TCanvas("cdedx","dedx SDD",1400,600);
  cdedx->SetLogz();
  hdEdxVsMod->Draw("col"); 
  hdEdxVsMod->GetXaxis()->SetTitle("SDD Module Id");
  hdEdxVsMod->GetYaxis()->SetTitle("dE/dx (keV/300 #mum)");
  hdEdxVsMod->GetYaxis()->SetTitleOffset(1.25);



  TCanvas* cv=new TCanvas("cv","Vertex",600,900);
  cv->Divide(1,3);
  cv->cd(1);
  hvx->Draw();
  hvx->GetXaxis()->SetTitle("Xv (cm)");
  cv->cd(2);
  hvy->Draw();
  hvy->GetXaxis()->SetTitle("Yv (cm)");
  cv->cd(3);
  hvz->Draw();
  hvz->GetXaxis()->SetTitle("Xv (cm)");

  hGoodPMod->SetStats(0);
  hGoodPMod->SetTitle("");
  TCanvas* ceff0=new TCanvas("ceff0","ModuleIndexInfo",1000,600);
  hGoodPMod->Draw("e");
  hGoodPMod->GetXaxis()->SetTitle("SDD Module Id");
  hGoodPMod->GetYaxis()->SetTitle("Number of tracks");
  hMissPMod->SetLineColor(2);
  hMissPMod->SetMarkerColor(2);
  hMissPMod->SetMarkerStyle(22);
  hMissPMod->SetMarkerSize(0.5);
  hMissPMod->Draw("psame");
  hBadRegMod->SetLineColor(kGreen+1);
  hBadRegMod->SetMarkerColor(kGreen+1);
  hBadRegMod->SetMarkerStyle(20);
  hBadRegMod->SetMarkerSize(0.5);
  hBadRegMod->Draw("esame");
  hSkippedMod->SetLineColor(kYellow);
  hSkippedMod->Draw("esame");
  hOutAccMod->SetLineColor(4);
  hOutAccMod->Draw("esame");
  hNoRefitMod->SetLineColor(6);
  hNoRefitMod->Draw("esame");
  TLatex* t1=new TLatex(0.7,0.85,"Good Point");
  t1->SetNDC();
  t1->SetTextColor(1);
  t1->Draw();
  TLatex* t2=new TLatex(0.7,0.8,"Missing Point");
  t2->SetNDC();
  t2->SetTextColor(2);
  t2->Draw();
  TLatex* t3=new TLatex(0.7,0.75,"Bad Region");
  t3->SetNDC();
  t3->SetTextColor(kGreen+1);
  t3->Draw();
  ceff0->Update();

  TH1F* heff=new TH1F("heff","",260,239.5,499.5);
  for(Int_t imod=0; imod<260;imod++){
    Float_t numer=hGoodPMod->GetBinContent(imod+1)+hBadRegMod->GetBinContent(imod+1)+hOutAccMod->GetBinContent(imod+1)+hNoRefitMod->GetBinContent(imod+1);
    Float_t denom=hAllPMod->GetBinContent(imod+1);
    Float_t eff=0.;
    Float_t erreff=0.;
    if(denom>0){
      eff=numer/denom;
      erreff=TMath::Sqrt(eff*(1-eff)/denom);
    }
    heff->SetBinContent(imod+1,eff);
    heff->SetBinError(imod+1,erreff);
  }

  printf("---- Modules with efficiency < 90%% ----\n");
  heff->SetStats(0);
  TCanvas* ceff1=new TCanvas("ceff1","Efficiency",1000,600);
  heff->Draw();
  heff->GetXaxis()->SetTitle("SDD Module Id");
  heff->GetYaxis()->SetTitle("Fraction of tracks with point in good region");
  for(Int_t ibin=1; ibin<=heff->GetNbinsX(); ibin++){
    Float_t e=heff->GetBinContent(ibin);
    if(e<0.9){
      Int_t iMod=(Int_t)heff->GetBinCenter(ibin);
      Int_t lay,lad,det;
      AliITSgeomTGeo::GetModuleId(iMod,lay,lad,det);
      printf("Module %d - Layer %d Ladder %2d Det %d  -   Eff. %.3f\n",iMod,lay,lad,det,heff->GetBinContent(ibin));
    }
  }
  ceff1->Update();



  hGoodPXloc->SetTitle("");
  hGoodPZloc->SetTitle("");
  hGoodPXloc->SetStats(0);
  hGoodPZloc->SetStats(0);
  hGoodPXloc->SetMinimum(0);
  hGoodPZloc->SetMinimum(0);
  TCanvas* ceff2=new TCanvas("ceff2","LocalCoord",1000,600);
  ceff2->Divide(2,1);
  ceff2->cd(1);
  hGoodPXloc->Draw("e");
  hGoodPXloc->GetXaxis()->SetTitle("Xlocal (cm)");
  hGoodPXloc->GetYaxis()->SetTitle("Number of tracks");
  hMissPXloc->SetLineColor(2);
  hMissPXloc->SetMarkerColor(2);
  hMissPXloc->SetMarkerStyle(22);
  hMissPXloc->SetMarkerSize(0.5);
  hMissPXloc->Draw("psame");
  hBadRegXloc->SetLineColor(kGreen+1);
  hBadRegXloc->SetMarkerColor(kGreen+1);
  hBadRegXloc->SetMarkerStyle(20);
  hBadRegXloc->SetMarkerSize(0.5);
  hBadRegXloc->Draw("psame");
  t1->Draw();
  t2->Draw();
  t3->Draw();
  ceff2->cd(2);
  hGoodPZloc->Draw("e");
  hGoodPZloc->GetXaxis()->SetTitle("Zlocal (cm)");
  hGoodPZloc->GetYaxis()->SetTitle("Number of tracks");
  hMissPZloc->SetLineColor(2);
  hMissPZloc->SetMarkerColor(2);
  hMissPZloc->SetMarkerStyle(22);
  hMissPZloc->SetMarkerSize(0.5);
  hMissPZloc->Draw("psame");
  hBadRegZloc->SetLineColor(kGreen+1);
  hBadRegZloc->SetMarkerColor(kGreen+1);
  hBadRegZloc->SetMarkerStyle(20);
  hBadRegZloc->SetMarkerSize(0.5);
  hBadRegZloc->Draw("psame");
  t1->Draw();
  t2->Draw();
  t3->Draw();
  ceff2->Update();


  
}
コード例 #27
0
ファイル: hists.C プロジェクト: jlrainbolt/Forest
void hists()
{
    // Trees
    TFile *sigRecFile = new TFile("/tthome/tgunter/work/WW/MC/signal_train9.root");
    TFile *bgRecFile = new TFile("/tthome/tgunter/work/WW/MC/background_train9.root");
    TFile *dyRecFile = new TFile("/tthome/tgunter/work/WW/MC/Drell_Yan_train.root");

    TTree *sigRecTree = (TTree *) sigRecFile->Get("trees_vec");
    TTree *bgRecTree = (TTree *) bgRecFile->Get("trees_vec");
    TTree *dyRecTree = (TTree *) dyRecFile->Get("trees_vec");

    TFile *sigSimFile = new TFile("sim_signal_train.root");
    TFile *bgSimFile = new TFile("sim_background_train.root");
    TFile *dySimFile = new TFile("sim_Drell_Yan_train.root");

    TTree *sigSimTree = (TTree *) sigSimFile->Get("tree");
    TTree *bgSimTree = (TTree *) bgSimFile->Get("tree");
    TTree *dySimTree = (TTree *) dySimFile->Get("tree");

    // Variables
    Int_t LChan_r, nExtraLept_r;
    Float_t LChan_s, nExtraLept_s;
    Float_t pT1_r, pT1_s, pT2_r, pT2_s, pT3_r, pT3_s;
    Float_t dPhi_r, dPhi_s, qT_r, qT_s, MLL_r, MLL_s;

    sigRecTree->SetBranchAddress("lep1_pt", &pT1_r);
    sigRecTree->SetBranchAddress("lep2_pt", &pT2_r);
    sigRecTree->SetBranchAddress("lep3_pt", &pT3_r);
    sigRecTree->SetBranchAddress("dPhiLL", &dPhi_r);
    sigRecTree->SetBranchAddress("qT", &qT_r);
    sigRecTree->SetBranchAddress("lep_Type", &LChan_r);
    sigRecTree->SetBranchAddress("numbExtraLep", &nExtraLept_r);
    sigRecTree->SetBranchAddress("mll", &MLL_r);

    bgRecTree->SetBranchAddress("lep1_pt", &pT1_r);
    bgRecTree->SetBranchAddress("lep2_pt", &pT2_r);
    bgRecTree->SetBranchAddress("lep3_pt", &pT3_r);
    bgRecTree->SetBranchAddress("dPhiLL", &dPhi_r);
    bgRecTree->SetBranchAddress("qT", &qT_r);
    bgRecTree->SetBranchAddress("lep_Type", &LChan_r);
    bgRecTree->SetBranchAddress("numbExtraLep", &nExtraLept_r);
    bgRecTree->SetBranchAddress("mll", &MLL_r);

    dyRecTree->SetBranchAddress("lep1_pt", &pT1_r);
    dyRecTree->SetBranchAddress("lep2_pt", &pT2_r);
    dyRecTree->SetBranchAddress("lep3_pt", &pT3_r);
    dyRecTree->SetBranchAddress("dPhiLL", &dPhi_r);
    dyRecTree->SetBranchAddress("qT", &qT_r);
    dyRecTree->SetBranchAddress("lep_Type", &LChan_r);
    dyRecTree->SetBranchAddress("numbExtraLep", &nExtraLept_r);
    dyRecTree->SetBranchAddress("mll", &MLL_r);

    sigSimTree->SetBranchAddress("pT1", &pT1_s);
    sigSimTree->SetBranchAddress("pT2", &pT2_s);
    sigSimTree->SetBranchAddress("pTLeptExtra", &pT3_s);
    sigSimTree->SetBranchAddress("dPhi", &dPhi_s);
    sigSimTree->SetBranchAddress("qT", &qT_s);
    sigSimTree->SetBranchAddress("LChan", &LChan_s);
    sigSimTree->SetBranchAddress("nExtraLept", &nExtraLept_s);
    sigSimTree->SetBranchAddress("MLL", &MLL_s);

    bgSimTree->SetBranchAddress("pT1", &pT1_s);
    bgSimTree->SetBranchAddress("pT2", &pT2_s);
    bgSimTree->SetBranchAddress("pTLeptExtra", &pT3_s);
    bgSimTree->SetBranchAddress("dPhi", &dPhi_s);
    bgSimTree->SetBranchAddress("qT", &qT_s);
    bgSimTree->SetBranchAddress("LChan", &LChan_s);
    bgSimTree->SetBranchAddress("nExtraLept", &nExtraLept_s);
    bgSimTree->SetBranchAddress("MLL", &MLL_s);

    dySimTree->SetBranchAddress("pT1", &pT1_s);
    dySimTree->SetBranchAddress("pT2", &pT2_s);
    dySimTree->SetBranchAddress("pTLeptExtra", &pT3_s);
    dySimTree->SetBranchAddress("dPhi", &dPhi_s);
    dySimTree->SetBranchAddress("qT", &qT_s);
    dySimTree->SetBranchAddress("LChan", &LChan_s);
    dySimTree->SetBranchAddress("nExtraLept", &nExtraLept_s);
    dySimTree->SetBranchAddress("MLL", &MLL_s);

    // Canvases
    TCanvas *c[8];
    c[0] = new TCanvas("c0", "pT1", 1280, 720);
    c[1] = new TCanvas("c1", "pT2", 1280, 720);
    c[2] = new TCanvas("c2", "pT3", 1280, 720);
    c[3] = new TCanvas("c3", "dPhi", 1280, 720);
    c[4] = new TCanvas("c4", "qT", 1280, 720);
    c[5] = new TCanvas("c5", "LChan", 1280, 720);
    c[6] = new TCanvas("c6", "nExtraLept", 1280, 720);
    c[7] = new TCanvas("c7", "MLL", 1280, 720);

    // Histograms
    // pT1
    TH1F *hpT1_r[3];
    Int_t pT1_bins = 50;
    Double_t pT1_min = 0, pT1_max = 300;
    hpT1_r[0] = new TH1F("hpT1_r0", "", pT1_bins, pT1_min, pT1_max);
    hpT1_r[1] = new TH1F("hpT1_r1", "", pT1_bins, pT1_min, pT1_max);
    hpT1_r[2] = new TH1F("hpT1_r2", "", pT1_bins, pT1_min, pT1_max);
    TH1F *hpT1_s[3];
    hpT1_s[0] = new TH1F("hpT1_s0", "", pT1_bins, pT1_min, pT1_max);
    hpT1_s[1] = new TH1F("hpT1_s1", "", pT1_bins, pT1_min, pT1_max);
    hpT1_s[2] = new TH1F("hpT1_s2", "", pT1_bins, pT1_min, pT1_max);

    // pT2
    TH1F *hpT2_r[3];
    Int_t pT2_bins = 50;
    Double_t pT2_min = 0, pT2_max = 200;
    hpT2_r[0] = new TH1F("hpT2_r0", "", pT2_bins, pT2_min, pT2_max);
    hpT2_r[1] = new TH1F("hpT2_r1", "", pT2_bins, pT2_min, pT2_max);
    hpT2_r[2] = new TH1F("hpT2_r2", "", pT2_bins, pT2_min, pT2_max);
    TH1F *hpT2_s[3];
    hpT2_s[0] = new TH1F("hpT2_s0", "", pT2_bins, pT2_min, pT2_max);
    hpT2_s[1] = new TH1F("hpT2_s1", "", pT2_bins, pT2_min, pT2_max);
    hpT2_s[2] = new TH1F("hpT2_s2", "", pT2_bins, pT2_min, pT2_max);

    // pT3
    TH1F *hpT3_r[3];
    Int_t pT3_bins = 50;
    Double_t pT3_min = 1, pT3_max = 200;
    hpT3_r[0] = new TH1F("hpT3_r0", "", pT3_bins, pT3_min, pT3_max);
    hpT3_r[1] = new TH1F("hpT3_r1", "", pT3_bins, pT3_min, pT3_max);
    hpT3_r[2] = new TH1F("hpT3_r2", "", pT3_bins, pT3_min, pT3_max);
    TH1F *hpT3_s[3];
    hpT3_s[0] = new TH1F("hpT3_s0", "", pT3_bins, pT3_min, pT3_max);
    hpT3_s[1] = new TH1F("hpT3_s1", "", pT3_bins, pT3_min, pT3_max);
    hpT3_s[2] = new TH1F("hpT3_s2", "", pT3_bins, pT3_min, pT3_max);

    // dPhi
    TH1F *hdPhi_r[3];
    Int_t dPhi_bins = 50;
    Double_t dPhi_min = -4, dPhi_max = 4;
    hdPhi_r[0] = new TH1F("hdPhi_r0", "", dPhi_bins, dPhi_min, dPhi_max);
    hdPhi_r[1] = new TH1F("hdPhi_r1", "", dPhi_bins, dPhi_min, dPhi_max);
    hdPhi_r[2] = new TH1F("hdPhi_r2", "", dPhi_bins, dPhi_min, dPhi_max);
    TH1F *hdPhi_s[3];
    hdPhi_s[0] = new TH1F("hdPhi_s0", "", dPhi_bins, dPhi_min, dPhi_max);
    hdPhi_s[1] = new TH1F("hdPhi_s1", "", dPhi_bins, dPhi_min, dPhi_max);
    hdPhi_s[2] = new TH1F("hdPhi_s2", "", dPhi_bins, dPhi_min, dPhi_max);

    // qT
    TH1F *hqT_r[3];
    Int_t qT_bins = 50;
    Double_t qT_min = 0, qT_max = 200;
    hqT_r[0] = new TH1F("hqT_r0", "", qT_bins, qT_min, qT_max);
    hqT_r[1] = new TH1F("hqT_r1", "", qT_bins, qT_min, qT_max);
    hqT_r[2] = new TH1F("hqT_r2", "", qT_bins, qT_min, qT_max);
    TH1F *hqT_s[3];
    hqT_s[0] = new TH1F("hqT_s0", "", qT_bins, qT_min, qT_max);
    hqT_s[1] = new TH1F("hqT_s1", "", qT_bins, qT_min, qT_max);
    hqT_s[2] = new TH1F("hqT_s2", "", qT_bins, qT_min, qT_max);

    // LChan
    TH1I *hLChan_r[3];
    Int_t LChan_bins = 4;
    Double_t LChan_min = -2.5, LChan_max = 1.5;
    hLChan_r[0] = new TH1I("hLChan_r0", "", LChan_bins, LChan_min, LChan_max);
    hLChan_r[1] = new TH1I("hLChan_r1", "", LChan_bins, LChan_min, LChan_max);
    hLChan_r[2] = new TH1I("hLChan_r2", "", LChan_bins, LChan_min, LChan_max);
    TH1F *hLChan_s[3];
    hLChan_s[0] = new TH1F("hLChan_s0", "", LChan_bins, LChan_min, LChan_max);
    hLChan_s[1] = new TH1F("hLChan_s1", "", LChan_bins, LChan_min, LChan_max);
    hLChan_s[2] = new TH1F("hLChan_s2", "", LChan_bins, LChan_min, LChan_max);

    // nExtraLept
    TH1I *hnExtraLept_r[3];
    Int_t nExtraLept_bins = 4;
    Double_t nExtraLept_min = -0.5, nExtraLept_max = 3.5;
    hnExtraLept_r[0] = new TH1I("hnExtraLept_r0", "", nExtraLept_bins, nExtraLept_min, nExtraLept_max);
    hnExtraLept_r[1] = new TH1I("hnExtraLept_r1", "", nExtraLept_bins, nExtraLept_min, nExtraLept_max);
    hnExtraLept_r[2] = new TH1I("hnExtraLept_r2", "", nExtraLept_bins, nExtraLept_min, nExtraLept_max);
    TH1F *hnExtraLept_s[3];
    hnExtraLept_s[0] = new TH1F("hnExtraLept_s0", "", nExtraLept_bins, nExtraLept_min, nExtraLept_max);
    hnExtraLept_s[1] = new TH1F("hnExtraLept_s1", "", nExtraLept_bins, nExtraLept_min, nExtraLept_max);
    hnExtraLept_s[2] = new TH1F("hnExtraLept_s2", "", nExtraLept_bins, nExtraLept_min, nExtraLept_max);

    // MLL
    TH1I *hMLL_r[3];
    Int_t MLL_bins = 50;
    Double_t MLL_min = 0, MLL_max = 350;
    hMLL_r[0] = new TH1I("hMLL_r0", "", MLL_bins, MLL_min, MLL_max);
    hMLL_r[1] = new TH1I("hMLL_r1", "", MLL_bins, MLL_min, MLL_max);
    hMLL_r[2] = new TH1I("hMLL_r2", "", MLL_bins, MLL_min, MLL_max);
    TH1F *hMLL_s[3];
    hMLL_s[0] = new TH1F("hMLL_s0", "", MLL_bins, MLL_min, MLL_max);
    hMLL_s[1] = new TH1F("hMLL_s1", "", MLL_bins, MLL_min, MLL_max);
    hMLL_s[2] = new TH1F("hMLL_s2", "", MLL_bins, MLL_min, MLL_max);

    // Fill
    Long64_t dyEntries = dySimTree->GetEntries();

    // WW
    for (Int_t i = 0; i < dyEntries; i++)
    {
	sigRecTree->GetEvent(i);
	sigSimTree->GetEvent(i);

	hpT1_r[0]->Fill(pT1_r);
	hpT1_s[0]->Fill(pT1_s);

	hpT2_r[0]->Fill(pT2_r);
	hpT2_s[0]->Fill(pT2_s);

	hpT3_r[0]->Fill(pT3_r);
	hpT3_s[0]->Fill(pT3_s);

	hdPhi_r[0]->Fill(TMath::Abs(dPhi_r));
	hdPhi_s[0]->Fill(dPhi_s);

	hqT_r[0]->Fill(qT_r);
	hqT_s[0]->Fill(qT_s);

	hLChan_r[0]->Fill(LChan_r);
	hLChan_s[0]->Fill(LChan_s);

	hnExtraLept_r[0]->Fill(nExtraLept_r);
	hnExtraLept_s[0]->Fill(nExtraLept_s);

	hMLL_r[0]->Fill(MLL_r);
	hMLL_s[0]->Fill(MLL_s);
    }

    // tt
    for (Int_t i = 0; i < dyEntries; i++)
    {
	bgRecTree->GetEvent(i);
	bgSimTree->GetEvent(i);

	hpT1_r[1]->Fill(pT1_r);
	hpT1_s[1]->Fill(pT1_s);

	hpT2_r[1]->Fill(pT2_r);
	hpT2_s[1]->Fill(pT2_s);

	hpT3_r[1]->Fill(pT3_r);
	hpT3_s[1]->Fill(pT3_s);

	hdPhi_r[1]->Fill(TMath::Abs(dPhi_r));
	hdPhi_s[1]->Fill(dPhi_s);

	hqT_r[1]->Fill(qT_r);
	hqT_s[1]->Fill(qT_s);

	hLChan_r[1]->Fill(LChan_r);
	hLChan_s[1]->Fill(LChan_s);

	hnExtraLept_r[1]->Fill(nExtraLept_r);
	hnExtraLept_s[1]->Fill(nExtraLept_s);

	hMLL_r[1]->Fill(MLL_r);
	hMLL_s[1]->Fill(MLL_s);
    }

    // DY hists
    for (Int_t i = 0; i < dyEntries; i++)
    {
	dyRecTree->GetEvent(i);
	dySimTree->GetEvent(i);

	hpT1_r[2]->Fill(pT1_r);
	hpT1_s[2]->Fill(pT1_s);

	hpT2_r[2]->Fill(pT2_r);
	hpT2_s[2]->Fill(pT2_s);

	hpT3_r[2]->Fill(pT3_r);
	hpT3_s[2]->Fill(pT3_s);

	hdPhi_r[2]->Fill(TMath::Abs(dPhi_r));
	hdPhi_s[2]->Fill(dPhi_s);

	hqT_r[2]->Fill(qT_r);
	hqT_s[2]->Fill(qT_s);

	hLChan_r[2]->Fill(LChan_r);
	hLChan_s[2]->Fill(LChan_s);

	hnExtraLept_r[2]->Fill(nExtraLept_r);
	hnExtraLept_s[2]->Fill(nExtraLept_s);

	hMLL_r[2]->Fill(MLL_r);
	hMLL_s[2]->Fill(MLL_s);
    }

    // Draw
    // pT1
    c[0]->cd();
    for (Int_t h = 0; h < 3; h++)
    {
	hpT1_r[h]->SetLineWidth(4);
	hpT1_s[h]->SetLineStyle(2);
    }
    hpT1_r[0]->SetLineColor(kBlue);
    hpT1_r[1]->SetLineColor(kRed);
    hpT1_s[0]->SetLineColor(kBlue);
    hpT1_s[1]->SetLineColor(kRed);
    hpT1_r[2]->Draw();
    hpT1_r[0]->Draw("SAME");
    hpT1_r[1]->Draw("SAME");
    hpT1_r[2]->Draw("SAME");
    hpT1_s[0]->Draw("SAME");
    hpT1_s[1]->Draw("SAME");
    hpT1_s[2]->Draw("SAME");

    // pT2
    c[1]->cd();
    for (Int_t h = 0; h < 3; h++)
    {
	hpT2_r[h]->SetLineWidth(4);
	hpT2_s[h]->SetLineStyle(2);
    }
    hpT2_r[0]->SetLineColor(kBlue);
    hpT2_r[1]->SetLineColor(kRed);
    hpT2_s[0]->SetLineColor(kBlue);
    hpT2_s[1]->SetLineColor(kRed);
    hpT2_r[2]->Draw();
    hpT2_r[0]->Draw("SAME");
    hpT2_r[1]->Draw("SAME");
    hpT2_r[2]->Draw("SAME");
    hpT2_s[0]->Draw("SAME");
    hpT2_s[1]->Draw("SAME");
    hpT2_s[2]->Draw("SAME");

    // pT3
    c[2]->cd();
    for (Int_t h = 0; h < 3; h++)
    {
	hpT3_r[h]->SetLineWidth(4);
	hpT3_s[h]->SetLineStyle(2);
    }
    hpT3_s[1]->SetLineColor(kRed);
    hpT3_r[0]->SetLineColor(kBlue);
    hpT3_r[1]->SetLineColor(kRed);
    hpT3_s[0]->SetLineColor(kBlue);
    hpT3_s[1]->Draw();
    hpT3_r[0]->Draw("SAME");
    hpT3_r[1]->Draw("SAME");
    hpT3_r[2]->Draw("SAME");
    hpT3_s[0]->Draw("SAME");
    hpT3_s[1]->Draw();
    hpT3_s[2]->Draw("SAME");

    // dPhi
    c[3]->cd();
    for (Int_t h = 0; h < 3; h++)
    {
	hdPhi_r[h]->SetLineWidth(4);
	hdPhi_s[h]->SetLineStyle(2);
    }
    hdPhi_r[0]->SetLineColor(kBlue);
    hdPhi_r[1]->SetLineColor(kRed);
    hdPhi_s[0]->SetLineColor(kBlue);
    hdPhi_s[1]->SetLineColor(kRed);
    hdPhi_s[2]->Draw();
    hdPhi_r[0]->Draw("SAME");
    hdPhi_r[1]->Draw("SAME");
    hdPhi_r[2]->Draw("SAME");
    hdPhi_s[0]->Draw("SAME");
    hdPhi_s[1]->Draw("SAME");
    hdPhi_s[2]->Draw("SAME");

    // qT
    c[4]->cd();
    for (Int_t h = 0; h < 3; h++)
    {
	hqT_r[h]->SetLineWidth(4);
	hqT_s[h]->SetLineStyle(2);
    }
    hqT_r[0]->SetLineColor(kBlue);
    hqT_r[1]->SetLineColor(kRed);
    hqT_s[0]->SetLineColor(kBlue);
    hqT_s[1]->SetLineColor(kRed);
    hqT_s[2]->Draw();
    hqT_r[0]->Draw("SAME");
    hqT_r[1]->Draw("SAME");
    hqT_r[2]->Draw("SAME");
    hqT_s[0]->Draw("SAME");
    hqT_s[1]->Draw("SAME");
    hqT_s[2]->Draw("SAME");

    // LChan
    c[5]->cd();
    for (Int_t h = 0; h < 3; h++)
    {
	hLChan_r[h]->SetLineWidth(4);
	hLChan_s[h]->SetLineStyle(2);
    }
    hLChan_s[1]->SetLineColor(kRed);
    hLChan_r[0]->SetLineColor(kBlue);
    hLChan_r[1]->SetLineColor(kRed);
    hLChan_s[0]->SetLineColor(kBlue);
    hLChan_s[1]->Draw();
    hLChan_r[0]->Draw("SAME");
    hLChan_r[1]->Draw("SAME");
    hLChan_r[2]->Draw("SAME");
    hLChan_s[0]->Draw("SAME");
    hLChan_s[1]->Draw("SAME");
    hLChan_s[2]->Draw("SAME");

    // nExtraLept
    c[6]->cd();
    for (Int_t h = 0; h < 3; h++)
    {
	hnExtraLept_r[h]->SetLineWidth(4);
	hnExtraLept_s[h]->SetLineStyle(2);
    }
    hnExtraLept_s[1]->SetLineColor(kRed);
    hnExtraLept_r[0]->SetLineColor(kBlue);
    hnExtraLept_r[1]->SetLineColor(kRed);
    hnExtraLept_s[0]->SetLineColor(kBlue);
    hnExtraLept_r[2]->Draw();
    hnExtraLept_r[0]->Draw("SAME");
    hnExtraLept_r[1]->Draw("SAME");
    hnExtraLept_r[2]->Draw("SAME");
    hnExtraLept_s[0]->Draw("SAME");
    hnExtraLept_s[1]->Draw("SAME");
    hnExtraLept_s[2]->Draw("SAME");

    // MLL
    c[7]->cd();
    for (Int_t h = 0; h < 3; h++)
    {
	hMLL_r[h]->SetLineWidth(4);
	hMLL_s[h]->SetLineStyle(2);
    }
    hMLL_s[1]->SetLineColor(kRed);
    hMLL_r[0]->SetLineColor(kBlue);
    hMLL_r[1]->SetLineColor(kRed);
    hMLL_s[0]->SetLineColor(kBlue);
    hMLL_r[2]->Draw();
    hMLL_r[0]->Draw("SAME");
    hMLL_r[1]->Draw("SAME");
    hMLL_r[2]->Draw("SAME");
    hMLL_s[0]->Draw("SAME");
    hMLL_s[1]->Draw("SAME");
    hMLL_s[2]->Draw("SAME");

}
コード例 #28
0
ファイル: Trasporta.c プロジェクト: MBoretto/TANS
void Trasporta(Int_t s,Int_t Rhum, TRandom *GeneratoreEsterno=0,Int_t Noise_Medio = 20) {

	TStopwatch tempo;

	tempo.Start(kTRUE);

	cout<<endl<<"Sto trasportando attraverso i rivelatori: attendere... "<<endl;
	TRandom *smear;
	if(GeneratoreEsterno == 0){
		smear = new TRandom3();
		cout<<"Generatore Interno";
	}else{
		smear = GeneratoreEsterno;
		cout<<"Generatore Esterno";
	}
	
	cout<<" FirstRNDM: "<<smear->Rndm()<<endl;
	
	//////////////////////////////////////////////////////
	//Creo un nuovo file e
	//Definisco Struct per salvare i nuovi dati x y z 
	//////////////////////////////////////////////////////

	//Definisco il nuovo albero per salvare i punti di hit	
	TFile sfile("trasporto_tree.root","RECREATE");
  
	TTree *trasporto = new TTree("Ttrasporto","TTree con 3 branches");
	 //Punti sul layer
	TTree *Rel_Lay1 = new TTree("Layer1","TTree con 1 branch");
	TTree *Rel_Lay2 = new TTree("Layer2","TTree con 1 branch");
	 //rumore
	TTree *Noise = new TTree("Rumore","TTree con 1 branch");

	typedef struct {
		Double_t X,Y,Z;
		Int_t Flag;		
	} HIT; 
	static HIT beam;  	
	static HIT lay1;  
	static HIT lay2;

	typedef struct {
		Int_t event;
		Int_t tipo;
		Int_t Noiselay1;
		Int_t Noiselay2;
	} infoRumore;
	static infoRumore InfoR;


	//Dichiaro i rami dei tree
	trasporto->Branch("BeamPipe",&beam.X,"X/D:Y:Z:Flag/I");  
	trasporto->Branch("Layer1",&lay1.X,"X/D:Y:Z:Flag/I"); 
	trasporto->Branch("Layer2",&lay2.X,"X/D:Y:Z:Flag/I");  

	Rel_Lay1->Branch("RealLayer1",&lay1.X,"X/D:Y:Z:Flag/I"); 
	Rel_Lay2->Branch("RealLayer2",&lay2.X,"X/D:Y:Z:Flag/I"); 
	
	Noise->Branch("Rumore",&InfoR,"event/I:tipo:Noiselay1:Noiselay2"); 
	Double_t temp_phi = 0;
	Int_t Nnoise=0;	

  ////////////////////////////////
  //Acquisizione Vertici
  ///////////////////////////////
  TClonesArray *dir = new TClonesArray("Direction",100);	
  typedef struct {
    Double_t X,Y,Z;
    Int_t N;
  }SINGLE_EVENT;
  static SINGLE_EVENT event;    //struct con molteplicita' e vertice di un singolo evento
	
  TFile hfile("event_tree.root");


  TTree *Born = (TTree*)hfile.Get("T");       
  TBranch *b1=Born->GetBranch("Event"); 
  TBranch *b2=Born->GetBranch("Direzioni");  //acquisisco i due branches


  b1->SetAddress(&event.X); //passo l'indirizzo del primo oggetto della struct e assegno tutto a b1
  b2->SetAddress(&dir); // lo stesso per il vettore 




  /////////////////////////
  //Geometria del rivelatore
  /////////////////////////
  Double_t R1=3;	//raggio 3 cm beam pipe
  Double_t R2=4;	//raggio 4 cm primo layer
  Double_t R3=7;	//raggio 7 cm secondo layer

  Double_t limit = 8.; //lunghezza layer su z-> z in [-8,8]

  //Variabili Varie
	Double_t Xo=0.;Double_t Yo=0.;Double_t Zo=0.;
  	Double_t X1=0.;Double_t Y1=0.;Double_t Z1=0.;
	Double_t X2=0.;Double_t Y2=0.;Double_t Z2=0.;

	Int_t N=0; //molteplicita'

	Int_t yes = 0;
	Int_t no = 0;	       
	
	for(Int_t e=0; e < Born->GetEntries(); e++){
	
		Born->GetEvent(e);
		Xo=event.X;
		Yo=event.Y;
		Zo=event.Z;		
		N=event.N;	    
		
		for(Int_t i=0; i<N; i++){
			
			//Cast dell'elemenento i di TClones a Direction
			Direction *angolacci=(Direction*)dir->At(i);
			angolacci->SetRNDGenerator(smear);//uso lo stesso generatore anche nella classe
			
			//primo hit beam pipe
			angolacci->GeneraHit(Xo,Yo,Zo,R1);//genero il punto di impatto sul beam pipe		
			
			beam.X=angolacci->GetNewX(); //recupero le coordinate del punto d'impatto sul BP
			beam.Y=angolacci->GetNewY();					
			beam.Z=angolacci->GetNewZ();
			beam.Flag=1;
		

			///////////////////////////////////////////////////
			/////////////scattering sul beam pipe//////////////
			///////////////////////////////////////////////////
			if(s==1){
				//dipende dal tipo di materiale
				angolacci->Scattering(0.08,35.28);
			}
					
				
			//secondo hit layer 1			
			angolacci->GeneraHit(beam.X,beam.Y,beam.Z,R2);

			X1 = angolacci->GetNewX();	
			Y1 = angolacci->GetNewY();
			Z1 = angolacci->GetNewZ();
			
			lay1.X=X1;
			lay1.Y=Y1;							
			lay1.Z=Z1;	
			
			//verifico che la particella colpisca il layer
			if(TMath::Abs(Z1) < limit){

				lay1.Flag = e;
				Rel_Lay1->Fill();					       
				
				///////////////////////////////////////////////
				/////////////scattering sul layer//////////////	
				///////////////////////////////////////////////
				if(s==1){
					angolacci->Scattering(0.02,9.37);
				}				
							
				yes++;
				
			}else no++;	      
				

		      //terzo hit layer 2			
		      angolacci->GeneraHit(X1,Y1,Z1,R3);

		      X2 = angolacci->GetNewX();	
		      Y2 = angolacci->GetNewY();
		      Z2 = angolacci->GetNewZ();
		      lay2.X=X2;
		      lay2.Y=Y2;							
		      lay2.Z=Z2;
			

		      //verifico che la particella colpisca il layer
		      if(TMath::Abs(Z2) < limit){

			lay2.Flag = e;	
			Rel_Lay2->Fill();			
	
			yes++;

		      }else{
			no++;	
		      }

			angolacci->RemoveGenerator();
			trasporto->Fill(); //riempie tutto con quello che ho definito sopra

		      // Debug
		      /*printf("Evento %d : part %d \n",e,i+1);
			printf("x beam= %f ; y beam= %f; z beam= %f \n",beam.X,beam.Y,beam.Z);

			if(lay1.Flag){
			printf("x lay1= %f ; y lay1= %f; z lay1= %f \n",lay1.X,lay1.Y,lay1.Z);
			}else{
			printf("Non urta sul layer 1 \n");
			}


			if(lay2.Flag){
			printf("x lay2= %f ; y lay2= %f; z lay2= %f \n",lay2.X,lay2.Y,lay2.Z);
			}else{
			printf("Non urta sul layer 2 \n");
			}*/
		}

		////////////////////////////////////////////////////////////////////////////
		//////////////////////////RUMORE////////////////////////////////////////////
		////////////////////////////////////////////////////////////////////////////
		InfoR.event = e;
		InfoR.tipo = Rhum;
		if(Rhum != 0){
		//genero rumore lay 1
			if(Rhum == 1){
				//Nnoise= TMath::Abs(smear->Gaus(20,5));
				//Nnoise = 1+(Int_t)(20*smear->Rndm());
				Nnoise = 1+(Int_t)(Noise_Medio*smear->Rndm());
			}else{
				Nnoise= Rhum;
			}
		
		
			InfoR.Noiselay1 = Nnoise;
		
			for(Int_t y =0; y < Nnoise; y++){
				temp_phi = smear->Uniform(0,2*TMath::Pi());
				lay1.X = R2*TMath::Cos(temp_phi);
				lay1.Y = R2*TMath::Sin(temp_phi);							
				lay1.Z = smear->Uniform(-limit,limit);
	
				lay1.Flag=e;

				Rel_Lay1->Fill();		
		
			}

		      //genero rumore lay 2					
			if(Rhum == 1){
				//Nnoise= TMath::Abs(smear->Gaus(20,5));
				//Nnoise = 1+(Int_t)(20*smear->Rndm());
				Nnoise = 1+(Int_t)(Noise_Medio*smear->Rndm());
			}else{
				Nnoise= Rhum;
			}

			InfoR.Noiselay2 = Nnoise;

			for(Int_t w =0; w < Nnoise; w++){
				temp_phi = smear->Uniform(0,2*TMath::Pi());

				lay2.X = R3*TMath::Cos(temp_phi);
				lay2.Y = R3*TMath::Sin(temp_phi);							
				lay2.Z = smear->Uniform(-limit,limit);
	
				lay2.Flag=e;

				Rel_Lay2->Fill();	
			}
		}else{
			InfoR.Noiselay1 = 0;
			InfoR.Noiselay2 = 0;
		}
	
	//fill per il rumore
	Noise->Fill();
	}


	sfile.Write(); 
 
	sfile.Close();
	//ho il file con tutti gli eventi

  

 	tempo.Stop();
  
	cout<<endl<<endl<<endl<<"//////////////////////////////////////"<<endl<<endl;
	cout<<"Completato!"<<endl<<endl;
	cout<<"Il trasporto è durato "<<endl;
	tempo.Print();
	cout<<endl<<endl;
	cout<<"PARAMETRI TRASPORTO: "<<endl;
	cout<<"\t"<<"Scattering:     "<<s;
	if(s==1)cout<<"  Scattering attivo"<<endl;
	if(s==0)cout<<"  Scattering non attivo"<<endl;
	cout<<"\t"<<"Rumore:         ";
	if(Rhum==1)cout<<"  Rumore gaussiano  "<<endl;
	if(Rhum==0)cout<<"  Nessun rumore"<<endl;
	if((Rhum!=0) & (Rhum!=1))cout<<"  Rumore con molteplicita' fissa "<<Rhum<<endl;
  	cout<<endl<<"//////////////////////////////////////"<<endl;

}
コード例 #29
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");
  

}
コード例 #30
0
int main(int argc, char *argv[])
{
  cout.setf(ios::fixed, ios::floatfield);
  cout.precision(12);
  TH1::AddDirectory(kFALSE);

  cout << "Run " << argv[1] << " ..." << endl;

  char tempOut[500];
  sprintf(tempOut, "%s/replay_pass1_%s.root",getenv("REPLAY_PASS1"), argv[1]);
  


  //Check if the file is good already and quit if it is so that we can 
  // only replay the files that are bad...

  if ( OnlyReplayBadFiles ) {
     
    if ( checkIfReplayFileIsGood(std::string(tempOut)) == 1 ) return 1;
  
    else {
      std::ofstream badRuns("badRuns.txt", std::fstream::app);
      badRuns << argv[1] << "\n";
      badRuns.close();
    }
  }



  // Read cuts file
  char tempFileCuts[500];
  sprintf(tempFileCuts, "%s/cuts_%s.dat", getenv("CUTS"),argv[1]);
  cout << "... Reading: " << tempFileCuts << endl;

  ifstream fileCuts(tempFileCuts);
  fileCuts >> cutBeamBurstTime >> comment;
  fileCuts >> nCutsTimeWindows >> comment;
  if (nCutsTimeWindows > 0) {
    for (int i=0; i<nCutsTimeWindows; i++) {
      fileCuts >> cutTimeWindowLower[i] >> cutTimeWindowUpper[i];
    }
  }
  fileCuts >> cutEastAnode >> comment;
  fileCuts >> cutWestAnode >> comment;
  fileCuts >> cutEastTwoFold >> comment;
  fileCuts >> cutWestTwoFold >> comment;
  fileCuts >> cutEastTopVetoQADC >> comment;
  fileCuts >> cutEastTopVetoTDC >> comment;
  fileCuts >> cutEastDriftTubeTAC >> comment;
  fileCuts >> cutWestDriftTubeTAC >> comment;
  fileCuts >> cutEastBackingVetoQADC >> comment;
  fileCuts >> cutEastBackingVetoTDC >> comment;
  fileCuts >> cutWestBackingVetoQADC >> comment;
  fileCuts >> cutWestBackingVetoTDC >> comment;

  cout << "... Beam Burst T0 Cut: " << cutBeamBurstTime << endl;
  cout << "... Number of Time Windows Cuts: " << nCutsTimeWindows << endl;
  if (nCutsTimeWindows > 0) {
    for (int i=0; i<nCutsTimeWindows; i++) {
      cout << "        [" << cutTimeWindowLower[i] << ", " << cutTimeWindowUpper[i] << "]" << endl;
    }
  }
  cout << "... East MWPC Anode Cut: " << cutEastAnode << endl;
  cout << "... West MWPC Anode Cut: " << cutWestAnode << endl;
  cout << "... East Scintillator Two-Fold Trigger Cut: " << cutEastTwoFold << endl;
  cout << "... West Scintillator Two-Fold Trigger Cut: " << cutWestTwoFold << endl;
  cout << "... East Top Veto QADC Cut: " << cutEastTopVetoQADC << endl;
  cout << "... East Top Veto TDC Cut: " << cutEastTopVetoTDC << endl;
  cout << "... East Drift Tube TAC Cut: " << cutEastDriftTubeTAC << endl;
  cout << "... West Drift Tube TAC Cut: " << cutWestDriftTubeTAC << endl;
  cout << "... East Backing Veto QADC Cut: " << cutEastBackingVetoQADC << endl;
  cout << "... East Backing Veto TDC Cut: " << cutEastBackingVetoTDC << endl;
  cout << "... West Backing Veto QADC Cut: " << cutWestBackingVetoQADC << endl;
  cout << "... West Backing Veto TDC Cut: " << cutWestBackingVetoTDC << endl;

  //First load separate PMT pedestals as produced by the trigger thresholds

  std::vector < std::vector <Double_t> > pmtPedestals = loadPMTpedestals(atoi(argv[1]));
  

  // Read pedestals file
  char tempFilePed[500];
  int iRun;
  sprintf(tempFilePed, "%s/pedestals_%s.dat", getenv("PEDESTALS"), argv[1]);
  cout << "... Reading: " << tempFilePed << endl;

  ifstream filePed(tempFilePed);
  for (int i=0; i<8; i++) {
    filePed >> iRun >> pedQadc[i];   
    pedQadc[i] = pmtPedestals[i][0]; //replace pedQadc[i] with the pedestals separately loaded
  }
  for (int i=0; i<32; i++) {
    filePed >> iRun >> pedPdc2[i];
  }
  for (int i=0; i<32; i++) {
    filePed >> iRun >> pedPadc[i];
  }

  
  filePed >> iRun >> pedPdc30;
  filePed >> iRun >> pedPdc34;

  

  //cout << iRun << " " << pedPdc30 << endl;
  //cout << iRun << " " << pedPdc34 << endl;
  
  // Open output ntuple


  DataTree *t = new DataTree();
  t->makeOutputTree(std::string(tempOut),"pass1");  
  
  
  // Open input ntuple
  char tempIn[500];
  sprintf(tempIn, "%s/full%s.root",getenv("UCNA_RAW_DATA"), argv[1]);

  TFile *fileIn = new TFile(tempIn, "READ");
  TTree *Tin = (TTree*)(fileIn->Get("h1"));

  // Variables
  Tin->SetBranchAddress("Pdc30",  &Pdc30);
  Tin->SetBranchAddress("Pdc34",  &Pdc34);

  Tin->SetBranchAddress("Tdc016", &Tdc016);
  Tin->SetBranchAddress("Tdc017", &Tdc017);
  Tin->SetBranchAddress("Tdc00", &Tdc00);
  Tin->SetBranchAddress("Tdc01", &Tdc01);
  Tin->SetBranchAddress("Tdc02", &Tdc02);
  Tin->SetBranchAddress("Tdc03", &Tdc03);
  Tin->SetBranchAddress("Tdc08", &Tdc08);
  Tin->SetBranchAddress("Tdc09", &Tdc09);
  Tin->SetBranchAddress("Tdc014", &Tdc010); //Note that what used to be TDC10 is now TDC14
  Tin->SetBranchAddress("Tdc011", &Tdc011);

  Tin->SetBranchAddress("Sis00",  &Sis00);

  Tin->SetBranchAddress("Qadc0",  &Qadc[0]);
  Tin->SetBranchAddress("Qadc1",  &Qadc[1]);
  Tin->SetBranchAddress("Qadc2",  &Qadc[2]);
  Tin->SetBranchAddress("Qadc3",  &Qadc[3]);
  Tin->SetBranchAddress("Qadc4",  &Qadc[4]);
  Tin->SetBranchAddress("Qadc5",  &Qadc[5]);
  Tin->SetBranchAddress("Qadc6",  &Qadc[6]);
  Tin->SetBranchAddress("Qadc7",  &Qadc[7]);

  Tin->SetBranchAddress("Pdc20",  &Pdc2[0]);
  Tin->SetBranchAddress("Pdc21",  &Pdc2[1]);
  Tin->SetBranchAddress("Pdc22",  &Pdc2[2]);
  Tin->SetBranchAddress("Pdc23",  &Pdc2[3]);
  Tin->SetBranchAddress("Pdc24",  &Pdc2[4]);
  Tin->SetBranchAddress("Pdc25",  &Pdc2[5]);
  Tin->SetBranchAddress("Pdc26",  &Pdc2[6]);
  Tin->SetBranchAddress("Pdc27",  &Pdc2[7]);
  Tin->SetBranchAddress("Pdc28",  &Pdc2[8]);
  Tin->SetBranchAddress("Pdc29",  &Pdc2[9]);
  Tin->SetBranchAddress("Pdc210", &Pdc2[10]);
  Tin->SetBranchAddress("Pdc211", &Pdc2[11]);
  Tin->SetBranchAddress("Pdc212", &Pdc2[12]);
  Tin->SetBranchAddress("Pdc213", &Pdc2[13]);
  Tin->SetBranchAddress("Pdc214", &Pdc2[14]);
  Tin->SetBranchAddress("Pdc215", &Pdc2[15]);
  Tin->SetBranchAddress("Pdc216", &Pdc2[16]);
  Tin->SetBranchAddress("Pdc217", &Pdc2[17]);
  Tin->SetBranchAddress("Pdc218", &Pdc2[18]);
  Tin->SetBranchAddress("Pdc219", &Pdc2[19]);
  Tin->SetBranchAddress("Pdc220", &Pdc2[20]);
  Tin->SetBranchAddress("Pdc221", &Pdc2[21]);
  Tin->SetBranchAddress("Pdc222", &Pdc2[22]);
  Tin->SetBranchAddress("Pdc223", &Pdc2[23]);
  Tin->SetBranchAddress("Pdc224", &Pdc2[24]);
  Tin->SetBranchAddress("Pdc225", &Pdc2[25]);
  Tin->SetBranchAddress("Pdc226", &Pdc2[26]);
  Tin->SetBranchAddress("Pdc227", &Pdc2[27]);
  Tin->SetBranchAddress("Pdc228", &Pdc2[28]);
  Tin->SetBranchAddress("Pdc229", &Pdc2[29]);
  Tin->SetBranchAddress("Pdc230", &Pdc2[30]);
  Tin->SetBranchAddress("Pdc231", &Pdc2[31]);

  Tin->SetBranchAddress("Padc0",  &Padc[0]);
  Tin->SetBranchAddress("Padc1",  &Padc[1]);
  Tin->SetBranchAddress("Padc2",  &Padc[2]);
  Tin->SetBranchAddress("Padc3",  &Padc[3]);
  Tin->SetBranchAddress("Padc4",  &Padc[4]);
  Tin->SetBranchAddress("Padc5",  &Padc[5]);
  Tin->SetBranchAddress("Padc6",  &Padc[6]);
  Tin->SetBranchAddress("Padc7",  &Padc[7]);
  Tin->SetBranchAddress("Padc8",  &Padc[8]);
  Tin->SetBranchAddress("Padc9",  &Padc[9]);
  Tin->SetBranchAddress("Padc10", &Padc[10]);
  Tin->SetBranchAddress("Padc11", &Padc[11]);
  Tin->SetBranchAddress("Padc12", &Padc[12]);
  Tin->SetBranchAddress("Padc13", &Padc[13]);
  Tin->SetBranchAddress("Padc14", &Padc[14]);
  Tin->SetBranchAddress("Padc15", &Padc[15]);
  Tin->SetBranchAddress("Padc16", &Padc[16]);
  Tin->SetBranchAddress("Padc17", &Padc[17]);
  Tin->SetBranchAddress("Padc18", &Padc[18]);
  Tin->SetBranchAddress("Padc19", &Padc[19]);
  Tin->SetBranchAddress("Padc20", &Padc[20]);
  Tin->SetBranchAddress("Padc21", &Padc[21]);
  Tin->SetBranchAddress("Padc22", &Padc[22]);
  Tin->SetBranchAddress("Padc23", &Padc[23]);
  Tin->SetBranchAddress("Padc24", &Padc[24]);
  Tin->SetBranchAddress("Padc25", &Padc[25]);
  Tin->SetBranchAddress("Padc26", &Padc[26]);
  Tin->SetBranchAddress("Padc27", &Padc[27]);
  Tin->SetBranchAddress("Padc28", &Padc[28]);
  Tin->SetBranchAddress("Padc29", &Padc[29]);
  Tin->SetBranchAddress("Padc30", &Padc[30]);
  Tin->SetBranchAddress("Padc31", &Padc[31]);

  Tin->SetBranchAddress("S83028", &S83028);
  Tin->SetBranchAddress("S8200", &S8200);
  Tin->SetBranchAddress("Clk0", &Clk0);
  Tin->SetBranchAddress("Clk1", &Clk1);
  Tin->SetBranchAddress("Clk2", &Clk2);
  Tin->SetBranchAddress("Clk3", &Clk3);

  Tin->SetBranchAddress("Pdc38",  &Pdc38);
  Tin->SetBranchAddress("Pdc39",  &Pdc39);
  Tin->SetBranchAddress("Pdc310", &Pdc310);
  Tin->SetBranchAddress("Pdc311", &Pdc311);

  Tin->SetBranchAddress("Qadc9",  &Qadc9);
  Tin->SetBranchAddress("Tdc019", &Tdc019);
  Tin->SetBranchAddress("Pdc313", &Pdc313);
  Tin->SetBranchAddress("Pdc315", &Pdc315);
  Tin->SetBranchAddress("Qadc8",  &Qadc8);
  Tin->SetBranchAddress("Tdc018", &Tdc018);
  Tin->SetBranchAddress("Qadc10", &Qadc10);
  Tin->SetBranchAddress("Tdc020", &Tdc020);

  Tin->SetBranchAddress("Number", &Number);
  Tin->SetBranchAddress("Delt0", &Delt0);

  Tin->SetBranchAddress("Evnb0", &Evnb[0]);
  Tin->SetBranchAddress("Evnb1", &Evnb[1]);
  Tin->SetBranchAddress("Evnb2", &Evnb[2]);
  Tin->SetBranchAddress("Evnb3", &Evnb[3]);
  Tin->SetBranchAddress("Evnb4", &Evnb[4]);
  Tin->SetBranchAddress("Bkhf0", &Bkhf[0]);
  Tin->SetBranchAddress("Bkhf1", &Bkhf[1]);
  Tin->SetBranchAddress("Bkhf2", &Bkhf[2]);
  Tin->SetBranchAddress("Bkhf3", &Bkhf[3]);
  Tin->SetBranchAddress("Bkhf4", &Bkhf[4]);


  int nEvents = Tin->GetEntries();
  cout << "... Processing nEvents = " << nEvents << endl;

  //Get length of run from UNBLINDED TIME
  float runLengthBlind[2] = {0.};
  float runLengthTrue = 0.;
  Tin->GetEvent(nEvents-1);
  runLengthTrue = S83028*scalerCountsToTime;
  runLengthBlind[0] = Clk0*scalerCountsToTime;
  runLengthBlind[1] = Clk1*scalerCountsToTime;
  
  //Histograms to hold UCNMonRate
  int binWidth = 10;
  int nbins = (int)(runLengthTrue+20.)/binWidth;
  t->UCN_Mon_1_Rate = new TH1F("UCN_Mon_1_Rate","UCN Mon 1 Rate",nbins, 0., (float)nbins*binWidth);
  t->UCN_Mon_2_Rate = new TH1F("UCN_Mon_2_Rate","UCN Mon 2 Rate",nbins, 0., (float)nbins*binWidth);
  t->UCN_Mon_3_Rate = new TH1F("UCN_Mon_3_Rate","UCN Mon 3 Rate",nbins, 0., (float)nbins*binWidth);
  t->UCN_Mon_4_Rate = new TH1F("UCN_Mon_4_Rate","UCN Mon 4 Rate",nbins, 0., (float)nbins*binWidth);


  // Loop over events
  for (int i=0; i<nEvents; i++) {

    Tin->GetEvent(i);

    if ( i%10000==0 ) std::cout << i << std::endl;
    
    t->xE.nClipped = t->yE.nClipped = t->xW.nClipped = t->yW.nClipped = 0;

    Int_t iSis00 = (int) Sis00;

    // Calculate pedestal-subtracted PMT QADC values
    for (int j=0; j<8; j++) {
      pmt[j] = ((double) Qadc[j]) - pedQadc[j];
    }
    
    // Set cathode values to non-ped subtracted values
    for (int j=0; j<32; j++) {
      
      if (j<16) {
	t->Cathodes_Ey[j] = (double)Pdc2[j];
	t->Cathodes_Wy[j] = (double)Padc[j];
      }
      else {
	t->Cathodes_Ex[j-16] = (double)Pdc2[j];
	t->Cathodes_Wx[j-16] = (double)Padc[j];
      }
    }

    //////////////////////////////////////////////////////////
    // For making a max Cathode signal cut

    double CathMaxCut = 300.; // This is pedestal subtracted
    
    MWPCCathodeHandler cathResp(t->Cathodes_Ex,t->Cathodes_Ey,t->Cathodes_Wx,t->Cathodes_Wy,&pedPdc2[16],&pedPdc2[0],&pedPadc[16],&pedPadc[0]);
    
    //Get the max signal in each plane (ped subtracted)
    double cathMaxEX = cathResp.getMaxSignalEX();
    double cathMaxEY = cathResp.getMaxSignalEY();
    double cathMaxWX = cathResp.getMaxSignalWX();
    double cathMaxWY = cathResp.getMaxSignalWY();
    
    double maxCathSumE = cathMaxEX + cathMaxEY;
    double maxCathSumW = cathMaxWX + cathMaxWY;

    //Also saving one set of positions for making position maps
    cathResp.findAllPositions(true,false);

    
    std::vector<double> posex = cathResp.getPosEX();
    std::vector<double> posey = cathResp.getPosEY();
    std::vector<double> poswx = cathResp.getPosWX();
    std::vector<double> poswy = cathResp.getPosWY();
    
    t->xE.center = posex[0] * positionProjection;
    t->yE.center = posey[0] * positionProjection;
    t->xW.center = poswx[0] * positionProjection;
    t->yW.center = poswy[0] * positionProjection;
    
    t->xE.width = posex[1] * positionProjection;
    t->yE.width = posey[1] * positionProjection;
    t->xW.width = poswx[1] * positionProjection;
    t->yW.width = poswy[1] * positionProjection;
    
    t->xE.height = posex[2];
    t->yE.height = posey[2];
    t->xW.height = poswx[2];
    t->yW.height = poswy[2];
    
    t->xE.mult = cathResp.getMultEX();
    t->yE.mult = cathResp.getMultEY();
    t->xW.mult = cathResp.getMultWX();
    t->yW.mult = cathResp.getMultWY();
    
    t->xE.nClipped = cathResp.getnClippedEX();
    t->yE.nClipped = cathResp.getnClippedEY();
    t->xW.nClipped = cathResp.getnClippedWX();
    t->yW.nClipped = cathResp.getnClippedWY();
    
    t->xE.maxWire = cathResp.getMaxWireEX();
    t->yE.maxWire = cathResp.getMaxWireEY();
    t->xW.maxWire = cathResp.getMaxWireWX();
    t->yW.maxWire = cathResp.getMaxWireWY();
    
    t->xE.maxValue = cathResp.getMaxSignalEX();
    t->yE.maxValue = cathResp.getMaxSignalEY();
    t->xW.maxValue = cathResp.getMaxSignalWX();
    t->yW.maxValue = cathResp.getMaxSignalWY();
    
    t->xE.cathSum = cathResp.getCathSumEX();
    t->yE.cathSum = cathResp.getCathSumEY();
    t->xW.cathSum = cathResp.getCathSumWX();
    t->yW.cathSum = cathResp.getCathSumWY();
    
    t->CathSumE = t->xE.cathSum + t->yE.cathSum;
    t->CathSumW = t->xW.cathSum + t->yW.cathSum;
    
    t->CathMaxE = t->xE.maxValue + t->yE.maxValue;
    t->CathMaxW = t->xW.maxValue + t->yW.maxValue;
    
    t->xE.rawCenter = cathResp.getWirePosEX(t->xE.maxWire);
    t->yE.rawCenter = cathResp.getWirePosEY(t->yE.maxWire);
    t->xW.rawCenter = cathResp.getWirePosWX(t->xW.maxWire);
    t->yW.rawCenter = cathResp.getWirePosWY(t->yW.maxWire);

      

    ///////////////////////////////////////////////////////////
    
    
    // Calculate pedestal-subtracted MWPC Anode PADC values
    AnodeE = ((double) Pdc30) - pedPdc30;
    AnodeW = ((double) Pdc34) - pedPdc34;

    // UCN monitor events
    bool UCNMonitorTrigger = false;
    
    float time = S83028*scalerCountsToTime;
    if (iSis00==260) {t->UCN_Mon_1_Rate->Fill(time,1./binWidth); UCNMonitorTrigger = true;}
    else if (iSis00==516) {t->UCN_Mon_2_Rate->Fill(time,1./binWidth); UCNMonitorTrigger = true;}
    else if (iSis00==1028) {t->UCN_Mon_3_Rate->Fill(time,1./binWidth); UCNMonitorTrigger = true;}
    else if (iSis00==2052) {t->UCN_Mon_4_Rate->Fill(time,1./binWidth); UCNMonitorTrigger = true;}
    

    // Events with a muon hit
    bool muonHitEast = false;
    bool muonHitWest = false;
    if ( (((double) Qadc8)  > cutEastBackingVetoQADC) ||
         (((double) Tdc018) > cutEastBackingVetoTDC)  ||
         (((double) Qadc9)  > cutEastTopVetoQADC)     ||
         (((double) Tdc019) > cutEastTopVetoTDC)      ||
         (((double) Pdc313) > cutEastDriftTubeTAC) ) {
      muonHitEast = true;
    }
    if ( (((double) Qadc10) > cutWestBackingVetoQADC) ||
         (((double) Tdc020) > cutWestBackingVetoTDC)  ||
         (((double) Pdc315) > cutWestDriftTubeTAC) ) {
      muonHitWest = true;
    }
    
    t->TaggedBackE = (((double) Qadc8)  > cutEastBackingVetoQADC || ((double) Tdc018) > cutEastBackingVetoTDC)?true:false;
    t->TaggedBackW = (((double) Qadc10)  > cutWestBackingVetoQADC || ((double) Tdc020) > cutEastBackingVetoTDC)?true:false;
    t->TaggedTopE = (((double) Qadc9)  > cutEastTopVetoQADC || ((double) Tdc019) > cutEastTopVetoTDC)?true:false;
    t->TaggedTopW = false;
    t->TaggedDriftE = (((double) Pdc313)  > cutEastDriftTubeTAC)?true:false;
    t->TaggedDriftW = (((double) Pdc315)  > cutWestDriftTubeTAC)?true:false;

    t->EastBackADC = (double) Qadc8;
    t->WestBackADC = (double) Qadc10;
    t->EastBackTDC = (double) Tdc018;
    t->WestBackTDC = (double) Tdc020;
    t->EastDriftVetoADC = (double) Pdc313;
    t->WestDriftVetoADC = (double) Pdc315;
    t->EastTopVetoADC = (double) Qadc9;
    t->EastTopVetoTDC = (double) Tdc019;
    

    // LED trigger events
    bool LEDTrigger = false;
    if ( (iSis00 == 128) || (iSis00 == 129) || (iSis00 == 130) || (iSis00 == 131) || (iSis00 == 163) ) {
      LEDTrigger = true;
    }

    // Bi pulser trigger events
    bool bismuthPulser = false;
    if (iSis00 == 32) bismuthPulser = true;

    // Scintillator events
    bool mwpcHitEast = false;
    bool mwpcHitWest = false;
    bool scintillatorHitEast = false;
    bool scintillatorHitWest = false;
    bool scintillatorHitBoth = false;
    bool coincidenceEast = false;
    bool coincidenceWest = false;
    bool scintillatorHitFirstEast = false;
    bool scintillatorHitFirstWest = false;
    bool scintillatorHitBothBad = false;
    bool triggerEast = false;
    bool triggerWest = false;

    t->PassedAnoE = t->PassedAnoW = false;
    t->PassedCathE = t->PassedCathW = false;
    
    if ( ((double) Pdc30)  > cutEastAnode) { t->PassedAnoE=true; }
    if ( ((double) Pdc34)  > cutWestAnode) { t->PassedAnoW=true; }


    // Using the cathode sum of max wires to determine MWPC trigger
    if ( maxCathSumE > CathMaxCut ) { mwpcHitEast = true; t->PassedCathE=true; }
    if ( maxCathSumW > CathMaxCut ) { mwpcHitWest = true; t->PassedCathW=true; }

    double timeEastTwoFold = ((double) Tdc016)*tdcChannelToTime;
    double timeWestTwoFold = ((double) Tdc017)*tdcChannelToTime;
    if (timeEastTwoFold > 0.*tdcChannelToTime) scintillatorHitEast = true;
    if (timeWestTwoFold > 0.*tdcChannelToTime) scintillatorHitWest = true;
    if (scintillatorHitEast && scintillatorHitWest) {
      scintillatorHitBoth = true;
      if ( (timeEastTwoFold > cutEastTwoFold) && (timeWestTwoFold < cutWestTwoFold) ) {
        scintillatorHitFirstEast = true;
      }
      else if ( (timeEastTwoFold < cutEastTwoFold) && (timeWestTwoFold > cutWestTwoFold) ) {
        scintillatorHitFirstWest = true;
      }
      else if ( (timeEastTwoFold > cutEastTwoFold) && (timeWestTwoFold > cutWestTwoFold) ) {
        scintillatorHitBothBad = true;
      }
      else if ( (timeEastTwoFold < cutEastTwoFold) && (timeWestTwoFold < cutWestTwoFold) ) {
        scintillatorHitBothBad = true;
      }
    }

    if (mwpcHitEast && scintillatorHitEast) coincidenceEast = true;
    if (mwpcHitWest && scintillatorHitWest) coincidenceWest = true;


    // Event PID logic

    type = 4; //not an electron event
    side = 2; //No scintillator triggers

    if (UCNMonitorTrigger) PID = 5;
    else if (LEDTrigger) PID = 3;
    else if (muonHitEast || muonHitWest) PID = 2;
    else if (bismuthPulser) PID = 4;
    else if ( (scintillatorHitEast && !mwpcHitEast && !scintillatorHitWest && !mwpcHitWest) ||
              (!scintillatorHitEast && !mwpcHitEast && scintillatorHitWest && !mwpcHitWest) ) { PID = 0; side = scintillatorHitEast ? 0 : 1; }
    else if ( (coincidenceEast && !scintillatorHitWest && !mwpcHitWest) ||
              (!scintillatorHitEast && !mwpcHitEast && coincidenceWest) ||
              (coincidenceEast && coincidenceWest) ||
              (coincidenceEast && !scintillatorHitWest && mwpcHitWest) ||
              (!scintillatorHitEast && mwpcHitEast && coincidenceWest) ) PID = 1;
    else PID = 6;

    
    if (PID == 1) {
      if (coincidenceEast && !scintillatorHitWest && !mwpcHitWest) {
        type = 0;
        side = 0;
      }
      if (!scintillatorHitEast && !mwpcHitEast && coincidenceWest) {
        type = 0;
        side = 1;
      }
      if (coincidenceEast && coincidenceWest) {
        type = 1;
        if (scintillatorHitFirstEast) side = 0;
        if (scintillatorHitFirstWest) side = 1;
      }
      if (coincidenceEast && !scintillatorHitWest && mwpcHitWest) {
        type = 2;
        side = 0;
      }
      if (!scintillatorHitEast && mwpcHitEast && coincidenceWest) {
        type = 2;
        side = 1;
      }
    }

    

    
    //////////////////////////////////////////////////////////////////////////////////
    /*  Swank's addition to the UK PA.  (2 of 2)
	this seems like a good spot since its around the position calculation. 
    */

    int xeRC,yeRC,xwRC,ywRC;
    WireChamberResponse * WCR = new WireChamberResponse();

    //changing the length 32 double array to length 16  float array.  using variables defined in WCR. 
    for(int j = 0; j<16; j++)
      {
	WCR->cathex[j]=Pdc2[16+j];
	WCR->cathey[j]=Pdc2[j];
	WCR->cathwx[j]=Padc[16+j];
	WCR->cathwy[j]=Padc[j];
      } 
    
    xeRC=WCR->ResponseType(WCR->cathex);   //response class x co-ordinate, East. 
    yeRC=WCR->ResponseType(WCR->cathey);   //response class y co-ordinate, East. 
    xwRC=WCR->ResponseType(WCR->cathwx);   //response class x co-ordinate, West. 
    ywRC=WCR->ResponseType(WCR->cathwy);   //response class y co-ordinate, West.

    delete WCR;
    /*
      End of swank's addtion (2 of 2)
    */
    ////////////////////////////////////////////////////////////////////////////////////
    
    // Calculate MWPC positions for electron events
    
    
    // Pass Everything to output tree
    t->TriggerNum = (int) Number;
    t->EvtN = i;
    t->Sis00 = iSis00;
    t->DeltaT = ((double)Delt0)*scalerCountsToTime;
    t->Tof = (double) S8200;
    t->TimeE = Clk0*scalerCountsToTime;
    t->TimeW = Clk1*scalerCountsToTime;
    t->Time = S83028*scalerCountsToTime;
    t->badTimeFlag = 0;
    t->oldTimeE = Clk0*scalerCountsToTime;
    t->oldTimeW = Clk1*scalerCountsToTime;
    t->oldTime = S83028*scalerCountsToTime;
    t->TDCE = (double) Tdc016;
    t->TDCW = (double) Tdc017;
    t->TDCE1 = (double) Tdc00;
    t->TDCE2 = (double) Tdc01;
    t->TDCE3 = (double) Tdc02;
    t->TDCE4 = (double) Tdc03;
    t->TDCW1 = (double) Tdc08;
    t->TDCW2 = (double) Tdc09;
    t->TDCW3 = (double) Tdc010;
    t->TDCW4 = (double) Tdc011;
    
    //Wirechambers
    
    t->xE.err = 0.;
    t->xE.rawCenter = 0.;
      
    t->yE.err = 0.;
    t->yE.rawCenter = 0.;
   
    t->xW.err = 0.;
    t->xW.rawCenter = 0.;
   
    t->yW.err = 0.;
    t->yW.rawCenter = 0.;
    
    t->ScintE.q1 = pmt[0];
    t->ScintE.q2 = pmt[1];
    t->ScintE.q3 = pmt[2];
    t->ScintE.q4 = pmt[3]; 
    t->ScintE.e1=t->ScintE.de1=t->ScintE.e2=t->ScintE.de2=t->ScintE.e3=t->ScintE.de3=t->ScintE.e4=t->ScintE.de4=0.;
    t->ScintE.energy=t->ScintE.denergy=0.;
    t->ScintE.nPE1=t->ScintE.nPE2=t->ScintE.nPE3=t->ScintE.nPE4=0.;
    
    t->ScintW.q1 = pmt[4];
    t->ScintW.q2 = pmt[5];
    t->ScintW.q3 = pmt[6];
    t->ScintW.q4 = pmt[7]; 
    t->ScintW.e1=t->ScintW.de1=t->ScintW.e2=t->ScintW.de2=t->ScintW.e3=t->ScintW.de3=t->ScintW.e4=t->ScintW.de4=0.;
    t->ScintW.energy=t->ScintW.denergy=0.;
    t->ScintW.nPE1=t->ScintW.nPE2=t->ScintW.nPE3=t->ScintW.nPE4=0.;

    t->ScintE_bare.q1 = pmt[0];
    t->ScintE_bare.q2 = pmt[1];
    t->ScintE_bare.q3 = pmt[2];
    t->ScintE_bare.q4 = pmt[3]; 
    t->ScintE_bare.e1=t->ScintE_bare.de1=t->ScintE_bare.e2=t->ScintE_bare.de2=t->ScintE_bare.e3=t->ScintE_bare.de3=t->ScintE_bare.e4=t->ScintE_bare.de4=0.;
    t->ScintE_bare.energy=t->ScintE_bare.denergy=0.;
    t->ScintE_bare.nPE1=t->ScintE_bare.nPE2=t->ScintE_bare.nPE3=t->ScintE_bare.nPE4=0.;
    
    t->ScintW_bare.q1 = pmt[4];
    t->ScintW_bare.q2 = pmt[5];
    t->ScintW_bare.q3 = pmt[6];
    t->ScintW_bare.q4 = pmt[7]; 
    t->ScintW_bare.e1=t->ScintW_bare.de1=t->ScintW_bare.e2=t->ScintW_bare.de2=t->ScintW_bare.e3=t->ScintW_bare.de3=t->ScintW_bare.e4=t->ScintW_bare.de4=0.;
    t->ScintW_bare.energy=t->ScintW_bare.denergy=0.;
    t->ScintW_bare.nPE1=t->ScintW_bare.nPE2=t->ScintW_bare.nPE3=t->ScintW_bare.nPE4=0.;
    
    t->EvisE = t->EvisW = 0.;
    
    t->CathSumE =  t->xE.cathSum+t->yE.cathSum;
    t->CathSumW =  t->xW.cathSum+t->yW.cathSum;
    
    t->CathMaxE = (t->xE.maxValue>t->yE.maxValue)?t->yE.maxValue:t->xE.maxValue;
    t->CathMaxW = (t->xW.maxValue>t->yW.maxValue)?t->yW.maxValue:t->xW.maxValue;
    
    t->EMWPC_E = t->EMWPC_W = 0.;
    
    t->AnodeE = AnodeE; // Pedestal subtracted
    t->AnodeW = AnodeW;
    
    t->EvnbGood = t->BkhfGood = true;
    for (Int_t i = 0; i<5; i++) {
      if ((int)Evnb[i]-t->TriggerNum) t->EvnbGood = false;
      if ((int)Bkhf[i]!=17) t->BkhfGood = false;
    }
    
    t->xeRC = xeRC;
    t->yeRC = yeRC;
    t->xwRC = xwRC;
    t->ywRC = ywRC;
    
    t->PID = PID;
    t->Type = type;
    t->Side = side;
    t->ProbIII = 0.;
    t->Erecon = 0.;
    t->Erecon_ee = 0.;
    t->old_Erecon = 0.;
    t->gaus_Erecon = 0.;


      /*timeE_BB = Clk2*scalerCountsToTime;
      timeW_BB = Clk3*scalerCountsToTime;
      UBtime = S83028*scalerCountsToTime;
      UBtime_BB = S8200*scalerCountsToTime;
      twoFoldE = Tdc016;
      twoFoldW = Tdc017;*/
  
    t->fillOutputTree();
    
  }
  
  fileIn->Close();

  
  // Write output ntuple
  t->writeOutputFile();
  delete t;


  if ( checkIfReplayFileIsGood(std::string(tempOut)) != 1 ) {

    std::ofstream badRuns("badRuns.txt", std::fstream::app);
    badRuns << argv[1] << "\n";
    badRuns.close();

  }
  

  return 0;
}