]> git.uio.no Git - u/mrichter/AliRoot.git/blob - PHOS/AliPHOSvImpacts.cxx
Coverity fixes
[u/mrichter/AliRoot.git] / PHOS / AliPHOSvImpacts.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
17 /* $Id$ */
18
19 /* History of cvs commits:
20  *
21  * $Log$
22  * Revision 1.24  2006/11/14 17:11:15  hristov
23  * Removing inheritances from TAttLine, TAttMarker and AliRndm in AliModule. The copy constructor and assignment operators are moved to the private part of the class and not implemented. The corresponding changes are propagated to the detectors
24  *
25  * Revision 1.23  2006/09/13 07:31:01  kharlov
26  * Effective C++ corrections (T.Pocheptsov)
27  *
28  * Revision 1.22  2005/06/17 07:39:07  hristov
29  * Removing GetDebug and SetDebug from AliRun and AliModule. Using AliLog for the messages
30  *
31  * Revision 1.21  2005/05/28 14:19:05  schutz
32  * Compilation warnings fixed by T.P.
33  *
34  */
35
36 //_________________________________________________________________________
37 // Implementation version vImpacts of PHOS Manager class.
38 // This class inherits from v1 and adds impacts storing.
39 // Impacts stands for exact values of track coming to the detectors
40 // EMC, CPV or PPSD.
41 // Impacts are written to the same tree as hits are
42 // but in separate branches.
43 //---
44 //*-- Author: Yuri Kharlov (IHEP, Protvino/SUBATECH, Nantes)
45
46
47 // --- ROOT system ---
48
49 //#include <TTree.h>
50 #include <TClonesArray.h>
51 #include <TVirtualMC.h>
52
53 // --- Standard library ---
54
55 // --- AliRoot header files ---
56
57 #include "AliPHOSGeometry.h"
58 #include "AliPHOSImpact.h"
59 #include "AliPHOSvImpacts.h"
60 #include "AliRun.h"
61 #include "AliMC.h"
62 #include "AliLog.h"
63
64 ClassImp(AliPHOSvImpacts)
65
66 //____________________________________________________________________________
67 AliPHOSvImpacts::AliPHOSvImpacts():
68   fEMCImpacts(new TList),
69   fCPVImpacts(new TList),
70   fPPSDImpacts(new TList)
71 {
72   // ctor
73 }
74
75 //____________________________________________________________________________
76 AliPHOSvImpacts::AliPHOSvImpacts(const char *name, const char *title):
77   AliPHOSv1(name,title),
78   fEMCImpacts(new TList),
79   fCPVImpacts(new TList),
80   fPPSDImpacts(0)
81 {
82   // ctor : title is used to identify the layout
83   //
84   // We store hits :
85   //   - fHits (the "normal" one), which retains the hits associated with
86   //     the current primary particle being tracked
87   //     (this array is reset after each primary has been tracked).
88   //     This part inherits from AliPHOSv1
89   //
90   // We store impacts :
91   //  - fEMCImpacts, fCPVImpacts which are
92   //    TList of EMC and CPV modules respectively, each
93   //    modules contains TClonesArray of AliPHOSImpacts
94
95   Int_t nPHOSModules = GetGeometry()->GetNModules();
96   Int_t nCPVModules  = GetGeometry()->GetNModules();
97
98   Int_t iPHOSModule;
99   TClonesArray * impacts;
100   for (iPHOSModule=0; iPHOSModule<nPHOSModules; iPHOSModule++) {
101     fEMCImpacts->Add(new TClonesArray("AliPHOSImpact",200)) ;
102     fNEMCImpacts[iPHOSModule] = 0;
103     impacts = dynamic_cast<TClonesArray *>(fEMCImpacts->At(iPHOSModule));
104   }
105   for (iPHOSModule=0; iPHOSModule<nCPVModules; iPHOSModule++) {
106     fCPVImpacts->Add(new TClonesArray("AliPHOSImpact",200)) ;
107     fNCPVImpacts[iPHOSModule] = 0;
108     impacts = dynamic_cast<TClonesArray *>(fCPVImpacts->At(iPHOSModule));
109   }
110
111 }
112
113 //____________________________________________________________________________
114 AliPHOSvImpacts::~AliPHOSvImpacts()
115 {
116   // dtor
117
118   // Delete hits
119   if ( fHits ) {
120     fHits->Delete() ; 
121     delete fHits ;
122     fHits = 0 ; 
123   }
124
125   // Delete impacts in EMC, CPV
126   if ( fEMCImpacts ) {
127     fEMCImpacts->Delete() ; 
128     delete fEMCImpacts ;
129     fEMCImpacts = 0 ; 
130   }
131   if ( fCPVImpacts ) {
132     fCPVImpacts->Delete() ; 
133     delete fCPVImpacts ;
134     fCPVImpacts = 0 ; 
135   }
136 }
137
138 //____________________________________________________________________________
139 void AliPHOSvImpacts::AddImpact(const char* det, Int_t shunt, Int_t primary, Int_t track, Int_t module,
140                            Int_t pid, TLorentzVector p, Float_t *xyz)
141 {
142   // Add an impact to the impact list.
143
144   TClonesArray * impacts = 0;
145   Int_t         nImpacts = 0;
146
147   if (strcmp(det,"EMC ")==0) {
148     impacts = dynamic_cast<TClonesArray *>(fEMCImpacts->At(module));
149     nImpacts= fNEMCImpacts[module];
150     fNEMCImpacts[module]++ ;
151   }
152   else if (strcmp(det,"CPV ")==0) {
153     impacts = dynamic_cast<TClonesArray *>(fCPVImpacts->At(module));
154     nImpacts= fNCPVImpacts[module];
155     fNCPVImpacts[module]++ ;
156   }
157   else
158     AliFatal(Form("Wrong PHOS configuration: det=%s",det));
159
160   new((*impacts)[nImpacts]) AliPHOSImpact(shunt,primary,track,pid,p,xyz) ;
161
162   AliDebugClass(1,Form("Module %d %s: ",module,det));
163   if (AliLog::GetGlobalDebugLevel()>0)
164     (static_cast<AliPHOSImpact*>((impacts->At(nImpacts))))->Print();
165 }
166
167 //____________________________________________________________________________
168 void AliPHOSvImpacts::MakeBranch(Option_t *opt)
169 {  
170   // Create new branch in the current Hits Root Tree containing
171   // a list of PHOS impacts (exact values of track coming to detector)
172
173   AliDetector::MakeBranch(opt);
174   
175   Int_t bufferSize = 32000 ;
176   Int_t splitlevel = 0 ;
177   fLoader->TreeH()->Branch("PHOSEmcImpacts" , "TList", &fEMCImpacts , bufferSize, splitlevel);
178   fLoader->TreeH()->Branch("PHOSCpvImpacts" , "TList", &fCPVImpacts , bufferSize, splitlevel);
179   
180 }
181
182 //____________________________________________________________________________
183 void AliPHOSvImpacts::ResetHits() 
184 {              
185   // Reset impact branches for EMC, CPV and PPSD
186
187   AliDetector::ResetHits();
188
189   Int_t i;
190   for (i=0; i<GetGeometry()->GetNModules(); i++) {
191     (static_cast<TClonesArray*>(fEMCImpacts->At(i))) -> Clear();
192     fNEMCImpacts[i] = 0 ;
193   }
194
195   for (i=0; i<GetGeometry()->GetNModules(); i++) {
196     (static_cast<TClonesArray*>(fCPVImpacts->At(i))) -> Clear();
197     fNCPVImpacts[i] = 0 ;
198   }
199   
200 }
201
202 //_____________________________________________________________________________
203 void AliPHOSvImpacts::StepManager(void)
204 {
205   // Find impacts (tracks which enter the EMC, CPV)
206   // and add them to to the impact lists
207
208   AliPHOSv1::StepManager();
209
210   Float_t xyzm[3], xyzd[3], pm[3], pd[3];
211   TLorentzVector pmom     ;           // Lorentz momentum of the particle initiated hit
212   TLorentzVector pos      ;           // Lorentz vector of the track current position
213   Int_t          copy     ;
214
215   Int_t tracknumber =  gAlice->GetMCApp()->GetCurrentTrackNumber() ; 
216   Int_t primary     =  gAlice->GetMCApp()->GetPrimary( gAlice->GetMCApp()->GetCurrentTrackNumber() ); 
217   TString name      =  GetGeometry()->GetName() ; 
218
219   // Add impact to EMC
220
221   static Int_t idPXTL = gMC->VolId("PXTL");
222   if( gMC->CurrentVolID(copy) == idPXTL &&
223       gMC->IsTrackEntering() ) {
224     gMC->TrackMomentum(pmom);
225     gMC->TrackPosition(pos) ;
226
227     Int_t i;
228     for (i=0; i<3; i++) xyzm[i] = pos[i];
229
230     for (i=0; i<3; i++) {
231       xyzm[i] = pos[i] ;
232       pm[i]   = pmom[i];
233     }
234     gMC -> Gmtod (xyzm, xyzd, 1);    // transform coordinate from master to daughter system
235     gMC -> Gmtod (pm,   pd,   2);    // transform 3-momentum from master to daughter system
236
237     // Select tracks coming to the crystal from up or down sides
238     if ((pd[1]<0 && xyzd[1] >  GetGeometry()->GetCrystalSize(1)/2-0.1) ||
239         (pd[1]>0 && xyzd[1] < -GetGeometry()->GetCrystalSize(1)/2+0.1)) {
240     // Select tracks coming to the crystal from up or down sides
241       Int_t pid = gMC->TrackPid();
242       Int_t module;
243       gMC->CurrentVolOffID(10,module);
244       module--;
245       AddImpact("EMC ",fIshunt, primary,tracknumber, module, pid, pmom, xyzm);
246     }
247   }
248
249   // Add impact to CPV
250
251   static Int_t idPCPQ = gMC->VolId("PCPQ");
252   if( gMC->CurrentVolID(copy) == idPCPQ &&
253       gMC->IsTrackEntering() ) {
254     gMC->TrackMomentum(pmom);
255     gMC->TrackPosition(pos) ;
256
257     Int_t i;
258     for (i=0; i<3; i++) xyzm[i] = pos[i];
259
260     for (i=0; i<3; i++) {
261       xyzm[i] = pos[i] ;
262       pm[i]   = pmom[i];
263     }
264     Int_t pid = gMC->TrackPid();
265     Int_t module;
266     gMC->CurrentVolOffID(3,module);
267     module--;
268     AddImpact("CPV ",fIshunt, primary,tracknumber, module, pid, pmom, xyzm);
269   }
270   
271 }