ROOT logo
// Test Macro, shows how to load Hits and Geometry, and how can we get 
// some of the parameters and variables.
// Author: Gustavo Conesa

void TestEMCALHit()
{
  
  // Getting EMCAL Detector and Geometry.
  
  AliRunLoader *rl = AliRunLoader::Open("galice.root",AliConfig::GetDefaultEventFolderName(),"read");
  
  if (rl == 0x0)
    cout<<"Can not instatiate the Run Loader"<<endl;
  
  rl->LoadgAlice();//Needed to get geometry
  
  AliEMCALLoader *emcalLoader = dynamic_cast<AliEMCALLoader*>
    (rl->GetDetectorLoader("EMCAL"));
  
  TGeoManager::Import("geometry.root");
  
  AliRun * alirun   = rl->GetAliRun(); // Needed to get Geometry
  AliEMCALGeometry * geom ;
  if(alirun){
    AliEMCAL * emcal  = (AliEMCAL*)alirun->GetDetector("EMCAL");
    geom = emcal->GetGeometry();
  }
  
  if (geom == 0) cout<<"Did not get geometry from EMCALLoader"<<endl;
  //else   geom->PrintGeometry();
  
  //Load Hits
  rl->LoadHits("EMCAL");
  
  //Get maximum number of events
  Int_t maxevent =  rl->GetNumberOfEvents();
  cout<<"Number of events "<<maxevent<<endl;
  //maxevent = 8000 ;
  
  
  AliEMCALHit * hit;
  TClonesArray *hits = 0;
  
  for (Int_t iEvent=0; iEvent<maxevent; iEvent++)
    {
      //cout <<  " ======> Event " << iEvent <<endl ;  
      //Load Event
      rl->GetEvent(iEvent);
      Float_t elos=-1;
      Float_t time  = -1 ;
      Int_t id      = -1 ;
      Int_t iSupMod =  0 ;
      Int_t iTower  =  0 ;
      Int_t iIphi   =  0 ;
      Int_t iIeta   =  0 ;
      Int_t iphi    =  0 ;
      Int_t ieta    =  0 ;
      
      //Fill array of hits
      cout <<  " ======> Event " << iEvent << endl; 
      
      
      //Get hits from the list      
      
      //Hits are stored in different branches in the hits Tree, 
      //first get the branch and then access the hits in the branch
      TTree *treeH = emcalLoader->TreeH();	
      if (treeH) {
	// TreeH exists, get the branch
	Int_t nTrack = treeH->GetEntries();  // TreeH has array of hits for every primary
	TBranch * branchH = treeH->GetBranch("EMCAL");
	branchH->SetAddress(&hits);
	for (Int_t iTrack = 0; iTrack < nTrack; iTrack++) {
	  branchH->GetEntry(iTrack);
	  //Now get the hits in this branch
	  Int_t nHit = hits->GetEntriesFast();
	  for(Int_t ihit = 0; ihit< nHit;ihit++){
	    hit = static_cast<AliEMCALHit *>hits->At(ihit);//(hits->At(ihit)) ;
	    
	    if(hit != 0){
	      id   = hit->GetId() ; //cell (hit) label
	      elos = hit->GetEnergy(); //amplitude in cell (hit)
	      time = hit->GetTime();//time of creation of hit after collision
	      
	      cout<<"Hit ID "<<id<<" ELoss "<<elos;
	      
	      //Geometry methods  
	      if(geom){
		geom->GetCellIndex(id,iSupMod,iTower,iIphi,iIeta); 
		//Gives SuperModule and Tower numbers
		geom->GetCellPhiEtaIndexInSModule(iSupMod,iTower,
						  iIphi, iIeta,iphi,ieta);
		//Gives label of cell in eta-phi position per each supermodule
		// cout<< "SModule "<<iSupMod<<"; Tower "<<iTower <<"; Eta "<<iIeta
		//<<"; Phi "<<iIphi<<"; Cell Eta "<<ieta<<"; Cell Phi "<<iphi<<endl;
		cout<< ";  SModule "<<iSupMod<<"; Cell Eta "<<ieta<<"; Cell Phi "<<iphi<<endl;
	      }//geom?
	    }//hit?
	    else
	      cout<<"Hit pointer 0x0"<<endl;
	  }//hit loop
	}// track loop
      }//treeH?
    }//event loop
}

 TestEMCALHit.C:1
 TestEMCALHit.C:2
 TestEMCALHit.C:3
 TestEMCALHit.C:4
 TestEMCALHit.C:5
 TestEMCALHit.C:6
 TestEMCALHit.C:7
 TestEMCALHit.C:8
 TestEMCALHit.C:9
 TestEMCALHit.C:10
 TestEMCALHit.C:11
 TestEMCALHit.C:12
 TestEMCALHit.C:13
 TestEMCALHit.C:14
 TestEMCALHit.C:15
 TestEMCALHit.C:16
 TestEMCALHit.C:17
 TestEMCALHit.C:18
 TestEMCALHit.C:19
 TestEMCALHit.C:20
 TestEMCALHit.C:21
 TestEMCALHit.C:22
 TestEMCALHit.C:23
 TestEMCALHit.C:24
 TestEMCALHit.C:25
 TestEMCALHit.C:26
 TestEMCALHit.C:27
 TestEMCALHit.C:28
 TestEMCALHit.C:29
 TestEMCALHit.C:30
 TestEMCALHit.C:31
 TestEMCALHit.C:32
 TestEMCALHit.C:33
 TestEMCALHit.C:34
 TestEMCALHit.C:35
 TestEMCALHit.C:36
 TestEMCALHit.C:37
 TestEMCALHit.C:38
 TestEMCALHit.C:39
 TestEMCALHit.C:40
 TestEMCALHit.C:41
 TestEMCALHit.C:42
 TestEMCALHit.C:43
 TestEMCALHit.C:44
 TestEMCALHit.C:45
 TestEMCALHit.C:46
 TestEMCALHit.C:47
 TestEMCALHit.C:48
 TestEMCALHit.C:49
 TestEMCALHit.C:50
 TestEMCALHit.C:51
 TestEMCALHit.C:52
 TestEMCALHit.C:53
 TestEMCALHit.C:54
 TestEMCALHit.C:55
 TestEMCALHit.C:56
 TestEMCALHit.C:57
 TestEMCALHit.C:58
 TestEMCALHit.C:59
 TestEMCALHit.C:60
 TestEMCALHit.C:61
 TestEMCALHit.C:62
 TestEMCALHit.C:63
 TestEMCALHit.C:64
 TestEMCALHit.C:65
 TestEMCALHit.C:66
 TestEMCALHit.C:67
 TestEMCALHit.C:68
 TestEMCALHit.C:69
 TestEMCALHit.C:70
 TestEMCALHit.C:71
 TestEMCALHit.C:72
 TestEMCALHit.C:73
 TestEMCALHit.C:74
 TestEMCALHit.C:75
 TestEMCALHit.C:76
 TestEMCALHit.C:77
 TestEMCALHit.C:78
 TestEMCALHit.C:79
 TestEMCALHit.C:80
 TestEMCALHit.C:81
 TestEMCALHit.C:82
 TestEMCALHit.C:83
 TestEMCALHit.C:84
 TestEMCALHit.C:85
 TestEMCALHit.C:86
 TestEMCALHit.C:87
 TestEMCALHit.C:88
 TestEMCALHit.C:89
 TestEMCALHit.C:90
 TestEMCALHit.C:91
 TestEMCALHit.C:92
 TestEMCALHit.C:93
 TestEMCALHit.C:94
 TestEMCALHit.C:95
 TestEMCALHit.C:96
 TestEMCALHit.C:97
 TestEMCALHit.C:98
 TestEMCALHit.C:99
 TestEMCALHit.C:100
 TestEMCALHit.C:101
 TestEMCALHit.C:102
 TestEMCALHit.C:103
 TestEMCALHit.C:104
 TestEMCALHit.C:105
 TestEMCALHit.C:106
 TestEMCALHit.C:107