]> git.uio.no Git - u/mrichter/AliRoot.git/blob - EMCAL/AliEMCALReconstructor.cxx
remove unused AliEMCALGeometryOfflineTrd1
[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 "AliCodeTimer.h"
32 #include "AliESDEvent.h"
33 #include "AliESDCaloCluster.h"
34 #include "AliESDCaloCells.h"
35 #include "AliESDtrack.h"
36 #include "AliEMCALLoader.h"
37 #include "AliEMCALRawUtils.h"
38 #include "AliEMCALDigit.h"
39 #include "AliEMCALClusterizerv1.h"
40 #include "AliEMCALRecPoint.h"
41 #include "AliEMCALPID.h"
42 #include "AliEMCALTrigger.h"
43 #include "AliRawReader.h"
44 #include "AliCDBEntry.h"
45 #include "AliCDBManager.h"
46 #include "AliEMCALRecParam.h"
47 #include "AliEMCALGeometry.h"
48
49
50 ClassImp(AliEMCALReconstructor)
51
52 AliEMCALRecParam* AliEMCALReconstructor::fgkRecParam = 0;  // EMCAL rec. parameters
53 AliEMCALRawUtils* AliEMCALReconstructor::fgRawUtils = 0;   // EMCAL raw utilities class
54 //____________________________________________________________________________
55 AliEMCALReconstructor::AliEMCALReconstructor() 
56   : fDebug(kFALSE),fGeom(0) 
57 {
58   // ctor
59   InitRecParam();
60
61   fgRawUtils = new AliEMCALRawUtils;
62   fGeom = AliEMCALGeometry::GetInstance();
63   if(!fGeom) {
64     fGeom = AliEMCALGeometry::GetInstance("","");
65     if(!fGeom) AliFatal(Form("Could not get geometry!"));
66   }
67
68
69
70 //____________________________________________________________________________
71 AliEMCALReconstructor::AliEMCALReconstructor(const AliEMCALReconstructor & rec)
72   : AliReconstructor(rec),
73     fDebug(rec.fDebug),
74     fGeom(rec.fGeom)
75 {
76   //copy ctor
77 }
78
79 //____________________________________________________________________________
80 AliEMCALReconstructor::~AliEMCALReconstructor()
81 {
82   // dtor
83   delete fGeom;
84   AliCodeTimer::Instance()->Print();
85
86
87 //____________________________________________________________________________
88 void AliEMCALReconstructor::InitRecParam() const
89 {
90   // Check if the instance of AliEMCALRecParam exists, 
91   // if not, get it from OCDB if available, otherwise create a default one
92
93  if (!fgkRecParam  && (AliCDBManager::Instance()->IsDefaultStorageSet())) {
94     AliCDBEntry *entry = (AliCDBEntry*) 
95       AliCDBManager::Instance()->Get("EMCAL/Config/RecParam");
96     if (entry) fgkRecParam =  (AliEMCALRecParam*) entry->GetObject();
97   }
98   
99   if(!fgkRecParam){
100     AliWarning("The Reconstruction parameters for EMCAL nonitialized - Used default one");
101     fgkRecParam = new AliEMCALRecParam;
102   }
103 }
104
105 //____________________________________________________________________________
106 void AliEMCALReconstructor::Reconstruct(TTree* digitsTree, TTree* clustersTree) const
107 {
108   // method called by AliReconstruction; 
109   // Only the clusterization is performed,; the rest of the reconstruction is done in FillESD because the track
110   // segment maker needs access to the AliESD object to retrieve the tracks reconstructed by 
111   // the global tracking.
112   // Works on the current event.
113
114   AliCodeTimerAuto("")
115
116   AliEMCALClusterizerv1 clu;
117   clu.SetInput(digitsTree);
118   clu.SetOutput(clustersTree);
119   if(Debug())
120     clu.Digits2Clusters("deb all") ;
121   else
122     clu.Digits2Clusters("") ;
123   
124 }
125
126 //____________________________________________________________________________
127 void AliEMCALReconstructor::ConvertDigits(AliRawReader* rawReader, TTree* digitsTree) const
128
129 {
130   // Conversion from raw data to
131   // EMCAL digits.
132   // Works on a single-event basis
133
134   rawReader->Reset() ; 
135
136   TClonesArray *digitsArr = new TClonesArray("AliEMCALDigit",100);
137   Int_t bufsize = 32000;
138   digitsTree->Branch("EMCAL", &digitsArr, bufsize);
139
140   //must be done here because, in constructor, option is not yet known
141   fgRawUtils->SetOption(GetOption());
142
143   fgRawUtils->SetRawFormatHighLowGainFactor(fgkRecParam->GetHighLowGainFactor());
144   fgRawUtils->SetRawFormatOrder(fgkRecParam->GetOrderParameter());
145   fgRawUtils->SetRawFormatTau(fgkRecParam->GetTau());
146   fgRawUtils->SetNoiseThreshold(fgkRecParam->GetNoiseThreshold());
147   fgRawUtils->SetNPedSamples(fgkRecParam->GetNPedSamples());
148
149   fgRawUtils->Raw2Digits(rawReader,digitsArr);
150
151   digitsTree->Fill();
152   digitsArr->Delete();
153   delete digitsArr;
154
155 }
156
157 //____________________________________________________________________________
158 void AliEMCALReconstructor::FillESD(TTree* digitsTree, TTree* clustersTree, 
159                                     AliESDEvent* esd) const
160 {
161   // Called by AliReconstruct after Reconstruct() and global tracking and vertexing 
162   // Works on the current event
163   // Creates AliESDCaloCluster from AliEMCALRecPoints 
164   // and AliESDCaloCells from AliEMCALDigits
165   // Also, fills ESD with calorimeter trigger information
166
167   //######################################################
168   //#########Calculate trigger and set trigger info###########
169   //######################################################
170
171   AliEMCALTrigger tr ;
172   //   tr.SetPatchSize(1);//create 4x4 patches
173   tr.Trigger();
174   
175   Float_t maxAmp2x2  = tr.Get2x2MaxAmplitude();
176   Float_t maxAmpnxn  = tr.GetnxnMaxAmplitude();
177   Float_t ampOutOfPatch2x2  = tr.Get2x2AmpOutOfPatch() ;
178   Float_t ampOutOfPatchnxn  = tr.GetnxnAmpOutOfPatch() ;
179
180   Int_t iSM2x2      = tr.Get2x2SuperModule();
181   Int_t iSMnxn      = tr.GetnxnSuperModule();
182   Int_t iCellPhi2x2 = tr.Get2x2CellPhi();
183   Int_t iCellPhinxn = tr.GetnxnCellPhi();
184   Int_t iCellEta2x2 = tr.Get2x2CellEta();
185   Int_t iCellEtanxn = tr.GetnxnCellEta();
186
187   AliDebug(2, Form("Trigger 2x2 max amp %f, out amp %f, SM %d, iphi %d ieta %d",  maxAmp2x2, ampOutOfPatch2x2, iSM2x2,iCellPhi2x2, iCellEta2x2));
188   AliDebug(2, Form("Trigger 4x4 max amp %f , out amp %f, SM %d, iphi %d, ieta %d",  maxAmpnxn, ampOutOfPatchnxn, iSMnxn,iCellPhinxn, iCellEtanxn));
189
190   TVector3    pos2x2(-1,-1,-1);
191   TVector3    posnxn(-1,-1,-1);
192
193   Int_t iAbsId2x2 = fGeom->GetAbsCellIdFromCellIndexes( iSM2x2, iCellPhi2x2, iCellEta2x2) ;
194   Int_t iAbsIdnxn = fGeom->GetAbsCellIdFromCellIndexes( iSMnxn, iCellPhinxn, iCellEtanxn) ;
195   fGeom->GetGlobal(iAbsId2x2, pos2x2);
196   fGeom->GetGlobal(iAbsIdnxn, posnxn);
197   
198   TArrayF triggerPosition(6);
199   triggerPosition[0] = pos2x2(0) ;   
200   triggerPosition[1] = pos2x2(1) ;   
201   triggerPosition[2] = pos2x2(2) ;  
202   triggerPosition[3] = posnxn(0) ;   
203   triggerPosition[4] = posnxn(1) ;   
204   triggerPosition[5] = posnxn(2) ;  
205
206   TArrayF triggerAmplitudes(4);
207   triggerAmplitudes[0] = maxAmp2x2 ;   
208   triggerAmplitudes[1] = ampOutOfPatch2x2 ;    
209   triggerAmplitudes[2] = maxAmpnxn ;   
210   triggerAmplitudes[3] = ampOutOfPatchnxn ;   
211
212   esd->AddEMCALTriggerPosition(triggerPosition);
213   esd->AddEMCALTriggerAmplitudes(triggerAmplitudes);
214
215   //########################################
216   //##############Fill CaloCells###############
217   //########################################
218
219   TClonesArray *digits = new TClonesArray("AliEMCALDigit",1000);
220   TBranch *branchdig = digitsTree->GetBranch("EMCAL");
221   if (!branchdig) { 
222     AliError("can't get the branch with the PHOS digits !");
223     return;
224   }
225   branchdig->SetAddress(&digits);
226   digitsTree->GetEvent(0);
227   Int_t nDigits = digits->GetEntries(), idignew = 0 ;
228   AliDebug(1,Form("%d digits",nDigits));
229
230   AliESDCaloCells &emcCells = *(esd->GetEMCALCells());
231   emcCells.CreateContainer(nDigits);
232   emcCells.SetType(AliESDCaloCells::kEMCALCell);
233   for (Int_t idig = 0 ; idig < nDigits ; idig++) {
234     const AliEMCALDigit * dig = (const AliEMCALDigit*)digits->At(idig);
235     if(dig->GetAmp() > 0 ){
236       emcCells.SetCell(idignew,dig->GetId(),dig->GetAmp(), dig->GetTime());   
237       idignew++;
238     }
239   }
240   emcCells.SetNumberOfCells(idignew);
241   emcCells.Sort();
242
243   //------------------------------------------------------------
244   //-----------------CLUSTERS-----------------------------
245   //------------------------------------------------------------
246   TObjArray *clusters = new TObjArray(100);
247   TBranch *branch = clustersTree->GetBranch("EMCALECARP");
248   branch->SetAddress(&clusters);
249   clustersTree->GetEvent(0);
250
251   Int_t nClusters = clusters->GetEntries(),  nClustersNew=0;
252   AliDebug(1,Form("%d clusters",nClusters));
253   esd->SetFirstEMCALCluster(esd->GetNumberOfCaloClusters()); // Put after Phos clusters 
254
255   //######################################################
256   //#######################TRACK MATCHING###############
257   //######################################################
258   //Fill list of integers, each one is index of track to which the cluster belongs.
259
260   // step 1 - initialize array of matched track indexes
261   Int_t *matchedTrack = new Int_t[nClusters];
262   for (Int_t iclus = 0; iclus < nClusters; iclus++)
263     matchedTrack[iclus] = -1;  // neg. index --> no matched track
264   
265   // step 2, change the flag for all matched clusters found in tracks
266   Int_t iemcalMatch = -1;
267   Int_t endtpc = esd->GetNumberOfTracks();
268   for (Int_t itrack = 0; itrack < endtpc; itrack++) {
269     AliESDtrack * track = esd->GetTrack(itrack) ; // retrieve track
270     iemcalMatch = track->GetEMCALcluster();
271     if(iemcalMatch >= 0) matchedTrack[iemcalMatch] = itrack;
272   } 
273
274   //########################################
275   //##############Fill CaloClusters############
276   //########################################
277
278   esd->SetNumberOfEMCALClusters(nClusters);
279   for (Int_t iClust = 0 ; iClust < nClusters ; iClust++) {
280     const AliEMCALRecPoint * clust = (const AliEMCALRecPoint*)clusters->At(iClust);
281     //if(clust->GetClusterType()== AliESDCaloCluster::kEMCALClusterv1) nRP++; else nPC++;
282     if (Debug()) clust->Print();
283     // Get information from EMCAL reconstruction points
284     Float_t xyz[3];
285     TVector3 gpos;
286     clust->GetGlobalPosition(gpos);
287     for (Int_t ixyz=0; ixyz<3; ixyz++) 
288       xyz[ixyz] = gpos[ixyz];
289     Float_t elipAxis[2];
290     clust->GetElipsAxis(elipAxis);
291     
292      //Create digits lists
293     Int_t cellMult = clust->GetMultiplicity();
294     //TArrayS digiList(digitMult);
295     Float_t *amplFloat = clust->GetEnergiesList();
296     Int_t   *digitInts = clust->GetAbsId();
297     TArrayS absIdList(cellMult);
298     //Uncomment when unfolding is done
299     //TArrayD fracList(cellMult);
300
301     Int_t newCellMult = 0; 
302     for (Int_t iCell=0; iCell<cellMult; iCell++) {
303       if (amplFloat[iCell] > 0) {
304         absIdList[newCellMult] = (UShort_t)(digitInts[iCell]);
305         //Uncomment when unfolding is done
306         //fracList[newCellMult] = amplFloat[iCell]/emcCells.GetCellAmplitude(digitInts[iCell]);
307         newCellMult++;
308       }
309     }
310     absIdList.Set(newCellMult);
311     //Uncomment when unfolding is done
312     //fracList.Set(newCellMult);
313  
314     if(newCellMult > 0) { // accept cluster if it has some digit
315       nClustersNew++;
316       //Primaries
317       Int_t  parentMult  = 0;
318       Int_t *parentList =  clust->GetParents(parentMult);
319       
320       // fills the ESDCaloCluster
321       AliESDCaloCluster * ec = new AliESDCaloCluster() ; 
322       ec->SetClusterType(AliESDCaloCluster::kEMCALClusterv1);
323       ec->SetPosition(xyz);
324       ec->SetE(clust->GetEnergy());
325       ec->SetNCells(newCellMult);
326       //Change type of list from short to ushort
327       UShort_t *newAbsIdList  = new UShort_t[newCellMult];
328       //Uncomment when unfolding is done
329       //Double_t *newFracList  = new Double_t[newCellMult];
330       for(Int_t i = 0; i < newCellMult ; i++) {
331         newAbsIdList[i]=absIdList[i];
332         //Uncomment when unfolding is done
333       //newFracList[i]=fracList[i];
334       }
335       ec->SetCellsAbsId(newAbsIdList);
336       //Uncomment when unfolding is done
337       //ec->SetCellsAmplitudeFraction(newFracList);
338       
339       ec->SetClusterDisp(clust->GetDispersion());
340       ec->SetClusterChi2(-1); //not yet implemented
341       ec->SetM02(elipAxis[0]*elipAxis[0]) ;
342       ec->SetM20(elipAxis[1]*elipAxis[1]) ;
343       ec->SetM11(-1) ;        //not yet implemented
344       
345       TArrayI arrayTrackMatched(1);// Only one track, temporal solution. 
346       arrayTrackMatched[0]= matchedTrack[iClust]; 
347       ec->AddTracksMatched(arrayTrackMatched); 
348       
349       TArrayI arrayParents(parentMult,parentList); 
350       ec->AddLabels(arrayParents);
351       
352       
353       // add the cluster to the esd object
354       esd->AddCaloCluster(ec);
355       delete ec;
356       //delete [] newAbsIdList ;
357       //delete [] newFracList ;
358     }
359   } // cycle on clusters
360   
361   delete [] matchedTrack;
362   
363   esd->SetNumberOfEMCALClusters(nClustersNew);
364   //if(nClustersNew != nClusters) 
365   //printf(" ##### nClusters %i -> new %i ##### \n", nClusters, nClustersNew );
366   
367   //Fill ESDCaloCluster with PID weights
368    AliEMCALPID *pid = new AliEMCALPID;
369    //pid->SetPrintInfo(kTRUE);
370    pid->SetReconstructor(kTRUE);
371    pid->RunPID(esd);
372    delete pid;
373
374 }
375
376