]> git.uio.no Git - u/mrichter/AliRoot.git/blob - ANALYSIS/TenderSupplies/AliT0TenderSupply.cxx
Fix for #95931: commit in trunk and port to release AliT0TenderSupply
[u/mrichter/AliRoot.git] / ANALYSIS / TenderSupplies / AliT0TenderSupply.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 ///////////////////////////////////////////////////////////////////////////
17 //                                                                       //
18 //  T0 Tender supply    //
19 //  //
20 //                                                                       //
21 ///////////////////////////////////////////////////////////////////////////
22
23 #include <AliESDEvent.h>
24 #include <AliESDtrack.h>
25
26 #include <AliTender.h>
27 #include <AliT0TenderSupply.h>
28 #include <AliCDBManager.h>
29 #include <AliCDBEntry.h>
30 #include <AliT0CalibSeasonTimeShift.h>
31 #include <AliESDInputHandler.h>
32
33 ClassImp(AliT0TenderSupply)
34
35 //________________________________________________________________________
36 AliT0TenderSupply::AliT0TenderSupply():
37   AliTenderSupply(),
38   fCorrectMeanTime(kFALSE),
39   fCorrectStartTimeOnAmplSatur(kFALSE),
40   fAmplitudeThreshold(100), 
41   fPass4LHC11aCorrection(kFALSE)
42 {
43   //
44   // default constructor
45   //
46   for(int i=0; i<4; i++) fTimeOffset[i]=0;
47 }
48
49 //________________________________________________________________________
50 AliT0TenderSupply::AliT0TenderSupply(const char *name, const AliTender *tender):
51   AliTenderSupply(name,tender),
52   fCorrectMeanTime(kFALSE),
53   fCorrectStartTimeOnAmplSatur(kFALSE),
54   fAmplitudeThreshold(100),
55   fPass4LHC11aCorrection(kFALSE)
56 {
57   //
58   // constructor
59   //
60   for(int i=0; i<3; i++) fTimeOffset[i]=0;
61
62 }
63
64 //________________________________________________________________________
65 AliT0TenderSupply::~AliT0TenderSupply(){
66   //
67   // destructor
68   //
69   
70 }
71
72 //________________________________________________________________________
73 void AliT0TenderSupply::Init(){
74   // Init
75   //
76   Int_t run = fTender->GetRun();
77   if (run == 0) return;    // to skip first init, when we don't have yet a run number
78   fPass4LHC11aCorrection=kFALSE;
79   
80
81   fCorrectMeanTime = kFALSE; //reset
82   for(int i=0; i<4; i++) fTimeOffset[i]=0;
83
84
85   fCorrectStartTimeOnAmplSatur = kFALSE;
86   fAmplitudeThreshold = 100; //in mips
87   
88   if(167693<= run && run<=170593){  // LHC11h
89     fCorrectStartTimeOnAmplSatur = kTRUE;
90     fAmplitudeThreshold = 50; //in mips
91   }
92
93 }
94
95 //________________________________________________________________________
96 void AliT0TenderSupply::ProcessEvent(){
97     //
98     // loop over all online T0 candidates and flag
99     // selected daughter tracks using the status bis of the TObject
100     //
101
102     AliESDEvent *event=fTender->GetEvent();
103     if (!event) return;
104      //...........................................
105    //Do something when the run number changed, like loading OCDB entries etc.
106     if(fTender->RunChanged()){
107       Init();
108       if (fTender->GetRun()>=139699&&  fTender->GetRun()<=146860){
109         AliESDInputHandler *esdIH = dynamic_cast<AliESDInputHandler*>  (fTender->GetESDhandler());
110         if (esdIH) {
111           TTree *tree= (TTree*)esdIH->GetTree();
112           TFile *file= (TFile*)tree->GetCurrentFile();
113          if (file){
114             TString fileName(file->GetName());
115             if (fileName.Contains("pass4") ) fPass4LHC11aCorrection=kTRUE;
116           }
117         }
118       }
119     }
120     
121     if(fPass4LHC11aCorrection) {
122       const Double32_t* mean = event->GetT0TOF();
123       event->SetT0TOF(0, (mean[1]+mean[2])/2.);
124  
125     }
126     //...........................................
127     if(fCorrectStartTimeOnAmplSatur){
128         //correct A side ORA on amplitude saturation
129         const Double32_t* time = event->GetT0time();
130         const Double32_t* amplitude = event->GetT0amplitude();
131
132         Int_t idxOfFirstPmtA = -1;
133         Double32_t timeOrA   = 99999;
134         for(int ipmt=12; ipmt<24; ipmt++){ //loop over A side
135             if( amplitude[ipmt] < fAmplitudeThreshold){
136                 if( time[ipmt] > -200 && time[ipmt]!=0 && time[ipmt] < timeOrA ){ 
137                     timeOrA        = time[ipmt];
138                     idxOfFirstPmtA = ipmt;
139                 }
140             }
141         }
142
143         if(idxOfFirstPmtA>-1){ //a hit in aside with less than 40 mips
144             const Double32_t* mean = event->GetT0TOF();
145             Double32_t timeOrC = mean[2];
146             Double32_t timeOrAplusOrC = (timeOrA+timeOrC)/2;
147
148             event->SetT0TOF(0, timeOrAplusOrC);
149             event->SetT0TOF(1, timeOrA);
150         }
151     }
152
153     //...........................................
154     Float_t *t0means=0x0;
155     if(fCorrectMeanTime) {
156       AliCDBManager* ocdbMan = AliCDBManager::Instance();
157       ocdbMan->SetRun(fTender->GetRun());    
158       AliCDBEntry *entry = ocdbMan->Get("T0/Calib/TimeAdjust/");
159       if(entry) {
160         AliT0CalibSeasonTimeShift *clb = (AliT0CalibSeasonTimeShift*) entry->GetObject();
161         t0means= clb->GetT0Means();
162       } else {
163         for (Int_t i=0;i<4;i++) t0means[i]=0;
164         AliWarning("T0Tender no T0 entry found T0shift set to 0");
165       }
166       
167       // correct mean time offsets  
168       const Double32_t* mean = event->GetT0TOF();
169       for(int it0=0; it0<3; it0++){
170         if(-2000 < mean[it0]){
171           event->SetT0TOF(it0, mean[it0] - t0means[it0]); 
172         }
173       }
174     }
175     //...........................................
176
177
178 }
179
180