]>
Commit | Line | Data |
---|---|---|
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" | |
37 | #include "AliRunDigitizer.h" | |
38 | #include "AliRunLoader.h" | |
78d18275 | 39 | #include "AliCDBManager.h" |
48642b09 | 40 | #include "AliCDBEntry.h" |
8309c1ab | 41 | #include "AliZDCSDigit.h" |
42 | #include "AliZDCDigit.h" | |
43 | #include "AliZDCFragment.h" | |
44 | #include "AliZDCDigitizer.h" | |
8a2624cc | 45 | |
46 | class AliCDBStorage; | |
47 | class AliZDCCalibData; | |
8309c1ab | 48 | |
49 | ClassImp(AliZDCDigitizer) | |
50 | ||
51 | ||
52 | //____________________________________________________________________________ | |
53 | AliZDCDigitizer::AliZDCDigitizer() | |
54 | { | |
55 | // Default constructor | |
56 | ||
57 | } | |
58 | ||
59 | //____________________________________________________________________________ | |
60 | AliZDCDigitizer::AliZDCDigitizer(AliRunDigitizer* manager): | |
61 | AliDigitizer(manager) | |
62 | { | |
78d18275 | 63 | |
48642b09 | 64 | // Constructor |
78d18275 | 65 | fStorage = SetStorage("local://$ALICE_ROOT"); |
66 | ||
67 | // Get calibration data | |
7f73eb6b | 68 | fCalibData = GetCalibData(); |
78d18275 | 69 | |
8309c1ab | 70 | } |
71 | ||
72 | //____________________________________________________________________________ | |
73 | AliZDCDigitizer::~AliZDCDigitizer() | |
74 | { | |
75 | // Destructor | |
76 | ||
77 | } | |
78 | ||
79 | ||
80 | //____________________________________________________________________________ | |
81 | Bool_t AliZDCDigitizer::Init() | |
82 | { | |
48642b09 | 83 | // Initialize the digitizer |
84 | // NB -> PM gain vs. HV & ADC resolutions will move to DCDB *************** | |
7f73eb6b | 85 | for(Int_t j = 0; j < 5; j++){ |
86 | fPMGain[0][j] = 50000.; | |
87 | fPMGain[1][j] = 100000.; | |
88 | fPMGain[2][j] = 100000.; | |
a017f01b | 89 | fPMGain[3][j] = 50000.; |
90 | fPMGain[4][j] = 100000.; | |
91 | fPMGain[5][j] = 100000.; | |
7f73eb6b | 92 | } |
93 | // ADC Caen V965 | |
94 | fADCRes[0] = 0.0000008; // ADC Resolution high gain: 200 fC/adcCh | |
95 | fADCRes[1] = 0.0000064; // ADC Resolution low gain: 25 fC/adcCh | |
8309c1ab | 96 | |
97 | return kTRUE; | |
98 | } | |
99 | ||
100 | //____________________________________________________________________________ | |
101 | void AliZDCDigitizer::Exec(Option_t* /*option*/) | |
102 | { | |
48642b09 | 103 | // Execute digitization |
8309c1ab | 104 | |
7f73eb6b | 105 | Float_t pm[5][5]; // !!! 2nd ZDC set added (needed for trigger purposes!) |
106 | // *** 1st 3 arrays are digits from REAL (simulated) hits | |
107 | // *** last 2 are copied from simulated digits | |
108 | // --- pm[0][...] = light in ZN right [C, Q1, Q2, Q3, Q4] | |
109 | // --- pm[1][...] = light in ZP right [C, Q1, Q2, Q3, Q4] | |
48642b09 | 110 | // --- pm[2][...] = light in ZEM [x, 1, 2, x, x] |
7f73eb6b | 111 | // --- pm[3][...] = light in ZN left [C, Q1, Q2, Q3, Q4] ->NEW! |
112 | // --- pm[4][...] = light in ZP left [C, Q1, Q2, Q3, Q4] ->NEW! | |
113 | ||
114 | for (Int_t iSector1=0; iSector1<5; iSector1++) | |
115 | for (Int_t iSector2=0; iSector2<5; iSector2++) { | |
8309c1ab | 116 | pm[iSector1][iSector2] = 0; |
117 | } | |
8309c1ab | 118 | |
119 | // impact parameter and number of spectators | |
120 | Float_t impPar = -1; | |
121 | Int_t specN = 0; | |
122 | Int_t specP = 0; | |
123 | ||
124 | // loop over input streams | |
7f73eb6b | 125 | for (Int_t iInput = 0; iInput<fManager->GetNinputs(); iInput++) { |
8309c1ab | 126 | |
127 | // get run loader and ZDC loader | |
128 | AliRunLoader* runLoader = | |
129 | AliRunLoader::GetRunLoader(fManager->GetInputFolderName(iInput)); | |
130 | AliLoader* loader = runLoader->GetLoader("ZDCLoader"); | |
131 | if (!loader) continue; | |
132 | ||
133 | // load sdigits | |
134 | loader->LoadSDigits(); | |
135 | TTree* treeS = loader->TreeS(); | |
136 | if (!treeS) continue; | |
137 | AliZDCSDigit sdigit; | |
138 | AliZDCSDigit* psdigit = &sdigit; | |
139 | treeS->SetBranchAddress("ZDC", &psdigit); | |
140 | ||
141 | // loop over sdigits | |
7f73eb6b | 142 | for (Int_t iSDigit=0; iSDigit<treeS->GetEntries(); iSDigit++) { |
8309c1ab | 143 | treeS->GetEntry(iSDigit); |
7f73eb6b | 144 | // |
8309c1ab | 145 | if (!psdigit) continue; |
8309c1ab | 146 | if ((sdigit.GetSector(1) < 0) || (sdigit.GetSector(1) > 4)) { |
147 | AliError(Form("\nsector[0] = %d, sector[1] = %d\n", | |
148 | sdigit.GetSector(0), sdigit.GetSector(1))); | |
149 | continue; | |
150 | } | |
7f73eb6b | 151 | // |
48642b09 | 152 | pm[(sdigit.GetSector(0))-1][sdigit.GetSector(1)] += sdigit.GetLightPM(); |
7f73eb6b | 153 | /*printf("\n\t Detector %d, Tower %d -> pm[%d][%d] = %.0f \n", |
48642b09 | 154 | sdigit.GetSector(0), sdigit.GetSector(1),sdigit.GetSector(0)-1, |
155 | sdigit.GetSector(1), pm[sdigit.GetSector(0)-1][sdigit.GetSector(1)]); // Chiara debugging! | |
7f73eb6b | 156 | */ |
8309c1ab | 157 | } |
158 | ||
8309c1ab | 159 | loader->UnloadSDigits(); |
160 | ||
161 | // get the impact parameter and the number of spectators in case of hijing | |
162 | if (!runLoader->GetAliRun()) runLoader->LoadgAlice(); | |
163 | AliHeader* header = runLoader->GetAliRun()->GetHeader(); | |
164 | if (!header) continue; | |
165 | AliGenEventHeader* genHeader = header->GenEventHeader(); | |
166 | if (!genHeader) continue; | |
167 | if (!genHeader->InheritsFrom(AliGenHijingEventHeader::Class())) continue; | |
168 | impPar = ((AliGenHijingEventHeader*) genHeader)->ImpactParameter(); | |
85a96223 | 169 | // |
170 | specN = ((AliGenHijingEventHeader*) genHeader)->ProjSpectatorsn(); | |
171 | specP = ((AliGenHijingEventHeader*) genHeader)->ProjSpectatorsp(); | |
78d18275 | 172 | AliDebug(2, Form("\n AliZDCDigitizer -> b = %f fm, Nspecn = %d, Nspecp = %d\n", |
8309c1ab | 173 | impPar, specN, specP)); |
7f73eb6b | 174 | printf("\n\t AliZDCDigitizer -> b = %f fm, Nspecn = %d, Nspecp = %d\n", impPar, specN, specP); |
8309c1ab | 175 | } |
176 | ||
177 | // add spectators | |
178 | if (impPar >= 0) { | |
179 | Int_t freeSpecN, freeSpecP; | |
180 | Fragmentation(impPar, specN, specP, freeSpecN, freeSpecP); | |
78d18275 | 181 | printf("\n\t AliZDCDigitizer ---- Adding signal for %d free spectator n\n",freeSpecN); |
8309c1ab | 182 | SpectatorSignal(1, freeSpecN, pm); |
78d18275 | 183 | printf("\t AliZDCDigitizer ---- Adding signal for %d free spectator p\n\n",freeSpecP); |
8309c1ab | 184 | SpectatorSignal(2, freeSpecP, pm); |
185 | } | |
186 | ||
8a2624cc | 187 | |
8309c1ab | 188 | // get the output run loader and loader |
189 | AliRunLoader* runLoader = | |
190 | AliRunLoader::GetRunLoader(fManager->GetOutputFolderName()); | |
191 | AliLoader* loader = runLoader->GetLoader("ZDCLoader"); | |
192 | if (!loader) { | |
193 | AliError("no ZDC loader found"); | |
194 | return; | |
195 | } | |
196 | ||
197 | // create the output tree | |
198 | const char* mode = "update"; | |
199 | if (runLoader->GetEventNumber() == 0) mode = "recreate"; | |
200 | loader->LoadDigits(mode); | |
201 | loader->MakeTree("D"); | |
202 | TTree* treeD = loader->TreeD(); | |
203 | AliZDCDigit digit; | |
204 | AliZDCDigit* pdigit = &digit; | |
205 | const Int_t kBufferSize = 4000; | |
206 | treeD->Branch("ZDC", "AliZDCDigit", &pdigit, kBufferSize); | |
207 | ||
208 | // Create digits | |
7f73eb6b | 209 | Int_t sector[2], sectorL[2]; |
210 | Int_t digi[2], digiL[2]; | |
211 | for (sector[0]=1; sector[0]<=3; sector[0]++) | |
212 | for (sector[1]=0; sector[1]<5; sector[1]++) { | |
213 | if ((sector[0]==3) && ((sector[1]<1) || (sector[1]>2))) continue; | |
214 | for (Int_t res=0; res<2; res++){ | |
48642b09 | 215 | digi[res] = Phe2ADCch(sector[0], sector[1], pm[sector[0]-1][sector[1]], res) |
216 | + Pedestal(sector[0], sector[1], res); | |
7f73eb6b | 217 | } |
218 | //printf("\t DIGIT added -> det = %d, quad = %d - digi[0,1] = [%d, %d]\n", | |
219 | // sector[0], sector[1], digi[0], digi[1]); // Chiara debugging! | |
8309c1ab | 220 | new(pdigit) AliZDCDigit(sector, digi); |
221 | treeD->Fill(); | |
7f73eb6b | 222 | // |
223 | // --- Adding digits for 2nd ZDC set (left side w.r.t. IP) --- | |
224 | // --- they are copied from right ZDC digits | |
225 | if(sector[0]==1 || sector[0]==2){ | |
226 | sectorL[0] = sector[0]+3; | |
227 | sectorL[1] = sector[1]; | |
228 | for (Int_t res=0; res<2; res++){ | |
229 | digiL[res] = Phe2ADCch(sectorL[0], sectorL[1], pm[sector[0]-1][sector[1]], res) | |
230 | + Pedestal(sectorL[0], sectorL[1], res); | |
231 | } | |
232 | //printf("\t DIGIT added -> det = %d, quad = %d - digi[0,1] = [%d, %d]\n", | |
233 | // sectorL[0], sectorL[1], digiL[0], digiL[1]); // Chiara debugging! | |
234 | new(pdigit) AliZDCDigit(sectorL, digiL); | |
235 | } | |
236 | // | |
237 | treeD->Fill(); | |
8309c1ab | 238 | } |
239 | ||
240 | // write the output tree | |
241 | loader->WriteDigits("OVERWRITE"); | |
242 | loader->UnloadDigits(); | |
243 | } | |
244 | ||
245 | ||
246 | //_____________________________________________________________________________ | |
247 | void AliZDCDigitizer::Fragmentation(Float_t impPar, Int_t specN, Int_t specP, | |
248 | Int_t &freeSpecN, Int_t &freeSpecP) const | |
249 | { | |
250 | // simulate fragmentation of spectators | |
251 | ||
252 | Int_t zz[100], nn[100]; | |
253 | AliZDCFragment frag(impPar); | |
254 | for (Int_t j=0; j<=99; j++){ | |
255 | zz[j] =0; | |
256 | nn[j] =0; | |
257 | } | |
258 | ||
259 | // Fragments generation | |
260 | Int_t nAlpha; | |
261 | frag.GenerateIMF(zz, nAlpha); | |
262 | ||
263 | // Attach neutrons | |
264 | Int_t ztot=0; | |
265 | Int_t ntot=0; | |
266 | frag.AttachNeutrons(zz, nn, ztot, ntot); | |
267 | freeSpecN = specN-ntot-2*nAlpha; | |
268 | freeSpecP = specP-ztot-2*nAlpha; | |
269 | if(freeSpecN<0) freeSpecN=0; | |
270 | if(freeSpecP<0) freeSpecP=0; | |
271 | AliDebug(2, Form("FreeSpn = %d, FreeSpp = %d", freeSpecN, freeSpecP)); | |
272 | } | |
273 | ||
274 | //_____________________________________________________________________________ | |
275 | void AliZDCDigitizer::SpectatorSignal(Int_t SpecType, Int_t numEvents, | |
276 | Float_t pm[3][5]) const | |
277 | { | |
278 | // add signal of the spectators | |
279 | ||
280 | TFile* file = NULL; | |
281 | if (SpecType == 1) { // --- Signal for spectator neutrons | |
282 | file = TFile::Open("$ALICE/$ALICE_LEVEL/ZDC/ZNsignalntu.root"); | |
283 | } else if (SpecType == 2) { // --- Signal for spectator protons | |
284 | file = TFile::Open("$ALICE/$ALICE_LEVEL/ZDC/ZPsignalntu.root"); | |
285 | } | |
286 | if (!file || !file->IsOpen()) { | |
287 | AliError("Opening of file failed"); | |
288 | return; | |
289 | } | |
290 | ||
291 | TNtuple* zdcSignal = (TNtuple*) file->Get("ZDCSignal"); | |
292 | Int_t nentries = (Int_t) zdcSignal->GetEntries(); | |
293 | ||
294 | Float_t *entry, hitsSpec[7]; | |
295 | Int_t pl, i, j, k, iev=0, rnd[125], volume[2]; | |
48642b09 | 296 | for(pl=0;pl<125;pl++) rnd[pl] = 0; |
8309c1ab | 297 | if (numEvents > 125) { |
298 | AliWarning(Form("numEvents (%d) is larger than 125", numEvents)); | |
299 | numEvents = 125; | |
300 | } | |
301 | for(pl=0;pl<numEvents;pl++){ | |
302 | rnd[pl] = (Int_t) (9999*gRandom->Rndm()); | |
85a96223 | 303 | if(rnd[pl] >= 9999) rnd[pl] = 9998; |
8309c1ab | 304 | //printf(" rnd[%d] = %d\n",pl,rnd[pl]); |
305 | } | |
306 | // Sorting vector in ascending order with C function QSORT | |
307 | qsort((void*)rnd,numEvents,sizeof(Int_t),comp); | |
308 | do{ | |
309 | for(i=0; i<nentries; i++){ | |
310 | zdcSignal->GetEvent(i); | |
311 | entry = zdcSignal->GetArgs(); | |
312 | if(entry[0] == rnd[iev]){ | |
313 | for(k=0; k<2; k++) volume[k] = (Int_t) entry[k+1]; | |
314 | for(j=0; j<7; j++) hitsSpec[j] = entry[j+3]; | |
48642b09 | 315 | // |
8309c1ab | 316 | Float_t lightQ = hitsSpec[4]; |
317 | Float_t lightC = hitsSpec[5]; | |
78d18275 | 318 | AliDebug(3, Form("SpectatorSignal -> vol = (%d, %d), lightQ = %.0f, lightC = %.0f", |
8309c1ab | 319 | volume[0], volume[1], lightQ, lightC)); |
48642b09 | 320 | //printf("\n Volume = (%d, %d), lightQ = %.0f, lightC = %.0f", |
321 | // volume[0], volume[1], lightQ, lightC); | |
8309c1ab | 322 | if (volume[0] < 3) { // ZN or ZP |
323 | pm[volume[0]-1][0] += lightC; | |
324 | pm[volume[0]-1][volume[1]] += lightQ; | |
48642b09 | 325 | //printf("\n pm[%d][0] = %.0f, pm[%d][%d] = %.0f\n",(volume[0]-1),pm[volume[0]-1][0], |
326 | // (volume[0]-1),volume[1],pm[volume[0]-1][volume[1]]); | |
327 | } | |
328 | else { | |
329 | if (volume[1] == 1) pm[2][1] += lightC; // ZEM 1 | |
330 | else pm[2][2] += lightQ; // ZEM 2 | |
331 | //printf("\n pm[2][1] = %.0f, pm[2][2] = %.0f\n",pm[2][1],pm[2][2]); | |
332 | } | |
8309c1ab | 333 | } |
334 | else if(entry[0] > rnd[iev]){ | |
335 | iev++; | |
336 | continue; | |
337 | } | |
338 | } | |
339 | }while(iev<numEvents); | |
340 | ||
341 | file->Close(); | |
342 | delete file; | |
343 | } | |
344 | ||
345 | ||
346 | //_____________________________________________________________________________ | |
347 | Int_t AliZDCDigitizer::Phe2ADCch(Int_t Det, Int_t Quad, Float_t Light, | |
348 | Int_t Res) const | |
349 | { | |
48642b09 | 350 | // Evaluation of the ADC channel corresponding to the light yield Light |
8a2624cc | 351 | Int_t vADCch = (Int_t) (Light * fPMGain[Det-1][Quad] * fADCRes[Res]); |
78d18275 | 352 | //printf("\t Phe2ADCch -> det %d quad %d - phe %.0f ADC %d\n", Det,Quad,Light,ADCch); |
7f73eb6b | 353 | |
8a2624cc | 354 | return vADCch; |
48642b09 | 355 | } |
8309c1ab | 356 | |
48642b09 | 357 | //_____________________________________________________________________________ |
358 | Int_t AliZDCDigitizer::Pedestal(Int_t Det, Int_t Quad, Int_t Res) const | |
359 | { | |
8a2624cc | 360 | // Returns a pedestal for detector det, PM quad, channel with res. |
361 | // | |
dbc8d7fc | 362 | Float_t meanPed; |
78d18275 | 363 | if(Det != 3) meanPed = fCalibData->GetMeanPed(10*(Det-1)+Quad+5*Res); |
364 | else meanPed = fCalibData->GetMeanPed(10*(Det-1)+Quad+1*Res); | |
dbc8d7fc | 365 | |
78d18275 | 366 | //printf("\t Pedestal -> det = %d, quad = %d, res = %d - Ped[%d] = %d\n", |
367 | // Det, Quad, Res,10*(Det-1)+Quad+5*Res,(Int_t) meanPed); // Chiara debugging! | |
48642b09 | 368 | |
7f73eb6b | 369 | // To create calibration object |
dbc8d7fc | 370 | /*Float_t meanPed; |
7f73eb6b | 371 | meanPed = gRandom->Gaus((40.+10.*gRandom->Rndm()),5.); |
dbc8d7fc | 372 | */ |
373 | ||
48642b09 | 374 | return (Int_t) meanPed; |
8309c1ab | 375 | } |
376 | ||
377 | //_____________________________________________________________________________ | |
78d18275 | 378 | AliCDBStorage* AliZDCDigitizer::SetStorage(const char *uri) |
8309c1ab | 379 | { |
8309c1ab | 380 | |
78d18275 | 381 | Bool_t deleteManager = kFALSE; |
48642b09 | 382 | |
78d18275 | 383 | AliCDBManager *manager = AliCDBManager::Instance(); |
384 | AliCDBStorage *defstorage = manager->GetDefaultStorage(); | |
48642b09 | 385 | |
78d18275 | 386 | if(!defstorage || !(defstorage->Contains("ZDC"))){ |
387 | AliWarning("No default storage set or default storage doesn't contain ZDC!"); | |
388 | manager->SetDefaultStorage(uri); | |
389 | deleteManager = kTRUE; | |
390 | } | |
391 | ||
392 | AliCDBStorage *storage = manager->GetDefaultStorage(); | |
393 | ||
394 | if(deleteManager){ | |
395 | AliCDBManager::Instance()->UnsetDefaultStorage(); | |
396 | defstorage = 0; // the storage is killed by AliCDBManager::Instance()->Destroy() | |
397 | } | |
398 | ||
399 | return storage; | |
400 | } | |
48642b09 | 401 | |
78d18275 | 402 | //_____________________________________________________________________________ |
7f73eb6b | 403 | AliZDCCalibData* AliZDCDigitizer::GetCalibData() const |
78d18275 | 404 | { |
8a2624cc | 405 | // returns pointer to AliZDCCalibData object |
406 | // | |
7f73eb6b | 407 | AliCDBEntry *entry = fStorage->Get("ZDC/Calib/Data",0); |
78d18275 | 408 | AliZDCCalibData *calibdata = (AliZDCCalibData*) entry->GetObject(); |
409 | ||
7f73eb6b | 410 | if (!calibdata) AliWarning("No ZDC calibration data from calibration database!"); |
8309c1ab | 411 | |
78d18275 | 412 | return calibdata; |
8309c1ab | 413 | } |