Formula for rB corrected.
[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$
2685bf00 18Revision 1.26 2001/10/04 14:30:28 coppedis
19Event merging for ZDC
20
1acbaaa8 21Revision 1.25 2001/10/04 14:24:15 coppedis
22Event merging for ZDC
23
b6d27557 24Revision 1.24 2001/09/26 16:03:41 coppedis
25Merging implemented
26
359cdddc 27Revision 1.23 2001/05/15 13:44:57 coppedis
28Changes in AddHit method
29
43f34e8b 30Revision 1.22 2001/05/14 09:53:32 coppedis
31Adding functions ZMin and ZMax
32
cefa66cb 33Revision 1.21 2001/04/20 10:05:02 coppedis
34Minor changes
35
0d2bb33c 36Revision 1.20 2001/03/26 13:39:20 coppedis
37Comment prints
38
4c38d2da 39Revision 1.19 2001/03/26 09:10:23 coppedis
40Corrected bug in constructor (fIshunt has to be =1)
41
2e6fc82a 42Revision 1.18 2001/03/20 08:21:55 coppedis
43ZDC needs PIPE, ABSO, DIPO and SHIL
44
ec71d094 45Revision 1.17 2001/03/16 16:18:03 coppedis
46Correction for superposition of ZDC volumes with MUON arm one
47
0014adbc 48Revision 1.16 2001/03/15 16:01:11 coppedis
49Code review
50
09630792 51Revision 1.15 2001/01/26 19:56:27 hristov
52Major upgrade of AliRoot code
53
2ab0c725 54Revision 1.14 2000/12/12 13:17:01 coppedis
55Minor corrections suggested by P. Hristov
56
65d4f2be 57Revision 1.12 2000/12/01 08:19:01 coppedis
58Adding a message error if ZDC is constructed without DIPO
59
588ed15d 60Revision 1.11 2000/11/30 17:21:03 coppedis
61Introduce hit array fStHits reset only at the end of the event (for digitization)
62
f901045b 63Revision 1.10 2000/11/22 11:32:58 coppedis
64Major code revision
65
866ab5a2 66Revision 1.9 2000/10/02 21:28:20 fca
67Removal of useless dependecies via forward declarations
68
94de3818 69Revision 1.8 2000/07/10 13:58:01 fca
70New version of ZDC from E.Scomparin & C.Oppedisano
71
68ca986e 72Revision 1.7 2000/01/19 17:17:40 fca
73
1cedd08a 74Revision 1.6 1999/09/29 09:24:35 fca
75Introduction of the Copyright and cvs Log
76
4c039060 77*/
78
fe4da5cc 79///////////////////////////////////////////////////////////////////////////////
80// //
359cdddc 81// Zero Degree Calorimeter //
82// This class contains the basic functions for the ZDCs; //
83// functions specific to one particular geometry are //
84// contained in the derived classes //
fe4da5cc 85// //
fe4da5cc 86///////////////////////////////////////////////////////////////////////////////
87
65a824a5 88#include <stdlib.h>
359cdddc 89#include <iostream.h>
65a824a5 90
f901045b 91// --- ROOT system
fe4da5cc 92#include <TBRIK.h>
93#include <TNode.h>
2ab0c725 94#include <TGeometry.h>
95#include <TFile.h>
96#include <TTree.h>
fe4da5cc 97
f901045b 98// --- AliRoot header files
fe4da5cc 99#include "AliZDC.h"
f901045b 100#include "AliZDCHit.h"
b6d27557 101#include "AliZDCMergedHit.h"
359cdddc 102#include "AliZDCDigit.h"
103#include "AliZDCMerger.h"
f901045b 104#include "AliDetector.h"
fe4da5cc 105#include "AliCallf77.h"
106#include "AliConst.h"
107#include "AliMC.h"
359cdddc 108#include "AliRun.h"
109#include "AliHeader.h"
fe4da5cc 110
fe4da5cc 111
112ClassImp(AliZDC)
113
114//_____________________________________________________________________________
115AliZDC::AliZDC()
116{
117 //
118 // Default constructor for the Zero Degree Calorimeter base class
119 //
2e6fc82a 120
359cdddc 121 fIshunt = 1;
122 fNoShower = 0;
123 fMerger = 0;
09630792 124
359cdddc 125 fHits = 0;
126 fNhits = 0;
09630792 127
359cdddc 128 fDigits = 0;
129 fNdigits = 0;
2685bf00 130
131 fMergedHits = 0;
132 fTreeSD = 0;
133 fTreeMD = 0;
134
135 fNRecPoints = 0;
136 fRecPoints = 0;
359cdddc 137
fe4da5cc 138}
139
140//_____________________________________________________________________________
141AliZDC::AliZDC(const char *name, const char *title)
142 : AliDetector(name,title)
143{
144 //
145 // Standard constructor for the Zero Degree Calorimeter base class
146 //
147
359cdddc 148 fIshunt = 1;
149 fNoShower = 0;
150 fMerger = 0;
f901045b 151
359cdddc 152 // Allocate the hits array
f901045b 153 fHits = new TClonesArray("AliZDCHit",1000);
1cedd08a 154 gAlice->AddHitList(fHits);
b6d27557 155 // Allocate the merged hits array
156 fMergedHits = new TClonesArray("AliZDCMergedHit",1000);
f901045b 157
359cdddc 158 // Allocate the digits array
159 fDigits = new TClonesArray("AliZDCDigit",1000);
160
2685bf00 161 fTreeSD = 0;
162 fTreeMD = 0;
163
164 fNRecPoints = 0;
165 fRecPoints = 0;
866ab5a2 166
167}
168//____________________________________________________________________________
169AliZDC::~AliZDC()
170{
171 //
172 // ZDC destructor
173 //
174
175 fIshunt = 0;
359cdddc 176
b6d27557 177 if(fMerger) delete fMerger;
2e6fc82a 178
359cdddc 179// if(fHits){
180// fHits->Delete();
181// delete fHits;
65d4f2be 182// }
359cdddc 183
184// if(fDigits){
185// fDigits->Delete();
186// delete fDigits;
187// }
188
fe4da5cc 189}
fe4da5cc 190//_____________________________________________________________________________
191void AliZDC::AddHit(Int_t track, Int_t *vol, Float_t *hits)
192{
193 //
f901045b 194 // Add a ZDC hit to the hit list.
195 // -> We make use of 2 array of hits:
196 // [1] fHits (the usual one) that contains hits for each PRIMARY
197 // [2] fStHits that contains hits for each EVENT and is used to
198 // obtain digits at the end of each event
fe4da5cc 199 //
f901045b 200
68ca986e 201 static Float_t primKinEn, xImpact, yImpact, sFlag;
202
43f34e8b 203 AliZDCHit *newquad, *curprimquad;
f901045b 204 newquad = new AliZDCHit(fIshunt, track, vol, hits);
65d4f2be 205 TClonesArray &lhits = *fHits;
cefa66cb 206
207 if(fNhits==0){
208 // First hit -> setting flag for primary or secondary particle
209 Int_t primary = gAlice->GetPrimary(track);
210 if(track != primary){
211 newquad->fSFlag = 1; // SECONDARY particle entering the ZDC
212 }
213 else if(track == primary){
214 newquad->fSFlag = 0; // PRIMARY particle entering the ZDC
215 }
216// fNPrimaryHits += 1;
217 sFlag = newquad->fSFlag;
218 primKinEn = newquad->fPrimKinEn;
219 xImpact = newquad->fXImpact;
220 yImpact = newquad->fYImpact;
221 }
222 else{
223 newquad->fPrimKinEn = primKinEn;
224 newquad->fXImpact = xImpact;
225 newquad->fYImpact = yImpact;
226 newquad->fSFlag = sFlag;
227 }
228
43f34e8b 229 Int_t j;
f901045b 230 for(j=0; j<fNhits; j++){
2e6fc82a 231 // If hits are equal (same track, same volume), sum them.
f901045b 232 curprimquad = (AliZDCHit*) lhits[j];
233 if(*curprimquad == *newquad){
234 *curprimquad = *curprimquad+*newquad;
235 delete newquad;
68ca986e 236 return;
f901045b 237 }
238 }
f901045b 239
240 //Otherwise create a new hit
241 new(lhits[fNhits]) AliZDCHit(newquad);
242 fNhits++;
243
866ab5a2 244 delete newquad;
cefa66cb 245}
246
866ab5a2 247//_____________________________________________________________________________
359cdddc 248void AliZDC::AddDigit(Int_t *sect, Int_t digit)
f901045b 249{
359cdddc 250//
251 AliZDCDigit *newdigit;
252 newdigit = new AliZDCDigit(sect, digit);
253
254// AliZDCDigit *curdigit;
255// TClonesArray &ldigits = *fDigits;
256//
257// Int_t j;
258// for(j=0; j<fNdigits; j++){
259// curdigit = (AliZDCDigit*) ldigits[j];
260// if(*curdigit == *newdigit){
261// *curdigit = *curdigit+*newdigit;
262// delete newdigit;
263// return;
264// }
265// }
266//
267
268// printf("\n AddDigit -> sector[0] = %d, sector[1] = %d, digit = %d",
269// sect[0], sect[1], digit);
270 new((*fDigits)[fNdigits]) AliZDCDigit(*newdigit);
271 fNdigits++;
272 delete newdigit;
f901045b 273}
359cdddc 274
fe4da5cc 275//_____________________________________________________________________________
276void AliZDC::BuildGeometry()
277{
278 //
279 // Build the ROOT TNode geometry for event display
280 // in the Zero Degree Calorimeter
281 // This routine is dummy for the moment
282 //
283
68ca986e 284 TNode *node, *top;
285 TBRIK *brik;
359cdddc 286 const int kColorZDC = kBlue;
fe4da5cc 287
288 //
68ca986e 289 top=gAlice->GetGeometry()->GetNode("alice");
fe4da5cc 290
291 // ZDC
fe4da5cc 292 brik = new TBRIK("S_ZDC","ZDC box","void",300,300,5);
68ca986e 293 top->cd();
294 node = new TNode("ZDC","ZDC","S_ZDC",0,0,600,"");
295 node->SetLineColor(kColorZDC);
296 fNodes->Add(node);
fe4da5cc 297}
298
299//_____________________________________________________________________________
300Int_t AliZDC::DistancetoPrimitive(Int_t , Int_t )
301{
302 //
303 // Distance from the mouse to the Zero Degree Calorimeter
304 // Dummy routine
305 //
306 return 9999;
307}
359cdddc 308
309//____________________________________________________________________________
310Float_t AliZDC::ZMin(void) const
311{
312 // Minimum dimension of the ZDC module in z
313 return 11600.;
314}
315
316//____________________________________________________________________________
317Float_t AliZDC::ZMax(void) const
318{
319 // Maximum dimension of the ZDC module in z
320 return 11750.;
321}
322
323
fe4da5cc 324//_____________________________________________________________________________
359cdddc 325 void AliZDC::MakeBranch(Option_t *opt, const char *file)
fe4da5cc 326{
327 //
359cdddc 328 // Create Tree branches for the ZDC
fe4da5cc 329 //
359cdddc 330
331 char branchname[10];
332 sprintf(branchname,"%s",GetName());
333
334 AliDetector::MakeBranch(opt);
335
336 const char *cS = strstr(opt,"S");
337
338 if (gAlice->TreeS() && cS) {
b6d27557 339 if(fMergedHits!=0) fMergedHits->Clear();
340 else fMergedHits = new TClonesArray ("AliZDCMergedHit",1000);
359cdddc 341 MakeBranchInTree(gAlice->TreeS(),
b6d27557 342 branchname, &fMergedHits, fBufferSize, file) ;
359cdddc 343 printf("* AliZDC::MakeBranch * Making Branch %s for SDigits\n\n",branchname);
344 }
345
346
347 const char *cD = strstr(opt,"D");
348
349 if (gAlice->TreeD() && cD) {
350 if(fDigits!=0) fDigits->Clear();
351 else fDigits = new TClonesArray ("AliZDCDigit",1000);
352 MakeBranchInTree(gAlice->TreeD(),
353 branchname, &fDigits, fBufferSize, file) ;
354 printf("* AliZDC::MakeBranch * Making Branch %s for Digits\n\n",branchname);
355 }
356
357
358 const char *cR = strstr(opt,"R");
359
360 if (gAlice->TreeR() && cR) {
361 MakeBranchInTree(gAlice->TreeR(),
362 branchname, &fRecPoints, fBufferSize, file) ;
363 printf("* AliZDC::MakeBranch * Making Branch %s for RecPoints\n\n",branchname); }
364
fe4da5cc 365}
359cdddc 366
367//_____________________________________________________________________________
b6d27557 368 void AliZDC::MakeBranchInTreeSD(TTree *treeSD, const char *file)
369{
370 // MakeBranchInTree
371 const Int_t kBufferSize = 4000;
372 char branchname[20];
373 sprintf(branchname,"%s",GetName());
374 MakeBranchInTree(treeSD, branchname, &fMergedHits, kBufferSize, file) ;
375 printf("* AliZDC::MakeBranch * Making Branch %s for SDigits\n\n",branchname);
376
377}
378//_____________________________________________________________________________
379 void AliZDC::MakeBranchInTreeD(TTree *treeD, const char *file)
359cdddc 380{
b6d27557 381 // MakeBranchInTree
382 const Int_t kBufferSize = 4000;
383 char branchname[20];
384 sprintf(branchname,"%s",GetName());
385 MakeBranchInTree(treeD, branchname, &fDigits, kBufferSize, file) ;
386 printf("* AliZDC::MakeBranch * Making Branch %s for Digits\n\n",branchname);
359cdddc 387
b6d27557 388}
389//_____________________________________________________________________________
390void AliZDC::Hits2SDigits()
391{
1acbaaa8 392// printf("\n Entering AliZDC::SDigits2Digits()\n");
b6d27557 393
394 //----------------------------------------------------------------
359cdddc 395 if(!fMerger){
1acbaaa8 396// printf("\n ZDC digitization (without merging)\n");
b6d27557 397
398 AliZDCMergedHit *MHit;
399 Int_t j, sector[2];
400 Float_t MHits[7];
401 fNMergedhits = 0;
402
359cdddc 403 TTree *treeH = gAlice->TreeH();
404 Int_t ntracks = (Int_t) treeH->GetEntries();
359cdddc 405 gAlice->ResetHits();
406
407 // Tracks loop
408 for(Int_t itrack=0; itrack<ntracks; itrack++){
409 treeH->GetEvent(itrack);
359cdddc 410 for(AliZDCHit* zdcHit=(AliZDCHit*)this->FirstHit(-1); zdcHit;
b6d27557 411 zdcHit = (AliZDCHit*)this->NextHit()){
412
413 for(j=0; j<2; j++) sector[j] = zdcHit->GetVolume(j);
414 MHits[0] = zdcHit->GetPrimKinEn();
415 MHits[1] = zdcHit->GetXImpact();
416 MHits[2] = zdcHit->GetYImpact();
417 MHits[3] = zdcHit->GetSFlag();
418 MHits[4] = zdcHit->GetLightPMQ();
419 MHits[5] = zdcHit->GetLightPMC();
420 MHits[6] = zdcHit->GetEnergy();
421 }//Hits loop
422
423 MHit = new AliZDCMergedHit(sector, MHits);
424 new((*fMergedHits)[fNMergedhits]) AliZDCMergedHit(*MHit);
425 TClonesArray &sdigits = *fMergedHits;
426 new (sdigits[fNMergedhits]) AliZDCMergedHit(*MHit);
427 fNMergedhits++;
428 delete MHit;
359cdddc 429 }
1acbaaa8 430// printf("\n ### Filling SDigits tree\n");
359cdddc 431 gAlice->TreeS()->Fill();
432 gAlice->TreeS()->Write(0,TObject::kOverwrite);
433 gAlice->TreeS()->Reset();
434 }
b6d27557 435 //----------------------------------------------------------------
436 else if(fMerger){
1acbaaa8 437// printf("\n ZDC merging and digitization\n");
b6d27557 438 // ### Initialise merging
439 fMerger -> InitMerging();
440
441 TFile *bgrFile = fMerger->BgrFile();
442 bgrFile->cd();
443 // SDigits tree
444 Int_t fNEvBgr = fMerger->EvNum();
445 char treeSDBgrName[20];
446 sprintf(treeSDBgrName,"TreeS%d",fNEvBgr);
447 fTreeSD = (TTree*)gDirectory->Get(treeSDBgrName); // TreeH
448 if(!fTreeSD){
449 printf("\n ERROR -> Can't find TreeS%d in background file\n",fNEvBgr);
450 }
451 // Branch address
452 TBranch *branchSD;
453 char branchSDname[20];
454 sprintf(branchSDname,"%s",GetName());
455 if(fTreeSD && fMergedHits){
456// printf("\n fTreeSD!=0 && fMergedHits!=0\n");
457 branchSD = fTreeSD->GetBranch(branchSDname);
458 if(branchSD) branchSD->SetAddress(&fMergedHits);
459 }
460 if(!branchSD) MakeBranchInTreeSD(fTreeSD);
461
462 // ### Get TCA of MergedHits from AliZDCMerger
463 fMergedHits = fMerger->MergedHits();
464 fNMergedhits = fMerger->GetNMhits();
1acbaaa8 465// printf("\n fNMergedhits (from AliZDCMerger) = %d\n", fNMergedhits);
b6d27557 466 AliZDCMergedHit *MHit;
467 TClonesArray &sdigits = *fMergedHits;
468 Int_t imhit;
469 //Merged Hits loop
470 for(imhit=0; imhit<fNMergedhits; imhit++){
471 MHit = (AliZDCMergedHit*) fMergedHits->UncheckedAt(imhit);
472 new (sdigits[imhit]) AliZDCMergedHit(*MHit);
473 }
474
475// printf("\n ### Filling SDigits tree\n");
476 bgrFile->cd();
477 fTreeSD->Fill();
478 fTreeSD->Write(0,TObject::kOverwrite);
479 }
359cdddc 480
481}
482
483//_____________________________________________________________________________
484void AliZDC::SDigits2Digits()
485{
1acbaaa8 486// printf("\n Entering AliZDC::SDigits2Digits()\n");
359cdddc 487 if(!fMerger){ // Only digitization
1acbaaa8 488// printf("\n ZDC digitization (without merging) \n");
359cdddc 489 fMerger = new AliZDCMerger();
b6d27557 490 fMerger->Digitize(fNMergedhits, fMergedHits);
491
492 char hname[30];
493 sprintf(hname,"TreeD%d",gAlice->GetHeader()->GetEvent());
494 gAlice->TreeD()->Fill();
495 gAlice->TreeD()->Write(0,TObject::kOverwrite);
496 gAlice->TreeD()->Reset();
359cdddc 497 }
b6d27557 498 else if(fMerger){ // Merging and digitization
1acbaaa8 499// printf("\n ZDC merging and digitization\n");
b6d27557 500 fMerger->Digitize(fNMergedhits, fMergedHits);
501
502 TFile *bgrFile = fMerger->BgrFile();
503 bgrFile->cd();
504 // Digits tree
505 Int_t fNEvBgr = fMerger->EvNum();
506 char treeDBgrName[20];
507 sprintf(treeDBgrName,"TreeD%d",fNEvBgr);
508 fTreeMD = (TTree*)gDirectory->Get(treeDBgrName); // TreeH
509 if(!fTreeMD){
510 printf("\n ERROR -> Can't find TreeD%d in background file\n",fNEvBgr);
511 }
512 // Branch address
513 TBranch *branchD;
514 char branchDname[20];
515 sprintf(branchDname,"%s",GetName());
516 if(fTreeMD && fDigits){
1acbaaa8 517// printf("\n fTreeMD!=0 && fDigits!=0\n");
b6d27557 518 branchD = fTreeMD->GetBranch(branchDname);
519 if(branchD) branchD->SetAddress(&fDigits);
520 }
521 if(!branchD) MakeBranchInTreeD(fTreeMD);
522
523// printf("\n ### Filling Digits tree\n");
524 fTreeMD->Fill();
525 fTreeMD->Write(0,TObject::kOverwrite);
359cdddc 526 }
b6d27557 527
359cdddc 528
529}
530//_____________________________________________________________________________
531void AliZDC::Hits2Digits()
532{
533 gAlice->Hits2SDigits();
534 gAlice->SDigits2Digits();
535}
536
537//_____________________________________________________________________________
538void AliZDC::Digits2Reco()
539{
540
541}
542
543
544//_____________________________________________________________________________
545void AliZDC::SetMerger(AliZDCMerger* merger)
546{
547// Set pointer to merger
548 fMerger = merger;
549}
550
551//_____________________________________________________________________________
552AliZDCMerger* AliZDC::Merger()
553{
554// Return pointer to merger
555 return fMerger;
556}
557