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>
21 #include <TLorentzVector.h>
24 #include "AliRunLoader.h"
25 #include "AliEMCALLoader.h"
26 #include "AliESDEvent.h"
27 #include "AliESDVertex.h"
29 #include "AliEMCALGeometry.h"
30 #include "AliEMCALHit.h"
31 #include "AliEMCALDigit.h"
33 #include "AliEMCALRecPoint.h"
34 #include "AliESDCaloCells.h"
35 #include "AliESDCaloCluster.h"
37 #include "AliEveEMCALData.h"
38 #include "AliEveEMCALSModule.h"
39 #include "AliEveEMCALSModuleData.h"
41 ClassImp(AliEveEMCALData)
43 //______________________________________________________________________________
44 AliEveEMCALData::AliEveEMCALData():
67 // for(Int_t i=0; i<12; i++)
69 // for(Int_t i=0; i<10; i++)
71 // fSMhalf[0] = fSMhalf[1] = 0x0;
78 //______________________________________________________________________________
79 AliEveEMCALData::AliEveEMCALData(AliRunLoader* rl, TGeoNode* node, TGeoHMatrix* m):
102 // for(Int_t i=0; i<12; i++)
104 // for(Int_t i=0; i<10; i++)
106 // fSMhalf[0] = fSMhalf[1] = 0x0;
113 //______________________________________________________________________________
114 AliEveEMCALData::~AliEveEMCALData()
120 DeleteSuperModules();
122 // delete fEmcal; // deleted by run-loader
129 //______________________________________________________________________________
130 void AliEveEMCALData::Reset()
135 //______________________________________________________________________________
136 AliEveEMCALData::AliEveEMCALData(const AliEveEMCALData &edata) :
139 fEmcal(edata.fEmcal),
142 fHMatrix(edata.fHMatrix),
146 fNsmfull(edata.fNsmfull),
147 fNsmhalf(edata.fNsmhalf),
149 fSMfull(edata.fSMfull),
150 fSMhalf(edata.fSMhalf),
151 fRunLoader(edata.fRunLoader),
152 fDebug(edata.fDebug),
158 InitEMCALGeom(edata.fRunLoader);
162 //______________________________________________________________________________
163 AliEveEMCALData& AliEveEMCALData::operator=(const AliEveEMCALData &edata)
166 // Assignment operator
169 if (this != &edata) {
177 //______________________________________________________________________________
178 void AliEveEMCALData::SetTree(TTree* tree)
181 // Set digit-tree to be used for digit retrieval.
182 // Data is loaded on demand.
189 //______________________________________________________________________________
190 void AliEveEMCALData::SetESD(AliESDEvent* esd)
199 //______________________________________________________________________________
200 void AliEveEMCALData::SetNode(TGeoNode* node)
209 //______________________________________________________________________________
210 void AliEveEMCALData::InitEMCALGeom(AliRunLoader* rl)
213 // Set data members for EMCAL geometry
216 fEmcal = (AliEMCAL*) rl->GetAliRun()->GetDetector("EMCAL");
217 fGeom = (AliEMCALGeometry*) fEmcal->GetGeometry();
221 //______________________________________________________________________________
222 void AliEveEMCALData::GetGeomInfo(Int_t id, Int_t &iSupMod, Double_t& x, Double_t& y, Double_t& z)
225 // Get geometrical information from hit/digit/cluster absolute id
233 fGeom->GetCellIndex(id,iSupMod,iTower,iIphi,iIeta);
234 //Gives SuperModule and Tower numbers
235 fGeom->RelPosCellInSModule(id, x, y, z);
239 //______________________________________________________________________________
240 void AliEveEMCALData::CreateAllSModules()
243 // Create all fNsm super modules
246 for(Int_t sm = 0; sm < fNsm; sm++)
251 //______________________________________________________________________________
252 void AliEveEMCALData::CreateSModule(Int_t sm)
255 // Create super-module-data for SM if it does not exist already.
258 if(fSM[sm] == 0) fSM[sm] = new AliEveEMCALSModuleData(sm,fGeom,fNode,fHMatrix);
259 if(fSMfull[sm] == 0 && sm < 10) fSMfull[sm] = new AliEveEMCALSModuleData(sm,fGeom,fNode,fHMatrix);
260 if(fSMhalf[sm-10] == 0 && sm > 10) fSMhalf[sm-10] = new AliEveEMCALSModuleData(sm,fGeom,fNode,fHMatrix);
263 //______________________________________________________________________________
264 void AliEveEMCALData::DropAllSModules()
267 // Drop data of all existing sectors.
270 for (Int_t sm = 0; sm < fNsm; sm++) {
276 //______________________________________________________________________________
277 void AliEveEMCALData::DeleteSuperModules()
280 // Delete all super module data
283 for (Int_t sm = 0; sm < fNsm; sm++)
289 for(Int_t smf = 0; smf < fNsmfull; smf++)
295 for(Int_t smh = 0; smh < fNsmhalf; smh++)
303 //______________________________________________________________________________
304 void AliEveEMCALData::LoadHits(TTree* t)
307 // Get hit information from RunLoader
311 // These are global coordinates !
313 const char *selection = "";
314 const char *varexp = "fX:fY:fZ";
315 sprintf(form,"EMCAL Hits '%s'", selection);
316 fPoint = new TEvePointSet(form);
318 TEvePointSelector ps(t, fPoint, varexp, selection);
321 if (fPoint->Size() == 0) {
322 Warning("emcal_hits", Form("No hits match '%s'", selection));
328 TObjArray *harr=NULL;
329 TBranch *hbranch=t->GetBranch("EMCAL");
330 hbranch->SetAddress(&harr);
332 if(hbranch->GetEvent(0)) {
333 for(Int_t ih = 0; ih < harr->GetEntriesFast(); ih++) {
334 AliEMCALHit* hit =(AliEMCALHit*)harr->UncheckedAt(ih);
336 if(fDebug>1) cout << "Hit info " << hit->GetId() << " " << hit->GetEnergy() << endl;
337 Int_t id = hit->GetId();
338 // These are local coordinates
339 Double_t xl = 0.; Double_t yl = 0.; Double_t zl = 0.;
340 // Get global coordinates
341 Double_t x = hit->X();
342 Double_t y = hit->Y();
343 Double_t z = hit->Z();
344 Double_t amp = hit->GetEnergy();
347 GetGeomInfo(id,iSupMod,xl,yl,zl);
348 fSM[iSupMod]->RegisterHit(id,iSupMod,amp,x,y,z);
354 //______________________________________________________________________________
355 void AliEveEMCALData::LoadHitsFromEMCALLoader(AliEMCALLoader* emcl)
358 // Get hit information from EMCAL Loader
364 TClonesArray *hits = (TClonesArray*)emcl->Hits();
366 //Get hits from the list
367 for(Int_t ihit = 0; ihit< hits->GetEntries();ihit++){
369 hit = static_cast<AliEMCALHit *>(hits->At(ihit)) ;
372 if(fDebug>1) cout << "Hit info " << hit->GetId() << " " << hit->GetEnergy() << endl;
374 Int_t id = hit->GetId();
375 // These are local coordinates
376 Double_t xl = 0.; Double_t yl = 0.; Double_t zl = 0.;
377 // Get global coordinates
378 Double_t x = hit->X();
379 Double_t y = hit->Y();
380 Double_t z = hit->Z();
381 Double_t amp = hit->GetEnergy();
384 GetGeomInfo(id,iSupMod,xl,yl,zl);
385 fSM[iSupMod]->RegisterHit(id,iSupMod,amp,x,y,z);
391 //______________________________________________________________________________
392 void AliEveEMCALData::LoadDigits(TTree *t)
395 // Get digit information from RunLoader
398 TClonesArray *digits = 0;
399 t->SetBranchAddress("EMCAL", &digits);
402 Int_t nEnt = digits->GetEntriesFast();
403 cout << "nEnt: " << nEnt << endl;
406 // Double_t amp = -1 ;
407 Double_t ampInt = -1 ;
412 for (Int_t idig = 0; idig < nEnt; idig++)
414 dig = static_cast<AliEMCALDigit *>(digits->At(idig));
417 id = dig->GetId() ; //cell (digit) label
419 ampInt = dig->GetAmp(); //amplitude in cell (digit)
421 // amp = ampInt*0.0153; // To be modified with correct OCDB conversion
423 GetGeomInfo(id,iSupMod,x,y,z);
426 // fSM[iSupMod]->RegisterDigit(id,iSupMod,amp,x,y,z);
427 // // fSM[iSupMod]->SaveDigit(dig);
428 // // if(iSupMod<fNsmfull) fSMfull[iSupMod]->RegisterDigit(id,iSupMod,amp,x,y,z);
429 // // if(iSupMod>fNsmfull) fSMhalf[iSupMod-10]->RegisterDigit(id,iSupMod,amp,x,y,z);
430 fSM[iSupMod]->RegisterDigit(id,iSupMod,ampInt,x,y,z);
431 // fSM[iSupMod]->SaveDigit(dig);
432 // if(iSupMod<fNsmfull) fSMfull[iSupMod]->RegisterDigit(id,iSupMod,amp,x,y,z);
433 // if(iSupMod>fNsmfull) fSMhalf[iSupMod-10]->RegisterDigit(id,iSupMod,amp,x,y,z);
436 cout << "Digit object empty" << endl;
440 cout << "after loop on digits !" << endl;
443 //______________________________________________________________________________
444 void AliEveEMCALData::LoadDigitsFromEMCALLoader(AliEMCALLoader* emcl)
448 // Get digit information from EMCAL Loader
453 //Fill array of digits
454 TClonesArray *digits = (TClonesArray*)emcl->Digits();
456 //Get digits from the list
458 // Double_t amp = -1 ;
459 Double_t ampInt = -1 ;
464 for(Int_t idig = 0; idig< digits->GetEntries();idig++){
466 dig = static_cast<AliEMCALDigit *>(digits->At(idig)) ;
469 if(fDebug>1) cout << "Digit info " << dig->GetId() << " " << dig->GetAmp() << endl;
470 id = dig->GetId() ; //cell (digit) label
472 ampInt = dig->GetAmp(); //amplitude in cell (digit)
474 // amp = ampInt*0.0153.; // To be modified with correct OCDB conversion
476 GetGeomInfo(id,iSupMod,x,y,z);
479 // fSM[iSupMod]->RegisterDigit(id,iSupMod,amp,x,y,z);
481 fSM[iSupMod]->RegisterDigit(id,iSupMod,ampInt,x,y,z);
484 cout << "Digit object empty" << endl;
487 } // end loop on digits
491 //______________________________________________________________________________
492 void AliEveEMCALData::LoadDigitsFromESD()
495 // Get digit information from esd
498 AliESDCaloCells &cells= *(fESD->GetEMCALCells());
499 Int_t ncell = cells.GetNumberOfCells() ;
503 // Extract digit information from the ESDs
504 for (Int_t icell= 0; icell < ncell; icell++)
506 Int_t id = cells.GetCellNumber(icell);
508 Double_t ampInt = cells.GetAmplitude(icell);
510 // Double_t amp = ampInt*0.0153; // To be modified with correct OCDB conversion
512 GetGeomInfo(id,iSupMod,x,y,z);
515 // fSM[iSupMod]->RegisterDigit(id,iSupMod,amp,x,y,z);
516 // if(iSupMod<fNsmfull) fSMfull[iSupMod]->RegisterDigit(id,iSupMod,amp,x,y,z);
517 // if(iSupMod>fNsmfull) fSMhalf[iSupMod-10]->RegisterDigit(id,iSupMod,amp,x,y,z);
519 fSM[iSupMod]->RegisterDigit(id,iSupMod,ampInt,x,y,z);
520 if(iSupMod<fNsmfull) fSMfull[iSupMod]->RegisterDigit(id,iSupMod,ampInt,x,y,z);
521 if(iSupMod>fNsmfull) fSMhalf[iSupMod-10]->RegisterDigit(id,iSupMod,ampInt,x,y,z);
526 //______________________________________________________________________________
527 void AliEveEMCALData::LoadRecPoints(TTree* t)
530 // Get rec point information from RunLoader
533 //*************************************************
534 // To be improved !!!!!
535 // Size and shape of cluster to be implemented
537 //*************************************************
540 TObjArray *carr=NULL;
541 TBranch *cbranch=t->GetBranch("EMCALECARP");
542 cbranch->SetAddress(&carr);
544 if(cbranch->GetEvent(0)) {
545 for(Int_t ic = 0; ic < carr->GetEntriesFast(); ic++) {
546 AliEMCALRecPoint* rp =(AliEMCALRecPoint*)carr->UncheckedAt(ic);
548 if(fDebug>1) cout << "RecPoint info " << rp->GetAbsId() << " " << rp->GetEnergy() << endl;
549 Int_t iSupMod = rp->GetSuperModuleNumber();
551 Double_t amp = (Double_t)rp->GetEnergy();
553 Double_t ampInt = amp/0.0153; // To be modified with correct OCDB conversion
555 rp->GetLocalPosition(lpos);
558 // fSM[iSupMod]->RegisterCluster(iSupMod,amp,lpos[0],lpos[1],lpos[2]);
560 fSM[iSupMod]->RegisterCluster(iSupMod,ampInt,lpos[0],lpos[1],lpos[2]);
567 //______________________________________________________________________________
568 void AliEveEMCALData::LoadRecPointsFromEMCALLoader(AliEMCALLoader* emcl)
571 // Get rec point information from EMCAL Loader
574 //*************************************************
575 // To be improved !!!!!
576 // Size and shape of cluster to be implemented
578 //*************************************************
581 AliEMCALRecPoint* rp;
583 //Fill array of clusters
584 TClonesArray *clusters = (TClonesArray*)emcl->RecPoints();
586 //Get clusters from the list
587 for(Int_t iclu = 0; iclu< clusters->GetEntries();iclu++){
589 rp = static_cast<AliEMCALRecPoint *>(clusters->At(iclu)) ;
592 if(fDebug>1) cout << "RecPoint info " << rp->GetAbsId() << " " << rp->GetEnergy() << endl;
593 Int_t iSupMod = rp->GetSuperModuleNumber();
594 Double_t amp = (Double_t)rp->GetEnergy();
595 Double_t ampInt = amp/0.0153; // To be modified with correct OCDB conversion
597 rp->GetLocalPosition(lpos);
600 // fSM[iSupMod]->RegisterCluster(iSupMod,amp,lpos[0],lpos[1],lpos[2]);
602 fSM[iSupMod]->RegisterCluster(iSupMod,ampInt,lpos[0],lpos[1],lpos[2]);
608 //______________________________________________________________________________
609 void AliEveEMCALData::LoadRecPointsFromESD()
612 // Get cluster information from esd
624 // Get reconstructed vertex position
625 AliESDVertex* primVertex =(AliESDVertex*) fESD->GetVertex();
626 Double_t vertex_position[3] ;
627 primVertex->GetXYZ(vertex_position) ;
629 //Get the CaloClusters
630 //select EMCAL clusters only
631 TRefArray * caloClusters = new TRefArray();
632 fESD->GetEMCALClusters(caloClusters);
633 Int_t nclus = caloClusters->GetEntries();
634 cout << "nclus: " << nclus << endl;
636 if(!caloClusters) return;
638 for (Int_t iclus = 0; iclus < nclus; iclus++)
640 AliESDCaloCluster *clus = (AliESDCaloCluster *) caloClusters->At(iclus) ;
641 //Get the cluster info
643 Double_t energy = clus->E() ;
645 // Int_t eneInt = (Int_t)energy*500+0.5;
646 Double_t eneInt = energy/0.0153; // To be modified with correct OCDB conversion
647 Double_t disp = clus->GetClusterDisp() ;
649 clus->GetPosition(pos) ; // Global position
650 TVector3 vpos(pos[0],pos[1],pos[2]) ;
653 clus->GetMomentum(p4,vertex_position);
654 p3.SetXYZ(p4[0],p4[1],p4[2]);
655 Double_t eta = p3.Eta();
656 Double_t phi = ( (p3.Phi()) < 0) ? (p3.Phi()) + 2. * TMath::Pi() : (p3.Phi());
658 Int_t mult = clus->GetNCells() ;
660 cout << "In cluster: " << iclus << ", ncells: " << mult << ", energy : " << energy <<
661 ", disp: " << disp << endl;
662 cout << "Cluster " << iclus << ", eta: " << eta << ", phi: " << phi << endl;
666 fGeom->GetAbsCellIdFromEtaPhi(eta,phi,clusId);
668 cout << "Abs Cluster Id: " << clusId << ", xc: " << pos[0] <<
669 ", yc: " << pos[1] << ", zc: " << pos[2] << endl;
672 GetGeomInfo(clusId,iSupMod,x,y,z);
674 //******** Not used yet but will come ********
675 // AliESDCaloCells &cells= *(fESD->GetEMCALCells());
676 Int_t digMult = clus->GetNCells() ;
677 UShort_t *digID = clus->GetCellsAbsId() ;
678 for(Int_t i=0; i<digMult; i++){
679 // Float_t digitAmp = cells.GetCellAmplitude(digID[i]) ;
680 fGeom->RelPosCellInSModule(digID[i], xd, yd, zd);
682 fGeom->GetCellIndex(digID[i],iSM,iT,iIp,iIe);
683 //Gives SuperModule and Tower numbers
686 //*********************************************
688 // fSM[iSupMod]->RegisterCluster(iSM,energy,x,y,z);
690 fSM[iSupMod]->RegisterCluster(iSM,eneInt,x,y,z);
692 } // end cluster loop
695 //______________________________________________________________________________
696 AliEveEMCALSModuleData* AliEveEMCALData::GetSModuleData(Int_t sm)
699 // Return super module data
702 if (sm < 0 || sm > fNsm)
704 printf("The number of super modules must be lower or equal to %d",fNsm);
711 //______________________________________________________________________________
712 void AliEveEMCALData::LoadRaw()
715 // Get raw information
718 // To be implemented !