forked from alisw/AliRoot
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathAliEMCALReconstructor.cxx
executable file
·1075 lines (898 loc) · 35.3 KB
/
AliEMCALReconstructor.cxx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/**************************************************************************
* Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
* *
* Author: The ALICE Off-line Project. *
* Contributors are mentioned in the code where appropriate. *
* *
* Permission to use, copy, modify and distribute this software and its *
* documentation strictly for non-commercial purposes is hereby granted *
* without fee, provided that the above copyright notice appears in all *
* copies and that both the copyright notice and this permission notice *
* appear in the supporting documentation. The authors make no claims *
* about the suitability of this software for any purpose. It is *
* provided "as is" without express or implied warranty. *
**************************************************************************/
// --- ROOT system ---
#include <TClonesArray.h>
#include "TGeoManager.h"
#include "TGeoMatrix.h"
// --- Standard library ---
#include <iostream>
// --- AliRoot header files ---
#include "AliEMCALReconstructor.h"
#include "AliCodeTimer.h"
#include "AliCaloCalibPedestal.h"
#include "AliEMCALCalibData.h"
#include "AliEMCALCalibTime.h"
#include "AliESDEvent.h"
#include "AliESDCaloCluster.h"
#include "AliESDCaloCells.h"
#include "AliESDtrack.h"
#include "AliEMCALLoader.h"
#include "AliEMCALRawUtils.h"
#include "AliEMCALDigit.h"
#include "AliEMCALClusterizerv1.h"
#include "AliEMCALClusterizerv2.h"
#include "AliEMCALClusterizerv3.h"
#include "AliEMCALClusterizerNxN.h"
#include "AliEMCALRecPoint.h"
#include "AliEMCALPID.h"
#include "AliEMCALRecoUtilsBase.h"
#include "AliRawReader.h"
#include "AliCDBEntry.h"
#include "AliCDBManager.h"
#include "AliEMCALGeometry.h"
#include "AliEMCAL.h"
#include "AliESDVZERO.h"
#include "AliCDBManager.h"
#include "AliRunLoader.h"
#include "AliRun.h"
#include "AliEMCALTriggerData.h"
#include "AliEMCALTriggerElectronics.h"
#include "AliEMCALTriggerDCSConfigDB.h"
#include "AliEMCALTriggerDCSConfig.h"
#include "AliEMCALTriggerData.h"
#include "AliEMCALTriggerRawDigit.h"
#include "AliEMCALTriggerPatch.h"
#include "AliEMCALTriggerTypes.h"
#include "AliESDCalofriend.h"
/// \cond CLASSIMP
ClassImp(AliEMCALReconstructor) ;
/// \endcond
const AliEMCALRecParam* AliEMCALReconstructor::fgkRecParam = 0; // EMCAL rec. parameters
AliEMCALRawUtils* AliEMCALReconstructor::fgRawUtils = 0; // EMCAL raw utilities class
AliEMCALClusterizer* AliEMCALReconstructor::fgClusterizer = 0; // EMCAL clusterizer class
TClonesArray* AliEMCALReconstructor::fgDigitsArr = 0; // list of digits, to be used multiple times
TObjArray* AliEMCALReconstructor::fgClustersArr = 0; // list of clusters, to be used multiple times
TClonesArray* AliEMCALReconstructor::fgTriggerDigits = 0; // list of trigger digits, to be used multiple times
AliEMCALTriggerElectronics *AliEMCALReconstructor::fgTriggerProcessor = 0x0;
TClonesArray *AliEMCALReconstructor::fgTriggerData = 0x0;
///
/// Constructor
///
/// Init :
/// * Geometry
/// * pointer to AliEMCALRawUtils
/// * OCDB: energy calibration, time calibration, bad map
/// * Trigger
/// * Lists: digits, rec points, matching
///
//____________________________________________________________________________
AliEMCALReconstructor::AliEMCALReconstructor()
: fGeom(0),fCalibData(0),fCalibTime(0),fPedestalData(0), fMatches(0x0), fESDCalofriend(0x0)
{
// OCDB initialization, do it here to recover run number
// for geometry
//
AliCDBManager* man = AliCDBManager::Instance();
//----------------------------------
// Initialize the geometry, 3 posibilities:
// * To make sure we match with the geometry in a simulation file,
// let's try to get it first.
// * If not, check the run number assigned for this chunk and set the
// geometry depending on the run number
// * If not, take the default geometry
//
AliRunLoader *rl = AliRunLoader::Instance();
if (rl->GetAliRun())
{
AliEMCAL * emcal = dynamic_cast<AliEMCAL*>(rl->GetAliRun()->GetDetector("EMCAL"));
if(emcal) fGeom = emcal->GetGeometry();
}
if(!fGeom)
{
Int_t runNumber = man->GetRun();
AliInfo(Form("Finding EMCAL Geometry from run number %d.",runNumber));
fGeom = AliEMCALGeometry::GetInstanceFromRunNumber(runNumber);
}
if(!fGeom)
{
AliWarning(Form("Using default geometry in reconstruction!!!"));
fGeom = AliEMCALGeometry::GetInstance(AliEMCALGeometry::GetDefaultGeometryName());
}
if ( !fGeom ) AliFatal(Form("Could not get geometry!"));
else AliInfo (Form("Geometry name: <<%s>>",fGeom->GetName()));
//---------------------------
// Initialize AliEMCALRawUtils
// It must be done after the geometry is initialized since there is a geometry
// initialization in AliEMCALRawUtils that could conflict
//
fgRawUtils = new AliEMCALRawUtils;
//=============================================
// OCDB containers, now get the different
// type of OCDB parameters
//
// Get energy calibration parameters
//
if(!fCalibData)
{
AliCDBEntry *entry = (AliCDBEntry*) man->Get("EMCAL/Calib/Data");
if (entry) fCalibData = (AliEMCALCalibData*) entry->GetObject();
}
if(!fCalibData)
AliFatal("Energy Calibration parameters not found in CDB!");
// Get time calibration parameters if requested
//
if(!fCalibTime)
{
AliCDBEntry *entry = (AliCDBEntry*) man->Get("EMCAL/Calib/Time");
if (entry) fCalibTime = (AliEMCALCalibTime*) entry->GetObject();
}
if(!fCalibTime)
AliFatal("Time Calibration parameters not found in CDB!");
// Get bad channels
//
if(!fPedestalData)
{
AliCDBEntry *entry = (AliCDBEntry*) man->Get("EMCAL/Calib/Pedestals");
if (entry) fPedestalData = (AliCaloCalibPedestal*) entry->GetObject();
}
if(!fPedestalData)
AliFatal("Dead map not found in CDB!");
//----------------------------------------------------
// Get trigger parameters and init other trigger stuff
int dsize = (fGeom->GetTriggerMappingVersion() == 2) ? 2 : 1;
fgTriggerData = new TClonesArray("AliEMCALTriggerData",dsize);
for (int i=0;i<dsize;i++) {
new((*fgTriggerData)[i]) AliEMCALTriggerData();
}
//-----------------------------
// Init temporary list of digits
//
fgDigitsArr = new TClonesArray("AliEMCALDigit",1000);
fgClustersArr = new TObjArray(1000);
const int kNTRU = fGeom->GetNTotalTRU();
fgTriggerDigits = new TClonesArray("AliEMCALTriggerRawDigit", kNTRU * 96);
//--------------------------
// Init Track matching array
//
fMatches = new TList();
fMatches->SetOwner(kTRUE);
}
///
/// Destructor
///
//____________________________________________________________________________
AliEMCALReconstructor::~AliEMCALReconstructor()
{
////RS if(fGeom) delete fGeom;
//No need to delete, recovered from OCDB
//if(fCalibData) delete fCalibData;
//if(fCalibTime) delete fCalibTime;
//if(fPedestalData) delete fPedestalData;
if(fgDigitsArr) fgDigitsArr->Clear("C");
delete fgDigitsArr;
fgDigitsArr = 0;
if(fgClustersArr) fgClustersArr->Clear();
delete fgClustersArr;
fgClustersArr = 0;
if(fgTriggerDigits) fgTriggerDigits->Clear();
delete fgTriggerDigits;
fgTriggerDigits = 0;
delete fgRawUtils;
fgRawUtils = 0;
delete fgClusterizer;
fgClusterizer = 0;
if(fgTriggerProcessor) delete fgTriggerProcessor;
fgTriggerProcessor = 0;
if(fMatches) { fMatches->Delete(); delete fMatches; fMatches = 0;}
if (fESDCalofriend) delete fESDCalofriend;
AliCodeTimer::Instance()->Print();
}
//_____________________________________________________________________________
void AliEMCALReconstructor::Init()
{
//
fESDCalofriend = new AliESDCalofriend;
}
///
/// @brief Init the fgTriggerProcessor
///
/// Trigger preprocessor will only be initialized in case
/// the trigger simulation is enabled via the reco params.
/// In case the trigger simulation is already initialized
/// the function will do nothing, otherwise it will check
/// whether the trigger simulation is switched on in the
/// reco params and initialize it.
///
//____________________________________________________________________________
void AliEMCALReconstructor::InitTriggerElectronics() const {
if(fgTriggerProcessor) return;
if(GetRecParam()){
if(GetRecParam()->IsSimulateTriggerElectronics()){
AliEMCALTriggerDCSConfigDB* dcsConfigDB = AliEMCALTriggerDCSConfigDB::Instance();
const AliEMCALTriggerDCSConfig* dcsConfig = dcsConfigDB->GetTriggerDCSConfig();
if(!dcsConfig)
AliFatal("No trigger configuration found in OCDB");
fgTriggerProcessor = new AliEMCALTriggerElectronics( dcsConfig );
}
}
}
///
/// Init the fgClusterizer with geometry and calibration pointers, avoid doing it twice.
///
//____________________________________________________________________________
void AliEMCALReconstructor::InitClusterizer() const
{
Int_t clusterizerType = -1;
Int_t eventType = -1;
if(GetRecParam())
{
clusterizerType = GetRecParam()->GetClusterizerFlag();
eventType = GetRecParam()->GetEventSpecie();
}
else
{
AliCDBEntry *entry = (AliCDBEntry*)
AliCDBManager::Instance()->Get("EMCAL/Calib/RecoParam");
// Get The reco param for the default event specie
if (entry)
{
AliEMCALRecParam *recParam = (AliEMCALRecParam*)((TObjArray *) entry->GetObject())->At(0);
if(recParam) clusterizerType = recParam->GetClusterizerFlag();
}
}
// Check if clusterizer previously set corresponds to what is needed for this event type
if(fgClusterizer)
{
if(eventType!=AliRecoParam::kCalib)
{
//printf("ReCreate clusterizer? Clusterizer set <%d>, Clusterizer in use <%s>\n",
// clusterizerType, fgClusterizer->Version());
if (clusterizerType == AliEMCALRecParam::kClusterizerv1 && !strcmp(fgClusterizer->Version(),"clu-v1")) return;
else if(clusterizerType == AliEMCALRecParam::kClusterizerNxN && !strcmp(fgClusterizer->Version(),"clu-NxN")) return;
else if(clusterizerType == AliEMCALRecParam::kClusterizerv2 && !strcmp(fgClusterizer->Version(),"clu-v2")) return;
else if(clusterizerType == AliEMCALRecParam::kClusterizerv3 && !strcmp(fgClusterizer->Version(),"clu-v3")) return;
//Need to create new clusterizer, the one set previously is not the correct one
delete fgClusterizer;
}
else return;
}
if (clusterizerType == AliEMCALRecParam::kClusterizerv1)
{
fgClusterizer = new AliEMCALClusterizerv1 (fGeom, fCalibData,fCalibTime,fPedestalData);
}
else if (clusterizerType == AliEMCALRecParam::kClusterizerNxN)
{
fgClusterizer = new AliEMCALClusterizerNxN(fGeom, fCalibData,fCalibTime,fPedestalData);
}
else if (clusterizerType == AliEMCALRecParam::kClusterizerv2)
{
fgClusterizer = new AliEMCALClusterizerv2 (fGeom, fCalibData,fCalibTime,fPedestalData);
}
else if (clusterizerType == AliEMCALRecParam::kClusterizerv3)
{
fgClusterizer = new AliEMCALClusterizerv3 (fGeom, fCalibData,fCalibTime,fPedestalData);
}
else
{
AliFatal(Form("Unknown clusterizer %d ", clusterizerType));
}
}
///
/// Method called by AliReconstruction;
/// Only the clusterization is performed, the rest of the reconstruction is done
/// in FillESD because the track matching needs access to the AliESD object to
/// retrieve the tracks reconstructed by the global tracking.
/// Works on the current event.
///
//____________________________________________________________________________
void AliEMCALReconstructor::Reconstruct(TTree* digitsTree, TTree* clustersTree) const
{
AliCodeTimerAuto("",0)
// Get input digits and put them in fgDigitsArr, clear the list before
ReadDigitsArrayFromTree(digitsTree);
InitClusterizer();
fgClusterizer->InitParameters();
fgClusterizer->SetOutput(clustersTree);
// Skip clusterization of LED events
if (GetRecParam()->GetEventSpecie()!=AliRecoParam::kCalib)
{
if(fgDigitsArr && fgDigitsArr->GetEntries())
{
fgClusterizer->SetInput(digitsTree);
//fgClusterizer->Digits2Clusters("deb all") ; //For debugging
fgClusterizer->Digits2Clusters("");
fgClusterizer->Clear();
}//digits array exists and has somethind
}//not a LED event
clustersTree->Fill();
// Deleting the recpoints at the end of the reconstruction call
fgClusterizer->DeleteRecPoints();
}
///
/// Conversion from raw data to EMCAL digits.
/// Works on a single-event basis.
///
//____________________________________________________________________________
void AliEMCALReconstructor::ConvertDigits(AliRawReader* rawReader, TTree* digitsTree) const
{
rawReader->Reset() ;
for (int i=0;i<fgTriggerData->GetEntriesFast();i++)
{
((AliEMCALTriggerData*)fgTriggerData->At(i))->SetMode(AliEMCALTriggerData::ETriggerDataMode_t::kRawData);
}
if(fgDigitsArr) fgDigitsArr->Clear("C");
fESDCalofriend->DeAllocate();
const int kNTRU = fGeom->GetNTotalTRU();
TClonesArray *digitsTrg = new TClonesArray("AliEMCALTriggerRawDigit", kNTRU * 96);
Int_t bufsize = 32000;
digitsTree->Branch("EMCAL", &fgDigitsArr, bufsize);
digitsTree->Branch("EMTRG", &digitsTrg, bufsize);
// Skip calibration events do the rest
Bool_t doFit = kTRUE;
if ( !(GetRecParam()->FitLEDEvents()) && GetRecParam()->GetEventSpecie()==AliRecoParam::kCalib) doFit = kFALSE;
if (doFit)
{
// must be done here because, in constructor, option is not yet known
fgRawUtils->SetOption(GetOption());
// fgRawUtils->SetRawFormatHighLowGainFactor(GetRecParam()->GetHighLowGainFactor());
// fgRawUtils->SetRawFormatOrder(GetRecParam()->GetOrderParameter());
// fgRawUtils->SetRawFormatTau(GetRecParam()->GetTau());
fgRawUtils->SetNoiseThreshold(GetRecParam()->GetNoiseThreshold());
fgRawUtils->SetNPedSamples(GetRecParam()->GetNPedSamples());
fgRawUtils->SetRemoveBadChannels(GetRecParam()->GetRemoveBadChannels());
if (!fgRawUtils->GetFittingAlgorithm()) fgRawUtils->SetFittingAlgorithm(GetRecParam()->GetFittingAlgorithm());
fgRawUtils->SetFALTROUsage(GetRecParam()->UseFALTRO());
fgRawUtils->SetL1PhaseUsage(GetRecParam()->UseL1Phase());
// fgRawUtils->SetFALTROUsage(0);
//fgRawUtils->SetTimeMin(GetRecParam()->GetTimeMin());
//fgRawUtils->SetTimeMax(GetRecParam()->GetTimeMax());
// fgRawUtils->SetTimeMin(-99999 );
// fgRawUtils->SetTimeMax( 99999 );
fgRawUtils->Raw2Digits(rawReader,fgDigitsArr,fPedestalData,digitsTrg,fgTriggerData);
}//skip calibration event
else
{
AliDebug(1," Calibration Event, skip!");
}
digitsTree->Fill();
digitsTrg->Delete();
delete digitsTrg;
}
///
/// Create AliESDCaloCells, AliESDCaloClusters and AliESDCaloTrigger entries
/// from AliEMCALRecPoints, AliEMCALDigits.
/// Called by AliReconstruct after Reconstruct() and global tracking and
/// vertexing and V0.
/// Works on the current event
///
//____________________________________________________________________________
void AliEMCALReconstructor::FillESD(TTree* digitsTree, TTree* clustersTree,
AliESDEvent* esd) const
{
//########################################
// Trigger
//########################################
static int saveOnce[2] = {0,0};
Int_t v0M[2] = {0, 0};
AliESDVZERO* esdV0 = esd->GetVZEROData();
if (esdV0)
{
v0M[0] = esdV0->GetTriggerChargeC();
v0M[1] = esdV0->GetTriggerChargeA();
}
else
{
AliWarning("No V0 ESD! Run trigger processor w/ null V0 charges");
}
if (fgTriggerDigits && fgTriggerDigits->GetEntriesFast()) fgTriggerDigits->Delete();
TBranch *branchtrg = digitsTree->GetBranch("EMTRG");
if (!branchtrg)
{
AliError("Can't get the branch with the EMCAL trigger digits!");
return;
}
branchtrg->SetAddress(&fgTriggerDigits);
branchtrg->GetEntry(0);
// Note: fgTriggerProcessor reset done at the end of this method
InitTriggerElectronics();
if(fgTriggerProcessor) fgTriggerProcessor->Digits2Trigger(fgTriggerDigits, v0M, (AliEMCALTriggerData*)fgTriggerData->At(0));
// Fill ESD
AliESDCaloTrigger* trgESD = esd->GetCaloTrigger("EMCAL");
Int_t totalSize = fgTriggerDigits->GetEntriesFast()+2*fgDigitsArr->GetEntriesFast(); //LG/HG
fESDCalofriend->Allocate(totalSize);
if (trgESD)
{
trgESD->Allocate(fgTriggerDigits->GetEntriesFast());
int trgBitWord=0;
for (Int_t i = 0; i < fgTriggerDigits->GetEntriesFast(); i++) {
AliEMCALTriggerRawDigit* rdig = (AliEMCALTriggerRawDigit*)fgTriggerDigits->At(i);
if (AliDebugLevel() > 999) rdig->Print("");
Int_t px, py, trgBitWord=0;
if (fGeom->GetPositionInEMCALFromAbsFastORIndex(rdig->GetId(), px, py)) {
Int_t a = -1, t = -1, times[10];
rdig->GetMaximum(a, t);
rdig->GetL0Times(times);
trgESD->Add(px, py, a, t, times, rdig->GetNL0Times(), rdig->GetL1TimeSum(), rdig->GetL1SubRegion(), rdig->GetTriggerBits());
trgBitWord |= rdig->GetTriggerBits();
if (rdig->GetNL0Times()) trgBitWord |= 1 << 5; // Overwrite L0 id from STU payload
const Int_t nSamples = 64;
Int_t samples[nSamples]={0};
if (rdig->GetNSamples() && rdig->GetSamples(samples,nSamples)) {
fESDCalofriend->Add(rdig->GetId(),5,nSamples,samples);
}
}
}
trgESD->SetTriggerBitWord(trgBitWord);
for (int i=0;i<fgTriggerData->GetEntriesFast();i++)
{
for (int j=0;j<2;j++) {
trgESD->SetL1Threshold(i,2 * j , ((AliEMCALTriggerData*)fgTriggerData->At(i))->GetL1JetThreshold( j));
trgESD->SetL1Threshold(i,2 * j + 1, ((AliEMCALTriggerData*)fgTriggerData->At(i))->GetL1GammaThreshold(j));
}
trgESD->SetL1FrameMask(i,((AliEMCALTriggerData*)fgTriggerData->At(i))->GetL1FrameMask());
Int_t v0[2];
((AliEMCALTriggerData*)fgTriggerData->At(i))->GetL1V0(v0);
trgESD->SetL1V0(i,v0);
trgESD->SetMedian(i,((AliEMCALTriggerData*)fgTriggerData->At(i))->GetMedian());
if (!saveOnce[i] && ((AliEMCALTriggerData*)fgTriggerData->At(i))->IsL1DataDecoded())
{
int type[19] = {0};
((AliEMCALTriggerData*)fgTriggerData->At(i))->GetL1TriggerType(type);
esd->SetCaloTriggerType(i,type);
saveOnce[i] = 1;
}
}
}
// Resetting
for (int i=0;i<fgTriggerData->GetEntriesFast();i++)
{
((AliEMCALTriggerData*)fgTriggerData->At(i))->Reset();
}
//########################################
//##############Fill CaloCells############
//########################################
// Get input digits and put them in fgDigitsArr, clear the list before
ReadDigitsArrayFromTree(digitsTree);
Int_t nDigits = fgDigitsArr->GetEntries(), idignew = 0 ;
AliDebug(1,Form("%d digits",nDigits));
AliESDCaloCells &emcCells = *(esd->GetEMCALCells());
emcCells.CreateContainer(nDigits);
emcCells.SetType(AliVCaloCells::kEMCALCell);
Float_t energy = 0;
Float_t time = 0;
Int_t mapDigitAndCellIndex[20000] = { 0 } ; // needed to pack cell MC labels in cluster and not loop all digits
for (Int_t idig = 0 ; idig < nDigits ; idig++)
{
const AliEMCALDigit * dig = (const AliEMCALDigit*)fgDigitsArr->At(idig);
time = dig->GetTime(); // Time already calibrated in clusterizer
energy = dig->GetAmplitude(); // energy calibrated in clusterizer
if (energy <= 0 ) continue ;
fgClusterizer->Calibrate(energy,time,dig->GetId()); // Digits already calibrated in clusterizers
if (energy <= 0 ) continue ; // Digits tagged as bad (dead, hot, not alive) are set to 0 in calibrate, remove them
// Only for MC
// Get the label of the primary particle that generated the cell
// Assign the particle that deposited more energy
Int_t nparents = dig->GetNiparent();
Int_t digLabel =-1 ;
Float_t edep =-1.;
if ( nparents > 0 )
{
for ( Int_t jndex = 0 ; jndex < nparents ; jndex++ )
{
if(edep >= dig->GetDEParent(jndex+1)) continue ;
digLabel = dig->GetIparent (jndex+1);
edep = dig->GetDEParent(jndex+1);
} // all primaries in digit
} // select primary label
Bool_t highGain = kFALSE;
if( dig->GetType() == AliEMCALDigit::kHG ) highGain = kTRUE;
emcCells.SetCell(idignew,dig->GetId(),energy, time,digLabel,0.,highGain);
mapDigitAndCellIndex[idignew] = idig; // needed to pack cell MC labels in cluster
// Trigger stuff
//
const Int_t nSamples = 64;//rdig->GetNSamples();
Int_t samples[nSamples]={0};
if (dig->GetNALTROSamplesLG()) {
dig->GetALTROSamplesLG(samples); fESDCalofriend->Add(dig->GetId(),1,nSamples,samples);
}
// Reset
for (int isamp=0;isamp<nSamples;isamp++) samples[isamp]=0;
if (dig->GetNALTROSamplesHG()) {
dig->GetALTROSamplesHG(samples); fESDCalofriend->Add(dig->GetId(),0,nSamples,samples);
}
idignew++;
}
emcCells.SetNumberOfCells(idignew);
emcCells.Sort();
//------------------------------------------------------------
//-----------------CLUSTERS-----------------------------------
//------------------------------------------------------------
clustersTree->SetBranchStatus("*",0); //disable all branches
clustersTree->SetBranchStatus("EMCALECARP",1); //Enable only the branch we need
if(fgClustersArr) fgClustersArr->Clear();
TBranch *branch = clustersTree->GetBranch("EMCALECARP");
branch->SetAddress(&fgClustersArr);
branch->GetEntry(0);
//clustersTree->GetEvent(0);
Int_t nClusters = fgClustersArr->GetEntries(), nClustersNew=0;
AliDebug(1,Form("%d clusters",nClusters));
//########################################
//##############Fill CaloClusters#########
//########################################
for (Int_t iClust = 0 ; iClust < nClusters ; iClust++)
{
const AliEMCALRecPoint * clust = (const AliEMCALRecPoint*)fgClustersArr->At(iClust);
if(!clust) continue;
// clust->Print(); //For debugging
// Get information from EMCAL reconstruction points
Float_t xyz[3];
TVector3 gpos;
clust->GetGlobalPosition(gpos);
for (Int_t ixyz=0; ixyz<3; ixyz++)
xyz[ixyz] = gpos[ixyz];
Float_t elipAxis[2];
clust->GetElipsAxis(elipAxis);
//Create digits lists
Int_t cellMult = clust->GetMultiplicity();
Float_t *amplFloat = clust->GetEnergiesList();
Int_t *digitInts = clust->GetAbsId();
TArrayS absIdList(cellMult);
TArrayD fracList(cellMult);
Int_t newCellMult = 0;
for (Int_t iCell=0; iCell<cellMult; iCell++)
{
if (amplFloat[iCell] > 0)
{
absIdList[newCellMult] = (UShort_t)(digitInts[iCell]);
//Calculate Fraction
if(emcCells.GetCellAmplitude(digitInts[iCell])>0 && GetRecParam()->GetUnfold())
fracList[newCellMult] = amplFloat[iCell]/(emcCells.GetCellAmplitude(digitInts[iCell]));//get cell calibration value
else
fracList[newCellMult] = 0;
newCellMult++;
}
}
absIdList.Set(newCellMult);
fracList.Set(newCellMult);
// Accept cluster if it has some digit
if(newCellMult > 0)
{
nClustersNew++;
// Fill the ESDCaloCluster
AliESDCaloCluster * ec = new AliESDCaloCluster() ;
ec->SetType(AliVCluster::kEMCALClusterv1);
ec->SetPosition(xyz);
ec->SetE(clust->GetEnergy());
ec->SetTOF(clust->GetTime()) ; //time-of-flight
ec->SetChi2(-1); //not yet implemented
// Distance to the nearest bad tower
ec->SetDistanceToBadChannel(clust->GetDistanceToBadTower());
//
// Shower shape related
//
ec->SetNCells(newCellMult);
ec->SetDispersion(clust->GetDispersion());
ec->SetM02(elipAxis[0]*elipAxis[0]) ;
ec->SetM20(elipAxis[1]*elipAxis[1]) ;
ec->SetNExMax(clust->GetNExMax()); //number of local maxima
//
// Primaries
//
Int_t parentMult = 0;
Int_t *parentList = clust->GetParents(parentMult); // label index
Float_t *parentListDE = clust->GetParentsDE(); // deposited energy
ec->SetLabel(parentList,parentMult);
ec->SetClusterMCEdepFractionFromEdepArray(parentListDE);
//
// Change type of cells list from short to ushort
// Pack the at maximum 4 different primary contributions on cells into a single int.
// (Profit from the same loop on cells in cluster)
//
UShort_t *newAbsIdList = new UShort_t[newCellMult];
Double_t *newFracList = new Double_t[newCellMult];
UInt_t *cellEDepFrac = new UInt_t [newCellMult];
for(Int_t i = 0; i < newCellMult ; i++)
{
// int to short
newAbsIdList[i] = absIdList[i];
newFracList [i] = fracList[i];
cellEDepFrac[i] = 0;
// *Pack cells parent energy deposit*
if(parentMult > 0)
{
// Get the digit that originated this cell cluster
Int_t cellPos = emcCells.GetCellPosition (newAbsIdList[i]);
Int_t idigit = mapDigitAndCellIndex[cellPos];
const AliEMCALDigit * dig = (const AliEMCALDigit*)fgDigitsArr->At(idigit);
// Find the 4 MC labels that contributed to the cluster and their
// deposited energy in the current digit
Int_t nparents = dig->GetNiparent();
if ( nparents > 0 )
{
Int_t digLabel =-1 ;
Float_t edep = 0 ;
Float_t edepTot = 0 ;
Float_t mcEDepFrac[4] = {0,0,0,0};
for ( Int_t jndex = 0 ; jndex < nparents ; jndex++ )
{ // all primaries in digit
digLabel = dig->GetIparent (jndex+1);
edep = dig->GetDEParent(jndex+1);
edepTot += edep;
if ( digLabel == parentList[0] ) mcEDepFrac[0] = edep;
else if ( digLabel == parentList[1] ) mcEDepFrac[1] = edep;
else if ( digLabel == parentList[2] ) mcEDepFrac[2] = edep;
else if ( digLabel == parentList[3] ) mcEDepFrac[3] = edep;
} // all primaries in digit
// Divide energy deposit by total deposited energy
// Do not take the stored digit energy since it is smeared and with noise
// One could go back to the sdigit, but it is simpler to take the added
// deposited energy of all primaries.
// Do this only when deposited energy is significant, use 10 MeV although 50 MeV should be expected
if(edepTot > 0.01)
{
for(Int_t idep = 0; idep < 4; idep++)
mcEDepFrac[idep] /= edepTot;
cellEDepFrac[i] = ec->PackMCEdepFraction(mcEDepFrac);
}
} // at least one parent in digit
} // at least one parent in cluster, do the cell primary packing
} // cell cluster loop
ec->SetCellsAbsId(newAbsIdList);
ec->SetCellsAmplitudeFraction(newFracList);
ec->SetCellsMCEdepFractionMap(cellEDepFrac);
//
// Track matching
//
fMatches->Clear();
Int_t nTracks = esd->GetNumberOfTracks();
for (Int_t itrack = 0; itrack < nTracks; itrack++)
{
AliESDtrack * track = esd->GetTrack(itrack) ; // retrieve track
if(track->GetEMCALcluster()==iClust)
{
Float_t dEta=-999, dPhi=-999;
Bool_t isMatch = CalculateResidual(track, ec, dEta, dPhi);
if(!isMatch)
{
// AliDebug(10, "Not good");
continue;
}
AliEMCALMatch *match = new AliEMCALMatch();
match->SetIndexT(itrack);
match->SetDistance(TMath::Sqrt(dEta*dEta+dPhi*dPhi));
match->SetdEta(dEta);
match->SetdPhi(dPhi);
fMatches->Add(match);
}
}
fMatches->Sort(kSortAscending); //Sort matched tracks from closest to furthest
Int_t nMatch = fMatches->GetEntries();
TArrayI arrayTrackMatched(nMatch);
for(Int_t imatch=0; imatch<nMatch; imatch++)
{
AliEMCALMatch *match = (AliEMCALMatch*)fMatches->At(imatch);
arrayTrackMatched[imatch] = match->GetIndexT();
if(imatch==0)
{
ec->SetTrackDistance(match->GetdPhi(), match->GetdEta());
}
}
ec->AddTracksMatched(arrayTrackMatched);
//add the cluster to the esd object
esd->AddCaloCluster(ec);
delete ec;
delete [] newAbsIdList ;
delete [] newFracList ;
delete [] cellEDepFrac ;
}
} // cycle on clusters
//
// Reset the index of matched cluster for tracks
// to the one in CaloCluster array
//
Int_t ncls = esd->GetNumberOfCaloClusters();
for(Int_t icl=0; icl<ncls; icl++)
{
AliESDCaloCluster *cluster = esd->GetCaloCluster(icl);
if(!cluster || !cluster->IsEMCAL()) continue;
TArrayI *trackIndex = cluster->GetTracksMatched();
for(Int_t itr=0; itr<trackIndex->GetSize(); itr++)
{
AliESDtrack *track = esd->GetTrack(trackIndex->At(itr));
track->SetEMCALcluster(cluster->GetID());
}
}
// Fill ESDCaloCluster with PID weights
AliEMCALPID *pid = new AliEMCALPID;
//pid->SetPrintInfo(kTRUE);
pid->SetReconstructor(kTRUE);
pid->RunPID(esd);
delete pid;
// Store EMCAL misalignment matrixes
FillMisalMatrixes(esd) ;
//add calo friends
if (esd) {
AliESDfriend *fr = (AliESDfriend*)esd->FindListObject("AliESDfriend");
if (fr) {
AliDebug(1, Form("Writing Calo friend data to ESD tree"));
fr->SetCalofriend(fESDCalofriend);
}
}
}
///
/// Store EMCAL matrixes in ESD Header.
///
//==================================================================================
void AliEMCALReconstructor::FillMisalMatrixes(AliESDEvent* esd)const
{
// Check, if matrixes was already stored
for(Int_t sm = 0 ; sm < fGeom->GetNumberOfSuperModules(); sm++)
{
if(esd->GetEMCALMatrix(sm)!=0)
return ;
}
// Create and store matrixes
if(!gGeoManager)
{
AliError("Can not store misal. matrixes: no gGeoManager! \n") ;
return ;
}
// Note, that owner of copied matrixes will be header
const Int_t bufsize = 255;
char path[bufsize] ;
TGeoHMatrix * m = 0x0;
Int_t tmpType = -1;
Int_t SMOrder = 0;
TString SMName;
for(Int_t sm = 0; sm < fGeom->GetNumberOfSuperModules(); sm++)
{
if(fGeom->GetSMType(sm) == AliEMCALGeometry::kEMCAL_Standard ) SMName = "SMOD";
else if(fGeom->GetSMType(sm) == AliEMCALGeometry::kEMCAL_Half ) SMName = "SM10";
else if(fGeom->GetSMType(sm) == AliEMCALGeometry::kEMCAL_3rd ) SMName = "SM3rd";
else if( fGeom->GetSMType(sm) == AliEMCALGeometry::kDCAL_Standard ) SMName = "DCSM";
else if( fGeom->GetSMType(sm) == AliEMCALGeometry::kDCAL_Ext ) SMName = "DCEXT";
else AliError("Unkown SM Type!!");
if(fGeom->GetSMType(sm) == tmpType)
{
SMOrder++;
}
else
{
tmpType = fGeom->GetSMType(sm);
SMOrder = 1;
}
snprintf(path,bufsize,"/ALIC_1/XEN1_1/%s_%d", SMName.Data(), SMOrder) ;
if (gGeoManager->CheckPath(path))
{
gGeoManager->cd(path);
m = gGeoManager->GetCurrentMatrix() ;
// printf("================================================= \n");
// printf("AliEMCALReconstructor::FixMisalMatrixes(), sm %d, \n",sm);
// m->Print("");
esd->SetEMCALMatrix(new TGeoHMatrix(*m),sm) ;
// printf("================================================= \n");
}
else
{
esd->SetEMCALMatrix(NULL,sm) ;
}
}
}
///
/// Read the digits from the input tree
/// See AliEMCALClusterizer::SetInput(TTree *digitsTree);
///
//__________________________________________________________________________
void AliEMCALReconstructor::ReadDigitsArrayFromTree(TTree *digitsTree) const
{
// Clear previous digits in the list
if(fgDigitsArr)
{
fgDigitsArr->Clear("C");
}
else
{
// It should not happen, but just in case ...
fgDigitsArr = new TClonesArray("AliEMCALDigit",100);
}
// Read the digits from the input tree
TBranch *branch = digitsTree->GetBranch("EMCAL");
if (!branch)
{
AliError("can't get the branch with the EMCAL digits !");
return;
}
branch->SetAddress(&fgDigitsArr);
branch->GetEntry(0);
}
///
/// Calculate the residual between track and cluster.
///
/// If the esdFriend is available, use the TPCOuter point as the starting
/// point of extrapolation, otherwise use the TPCInner point.
///
//==================================================================================
Bool_t AliEMCALReconstructor::CalculateResidual(AliESDtrack *track, AliESDCaloCluster *cluster, Float_t &dEta, Float_t &dPhi)const
{
dEta = -999, dPhi = -999;
Bool_t ITSTrackSA = 0;
AliExternalTrackParam *trkParam = 0;
const AliESDfriendTrack* friendTrack = track->GetFriendTrack();