Optimisation for Geant3
[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$
92e95964 18Revision 1.28 2002/02/04 09:18:08 coppedis
19Merging and reconstruction code review
20
1450a7cd 21Revision 1.26.2.2 2001/11/12 18:41:44 hristov
22All the changes from the head are merged to the release
23
24Revision 1.27 2001/10/21 18:27:45 hristov
25Several pointers were set to zero in the default constructors to avoid memory management problems
26
2685bf00 27Revision 1.26 2001/10/04 14:30:28 coppedis
28Event merging for ZDC
29
1acbaaa8 30Revision 1.25 2001/10/04 14:24:15 coppedis
31Event merging for ZDC
32
b6d27557 33Revision 1.24 2001/09/26 16:03:41 coppedis
34Merging implemented
35
359cdddc 36Revision 1.23 2001/05/15 13:44:57 coppedis
37Changes in AddHit method
38
43f34e8b 39Revision 1.22 2001/05/14 09:53:32 coppedis
40Adding functions ZMin and ZMax
41
cefa66cb 42Revision 1.21 2001/04/20 10:05:02 coppedis
43Minor changes
44
0d2bb33c 45Revision 1.20 2001/03/26 13:39:20 coppedis
46Comment prints
47
4c38d2da 48Revision 1.19 2001/03/26 09:10:23 coppedis
49Corrected bug in constructor (fIshunt has to be =1)
50
2e6fc82a 51Revision 1.18 2001/03/20 08:21:55 coppedis
52ZDC needs PIPE, ABSO, DIPO and SHIL
53
ec71d094 54Revision 1.17 2001/03/16 16:18:03 coppedis
55Correction for superposition of ZDC volumes with MUON arm one
56
0014adbc 57Revision 1.16 2001/03/15 16:01:11 coppedis
58Code review
59
09630792 60Revision 1.15 2001/01/26 19:56:27 hristov
61Major upgrade of AliRoot code
62
2ab0c725 63Revision 1.14 2000/12/12 13:17:01 coppedis
64Minor corrections suggested by P. Hristov
65
65d4f2be 66Revision 1.12 2000/12/01 08:19:01 coppedis
67Adding a message error if ZDC is constructed without DIPO
68
588ed15d 69Revision 1.11 2000/11/30 17:21:03 coppedis
70Introduce hit array fStHits reset only at the end of the event (for digitization)
71
f901045b 72Revision 1.10 2000/11/22 11:32:58 coppedis
73Major code revision
74
866ab5a2 75Revision 1.9 2000/10/02 21:28:20 fca
76Removal of useless dependecies via forward declarations
77
94de3818 78Revision 1.8 2000/07/10 13:58:01 fca
79New version of ZDC from E.Scomparin & C.Oppedisano
80
68ca986e 81Revision 1.7 2000/01/19 17:17:40 fca
82
1cedd08a 83Revision 1.6 1999/09/29 09:24:35 fca
84Introduction of the Copyright and cvs Log
85
4c039060 86*/
87
fe4da5cc 88///////////////////////////////////////////////////////////////////////////////
89// //
359cdddc 90// Zero Degree Calorimeter //
91// This class contains the basic functions for the ZDCs; //
92// functions specific to one particular geometry are //
93// contained in the derived classes //
fe4da5cc 94// //
fe4da5cc 95///////////////////////////////////////////////////////////////////////////////
96
65a824a5 97#include <stdlib.h>
359cdddc 98#include <iostream.h>
65a824a5 99
f901045b 100// --- ROOT system
fe4da5cc 101#include <TBRIK.h>
102#include <TNode.h>
2ab0c725 103#include <TGeometry.h>
104#include <TFile.h>
105#include <TTree.h>
1450a7cd 106#include <TDirectory.h>
107#include <TF1.h>
fe4da5cc 108
f901045b 109// --- AliRoot header files
fe4da5cc 110#include "AliZDC.h"
f901045b 111#include "AliZDCHit.h"
b6d27557 112#include "AliZDCMergedHit.h"
359cdddc 113#include "AliZDCMerger.h"
1450a7cd 114#include "AliZDCDigit.h"
115#include "AliZDCReco.h"
f901045b 116#include "AliDetector.h"
fe4da5cc 117#include "AliCallf77.h"
118#include "AliConst.h"
119#include "AliMC.h"
359cdddc 120#include "AliRun.h"
121#include "AliHeader.h"
fe4da5cc 122
fe4da5cc 123
124ClassImp(AliZDC)
125
126//_____________________________________________________________________________
127AliZDC::AliZDC()
128{
129 //
130 // Default constructor for the Zero Degree Calorimeter base class
131 //
2e6fc82a 132
1450a7cd 133 fIshunt = 1;
134 fNoShower = 0;
92e95964 135 fMerger = new AliZDCMerger();
09630792 136
1450a7cd 137 fHits = 0;
138 fNhits = 0;
09630792 139
1450a7cd 140 fDigits = 0;
141 fNdigits = 0;
2685bf00 142
143 fMergedHits = 0;
1450a7cd 144 fTreeSD = 0;
145 fTreeMD = 0;
2685bf00 146
147 fNRecPoints = 0;
1450a7cd 148 fRecPoints = 0;
359cdddc 149
fe4da5cc 150}
151
152//_____________________________________________________________________________
153AliZDC::AliZDC(const char *name, const char *title)
154 : AliDetector(name,title)
155{
156 //
157 // Standard constructor for the Zero Degree Calorimeter base class
158 //
159
359cdddc 160 fIshunt = 1;
161 fNoShower = 0;
162 fMerger = 0;
f901045b 163
359cdddc 164 // Allocate the hits array
f901045b 165 fHits = new TClonesArray("AliZDCHit",1000);
1cedd08a 166 gAlice->AddHitList(fHits);
b6d27557 167 // Allocate the merged hits array
168 fMergedHits = new TClonesArray("AliZDCMergedHit",1000);
f901045b 169
359cdddc 170 // Allocate the digits array
171 fDigits = new TClonesArray("AliZDCDigit",1000);
172
2685bf00 173 fTreeSD = 0;
174 fTreeMD = 0;
175
176 fNRecPoints = 0;
1450a7cd 177 fRecPoints = 0;
866ab5a2 178
179}
180//____________________________________________________________________________
181AliZDC::~AliZDC()
182{
183 //
184 // ZDC destructor
185 //
186
187 fIshunt = 0;
359cdddc 188
b6d27557 189 if(fMerger) delete fMerger;
2e6fc82a 190
359cdddc 191// if(fHits){
192// fHits->Delete();
193// delete fHits;
65d4f2be 194// }
359cdddc 195
196// if(fDigits){
197// fDigits->Delete();
198// delete fDigits;
199// }
200
fe4da5cc 201}
fe4da5cc 202//_____________________________________________________________________________
203void AliZDC::AddHit(Int_t track, Int_t *vol, Float_t *hits)
204{
205 //
f901045b 206 // Add a ZDC hit to the hit list.
207 // -> We make use of 2 array of hits:
208 // [1] fHits (the usual one) that contains hits for each PRIMARY
209 // [2] fStHits that contains hits for each EVENT and is used to
210 // obtain digits at the end of each event
fe4da5cc 211 //
f901045b 212
68ca986e 213 static Float_t primKinEn, xImpact, yImpact, sFlag;
214
43f34e8b 215 AliZDCHit *newquad, *curprimquad;
f901045b 216 newquad = new AliZDCHit(fIshunt, track, vol, hits);
65d4f2be 217 TClonesArray &lhits = *fHits;
cefa66cb 218
219 if(fNhits==0){
220 // First hit -> setting flag for primary or secondary particle
221 Int_t primary = gAlice->GetPrimary(track);
222 if(track != primary){
223 newquad->fSFlag = 1; // SECONDARY particle entering the ZDC
224 }
225 else if(track == primary){
226 newquad->fSFlag = 0; // PRIMARY particle entering the ZDC
227 }
228// fNPrimaryHits += 1;
229 sFlag = newquad->fSFlag;
230 primKinEn = newquad->fPrimKinEn;
231 xImpact = newquad->fXImpact;
232 yImpact = newquad->fYImpact;
233 }
234 else{
235 newquad->fPrimKinEn = primKinEn;
236 newquad->fXImpact = xImpact;
237 newquad->fYImpact = yImpact;
238 newquad->fSFlag = sFlag;
239 }
240
43f34e8b 241 Int_t j;
f901045b 242 for(j=0; j<fNhits; j++){
2e6fc82a 243 // If hits are equal (same track, same volume), sum them.
f901045b 244 curprimquad = (AliZDCHit*) lhits[j];
245 if(*curprimquad == *newquad){
246 *curprimquad = *curprimquad+*newquad;
247 delete newquad;
68ca986e 248 return;
f901045b 249 }
250 }
f901045b 251
252 //Otherwise create a new hit
253 new(lhits[fNhits]) AliZDCHit(newquad);
254 fNhits++;
255
866ab5a2 256 delete newquad;
cefa66cb 257}
258
866ab5a2 259//_____________________________________________________________________________
359cdddc 260void AliZDC::AddDigit(Int_t *sect, Int_t digit)
f901045b 261{
359cdddc 262//
263 AliZDCDigit *newdigit;
264 newdigit = new AliZDCDigit(sect, digit);
359cdddc 265
266// printf("\n AddDigit -> sector[0] = %d, sector[1] = %d, digit = %d",
267// sect[0], sect[1], digit);
268 new((*fDigits)[fNdigits]) AliZDCDigit(*newdigit);
269 fNdigits++;
270 delete newdigit;
f901045b 271}
359cdddc 272
fe4da5cc 273//_____________________________________________________________________________
274void AliZDC::BuildGeometry()
275{
276 //
277 // Build the ROOT TNode geometry for event display
278 // in the Zero Degree Calorimeter
279 // This routine is dummy for the moment
280 //
281
68ca986e 282 TNode *node, *top;
283 TBRIK *brik;
359cdddc 284 const int kColorZDC = kBlue;
fe4da5cc 285
286 //
68ca986e 287 top=gAlice->GetGeometry()->GetNode("alice");
fe4da5cc 288
289 // ZDC
fe4da5cc 290 brik = new TBRIK("S_ZDC","ZDC box","void",300,300,5);
68ca986e 291 top->cd();
292 node = new TNode("ZDC","ZDC","S_ZDC",0,0,600,"");
293 node->SetLineColor(kColorZDC);
294 fNodes->Add(node);
fe4da5cc 295}
296
297//_____________________________________________________________________________
298Int_t AliZDC::DistancetoPrimitive(Int_t , Int_t )
299{
300 //
301 // Distance from the mouse to the Zero Degree Calorimeter
302 // Dummy routine
303 //
304 return 9999;
305}
359cdddc 306
307//____________________________________________________________________________
308Float_t AliZDC::ZMin(void) const
309{
310 // Minimum dimension of the ZDC module in z
311 return 11600.;
312}
313
314//____________________________________________________________________________
315Float_t AliZDC::ZMax(void) const
316{
317 // Maximum dimension of the ZDC module in z
318 return 11750.;
319}
320
321
fe4da5cc 322//_____________________________________________________________________________
359cdddc 323 void AliZDC::MakeBranch(Option_t *opt, const char *file)
fe4da5cc 324{
325 //
359cdddc 326 // Create Tree branches for the ZDC
fe4da5cc 327 //
359cdddc 328
329 char branchname[10];
330 sprintf(branchname,"%s",GetName());
331
332 AliDetector::MakeBranch(opt);
333
334 const char *cS = strstr(opt,"S");
335
336 if (gAlice->TreeS() && cS) {
b6d27557 337 if(fMergedHits!=0) fMergedHits->Clear();
338 else fMergedHits = new TClonesArray ("AliZDCMergedHit",1000);
359cdddc 339 MakeBranchInTree(gAlice->TreeS(),
b6d27557 340 branchname, &fMergedHits, fBufferSize, file) ;
359cdddc 341 printf("* AliZDC::MakeBranch * Making Branch %s for SDigits\n\n",branchname);
342 }
343
344
345 const char *cD = strstr(opt,"D");
346
347 if (gAlice->TreeD() && cD) {
348 if(fDigits!=0) fDigits->Clear();
349 else fDigits = new TClonesArray ("AliZDCDigit",1000);
350 MakeBranchInTree(gAlice->TreeD(),
351 branchname, &fDigits, fBufferSize, file) ;
352 printf("* AliZDC::MakeBranch * Making Branch %s for Digits\n\n",branchname);
353 }
354
355
356 const char *cR = strstr(opt,"R");
357
358 if (gAlice->TreeR() && cR) {
359 MakeBranchInTree(gAlice->TreeR(),
360 branchname, &fRecPoints, fBufferSize, file) ;
361 printf("* AliZDC::MakeBranch * Making Branch %s for RecPoints\n\n",branchname); }
362
fe4da5cc 363}
359cdddc 364
365//_____________________________________________________________________________
b6d27557 366 void AliZDC::MakeBranchInTreeSD(TTree *treeSD, const char *file)
367{
368 // MakeBranchInTree
369 const Int_t kBufferSize = 4000;
370 char branchname[20];
371 sprintf(branchname,"%s",GetName());
372 MakeBranchInTree(treeSD, branchname, &fMergedHits, kBufferSize, file) ;
373 printf("* AliZDC::MakeBranch * Making Branch %s for SDigits\n\n",branchname);
374
375}
376//_____________________________________________________________________________
377 void AliZDC::MakeBranchInTreeD(TTree *treeD, const char *file)
359cdddc 378{
b6d27557 379 // MakeBranchInTree
380 const Int_t kBufferSize = 4000;
381 char branchname[20];
382 sprintf(branchname,"%s",GetName());
383 MakeBranchInTree(treeD, branchname, &fDigits, kBufferSize, file) ;
384 printf("* AliZDC::MakeBranch * Making Branch %s for Digits\n\n",branchname);
359cdddc 385
b6d27557 386}
387//_____________________________________________________________________________
1450a7cd 388 void AliZDC::MakeBranchInTreeR(TTree *treeR, const char *file)
389{
390 // MakeBranchInTree
391 const Int_t kBufferSize = 4000;
392 char branchname[20];
393 sprintf(branchname,"%s",GetName());
394 MakeBranchInTree(treeR, branchname, &fRecPoints, kBufferSize, file) ;
395 printf("* AliZDC::MakeBranch * Making Branch %s for RecPoints\n\n",branchname);
396
397}
398//_____________________________________________________________________________
b6d27557 399void AliZDC::Hits2SDigits()
400{
1450a7cd 401 printf("\n Entering AliZDC::SDigits2Digits() ");
b6d27557 402
403 //----------------------------------------------------------------
359cdddc 404 if(!fMerger){
1450a7cd 405 printf(" ZDC digitization (without merging)\n");
b6d27557 406
407 AliZDCMergedHit *MHit;
408 Int_t j, sector[2];
409 Float_t MHits[7];
410 fNMergedhits = 0;
411
359cdddc 412 TTree *treeH = gAlice->TreeH();
413 Int_t ntracks = (Int_t) treeH->GetEntries();
359cdddc 414 gAlice->ResetHits();
415
416 // Tracks loop
417 for(Int_t itrack=0; itrack<ntracks; itrack++){
418 treeH->GetEvent(itrack);
359cdddc 419 for(AliZDCHit* zdcHit=(AliZDCHit*)this->FirstHit(-1); zdcHit;
b6d27557 420 zdcHit = (AliZDCHit*)this->NextHit()){
421
422 for(j=0; j<2; j++) sector[j] = zdcHit->GetVolume(j);
423 MHits[0] = zdcHit->GetPrimKinEn();
424 MHits[1] = zdcHit->GetXImpact();
425 MHits[2] = zdcHit->GetYImpact();
426 MHits[3] = zdcHit->GetSFlag();
427 MHits[4] = zdcHit->GetLightPMQ();
428 MHits[5] = zdcHit->GetLightPMC();
429 MHits[6] = zdcHit->GetEnergy();
430 }//Hits loop
431
432 MHit = new AliZDCMergedHit(sector, MHits);
433 new((*fMergedHits)[fNMergedhits]) AliZDCMergedHit(*MHit);
434 TClonesArray &sdigits = *fMergedHits;
435 new (sdigits[fNMergedhits]) AliZDCMergedHit(*MHit);
436 fNMergedhits++;
437 delete MHit;
359cdddc 438 }
1acbaaa8 439// printf("\n ### Filling SDigits tree\n");
359cdddc 440 gAlice->TreeS()->Fill();
441 gAlice->TreeS()->Write(0,TObject::kOverwrite);
442 gAlice->TreeS()->Reset();
443 }
b6d27557 444 //----------------------------------------------------------------
445 else if(fMerger){
1450a7cd 446 printf(" ZDC merging and digitization\n");
b6d27557 447 // ### Initialise merging
448 fMerger -> InitMerging();
449
92e95964 450 TFile *bgrFile = fMerger->BgrFile();
b6d27557 451 bgrFile->cd();
92e95964 452
b6d27557 453 // SDigits tree
454 Int_t fNEvBgr = fMerger->EvNum();
455 char treeSDBgrName[20];
456 sprintf(treeSDBgrName,"TreeS%d",fNEvBgr);
457 fTreeSD = (TTree*)gDirectory->Get(treeSDBgrName); // TreeH
458 if(!fTreeSD){
459 printf("\n ERROR -> Can't find TreeS%d in background file\n",fNEvBgr);
460 }
461 // Branch address
b6d27557 462 char branchSDname[20];
463 sprintf(branchSDname,"%s",GetName());
464 if(fTreeSD && fMergedHits){
1450a7cd 465 TBranch *branchSD = fTreeSD->GetBranch(branchSDname);
b6d27557 466 if(branchSD) branchSD->SetAddress(&fMergedHits);
1450a7cd 467 else if(!branchSD) MakeBranchInTreeSD(fTreeSD);
b6d27557 468 }
b6d27557 469
470 // ### Get TCA of MergedHits from AliZDCMerger
471 fMergedHits = fMerger->MergedHits();
472 fNMergedhits = fMerger->GetNMhits();
1acbaaa8 473// printf("\n fNMergedhits (from AliZDCMerger) = %d\n", fNMergedhits);
b6d27557 474 AliZDCMergedHit *MHit;
475 TClonesArray &sdigits = *fMergedHits;
476 Int_t imhit;
477 //Merged Hits loop
478 for(imhit=0; imhit<fNMergedhits; imhit++){
479 MHit = (AliZDCMergedHit*) fMergedHits->UncheckedAt(imhit);
480 new (sdigits[imhit]) AliZDCMergedHit(*MHit);
481 }
482
483// printf("\n ### Filling SDigits tree\n");
484 bgrFile->cd();
485 fTreeSD->Fill();
486 fTreeSD->Write(0,TObject::kOverwrite);
487 }
359cdddc 488
489}
490
491//_____________________________________________________________________________
492void AliZDC::SDigits2Digits()
493{
1450a7cd 494 //printf("\n Entering AliZDC::SDigits2Digits() ");
359cdddc 495 if(!fMerger){ // Only digitization
1450a7cd 496 printf(" ZDC digitization (without merging) \n");
359cdddc 497 fMerger = new AliZDCMerger();
b6d27557 498 fMerger->Digitize(fNMergedhits, fMergedHits);
499
500 char hname[30];
501 sprintf(hname,"TreeD%d",gAlice->GetHeader()->GetEvent());
502 gAlice->TreeD()->Fill();
503 gAlice->TreeD()->Write(0,TObject::kOverwrite);
504 gAlice->TreeD()->Reset();
359cdddc 505 }
b6d27557 506 else if(fMerger){ // Merging and digitization
1450a7cd 507 printf(" ZDC merging and digitization\n");
b6d27557 508 fMerger->Digitize(fNMergedhits, fMergedHits);
509
510 TFile *bgrFile = fMerger->BgrFile();
511 bgrFile->cd();
512 // Digits tree
513 Int_t fNEvBgr = fMerger->EvNum();
1450a7cd 514 //printf(" fNEvBgr = %d\n",fNEvBgr);
b6d27557 515 char treeDBgrName[20];
516 sprintf(treeDBgrName,"TreeD%d",fNEvBgr);
517 fTreeMD = (TTree*)gDirectory->Get(treeDBgrName); // TreeH
518 if(!fTreeMD){
519 printf("\n ERROR -> Can't find TreeD%d in background file\n",fNEvBgr);
520 }
521 // Branch address
b6d27557 522 char branchDname[20];
523 sprintf(branchDname,"%s",GetName());
524 if(fTreeMD && fDigits){
1acbaaa8 525// printf("\n fTreeMD!=0 && fDigits!=0\n");
1450a7cd 526 TBranch *branchD = fTreeMD->GetBranch(branchDname);
b6d27557 527 if(branchD) branchD->SetAddress(&fDigits);
1450a7cd 528 else if(!branchD) MakeBranchInTreeD(fTreeMD);
b6d27557 529 }
b6d27557 530
b6d27557 531 fTreeMD->Fill();
532 fTreeMD->Write(0,TObject::kOverwrite);
359cdddc 533 }
b6d27557 534
359cdddc 535
536}
537//_____________________________________________________________________________
538void AliZDC::Hits2Digits()
539{
540 gAlice->Hits2SDigits();
541 gAlice->SDigits2Digits();
542}
543
544//_____________________________________________________________________________
545void AliZDC::Digits2Reco()
546{
1450a7cd 547 //printf("\n Entering AliZDC::Digits2Reco() ");
359cdddc 548
1450a7cd 549 Int_t fNEvBgr = fMerger->EvNum();
550 //printf(" fNEvBgr = %d\n",fNEvBgr);
551 gAlice->GetEvent(fNEvBgr);
552
553 AliDetector *ZDC = gAlice->GetDetector("ZDC");
554 TClonesArray *ZDCdigits = ZDC->Digits();
555
556 char tdname[20];
557 sprintf(tdname,"TreeD%d",fNEvBgr);
558 TTree *TD = (TTree*)gDirectory->Get(tdname);
559 //TTree *TD = gAlice->TreeD();
560 if(TD){
561 //printf(" TreeD found in gAlice object\n");
562 char brname[20];
563 sprintf(brname,"%s",ZDC->GetName());
564 TBranch *br = TD->GetBranch(brname);
565 if(br) br->SetAddress(&ZDCdigits);
566 }
567 else if(!TD) printf(" ERROR -> TreeD NOT found in gAlice object\n");
568
569 Int_t nt = (Int_t) (TD->GetEntries());
570 //printf("\n #entries in TreeD = %d\n",nt);
571 gAlice->ResetDigits();
572
573 AliZDCDigit *dig;
574 Int_t j, idig, ndigits, ZNraw=0, ZPraw=0, ZEMraw=0;
575 // --- Summing raw ADCs for each detector to obtain total light
576 for(j=0; j<nt; j++){
577 TD->GetEvent(j);
578 ndigits = ZDCdigits->GetEntries();
579 //printf("\n Entry #%d, ndigits = %d",j,ndigits);
580 ZNraw=0;
581 ZPraw=0;
582 ZEMraw=0;
583 // --- Loop over event digits
584 for(idig=0; idig<ndigits; idig++){
585 dig = (AliZDCDigit*) ZDCdigits->UncheckedAt(idig);
586 if(dig->GetSector(0) == 1) ZNraw += dig->GetADCValue();
587 else if(dig->GetSector(0) == 2) ZPraw += dig->GetADCValue();
588 else if(dig->GetSector(0) == 3) ZEMraw += dig->GetADCValue();
589 } // Digits loop
590 } // TreeD entries loop
591 printf("\n --- ZNraw = %d, ZPraw = %d, ZEMraw = %d\n",ZNraw, ZPraw, ZEMraw);
592
593 // --- Pedestal subtraction
594 Int_t ZNcorr, ZPcorr, ZEMcorr, MeanPed=50;
595 ZNcorr = ZNraw - 5*MeanPed;
596 ZPcorr = ZPraw - 5*MeanPed;
597 ZEMcorr = ZEMraw - 2*MeanPed;
598 if(ZNcorr<0) ZNcorr=0;
599 if(ZPcorr<0) ZPcorr=0;
600 if(ZEMcorr<0) ZEMcorr=0;
601 printf("\n ZNcorr = %d, ZPcorr = %d, ZEMcorr = %d\n",ZNcorr,ZPcorr,ZEMcorr);
602
603 // --- ADCchannel -> photoelectrons
604 // NB-> PM gain = 10^(5), ADC resolution = 6.4*10^(-7)
605 Float_t ZNphe, ZPphe, ZEMphe, ConvFactor = 0.064;
606 ZNphe = ZNcorr/ConvFactor;
607 ZPphe = ZPcorr/ConvFactor;
608 ZEMphe = ZEMcorr/ConvFactor;
609 printf("\n ZNphe = %f, ZPphe = %f, ZEMphe = %f\n",ZNphe, ZPphe, ZEMphe);
610
611 // --- Energy calibration
612 // Conversion factors for hadronic ZDCs goes from phe yield to TRUE incident
613 // energy (conversion from GeV to TeV is included); while for EM calos
614 // conversion is from light yield to detected energy calculated by GEANT
615 // NB -> ZN and ZP conversion factors are constant since incident spectators
616 // have all the same energy, ZEM energy is obtained through a fit over the whole
617 // range of incident particle energies (obtained with full HIJING simulations)
618 Float_t ZNenergy, ZPenergy, ZEMenergy, ZDCenergy;
619 Float_t ZNphexTeV=329., ZPphexTeV=369.;
620 ZNenergy = ZNphe/ZNphexTeV;
621 ZPenergy = ZPphe/ZPphexTeV;
622 ZDCenergy = ZNenergy+ZPenergy;
623 ZEMenergy = -4.81+0.3238*ZEMphe;
624 if(ZEMenergy<0) ZEMenergy=0;
625 printf(" ZNenergy = %f TeV, ZPenergy = %f TeV, ZDCenergy = %f GeV, "
626 "\n ZEMenergy = %f TeV\n", ZNenergy, ZPenergy,
627 ZDCenergy, ZEMenergy);
628
629 if(ZDCenergy==0)
630 printf("\n\n ### ATTENZIONE!!! -> ev# %d: ZNenergy = %f TeV, ZPenergy = %f TeV, ZDCenergy = %f GeV, "
631 " ZEMenergy = %f TeV\n\n", fNEvBgr, ZNenergy, ZPenergy, ZDCenergy, ZEMenergy);
632
633 // --- Number of incident spectator nucleons
634 Int_t NDetSpecN, NDetSpecP;
635 NDetSpecN = (Int_t) (ZNenergy/2.760);
636 NDetSpecP = (Int_t) (ZPenergy/2.760);
637 printf("\n NDetSpecN = %d, NDetSpecP = %d\n",NDetSpecN, NDetSpecP);
638
639 // --- Number of generated spectator nucleons and impact parameter
92e95964 640 // --------------------------------------------------------------------------------------------------
641 // [1] ### Results in Chiara's PhD thesis -> 0<b<15 fm (Dec 2001)
642 /*// Fit results for neutrons (Nspectator n true vs. EZN)
1450a7cd 643 TF1 *fZNCen = new TF1("fZNCen",
644 "(-2.116909+sqrt(2.116909*2.116909-4*(-0.00651)*(14.556798-x)))/(2*(-0.00651))",0.,158.5);
645 TF1 *fZNPer = new TF1("fZNPer",
646 "(-34.695134-sqrt(34.695134*34.695134-4*(-0.174780)*(-1562.283443-x)))/(2*(-0.174780))",0.,158.5);
647 // Fit results for protons (Nspectator p true vs. EZP)
648 TF1 *fZPCen = new TF1("fZPCen",
649 "(-1.3217+sqrt(1.3217*1.3217-4*(-0.007934)*(4.742873-x)))/(2*(-0.007934))",0.,58.91);
650 TF1 *fZPPer = new TF1("fZPPer",
651 "(-15.788267-sqrt(15.788267*15.788267-4*(-0.133359)*(-383.800673-x)))/(2*(-0.133359))",0.,58.91);
652 // Fit results for total number of spectators (Nspectators true vs. EZDC)
653 TF1 *fZDCCen = new TF1("fZDCCen",
654 "(-1.867335+sqrt(1.867335*1.867335-4*(-0.004119)*(19.100289-x)))/(2*(-0.004119))",0.,220.4);
655 TF1 *fZDCPer = new TF1("fZDCPer",
92e95964 656 "(-22.429097-sqrt(22.429097*22.429097-4*(-0.072435)*(-1482.034526-x)))/(2*(-0.072435))",0.,220.4);*/
657 // --------------------------------------------------------------------------------------------------
658 // [1] ### Results from a new production -> 0<b<18 fm (Apr 2002)
659 // Fit results for neutrons (Nspectator n true vs. EZN)
660 TF1 *fZNCen = new TF1("fZNCen",
661 "(-2.287920+sqrt(2.287920*2.287920-4*(-0.007629)*(11.921710-x)))/(2*(-0.007629))",0.,164.);
662 TF1 *fZNPer = new TF1("fZNPer",
663 "(-37.812280-sqrt(37.812280*37.812280-4*(-0.190932)*(-1709.249672-x)))/(2*(-0.190932))",0.,164.);
664 // Fit results for protons (Nspectator p true vs. EZP)
665 TF1 *fZPCen = new TF1("fZPCen",
666 "(-1.321353+sqrt(1.321353*1.321353-4*(-0.007283)*(3.550697-x)))/(2*(-0.007283))",0.,60.);
667 TF1 *fZPPer = new TF1("fZPPer",
668 "(-42.643308-sqrt(42.643308*42.643308-4*(-0.310786)*(-1402.945615-x)))/(2*(-0.310786))",0.,60.);
669 // Fit results for total number of spectators (Nspectators true vs. EZDC)
670 TF1 *fZDCCen = new TF1("fZDCCen",
671 "(-1.934991+sqrt(1.934991*1.934991-4*(-0.004080)*(15.111124-x)))/(2*(-0.004080))",0.,225.);
672 TF1 *fZDCPer = new TF1("fZDCPer",
673 "(-34.380639-sqrt(34.380639*34.380639-4*(-0.104251)*(-2612.189017-x)))/(2*(-0.104251))",0.,225.);
674 // --------------------------------------------------------------------------------------------------
675 // [1] ### Results in Chiara's PhD thesis -> 0<b<15 fm (Dec 2001)
676 /*// Fit results for b (b vs. EZDC)
1450a7cd 677 //TF1 *fbCen = new TF1("fbCen","0.611543+0.052231*x-0.000112*x*x+0.000000374*x*x*x",0.,222.);
678 //TF1 *fbPer = new TF1("fbPer","16.552010-0.023866*x-0.00001*x*x",0.,222.);
679 TF1 *fbCen = new TF1("fbCen","0.612769+0.051929*x-0.0001074*x*x+0.0000003724*x*x*x",0.,225.);
92e95964 680 TF1 *fbPer = new TF1("fbPer","16.6131016-0.026053*x+0.000006893*x*x",0.,225.);*/
681 // --------------------------------------------------------------------------------------------------
682 // [2] ### Results from a new production -> 0<b<18 fm (Apr 2002)
683 TF1 *fbCen = new TF1("fbCen","-0.056923+0.079703*x-0.0004301*x*x+0.000001366*x*x*x",0.,220.);
684 TF1 *fbPer = new TF1("fbPer","17.943998-0.046846*x+0.000074*x*x",0.,220.);
685 // --------------------------------------------------------------------------------------------------
1450a7cd 686 // Evaluating Nspectators and b from ZEM energy
92e95964 687 // [1] ### Results in Chiara's PhD thesis -> 0<b<15 fm (Dec 2001)
688 /*TF1 *fZEMn = new TF1("fZEMn","124.2-0.0566*x+0.000006014*x*x",0.,3500.);
1450a7cd 689 TF1 *fZEMp = new TF1("fZEMp","81.3-0.03834*x+0.000004359*x*x",0.,3500.);
690 TF1 *fZEMsp = new TF1("fZEMsp","205.6-0.09567*x+0.00001056*x*x",0.,3500.);
92e95964 691 TF1 *fZEMb = new TF1("fZEMb","15.8-0.02084*x+2.802e-5*x*x-2.007e-8*x*x*x+6.586e-12*x*x*x*x-8.042e-16*x*x*x*x*x",0.,3500.);*/
692 // --------------------------------------------------------------------------------------------------
693 // [2] ### Results from a new production -> 0<b<18 fm (Apr 2002)
694 TF1 *fZEMn = new TF1("fZEMn","126.2-0.05399*x+0.000005679*x*x",0.,4000.);
695 TF1 *fZEMp = new TF1("fZEMp","82.49-0.03611*x+0.00000385*x*x",0.,4000.);
696 TF1 *fZEMsp = new TF1("fZEMsp","208.7-0.09006*x+0.000009526*x*x",0.,4000.);
697 TF1 *fZEMb = new TF1("fZEMb","16.06-0.01633*x+1.44e-5*x*x-6.778e-9*x*x*x+1.438e-12*x*x*x*x-1.112e-16*x*x*x*x*x",0.,4000.);
1450a7cd 698
699 Int_t NGenSpecN=0, NGenSpecP=0, NGenSpec=0;
700 Double_t ImpPar=0;
92e95964 701 // Cut value for Ezem (GeV)
702 // [1] ### Results in Chiara's PhD thesis -> 0<b<15 fm (Dec 2001)
703 //Float_t EZEMCut = 360.;
704 // [2] ### Results from a new production -> 0<b<18 fm (Apr 2002)
705 Float_t EZEMCut = 420.;
706 Float_t DeltaEZEMSup = 690.;
707 Float_t DeltaEZEMInf = 270.;
708 if(ZEMenergy > (EZEMCut+DeltaEZEMSup)){
1450a7cd 709 NGenSpecN = (Int_t) (fZNCen->Eval(ZNenergy));
710 NGenSpecP = (Int_t) (fZPCen->Eval(ZPenergy));
711 NGenSpec = (Int_t) (fZDCCen->Eval(ZDCenergy));
712 ImpPar = fbCen->Eval(ZDCenergy);
713 //printf(" fZNCen = %f, fZPCen = %f, fZDCCen = %f\n",fZNCen->Eval(ZNenergy),
714 // fZPCen->Eval(ZPenergy),fZDCCen->Eval(ZDCenergy));
715 }
92e95964 716 else if(ZEMenergy < (EZEMCut-DeltaEZEMInf)){
1450a7cd 717 NGenSpecN = (Int_t) (fZNPer->Eval(ZNenergy));
718 NGenSpecP = (Int_t) (fZPPer->Eval(ZPenergy));
719 NGenSpec = (Int_t) (fZDCPer->Eval(ZDCenergy));
720 ImpPar = fbPer->Eval(ZDCenergy);
721 //printf(" fZNPer = %f, fZPPer = %f, fZDCPer = %f\n",fZNPer->Eval(ZNenergy),
722 // fZPPer->Eval(ZPenergy),fZDCPer->Eval(ZDCenergy));
723 }
92e95964 724 else if(ZEMenergy >= (EZEMCut-DeltaEZEMInf) && ZEMenergy <= (EZEMCut+DeltaEZEMSup)){
725 NGenSpecN = (Int_t) (fZEMn->Eval(ZEMenergy));
726 NGenSpecP = (Int_t) (fZEMp->Eval(ZEMenergy));
727 NGenSpec = (Int_t)(fZEMsp->Eval(ZEMenergy));
728 ImpPar = fZEMb->Eval(ZEMenergy);
729 //printf(" Nspec ZEM = %f, Nspec ZDC = %f\n",fZEMsp->Eval(ZNenergy),fZDCPer->Eval(ZDCenergy));
730 }
731 // [1] ### Results in Chiara's PhD thesis -> 0<b<15 fm (Dec 2001)
732 /*if(ZNenergy>158.5) NGenSpecN = (Int_t) (fZEMn->Eval(ZEMenergy));
1450a7cd 733 if(ZPenergy>58.91) NGenSpecP = (Int_t) (fZEMp->Eval(ZEMenergy));
734 if(ZDCenergy>220.4) NGenSpec = (Int_t)(fZEMsp->Eval(ZEMenergy));
92e95964 735 if(ZDCenergy>225.) ImpPar = fZEMb->Eval(ZEMenergy);*/
736 // [2] ### Results from a new production -> 0<b<18 fm (Apr 2002)
737 if(ZNenergy>162.) NGenSpecN = (Int_t) (fZEMn->Eval(ZEMenergy));
738 if(ZPenergy>59.75) NGenSpecP = (Int_t) (fZEMp->Eval(ZEMenergy));
739 if(ZDCenergy>221.5) NGenSpec = (Int_t)(fZEMsp->Eval(ZEMenergy));
740 if(ZDCenergy>220.) ImpPar = fZEMb->Eval(ZEMenergy);
1450a7cd 741
742 if(NGenSpecN>125) NGenSpecN=125;
743 else if(NGenSpecN<0) NGenSpecN=0;
744 if(NGenSpecP>82) NGenSpecP=82;
745 else if(NGenSpecP<0) NGenSpecP=0;
746 if(NGenSpec>207) NGenSpec=207;
747 else if(NGenSpec<0) NGenSpec=0;
92e95964 748 //printf(" NRecSpecN = %d, NRecSpecP = %d, NRecSpec = %d\n",NGenSpecN,NGenSpecP,NGenSpec);
1450a7cd 749
750 // --- Number of participants
751 Int_t NPart, NPartTot;
92e95964 752 NPart = 207-NGenSpecN-NGenSpecP;
753 NPartTot = 207-NGenSpec;
754 //printf(" ### NPart(ZP+ZN) = %d, NPart(ZDC) = %d, b = %f fm\n",NPart,NPartTot,ImpPar);
755 printf(" ### NPart = %d, b = %f fm\n",NPartTot,ImpPar);
1450a7cd 756
757 // --- Writing RecPoints TCA
758 // Allocate the RecPoints TCA
759 fRecPoints = new TClonesArray("AliZDCReco",1000);
760 AliZDCReco *reco = new AliZDCReco(ZNenergy,ZPenergy,ZDCenergy,ZEMenergy,
761 NDetSpecN,NDetSpecP,NGenSpecN,NGenSpecP,NGenSpec,NPartTot,ImpPar);
762 new((*fRecPoints)[fNRecPoints]) AliZDCReco(*reco);
763 //printf(" fNRecPoints = %d \n",fNRecPoints );
764 //fNRecPoints++;
765 //fRecPoints->Dump();
766 delete reco;
767
768 // TreeR
769 TTree *treeR = gAlice->TreeR();
770 char tname[20];
771 sprintf(tname,"TreeR%d",fNEvBgr);
772 if(!treeR) printf("\n ERROR -> Can't find TreeR%d in background file\n",fNEvBgr);
773 // Branch address
774 char branchRname[20];
775 sprintf(branchRname,"%s",GetName());
776 if(fRecPoints){
777 TBranch *branchR = treeR->GetBranch(branchRname);
778 if(branchR) branchR->SetAddress(&fRecPoints);
779 else if(!branchR) MakeBranchInTreeR(treeR);
780 }
781 treeR->Fill();
782 treeR->Write(tname,TObject::kOverwrite);
783 treeR->Reset();
359cdddc 784}
785
786
787//_____________________________________________________________________________
788void AliZDC::SetMerger(AliZDCMerger* merger)
789{
790// Set pointer to merger
791 fMerger = merger;
792}
793
794//_____________________________________________________________________________
795AliZDCMerger* AliZDC::Merger()
796{
797// Return pointer to merger
798 return fMerger;
799}
800