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 **************************************************************************/
17 ///////////////////////////////////////////////////////////////////////////////
19 // ZDC event merging class //
21 ///////////////////////////////////////////////////////////////////////////////
27 #include <TDirectory.h>
31 // --- AliRoot header files
32 #include "AliZDCMerger.h"
34 #include "AliZDCHit.h"
35 #include "AliZDCDigit.h"
36 #include "AliZDCFragment.h"
38 #include "AliDetector.h"
39 #include "AliHeader.h"
40 #include "AliGenEventHeader.h"
41 #include "AliGenHijingEventHeader.h"
43 ClassImp(AliZDCMerger)
45 //____________________________________________________________________________
46 AliZDCMerger::AliZDCMerger()
48 // Default constructor
67 //____________________________________________________________________________
68 AliZDCMerger::~AliZDCMerger()
71 if (fBgrFile) delete fBgrFile;
72 if (fTrHBgr) delete fTrHBgr;
73 if (fTrSDBgr) delete fTrSDBgr;
74 if (fHitsBgr) delete fHitsBgr;
75 if (fSpecnFile) delete fSpecnFile;
76 if (fSpecpFile) delete fSpecpFile;
79 //____________________________________________________________________________
80 void AliZDCMerger::InitMerging()
82 // Hits tree, impact parameter, num. of spectators n & p
83 // in background (full Hijing) event
86 Background(b, nspecn, nspecp);
88 // Production of nuclear fragments -> num. of FREE spectators n & p
89 Fragmentation(b, nspecn, nspecp, fFreeSpn, fFreeSpp);
91 // Extract from spectators distribution the signal events:
92 // NFreeSpectatorN spectator n & NFreeSpectatorP spectator p
93 Mixing(fFreeSpn, fFreeSpp);
96 //____________________________________________________________________________
97 void AliZDCMerger::Background(Float_t &fImpPar, Int_t &fSpecn, Int_t &fSpecp)
100 // --- Open the background file
101 if (fMerge && !fBgrFile) fBgrFile = OpenBgrFile();
103 // --- Read from the TreeE impact parameter (b),
104 // # of spectators n and p (fSpecn, fSpecp)
107 // Get AliRun object from file or create it if not on file
108 gAlice = (AliRun*)fBgrFile->Get("gAlice");
110 gAlice = (AliRun*)fBgrFile->Get("gAlice");
111 if (gAlice) printf("AliRun object found on file\n");
113 printf("\n create new gAlice object");
114 gAlice = new AliRun("gAlice","Alice test program");
118 // gAlice = (AliRun*)fBgrFile->Get("gAlice");
119 AliHeader *header = gAlice->GetHeader();
120 AliGenEventHeader* mcHeader = header->GenEventHeader();
121 fImpPar = ((AliGenHijingEventHeader*) mcHeader)->ImpactParameter();
122 fSpecn = ((AliGenHijingEventHeader*) mcHeader)->Spectatorsn();
123 fSpecp = ((AliGenHijingEventHeader*) mcHeader)->Spectatorsp();
124 // printf("\n HIJING simulation - b = %f fm, Nspecn = %d, Nspecp = %d\n",fImpPar,fSpecn,fSpecp);
127 //____________________________________________________________________________
128 TFile* AliZDCMerger::OpenBgrFile()
130 // Initialise background event
131 TFile *file = new TFile(fFnBgr,"UPDATE");
132 // printf("\n AliZDCMerger --- Background event -> %s file opened \n", fFnBgr);
133 fHitsBgr = new TClonesArray("AliZDCHit",1000);
137 //____________________________________________________________________________
138 void AliZDCMerger::Fragmentation(Float_t fImpPar, Int_t fSpecn, Int_t fSpecp,
139 Int_t &fFreeSpn, Int_t &fFreeSpp)
141 Int_t j, zz[100], nn[100], nAlpha, Ztot, Ntot;
142 AliZDCFragment *frag = new AliZDCFragment(fImpPar);
143 for(j=0; j<=99; j++){
148 // Fragments generation
149 frag->GenerateIMF(zz, nAlpha);
154 frag->AttachNeutrons(zz, nn, Ztot, Ntot);
155 fFreeSpn = fSpecn-Ztot-2*nAlpha;
156 fFreeSpp = fSpecp-Ntot-2*nAlpha;
157 // printf("\n Fragmentation -> FreeSpn = %d, FreeSpp = %d\n",fFreeSpn,fFreeSpp);
160 //____________________________________________________________________________
161 void AliZDCMerger::Mixing(Int_t fFreeSpn, Int_t fFreeSpp)
164 // printf("\n AliZDCMerger->Mixing\n");
166 // ### Background event Hits ###########################################
170 AliZDC *ZDC = (AliZDC *)gAlice->GetModule("ZDC");
171 // if(ZDC) printf("\n Ho trovato lo ZDC!\n");
174 if(fTrHBgr) delete fTrHBgr;
177 if(fTrSDBgr) delete fTrSDBgr;
180 // // Read from Event Tree the # of events of the Hijing file
181 // TTree *thead = (TTree *) fBgrFile->Get("TE");
183 // printf("\n ERROR! -> File %s does not contain TreeE\n");
185 // fNEvBgr = (Int_t) te->GetEntries();
186 fNEvBgr = 0; // Let's suppose to have 1 full Hijing event per file
189 char treeBgrName[20];
190 sprintf(treeBgrName,"TreeH%d",fNEvBgr);
191 fTrHBgr = (TTree*)gDirectory->Get(treeBgrName); // TreeH
193 printf("\n ERROR -> Can't find TreeH%d in background file\n",fNEvBgr);
195 Int_t ntracks = (Int_t) fTrHBgr->GetEntries();
196 // printf("\n --- ntracks = %d\n",ntracks);
199 char treeSBgrName[20];
200 sprintf(treeSBgrName,"TreeS%d",fNEvBgr);
201 fTrSDBgr = (TTree*)gDirectory->Get(treeSBgrName); // TreeH
203 printf("\n ERROR -> Can't find TreeS%d in background file\n",fNEvBgr);
206 Int_t itrack, i, volume[2], detector, quadrant;
207 TClonesArray &sdigits = *fHitsBgr; // SDigits TCArray
210 for(itrack=0; itrack<ntracks; itrack++){
211 // printf(" itrack = %d \n", itrack);
212 fTrHBgr->GetEvent(itrack);
216 for(AliZDCHit* zdcHit=(AliZDCHit*)ZDC->FirstHit(-1);
218 zdcHit = (AliZDCHit*)ZDC->NextHit()){
220 for(i=0; i<2; i++) volume[i] = zdcHit->GetVolume(i);
221 // printf("\n volume[0] = %d volume[1]= %d \n",volume[0], volume[1]);
224 hits[7] = zdcHit->GetLightPMQ();
225 hits[8] = zdcHit->GetLightPMC();
226 // printf("\n Prima ### Background -> PMQ = %f, PMC = %f\n",hits[7],hits[8]);
229 detector = volume[0];
230 quadrant = volume[1];
231 ExtractSignal(detector, quadrant, fQuadLight, fComLight);
232 hits[7] += fQuadLight;
233 hits[8] += fComLight;
234 // printf("\n Bckg + Signal -> PMQ = %f, PMC = %f\n",hits[7],hits[8]);
236 zdcHit->SetLightPMQ(hits[7]);
237 zdcHit->SetLightPMC(hits[8]);
238 hits[7] = zdcHit->GetLightPMQ();
239 hits[8] = zdcHit->GetLightPMC();
240 // printf("\n Dopo ### Background -> PMQ = %f, PMC = %f\n",hits[7],hits[8]);
242 new (sdigits[NMhits++]) AliZDCHit(zdcHit);
243 // printf("\n NMhits = %d\n",NMhits);
247 fTrSDBgr->Write(0,TObject::kOverwrite);
252 // fBgrFile->Close();
256 //____________________________________________________________________________
257 void AliZDCMerger::ExtractSignal(Int_t detector, Int_t quadrant,
258 Float_t &fQuadLight, Float_t &fComLight)
261 // printf("\n Entering ExtractSignal method -> detector = %d quadrant = %d\n",
262 // detector, quadrant);
264 // Connect spectator n histo's file
265 fFnSpecn = gSystem->ExpandPathName("$ALICE/$ALICE_LEVEL/ZDC/ZNsignal.root");
266 fSpecnFile = TFile::Open(fFnSpecn,"R");
269 TH1F *hPMQ1zn = (TH1F*) gDirectory->Get("hPMQ1zn;1");
270 TH1F *hPMQ2zn = (TH1F*) gDirectory->Get("hPMQ2zn;1");
271 TH1F *hPMQ3zn = (TH1F*) gDirectory->Get("hPMQ3zn;1");
272 TH1F *hPMQ4zn = (TH1F*) gDirectory->Get("hPMQ4zn;1");
273 TH1F *hPMC1zn = (TH1F*) gDirectory->Get("hPMC1zn;1");
274 TH1F *hPMC2zn = (TH1F*) gDirectory->Get("hPMC2zn;1");
275 TH1F *hPMC3zn = (TH1F*) gDirectory->Get("hPMC3zn;1");
276 TH1F *hPMC4zn = (TH1F*) gDirectory->Get("hPMC4zn;1");
277 // Axis_t x = hPMQ1zn -> GetRandom();
278 // printf(" hPMQ1zn -> GetRandom() = %f\n",x);
280 // Connect spectator p histo's file
281 fFnSpecp = gSystem->ExpandPathName("$ALICE/$ALICE_LEVEL/ZDC/ZPsignal.root");
282 fSpecpFile = TFile::Open(fFnSpecp,"R");
285 TH1F *hPMQ1zp = (TH1F*) gDirectory->Get("hPMQ1zp;1");
286 TH1F *hPMQ2zp = (TH1F*) gDirectory->Get("hPMQ2zp;1");
287 TH1F *hPMQ3zp = (TH1F*) gDirectory->Get("hPMQ3zp;1");
288 TH1F *hPMQ4zp = (TH1F*) gDirectory->Get("hPMQ4zp;1");
289 TH1F *hPMC1zp = (TH1F*) gDirectory->Get("hPMC1zp;1");
290 TH1F *hPMC2zp = (TH1F*) gDirectory->Get("hPMC2zp;1");
291 TH1F *hPMC3zp = (TH1F*) gDirectory->Get("hPMC3zp;1");
292 TH1F *hPMC4zp = (TH1F*) gDirectory->Get("hPMC4zp;1");
294 if(detector == 1){ // --- ZN
296 fQuadLight = (Float_t) hPMQ1zn -> GetRandom();
297 fComLight = (Float_t) hPMC1zn -> GetRandom();
299 else if(quadrant == 2){
300 fQuadLight = (Float_t) hPMQ2zn -> GetRandom();
301 fComLight = (Float_t) hPMC2zn -> GetRandom();
303 else if(quadrant == 3){
304 fQuadLight = (Float_t) hPMQ3zn -> GetRandom();
305 fComLight = (Float_t) hPMC3zn -> GetRandom();
307 else if(quadrant == 4){
308 fQuadLight = (Float_t) hPMQ4zn -> GetRandom();
309 fComLight = (Float_t) hPMC4zn -> GetRandom();
313 else if(detector == 2){ // --- ZP
314 fSpecpFile->cd(); // Connect spectator p histo's file
317 fQuadLight = (Float_t) hPMQ1zp -> GetRandom();
318 fComLight = (Float_t) hPMC1zp -> GetRandom();
320 else if(quadrant == 2){
321 fQuadLight = (Float_t) hPMQ2zp -> GetRandom();
322 fComLight = (Float_t) hPMC2zp -> GetRandom();
324 else if(quadrant == 3){
325 fQuadLight = (Float_t) hPMQ3zp -> GetRandom();
326 fComLight = (Float_t) hPMC3zp -> GetRandom();
328 else if(quadrant == 4){
329 fQuadLight = (Float_t) hPMQ4zp -> GetRandom();
330 fComLight = (Float_t) hPMC4zp -> GetRandom();
333 // printf(" --- Exiting ExtractSignal -> fQuadLight = %f, fComLight = %f",
334 // fQuadLight,fComLight);
338 //____________________________________________________________________________
339 void AliZDCMerger::Digitize()
342 // printf("\n AliZDCMerger->Digitize()");
344 AliZDC *ZDC = (AliZDC *)gAlice->GetModule("ZDC");
345 // if(ZDC) printf("\n Ho trovato lo ZDC!\n");
347 Int_t itrack, lightQ, lightC, sector[2], digit;
348 Int_t PMCZN = 0, PMCZP = 0, PMQZN[4], PMQZP[4], PMZEM = 0;
355 // ### Digitization "on the flight" (no merging) #######################
356 if(fMerge == kDigitize){
357 // printf("\n fMerge == kDigitize\n");
358 fTrHBgr = gAlice->TreeH(); // TTree
359 TTree *treeH = gAlice->TreeH();
361 printf("\n ERROR -> Can't find TreeH%d in background file\n",fNEvBgr);
363 Int_t ntracks = (Int_t) treeH->GetEntries();
364 // printf("\n --- ntracks = %d\n",ntracks);
367 for(itrack=0; itrack<ntracks; itrack++){
369 gAlice->TreeH()->GetEvent(itrack);
372 for(AliZDCHit* zdcHit=(AliZDCHit*)ZDC->FirstHit(-1);
374 zdcHit = (AliZDCHit*)ZDC->NextHit()){
375 sector[0] = zdcHit->GetVolume(0);
376 sector[1] = zdcHit->GetVolume(1);
377 lightQ = Int_t(zdcHit->GetLightPMQ());
378 lightC = Int_t(zdcHit->GetLightPMC());
379 // printf("\n Digitise -> DET. = %d, quad = %d", sector[0], sector[1]);
380 // printf(" PMQ = %d, PMC = %d", lightQ, lightC);
382 if(sector[0] == 1){ //ZN
383 PMCZN = PMCZN + lightC;
384 PMQZN[sector[1]-1] = PMQZN[sector[1]-1] + lightQ;
386 else if(sector[0] == 2){ //ZP
387 PMCZP = PMCZP + lightC;
388 PMQZP[sector[1]-1] = PMQZP[sector[1]-1] + lightQ;
390 else if(sector[0] == 3){ //ZEM
391 PMZEM = PMZEM + lightC;
397 // ### Merging and digitization #######################################
398 else if(fMerge == kMerge){
399 // printf("\n fMerge == kMerge\n");
401 // Int_t ntracks = (Int_t) fTrHBgr->GetEntries();
402 // printf("\n --- ntracks = %d\n",ntracks);
404 // // Loop over tracks
405 // for(itrack=0; itrack<ntracks; itrack++){
406 fTrHBgr->GetEvent(fTrack);
408 // printf("\n\n Track # %d --- Digitise -> ", fTrack);
410 for(AliZDCHit* zdcHit=(AliZDCHit*)ZDC->FirstHit(-1);
412 zdcHit = (AliZDCHit*)ZDC->NextHit()){
413 sector[0] = zdcHit->GetVolume(0);
414 sector[1] = zdcHit->GetVolume(1);
415 lightQ = Int_t(zdcHit->GetLightPMQ());
416 lightC = Int_t(zdcHit->GetLightPMC());
417 // printf("\n DET. = %d, quad = %d,PMQ = %d, PMC = %d",
418 // sector[0], sector[1],lightQ, lightC);
420 if(sector[0] == 1){ //ZN
421 PMCZN = PMCZN + lightC;
422 PMQZN[sector[1]-1] = PMQZN[sector[1]-1] + lightQ;
424 else if(sector[0] == 2){ //ZP
425 PMCZP = PMCZP + lightC;
426 PMQZP[sector[1]-1] = PMQZP[sector[1]-1] + lightQ;
428 else if(sector[0] == 3){ //ZEM
429 PMZEM = PMZEM + lightC;
436 // Create digits for ZN
438 sector[0] = 1; // Detector = ZN
439 sector[1] = 0; // Common PM ADC
440 digit = Phe2ADCch(1, 0, PMCZN);
441 // printf("\n\n ZN ### PMCZN = %d ADCZN = %d",PMCZN, digit);
442 ZDC->AddDigit(sector, digit);
445 sector[1] = j+1; // Towers PM ADCs
446 digit = Phe2ADCch(1, j+1, PMQZN[j]);
447 // printf("\n PMQZN[%d] = %d ADCZN[%d] = %d",j,PMQZN[j],j,digit);
448 PedValue = AddPedestal();
450 // printf(" PedValue = %d",PedValue);
451 ZDC->AddDigit(sector, digit);
455 // Create digits for ZP
456 sector[0] = 2; // Detector = ZP
457 sector[1] = 0; // Common PM ADC
458 digit = Phe2ADCch(2, 0, PMCZP);
459 // printf("\n ZP --- PMCZP = %d ADCZP = %d",PMCZP,digit);
460 ZDC->AddDigit(sector, digit);
462 sector[1] = j+1; // Towers PM ADCs
463 digit = Phe2ADCch(2, j+1, PMQZP[j]);
464 // printf("\n PMQZP[%d] = %d ADCZP[%d] = %d",j,PMQZP[j],j,digit);
465 PedValue = AddPedestal();
467 // printf(" PedValue = %d",PedValue);
468 ZDC->AddDigit(sector, digit);
472 // Create digits for ZEM
473 sector[0] = 3; // Detector = ZZEM
474 sector[1] = 0; // Single PM ADC
475 digit = Phe2ADCch(3, 0, PMZEM);
476 // printf("\n ZEM *** PMZEM = %d ADCZEM = %d",PMZEM,digit);
477 PedValue = AddPedestal();
479 // printf(" PedValue = %d\n",PedValue);
480 ZDC->AddDigit(sector, digit);
484 //_____________________________________________________________________________
485 Int_t AliZDCMerger::Phe2ADCch(Int_t Det, Int_t Quad, Int_t Light)
487 // Evaluation of the ADC channel corresponding to the light yield Light
489 if(gAlice->GetDebug() > 0){
490 // printf("\n Phe2ADCch -> Detector = %d, Quadrant = %d, Light = %d\n", Det, Quad, Light);
494 // Parameters for conversion of light yield in ADC channels
495 Float_t fPMGain[3][5]; // PM gain
496 Float_t fADCRes; // ADC conversion factor
501 fPMGain[i][j] = 100000.;
504 fADCRes = 0.00000064; // ADC Resolution: 250 fC/ADCch
506 ADCch = (Int_t) (Light*fPMGain[Det-1][Quad]*fADCRes);
511 //_____________________________________________________________________________
512 Int_t AliZDCMerger::AddPedestal()
514 // --- Pedestal value -> extracted from a gaussian distribution
515 // obtained from the beam test on the ZEM prototype (Aug. 2000)
518 Float_t PedMean = 50.;
519 Float_t PedWidth = 10.;
521 PedValue = (Int_t) gRandom->Gaus(PedMean,PedWidth);