AliPhysics  6f1d526 (6f1d526)
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
AliJetEmbeddingFromPYTHIATask.cxx
Go to the documentation of this file.
1 // $Id$
2 //
3 // Jet embedding from PYTHIA task.
4 //
5 // Author: S.Aiola, C.Loizides
6 
8 
9 #include <TFile.h>
10 #include <TMath.h>
11 #include <TString.h>
12 #include <TRandom.h>
13 #include <TParameter.h>
14 #include <TH1I.h>
15 #include <TGrid.h>
16 #include <THashTable.h>
17 #include <TSystem.h>
18 
19 #include "AliVEvent.h"
20 #include "AliLog.h"
21 
23 
24 //________________________________________________________________________
27  fPYTHIAPath(),
28  fPtHardBinScaling(),
29  fLHC11hAnchorRun(kTRUE),
30  fAnchorRun(-1),
31  fFileTable(0),
32  fUseAsVetoTable(kTRUE),
33  fMinEntriesPerPtHardBin(1),
34  fCurrentPtHardBin(-1),
35  fPtHardBinParam(0),
36  fPtHardBinCount(0),
37  fHistPtHardBins(0),
38  fDebugEmbedding(kFALSE)
39 {
40  // Default constructor.
41  SetSuffix("PYTHIAEmbedding");
42  fTotalFiles = 140;
43  fRandomAccess = kTRUE;
44  SetAODMC(kTRUE);
45 }
46 
47 //________________________________________________________________________
49  AliJetEmbeddingFromAODTask(name, drawqa),
50  fPYTHIAPath("alien:///alice/sim/2012/LHC12a15e_fix/%d/%d/AOD149/%04d/AliAOD.root"),
51  fPtHardBinScaling(),
52  fLHC11hAnchorRun(kTRUE),
53  fAnchorRun(-1),
54  fFileTable(0),
55  fUseAsVetoTable(kTRUE),
56  fMinEntriesPerPtHardBin(1),
57  fCurrentPtHardBin(-1),
58  fPtHardBinParam(0),
59  fPtHardBinCount(0),
60  fHistPtHardBins(0),
61  fDebugEmbedding(kFALSE)
62 {
63  // Standard constructor.
64  SetSuffix("PYTHIAEmbedding");
65  fTotalFiles = 140;
66  fRandomAccess = kTRUE;
67  SetAODMC(kTRUE);
68 }
69 
70 //________________________________________________________________________
72 {
73  // Destructor
74 }
75 
76 //________________________________________________________________________
78 {
79  if (!fQAhistos)
80  return;
81 
83 
84  fHistPtHardBins = new TH1F("fHistPtHardBins", "fHistPtHardBins", 11, 0, 11);
85  fHistPtHardBins->GetXaxis()->SetTitle("p_{T} hard bin");
86  fHistPtHardBins->GetYaxis()->SetTitle("total events");
88 
89  const Int_t ptHardLo[11] = { 0, 5,11,21,36,57, 84,117,152,191,234};
90  const Int_t ptHardHi[11] = { 5,11,21,36,57,84,117,152,191,234,1000000};
91 
92  for (Int_t i = 1; i < 12; i++)
93  fHistPtHardBins->GetXaxis()->SetBinLabel(i, Form("%d-%d",ptHardLo[i-1],ptHardHi[i-1]));
94 
95  fHistEmbeddingQA = new TH1F("fHistEmbeddingQA", "fHistEmbeddingQA", 2, 0, 2);
96  fHistEmbeddingQA->GetXaxis()->SetTitle("Event state");
97  fHistEmbeddingQA->GetYaxis()->SetTitle("counts");
98  fHistEmbeddingQA->GetXaxis()->SetBinLabel(1, "OK");
99  fHistEmbeddingQA->GetXaxis()->SetBinLabel(2, "Not embedded");
101 
102  fHistRejectedEvents = new TH1F("fHistRejectedEvents", "fHistRejectedEvents", 500, -0.5, 499.5);
103  fHistRejectedEvents->GetXaxis()->SetTitle("# of rejected events");
104  fHistRejectedEvents->GetYaxis()->SetTitle("counts");
106 
107  PostData(1, fOutput);
108 }
109 
110 //________________________________________________________________________
112 {
113  if (fPtHardBinScaling.GetSize() > 0) {
114  Double_t sum = 0;
115  for (Int_t i = 0; i < fPtHardBinScaling.GetSize(); i++)
116  sum += fPtHardBinScaling[i];
117 
118  if (sum == 0) {
119  AliWarning("No hard pt bin scaling!");
120  sum = fPtHardBinScaling.GetSize();
121  for (Int_t i = 0; i < fPtHardBinScaling.GetSize(); i++)
122  fPtHardBinScaling[i] /= sum;
123  }
124  else {
125  for (Int_t i = 0; i < fPtHardBinScaling.GetSize(); i++)
126  fPtHardBinScaling[i] /= sum;
127  }
128  }
129 
130  fPtHardBinParam = static_cast<TParameter<int>*>(InputEvent()->FindListObject("PYTHIAPtHardBin"));
131  if (!fPtHardBinParam) {
132  fPtHardBinParam = new TParameter<int>("PYTHIAPtHardBin", 0);
133  AliDebug(3,"Adding pt hard bin param object to the event list...");
134  InputEvent()->AddObject(fPtHardBinParam);
135  }
136 
138 }
139 
140 //________________________________________________________________________
142 {
144  fPtHardBinCount = 0;
145 
146  Int_t newPtHard = GetRandomPtHardBin();
147 
148  if (newPtHard != fCurrentPtHardBin) {
149  fPtHardBinParam->SetVal(newPtHard);
150  fCurrentPtHardBin = newPtHard;
151  if (!OpenNextFile()) return kFALSE;
152  }
153  }
154 
155  fPtHardBinCount++;
156  if (fHistPtHardBins) fHistPtHardBins->SetBinContent(fCurrentPtHardBin+1, fHistPtHardBins->GetBinContent(fCurrentPtHardBin+1)+1);
157 
159 }
160 
161 //________________________________________________________________________
163 {
164  static Int_t order[20]={-1};
165 
166  if (order[0] == -1)
167  TMath::Sort(fPtHardBinScaling.GetSize(), fPtHardBinScaling.GetArray(), order);
168 
169  Double_t rnd = gRandom->Rndm();
170  Double_t sum = 0;
171  Int_t ptHard = -1;
172  for (Int_t i = 0; i < fPtHardBinScaling.GetSize(); i++) {
173  sum += fPtHardBinScaling[order[i]];
174  if (sum >= rnd) {
175  ptHard = order[i];
176  break;
177  }
178  }
179 
180  return ptHard;
181 }
182 
183 //________________________________________________________________________
185 {
186  if (!fLHC11hAnchorRun)
187  return kTRUE;
188 
189  Int_t runNumber = InputEvent()->GetRunNumber();
190 
191  Int_t semiGoodRunList[32] = {169975, 169981, 170038, 170040, 170083, 170084, 170085,
192  170088, 170089, 170091, 170152, 170155, 170159, 170163,
193  170193, 170195, 170203, 170204, 170228, 170230, 170268,
194  170269, 170270, 170306, 170308, 170309, 169238, 169160,
195  169156, 169148, 169145, 169144};
196 
197  fAnchorRun = 169838; // Assume it is a good run
198 
199  for (Int_t i = 0; i < 32; i++) {
200  if (runNumber == semiGoodRunList[i]) { // If it is semi good, change the anchor run
201  fAnchorRun = 170040;
202  break;
203  }
204  }
205 
206  return kTRUE;
207 }
208 
209 //________________________________________________________________________
211 {
212  if (fDebugEmbedding == kTRUE) {
213  // Embed files in order
215  // Ensure only files up to the total number of files are used
217  fCurrentAODFileID = 1;
218  }
219  }
220  else {
221  fCurrentAODFileID = TMath::Nint(gRandom->Rndm()*(fTotalFiles-1))+1;
222  }
223 
224  if (fMinEntriesPerPtHardBin < 0) {
227  }
228 
230 
231  if (fAnchorRun>0)
232  fileName = Form(fPYTHIAPath.Data(), fAnchorRun, fCurrentPtHardBin, fCurrentAODFileID);
233  else
234  fileName = Form(fPYTHIAPath.Data(), fCurrentPtHardBin, fCurrentAODFileID);
235 
236  if (fFileTable && fFileTable->GetEntries() > 0) {
237  TObject* obj = fFileTable->FindObject(fileName);
238  if (obj != 0 && fUseAsVetoTable) {
239  AliWarning(Form("File %s found in the vetoed file table. Skipping...", fileName.Data()));
240  return 0;
241  }
242  if (obj == 0 && !fUseAsVetoTable) {
243  AliWarning(Form("File %s not found in the allowed file table. Skipping...", fileName.Data()));
244  return 0;
245  }
246  }
247 
248  if (fileName.BeginsWith("alien://") && !gGrid) {
249  AliInfo("Trying to connect to AliEn ...");
250  TGrid::Connect("alien://");
251  }
252 
253  TString baseFileName(fileName);
254  if (baseFileName.Contains(".zip#")) {
255  Ssiz_t pos = baseFileName.Last('#');
256  baseFileName.Remove(pos);
257  }
258 
259  if (gSystem->AccessPathName(baseFileName)) {
260  AliError(Form("File %s does not exist!", baseFileName.Data()));
261  return 0;
262  }
263 
264  AliDebug(3,Form("Trying to open file %s...", fileName.Data()));
265  TFile *file = TFile::Open(fileName);
266 
267  if (!file || file->IsZombie()) {
268  AliError(Form("Unable to open file: %s!", fileName.Data()));
269  return 0;
270  }
271 
272  return file;
273 }
double Double_t
Definition: External.C:58
TString fileName
TList * fOutput
! output list for QA histograms
TSystem * gSystem
TH1 * fHistEmbeddingQA
File ID not embedded.
Class for Pythia event embedding into data.
Bool_t ExecOnce()
generate a particle with random eta,phi, and correlated pt,mass values
TRandom * gRandom
Bool_t ExecOnce()
generate a particle with random eta,phi, and correlated pt,mass values
ClassImp(AliJetEmbeddingFromPYTHIATask) AliJetEmbeddingFromPYTHIATask
int Int_t
Definition: External.C:63
TParameter< int > * fPtHardBinParam
Pt hard bin of the current open file.
Bool_t fQAhistos
draw QA histograms
TFile * file
Int_t fCurrentAODFileID
Current file being processed (via the event handler)
void SetSuffix(const char *s)
bool Bool_t
Definition: External.C:53
Bool_t fDebugEmbedding
Number of event embedded from the current pt hard bin.
Class for embedding a AOD event into a data event.