To follow coding conventions
[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
88cb7938 16/* $Id$ */
4c039060 17
fe4da5cc 18///////////////////////////////////////////////////////////////////////////////
19// //
359cdddc 20// Zero Degree Calorimeter //
21// This class contains the basic functions for the ZDCs; //
22// functions specific to one particular geometry are //
23// contained in the derived classes //
fe4da5cc 24// //
fe4da5cc 25///////////////////////////////////////////////////////////////////////////////
26
65a824a5 27#include <stdlib.h>
ef0750c2 28#include <Riostream.h>
65a824a5 29
f901045b 30// --- ROOT system
fe4da5cc 31#include <TBRIK.h>
1450a7cd 32#include <TDirectory.h>
33#include <TF1.h>
88cb7938 34#include <TFile.h>
35#include <TGeometry.h>
36#include <TNode.h>
37#include <TTree.h>
38#include <TVirtualMC.h>
fe4da5cc 39
f901045b 40// --- AliRoot header files
88cb7938 41#include "AliDetector.h"
fe4da5cc 42#include "AliZDC.h"
88cb7938 43#include "AliZDCDigit.h"
f901045b 44#include "AliZDCHit.h"
b6d27557 45#include "AliZDCMergedHit.h"
359cdddc 46#include "AliZDCMerger.h"
1450a7cd 47#include "AliZDCReco.h"
88cb7938 48
fe4da5cc 49#include "AliConst.h"
88cb7938 50
359cdddc 51#include "AliHeader.h"
88cb7938 52#include "AliLoader.h"
53#include "AliRun.h"
5d12ce38 54#include "AliMC.h"
fe4da5cc 55
fe4da5cc 56
57ClassImp(AliZDC)
58
59//_____________________________________________________________________________
60AliZDC::AliZDC()
61{
62 //
63 // Default constructor for the Zero Degree Calorimeter base class
64 //
2e6fc82a 65
1450a7cd 66 fIshunt = 1;
67 fNoShower = 0;
09630792 68
669dbdaa 69 fMerger = 0;
1450a7cd 70 fHits = 0;
71 fNhits = 0;
09630792 72
1450a7cd 73 fDigits = 0;
74 fNdigits = 0;
2685bf00 75
76 fMergedHits = 0;
2685bf00 77
78 fNRecPoints = 0;
1450a7cd 79 fRecPoints = 0;
359cdddc 80
fe4da5cc 81}
82
83//_____________________________________________________________________________
84AliZDC::AliZDC(const char *name, const char *title)
85 : AliDetector(name,title)
86{
87 //
88 // Standard constructor for the Zero Degree Calorimeter base class
89 //
90
359cdddc 91 fIshunt = 1;
92 fNoShower = 0;
93 fMerger = 0;
f901045b 94
359cdddc 95 // Allocate the hits array
f901045b 96 fHits = new TClonesArray("AliZDCHit",1000);
5d12ce38 97 gAlice->GetMCApp()->AddHitList(fHits);
b6d27557 98 // Allocate the merged hits array
99 fMergedHits = new TClonesArray("AliZDCMergedHit",1000);
f901045b 100
359cdddc 101 // Allocate the digits array
102 fDigits = new TClonesArray("AliZDCDigit",1000);
103
2685bf00 104 fNRecPoints = 0;
1450a7cd 105 fRecPoints = 0;
866ab5a2 106
107}
108//____________________________________________________________________________
109AliZDC::~AliZDC()
110{
111 //
112 // ZDC destructor
113 //
114
115 fIshunt = 0;
359cdddc 116
b6d27557 117 if(fMerger) delete fMerger;
2e6fc82a 118
fe4da5cc 119}
fe4da5cc 120//_____________________________________________________________________________
121void AliZDC::AddHit(Int_t track, Int_t *vol, Float_t *hits)
122{
123 //
f901045b 124 // Add a ZDC hit to the hit list.
125 // -> We make use of 2 array of hits:
126 // [1] fHits (the usual one) that contains hits for each PRIMARY
127 // [2] fStHits that contains hits for each EVENT and is used to
128 // obtain digits at the end of each event
fe4da5cc 129 //
f901045b 130
68ca986e 131 static Float_t primKinEn, xImpact, yImpact, sFlag;
132
43f34e8b 133 AliZDCHit *newquad, *curprimquad;
f901045b 134 newquad = new AliZDCHit(fIshunt, track, vol, hits);
65d4f2be 135 TClonesArray &lhits = *fHits;
cefa66cb 136
137 if(fNhits==0){
138 // First hit -> setting flag for primary or secondary particle
5d12ce38 139 Int_t primary = gAlice->GetMCApp()->GetPrimary(track);
cefa66cb 140 if(track != primary){
141 newquad->fSFlag = 1; // SECONDARY particle entering the ZDC
142 }
143 else if(track == primary){
144 newquad->fSFlag = 0; // PRIMARY particle entering the ZDC
145 }
cefa66cb 146 sFlag = newquad->fSFlag;
147 primKinEn = newquad->fPrimKinEn;
148 xImpact = newquad->fXImpact;
149 yImpact = newquad->fYImpact;
150 }
151 else{
152 newquad->fPrimKinEn = primKinEn;
153 newquad->fXImpact = xImpact;
154 newquad->fYImpact = yImpact;
155 newquad->fSFlag = sFlag;
156 }
157
43f34e8b 158 Int_t j;
f901045b 159 for(j=0; j<fNhits; j++){
2e6fc82a 160 // If hits are equal (same track, same volume), sum them.
f901045b 161 curprimquad = (AliZDCHit*) lhits[j];
162 if(*curprimquad == *newquad){
163 *curprimquad = *curprimquad+*newquad;
164 delete newquad;
68ca986e 165 return;
f901045b 166 }
167 }
f901045b 168
169 //Otherwise create a new hit
170 new(lhits[fNhits]) AliZDCHit(newquad);
171 fNhits++;
172
866ab5a2 173 delete newquad;
cefa66cb 174}
175
866ab5a2 176//_____________________________________________________________________________
359cdddc 177void AliZDC::AddDigit(Int_t *sect, Int_t digit)
f901045b 178{
359cdddc 179//
180 AliZDCDigit *newdigit;
181 newdigit = new AliZDCDigit(sect, digit);
359cdddc 182
183// printf("\n AddDigit -> sector[0] = %d, sector[1] = %d, digit = %d",
184// sect[0], sect[1], digit);
185 new((*fDigits)[fNdigits]) AliZDCDigit(*newdigit);
186 fNdigits++;
187 delete newdigit;
f901045b 188}
359cdddc 189
fe4da5cc 190//_____________________________________________________________________________
191void AliZDC::BuildGeometry()
192{
193 //
194 // Build the ROOT TNode geometry for event display
195 // in the Zero Degree Calorimeter
196 // This routine is dummy for the moment
197 //
198
68ca986e 199 TNode *node, *top;
200 TBRIK *brik;
359cdddc 201 const int kColorZDC = kBlue;
fe4da5cc 202
203 //
68ca986e 204 top=gAlice->GetGeometry()->GetNode("alice");
fe4da5cc 205
206 // ZDC
fe4da5cc 207 brik = new TBRIK("S_ZDC","ZDC box","void",300,300,5);
68ca986e 208 top->cd();
209 node = new TNode("ZDC","ZDC","S_ZDC",0,0,600,"");
210 node->SetLineColor(kColorZDC);
211 fNodes->Add(node);
fe4da5cc 212}
213
214//_____________________________________________________________________________
215Int_t AliZDC::DistancetoPrimitive(Int_t , Int_t )
216{
217 //
218 // Distance from the mouse to the Zero Degree Calorimeter
219 // Dummy routine
220 //
221 return 9999;
222}
359cdddc 223
224//____________________________________________________________________________
225Float_t AliZDC::ZMin(void) const
226{
227 // Minimum dimension of the ZDC module in z
228 return 11600.;
229}
230
231//____________________________________________________________________________
232Float_t AliZDC::ZMax(void) const
233{
234 // Maximum dimension of the ZDC module in z
235 return 11750.;
236}
237
238
fe4da5cc 239//_____________________________________________________________________________
359cdddc 240 void AliZDC::MakeBranch(Option_t *opt, const char *file)
fe4da5cc 241{
242 //
359cdddc 243 // Create Tree branches for the ZDC
fe4da5cc 244 //
359cdddc 245
246 char branchname[10];
247 sprintf(branchname,"%s",GetName());
88cb7938 248
249 const char *cH = strstr(opt,"H");
250
251 if (cH && fLoader->TreeH())
252 fHits = new TClonesArray("AliZDCHit",1000);
359cdddc 253
254 AliDetector::MakeBranch(opt);
255
256 const char *cS = strstr(opt,"S");
257
88cb7938 258 if (fLoader->TreeS() && cS) {
b6d27557 259 if(fMergedHits!=0) fMergedHits->Clear();
260 else fMergedHits = new TClonesArray ("AliZDCMergedHit",1000);
88cb7938 261 MakeBranchInTree(fLoader->TreeS(),
b6d27557 262 branchname, &fMergedHits, fBufferSize, file) ;
359cdddc 263 printf("* AliZDC::MakeBranch * Making Branch %s for SDigits\n\n",branchname);
264 }
265
266
267 const char *cD = strstr(opt,"D");
268
88cb7938 269 if (fLoader->TreeD() && cD) {
359cdddc 270 if(fDigits!=0) fDigits->Clear();
271 else fDigits = new TClonesArray ("AliZDCDigit",1000);
88cb7938 272 MakeBranchInTree(fLoader->TreeD(),
359cdddc 273 branchname, &fDigits, fBufferSize, file) ;
274 printf("* AliZDC::MakeBranch * Making Branch %s for Digits\n\n",branchname);
275 }
276
277
278 const char *cR = strstr(opt,"R");
279
280 if (gAlice->TreeR() && cR) {
669dbdaa 281 if(fRecPoints==0) fRecPoints = new TClonesArray("AliZDCReco",1000);
359cdddc 282 MakeBranchInTree(gAlice->TreeR(),
283 branchname, &fRecPoints, fBufferSize, file) ;
284 printf("* AliZDC::MakeBranch * Making Branch %s for RecPoints\n\n",branchname); }
285
fe4da5cc 286}
359cdddc 287
288//_____________________________________________________________________________
669dbdaa 289 void AliZDC::MakeBranchInTreeS(TTree *treeS, const char *file)
b6d27557 290{
291 // MakeBranchInTree
292 const Int_t kBufferSize = 4000;
293 char branchname[20];
294 sprintf(branchname,"%s",GetName());
88cb7938 295 if (fMergedHits==0x0) fMergedHits = new TClonesArray("AliZDCMergedHit",1000);
669dbdaa 296 MakeBranchInTree(treeS, branchname, &fMergedHits, kBufferSize, file) ;
b6d27557 297 printf("* AliZDC::MakeBranch * Making Branch %s for SDigits\n\n",branchname);
298
299}
300//_____________________________________________________________________________
301 void AliZDC::MakeBranchInTreeD(TTree *treeD, const char *file)
359cdddc 302{
b6d27557 303 // MakeBranchInTree
304 const Int_t kBufferSize = 4000;
305 char branchname[20];
306 sprintf(branchname,"%s",GetName());
88cb7938 307 if (fDigits == 0x0) fDigits = new TClonesArray("AliZDCDigit",1000);
b6d27557 308 MakeBranchInTree(treeD, branchname, &fDigits, kBufferSize, file) ;
309 printf("* AliZDC::MakeBranch * Making Branch %s for Digits\n\n",branchname);
359cdddc 310
b6d27557 311}
312//_____________________________________________________________________________
1450a7cd 313 void AliZDC::MakeBranchInTreeR(TTree *treeR, const char *file)
314{
315 // MakeBranchInTree
316 const Int_t kBufferSize = 4000;
317 char branchname[20];
318 sprintf(branchname,"%s",GetName());
319 MakeBranchInTree(treeR, branchname, &fRecPoints, kBufferSize, file) ;
320 printf("* AliZDC::MakeBranch * Making Branch %s for RecPoints\n\n",branchname);
321
322}
323//_____________________________________________________________________________
b6d27557 324void AliZDC::Hits2SDigits()
325{
1450a7cd 326 printf("\n Entering AliZDC::SDigits2Digits() ");
b6d27557 327
85a5290f 328 fLoader->LoadHits("read");
329 fLoader->LoadSDigits("recreate");
330 AliRunLoader* runLoader = fLoader->GetRunLoader();
331
332 for (Int_t iEvent = 0; iEvent < runLoader->GetNumberOfEvents(); iEvent++) {
333 runLoader->GetEvent(iEvent);
334 if (!fLoader->TreeS()) fLoader->MakeTree("S");
335 MakeBranch("S");
336
b6d27557 337 //----------------------------------------------------------------
359cdddc 338 if(!fMerger){
1450a7cd 339 printf(" ZDC digitization (without merging)\n");
b6d27557 340
70b76f82 341 AliZDCMergedHit *mHit;
b6d27557 342 Int_t j, sector[2];
70b76f82 343 Float_t mHits[7];
b6d27557 344 fNMergedhits = 0;
345
88cb7938 346 TTree *treeH = TreeH();
359cdddc 347 Int_t ntracks = (Int_t) treeH->GetEntries();
359cdddc 348 gAlice->ResetHits();
349
350 // Tracks loop
351 for(Int_t itrack=0; itrack<ntracks; itrack++){
352 treeH->GetEvent(itrack);
359cdddc 353 for(AliZDCHit* zdcHit=(AliZDCHit*)this->FirstHit(-1); zdcHit;
b6d27557 354 zdcHit = (AliZDCHit*)this->NextHit()){
355
356 for(j=0; j<2; j++) sector[j] = zdcHit->GetVolume(j);
70b76f82 357 mHits[0] = zdcHit->GetPrimKinEn();
358 mHits[1] = zdcHit->GetXImpact();
359 mHits[2] = zdcHit->GetYImpact();
360 mHits[3] = zdcHit->GetSFlag();
361 mHits[4] = zdcHit->GetLightPMQ();
362 mHits[5] = zdcHit->GetLightPMC();
363 mHits[6] = zdcHit->GetEnergy();
b6d27557 364 }//Hits loop
365
70b76f82 366 mHit = new AliZDCMergedHit(sector, mHits);
367 new((*fMergedHits)[fNMergedhits]) AliZDCMergedHit(*mHit);
b6d27557 368 TClonesArray &sdigits = *fMergedHits;
70b76f82 369 new (sdigits[fNMergedhits]) AliZDCMergedHit(*mHit);
b6d27557 370 fNMergedhits++;
70b76f82 371 delete mHit;
359cdddc 372 }
85a5290f 373 fLoader->TreeS()->Fill();
374 fLoader->TreeS()->AutoSave();
375 fLoader->TreeS()->Reset();
359cdddc 376 }
b6d27557 377 //----------------------------------------------------------------
378 else if(fMerger){
1450a7cd 379 printf(" ZDC merging and digitization\n");
b6d27557 380 // ### Initialise merging
381 fMerger -> InitMerging();
382
b6d27557 383 // SDigits tree
88cb7938 384
385
386
387 TTree *treeS = fLoader->TreeS();
388 if (treeS == 0x0)
389 {
390 Int_t retval = fLoader->LoadSDigits();
391 if (retval)
392 {
393 Error("Hits2SDigits","Error while loading S. Digits");
394 return;
395 }
396 treeS = fLoader->TreeS();
397 }
398
669dbdaa 399 if(!treeS){
400 printf("\n ERROR -> Can't find TreeS%d in background file\n",fMerger->EvNum());
b6d27557 401 }
669dbdaa 402
403 // ### Get TCA of MergedHits from AliZDCMerger
404 fMergedHits = fMerger->MergedHits();
405 fNMergedhits = fMerger->GetNMhits();
406
b6d27557 407 // Branch address
b6d27557 408 char branchSDname[20];
409 sprintf(branchSDname,"%s",GetName());
669dbdaa 410 if(treeS && fMergedHits){
411 TBranch *branchSD = treeS->GetBranch(branchSDname);
b6d27557 412 if(branchSD) branchSD->SetAddress(&fMergedHits);
669dbdaa 413 else if(!branchSD) MakeBranchInTreeS(treeS);
b6d27557 414 }
70b76f82 415 AliZDCMergedHit *mHit;
b6d27557 416 TClonesArray &sdigits = *fMergedHits;
417 Int_t imhit;
418 //Merged Hits loop
419 for(imhit=0; imhit<fNMergedhits; imhit++){
70b76f82 420 mHit = (AliZDCMergedHit*) fMergedHits->UncheckedAt(imhit);
421 new (sdigits[imhit]) AliZDCMergedHit(*mHit);
b6d27557 422 }
669dbdaa 423 treeS->Fill();
424 treeS->AutoSave();
b6d27557 425 }
359cdddc 426
85a5290f 427 }
428
429 fLoader->UnloadHits();
430 fLoader->UnloadSDigits();
359cdddc 431}
432
433//_____________________________________________________________________________
434void AliZDC::SDigits2Digits()
435{
436 if(!fMerger){ // Only digitization
669dbdaa 437 printf(" ZDC digitization (no merging) \n");
359cdddc 438 fMerger = new AliZDCMerger();
b6d27557 439 fMerger->Digitize(fNMergedhits, fMergedHits);
440
441 char hname[30];
442 sprintf(hname,"TreeD%d",gAlice->GetHeader()->GetEvent());
443 gAlice->TreeD()->Fill();
669dbdaa 444 gAlice->TreeD()->AutoSave();
b6d27557 445 gAlice->TreeD()->Reset();
359cdddc 446 }
b6d27557 447 else if(fMerger){ // Merging and digitization
1450a7cd 448 printf(" ZDC merging and digitization\n");
b6d27557 449 fMerger->Digitize(fNMergedhits, fMergedHits);
450
b6d27557 451 // Digits tree
88cb7938 452
453 TTree *treeD = fLoader->TreeD();
454 if (treeD == 0x0)
455 {
456 Int_t retval = fLoader->LoadDigits();
457 if (retval)
458 {
459 Error("SDigits2Digits","Error while loading Digits");
460 return;
461 }
462 treeD = fLoader->TreeD();
463 }
464
465
466
669dbdaa 467 if(!treeD){
468 printf("\n ERROR -> Can't find TreeD%d in background file\n",fMerger->EvNum());
b6d27557 469 }
470 // Branch address
b6d27557 471 char branchDname[20];
472 sprintf(branchDname,"%s",GetName());
669dbdaa 473 if(treeD && fDigits){
474 TBranch *branchD = treeD->GetBranch(branchDname);
b6d27557 475 if(branchD) branchD->SetAddress(&fDigits);
669dbdaa 476 else if(!branchD) MakeBranchInTreeD(treeD);
b6d27557 477 }
669dbdaa 478 treeD->Fill();
479 treeD->AutoSave();
359cdddc 480 }
b6d27557 481
359cdddc 482
483}
484//_____________________________________________________________________________
485void AliZDC::Hits2Digits()
486{
487 gAlice->Hits2SDigits();
488 gAlice->SDigits2Digits();
489}
490
491//_____________________________________________________________________________
492void AliZDC::Digits2Reco()
493{
669dbdaa 494 printf(" Entering AliZDC::Digits2Reco\n");
70b76f82 495 AliDetector *zdcd = gAlice->GetDetector("ZDC");
496 TClonesArray *zdcdigits = zdcd->Digits();
1450a7cd 497
70b76f82 498 TTree *td = fLoader->TreeD();
499 if (td == 0x0)
88cb7938 500 {
501 Int_t retval = fLoader->LoadDigits();
502 if (retval)
503 {
504 Error("Digits2Reco","Error while loading Digits");
505 return;
506 }
70b76f82 507 td = fLoader->TreeD();
88cb7938 508 }
509
510
70b76f82 511 if(td){
1450a7cd 512 char brname[20];
70b76f82 513 sprintf(brname,"%s",zdcd->GetName());
514 TBranch *br = td->GetBranch(brname);
515 if(br) br->SetAddress(&zdcdigits);
1450a7cd 516 }
70b76f82 517 else if(!td) printf(" ERROR -> TreeD NOT found in gAlice object\n");
1450a7cd 518
70b76f82 519 Int_t nt = (Int_t) (td->GetEntries());
1450a7cd 520 gAlice->ResetDigits();
521
522 AliZDCDigit *dig;
70b76f82 523 Int_t j, idig, ndigits, znraw=0, zpraw=0, zemraw=0;
1450a7cd 524 // --- Summing raw ADCs for each detector to obtain total light
525 for(j=0; j<nt; j++){
70b76f82 526 td->GetEvent(j);
527 ndigits = zdcdigits->GetEntries();
528 znraw=0;
529 zpraw=0;
530 zemraw=0;
1450a7cd 531 // --- Loop over event digits
532 for(idig=0; idig<ndigits; idig++){
70b76f82 533 dig = (AliZDCDigit*) zdcdigits->UncheckedAt(idig);
534 if(dig->GetSector(0) == 1) znraw += dig->GetADCValue();
535 else if(dig->GetSector(0) == 2) zpraw += dig->GetADCValue();
536 else if(dig->GetSector(0) == 3) zemraw += dig->GetADCValue();
1450a7cd 537 } // Digits loop
538 } // TreeD entries loop
70b76f82 539 printf("\n --- znraw = %d, zpraw = %d, zemraw = %d\n",znraw, zpraw, zemraw);
1450a7cd 540
541 // --- Pedestal subtraction
70b76f82 542 Int_t zncorr, zpcorr, zemcorr, meanPed=50;
543 zncorr = znraw - 5*meanPed;
544 zpcorr = zpraw - 5*meanPed;
545 zemcorr = zemraw - 2*meanPed;
546 if(zncorr<0) zncorr=0;
547 if(zpcorr<0) zpcorr=0;
548 if(zemcorr<0) zemcorr=0;
549 printf("\n zncorr = %d, zpcorr = %d, zemcorr = %d\n",zncorr,zpcorr,zemcorr);
1450a7cd 550
551 // --- ADCchannel -> photoelectrons
552 // NB-> PM gain = 10^(5), ADC resolution = 6.4*10^(-7)
70b76f82 553 Float_t znphe, zpphe, zemphe, convFactor = 0.064;
554 znphe = zncorr/convFactor;
555 zpphe = zpcorr/convFactor;
556 zemphe = zemcorr/convFactor;
557 printf("\n znphe = %f, zpphe = %f, zemphe = %f\n",znphe, zpphe, zemphe);
1450a7cd 558
559 // --- Energy calibration
560 // Conversion factors for hadronic ZDCs goes from phe yield to TRUE incident
561 // energy (conversion from GeV to TeV is included); while for EM calos
562 // conversion is from light yield to detected energy calculated by GEANT
563 // NB -> ZN and ZP conversion factors are constant since incident spectators
564 // have all the same energy, ZEM energy is obtained through a fit over the whole
565 // range of incident particle energies (obtained with full HIJING simulations)
70b76f82 566 Float_t znenergy, zpenergy, zemenergy, zdcenergy;
567 Float_t znphexTeV=329., zpphexTeV=369.;
568 znenergy = znphe/znphexTeV;
569 zpenergy = zpphe/zpphexTeV;
570 zdcenergy = znenergy+zpenergy;
571 zemenergy = -4.81+0.3238*zemphe;
572 if(zemenergy<0) zemenergy=0;
573 printf(" znenergy = %f TeV, zpenergy = %f TeV, zdcenergy = %f GeV, "
574 "\n zemenergy = %f TeV\n", znenergy, zpenergy,
575 zdcenergy, zemenergy);
1450a7cd 576
70b76f82 577 if(zdcenergy==0)
578 printf("\n\n ### ATTENZIONE!!! -> ev# %d: znenergy = %f TeV, zpenergy = %f TeV, zdcenergy = %f GeV, "
579 " zemenergy = %f TeV\n\n", fMerger->EvNum(), znenergy, zpenergy, zdcenergy, zemenergy);
1450a7cd 580
581 // --- Number of incident spectator nucleons
70b76f82 582 Int_t nDetSpecN, nDetSpecP;
583 nDetSpecN = (Int_t) (znenergy/2.760);
584 nDetSpecP = (Int_t) (zpenergy/2.760);
585 printf("\n nDetSpecN = %d, nDetSpecP = %d\n",nDetSpecN, nDetSpecP);
1450a7cd 586
587 // --- Number of generated spectator nucleons and impact parameter
92e95964 588 // --------------------------------------------------------------------------------------------------
589 // [1] ### Results in Chiara's PhD thesis -> 0<b<15 fm (Dec 2001)
590 /*// Fit results for neutrons (Nspectator n true vs. EZN)
1450a7cd 591 TF1 *fZNCen = new TF1("fZNCen",
592 "(-2.116909+sqrt(2.116909*2.116909-4*(-0.00651)*(14.556798-x)))/(2*(-0.00651))",0.,158.5);
593 TF1 *fZNPer = new TF1("fZNPer",
594 "(-34.695134-sqrt(34.695134*34.695134-4*(-0.174780)*(-1562.283443-x)))/(2*(-0.174780))",0.,158.5);
595 // Fit results for protons (Nspectator p true vs. EZP)
596 TF1 *fZPCen = new TF1("fZPCen",
597 "(-1.3217+sqrt(1.3217*1.3217-4*(-0.007934)*(4.742873-x)))/(2*(-0.007934))",0.,58.91);
598 TF1 *fZPPer = new TF1("fZPPer",
599 "(-15.788267-sqrt(15.788267*15.788267-4*(-0.133359)*(-383.800673-x)))/(2*(-0.133359))",0.,58.91);
600 // Fit results for total number of spectators (Nspectators true vs. EZDC)
601 TF1 *fZDCCen = new TF1("fZDCCen",
602 "(-1.867335+sqrt(1.867335*1.867335-4*(-0.004119)*(19.100289-x)))/(2*(-0.004119))",0.,220.4);
603 TF1 *fZDCPer = new TF1("fZDCPer",
92e95964 604 "(-22.429097-sqrt(22.429097*22.429097-4*(-0.072435)*(-1482.034526-x)))/(2*(-0.072435))",0.,220.4);*/
605 // --------------------------------------------------------------------------------------------------
606 // [1] ### Results from a new production -> 0<b<18 fm (Apr 2002)
607 // Fit results for neutrons (Nspectator n true vs. EZN)
608 TF1 *fZNCen = new TF1("fZNCen",
609 "(-2.287920+sqrt(2.287920*2.287920-4*(-0.007629)*(11.921710-x)))/(2*(-0.007629))",0.,164.);
610 TF1 *fZNPer = new TF1("fZNPer",
611 "(-37.812280-sqrt(37.812280*37.812280-4*(-0.190932)*(-1709.249672-x)))/(2*(-0.190932))",0.,164.);
612 // Fit results for protons (Nspectator p true vs. EZP)
613 TF1 *fZPCen = new TF1("fZPCen",
614 "(-1.321353+sqrt(1.321353*1.321353-4*(-0.007283)*(3.550697-x)))/(2*(-0.007283))",0.,60.);
615 TF1 *fZPPer = new TF1("fZPPer",
616 "(-42.643308-sqrt(42.643308*42.643308-4*(-0.310786)*(-1402.945615-x)))/(2*(-0.310786))",0.,60.);
617 // Fit results for total number of spectators (Nspectators true vs. EZDC)
618 TF1 *fZDCCen = new TF1("fZDCCen",
619 "(-1.934991+sqrt(1.934991*1.934991-4*(-0.004080)*(15.111124-x)))/(2*(-0.004080))",0.,225.);
620 TF1 *fZDCPer = new TF1("fZDCPer",
621 "(-34.380639-sqrt(34.380639*34.380639-4*(-0.104251)*(-2612.189017-x)))/(2*(-0.104251))",0.,225.);
622 // --------------------------------------------------------------------------------------------------
623 // [1] ### Results in Chiara's PhD thesis -> 0<b<15 fm (Dec 2001)
624 /*// Fit results for b (b vs. EZDC)
1450a7cd 625 //TF1 *fbCen = new TF1("fbCen","0.611543+0.052231*x-0.000112*x*x+0.000000374*x*x*x",0.,222.);
626 //TF1 *fbPer = new TF1("fbPer","16.552010-0.023866*x-0.00001*x*x",0.,222.);
627 TF1 *fbCen = new TF1("fbCen","0.612769+0.051929*x-0.0001074*x*x+0.0000003724*x*x*x",0.,225.);
92e95964 628 TF1 *fbPer = new TF1("fbPer","16.6131016-0.026053*x+0.000006893*x*x",0.,225.);*/
629 // --------------------------------------------------------------------------------------------------
630 // [2] ### Results from a new production -> 0<b<18 fm (Apr 2002)
631 TF1 *fbCen = new TF1("fbCen","-0.056923+0.079703*x-0.0004301*x*x+0.000001366*x*x*x",0.,220.);
632 TF1 *fbPer = new TF1("fbPer","17.943998-0.046846*x+0.000074*x*x",0.,220.);
633 // --------------------------------------------------------------------------------------------------
1450a7cd 634 // Evaluating Nspectators and b from ZEM energy
92e95964 635 // [1] ### Results in Chiara's PhD thesis -> 0<b<15 fm (Dec 2001)
636 /*TF1 *fZEMn = new TF1("fZEMn","124.2-0.0566*x+0.000006014*x*x",0.,3500.);
1450a7cd 637 TF1 *fZEMp = new TF1("fZEMp","81.3-0.03834*x+0.000004359*x*x",0.,3500.);
638 TF1 *fZEMsp = new TF1("fZEMsp","205.6-0.09567*x+0.00001056*x*x",0.,3500.);
92e95964 639 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.);*/
640 // --------------------------------------------------------------------------------------------------
641 // [2] ### Results from a new production -> 0<b<18 fm (Apr 2002)
642 TF1 *fZEMn = new TF1("fZEMn","126.2-0.05399*x+0.000005679*x*x",0.,4000.);
643 TF1 *fZEMp = new TF1("fZEMp","82.49-0.03611*x+0.00000385*x*x",0.,4000.);
644 TF1 *fZEMsp = new TF1("fZEMsp","208.7-0.09006*x+0.000009526*x*x",0.,4000.);
645 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 646
70b76f82 647 Int_t nGenSpecN=0, nGenSpecP=0, nGenSpec=0;
648 Double_t impPar=0;
92e95964 649 // Cut value for Ezem (GeV)
650 // [1] ### Results in Chiara's PhD thesis -> 0<b<15 fm (Dec 2001)
70b76f82 651 //Float_t eZEMCut = 360.;
92e95964 652 // [2] ### Results from a new production -> 0<b<18 fm (Apr 2002)
70b76f82 653 Float_t eZEMCut = 420.;
654 Float_t deltaEZEMSup = 690.;
655 Float_t deltaEZEMInf = 270.;
656 if(zemenergy > (eZEMCut+deltaEZEMSup)){
657 nGenSpecN = (Int_t) (fZNCen->Eval(znenergy));
658 nGenSpecP = (Int_t) (fZPCen->Eval(zpenergy));
659 nGenSpec = (Int_t) (fZDCCen->Eval(zdcenergy));
660 impPar = fbCen->Eval(zdcenergy);
661 //printf(" fZNCen = %f, fZPCen = %f, fZDCCen = %f\n",fZNCen->Eval(znenergy),
662 // fZPCen->Eval(zpenergy),fZDCCen->Eval(zdcenergy));
1450a7cd 663 }
70b76f82 664 else if(zemenergy < (eZEMCut-deltaEZEMInf)){
665 nGenSpecN = (Int_t) (fZNPer->Eval(znenergy));
666 nGenSpecP = (Int_t) (fZPPer->Eval(zpenergy));
667 nGenSpec = (Int_t) (fZDCPer->Eval(zdcenergy));
668 impPar = fbPer->Eval(zdcenergy);
669 //printf(" fZNPer = %f, fZPPer = %f, fZDCPer = %f\n",fZNPer->Eval(znenergy),
670 // fZPPer->Eval(zpenergy),fZDCPer->Eval(zdcenergy));
1450a7cd 671 }
70b76f82 672 else if(zemenergy >= (eZEMCut-deltaEZEMInf) && zemenergy <= (eZEMCut+deltaEZEMSup)){
673 nGenSpecN = (Int_t) (fZEMn->Eval(zemenergy));
674 nGenSpecP = (Int_t) (fZEMp->Eval(zemenergy));
675 nGenSpec = (Int_t)(fZEMsp->Eval(zemenergy));
676 impPar = fZEMb->Eval(zemenergy);
677 //printf(" Nspec ZEM = %f, Nspec ZDC = %f\n",fZEMsp->Eval(znenergy),fZDCPer->Eval(zdcenergy));
92e95964 678 }
679 // [1] ### Results in Chiara's PhD thesis -> 0<b<15 fm (Dec 2001)
70b76f82 680 /*if(znenergy>158.5) nGenSpecN = (Int_t) (fZEMn->Eval(zemenergy));
681 if(zpenergy>58.91) nGenSpecP = (Int_t) (fZEMp->Eval(zemenergy));
682 if(zdcenergy>220.4) nGenSpec = (Int_t)(fZEMsp->Eval(zemenergy));
683 if(zdcenergy>225.) impPar = fZEMb->Eval(zemenergy);*/
92e95964 684 // [2] ### Results from a new production -> 0<b<18 fm (Apr 2002)
70b76f82 685 if(znenergy>162.) nGenSpecN = (Int_t) (fZEMn->Eval(zemenergy));
686 if(zpenergy>59.75) nGenSpecP = (Int_t) (fZEMp->Eval(zemenergy));
687 if(zdcenergy>221.5) nGenSpec = (Int_t)(fZEMsp->Eval(zemenergy));
688 if(zdcenergy>220.) impPar = fZEMb->Eval(zemenergy);
1450a7cd 689
70b76f82 690 if(nGenSpecN>125) nGenSpecN=125;
691 else if(nGenSpecN<0) nGenSpecN=0;
692 if(nGenSpecP>82) nGenSpecP=82;
693 else if(nGenSpecP<0) nGenSpecP=0;
694 if(nGenSpec>207) nGenSpec=207;
695 else if(nGenSpec<0) nGenSpec=0;
696 //printf(" NRecSpecN = %d, NRecSpecP = %d, NRecSpec = %d\n",nGenSpecN,nGenSpecP,nGenSpec);
1450a7cd 697
698 // --- Number of participants
70b76f82 699 Int_t nPart, nPartTot;
700 nPart = 207-nGenSpecN-nGenSpecP;
701 nPartTot = 207-nGenSpec;
702 //printf(" ### nPart(ZP+ZN) = %d, nPart(ZDC) = %d, b = %f fm\n",nPart,nPartTot,impPar);
703 printf(" ### nPart = %d, b = %f fm\n",nPartTot,impPar);
1450a7cd 704
705 // --- Writing RecPoints TCA
706 // Allocate the RecPoints TCA
707 fRecPoints = new TClonesArray("AliZDCReco",1000);
70b76f82 708 AliZDCReco *reco = new AliZDCReco(znenergy,zpenergy,zdcenergy,zemenergy,
709 nDetSpecN,nDetSpecP,nGenSpecN,nGenSpecP,nGenSpec,nPartTot,impPar);
1450a7cd 710 new((*fRecPoints)[fNRecPoints]) AliZDCReco(*reco);
1450a7cd 711 //fNRecPoints++;
712 //fRecPoints->Dump();
713 delete reco;
714
715 // TreeR
716 TTree *treeR = gAlice->TreeR();
669dbdaa 717 if(!treeR) printf("\n ERROR -> Can't find TreeR%d in background file\n",fMerger->EvNum());
1450a7cd 718 // Branch address
719 char branchRname[20];
720 sprintf(branchRname,"%s",GetName());
721 if(fRecPoints){
722 TBranch *branchR = treeR->GetBranch(branchRname);
723 if(branchR) branchR->SetAddress(&fRecPoints);
724 else if(!branchR) MakeBranchInTreeR(treeR);
725 }
726 treeR->Fill();
669dbdaa 727 treeR->AutoSave();
1450a7cd 728 treeR->Reset();
359cdddc 729}
730
b81c9821 731//______________________________________________________________________
732void AliZDC::SetTreeAddress(){
733 // Set branch address for the Trees.
734 // Inputs:
735 // none.
736 // Outputs:
737 // none.
738 // Return:
739 // none.
740 if (fLoader->TreeH() && (fHits == 0x0))
741 fHits = new TClonesArray("AliZDCHit",1000);
742
743 if (fLoader->TreeD() && (fDigits == 0x0))
744 fDigits = new TClonesArray("AliZDCDigit",1000);
745
746 AliDetector::SetTreeAddress();
747}
359cdddc 748