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