765bf4a4a721135b420136dc72533fc8009af42a
[u/mrichter/AliRoot.git] / PHOS / AliPHOSReconstructioner.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 //  Algorithm class for the reconstruction: clusterizer
20 //                                          track segment maker
21 //                                          particle identifier   
22 //                  
23 //*-- Author: Gines Martinez & Yves Schutz (SUBATECH)
24
25
26 // --- ROOT system ---
27
28 #include "TClonesArray.h"
29
30 // --- Standard library ---
31
32 #include <iomanip.h>
33
34 // --- AliRoot header files ---
35
36 #include "AliPHOSReconstructioner.h"
37 #include "AliPHOSClusterizer.h"
38 #include "AliPHOSFastRecParticle.h"
39
40 ClassImp(AliPHOSReconstructioner)
41
42 //____________________________________________________________________________
43 AliPHOSReconstructioner::AliPHOSReconstructioner(AliPHOSClusterizer * Clusterizer, 
44                                                  AliPHOSTrackSegmentMaker * Tracker,
45                                                  AliPHOSPID * Pid)
46 {
47   // ctor
48   
49   fClusterizer        = Clusterizer ;
50   fTrackSegmentMaker  = Tracker ;
51   fPID                = Pid ; 
52   fDebugReconstruction = kFALSE ;
53
54
55
56 //____________________________________________________________________________
57  void AliPHOSReconstructioner::Init(AliPHOSClusterizer * Clusterizer, 
58                                                  AliPHOSTrackSegmentMaker * Tracker,
59                                                  AliPHOSPID * Pid)
60 {
61   fClusterizer        = Clusterizer ;
62   fTrackSegmentMaker  = Tracker ;
63   fPID                = Pid ; 
64   fDebugReconstruction = kFALSE ;
65
66
67 //____________________________________________________________________________
68  void AliPHOSReconstructioner::Make(DigitsList * dl, 
69                                     AliPHOSRecPoint::RecPointsList * emccl, 
70                                     AliPHOSRecPoint::RecPointsList * ppsdl, 
71                                     AliPHOSTrackSegment::TrackSegmentsList * trsl, 
72                                     AliPHOSRecParticle::RecParticlesList * rpl)
73 {
74   // Launches the Reconstruction process in the sequence: Make the reconstructed poins (clusterize)
75   //                                                      Make the track segments 
76   //                                                      Make the reconstructed particles
77   Int_t index ;   
78   cout << "Start making reconstructed points (clusterizing!!)" << endl;
79   fClusterizer->MakeClusters(dl, emccl, ppsdl);
80
81   cout << "AliPHOSReconstructioner: Digit list entries is " << dl->GetEntries() << endl ;
82   cout << "AliPHOSReconstructioner: Emc  list entries is " << emccl->GetEntries() << endl ;
83   cout << "AliPHOSReconstructioner: Ppsd list entries is " << ppsdl->GetEntries() << endl ;
84
85   // Digit Debuging
86   if  (fDebugReconstruction)     {
87     cout << ">>>>>>>>>>>>>>>>>>>>>> DebugReconstruction  <<<<<<<<<<<<<<<<<<<<<<<<<<"  << endl ;
88     cout << "DebugReconstruction>>> Digit list entries is " <<    dl->GetEntries() << endl ;
89     AliPHOSDigit * digit;
90     Bool_t calorimeter ;
91     Float_t factor;
92     cout << "DebugReconstruction>>>    Vol Id " << 
93       " Ene(MeV, KeV) "             <<                         
94       " Index "                    << 
95       " Nprim "                     << 
96       " Prim1 "                      << 
97       " Prim2 "                      << 
98       " Prim3 "                      <<  endl;      
99     for (index = 0 ; index < dl->GetEntries() ; index++) {
100       digit = (AliPHOSDigit * )  dl->At(index) ;
101       calorimeter = fClusterizer->IsInEmc(digit);
102       if (calorimeter) factor =1000. ; else factor=1000000.;
103       cout << "DebugReconstruction>>>  " << 
104         setw(8)  <<  digit->GetId() << " "  <<
105         setw(3)  <<  calorimeter <<  
106         setw(10) <<  factor*fClusterizer->Calibrate(digit->GetAmp()) <<       "  "  <<                   
107         setw(6)  <<  digit->GetIndexInList() << "  "  << 
108         setw(5)  <<  digit->GetNprimary() <<"  "  << 
109         setw(5)  <<  digit->GetPrimary(1) <<"  "  << 
110         setw(5)  <<  digit->GetPrimary(2) <<"  "  << 
111         setw(5)  <<  digit->GetPrimary(3) << endl;       
112     }
113     
114   }
115
116
117
118   // Making Clusters
119   if  (fDebugReconstruction)  cout << "DebugReconstruction>>> Start making reconstructed points (clusterizing)" << endl;
120
121   // mark the position of the RecPoints in the array
122   AliPHOSEmcRecPoint * emcrp ; 
123   for (index = 0 ; index < emccl->GetEntries() ; index++) {
124     emcrp = (AliPHOSEmcRecPoint * )emccl->At(index) ; 
125     emcrp->SetIndexInList(index) ; 
126   }
127   AliPHOSPpsdRecPoint * ppsdrp ; 
128   for (index = 0 ; index < ppsdl->GetEntries() ; index++) {
129     ppsdrp = (AliPHOSPpsdRecPoint * )ppsdl->At(index) ; 
130     ppsdrp->SetIndexInList(index) ; 
131   }
132   
133   if  (fDebugReconstruction) 
134     {
135       cout << "DebugReconstruction>>> Cluster emc list entries is " <<    emccl->GetEntries() << endl ;
136       AliPHOSEmcRecPoint * recpoint;
137       cout << "DebugReconstruction>>> Module "  << 
138         "Ene(MeV) "             <<                         
139         "Index "                    << 
140         "Multi "                    << 
141         "   X     "                      << 
142         "   Y     "                      << 
143         "   Z    "                      << 
144         " Lambda 1   "                     <<  
145         " Lambda 2   "                     <<
146         "MaxEnergy(MeV) "                 <<
147         "Nprim "                 <<
148         "Prim1 "                 <<
149         "Prim2 "                 <<
150         "Prim3 "                 << endl;  
151       for (index = 0 ; index < emccl->GetEntries() ; index++) {
152         recpoint = (AliPHOSEmcRecPoint * )emccl->At(index) ; 
153         TVector3  locpos;  recpoint->GetLocalPosition(locpos);
154         Float_t lambda[2]; recpoint->GetElipsAxis(lambda);
155         Int_t * primaries; 
156         Int_t nprimaries;
157         primaries = recpoint->GetPrimaries(nprimaries);
158         cout << "DebugReconstruction>>>  " << 
159           setw(2) <<recpoint->GetPHOSMod() << " "  << 
160           setw(9) << 1000.*recpoint->GetTotalEnergy() <<       " "  <<                   
161           setw(6) <<  recpoint->GetIndexInList() << " "  << 
162           setw(5) <<  recpoint->GetMultiplicity() <<" "  << 
163           setw(8) <<  locpos.X() <<" "  << 
164           setw(8) <<  locpos.Y() <<" "  << 
165           setw(8) <<  locpos.Z() << " " <<
166           setw(10) << lambda[0] << "  " <<
167           setw(10) << lambda[1] << "  " <<
168           setw(9) << 1000*recpoint->GetMaximalEnergy() << "  " << 
169           setw(9) << nprimaries << "  "  <<
170           setw(4) << primaries[0] << "  "  <<
171           setw(4) << primaries[1] << "  "  <<
172           setw(4) << primaries[2] << "  "  << endl;              
173       }
174       
175       cout << "DebugReconstruction>>> Cluster ppsd list entries is " <<    ppsdl->GetEntries() << endl ;
176       AliPHOSPpsdRecPoint * ppsdrecpoint;
177       Text_t detector[4];
178       cout << "DebugReconstruction>>> Module "  << 
179         "Det     "             <<      
180         "Ene(KeV) "             <<                         
181         "Index "                    << 
182         "Multi "                    << 
183         "   X     "                      << 
184         "   Y     "                      << 
185         "   Z         "                      << 
186         "Nprim "                 <<
187         "Prim1 "                 <<
188         "Prim2 "                 <<
189         "Prim3 "                 << endl;  
190       for (index = 0 ; index < ppsdl->GetEntries() ; index++) {
191         ppsdrecpoint = (AliPHOSPpsdRecPoint * ) ppsdl->At(index) ; 
192         TVector3  locpos; ppsdrecpoint->GetLocalPosition(locpos);
193         Int_t * primaries; 
194         Int_t nprimaries;
195         if (ppsdrecpoint->GetUp()) 
196           strcpy(detector, "CPV"); 
197         else 
198           strcpy(detector, "PC ");
199         primaries = ppsdrecpoint->GetPrimaries(nprimaries);
200         cout << "DebugReconstruction>>> " << 
201           setw(4) << ppsdrecpoint->GetPHOSMod() << "  "  << 
202           setw(4)  << detector << " "      <<
203           setw(9) << 1000000.*ppsdrecpoint->GetTotalEnergy() <<       " "  <<             
204           setw(6) <<  ppsdrecpoint->GetIndexInList() << " "  << 
205           setw(5) <<  ppsdrecpoint->GetMultiplicity() <<" "  << 
206           setw(8) <<  locpos.X() <<" "  << 
207           setw(8) <<  locpos.Y() <<" "  << 
208           setw(8) <<  locpos.Z() << " " <<
209           setw(9) << nprimaries << "  "  <<
210           setw(4) << primaries[0] << "  "  <<
211           setw(4) << primaries[1] << "  "  <<
212           setw(4) << primaries[2] << "  "  << endl;              
213       }
214     }  
215   
216   
217   if  (fDebugReconstruction)  cout << "DebugReconstruction>>>> Start making track segments(unfolding+tracksegments)" << endl;
218   fTrackSegmentMaker->MakeTrackSegments(dl, emccl, ppsdl, trsl) ;   
219   
220   // mark the position of the TrackSegments in the array
221   AliPHOSTrackSegment * trs ; 
222   for (index = 0 ; index < trsl->GetEntries() ; index++) {
223     trs = (AliPHOSTrackSegment * )trsl->At(index) ; 
224     trs->SetIndexInList(index) ; 
225   }
226   if  (fDebugReconstruction){
227     cout << "DebugReconstruction>>> Track segment list entries is " <<    trsl->GetEntries() << endl ;
228     cout << "DebugReconstruction>>> Module "  << 
229       "Ene(KeV) "             <<                         
230       "Index "                    << 
231       "   X      "                      << 
232       "   Y      "                      << 
233       "   Z       "                      <<
234       " rX        "                      << 
235       " rY        "                      << 
236       " rZ      "                               << 
237       "Nprim "                 <<
238       "Prim1 "                 <<
239       "Prim2 "                 <<
240       "Prim3 "                 << endl;  
241     
242     for (index = 0 ; index < trsl->GetEntries() ; index++) {
243       trs = (AliPHOSTrackSegment * )trsl->At(index) ; 
244       TVector3 locpos; trs->GetPosition(locpos);
245       Int_t * primaries; 
246       Int_t nprimaries;
247       primaries = trs->GetPrimariesEmc(nprimaries);
248       cout << "DebugReconstruction>>> " << 
249         setw(4) << trs->GetPHOSMod() << "  "  << 
250         setw(9) << 1000.*trs->GetEnergy() <<       " "  <<             
251         setw(3) <<  trs->GetIndexInList() << " "  <<  
252         setw(9) <<  locpos.X() <<" "  << 
253         setw(9) <<  locpos.Y() <<" "  << 
254         setw(9) <<  locpos.Z() << " " <<
255         setw(10) <<  (trs->GetMomentumDirection()).X() << " " <<
256         setw(10) <<  (trs->GetMomentumDirection()).Y() << " " <<
257         setw(10) <<  (trs->GetMomentumDirection()).Z() << " " <<
258         setw(4) << nprimaries << "  "  <<
259         setw(4) << primaries[0] << "  "  <<
260         setw(4) << primaries[1] << "  "  <<
261         setw(4) << primaries[2] << "  "  << endl;
262     }
263     
264   }
265   if  (fDebugReconstruction)  cout << "DebugReconstruction>>>> Start making reconstructed particles" << endl;
266   
267   fPID->MakeParticles(trsl, rpl) ; 
268   
269   // mark the position of the RecParticles in the array
270   AliPHOSRecParticle * rp ; 
271   for (index = 0 ; index < rpl->GetEntries() ; index++) {
272     rp = (AliPHOSRecParticle * )rpl->At(index) ; 
273     rp->SetIndexInList(index) ; 
274   }
275   //Debugger of RecParticles
276  if  (fDebugReconstruction){
277     cout << "DebugReconstruction>>>  Reconstructed particle list entries is " <<    rpl->GetEntries() << endl ;
278     cout << "DebugReconstruction>>> Module "  << 
279       "    PARTICLE     "   <<
280       "Ene(KeV) "             <<                         
281       "Index "                    << 
282       "   X      "                      << 
283       "   Y      "                      << 
284       "   Z       "                      <<
285       "Nprim "                 <<
286       "Prim1 "                 <<
287       "Prim2 "                 <<
288       "Prim3 "                 << endl;  
289     for (index = 0 ; index < rpl->GetEntries() ; index++) {
290       rp = (AliPHOSRecParticle * ) rpl->At(index) ;       
291       TVector3 locpos; (rp->GetPHOSTrackSegment())->GetPosition(locpos);
292       Int_t * primaries; 
293       Int_t nprimaries;
294       Text_t particle[11];
295       primaries = (rp->GetPHOSTrackSegment())->GetPrimariesEmc(nprimaries);
296       switch(rp->GetType())
297         {
298         case  AliPHOSFastRecParticle::kNEUTRALEM:
299           strcpy( particle, "NEUTRAL_EM");
300           break;
301         case  AliPHOSFastRecParticle::kNEUTRALHA:
302           strcpy(particle, "NEUTRAL_HA");
303           break;
304         case  AliPHOSFastRecParticle::kGAMMA:
305           strcpy(particle, "GAMMA");
306           break ;
307         case  AliPHOSFastRecParticle::kGAMMAHA: 
308           strcpy(particle, "GAMMA_H");
309           break ;
310         case  AliPHOSFastRecParticle::kABSURDEM:
311           strcpy(particle, "ABSURD_EM") ;
312           break ;
313         case  AliPHOSFastRecParticle::kABSURDHA:
314           strcpy(particle, "ABSURD_HA") ;
315           break ;       
316         case  AliPHOSFastRecParticle::kELECTRON:
317           strcpy(particle, "ELECTRON") ;
318           break ;
319         case  AliPHOSFastRecParticle::kCHARGEDHA:
320           strcpy(particle, "CHARGED_HA") ;
321           break ; 
322         }
323       
324       cout << "DebugReconstruction>>> " << 
325         setw(4) << (rp->GetPHOSTrackSegment())->GetPHOSMod() << "  "  <<
326         setw(15) << particle << "  " <<
327         setw(9) << 1000.*(rp->GetPHOSTrackSegment())->GetEnergy() <<       " "  <<             
328         setw(3) <<  rp->GetIndexInList() << " "  <<  
329         setw(9) <<  locpos.X() <<" "  << 
330         setw(9) <<  locpos.Y() <<" "  << 
331         setw(9) <<  locpos.Z() << " " <<
332         setw(4) << nprimaries << "  "  <<
333         setw(4) << primaries[0] << "  "  <<
334         setw(4) << primaries[1] << "  "  <<
335         setw(4) << primaries[2] << "  "  << endl;
336     }
337     
338   }
339
340
341 }