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