]> git.uio.no Git - u/mrichter/AliRoot.git/blob - ANALYSIS/ANALYSISalice/AliAnalysisTaskBadChunkID.cxx
Updated branch aliroot-master, development and master to
[u/mrichter/AliRoot.git] / ANALYSIS / ANALYSISalice / AliAnalysisTaskBadChunkID.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 // MC bad chunk identifier 
19 // --- david.dobrigkeit.chinellato@cern.ch
20 //
21 // Loops over all chunks and fills a TTree object with a TString locating 
22 // chunk name for each event and a "number of global tracks" variable. 
23 //
24 // TTree is filled event-by-event but has only very few data members, 
25 // so memory consumption should still be reasonable. 
26 //
27 // +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
28
29 class TTree;
30 class TParticle;
31
32 #include <Riostream.h>
33 #include "TList.h"
34 #include "TH1.h"
35 #include "TFile.h"
36 #include "TString.h"
37 #include "AliLog.h"
38 #include "AliESDEvent.h"
39 #include "AliESDtrack.h"
40 #include "AliInputEventHandler.h"
41 #include "AliAnalysisManager.h"
42 //#include "AliMCEventHandler.h"
43 //#include "AliMCEvent.h"
44 //#include "AliStack.h"
45 #include "AliAnalysisTaskBadChunkID.h"
46
47 using std::cout;
48 using std::endl;
49
50 ClassImp(AliAnalysisTaskBadChunkID)
51
52 AliAnalysisTaskBadChunkID::AliAnalysisTaskBadChunkID() 
53 : AliAnalysisTaskSE(), fList(0), fTree(0),
54   fHistNEvents(0),
55   fRunNumber(0),
56   fFileName(0),
57   fNGlobalTracks(0),
58   fNTracks(0)
59 {
60   // Dummy Constructor
61
62 }
63
64 AliAnalysisTaskBadChunkID::AliAnalysisTaskBadChunkID(const char *name) 
65   : AliAnalysisTaskSE(name), fList(0), fTree(0),
66     fHistNEvents(0),
67     fRunNumber(0),
68     fFileName(0),
69     fNGlobalTracks(0),
70     fNTracks(0)
71 {
72   // Constructor
73   // Output slot #0 writes into a TList container (Cascade)
74   DefineOutput(1, TList::Class());
75   DefineOutput(2, TTree::Class());
76 }
77
78
79 AliAnalysisTaskBadChunkID::~AliAnalysisTaskBadChunkID()
80 {
81 //------------------------------------------------
82 // DESTRUCTOR
83 //------------------------------------------------
84
85    if (fList){
86       delete fList;
87       fList = 0x0;
88    }
89    /*
90    if (fTree){
91       delete fTree;
92       fTree = 0x0;
93    }
94    */
95 }
96
97 //________________________________________________________________________
98 void AliAnalysisTaskBadChunkID::UserCreateOutputObjects()
99 {
100
101    
102    // Create histograms
103    OpenFile(1);
104    fList = new TList();
105    fList->SetOwner();  // See http://root.cern.ch/root/html/TCollection.html#TCollection:SetOwner
106
107    if(! fHistNEvents) {
108       fHistNEvents = new TH1F("fHistNEvents", 
109          "NumberOfEvents", 
110          1, 0, 1);              
111       fList->Add(fHistNEvents);
112    }
113
114    OpenFile(2); 
115    // Called once
116
117 //------------------------------------------------
118
119    fTree = new TTree("fTree","V0Candidates");
120
121 //------------------------------------------------
122 // fTree Branch definitions - V0 Tree
123 //------------------------------------------------
124
125 //-----------BASIC-INFO---------------------------
126    /*1*/ fTree->Branch("fNGlobalTracks",&fNGlobalTracks,"fNGlobalTracks/I");    
127    /*2*/ fTree->Branch("fNTracks",&fNTracks,"fNTracks/I");      
128    /*3*/ fTree->Branch("fRunNumber",&fRunNumber,"fRunNumber/I");        
129    /*4*/ fTree->Branch("fFileName",&fFileName,16000,0); 
130
131    //List of Histograms: Normal
132    PostData(1, fList);
133
134    //TTree Object: Saved to base directory. Should cache to disk while saving. 
135    //(Important to avoid excessive memory usage, particularly when merging)
136    PostData(2, fTree);
137
138 }// end UserCreateOutputObjects
139
140
141 //________________________________________________________________________
142 void AliAnalysisTaskBadChunkID::UserExec(Option_t *) 
143 {
144   // Main loop
145   // Called for each event
146
147    AliESDEvent *lESDevent = 0x0;
148    //AliMCEvent  *lMCevent  = 0x0;
149    //AliStack    *lMCstack  = 0x0;
150
151   // Connect to the InputEvent   
152   // After these lines, we should have an ESD/AOD event
153
154    // Appropriate for ESD analysis! 
155       
156    lESDevent = dynamic_cast<AliESDEvent*>( InputEvent() );
157    if (!lESDevent) {
158       AliWarning("ERROR: lESDevent not available \n");
159       return;
160    }
161
162 /* Anyhow not needed for cross-check
163  
164    lMCevent = MCEvent();
165    if (!lMCevent) {
166       Printf("ERROR: Could not retrieve MC event \n");
167       cout << "Name of the file with pb :" <<  fInputHandler->GetTree()->GetCurrentFile()->GetName() << endl;   
168       return;
169    }
170
171    lMCstack = lMCevent->Stack();
172    if (!lMCstack) {
173       Printf("ERROR: Could not retrieve MC stack \n");
174       cout << "Name of the file with pb :" <<  fInputHandler->GetTree()->GetCurrentFile()->GetName() << endl;
175       return;
176    }
177  
178 */
179 //------------------------------------------------
180 // Track Multiplicity Information Acquistion
181 //------------------------------------------------
182
183    Int_t lNTracks = -1; 
184    Int_t lNGlobalTracks = 0;
185
186    lNTracks = lESDevent->GetNumberOfTracks();
187
188 //----- Loop on Tracks --------------------------------------------------------------
189    for (Int_t iCurrentTrack = 0; iCurrentTrack < lNTracks; iCurrentTrack++) 
190    {// This is the begining of the loop on tracks
191       AliESDtrack *lThisTrack=((AliESDEvent*)lESDevent)->GetTrack(iCurrentTrack);
192
193       // kITSrefit refit condition: Global Track
194       if( !(lThisTrack->GetStatus() & AliESDtrack::kITSrefit)) continue; 
195       lNGlobalTracks++;
196    }
197 //----- End Loop on Tracks ----------------------------------------------------------
198
199   fHistNEvents->Fill(0.5); // valid event
200   fNGlobalTracks  = lNGlobalTracks;
201   fNTracks        = lNTracks;
202   fRunNumber      = lESDevent->GetRunNumber();
203
204   //Gymnastics to get the chunk number...
205   TString lFileName = CurrentFileName();
206   //  TObjArray *lLocationArray = lFileName.Tokenize("/");
207   fFileName = fInputHandler->GetTree()->GetCurrentFile()->GetName();
208   //  delete lLocationArray;
209   fTree->Fill();
210
211   //Printf("%i in run %i, Nglob = %i, Ntrack = %i \n",fChunkNumber,fRunNumber,fNGlobalTracks,fNTracks);
212
213    // Post output data.
214   PostData(1, fList);
215   PostData(2, fTree);
216 }
217
218 //________________________________________________________________________
219 void AliAnalysisTaskBadChunkID::Terminate(Option_t *)
220 {
221    // Draw result to the screen
222    // Called once at the end of the query
223
224    // Not interesting at this point.
225 }