]> git.uio.no Git - u/mrichter/AliRoot.git/blob - PHOS/AliPHOSReconstructor.cxx
Implementation of copy constructor and assignement operators (Marian)
[u/mrichter/AliRoot.git] / PHOS / AliPHOSReconstructor.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 "AliLog.h"
30 #include "AliAltroMapping.h"
31 #include "AliESDEvent.h"
32 #include "AliESDCaloCluster.h"
33 #include "AliESDCaloCells.h"
34 #include "AliPHOSReconstructor.h"
35 #include "AliPHOSClusterizerv1.h"
36 #include "AliPHOSTrackSegmentMakerv1.h"
37 #include "AliPHOSPIDv1.h"
38 #include "AliPHOSTracker.h"
39 #include "AliRawReader.h"
40 #include "AliPHOSTrigger.h"
41 #include "AliPHOSGeometry.h"
42 #include "AliPHOSRecoParam.h"
43 #include "AliPHOSRecoParamEmc.h"
44 #include "AliPHOSRecoParamCpv.h"
45 #include "AliPHOSDigit.h"
46 #include "AliPHOSTrackSegment.h"
47 #include "AliPHOSEmcRecPoint.h"
48 #include "AliPHOSRecParticle.h"
49 #include "AliPHOSRawDecoder.h"
50 #include "AliPHOSRawDecoderv1.h"
51 #include "AliPHOSRawDecoderv2.h"
52 #include "AliPHOSRawDigiProducer.h"
53 #include "AliPHOSPulseGenerator.h"
54
55 ClassImp(AliPHOSReconstructor)
56
57 Bool_t AliPHOSReconstructor::fgDebug = kFALSE ; 
58 AliPHOSRecoParam* AliPHOSReconstructor::fgkRecoParamEmc =0;  // EMC rec. parameters
59 AliPHOSRecoParam* AliPHOSReconstructor::fgkRecoParamCpv =0;  // CPV rec. parameters
60
61 //____________________________________________________________________________
62 AliPHOSReconstructor::AliPHOSReconstructor() :
63   fGeom(NULL)
64 {
65   // ctor
66
67   if (!fgkRecoParamEmc) {
68     AliWarning("The Reconstruction parameters for EMC nonitialized - Used default one");
69     fgkRecoParamEmc = AliPHOSRecoParamEmc::GetEmcDefaultParameters();
70   }
71
72   if (!fgkRecoParamCpv) {
73     AliWarning("The Reconstruction parameters for CPV nonitialized - Used default one");
74     fgkRecoParamCpv = AliPHOSRecoParamCpv::GetCpvDefaultParameters();
75   }
76
77   fGeom = AliPHOSGeometry::GetInstance("IHEP","");
78 }
79
80 //____________________________________________________________________________
81   AliPHOSReconstructor::~AliPHOSReconstructor()
82 {
83   // dtor
84   delete fGeom;
85
86
87 //____________________________________________________________________________
88 void AliPHOSReconstructor::Reconstruct(TTree* digitsTree, TTree* clustersTree) const
89 {
90   // 'single-event' local reco method called by AliReconstruction; 
91   // Only the clusterization is performed,; the rest of the reconstruction is done in FillESD because the track
92   // segment maker needs access to the AliESDEvent object to retrieve the tracks reconstructed by 
93   // the global tracking.
94
95   AliPHOSClusterizerv1 clu(fGeom);
96   clu.SetInput(digitsTree);
97   clu.SetOutput(clustersTree);
98   if ( Debug() ) 
99     clu.Digits2Clusters("deb all") ; 
100   else 
101     clu.Digits2Clusters("") ;
102 }
103
104 //____________________________________________________________________________
105 void AliPHOSReconstructor::FillESD(TTree* digitsTree, TTree* clustersTree, 
106                                    AliESDEvent* esd) const
107 {
108   // This method produces PHOS rec-particles,
109   // then it creates AliESDtracks out of them and
110   // write tracks to the ESD
111
112   AliPHOSTrackSegmentMaker *tsm = new AliPHOSTrackSegmentMakerv1(fGeom);
113   AliPHOSPID               *pid = new AliPHOSPIDv1              (fGeom);
114
115   // do current event; the loop over events is done by AliReconstruction::Run()
116   tsm->SetESD(esd) ; 
117   tsm->SetInput(clustersTree);
118   if ( Debug() ) 
119     tsm->Clusters2TrackSegments("deb all") ;
120   else 
121     tsm->Clusters2TrackSegments("") ;
122   
123   pid->SetInput(clustersTree, tsm->GetTrackSegments()) ; 
124   pid->SetESD(esd) ; 
125   if ( Debug() ) 
126     pid->TrackSegments2RecParticles("deb all") ;
127   else 
128     pid->TrackSegments2RecParticles("") ;
129
130
131   // This function creates AliESDtracks from AliPHOSRecParticles
132   //         and
133   // writes them to the ESD
134
135   TClonesArray *recParticles  = pid->GetRecParticles();
136   Int_t nOfRecParticles = recParticles->GetEntries();
137   
138   esd->SetNumberOfPHOSClusters(nOfRecParticles) ; 
139   esd->SetFirstPHOSCluster(esd->GetNumberOfCaloClusters()) ;
140   
141   AliDebug(2,Form("%d rec. particles, option %s",nOfRecParticles,GetOption()));
142   
143   // Read digits array
144
145   TBranch *branch = digitsTree->GetBranch("PHOS");
146   if (!branch) { 
147     AliError("can't get the branch with the PHOS digits !");
148     return;
149   }
150   TClonesArray *digitsArray    = new TClonesArray("AliPHOSDigit",100);
151   branch->SetAddress(&digitsArray);
152   branch->GetEntry(0);
153
154   // Get the clusters array
155
156   TBranch *emcbranch = clustersTree->GetBranch("PHOSEmcRP");
157   if (!emcbranch) { 
158     AliError("can't get the branch with the PHOS EMC clusters !");
159     return;
160   }
161
162   TObjArray *emcRecPoints = new TObjArray(100) ;
163   emcbranch->SetAddress(&emcRecPoints);
164   emcbranch->GetEntry(0);
165
166   //#########Calculate trigger and set trigger info###########
167
168   AliPHOSTrigger tr ;
169   //   tr.SetPatchSize(1);//create 4x4 patches
170   tr.Trigger();
171   
172   Float_t maxAmp2x2  = tr.Get2x2MaxAmplitude();
173   Float_t maxAmpnxn  = tr.GetnxnMaxAmplitude();
174   Float_t ampOutOfPatch2x2  = tr.Get2x2AmpOutOfPatch() ;
175   Float_t ampOutOfPatchnxn  = tr.GetnxnAmpOutOfPatch() ;
176
177   Int_t iSM2x2      = tr.Get2x2SuperModule();
178   Int_t iSMnxn      = tr.GetnxnSuperModule();
179   Int_t iCrystalPhi2x2 = tr.Get2x2CrystalPhi();
180   Int_t iCrystalPhinxn = tr.GetnxnCrystalPhi();
181   Int_t iCrystalEta2x2 = tr.Get2x2CrystalEta();
182   Int_t iCrystalEtanxn = tr.GetnxnCrystalEta();
183
184   AliDebug(2, Form("Trigger 2x2 max amp %f, out amp %f, SM %d, iphi %d ieta %d",  
185                    maxAmp2x2, ampOutOfPatch2x2, iSM2x2,iCrystalPhi2x2, iCrystalEta2x2));
186   AliDebug(2, Form("Trigger 4x4 max amp %f , out amp %f, SM %d, iphi %d, ieta %d",
187                    maxAmpnxn, ampOutOfPatchnxn, iSMnxn,iCrystalPhinxn, iCrystalEtanxn));
188
189   Int_t iRelId2x2 []= {iSM2x2+1,0,iCrystalPhi2x2,iCrystalEta2x2};// PHOS modules in order to calculate AbsId need to be 1-5 not 0-4 as returns trigger.
190   Int_t iAbsId2x2 =-1;
191   Int_t iRelIdnxn []= {iSMnxn+1,0,iCrystalPhinxn,iCrystalEtanxn};// PHOS modules in order to calculate AbsId need to be 1-5 not 0-4 as returns trigger.
192   Int_t iAbsIdnxn =-1;
193   TVector3    pos2x2(-1,-1,-1);
194   TVector3    posnxn(-1,-1,-1);
195   fGeom->RelToAbsNumbering(iRelId2x2, iAbsId2x2);
196   fGeom->RelToAbsNumbering(iRelIdnxn, iAbsIdnxn);
197   fGeom->RelPosInAlice(iAbsId2x2, pos2x2);
198   fGeom->RelPosInAlice(iAbsIdnxn, posnxn);
199
200   TArrayF triggerPosition(6);
201   triggerPosition[0] = pos2x2(0) ;   
202   triggerPosition[1] = pos2x2(1) ;   
203   triggerPosition[2] = pos2x2(2) ;  
204   triggerPosition[3] = posnxn(0) ;   
205   triggerPosition[4] = posnxn(1) ;   
206   triggerPosition[5] = posnxn(2) ;  
207
208   TArrayF triggerAmplitudes(4);
209   triggerAmplitudes[0] = maxAmp2x2 ;   
210   triggerAmplitudes[1] = ampOutOfPatch2x2 ;    
211   triggerAmplitudes[2] = maxAmpnxn ;   
212   triggerAmplitudes[3] = ampOutOfPatchnxn ;   
213
214   //esd->SetPHOSTriggerCells(triggerPosition);
215   esd->AddPHOSTriggerPosition(triggerPosition);
216   esd->AddPHOSTriggerAmplitudes(triggerAmplitudes);
217   
218
219   //########################################
220   //############# Fill CaloCells ###########
221   //########################################
222
223   Int_t nDigits = digitsArray->GetEntries();
224   Int_t idignew = 0 ;
225   AliDebug(1,Form("%d digits",nDigits));
226
227   const Int_t knEMC = fGeom->GetNModules()*fGeom->GetNPhi()*fGeom->GetNZ();
228   AliESDCaloCells &phsCells = *(esd->GetPHOSCells());
229   phsCells.CreateContainer(nDigits);
230   phsCells.SetType(AliESDCaloCells::kPHOSCell);
231
232   // Add to CaloCells only EMC digits with non-zero energy 
233   for (Int_t idig = 0 ; idig < nDigits ; idig++) {
234     const AliPHOSDigit * dig = (const AliPHOSDigit*)digitsArray->At(idig);
235     if(dig->GetId() <= knEMC && dig->GetEnergy() > 0 ){
236       //printf("i %d; id %d; amp %f; time %e\n",
237       //idignew,dig->GetId(),dig->GetEnergy(), dig->GetTime());
238       phsCells.SetCell(idignew,dig->GetId(), dig->GetEnergy(), dig->GetTime());   
239       idignew++;
240     }
241   }
242   phsCells.SetNumberOfCells(idignew);
243   phsCells.Sort();
244
245   //########################################
246   //############## Fill CaloClusters #######
247   //########################################
248
249   for (Int_t recpart = 0 ; recpart < nOfRecParticles ; recpart++) {
250     AliPHOSRecParticle  *rp    = dynamic_cast<AliPHOSRecParticle*>(recParticles->At(recpart));
251     if (Debug()) 
252       rp->Print();
253     // Get track segment and EMC rec.point associated with this rec.particle
254     AliPHOSTrackSegment *ts    = static_cast<AliPHOSTrackSegment *>(tsm->GetTrackSegments()
255                                                                     ->At(rp->GetPHOSTSIndex()));
256
257     AliPHOSEmcRecPoint  *emcRP = static_cast<AliPHOSEmcRecPoint *>(emcRecPoints->At(ts->GetEmcIndex()));
258     AliESDCaloCluster   *ec    = new AliESDCaloCluster() ; 
259     
260     Float_t xyz[3];
261     for (Int_t ixyz=0; ixyz<3; ixyz++) 
262       xyz[ixyz] = rp->GetPos()[ixyz];
263     
264     AliDebug(2,Form("Global position xyz=(%f,%f,%f)",xyz[0],xyz[1],xyz[2]));
265    
266     // Create cell lists
267
268     Int_t     cellMult   = emcRP->GetDigitsMultiplicity();
269     Int_t    *digitsList = emcRP->GetDigitsList();
270     Float_t  *rpElist    = emcRP->GetEnergiesList() ;
271     UShort_t *absIdList  = new UShort_t[cellMult];
272     Double_t *fracList   = new Double_t[cellMult];
273
274     for (Int_t iCell=0; iCell<cellMult; iCell++) {
275       AliPHOSDigit *digit = static_cast<AliPHOSDigit *>(digitsArray->At(digitsList[iCell]));
276       absIdList[iCell] = (UShort_t)(digit->GetId());
277       if (digit->GetEnergy() > 0)
278         fracList[iCell] = rpElist[iCell]/digit->GetEnergy();
279       else
280         fracList[iCell] = 0;
281     }
282
283     //Primaries
284     Int_t  primMult  = 0;
285     Int_t *primList =  emcRP->GetPrimaries(primMult);
286
287     // fills the ESDCaloCluster
288     ec->SetClusterType(AliESDCaloCluster::kPHOSCluster);
289     ec->SetPosition(xyz);                       //rec.point position in MARS
290     ec->SetE(rp->Energy());                     //total particle energy
291     ec->SetClusterDisp(emcRP->GetDispersion()); //cluster dispersion
292     ec->SetPid(rp->GetPID()) ;                  //array of particle identification
293     ec->SetM02(emcRP->GetM2x()) ;               //second moment M2x
294     ec->SetM20(emcRP->GetM2z()) ;               //second moment M2z
295     ec->SetNExMax(emcRP->GetNExMax());          //number of local maxima
296     ec->SetEmcCpvDistance(ts->GetCpvDistance("r")); //Only radius, what about separate x,z????
297     ec->SetClusterChi2(-1);                     //not yet implemented
298     ec->SetM11(-1) ;                            //not yet implemented
299  
300     //Cells contributing to clusters
301     ec->SetNCells(cellMult);
302     ec->SetCellsAbsId(absIdList);
303     ec->SetCellsAmplitudeFraction(fracList);
304
305     //Distance to the nearest bad crystal
306     ec->SetDistanceToBadChannel(emcRP->GetDistanceToBadCrystal()); 
307   
308     //Array of MC indeces
309     TArrayI arrayPrim(primMult,primList);
310     ec->AddLabels(arrayPrim);
311
312     //Array of tracks uncomment when available in future
313     //TArrayS arrayTrackMatched(1);// Only one track, temporal solution.
314     //arrayTrackMatched[0]= (Short_t)(matchedTrack[iClust]);
315     //ec->AddTracksMatched(arrayTrackMatched);
316     
317     // add the track to the esd object
318
319     esd->AddCaloCluster(ec);
320     delete ec;   
321   }
322   digitsArray ->Delete();
323   delete digitsArray;
324   emcRecPoints->Delete();
325   delete emcRecPoints;
326   delete tsm;
327   delete pid;
328 }
329
330 //____________________________________________________________________________
331 AliTracker* AliPHOSReconstructor::CreateTracker() const
332 {
333   // creates the PHOS tracker
334   return new AliPHOSTracker();
335 }
336
337 //____________________________________________________________________________
338 void  AliPHOSReconstructor::ConvertDigits(AliRawReader* rawReader, TTree* digitsTree) const
339 {
340   // Converts raw data to
341   // PHOS digits
342   // Works on a single-event basis
343
344   rawReader->Reset() ; 
345
346   AliPHOSRawDecoder * dc ;
347
348   const TObjArray* maps = AliPHOSRecoParamEmc::GetMappings();
349   if(!maps) AliFatal("Cannot retrieve ALTRO mappings!!");
350
351   AliAltroMapping *mapping[4];
352   for(Int_t i = 0; i < 4; i++) {
353     mapping[i] = (AliAltroMapping*)maps->At(i);
354   }
355
356   if(strcmp(fgkRecoParamEmc->DecoderVersion(),"v1")==0) 
357     dc=new AliPHOSRawDecoderv1(rawReader,mapping);
358   else 
359     if(strcmp(fgkRecoParamEmc->DecoderVersion(),"v2")==0) 
360       dc=new AliPHOSRawDecoderv2(rawReader,mapping);
361     else
362       dc=new AliPHOSRawDecoder(rawReader,mapping);
363
364   dc->SetOldRCUFormat(fgkRecoParamEmc->IsOldRCUFormat());
365   
366   dc->SubtractPedestals(fgkRecoParamEmc->SubtractPedestals());
367   
368   TClonesArray *digits = new TClonesArray("AliPHOSDigit",1);
369   digits->SetName("DIGITS");
370   Int_t bufsize = 32000;
371   digitsTree->Branch("PHOS", &digits, bufsize);
372
373   AliPHOSRawDigiProducer pr(fgkRecoParamEmc,fgkRecoParamCpv);
374   pr.MakeDigits(digits,dc);
375
376   delete dc ;
377
378   //!!!!for debug!!!
379 /*
380   Int_t modMax=-111;
381   Int_t colMax=-111;
382   Int_t rowMax=-111;
383   Float_t eMax=-333;
384   //!!!for debug!!!
385
386   Int_t relId[4];
387   for(Int_t iDigit=0; iDigit<digits->GetEntries(); iDigit++) {
388     AliPHOSDigit* digit = (AliPHOSDigit*)digits->At(iDigit);
389     if(digit->GetEnergy()>eMax) {
390       fGeom->AbsToRelNumbering(digit->GetId(),relId);
391       eMax=digit->GetEnergy();
392       modMax=relId[0];
393       rowMax=relId[2];
394       colMax=relId[3];
395     }
396   }
397
398   AliDebug(1,Form("Digit with max. energy:  modMax %d colMax %d rowMax %d  eMax %f\n\n",
399                   modMax,colMax,rowMax,eMax));
400 */
401   digitsTree->Fill();
402   digits->Delete();
403   delete digits;
404 }