1 #define AliTRDcalib_cxx
2 // The class definition in Calib.h has been generated automatically
3 // by the ROOT utility TTree::MakeSelector(). This class is derived
4 // from the ROOT class TSelector. For more information on the TSelector
5 // framework see $ROOTSYS/README/README.SELECTOR or the ROOT User Manual.
7 // The following methods are defined in this file:
8 // Begin(): called everytime a loop on the tree starts,
9 // a convenient place to create your histograms.
10 // SlaveBegin(): called after Begin(), when on PROOF called only on the
12 // Process(): called for each event, in this function you decide what
13 // to read and fill your histograms.
14 // SlaveTerminate: called at the end of the loop on the tree, when on PROOF
15 // called only on the slave servers.
16 // Terminate(): called at the end of the loop on the tree,
17 // a convenient place to draw/fit your histograms.
19 // To use this file, try the following session on your Tree T:
21 // Root > T->Process("AliTRDcalib.cxx")
22 // Root > T->Process("AliTRDcalib.cxx","some options")
23 // Root > T->Process("AliTRDcalib.cxx+")
26 #include "AliTRDcalib.h"
32 #include <TProfile2D.h>
37 #include <AliESDEvent.h>
38 #include <AliESDfriend.h>
39 #include <AliESDtrack.h>
40 #include <AliESDfriendTrack.h>
42 #include <AliTRDgeometry.h>
43 #include <AliTRDtrack.h>
44 #include <AliCDBManager.h>
45 #include <AliTRDCalibraFillHisto.h>
46 #include <AliTRDCalibraVdriftLinearFit.h>
49 AliTRDcalib::AliTRDcalib(TTree *) :
60 //G__SetCatchException(0);
62 //_____________________________________________________________________
63 void AliTRDcalib::Begin(TTree * /*tree*/)
65 // The Begin() function is called at the start of the query.
66 // When running with PROOF Begin() is only called on the client.
67 // The tree argument is deprecated (on PROOF 0 is passed).
69 //TString option = GetOption();
72 //______________________________________________________________________
73 void AliTRDcalib::SlaveBegin(TTree * tree)
75 // The SlaveBegin() function is called after the Begin() function.
76 // When running with PROOF SlaveBegin() is called on each slave server.
77 // The tree argument is deprecated (on PROOF 0 is passed).
79 //printf("Slave Begin\n");
81 //TString option = GetOption();
89 AliCDBManager *cdbManager = AliCDBManager::Instance();
90 cdbManager->SetDefaultStorage("local://$ALICE_ROOT/OCDB");
91 //cdbManager->SetSpecificStorage("TRD/Calib/FEE","local:///u/bailhach/aliroot/database30head/");
92 cdbManager->SetRun(0);
94 // instance calibration
95 fcalib = AliTRDCalibraFillHisto::Instance();
97 fcalib->SetNrphi(0,0);
99 fcalib->SetNrphi(1,0);
100 fcalib->SetHisto2d();
101 fcalib->SetVector2d();
102 fcalib->SetLinearFitterOn();
103 fcalib->SetLinearFitterDebugOn();
106 fcalib->SetPRF2dOn();
107 fcalib->Init2Dhistos();
108 //fcalib->SetDebugLevel(1);
109 fcalib->SetNumberClusters(14);
112 //__________________________________________________________________________
113 void AliTRDcalib::CleanESD(){
115 //printf("CleanESD\n");
125 //_________________________________________________________________________________
126 Bool_t AliTRDcalib::Process(Long64_t entry)
128 // The Process() function is called for each entry in the tree (or possibly
129 // keyed object in the case of PROOF) to be processed. The entry argument
130 // specifies which entry in the currently loaded tree is to be processed.
131 // It can be passed to either Calib::GetEntry() or TBranch::GetEntry()
132 // to read either all or the required parts of the data. When processing
133 // keyed objects with PROOF, the object is already loaded and is available
134 // via the fObject pointer.
136 // This function should contain the "body" of the analysis. It can contain
137 // simple or elaborate selection criteria, run algorithms on the data
138 // of the event and typically fill histograms.
140 // The processing can be stopped by calling Abort().
142 // Use fStatus to set the return value of TTree::Process().
144 // The return value is currently not used.
145 //printf("process\n");
148 ////////////////////////////////
150 //////////////////////////////
151 Int_t status = ReadEvent(entry);
152 if (status<0) return status;
153 Int_t ntr = fev->GetNumberOfTracks();
156 //////////////////////////////
157 // Loop over AliESDtrack
158 //////////////////////////////
162 fev->SetESDfriend(fevf);
164 //printf("Number of friends tracks %d\n",fevf->GetNumberOfTracks());
167 for(int itrk=0; itrk<fev->GetNumberOfTracks(); itrk++){
169 fesdTrack = fev->GetTrack(itrk);
170 if(!(nTRDcls = fesdTrack->GetTRDncls())) continue;
171 if(!(fesdTrack->GetFriendTrack())) continue;
172 ffriendTrack = new AliESDfriendTrack(*(fesdTrack->GetFriendTrack()));
175 while((fo = (TObject *)(ffriendTrack->GetCalibObject(icalib++)))){
176 //printf("Name of calibObject %s\n",fo->IsA()->GetName());
177 if(strcmp(fo->IsA()->GetName(), "AliTRDtrack") != 0) continue;
178 //printf("\tfound %s @ 0x%x; calib object %d\n", fo->IsA()->GetName(), fo, icalib-1);
179 ft = (AliTRDtrack *)fo;
181 fcalib->UpdateHistograms(ft);
189 //______________________________________________________________________________________________
190 void AliTRDcalib::SlaveTerminate()
192 // The SlaveTerminate() function is called after all entries or objects
193 // have been processed. When running with PROOF SlaveTerminate() is called
194 // on each slave server.
198 printf("ERROR: Output list not initialized\n");
202 fCH2d = new TH2I(*(fcalib->GetCH2d()));
203 fPH2d = new TProfile2D(*(fcalib->GetPH2d()));
204 fPRF2d = new TProfile2D(*(fcalib->GetPRF2d()));
206 AliTRDCalibraVdriftLinearFit *ju = fcalib->GetVdriftLinearFit();
207 for(Int_t det = 0; det < 540; det++){
208 fVdriftLinear[det] = new TH2F(*(ju->GetLinearFitterHisto(det,kTRUE)));
215 fOutput->Add(fPRF2d);
216 for(Int_t det = 0; det < 540; det++){
217 fOutput->Add(fVdriftLinear[det]);
223 //____________________________________________________________________________________
224 void AliTRDcalib::Terminate()
226 // The Terminate() function is the last function to be called during
227 // a query. It always runs on the client, it can be used to present
228 // the results graphically or save the results to file.
231 printf("InTerminate()\n");
232 if (!fOutput) return;
236 fCH2d = dynamic_cast<TH2I*>(fOutput->FindObject("CH2d"));
240 printf("Error: %s not returned\n","fCH2d");
244 fPH2d = dynamic_cast<TProfile2D*>(fOutput->FindObject("PH2d"));
248 printf("Error: %s not returned\n","fPH2d");
252 fPRF2d = dynamic_cast<TProfile2D*>(fOutput->FindObject("PRF2d"));
256 printf("Error: %s not returned\n","fPRF2d");
261 const char * Name = 0x0;
262 Name = "LFDV%dversion0";
263 TObjArray array(540);
265 for(Int_t det = 0; det < 540; det++){
267 TString Namehisto (Form(Name, det));
268 fVdriftLinear[det] = dynamic_cast<TH2F*>(fOutput->FindObject((const char *)Namehisto));
269 if (!fVdriftLinear[det])
271 printf("Error: %s not returned\n",(const char *)Namehisto);
274 array.AddAt(fVdriftLinear[det],det);
277 AliTRDCalibraVdriftLinearFit vdriftlinearfit = AliTRDCalibraVdriftLinearFit(array);
278 vdriftlinearfit.FillPEArray();
280 gStyle->SetPalette(1);
281 gStyle->SetOptStat(1111);
282 gStyle->SetPadBorderMode(0);
283 gStyle->SetCanvasColor(10);
284 gStyle->SetPadLeftMargin(0.13);
285 gStyle->SetPadRightMargin(0.10);
288 printf("There are %d files analysed\n",fFileNo);
291 TCanvas *u = new TCanvas("u","",50,50,600,800);
294 fCH2d->DrawCopy("lego");
296 fPH2d->DrawCopy("lego");
298 fPRF2d->DrawCopy("lego");
300 TObjArray *arrayE = vdriftlinearfit.GetEArray();
302 Double_t totalsum = 0.0;
303 for(Int_t k = 0; k < 540; k++){
304 TVectorD *h = (TVectorD *) arrayE->UncheckedAt(k);
310 TFile file("Output.root","recreate");
314 //___________________________________________________________________________________________
315 void AliTRDcalib::Init(TTree *tree)
317 // The Init() function is called when the selector needs to initialize
318 // a new tree or chain. Typically here the branch addresses and branch
319 // pointers of the tree will be set.
320 // It is normaly not necessary to make changes to the generated
321 // code, but the routine can be extended by the user if needed.
322 // Init() will be called many times when running on PROOF
323 // (once per file to be processed).
325 // Set branch addresses and branch pointers
328 //if (counter>1) return;
329 tree->SetBranchStatus("*",1);
331 // New AliESDevent format
333 if (!fChain->GetBranch("ESD")){
338 fev = new AliESDEvent();
339 fev->ReadFromTree(tree); // Attach the branch with ESD friends
340 fevf = (AliESDfriend*)fev->FindListObject("AliESDfriend");
341 tree->SetBranchAddress("ESDfriend.",&fevf);
345 fChain->SetBranchAddress("ESD",&fESD);
346 Info("Init","Enter");
348 if (fChain->GetBranch("ESDfriend")) {
349 fChain->SetBranchAddress("ESDfriend",&fevf);
350 Info("Init","V0-ESDfriend.");
353 if (fChain->GetBranch("ESDfriend.")){
354 Info("Init","V1-ESDfriend.");
355 fChain->SetBranchAddress("ESDfriend.",&fevf);
361 //___________________________________________________________________________________________
362 Bool_t AliTRDcalib::Notify()
364 // The Notify() function is called when a new file is opened. This
365 // can be either for a new TTree in a TChain or when when a new TTree
366 // is started when using PROOF. It is normaly not necessary to make changes
367 // to the generated code, but the routine can be extended by the
368 // user if needed. The return value is currently not used.
371 printf ("Processing file no %d\n",fFileNo);
375 //__________________________________________________________________________________
376 Int_t AliTRDcalib::ReadEvent(Long64_t entry){
382 if (!fChain) return -1;
383 if (!fChain->GetTree()) return -1;
385 fChain->GetTree()->GetEntry(entry);
386 } catch (std::bad_alloc) {
387 printf("Pica vyjebana pojebany skurveny kokot piciak\n");
393 Int_t ntracks = (fESD) ? fESD->GetNumberOfTracks() : fev->GetNumberOfTracks();
396 fev->SetESDfriend(fevf);
400 if (!fevf || fevf->GetNumberOfTracks() != ntracks) {
404 catch (std::bad_alloc) {
405 printf("Pica vyjebana pojebany skurveny kokot piciak\n");
411 if (fESD) fESD->SetESDfriend(fevf);