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