Patch for the division par zero in fQ[1]. To be investigated
[u/mrichter/AliRoot.git] / MUON / AliMUONData.cxx
CommitLineData
50837721 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/* $Id$ */
6309cf6e 17
6309cf6e 18//Root includes
1a1cdff8 19#include "TNamed.h"
6309cf6e 20//AliRoot includes
1a1cdff8 21#include "AliLoader.h"
22#include "AliMUONConstants.h"
6309cf6e 23#include "AliMUONData.h"
24#include "AliMUONDigit.h"
25#include "AliMUONHit.h"
26#include "AliMUONLocalTrigger.h"
27#include "AliMUONGlobalTrigger.h"
28#include "AliMUONRawCluster.h"
dcd2690d 29#include "AliMUONTrack.h"
6309cf6e 30
31ClassImp(AliMUONData)
32
33//_____________________________________________________________________________
34AliMUONData::AliMUONData():TNamed()
35{
36 fLoader = 0x0;
37 fHits = 0x0; // One event in treeH per primary track
38 fDigits = 0x0; // One event in treeH per detection plane
ce3f5e87 39 fNdigits = 0x0;
6309cf6e 40 fRawClusters = 0x0; //One event in TreeR/RawclusterBranch per tracking detection plane
41 fGlobalTrigger = 0x0; //! List of Global Trigger 1st event in TreeR/GlobalTriggerBranch
dcd2690d 42 fLocalTrigger = 0x0; //! List of Local Trigger, 1st event in TreeR/LocalTriggerBranch
43 fRecTracks = 0x0;
6309cf6e 44//default constructor
45}
46//_____________________________________________________________________________
47AliMUONData::AliMUONData(AliLoader * loader, const char* name, const char* title):
48 TNamed(name,title)
49{
50 fLoader = loader;
51 fHits = new TClonesArray("AliMUONHit",1000);
52 fNhits = 0;
53 fDigits = new TObjArray(AliMUONConstants::NCh());
54 fNdigits = new Int_t[AliMUONConstants::NCh()];
55 for (Int_t iDetectionPlane=0; iDetectionPlane<AliMUONConstants::NCh() ;iDetectionPlane++) {
56 fDigits->AddAt(new TClonesArray("AliMUONDigit",10000),iDetectionPlane);
57 fNdigits[iDetectionPlane]=0;
58 }
59 fRawClusters = new TObjArray(AliMUONConstants::NTrackingCh());
60 fNrawclusters = new Int_t[AliMUONConstants::NTrackingCh()];
61 for (Int_t iDetectionPlane=0; iDetectionPlane<AliMUONConstants::NTrackingCh();iDetectionPlane++) {
62 fRawClusters->AddAt(new TClonesArray("AliMUONRawCluster",10000),iDetectionPlane);
63 fNrawclusters[iDetectionPlane]=0;
64 }
65 fGlobalTrigger = new TClonesArray("AliMUONGlobalTrigger",1);
66 fNglobaltrigger =0;
67 fLocalTrigger = new TClonesArray("AliMUONLocalTrigger",234);
68 fNlocaltrigger = 0;
dcd2690d 69 fRecTracks = new TClonesArray("AliMUONTrack", 10);
70 fNrectracks = 0; // really needed or GetEntriesFast sufficient ????
6309cf6e 71 //default constructor
72}
73//_____________________________________________________________________________
74AliMUONData::AliMUONData(const AliMUONData& rMUONData):TNamed(rMUONData)
75{
76 // Dummy copy constructor
77 ;
78}
79//_____________________________________________________________________________
80AliMUONData::~AliMUONData()
81{
82 if (fHits) {
83 fHits->Delete();
84 delete fHits;
85 }
86 if (fDigits) {
87 fDigits->Delete();
88 delete fDigits;
89 }
90 if (fRawClusters) {
91 fRawClusters->Delete();
92 delete fRawClusters;
93 }
94 if (fGlobalTrigger){
95 fGlobalTrigger->Delete();
96 delete fGlobalTrigger;
97 }
98 if (fLocalTrigger){
99 fLocalTrigger->Delete();
100 delete fLocalTrigger;
101 }
dcd2690d 102 if (fRecTracks){
103 fRecTracks->Delete();
104 delete fRecTracks;
105 }
6309cf6e 106 //detructor
107}
108//_____________________________________________________________________________
109void AliMUONData::AddDigit(Int_t id, Int_t *tracks, Int_t *charges, Int_t *digits)
110{
111 //
112 // Add a MUON digit to the list of Digits of the detection plane id
113 //
1a1cdff8 114 TClonesArray &ldigits = * Digits(id) ;
6309cf6e 115 new(ldigits[fNdigits[id]++]) AliMUONDigit(tracks,charges,digits);
116}
117//_____________________________________________________________________________
118void AliMUONData::AddGlobalTrigger(Int_t *singlePlus, Int_t *singleMinus,
119 Int_t *singleUndef,
120 Int_t *pairUnlike, Int_t *pairLike)
121{
122 // add a MUON Global Trigger to the list (only one GlobalTrigger per event !)
123 TClonesArray &globalTrigger = *fGlobalTrigger;
124 new(globalTrigger[fNglobaltrigger++])
125 AliMUONGlobalTrigger(singlePlus, singleMinus, singleUndef, pairUnlike, pairLike);
126}
127//_____________________________________________________________________________
128void AliMUONData::AddHit(Int_t fIshunt, Int_t track, Int_t iChamber,
129 Int_t idpart, Float_t X, Float_t Y, Float_t Z,
130 Float_t tof, Float_t momentum, Float_t theta,
131 Float_t phi, Float_t length, Float_t destep)
132{
133 TClonesArray &lhits = *fHits;
134 new(lhits[fNhits++]) AliMUONHit(fIshunt, track, iChamber,
135 idpart, X, Y, Z,
136 tof, momentum, theta,
137 phi, length, destep);
138}
139//____________________________________________________________________________
140void AliMUONData::AddLocalTrigger(Int_t *localtr)
141{
142 // add a MUON Local Trigger to the list
143 TClonesArray &localTrigger = *fLocalTrigger;
144 new(localTrigger[fNlocaltrigger++]) AliMUONLocalTrigger(localtr);
145}
146//_____________________________________________________________________________
147void AliMUONData::AddRawCluster(Int_t id, const AliMUONRawCluster& c)
148{
149 //
150 // Add a MUON rawcluster to the list in the detection plane id
151 //
152 TClonesArray &lrawcl = *((TClonesArray*) fRawClusters->At(id));
153 new(lrawcl[fNrawclusters[id]++]) AliMUONRawCluster(c);
154}
dcd2690d 155//_____________________________________________________________________________
156void AliMUONData::AddRecTrack(const AliMUONTrack& track)
157{
158 //
159 // Add a MUON rectrack
160 //
161 TClonesArray &lrectracks = *fRecTracks;
162 new(lrectracks[fNrectracks++]) AliMUONTrack(track);
163}
ce3f5e87 164//____________________________________________________________________________
c1d45bdf 165Bool_t AliMUONData::IsRawClusterBranchesInTree()
166{
167 if (TreeR()==0x0) {
168 Error("TreeR","No treeR in memory");
169 return kFALSE;
170 }
171 else {
172 char branchname[30];
173 sprintf(branchname,"%sRawClusters1",GetName());
174 TBranch * branch = 0x0;
175 branch = TreeR()->GetBranch(branchname);
176 if (branch) return kTRUE;
177 else return kFALSE;
178 }
179}
180//____________________________________________________________________________
181Bool_t AliMUONData::IsTriggerBranchesInTree()
182{
183 if (TreeR()==0x0) {
184 Error("TreeR","No treeR in memory");
185 return kFALSE;
186 }
187 else {
188 char branchname[30];
189 sprintf(branchname,"%sLocalTrigger",GetName());
190 TBranch * branch = 0x0;
191 branch = TreeR()->GetBranch(branchname);
192 if (branch) return kTRUE;
193 else return kFALSE;
194 }
195}
196//____________________________________________________________________________
1a1cdff8 197void AliMUONData::Fill(Option_t* option)
198{
199 // Method to fill the trees
200 const char *cH = strstr(option,"H");
201 const char *cD = strstr(option,"D"); // Digits branches in TreeD
202 const char *cRC = strstr(option,"RC"); // RawCluster branches in TreeR
203 const char *cGLT = strstr(option,"GLT"); // Global and Local Trigger branches in TreeR
204 const char *cRT = strstr(option,"RT"); // Reconstructed Track in TreeT
205 //const char *cRP = strstr(option,"RP"); // Reconstructed Particle in TreeP
206
207 char branchname[30];
208 TBranch * branch = 0x0;
209
210 //
211 // Filling TreeH
212 if ( TreeH() && cH ) {
213 TreeH()->Fill();
214 }
215 //
216 // Filling TreeD
217 if ( TreeD() && cD) {
218 TreeD()->Fill();
219 }
c1d45bdf 220
1a1cdff8 221 //
222 // filling rawclusters
c1d45bdf 223 if ( TreeR() && cRC ) {
224 if ( IsTriggerBranchesInTree() ) {
225 // Branch per branch filling
226 for (int i=0; i<AliMUONConstants::NTrackingCh(); i++) {
227 sprintf(branchname,"%sRawClusters%d",GetName(),i+1);
228 branch = TreeR()->GetBranch(branchname);
229 branch->Fill();
230 }
231 }
232 else TreeR()->Fill();
1a1cdff8 233 }
c1d45bdf 234
1a1cdff8 235 //
236 // filling trigger
237 if ( TreeR() && cGLT) {
346357f4 238 if (IsRawClusterBranchesInTree()) {
c1d45bdf 239 // Branch per branch filling
240 sprintf(branchname,"%sLocalTrigger",GetName());
241 branch = TreeR()->GetBranch(branchname);
242 branch->Fill();
243 sprintf(branchname,"%sGlobalTrigger",GetName());
244 branch = TreeR()->GetBranch(branchname);
245 branch->Fill();
246 }
247 else TreeR()->Fill();
1a1cdff8 248 }
249 //
250 // filling tracks
251 if ( TreeT() && cRT ) {
252 sprintf(branchname,"%sTrack",GetName());
253 branch = TreeT()->GetBranch(branchname);
254 branch->Fill();
255 }
256}
257//_____________________________________________________________________________
6309cf6e 258void AliMUONData::MakeBranch(Option_t* option)
259{
260 //
261 // Create Tree branches for the MUON.
262 //
263 const Int_t kBufferSize = 4000;
264 char branchname[30];
265
266 const char *cH = strstr(option,"H");
267 const char *cD = strstr(option,"D"); // Digits branches in TreeD
268 const char *cRC = strstr(option,"RC"); // RawCluster branches in TreeR
269 const char *cGLT = strstr(option,"GLT"); // Global and Local Trigger branches in TreeR
270 const char *cRT = strstr(option,"RT"); // Reconstructed Track in TreeT
271 const char *cRP = strstr(option,"RP"); // Reconstructed Particle in TreeP
272
273 TBranch * branch = 0x0;
274
275 // Creating Branches for Hits
276 if (TreeH() && cH) {
277 if (fHits == 0x0) fHits = new TClonesArray("AliMUONHit",1000);
278 fNhits = 0;
279 sprintf(branchname,"%sHits",GetName());
280 branch = TreeH()->GetBranch(branchname);
281 if (branch) {
282 Info("MakeBranch","Branch %s is already in tree.",GetName());
283 return ;
284 }
285 branch = TreeH()->Branch(branchname,&fHits,kBufferSize);
286 Info("MakeBranch","Making Branch %s for hits \n",branchname);
287 }
288
289 //Creating Branches for Digits
290 if (TreeD() && cD ) {
291 // one branch for digits per chamber
292 if (fDigits == 0x0) {
ce3f5e87 293 fDigits = new TObjArray(AliMUONConstants::NCh());
6309cf6e 294 for (Int_t iDetectionPlane=0; iDetectionPlane<AliMUONConstants::NCh() ;iDetectionPlane++) {
295 fDigits->AddAt(new TClonesArray("AliMUONDigit",10000),iDetectionPlane);
ce3f5e87 296 }
297 }
298 if (fNdigits == 0x0) {
299 fNdigits = new Int_t[AliMUONConstants::NCh()];
300 for (Int_t iDetectionPlane=0; iDetectionPlane<AliMUONConstants::NCh() ;iDetectionPlane++) {
6309cf6e 301 fNdigits[iDetectionPlane]=0;
302 }
303 }
304 for (Int_t iDetectionPlane=0; iDetectionPlane<AliMUONConstants::NCh() ;iDetectionPlane++) {
305 sprintf(branchname,"%sDigits%d",GetName(),iDetectionPlane+1);
306 branch = 0x0;
307 branch = TreeD()->GetBranch(branchname);
308 if (branch) {
309 Info("MakeBranch","Branch %s is already in tree.",GetName());
310 return;
311 }
1a1cdff8 312 TClonesArray * digits = Digits(iDetectionPlane);
ce3f5e87 313 branch = TreeD()->Branch(branchname, &digits, kBufferSize);
6309cf6e 314 Info("MakeBranch","Making Branch %s for digits in detection plane %d\n",branchname,iDetectionPlane+1);
315 }
316 }
317
318 if (TreeR() && cRC ) {
319 // one branch for raw clusters per tracking detection plane
320 //
321 Int_t i;
322 if (fRawClusters == 0x0) {
323 fRawClusters = new TObjArray(AliMUONConstants::NTrackingCh());
6309cf6e 324 for (Int_t i=0; i<AliMUONConstants::NTrackingCh();i++) {
325 fRawClusters->AddAt(new TClonesArray("AliMUONRawCluster",10000),i);
ce3f5e87 326 }
327 }
328
329 if (fNrawclusters == 0x0) {
330 fNrawclusters= new Int_t[AliMUONConstants::NTrackingCh()];
331 for (Int_t i=0; i<AliMUONConstants::NTrackingCh();i++) {
6309cf6e 332 fNrawclusters[i]=0;
333 }
334 }
335
336 for (i=0; i<AliMUONConstants::NTrackingCh() ;i++) {
337 sprintf(branchname,"%sRawClusters%d",GetName(),i+1);
338 branch = 0x0;
339 branch = TreeR()->GetBranch(branchname);
340 if (branch) {
341 Info("MakeBranch","Branch %s is already in tree.",GetName());
342 return;
343 }
344 branch = TreeR()->Branch(branchname, &((*fRawClusters)[i]),kBufferSize);
345 Info("MakeBranch","Making Branch %s for rawcluster in detection plane %d\n",branchname,i+1);
346 }
347 }
348
349 if (TreeR() && cGLT ) {
350 //
351 // one branch for global trigger
352 //
353 sprintf(branchname,"%sGlobalTrigger",GetName());
354 branch = 0x0;
355
356 if (fGlobalTrigger == 0x0) {
357 fGlobalTrigger = new TClonesArray("AliMUONGlobalTrigger",1);
358 fNglobaltrigger = 0;
359 }
360 branch = TreeR()->GetBranch(branchname);
361 if (branch) {
362 Info("MakeBranch","Branch %s is already in tree.",GetName());
363 return ;
364 }
365 branch = TreeR()->Branch(branchname, &fGlobalTrigger, kBufferSize);
366 Info("MakeBranch", "Making Branch %s for Global Trigger\n",branchname);
367
368 //
369 // one branch for local trigger
370 //
371 sprintf(branchname,"%sLocalTrigger",GetName());
372 branch = 0x0;
373
374 if (fLocalTrigger == 0x0) {
375 fLocalTrigger = new TClonesArray("AliMUONLocalTrigger",234);
376 fNlocaltrigger = 0;
377 }
378 branch = TreeR()->GetBranch(branchname);
379 if (branch) {
380 Info("MakeBranch","Branch %s is already in tree.",GetName());
381 return;
382 }
383 branch = TreeR()->Branch(branchname, &fLocalTrigger, kBufferSize);
384 Info("MakeBranch", "Making Branch %s for Global Trigger\n",branchname);
385 }
386
dcd2690d 387 if (TreeT() && cRT ) {
388 if (fRecTracks == 0x0) fRecTracks = new TClonesArray("AliMUONTrack",10);
389 fNrectracks = 0;
390 sprintf(branchname,"%sTrack",GetName());
391 branch = TreeT()->GetBranch(branchname);
392 if (branch) {
393 Info("MakeBranch","Branch %s is already in tree.",GetName());
394 return ;
395 }
396 branch = TreeT()->Branch(branchname,&fRecTracks,kBufferSize);
397 Info("MakeBranch","Making Branch %s for tracks \n",branchname);
398 }
399
400 if (TreeP() && cRP ) {
6309cf6e 401 Info("MakeBranch","Making Branch for TreeP is not yet ready. \n");
402 }
403}
404
405//____________________________________________________________________________
406void AliMUONData::ResetDigits()
407{
408 //
409 // Reset number of digits and the digits array for this detector
410 //
411 if (fDigits == 0x0) return;
412 for ( int i=0;i<AliMUONConstants::NCh();i++ ) {
413 if ((*fDigits)[i]) ((TClonesArray*)fDigits->At(i))->Clear();
414 if (fNdigits) fNdigits[i]=0;
415 }
416}
417//______________________________________________________________________________
418void AliMUONData::ResetHits()
419{
420 // Reset number of clusters and the cluster array for this detector
421 fNhits = 0;
422 if (fHits) fHits->Clear();
423}
424//_______________________________________________________________________________
425void AliMUONData::ResetRawClusters()
426{
427 // Reset number of raw clusters and the raw clust array for this detector
428 //
429 for ( int i=0;i<AliMUONConstants::NTrackingCh();i++ ) {
430 if ((*fRawClusters)[i]) ((TClonesArray*)fRawClusters->At(i))->Clear();
431 if (fNrawclusters) fNrawclusters[i]=0;
432 }
433}
434//_______________________________________________________________________________
435void AliMUONData::ResetTrigger()
436{
437 // Reset Local and Global Trigger
438 fNglobaltrigger = 0;
439 if (fGlobalTrigger) fGlobalTrigger->Clear();
440 fNlocaltrigger = 0;
441 if (fLocalTrigger) fLocalTrigger->Clear();
442}
dcd2690d 443//____________________________________________________________________________
444void AliMUONData::ResetRecTracks()
445{
446 // Reset tracks information
447 fNrectracks = 0;
448 if (fRecTracks) fRecTracks->Clear();
449}
6309cf6e 450//_____________________________________________________________________________
ce3f5e87 451void AliMUONData::SetTreeAddress(Option_t* option)
6309cf6e 452{
ce3f5e87 453 const char *cH = strstr(option,"H");
454 const char *cD = strstr(option,"D"); // Digits branches in TreeD
455 const char *cRC = strstr(option,"RC"); // RawCluster branches in TreeR
456 const char *cGLT = strstr(option,"GLT"); // Global and Local Trigger branches in TreeR
dcd2690d 457 const char *cRT = strstr(option,"RT"); // Reconstructed Track in TreeT
ce3f5e87 458 //const char *cRP = strstr(option,"RP"); // Reconstructed Particle in TreeP
459
6309cf6e 460 // Set branch address for the Hits, Digits, RawClusters, GlobalTrigger and LocalTrigger Tree.
461 char branchname[30];
462 TBranch * branch = 0x0;
463
464 //
465 // Branch address for hit tree
ce3f5e87 466 if ( TreeH() && cH ) {
6309cf6e 467 if (fHits == 0x0) fHits = new TClonesArray("AliMUONHit",1000);
468 fNhits =0;
469 }
ce3f5e87 470 if (TreeH() && fHits && cH) {
6309cf6e 471 sprintf(branchname,"%sHits",GetName());
472 branch = TreeH()->GetBranch(branchname);
473 if (branch) {
474 Info("SetTreeAddress","(%s) Setting for Hits",GetName());
475 branch->SetAddress(&fHits);
476 }
477 else { //can be invoked before branch creation
478 Warning("SetTreeAddress","(%s) Failed for Hits. Can not find branch in tree.",GetName());
479 }
480 }
481
482 //
483 // Branch address for digit tree
ce3f5e87 484 if ( TreeD() && cD) {
6309cf6e 485 if (fDigits == 0x0) {
486 fDigits = new TObjArray(AliMUONConstants::NCh());
487 fNdigits= new Int_t[AliMUONConstants::NCh()];
488 for (Int_t i=0; i<AliMUONConstants::NCh() ;i++) {
489 fDigits->AddAt(new TClonesArray("AliMUONDigit",10000),i);
490 fNdigits[i]=0;
491 }
492 }
493 }
494
ce3f5e87 495 if (TreeD() && fDigits && cD) {
6309cf6e 496 for (int i=0; i<AliMUONConstants::NCh(); i++) {
497 sprintf(branchname,"%sDigits%d",GetName(),i+1);
498 branch = TreeD()->GetBranch(branchname);
1a1cdff8 499 TClonesArray * digits = Digits(i);
ce3f5e87 500 if (branch) branch->SetAddress( &digits );
6309cf6e 501 else Warning("SetTreeAddress","(%s) Failed for Digits Detection plane %d. Can not find branch in tree.",GetName(),i);
502 }
503 }
504
505 //
506 // Branch address for rawclusters, globaltrigger and local trigger tree
507 if (TreeR() ) {
ce3f5e87 508 if (fRawClusters == 0x0 && cRC) {
6309cf6e 509 fRawClusters = new TObjArray(AliMUONConstants::NTrackingCh());
510 fNrawclusters= new Int_t[AliMUONConstants::NTrackingCh()];
511 for (Int_t i=0; i<AliMUONConstants::NTrackingCh();i++) {
512 fRawClusters->AddAt(new TClonesArray("AliMUONRawCluster",10000),i);
513 fNrawclusters[i]=0;
514 }
515 }
ce3f5e87 516 if (fLocalTrigger == 0x0 && cGLT) {
6309cf6e 517 fLocalTrigger = new TClonesArray("AliMUONLocalTrigger",234);
518 }
ce3f5e87 519 if (fGlobalTrigger== 0x0 && cGLT) {
6309cf6e 520 fGlobalTrigger = new TClonesArray("AliMUONGlobalTrigger",1);
521 }
522
523 }
ce3f5e87 524 if ( TreeR() && fRawClusters && cRC) {
6309cf6e 525 for (int i=0; i<AliMUONConstants::NTrackingCh(); i++) {
526 sprintf(branchname,"%sRawClusters%d",GetName(),i+1);
527 if (fRawClusters) {
528 branch = TreeR()->GetBranch(branchname);
529 if (branch) branch->SetAddress(&((*fRawClusters)[i]));
530 else Warning("SetTreeAddress","(%s) Failed for RawClusters Detection plane %d. Can not find branch in tree.",GetName(),i);
531 }
532 }
533 }
ce3f5e87 534 if ( TreeR() && fLocalTrigger && cGLT) {
6309cf6e 535 sprintf(branchname,"%sLocalTrigger",GetName());
536 branch = TreeR()->GetBranch(branchname);
537 if (branch) branch->SetAddress(&fLocalTrigger);
538 else Warning("SetTreeAddress","(%s) Failed for LocalTrigger. Can not find branch in tree.",GetName());
539 }
ce3f5e87 540 if ( TreeR() && fGlobalTrigger && cGLT) {
6309cf6e 541 sprintf(branchname,"%sGlobalTrigger",GetName());
542 branch = TreeR()->GetBranch(branchname);
543 if (branch) branch->SetAddress(&fGlobalTrigger);
544 else Warning("SetTreeAddress","(%s) Failed for LocalTrigger. Can not find branch in tree.",GetName());
545 }
dcd2690d 546
547 if ( TreeT() && fRecTracks && cRT ) {
548 sprintf(branchname,"%sTrack",GetName());
549 branch = TreeT()->GetBranch(branchname);
550 if (branch) branch->SetAddress(&fRecTracks);
551 else Warning("SetTreeAddress","(%s) Failed for Tracks. Can not find branch in tree.",GetName());
552 }
6309cf6e 553}
554//_____________________________________________________________________________