]> git.uio.no Git - u/mrichter/AliRoot.git/blame - ZDC/AliZDCDigitizer.cxx
macro to configure EMCAL trigger QA analysis
[u/mrichter/AliRoot.git] / ZDC / AliZDCDigitizer.cxx
CommitLineData
8309c1ab 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/* $Id$ */
17
18///////////////////////////////////////////////////////////////////////////////
19// //
20// ZDC digitizer class //
21// //
22///////////////////////////////////////////////////////////////////////////////
23
24#include <stdlib.h>
25
26// --- ROOT system
27#include <TTree.h>
28#include <TFile.h>
29#include <TNtuple.h>
30#include <TRandom.h>
31
32// --- AliRoot header files
33#include "AliLog.h"
34#include "AliRun.h"
35#include "AliHeader.h"
36#include "AliGenHijingEventHeader.h"
f21fc003 37#include "AliDigitizationInput.h"
8309c1ab 38#include "AliRunLoader.h"
c93255fe 39#include "AliLoader.h"
12434381 40#include "AliGRPObject.h"
78d18275 41#include "AliCDBManager.h"
48642b09 42#include "AliCDBEntry.h"
8309c1ab 43#include "AliZDCSDigit.h"
44#include "AliZDCDigit.h"
45#include "AliZDCFragment.h"
a18a0543 46#include "AliZDCv3.h"
8309c1ab 47#include "AliZDCDigitizer.h"
8a2624cc 48
49class AliCDBStorage;
6024ec85 50class AliZDCPedestals;
8309c1ab 51
52ClassImp(AliZDCDigitizer)
53
54
55//____________________________________________________________________________
a718c993 56AliZDCDigitizer::AliZDCDigitizer() :
57 fIsCalibration(0),
fd9afd60 58 fIsSignalInADCGate(kFALSE),
59 fFracLostSignal(0.),
a718c993 60 fPedData(0),
2d9c70ab 61 fSpectators2Track(kFALSE),
f2e2aa97 62 fBeamEnergy(0.),
63 fIspASystem(kFALSE)
8309c1ab 64{
698e394d 65 // Default constructor
83534754 66 for(Int_t i=0; i<2; i++) fADCRes[i]=0.;
8309c1ab 67}
68
69//____________________________________________________________________________
f21fc003 70AliZDCDigitizer::AliZDCDigitizer(AliDigitizationInput* digInput):
71 AliDigitizer(digInput),
a718c993 72 fIsCalibration(0), //By default the simulation doesn't create calib. data
fd9afd60 73 fIsSignalInADCGate(kFALSE),
74 fFracLostSignal(0.),
a718c993 75 fPedData(GetPedData()),
2d9c70ab 76 fSpectators2Track(kFALSE),
f2e2aa97 77 fBeamEnergy(0.),
78 fIspASystem(kFALSE)
8309c1ab 79{
78d18275 80 // Get calibration data
d27e20dd 81 if(fIsCalibration!=0) printf("\n\t AliZDCDigitizer -> Creating calibration data (pedestals)\n");
edb4e893 82 for(Int_t i=0; i<5; i++){
698e394d 83 for(Int_t j=0; j<5; j++)
84 fPMGain[i][j] = 0.;
85 }
8309c1ab 86}
87
88//____________________________________________________________________________
89AliZDCDigitizer::~AliZDCDigitizer()
90{
91// Destructor
a718c993 92// Not implemented
8309c1ab 93}
94
95
cc2abffd 96//____________________________________________________________________________
97AliZDCDigitizer::AliZDCDigitizer(const AliZDCDigitizer &digitizer):
a718c993 98 AliDigitizer(),
99 fIsCalibration(digitizer.fIsCalibration),
fd9afd60 100 fIsSignalInADCGate(digitizer.fIsSignalInADCGate),
101 fFracLostSignal(digitizer.fFracLostSignal),
a718c993 102 fPedData(digitizer.fPedData),
2d9c70ab 103 fSpectators2Track(digitizer.fSpectators2Track),
f2e2aa97 104 fBeamEnergy(digitizer.fBeamEnergy),
105 fIspASystem(digitizer.fIspASystem)
cc2abffd 106{
107 // Copy constructor
108
edb4e893 109 for(Int_t i=0; i<5; i++){
cc2abffd 110 for(Int_t j=0; j<5; j++){
111 fPMGain[i][j] = digitizer.fPMGain[i][j];
112 }
113 }
114 for(Int_t i=0; i<2; i++) fADCRes[i] = digitizer.fADCRes[i];
cc2abffd 115
12434381 116
cc2abffd 117}
118
8309c1ab 119//____________________________________________________________________________
120Bool_t AliZDCDigitizer::Init()
121{
48642b09 122 // Initialize the digitizer
12434381 123
124 AliCDBEntry* entry = AliCDBManager::Instance()->Get("GRP/GRP/Data");
83534754 125 if(!entry) AliFatal("No calibration data loaded!");
12434381 126 AliGRPObject* grpData = 0x0;
127 if(entry){
128 TMap* m = dynamic_cast<TMap*>(entry->GetObject()); // old GRP entry
129 if(m){
130 //m->Print();
131 grpData = new AliGRPObject();
132 grpData->ReadValuesFromMap(m);
133 }
134 else{
135 grpData = dynamic_cast<AliGRPObject*>(entry->GetObject()); // new GRP entry
136 }
137 entry->SetOwner(0);
138 AliCDBManager::Instance()->UnloadFromCache("GRP/GRP/Data");
139 }
83534754 140 if(!grpData){
141 AliError("No GRP entry found in OCDB! \n ");
142 return kFALSE;
143 }
12434381 144
145 TString beamType = grpData->GetBeamType();
146 if(beamType==AliGRPObject::GetInvalidString()){
147 AliError("\t UNKNOWN beam type from GRP obj -> PMT gains not set in ZDC digitizer!!!\n");
148 }
149
2d9c70ab 150 fBeamEnergy = grpData->GetBeamEnergy();
f2e2aa97 151 printf(" beam energy = %f GeV\n", fBeamEnergy);
2d9c70ab 152 if(fBeamEnergy==AliGRPObject::GetInvalidFloat()){
12434381 153 AliWarning("GRP/GRP/Data entry: missing value for the beam energy ! Using 0.");
154 AliError("\t UNKNOWN beam type from GRP obj -> PMT gains not set in ZDC digitizer!!!\n");
2d9c70ab 155 fBeamEnergy = 0.;
12434381 156 }
b553507a 157
96221dca 158 if((beamType.CompareTo("P-P")) == 0 || (beamType.CompareTo("p-p")) == 0 && !fIspASystem){
f2e2aa97 159 // PTM gains rescaled to beam energy for p-p
a66caee1 160 // New correction coefficients for PMT gains needed
161 // to reproduce experimental spectra (from Grazia Jul 2010)
2d9c70ab 162 if(fBeamEnergy != 0){
4df5e18f 163 for(Int_t j = 0; j < 5; j++){
164 fPMGain[0][j] = 1.515831*(661.444/fBeamEnergy+0.000740671)*10000000;
165 fPMGain[1][j] = 0.674234*(864.350/fBeamEnergy+0.00234375)*10000000;
166 fPMGain[3][j] = 1.350938*(661.444/fBeamEnergy+0.000740671)*10000000;
167 fPMGain[4][j] = 0.678597*(864.350/fBeamEnergy+0.00234375)*10000000;
168 }
169 fPMGain[2][1] = 0.869654*(1.32312-0.000101515*fBeamEnergy)*10000000;
170 fPMGain[2][2] = 1.030883*(1.32312-0.000101515*fBeamEnergy)*10000000;
dcb6916a 171 //
172 AliInfo(Form(" PMT gains for p-p @ %1.0f+%1.0f GeV: ZN(%1.0f), ZP(%1.0f), ZEM(%1.0f)\n",
173 fBeamEnergy, fBeamEnergy, fPMGain[0][0], fPMGain[1][0], fPMGain[2][1]));
12434381 174 }
f2e2aa97 175 else{ // for RELDIS simulation @ sqrt(s_{NN}) = 2.76 TeV
dcb6916a 176 Float_t scalGainFactor = 0.5;
a736fd93 177 for(Int_t j = 0; j < 5; j++){
dcf187b9 178 fPMGain[0][j] = 50000./scalGainFactor; // ZNC
179 fPMGain[1][j] = 100000./scalGainFactor; // ZPC
f2e2aa97 180 fPMGain[2][j] = 100000./scalGainFactor; // ZEM
dcf187b9 181 fPMGain[3][j] = 50000./scalGainFactor; // ZNA
182 fPMGain[4][j] = 100000./scalGainFactor; // ZPA
a736fd93 183 }
dcb6916a 184 //
185 AliInfo(Form(" PMT gains for RELDIS simulation: ZN(%1.0f), ZP(%1.0f), ZEM(%1.0f)\n",
186 fPMGain[0][0], fPMGain[1][0], fPMGain[2][1]));
a736fd93 187 }
12434381 188 }
96221dca 189 else if((beamType.CompareTo("A-A")) == 0 && !fIspASystem){
2d9c70ab 190 // PTM gains for Pb-Pb @ 2.7+2.7 A TeV ***************
191 // rescaled for Pb-Pb @ 1.38+1.38 A TeV ***************
a66caee1 192 // Values corrected after 2010 Pb-Pb data taking (7/2/2011 - Ch.)
193 // Experimental data compared to EMD simulation for single nucleon peaks:
194 // ZN gains must be divided by 4, ZP gains by 10!
2d9c70ab 195 Float_t scalGainFactor = fBeamEnergy/2760.;
12434381 196 for(Int_t j = 0; j < 5; j++){
dcb6916a 197 fPMGain[0][j] = 50000./(4*scalGainFactor); // ZNC
198 fPMGain[1][j] = 100000./(5*scalGainFactor); // ZPC
199 fPMGain[2][j] = 100000./scalGainFactor; // ZEM
200 fPMGain[3][j] = 50000./(4*scalGainFactor); // ZNA
201 fPMGain[4][j] = 100000./(5*scalGainFactor); // ZPA
12434381 202 }
2d9c70ab 203 AliInfo(Form(" PMT gains for Pb-Pb @ %1.0f+%1.0f A GeV: ZN(%1.0f), ZP(%1.0f), ZEM(%1.0f)\n",
4df5e18f 204 fBeamEnergy, fBeamEnergy, fPMGain[0][0], fPMGain[1][0], fPMGain[2][1]));
12434381 205 }
f2e2aa97 206
207 if(fIspASystem){
96221dca 208 // PTM gains for Pb-Pb @ 1.38+1.38 A TeV on side A
209 // PTM gains rescaled to beam energy for p-p on side C
210 // WARNING! Energies are set by hand for 2011 pA RUN!!!
211 Float_t scalGainFactor = 0.5;
f2e2aa97 212 Float_t fpBeamEnergy = 3500.;
213
214 for(Int_t j = 0; j < 5; j++){
96221dca 215 fPMGain[0][j] = 1.350938*(661.444/fpBeamEnergy+0.000740671)*10000000; //ZNC (p)
216 fPMGain[1][j] = 0.678597*(864.350/fpBeamEnergy+0.00234375)*10000000; //ZPC (p)
217 fPMGain[2][j] = 100000./scalGainFactor; // ZEM (Pb)
218 fPMGain[3][j] = 50000./(4*scalGainFactor); // ZNA (Pb)
219 fPMGain[4][j] = 100000./(5*scalGainFactor); // ZPA (Pb)
f2e2aa97 220 }
f2e2aa97 221 AliInfo(Form(" PMT gains for p-Pb: ZNC(%1.0f), ZPC(%1.0f), ZEM(%1.0f), ZNA(%1.0f) ZPA(%1.0f)\n",
222 fPMGain[0][0], fPMGain[1][0], fPMGain[2][1], fPMGain[3][0], fPMGain[4][0]));
223 }
698e394d 224
225 // ADC Caen V965
7f73eb6b 226 fADCRes[0] = 0.0000008; // ADC Resolution high gain: 200 fC/adcCh
227 fADCRes[1] = 0.0000064; // ADC Resolution low gain: 25 fC/adcCh
8309c1ab 228
229 return kTRUE;
230}
231
232//____________________________________________________________________________
f21fc003 233void AliZDCDigitizer::Digitize(Option_t* /*option*/)
8309c1ab 234{
48642b09 235 // Execute digitization
8309c1ab 236
d79f8d50 237 // ------------------------------------------------------------
f91d1e35 238 // !!! 2nd ZDC set added
239 // *** 1st 3 arrays are digits from REAL (simulated) hits
240 // *** last 2 are copied from simulated digits
fd9afd60 241 // --- pm[0][...] = light in ZN side C [C, Q1, Q2, Q3, Q4]
242 // --- pm[1][...] = light in ZP side C [C, Q1, Q2, Q3, Q4]
48642b09 243 // --- pm[2][...] = light in ZEM [x, 1, 2, x, x]
fd9afd60 244 // --- pm[3][...] = light in ZN side A [C, Q1, Q2, Q3, Q4] ->NEW!
245 // --- pm[4][...] = light in ZP side A [C, Q1, Q2, Q3, Q4] ->NEW!
d79f8d50 246 // ------------------------------------------------------------
247 Float_t pm[5][5];
8574b308 248 for(Int_t iSector1=0; iSector1<5; iSector1++)
249 for(Int_t iSector2=0; iSector2<5; iSector2++){
8309c1ab 250 pm[iSector1][iSector2] = 0;
251 }
d79f8d50 252
253 // ------------------------------------------------------------
254 // ### Out of time ADC added (22 channels)
255 // --- same codification as for signal PTMs (see above)
256 // ------------------------------------------------------------
257 Float_t pmoot[5][5];
8574b308 258 for(Int_t iSector1=0; iSector1<5; iSector1++)
259 for(Int_t iSector2=0; iSector2<5; iSector2++){
d79f8d50 260 pmoot[iSector1][iSector2] = 0;
261 }
8309c1ab 262
263 // impact parameter and number of spectators
131b5d31 264 Float_t impPar = 0;
fd9afd60 265 Int_t specNTarg = 0, specPTarg = 0;
266 Int_t specNProj = 0, specPProj = 0;
a18a0543 267 Float_t signalTime0 = 0.;
8309c1ab 268
269 // loop over input streams
f21fc003 270 for(Int_t iInput = 0; iInput<fDigInput->GetNinputs(); iInput++){
8309c1ab 271
272 // get run loader and ZDC loader
273 AliRunLoader* runLoader =
f21fc003 274 AliRunLoader::GetRunLoader(fDigInput->GetInputFolderName(iInput));
8309c1ab 275 AliLoader* loader = runLoader->GetLoader("ZDCLoader");
8574b308 276 if(!loader) continue;
8309c1ab 277
278 // load sdigits
279 loader->LoadSDigits();
280 TTree* treeS = loader->TreeS();
8574b308 281 if(!treeS) continue;
8309c1ab 282 AliZDCSDigit sdigit;
283 AliZDCSDigit* psdigit = &sdigit;
284 treeS->SetBranchAddress("ZDC", &psdigit);
285
286 // loop over sdigits
8574b308 287 for(Int_t iSDigit=0; iSDigit<treeS->GetEntries(); iSDigit++){
8309c1ab 288 treeS->GetEntry(iSDigit);
7f73eb6b 289 //
8574b308 290 if(!psdigit) continue;
291 if((sdigit.GetSector(1) < 0) || (sdigit.GetSector(1) > 4)){
8309c1ab 292 AliError(Form("\nsector[0] = %d, sector[1] = %d\n",
293 sdigit.GetSector(0), sdigit.GetSector(1)));
294 continue;
295 }
fd9afd60 296 // Checking if signal is inside ADC gate
297 if(iSDigit==0) signalTime0 = sdigit.GetTrackTime();
298 else{
299 // Assuming a signal lenght of 20 ns, signal is in gate if
300 // signal ENDS in signalTime0+50. -> sdigit.GetTrackTime()+20<=signalTime0+50.
301 if(sdigit.GetTrackTime()<=signalTime0+30.) fIsSignalInADCGate = kTRUE;
302 if(sdigit.GetTrackTime()>signalTime0+30.){
303 fIsSignalInADCGate = kFALSE;
304 // Vedi quaderno per spiegazione approx. usata
305 // nel calcolo della fraz. di segnale perso
306 fFracLostSignal = (sdigit.GetTrackTime()-30)*(sdigit.GetTrackTime()-30)/280.;
307 }
308 }
698e394d 309
fd9afd60 310 Float_t sdSignal = sdigit.GetLightPM();
311 if(fIsSignalInADCGate == kFALSE){
7e858b1d 312 AliDebug(2,Form("\t Signal time %f -> fraction %f of ZDC signal for det.(%d, %d) out of ADC gate\n",
0fba8107 313 sdigit.GetTrackTime(),fFracLostSignal,sdigit.GetSector(0),sdigit.GetSector(1)));
fd9afd60 314 sdSignal = (1-fFracLostSignal)*sdSignal;
315 }
316
48642b09 317 pm[(sdigit.GetSector(0))-1][sdigit.GetSector(1)] += sdigit.GetLightPM();
698e394d 318 //Ch. debug
319 /*printf("\t Detector %d, Tower %d -> pm[%d][%d] = %.0f \n",
48642b09 320 sdigit.GetSector(0), sdigit.GetSector(1),sdigit.GetSector(0)-1,
698e394d 321 sdigit.GetSector(1), pm[sdigit.GetSector(0)-1][sdigit.GetSector(1)]);
878fa0b3 322 */
fd9afd60 323
8309c1ab 324 }
325
8309c1ab 326 loader->UnloadSDigits();
327
328 // get the impact parameter and the number of spectators in case of hijing
8574b308 329 if(!runLoader->GetAliRun()) runLoader->LoadgAlice();
d3b3a3b2 330 AliHeader* header = runLoader->GetHeader();
8574b308 331 if(!header) continue;
8309c1ab 332 AliGenEventHeader* genHeader = header->GenEventHeader();
8574b308 333 if(!genHeader) continue;
334 if(!genHeader->InheritsFrom(AliGenHijingEventHeader::Class())) continue;
a18a0543 335
f2e2aa97 336 if(fSpectators2Track==kTRUE && fIspASystem==kFALSE){
a18a0543 337 impPar = ((AliGenHijingEventHeader*) genHeader)->ImpactParameter();
338 specNProj = ((AliGenHijingEventHeader*) genHeader)->ProjSpectatorsn();
339 specPProj = ((AliGenHijingEventHeader*) genHeader)->ProjSpectatorsp();
340 specNTarg = ((AliGenHijingEventHeader*) genHeader)->TargSpectatorsn();
341 specPTarg = ((AliGenHijingEventHeader*) genHeader)->TargSpectatorsp();
7fe9b721 342 /*printf("\n\t AliZDCDigitizer: b = %1.2f fm\n"
a18a0543 343 " \t PROJ.: #spectator n %d, #spectator p %d\n"
2413fd18 344 " \t TARG.: #spectator n %d, #spectator p %d\n",
7fe9b721 345 impPar, specNProj, specPProj, specNTarg, specPTarg);*/
a18a0543 346 }
347
8309c1ab 348 }
349
fd9afd60 350 // Applying fragmentation algorithm and adding spectator signal
f2e2aa97 351 if(fSpectators2Track==kTRUE && impPar && fIspASystem==kFALSE) {
fd9afd60 352 Int_t freeSpecNProj, freeSpecPProj;
353 Fragmentation(impPar, specNProj, specPProj, freeSpecNProj, freeSpecPProj);
354 Int_t freeSpecNTarg, freeSpecPTarg;
355 Fragmentation(impPar, specNTarg, specPTarg, freeSpecNTarg, freeSpecPTarg);
356 SpectatorSignal(1, freeSpecNProj, pm);
7fe9b721 357// printf("\t AliZDCDigitizer -> Adding signal for %d PROJ free spectator n",freeSpecNProj);
fd9afd60 358 SpectatorSignal(2, freeSpecPProj, pm);
7fe9b721 359// printf(" and %d free spectator p\n",freeSpecPProj);
fd9afd60 360 SpectatorSignal(3, freeSpecNTarg, pm);
7fe9b721 361// printf("\t AliZDCDigitizer -> Adding signal for %d TARG free spectator n",freeSpecNTarg);
fd9afd60 362 SpectatorSignal(4, freeSpecPTarg, pm);
7fe9b721 363// printf(" and %d free spectator p\n\n",freeSpecPTarg);
8309c1ab 364 }
365
8a2624cc 366
8309c1ab 367 // get the output run loader and loader
368 AliRunLoader* runLoader =
f21fc003 369 AliRunLoader::GetRunLoader(fDigInput->GetOutputFolderName());
8309c1ab 370 AliLoader* loader = runLoader->GetLoader("ZDCLoader");
8574b308 371 if(!loader) {
8309c1ab 372 AliError("no ZDC loader found");
373 return;
374 }
375
376 // create the output tree
377 const char* mode = "update";
8574b308 378 if(runLoader->GetEventNumber() == 0) mode = "recreate";
8309c1ab 379 loader->LoadDigits(mode);
380 loader->MakeTree("D");
381 TTree* treeD = loader->TreeD();
382 AliZDCDigit digit;
383 AliZDCDigit* pdigit = &digit;
384 const Int_t kBufferSize = 4000;
385 treeD->Branch("ZDC", "AliZDCDigit", &pdigit, kBufferSize);
386
387 // Create digits
80e87581 388 Int_t sector[2];
389 Int_t digi[2], digioot[2];
390 for(sector[0]=1; sector[0]<6; sector[0]++){
abf60186 391 for(sector[1]=0; sector[1]<5; sector[1]++){
392 if((sector[0]==3) && ((sector[1]<1) || (sector[1]>2))) continue;
8574b308 393 for(Int_t res=0; res<2; res++){
abf60186 394 digi[res] = Phe2ADCch(sector[0], sector[1], pm[sector[0]-1][sector[1]], res)
48642b09 395 + Pedestal(sector[0], sector[1], res);
7f73eb6b 396 }
abf60186 397 new(pdigit) AliZDCDigit(sector, digi);
8309c1ab 398 treeD->Fill();
698e394d 399
400 //Ch. debug
401 //printf("\t DIGIT added -> det %d quad %d - digi[0,1] = [%d, %d]\n",
402 // sector[0], sector[1], digi[0], digi[1]); // Chiara debugging!
403
8309c1ab 404 }
83347831 405 } // Loop over detector
406 // Adding in-time digits for 2 reference PTM signals (after signal ch.)
407 // (for the moment the ref. signal is completely invented assuming a PMgain of 5*10^4!)
408 Int_t sectorRef[2];
409 sectorRef[1] = 5;
9d38ced8 410 Int_t sigRef[2];
80e87581 411 // Reference signal are set to 100 (high gain chain) and 800 (low gain chain)
9d38ced8 412 if(fIsCalibration==0) {sigRef[0]=100; sigRef[1]=800;}
80e87581 413 else {sigRef[0]=0; sigRef[1]=0;} // calibration -> simulation of pedestal values
9d38ced8 414 //
83347831 415 for(Int_t iref=0; iref<2; iref++){
416 sectorRef[0] = 3*iref+1;
417 for(Int_t res=0; res<2; res++){
418 sigRef[res] += Pedestal(sectorRef[0], sectorRef[1], res);
419 }
83347831 420 new(pdigit) AliZDCDigit(sectorRef, sigRef);
421 treeD->Fill();
698e394d 422
423 //Ch. debug
424 //printf("\t RefDigit added -> det = %d, quad = %d - digi[0,1] = [%d, %d]\n",
425 // sectorRef[0], sectorRef[1], sigRef[0], sigRef[1]); // Chiara debugging!
abf60186 426 }
d79f8d50 427 //
428 // --- Adding digits for out-of-time channels after signal digits
80e87581 429 for(sector[0]=1; sector[0]<6; sector[0]++){
d79f8d50 430 for(sector[1]=0; sector[1]<5; sector[1]++){
431 if((sector[0]==3) && ((sector[1]<1) || (sector[1]>2))) continue;
8574b308 432 for(Int_t res=0; res<2; res++){
d79f8d50 433 digioot[res] = Pedestal(sector[0], sector[1], res); // out-of-time ADCs
434 }
d79f8d50 435 new(pdigit) AliZDCDigit(sector, digioot);
436 treeD->Fill();
698e394d 437
438 //Ch. debug
439 //printf("\t DIGIToot added -> det = %d, quad = %d - digi[0,1] = [%d, %d]\n",
440 // sector[0], sector[1], digioot[0], digioot[1]); // Chiara debugging!
d79f8d50 441 }
442 }
83347831 443 // Adding out-of-time digits for 2 reference PTM signals (after out-of-time ch.)
444 Int_t sigRefoot[2];
445 for(Int_t iref=0; iref<2; iref++){
446 sectorRef[0] = 3*iref+1;
447 for(Int_t res=0; res<2; res++){
448 sigRefoot[res] = Pedestal(sectorRef[0], sectorRef[1], res);
449 }
83347831 450 new(pdigit) AliZDCDigit(sectorRef, sigRefoot);
451 treeD->Fill();
698e394d 452 //Ch. debug
453 //printf("\t RefDigitoot added -> det = %d, quad = %d - digi[0,1] = [%d, %d]\n",
454 // sectorRef[0], sectorRef[1], sigRefoot[0], sigRefoot[1]); // Chiara debugging!
455
83347831 456 }
457 //printf("\t AliZDCDigitizer -> TreeD has %d entries\n",(Int_t) treeD->GetEntries());
458
8309c1ab 459 // write the output tree
460 loader->WriteDigits("OVERWRITE");
461 loader->UnloadDigits();
462}
463
464
465//_____________________________________________________________________________
466void AliZDCDigitizer::Fragmentation(Float_t impPar, Int_t specN, Int_t specP,
467 Int_t &freeSpecN, Int_t &freeSpecP) const
468{
469// simulate fragmentation of spectators
470
8309c1ab 471 AliZDCFragment frag(impPar);
8309c1ab 472
473 // Fragments generation
92339a90 474 frag.GenerateIMF();
475 Int_t nAlpha = frag.GetNalpha();
8309c1ab 476
477 // Attach neutrons
98711e01 478 frag.AttachNeutrons();
92339a90 479 Int_t ztot = frag.GetZtot();
480 Int_t ntot = frag.GetNtot();
98711e01 481
482 // Removing fragments and alpha pcs
8309c1ab 483 freeSpecN = specN-ntot-2*nAlpha;
484 freeSpecP = specP-ztot-2*nAlpha;
98711e01 485
3848c666 486 // Removing deuterons
a0607c1f 487 Int_t ndeu = (Int_t) (freeSpecN*frag.DeuteronNumber());
3848c666 488 freeSpecN -= ndeu;
98711e01 489 freeSpecP -= ndeu;
3848c666 490 //
8309c1ab 491 if(freeSpecN<0) freeSpecN=0;
492 if(freeSpecP<0) freeSpecP=0;
493 AliDebug(2, Form("FreeSpn = %d, FreeSpp = %d", freeSpecN, freeSpecP));
494}
495
496//_____________________________________________________________________________
497void AliZDCDigitizer::SpectatorSignal(Int_t SpecType, Int_t numEvents,
fd9afd60 498 Float_t pm[5][5]) const
8309c1ab 499{
500// add signal of the spectators
fd9afd60 501
2d9c70ab 502 TFile *specSignalFile = TFile::Open("$ALICE_ROOT/ZDC/SpectatorSignal.root");
503 if(!specSignalFile || !specSignalFile->IsOpen()) {
504 AliError((" Opening file $ALICE_ROOT/ZDC/SpectatorSignal.root failed\n"));
505 return;
8309c1ab 506 }
2d9c70ab 507
e7eabc21 508 TNtuple* zdcSignal=0x0;
2d9c70ab 509
510 Float_t sqrtS = 2*fBeamEnergy;
511 //
512 if(TMath::Abs(sqrtS-5500) < 100.){
513 specSignalFile->cd("energy5500");
514 //
515 if(SpecType == 1) { // --- Signal for projectile spectator neutrons
516 specSignalFile->GetObject("energy5500/ZNCSignal;1",zdcSignal);
517 if(!zdcSignal) AliError(" PROBLEM!!! Can't retrieve ZNCSignal from SpectatorSignal.root file");
518 }
519 else if(SpecType == 2) { // --- Signal for projectile spectator protons
520 specSignalFile->GetObject("energy5500/ZPCSignal;1",zdcSignal);
521 if(!zdcSignal) AliError(" PROBLEM!!! Can't retrieve ZPCSignal from SpectatorSignal.root file");
522 }
523 else if(SpecType == 3) { // --- Signal for target spectator neutrons
524 specSignalFile->GetObject("energy5500/ZNASignal;1",zdcSignal);
525 if(!zdcSignal) AliError(" PROBLEM!!! Can't retrieve ZNASignal from SpectatorSignal.root file");
526 }
527 else if(SpecType == 4) { // --- Signal for target spectator protons
528 specSignalFile->GetObject("energy5500/ZPASignal;1",zdcSignal);
529 if(!zdcSignal) AliError(" PROBLEM!!! Can't retrieve ZPASignal from SpectatorSignal.root file");
530 }
fd9afd60 531 }
2d9c70ab 532 else if(TMath::Abs(sqrtS-2760) < 100.){
533 specSignalFile->cd("energy2760");
534 //
535 if(SpecType == 1) { // --- Signal for projectile spectator neutrons
536 specSignalFile->GetObject("energy2760/ZNCSignal;1",zdcSignal);
537 if(!zdcSignal) AliError(" PROBLEM!!! Can't retrieve ZNCSignal from SpectatorSignal.root file");
538 }
539 else if(SpecType == 2) { // --- Signal for projectile spectator protons
540 specSignalFile->GetObject("energy2760/ZPCSignal;1",zdcSignal);
541 if(!zdcSignal) AliError(" PROBLEM!!! Can't retrieve ZPCSignal from SpectatorSignal.root file");
542 }
543 else if(SpecType == 3) { // --- Signal for target spectator neutrons
544 specSignalFile->GetObject("energy2760/ZNASignal;1",zdcSignal);
545 if(!zdcSignal) AliError(" PROBLEM!!! Can't retrieve ZNASignal from SpectatorSignal.root file");
546 }
547 else if(SpecType == 4) { // --- Signal for target spectator protons
548 specSignalFile->GetObject("energy2760/ZPASignal;1",zdcSignal);
549 if(!zdcSignal) AliError(" PROBLEM!!! Can't retrieve ZPASignal from SpectatorSignal.root file");
550 }
fd9afd60 551 }
552
83534754 553 if(!zdcSignal){
554 printf("\n No spectator signal available for ZDC digitization\n");
555 return;
556 }
557
8309c1ab 558 Int_t nentries = (Int_t) zdcSignal->GetEntries();
559
fd9afd60 560 Float_t *entry;
561 Int_t pl, i, k, iev=0, rnd[125], volume[2];
48642b09 562 for(pl=0;pl<125;pl++) rnd[pl] = 0;
8574b308 563 if(numEvents > 125) {
fea9b334 564 AliDebug(2,Form("numEvents (%d) is larger than 125", numEvents));
8309c1ab 565 numEvents = 125;
566 }
567 for(pl=0;pl<numEvents;pl++){
568 rnd[pl] = (Int_t) (9999*gRandom->Rndm());
85a96223 569 if(rnd[pl] >= 9999) rnd[pl] = 9998;
8309c1ab 570 //printf(" rnd[%d] = %d\n",pl,rnd[pl]);
571 }
572 // Sorting vector in ascending order with C function QSORT
573 qsort((void*)rnd,numEvents,sizeof(Int_t),comp);
574 do{
575 for(i=0; i<nentries; i++){
576 zdcSignal->GetEvent(i);
577 entry = zdcSignal->GetArgs();
578 if(entry[0] == rnd[iev]){
579 for(k=0; k<2; k++) volume[k] = (Int_t) entry[k+1];
48642b09 580 //
fd9afd60 581 Float_t lightQ = entry[7];
582 Float_t lightC = entry[8];
583 //
acf9550c 584 if(volume[0] != 3) { // ZN or ZP
8309c1ab 585 pm[volume[0]-1][0] += lightC;
586 pm[volume[0]-1][volume[1]] += lightQ;
48642b09 587 //printf("\n pm[%d][0] = %.0f, pm[%d][%d] = %.0f\n",(volume[0]-1),pm[volume[0]-1][0],
588 // (volume[0]-1),volume[1],pm[volume[0]-1][volume[1]]);
589 }
590 else {
8574b308 591 if(volume[1] == 1) pm[2][1] += lightC; // ZEM 1
acf9550c 592 else pm[2][2] += lightQ; // ZEM 2
48642b09 593 //printf("\n pm[2][1] = %.0f, pm[2][2] = %.0f\n",pm[2][1],pm[2][2]);
594 }
8309c1ab 595 }
596 else if(entry[0] > rnd[iev]){
597 iev++;
598 continue;
599 }
600 }
601 }while(iev<numEvents);
602
2d9c70ab 603 specSignalFile->Close();
604 delete specSignalFile;
8309c1ab 605}
606
607
608//_____________________________________________________________________________
609Int_t AliZDCDigitizer::Phe2ADCch(Int_t Det, Int_t Quad, Float_t Light,
610 Int_t Res) const
611{
48642b09 612 // Evaluation of the ADC channel corresponding to the light yield Light
8a2624cc 613 Int_t vADCch = (Int_t) (Light * fPMGain[Det-1][Quad] * fADCRes[Res]);
698e394d 614 // Ch. debug
615 //printf("\t Phe2ADCch -> det %d quad %d - PMGain[%d][%d] %1.0f phe %1.2f ADC %d\n",
616 // Det,Quad,Det-1,Quad,fPMGain[Det-1][Quad],Light,vADCch);
7f73eb6b 617
8a2624cc 618 return vADCch;
48642b09 619}
8309c1ab 620
48642b09 621//_____________________________________________________________________________
622Int_t AliZDCDigitizer::Pedestal(Int_t Det, Int_t Quad, Int_t Res) const
623{
8a2624cc 624 // Returns a pedestal for detector det, PM quad, channel with res.
625 //
65b16e87 626 Float_t pedValue;
abf60186 627 // Normal run
628 if(fIsCalibration == 0){
c35ed519 629 Int_t index=0, kNch=24;
83347831 630 if(Quad!=5){
c35ed519 631 if(Det==1) index = Quad+kNch*Res; // ZNC
632 else if(Det==2) index = (Quad+5)+kNch*Res; // ZPC
633 else if(Det==3) index = (Quad+9)+kNch*Res; // ZEM
634 else if(Det==4) index = (Quad+12)+kNch*Res; // ZNA
635 else if(Det==5) index = (Quad+17)+kNch*Res; // ZPA
83347831 636 }
c35ed519 637 else index = (Det-1)/3+22+kNch*Res; // Reference PMs
83347831 638 //
c35ed519 639 Float_t meanPed = fPedData->GetMeanPed(index);
640 Float_t pedWidth = fPedData->GetMeanPedWidth(index);
65b16e87 641 pedValue = gRandom->Gaus(meanPed,pedWidth);
abf60186 642 //
58e12fee 643 /*printf("\t AliZDCDigitizer::Pedestal -> det %d quad %d res %d - Ped[%d] = %d\n",
65b16e87 644 Det, Quad, Res, index,(Int_t) pedValue); // Chiara debugging!
abf60186 645 */
646 }
7f73eb6b 647 // To create calibration object
83347831 648 else{
65b16e87 649 if(Res == 0) pedValue = gRandom->Gaus((35.+10.*gRandom->Rndm()),(0.5+0.2*gRandom->Rndm())); //High gain
650 else pedValue = gRandom->Gaus((250.+100.*gRandom->Rndm()),(3.5+2.*gRandom->Rndm())); //Low gain
83347831 651 }
dbc8d7fc 652
65b16e87 653 return (Int_t) pedValue;
8309c1ab 654}
655
656//_____________________________________________________________________________
78d18275 657AliCDBStorage* AliZDCDigitizer::SetStorage(const char *uri)
8309c1ab 658{
8309c1ab 659
78d18275 660 Bool_t deleteManager = kFALSE;
48642b09 661
78d18275 662 AliCDBManager *manager = AliCDBManager::Instance();
663 AliCDBStorage *defstorage = manager->GetDefaultStorage();
48642b09 664
78d18275 665 if(!defstorage || !(defstorage->Contains("ZDC"))){
666 AliWarning("No default storage set or default storage doesn't contain ZDC!");
667 manager->SetDefaultStorage(uri);
668 deleteManager = kTRUE;
669 }
670
671 AliCDBStorage *storage = manager->GetDefaultStorage();
672
673 if(deleteManager){
674 AliCDBManager::Instance()->UnsetDefaultStorage();
675 defstorage = 0; // the storage is killed by AliCDBManager::Instance()->Destroy()
676 }
677
678 return storage;
679}
48642b09 680
78d18275 681//_____________________________________________________________________________
6024ec85 682AliZDCPedestals* AliZDCDigitizer::GetPedData() const
683{
684
685 // Getting pedestal calibration object for ZDC set
686
687 AliCDBEntry *entry = AliCDBManager::Instance()->Get("ZDC/Calib/Pedestals");
688 if(!entry) AliFatal("No calibration data loaded!");
689
690 AliZDCPedestals *calibdata = dynamic_cast<AliZDCPedestals*> (entry->GetObject());
691 if(!calibdata) AliFatal("Wrong calibration object in calibration file!");
692
693 return calibdata;
694}
f91d1e35 695