]> git.uio.no Git - u/mrichter/AliRoot.git/blame - PWG/muon/AliAnalysisMuMuEventCutter.cxx
Merge branch 'feature-movesplit'
[u/mrichter/AliRoot.git] / PWG / muon / AliAnalysisMuMuEventCutter.cxx
CommitLineData
5376e016
CP
1#include "AliAnalysisMuMuEventCutter.h"
2
3/**
4 *
5 * \ingroup pwg-muon-mumu
6 *
7 * \class AliAnalysisMuMuEventCutter
8 *
9 * We're grouping here various event cut methods that can be used
10 * as AliAnalysisMuMuCutElement. For instance :
11 *
12 * - \ref IsPhysicsSelected this is the normal physics selection check
13 * - \ref IsPhysicsSelectedVDM version of the physics selection used for VdM analysis
14 * - \ref IsSPDzVertexInRange selects event with a SPDvertex in a given range
15 * - \ref IsAbsZBelowValue selects event with |Zvertex| (being SPD or not) below a given value
16 * - \ref IsAbsZBelowValue as above but requesting explicitely the SPD vertex
17 * - \ref IsSPDzQA whether the SPD vertex is a good one
18 */
19
20#include "TObjString.h"
21#include "AliLog.h"
22#include "AliMuonEventCuts.h"
16560e8e 23#include "AliAnalysisMuonUtility.h"
5376e016 24#include "TList.h"
16560e8e 25#include "TTree.h"
5376e016
CP
26#include "Riostream.h"
27#include "AliVVertex.h"
28#include "AliAODVertex.h"
29#include "AliVVZERO.h"
30#include "AliInputEventHandler.h"
16560e8e 31#include "AliMCEventHandler.h"
5376e016 32#include "AliVEvent.h"
16560e8e 33#include "AliMCEvent.h"
5376e016 34#include "TMath.h"
16560e8e 35#include "TParameter.h"
5376e016
CP
36#include "AliESDTZERO.h"
37#include "AliAODTZERO.h"
38#include "AliESDEvent.h"
39#include "AliAODEvent.h"
16560e8e 40#include "AliAODMCHeader.h"
41#include "AliGenEventHeader.h"
42#include "AliGenHijingEventHeader.h"
43#include "AliGenDPMjetEventHeader.h"
44#include "AliGenCocktailEventHeader.h"
5376e016
CP
45
46ClassImp(AliAnalysisMuMuEventCutter)
47
48//______________________________________________________________________________
16560e8e 49AliAnalysisMuMuEventCutter::AliAnalysisMuMuEventCutter(TList* triggerClasses, TList* triggerInputsMap)
5376e016
CP
50: TObject(), fMuonEventCuts(0x0)
51{
52 /// ctor
53 TString tclasses;
54
55 if ( !triggerClasses )
56 {
57 tclasses = "ANY";
58 }
59 else
60 {
61 TObjString* tname;
62 TIter next(triggerClasses);
63
64 while ( ( tname = static_cast<TObjString*>(next()) ) )
65 {
66 if (tclasses.Length()>0)
67 {
68 tclasses += ",";
69 }
70
71 tclasses += tname->String();
72 }
73 }
74
16560e8e 75 TString tinputs;
76
77 if ( !triggerInputsMap )
78 {
79 tinputs = "";
80 }
81 else
82 {
83 TObjString* tinputsname;
84 TIter next(triggerInputsMap);
85
86 while ( ( tinputsname = static_cast<TObjString*>(next()) ) )
87 {
88 if (tinputs.Length()>0)
89 {
90 tinputs += ",";
91 }
92
93 tinputs += tinputsname->String();
94 }
95 }
96
97 MuonEventCuts()->SetTrigClassPatterns(tclasses,tinputs);
98
5376e016
CP
99}
100
16560e8e 101
5376e016
CP
102//______________________________________________________________________________
103AliAnalysisMuMuEventCutter::~AliAnalysisMuMuEventCutter()
104{
105 /// dtor
106 delete fMuonEventCuts;
107}
108
109//_____________________________________________________________________________
110Bool_t AliAnalysisMuMuEventCutter::SelectTriggerClass(const TString& firedTriggerClasses,
111 TString& acceptedClasses,
112 UInt_t L0, UInt_t L1, UInt_t L2) const
113{
114 /// Forward the trigger class selection to MuonEventCuts::GetSelectedTrigClassesInEvent
115 acceptedClasses = "";
116
117 TIter next(MuonEventCuts()->GetSelectedTrigClassesInEvent(firedTriggerClasses,L0,L1,L2));
118 TObjString* str;
119
120 while ( ( str = static_cast<TObjString*>(next()) ) )
121 {
122 acceptedClasses += str->String();
123 acceptedClasses += " ";
124 }
125 return (acceptedClasses.Length()>0);
126}
127
128//_____________________________________________________________________________
129Bool_t AliAnalysisMuMuEventCutter::IsPhysicsSelected(const AliInputEventHandler& eventHandler) const
130{
131 /// Whether or not the event is physics selected
132 return const_cast<AliInputEventHandler&>(eventHandler).IsEventSelected() & AliVEvent::kAny;
133}
134
135//_____________________________________________________________________________
136Bool_t AliAnalysisMuMuEventCutter::IsPhysicsSelectedVDM(const AliVEvent& event) const
137{
138 // cut used in vdM scans
139
140 AliVVZERO* vzero = event.GetVZEROData();
141
142 if (vzero)
143 {
144 Float_t v0a = vzero->GetV0ATime();
145 Float_t v0c = vzero->GetV0CTime();
146
147 Float_t v0diff = v0a-v0c;
148 Float_t v0sum = v0a+v0c;
149
150 if ( ( v0sum > 10.5 && v0sum < 18 ) && ( v0diff > 4 && v0diff < 12 ) )
151 {
152 return kTRUE;
153 }
154 }
155 return kFALSE;
156}
157
16560e8e 158//_____________________________________________________________________________
159Bool_t AliAnalysisMuMuEventCutter::IsMCEventNSD(const AliVEvent& event) const
160{
161 // Check for headers
162 //FIXME: For now this is only valid for DPMJET
163 //FIXME: working only on AODs
164
165 if ( static_cast<const AliVEvent*>(&event)->IsA() == AliESDEvent::Class() )
166 {
167 AliWarning("Not implemented for ESDs yet");
168 return kFALSE;
169 }
170
171 const AliAODEvent* eventAOD = static_cast<const AliAODEvent*>(&event);
172
173 AliAODMCHeader* mcHeader = static_cast<AliAODMCHeader*>(eventAOD->FindListObject(AliAODMCHeader::StdBranchName()));
174
175 if(mcHeader)
176 {
177 TList* lheaders = mcHeader->GetCocktailHeaders();
178
179 if ( lheaders->GetEntries() > 1 ) AliWarning("There is more than one header: The simulation is a cocktail");
180
181 AliGenEventHeader* mcGenH(0x0);
182 AliGenHijingEventHeader* hHijing(0x0);
183 AliGenDPMjetEventHeader* hDpmJet(0x0);
184 TIter next(lheaders); // Get the iterator on the list of cocktail headers
185
186// lheaders->Print();
187
188 while ( (mcGenH = static_cast<AliGenEventHeader*>(next())) ) // Loop over the cocktail headers
189 {
190// std::cout << mcGenH->GetName() << std::endl;
191 if (mcGenH->InheritsFrom(AliGenHijingEventHeader::Class()))
192 {
193 hHijing = static_cast<AliGenHijingEventHeader*>(mcGenH);
194 }
195 if (mcGenH->InheritsFrom(AliGenDPMjetEventHeader::Class()))
196 {
197 hDpmJet = static_cast<AliGenDPMjetEventHeader*>(mcGenH);
198 }
199 } // End of loop over cocktail headers
200
201 if ( !hDpmJet && !hHijing )
202 {
203 AliError("No GenHeader found");
204 return kFALSE;
205 }
206 else if ( hDpmJet )
207 {
208 Int_t nsd1,nsd2,ndd;
209 Int_t npProj = hDpmJet->ProjectileParticipants();
210// Int_t npProj = hDpmJet->TargetParticipants();
211
212// std::cout << hDpmJet->ProcessType() << std::endl;
213 hDpmJet->GetNDiffractive(nsd1,nsd2,ndd);
214
215 if (ndd==0 && (npProj==nsd1 || npProj==nsd2))
216 {
217 return kFALSE; // reject SD
218 }
219 else return kTRUE; //Is NSD event
220
221 }
222 else
223 {
224 AliWarning("Implement the Hijing section");
225 return kFALSE;
226 }
227 }
228 else
229 {
230 AliError("No MCheader in MCEvent");
231 return kFALSE;
232 }
233
234}
235
5376e016
CP
236//_____________________________________________________________________________
237Bool_t AliAnalysisMuMuEventCutter::IsAbsZBelowValue(const AliVEvent& event, const Double_t& z) const
238{
239 // Checks if the absolute value of the Z component of the primary vertex is below a certain value
240
241 const AliVVertex* vertex = event.GetPrimaryVertex();
242 return (TMath::Abs(vertex->GetZ())<=z);
243}
244
245//_____________________________________________________________________________
246Bool_t AliAnalysisMuMuEventCutter::IsAbsZSPDBelowValue(const AliVEvent& event, const Double_t& z) const
247{
248 // Checks if the absolute value of the SPD Z component of the given vertex is below a certain value
5376e016 249
16560e8e 250 Double_t SPDzv(0.);
251 Bool_t vertexFound(kFALSE);
252
253 AliVVertex* SPDVertex = AliAnalysisMuonUtility::GetVertexSPD(static_cast<const AliVEvent*>(&event));
254 if ( SPDVertex )
255 {
256 vertexFound = kTRUE;
257 SPDzv = SPDVertex->GetZ();
258 }
259
260 if ( !vertexFound )
5376e016
CP
261 {
262 AliError("SPD |z| cut requested and no SPD vertex found in the event");
263 return kFALSE;
264 }
265
16560e8e 266 else return (TMath::Abs(SPDzv)<z);
5376e016
CP
267}
268
269
270//_____________________________________________________________________________
271Bool_t AliAnalysisMuMuEventCutter::IsSPDzVertexInRange(AliVEvent& event, const Double_t& zMin, const Double_t& zMax) const
272{
273 /// Whether or not the SPD Z vertex is in the range [zMin,zMax[
274
16560e8e 275 AliVVertex* SPDVertex = AliAnalysisMuonUtility::GetVertexSPD(static_cast<const AliVEvent*>(&event));
5376e016
CP
276
277 if ( !SPDVertex )
278 {
279 AliError("Cut on SPD z Vertex requested for an event with no SPD vertex info");
280 return kFALSE;
281 }
282 Double_t zV = SPDVertex->GetZ();
283
284 if ( zV >= zMin && zV < zMax ) return kTRUE;
285 else return kFALSE;
286}
287
288
289//_____________________________________________________________________________
290Bool_t AliAnalysisMuMuEventCutter::HasSPDVertex(AliVEvent& event) const
291{
292 /// Does the event have a SPD vertex ?
16560e8e 293 AliVVertex* SPDVertex = AliAnalysisMuonUtility::GetVertexSPD(static_cast<const AliVEvent*>(&event));
5376e016
CP
294 if ( SPDVertex && SPDVertex->GetNContributors() > 0) return kTRUE;
295 else return kFALSE;
296}
297
298
299//_____________________________________________________________________________
300Bool_t AliAnalysisMuMuEventCutter::IsSPDzQA(const AliVEvent& event, /*const AliVVertex& vertex2Test,*/ const Double_t& zResCut, const Double_t& zDifCut) const
301{
302 // Checks if the value of the Z component of the given vertex fullfills the quality assurance condition
16560e8e 303 Double_t zRes,zvertex;
5376e016
CP
304
305 const AliVVertex* vertex = event.GetPrimaryVertex();
5376e016 306
16560e8e 307 if ( vertex )
308 {
309 AliVVertex* SPDVertex = AliAnalysisMuonUtility::GetVertexSPD(static_cast<const AliVEvent*>(&event));
310 if ( SPDVertex )
311 {
312 if ( SPDVertex->GetNContributors() > 0 )
313 {
314 Double_t cov[6]={0};
315 SPDVertex->GetCovarianceMatrix(cov);
316 zRes = TMath::Sqrt(cov[5]);
317 zvertex = SPDVertex->GetZ();
318 }
319 else return kFALSE;
320 }
321 else
322 {
323 AliError("Cut on SPD z Vertex requested for an event with no SPD vertex info");
324 return kFALSE;
325 }
326 }
327 else
328 {
329 AliError("Cut on SPD z Vertex requested for an event with no vertex info");
330 return kFALSE;
331 }
5376e016 332
16560e8e 333 if ( (zRes < zResCut) && TMath::Abs(zvertex - vertex->GetZ()) <= zDifCut )
5376e016
CP
334 {
335 return kTRUE;
336 }
337 else return kFALSE;
338}
339
340
341//_____________________________________________________________________________
342Bool_t AliAnalysisMuMuEventCutter::IsMeandNchdEtaInRange(AliVEvent& event, const Double_t& dNchdEtaMin, const Double_t& dNchdEtaMax) const
343{
344 TList* nchList = static_cast<TList*>(event.FindListObject("NCH"));
345
346 if (!nchList || nchList->IsEmpty())
347 {
348 AliFatal("No NCH information found in event. Nch analysis MUST be executed to apply a NCH cut");
349 return kFALSE;
350 }
351
352 Int_t i(0);
16560e8e 353 Bool_t parFound(kFALSE);
354 TParameter<Double_t>* eventdNchdEta;
5376e016 355
16560e8e 356 while ( !parFound )
5376e016 357 {
16560e8e 358 while ( nchList->At(i)->IsA() != TParameter<Double_t>::Class() )
359 {
360 i++;
361 }
362
363 eventdNchdEta = static_cast<TParameter<Double_t>*>(nchList->At(i));
364
365 if ( TString(eventdNchdEta->GetName()).Contains("MeandNchdEta") ) parFound = kTRUE;
5376e016
CP
366 }
367
16560e8e 368 Double_t meandNchdEta = eventdNchdEta->GetVal();
5376e016
CP
369
370 if ( meandNchdEta >= dNchdEtaMin && meandNchdEta < dNchdEtaMax ) return kTRUE;
371 else return kFALSE;
372}
373
5376e016
CP
374//_____________________________________________________________________________
375AliMuonEventCuts*
376AliAnalysisMuMuEventCutter::MuonEventCuts() const
377{
378 /// Return the single instance of AliMuonEventCuts object we're using
379
380 if (!fMuonEventCuts)
381 {
382 fMuonEventCuts = new AliMuonEventCuts("EventCut","");
383 }
384 return fMuonEventCuts;
385}
386
387
388//_____________________________________________________________________________
389void AliAnalysisMuMuEventCutter::NameOfIsSPDzVertexInRange(TString& name, const Double_t& zMin, const Double_t& zMax) const
390{
391 name.Form("SPDZBTW%3.2f_%3.2f",zMin,zMax);
392}
393//_____________________________________________________________________________
394void AliAnalysisMuMuEventCutter::NameOfIsAbsZBelowValue(TString& name, const Double_t& z) const
395{
396 name.Form("ABSZLT%3.2f",z);
397}
398
399//_____________________________________________________________________________
400void AliAnalysisMuMuEventCutter::NameOfIsAbsZSPDBelowValue(TString& name, const Double_t& z) const
401{
402 name.Form("SPDABSZLT%3.2f",z);
403}
404
405
406//_____________________________________________________________________________
407void AliAnalysisMuMuEventCutter::NameOfIsSPDzQA(TString& name, const Double_t& zResCut, const Double_t& zDifCut) const
408{
409 name.Form("SPDZQA_RES%3.2f_ZDIF%3.2f",zResCut,zDifCut);
410}
411
412//_____________________________________________________________________________
413void AliAnalysisMuMuEventCutter::NameOfIsMeandNchdEtaInRange(TString& name, const Double_t& dNchdEtaMin, const Double_t& dNchdEtaMax) const
414{
415 name.Form("MEANDNDETABTW%3.2f_%3.2f",dNchdEtaMin,dNchdEtaMax);
416}
417
418
419//_____________________________________________________________________________
420Bool_t AliAnalysisMuMuEventCutter::IsTZEROPileUp(const AliVEvent& event) const
421{
422 Bool_t pileupFlag(kFALSE);
423
424 if ( event.IsA() == AliESDEvent::Class() )
425 {
426 const AliESDTZERO* tzero = static_cast<AliESDEvent&>(const_cast<AliVEvent&>(event)).GetESDTZERO();
427 if ( tzero )
428 {
429 pileupFlag = tzero->GetPileupFlag();
430 }
431 }
432 else if ( event.IsA() == AliAODEvent::Class() )
433 {
434 AliAODTZERO* tzero = static_cast<const AliAODEvent&>(event).GetTZEROData();
435 if ( tzero )
436 {
437 pileupFlag = tzero->GetPileupFlag();
438 }
439 }
440 return pileupFlag;
441}