Change in AddHit suggested by J. Chudoba
[u/mrichter/AliRoot.git] / ZDC / AliZDC.cxx
CommitLineData
4c039060 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$Log$
0d2bb33c 18Revision 1.20 2001/03/26 13:39:20 coppedis
19Comment prints
20
4c38d2da 21Revision 1.19 2001/03/26 09:10:23 coppedis
22Corrected bug in constructor (fIshunt has to be =1)
23
2e6fc82a 24Revision 1.18 2001/03/20 08:21:55 coppedis
25ZDC needs PIPE, ABSO, DIPO and SHIL
26
ec71d094 27Revision 1.17 2001/03/16 16:18:03 coppedis
28Correction for superposition of ZDC volumes with MUON arm one
29
0014adbc 30Revision 1.16 2001/03/15 16:01:11 coppedis
31Code review
32
09630792 33Revision 1.15 2001/01/26 19:56:27 hristov
34Major upgrade of AliRoot code
35
2ab0c725 36Revision 1.14 2000/12/12 13:17:01 coppedis
37Minor corrections suggested by P. Hristov
38
65d4f2be 39Revision 1.12 2000/12/01 08:19:01 coppedis
40Adding a message error if ZDC is constructed without DIPO
41
588ed15d 42Revision 1.11 2000/11/30 17:21:03 coppedis
43Introduce hit array fStHits reset only at the end of the event (for digitization)
44
f901045b 45Revision 1.10 2000/11/22 11:32:58 coppedis
46Major code revision
47
866ab5a2 48Revision 1.9 2000/10/02 21:28:20 fca
49Removal of useless dependecies via forward declarations
50
94de3818 51Revision 1.8 2000/07/10 13:58:01 fca
52New version of ZDC from E.Scomparin & C.Oppedisano
53
68ca986e 54Revision 1.7 2000/01/19 17:17:40 fca
55
1cedd08a 56Revision 1.6 1999/09/29 09:24:35 fca
57Introduction of the Copyright and cvs Log
58
4c039060 59*/
60
fe4da5cc 61///////////////////////////////////////////////////////////////////////////////
62// //
63// Zero Degree Calorimeter //
f901045b 64// This class contains the basic functions for the ZDCs //
65// Functions specific to one particular geometry are //
fe4da5cc 66// contained in the derived classes //
67// //
fe4da5cc 68///////////////////////////////////////////////////////////////////////////////
69
65a824a5 70#include <stdlib.h>
71
f901045b 72// --- ROOT system
fe4da5cc 73#include <TBRIK.h>
74#include <TNode.h>
2ab0c725 75#include <TGeometry.h>
76#include <TFile.h>
77#include <TTree.h>
fe4da5cc 78
f901045b 79// --- AliRoot header files
fe4da5cc 80#include "AliZDC.h"
f901045b 81#include "AliZDCHit.h"
fe4da5cc 82#include "AliRun.h"
f901045b 83#include "AliDetector.h"
fe4da5cc 84#include "AliCallf77.h"
85#include "AliConst.h"
86#include "AliMC.h"
87
fe4da5cc 88
89ClassImp(AliZDC)
90
91//_____________________________________________________________________________
92AliZDC::AliZDC()
93{
94 //
95 // Default constructor for the Zero Degree Calorimeter base class
96 //
2e6fc82a 97
98 fIshunt = 1;
f901045b 99
f901045b 100 fNhits = 0;
09630792 101
f901045b 102 fNStHits = 0;
09630792 103
f901045b 104 fNPrimaryHits = 0;
09630792 105 fNoShower = 0;
fe4da5cc 106}
107
108//_____________________________________________________________________________
109AliZDC::AliZDC(const char *name, const char *title)
110 : AliDetector(name,title)
111{
112 //
113 // Standard constructor for the Zero Degree Calorimeter base class
114 //
115
116 //
117 // Allocate the array of hits
2e6fc82a 118
119 fIshunt = 1;
f901045b 120
121 fHits = new TClonesArray("AliZDCHit",1000);
1cedd08a 122 gAlice->AddHitList(fHits);
fe4da5cc 123
f901045b 124 fStHits = new TClonesArray("AliZDCHit",1000);
f901045b 125 fNStHits = 0;
126
127 fNPrimaryHits = 0;
09630792 128 fNoShower = 0;
866ab5a2 129
130}
131//____________________________________________________________________________
132AliZDC::~AliZDC()
133{
134 //
135 // ZDC destructor
136 //
137
138 fIshunt = 0;
2e6fc82a 139
65d4f2be 140// delete fHits;
141// if(fStHits){
142// fStHits->Delete();
143// delete fStHits;
144// fNStHits = 0;
145// }
146// delete fDigits;
fe4da5cc 147}
fe4da5cc 148//_____________________________________________________________________________
149void AliZDC::AddHit(Int_t track, Int_t *vol, Float_t *hits)
150{
151 //
f901045b 152 // Add a ZDC hit to the hit list.
153 // -> We make use of 2 array of hits:
154 // [1] fHits (the usual one) that contains hits for each PRIMARY
155 // [2] fStHits that contains hits for each EVENT and is used to
156 // obtain digits at the end of each event
fe4da5cc 157 //
f901045b 158
68ca986e 159 static Float_t primKinEn, xImpact, yImpact, sFlag;
160
f901045b 161 AliZDCHit *newquad, *curevquad, *curprimquad;
162 newquad = new AliZDCHit(fIshunt, track, vol, hits);
65d4f2be 163
2e6fc82a 164 TClonesArray &lsthits = *fStHits;
65d4f2be 165 TClonesArray &lhits = *fHits;
f901045b 166
167 Int_t i,j,kStHit = 1;
168 for(i=0; i<fNStHits; i++){
2e6fc82a 169 // If hits are equal (same track, same volume), sum them.
f901045b 170 curevquad = (AliZDCHit*) lsthits[i];
171 kStHit = 1;
172 if(*curevquad == *newquad){
173 *curevquad = *curevquad+*newquad;
174 kStHit = 0;
175 }
176 }
177
178 for(j=0; j<fNhits; j++){
2e6fc82a 179 // If hits are equal (same track, same volume), sum them.
f901045b 180 curprimquad = (AliZDCHit*) lhits[j];
181 if(*curprimquad == *newquad){
182 *curprimquad = *curprimquad+*newquad;
183 delete newquad;
68ca986e 184 return;
f901045b 185 }
186 }
187
188 if(fNhits==0){
68ca986e 189 // First hit -> setting flag for primary or secondary particle
190 Int_t primary = gAlice->GetPrimary(track);
191 if(track != primary){
192 newquad->fSFlag = 1; // Hit created by secondary particle entering the ZDC
193 }
194 else if(track == primary){
195 newquad->fSFlag = 0; // Hit created by PRIMARY particle entering the ZDC
196 }
09630792 197 fNPrimaryHits += 1;
68ca986e 198 sFlag = newquad->fSFlag;
199 primKinEn = newquad->fPrimKinEn;
200 xImpact = newquad->fXImpact;
201 yImpact = newquad->fYImpact;
202 }
203 else{
204 newquad->fPrimKinEn = primKinEn;
205 newquad->fXImpact = xImpact;
206 newquad->fYImpact = yImpact;
207 newquad->fSFlag = sFlag;
208 }
f901045b 209
210 //Otherwise create a new hit
211 new(lhits[fNhits]) AliZDCHit(newquad);
212 fNhits++;
213
214 if(kStHit){
215 new(lsthits[fNStHits]) AliZDCHit(newquad);
216 fNStHits++;
217 }
218
2e6fc82a 219// if(fDebug == 1){
4c38d2da 220// printf("\n Primary Hits --------------------------------------------------------\n");
221// fHits->Print("");
222// printf("\n Event Hits --------------------------------------------------------\n");
223// fStHits->Print("");
2e6fc82a 224// }
f901045b 225
866ab5a2 226 delete newquad;
227 }
68ca986e 228
866ab5a2 229//_____________________________________________________________________________
f901045b 230void AliZDC::ResetDigits()
231{
232 //
233 // Reset number of digits and the digits array
234 //
235
236 AliDetector::ResetDigits();
65d4f2be 237// fNStHits = 0;
238// if(fStHits) fStHits->Clear();
f901045b 239}
240
fe4da5cc 241//_____________________________________________________________________________
242void AliZDC::BuildGeometry()
243{
244 //
245 // Build the ROOT TNode geometry for event display
246 // in the Zero Degree Calorimeter
247 // This routine is dummy for the moment
248 //
249
68ca986e 250 TNode *node, *top;
251 TBRIK *brik;
252 const int kColorZDC = kRed;
fe4da5cc 253
254 //
68ca986e 255 top=gAlice->GetGeometry()->GetNode("alice");
fe4da5cc 256
257 // ZDC
fe4da5cc 258 brik = new TBRIK("S_ZDC","ZDC box","void",300,300,5);
68ca986e 259 top->cd();
260 node = new TNode("ZDC","ZDC","S_ZDC",0,0,600,"");
261 node->SetLineColor(kColorZDC);
262 fNodes->Add(node);
fe4da5cc 263}
264
265//_____________________________________________________________________________
266Int_t AliZDC::DistancetoPrimitive(Int_t , Int_t )
267{
268 //
269 // Distance from the mouse to the Zero Degree Calorimeter
270 // Dummy routine
271 //
272 return 9999;
273}
274
275//_____________________________________________________________________________
fe4da5cc 276void AliZDC::StepManager()
277{
278 //
279 // Routine called at every step in the Zero Degree Calorimeter
fe4da5cc 280 //
fe4da5cc 281}