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 /* History of cvs commits:
22 //_________________________________________________________________________
23 // Base Class for EMCAL description:
24 // This class contains material definitions
25 // for the EMCAL - It does not place the detector in Alice
26 //*-- Author: Yves Schutz (SUBATECH)
28 //*-- Additional Contributions: Sahal Yacoob (LBNL/UCT)
30 //////////////////////////////////////////////////////////////////////////////
32 // --- ROOT system ---
36 #include <TVirtualMC.h>
42 // --- Standard library ---
44 // --- AliRoot header files ---
48 #include "AliEMCALLoader.h"
49 #include "AliEMCALSDigitizer.h"
50 #include "AliEMCALDigitizer.h"
51 #include "AliEMCALDigit.h"
52 //#include "AliAltroMapping.h"
53 #include "AliCaloAltroMapping.h"
54 #include "AliAltroBuffer.h"
55 #include "AliRawReader.h"
56 #include "AliCaloRawStream.h"
60 Double_t AliEMCAL::fgCapa = 1.; // 1pF
61 Int_t AliEMCAL::fgOrder = 2 ;
62 Double_t AliEMCAL::fgTimeMax = 2.56E-5 ; // each sample is over 100 ns fTimeMax/fTimeBins
63 Double_t AliEMCAL::fgTimePeak = 4.1E-6 ; // 4 micro seconds
64 Double_t AliEMCAL::fgTimeTrigger = 100E-9 ; // 100ns, just for a reference
65 // some digitization constants
66 Int_t AliEMCAL::fgThreshold = 1;
67 Int_t AliEMCAL::fgDDLPerSuperModule = 2; // 2 ddls per SuperModule
69 //____________________________________________________________________________
77 fHighLowGainFactor(0.),
86 //____________________________________________________________________________
87 AliEMCAL::AliEMCAL(const char* name, const char* title)
88 : AliDetector(name,title),
94 fHighLowGainFactor(0.),
97 // ctor : title is used to identify the layout
102 //____________________________________________________________________________
103 AliEMCAL::~AliEMCAL()
108 //____________________________________________________________________________
109 void AliEMCAL::Init(void)
111 //initialize EMCAL values
113 fBirkC1 = 0.013/1.032;
114 fBirkC2 = 9.6e-6/(1.032 * 1.032);
116 fHighCharge = 8.2 ; // adjusted for a high gain range of 5.12 GeV (10 bits)
118 fHighLowGainFactor = 16. ; // adjusted for a low gain range of 82 GeV (10 bits)
119 fLowGainOffset = 1 ; // offset added to the module id to distinguish high and low gain data
122 //____________________________________________________________________________
123 AliDigitizer* AliEMCAL::CreateDigitizer(AliRunDigitizer* manager) const
125 //create and return the digitizer
126 return new AliEMCALDigitizer(manager);
129 //____________________________________________________________________________
130 void AliEMCAL::CreateMaterials()
132 // Definitions of materials to build EMCAL and associated tracking media.
133 // media number in idtmed are 1599 to 1698.
136 Float_t aAir[4]={12.0107,14.0067,15.9994,39.948};
137 Float_t zAir[4]={6.,7.,8.,18.};
138 Float_t wAir[4]={0.000124,0.755267,0.231781,0.012827};
139 Float_t dAir = 1.20479E-3;
140 AliMixture(0, "Air$", aAir, zAir, dAir, 4, wAir) ;
143 AliMaterial(1, "Pb$", 207.2, 82, 11.35, 0.56, 0., 0, 0) ;
146 // --- The polysterene scintillator (CH) ---
147 Float_t aP[2] = {12.011, 1.00794} ;
148 Float_t zP[2] = {6.0, 1.0} ;
149 Float_t wP[2] = {1.0, 1.0} ;
152 AliMixture(2, "Polystyrene$", aP, zP, dP, -2, wP) ;
155 AliMaterial(3, "Al$", 26.98, 13., 2.7, 8.9, 999., 0, 0) ;
156 // --- Absorption length is ignored ^
158 // 25-aug-04 by PAI - see PMD/AliPMDv0.cxx for STEEL definition
159 Float_t asteel[4] = { 55.847,51.9961,58.6934,28.0855 };
160 Float_t zsteel[4] = { 26.,24.,28.,14. };
161 Float_t wsteel[4] = { .715,.18,.1,.005 };
162 AliMixture(4, "STAINLESS STEEL$", asteel, zsteel, 7.88, 4, wsteel);
164 // DEFINITION OF THE TRACKING MEDIA
166 // for EMCAL: idtmed[1599->1698] equivalent to fIdtmed[0->100]
167 Int_t * idtmed = fIdtmed->GetArray() - 1599 ;
168 Int_t isxfld = gAlice->Field()->Integ() ;
169 Float_t sxmgmx = gAlice->Field()->Max() ;
171 // Air -> idtmed[1599]
172 AliMedium(0, "Air$", 0, 0,
173 isxfld, sxmgmx, 10.0, 1.0, 0.1, 0.1, 10.0, 0, 0) ;
175 // The Lead -> idtmed[1600]
177 AliMedium(1, "Lead$", 1, 0,
178 isxfld, sxmgmx, 10.0, 0.1, 0.1, 0.1, 0.1, 0, 0) ;
180 // The scintillator of the CPV made of Polystyrene scintillator -> idtmed[1601]
181 AliMedium(2, "Scintillator$", 2, 1,
182 isxfld, sxmgmx, 10.0, 0.001, 0.1, 0.001, 0.001, 0, 0) ;
184 // Various Aluminium parts made of Al -> idtmed[1602]
185 AliMedium(3, "Al$", 3, 0,
186 isxfld, sxmgmx, 10.0, 0.1, 0.1, 0.001, 0.001, 0, 0) ;
188 // 25-aug-04 by PAI : see PMD/AliPMDv0.cxx for STEEL definition -> idtmed[1603]
189 AliMedium(4, "S steel$", 4, 0,
190 isxfld, sxmgmx, 10.0, 0.1, 0.1, 0.001, 0.001, 0, 0) ;
192 // --- Set decent energy thresholds for gamma and electron tracking
194 // Tracking threshold for photons and electrons in Lead
195 Float_t cutgam=10.e-5; // 100 kev;
196 Float_t cutele=10.e-5; // 100 kev;
197 TString ntmp(GetTitle());
199 if(ntmp.Contains("10KEV")) {
200 cutele = cutgam = 1.e-5;
201 } else if(ntmp.Contains("50KEV")) {
202 cutele = cutgam = 5.e-5;
203 } else if(ntmp.Contains("100KEV")) {
204 cutele = cutgam = 1.e-4;
205 } else if(ntmp.Contains("200KEV")) {
206 cutele = cutgam = 2.e-4;
207 } else if(ntmp.Contains("500KEV")) {
208 cutele = cutgam = 5.e-4;
211 gMC->Gstpar(idtmed[1600],"CUTGAM", cutgam);
212 gMC->Gstpar(idtmed[1600],"CUTELE", cutele); // 1MEV -> 0.1MEV; 15-aug-05
213 gMC->Gstpar(idtmed[1600],"BCUTE", cutgam); // BCUTE and BCUTM start from GUTGUM
214 gMC->Gstpar(idtmed[1600],"BCUTM", cutgam); // BCUTE and BCUTM start from GUTGUM
215 // --- Generate explicitly delta rays in Lead ---
216 gMC->Gstpar(idtmed[1600], "LOSS",3.) ;
217 gMC->Gstpar(idtmed[1600], "DRAY",1.) ;
218 gMC->Gstpar(idtmed[1600], "DCUTE", cutele) ;
219 gMC->Gstpar(idtmed[1600], "DCUTM", cutele) ;
221 // --- in aluminium parts ---
222 gMC->Gstpar(idtmed[1602],"CUTGAM", cutgam) ;
223 gMC->Gstpar(idtmed[1602],"CUTELE", cutele) ;
224 gMC->Gstpar(idtmed[1602],"BCUTE", cutgam); // BCUTE and BCUTM start from GUTGUM
225 gMC->Gstpar(idtmed[1602],"BCUTM", cutgam); // BCUTE and BCUTM start from GUTGUM
226 gMC->Gstpar(idtmed[1602], "LOSS",3.) ;
227 gMC->Gstpar(idtmed[1602], "DRAY",1.) ;
228 gMC->Gstpar(idtmed[1602], "DCUTE", cutele) ;
229 gMC->Gstpar(idtmed[1602], "DCUTM", cutele) ;
231 // --- and finally thresholds for photons and electrons in the scintillator ---
232 gMC->Gstpar(idtmed[1601],"CUTGAM", cutgam) ;
233 gMC->Gstpar(idtmed[1601],"CUTELE", cutele) ;// 1MEV -> 0.1MEV; 15-aug-05
234 gMC->Gstpar(idtmed[1601],"BCUTE", cutgam); // BCUTE and BCUTM start from GUTGUM
235 gMC->Gstpar(idtmed[1601],"BCUTM", cutgam); // BCUTE and BCUTM start from GUTGUM
236 gMC->Gstpar(idtmed[1601], "LOSS",3.) ; // generate delta rays
237 gMC->Gstpar(idtmed[1601], "DRAY",1.) ;
238 gMC->Gstpar(idtmed[1601], "DCUTE", cutele) ;
239 gMC->Gstpar(idtmed[1601], "DCUTM", cutele) ;
242 gMC->Gstpar(idtmed[1603],"CUTGAM", cutgam);
243 gMC->Gstpar(idtmed[1603],"CUTELE", cutele);
244 gMC->Gstpar(idtmed[1603],"BCUTE", cutgam); // BCUTE and BCUTM start from GUTGUM
245 gMC->Gstpar(idtmed[1603],"BCUTM", cutgam); // BCUTE and BCUTM start from GUTGUM
246 // --- Generate explicitly delta rays
247 gMC->Gstpar(idtmed[1603], "LOSS",3.);
248 gMC->Gstpar(idtmed[1603], "DRAY",1.);
249 gMC->Gstpar(idtmed[1603], "DCUTE", cutele) ;
250 gMC->Gstpar(idtmed[1603], "DCUTM", cutele) ;
252 //set constants for Birk's Law implentation
255 fBirkC2 = 9.6e-6/(dP * dP);
258 //____________________________________________________________________________
259 void AliEMCAL::Digits2Raw()
261 // convert digits of the current event to raw data
263 AliEMCALLoader * loader = dynamic_cast<AliEMCALLoader*>(fLoader) ;
266 loader->LoadDigits("EMCAL");
268 TClonesArray* digits = loader->Digits() ;
271 Error("Digits2Raw", "no digits found !");
276 loader->LoadDigitizer();
277 AliEMCALDigitizer * digitizer = dynamic_cast<AliEMCALDigitizer *>(loader->Digitizer()) ;
280 AliEMCALGeometry* geom = GetGeometry();
282 AliError(Form("No geometry found !"));
286 AliAltroBuffer* buffer = NULL;
288 Int_t adcValuesLow[fgkTimeBins];
289 Int_t adcValuesHigh[fgkTimeBins];
291 //Load Mapping RCU files once
292 TString path = gSystem->Getenv("ALICE_ROOT");
293 path += "/EMCAL/mapping/RCU";
294 TString path0 = path+"0.data";//This file will change in future
295 TString path1 = path+"1.data";//This file will change in future
296 AliAltroMapping * mapping[2] ; // For the moment only 2
297 mapping[0] = new AliCaloAltroMapping(path0.Data());
298 mapping[1] = new AliCaloAltroMapping(path1.Data());
300 // loop over digits (assume ordered digits)
301 for (Int_t iDigit = 0; iDigit < digits->GetEntries(); iDigit++) {
302 AliEMCALDigit* digit = dynamic_cast<AliEMCALDigit *>(digits->At(iDigit)) ;
303 if (digit->GetAmp() < fgThreshold)
313 geom->GetCellIndex(digit->GetId(), nSM, nTower, nIphi, nIeta);
314 geom->GetCellPhiEtaIndexInSModule(nSM, nTower, nIphi, nIeta,iphi, ieta) ;
316 //Check which is the RCU of the cell.
319 if (0<=iphi&&iphi<8) iRCU=0; // first cable row
320 else if (8<=iphi&&iphi<16 && 0<=ieta&&ieta<24) iRCU=0; // first half;
323 else if(8<=iphi&&iphi<16 && 24<=ieta&&ieta<48) iRCU=1; // second half;
325 else if(16<=iphi&&iphi<24) iRCU=1; // third cable row
328 Int_t iDDL = fgDDLPerSuperModule* nSM + iRCU;
331 if (iDDL != prevDDL) {
332 // write real header and close previous file
336 buffer->WriteDataHeader(kFALSE, kFALSE);
340 // open new file and write dummy header
341 TString fileName = AliDAQ::DdlFileName("EMCAL",iDDL);
342 buffer = new AliAltroBuffer(fileName.Data(),mapping[iRCU]);
343 buffer->WriteDataHeader(kTRUE, kFALSE); //Dummy;
347 // out of time range signal (?)
348 if (digit->GetTimeR() > GetRawFormatTimeMax() ) {
349 AliInfo("Signal is out of time range.\n");
350 buffer->FillBuffer((Int_t)digit->GetAmp());
351 buffer->FillBuffer(GetRawFormatTimeBins() ); // time bin
352 buffer->FillBuffer(3); // bunch length
353 buffer->WriteTrailer(3, ieta, iphi, nSM); // trailer
354 // calculate the time response function
357 Double_t energy = digit->GetAmp() * digitizer->GetECAchannel() + digitizer->GetECApedestal() ;
359 Bool_t lowgain = RawSampledResponse(digit->GetTimeR(), energy, adcValuesHigh, adcValuesLow) ;
362 buffer->WriteChannel(ieta, iphi, 0, GetRawFormatTimeBins(), adcValuesLow, fgThreshold);
364 buffer->WriteChannel(ieta,iphi, 1, GetRawFormatTimeBins(), adcValuesHigh, fgThreshold);
369 // write real header and close last file
372 buffer->WriteDataHeader(kFALSE, kFALSE);
375 mapping[0]->Delete();
376 mapping[1]->Delete();
377 loader->UnloadDigits();
380 //____________________________________________________________________________
381 void AliEMCAL::Raw2Digits(AliRawReader* reader)
383 // convert raw data of the current event to digits
384 AliEMCALGeometry * geom = GetGeometry();
385 AliEMCALLoader * loader = dynamic_cast<AliEMCALLoader*>(fLoader) ;
388 loader->CleanDigits(); // start from scratch
389 loader->LoadDigits("EMCAL");
390 TClonesArray* digits = loader->Digits() ;
391 digits->Clear(); // yes, this is perhaps somewhat paranoid.. [clearing an extra time]
394 Error("Raw2Digits", "no digits found !");
398 Error("Raw2Digits", "no raw reader found !");
402 // and get the digitizer too
403 loader->LoadDigitizer();
404 AliEMCALDigitizer * digitizer = dynamic_cast<AliEMCALDigitizer *>(loader->Digitizer()) ;
406 // Use AliAltroRawStream to read the ALTRO format. No need to
407 // reinvent the wheel :-)
408 AliCaloRawStream in(reader,"EMCAL");
409 // Select EMCAL DDL's;
410 reader->Select("EMCAL");
412 // reading is from previously existing AliEMCALGetter.cxx
414 Bool_t first = kTRUE ;
416 TF1 * signalF = new TF1("signal", RawResponseFunction, 0, GetRawFormatTimeMax(), 4);
417 signalF->SetParNames("Charge", "Gain", "Amplitude", "TimeZero");
419 Bool_t lowGainFlag = kFALSE ;
424 Double_t energy = 0. ;
426 TGraph * gLowGain = new TGraph(GetRawFormatTimeBins()) ;
427 TGraph * gHighGain= new TGraph(GetRawFormatTimeBins()) ;
429 while ( in.Next() ) { // EMCAL entries loop
430 if ( in.IsNewRow() ) {//phi
431 if ( in.IsNewColumn() ) {//eta
432 id = geom->GetAbsCellIdFromCellIndexes(in.GetModule(), in.GetRow(), in.GetColumn()) ;
434 FitRaw(lowGainFlag, gLowGain, gHighGain, signalF, energy, time) ;
436 if (time == 0. && energy == 0.) {
440 amp = static_cast<Int_t>( (energy - digitizer->GetECApedestal()) / digitizer->GetECAchannel() + 0.5 ) ;
444 new((*digits)[idigit]) AliEMCALDigit( -1, -1, id, amp, time) ;
448 for (index = 0; index < GetRawFormatTimeBins(); index++) {
449 gLowGain->SetPoint(index, index * GetRawFormatTimeMax() / GetRawFormatTimeBins(), 0) ;
450 gHighGain->SetPoint(index, index * GetRawFormatTimeMax() / GetRawFormatTimeBins(), 0) ;
454 id = geom->GetAbsCellIdFromCellIndexes(in.GetModule(), in.GetRow(), in.GetColumn()) ;
455 if (in.GetModule() == GetRawFormatLowGainOffset() ) {
456 lowGainFlag = kTRUE ;
459 lowGainFlag = kFALSE ;
464 gLowGain->SetPoint(in.GetTime(),
465 in.GetTime()* GetRawFormatTimeMax() / GetRawFormatTimeBins(),
469 gHighGain->SetPoint(in.GetTime(),
470 in.GetTime() * GetRawFormatTimeMax() / GetRawFormatTimeBins(),
473 } // EMCAL entries loop
483 //____________________________________________________________________________
484 void AliEMCAL::FitRaw(Bool_t lowGainFlag, TGraph * gLowGain, TGraph * gHighGain, TF1* signalF, Double_t & energy, Double_t & time)
486 // Fits the raw signal time distribution; from AliEMCALGetter
488 const Int_t kNoiseThreshold = 0 ;
489 Double_t timezero1 = 0., timezero2 = 0., timemax = 0. ;
490 Double_t signal = 0., signalmax = 0. ;
494 timezero1 = timezero2 = signalmax = timemax = 0. ;
495 signalF->FixParameter(0, GetRawFormatLowCharge()) ;
496 signalF->FixParameter(1, GetRawFormatLowGain()) ;
498 for (index = 0; index < GetRawFormatTimeBins(); index++) {
499 gLowGain->GetPoint(index, time, signal) ;
500 if (signal > kNoiseThreshold && timezero1 == 0.)
502 if (signal <= kNoiseThreshold && timezero1 > 0. && timezero2 == 0.)
504 if (signal > signalmax) {
509 signalmax /= RawResponseFunctionMax(GetRawFormatLowCharge(),
510 GetRawFormatLowGain()) ;
511 if ( timezero1 + GetRawFormatTimePeak() < GetRawFormatTimeMax() * 0.4 ) { // else its noise
512 signalF->SetParameter(2, signalmax) ;
513 signalF->SetParameter(3, timezero1) ;
514 gLowGain->Fit(signalF, "QRON", "", 0., timezero2); //, "QRON") ;
515 energy = signalF->GetParameter(2) ;
516 time = signalF->GetMaximumX() - GetRawFormatTimePeak() - GetRawFormatTimeTrigger() ;
519 timezero1 = timezero2 = signalmax = timemax = 0. ;
520 signalF->FixParameter(0, GetRawFormatHighCharge()) ;
521 signalF->FixParameter(1, GetRawFormatHighGain()) ;
523 for (index = 0; index < GetRawFormatTimeBins(); index++) {
524 gHighGain->GetPoint(index, time, signal) ;
525 if (signal > kNoiseThreshold && timezero1 == 0.)
527 if (signal <= kNoiseThreshold && timezero1 > 0. && timezero2 == 0.)
529 if (signal > signalmax) {
534 signalmax /= RawResponseFunctionMax(GetRawFormatHighCharge(),
535 GetRawFormatHighGain()) ;;
536 if ( timezero1 + GetRawFormatTimePeak() < GetRawFormatTimeMax() * 0.4 ) { // else its noise
537 signalF->SetParameter(2, signalmax) ;
538 signalF->SetParameter(3, timezero1) ;
539 gHighGain->Fit(signalF, "QRON", "", 0., timezero2) ;
540 energy = signalF->GetParameter(2) ;
541 time = signalF->GetMaximumX() - GetRawFormatTimePeak() - GetRawFormatTimeTrigger() ;
548 //____________________________________________________________________________
549 void AliEMCAL::Hits2SDigits()
551 // create summable digits
554 AliEMCALSDigitizer emcalDigitizer(fLoader->GetRunLoader()->GetFileName().Data()) ;
555 emcalDigitizer.SetEventRange(0, -1) ; // do all the events
556 emcalDigitizer.ExecuteTask() ;
559 //____________________________________________________________________________
561 AliLoader* AliEMCAL::MakeLoader(const char* topfoldername)
563 //different behaviour than standard (singleton getter)
564 // --> to be discussed and made eventually coherent
565 fLoader = new AliEMCALLoader(GetName(),topfoldername);
569 //__________________________________________________________________
570 Double_t AliEMCAL::RawResponseFunction(Double_t *x, Double_t *par)
572 // Shape of the electronics raw reponse:
573 // It is a semi-gaussian, 2nd order Gamma function of the general form
574 // v(t) = n**n * Q * A**n / C *(t/tp)**n * exp(-n * t/tp) with
575 // tp : peaking time par[0]
576 // n : order of the function
577 // C : integrating capacitor in the preamplifier
578 // A : open loop gain of the preamplifier
579 // Q : the total APD charge to be measured Q = C * energy
582 Double_t xx = x[0] - ( fgTimeTrigger + par[3] ) ;
584 if (xx < 0 || xx > fgTimeMax)
587 Double_t fac = par[0] * TMath::Power(fgOrder, fgOrder) * TMath::Power(par[1], fgOrder) / fgCapa ;
588 signal = fac * par[2] * TMath::Power(xx / fgTimePeak, fgOrder) * TMath::Exp(-fgOrder * (xx / fgTimePeak)) ;
593 //__________________________________________________________________
594 Double_t AliEMCAL::RawResponseFunctionMax(Double_t charge, Double_t gain)
596 //compute the maximum of the raw response function and return
597 return ( charge * TMath::Power(fgOrder, fgOrder) * TMath::Power(gain, fgOrder)
598 / ( fgCapa * TMath::Exp(fgOrder) ) );
601 //__________________________________________________________________
602 Bool_t AliEMCAL::RawSampledResponse(
603 const Double_t dtime, const Double_t damp, Int_t * adcH, Int_t * adcL) const
605 // for a start time dtime and an amplitude damp given by digit,
606 // calculates the raw sampled response AliEMCAL::RawResponseFunction
608 const Int_t kRawSignalOverflow = 0x3FF ;
609 Bool_t lowGain = kFALSE ;
611 TF1 signalF("signal", RawResponseFunction, 0, GetRawFormatTimeMax(), 4);
613 for (Int_t iTime = 0; iTime < GetRawFormatTimeBins(); iTime++) {
614 signalF.SetParameter(0, GetRawFormatHighCharge() ) ;
615 signalF.SetParameter(1, GetRawFormatHighGain() ) ;
616 signalF.SetParameter(2, damp) ;
617 signalF.SetParameter(3, dtime) ;
618 Double_t time = iTime * GetRawFormatTimeMax() / GetRawFormatTimeBins() ;
619 Double_t signal = signalF.Eval(time) ;
620 if ( static_cast<Int_t>(signal+0.5) > kRawSignalOverflow ){ // larger than 10 bits
621 signal = kRawSignalOverflow ;
624 adcH[iTime] = static_cast<Int_t>(signal + 0.5) ;
626 signalF.SetParameter(0, GetRawFormatLowCharge() ) ;
627 signalF.SetParameter(1, GetRawFormatLowGain() ) ;
628 signal = signalF.Eval(time) ;
629 if ( static_cast<Int_t>(signal+0.5) > kRawSignalOverflow) // larger than 10 bits
630 signal = kRawSignalOverflow ;
631 adcL[iTime] = static_cast<Int_t>(0.5 + signal ) ;