Bug fix in the constructor (thanks to A.Marin)
[u/mrichter/AliRoot.git] / EMCAL / AliEMCAL.cxx
CommitLineData
2012850d 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$ */
2012850d 17//_________________________________________________________________________
18// Base Class for EMCAL description:
ffa6d63b 19// This class contains material definitions
20// for the EMCAL - It does not place the detector in Alice
2012850d 21//*-- Author: Yves Schutz (SUBATECH)
b13bbe81 22//
23//*-- Additional Contributions: Sahal Yacoob (LBNL/UCT)
3d841a9f 24// : Alexei Pavlinov (WSU)
b13bbe81 25//
2012850d 26//////////////////////////////////////////////////////////////////////////////
27
2012850d 28// --- ROOT system ---
b13bbe81 29class TFile;
88cb7938 30#include <TFolder.h>
f7a1cc68 31#include <TGeoGlobalMagField.h>
32#include <TGraph.h>
046ae904 33#include <TH1F.h>
046ae904 34#include <TRandom.h>
f7a1cc68 35#include <TTree.h>
36#include <TVirtualMC.h>
2012850d 37
05a92d59 38// --- Standard library ---
2012850d 39
05a92d59 40// --- AliRoot header files ---
2012850d 41#include "AliMagF.h"
050f9171 42#include "AliLog.h"
88cb7938 43#include "AliEMCAL.h"
85a5290f 44#include "AliRun.h"
050f9171 45#include "AliRunLoader.h"
46#include "AliCDBManager.h"
5dee926e 47#include "AliEMCALLoader.h"
85a5290f 48#include "AliEMCALSDigitizer.h"
49#include "AliEMCALDigitizer.h"
5dee926e 50#include "AliEMCALDigit.h"
ee299369 51#include "AliEMCALRawUtils.h"
3294dade 52#include "AliCDBManager.h"
53#include "AliCDBEntry.h"
6cc75819 54#include "AliEMCALRawUtils.h"
55#include "AliRawReader.h"
56#include "AliEMCALTriggerData.h"
57#include "AliEMCALRecParam.h"
58#include "AliRawEventHeaderBase.h"
3294dade 59
2012850d 60ClassImp(AliEMCAL)
4884333f 61
6cc75819 62//for embedding
63AliEMCALRawUtils* AliEMCAL::fgRawUtils = 0; // EMCAL raw utilities class
64
2012850d 65//____________________________________________________________________________
18a21c7c 66AliEMCAL::AliEMCAL()
67 : AliDetector(),
68 fBirkC0(0),
69 fBirkC1(0.),
70 fBirkC2(0.),
c2ef87c2 71 fGeometry(0),
6cc75819 72 fCheckRunNumberAndGeoVersion(kTRUE),
73 fTriggerData(0x0)
2012850d 74{
05a92d59 75 // Default ctor
046ae904 76 fName = "EMCAL" ;
7235aed2 77 InitConstants();
6cc75819 78
23ef18ac 79 // Should call AliEMCALGeometry::GetInstance(EMCAL->GetTitle(),"") for getting EMCAL geometry
2012850d 80}
05a92d59 81
2012850d 82//____________________________________________________________________________
18a21c7c 83AliEMCAL::AliEMCAL(const char* name, const char* title)
84 : AliDetector(name,title),
85 fBirkC0(0),
86 fBirkC1(0.),
87 fBirkC2(0.),
c2ef87c2 88 fGeometry(0),
6cc75819 89 fCheckRunNumberAndGeoVersion(kTRUE),
90 fTriggerData(0x0)
05a92d59 91{
92 // ctor : title is used to identify the layout
7235aed2 93 InitConstants();
6cc75819 94
0a4cb131 95}
96
97//____________________________________________________________________________
05a92d59 98AliEMCAL::~AliEMCAL()
99{
14ce0a6e 100 //dtor
6cc75819 101 delete fgRawUtils;
102 delete fTriggerData;
103
104 AliLoader *emcalLoader=0;
105 if ((emcalLoader = AliRunLoader::Instance()->GetDetectorLoader("EMCAL")))
106 emcalLoader->CleanSDigitizer();
107
108
2012850d 109}
110
111//____________________________________________________________________________
7235aed2 112void AliEMCAL::InitConstants()
0a4cb131 113{
114 //initialize EMCAL values
115 fBirkC0 = 1;
116 fBirkC1 = 0.013/1.032;
117 fBirkC2 = 9.6e-6/(1.032 * 1.032);
050f9171 118}
0a4cb131 119
b8a520ff 120//Not needed, modify $ALICE_ROOT/data/galice.cuts instead.
121//Load the modified one in the configuration file with SetTransPar
122// //____________________________________________________________________________
123// void AliEMCAL::DefineMediumParameters()
124// {
125// //
126// // EMCAL cuts (Geant3)
127// //
128// Int_t * idtmed = fIdtmed->GetArray() - 1599 ;
129// // --- Set decent energy thresholds for gamma and electron tracking
130
131// // Tracking threshold for photons and electrons in Lead
132// Float_t cutgam=10.e-5; // 100 kev;
133// Float_t cutele=10.e-5; // 100 kev;
134// TString ntmp(GetTitle());
135// ntmp.ToUpper();
136// if(ntmp.Contains("10KEV")) {
137// cutele = cutgam = 1.e-5;
138// } else if(ntmp.Contains("50KEV")) {
139// cutele = cutgam = 5.e-5;
140// } else if(ntmp.Contains("100KEV")) {
141// cutele = cutgam = 1.e-4;
142// } else if(ntmp.Contains("200KEV")) {
143// cutele = cutgam = 2.e-4;
144// } else if(ntmp.Contains("500KEV")) {
145// cutele = cutgam = 5.e-4;
146// }
147
148// gMC->Gstpar(idtmed[1600],"CUTGAM", cutgam);
149// gMC->Gstpar(idtmed[1600],"CUTELE", cutele); // 1MEV -> 0.1MEV; 15-aug-05
150// gMC->Gstpar(idtmed[1600],"BCUTE", cutgam); // BCUTE and BCUTM start from GUTGUM
151// gMC->Gstpar(idtmed[1600],"BCUTM", cutgam); // BCUTE and BCUTM start from GUTGUM
152// // --- Generate explicitly delta rays in Lead ---
153// gMC->Gstpar(idtmed[1600], "LOSS", 3) ;
154// gMC->Gstpar(idtmed[1600], "DRAY", 1) ;
155// gMC->Gstpar(idtmed[1600], "DCUTE", cutele) ;
156// gMC->Gstpar(idtmed[1600], "DCUTM", cutele) ;
157
158// // --- in aluminium parts ---
159// gMC->Gstpar(idtmed[1602],"CUTGAM", cutgam) ;
160// gMC->Gstpar(idtmed[1602],"CUTELE", cutele) ;
161// gMC->Gstpar(idtmed[1602],"BCUTE", cutgam); // BCUTE and BCUTM start from GUTGUM
162// gMC->Gstpar(idtmed[1602],"BCUTM", cutgam); // BCUTE and BCUTM start from GUTGUM
163// gMC->Gstpar(idtmed[1602], "LOSS",3.) ;
164// gMC->Gstpar(idtmed[1602], "DRAY",1.) ;
165// gMC->Gstpar(idtmed[1602], "DCUTE", cutele) ;
166// gMC->Gstpar(idtmed[1602], "DCUTM", cutele) ;
167
168// // --- and finally thresholds for photons and electrons in the scintillator ---
169// gMC->Gstpar(idtmed[1601],"CUTGAM", cutgam) ;
170// gMC->Gstpar(idtmed[1601],"CUTELE", cutele) ;// 1MEV -> 0.1MEV; 15-aug-05
171// gMC->Gstpar(idtmed[1601],"BCUTE", cutgam); // BCUTE and BCUTM start from GUTGUM
172// gMC->Gstpar(idtmed[1601],"BCUTM", cutgam); // BCUTE and BCUTM start from GUTGUM
173// gMC->Gstpar(idtmed[1601], "LOSS",3) ; // generate delta rays
174// gMC->Gstpar(idtmed[1601], "DRAY",1) ;
175// gMC->Gstpar(idtmed[1601], "DCUTE", cutele) ;
176// gMC->Gstpar(idtmed[1601], "DCUTM", cutele) ;
177
178// // S steel -
179// gMC->Gstpar(idtmed[1603],"CUTGAM", cutgam);
180// gMC->Gstpar(idtmed[1603],"CUTELE", cutele);
181// gMC->Gstpar(idtmed[1603],"BCUTE", cutgam); // BCUTE and BCUTM start from GUTGUM
182// gMC->Gstpar(idtmed[1603],"BCUTM", cutgam); // BCUTE and BCUTM start from GUTGUM
183// // --- Generate explicitly delta rays
184// gMC->Gstpar(idtmed[1603], "LOSS",3);
185// gMC->Gstpar(idtmed[1603], "DRAY",1);
186// gMC->Gstpar(idtmed[1603], "DCUTE", cutele) ;
187// gMC->Gstpar(idtmed[1603], "DCUTM", cutele) ;
188
189// AliEMCALGeometry* geom = GetGeometry();
190// if(geom->GetILOSS()>=0) {
191// for(int i=1600; i<=1603; i++) gMC->Gstpar(idtmed[i], "LOSS", geom->GetILOSS()) ;
192// }
193// if(geom->GetIHADR()>=0) {
194// for(int i=1600; i<=1603; i++) gMC->Gstpar(idtmed[i], "HADR", geom->GetIHADR()) ;
195// }
196// }
7235aed2 197
198//____________________________________________________________________________
199AliDigitizer* AliEMCAL::CreateDigitizer(AliRunDigitizer* manager) const
200{
201 //create and return the digitizer
202 return new AliEMCALDigitizer(manager);
203}
204
205//____________________________________________________________________________
206void AliEMCAL::CreateMaterials()
207{
208 // Definitions of materials to build EMCAL and associated tracking media.
209 // media number in idtmed are 1599 to 1698.
210 // --- Air ---
211 Float_t aAir[4]={12.0107,14.0067,15.9994,39.948};
212 Float_t zAir[4]={6.,7.,8.,18.};
213 Float_t wAir[4]={0.000124,0.755267,0.231781,0.012827};
214 Float_t dAir = 1.20479E-3;
215 AliMixture(0, "Air$", aAir, zAir, dAir, 4, wAir) ;
216
217 // --- Lead ---
218 AliMaterial(1, "Pb$", 207.2, 82, 11.35, 0.56, 0., 0, 0) ;
219
220
221 // --- The polysterene scintillator (CH) ---
222 Float_t aP[2] = {12.011, 1.00794} ;
223 Float_t zP[2] = {6.0, 1.0} ;
224 Float_t wP[2] = {1.0, 1.0} ;
225 Float_t dP = 1.032 ;
226
227 AliMixture(2, "Polystyrene$", aP, zP, dP, -2, wP) ;
228
229 // --- Aluminium ---
230 AliMaterial(3, "Al$", 26.98, 13., 2.7, 8.9, 999., 0, 0) ;
231 // --- Absorption length is ignored ^
232
233 // 25-aug-04 by PAI - see PMD/AliPMDv0.cxx for STEEL definition
234 Float_t asteel[4] = { 55.847,51.9961,58.6934,28.0855 };
235 Float_t zsteel[4] = { 26.,24.,28.,14. };
236 Float_t wsteel[4] = { .715,.18,.1,.005 };
237 AliMixture(4, "STAINLESS STEEL$", asteel, zsteel, 7.88, 4, wsteel);
238
3d841a9f 239 // Oct 26,2010 : Multipurpose Copy Paper UNV-21200), weiht 75 g/m**2.
240 // *Cellulose C6H10O5
241 // Component C A=12.01 Z=6. W=6./21.
242 // Component H A=1. Z=1. W=10./21.
243 // Component O A=16. Z=8. W=5./21.
244 Float_t apaper[3] = { 12.01, 1.0, 16.0};
fb3bd607 245 Float_t zpaper[3] = { 6.0, 1.0, 8.0};
3d841a9f 246 Float_t wpaper[3] = {6./21., 10./21., 5./21.};
247 AliMixture(5, "BondPaper$", apaper, zpaper, 0.75, 3, wpaper);
248
7235aed2 249 // DEFINITION OF THE TRACKING MEDIA
ce540969 250 // Look to the $ALICE_ROOT/data/galice.cuts for particular values
251 // of cuts.
252 // Don't forget to add a new tracking medium with non-default cuts
7235aed2 253
254 // for EMCAL: idtmed[1599->1698] equivalent to fIdtmed[0->100]
f7a1cc68 255 Int_t isxfld = ((AliMagF*)TGeoGlobalMagField::Instance()->GetField())->Integ() ;
256 Float_t sxmgmx = ((AliMagF*)TGeoGlobalMagField::Instance()->GetField())->Max() ;
7235aed2 257
258 // Air -> idtmed[1599]
259 AliMedium(0, "Air$", 0, 0,
260 isxfld, sxmgmx, 10.0, 1.0, 0.1, 0.1, 10.0, 0, 0) ;
261
262 // The Lead -> idtmed[1600]
263
264 AliMedium(1, "Lead$", 1, 0,
265 isxfld, sxmgmx, 10.0, 0.1, 0.1, 0.1, 0.1, 0, 0) ;
266
267 // The scintillator of the CPV made of Polystyrene scintillator -> idtmed[1601]
ee299369 268 float deemax = 0.1; // maximum fractional energy loss in one step (0 < DEEMAX < deemax )
7235aed2 269 AliMedium(2, "Scintillator$", 2, 1,
270 isxfld, sxmgmx, 10.0, 0.001, deemax, 0.001, 0.001, 0, 0) ;
271
272 // Various Aluminium parts made of Al -> idtmed[1602]
273 AliMedium(3, "Al$", 3, 0,
274 isxfld, sxmgmx, 10.0, 0.1, 0.1, 0.001, 0.001, 0, 0) ;
275
276 // 25-aug-04 by PAI : see PMD/AliPMDv0.cxx for STEEL definition -> idtmed[1603]
277 AliMedium(4, "S steel$", 4, 0,
3d841a9f 278 isxfld, sxmgmx, 10.0, 0.01, 0.1, 0.001, 0.001, 0, 0) ;
279
ce540969 280 // Oct 26,2010; Nov 24,2010 -> idtmed[1604]
281 deemax = 0.01;
3d841a9f 282 AliMedium(5, "Paper$", 5, 0,
ce540969 283 isxfld, sxmgmx, 10.0, deemax, 0.1, 0.001, 0.001, 0, 0) ;
7235aed2 284
89557f6d 285
ab37d09c 286 //set constants for Birk's Law implentation
287 fBirkC0 = 1;
288 fBirkC1 = 0.013/dP;
289 fBirkC2 = 9.6e-6/(dP * dP);
290
2012850d 291}
dde0a601 292
293//____________________________________________________________________________
294void AliEMCAL::Init()
b8a520ff 295{
296 // Init
297 //Not needed, modify $ALICE_ROOT/data/galice.cuts instead.
298 //Load the modified one in the configuration file with SetTransPar
299 //DefineMediumParameters();
dde0a601 300}
301
f51151a0 302//____________________________________________________________________________
ee299369 303void AliEMCAL::Digits2Raw() {
65bdc82f 304
305 static AliEMCALRawUtils rawUtils;
306 rawUtils.Digits2Raw();
307
2d5d9e60 308}
2d5d9e60 309//____________________________________________________________________________
8367ce9a 310void AliEMCAL::Hits2SDigits()
311{
312// create summable digits
313
ddca522a 314 GetGeometry();
4d33c797 315 AliEMCALSDigitizer emcalDigitizer(fLoader->GetRunLoader()->GetFileName().Data()) ;
316 emcalDigitizer.SetEventRange(0, -1) ; // do all the events
317 emcalDigitizer.ExecuteTask() ;
da480a28 318}
319
6cc75819 320//______________________________________________________________________
321Bool_t AliEMCAL::Raw2SDigits(AliRawReader* rawReader){
322
323 // Conversion from raw data to EMCAL sdigits.
324 // Does the same as AliEMCALReconstructor::ConvertDigits()
325 // Needed to embed real data and simulation
326 // Works on a single-event basis
327
328 rawReader->Reset() ;
329
330 //Get/create the sdigits tree and array
331 AliRunLoader *rl = AliRunLoader::Instance();
1c67f0f5 332 AliEMCALLoader *emcalLoader = dynamic_cast<AliEMCALLoader*>(rl->GetDetectorLoader("EMCAL"));
333
334 if(!emcalLoader){
335 AliFatal("NULL loader");
336 return kFALSE;
337 }
338
6cc75819 339 emcalLoader->GetEvent();
340 emcalLoader->LoadSDigits("UPDATE");
341
342 TTree * treeS = emcalLoader->TreeS();
343 if ( !treeS ) {
344 emcalLoader->MakeSDigitsContainer();
345 treeS = emcalLoader->TreeS();
346 }
347
348 if(!emcalLoader->SDigits()) {
349 AliFatal("No sdigits array available\n");
350 return kFALSE;
351 }
352
353 TClonesArray * sdigits = emcalLoader->SDigits();
354 sdigits->Clear("C");
355
356 //Trigger sdigits
357 if(!fTriggerData)fTriggerData = new AliEMCALTriggerData();
358 fTriggerData->SetMode(1);
359 TClonesArray *digitsTrg = new TClonesArray("AliEMCALTriggerRawDigit", 32 * 96);
360 Int_t bufsize = 32000;
361 treeS->Branch("EMTRG", &digitsTrg, bufsize);
362
363
364 //Only physics events
365 if (rawReader->GetType()== AliRawEventHeaderBase::kPhysicsEvent) {
366
367 if(!fgRawUtils) fgRawUtils = new AliEMCALRawUtils;
368 //must be done here because, in constructor, option is not yet known
369 fgRawUtils->SetOption(GetOption());
370
371 // Set parameters from OCDB to raw utils
372 AliEMCALRecParam* recpar = emcalLoader->ReconstructionParameters(0);
373 // fgRawUtils->SetRawFormatHighLowGainFactor(recpar->GetHighLowGainFactor());
374 // fgRawUtils->SetRawFormatOrder(recpar->GetOrderParameter());
375 // fgRawUtils->SetRawFormatTau(recpar->GetTau());
376 fgRawUtils->SetNoiseThreshold(recpar->GetNoiseThreshold());
377 fgRawUtils->SetNPedSamples(recpar->GetNPedSamples());
378 fgRawUtils->SetRemoveBadChannels(recpar->GetRemoveBadChannels());
379 fgRawUtils->SetFittingAlgorithm(recpar->GetFittingAlgorithm());
380 fgRawUtils->SetFALTROUsage(recpar->UseFALTRO());
381 // fgRawUtils->SetTimeMin(recpar->GetTimeMin());
382 // fgRawUtils->SetTimeMax(recpar->GetTimeMax());
383
384 //Fit
385 fgRawUtils->Raw2Digits(rawReader,sdigits,emcalLoader->PedestalData(),digitsTrg,fTriggerData);
386
387 }//skip calibration event
388 else{
389 AliDebug(1," Calibration Event, skip!");
390 }
391
392 //Final arrangements of the array, set all sdigits as embedded
393 sdigits->Sort() ;
394 for (Int_t iSDigit = 0 ; iSDigit < sdigits->GetEntriesFast() ; iSDigit++) {
395 AliEMCALDigit * sdigit = dynamic_cast<AliEMCALDigit *>(sdigits->At(iSDigit)) ;
396 if(sdigit){
397 sdigit->SetIndexInList(iSDigit) ;
398 sdigit->SetType(AliEMCALDigit::kEmbedded);
399 }
400 else {
401 AliFatal("sdigit is NULL!");
402 }
403 }
404
405 AliDebug(1,Form("Embedded sdigits entries %d \n",sdigits->GetEntriesFast()));
406
407 //Write array, clean arrays, unload ..
408
409 Int_t bufferSize = 32000 ;
410 TBranch * sdigitsBranch = treeS->GetBranch("EMCAL");
411 if (sdigitsBranch)
412 sdigitsBranch->SetAddress(&sdigits);
413 else
414 treeS->Branch("EMCAL",&sdigits,bufferSize);
415
416 treeS->Fill();
417 emcalLoader->WriteSDigits("OVERWRITE");
418 emcalLoader->UnloadSDigits();
419
420 digitsTrg->Delete();
421 delete digitsTrg;
422
423 return kTRUE;
424
425}
426
da480a28 427//____________________________________________________________________________
5dee926e 428
8367ce9a 429AliLoader* AliEMCAL::MakeLoader(const char* topfoldername)
430{
431//different behaviour than standard (singleton getter)
432// --> to be discussed and made eventually coherent
433 fLoader = new AliEMCALLoader(GetName(),topfoldername);
434 return fLoader;
435}
050f9171 436
437//____________________________________________________________________________
438
439AliEMCALGeometry* AliEMCAL::GetGeometry() const
440{
441 //Initializes and returns geometry
442
443 //Check if run number and requested geometry correspond to the same geometry as
444 //in real data taking. To prevent errors in official simulation productions
445 if(!(AliEMCALGeometry::GetInstance()))
446 {
447 if(!fCheckRunNumberAndGeoVersion){// Set geometry with the name used in the configuration file
448 return AliEMCALGeometry::GetInstance(GetTitle(),"EMCAL") ;
449 }
450 else{//Check run number and version and set the corresponding one.
451 //Get run number
452 //AliRunLoader *rl = AliRunLoader::Instance();
453 //Int_t runNumber = rl->GetRunNumber();
454
455 AliCDBManager* man = AliCDBManager::Instance();
456 Int_t runNumber = man->GetRun();
457
458 //Instanciate geometry depending on the run number
459 TString geoName(GetTitle());
460 if(runNumber > 104064 && runNumber <= 140000 ){//2009-2010 runs
461 //First year geometry, 4 SM.
462
463 if(!geoName.Contains("FIRSTYEARV1")){
464 AliInfo(Form("*** ATTENTION *** \n \t Specified geometry name <<%s>> for run %d is not considered! \n \t In use <<EMCAL_FIRSTYEARV1>>, check run number and year \n ",
465 geoName.Data(),runNumber)); }
466 else {
467 AliDebug(1,"Initialized geometry with name <<EMCAL_FIRSTYEARV1>>");}
468
469 return AliEMCALGeometry::GetInstance("EMCAL_FIRSTYEARV1","EMCAL") ;// Set geometry with the name used in the configuration file
470 }
471 else{ //Default geometry
472 //Complete EMCAL geometry, 10 SM.
473
474 if(!geoName.Contains("COMPLETEV1")){
475 AliInfo(Form("*** ATTENTION *** \n \t Specified geometry name <<%s>> for run %d is not considered! \n \t In use <<EMCAL_COMPLETEV1>>, check run number and year \n ",
476 geoName.Data(),runNumber));}
477 else {
478 AliDebug(1,"Initialized geometry with name <<EMCAL_COMPLETEV1>>");}
479
480 return AliEMCALGeometry::GetInstance("EMCAL_COMPLETEV1","EMCAL") ;// Set geometry with the name used in the configuration file
481 }
482 }
483 }// Init geometry for the first time
484
485 return AliEMCALGeometry::GetInstance();
486
487}