]> git.uio.no Git - u/mrichter/AliRoot.git/blame - PHOS/AliPHOS.cxx
Preparing to reconstruct from raw data
[u/mrichter/AliRoot.git] / PHOS / AliPHOS.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 **************************************************************************/
b2a60966 15/* $Id$ */
16
d15a28e7 17//_________________________________________________________________________
b2a60966 18// Base Class for PHOS description:
19// PHOS consists of a PbWO4 calorimeter (EMCA) and a gazeous charged
20// particles detector (CPV or PPSD).
21// The only provided method here is CreateMaterials,
22// which defines the materials common to all PHOS versions.
23//
24//*-- Author: Laurent Aphecetche & Yves Schutz (SUBATECH)
d15a28e7 25//////////////////////////////////////////////////////////////////////////////
e84be1eb 26
fdeead01 27
fe4da5cc 28// --- ROOT system ---
2ab0c725 29class TFile;
88cb7938 30#include <TFolder.h>
88cb7938 31#include <TTree.h>
32#include <TVirtualMC.h>
046ae904 33#include <TH1F.h>
34#include <TF1.h>
e9a5efdf 35#include <TRandom.h>
fe4da5cc 36
37// --- Standard library ---
d15a28e7 38
548f0134 39// --- AliRoot header files ---
94de3818 40#include "AliMagF.h"
88cb7938 41#include "AliPHOS.h"
e9a5efdf 42#include "AliPHOSGetter.h"
85a5290f 43#include "AliRun.h"
44#include "AliPHOSDigitizer.h"
45#include "AliPHOSSDigitizer.h"
65792ca0 46#include "AliPHOSDigit.h"
47#include "AliAltroBuffer.h"
7f78a025 48
fe4da5cc 49ClassImp(AliPHOS)
0ce0b56f 50//____________________________________________________________________________
046ae904 51 AliPHOS:: AliPHOS() : AliDetector()
6b87d0dd 52{
a532e9d8 53 // Default ctor
046ae904 54 fName = "PHOS" ;
2685bf00 55 fQATask = 0;
56 fTreeQA = 0;
3d60069b 57 fDebug = 0;
6b87d0dd 58}
fa7cce36 59
6b87d0dd 60//____________________________________________________________________________
046ae904 61AliPHOS::AliPHOS(const char* name, const char* title): AliDetector(name, title)
6b87d0dd 62{
a532e9d8 63 // ctor : title is used to identify the layout
64
046ae904 65 fQATask = 0 ;
66 fTreeQA = 0 ;
67 fDebug = 0 ;
68 fTimeMax = 1.28E-5 ;
69 fTimePeak = 2.0E-6 ;
70 fTimeRes = 1.5E-6 ;
71 fHighGainFactor = 40;
72 fHighGainOffset = 0x200 ;
6b87d0dd 73}
fa7cce36 74
0ce0b56f 75//____________________________________________________________________________
7b326aac 76AliPHOS::~AliPHOS()
77{
0ce0b56f 78}
79
780fda6d 80//____________________________________________________________________________
81void AliPHOS::Copy(AliPHOS & phos)
82{
7f78a025 83 // copy method to be used byy the cpy ctor
780fda6d 84 TObject::Copy(phos) ;
85 // fQATask = AliPHOSQAChecker::Copy(*(phos.fQATask)) ;
86 phos.fTreeQA = fTreeQA->CloneTree() ;
87}
88
487d23e3 89//____________________________________________________________________________
90AliDigitizer* AliPHOS::CreateDigitizer(AliRunDigitizer* manager) const
91{
92 return new AliPHOSDigitizer(manager);
93}
94
d15a28e7 95//____________________________________________________________________________
fe4da5cc 96void AliPHOS::CreateMaterials()
97{
b2a60966 98 // Definitions of materials to build PHOS and associated tracking media.
99 // media number in idtmed are 699 to 798.
fe4da5cc 100
d15a28e7 101 // --- The PbWO4 crystals ---
92862013 102 Float_t aX[3] = {207.19, 183.85, 16.0} ;
103 Float_t zX[3] = {82.0, 74.0, 8.0} ;
104 Float_t wX[3] = {1.0, 1.0, 4.0} ;
105 Float_t dX = 8.28 ;
fe4da5cc 106
92862013 107 AliMixture(0, "PbWO4$", aX, zX, dX, -3, wX) ;
fe4da5cc 108
fe4da5cc 109
d15a28e7 110 // --- The polysterene scintillator (CH) ---
92862013 111 Float_t aP[2] = {12.011, 1.00794} ;
112 Float_t zP[2] = {6.0, 1.0} ;
113 Float_t wP[2] = {1.0, 1.0} ;
114 Float_t dP = 1.032 ;
fe4da5cc 115
92862013 116 AliMixture(1, "Polystyrene$", aP, zP, dP, -2, wP) ;
fe4da5cc 117
d15a28e7 118 // --- Aluminium ---
119 AliMaterial(2, "Al$", 26.98, 13., 2.7, 8.9, 999., 0, 0) ;
120 // --- Absorption length is ignored ^
fe4da5cc 121
d15a28e7 122 // --- Tyvek (CnH2n) ---
92862013 123 Float_t aT[2] = {12.011, 1.00794} ;
124 Float_t zT[2] = {6.0, 1.0} ;
125 Float_t wT[2] = {1.0, 2.0} ;
126 Float_t dT = 0.331 ;
fe4da5cc 127
92862013 128 AliMixture(3, "Tyvek$", aT, zT, dT, -2, wT) ;
fe4da5cc 129
d15a28e7 130 // --- Polystyrene foam ---
92862013 131 Float_t aF[2] = {12.011, 1.00794} ;
132 Float_t zF[2] = {6.0, 1.0} ;
133 Float_t wF[2] = {1.0, 1.0} ;
134 Float_t dF = 0.12 ;
fe4da5cc 135
92862013 136 AliMixture(4, "Foam$", aF, zF, dF, -2, wF) ;
fe4da5cc 137
d15a28e7 138 // --- Titanium ---
92862013 139 Float_t aTIT[3] = {47.88, 26.98, 54.94} ;
140 Float_t zTIT[3] = {22.0, 13.0, 25.0} ;
141 Float_t wTIT[3] = {69.0, 6.0, 1.0} ;
142 Float_t dTIT = 4.5 ;
fe4da5cc 143
92862013 144 AliMixture(5, "Titanium$", aTIT, zTIT, dTIT, -3, wTIT);
fe4da5cc 145
d15a28e7 146 // --- Silicon ---
147 AliMaterial(6, "Si$", 28.0855, 14., 2.33, 9.36, 42.3, 0, 0) ;
fe4da5cc 148
fe4da5cc 149
fe4da5cc 150
d15a28e7 151 // --- Foam thermo insulation ---
92862013 152 Float_t aTI[2] = {12.011, 1.00794} ;
153 Float_t zTI[2] = {6.0, 1.0} ;
154 Float_t wTI[2] = {1.0, 1.0} ;
85218d13 155 Float_t dTI = 0.04 ;
fe4da5cc 156
92862013 157 AliMixture(7, "Thermo Insul.$", aTI, zTI, dTI, -2, wTI) ;
fe4da5cc 158
d15a28e7 159 // --- Textolitn ---
92862013 160 Float_t aTX[4] = {16.0, 28.09, 12.011, 1.00794} ;
161 Float_t zTX[4] = {8.0, 14.0, 6.0, 1.0} ;
162 Float_t wTX[4] = {292.0, 68.0, 462.0, 736.0} ;
163 Float_t dTX = 1.75 ;
fe4da5cc 164
92862013 165 AliMixture(8, "Textolit$", aTX, zTX, dTX, -4, wTX) ;
fe4da5cc 166
d15a28e7 167 //--- FR4 ---
92862013 168 Float_t aFR[3] = {28.0855, 15.9994, 17.749} ;
169 Float_t zFR[3] = {14., 8., 8.875} ;
170 Float_t wFR[3] = {.28, .32, .4} ;
171 Float_t dFR = 1.8 ;
fe4da5cc 172
92862013 173 AliMixture(9, "FR4$", aFR, zFR, dFR, -3, wFR) ;
fe4da5cc 174
d15a28e7 175 // --- The Composite Material for micromegas (so far polyetylene) ---
92862013 176 Float_t aCM[2] = {12.01, 1.} ;
177 Float_t zCM[2] = {6., 1.} ;
178 Float_t wCM[2] = {1., 2.} ;
179 Float_t dCM = 0.935 ;
fe4da5cc 180
92862013 181 AliMixture(10, "Compo Mat$", aCM, zCM, dCM, -2, wCM) ;
fe4da5cc 182
d15a28e7 183 // --- Copper ---
184 AliMaterial(11, "Cu$", 63.546, 29, 8.96, 1.43, 14.8, 0, 0) ;
185
186 // --- G10 : Printed Circuit material ---
92862013 187 Float_t aG10[4] = { 12., 1., 16., 28.} ;
188 Float_t zG10[4] = { 6., 1., 8., 14.} ;
189 Float_t wG10[4] = { .259, .288, .248, .205} ;
190 Float_t dG10 = 1.7 ;
d15a28e7 191
92862013 192 AliMixture(12, "G10$", aG10, zG10, dG10, -4, wG10);
fe4da5cc 193
d15a28e7 194 // --- Lead ---
195 AliMaterial(13, "Pb$", 207.2, 82, 11.35, 0.56, 0., 0, 0) ;
fe4da5cc 196
d15a28e7 197 // --- The gas mixture ---
198 // Co2
92862013 199 Float_t aCO[2] = {12.0, 16.0} ;
200 Float_t zCO[2] = {6.0, 8.0} ;
201 Float_t wCO[2] = {1.0, 2.0} ;
202 Float_t dCO = 0.001977 ;
fe4da5cc 203
92862013 204 AliMixture(14, "CO2$", aCO, zCO, dCO, -2, wCO);
fe4da5cc 205
d15a28e7 206 // Ar
92862013 207 Float_t dAr = 0.001782 ;
208 AliMaterial(15, "Ar$", 39.948, 18.0, dAr, 14.0, 0., 0, 0) ;
d15a28e7 209
210 // ArCo2
00d6d986 211 Char_t namate[21]="";
92862013 212 Float_t aGM[2] ;
213 Float_t zGM[2] ;
214 Float_t wGM[2] ;
215 Float_t dGM ;
fe4da5cc 216
92862013 217 Float_t absL, radL, density ;
d15a28e7 218 Float_t buf[1] ;
219 Int_t nbuf ;
bc9ab547 220
92862013 221 gMC->Gfmate((*fIdmate)[15], namate, aGM[0], zGM[0], density, radL, absL, buf, nbuf) ; // Get properties of Ar
222 gMC->Gfmate((*fIdmate)[14], namate, aGM[1], zGM[1], density, radL, absL, buf, nbuf) ; // Get properties of CO2
bc9ab547 223
fe4da5cc 224
d15a28e7 225 // Create gas mixture
fe4da5cc 226
92862013 227 Float_t arContent = 0.80 ; // Ar-content of the Ar/CO2-mixture (80% / 20%)
d15a28e7 228
92862013 229 wGM[0] = arContent;
230 wGM[1] = 1. - arContent ;
231 dGM = wGM[0] * dAr + wGM[1] * dCO;
fe4da5cc 232
a7262d8e 233
92862013 234 AliMixture(16, "ArCO2$", aGM, zGM, dGM, 2, wGM) ;
fe4da5cc 235
a530ba0a 236 // --- Stainless steel (let it be pure iron) ---
237 AliMaterial(17, "Steel$", 55.845, 26, 7.87, 1.76, 0., 0, 0) ;
85218d13 238
239
240 // --- Fiberglass ---
241 Float_t aFG[4] = {16.0, 28.09, 12.011, 1.00794} ;
242 Float_t zFG[4] = {8.0, 14.0, 6.0, 1.0} ;
243 Float_t wFG[4] = {292.0, 68.0, 462.0, 736.0} ;
244 Float_t dFG = 1.9 ;
245
246 AliMixture(18, "Fibergla$", aFG, zFG, dFG, -4, wFG) ;
247
248 // --- Cables in Air box ---
249 // SERVICES
250
251 Float_t aCA[4] = { 1.,12.,55.8,63.5 };
252 Float_t zCA[4] = { 1.,6.,26.,29. };
253 Float_t wCA[4] = { .014,.086,.42,.48 };
254 Float_t dCA = 0.8 ; //this density is raw estimation, if you know better - correct
255
256 AliMixture(19, "Cables $", aCA, zCA, dCA, -4, wCA) ;
257
258
d15a28e7 259 // --- Air ---
a7262d8e 260 Float_t aAir[4]={12.0107,14.0067,15.9994,39.948};
261 Float_t zAir[4]={6.,7.,8.,18.};
262 Float_t wAir[4]={0.000124,0.755267,0.231781,0.012827};
263 Float_t dAir = 1.20479E-3;
d15a28e7 264
a7262d8e 265 AliMixture(99, "Air$", aAir, zAir, dAir, 4, wAir) ;
266
d15a28e7 267 // DEFINITION OF THE TRACKING MEDIA
fe4da5cc 268
d15a28e7 269 // for PHOS: idtmed[699->798] equivalent to fIdtmed[0->100]
270 Int_t * idtmed = fIdtmed->GetArray() - 699 ;
92862013 271 Int_t isxfld = gAlice->Field()->Integ() ;
272 Float_t sxmgmx = gAlice->Field()->Max() ;
fe4da5cc 273
d15a28e7 274 // The scintillator of the calorimeter made of PBW04 -> idtmed[699]
275 AliMedium(0, "PHOS Xtal $", 0, 1,
92862013 276 isxfld, sxmgmx, 10.0, 0.1, 0.1, 0.1, 0.1, 0, 0) ;
fe4da5cc 277
d15a28e7 278 // The scintillator of the CPV made of Polystyrene scintillator -> idtmed[700]
279 AliMedium(1, "CPV scint. $", 1, 1,
92862013 280 isxfld, sxmgmx, 10.0, 0.1, 0.1, 0.1, 0.1, 0, 0) ;
fe4da5cc 281
d15a28e7 282 // Various Aluminium parts made of Al -> idtmed[701]
283 AliMedium(2, "Al parts $", 2, 0,
92862013 284 isxfld, sxmgmx, 10.0, 0.1, 0.1, 0.001, 0.001, 0, 0) ;
fe4da5cc 285
d15a28e7 286 // The Tywek which wraps the calorimeter crystals -> idtmed[702]
287 AliMedium(3, "Tyvek wrapper$", 3, 0,
92862013 288 isxfld, sxmgmx, 10.0, 0.1, 0.1, 0.001, 0.001, 0, 0) ;
fe4da5cc 289
d15a28e7 290 // The Polystyrene foam around the calorimeter module -> idtmed[703]
291 AliMedium(4, "Polyst. foam $", 4, 0,
92862013 292 isxfld, sxmgmx, 10.0, 0.1, 0.1, 0.1, 0.1, 0, 0) ;
fe4da5cc 293
d15a28e7 294 // The Titanium around the calorimeter crystal -> idtmed[704]
295 AliMedium(5, "Titan. cover $", 5, 0,
92862013 296 isxfld, sxmgmx, 10.0, 0.1, 0.1, 0.0001, 0.0001, 0, 0) ;
fe4da5cc 297
d15a28e7 298 // The Silicon of the pin diode to read out the calorimeter crystal -> idtmed[705]
299 AliMedium(6, "Si PIN $", 6, 0,
7b326aac 300 isxfld, sxmgmx, 10.0, 0.1, 0.1, 0.01, 0.01, 0, 0) ;
fe4da5cc 301
d15a28e7 302 // The thermo insulating material of the box which contains the calorimeter module -> idtmed[706]
303 AliMedium(7, "Thermo Insul.$", 7, 0,
92862013 304 isxfld, sxmgmx, 10.0, 0.1, 0.1, 0.1, 0.1, 0, 0) ;
fe4da5cc 305
d15a28e7 306 // The Textolit which makes up the box which contains the calorimeter module -> idtmed[707]
307 AliMedium(8, "Textolit $", 8, 0,
92862013 308 isxfld, sxmgmx, 10.0, 0.1, 0.1, 0.1, 0.1, 0, 0) ;
fe4da5cc 309
d15a28e7 310 // FR4: The Plastic which makes up the frame of micromegas -> idtmed[708]
311 AliMedium(9, "FR4 $", 9, 0,
92862013 312 isxfld, sxmgmx, 10.0, 0.1, 0.1, 0.1, 0.0001, 0, 0) ;
fe4da5cc 313
fe4da5cc 314
d15a28e7 315 // The Composite Material for micromegas -> idtmed[709]
316 AliMedium(10, "CompoMat $", 10, 0,
92862013 317 isxfld, sxmgmx, 10.0, 0.1, 0.1, 0.1, 0.1, 0, 0) ;
fe4da5cc 318
d15a28e7 319 // Copper -> idtmed[710]
320 AliMedium(11, "Copper $", 11, 0,
92862013 321 isxfld, sxmgmx, 10.0, 0.1, 0.1, 0.1, 0.0001, 0, 0) ;
fe4da5cc 322
d15a28e7 323 // G10: Printed Circuit material -> idtmed[711]
324
325 AliMedium(12, "G10 $", 12, 0,
92862013 326 isxfld, sxmgmx, 10.0, 0.1, 0.1, 0.1, 0.01, 0, 0) ;
fe4da5cc 327
d15a28e7 328 // The Lead -> idtmed[712]
329
330 AliMedium(13, "Lead $", 13, 0,
92862013 331 isxfld, sxmgmx, 10.0, 0.1, 0.1, 0.1, 0.1, 0, 0) ;
fe4da5cc 332
d15a28e7 333 // The gas mixture: ArCo2 -> idtmed[715]
334
335 AliMedium(16, "ArCo2 $", 16, 1,
92862013 336 isxfld, sxmgmx, 10.0, 0.1, 0.1, 0.1, 0.01, 0, 0) ;
d15a28e7 337
a530ba0a 338 // Stainless steel -> idtmed[716]
339 AliMedium(17, "Steel $", 17, 0,
340 isxfld, sxmgmx, 10.0, 0.1, 0.1, 0.1, 0.0001, 0, 0) ;
341
85218d13 342 // Fibergalss -> idtmed[717]
343 AliMedium(18, "Fiberglass$", 18, 0,
344 isxfld, sxmgmx, 10.0, 0.1, 0.1, 0.1, 0.1, 0, 0) ;
345
346 // Cables in air -> idtmed[718]
347 AliMedium(19, "Cables $", 19, 0,
348 isxfld, sxmgmx, 10.0, 0.1, 0.1, 0.1, 0.1, 0, 0) ;
349
d15a28e7 350 // Air -> idtmed[798]
351 AliMedium(99, "Air $", 99, 0,
92862013 352 isxfld, sxmgmx, 10.0, 1.0, 0.1, 0.1, 10.0, 0, 0) ;
fe4da5cc 353
d15a28e7 354 // --- Set decent energy thresholds for gamma and electron tracking
fe4da5cc 355
d15a28e7 356 // Tracking threshold for photons and electrons in the scintillator crystal
357 gMC->Gstpar(idtmed[699], "CUTGAM",0.5E-4) ;
358 gMC->Gstpar(idtmed[699], "CUTELE",1.0E-4) ;
9f616d61 359
d15a28e7 360 // --- Generate explicitly delta rays in the titan cover ---
361 gMC->Gstpar(idtmed[704], "LOSS",3.) ;
362 gMC->Gstpar(idtmed[704], "DRAY",1.) ;
d15a28e7 363 // --- and in aluminium parts ---
364 gMC->Gstpar(idtmed[701], "LOSS",3.) ;
365 gMC->Gstpar(idtmed[701], "DRAY",1.) ;
92862013 366 // --- and in PIN diode
367 gMC->Gstpar(idtmed[705], "LOSS",3) ;
368 gMC->Gstpar(idtmed[705], "DRAY",1) ;
369 // --- and in the passive convertor
370 gMC->Gstpar(idtmed[712], "LOSS",3) ;
371 gMC->Gstpar(idtmed[712], "DRAY",1) ;
372 // Tracking threshold for photons and electrons in the gas ArC02
b7101219 373 gMC->Gstpar(idtmed[715], "CUTGAM",1.E-5) ;
374 gMC->Gstpar(idtmed[715], "CUTELE",1.E-5) ;
375 gMC->Gstpar(idtmed[715], "CUTNEU",1.E-5) ;
376 gMC->Gstpar(idtmed[715], "CUTHAD",1.E-5) ;
377 gMC->Gstpar(idtmed[715], "CUTMUO",1.E-5) ;
378 gMC->Gstpar(idtmed[715], "BCUTE",1.E-5) ;
379 gMC->Gstpar(idtmed[715], "BCUTM",1.E-5) ;
380 gMC->Gstpar(idtmed[715], "DCUTE",1.E-5) ;
381 gMC->Gstpar(idtmed[715], "DCUTM",1.E-5) ;
382 gMC->Gstpar(idtmed[715], "PPCUTM",1.E-5) ;
9f616d61 383 gMC->Gstpar(idtmed[715], "LOSS",2.) ;
384 gMC->Gstpar(idtmed[715], "DRAY",0.) ;
385 gMC->Gstpar(idtmed[715], "STRA",2.) ;
386
0c409cb2 387}
a532e9d8 388
65792ca0 389//____________________________________________________________________________
390void AliPHOS::Digits2Raw()
391{
392// convert digits of the current event to raw data
393
394 // get the digits
e9a5efdf 395 AliPHOSGetter * gime = AliPHOSGetter::Instance(AliRunLoader::GetGAliceName()) ;
396 if (!gime) {
397 Error("Digits2Raw", "PHOS Getter not instantiated") ;
398 return ;
399 }
400 gime->Event(gime->EventNumber(), "D") ;
401 TClonesArray* digits = gime->Digits() ;
402
65792ca0 403 if (!digits) {
e9a5efdf 404 Error("Digits2Raw", "no digits found !");
65792ca0 405 return;
406 }
407
408 // get the geometry
e9a5efdf 409 AliPHOSGeometry* geom = gime->PHOSGeometry();
65792ca0 410 if (!geom) {
e9a5efdf 411 Error("Digits2Raw", "no geometry found !");
65792ca0 412 return;
413 }
414
415 // some digitization constants
046ae904 416 const Int_t kDDLOffset = 0x600; // assigned to PHOS
417 const Int_t kThreshold = 3; // skip digits below this threshold
65792ca0 418
419 AliAltroBuffer* buffer = NULL;
420 Int_t prevDDL = -1;
046ae904 421 Int_t adcValuesLow[fkTimeBins];
422 Int_t adcValuesHigh[fkTimeBins];
65792ca0 423
424 // loop over digits (assume ordered digits)
425 for (Int_t iDigit = 0; iDigit < digits->GetEntries(); iDigit++) {
e9a5efdf 426 AliPHOSDigit* digit = gime->Digit(iDigit);
427 if (digit->GetAmp() < kThreshold)
428 continue;
65792ca0 429 Int_t relId[4];
430 geom->AbsToRelNumbering(digit->GetId(), relId);
431 Int_t module = relId[0];
e9a5efdf 432
433 // Begin FIXME
434 if (relId[1] != 0)
435 continue; // ignore digits from CPV
436 // End FIXME
437
438 // PHOS EMCA has 4 DDL per module. Splitting is done based on the row number
65792ca0 439 Int_t iDDL = 4 * (module - 1) + (4 * (relId[2] - 1)) / geom->GetNPhi();
440
441 // new DDL
442 if (iDDL != prevDDL) {
443 // write real header and close previous file
444 if (buffer) {
445 buffer->Flush();
446 buffer->WriteDataHeader(kFALSE, kFALSE);
447 delete buffer;
448 }
449
450 // open new file and write dummy header
e9a5efdf 451 TString fileName("PHOS_") ;
452 fileName += (iDDL + kDDLOffset) ;
453 fileName += ".ddl" ;
454 buffer = new AliAltroBuffer(fileName.Data(), 1);
65792ca0 455 buffer->WriteDataHeader(kTRUE, kFALSE); //Dummy;
456
457 prevDDL = iDDL;
458 }
459
460 // out of time range signal (?)
046ae904 461 if (digit->GetTimeR() > fTimeMax) {
65792ca0 462 buffer->FillBuffer(digit->GetAmp());
046ae904 463 buffer->FillBuffer(fkTimeBins); // time bin
65792ca0 464 buffer->FillBuffer(3); // bunch length
465 buffer->WriteTrailer(3, relId[3], relId[2], module); // trailer
466
467 // simulate linear rise and gaussian decay of signal
468 } else {
046ae904 469 Bool_t highGain = RawSampledResponse(digit->GetTimeR(), digit->GetAmp(), adcValuesHigh, adcValuesLow) ;
470
471
65792ca0 472 // write low and eventually high gain channel
473 buffer->WriteChannel(relId[3], relId[2], module,
046ae904 474 fkTimeBins, adcValuesLow, kThreshold);
65792ca0 475 if (highGain) {
046ae904 476 buffer->WriteChannel(relId[3], relId[2], module + fHighGainOffset,
477 fkTimeBins, adcValuesHigh, 1);
65792ca0 478 }
479 }
480 }
046ae904 481
65792ca0 482 // write real header and close last file
483 if (buffer) {
484 buffer->Flush();
485 buffer->WriteDataHeader(kFALSE, kFALSE);
486 delete buffer;
487 }
046ae904 488
e9a5efdf 489 gime->PhosLoader()->UnloadDigits();
490}
491
492//____________________________________________________________________________
493void AliPHOS::Hits2SDigits()
494{
495// create summable digits
496
497 AliPHOSSDigitizer* phosDigitizer =
498 new AliPHOSSDigitizer(fLoader->GetRunLoader()->GetFileName().Data()) ;
499 phosDigitizer->SetEventRange(0, -1) ; // do all the events
500 phosDigitizer->ExecuteTask("all") ;
501}
502
503//____________________________________________________________________________
504AliLoader* AliPHOS::MakeLoader(const char* topfoldername)
505{
506//different behaviour than standard (singleton getter)
507// --> to be discussed and made eventually coherent
508 fLoader = new AliPHOSLoader(GetName(),topfoldername);
509 return fLoader;
510}
511
046ae904 512//__________________________________________________________________
513Double_t AliPHOS::RawResponseFunction(Double_t *x, Double_t *par)
514{
515 // Shape of the electronics raw reponse:
516 // 1. the signal rises linearly from par[4] to par[1] to reach the maximu par[3]
517 // 2. the signal decays with a gaussian shape for par[4]+par[1] with a sigma of par[2]
518
519 Float_t xx = x[0] ;
520
521 Double_t signal = 0. ;
522
523 if (xx < par[4] + par[1]) // signal is rising
524 signal = (gRandom->Rndm() + par[3]) * (xx - par[4]) / (par[1] - par[4]) ;
525 else // signal is decaying
526 signal = (gRandom->Rndm() + par[3]) * TMath::Gaus(xx, par[4] + par[1], par[2]) ;
527
528 return signal < 0. ? 0. : signal ;
529}
530
531//__________________________________________________________________
532Bool_t AliPHOS::RawSampledResponse(const Float_t dtime, const Int_t damp, Int_t * adcH, Int_t * adcL) const
533{
534 // for a start time dtime and an amplitude damp given by digit,
535 // calculates the raw sampled response
536
537 const Int_t kRawSignalOverflow = 0x3FF ;
538 Bool_t highGain = kFALSE ;
539
540 TF1 f1("signal", RawResponseFunction, 0, fkTimeBins, 5);
541
542 f1.SetParNames("Time Max", "Peaking time", "Decay width", "Amp max", "Start time") ;
543 f1.SetParameter(0, fTimeMax) ;
544 f1.SetParameter(1, fTimePeak) ;
545 f1.SetParameter(2, fTimeRes) ;
546 f1.SetParameter(3, damp) ;
547 f1.SetParameter(4, dtime) ;
548
549 for (Int_t iTime = 0; iTime < fkTimeBins; iTime++) {
550 Double_t time = iTime * fTimeMax/fkTimeBins;
551 Double_t signal = f1.Eval(time) ;
552 adcL[iTime] = static_cast<Int_t>(signal + 0.5) ;
553 if ( adcL[iTime] > kRawSignalOverflow) // larger than 10 bits
554 adcL[iTime] = kRawSignalOverflow ;
555 adcH[iTime] = static_cast<Int_t>(0.5 + (signal / fHighGainFactor)) ;
556 if (adcH[iTime] > 0)
557 highGain = kTRUE;
558 }
559 return highGain ;
560}
561
e9a5efdf 562//____________________________________________________________________________
563void AliPHOS::SetTreeAddress()
564{
565 // Links Hits in the Tree to Hits array
566 TBranch *branch;
567 char branchname[20];
568 sprintf(branchname,"%s",GetName());
569
570 // Branch address for hit tree
571 TTree *treeH = TreeH();
572 if (treeH) {
573 branch = treeH->GetBranch(branchname);
574 if (branch)
575 {
576 if (fHits == 0x0) fHits= new TClonesArray("AliPHOSHit",1000);
577 //Info("SetTreeAddress","<%s> Setting Hits Address",GetName());
578 branch->SetAddress(&fHits);
579 }
580 }
581}
582
583//____________________________________________________________________________
584void AliPHOS::WriteQA()
585{
586
587 // Make TreeQA in the output file.
588
589 if(fTreeQA == 0)
590 fTreeQA = new TTree("TreeQA", "QA Alarms") ;
591 // Create Alarms branches
592 Int_t bufferSize = 32000 ;
593 Int_t splitlevel = 0 ;
594
595 TFolder* topfold = GetLoader()->GetTopFolder(); //get top aliroot folder; skowron
596 TString phosqafn(AliConfig::Instance()->GetQAFolderName()+"/"); //get name of QAaut folder relative to top event; skowron
597 phosqafn+=GetName(); //hard wired string!!! add the detector name to the pathname; skowron
598 TFolder * alarmsF = (TFolder*)topfold->FindObjectAny(phosqafn); //get the folder
599
600 if (alarmsF == 0x0)
601 {
602 Error("WriteQA","Can not find folder with qa alarms");
603 return;
604 }
605 TString branchName(alarmsF->GetName());
606 TBranch * alarmsBranch = fTreeQA->Branch(branchName,"TFolder", &alarmsF, bufferSize, splitlevel);
607 TString branchTitle = branchName + " QA alarms" ;
608 alarmsBranch->SetTitle(branchTitle);
609 alarmsBranch->Fill() ;
610
611 //fTreeQA->Fill() ;
65792ca0 612}
613