<commit_before>/**************************************************************************
 * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
 *                                                                        *
 * Author: The ALICE Off-line Project.                                    *
 * Contributors are mentioned in the code where appropriate.              *
 *                                                                        *
 * Permission to use, copy, modify and distribute this software and its   *
 * documentation strictly for non-commercial purposes is hereby granted   *
 * without fee, provided that the above copyright notice appears in all   *
 * copies and that both the copyright notice and this permission notice   *
 * appear in the supporting documentation. The authors make no claims     *
 * about the suitability of this software for any purpose. It is          *
 * provided "as is" without express or implied warranty.                  *
 **************************************************************************/

////////////////////////////////////////////////////////////////////////////
//
//
//  Gain calibration using tracks
//
//  The main goal:
//    1.) Inner TPC gain alignement - (parabolic) parameterization (inside of one sector) 
//    2.) Angular and z-position correction (parabolic) parameterization 
//    3.) Sector gain alignment  
//   
//  Following histograms are accumulated
//    a.) Simple 1D histograms  per chamber  
//    b.) Profile histograms per chamber - local x dependence    
//    c.) 2D Profile histograms  - local x - fi dependence
//
//  To get the gain map - the simple solution - use the histograms - is not enough
//  The resulting mean amplitude map depends strongly on the track topology
//  These dependence can be reduced, taking into account angular effect, and diffusion effect 
//  Using proper fit modeles
//
//     
//
//                                                                        
//       === Calibration class for gain calibration using tracks ===
//
//    1) Genereal idea
//    ================
//       A 6-parametric parabolic function
//
//          G(x, y) = p0 + p1*x + p2*y + p3*x^2 + p4*y^2 + p5 * x*y
//
//       is fitted to the maximum charge values or total charge values of
//       all the clusters contained in the tracks that are added to this
//       object. This fit is performed for each read out chamber, in fact even
//       for each type of pad sizes (thus for one segment, which consists of
//       an IROC and an OROC, there are three fitters used, corresponding to
//       the three pad sizes). The coordinate origin is at the center of the
//       particular pad size region on each ROC.
//
//       Because of the Landau nature of the charge deposition we use
//       different "types" of fitters instead of one to minimize the effect
//       of the long Landau tail. The difference between the fitters is only
//       the charge value, that is put into them, i.e. the charge is subject
//       to a transformation. At this point we use three different fit types:
//
//          a) simple: the charge is put in as it is
//          b) sqrt:   the square root of the charge is put into the fitter
//          c) log:    fgkM * Log(1+q/fgkM) is put into the fitter, with
//                     q being the untransformed charge and fgkM=25
//
//       The results of the fits may be visualized and further used by
//       creating an AliTPCCalROC or AliTPCCalPad. You may specify to undo
//       the transformation and/or to normalize to the pad size.
//
//       Not every track you add to this object is actually used for
//       calibration. There are some cuts and conditions to exclude bad
//       tracks, e.g. a pt cut to cut out tracks with too much charge
//       deposition or a cut on edge clusters which are not fully
//       registered and don't give a usable signal.
//
//    2) Interface / usage
//    ====================
//       For each track to be added you need to call Process().
//       This method expects an AliTPCseed, which contains the necessary
//       cluster information. At the moment of writing this information
//       is stored in an AliESDfriend corresponding to an AliESD.
//       You may also call AddTrack() if you don't want the cuts and
//       other quality conditions to kick in (thus forcing the object to
//       accept the track) or AddCluster() for adding single clusters.
//       Call one of the Evaluate functions to evaluate the fitter(s) and
//       to retrieve the fit parameters, erros and so on. You can also
//       do this later on by using the different Getters.
//
//       The visualization methods CreateFitCalPad() and CreateFitCalROC()
//       are straight forward to use.
//
//       Note: If you plan to write this object to a ROOT file, make sure
//             you evaluate all the fitters *before* writing, because due
//             to a bug in the fitter component writing fitters doesn't
//             work properly (yet). Be aware that you cannot re-evaluate
//             the fitters after loading this object from file.
//             (This will be gone for a new ROOT version > v5-17-05)
//                                                                        
//
//    In order to debug some numerical algorithm all data data which are used for
//    fitters can be stored in the debug streamers. In case of fitting roblems the 
//    errors and tendencies can be checked.
//
//    Debug Streamers:
//      
// 
//
//
//
////////////////////////////////////////////////////////////////////////////

/*
  .x ~/UliStyle.C
  gSystem->Load("libANALYSIS");
  gSystem->Load("libTPCcalib");
  TFile fcalib("CalibObjects.root");
  TObjArray * array = (TObjArray*)fcalib.Get("TPCCalib");
  AliTPCcalibTracksGain * gain = ( AliTPCcalibTracksGain *)array->FindObject("calibTracksGain");

  //
  // Angular and drift correction
  //
  AliTPCClusterParam *param = new AliTPCClusterParam;param->SetInstance(param);
  gain->UpdateClusterParam(param);
  TF2 fdrty("fdrty","AliTPCClusterParam::SQnorm(0,0,x,y,0)",0,1,0,1)

  //
  // Make visual Tree - compare with Kr calibration
  // 
  AliTPCCalPad * gain010 = gain->CreateFitCalPad(0,kTRUE,0); gain010->SetName("CGain010");
  AliTPCCalPad * gain110 = gain->CreateFitCalPad(1,kTRUE,0); gain110->SetName("CGain110");
  AliTPCCalPad * gain210 = gain->CreateFitCalPad(2,kTRUE,0); gain210->SetName("CGain210");
  TFile fkr("/u/miranov/GainMap.root");
  AliTPCCalPad *gainKr = fkr.Get("GainMap"); fkr->SetName("KrGain");
  //
  AliTPCPreprocessorOnline * preprocesor = new AliTPCPreprocessorOnline;
  preprocesor->AddComponent(gain010);
  preprocesor->AddComponent(gain110);
  preprocesor->AddComponent(gain210);
  preprocesor->AddComponent(gainKr);
  preprocesor->DumpToFile("cosmicGain.root");
  //
  //
  //
  // Simple session using the debug streamers
  //

  gSystem->AddIncludePath("-I$ALICE_ROOT/TPC/macros");
  gROOT->LoadMacro("$ALICE_ROOT/TPC/macros/AliXRDPROOFtoolkit.cxx+")
  AliXRDPROOFtoolkit tool;   

  TChain * chain0 = tool.MakeChain("gain.txt","dEdx",0,1000000);
  TChain * chain1 = tool.MakeChain("gain.txt","Track",0,1000000);
  TChain * chain2 = tool.MakeChain("gain.txt","TrackG",0,1000000);
  chain0->Lookup();
  chain1->Lookup();
  chain2->Lookup();

  chain2->SetAlias("k1","1/0.855");
  chain2->SetAlias("k0","1/0.9928");
  chain2->SetAlias("k2","1/1.152");
  



*/





#include <TPDGCode.h>
#include <TStyle.h>
#include "TSystem.h"
#include "TMatrixD.h"
#include "TTreeStream.h"
#include "TF1.h"
#include "AliTPCParamSR.h"
#include "AliTPCClusterParam.h"
#include "AliTrackPointArray.h"
#include "TCint.h"
#include "AliTPCcalibTracksGain.h"
#include <TH1.h>
#include <TH3F.h>
#include <TLinearFitter.h>
#include <TTreeStream.h>
#include <TFile.h>
#include <TCollection.h>
#include <TIterator.h>
#include <TProfile.h>
#include <TProfile2D.h>
#include <TProof.h>
<commit_msg>Example: dedx correction for the pad and time bin posiotion (Marian)<commit_after>/**************************************************************************
 * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
 *                                                                        *
 * Author: The ALICE Off-line Project.                                    *
 * Contributors are mentioned in the code where appropriate.              *
 *                                                                        *
 * Permission to use, copy, modify and distribute this software and its   *
 * documentation strictly for non-commercial purposes is hereby granted   *
 * without fee, provided that the above copyright notice appears in all   *
 * copies and that both the copyright notice and this permission notice   *
 * appear in the supporting documentation. The authors make no claims     *
 * about the suitability of this software for any purpose. It is          *
 * provided "as is" without express or implied warranty.                  *
 **************************************************************************/

////////////////////////////////////////////////////////////////////////////
//
//
//  Gain calibration using tracks
//
//  The main goal:
//    1.) Inner TPC gain alignement - (parabolic) parameterization (inside of one sector) 
//    2.) Angular and z-position correction (parabolic) parameterization 
//    3.) Sector gain alignment  
//   
//  Following histograms are accumulated
//    a.) Simple 1D histograms  per chamber  
//    b.) Profile histograms per chamber - local x dependence    
//    c.) 2D Profile histograms  - local x - fi dependence
//
//  To get the gain map - the simple solution - use the histograms - is not enough
//  The resulting mean amplitude map depends strongly on the track topology
//  These dependence can be reduced, taking into account angular effect, and diffusion effect 
//  Using proper fit modeles
//
//     
//
//                                                                        
//       === Calibration class for gain calibration using tracks ===
//
//    1) Genereal idea
//    ================
//       A 6-parametric parabolic function
//
//          G(x, y) = p0 + p1*x + p2*y + p3*x^2 + p4*y^2 + p5 * x*y
//
//       is fitted to the maximum charge values or total charge values of
//       all the clusters contained in the tracks that are added to this
//       object. This fit is performed for each read out chamber, in fact even
//       for each type of pad sizes (thus for one segment, which consists of
//       an IROC and an OROC, there are three fitters used, corresponding to
//       the three pad sizes). The coordinate origin is at the center of the
//       particular pad size region on each ROC.
//
//       Because of the Landau nature of the charge deposition we use
//       different "types" of fitters instead of one to minimize the effect
//       of the long Landau tail. The difference between the fitters is only
//       the charge value, that is put into them, i.e. the charge is subject
//       to a transformation. At this point we use three different fit types:
//
//          a) simple: the charge is put in as it is
//          b) sqrt:   the square root of the charge is put into the fitter
//          c) log:    fgkM * Log(1+q/fgkM) is put into the fitter, with
//                     q being the untransformed charge and fgkM=25
//
//       The results of the fits may be visualized and further used by
//       creating an AliTPCCalROC or AliTPCCalPad. You may specify to undo
//       the transformation and/or to normalize to the pad size.
//
//       Not every track you add to this object is actually used for
//       calibration. There are some cuts and conditions to exclude bad
//       tracks, e.g. a pt cut to cut out tracks with too much charge
//       deposition or a cut on edge clusters which are not fully
//       registered and don't give a usable signal.
//
//    2) Interface / usage
//    ====================
//       For each track to be added you need to call Process().
//       This method expects an AliTPCseed, which contains the necessary
//       cluster information. At the moment of writing this information
//       is stored in an AliESDfriend corresponding to an AliESD.
//       You may also call AddTrack() if you don't want the cuts and
//       other quality conditions to kick in (thus forcing the object to
//       accept the track) or AddCluster() for adding single clusters.
//       Call one of the Evaluate functions to evaluate the fitter(s) and
//       to retrieve the fit parameters, erros and so on. You can also
//       do this later on by using the different Getters.
//
//       The visualization methods CreateFitCalPad() and CreateFitCalROC()
//       are straight forward to use.
//
//       Note: If you plan to write this object to a ROOT file, make sure
//             you evaluate all the fitters *before* writing, because due
//             to a bug in the fitter component writing fitters doesn't
//             work properly (yet). Be aware that you cannot re-evaluate
//             the fitters after loading this object from file.
//             (This will be gone for a new ROOT version > v5-17-05)
//                                                                        
//
//    In order to debug some numerical algorithm all data data which are used for
//    fitters can be stored in the debug streamers. In case of fitting roblems the 
//    errors and tendencies can be checked.
//
//    Debug Streamers:
//      
// 
//
//
//
////////////////////////////////////////////////////////////////////////////

/*
  .x ~/UliStyle.C
  gSystem->Load("libANALYSIS");
  gSystem->Load("libTPCcalib");
  TFile fcalib("CalibObjects.root");
  TObjArray * array = (TObjArray*)fcalib.Get("TPCCalib");
  AliTPCcalibTracksGain * gain = ( AliTPCcalibTracksGain *)array->FindObject("calibTracksGain");

  //
  // Angular and drift correction
  //
  AliTPCClusterParam *param = new AliTPCClusterParam;param->SetInstance(param);
  gain->UpdateClusterParam(param);
  TF2 fdrty("fdrty","AliTPCClusterParam::SQnorm(0,0,x,y,0)",0,1,0,1)

  //
  // Make visual Tree - compare with Kr calibration
  // 
  AliTPCCalPad * gain010 = gain->CreateFitCalPad(0,kTRUE,0); gain010->SetName("CGain010");
  AliTPCCalPad * gain110 = gain->CreateFitCalPad(1,kTRUE,0); gain110->SetName("CGain110");
  AliTPCCalPad * gain210 = gain->CreateFitCalPad(2,kTRUE,0); gain210->SetName("CGain210");
  TFile fkr("/u/miranov/GainMap.root");
  AliTPCCalPad *gainKr = fkr.Get("GainMap"); fkr->SetName("KrGain");
  //
  AliTPCPreprocessorOnline * preprocesor = new AliTPCPreprocessorOnline;
  preprocesor->AddComponent(gain010);
  preprocesor->AddComponent(gain110);
  preprocesor->AddComponent(gain210);
  preprocesor->AddComponent(gainKr);
  preprocesor->DumpToFile("cosmicGain.root");
  //
  //
  //
  // Simple session using the debug streamers
  //

  gSystem->AddIncludePath("-I$ALICE_ROOT/TPC/macros");
  gROOT->LoadMacro("$ALICE_ROOT/TPC/macros/AliXRDPROOFtoolkit.cxx+")
  AliXRDPROOFtoolkit tool;   

  TChain * chain0 = tool.MakeChain("gain.txt","dEdx",0,1000000);
  TChain * chain1 = tool.MakeChain("gain.txt","Track",0,1000000);
  TChain * chain2 = tool.MakeChain("gain.txt","TrackG",0,1000000);
  chain0->Lookup();
  chain1->Lookup();
  chain2->Lookup();

  chain2->SetAlias("k1","1/0.855");
  chain2->SetAlias("k0","1/0.9928");
  chain2->SetAlias("k2","1/1.152");
  

  Position correction fit:
  //
  gSystem->Load("libSTAT.so")
  TStatToolkit toolkit;
  Double_t chi2;
  TVectorD fitParam;
  TMatrixD covMatrix;
  Int_t npoints;
  //
  TCut cutA("dedge>3&&fraction2<0.5");
  chain0->SetAlias("dp","(Cl.fPad-int(Cl.fPad)-0.5)");
  chain0->SetAlias("dt","(Cl.fTimeBin-int(Cl.fTimeBin)-0.5)");
  chain0->SetAlias("di","(sqrt(1.-abs(Cl.fZ)/250.))");

  TString fstring="";  
  fstring+="dp++";                               //1
  fstring+="dt++";                               //2
  fstring+="dp^2++";                             //3
  fstring+="dt^2++";                             //4
  fstring+="dt^3++";                             //4
  fstring+="dp*dt++";                            //5
  fstring+="dp*dt^2++";                          //6
  //
  fstring+="dp^2*(di)++";                        //7
  fstring+="dt^2*(di)++";                        //8
  fstring+="dp^2*(abs(parY.fElements[1]))++";                        //9
  fstring+="dt^2*(abs(parY.fElements[1]))++";                        //10
  fstring+="dp^2*(abs(parZ.fElements[1]))++";                        //11
  fstring+="dt^2*(abs(parZ.fElements[1]))++";                        //12


 TString *strq0 = toolkit.FitPlane(chain0,"Cl.fMax/gain/dedxM.fElements[0]",fstring->Data(), "IPad==0"+cutA, chi2,npoints,fitParam,covMatrix,-1,0,100000);

 chain0->SetAlias("qcorM0",strq0->Data());
 chain0->Draw("(Cl.fMax/gain/dedxM.fElements[0]):qcorM0","IPad==0"+cutA,"prof",100000)


*/





#include <TPDGCode.h>
#include <TStyle.h>
#include "TSystem.h"
#include "TMatrixD.h"
#include "TTreeStream.h"
#include "TF1.h"
#include "AliTPCParamSR.h"
#include "AliTPCClusterParam.h"
#include "AliTrackPointArray.h"
#include "TCint.h"
#include "AliTPCcalibTracksGain.h"
#include <TH1.h>
#include <TH3F.h>
#include <TLinearFitter.h>
#include <TTreeStream.h>
#include <TFile.h>
#include <TCollection.h>
#include <TIterator.h>
#include <TProfile.h>
#include <TProfile2D.h>
#include <TProof.h>

{'fraction_non_alphanumeric': 0.1470168427062518, 'fraction_numerical': 0.01986868398515558, 'mean_word_length': 2.2893896713615023, 'pattern_counts': {'":': 0, '<': 28, '<?xml version=': 0, '>': 88, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 26, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4901568', 'n_tokens_mistral': 5283, 'n_tokens_neox': 4965, 'n_words': 1696}