1 #define AliTRDcalibV1_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("AliTRDcalibV1.cxx")
22 // Root > T->Process("AliTRDcalibV1.cxx","some options")
23 // Root > T->Process("AliTRDcalibV1.cxx+")
26 #include "AliTRDcalibV1.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 AliTRDcalibV1::AliTRDcalibV1(TTree *) :
60 //G__SetCatchException(0);
62 //_____________________________________________________________________
63 void AliTRDcalibV1::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 AliTRDcalibV1::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 AliTRDcalibV1::CleanESD(){
115 //printf("CleanESD\n");
125 //_________________________________________________________________________________
126 Bool_t AliTRDcalibV1::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");
147 if (!fChain) return kFALSE;
148 //printf("process1\n");
151 nBytes = fChain->GetTree()->GetEntry(entry);
152 //printf("There are %d bytes for these event\n",nBytes);
153 if (!fev || (nBytes == 0)) {
156 if(fev->GetAliESDOld()) fev->CopyFromOldESD();
157 //printf("process2\n");
158 Int_t ntr = fev->GetNumberOfTracks();
159 //printf("Tracks new %d\n",ntr);
161 if (!fevf || (fevf->GetNumberOfTracks()!=ntr)) {
167 fev->SetESDfriend(fevf);
169 //printf("Number of friends tracks %d\n",fevf->GetNumberOfTracks());
172 for(int itrk=0; itrk<fev->GetNumberOfTracks(); itrk++){
174 fesdTrack = fev->GetTrack(itrk);
175 if(!(nTRDcls = fesdTrack->GetTRDncls())) continue;
176 if(!(fesdTrack->GetFriendTrack())) continue;
177 //ffriendTrack = new AliESDfriendTrack(*(fesdTrack->GetFriendTrack()));
178 ffriendTrack = fevf->GetTrack(itrk);
181 while((fo = (TObject *)(ffriendTrack->GetCalibObject(icalib++)))){
182 //printf("Name of calibObject %s\n",fo->IsA()->GetName());
183 if(strcmp(fo->IsA()->GetName(), "AliTRDtrackV1") != 0) continue;
184 //printf("\tfound %s @ 0x%x; calib object %d\n", fo->IsA()->GetName(), fo, icalib-1);
185 ft = (AliTRDtrackV1 *)fo;
187 fcalib->UpdateHistogramsV1(ft);
195 //______________________________________________________________________________________________
196 void AliTRDcalibV1::SlaveTerminate()
198 // The SlaveTerminate() function is called after all entries or objects
199 // have been processed. When running with PROOF SlaveTerminate() is called
200 // on each slave server.
204 printf("ERROR: Output list not initialized\n");
208 fCH2d = new TH2I(*(fcalib->GetCH2d()));
209 fPH2d = new TProfile2D(*(fcalib->GetPH2d()));
210 fPRF2d = new TProfile2D(*(fcalib->GetPRF2d()));
212 AliTRDCalibraVdriftLinearFit *ju = fcalib->GetVdriftLinearFit();
213 for(Int_t det = 0; det < 540; det++){
214 fVdriftLinear[det] = new TH2F(*(ju->GetLinearFitterHisto(det,kTRUE)));
221 fOutput->Add(fPRF2d);
222 for(Int_t det = 0; det < 540; det++){
223 fOutput->Add(fVdriftLinear[det]);
229 //____________________________________________________________________________________
230 void AliTRDcalibV1::Terminate()
232 // The Terminate() function is the last function to be called during
233 // a query. It always runs on the client, it can be used to present
234 // the results graphically or save the results to file.
237 printf("InTerminate()\n");
238 if (!fOutput) return;
242 fCH2d = dynamic_cast<TH2I*>(fOutput->FindObject("CH2d"));
246 printf("Error: %s not returned\n","fCH2d");
250 fPH2d = dynamic_cast<TProfile2D*>(fOutput->FindObject("PH2d"));
254 printf("Error: %s not returned\n","fPH2d");
258 fPRF2d = dynamic_cast<TProfile2D*>(fOutput->FindObject("PRF2d"));
262 printf("Error: %s not returned\n","fPRF2d");
267 const char * Name = 0x0;
268 Name = "LFDV%dversion0";
269 TObjArray array(540);
271 for(Int_t det = 0; det < 540; det++){
273 TString Namehisto (Form(Name, det));
274 fVdriftLinear[det] = dynamic_cast<TH2F*>(fOutput->FindObject((const char *)Namehisto));
275 if (!fVdriftLinear[det])
277 printf("Error: %s not returned\n",(const char *)Namehisto);
280 array.AddAt(fVdriftLinear[det],det);
283 AliTRDCalibraVdriftLinearFit vdriftlinearfit = AliTRDCalibraVdriftLinearFit(array);
284 vdriftlinearfit.FillPEArray();
286 gStyle->SetPalette(1);
287 gStyle->SetOptStat(1111);
288 gStyle->SetPadBorderMode(0);
289 gStyle->SetCanvasColor(10);
290 gStyle->SetPadLeftMargin(0.13);
291 gStyle->SetPadRightMargin(0.10);
294 printf("There are %d files analysed\n",fFileNo);
297 TCanvas *u = new TCanvas("u","",50,50,600,800);
300 fCH2d->DrawCopy("lego");
302 fPH2d->DrawCopy("lego");
304 fPRF2d->DrawCopy("lego");
306 TObjArray *arrayE = vdriftlinearfit.GetEArray();
308 Double_t totalsum = 0.0;
309 for(Int_t k = 0; k < 540; k++){
310 TVectorD *h = (TVectorD *) arrayE->UncheckedAt(k);
316 TFile file("Output.root","recreate");
320 //___________________________________________________________________________________________
321 void AliTRDcalibV1::Init(TTree *tree)
323 // The Init() function is called when the selector needs to initialize
324 // a new tree or chain. Typically here the branch addresses and branch
325 // pointers of the tree will be set.
326 // It is normaly not necessary to make changes to the generated
327 // code, but the routine can be extended by the user if needed.
328 // Init() will be called many times when running on PROOF
329 // (once per file to be processed).
331 // Set branch addresses and branch pointers
334 //if (counter>1) return;
335 tree->SetBranchStatus("*",1);
337 // New AliESDevent format
339 if (!fChain->GetBranch("ESD")){
344 fev = new AliESDEvent();
345 fev->ReadFromTree(tree); // Attach the branch with ESD friends
346 fevf = (AliESDfriend*)fev->FindListObject("AliESDfriend");
347 tree->SetBranchAddress("ESDfriend.",&fevf);
351 fChain->SetBranchAddress("ESD",&fESD);
352 Info("Init","Enter");
354 if (fChain->GetBranch("ESDfriend")) {
355 fChain->SetBranchAddress("ESDfriend",&fevf);
356 Info("Init","V0-ESDfriend.");
359 if (fChain->GetBranch("ESDfriend.")){
360 Info("Init","V1-ESDfriend.");
361 fChain->SetBranchAddress("ESDfriend.",&fevf);
367 //___________________________________________________________________________________________
368 Bool_t AliTRDcalibV1::Notify()
370 // The Notify() function is called when a new file is opened. This
371 // can be either for a new TTree in a TChain or when when a new TTree
372 // is started when using PROOF. It is normaly not necessary to make changes
373 // to the generated code, but the routine can be extended by the
374 // user if needed. The return value is currently not used.
377 printf ("Processing file no %d\n",fFileNo);
381 //__________________________________________________________________________________
382 Int_t AliTRDcalibV1::ReadEvent(Long64_t entry){
388 if (!fChain) return -1;
389 if (!fChain->GetTree()) return -1;
391 fChain->GetTree()->GetEntry(entry);
392 } catch (std::bad_alloc) {
393 printf("Pica vyjebana pojebany skurveny kokot piciak\n");
399 Int_t ntracks = (fESD) ? fESD->GetNumberOfTracks() : fev->GetNumberOfTracks();
402 fev->SetESDfriend(fevf);
406 if (!fevf || fevf->GetNumberOfTracks() != ntracks) {
410 catch (std::bad_alloc) {
411 printf("Pica vyjebana pojebany skurveny kokot piciak\n");
417 if (fESD) fESD->SetESDfriend(fevf);