1 /**************************************************************************
2 * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
4 * Author: The ALICE Off-line Project. *
5 * Contributors are mentioned in the code where appropriate. *
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 **************************************************************************/
18 Revision 1.26 2001/10/04 14:30:28 coppedis
21 Revision 1.25 2001/10/04 14:24:15 coppedis
24 Revision 1.24 2001/09/26 16:03:41 coppedis
27 Revision 1.23 2001/05/15 13:44:57 coppedis
28 Changes in AddHit method
30 Revision 1.22 2001/05/14 09:53:32 coppedis
31 Adding functions ZMin and ZMax
33 Revision 1.21 2001/04/20 10:05:02 coppedis
36 Revision 1.20 2001/03/26 13:39:20 coppedis
39 Revision 1.19 2001/03/26 09:10:23 coppedis
40 Corrected bug in constructor (fIshunt has to be =1)
42 Revision 1.18 2001/03/20 08:21:55 coppedis
43 ZDC needs PIPE, ABSO, DIPO and SHIL
45 Revision 1.17 2001/03/16 16:18:03 coppedis
46 Correction for superposition of ZDC volumes with MUON arm one
48 Revision 1.16 2001/03/15 16:01:11 coppedis
51 Revision 1.15 2001/01/26 19:56:27 hristov
52 Major upgrade of AliRoot code
54 Revision 1.14 2000/12/12 13:17:01 coppedis
55 Minor corrections suggested by P. Hristov
57 Revision 1.12 2000/12/01 08:19:01 coppedis
58 Adding a message error if ZDC is constructed without DIPO
60 Revision 1.11 2000/11/30 17:21:03 coppedis
61 Introduce hit array fStHits reset only at the end of the event (for digitization)
63 Revision 1.10 2000/11/22 11:32:58 coppedis
66 Revision 1.9 2000/10/02 21:28:20 fca
67 Removal of useless dependecies via forward declarations
69 Revision 1.8 2000/07/10 13:58:01 fca
70 New version of ZDC from E.Scomparin & C.Oppedisano
72 Revision 1.7 2000/01/19 17:17:40 fca
74 Revision 1.6 1999/09/29 09:24:35 fca
75 Introduction of the Copyright and cvs Log
79 ///////////////////////////////////////////////////////////////////////////////
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 //
86 ///////////////////////////////////////////////////////////////////////////////
94 #include <TGeometry.h>
98 // --- AliRoot header files
100 #include "AliZDCHit.h"
101 #include "AliZDCMergedHit.h"
102 #include "AliZDCDigit.h"
103 #include "AliZDCMerger.h"
104 #include "AliDetector.h"
105 #include "AliCallf77.h"
106 #include "AliConst.h"
109 #include "AliHeader.h"
114 //_____________________________________________________________________________
118 // Default constructor for the Zero Degree Calorimeter base class
140 //_____________________________________________________________________________
141 AliZDC::AliZDC(const char *name, const char *title)
142 : AliDetector(name,title)
145 // Standard constructor for the Zero Degree Calorimeter base class
152 // Allocate the hits array
153 fHits = new TClonesArray("AliZDCHit",1000);
154 gAlice->AddHitList(fHits);
155 // Allocate the merged hits array
156 fMergedHits = new TClonesArray("AliZDCMergedHit",1000);
158 // Allocate the digits array
159 fDigits = new TClonesArray("AliZDCDigit",1000);
168 //____________________________________________________________________________
177 if(fMerger) delete fMerger;
185 // fDigits->Delete();
190 //_____________________________________________________________________________
191 void AliZDC::AddHit(Int_t track, Int_t *vol, Float_t *hits)
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
201 static Float_t primKinEn, xImpact, yImpact, sFlag;
203 AliZDCHit *newquad, *curprimquad;
204 newquad = new AliZDCHit(fIshunt, track, vol, hits);
205 TClonesArray &lhits = *fHits;
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
213 else if(track == primary){
214 newquad->fSFlag = 0; // PRIMARY particle entering the ZDC
216 // fNPrimaryHits += 1;
217 sFlag = newquad->fSFlag;
218 primKinEn = newquad->fPrimKinEn;
219 xImpact = newquad->fXImpact;
220 yImpact = newquad->fYImpact;
223 newquad->fPrimKinEn = primKinEn;
224 newquad->fXImpact = xImpact;
225 newquad->fYImpact = yImpact;
226 newquad->fSFlag = sFlag;
230 for(j=0; j<fNhits; j++){
231 // If hits are equal (same track, same volume), sum them.
232 curprimquad = (AliZDCHit*) lhits[j];
233 if(*curprimquad == *newquad){
234 *curprimquad = *curprimquad+*newquad;
240 //Otherwise create a new hit
241 new(lhits[fNhits]) AliZDCHit(newquad);
247 //_____________________________________________________________________________
248 void AliZDC::AddDigit(Int_t *sect, Int_t digit)
251 AliZDCDigit *newdigit;
252 newdigit = new AliZDCDigit(sect, digit);
254 // AliZDCDigit *curdigit;
255 // TClonesArray &ldigits = *fDigits;
258 // for(j=0; j<fNdigits; j++){
259 // curdigit = (AliZDCDigit*) ldigits[j];
260 // if(*curdigit == *newdigit){
261 // *curdigit = *curdigit+*newdigit;
268 // printf("\n AddDigit -> sector[0] = %d, sector[1] = %d, digit = %d",
269 // sect[0], sect[1], digit);
270 new((*fDigits)[fNdigits]) AliZDCDigit(*newdigit);
275 //_____________________________________________________________________________
276 void AliZDC::BuildGeometry()
279 // Build the ROOT TNode geometry for event display
280 // in the Zero Degree Calorimeter
281 // This routine is dummy for the moment
286 const int kColorZDC = kBlue;
289 top=gAlice->GetGeometry()->GetNode("alice");
292 brik = new TBRIK("S_ZDC","ZDC box","void",300,300,5);
294 node = new TNode("ZDC","ZDC","S_ZDC",0,0,600,"");
295 node->SetLineColor(kColorZDC);
299 //_____________________________________________________________________________
300 Int_t AliZDC::DistancetoPrimitive(Int_t , Int_t )
303 // Distance from the mouse to the Zero Degree Calorimeter
309 //____________________________________________________________________________
310 Float_t AliZDC::ZMin(void) const
312 // Minimum dimension of the ZDC module in z
316 //____________________________________________________________________________
317 Float_t AliZDC::ZMax(void) const
319 // Maximum dimension of the ZDC module in z
324 //_____________________________________________________________________________
325 void AliZDC::MakeBranch(Option_t *opt, const char *file)
328 // Create Tree branches for the ZDC
332 sprintf(branchname,"%s",GetName());
334 AliDetector::MakeBranch(opt);
336 const char *cS = strstr(opt,"S");
338 if (gAlice->TreeS() && cS) {
339 if(fMergedHits!=0) fMergedHits->Clear();
340 else fMergedHits = new TClonesArray ("AliZDCMergedHit",1000);
341 MakeBranchInTree(gAlice->TreeS(),
342 branchname, &fMergedHits, fBufferSize, file) ;
343 printf("* AliZDC::MakeBranch * Making Branch %s for SDigits\n\n",branchname);
347 const char *cD = strstr(opt,"D");
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);
358 const char *cR = strstr(opt,"R");
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); }
367 //_____________________________________________________________________________
368 void AliZDC::MakeBranchInTreeSD(TTree *treeSD, const char *file)
371 const Int_t kBufferSize = 4000;
373 sprintf(branchname,"%s",GetName());
374 MakeBranchInTree(treeSD, branchname, &fMergedHits, kBufferSize, file) ;
375 printf("* AliZDC::MakeBranch * Making Branch %s for SDigits\n\n",branchname);
378 //_____________________________________________________________________________
379 void AliZDC::MakeBranchInTreeD(TTree *treeD, const char *file)
382 const Int_t kBufferSize = 4000;
384 sprintf(branchname,"%s",GetName());
385 MakeBranchInTree(treeD, branchname, &fDigits, kBufferSize, file) ;
386 printf("* AliZDC::MakeBranch * Making Branch %s for Digits\n\n",branchname);
389 //_____________________________________________________________________________
390 void AliZDC::Hits2SDigits()
392 // printf("\n Entering AliZDC::SDigits2Digits()\n");
394 //----------------------------------------------------------------
396 // printf("\n ZDC digitization (without merging)\n");
398 AliZDCMergedHit *MHit;
403 TTree *treeH = gAlice->TreeH();
404 Int_t ntracks = (Int_t) treeH->GetEntries();
408 for(Int_t itrack=0; itrack<ntracks; itrack++){
409 treeH->GetEvent(itrack);
410 for(AliZDCHit* zdcHit=(AliZDCHit*)this->FirstHit(-1); zdcHit;
411 zdcHit = (AliZDCHit*)this->NextHit()){
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();
423 MHit = new AliZDCMergedHit(sector, MHits);
424 new((*fMergedHits)[fNMergedhits]) AliZDCMergedHit(*MHit);
425 TClonesArray &sdigits = *fMergedHits;
426 new (sdigits[fNMergedhits]) AliZDCMergedHit(*MHit);
430 // printf("\n ### Filling SDigits tree\n");
431 gAlice->TreeS()->Fill();
432 gAlice->TreeS()->Write(0,TObject::kOverwrite);
433 gAlice->TreeS()->Reset();
435 //----------------------------------------------------------------
437 // printf("\n ZDC merging and digitization\n");
438 // ### Initialise merging
439 fMerger -> InitMerging();
441 TFile *bgrFile = fMerger->BgrFile();
444 Int_t fNEvBgr = fMerger->EvNum();
445 char treeSDBgrName[20];
446 sprintf(treeSDBgrName,"TreeS%d",fNEvBgr);
447 fTreeSD = (TTree*)gDirectory->Get(treeSDBgrName); // TreeH
449 printf("\n ERROR -> Can't find TreeS%d in background file\n",fNEvBgr);
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);
460 if(!branchSD) MakeBranchInTreeSD(fTreeSD);
462 // ### Get TCA of MergedHits from AliZDCMerger
463 fMergedHits = fMerger->MergedHits();
464 fNMergedhits = fMerger->GetNMhits();
465 // printf("\n fNMergedhits (from AliZDCMerger) = %d\n", fNMergedhits);
466 AliZDCMergedHit *MHit;
467 TClonesArray &sdigits = *fMergedHits;
470 for(imhit=0; imhit<fNMergedhits; imhit++){
471 MHit = (AliZDCMergedHit*) fMergedHits->UncheckedAt(imhit);
472 new (sdigits[imhit]) AliZDCMergedHit(*MHit);
475 // printf("\n ### Filling SDigits tree\n");
478 fTreeSD->Write(0,TObject::kOverwrite);
483 //_____________________________________________________________________________
484 void AliZDC::SDigits2Digits()
486 // printf("\n Entering AliZDC::SDigits2Digits()\n");
487 if(!fMerger){ // Only digitization
488 // printf("\n ZDC digitization (without merging) \n");
489 fMerger = new AliZDCMerger();
490 fMerger->Digitize(fNMergedhits, fMergedHits);
493 sprintf(hname,"TreeD%d",gAlice->GetHeader()->GetEvent());
494 gAlice->TreeD()->Fill();
495 gAlice->TreeD()->Write(0,TObject::kOverwrite);
496 gAlice->TreeD()->Reset();
498 else if(fMerger){ // Merging and digitization
499 // printf("\n ZDC merging and digitization\n");
500 fMerger->Digitize(fNMergedhits, fMergedHits);
502 TFile *bgrFile = fMerger->BgrFile();
505 Int_t fNEvBgr = fMerger->EvNum();
506 char treeDBgrName[20];
507 sprintf(treeDBgrName,"TreeD%d",fNEvBgr);
508 fTreeMD = (TTree*)gDirectory->Get(treeDBgrName); // TreeH
510 printf("\n ERROR -> Can't find TreeD%d in background file\n",fNEvBgr);
514 char branchDname[20];
515 sprintf(branchDname,"%s",GetName());
516 if(fTreeMD && fDigits){
517 // printf("\n fTreeMD!=0 && fDigits!=0\n");
518 branchD = fTreeMD->GetBranch(branchDname);
519 if(branchD) branchD->SetAddress(&fDigits);
521 if(!branchD) MakeBranchInTreeD(fTreeMD);
523 // printf("\n ### Filling Digits tree\n");
525 fTreeMD->Write(0,TObject::kOverwrite);
530 //_____________________________________________________________________________
531 void AliZDC::Hits2Digits()
533 gAlice->Hits2SDigits();
534 gAlice->SDigits2Digits();
537 //_____________________________________________________________________________
538 void AliZDC::Digits2Reco()
544 //_____________________________________________________________________________
545 void AliZDC::SetMerger(AliZDCMerger* merger)
547 // Set pointer to merger
551 //_____________________________________________________________________________
552 AliZDCMerger* AliZDC::Merger()
554 // Return pointer to merger