#ifndef comparison_h
#define comparison_h

#include <TROOT.h>
#include <TChain.h>
#include <TFile.h>
#include <TH1F.h>

class comparison {
public :
   TTree          *fChain;   //!pointer to the analyzed TTree or TChain
   Int_t           fCurrent; //!current Tree number in a TChain

   // Histograms
   TH1F* _th1AllCells;
   TH1F* _th1FinalCells;
   TH1F* _th1MissedCells;
   TH1F* _th1DeltaADC;

   // Declaration of leave types
   Int_t           eventNum;
   Int_t           runNum;
   Int_t           nCells;
   Int_t           nCellsCalChunk;
   Int_t           Clayer[60000];   //[nCells]
   Int_t           Ciphi[60000];   //[nCells]
   Int_t           Cieta[60000];   //[nCells]
   Int_t           Cstatus[60000];   //[nCells]
   Float_t         CE[60000];   //[nCells]
   Float_t         CpT[60000];   //[nCells]
   Int_t           Cchannel[60000];   //[nCells]
   Int_t           Cadccounts[60000];   //[nCells]

   // List of branches
   TBranch        *b_eventNum;   //!
   TBranch        *b_runNum;   //!
   TBranch        *b_nCells;   //!
   TBranch        *b_nCellsCalChunk;   //!
   TBranch        *b_Clayer;   //!
   TBranch        *b_Ciphi;   //!
   TBranch        *b_Cieta;   //!
   TBranch        *b_Cstatus;   //!
   TBranch        *b_CE;   //!
   TBranch        *b_CpT;   //!
   TBranch        *b_Cchannel;   //!
   TBranch        *b_Cadccounts;   //!

   comparison(TTree *tree=0);
   virtual ~comparison();
   virtual Int_t    Cut(Long64_t entry);
   virtual Int_t    GetEntry(Long64_t entry);
   virtual Long64_t LoadTree(Long64_t entry);
   virtual void     Init(TTree *tree);
   virtual void     Loop();
   virtual Bool_t   Notify();
   virtual void     Show(Long64_t entry = -1);
};

#endif

#ifdef comparison_cxx
comparison::comparison(TTree *tree)
{
// if parameter tree is not specified (or zero), connect the file
// used to generate this class and read the Tree.
   if (tree == 0) {
      TFile *f = (TFile*)gROOT->GetListOfFiles()->FindObject("CalCellValid.root");
      if (!f) {
         f = new TFile("CalCellValid.root");
      }
      tree = (TTree*)gDirectory->Get("tree");

   }
   Init(tree);
}

comparison::~comparison()
{
   if (!fChain) return;
   delete fChain->GetCurrentFile();
}

Int_t comparison::GetEntry(Long64_t entry)
{
// Read contents of entry.
   if (!fChain) return 0;
   return fChain->GetEntry(entry);
}
Long64_t comparison::LoadTree(Long64_t entry)
{
// Set the environment to read one entry
   if (!fChain) return -5;
   Long64_t centry = fChain->LoadTree(entry);
   if (centry < 0) return centry;
   if (fChain->IsA() != TChain::Class()) return centry;
   TChain *chain = (TChain*)fChain;
   if (chain->GetTreeNumber() != fCurrent) {
      fCurrent = chain->GetTreeNumber();
      Notify();
   }
   return centry;
}

void comparison::Init(TTree *tree)
{
   // The Init() function is called when the selector needs to initialize
   // a new tree or chain. Typically here the branch addresses of the tree
   // will be set. It is normaly not necessary to make changes to the
   // generated code, but the routine can be extended by the user if needed.
   // Init() will be called many times when running with PROOF.

   // Set branch addresses
   if (tree == 0) return;
   fChain = tree;
   fCurrent = -1;
   fChain->SetMakeClass(1);

   fChain->SetBranchAddress("eventNum",&eventNum);
   fChain->SetBranchAddress("runNum",&runNum);
   fChain->SetBranchAddress("nCells",&nCells);
   fChain->SetBranchAddress("nCellsCalChunk",&nCellsCalChunk);
   fChain->SetBranchAddress("Clayer",Clayer);
   fChain->SetBranchAddress("Ciphi",Ciphi);
   fChain->SetBranchAddress("Cieta",Cieta);
   fChain->SetBranchAddress("Cstatus",Cstatus);
   fChain->SetBranchAddress("CE",CE);
   fChain->SetBranchAddress("CpT",CpT);
   fChain->SetBranchAddress("Cchannel",Cchannel);
   fChain->SetBranchAddress("Cadccounts",Cadccounts);
   Notify();
}

Bool_t comparison::Notify()
{
   // The Notify() function is called when a new file is opened. This
   // can be either for a new TTree in a TChain or when when a new TTree
   // is started when using PROOF. Typically here the branch pointers
   // will be retrieved. It is normaly not necessary to make changes
   // to the generated code, but the routine can be extended by the
   // user if needed.

   // Get branch pointers
   b_eventNum = fChain->GetBranch("eventNum");
   b_runNum = fChain->GetBranch("runNum");
   b_nCells = fChain->GetBranch("nCells");
   b_nCellsCalChunk = fChain->GetBranch("nCellsCalChunk");
   b_Clayer = fChain->GetBranch("Clayer");
   b_Ciphi = fChain->GetBranch("Ciphi");
   b_Cieta = fChain->GetBranch("Cieta");
   b_Cstatus = fChain->GetBranch("Cstatus");
   b_CE = fChain->GetBranch("CE");
   b_CpT = fChain->GetBranch("CpT");
   b_Cchannel = fChain->GetBranch("Cchannel");
   b_Cadccounts = fChain->GetBranch("Cadccounts");

   return kTRUE;
}

void comparison::Show(Long64_t entry)
{
// Print contents of entry.
// If entry is not specified, print current entry
   if (!fChain) return;
   fChain->Show(entry);
}
Int_t comparison::Cut(Long64_t entry)
{
// This function may be called from Loop.
// returns  1 if entry is accepted.
// returns -1 otherwise.
   return 1;
}
#endif // #ifdef comparison_cxx