Missing protection added. (A.Gheata)
[u/mrichter/AliRoot.git] / TPC / AliTPCcalibBase.cxx
CommitLineData
3ab35fc5 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// //
19// Base class for the calibration components using
20// as input TPCseeds and ESDs
21// Event loop outside of the component
22//
23//
ae28e92e 24// Base functionality to be implemeneted by component
25/*
26 //In some cases only one of this function to be implemented
27 virtual void Process(AliESDEvent *event)
28 virtual void Process(AliTPCseed *track)
29 //
30 virtual Long64_t Merge(TCollection *li);
31 virtual void Analyze()
32 void Terminate();
33*/
34// Functionality provided by base class for Algorith debuging:
35// TTreeSRedirector * cstream = GetDebugStreamer() - get debug streamer which can be use for numerical debugging
36//
37
38
39
40// marian.ivanov@cern.ch
3ab35fc5 41//
42#include "AliTPCcalibBase.h"
f7f33dec 43#include "TSystem.h"
44#include "TFile.h"
ae28e92e 45#include "TTreeStream.h"
f7f33dec 46#include "AliLog.h"
47328338 47#include "TTimeStamp.h"
108953e9 48#include "AliESDEvent.h"
f7f33dec 49
3ab35fc5 50
51ClassImp(AliTPCcalibBase)
52
ae28e92e 53AliTPCcalibBase::AliTPCcalibBase():
54 TNamed(),
55 fDebugStreamer(0),
108953e9 56 fStreamLevel(0),
57 fRun(0), //! current Run number
58 fEvent(0), //! current Event number
59 fTime(0), //! current Time
60 fTrigger(0), //! current trigger type
61 fMagF(0), //! current magnetic field
c51653e8 62 fTriggerMaskReject(-1), //trigger mask - reject trigger
63 fTriggerMaskAccept(-1), //trigger mask - accept trigger
2d22fa36 64 fHasLaser(kFALSE), //flag the laser is overlayed with given event
65 fRejectLaser(kTRUE), //flag- reject laser
15e48021 66 fTriggerClass(),
ae28e92e 67 fDebugLevel(0)
3ab35fc5 68{
69 //
70 // Constructor
71 //
72}
73
8cf12c96 74AliTPCcalibBase::AliTPCcalibBase(const char * name, const char * title):
75 TNamed(name,title),
76 fDebugStreamer(0),
77 fStreamLevel(0),
78 fRun(0), //! current Run number
79 fEvent(0), //! current Event number
80 fTime(0), //! current Time
81 fTrigger(0), //! current trigger type
82 fMagF(0), //! current magnetic field
83 fTriggerMaskReject(-1), //trigger mask - reject trigger
84 fTriggerMaskAccept(-1), //trigger mask - accept trigger
85 fHasLaser(kFALSE), //flag the laser is overlayed with given event
86 fRejectLaser(kTRUE), //flag- reject laser
15e48021 87 fTriggerClass(),
8cf12c96 88 fDebugLevel(0)
89{
90 //
91 // Constructor
92 //
93}
94
ae28e92e 95AliTPCcalibBase::AliTPCcalibBase(const AliTPCcalibBase&calib):
96 TNamed(calib),
97 fDebugStreamer(0),
98 fStreamLevel(calib.fStreamLevel),
e5cbd73f 99 fRun(0), //! current Run number
100 fEvent(0), //! current Event number
101 fTime(0), //! current Time
102 fTrigger(0), //! current trigger type
103 fMagF(0), //! current magnetic field
c51653e8 104 fTriggerMaskReject(calib.fTriggerMaskReject), //trigger mask - reject trigger
105 fTriggerMaskAccept(calib.fTriggerMaskAccept), //trigger mask - accept trigger
2d22fa36 106 fHasLaser(calib.fHasLaser), //flag the laser is overlayed with given event
107 fRejectLaser(calib.fRejectLaser), //flag- reject laser
fe8454d9 108 fTriggerClass(calib.fTriggerClass),
ae28e92e 109 fDebugLevel(calib.fDebugLevel)
110{
111 //
112 // copy constructor
113 //
114}
115
116AliTPCcalibBase &AliTPCcalibBase::operator=(const AliTPCcalibBase&calib){
117 //
118 //
119 //
120 ((TNamed *)this)->operator=(calib);
121 fDebugStreamer=0;
122 fStreamLevel=calib.fStreamLevel;
123 fDebugLevel=calib.fDebugLevel;
525062ee 124 return *this;
ae28e92e 125}
126
127
3ab35fc5 128AliTPCcalibBase::~AliTPCcalibBase() {
129 //
130 // destructor
131 //
f7f33dec 132 if (fDebugLevel>0) printf("AliTPCcalibBase::~AliTPCcalibBase\n");
ae28e92e 133 if (fDebugStreamer) delete fDebugStreamer;
134 fDebugStreamer=0;
135}
136
137void AliTPCcalibBase::Terminate(){
138 //
139 //
140 //
f7f33dec 141 if (fDebugLevel>0) printf("AliTPCcalibBase::Terminate\n");
ae28e92e 142 if (fDebugStreamer) delete fDebugStreamer;
143 fDebugStreamer = 0;
144 return;
145}
146
147TTreeSRedirector *AliTPCcalibBase::GetDebugStreamer(){
148 //
149 // Get Debug streamer
150 // In case debug streamer not yet initialized and StreamLevel>0 create new one
151 //
152 if (fStreamLevel==0) return 0;
153 if (fDebugStreamer) return fDebugStreamer;
154 TString dsName;
155 dsName=GetName();
156 dsName+="Debug.root";
157 dsName.ReplaceAll(" ","");
158 fDebugStreamer = new TTreeSRedirector(dsName.Data());
159 return fDebugStreamer;
3ab35fc5 160}
f7f33dec 161
162
108953e9 163void AliTPCcalibBase::UpdateEventInfo(AliESDEvent * event){
164 //
165 //
166 //
167 fRun = event->GetRunNumber();
168 fEvent = event->GetEventNumberInFile();
169 fTime = event->GetTimeStamp();
170 fTrigger = event->GetTriggerMask();
171 fMagF = event->GetMagneticField();
15e48021 172 fTriggerClass = event->GetFiredTriggerClasses().Data();
2d22fa36 173 fHasLaser = HasLaser(event);
15e48021 174
108953e9 175}
176
2d22fa36 177
178Bool_t AliTPCcalibBase::HasLaser(AliESDEvent *event){
179 //
180 //
181 //
182 // Thresholds more than 8 tracks with small dip angle
183
184 const Int_t kMinLaserTracks = 8;
185 const Float_t kThrLaser = 0.3;
186 const Float_t kLaserTgl = 0.01;
187
188 Int_t ntracks = event->GetNumberOfTracks();
189 if (ntracks<kMinLaserTracks) return kFALSE;
190 Float_t nlaser=0;
191 Float_t nall=0;
192 for (Int_t i=0;i<ntracks;++i) {
193 AliESDtrack *track=event->GetTrack(i);
194 if (!track) continue;
195 if (track->GetTPCNcls()<=0) continue;
196 nall++;
197 if (TMath::Abs(track->GetTgl())<kLaserTgl) nlaser++;
198 }
199 if (nlaser>kMinLaserTracks) return kTRUE;
200 if (nall>0 && nlaser/nall>kThrLaser) return kTRUE;
201 return kFALSE;
202}
203
204
205
c51653e8 206Bool_t AliTPCcalibBase::AcceptTrigger(){
207 //
208 // Apply trigger mask - Don't do calibration for non proper triggers
209 //
2d22fa36 210 if (fTriggerMaskReject==(Int_t)fTrigger) return kFALSE;
211 if (fTriggerMaskAccept>0 && fTriggerMaskAccept!=(Int_t)fTrigger) return kFALSE;
212 if (fHasLaser && fRejectLaser) return kFALSE;
c51653e8 213 return kTRUE;
214}
215
216
f7f33dec 217void AliTPCcalibBase::RegisterDebugOutput(const char *path){
218 //
219 // store - copy debug output to the destination position
220 // currently ONLY for local copy
221 if (fDebugLevel>0) printf("AliTPCcalibBase::RegisterDebugOutput(%s)\n",path);
222 if (fStreamLevel==0) return;
223 TString dsName;
224 dsName=GetName();
225 dsName+="Debug.root";
226 dsName.ReplaceAll(" ","");
227 TString dsName2=path;
228 gSystem->MakeDirectory(dsName2.Data());
229 dsName2+=gSystem->HostName();
230 gSystem->MakeDirectory(dsName2.Data());
231 dsName2+="/";
47328338 232 TTimeStamp s;
233 dsName2+=Int_t(s.GetNanoSec());
234 dsName2+="/";
235 gSystem->MakeDirectory(dsName2.Data());
f7f33dec 236 dsName2+=dsName;
237 AliInfo(Form("copy %s\t%s\n",dsName.Data(),dsName2.Data()));
238 printf("copy %s\t%s\n",dsName.Data(),dsName2.Data());
239 TFile::Cp(dsName.Data(),dsName2.Data());
240}