LCOV - code coverage report
Current view: top level - TPC/TPCcalib - AliTPCcalibTimeGain.cxx (source / functions) Hit Total Coverage
Test: coverage.info Lines: 1 403 0.2 %
Date: 2016-06-14 17:26:59 Functions: 1 20 5.0 %

          Line data    Source code
       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             : /*
      17             : 
      18             : This class provides the calibration of the time dependence of the TPC gain due to pressure and temperature changes etc.
      19             : 
      20             : 
      21             : //0.  Libraries to load
      22             : gSystem->Load("libANALYSIS");
      23             : gSystem->Load("libSTAT");
      24             : gSystem->Load("libTPCcalib");
      25             : 
      26             : 
      27             : //1. Do calibration ...
      28             : //
      29             : // compare reference
      30             : 
      31             : //
      32             : //2. Visualize results
      33             : //
      34             : TFile fcalib("CalibObjects.root");
      35             : TObjArray * array = (TObjArray*)fcalib.Get("TPCCalib");
      36             : AliTPCcalibTimeGain * gain = ( AliTPCcalibTimeGain *)array->FindObject("calibTimeGain");
      37             : TGraphErrors * gr = gain->GetGraphGainVsTime(0,1000)
      38             : 
      39             : // gain->GetHistGainTime()->GetAxis(1)->SetRangeUser(1213.8e6,1214.3e6)
      40             : TH2D * GainTime = gain->GetHistGainTime()->Projection(0,1)
      41             : GainTime->GetXaxis()->SetTimeDisplay(kTRUE)
      42             : GainTime->GetXaxis()->SetTimeFormat("#splitline{%d/%m}{%H:%M}")
      43             : GainTime->Draw("colz")
      44             : 
      45             : //
      46             : // MakeSlineFit example
      47             : //
      48             : AliSplineFit *fit = AliTPCcalibTimeGain::MakeSplineFit(gr)
      49             : 
      50             : TGraph * grfit = fit.MakeGraph(gr->GetX()[0],gr->GetX()[gr->GetN()-1],50000,0);
      51             : 
      52             : gr->SetMarkerStyle(25);
      53             : gr->Draw("lp");
      54             : grfit->SetLineColor(2);
      55             : grfit->Draw("lu");
      56             : 
      57             : //
      58             : // QA - dE/dx resoultion as a function of time
      59             : //TCa
      60             : 
      61             : TGraph * grSigma = AliTPCcalibBase::FitSlicesSigma(gain->GetHistGainTime(),0,1,1800,5)
      62             : 
      63             : TCanvas *c1 = new TCanvas("c1","transparent pad",200,10,700,500);
      64             :    TPad *pad1 = new TPad("pad1","",0,0,1,1);
      65             :    TPad *pad2 = new TPad("pad2","",0,0,1,1);
      66             :    pad2->SetFillStyle(4000); //will be transparent
      67             :    pad1->Draw();
      68             :    pad1->cd();
      69             : 
      70             : GainTime->Draw("colz")
      71             : gr->Draw("lp")
      72             : 
      73             : 
      74             : 
      75             :   c1->cd();
      76             :  Double_t ymin = -0.04;
      77             :  Double_t ymax = 0.12;
      78             : Double_t dy = (ymax-ymin)/0.8;
      79             : Double_t xmin = GainTime->GetXaxis()->GetXmin()
      80             : Double_t xmax = GainTime->GetXaxis()->GetXmax()
      81             : Double_t dx = (xmax-xmin)/0.8; //10 per cent margins left and right
      82             : pad2->Range(xmin-0.1*dx,ymin-0.1*dy,xmax+0.1*dx,ymax+0.1*dy);
      83             :    pad2->Draw();
      84             :    pad2->cd();
      85             : grSigma->SetLineColor(2);
      86             : grSigma->SetLineWidth(2);
      87             : grSigma->Draw("lp")
      88             : TGaxis *axis = new TGaxis(xmax,ymin,xmax,ymax,ymin,ymax,50510,"+L");
      89             :    axis->SetLabelColor(kRed);
      90             :    axis->SetTitle("dE/dx resolution #sigma_{dE/dx}");
      91             :    axis->Draw();
      92             : 
      93             : ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
      94             : 
      95             :  ----> make Attachment study
      96             : 
      97             : TFile fcalib("CalibObjects40366b.root");
      98             : TObjArray * array = (TObjArray*)fcalib.Get("TPCCalib");
      99             : AliTPCcalibTimeGain * gain = ( AliTPCcalibTimeGain *)array->FindObject("calibTimeGain");
     100             : TGraphErrors * grAttach = gain->GetGraphAttachment(2000,4)
     101             : 
     102             : TCanvas *c1 = new TCanvas("c1","transparent pad",200,10,700,500);
     103             :    TPad *pad1 = new TPad("pad1","",0,0,1,1);
     104             :    TPad *pad2 = new TPad("pad2","",0,0,1,1);
     105             :    pad2->SetFillStyle(4000); //will be transparent
     106             :    pad1->Draw();
     107             :    pad1->cd();
     108             : 
     109             : gain->GetHistGainTime()->GetAxis(1)->SetRangeUser(1213.8e6,1214.3e6)
     110             : TH2D * GainTime = gain->GetHistGainTime()->Projection(0,1)
     111             : GainTime->GetXaxis()->SetTimeDisplay(kTRUE)
     112             : GainTime->GetXaxis()->SetTimeFormat("#splitline{%d/%m}{%H:%M}")
     113             : GainTime->Draw("colz")
     114             : //gr->Draw("lp")
     115             : 
     116             :   c1->cd();
     117             :  Double_t ymin = -0.001;
     118             :  Double_t ymax = 0.001;
     119             : Double_t dy = (ymax-ymin)/0.8;
     120             : Double_t xmin = GainTime->GetXaxis()->GetXmin()
     121             : Double_t xmax = GainTime->GetXaxis()->GetXmax()
     122             : Double_t dx = (xmax-xmin)/0.8; //10 per cent margins left and right
     123             : pad2->Range(xmin-0.1*dx,ymin-0.1*dy,xmax+0.1*dx,ymax+0.1*dy);
     124             :    pad2->Draw();
     125             :    pad2->cd();
     126             : grAttach->SetLineColor(2);
     127             : grAttach->SetLineWidth(2);
     128             : grAttach->Draw("lp")
     129             : TGaxis *axis = new TGaxis(xmax,ymin,xmax,ymax,ymin,ymax,50510,"+L");
     130             :    axis->SetLabelColor(kRed);
     131             :    axis->SetTitle("attachment coefficient b");
     132             :    axis->Draw();
     133             : 
     134             : 
     135             : */
     136             : 
     137             : 
     138             : #include "Riostream.h"
     139             : #include "TChain.h"
     140             : #include "TTree.h"
     141             : #include "TH1F.h"
     142             : #include "TH2F.h"
     143             : #include "TH3F.h"
     144             : #include "THnSparse.h"
     145             : #include "TGraphErrors.h"
     146             : #include "TList.h"
     147             : #include "TMath.h"
     148             : #include "TCanvas.h"
     149             : #include "TFile.h"
     150             : #include "TF1.h"
     151             : #include "TVectorD.h"
     152             : #include "TProfile.h"
     153             : #include "TGraphErrors.h"
     154             : #include "TCanvas.h"
     155             : 
     156             : #include "AliTPCclusterMI.h"
     157             : #include "AliTPCseed.h"
     158             : #include "AliTPCreco.h"
     159             : #include "AliESDVertex.h"
     160             : #include "AliESDEvent.h"
     161             : #include "AliESDfriend.h"
     162             : #include "AliESDInputHandler.h"
     163             : #include "AliAnalysisManager.h"
     164             : 
     165             : #include "AliTracker.h"
     166             : #include "AliMagF.h"
     167             : #include "AliTPCCalROC.h"
     168             : #include "AliESDv0.h"
     169             : 
     170             : #include "AliLog.h"
     171             : 
     172             : #include "AliTPCcalibTimeGain.h"
     173             : 
     174             : #include "TTreeStream.h"
     175             : #include "AliTPCTracklet.h"
     176             : #include "TTimeStamp.h"
     177             : #include "AliTPCcalibDB.h"
     178             : #include "AliTPCcalibLaser.h"
     179             : #include "AliDCSSensorArray.h"
     180             : #include "AliDCSSensor.h"
     181             : #include "AliTPCTransform.h"
     182             : 
     183           6 : ClassImp(AliTPCcalibTimeGain)
     184             : 
     185             : Double_t AliTPCcalibTimeGain::fgMergeEntriesCut=10000000.;
     186             : 
     187             : AliTPCcalibTimeGain::AliTPCcalibTimeGain() 
     188           0 :   :AliTPCcalibBase(), 
     189           0 :    fHistGainTime(0),
     190           0 :    fGainVsTime(0),
     191           0 :    fHistDeDxTotal(0),
     192           0 :    fIntegrationTimeDeDx(0),
     193           0 :    fMIP(0),
     194           0 :    fCutCrossRows(0),
     195           0 :    fCutEtaWindow(0),
     196           0 :    fCutRequireITSrefit(0),
     197           0 :    fCutMaxDcaXY(0),
     198           0 :    fCutMaxDcaZ(0),
     199           0 :    fMinMomentumMIP(0),
     200           0 :    fMaxMomentumMIP(0),
     201           0 :    fAlephParameters(),
     202           0 :    fUseMax(0),
     203           0 :    fLowerTrunc(0),
     204           0 :    fUpperTrunc(0),
     205           0 :    fUseShapeNorm(0),
     206           0 :    fUsePosNorm(0),
     207           0 :    fUsePadNorm(0),
     208           0 :    fUseCookAnalytical(0),
     209           0 :    fIsCosmic(0),
     210           0 :    fLowMemoryConsumption(0)
     211           0 : {  
     212             :   //
     213             :   // Default constructor
     214             :   //
     215           0 :   AliDebug(5,"Default Constructor");  
     216           0 : }
     217             : 
     218             : 
     219             : AliTPCcalibTimeGain::AliTPCcalibTimeGain(const Text_t *name, const Text_t *title, UInt_t StartTime, UInt_t EndTime, Int_t deltaIntegrationTimeGain)
     220           0 :   :AliTPCcalibBase(),
     221           0 :    fHistGainTime(0),
     222           0 :    fGainVsTime(0),
     223           0 :    fHistDeDxTotal(0),
     224           0 :    fIntegrationTimeDeDx(0),
     225           0 :    fMIP(0),
     226           0 :    fCutCrossRows(0),
     227           0 :    fCutEtaWindow(0),
     228           0 :    fCutRequireITSrefit(0),
     229           0 :    fCutMaxDcaXY(0),
     230           0 :    fCutMaxDcaZ(0),
     231           0 :    fMinMomentumMIP(0),
     232           0 :    fMaxMomentumMIP(0),
     233           0 :    fAlephParameters(),
     234           0 :    fUseMax(0),
     235           0 :    fLowerTrunc(0),
     236           0 :    fUpperTrunc(0),
     237           0 :    fUseShapeNorm(0),
     238           0 :    fUsePosNorm(0),
     239           0 :    fUsePadNorm(0),
     240           0 :    fUseCookAnalytical(0),
     241           0 :    fIsCosmic(0),
     242           0 :    fLowMemoryConsumption(0)
     243           0 : {
     244             :   //
     245             :   // No default constructor
     246             :   //
     247           0 :   SetName(name);
     248           0 :   SetTitle(title);
     249             :   
     250           0 :   AliDebug(5,"Non Default Constructor");
     251             :   
     252           0 :   fIntegrationTimeDeDx = deltaIntegrationTimeGain;
     253             :   
     254           0 :   Double_t deltaTime = EndTime - StartTime;
     255             :   
     256             :   
     257             :   // main histogram for time dependence: dE/dx, time, type (1-muon cosmic,2-pion beam data, 3&4 - proton points at higher dE/dx), meanDriftlength, momenta (only filled if enough space is available), run number, eta
     258           0 :   Int_t timeBins = TMath::Nint(deltaTime/deltaIntegrationTimeGain);
     259           0 :   Int_t binsGainTime[7]    = {150,  static_cast<Int_t>(timeBins),    4,  25, 200, 10000000, 20};
     260           0 :   Double_t xminGainTime[7] = {0.5, static_cast<Double_t>(StartTime),  0.5,   0, 0.1,    -0.5,  -1};
     261           0 :   Double_t xmaxGainTime[7] = {  8,   static_cast<Double_t>(EndTime),  4.5, 250,  50, 9999999.5, 1};
     262           0 :   fHistGainTime = new THnSparseF("HistGainTime","dEdx time dep.;dEdx,time,type,driftlength,momenta,run number, eta;dEdx",7,binsGainTime,xminGainTime,xmaxGainTime);
     263           0 :   BinLogX(fHistGainTime, 4);
     264             :   //
     265           0 :   fHistDeDxTotal = new TH2F("DeDx","dEdx; momentum p (GeV); TPC signal (a.u.)",250,0.01,100.,1000,0.,8);
     266           0 :   BinLogX(fHistDeDxTotal);
     267             :   
     268             :   
     269             :   // default track selection cuts
     270           0 :   fCutCrossRows = 80;
     271           0 :   fCutEtaWindow = 0.8;
     272           0 :   fCutRequireITSrefit = kFALSE;
     273           0 :   fCutMaxDcaXY = 3.5;
     274           0 :   fCutMaxDcaZ  = 25.;
     275             : 
     276             :   // default values for MIP window selection
     277           0 :   fMinMomentumMIP = 0.4;
     278           0 :   fMaxMomentumMIP = 0.6;
     279           0 :   fAlephParameters[0] = 0.07657; // the following parameters work for most of the periods and are therefore default
     280           0 :   fAlephParameters[1] = 10.6654; // but they can be overwritten in the train setup of cpass0
     281           0 :   fAlephParameters[2] = 2.51466e-14;
     282           0 :   fAlephParameters[3] = 2.05379;
     283           0 :   fAlephParameters[4] = 1.84288;
     284             : 
     285             :   // default values for dE/dx
     286           0 :   fMIP = 50.;
     287           0 :   fUseMax = kTRUE;
     288           0 :   fLowerTrunc = 0.02;
     289           0 :   fUpperTrunc = 0.6;
     290           0 :   fUseShapeNorm = kTRUE;
     291           0 :   fUsePosNorm = kFALSE;
     292           0 :   fUsePadNorm = kFALSE;
     293           0 :   fUseCookAnalytical = kFALSE;
     294             :   //
     295           0 :   fIsCosmic = kTRUE;
     296           0 :   fLowMemoryConsumption = kTRUE;
     297             :   //
     298             :   
     299           0 : }
     300             : 
     301             : 
     302             : 
     303           0 : AliTPCcalibTimeGain::~AliTPCcalibTimeGain(){
     304             :   //
     305             :   // Destructor
     306             :   //
     307           0 :   delete fHistGainTime;
     308           0 :   delete fGainVsTime;
     309           0 :   delete fHistDeDxTotal;
     310           0 : }
     311             : 
     312             : 
     313             : void AliTPCcalibTimeGain::Process(AliESDEvent *event) {
     314             :   //
     315             :   // main track loop
     316             :   //
     317           0 :   if (!event) {
     318           0 :     Printf("ERROR: ESD not available");
     319           0 :     return;
     320             :   }
     321           0 :   AliESDfriend *ESDfriend=static_cast<AliESDfriend*>(event->FindListObject("AliESDfriend"));
     322           0 :   if (!ESDfriend) {
     323           0 :    return;
     324             :   }
     325           0 :   if (ESDfriend->TestSkipBit()) return;
     326             : 
     327             :   // CookdEdxAnalytical requires the time stamp in AliTPCTransform to be set
     328           0 :   AliTPCTransform *transform = AliTPCcalibDB::Instance()->GetTransform() ;
     329           0 :   transform->SetCurrentRun(fRun);
     330           0 :   transform->SetCurrentTimeStamp((UInt_t)fTime);
     331             : 
     332           0 :   if (fIsCosmic) { // this should be removed at some point based on trigger mask !?
     333           0 :     ProcessCosmicEvent(event);
     334           0 :   } else {
     335           0 :     ProcessBeamEvent(event);
     336             :   }
     337             :   
     338             : 
     339             :   
     340             :   
     341           0 : }
     342             : 
     343             : 
     344             : void AliTPCcalibTimeGain::ProcessCosmicEvent(AliESDEvent *event) {
     345             :   //
     346             :   // Process in case of cosmic event
     347             :   //
     348           0 :   if (!event->FindListObject("AliESDfriend")) {
     349           0 :    Printf("ERROR: ESDfriend not available");
     350           0 :    return;
     351             :   }
     352             :   //
     353           0 :   UInt_t time = event->GetTimeStamp();
     354           0 :   Int_t nTracks = event->GetNumberOfTracks();
     355           0 :   Int_t runNumber = event->GetRunNumber();
     356             :   //
     357             :   // track loop
     358             :   //
     359           0 :   for (Int_t i=0;i<nTracks;++i) {
     360             : 
     361           0 :     AliESDtrack *track = event->GetTrack(i);
     362           0 :     if (!track) continue;
     363           0 :     AliESDfriendTrack *friendTrack = (AliESDfriendTrack*)track->GetFriendTrack();
     364           0 :     if (!friendTrack) continue;        
     365           0 :     const AliExternalTrackParam * trackIn = track->GetInnerParam();
     366           0 :     const AliExternalTrackParam * trackOut = friendTrack->GetTPCOut();
     367           0 :     if (!trackIn) continue;
     368           0 :     if (!trackOut) continue;
     369             : 
     370             :     // calculate necessary track parameters
     371           0 :     Double_t meanP = trackIn->GetP();
     372           0 :     Double_t meanDrift = 250 - 0.5*TMath::Abs(trackIn->GetZ() + trackOut->GetZ());
     373           0 :     Int_t nclsDeDx = track->GetTPCNcls();
     374             : 
     375             :     // exclude tracks which do not look like primaries or are simply too short or on wrong sectors
     376           0 :     if (nclsDeDx < 60) continue;     
     377           0 :     if (TMath::Abs(trackIn->GetTgl()) > 1) continue;
     378           0 :     if (TMath::Abs(trackIn->GetSnp()) > 0.6) continue;
     379             :     
     380             :     // Get seeds
     381             :     TObject *calibObject;
     382             :     AliTPCseed *seed = 0;
     383           0 :     for (Int_t l=0;(calibObject=friendTrack->GetCalibObject(l));++l) {
     384           0 :       if ((seed=dynamic_cast<AliTPCseed*>(calibObject))) break;
     385             :     }    
     386             : 
     387           0 :     if (seed) { 
     388           0 :       Double_t tpcSignal = GetTPCdEdx(seed);
     389           0 :       if (nclsDeDx > 100) fHistDeDxTotal->Fill(meanP, tpcSignal);
     390             :       //
     391           0 :       if (fLowMemoryConsumption) {
     392           0 :         if (meanP < 20) continue;
     393             :         meanP = 30; // set all momenta to one in order to save memory
     394           0 :       }
     395             :       //dE/dx, time, type (1-muon cosmic,2-pion beam data), momenta
     396           0 :       Double_t vec[6] = {tpcSignal,static_cast<Double_t>(time),1,meanDrift,meanP,static_cast<Double_t>(runNumber)};
     397           0 :       fHistGainTime->Fill(vec);
     398           0 :     }
     399             :     
     400           0 :   }
     401             : 
     402           0 : }
     403             : 
     404             : 
     405             : 
     406             : void AliTPCcalibTimeGain::ProcessBeamEvent(AliESDEvent *event) {
     407             :   //
     408             :   // Process in case of beam event
     409             :   //
     410           0 :   if (!event->FindListObject("AliESDfriend")) {
     411           0 :    Printf("ERROR: ESDfriend not available");
     412           0 :    return;
     413             :   }
     414             :   //
     415           0 :   UInt_t time = event->GetTimeStamp();
     416           0 :   Int_t nTracks = event->GetNumberOfTracks();
     417           0 :   Int_t runNumber = event->GetRunNumber();
     418             :   //
     419             :   // track loop
     420             :   //
     421           0 :   for (Int_t i=0;i<nTracks;++i) { // begin track loop
     422             : 
     423           0 :     AliESDtrack *track = event->GetTrack(i);
     424           0 :     if (!track) continue;
     425           0 :     AliESDfriendTrack *friendTrack = (AliESDfriendTrack*)track->GetFriendTrack();
     426           0 :     if (!friendTrack) continue;
     427             :         
     428           0 :     const AliExternalTrackParam * trackIn = track->GetInnerParam();
     429           0 :     const AliExternalTrackParam * trackOut = friendTrack->GetTPCOut();
     430           0 :     if (!trackIn) continue;
     431           0 :     if (!trackOut) continue;
     432             : 
     433             :     // calculate necessary track parameters
     434           0 :     Double_t meanP = trackIn->GetP();
     435           0 :     Double_t meanDrift = 250 - 0.5*TMath::Abs(trackIn->GetZ() + trackOut->GetZ());
     436           0 :     Int_t nCrossedRows = track->GetTPCCrossedRows();
     437             : 
     438             :     //
     439             :     // exclude tracks which do not look like primaries or are simply too short or on wrong sectors
     440             :     // fCutCrossRows = 80, fCutEtaWindow = 0.8, fCutRequireITSrefit, fCutMaxDcaXY = 3.5, fCutMaxDcaZ = 25
     441             :     //
     442           0 :     if (nCrossedRows < fCutCrossRows) continue;     
     443           0 :     if (TMath::Abs(trackIn->Eta()) > fCutEtaWindow) continue;
     444             :     //
     445           0 :     UInt_t status = track->GetStatus();
     446           0 :     if ((status&AliESDtrack::kTPCrefit)==0) continue;
     447           0 :     if ((status&AliESDtrack::kITSrefit)==0 && fCutRequireITSrefit) continue; // ITS cluster
     448             :     //
     449           0 :     Float_t dca[2], cov[3];
     450           0 :     track->GetImpactParameters(dca,cov);
     451           0 :     if (TMath::Abs(dca[0]) > fCutMaxDcaXY || TMath::Abs(dca[0]) < 0.0000001) continue;  // cut in xy
     452           0 :     if (((status&AliESDtrack::kITSrefit) == 1 && TMath::Abs(dca[1]) > 3.) || TMath::Abs(dca[1]) > fCutMaxDcaZ ) continue;
     453             :     //
     454           0 :     Double_t eta = trackIn->Eta();
     455             :     
     456             :     // Get seeds
     457             :     TObject *calibObject;
     458             :     AliTPCseed *seed = 0;
     459           0 :     for (Int_t l=0;(calibObject=friendTrack->GetCalibObject(l));++l) {
     460           0 :       if ((seed=dynamic_cast<AliTPCseed*>(calibObject))) break;
     461             :     }    
     462             : 
     463           0 :     if (seed) {
     464             :       Int_t particleCase = 0;
     465           0 :       if (meanP < fMaxMomentumMIP && meanP > fMinMomentumMIP)  particleCase = 2; // MIP pions
     466           0 :       if (meanP < 0.57 && meanP > 0.56) particleCase = 3; // protons 1
     467           0 :       if (meanP < 0.66 && meanP > 0.65) particleCase = 4; // protons 2
     468             :       //
     469           0 :       if (fLowMemoryConsumption && particleCase == 0) continue;
     470             :       //
     471           0 :       Double_t tpcSignal = GetTPCdEdx(seed);
     472             :       //
     473             :       // flattens signal in MIP window
     474             :       //
     475           0 :       if (particleCase == 2) {
     476           0 :         Float_t corrFactor = AliExternalTrackParam::BetheBlochAleph(meanP/0.13957, 
     477           0 :                                                                     fAlephParameters[0], 
     478           0 :                                                                     fAlephParameters[1], 
     479           0 :                                                                     fAlephParameters[2], 
     480           0 :                                                                     fAlephParameters[3],
     481           0 :                                                                     fAlephParameters[4]);
     482           0 :         tpcSignal /= corrFactor; 
     483           0 :       } 
     484           0 :       fHistDeDxTotal->Fill(meanP, tpcSignal);
     485             :       //
     486             :       //dE/dx, time, type (1-muon cosmic,2-pion beam data, 3&4 protons), momenta, runNumner, eta
     487           0 :       Double_t vec[7] = {tpcSignal,static_cast<Double_t>(time),static_cast<Double_t>(particleCase),meanDrift,meanP,static_cast<Double_t>(runNumber), eta};
     488           0 :       fHistGainTime->Fill(vec);
     489           0 :     }
     490             :     
     491           0 :   } // end track loop
     492             :   //
     493             :   // V0 loop -- in beam events the cosmic part of the histogram is filled with GammaConversions
     494             :   //
     495           0 :   for(Int_t iv0 = 0; iv0 < event->GetNumberOfV0s(); iv0++) {
     496           0 :     AliESDv0 * v0 = event->GetV0(iv0);
     497           0 :     if (!v0->GetOnFlyStatus()) continue;
     498           0 :     if (v0->GetEffMass(0,0) > 0.02) continue; // select low inv. mass
     499           0 :     Double_t xyz[3];
     500           0 :     v0->GetXYZ(xyz[0], xyz[1], xyz[2]);
     501           0 :     if (TMath::Sqrt(xyz[0]*xyz[0] + xyz[1]*xyz[1]) < 3 || TMath::Sqrt(xyz[0]*xyz[0] + xyz[1]*xyz[1]) > 30) continue;
     502             :     //
     503             :     // "loop over daughters" 
     504             :     //
     505           0 :     for(Int_t idaughter = 0; idaughter < 2; idaughter++) { // daughter loop
     506           0 :       Int_t index = idaughter == 0 ? v0->GetPindex() : v0->GetNindex();
     507           0 :       AliESDtrack * trackP = event->GetTrack(index);
     508           0 :       AliESDfriendTrack *friendTrackP = (AliESDfriendTrack*)trackP->GetFriendTrack();
     509           0 :       if (!friendTrackP) continue;
     510           0 :       const AliExternalTrackParam * trackPIn = trackP->GetInnerParam();
     511           0 :       const AliExternalTrackParam * trackPOut = friendTrackP->GetTPCOut();
     512           0 :       if (!trackPIn) continue;
     513           0 :       if (!trackPOut) continue;
     514             :       // calculate necessary track parameters
     515           0 :       Double_t meanP = trackPIn->GetP();
     516           0 :       Double_t meanDrift = 250 - 0.5*TMath::Abs(trackPIn->GetZ() + trackPOut->GetZ());
     517           0 :       Int_t nclsDeDx = trackP->GetTPCNcls();
     518             :       // exclude tracks which do not look like primaries or are simply too short or on wrong sectors
     519           0 :       if (nclsDeDx < 60) continue;     
     520           0 :       if (TMath::Abs(trackPIn->GetTgl()) > 1) continue;
     521             :       //
     522             :       TObject *calibObject;
     523             :       AliTPCseed *seed = 0;
     524           0 :       for (Int_t l=0;(calibObject=friendTrackP->GetCalibObject(l));++l) {
     525           0 :       if ((seed=dynamic_cast<AliTPCseed*>(calibObject))) break;
     526             :       }    
     527           0 :       if (seed) { 
     528           0 :         if (fLowMemoryConsumption) {
     529           0 :           if (meanP > fMaxMomentumMIP || meanP < fMinMomentumMIP) continue;
     530             :           meanP = 0.45; // set all momenta to one in order to save memory
     531           0 :       }
     532           0 :         Double_t tpcSignal = GetTPCdEdx(seed);
     533             :         //dE/dx, time, type (1-muon cosmic,2-pion beam data), momenta
     534           0 :         Double_t vec[6] = {tpcSignal,static_cast<Double_t>(time),1,meanDrift,meanP,static_cast<Double_t>(runNumber)};
     535           0 :         fHistGainTime->Fill(vec);
     536           0 :       }
     537           0 :     }
     538             :     
     539           0 :   }
     540             : 
     541           0 : }
     542             : 
     543             : 
     544             : Float_t AliTPCcalibTimeGain::GetTPCdEdx(AliTPCseed * seed) {
     545             :   //
     546             :   // calculate tpc dEdx
     547             :   //
     548             :   Double_t signal = 0;
     549             :   //
     550           0 :   if (!fUseCookAnalytical) {
     551           0 :     signal = (1/fMIP)*seed->CookdEdxNorm(fLowerTrunc,fUpperTrunc,fUseMax,0,kMaxRow,fUseShapeNorm,fUsePosNorm,fUsePadNorm,0);
     552           0 :   } else {
     553           0 :     signal = (1/fMIP)*seed->CookdEdxAnalytical(fLowerTrunc,fUpperTrunc,fUseMax);
     554             :   }
     555             :   //
     556           0 :   return signal;
     557             : }
     558             : 
     559             : 
     560             : void AliTPCcalibTimeGain::AnalyzeRun(Int_t minEntries) {
     561             :   //
     562             :   // Analyze results of calibration
     563             :   //
     564           0 :   if (fIsCosmic) {
     565           0 :     fHistGainTime->GetAxis(2)->SetRangeUser(0.51,1.49); // only cosmics
     566           0 :     fHistGainTime->GetAxis(4)->SetRangeUser(20,100);    // only Fermi-Plateau muons
     567           0 :   } else {
     568           0 :     fHistGainTime->GetAxis(2)->SetRangeUser(1.51,2.49); // only beam data
     569           0 :     fHistGainTime->GetAxis(4)->SetRangeUser(0.39,0.51); // only MIP pions
     570             :   }
     571             :   //
     572           0 :   fGainVsTime = AliTPCcalibBase::FitSlices(fHistGainTime,0,1,minEntries,10);
     573             :   //
     574           0 :   return;
     575             : }
     576             : 
     577             : 
     578             : TGraphErrors * AliTPCcalibTimeGain::GetGraphGainVsTime(Int_t runNumber, Int_t minEntries) {
     579             :   //
     580             :   // Analyze results and get the graph 
     581             :   //
     582           0 :   if (runNumber == 0) {
     583           0 :     if (!fGainVsTime) {
     584           0 :       AnalyzeRun(minEntries);
     585           0 :     }
     586             :   } else {
     587             :     // 1st check if the current run was cosmic or beam event
     588           0 :     fHistGainTime->GetAxis(5)->SetRangeUser(runNumber,runNumber);
     589           0 :     AnalyzeRun(minEntries);
     590             :   }
     591           0 :   if (fGainVsTime->GetN() == 0) return 0;
     592           0 :   return fGainVsTime;
     593           0 : }
     594             : 
     595             : Long64_t AliTPCcalibTimeGain::Merge(TCollection *li) {
     596             :   //
     597             :   // merge component
     598             :   //
     599           0 :   TIterator* iter = li->MakeIterator();
     600             :   AliTPCcalibTimeGain* cal = 0;
     601             : 
     602           0 :   while ((cal = (AliTPCcalibTimeGain*)iter->Next())) {
     603           0 :     if (!cal->InheritsFrom(AliTPCcalibTimeGain::Class())) {
     604           0 :       Error("Merge","Attempt to add object of class %s to a %s", cal->ClassName(), this->ClassName());
     605           0 :       return -1;
     606             :     }
     607             : 
     608             :     // add histograms here...
     609           0 :     if (cal->GetHistGainTime() && fHistGainTime ) 
     610             :     {
     611           0 :       if ((fHistGainTime->GetEntries() + cal->GetHistGainTime()->GetEntries()) < fgMergeEntriesCut) 
     612             :       {
     613             :         //AliInfo(Form("fHistGainTime has %.0f tracks, going to add %.0f\n",fHistGainTime->GetEntries(),cal->GetHistGainTime()->GetEntries()));
     614           0 :         fHistGainTime->Add(cal->GetHistGainTime());
     615           0 :       }
     616             :       else
     617             :       {
     618           0 :         AliInfo(Form("fHistGainTime full (has %.0f merged tracks, trying to add %.0f, max allowed: %.0f)",fHistGainTime->GetEntries(), cal->GetHistGainTime()->GetEntries(), fgMergeEntriesCut));
     619             :       }
     620             :     }
     621             : 
     622           0 :     if (cal->GetHistDeDxTotal()) fHistDeDxTotal->Add(cal->GetHistDeDxTotal());
     623             : 
     624             :   }
     625           0 :   delete iter;
     626           0 :   return 0;
     627             :   
     628           0 : }
     629             : 
     630             : 
     631             : AliSplineFit * AliTPCcalibTimeGain::MakeSplineFit(TGraphErrors * graph) {
     632             :   //
     633             :   // make spline fit of gain
     634             :   //
     635           0 :   AliSplineFit *fit = new AliSplineFit();
     636           0 :   fit->SetGraph(graph);
     637           0 :   fit->SetMinPoints(graph->GetN()+1);
     638           0 :   fit->InitKnots(graph,2,0,0.001);
     639           0 :   fit->SplineFit(0);
     640           0 :   return fit;
     641             :   
     642           0 : }
     643             : 
     644             : 
     645             : 
     646             : TGraphErrors * AliTPCcalibTimeGain::GetGraphAttachment(Int_t minEntries, Int_t nmaxBin, Float_t /*fracLow*/, Float_t /*fracUp*/) {
     647             :   //
     648             :   // For each time bin the driftlength-dependence of the signal is fitted.
     649             :   //
     650           0 :   TH3D * hist = fHistGainTime->Projection(1, 0, 3);
     651           0 :   Double_t *xvec = new Double_t[hist->GetNbinsX()];
     652           0 :   Double_t *yvec = new Double_t[hist->GetNbinsX()];
     653           0 :   Double_t *xerr = new Double_t[hist->GetNbinsX()];
     654           0 :   Double_t *yerr = new Double_t[hist->GetNbinsX()];
     655             :   Int_t counter  = 0;
     656             :   TH2D * projectionHist = 0x0;
     657             :   //
     658           0 :   for(Int_t i=1; i < hist->GetNbinsX(); i++) {
     659             :     Int_t nsum=0;
     660             :     Int_t imin   =  i;
     661             :     Int_t imax   =  i;    
     662           0 :     for (Int_t idelta=0; idelta<nmaxBin; idelta++){
     663             :       //
     664           0 :       imin   =  TMath::Max(i-idelta,1);
     665           0 :       imax   =  TMath::Min(i+idelta,hist->GetNbinsX());
     666           0 :       nsum = TMath::Nint(hist->Integral(imin,imax,1,hist->GetNbinsY()-1,1,hist->GetNbinsZ()-1));
     667           0 :       if (nsum==0) break;
     668           0 :       if (nsum>minEntries) break;
     669             :     }
     670           0 :     if (nsum<minEntries) continue;
     671             :     //
     672           0 :     hist->GetXaxis()->SetRange(imin,imax);
     673           0 :     projectionHist = (TH2D*)hist->Project3D("yzNUFNOF");
     674             :     //
     675           0 :     TObjArray arr;
     676           0 :     projectionHist->FitSlicesY(0,2, projectionHist->GetNbinsX()-2,0,"QNR",&arr);
     677           0 :     TH1D * histAttach = (TH1D*)arr.At(1);
     678           0 :     TF1 pol1("polynom1","pol1",10,240);
     679           0 :     histAttach->Fit(&pol1,"QNR");
     680           0 :     xvec[counter] = 0.5*(hist->GetXaxis()->GetBinCenter(imin)+hist->GetXaxis()->GetBinCenter(imax));
     681           0 :     yvec[counter] = pol1.GetParameter(1)/pol1.GetParameter(0);
     682           0 :     xerr[counter] = 0;
     683           0 :     yerr[counter] = pol1.GetParError(1)/pol1.GetParameter(0);
     684           0 :     counter++;
     685             :     //
     686           0 :     delete projectionHist;
     687           0 :   }
     688             :   
     689           0 :   TGraphErrors * graphErrors = new TGraphErrors(counter, xvec, yvec, xerr, yerr);
     690           0 :   delete [] xvec;
     691           0 :   delete [] yvec;
     692           0 :   delete [] xerr;
     693           0 :   delete [] yerr;
     694           0 :   delete hist;
     695           0 :   return graphErrors;
     696             :   
     697           0 : }
     698             : 
     699             : 
     700             : 
     701             : void AliTPCcalibTimeGain::BinLogX(THnSparse *h, Int_t axisDim) {
     702             :   //
     703             :   // Method for the correct logarithmic binning of histograms
     704             :   //
     705           0 :   TAxis *axis = h->GetAxis(axisDim);
     706           0 :   int bins = axis->GetNbins();
     707             : 
     708           0 :   Double_t from = axis->GetXmin();
     709           0 :   Double_t to = axis->GetXmax();
     710           0 :   Double_t *newBins = new Double_t[bins + 1];
     711             :    
     712           0 :   newBins[0] = from;
     713           0 :   Double_t factor = pow(to/from, 1./bins);
     714             :   
     715           0 :   for (int i = 1; i <= bins; i++) {
     716           0 :    newBins[i] = factor * newBins[i-1];
     717             :   }
     718           0 :   axis->Set(bins, newBins);
     719           0 :   delete[] newBins;
     720             :   
     721           0 : }
     722             : 
     723             : 
     724             : void AliTPCcalibTimeGain::BinLogX(TH1 *h) {
     725             :   //
     726             :   // Method for the correct logarithmic binning of histograms
     727             :   //
     728           0 :   TAxis *axis = h->GetXaxis();
     729           0 :   int bins = axis->GetNbins();
     730             : 
     731           0 :   Double_t from = axis->GetXmin();
     732           0 :   Double_t to = axis->GetXmax();
     733           0 :   Double_t *newBins = new Double_t[bins + 1];
     734             :    
     735           0 :   newBins[0] = from;
     736           0 :   Double_t factor = pow(to/from, 1./bins);
     737             :   
     738           0 :   for (int i = 1; i <= bins; i++) {
     739           0 :    newBins[i] = factor * newBins[i-1];
     740             :   }
     741           0 :   axis->Set(bins, newBins);
     742           0 :   delete[] newBins;
     743             :   
     744           0 : }
     745             : 
     746             : 
     747             : 
     748             : void AliTPCcalibTimeGain::CalculateBetheAlephParams(TH2F *hist, Double_t * ini) {
     749             :   //
     750             :   // Fit the bethe bloch params
     751             :   //
     752             :   //{0.0762*MIP,10.632,1.34e-05,1.863,1.948}
     753             :   const Double_t sigma = 0.06;
     754             : 
     755           0 :   TH2F *histBG = new TH2F("histBG","dEdxBg; #beta #gamma; TPC signal (a.u.)",TMath::Nint(0.5*hist->GetNbinsX()),0.1,5000.,hist->GetNbinsY(),hist->GetYaxis()->GetXmin(),hist->GetYaxis()->GetXmax());
     756           0 :   BinLogX(histBG);
     757             : 
     758           0 :   TF1 *foElectron = new TF1("foElectron", "AliExternalTrackParam::BetheBlochAleph(x/0.000511,[0],[1],[2],[3],[4])",0.01,100);
     759           0 :   TF1 *foMuon = new TF1("foMuon", "AliExternalTrackParam::BetheBlochAleph(x/0.1056,[0],[1],[2],[3],[4])",0.01,100);
     760           0 :   TF1 *foPion = new TF1("foPion", "AliExternalTrackParam::BetheBlochAleph(x/0.138,[0],[1],[2],[3],[4])",0.01,100);
     761           0 :   TF1 *foKaon = new TF1("foKaon", "AliExternalTrackParam::BetheBlochAleph(x/0.498,[0],[1],[2],[3],[4])",0.01,100);
     762           0 :   TF1 *foProton = new TF1("foProton", "AliExternalTrackParam::BetheBlochAleph(x/0.938,[0],[1],[2],[3],[4])",0.01,100);
     763           0 :   foElectron->SetParameters(ini);
     764           0 :   foMuon->SetParameters(ini);
     765           0 :   foPion->SetParameters(ini);
     766           0 :   foKaon->SetParameters(ini);
     767           0 :   foProton->SetParameters(ini);
     768             :   
     769           0 :   TCanvas *canvCheck1 = new TCanvas();
     770           0 :   hist->Draw("colz");
     771           0 :   foElectron->Draw("same");
     772           0 :   foMuon->Draw("same");
     773           0 :   foPion->Draw("same");
     774           0 :   foKaon->Draw("same");  
     775           0 :   foProton->Draw("same");
     776             :  
     777             :   // Loop over all points of the input histogram
     778             :   
     779           0 :   for(Int_t i=1; i < hist->GetNbinsX(); i++) {
     780           0 :     Double_t x = hist->GetXaxis()->GetBinCenter(i);   
     781           0 :     for(Int_t j=1; j < hist->GetNbinsY(); j++) {
     782           0 :       Long64_t n = hist->GetBin(i, j);
     783           0 :       Double_t y = hist->GetYaxis()->GetBinCenter(j);
     784           0 :       Double_t entries = hist->GetBinContent(n);
     785             :       Double_t mass = 0;
     786             : 
     787             :       // 1. identify protons
     788             :       mass = 0.938;
     789           0 :       if (TMath::Abs(y - foProton->Eval(x))/foProton->Eval(x) < 4*sigma && x < 0.65 ) {
     790           0 :         for(Int_t iEntries =0; iEntries < entries; iEntries++) histBG->Fill(x/mass, y);
     791           0 :       }
     792             : 
     793             :       // 2. identify electrons
     794             :       mass = 0.000511;
     795           0 :       if (fIsCosmic) {
     796           0 :         if (TMath::Abs(y - foElectron->Eval(x))/foElectron->Eval(x) < 4*sigma && (x>0.25&&x<0.7) && fIsCosmic) {
     797           0 :           for(Int_t iEntries =0; iEntries < entries; iEntries++) histBG->Fill(x/mass, y);
     798           0 :         }
     799             :       } else {
     800           0 :         if (TMath::Abs(y - foElectron->Eval(x))/foElectron->Eval(x) < 2*sigma && ((x>0.25&&x<0.35) || (x>1.5&&x<1.8) || (x>0.65&&x<0.7))) {
     801           0 :           for(Int_t iEntries =0; iEntries < entries; iEntries++) histBG->Fill(x/mass, y);
     802           0 :         }
     803             :       }
     804             :       
     805             :       // 3. identify either muons or pions depending on cosmic or not
     806           0 :       if (fIsCosmic) {
     807             :         mass = 0.1056;
     808           0 :         if (TMath::Abs(y - foMuon->Eval(x))/foMuon->Eval(x) < 4*sigma && x > 0.25 && x < 100 ) {
     809           0 :           for(Int_t iEntries =0; iEntries < entries; iEntries++) histBG->Fill(x/mass, y);
     810           0 :         }
     811             :       } else {
     812             :         mass = 0.1396;
     813           0 :         if (TMath::Abs(y - foPion->Eval(x))/foPion->Eval(x) < 4*sigma && x > 0.15 && x < 2) {
     814           0 :           for(Int_t iEntries =0; iEntries < entries; iEntries++) histBG->Fill(x/mass, y);
     815           0 :         }
     816             :       }
     817             :       
     818             :       // 4. for pp also Kaons must be included
     819           0 :       if (!fIsCosmic) {
     820             :         mass = 0.4936;
     821           0 :         if (TMath::Abs(y - foKaon->Eval(x))/foKaon->Eval(x) < 4*sigma && x > 0.2 && x < 0.3 ) {
     822           0 :           for(Int_t iEntries =0; iEntries < entries; iEntries++) histBG->Fill(x/mass, y);
     823           0 :         }
     824             :       }
     825             :     }
     826             :   }
     827             : 
     828             :   // Fit Aleph-Parameters to the obtained profile
     829           0 :   TF1 * funcAlephD = new TF1("AlephParametrizationD", "AliExternalTrackParam::BetheBlochAleph(x,[0],[1],[2],[3],[4])",0.3,10000);
     830           0 :   funcAlephD->SetParameters(ini);
     831             : 
     832           0 :   TCanvas *canvCheck2 = new TCanvas();
     833           0 :   histBG->Draw();
     834             :   
     835             :   //FitSlices
     836           0 :   TObjArray * arr = new TObjArray();
     837           0 :   histBG->FitSlicesY(0,0,-1,0,"QN",arr);
     838           0 :   TH1D * fitMean = (TH1D*) arr->At(1);
     839           0 :   fitMean->Draw("same");
     840             : 
     841           0 :   funcAlephD->SetParLimits(2,1e-3,1e-7);
     842           0 :   funcAlephD->SetParLimits(3,0.5,3.5);
     843           0 :   funcAlephD->SetParLimits(4,0.5,3.5);
     844           0 :   fitMean->Fit(funcAlephD, "QNR");
     845           0 :   funcAlephD->Draw("same");
     846             : 
     847           0 :   for(Int_t i=0;i<5;i++) ini[i] = funcAlephD->GetParameter(i);
     848             : 
     849           0 :   foElectron->SetParameters(ini);
     850           0 :   foMuon->SetParameters(ini);
     851           0 :   foPion->SetParameters(ini);
     852           0 :   foKaon->SetParameters(ini);
     853           0 :   foProton->SetParameters(ini);
     854             :   
     855           0 :   TCanvas *canvCheck3 = new TCanvas();
     856           0 :   hist->Draw("colz");
     857           0 :   foElectron->Draw("same");
     858           0 :   foMuon->Draw("same");
     859           0 :   foPion->Draw("same");
     860           0 :   foKaon->Draw("same");  
     861           0 :   foProton->Draw("same");
     862             :   
     863           0 :   canvCheck1->Print();
     864           0 :   canvCheck2->Print();
     865           0 :   canvCheck3->Print();
     866             : 
     867             :   return;
     868             : 
     869             : 
     870           0 : }

Generated by: LCOV version 1.11