]> git.uio.no Git - u/mrichter/AliRoot.git/blob - EMCAL/AliEMCALReconstructor.cxx
Store in AliESDCaloCluster label of all primaries contributing to the cluster
[u/mrichter/AliRoot.git] / EMCAL / AliEMCALReconstructor.cxx
1 /**************************************************************************
2  * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
3  *                                                                        *
4  * Author: The ALICE Off-line Project.                                    *
5  * Contributors are mentioned in the code where appropriate.              *
6  *                                                                        *
7  * Permission to use, copy, modify and distribute this software and its   *
8  * documentation strictly for non-commercial purposes is hereby granted   *
9  * without fee, provided that the above copyright notice appears in all   *
10  * copies and that both the copyright notice and this permission notice   *
11  * appear in the supporting documentation. The authors make no claims     *
12  * about the suitability of this software for any purpose. It is          *
13  * provided "as is" without express or implied warranty.                  *
14  **************************************************************************/
15
16 /* $Id$ */
17
18 //_________________________________________________________________________
19 //*--
20 //*-- Yves Schutz (SUBATECH) 
21 // Reconstruction class. Redesigned from the old AliReconstructionner class and 
22 // derived from STEER/AliReconstructor. 
23 // 
24 // --- ROOT system ---
25
26 // --- Standard library ---
27
28 // --- AliRoot header files ---
29 #include "AliEMCALReconstructor.h"
30
31 #include "AliESD.h"
32 #include "AliRunLoader.h"
33 #include "AliEMCALLoader.h"
34 #include "AliEMCALClusterizerv1.h"
35 #include "AliEMCALRecPoint.h"
36 #include "AliEMCALPID.h"
37 #include "AliEMCALTrigger.h"
38 #include "AliRawReader.h"
39
40
41 ClassImp(AliEMCALReconstructor)
42
43 //____________________________________________________________________________
44 AliEMCALReconstructor::AliEMCALReconstructor() 
45   : fDebug(kFALSE) 
46 {
47   // ctor
48
49
50 //____________________________________________________________________________
51 AliEMCALReconstructor::AliEMCALReconstructor(const AliEMCALReconstructor & rec)
52   : AliReconstructor(rec),
53     fDebug(rec.fDebug)
54 {
55   //copy ctor
56 }
57
58 //____________________________________________________________________________
59 AliEMCALReconstructor::~AliEMCALReconstructor()
60 {
61   // dtor
62
63
64 //____________________________________________________________________________
65 void AliEMCALReconstructor::Reconstruct(AliRunLoader* runLoader) const 
66 {
67   // method called by AliReconstruction; 
68   // Only the clusterization is performed,; the rest of the reconstruction is done in FillESD because the track
69   // segment maker needs access to the AliESD object to retrieve the tracks reconstructed by 
70   // the global tracking.
71  
72   TString headerFile(runLoader->GetFileName()) ; 
73   TString branchName(runLoader->GetEventFolder()->GetName() ) ;  
74   
75   AliEMCALClusterizerv1 clu(headerFile, branchName);
76   clu.SetEventRange(0, -1) ; // do all the events
77   if ( Debug() ) 
78     clu.ExecuteTask("deb all") ; 
79   else 
80     clu.ExecuteTask("pseudo") ;  
81  
82 }
83
84 //____________________________________________________________________________
85 void AliEMCALReconstructor::Reconstruct(AliRunLoader* runLoader, AliRawReader* rawreader) const 
86 {
87   // method called by AliReconstruction; 
88   // Only the clusterization is performed,; the rest of the reconstruction is done in FillESD because the track
89   // segment maker needs access to the AliESD object to retrieve the tracks reconstructed by 
90   // the global tracking.
91   // Here we reconstruct from Raw Data
92   
93   rawreader->Reset() ; 
94   TString headerFile(runLoader->GetFileName()) ; 
95   TString branchName(runLoader->GetEventFolder()->GetName()) ;  
96
97   AliEMCALClusterizerv1 clu(headerFile, branchName);
98   clu.SetEventRange(0, -1) ; // do all the events
99   if ( Debug() ) 
100     clu.ExecuteTask("deb pseudo all") ; 
101   else 
102     clu.ExecuteTask("pseudo") ;  
103
104 }
105
106 //____________________________________________________________________________
107 void AliEMCALReconstructor::FillESD(AliRunLoader* runLoader, AliESD* esd) const
108 {
109   // Called by AliReconstruct after Reconstruct() and global tracking and vertxing 
110   const double timeScale = 1.e+11; // transition constant from sec to 0.01ns (10ps)
111
112   Int_t eventNumber = runLoader->GetEventNumber() ;
113
114   TString headerFile(runLoader->GetFileName()) ; 
115   TString branchName(runLoader->GetEventFolder()->GetName()) ;  
116   // Creates AliESDCaloCluster from AliEMCALRecPoints 
117   AliRunLoader *rl = AliRunLoader::GetRunLoader();
118   AliEMCALLoader *emcalLoader = dynamic_cast<AliEMCALLoader*>(rl->GetDetectorLoader("EMCAL"));
119   rl->LoadRecPoints();
120   rl->LoadKinematics(); // To get the primary label
121   rl->LoadDigits();     // To get the primary label
122   rl->LoadHits();       // To get the primary label
123   rl->GetEvent(eventNumber);
124   TObjArray *clusters = emcalLoader->RecPoints();
125   Int_t nClusters = clusters->GetEntries(), nClustersNew=0;
126   //  Int_t nRP=0, nPC=0; // in input
127   esd->SetFirstEMCALCluster(esd->GetNumberOfCaloClusters()); // Put after Phos clusters 
128
129   //#########Calculate trigger and set trigger info###########
130  
131   AliEMCALTrigger tr ;
132   //   tr.SetPatchSize(1);//create 4x4 patches
133   tr.Trigger();
134   
135   Float_t maxAmp2x2  = tr.Get2x2MaxAmplitude();
136   Float_t maxAmpnxn  = tr.GetnxnMaxAmplitude();
137   Float_t ampOutOfPatch2x2  = tr.Get2x2AmpOutOfPatch() ;
138   Float_t ampOutOfPatchnxn  = tr.GetnxnAmpOutOfPatch() ;
139
140   AliEMCALGeometry * geom =  AliEMCALGeometry::GetInstance(AliEMCALGeometry::GetDefaulGeometryName());
141
142   Int_t iSM2x2      = tr.Get2x2SuperModule();
143   Int_t iSMnxn      = tr.GetnxnSuperModule();
144   Int_t iCellPhi2x2 = tr.Get2x2CellPhi();
145   Int_t iCellPhinxn = tr.GetnxnCellPhi();
146   Int_t iCellEta2x2 = tr.Get2x2CellEta();
147   Int_t iCellEtanxn = tr.GetnxnCellEta();
148
149   AliDebug(2, Form("Trigger 2x2 max amp %f, out amp %f, SM %d, iphi %d ieta %d",  maxAmp2x2, ampOutOfPatch2x2, iSM2x2,iCellPhi2x2, iCellEta2x2));
150   AliDebug(2, Form("Trigger 4x4 max amp %f , out amp %f, SM %d, iphi %d, ieta %d",  maxAmpnxn, ampOutOfPatchnxn, iSMnxn,iCellPhinxn, iCellEtanxn));
151
152   TVector3    pos2x2(-1,-1,-1);
153   TVector3    posnxn(-1,-1,-1);
154
155   Int_t iAbsId2x2 = geom->GetAbsCellIdFromCellIndexes( iSM2x2, iCellPhi2x2, iCellEta2x2) ;
156   Int_t iAbsIdnxn = geom->GetAbsCellIdFromCellIndexes( iSMnxn, iCellPhinxn, iCellEtanxn) ;
157   geom->GetGlobal(iAbsId2x2, pos2x2);
158   geom->GetGlobal(iAbsIdnxn, posnxn);
159   
160   TArrayF triggerPosition(6);
161   triggerPosition[0] = pos2x2(0) ;   
162   triggerPosition[1] = pos2x2(1) ;   
163   triggerPosition[2] = pos2x2(2) ;  
164   triggerPosition[3] = posnxn(0) ;   
165   triggerPosition[4] = posnxn(1) ;   
166   triggerPosition[5] = posnxn(2) ;  
167
168   TArrayF triggerAmplitudes(4);
169   triggerAmplitudes[0] = maxAmp2x2 ;   
170   triggerAmplitudes[1] = ampOutOfPatch2x2 ;    
171   triggerAmplitudes[2] = maxAmpnxn ;   
172   triggerAmplitudes[3] = ampOutOfPatchnxn ;   
173
174   esd->AddEMCALTriggerPosition(triggerPosition);
175   esd->AddEMCALTriggerAmplitudes(triggerAmplitudes);
176   
177   //######################################
178
179   //Fill CaloClusters 
180
181   for (Int_t iClust = 0 ; iClust < nClusters ; iClust++) {
182     const AliEMCALRecPoint * clust = emcalLoader->RecPoint(iClust);
183     //if(clust->GetClusterType()== AliESDCaloCluster::kClusterv1) nRP++; else nPC++;
184     if (Debug()) clust->Print();
185     // Get information from EMCAL reconstruction points
186     Float_t xyz[3];
187     TVector3 gpos;
188     clust->GetGlobalPosition(gpos);
189     for (Int_t ixyz=0; ixyz<3; ixyz++) 
190       xyz[ixyz] = gpos[ixyz];
191
192     Int_t digitMult = clust->GetMultiplicity();
193     UShort_t *amplList = new UShort_t[digitMult];
194     UShort_t *timeList = new UShort_t[digitMult];
195     UShort_t *digiList = new UShort_t[digitMult];
196     Float_t *amplFloat = clust->GetEnergiesList();
197     Float_t *timeFloat = clust->GetTimeList();
198     Int_t   *digitInts = clust->GetAbsId();
199     Float_t elipAxis[2];
200     clust->GetElipsAxis(elipAxis);
201
202     // Convert Float_t* and Int_t* to UShort_t* to save memory
203     // Problem : we should recalculate a cluster characteristics when discard digit(s)
204     Int_t newdigitMult = 0; 
205     for (Int_t iDigit=0; iDigit<digitMult; iDigit++) {
206       if(timeFloat[iDigit] < 65536./timeScale) {
207         amplList[newdigitMult] = (UShort_t)(amplFloat[iDigit]*500);
208         if(amplList[newdigitMult] > 0) { // accept digit if poztive amplitude
209           timeList[newdigitMult] = (UShort_t)(timeFloat[iDigit]*timeScale); // Time in units of 0.01 ns = 10 ps
210           digiList[newdigitMult] = (UShort_t)(digitInts[iDigit]);
211           newdigitMult++;
212         }
213       }
214     }
215
216     if(newdigitMult > 0) { // accept cluster if it has some digit
217       nClustersNew++;
218       if(newdigitMult != digitMult) { // some digits were deleted
219         UShort_t *amplListNew = new UShort_t[newdigitMult];
220         UShort_t *timeListNew = new UShort_t[newdigitMult];
221         UShort_t *digiListNew = new UShort_t[newdigitMult];
222         for (Int_t iDigit=0; iDigit<newdigitMult; iDigit++) {
223           amplListNew[iDigit] = amplList[iDigit];
224           timeListNew[iDigit] = timeList[iDigit];
225           digiListNew[iDigit] = digiList[iDigit];
226         }
227
228         delete [] amplList;
229         delete [] timeList;
230         delete [] digiList;
231
232         amplList = amplListNew;
233         timeList = timeListNew;
234         digiList = digiListNew;
235       }
236
237       //Primaries
238       Int_t  primMult  = 0;
239       Int_t *primInts =  clust->GetPrimaries(primMult);
240       UShort_t *primList = new UShort_t[primMult];
241       for (Int_t ipr=0; ipr<primMult; ipr++) 
242         primList[ipr] = (UShort_t)(primInts[ipr]);       
243
244
245       // fills the ESDCaloCluster
246       AliESDCaloCluster * ec = new AliESDCaloCluster() ; 
247       ec->SetClusterType(clust->GetClusterType());
248       ec->SetGlobalPosition(xyz);
249       ec->SetClusterEnergy(clust->GetEnergy());
250       
251       ec->SetNumberOfDigits(newdigitMult);
252       ec->SetDigitAmplitude(amplList); //energies
253       ec->SetDigitTime(timeList);      //times
254       ec->SetDigitIndex(digiList);     //indices
255       if(clust->GetClusterType()== AliESDCaloCluster::kClusterv1){
256         ec->SetPrimaryIndex(clust->GetPrimaryIndex());
257         ec->SetNumberOfPrimaries(primMult);           //primary multiplicity
258         ec->SetListOfPrimaries(primList);                  //primary List for a cluster  
259         ec->SetClusterDisp(clust->GetDispersion());
260         ec->SetClusterChi2(-1); //not yet implemented
261         ec->SetM02(elipAxis[0]*elipAxis[0]) ;
262         ec->SetM20(elipAxis[1]*elipAxis[1]) ;
263         ec->SetM11(-1) ;        //not yet implemented
264       } 
265     // add the cluster to the esd object
266       esd->AddCaloCluster(ec);
267       delete ec;
268     } else { // no new ESD cluster
269         delete [] amplList;
270         delete [] timeList;
271         delete [] digiList;
272     }
273   } // cycle on clusters
274   //  printf(" %i : nClusters %i : RP %i PC %i \n", eventNumber, nClusters, nRP, nPC);
275   esd->SetNumberOfEMCALClusters(nClustersNew);
276   //if(nClustersNew != nClusters) 
277   //printf(" ##### nClusters %i -> new %i ##### \n", nClusters, nClustersNew );
278
279   //Fill ESDCaloCluster with PID weights
280   AliEMCALPID *pid = new AliEMCALPID;
281   //pid->SetPrintInfo(kTRUE);
282   pid->SetReconstructor(kTRUE);
283   pid->RunPID(esd);
284 }
285