1 //*********************************************************************
2 // - AliEVE implementation -
3 // Fill containers for visualisation of EMCAL data structures
4 // - read and store MC Hits
5 // - read and store digits from esds or runloader
6 // - read and store clusters from esds or runloader
8 // Author: Magali Estienne (magali.estienne@cern.ch)
10 //*********************************************************************
16 #include <TObjArray.h>
17 #include <TRefArray.h>
18 #include <TClonesArray.h>
19 #include <TEvePointSet.h>
22 #include "AliRunLoader.h"
23 #include "AliEMCALLoader.h"
24 #include "AliESDEvent.h"
25 #include "AliESDVertex.h"
27 #include "AliEMCALGeometry.h"
28 #include "AliEMCALHit.h"
29 #include "AliEMCALDigit.h"
30 #include "AliEMCALRecPoint.h"
31 #include "AliESDCaloCells.h"
32 #include "AliESDCaloCluster.h"
34 #include "AliEveEMCALData.h"
35 #include "AliEveEMCALSModule.h"
36 #include "AliEveEMCALSModuleData.h"
38 ClassImp(AliEveEMCALData)
40 //______________________________________________________________________________
41 AliEveEMCALData::AliEveEMCALData():
64 // for(Int_t i=0; i<12; i++)
66 // for(Int_t i=0; i<10; i++)
68 // fSMhalf[0] = fSMhalf[1] = 0x0;
75 //______________________________________________________________________________
76 AliEveEMCALData::AliEveEMCALData(AliRunLoader* rl, TGeoNode* node, TGeoHMatrix* m):
99 // for(Int_t i=0; i<12; i++)
101 // for(Int_t i=0; i<10; i++)
103 // fSMhalf[0] = fSMhalf[1] = 0x0;
110 //______________________________________________________________________________
111 AliEveEMCALData::~AliEveEMCALData()
117 DeleteSuperModules();
126 //______________________________________________________________________________
127 void AliEveEMCALData::Reset()
132 //______________________________________________________________________________
133 AliEveEMCALData::AliEveEMCALData(const AliEveEMCALData &edata) :
136 fEmcal(edata.fEmcal),
139 fHMatrix(edata.fHMatrix),
143 fNsmfull(edata.fNsmfull),
144 fNsmhalf(edata.fNsmhalf),
146 fSMfull(edata.fSMfull),
147 fSMhalf(edata.fSMhalf),
148 fRunLoader(edata.fRunLoader),
149 fDebug(edata.fDebug),
155 InitEMCALGeom(edata.fRunLoader);
159 //______________________________________________________________________________
160 AliEveEMCALData& AliEveEMCALData::operator=(const AliEveEMCALData &edata)
163 // Assignment operator
166 if (this != &edata) {
174 //______________________________________________________________________________
175 void AliEveEMCALData::SetTree(TTree* tree)
178 // Set digit-tree to be used for digit retrieval.
179 // Data is loaded on demand.
186 //______________________________________________________________________________
187 void AliEveEMCALData::SetESD(AliESDEvent* esd)
196 //______________________________________________________________________________
197 void AliEveEMCALData::SetNode(TGeoNode* node)
206 //______________________________________________________________________________
207 void AliEveEMCALData::InitEMCALGeom(AliRunLoader* rl)
210 // Set data members for EMCAL geometry
213 fEmcal = (AliEMCAL*) rl->GetAliRun()->GetDetector("EMCAL");
214 fGeom = (AliEMCALGeometry*) fEmcal->GetGeometry();
218 //______________________________________________________________________________
219 void AliEveEMCALData::GetGeomInfo(Int_t id, Int_t &iSupMod, Double_t& x, Double_t& y, Double_t& z)
222 // Get geometrical information from hit/digit/cluster absolute id
230 fGeom->GetCellIndex(id,iSupMod,iTower,iIphi,iIeta);
231 //Gives SuperModule and Tower numbers
232 fGeom->RelPosCellInSModule(id, x, y, z);
236 //______________________________________________________________________________
237 void AliEveEMCALData::CreateAllSModules()
240 // Create all fNsm super modules
243 for(Int_t sm = 0; sm < fNsm; sm++)
248 //______________________________________________________________________________
249 void AliEveEMCALData::CreateSModule(Int_t sm)
252 // Create super-module-data for SM if it does not exist already.
255 if(fSM[sm] == 0) fSM[sm] = new AliEveEMCALSModuleData(sm,fGeom,fNode,fHMatrix);
256 if(fSMfull[sm] == 0 && sm < 10) fSMfull[sm] = new AliEveEMCALSModuleData(sm,fGeom,fNode,fHMatrix);
257 if(fSMhalf[sm-10] == 0 && sm > 10) fSMhalf[sm-10] = new AliEveEMCALSModuleData(sm,fGeom,fNode,fHMatrix);
260 //______________________________________________________________________________
261 void AliEveEMCALData::DropAllSModules()
264 // Drop data of all existing sectors.
267 for (Int_t sm = 0; sm < fNsm; sm++) {
273 //______________________________________________________________________________
274 void AliEveEMCALData::DeleteSuperModules()
277 // Delete all super module data
280 for (Int_t sm = 0; sm < fNsm; sm++)
286 for(Int_t smf = 0; smf < fNsmfull; smf++)
292 for(Int_t smh = 0; smh < fNsmhalf; smh++)
300 //______________________________________________________________________________
301 void AliEveEMCALData::LoadHits(TTree* t)
304 // Get hit information from RunLoader
308 // These are global coordinates !
310 const char *selection = "";
311 const char *varexp = "fX:fY:fZ";
312 sprintf(form,"EMCAL Hits '%s'", selection);
313 fPoint = new TEvePointSet(form);
315 TEvePointSelector ps(t, fPoint, varexp, selection);
318 if (fPoint->Size() == 0) {
319 Warning("emcal_hits", Form("No hits match '%s'", selection));
325 TObjArray *harr=NULL;
326 TBranch *hbranch=t->GetBranch("EMCAL");
327 hbranch->SetAddress(&harr);
329 if(hbranch->GetEvent(0)) {
330 for(Int_t ih = 0; ih < harr->GetEntriesFast(); ih++) {
331 AliEMCALHit* hit =(AliEMCALHit*)harr->UncheckedAt(ih);
333 if(fDebug>1) cout << "Hit info " << hit->GetId() << " " << hit->GetEnergy() << endl;
334 Int_t id = hit->GetId();
335 // These are local coordinates
336 Double_t xl = 0.; Double_t yl = 0.; Double_t zl = 0.;
337 // Get global coordinates
338 Double_t x = hit->X();
339 Double_t y = hit->Y();
340 Double_t z = hit->Z();
341 Double_t amp = hit->GetEnergy();
344 GetGeomInfo(id,iSupMod,xl,yl,zl);
345 fSM[iSupMod]->RegisterHit(id,iSupMod,amp,x,y,z);
351 //______________________________________________________________________________
352 void AliEveEMCALData::LoadHitsFromEMCALLoader(AliEMCALLoader* emcl)
355 // Get hit information from EMCAL Loader
361 TClonesArray *hits = (TClonesArray*)emcl->Hits();
363 //Get hits from the list
364 for(Int_t ihit = 0; ihit< hits->GetEntries();ihit++){
366 hit = static_cast<AliEMCALHit *>(hits->At(ihit)) ;
369 if(fDebug>1) cout << "Hit info " << hit->GetId() << " " << hit->GetEnergy() << endl;
371 Int_t id = hit->GetId();
372 // These are local coordinates
373 Double_t xl = 0.; Double_t yl = 0.; Double_t zl = 0.;
374 // Get global coordinates
375 Double_t x = hit->X();
376 Double_t y = hit->Y();
377 Double_t z = hit->Z();
378 Double_t amp = hit->GetEnergy();
381 GetGeomInfo(id,iSupMod,xl,yl,zl);
382 fSM[iSupMod]->RegisterHit(id,iSupMod,amp,x,y,z);
388 //______________________________________________________________________________
389 void AliEveEMCALData::LoadDigits(TTree *t)
392 // Get digit information from RunLoader
395 TClonesArray *digits = 0;
396 t->SetBranchAddress("EMCAL", &digits);
399 Int_t nEnt = digits->GetEntriesFast();
400 cout << "nEnt: " << nEnt << endl;
403 // Double_t amp = -1 ;
404 Double_t ampInt = -1 ;
409 for (Int_t idig = 0; idig < nEnt; idig++)
411 dig = static_cast<AliEMCALDigit *>(digits->At(idig));
414 id = dig->GetId() ; //cell (digit) label
416 ampInt = dig->GetAmp(); //amplitude in cell (digit)
418 // amp = ampInt*0.0153; // To be modified with correct OCDB conversion
420 GetGeomInfo(id,iSupMod,x,y,z);
423 // fSM[iSupMod]->RegisterDigit(id,iSupMod,amp,x,y,z);
424 // // fSM[iSupMod]->SaveDigit(dig);
425 // // if(iSupMod<fNsmfull) fSMfull[iSupMod]->RegisterDigit(id,iSupMod,amp,x,y,z);
426 // // if(iSupMod>fNsmfull) fSMhalf[iSupMod-10]->RegisterDigit(id,iSupMod,amp,x,y,z);
427 fSM[iSupMod]->RegisterDigit(id,iSupMod,ampInt,x,y,z);
428 // fSM[iSupMod]->SaveDigit(dig);
429 // if(iSupMod<fNsmfull) fSMfull[iSupMod]->RegisterDigit(id,iSupMod,amp,x,y,z);
430 // if(iSupMod>fNsmfull) fSMhalf[iSupMod-10]->RegisterDigit(id,iSupMod,amp,x,y,z);
433 cout << "Digit object empty" << endl;
437 cout << "after loop on digits !" << endl;
440 //______________________________________________________________________________
441 void AliEveEMCALData::LoadDigitsFromEMCALLoader(AliEMCALLoader* emcl)
445 // Get digit information from EMCAL Loader
450 //Fill array of digits
451 TClonesArray *digits = (TClonesArray*)emcl->Digits();
453 //Get digits from the list
455 // Double_t amp = -1 ;
456 Double_t ampInt = -1 ;
461 for(Int_t idig = 0; idig< digits->GetEntries();idig++){
463 dig = static_cast<AliEMCALDigit *>(digits->At(idig)) ;
466 if(fDebug>1) cout << "Digit info " << dig->GetId() << " " << dig->GetAmp() << endl;
467 id = dig->GetId() ; //cell (digit) label
469 ampInt = dig->GetAmp(); //amplitude in cell (digit)
471 // amp = ampInt*0.0153.; // To be modified with correct OCDB conversion
473 GetGeomInfo(id,iSupMod,x,y,z);
476 // fSM[iSupMod]->RegisterDigit(id,iSupMod,amp,x,y,z);
478 fSM[iSupMod]->RegisterDigit(id,iSupMod,ampInt,x,y,z);
481 cout << "Digit object empty" << endl;
484 } // end loop on digits
488 //______________________________________________________________________________
489 void AliEveEMCALData::LoadDigitsFromESD()
492 // Get digit information from esd
495 AliESDCaloCells &cells= *(fESD->GetEMCALCells());
496 Int_t ncell = cells.GetNumberOfCells() ;
500 // Extract digit information from the ESDs
501 for (Int_t icell= 0; icell < ncell; icell++)
503 Int_t id = cells.GetCellNumber(icell);
505 Double_t ampInt = cells.GetAmplitude(icell);
507 // Double_t amp = ampInt*0.0153; // To be modified with correct OCDB conversion
509 GetGeomInfo(id,iSupMod,x,y,z);
512 // fSM[iSupMod]->RegisterDigit(id,iSupMod,amp,x,y,z);
513 // if(iSupMod<fNsmfull) fSMfull[iSupMod]->RegisterDigit(id,iSupMod,amp,x,y,z);
514 // if(iSupMod>fNsmfull) fSMhalf[iSupMod-10]->RegisterDigit(id,iSupMod,amp,x,y,z);
516 fSM[iSupMod]->RegisterDigit(id,iSupMod,ampInt,x,y,z);
517 if(iSupMod<fNsmfull) fSMfull[iSupMod]->RegisterDigit(id,iSupMod,ampInt,x,y,z);
518 if(iSupMod>fNsmfull) fSMhalf[iSupMod-10]->RegisterDigit(id,iSupMod,ampInt,x,y,z);
523 //______________________________________________________________________________
524 void AliEveEMCALData::LoadRecPoints(TTree* t)
527 // Get rec point information from RunLoader
530 //*************************************************
531 // To be improved !!!!!
532 // Size and shape of cluster to be implemented
534 //*************************************************
537 TObjArray *carr=NULL;
538 TBranch *cbranch=t->GetBranch("EMCALECARP");
539 cbranch->SetAddress(&carr);
541 if(cbranch->GetEvent(0)) {
542 for(Int_t ic = 0; ic < carr->GetEntriesFast(); ic++) {
543 AliEMCALRecPoint* rp =(AliEMCALRecPoint*)carr->UncheckedAt(ic);
545 if(fDebug>1) cout << "RecPoint info " << rp->GetAbsId() << " " << rp->GetEnergy() << endl;
546 Int_t iSupMod = rp->GetSuperModuleNumber();
548 Double_t amp = (Double_t)rp->GetEnergy();
550 Double_t ampInt = amp/0.0153; // To be modified with correct OCDB conversion
552 rp->GetLocalPosition(lpos);
555 // fSM[iSupMod]->RegisterCluster(iSupMod,amp,lpos[0],lpos[1],lpos[2]);
557 fSM[iSupMod]->RegisterCluster(iSupMod,ampInt,lpos[0],lpos[1],lpos[2]);
564 //______________________________________________________________________________
565 void AliEveEMCALData::LoadRecPointsFromEMCALLoader(AliEMCALLoader* emcl)
568 // Get rec point information from EMCAL Loader
571 //*************************************************
572 // To be improved !!!!!
573 // Size and shape of cluster to be implemented
575 //*************************************************
578 AliEMCALRecPoint* rp;
580 //Fill array of clusters
581 TClonesArray *clusters = (TClonesArray*)emcl->RecPoints();
583 //Get clusters from the list
584 for(Int_t iclu = 0; iclu< clusters->GetEntries();iclu++){
586 rp = static_cast<AliEMCALRecPoint *>(clusters->At(iclu)) ;
589 if(fDebug>1) cout << "RecPoint info " << rp->GetAbsId() << " " << rp->GetEnergy() << endl;
590 Int_t iSupMod = rp->GetSuperModuleNumber();
591 Double_t amp = (Double_t)rp->GetEnergy();
592 Double_t ampInt = amp/0.0153; // To be modified with correct OCDB conversion
594 rp->GetLocalPosition(lpos);
597 // fSM[iSupMod]->RegisterCluster(iSupMod,amp,lpos[0],lpos[1],lpos[2]);
599 fSM[iSupMod]->RegisterCluster(iSupMod,ampInt,lpos[0],lpos[1],lpos[2]);
605 //______________________________________________________________________________
606 void AliEveEMCALData::LoadRecPointsFromESD()
609 // Get cluster information from esd
621 // Get reconstructed vertex position
622 AliESDVertex* primVertex =(AliESDVertex*) fESD->GetVertex();
623 Double_t vertex_position[3] ;
624 primVertex->GetXYZ(vertex_position) ;
626 //Get the CaloClusters
627 //select EMCAL clusters only
628 TRefArray * caloClusters = new TRefArray();
629 fESD->GetEMCALClusters(caloClusters);
630 Int_t nclus = caloClusters->GetEntries();
631 cout << "nclus: " << nclus << endl;
633 if(!caloClusters) return;
635 for (Int_t iclus = 0; iclus < nclus; iclus++)
637 AliESDCaloCluster *clus = (AliESDCaloCluster *) caloClusters->At(iclus) ;
638 //Get the cluster info
640 Double_t energy = clus->E() ;
642 // Int_t eneInt = (Int_t)energy*500+0.5;
643 Double_t eneInt = energy/0.0153; // To be modified with correct OCDB conversion
644 Double_t disp = clus->GetClusterDisp() ;
646 clus->GetPosition(pos) ; // Global position
647 TVector3 vpos(pos[0],pos[1],pos[2]) ;
650 clus->GetMomentum(p4,vertex_position);
651 p3.SetXYZ(p4[0],p4[1],p4[2]);
652 Double_t eta = p3.Eta();
653 Double_t phi = ( (p3.Phi()) < 0) ? (p3.Phi()) + 2. * TMath::Pi() : (p3.Phi());
655 Int_t mult = clus->GetNCells() ;
657 cout << "In cluster: " << iclus << ", ncells: " << mult << ", energy : " << energy <<
658 ", disp: " << disp << endl;
659 cout << "Cluster " << iclus << ", eta: " << eta << ", phi: " << phi << endl;
663 fGeom->GetAbsCellIdFromEtaPhi(eta,phi,clusId);
665 cout << "Abs Cluster Id: " << clusId << ", xc: " << pos[0] <<
666 ", yc: " << pos[1] << ", zc: " << pos[2] << endl;
669 GetGeomInfo(clusId,iSupMod,x,y,z);
671 //******** Not used yet but will come ********
672 // AliESDCaloCells &cells= *(fESD->GetEMCALCells());
673 Int_t digMult = clus->GetNCells() ;
674 UShort_t *digID = clus->GetCellsAbsId() ;
675 for(Int_t i=0; i<digMult; i++){
676 // Float_t digitAmp = cells.GetCellAmplitude(digID[i]) ;
677 fGeom->RelPosCellInSModule(digID[i], xd, yd, zd);
679 fGeom->GetCellIndex(digID[i],iSM,iT,iIp,iIe);
680 //Gives SuperModule and Tower numbers
683 //*********************************************
685 // fSM[iSupMod]->RegisterCluster(iSM,energy,x,y,z);
687 fSM[iSupMod]->RegisterCluster(iSM,eneInt,x,y,z);
689 } // end cluster loop
692 //______________________________________________________________________________
693 AliEveEMCALSModuleData* AliEveEMCALData::GetSModuleData(Int_t sm)
696 // Return super module data
699 if (sm < 0 || sm > fNsm)
701 printf("The number of super modules must be lower or equal to %d",fNsm);
708 //______________________________________________________________________________
709 void AliEveEMCALData::LoadRaw()
712 // Get raw information
715 // To be implemented !