]> git.uio.no Git - u/mrichter/AliRoot.git/blob - FMD/analysis/AliFMDAnaParameters.cxx
Adding calibration object for the sharing efficiency
[u/mrichter/AliRoot.git] / FMD / analysis / AliFMDAnaParameters.cxx
1 /**************************************************************************
2  * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
3  *                                                                        *
4  * Author: The ALICE Off-line Project.                                    *
5  * Contributors are mentioned in the code where appropriate.              *
6  *                                                                        *
7  * Permission to use, copy, modify and distribute this software and its   *
8  * documentation strictly for non-commercial purposes is hereby granted   *
9  * without fee, provided that the above copyright notice appears in all   *
10  * copies and that both the copyright notice and this permission notice   *
11  * appear in the supporting documentation. The authors make no claims     *
12  * about the suitability of this software for any purpose. It is          *
13  * provided "as is" without express or implied warranty.                  *
14  **************************************************************************/
15 //
16 //The design of this class is based on the AliFMDParameters class. Its purpose
17 //is to hold parameters for the analysis such as background correction and 
18 //fit functions.
19 //
20 //Author: Hans Hjersing Dalsgaard, NBI, hans.dalsgaard@cern.ch
21 //
22
23 #include "AliFMDDebug.h"                   // ALILOG_H
24 #include "AliFMDAnaParameters.h"           // ALIFMDPARAMETERS_H
25 //#include <AliCDBManager.h>         // ALICDBMANAGER_H
26 //#include <AliCDBEntry.h>           // ALICDBMANAGER_H
27 //#include "AliFMDRing.h"
28 #include <AliLog.h>
29 #include <Riostream.h>
30 #include <sstream>
31 #include <TSystem.h>
32 #include <TH2D.h>
33 #include <TF1.h>
34 #include <TMath.h>
35 #include "AliESDEvent.h"
36 #include "AliESDVertex.h"
37
38 //====================================================================
39 ClassImp(AliFMDAnaParameters)
40 #if 0
41   ; // This is here to keep Emacs for indenting the next line
42 #endif
43
44 //const char* AliFMDAnaParameters::fgkBackgroundCorrection  = "FMD/Correction/Background";
45 //const char* AliFMDAnaParameters::fgkEnergyDists = "FMD/Correction/EnergyDistribution";
46 const char* AliFMDAnaParameters::fgkBackgroundID         = "background";
47 const char* AliFMDAnaParameters::fgkEnergyDistributionID = "energydistributions";
48 const char* AliFMDAnaParameters::fgkEventSelectionEffID  = "eventselectionefficiency";
49 const char* AliFMDAnaParameters::fgkSharingEffID         = "sharingefficiency";
50 //____________________________________________________________________
51 AliFMDAnaParameters* AliFMDAnaParameters::fgInstance = 0;
52
53 //____________________________________________________________________
54
55 AliFMDAnaParameters* 
56 AliFMDAnaParameters::Instance() 
57 {
58   // Get static instance 
59   if (!fgInstance) fgInstance = new AliFMDAnaParameters;
60   return fgInstance;
61 }
62
63 //____________________________________________________________________
64 AliFMDAnaParameters::AliFMDAnaParameters() :
65   fIsInit(kFALSE),
66   fBackground(0),
67   fEnergyDistribution(0),
68   fEventSelectionEfficiency(0),
69   fCorner1(4.2231, 26.6638),
70   fCorner2(1.8357, 27.9500),
71   fEnergyPath("$ALICE_ROOT/FMD/Correction/EnergyDistribution"),
72   fBackgroundPath("$ALICE_ROOT/FMD/Correction/Background"),
73   fEventSelectionEffPath("$ALICE_ROOT/FMD/Correction/EventSelectionEfficiency"),
74   fSharingEffPath("$ALICE_ROOT/FMD/Correction/SharingEfficiency"),
75   fProcessPrimary(kFALSE),
76   fProcessHits(kFALSE),
77   fTrigger(kMB1),
78   fEnergy(k10000),
79   fMagField(k5G),
80   fSpecies(kPP)
81 {
82   
83   
84   //fVerticies.Add(new TVector2(4.2231, 26.6638));
85   // fVerticies.Add(new TVector2(1.8357, 27.9500));
86   // Default constructor 
87 }
88 //____________________________________________________________________
89 char* AliFMDAnaParameters::GetPath(const char* species) {
90   
91   char* path ;
92   
93   if(species == fgkBackgroundID)
94     path = Form("%s/%s_%d_%d_%d_%d_%d_%d.root",
95                 fBackgroundPath.Data(),
96                 fgkBackgroundID,
97                 fEnergy,
98                 fTrigger,
99                 fMagField,
100                 fSpecies,
101                 0,
102                 0);
103   if(species == fgkEnergyDistributionID)
104     path = Form("%s/%s_%d_%d_%d_%d_%d_%d.root",
105                 fEnergyPath.Data(),
106                 fgkEnergyDistributionID,
107                 fEnergy,
108                 fTrigger,
109                 fMagField,
110                 fSpecies,
111                 0,
112                 0);
113   if(species == fgkEventSelectionEffID)
114     path = Form("%s/%s_%d_%d_%d_%d_%d_%d.root",
115                 fEventSelectionEffPath.Data(),
116                 fgkEventSelectionEffID,
117                 fEnergy,
118                 fTrigger,
119                 fMagField,
120                 fSpecies,
121                 0,
122                 0);
123   if(species == fgkSharingEffID)
124     path = Form("%s/%s_%d_%d_%d_%d_%d_%d.root",
125                 fSharingEffPath.Data(),
126                 fgkSharingEffID,
127                 fEnergy,
128                 fTrigger,
129                 fMagField,
130                 fSpecies,
131                 0,
132                 0);
133
134   return path;
135 }
136 //____________________________________________________________________
137 void AliFMDAnaParameters::Init(Bool_t forceReInit, UInt_t what)
138 {
139   // Initialize the parameters manager.  We need to get stuff from the
140   // CDB here. 
141   if (forceReInit) fIsInit = kFALSE;
142   if (fIsInit) return;
143   if (what & kBackgroundCorrection)       InitBackground();
144   if (what & kEnergyDistributions)        InitEnergyDists();
145   if (what & kEventSelectionEfficiency)   InitEventSelectionEff();
146   if (what & kSharingEfficiency)          InitSharingEff();
147
148   fIsInit = kTRUE;
149 }
150 //____________________________________________________________________
151
152 void AliFMDAnaParameters::InitBackground() {
153   
154   //AliCDBEntry*   background = GetEntry(fgkBackgroundCorrection);
155   
156   TFile* fin = TFile::Open(GetPath(fgkBackgroundID));
157   
158   if (!fin) return;
159   
160   fBackground = dynamic_cast<AliFMDAnaCalibBackgroundCorrection*>(fin->Get(fgkBackgroundID));
161   if (!fBackground) AliFatal("Invalid background object from CDB");
162   
163 }
164
165 //____________________________________________________________________
166
167 void AliFMDAnaParameters::InitEnergyDists() {
168   
169   TFile* fin = TFile::Open(GetPath(fgkEnergyDistributionID));
170   //AliCDBEntry*   edist = GetEntry(fgkEnergyDists);
171   if (!fin) return;
172   
173   fEnergyDistribution = dynamic_cast<AliFMDAnaCalibEnergyDistribution*>(fin->Get(fgkEnergyDistributionID));
174   
175   if (!fEnergyDistribution) AliFatal("Invalid background object from CDB");
176   
177 }
178
179 //____________________________________________________________________
180
181 void AliFMDAnaParameters::InitEventSelectionEff() {
182   
183   //AliCDBEntry*   background = GetEntry(fgkBackgroundCorrection);
184   TFile* fin = TFile::Open(GetPath(fgkEventSelectionEffID));
185                             
186   if (!fin) return;
187   
188   fEventSelectionEfficiency = dynamic_cast<AliFMDAnaCalibEventSelectionEfficiency*>(fin->Get(fgkEventSelectionEffID));
189   if (!fEventSelectionEfficiency) AliFatal("Invalid background object from CDB");
190   
191 }
192 //____________________________________________________________________
193
194 void AliFMDAnaParameters::InitSharingEff() {
195   
196   //AliCDBEntry*   background = GetEntry(fgkBackgroundCorrection);
197   TFile* fin = TFile::Open(GetPath(fgkSharingEffID));
198                             
199   if (!fin) return;
200   
201   fSharingEfficiency = dynamic_cast<AliFMDAnaCalibSharingEfficiency*>(fin->Get(fgkSharingEffID));
202   if (!fSharingEfficiency) AliFatal("Invalid background object from CDB");
203   
204 }
205 //____________________________________________________________________
206 Float_t AliFMDAnaParameters::GetVtxCutZ() {
207   
208   if(!fIsInit) {
209     AliWarning("Not initialized yet. Call Init() to remedy");
210     return -1;
211   }
212   
213   return fBackground->GetVtxCutZ();
214 }
215
216 //____________________________________________________________________
217 Int_t AliFMDAnaParameters::GetNvtxBins() {
218   
219   if(!fIsInit) {
220     AliWarning("Not initialized yet. Call Init() to remedy");
221     return -1;
222   }
223   
224   return fBackground->GetNvtxBins();
225 }
226 //____________________________________________________________________
227 TH1F* AliFMDAnaParameters::GetEnergyDistribution(Int_t det, Char_t ring, Float_t eta) {
228   
229   return fEnergyDistribution->GetEnergyDistribution(det, ring, eta);
230 }
231 //____________________________________________________________________
232 Float_t AliFMDAnaParameters::GetSigma(Int_t det, Char_t ring, Float_t eta) {
233   
234   if(!fIsInit) {
235     AliWarning("Not initialized yet. Call Init() to remedy");
236     return 0;
237   }
238   
239   TH1F* hEnergyDist       = GetEnergyDistribution(det,ring, eta);
240   TF1*  fitFunc           = hEnergyDist->GetFunction("FMDfitFunc");
241   if(!fitFunc) {
242     AliWarning(Form("No function for FMD%d%c, eta %f",det,ring,eta));
243     return 1024;
244   }
245   Float_t sigma           = fitFunc->GetParameter(2);
246   return sigma;
247 }
248
249
250 //____________________________________________________________________
251 Float_t AliFMDAnaParameters::GetMPV(Int_t det, Char_t ring, Float_t eta) {
252   
253   if(!fIsInit) {
254     AliWarning("Not initialized yet. Call Init() to remedy");
255     return 0;
256   }
257   
258   TH1F* hEnergyDist     = GetEnergyDistribution(det,ring,eta);
259   TF1*  fitFunc         = hEnergyDist->GetFunction("FMDfitFunc");
260   if(!fitFunc) {
261     AliWarning(Form("No function for FMD%d%c, eta %f",det,ring,eta));
262     return 1024;
263   }
264     
265   Float_t mpv           = fitFunc->GetParameter(1);
266   return mpv;
267 }
268 //____________________________________________________________________
269 Float_t AliFMDAnaParameters::Get2MIPWeight(Int_t det, Char_t ring, Float_t eta) {
270   
271   if(!fIsInit) {
272     AliWarning("Not initialized yet. Call Init() to remedy");
273     return 0;
274   }
275   
276   TH1F* hEnergyDist     = GetEnergyDistribution(det,ring,eta);
277   TF1*  fitFunc         = hEnergyDist->GetFunction("FMDfitFunc");
278   if(!fitFunc) return 0;
279   Float_t twoMIPweight    = fitFunc->GetParameter(3);
280   
281   
282   
283   if(twoMIPweight < 1e-05)
284     twoMIPweight = 0;
285   
286   return twoMIPweight;
287 }
288 //____________________________________________________________________
289 Float_t AliFMDAnaParameters::Get3MIPWeight(Int_t det, Char_t ring, Float_t eta) {
290   
291   if(!fIsInit) {
292     AliWarning("Not initialized yet. Call Init() to remedy");
293     return 0;
294   }
295   
296   TH1F* hEnergyDist     = GetEnergyDistribution(det,ring,eta);
297   TF1*  fitFunc         = hEnergyDist->GetFunction("FMDfitFunc");
298   if(!fitFunc) return 0;
299   Float_t threeMIPweight    = fitFunc->GetParameter(4);
300   
301   if(threeMIPweight < 1e-05)
302     threeMIPweight = 0;
303   
304   Float_t twoMIPweight    = fitFunc->GetParameter(3);
305   
306   if(twoMIPweight < 1e-05)
307     threeMIPweight = 0;
308     
309   return threeMIPweight;
310 }
311 //____________________________________________________________________
312 Int_t AliFMDAnaParameters::GetNetaBins() {
313   return GetBackgroundCorrection(1,'I',0)->GetNbinsX();
314   
315 }
316 //____________________________________________________________________
317 Float_t AliFMDAnaParameters::GetEtaMin() {
318
319   return GetBackgroundCorrection(1,'I',0)->GetXaxis()->GetXmin();
320
321 //____________________________________________________________________
322 Float_t AliFMDAnaParameters::GetEtaMax() {
323
324 return GetBackgroundCorrection(1,'I',0)->GetXaxis()->GetXmax();
325
326 }
327 //____________________________________________________________________
328
329 TH2F* AliFMDAnaParameters::GetBackgroundCorrection(Int_t det, 
330                                                    Char_t ring, 
331                                                    Int_t vtxbin) {
332   
333   if(!fIsInit) {
334     AliWarning("Not initialized yet. Call Init() to remedy");
335     return 0;
336   }
337   
338   
339   
340   if(vtxbin > fBackground->GetNvtxBins()) {
341     AliWarning(Form("No background object for vertex bin %d", vtxbin));
342     return 0;
343   } 
344   
345   return fBackground->GetBgCorrection(det,ring,vtxbin);
346 }
347 //____________________________________________________________________
348
349 TH1F* AliFMDAnaParameters::GetDoubleHitCorrection(Int_t det, 
350                                                   Char_t ring) {
351   
352   if(!fIsInit) {
353     AliWarning("Not initialized yet. Call Init() to remedy");
354     return 0;
355   }
356   
357   return fBackground->GetDoubleHitCorrection(det,ring);
358 }
359 //_____________________________________________________________________
360 Float_t AliFMDAnaParameters::GetEventSelectionEfficiency(Int_t vtxbin) {
361   if(!fIsInit) {
362     AliWarning("Not initialized yet. Call Init() to remedy");
363     return 0;
364   }
365   return fEventSelectionEfficiency->GetCorrection(vtxbin);
366
367 }
368 //_____________________________________________________________________
369 TH1F* AliFMDAnaParameters::GetSharingEfficiency(Int_t det, Char_t ring, Int_t vtxbin) {
370   if(!fIsInit) {
371     AliWarning("Not initialized yet. Call Init() to remedy");
372     return 0;
373   }
374   
375   return fSharingEfficiency->GetSharingEff(det,ring,vtxbin);
376
377 }
378 //_____________________________________________________________________
379 Float_t AliFMDAnaParameters::GetMaxR(Char_t ring) const{
380   Float_t radius = 0;
381   if(ring == 'I')
382     radius = 17.2;
383   else if(ring == 'O')
384     radius = 28.0;
385   else
386     AliWarning("Unknown ring - must be I or O!");
387   
388   return radius;
389 }
390 //_____________________________________________________________________
391 Float_t AliFMDAnaParameters::GetMinR(Char_t ring) const{
392   Float_t radius = 0;
393   if(ring == 'I')
394     radius = 4.5213;
395   else if(ring == 'O')
396     radius = 15.4;
397   else
398     AliWarning("Unknown ring - must be I or O!");
399   
400   return radius;
401
402 }
403 //_____________________________________________________________________
404 void AliFMDAnaParameters::SetCorners(Char_t ring) {
405   
406   if(ring == 'I') {
407     fCorner1.Set(4.9895, 15.3560);
408     fCorner2.Set(1.8007, 17.2000);
409   }
410   else {
411     fCorner1.Set(4.2231, 26.6638);
412     fCorner2.Set(1.8357, 27.9500);
413   }
414   
415 }
416 //_____________________________________________________________________
417 Float_t AliFMDAnaParameters::GetPhiFromSector(UShort_t det, Char_t ring, UShort_t sec) const
418 {
419   Int_t nsec = (ring == 'I' ? 20 : 40);
420   Float_t basephi = 0;
421   if(det == 1) 
422     basephi = 1.72787594; 
423   if(det == 2 && ring == 'I')
424     basephi = 0.15707963;
425   if(det == 2 && ring == 'O')
426     basephi = 0.078539818;
427   if(det == 3 && ring == 'I')
428     basephi = 2.984513044;
429   if(det == 3 && ring == 'O')
430     basephi = 3.06305289;
431   
432   Float_t step = 2*TMath::Pi() / nsec;
433   Float_t phi = 0;
434   if(det == 3)
435     phi = basephi - sec*step;
436   else
437     phi = basephi + sec*step;
438   
439   if(phi < 0) 
440     phi = phi +2*TMath::Pi();
441   if(phi > 2*TMath::Pi() )
442     phi = phi - 2*TMath::Pi();
443   
444   return phi;
445 }
446 //_____________________________________________________________________
447 Float_t AliFMDAnaParameters::GetEtaFromStrip(UShort_t det, Char_t ring, UShort_t sec, UShort_t strip, Float_t zvtx) const
448 {
449   // AliFMDRing fmdring(ring);
450   // fmdring.Init();
451   Float_t   rad       = GetMaxR(ring)-GetMinR(ring);
452   Float_t   nStrips   = (ring == 'I' ? 512 : 256);
453   Float_t   segment   = rad / nStrips;
454   Float_t   r         = GetMinR(ring) + segment*strip;
455   Float_t   z         = 0;
456   Int_t hybrid = sec / 2;
457   
458   if(det == 1) {
459     if(!(hybrid%2)) z = 320.266; else z = 319.766;
460   }
461   if(det == 2 && ring == 'I' ) {
462     if(!(hybrid%2)) z = 83.666; else z = 83.166;
463   }
464   if(det == 2 && ring == 'O' ) {
465     if(!(hybrid%2)) z = 74.966; else z = 75.466;
466   }
467   if(det == 3 && ring == 'I' ) {
468     if(!(hybrid%2)) z = -63.066; else z = -62.566;
469   }
470   if(det == 3 && ring == 'O' ) {
471     if(!(hybrid%2)) z = -74.966; else z = -75.466;
472   }
473   
474   //std::cout<<det<<"   "<<ring<<"   "<<sec<<"   "<<hybrid<<"    "<<z<<std::endl;
475   
476   // Float_t   r     = TMath::Sqrt(TMath::Power(x,2)+TMath::Power(y,2));
477   Float_t   theta = TMath::ATan2(r,z-zvtx);
478   Float_t   eta   = -1*TMath::Log(TMath::Tan(0.5*theta));
479   
480   return eta;
481 }
482
483 //_____________________________________________________________________
484
485 void AliFMDAnaParameters::GetVertex(AliESDEvent* esd, Double_t* vertexXYZ) 
486 {
487   const AliESDVertex* vertex = 0;
488   vertex = esd->GetPrimaryVertex();
489   if(!vertex || (vertexXYZ[0] == 0 && vertexXYZ[1] == 0 && vertexXYZ[2] == 0))        
490     vertex = esd->GetPrimaryVertexSPD();
491   if(!vertex || (vertexXYZ[0] == 0 && vertexXYZ[1] == 0 && vertexXYZ[2] == 0))        
492     vertex = esd->GetPrimaryVertexTPC();
493   if(!vertex || (vertexXYZ[0] == 0 && vertexXYZ[1] == 0 && vertexXYZ[2] == 0))    
494     vertex = esd->GetVertex();
495   if (vertex && (vertexXYZ[0] != 0 || vertexXYZ[1] != 0 || vertexXYZ[2] != 0)) {
496     vertex->GetXYZ(vertexXYZ);
497     //std::cout<<vertex->GetName()<<"   "<< vertex->GetTitle() <<"   "<< vertex->GetZv()<<std::endl;
498     return;
499   }
500   else if (esd->GetESDTZERO()) { 
501     vertexXYZ[0] = 0;
502     vertexXYZ[1] = 0;
503     vertexXYZ[2] = esd->GetT0zVertex();
504     
505     return;
506   }
507   
508   return;
509   
510 }
511
512 //____________________________________________________________________
513 Bool_t AliFMDAnaParameters::IsEventTriggered(AliESDEvent *esd) {
514   // check if the event was triggered
515   ULong64_t triggerMask = esd->GetTriggerMask();
516   
517   // definitions from p-p.cfg
518   ULong64_t spdFO = (1 << 14);
519   ULong64_t v0left = (1 << 11);
520   ULong64_t v0right = (1 << 12);
521   
522   switch (fTrigger) {
523   case kMB1: {
524     if (triggerMask & spdFO || ((triggerMask & v0left) || (triggerMask & v0right)))
525       return kTRUE;
526     break;
527   }
528   case kMB2: {
529     if (triggerMask & spdFO && ((triggerMask & v0left) || (triggerMask & v0right)))
530       return kTRUE;
531     break;
532   }
533   case kSPDFASTOR: {
534     if (triggerMask & spdFO)
535       return kTRUE;
536     break;
537   }
538   case kTEST_NOCTP: {
539     return kTRUE;
540     break;
541   }
542   }//switch
543
544   return kFALSE;
545 }
546
547 //____________________________________________________________________
548 Float_t 
549 AliFMDAnaParameters::GetStripLength(Char_t ring, UShort_t strip)  
550 {
551   //AliFMDRing fmdring(ring);
552   // fmdring.Init();
553   
554   Float_t rad        = GetMaxR(ring)-GetMinR(ring);
555   Float_t   nStrips   = (ring == 'I' ? 512 : 256);
556   Float_t segment    = rad / nStrips;
557   
558   //TVector2* corner1  = fmdring.GetVertex(2);  
559   // TVector2* corner2  = fmdring.GetVertex(3);
560   
561   SetCorners(ring);
562   /*
563   std::cout<<GetMaxR(ring)<<"   "<<fmdring.GetMaxR()<<std::endl;
564   std::cout<<GetMinR(ring)<<"   "<<fmdring.GetMinR()<<std::endl;
565   std::cout<<corner1->X()<<"   "<<fCorner1.X()<<std::endl;
566   std::cout<<corner2->X()<<"   "<<fCorner2.X()<<std::endl;
567   std::cout<<corner1->Y()<<"   "<<fCorner1.Y()<<std::endl;
568   std::cout<<corner2->Y()<<"   "<<fCorner2.Y()<<std::endl;*/
569   Float_t slope      = (fCorner1.Y() - fCorner2.Y()) / (fCorner1.X() - fCorner2.X());
570   Float_t constant   = (fCorner2.Y()*fCorner1.X()-(fCorner2.X()*fCorner1.Y())) / (fCorner1.X() - fCorner2.X());
571   Float_t radius     = GetMinR(ring) + strip*segment;
572   
573   Float_t d          = TMath::Power(TMath::Abs(radius*slope),2) + TMath::Power(radius,2) - TMath::Power(constant,2);
574   
575   Float_t arclength  = GetBaseStripLength(ring,strip);
576   if(d>0) {
577     
578     Float_t x        = (-1*TMath::Sqrt(d) -slope*constant) / (1+TMath::Power(slope,2));
579     Float_t y        = slope*x + constant;
580     Float_t theta    = TMath::ATan2(x,y);
581     
582     if(x < fCorner1.X() && y > fCorner1.Y()) {
583       arclength = radius*theta;                        //One sector since theta is by definition half-hybrid
584       
585     }
586     
587   }
588   
589   return arclength;
590   
591   
592 }
593 //____________________________________________________________________
594 Float_t 
595 AliFMDAnaParameters::GetBaseStripLength(Char_t ring, UShort_t strip)  
596 {  
597   // AliFMDRing fmdring(ring);
598   // fmdring.Init();
599   Float_t rad             = GetMaxR(ring)-GetMinR(ring);
600   Float_t nStrips         = (ring == 'I' ? 512 : 256);
601   Float_t nSec            = (ring == 'I' ? 20 : 40);
602   Float_t segment         = rad / nStrips;
603   Float_t basearc         = 2*TMath::Pi() / (0.5*nSec); // One hybrid: 36 degrees inner, 18 outer
604   Float_t radius          = GetMinR(ring) + strip*segment;
605   Float_t basearclength   = 0.5*basearc * radius;                // One sector   
606   
607   return basearclength;
608 }
609 //____________________________________________________________________
610 //
611 // EOF
612 //