-
Notifications
You must be signed in to change notification settings - Fork 785
/
AliEmcalJetTask.cxx
1337 lines (1162 loc) · 46.8 KB
/
AliEmcalJetTask.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) 2016, Copyright Holders of the ALICE Collaboration *
* All rights reserved. *
* *
* Redistribution and use in source and binary forms, with or without *
* modification, are permitted provided that the following conditions are met: *
* * Redistributions of source code must retain the above copyright *
* notice, this list of conditions and the following disclaimer. *
* * Redistributions in binary form must reproduce the above copyright *
* notice, this list of conditions and the following disclaimer in the *
* documentation and/or other materials provided with the distribution. *
* * Neither the name of the <organization> nor the *
* names of its contributors may be used to endorse or promote products *
* derived from this software without specific prior written permission. *
* *
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND *
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED *
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE *
* DISCLAIMED. IN NO EVENT SHALL ALICE COLLABORATION BE LIABLE FOR ANY *
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES *
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; *
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND *
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT *
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS *
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. *
**************************************************************************************/
#include <vector>
#include <TClonesArray.h>
#include <TMath.h>
#include <TRandom3.h>
#include <TGrid.h>
#include <TFile.h>
#include <AliVCluster.h>
#include <AliVEvent.h>
#include <AliVParticle.h>
#include <AliEMCALGeometry.h>
#include <AliAnalysisManager.h>
#include <AliVEventHandler.h>
#include <AliMultiInputEventHandler.h>
#include "AliTLorentzVector.h"
#include "AliEmcalJet.h"
#include "AliEmcalParticle.h"
#include "AliFJWrapper.h"
#include "AliEmcalJetUtility.h"
#include "AliParticleContainer.h"
#include "AliClusterContainer.h"
#include "AliEmcalClusterJetConstituent.h"
#include "AliEmcalParticleJetConstituent.h"
#include "AliEmcalJetTask.h"
#include "AliProdInfo.h"
using std::cout;
using std::endl;
using std::cerr;
/// \cond CLASSIMP
ClassImp(AliEmcalJetTask);
/// \endcond
const Int_t AliEmcalJetTask::fgkConstIndexShift = 100000;
/**
* Default constructor. This constructor is only for ROOT I/O and
* not to be used by users.
*/
AliEmcalJetTask::AliEmcalJetTask() :
AliAnalysisTaskEmcal(),
fJetsTag(),
fJetType(AliJetContainer::kFullJet),
fJetAlgo(AliJetContainer::antikt_algorithm),
fRecombScheme(AliJetContainer::pt_scheme),
fRadius(0.4),
fMinJetArea(0.001),
fMinJetPt(1.0),
fJetPhiMin(-10),
fJetPhiMax(+10),
fJetEtaMin(-1),
fJetEtaMax(+1),
fGhostArea(0.005),
fTrackEfficiency(1.),
fQoverPtShift(0.),
fUtilities(0),
fTrackEfficiencyOnlyForEmbedding(kFALSE),
fTrackEfficiencyFunction(nullptr),
fTrackEfficiencyHistogram(nullptr),
fApplyArtificialTrackingEfficiency(kFALSE),
fApplyPtDependentTrackingEfficiency(kFALSE),
fApplyQoverPtShift(kFALSE),
fRandom(0),
fLocked(0),
fFillConstituents(kTRUE),
fJetsName(),
fIsInit(0),
fIsPSelSet(0),
fIsEmcPart(0),
fEnableAliBasicParticleCompatibility(kFALSE),
fLegacyMode(kFALSE),
fFillGhost(kFALSE),
fJets(0),
fFastJetWrapper("AliEmcalJetTask","AliEmcalJetTask"),
fYAMLConfig(),
fClusterContainerIndexMap(),
fParticleContainerIndexMap()
{
}
/**
* Standard named constructor.
* @param name Name of the task.
*/
AliEmcalJetTask::AliEmcalJetTask(const char *name) :
AliAnalysisTaskEmcal(name),
fJetsTag("Jets"),
fJetType(AliJetContainer::kFullJet),
fJetAlgo(AliJetContainer::antikt_algorithm),
fRecombScheme(AliJetContainer::pt_scheme),
fRadius(0.4),
fMinJetArea(0.001),
fMinJetPt(1.0),
fJetPhiMin(-10),
fJetPhiMax(+10),
fJetEtaMin(-1),
fJetEtaMax(+1),
fGhostArea(0.005),
fTrackEfficiency(1.),
fQoverPtShift(0.),
fUtilities(0),
fTrackEfficiencyOnlyForEmbedding(kFALSE),
fTrackEfficiencyFunction(nullptr),
fTrackEfficiencyHistogram(nullptr),
fApplyArtificialTrackingEfficiency(kFALSE),
fApplyPtDependentTrackingEfficiency(kFALSE),
fApplyQoverPtShift(kFALSE),
fRandom(0),
fLocked(0),
fFillConstituents(kTRUE),
fJetsName(),
fIsInit(0),
fIsPSelSet(0),
fIsEmcPart(0),
fEnableAliBasicParticleCompatibility(kFALSE),
fLegacyMode(kFALSE),
fFillGhost(kFALSE),
fJets(0),
fFastJetWrapper(name,name),
fYAMLConfig(),
fClusterContainerIndexMap(),
fParticleContainerIndexMap()
{
}
/**
* Destructor
*/
AliEmcalJetTask::~AliEmcalJetTask()
{
}
/**
* Add a utility to the utility list. Utilities are instances of classes
* derived from AliEmcalJetUtility that implements wrappers to FastJet contribs.
*/
AliEmcalJetUtility* AliEmcalJetTask::AddUtility(AliEmcalJetUtility* utility)
{
if (!fUtilities) fUtilities = new TObjArray();
if (fUtilities->FindObject(utility)) {
Error("AddUtility", "Jet utility %s already connected.", utility->GetName());
return utility;
}
fUtilities->Add(utility);
utility->SetJetTask(this);
return utility;
}
/**
* This method is called once before analyzing the first event. It executes
* the Init() method of all utilities (if any).
*/
void AliEmcalJetTask::InitUtilities()
{
TIter next(fUtilities);
AliEmcalJetUtility *utility = 0;
while ((utility=static_cast<AliEmcalJetUtility*>(next()))) utility->Init();
}
/**
* This method is called before analyzing each event. It executes
* the InitEvent() method of all utilities (if any).
*/
void AliEmcalJetTask::InitEvent()
{
TIter next(fUtilities);
AliEmcalJetUtility *utility = 0;
while ((utility=static_cast<AliEmcalJetUtility*>(next()))) utility->InitEvent(fFastJetWrapper);
}
/**
* This method is called in the event loop after jet finding but before filling
* the output jet branch to prepare the utilities.
* It executes the Prepare() method of all utilities (if any).
*/
void AliEmcalJetTask::PrepareUtilities()
{
TIter next(fUtilities);
AliEmcalJetUtility *utility = 0;
while ((utility=static_cast<AliEmcalJetUtility*>(next()))) utility->Prepare(fFastJetWrapper);
}
/**
* This method is called in the event loop for each jet found, while filling the output jet branch.
* It executes the ProcessJet() method of all utilities (if any).
*/
void AliEmcalJetTask::ExecuteUtilities(AliEmcalJet* jet, Int_t ij)
{
TIter next(fUtilities);
AliEmcalJetUtility *utility = 0;
while ((utility=static_cast<AliEmcalJetUtility*>(next()))) utility->ProcessJet(jet, ij, fFastJetWrapper);
}
/**
* This method is called in the event loop after jet finding has been completed.
* It executes the Terminate() method of all utilities (if any).
*/
void AliEmcalJetTask::TerminateUtilities()
{
TIter next(fUtilities);
AliEmcalJetUtility *utility = 0;
while ((utility=static_cast<AliEmcalJetUtility*>(next()))) utility->Terminate(fFastJetWrapper);
}
/**
* This method is called for each event.
* @return Always kTRUE
*/
Bool_t AliEmcalJetTask::Run()
{
InitEvent();
// clear the jet array (normally a null operation)
fJets->Delete();
Int_t n = FindJets();
if (n == 0) return kFALSE;
FillJetBranch();
return kTRUE;
}
/**
* This method steers the jet finding. It first loops over all particle and cluster containers
* that were provided when the task was initialized. All accepted objects (tracks, particle, clusters)
* are added as input vectors to the FastJet wrapper. Then the jet finding is launched
* in the wrapper.
* @return Total number of jets found.
*/
Int_t AliEmcalJetTask::FindJets()
{
if (fParticleCollArray.GetEntriesFast() == 0 && fClusterCollArray.GetEntriesFast() == 0){
AliError("No tracks or clusters, returning.");
return 0;
}
fFastJetWrapper.Clear();
AliDebug(2,Form("Jet type = %d", fJetType));
Int_t iColl = 1;
TIter nextPartColl(&fParticleCollArray);
AliParticleContainer* tracks = 0;
while ((tracks = static_cast<AliParticleContainer*>(nextPartColl()))) {
AliDebug(2,Form("Tracks from collection %d: '%s'. Embedded: %i, nTracks: %i", iColl-1, tracks->GetName(), tracks->GetIsEmbedding(), tracks->GetNParticles()));
AliParticleIterableMomentumContainer itcont = tracks->accepted_momentum();
for (AliParticleIterableMomentumContainer::iterator it = itcont.begin(); it != itcont.end(); it++) {
// Apply artificial track inefficiency, if supplied (either constant or pT-dependent)
if (fApplyArtificialTrackingEfficiency) {
if (fTrackEfficiencyOnlyForEmbedding == kFALSE || (fTrackEfficiencyOnlyForEmbedding == kTRUE && tracks->GetIsEmbedding())) {
Double_t trackEfficiency = 1.;
if(fTrackEfficiencyFunction!=nullptr) {
trackEfficiency = fTrackEfficiencyFunction->Eval(it->first.Pt());
}
if(fApplyPtDependentTrackingEfficiency) {
// if it exists, centrality-integrated tracking efficiency taken from index 0
if(fTrackEfficiencyHistogramVector.at(0) ) {
trackEfficiency -= (1. - fTrackEfficiencyHistogramVector.at(0)->GetBinContent(fTrackEfficiencyHistogramVector.at(0)->FindBin(it->first.Pt())));
}
// otherwise, tracking efficiency taken from corresponding centrality bin stored in index 1-4
else {
if(fTrackEfficiencyHistogramVector.at(fCentBin+1)) {
trackEfficiency -= (1. - fTrackEfficiencyHistogramVector.at(fCentBin+1)->GetBinContent(fTrackEfficiencyHistogramVector.at(fCentBin+1)->FindBin(it->first.Pt())));
}
else {
AliFatal(TString::Format("You're running over centrality (%.0f) for which the pt-dependent tracking uncertainty has not been defined",fCent).Data());
}
}
}
Double_t rnd = fRandom.Rndm();
if (trackEfficiency < rnd) {
AliDebug(2,Form("Track %d rejected due to artificial tracking inefficiency", it.current_index()));
continue;
}
}
}
TLorentzVector pvec(it->first.Px(), it->first.Py(), it->first.Pz(), it->first.E());
if(fApplyQoverPtShift){
AliDebugStream(2) << "Q/pt shift enabled" << std::endl;
if(TMath::Abs(fQoverPtShift) > DBL_EPSILON) {
AliDebugStream(2) << "Applying Q/pt shift " << fQoverPtShift << std::endl;
double chargedval = it->second->Charge() > 0 ? 1. : -1.;
double shiftedPt = TMath::Max(1/(chargedval * fQoverPtShift + 1/TMath::Abs(it->second->Pt())), 0.);
// Calculate new momentum vector
TVector3 shiftedmom;
shiftedmom.SetPtEtaPhi(shiftedPt, pvec.Eta(), pvec.Phi());
double oldE = pvec.E(), oldp = pvec.P(), newp = shiftedmom.Mag();
double shiftedE = TMath::Sqrt(oldE * oldE - oldp * oldp + newp * newp);
pvec.SetPtEtaPhiE(shiftedPt, pvec.Eta(), pvec.Phi(), shiftedE);
AliDebugStream(2) << "Original pt " << it->second->Pt() << ", shifted pt " << shiftedPt << std::endl;
}
}
AliDebug(2,Form("Track %d accepted (label = %d, pt = %f, eta = %f, phi = %f, E = %f, m = %f, px = %f, py = %f, pz = %f)", it.current_index(), it->second->GetLabel(), pvec.Pt(), pvec.Eta(), pvec.Phi(), pvec.E(), it->first.M(), pvec.Px(), pvec.Py(), pvec.Pz()));
Int_t uid = it.current_index() + fgkConstIndexShift * iColl;
fFastJetWrapper.AddInputVector(pvec.Px(), pvec.Py(), pvec.Pz(), pvec.E(), uid);
}
iColl++;
}
iColl = 1;
TIter nextClusColl(&fClusterCollArray);
AliClusterContainer* clusters = 0;
while ((clusters = static_cast<AliClusterContainer*>(nextClusColl()))) {
AliDebug(2,Form("Clusters from collection %d: '%s'. Embedded: %i, nClusters: %i", iColl-1, clusters->GetName(), clusters->GetIsEmbedding(), clusters->GetNClusters()));
AliClusterIterableMomentumContainer itcont = clusters->accepted_momentum();
for (AliClusterIterableMomentumContainer::iterator it = itcont.begin(); it != itcont.end(); it++) {
AliDebug(2,Form("Cluster %d accepted (label = %d, energy = %.3f)", it.current_index(), it->second->GetLabel(), it->first.E()));
Int_t uid = -it.current_index() - fgkConstIndexShift * iColl;
fFastJetWrapper.AddInputVector(it->first.Px(), it->first.Py(), it->first.Pz(), it->first.E(), uid);
}
iColl++;
}
if (fFastJetWrapper.GetInputVectors().size() == 0) return 0;
// run jet finder
fFastJetWrapper.Run();
return fFastJetWrapper.GetInclusiveJets().size();
}
/**
* This method fills the jet output branch (TClonesArray) with the jet found by the FastJet
* wrapper. Before filling the jet branch, the utilities are prepared. Then the utilities are
* called for each jet and finally after jet finding the terminate method of all utilities is called.
*/
void AliEmcalJetTask::FillJetBranch()
{
PrepareUtilities();
// loop over fastjet jets
std::vector<fastjet::PseudoJet> jets_incl = fFastJetWrapper.GetInclusiveJets();
// sort jets according to jet pt
static Int_t indexes[9999] = {-1};
GetSortedArray(indexes, jets_incl);
AliDebug(1,Form("%d jets found", (Int_t)jets_incl.size()));
for (UInt_t ijet = 0, jetCount = 0; ijet < jets_incl.size(); ++ijet) {
Int_t ij = indexes[ijet];
AliDebug(3,Form("Jet pt = %f, area = %f", jets_incl[ij].perp(), fFastJetWrapper.GetJetArea(ij)));
if (jets_incl[ij].perp() < fMinJetPt) continue;
if (fFastJetWrapper.GetJetArea(ij) < fMinJetArea) continue;
if ((jets_incl[ij].eta() < fJetEtaMin) || (jets_incl[ij].eta() > fJetEtaMax) ||
(jets_incl[ij].phi() < fJetPhiMin) || (jets_incl[ij].phi() > fJetPhiMax))
continue;
AliEmcalJet *jet = new ((*fJets)[jetCount])
AliEmcalJet(jets_incl[ij].perp(), jets_incl[ij].eta(), jets_incl[ij].phi(), jets_incl[ij].m());
jet->SetLabel(ij);
fastjet::PseudoJet area(fFastJetWrapper.GetJetAreaVector(ij));
jet->SetArea(area.perp());
jet->SetAreaEta(area.eta());
jet->SetAreaPhi(area.phi());
jet->SetAreaE(area.E());
jet->SetJetAcceptanceType(FindJetAcceptanceType(jet->Eta(), jet->Phi_0_2pi(), fRadius));
// Fill constituent info
std::vector<fastjet::PseudoJet> constituents(fFastJetWrapper.GetJetConstituents(ij));
FillJetConstituents(jet, constituents, constituents);
if (fGeom) {
if ((jet->Phi() > fGeom->GetArm1PhiMin() * TMath::DegToRad()) &&
(jet->Phi() < fGeom->GetArm1PhiMax() * TMath::DegToRad()) &&
(jet->Eta() > fGeom->GetArm1EtaMin()) &&
(jet->Eta() < fGeom->GetArm1EtaMax()))
jet->SetAxisInEmcal(kTRUE);
}
ExecuteUtilities(jet, ij);
AliDebug(2,Form("Added jet n. %d, pt = %f, area = %f, constituents = %d", jetCount, jet->Pt(), jet->Area(), jet->GetNumberOfConstituents()));
jetCount++;
}
TerminateUtilities();
}
/**
* Sorts jets by pT (decreasing)
* @param[out] indexes This array is used to return the indexes of the jets ordered by pT
* @param[in] array Vector containing the list of jets obtained by the FastJet wrapper
* @return kTRUE if at least one jet was found in array; kFALSE otherwise
*/
Bool_t AliEmcalJetTask::GetSortedArray(Int_t indexes[], std::vector<fastjet::PseudoJet> array) const
{
static Float_t pt[9999] = {0};
const Int_t n = (Int_t)array.size();
if (n < 1)
return kFALSE;
for (Int_t i = 0; i < n; i++)
pt[i] = array[i].perp();
TMath::Sort(n, pt, indexes);
return kTRUE;
}
/**
* This method is called once before analzying the first event.
* It generates the output jet branch name, initializes the FastJet wrapper
* and the utilities (FJ contribs).
*/
void AliEmcalJetTask::ExecOnce()
{
fYAMLConfig.Reinitialize();
if(fApplyPtDependentTrackingEfficiency) {
SetArtificialTrackingEfficiencyFromYAML();
}
// If a constant artificial track efficiency is supplied, create a TF1 that is constant in pT
if (fTrackEfficiency < 1.) {
// If a TF1 was already loaded, throw an error
if (fApplyArtificialTrackingEfficiency && fTrackEfficiencyHistogram==nullptr) {
AliError(Form("%s: fTrackEfficiencyFunction was already loaded! Do not apply multiple artificial track efficiencies.", GetName()));
}
fTrackEfficiencyFunction = new TF1("trackEfficiencyFunction", "[0]", 0., fMaxBinPt);
fTrackEfficiencyFunction->SetParameter(0, fTrackEfficiency);
fApplyArtificialTrackingEfficiency = kTRUE;
}
// If artificial tracking efficiency is enabled (either constant or pT-depdendent), set up random number generator
if (fApplyArtificialTrackingEfficiency) {
fRandom.SetSeed(0);
}
fJetsName = AliJetContainer::GenerateJetName(fJetType, fJetAlgo, fRecombScheme, fRadius, GetParticleContainer(0), GetClusterContainer(0), fJetsTag);
std::cout << GetName() << ": Name of the jet container: " << fJetsName << std::endl;
std::cout << "Use this name in order to connect jet containers in your task to connect to the collection of jets found by this jet finder" << std::endl;
if(auto partcont = GetParticleContainer(0)) {
std::cout << "Found particle container with name " << partcont->GetName() << std::endl;
} else {
std::cout << "Not particle container found for task" << std::endl;
}
if(auto clustcont = GetClusterContainer(0)){
std::cout << "Found cluster container with name " << clustcont->GetName() << std::endl;
} else {
std::cout << "Not cluster container found for task" << std::endl;
}
// add jets to event if not yet there
if (!(InputEvent()->FindListObject(fJetsName))) {
fJets = new TClonesArray("AliEmcalJet");
fJets->SetName(fJetsName);
::Info("AliEmcalJetTask::ExecOnce", "Jet collection with name '%s' has been added to the event.", fJetsName.Data());
InputEvent()->AddObject(fJets);
}
else {
AliError(Form("%s: Object with name %s already in event! Returning", GetName(), fJetsName.Data()));
return;
}
// setup fj wrapper
fFastJetWrapper.SetAreaType(fastjet::active_area_explicit_ghosts);
fFastJetWrapper.SetGhostArea(fGhostArea);
fFastJetWrapper.SetR(fRadius);
fFastJetWrapper.SetAlgorithm(ConvertToFJAlgo(fJetAlgo));
fFastJetWrapper.SetRecombScheme(ConvertToFJRecoScheme(fRecombScheme));
fFastJetWrapper.SetMaxRap(1);
// setting legacy mode
if (fLegacyMode) {
fFastJetWrapper.SetLegacyMode(kTRUE);
}
InitUtilities();
AliAnalysisTaskEmcal::ExecOnce();
// Setup container utils. Must be called after AliAnalysisTaskEmcal::ExecOnce() so that the
// containers' arrays are setup.
fClusterContainerIndexMap.CopyMappingFrom(AliClusterContainer::GetEmcalContainerIndexMap(), fClusterCollArray);
fParticleContainerIndexMap.CopyMappingFrom(AliParticleContainer::GetEmcalContainerIndexMap(), fParticleCollArray);
}
/**
* This method is called for each jet. It loops over the jet constituents and
* adds them to the jet object.
* @param jet Pointer to the AliEmcalJet object where the jet constituents will be added
* @param constituents List of the jet constituents returned by the FastJet wrapper
* @param constituents_unsub List of jet constituents before background subtraction
* @param flag If kTRUE it means that the argument "constituents" is a list of subtracted constituents
* @param particles_sub Array containing subtracted constituents
*/
void AliEmcalJetTask::FillJetConstituents(AliEmcalJet *jet, std::vector<fastjet::PseudoJet>& constituents,
std::vector<fastjet::PseudoJet>& constituents_unsub, Int_t flag, TString particlesSubName)
{
Int_t nt = 0;
Int_t nc = 0;
Double_t neutralE = 0.;
Double_t maxCh = 0.;
Double_t maxNe = 0.;
Int_t gall = 0;
Int_t gemc = 0;
Int_t cemc = 0;
Int_t ncharged = 0;
Int_t nneutral = 0;
Double_t mcpt = 0.;
Double_t emcpt = 0.;
TClonesArray * particles_sub = 0;
Int_t uid = -1;
jet->SetNumberOfTracks(constituents.size());
jet->SetNumberOfClusters(constituents.size());
for (UInt_t ic = 0; ic < constituents.size(); ++ic) {
if (flag == 0) {
uid = constituents[ic].user_index();
}
else {
if (constituents[ic].perp()<1.e-10) {
uid=-1;
}
else {
uid = constituents[ic].user_index();
}
if (uid==0) {
AliError("correspondence between un/subtracted constituent not found");
continue;
}
}
AliDebug(3,Form("Processing constituent %d", uid));
if (uid == -1) { //ghost particle
++gall;
if (fGeom) {
Double_t gphi = constituents[ic].phi();
if (gphi < 0) gphi += TMath::TwoPi();
gphi *= TMath::RadToDeg();
Double_t geta = constituents[ic].eta();
if ((gphi > fGeom->GetArm1PhiMin()) && (gphi < fGeom->GetArm1PhiMax()) &&
(geta > fGeom->GetArm1EtaMin()) && (geta < fGeom->GetArm1EtaMax()))
++gemc;
}
if (fFillGhost) jet->AddGhost(constituents[ic].px(),
constituents[ic].py(),
constituents[ic].pz(),
constituents[ic].e());
}
else if (uid >= fgkConstIndexShift) { // track constituent
Int_t iColl = uid / fgkConstIndexShift;
Int_t tid = uid - iColl * fgkConstIndexShift;
iColl--;
AliDebug(3,Form("Constituent %d is a track from collection %d and with ID %d", uid, iColl, tid));
AliParticleContainer* partCont = GetParticleContainer(iColl);
if (!partCont) {
AliError(Form("Could not find particle container %d",iColl));
continue;
}
AliVParticle *t = partCont->GetParticle(tid);
if (!t) {
AliError(Form("Could not find track %d",tid));
continue;
}
Double_t cEta = t->Eta();
Double_t cPhi = t->Phi();
Double_t cPt = t->Pt();
if (t->Charge() == 0) {
if (!fEnableAliBasicParticleCompatibility) {
neutralE += t->P();
}
++nneutral;
if (cPt > maxNe) maxNe = cPt;
} else {
++ncharged;
if (cPt > maxCh) maxCh = cPt;
}
// check if MC particle
if (!fEnableAliBasicParticleCompatibility) {
if (TMath::Abs(t->GetLabel()) > fMinMCLabel) mcpt += cPt;
}
if (fGeom) {
if (cPhi < 0) cPhi += TMath::TwoPi();
cPhi *= TMath::RadToDeg();
if ((cPhi > fGeom->GetArm1PhiMin()) && (cPhi < fGeom->GetArm1PhiMax()) &&
(cEta > fGeom->GetArm1EtaMin()) && (cEta < fGeom->GetArm1EtaMax())) {
emcpt += cPt;
++cemc;
}
}
if (flag == 0 || particlesSubName == "") {
jet->AddTrackAt(fParticleContainerIndexMap.GlobalIndexFromLocalIndex(partCont, tid), nt);
if(fFillConstituents){
jet->AddParticleConstituent(t, partCont->GetIsEmbedding(), fParticleContainerIndexMap.GlobalIndexFromLocalIndex(partCont, tid));
}
}
else {
// Get the particle container and array corresponding to the subtracted particles
partCont = GetParticleContainer(particlesSubName);
particles_sub = partCont->GetArray();
// Create the new particle in the particles_sub array and add it to the jet
Int_t part_sub_id = particles_sub->GetEntriesFast();
AliEmcalParticle* part_sub = new ((*particles_sub)[part_sub_id]) AliEmcalParticle(dynamic_cast<AliVTrack*>(t)); // SA: probably need to be fixed!!
part_sub->SetPtEtaPhiM(constituents[ic].perp(),constituents[ic].eta(),constituents[ic].phi(),constituents[ic].m());
jet->AddTrackAt(fParticleContainerIndexMap.GlobalIndexFromLocalIndex(partCont, part_sub_id), nt);
if(fFillConstituents){
jet->AddParticleConstituent(part_sub, partCont->GetIsEmbedding(), fParticleContainerIndexMap.GlobalIndexFromLocalIndex(partCont, part_sub_id));
}
}
++nt;
}
else if (uid <= -fgkConstIndexShift) { // cluster constituent
Int_t iColl = -uid / fgkConstIndexShift;
Int_t cid = -uid - iColl * fgkConstIndexShift;
iColl--;
AliDebug(3,Form("Constituent %d is a cluster from collection %d and with ID %d", uid, iColl, cid));
AliClusterContainer* clusCont = GetClusterContainer(iColl);
AliVCluster *c = clusCont->GetCluster(cid);
if (!c) continue;
AliTLorentzVector nP;
clusCont->GetMomentum(nP, cid);
Double_t cEta = nP.Eta();
Double_t cPhi = nP.Phi_0_2pi();
Double_t cPt = nP.Pt();
Double_t cP = nP.P();
neutralE += cP;
if (cPt > maxNe) maxNe = cPt;
// MC particle
if (TMath::Abs(c->GetLabel()) > fMinMCLabel) mcpt += c->GetMCEnergyFraction() > 1e-6 ? cPt * c->GetMCEnergyFraction() : cPt;
if (fGeom) {
if (cPhi<0) cPhi += TMath::TwoPi();
cPhi *= TMath::RadToDeg();
if ((cPhi > fGeom->GetArm1PhiMin()) && (cPhi < fGeom->GetArm1PhiMax()) &&
(cEta > fGeom->GetArm1EtaMin()) && (cEta < fGeom->GetArm1EtaMax())) {
emcpt += cPt;
++cemc;
}
}
if (flag == 0 || particlesSubName == "") {
jet->AddClusterAt(fClusterContainerIndexMap.GlobalIndexFromLocalIndex(clusCont, cid), nc);
if(fFillConstituents) {
Double_t pvec[3] = {nP.Px(), nP.Py(), nP.Pz()};
jet->AddClusterConstituent(c, (AliVCluster::VCluUserDefEnergy_t)clusCont->GetDefaultClusterEnergy(), pvec, clusCont->GetIsEmbedding(), fClusterContainerIndexMap.GlobalIndexFromLocalIndex(clusCont, cid));
}
}
else {
// Get the cluster container and array corresponding to the subtracted particles
clusCont = GetClusterContainer(particlesSubName);
particles_sub = clusCont->GetArray();
// Create the new particle in the particles_sub array and add it to the jet
Int_t part_sub_id = particles_sub->GetEntriesFast();
AliEmcalParticle* part_sub = new ((*particles_sub)[part_sub_id]) AliEmcalParticle(c);
part_sub->SetPtEtaPhiM(constituents[ic].perp(),constituents[ic].eta(),constituents[ic].phi(),constituents[ic].m());
jet->AddClusterAt(fClusterContainerIndexMap.GlobalIndexFromLocalIndex(clusCont, part_sub_id), nc);
if(fFillConstituents) {
// NOTE: The ClusterConstituent constructor won't work here because we're not passing an AliVCluster.
// We don't have an subtracted object. However, we don't want a user to miss this issue, so we raise an exception.
// - RE 2020-05-13
//clusCont->GetMomentum(nP, part_sub_id);
//Double_t pvec[3] = {nP.Px(), nP.Py(), nP.Pz()};
//jet->AddClusterConstituent(part_sub, (AliVCluster::VCluUserDefEnergy_t)clusCont->GetDefaultClusterEnergy(), pvec, clusCont->GetIsEmbedding(), fClusterContainerIndexMap.GlobalIndexFromLocalIndex(clusCont, part_sub_id));
throw std::runtime_error("Subtracted clusters constituents are not implemented.");
}
}
++nc;
++nneutral;
}
else {
AliError(Form("%s: No logical way to end up here (uid = %d).", GetName(), uid));
continue;
}
}
jet->SetNumberOfTracks(nt);
jet->SetNumberOfClusters(nc);
jet->SetNEF(neutralE / jet->E());
jet->SetMaxChargedPt(maxCh);
jet->SetMaxNeutralPt(maxNe);
if (gall > 0) jet->SetAreaEmc(jet->Area() * gemc / gall);
else jet->SetAreaEmc(-1);
jet->SetNEmc(cemc);
jet->SetNumberOfCharged(ncharged);
jet->SetNumberOfNeutrals(nneutral);
jet->SetMCPt(mcpt);
jet->SetPtEmc(emcpt);
jet->SortConstituents();
}
/**
* An instance of this class can be "locked". Once locked, it cannot be unlocked.
* If the instance is locked, attempting to change the configuration will throw a
* fatal and stop the execution of the program. This method checks whether the instance
* is locked and throw a fatal if it is locked.
*/
Bool_t AliEmcalJetTask::IsLocked() const
{
if (fLocked) {
AliFatal("Jet finder task is locked! Changing properties is not allowed.");
return kTRUE;
}
else {
return kFALSE;
}
}
/**
* This overloads the method of AliAnalysisTaskSE to set the trigger bits. Since
* the output of this task is often a shared input of several consumer task
* the event selection is not allwed.
* @param offlineTriggerMask Trigger bit mask
*/
void AliEmcalJetTask::SelectCollisionCandidates(UInt_t offlineTriggerMask)
{
if(!fIsPSelSet) {
fIsPSelSet = kTRUE;
fOfflineTriggerMask = offlineTriggerMask;
}
else {
AliWarning("Manually setting the event selection for jet finders is not allowed! Using trigger=old_trigger | your_trigger");
fOfflineTriggerMask = fOfflineTriggerMask | offlineTriggerMask;
}
}
/**
* Set the eta range of the track constituents.
* @param emi Minimum eta
* @param ema Maximum eta
*/
void AliEmcalJetTask::SetEtaRange(Double_t emi, Double_t ema)
{
if (IsLocked()) return;
TIter nextPartColl(&fParticleCollArray);
AliParticleContainer* tracks = 0;
while ((tracks = static_cast<AliParticleContainer*>(nextPartColl()))) {
tracks->SetParticleEtaLimits(emi, ema);
}
}
/**
* Set the minimum pT of the cluster constituents.
* @param min Minimum pT
*/
void AliEmcalJetTask::SetMinJetClusPt(Double_t min)
{
if (IsLocked()) return;
TIter nextClusColl(&fClusterCollArray);
AliClusterContainer* clusters = 0;
while ((clusters = static_cast<AliClusterContainer*>(nextClusColl()))) {
clusters->SetClusPtCut(min);
}
}
/**
* Set the minimum energy of the cluster constituents.
* @param min Minimum energy
*/
void AliEmcalJetTask::SetMinJetClusE(Double_t min)
{
if (IsLocked()) return;
TIter nextClusColl(&fClusterCollArray);
AliClusterContainer* clusters = 0;
while ((clusters = static_cast<AliClusterContainer*>(nextClusColl()))) {
clusters->SetClusECut(min);
}
}
/**
* Set the minimum pT of the track constituents.
* @param min Minimum pT
*/
void AliEmcalJetTask::SetMinJetTrackPt(Double_t min)
{
if (IsLocked()) return;
TIter nextPartColl(&fParticleCollArray);
AliParticleContainer* tracks = 0;
while ((tracks = static_cast<AliParticleContainer*>(nextPartColl()))) {
tracks->SetParticlePtCut(min);
}
}
/**
* Set the phi range of the track constituents.
* @param pmi Minimum phi
* @param pma Maximum phi
*/
void AliEmcalJetTask::SetPhiRange(Double_t pmi, Double_t pma)
{
if (IsLocked()) return;
TIter nextPartColl(&fParticleCollArray);
AliParticleContainer* tracks = 0;
while ((tracks = static_cast<AliParticleContainer*>(nextPartColl()))) {
tracks->SetParticlePhiLimits(pmi, pma);
}
}
/**
* Converts the internal enum values representing jet algorithms in
* the corresponding values accepted by the FastJet wrapper.
* @param algo Algorithm represented in the EJetAlgo_t enum
* @return Algortithm represented in the fastjet::JetAlgorithm enum
*/
fastjet::JetAlgorithm AliEmcalJetTask::ConvertToFJAlgo(EJetAlgo_t algo)
{
switch(algo) {
case AliJetContainer::kt_algorithm:
return fastjet::kt_algorithm;
case AliJetContainer::antikt_algorithm:
return fastjet::antikt_algorithm;
case AliJetContainer::cambridge_algorithm:
return fastjet::cambridge_algorithm;
case AliJetContainer::genkt_algorithm:
return fastjet::genkt_algorithm;
case AliJetContainer::cambridge_for_passive_algorithm:
return fastjet::cambridge_for_passive_algorithm;
case AliJetContainer::genkt_for_passive_algorithm:
return fastjet::genkt_for_passive_algorithm;
case AliJetContainer::plugin_algorithm:
return fastjet::plugin_algorithm;
case AliJetContainer::undefined_jet_algorithm:
return fastjet::undefined_jet_algorithm;
default:
::Error("AliEmcalJetTask::ConvertToFJAlgo", "Jet algorithm %d not recognized!!!", algo);
return fastjet::undefined_jet_algorithm;
}
}
/**
* Converts the internal enum values representing jet recombination schemes in
* the corresponding values accepted by the FastJet wrapper.
* @param reco Recombination scheme represented in the EJetAlgo_t enum
* @return Recombination scheme represented in the fastjet::JetAlgorithm enum
*/
fastjet::RecombinationScheme AliEmcalJetTask::ConvertToFJRecoScheme(ERecoScheme_t reco)
{
switch(reco) {
case AliJetContainer::E_scheme:
return fastjet::E_scheme;
case AliJetContainer::pt_scheme:
return fastjet::pt_scheme;
case AliJetContainer::pt2_scheme:
return fastjet::pt2_scheme;
case AliJetContainer::Et_scheme:
return fastjet::Et_scheme;
case AliJetContainer::Et2_scheme:
return fastjet::Et2_scheme;
case AliJetContainer::BIpt_scheme:
return fastjet::BIpt_scheme;
case AliJetContainer::BIpt2_scheme:
return fastjet::BIpt2_scheme;
case AliJetContainer::external_scheme:
return fastjet::external_scheme;
default:
::Error("AliEmcalJetTask::ConvertToFJRecoScheme", "Recombination scheme %d not recognized!!!", reco);
return fastjet::external_scheme;
}
}
/**
* Finds which geometrical acceptance types the jet satisfies.
* @return bitwise jet acceptance type
*/
UInt_t AliEmcalJetTask::FindJetAcceptanceType(Double_t eta, Double_t phi, Double_t r) {
//This method has to be called after the run number is known because it needs the EMCal geometry object.
UInt_t jetAcceptanceType = AliEmcalJet::kUser; // all jets satify the "no acceptance cut" condition
// Check if TPC
if( eta < 0.9 && eta > -0.9 ) {
jetAcceptanceType |= AliEmcalJet::kTPC;
// Check if TPCfid
if (eta < 0.9 - r && eta > -0.9 + r)
jetAcceptanceType |= AliEmcalJet::kTPCfid;
}
// Check if EMCAL
if( IsJetInEmcal(eta, phi, 0) ) {
jetAcceptanceType |= AliEmcalJet::kEMCAL;
// Check if EMCALfid
if( IsJetInEmcal(eta, phi, r) )
jetAcceptanceType |= AliEmcalJet::kEMCALfid;
}
// Check if DCAL (i.e. eta-phi rectangle spanning DCal, which includes most of PHOS)
if( IsJetInDcal(eta, phi, 0) ) {
jetAcceptanceType |= AliEmcalJet::kDCAL;
// Check if DCALfid
if( IsJetInDcal(eta, phi, r) )
jetAcceptanceType |= AliEmcalJet::kDCALfid;
}
// Check if DCALonly (i.e. ONLY DCal, does not include any of PHOS region)
if( IsJetInDcalOnly(eta, phi, 0) ) {
jetAcceptanceType |= AliEmcalJet::kDCALonly;
// Check if DCALonlyfid
if( IsJetInDcalOnly(eta, phi, r) )
jetAcceptanceType |= AliEmcalJet::kDCALonlyfid;
}
// Check if PHOS
if( IsJetInPhos(eta, phi, 0) ) {
jetAcceptanceType |= AliEmcalJet::kPHOS;
// Check if PHOSfid
if( IsJetInPhos(eta, phi, r) )
jetAcceptanceType |= AliEmcalJet::kPHOSfid;
}
return jetAcceptanceType;
}
/**
* Returns whether or not jet with given eta, phi, R is in EMCal.
*/
Bool_t AliEmcalJetTask::IsJetInEmcal(Double_t eta, Double_t phi, Double_t r)
{
if (!fGeom) return kFALSE;
if ( eta < fGeom->GetArm1EtaMax() - r && eta > fGeom->GetArm1EtaMin() + r ) {
if(fRunNumber >= 177295 && fRunNumber <= 197470) {//small SM masked in 2012 and 2013
if ( phi < 3.135 - r && phi > 1.405 + r )
return kTRUE;
}
else {
if ( phi < fGeom->GetEMCALPhiMax() * TMath::DegToRad() - r && phi > fGeom->GetArm1PhiMin() * TMath::DegToRad() + r)
return kTRUE;
}
}
return kFALSE;
}
/**
* Returns whether or not jet with given eta, phi, R is in DCal region (note: spans most of PHOS as well).
*/
Bool_t AliEmcalJetTask::IsJetInDcal(Double_t eta, Double_t phi, Double_t r)