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>
30 // --- AliRoot header files
31 #include "AliZDCMerger.h"
33 #include "AliZDCHit.h"
34 #include "AliZDCDigit.h"
35 #include "AliZDCFragment.h"
37 #include "AliDetector.h"
38 #include "AliHeader.h"
39 #include "AliGenEventHeader.h"
40 #include "/home/oppedisa/AliRoot/pro/EVGEN/AliGenHijingEventHeader.h"
42 ClassImp(AliZDCMerger)
44 //____________________________________________________________________________
45 AliZDCMerger::AliZDCMerger()
47 // Default constructor
51 // fFnBgr = "/home/oppedisa/alirun/hijing.root";
61 // fFnSpecn = "/home/oppedisa/alirun/ZNsignal.root";
64 // fFnSpecp = "/home/oppedisa/alirun/ZPsignal.root";
69 //____________________________________________________________________________
70 AliZDCMerger::~AliZDCMerger()
73 if (fBgrFile) delete fBgrFile;
74 if (fTrHBgr) delete fTrHBgr;
75 if (fTrSDBgr) delete fTrSDBgr;
76 if (fHitsBgr) delete fHitsBgr;
77 if (fSpecnFile) delete fSpecnFile;
78 if (fSpecpFile) delete fSpecpFile;
81 //____________________________________________________________________________
82 void AliZDCMerger::InitMerging()
84 // Hits tree, impact parameter, num. of spectators n & p
85 // in background (full Hijing) event
88 Background(b, nspecn, nspecp);
90 // Production of nuclear fragments -> num. of FREE spectators n & p
91 Fragmentation(b, nspecn, nspecp, fFreeSpn, fFreeSpp);
93 // Extract from spectators distribution the signal events:
94 // NFreeSpectatorN spectator n & NFreeSpectatorP spectator p
95 Mixing(fFreeSpn, fFreeSpp);
98 //____________________________________________________________________________
99 void AliZDCMerger::Background(Float_t &fImpPar, Int_t &fSpecn, Int_t &fSpecp)
102 // --- Open the background file
103 if (fMerge && !fBgrFile) fBgrFile = OpenBgrFile();
105 // --- Read from the TreeE impact parameter (b),
106 // # of spectators n and p (fSpecn, fSpecp)
109 // Get AliRun object from file or create it if not on file
110 gAlice = (AliRun*)fBgrFile->Get("gAlice");
112 gAlice = (AliRun*)fBgrFile->Get("gAlice");
113 if (gAlice) printf("AliRun object found on file\n");
115 printf("\n create new gAlice object");
116 gAlice = new AliRun("gAlice","Alice test program");
120 // gAlice = (AliRun*)fBgrFile->Get("gAlice");
121 AliHeader *header = gAlice->GetHeader();
122 AliGenEventHeader* mcHeader = header->GenEventHeader();
123 fImpPar = ((AliGenHijingEventHeader*) mcHeader)->ImpactParameter();
124 fSpecn = ((AliGenHijingEventHeader*) mcHeader)->Spectatorsn();
125 fSpecp = ((AliGenHijingEventHeader*) mcHeader)->Spectatorsp();
126 // printf("\n HIJING simulation - b = %f fm, Nspecn = %d, Nspecp = %d\n",fImpPar,fSpecn,fSpecp);
129 //____________________________________________________________________________
130 TFile* AliZDCMerger::OpenBgrFile()
132 // Initialise background event
133 TFile *file = new TFile(fFnBgr,"UPDATE");
134 // printf("\n AliZDCMerger --- Background event -> %s file opened \n", fFnBgr);
135 fHitsBgr = new TClonesArray("AliZDCHit",1000);
139 //____________________________________________________________________________
140 void AliZDCMerger::Fragmentation(Float_t fImpPar, Int_t fSpecn, Int_t fSpecp,
141 Int_t &fFreeSpn, Int_t &fFreeSpp)
143 Int_t j, zz[100], nn[100], nAlpha, Ztot, Ntot;
144 AliZDCFragment *frag = new AliZDCFragment(fImpPar);
145 for(j=0; j<=99; j++){
150 // Fragments generation
151 frag->GenerateIMF(zz, nAlpha);
156 frag->AttachNeutrons(zz, nn, Ztot, Ntot);
157 fFreeSpn = fSpecn-Ztot-2*nAlpha;
158 fFreeSpp = fSpecp-Ntot-2*nAlpha;
159 // printf("\n Fragmentation -> FreeSpn = %d, FreeSpp = %d\n",fFreeSpn,fFreeSpp);
162 //____________________________________________________________________________
163 void AliZDCMerger::Mixing(Int_t fFreeSpn, Int_t fFreeSpp)
166 // printf("\n AliZDCMerger->Mixing\n");
168 // ### Background event Hits ###########################################
172 AliZDC *ZDC = (AliZDC *)gAlice->GetModule("ZDC");
173 // if(ZDC) printf("\n Ho trovato lo ZDC!\n");
176 if(fTrHBgr) delete fTrHBgr;
179 if(fTrSDBgr) delete fTrSDBgr;
182 // // Read from Event Tree the # of events of the Hijing file
183 // TTree *thead = (TTree *) fBgrFile->Get("TE");
185 // printf("\n ERROR! -> File %s does not contain TreeE\n");
187 // fNEvBgr = (Int_t) te->GetEntries();
188 fNEvBgr = 0; // Let's suppose to have 1 full Hijing event per file
191 char treeBgrName[20];
192 sprintf(treeBgrName,"TreeH%d",fNEvBgr);
193 fTrHBgr = (TTree*)gDirectory->Get(treeBgrName); // TreeH
195 printf("\n ERROR -> Can't find TreeH%d in background file\n",fNEvBgr);
197 Int_t ntracks = (Int_t) fTrHBgr->GetEntries();
198 // printf("\n --- ntracks = %d\n",ntracks);
201 char treeSBgrName[20];
202 sprintf(treeSBgrName,"TreeS%d",fNEvBgr);
203 fTrSDBgr = (TTree*)gDirectory->Get(treeSBgrName); // TreeH
205 printf("\n ERROR -> Can't find TreeS%d in background file\n",fNEvBgr);
208 Int_t itrack, i, volume[2], detector, quadrant;
209 TClonesArray &sdigits = *fHitsBgr; // SDigits TCArray
212 for(itrack=0; itrack<ntracks; itrack++){
213 // printf(" itrack = %d \n", itrack);
214 fTrHBgr->GetEvent(itrack);
218 for(AliZDCHit* zdcHit=(AliZDCHit*)ZDC->FirstHit(-1);
220 zdcHit = (AliZDCHit*)ZDC->NextHit()){
222 for(i=0; i<2; i++) volume[i] = zdcHit->GetVolume(i);
223 // printf("\n volume[0] = %d volume[1]= %d \n",volume[0], volume[1]);
226 hits[7] = zdcHit->GetLightPMQ();
227 hits[8] = zdcHit->GetLightPMC();
228 // printf("\n Prima ### Background -> PMQ = %f, PMC = %f\n",hits[7],hits[8]);
231 detector = volume[0];
232 quadrant = volume[1];
233 ExtractSignal(detector, quadrant, fQuadLight, fComLight);
234 hits[7] += fQuadLight;
235 hits[8] += fComLight;
236 // printf("\n Bckg + Signal -> PMQ = %f, PMC = %f\n",hits[7],hits[8]);
238 zdcHit->SetLightPMQ(hits[7]);
239 zdcHit->SetLightPMC(hits[8]);
240 hits[7] = zdcHit->GetLightPMQ();
241 hits[8] = zdcHit->GetLightPMC();
242 // printf("\n Dopo ### Background -> PMQ = %f, PMC = %f\n",hits[7],hits[8]);
244 new (sdigits[NMhits++]) AliZDCHit(zdcHit);
245 // printf("\n NMhits = %d\n",NMhits);
249 fTrSDBgr->Write(0,TObject::kOverwrite);
254 // fBgrFile->Close();
258 //____________________________________________________________________________
259 void AliZDCMerger::ExtractSignal(Int_t detector, Int_t quadrant,
260 Float_t &fQuadLight, Float_t &fComLight)
263 // printf("\n Entering ExtractSignal method -> detector = %d quadrant = %d\n",
264 // detector, quadrant);
266 // Connect spectator n histo's file
267 fSpecnFile = TFile::Open("/home/oppedisa/alirun/ZNsignal.root");
270 TH1F *hPMQ1zn = (TH1F*) gDirectory->Get("hPMQ1zn;1");
271 TH1F *hPMQ2zn = (TH1F*) gDirectory->Get("hPMQ2zn;1");
272 TH1F *hPMQ3zn = (TH1F*) gDirectory->Get("hPMQ3zn;1");
273 TH1F *hPMQ4zn = (TH1F*) gDirectory->Get("hPMQ4zn;1");
274 TH1F *hPMC1zn = (TH1F*) gDirectory->Get("hPMC1zn;1");
275 TH1F *hPMC2zn = (TH1F*) gDirectory->Get("hPMC2zn;1");
276 TH1F *hPMC3zn = (TH1F*) gDirectory->Get("hPMC3zn;1");
277 TH1F *hPMC4zn = (TH1F*) gDirectory->Get("hPMC4zn;1");
278 // Axis_t x = hPMQ1zn -> GetRandom();
279 // printf(" hPMQ1zn -> GetRandom() = %f\n",x);
281 // Connect spectator p histo's file
282 fSpecpFile = TFile::Open("/home/oppedisa/alirun/ZPsignal.root");
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);