AliPhysics  master (3d17d9d)
AliAnalysisTaskEmcalQoverPtShift.cxx
Go to the documentation of this file.
1 /************************************************************************************
2  * Copyright (C) 2020, Copyright Holders of the ALICE Collaboration *
3  * All rights reserved. *
4  * *
5  * Redistribution and use in source and binary forms, with or without *
6  * modification, are permitted provided that the following conditions are met: *
7  * * Redistributions of source code must retain the above copyright *
8  * notice, this list of conditions and the following disclaimer. *
9  * * Redistributions in binary form must reproduce the above copyright *
10  * notice, this list of conditions and the following disclaimer in the *
11  * documentation and/or other materials provided with the distribution. *
12  * * Neither the name of the <organization> nor the *
13  * names of its contributors may be used to endorse or promote products *
14  * derived from this software without specific prior written permission. *
15  * *
16  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND *
17  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED *
18  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE *
19  * DISCLAIMED. IN NO EVENT SHALL ALICE COLLABORATION BE LIABLE FOR ANY *
20  * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES *
21  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; *
22  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND *
23  * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT *
24  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS *
25  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. *
26  ************************************************************************************/
27 #include <array>
28 #include <iostream>
29 #include <string>
30 #include <sstream>
31 #include "THashList.h"
32 #include "THistManager.h"
33 #include "AliAnalysisManager.h"
35 #include "AliAODInputHandler.h"
36 #include "AliESDInputHandler.h"
37 #include "AliLog.h"
38 #include "AliTrackContainer.h"
39 #include "AliVEvent.h"
40 #include "AliVEventHandler.h"
41 #include "AliVTrack.h"
42 
44 
45 using namespace PWGJE::EMCALJetTasks;
46 
49  fHistos(nullptr),
50  fQOverPtShift(0.),
51  fTriggerBits(0),
52  fTriggerString()
53 {
54 }
55 
56 AliAnalysisTaskEmcalQoverPtShift::AliAnalysisTaskEmcalQoverPtShift(const char *name):
57  AliAnalysisTaskEmcalLight(name, kTRUE),
58  fHistos(nullptr),
59  fQOverPtShift(0.),
60  fTriggerBits(0),
61  fTriggerString()
62 {
63 }
64 
66 {
67 }
68 
71 
72  fHistos = new THistManager("fHistos");
73 
74  std::array<std::string, 2> chargetypes = {{"pos", "neg"}};
75  for(auto charge : chargetypes) {
76  fHistos->CreateTH2(Form("fHistShift%s", charge.data()), Form("Pt-shift for charge %s; p_{t}^{orig} (GeV/c); p_{t}^{shift}", charge.data()), 300, 0., 300, 300, 0., 300.);
77  }
78 
79  for(auto hist : *fHistos->GetListOfHistograms()) fOutput->Add(hist);
80 
81  PostData(1, fOutput);
82 }
83 
85  auto tracks = GetTrackContainer("detector");
86  if(!tracks) {
87  AliErrorStream() << "No track container attached, not entering track loop" << std::endl;
88  return kFALSE;
89  }
90 
91  for(auto trk : tracks->accepted()) {
92  Double_t chargeval = trk->Charge() > 0 ? 1 : -1;
93  std::string chargestring = chargeval > 0 ? "pos" : "neg";
94  Double_t ptorig = abs(trk->Pt());
95  Double_t ptshift = 1./(fQOverPtShift*chargeval + 1./ptorig);
96  fHistos->FillTH2(Form("fHistShift%s", chargestring.data()), ptorig, ptshift);
97  }
98  return kTRUE;
99 }
100 
102  if(!(fInputHandler->IsEventSelected() & fTriggerBits)) return kFALSE;
103  if(!fInputEvent->GetFiredTriggerClasses().Contains(fTriggerString)) return kFALSE;
104  return kTRUE;
105 }
106 
108  auto mgr = AliAnalysisManager::GetAnalysisManager();
109  if(!mgr) {
110  std::cerr << "Analysis Manager not initialized" << std::endl;
111  return nullptr;
112  }
113 
114  std::string track_name;
115  auto inputhandler = mgr->GetInputEventHandler();
116  if(inputhandler->InheritsFrom(AliAODInputHandler::Class())) {
117  track_name = "tracks";
118  std::cout << "Setting track container \"" << track_name << "\" for AODs" << std::endl;
119  } else if(inputhandler->InheritsFrom(AliESDInputHandler::Class())) {
120  track_name = "Tracks";
121  std::cout << "Setting track container \"" << track_name << "\" for ESDs" << std::endl;
122  } else {
123  std::cerr << "Unknown input format or input handler not set" << std::endl;
124  return nullptr;
125  }
126 
127  UInt_t triggerbits(0);
128  EMCAL_STRINGVIEW triggerstring(trigger);
129  if(triggerstring == "INT7") triggerbits = AliVEvent::kINT7;
130  else if(triggerstring == "EJ1" || triggerstring == "EJ2") triggerbits = AliVEvent::kEMCEJE;
131  else if(triggerstring == "EG1" || triggerstring == "EG2") triggerbits = AliVEvent::kEMCEGA;
132  if(!triggerbits) {
133  std::cerr << "Unknown trigger class " << triggerstring << ", cannot configure task" << std::endl;
134  return nullptr;
135  }
136 
137  std::stringstream taskname;
138  std::string qoverptstring(Form("%c%05d", shift > 0 ? 'p' : 'm', std::abs(int(shift * 1e5))));
139  taskname << "QOverPtTask_" << qoverptstring << "_" << trigger;
140  auto task = new AliAnalysisTaskEmcalQoverPtShift(taskname.str().data());
141  task->AddParticleContainer(track_name.data(), "detector");
142  task->SetQOverPtShift(shift);
143  task->SetTriggerSelection(triggerbits, trigger);
144  mgr->AddTask(task);
145 
146  std::stringstream outputfile, listname;
147  outputfile << mgr->GetCommonFileName() << ":QOverPtShift_" << qoverptstring << "_" << trigger;
148  listname << "QOverPtShiftHistos_" << qoverptstring << "_" << trigger;
149 
150  mgr->ConnectInput(task, 0, mgr->GetCommonInputContainer());
151  mgr->ConnectOutput(task, 1, mgr->CreateContainer(listname.str().data(), TList::Class(), AliAnalysisManager::kOutputContainer, outputfile.str().data()));
152 
153  return task;
154 }
Int_t charge
double Double_t
Definition: External.C:58
void FillTH2(const char *hname, double x, double y, double weight=1., Option_t *opt="")
Fill a 2D histogram within the container.
TH2 * CreateTH2(const char *name, const char *title, int nbinsx, double xmin, double xmax, int nbinsy, double ymin, double ymax, Option_t *opt="")
Create a new TH2 within the container.
unsigned int UInt_t
Definition: External.C:33
THashList * GetListOfHistograms() const
Get the list of histograms.
Definition: THistManager.h:671
Base task in the EMCAL framework (lighter version of AliAnalysisTaskEmcal)
AliTrackContainer * GetTrackContainer(EMCAL_STRINGVIEW name) const
#define EMCAL_STRINGVIEW
Container class for histograms.
Definition: THistManager.h:99
static AliAnalysisTaskEmcalQoverPtShift * AddTaskQOverPtShift(const char *trigger, double shift)
bool Bool_t
Definition: External.C:53