ROOT logo
//Do a fast test of the different EMCAL data objects
void TestEMCALData() {
  
  TH1F* hE = new TH1F("hEmcalHits",    "Hits energy distribution in EMCAL",       100, 0., 10.) ;
  hE->Sumw2() ;
  TH1I* hM = new TH1I("hEmcalHitsMul", "Hits multiplicity distribution in EMCAL", 500, 0., 10000) ;
  hM->Sumw2() ;
  
  TH1I * dA = new TH1I("hEmcalDigits",    "Digits amplitude distribution in EMCAL",    500, 0, 5000) ;
  dA->Sumw2() ;
  TH1I * dM = new TH1I("hEmcalDigitsMul", "Digits multiplicity distribution in EMCAL", 500, 0, 1000) ;
  dM->Sumw2() ;
  
  TH1F * sE = new TH1F("hEmcalSDigits",    "SDigits energy distribution in EMCAL",    200, 0, 1000) ;
  sE->Sumw2() ;
  TH1I * sM = new TH1I("hEmcalSDigitsMul", "SDigits multiplicity distribution in EMCAL", 500, 0, 1000) ;
  sM->Sumw2() ;
  
  TH1F * cE = new TH1F("hEmcalRecPoints",    "RecPoints energy distribution in EMCAL",    100, 0, 20) ;
  cE->Sumw2() ;
  TH1I * cM = new TH1I("hEmcalRecPointsMul", "RecPoints multiplicity distribution in EMCAL", 500, 0, 1000) ;
  cM->Sumw2() ;
  
  AliRunLoader *rl = AliRunLoader::Open("galice.root",AliConfig::GetDefaultEventFolderName(),"read");
  if (rl == 0x0)
    cout<<"Can not instatiate the Run Loader"<<endl;
  
  AliEMCALLoader *emcalLoader = dynamic_cast<AliEMCALLoader*>
    (rl->GetDetectorLoader("EMCAL"));
  
  //Load Hits
  rl->LoadHits("EMCAL");
  //Load Digits
  rl->LoadDigits("EMCAL");
  //Load SDigits
  rl->LoadSDigits("EMCAL");
  //Load RecPoints
  rl->LoadRecPoints("EMCAL");
  
  
  //one way to do it that works for all three
  AliEMCALHit* hit;
  AliEMCALDigit* dig;
  AliEMCALRecPoint* rp;
  
  rl->GetEvent(0);

  TClonesArray *hits = 0;  
  //Fill array of digits                                                                        
  TClonesArray *sdigits = emcalLoader->SDigits();
  //Fill array of digits                                                                        
  TClonesArray *digits = emcalLoader->Digits();
  //Fill array of clusters                                                                        
  //TObjArray *clusters = emcalLoader->RecPoints(); //It should work, need to FIX
  TObjArray *clusters = 0;
  
  //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
  Int_t nHit = 0;
  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);
    //Now get the hits in this branch
    for (Int_t iTrack = 0; iTrack < nTrack; iTrack++) {
      branchH->GetEntry(iTrack);
      Int_t nHit = hits->GetEntriesFast();
      for(Int_t ihit = 0; ihit< nHit;ihit++){
        hit = static_cast<AliEMCALHit *>hits->At(ihit);
        if(hit != 0){
          nHit++;
          hE->Fill(hit->GetEnergy());
          cout<<"Hit Info "<<hit->GetId()<<" ELoss "<<hit->GetEnergy()<<endl;
        }//hit?
      }//hit loop
    }// track loop
  }//treeH?
  
  hM->Fill(nHit);
  
  //Get digits from the list    
  if(sdigits){
    sM->Fill(sdigits->GetEntries());
    for(Int_t isdig = 0; isdig< sdigits->GetEntries();isdig++){
      //cout<<">> idig "<<idig<<endl;                                                             
      dig = static_cast<AliEMCALDigit *>(sdigits->At(isdig)) ;
      
      if(dig != 0){
        sE->Fill(dig->GetAmplitude());
        cout << "SDigit info " << dig->GetId() << " " << dig->GetAmplitude() << endl;
      }
    }
  }
  else printf("No Sdigits available\n");
  
  
  //Get digits from the list    
  if(digits){
    dM->Fill(digits->GetEntries());
    for(Int_t idig = 0; idig< digits->GetEntries();idig++){
      //cout<<">> idig "<<idig<<endl;                                                             
      dig = static_cast<AliEMCALDigit *>(digits->At(idig)) ;
    
      if(dig != 0){
        dA->Fill(dig->GetAmplitude());
        cout << "Digit info " << dig->GetId() << " " << dig->GetAmplitude() << endl;
      }
    }
  }
  else printf("No digits available\n");
  
  //Get clusters from the list 
  TTree *treeR = emcalLoader->TreeR();
  TBranch * branchR = treeR->GetBranch("EMCALECARP");	
  branchR->SetAddress(&clusters);
  branchR->GetEntry(0);
  
  if(clusters){
    cM->Fill(clusters->GetEntries());
    for(Int_t iclu = 0; iclu< clusters->GetEntries();iclu++){
      //cout<<">> idig "<<idig<<endl;                                                             
      rp = static_cast<AliEMCALRecPoint *>(clusters->At(iclu)) ;
      
      if(rp != 0){
	cE->Fill(rp->GetEnergy());
	cout << "RecPoint info " << rp->GetAbsId(0) << " " << rp->GetEnergy() << endl;
      }
    }
  }else printf("No recpoints available\n");
  
  /*
   //another way to do it
   TTree *hTree = rl->GetTreeH("EMCAL",false);
   TTree *dTree = rl->GetTreeD("EMCAL",false);
   TTree *sTree = rl->GetTreeS("EMCAL",false);
   TTree *cTree = rl->GetTreeR("EMCAL",false);
   
   TObjArray *harr=NULL;
   TBranch *hbranch=hTree->GetBranch("EMCAL");
   hbranch->SetAddress(&harr);
   
   TObjArray *darr=NULL;
   TBranch *dbranch=dTree->GetBranch("EMCAL");
   dbranch->SetAddress(&darr);
   
   TObjArray *sarr=NULL;
   TBranch *sbranch=sTree->GetBranch("EMCAL");
   sbranch->SetAddress(&sarr);
   
   TObjArray *carr=NULL;
   TBranch *cbranch=cTree->GetBranch("EMCALECARP");
   cbranch->SetAddress(&carr);
   
   
   if(hbranch->GetEvent(0)) {
   for(Int_t ih = 0; ih < harr->GetEntriesFast(); ih++) {
   hM->Fill(harr->GetEntriesFast());
   AliEMCALHit* hit =(AliEMCALHit*)harr->UncheckedAt(ih);
   if(hit != 0){
	 hE->Fill(hit->GetEnergy());
	 cout << "Hit info " << hit->GetId() << " " << hit->GetEnergy()*10.5 << endl;
   }
   }
   }
   
   if(dbranch->GetEvent(0)) {
   for(Int_t id = 0; id < darr->GetEntriesFast(); id++) {
   dM->Fill(darr->GetEntriesFast());
   AliEMCALDigit* dig =(AliEMCALDigit*)darr->UncheckedAt(id);
   if(dig != 0){
	 dA->Fill(dig->GetAmp());
	 cout << "Digit info " << dig->GetId() << " " << dig->GetAmp() << endl;
   }
   }
   }
   
   if(sbranch->GetEvent(0)) {
   for(Int_t id = 0; id < sarr->GetEntriesFast(); id++) {
   sM->Fill(sarr->GetEntriesFast());
   AliEMCALDigit* sdig =(AliEMCALDigit*)sarr->UncheckedAt(id);
   if(sdig != 0){
	 sE->Fill(sdig->GetAmp()/1.e+6);
	 cout << "SDigit info " << sdig->GetId() << " " << sdig->GetAmp()/1.e+6 << endl;
   }
   }
   }
   
   if(cbranch->GetEvent(0)) {
   for(Int_t ic = 0; ic < carr->GetEntriesFast(); ic++) {
   cE->Fill(carr->GetEntriesFast());
   AliEMCALRecPoint* rp =(AliEMCALRecPoint*)carr->UncheckedAt(ic);
   if(rp != 0){
	 cE->Fill(rp->GetEnergy());
	 cout << "RecPoint info " << rp->GetAbsId() << " " << rp->GetEnergy() << endl;
   }
   }
   }
   
   */
  
  TCanvas *chits = new TCanvas("chits","Hits",20,20,800,400);
  chits->Divide(2,1);
  chits->cd(1);
  hE->Draw();
  chits->cd(2);
  hM->Draw();
  
  TCanvas *cdig = new TCanvas("cdig","Digits",20,40,800,400);
  cdig->Divide(2,1);
  cdig->cd(1);
  dA->Draw();
  cdig->cd(2);
  dM->Draw();
  
  
  TCanvas *csdig = new TCanvas("csdig","SDigits",20,60,800,400);
  csdig->Divide(2,1);
  csdig->cd(1);
  sE->Draw();
  csdig->cd(2);
  sM->Draw();
  
  TCanvas *cclu = new TCanvas("cclu","Clusters",20,60,800,400);
  cclu->Divide(2,1);
  cclu->cd(1);
  cE->Draw();
  cclu->cd(2);
  cM->Draw();
  
}
 TestEMCALData.C:1
 TestEMCALData.C:2
 TestEMCALData.C:3
 TestEMCALData.C:4
 TestEMCALData.C:5
 TestEMCALData.C:6
 TestEMCALData.C:7
 TestEMCALData.C:8
 TestEMCALData.C:9
 TestEMCALData.C:10
 TestEMCALData.C:11
 TestEMCALData.C:12
 TestEMCALData.C:13
 TestEMCALData.C:14
 TestEMCALData.C:15
 TestEMCALData.C:16
 TestEMCALData.C:17
 TestEMCALData.C:18
 TestEMCALData.C:19
 TestEMCALData.C:20
 TestEMCALData.C:21
 TestEMCALData.C:22
 TestEMCALData.C:23
 TestEMCALData.C:24
 TestEMCALData.C:25
 TestEMCALData.C:26
 TestEMCALData.C:27
 TestEMCALData.C:28
 TestEMCALData.C:29
 TestEMCALData.C:30
 TestEMCALData.C:31
 TestEMCALData.C:32
 TestEMCALData.C:33
 TestEMCALData.C:34
 TestEMCALData.C:35
 TestEMCALData.C:36
 TestEMCALData.C:37
 TestEMCALData.C:38
 TestEMCALData.C:39
 TestEMCALData.C:40
 TestEMCALData.C:41
 TestEMCALData.C:42
 TestEMCALData.C:43
 TestEMCALData.C:44
 TestEMCALData.C:45
 TestEMCALData.C:46
 TestEMCALData.C:47
 TestEMCALData.C:48
 TestEMCALData.C:49
 TestEMCALData.C:50
 TestEMCALData.C:51
 TestEMCALData.C:52
 TestEMCALData.C:53
 TestEMCALData.C:54
 TestEMCALData.C:55
 TestEMCALData.C:56
 TestEMCALData.C:57
 TestEMCALData.C:58
 TestEMCALData.C:59
 TestEMCALData.C:60
 TestEMCALData.C:61
 TestEMCALData.C:62
 TestEMCALData.C:63
 TestEMCALData.C:64
 TestEMCALData.C:65
 TestEMCALData.C:66
 TestEMCALData.C:67
 TestEMCALData.C:68
 TestEMCALData.C:69
 TestEMCALData.C:70
 TestEMCALData.C:71
 TestEMCALData.C:72
 TestEMCALData.C:73
 TestEMCALData.C:74
 TestEMCALData.C:75
 TestEMCALData.C:76
 TestEMCALData.C:77
 TestEMCALData.C:78
 TestEMCALData.C:79
 TestEMCALData.C:80
 TestEMCALData.C:81
 TestEMCALData.C:82
 TestEMCALData.C:83
 TestEMCALData.C:84
 TestEMCALData.C:85
 TestEMCALData.C:86
 TestEMCALData.C:87
 TestEMCALData.C:88
 TestEMCALData.C:89
 TestEMCALData.C:90
 TestEMCALData.C:91
 TestEMCALData.C:92
 TestEMCALData.C:93
 TestEMCALData.C:94
 TestEMCALData.C:95
 TestEMCALData.C:96
 TestEMCALData.C:97
 TestEMCALData.C:98
 TestEMCALData.C:99
 TestEMCALData.C:100
 TestEMCALData.C:101
 TestEMCALData.C:102
 TestEMCALData.C:103
 TestEMCALData.C:104
 TestEMCALData.C:105
 TestEMCALData.C:106
 TestEMCALData.C:107
 TestEMCALData.C:108
 TestEMCALData.C:109
 TestEMCALData.C:110
 TestEMCALData.C:111
 TestEMCALData.C:112
 TestEMCALData.C:113
 TestEMCALData.C:114
 TestEMCALData.C:115
 TestEMCALData.C:116
 TestEMCALData.C:117
 TestEMCALData.C:118
 TestEMCALData.C:119
 TestEMCALData.C:120
 TestEMCALData.C:121
 TestEMCALData.C:122
 TestEMCALData.C:123
 TestEMCALData.C:124
 TestEMCALData.C:125
 TestEMCALData.C:126
 TestEMCALData.C:127
 TestEMCALData.C:128
 TestEMCALData.C:129
 TestEMCALData.C:130
 TestEMCALData.C:131
 TestEMCALData.C:132
 TestEMCALData.C:133
 TestEMCALData.C:134
 TestEMCALData.C:135
 TestEMCALData.C:136
 TestEMCALData.C:137
 TestEMCALData.C:138
 TestEMCALData.C:139
 TestEMCALData.C:140
 TestEMCALData.C:141
 TestEMCALData.C:142
 TestEMCALData.C:143
 TestEMCALData.C:144
 TestEMCALData.C:145
 TestEMCALData.C:146
 TestEMCALData.C:147
 TestEMCALData.C:148
 TestEMCALData.C:149
 TestEMCALData.C:150
 TestEMCALData.C:151
 TestEMCALData.C:152
 TestEMCALData.C:153
 TestEMCALData.C:154
 TestEMCALData.C:155
 TestEMCALData.C:156
 TestEMCALData.C:157
 TestEMCALData.C:158
 TestEMCALData.C:159
 TestEMCALData.C:160
 TestEMCALData.C:161
 TestEMCALData.C:162
 TestEMCALData.C:163
 TestEMCALData.C:164
 TestEMCALData.C:165
 TestEMCALData.C:166
 TestEMCALData.C:167
 TestEMCALData.C:168
 TestEMCALData.C:169
 TestEMCALData.C:170
 TestEMCALData.C:171
 TestEMCALData.C:172
 TestEMCALData.C:173
 TestEMCALData.C:174
 TestEMCALData.C:175
 TestEMCALData.C:176
 TestEMCALData.C:177
 TestEMCALData.C:178
 TestEMCALData.C:179
 TestEMCALData.C:180
 TestEMCALData.C:181
 TestEMCALData.C:182
 TestEMCALData.C:183
 TestEMCALData.C:184
 TestEMCALData.C:185
 TestEMCALData.C:186
 TestEMCALData.C:187
 TestEMCALData.C:188
 TestEMCALData.C:189
 TestEMCALData.C:190
 TestEMCALData.C:191
 TestEMCALData.C:192
 TestEMCALData.C:193
 TestEMCALData.C:194
 TestEMCALData.C:195
 TestEMCALData.C:196
 TestEMCALData.C:197
 TestEMCALData.C:198
 TestEMCALData.C:199
 TestEMCALData.C:200
 TestEMCALData.C:201
 TestEMCALData.C:202
 TestEMCALData.C:203
 TestEMCALData.C:204
 TestEMCALData.C:205
 TestEMCALData.C:206
 TestEMCALData.C:207
 TestEMCALData.C:208
 TestEMCALData.C:209
 TestEMCALData.C:210
 TestEMCALData.C:211
 TestEMCALData.C:212
 TestEMCALData.C:213
 TestEMCALData.C:214
 TestEMCALData.C:215
 TestEMCALData.C:216
 TestEMCALData.C:217
 TestEMCALData.C:218
 TestEMCALData.C:219
 TestEMCALData.C:220
 TestEMCALData.C:221
 TestEMCALData.C:222
 TestEMCALData.C:223
 TestEMCALData.C:224
 TestEMCALData.C:225
 TestEMCALData.C:226
 TestEMCALData.C:227
 TestEMCALData.C:228
 TestEMCALData.C:229
 TestEMCALData.C:230
 TestEMCALData.C:231
 TestEMCALData.C:232
 TestEMCALData.C:233
 TestEMCALData.C:234
 TestEMCALData.C:235