1 /**************************************************************************
2 * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
4 * Author: The ALICE Off-line Project. *
5 * Contributors are mentioned in the code where appropriate. *
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 **************************************************************************/
18 /// \class AliMUONSimData
20 /// Class containing MUON data: hits, digits, rawclusters, globaltrigger, localtrigger, etc ..
21 /// The classe makes the lik between the MUON data lists and the event trees from loaders
23 /// \author Gines Martinez, Subatech, September 2003
26 #include "AliMUONSimData.h"
27 #include "AliMUONDataIterator.h"
28 #include "AliMUONConstants.h"
29 #include "AliMUONHit.h"
30 #include "AliMUONDigit.h"
31 #include "AliMUONGlobalTrigger.h"
32 #include "AliMUONLocalTrigger.h"
33 #include "AliMUONRegionalTrigger.h"
34 #include "AliMUONTriggerCrateStore.h"
35 #include "AliMUONTriggerCircuit.h"
36 #include "AliMUONGeometryTransformer.h"
37 #include "AliMUONRawCluster.h"
39 // This is from rec, classes in base should not depend on rec !!!
40 //#include "AliMUONTrack.h"
41 //#include "AliMUONTriggerTrack.h"
43 #include "AliRunLoader.h"
48 #include <TParticle.h>
50 #include <Riostream.h>
54 ClassImp(AliMUONSimData)
57 //_____________________________________________________________________________
58 AliMUONSimData::AliMUONSimData()
65 /// Default constructor
67 //_____________________________________________________________________________
68 AliMUONSimData::AliMUONSimData(AliLoader * loader, const char* name, const char* title)
69 : AliMUONData(loader, name, title),
75 /// Standard constructor
78 //_____________________________________________________________________________
79 AliMUONSimData::AliMUONSimData(const char* galiceFile)
80 : AliMUONData(galiceFile, "MUONFolderSim"),
86 /// Constructor for loading data from gAlice file
89 //_____________________________________________________________________________
90 AliMUONSimData::~AliMUONSimData()
92 /// Destructor for AliMUONSimData
104 //____________________________________________________________________________
105 void AliMUONSimData::AddHit(Int_t fIshunt, Int_t track, Int_t detElemId,
106 Int_t idpart, Float_t X, Float_t Y, Float_t Z,
107 Float_t tof, Float_t momentum, Float_t theta,
108 Float_t phi, Float_t length, Float_t destep,
109 Float_t Xref,Float_t Yref,Float_t Zref)
111 /// Add new hit to the hit list
113 TClonesArray &lhits = *fHits;
114 new(lhits[fNhits++]) AliMUONHit(fIshunt, track, detElemId,
116 tof, momentum, theta,
121 //_____________________________________________________________________________
122 void AliMUONSimData::AddSDigit(Int_t id, const AliMUONDigit& Sdigit)
124 /// Add a MUON Sdigit to the list of SDigits of the detection plane id
126 TClonesArray &lSdigits = * SDigits(id) ;
127 new(lSdigits[fNSdigits[id]++]) AliMUONDigit(Sdigit);
130 //____________________________________________________________________________
131 TClonesArray* AliMUONSimData::SDigits(Int_t DetectionPlane) const
133 /// Getting List of SDigits
136 return ( (TClonesArray*) fSDigits->At(DetectionPlane) );
141 //____________________________________________________________________________
142 void AliMUONSimData::FillOwn(Option_t* option)
144 /// Method to fill the trees
146 const char *cH = strstr(option,"H");
147 //const char *cS = strstr(option,"S"); // SDigits branches in TreeS
149 //const char *cRP = strstr(option,"RP"); // Reconstructed Particle in TreeP
165 //_____________________________________________________________________________
166 void AliMUONSimData::MakeOwnBranch(Option_t* option)
168 /// Create Tree branches for the MUON.
170 const Int_t kBufferSize = 4000;
173 //Setting Data Container
174 SetDataContainer(option);
176 const char *cH = strstr(option,"H");
177 //const char *cS = strstr(option,"S"); // Digits branches in TreeS
179 TBranch * branch = 0x0;
181 // Creating Branches for Hits
183 sprintf(branchname,"%sHits",GetName());
184 branch = TreeH()->GetBranch(branchname);
186 AliInfo(Form("MakeBranch","Branch %s is already in tree.",branchname));
189 branch = TreeH()->Branch(branchname,&fHits,kBufferSize);
190 //Info("MakeBranch","Making Branch %s for hits \n",branchname);
193 //Creating Branches for SDigits
194 if (TreeS() && cS ) {
195 // one branch for Sdigits per chamber
196 for (Int_t iDetectionPlane=0; iDetectionPlane<AliMUONConstants::NCh() ;iDetectionPlane++) {
197 sprintf(branchname,"%sSDigits%d",GetName(),iDetectionPlane+1);
199 branch = TreeS()->GetBranch(branchname);
201 AliInfo(Form("Branch %s is already in tree.",branchname));
204 TClonesArray * sdigits = SDigits(iDetectionPlane);
205 branch = TreeS()->Branch(branchname, &sdigits, kBufferSize,1);
206 //Info("MakeBranch","Making Branch %s for sdigits in detection plane %d\n",branchname,iDetectionPlane+1);
212 //____________________________________________________________________________
213 void AliMUONSimData::SetOwnDataContainer(Option_t* option)
215 /// Setting data containers of muon data
217 const char *cH = strstr(option,"H");
218 //const char *cS = strstr(option,"S"); // SDigits
219 //const char *cRP = strstr(option,"RP"); // Reconstructed Particles
220 AliDebug(1,Form("option=%s",option));
222 // Clones array for hits
225 fHits = new TClonesArray("AliMUONHit",1000);
231 // Container for Sdigits
233 if (fSDigits == 0x0) {
234 AliDebug(1,"Creating fSDigits TObjArray");
235 fSDigits = new TObjArray(AliMUONConstants::NCh());
236 fNSdigits= new Int_t[AliMUONConstants::NCh()];
237 for (Int_t i=0; i<AliMUONConstants::NCh() ;i++) {
238 TClonesArray* a = new TClonesArray("AliMUONDigit",10000);
240 fSDigits->AddAt(a,i);
241 AliDebug(1,Form("fSDigits[%d]=%p",i,a));
246 AliDebug(1,Form("fSDigits already there = %p",fSDigits));
253 //____________________________________________________________________________
254 void AliMUONSimData::SetOwnTreeAddress(Option_t* option)
256 // Setting Data containers
257 SetOwnDataContainer(option);
259 /// Setting Addresses to the events trees
261 const char *cH = strstr(option,"H");
262 //const char *cS = strstr(option,"S"); // SDigits branches in TreeS
264 // Set branch address for the Hits, Digits, RawClusters, GlobalTrigger and LocalTrigger Tree.
266 TBranch * branch = 0x0;
268 AliDebug(1,Form("option=%s",option));
270 // Branch address for hit tree
271 if (TreeH() && fHits && cH) {
272 sprintf(branchname,"%sHits",GetName());
273 branch = TreeH()->GetBranch(branchname);
275 // Info("SetTreeAddress","(%s) Setting for Hits",GetName());
276 branch->SetAddress(&fHits);
278 else { //can be invoked before branch creation
279 //AliWarning(Form("(%s) Failed for Hits. Can not find branch in tree.",GetName()));
284 // Branch address for Sdigit tree
285 if (TreeS() && fSDigits && cS) {
286 AliDebug(1,"Setting branch addresses");
287 for (int i=0; i<AliMUONConstants::NCh(); i++) {
288 sprintf(branchname,"%sSDigits%d",GetName(),i+1);
290 AliDebug(1,Form("TreeS=%p for ich=%d branchname=%s",
291 TreeS(),i,branchname));
292 branch = TreeS()->GetBranch(branchname);
293 TClonesArray * sdigits = SDigits(i);
294 if (branch) branch->SetAddress( &sdigits );
295 else AliWarning(Form("(%s) Failed for SDigits Detection plane %d. Can not find branch in tree.",GetName(),i));
302 //____________________________________________________________________________
303 void AliMUONSimData::Fill(Option_t* option)
305 /// Method to fill the trees
307 AliMUONData::Fill(option);
311 //_____________________________________________________________________________
312 void AliMUONSimData::MakeBranch(Option_t* option)
314 /// Create Tree branches for the MUON.
316 AliMUONData::MakeBranch(option);
317 MakeOwnBranch(option);
320 //____________________________________________________________________________
321 void AliMUONSimData::SetDataContainer(Option_t* option)
323 /// Setting data containers of muon data
325 AliMUONData::SetDataContainer(option);
326 SetOwnDataContainer(option);
329 //____________________________________________________________________________
330 void AliMUONSimData::SetTreeAddress(Option_t* option)
332 /// Setting Addresses to the events trees
334 // Setting Data containers
335 SetDataContainer(option);
337 AliMUONData::SetTreeAddress(option);
338 SetOwnTreeAddress(option);
341 //____________________________________________________________________________
343 AliMUONSimData::GetNtracks() const
345 /// Get number of entries in hits three
348 if (fLoader && fLoader->TreeH())
349 ntrk = (Int_t) fLoader->TreeH()->GetEntries();
353 //____________________________________________________________________________
354 void AliMUONSimData::ResetSDigits()
356 /// Reset number of Sdigits and the Sdigits array for this detector
358 if (fSDigits == 0x0) return;
359 for ( int i=0;i<AliMUONConstants::NCh();i++ ) {
360 if ((*fSDigits)[i]) ((TClonesArray*)fSDigits->At(i))->Clear();
361 if (fNSdigits) fNSdigits[i]=0;
365 //______________________________________________________________________________
366 void AliMUONSimData::ResetHits()
368 /// Reset number of clusters and the cluster array for this detector
371 if (fHits) fHits->Clear();
374 //_____________________________________________________________________________
376 AliMUONSimData::DumpKine(Int_t event2Check)
380 fRunLoader->LoadKinematics("READ");
382 Int_t nevents = fRunLoader->GetNumberOfEvents();
383 for (Int_t ievent=0; ievent<nevents; ievent++) { // Event loop
384 if ( event2Check != 0 ) ievent=event2Check;
386 // Getting event ievent
387 fRunLoader->GetEvent(ievent);
389 // Stack of particle for this event
390 AliStack* stack = fRunLoader->Stack();
392 Int_t nparticles = (Int_t) fRunLoader->Stack()->GetNtrack();
393 printf(">>> Event %d, Number of particles is %d \n", ievent, nparticles);
395 for (Int_t iparticle=0; iparticle<nparticles; iparticle++) {
396 stack->Particle(iparticle)->Print("");
398 if (event2Check!=0) ievent=nevents;
400 fRunLoader->UnloadKinematics();
404 //_____________________________________________________________________________
406 AliMUONSimData::DumpHits(Int_t event2Check, Option_t* opt)
410 fLoader->LoadHits("READ");
413 Int_t nevents = fRunLoader->GetNumberOfEvents();
414 for (Int_t ievent=0; ievent<nevents; ievent++) {
415 if (event2Check!=0) ievent=event2Check;
416 printf(">>> Event %d \n",ievent);
418 // Getting event ievent
419 fRunLoader->GetEvent(ievent);
423 Int_t ntracks = (Int_t) GetNtracks();
424 for (Int_t itrack=0; itrack<ntracks; itrack++) {
425 //Getting List of Hits of Track itrack
428 Int_t nhits = (Int_t) Hits()->GetEntriesFast();
429 printf(">>> Track %d, Number of hits %d \n",itrack,nhits);
430 for (Int_t ihit=0; ihit<nhits; ihit++) {
431 AliMUONHit* mHit = static_cast<AliMUONHit*>(Hits()->At(ihit));
436 if (event2Check!=0) ievent=nevents;
438 fLoader->UnloadHits();
441 //_____________________________________________________________________________
443 AliMUONSimData::DumpSDigits(Int_t event2Check, Option_t* opt)
447 fLoader->LoadSDigits("READ");
450 Int_t nevents = fRunLoader->GetNumberOfEvents();
451 for (Int_t ievent=0; ievent<nevents; ievent++) {
452 if (event2Check!=0) ievent=event2Check;
453 printf(">>> Event %d \n",ievent);
455 // Getting event ievent
456 fRunLoader->GetEvent(ievent);
461 Int_t nchambers = AliMUONConstants::NCh(); ;
462 for (Int_t ichamber=0; ichamber<nchambers; ichamber++) {
463 TClonesArray* digits = SDigits(ichamber);
466 Int_t ndigits = (Int_t)digits->GetEntriesFast();
467 for (Int_t idigit=0; idigit<ndigits; idigit++) {
468 AliMUONDigit* mDigit = static_cast<AliMUONDigit*>(digits->At(idigit));
473 if (event2Check!=0) ievent=nevents;
475 fLoader->UnloadSDigits();