]> git.uio.no Git - u/mrichter/AliRoot.git/blob - ZDC/AliZDC.cxx
Minor corrections
[u/mrichter/AliRoot.git] / ZDC / AliZDC.cxx
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$
18 Revision 1.26  2001/10/04 14:30:28  coppedis
19 Event merging for ZDC
20
21 Revision 1.25  2001/10/04 14:24:15  coppedis
22 Event merging for ZDC
23
24 Revision 1.24  2001/09/26 16:03:41  coppedis
25 Merging implemented
26
27 Revision 1.23  2001/05/15 13:44:57  coppedis
28 Changes in AddHit method
29
30 Revision 1.22  2001/05/14 09:53:32  coppedis
31 Adding functions ZMin and ZMax
32
33 Revision 1.21  2001/04/20 10:05:02  coppedis
34 Minor changes
35
36 Revision 1.20  2001/03/26 13:39:20  coppedis
37 Comment prints
38
39 Revision 1.19  2001/03/26 09:10:23  coppedis
40 Corrected bug in constructor (fIshunt has to be =1)
41
42 Revision 1.18  2001/03/20 08:21:55  coppedis
43 ZDC needs PIPE, ABSO, DIPO and SHIL
44
45 Revision 1.17  2001/03/16 16:18:03  coppedis
46 Correction for superposition of ZDC volumes with MUON arm one
47
48 Revision 1.16  2001/03/15 16:01:11  coppedis
49 Code review
50
51 Revision 1.15  2001/01/26 19:56:27  hristov
52 Major upgrade of AliRoot code
53
54 Revision 1.14  2000/12/12 13:17:01  coppedis
55 Minor corrections suggested by P. Hristov
56
57 Revision 1.12  2000/12/01 08:19:01  coppedis
58 Adding a message error if ZDC is constructed without DIPO
59
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)
62
63 Revision 1.10  2000/11/22 11:32:58  coppedis
64 Major code revision
65
66 Revision 1.9  2000/10/02 21:28:20  fca
67 Removal of useless dependecies via forward declarations
68
69 Revision 1.8  2000/07/10 13:58:01  fca
70 New version of ZDC from E.Scomparin & C.Oppedisano
71
72 Revision 1.7  2000/01/19 17:17:40  fca
73
74 Revision 1.6  1999/09/29 09:24:35  fca
75 Introduction of the Copyright and cvs Log
76
77 */
78
79 ///////////////////////////////////////////////////////////////////////////////
80 //                                                                           //
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                     //
85 //                                                                           //
86 ///////////////////////////////////////////////////////////////////////////////
87
88 #include <stdlib.h>
89 #include <iostream.h>
90
91 // --- ROOT system
92 #include <TBRIK.h>
93 #include <TNode.h>
94 #include <TGeometry.h>
95 #include <TFile.h>
96 #include <TTree.h>
97
98 // --- AliRoot header files
99 #include "AliZDC.h"
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"
107 #include "AliMC.h"
108 #include "AliRun.h"
109 #include "AliHeader.h"
110
111  
112 ClassImp(AliZDC)
113  
114 //_____________________________________________________________________________
115 AliZDC::AliZDC()
116 {
117   //
118   // Default constructor for the Zero Degree Calorimeter base class
119   //
120   
121   fIshunt   = 1;
122   fNoShower = 0;
123   fMerger   = 0;
124
125   fHits     = 0;
126   fNhits    = 0;
127
128   fDigits   = 0;
129   fNdigits  = 0;
130
131   fMergedHits = 0;
132   fTreeSD = 0;
133   fTreeMD = 0;
134
135   fNRecPoints = 0;
136   fRecPoints = 0;
137   
138 }
139  
140 //_____________________________________________________________________________
141 AliZDC::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
148   fIshunt   = 1;
149   fNoShower = 0;
150   fMerger   = 0;
151
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);
157
158   // Allocate the digits array  
159   fDigits = new TClonesArray("AliZDCDigit",1000);
160   
161   fTreeSD = 0;
162   fTreeMD = 0;
163
164   fNRecPoints = 0;
165   fRecPoints = 0;
166
167 }
168 //____________________________________________________________________________ 
169 AliZDC::~AliZDC()
170 {
171   //
172   // ZDC destructor
173   //
174
175   fIshunt   = 0;
176   
177   if(fMerger) delete fMerger;
178
179 //  if(fHits){
180 //    fHits->Delete();
181 //    delete fHits;
182 //  }
183
184 //  if(fDigits){
185 //    fDigits->Delete();
186 //    delete fDigits;
187 //  }
188
189 }
190 //_____________________________________________________________________________
191 void AliZDC::AddHit(Int_t track, Int_t *vol, Float_t *hits)
192 {
193   //
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
199   //
200   
201   static Float_t primKinEn, xImpact, yImpact, sFlag;
202
203   AliZDCHit *newquad, *curprimquad;
204   newquad = new AliZDCHit(fIshunt, track, vol, hits);
205   TClonesArray &lhits = *fHits;
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  
229   Int_t j;
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;
235         delete newquad;
236         return;
237      } 
238   }
239
240     //Otherwise create a new hit
241     new(lhits[fNhits]) AliZDCHit(newquad);
242     fNhits++;
243     
244     delete newquad;
245 }
246
247 //_____________________________________________________________________________
248 void  AliZDC::AddDigit(Int_t *sect, Int_t digit)
249 {
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;
273 }
274       
275 //_____________________________________________________________________________
276 void 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
284   TNode *node, *top;
285   TBRIK *brik;
286   const int kColorZDC  = kBlue;
287   
288   //
289   top=gAlice->GetGeometry()->GetNode("alice");
290   
291   // ZDC
292     brik = new TBRIK("S_ZDC","ZDC box","void",300,300,5);
293     top->cd();
294     node = new TNode("ZDC","ZDC","S_ZDC",0,0,600,"");
295     node->SetLineColor(kColorZDC);
296     fNodes->Add(node);
297 }
298
299 //_____________________________________________________________________________
300 Int_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 }
308
309 //____________________________________________________________________________
310 Float_t AliZDC::ZMin(void) const
311 {
312   // Minimum dimension of the ZDC module in z
313   return 11600.;
314 }
315
316 //____________________________________________________________________________
317 Float_t AliZDC::ZMax(void) const
318 {
319   // Maximum dimension of the ZDC module in z
320   return  11750.;
321 }
322   
323
324 //_____________________________________________________________________________
325  void AliZDC::MakeBranch(Option_t *opt, const char *file)
326 {
327   //
328   // Create Tree branches for the ZDC
329   //
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) {
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);
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           
365 }
366
367 //_____________________________________________________________________________
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)
380 {
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);
387
388 }
389 //_____________________________________________________________________________
390 void AliZDC::Hits2SDigits()
391 {
392 //  printf("\n  Entering AliZDC::SDigits2Digits()\n");
393   
394   //----------------------------------------------------------------
395   if(!fMerger){ 
396 //    printf("\n        ZDC digitization (without merging)\n");
397
398     AliZDCMergedHit *MHit;
399     Int_t j, sector[2];
400     Float_t MHits[7];
401     fNMergedhits = 0;
402
403     TTree *treeH = gAlice->TreeH();
404     Int_t ntracks = (Int_t) treeH->GetEntries();
405     gAlice->ResetHits();
406   
407     // Tracks loop
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()){ 
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;
429     }
430 //    printf("\n        ### Filling SDigits tree\n");
431     gAlice->TreeS()->Fill();
432     gAlice->TreeS()->Write(0,TObject::kOverwrite);  
433     gAlice->TreeS()->Reset();  
434   }
435   //----------------------------------------------------------------
436   else if(fMerger){
437 //    printf("\n         ZDC merging and digitization\n");
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();
465 //    printf("\n         fNMergedhits (from AliZDCMerger) = %d\n", fNMergedhits);   
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   }
480   
481 }
482
483 //_____________________________________________________________________________
484 void AliZDC::SDigits2Digits()
485 {
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);
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();  
497   }
498   else if(fMerger){     // Merging and digitization
499 //    printf("\n        ZDC merging and digitization\n");
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){
517 //      printf("\n      fTreeMD!=0 && fDigits!=0\n");
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);
526   }
527   
528   
529 }
530 //_____________________________________________________________________________
531 void AliZDC::Hits2Digits()
532 {
533     gAlice->Hits2SDigits();
534     gAlice->SDigits2Digits();
535 }
536
537 //_____________________________________________________________________________
538 void AliZDC::Digits2Reco()
539 {
540     
541 }
542
543  
544 //_____________________________________________________________________________
545 void   AliZDC::SetMerger(AliZDCMerger* merger)
546 {
547 // Set pointer to merger 
548     fMerger = merger;
549 }
550
551 //_____________________________________________________________________________
552 AliZDCMerger*  AliZDC::Merger()
553 {
554 // Return pointer to merger
555     return fMerger;
556 }
557