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 **************************************************************************/
19 ///////////////////////////////////////////////////////////////////////////////
21 // An overview of the basic philosophy of the ITS code development
22 // and analysis is show in the figure below.
25 <img src="picts/ITS/ITS_Analysis_schema.gif">
28 <font size=+2 color=red>
29 <p>Roberto Barbera is in charge of the ITS Offline code (1999).
30 <a href="mailto:roberto.barbera@ct.infn.it">Roberto Barbera</a>.
36 // AliITS. Inner Traking System base class.
37 // This class contains the base procedures for the Inner Tracking System
41 <img src="picts/ITS/AliITS_Class_Diagram.gif">
44 <font size=+2 color=red>
45 <p>This show the class diagram of the different elements that are part of
53 // Written by Rene Brun, Federico Carminati, and Roberto Barbera
56 // Modified and documented by Bjorn S. Nilsen
60 // Modified and documented by A. Bologna
63 // AliITS is the general base class for the ITS. Also see AliDetector for
64 // futher information.
66 ///////////////////////////////////////////////////////////////////////////////
68 #include <Riostream.h>
72 #include <TClonesArray.h>
75 #include <TObjectTable.h>
81 #include <TVirtualMC.h>
83 #include "AliConfig.h"
84 #include "AliHeader.h"
86 #include "AliITSClusterFinderSDD.h"
87 #include "AliITSClusterFinderSPD.h"
88 #include "AliITSClusterFinderSSD.h"
89 #include "AliITSDetType.h"
90 #include "AliITSLoader.h"
91 #include "AliITSRawClusterSPD.h"
92 #include "AliITSRawClusterSDD.h"
93 #include "AliITSRawClusterSSD.h"
94 #include "AliITSRecPoint.h"
95 #include "AliITSdigitSPD.h"
96 #include "AliITSdigitSDD.h"
97 #include "AliITSdigitSSD.h"
98 #include "AliITSgeom.h"
99 #include "AliITShit.h"
100 #include "AliITSmodule.h"
101 #include "AliITSpList.h"
102 #include "AliITSresponseSDD.h"
103 #include "AliITSresponseSPD.h"
104 #include "AliITSresponseSSD.h"
105 #include "AliITSsegmentationSDD.h"
106 #include "AliITSsegmentationSPD.h"
107 #include "AliITSsegmentationSSD.h"
108 #include "AliITSsimulationSDD.h"
109 #include "AliITSsimulationSPD.h"
110 #include "AliITSsimulationSSD.h"
112 #include "AliITSDigitizer.h"
113 #include "AliITSDDLRawData.h"
118 //______________________________________________________________________
119 AliITS::AliITS() : AliDetector(),
137 fSelectedVertexer(0){
138 // Default initializer for ITS
139 // The default constructor of the AliITS class. In addition to
140 // creating the AliITS class it zeros the variables fIshunt (a member
141 // of AliDetector class), fEuclidOut, and fIdN, and zeros the pointers
142 // fITSpoints, fIdSens, and fIdName. The AliDetector default constructor
151 fIshunt = 0; // not zeroed in AliDetector.
154 // SetDetectors(); // default to fOpt="All". This variable not written out.
155 SetMarkerColor(kRed);
158 //______________________________________________________________________
159 AliITS::AliITS(const char *name, const char *title):AliDetector(name,title),
177 fSelectedVertexer(0){
178 // The standard Constructor for the ITS class. In addition to
179 // creating the AliITS class, it allocates memory for the TClonesArrays
180 // fHits, fSDigits, fDigits, fITSpoints, and the TObjArray of fCtype
181 // (clusters). It also zeros the variables
182 // fIshunt (a member of AliDetector class), fEuclidOut, and fIdN, and zeros
183 // the pointers fIdSens and fIdName. To help in displaying hits via the
184 // ROOT macro display.C AliITS also sets the marker color to red. The
185 // variables passes with this constructor, const char *name and *title,
186 // are used by the constructor of AliDetector class. See AliDetector
187 // class for a description of these parameters and its constructor
190 // const char *name Detector name. Should always be "ITS"
191 // const char *title Detector title.
197 fIshunt = 0; // not zeroed in AliDetector
198 fHits = new TClonesArray("AliITShit", 1560);//not done in AliDetector
199 // Not done in AliDetector.
200 if(gAlice->GetMCApp()) gAlice->GetMCApp()->AddHitList(fHits);
205 SetDetectors(); // default to fOpt="All". This variable not written out.
211 fNDetTypes = kNTYPES;
212 fDetTypes = new TObjArray(fNDetTypes);
214 fSDigits = new TClonesArray("AliITSpListItem",1000);
217 fNdtype = new Int_t[fNDetTypes];
218 fDtype = new TObjArray(fNDetTypes);
220 fCtype = new TObjArray(fNDetTypes);
221 fNctype = new Int_t[fNDetTypes];
223 fRecPoints = new TClonesArray("AliITSRecPoint",1000);
227 for(i=0;i<fNDetTypes;i++) {
228 fDetTypes->AddAt(new AliITSDetType(),i);
233 SetMarkerColor(kRed);
236 //______________________________________________________________________
238 // Default destructor for ITS.
239 // The default destructor of the AliITS class. In addition to deleting
240 // the AliITS class it deletes the memory pointed to by the fHits, fDigits,
241 // fSDigits, fCtype, fITSmodules, fITSgeom, fRecPoints, fIdSens, fIdName,
242 // fITSpoints, fDetType and it's contents.
266 fRecPoints->Delete();
270 delete[] fIdName; // Array of TStrings
273 this->ClearModules();
276 }// end if fITSmodules!=0
294 } // end if fDetTypes
297 if (fITSgeom) delete fITSgeom;
299 //______________________________________________________________________
300 AliITS::AliITS(const AliITS &source) : AliDetector(source){
301 // Copy constructor. This is a function which is not allowed to be
302 // done to the ITS. It exits with an error.
304 // AliITS &source An AliITS class.
310 if(this==&source) return;
311 Error("Copy constructor",
312 "You are not allowed to make a copy of the AliITS");
315 //______________________________________________________________________
316 AliITS& AliITS::operator=(AliITS &source){
317 // Assignment operator. This is a function which is not allowed to be
318 // done to the ITS. It exits with an error.
320 // AliITS &source An AliITS class.
326 if(this==&source) return *this;
327 Error("operator=","You are not allowed to make a copy of the AliITS");
329 return *this; //fake return
331 //______________________________________________________________________
332 AliDigitizer* AliITS::CreateDigitizer(AliRunDigitizer* manager)const{
333 // Creates the AliITSDigitizer in a standard way for use via AliModule.
334 // This function can not be included in the .h file because of problems
335 // with the order of inclusion (recursive).
337 // AliRunDigitizer *manager The Manger class for Digitization
341 // A new AliITSRunDigitizer (cast as a AliDigitizer).
343 return new AliITSDigitizer(manager);
345 //______________________________________________________________________
347 // Initializer ITS after it has been built
348 // This routine initializes the AliITS class. It is intended to be
349 // called from the Init function in AliITSv?. Besides displaying a banner
350 // indicating that it has been called it initializes the array fIdSens
351 // and sets the default segmentation, response, digit and raw cluster
352 // classes therefore it should be called after a call to CreateGeometry.
363 if(gMC) for(i=0;i<fIdN;i++) fIdSens[i] = gMC->VolId(fIdName[i]);
365 //______________________________________________________________________
366 void AliITS::SetDefaults(){
367 // sets the default segmentation, response, digit and raw cluster classes.
374 AliITSsegmentation *seg;
375 AliITSresponse *resp;
376 AliITSDetType *iDetType;
378 if(fDebug) Info("SetDefauls","%s: SetDefaults",ClassName());
381 iDetType = DetType(kSPD);
383 if (!iDetType->GetSegmentationModel()) {
384 seg = new AliITSsegmentationSPD(fITSgeom);
385 SetSegmentationModel(kSPD,seg);
387 if (!iDetType->GetResponseModel()) {
388 SetResponseModel(kSPD,new AliITSresponseSPD());
390 // set digit and raw cluster classes to be used
392 const char *kData0=(iDetType->GetResponseModel())->DataType();
393 if (strstr(kData0,"real")) {
394 iDetType->ClassNames("AliITSdigit","AliITSRawClusterSPD");
395 } else iDetType->ClassNames("AliITSdigitSPD","AliITSRawClusterSPD");
399 iDetType = DetType(kSDD);
401 if (!iDetType->GetResponseModel()) {
402 SetResponseModel(kSDD,new AliITSresponseSDD("simulated"));
404 resp = iDetType->GetResponseModel();
405 if (!iDetType->GetSegmentationModel()) {
406 seg = new AliITSsegmentationSDD(fITSgeom,resp);
407 SetSegmentationModel(kSDD,seg);
409 const char *kData1 = (iDetType->GetResponseModel())->DataType();
410 const char *kopt = iDetType->GetResponseModel()->ZeroSuppOption();
411 if((!strstr(kopt,"2D"))&&(!strstr(kopt,"1D")) ||
412 strstr(kData1,"real") ){
413 iDetType->ClassNames("AliITSdigit","AliITSRawClusterSDD");
414 } else iDetType->ClassNames("AliITSdigitSDD","AliITSRawClusterSDD");
418 iDetType = DetType(kSSD);
420 if (!iDetType->GetSegmentationModel()) {
421 seg = new AliITSsegmentationSSD(fITSgeom);
422 SetSegmentationModel(kSSD,seg);
424 if (!iDetType->GetResponseModel()) {
425 SetResponseModel(kSSD,new AliITSresponseSSD("simulated"));
427 const char *kData2 = (iDetType->GetResponseModel())->DataType();
428 if (strstr(kData2,"real")) {
429 iDetType->ClassNames("AliITSdigit","AliITSRawClusterSSD");
430 } else iDetType->ClassNames("AliITSdigitSSD","AliITSRawClusterSSD");
434 Warning("SetDefaults",
435 "Only the three basic detector types are initialized!");
438 //______________________________________________________________________
439 void AliITS::SetDefaultSimulation(){
440 // sets the default simulation.
447 AliITSDetType *iDetType;
448 AliITSsimulation *sim;
449 AliITSsegmentation *seg;
452 iDetType = DetType(kSPD);
454 sim = iDetType->GetSimulationModel();
456 seg = (AliITSsegmentation*)iDetType->GetSegmentationModel();
457 res = (AliITSresponse*)iDetType->GetResponseModel();
458 sim = new AliITSsimulationSPD(seg,res);
459 SetSimulationModel(kSPD,sim);
460 }else{ // simulation exists, make sure it is set up properly.
461 if(sim->GetResponseModel()==0) sim->SetResponseModel(
462 (AliITSresponse*)iDetType->GetResponseModel());
463 if(sim->GetSegmentationModel()==0) sim->SetSegmentationModel(
464 (AliITSsegmentation*)iDetType->GetSegmentationModel());
468 iDetType = DetType(kSDD);
470 sim = iDetType->GetSimulationModel();
472 seg = (AliITSsegmentation*)iDetType->GetSegmentationModel();
473 res = (AliITSresponse*)iDetType->GetResponseModel();
474 sim = new AliITSsimulationSDD(seg,res);
475 SetSimulationModel(kSDD,sim);
476 }else{ // simulation exists, make sure it is set up properly.
477 if(sim->GetResponseModel()==0) sim->SetResponseModel(
478 (AliITSresponse*)iDetType->GetResponseModel());
479 if(sim->GetSegmentationModel()==0) sim->SetSegmentationModel(
480 (AliITSsegmentation*)iDetType->GetSegmentationModel());
484 iDetType = DetType(kSSD);
486 sim = iDetType->GetSimulationModel();
488 seg =(AliITSsegmentation*)iDetType->GetSegmentationModel();
489 res = (AliITSresponse*)iDetType->GetResponseModel();
490 sim = new AliITSsimulationSSD(seg,res);
491 SetSimulationModel(kSSD,sim);
492 }else{ // simulation exists, make sure it is set up properly.
493 if(sim->GetResponseModel()==0) sim->SetResponseModel(
494 (AliITSresponse*)iDetType->GetResponseModel());
495 if(sim->GetSegmentationModel()==0) sim->SetSegmentationModel(
496 (AliITSsegmentation*)iDetType->GetSegmentationModel());
501 //______________________________________________________________________
502 void AliITS::SetDefaultClusterFinders(){
503 // Sets the default cluster finders. Used in finding RecPoints.
510 AliITSDetType *iDetType;
511 AliITSsegmentation *seg;
512 AliITSClusterFinder *clf;
518 iDetType=DetType(kSPD);
520 if (!iDetType->GetReconstructionModel()) {
521 seg =(AliITSsegmentation*)iDetType->GetSegmentationModel();
522 TClonesArray *dig0 = DigitsAddress(0);
523 TClonesArray *recp0 = ClustersAddress(0);
524 clf = new AliITSClusterFinderSPD(seg,dig0,recp0);
525 SetReconstructionModel(kSPD,clf);
530 iDetType=DetType(kSDD);
532 if (!iDetType->GetReconstructionModel()) {
533 seg = (AliITSsegmentation*)iDetType->GetSegmentationModel();
534 res = (AliITSresponse*)iDetType->GetResponseModel();
535 TClonesArray *dig1 = DigitsAddress(1);
536 TClonesArray *recp1 = ClustersAddress(1);
537 clf = new AliITSClusterFinderSDD(seg,res,dig1,recp1);
538 SetReconstructionModel(kSDD,clf);
543 iDetType=DetType(kSSD);
545 if (!iDetType->GetReconstructionModel()) {
546 seg = (AliITSsegmentation*)iDetType->GetSegmentationModel();
547 TClonesArray *dig2 = DigitsAddress(2);
548 clf = new AliITSClusterFinderSSD(seg,dig2);
549 SetReconstructionModel(kSSD,clf);
553 //______________________________________________________________________
554 void AliITS::MakeBranch(Option_t* option){
555 // Creates Tree branches for the ITS.
557 // Option_t *option String of Tree types S,D, and/or R.
558 // const char *file String of the file name where these branches
559 // are to be stored. If blank then these branches
560 // are written to the same tree as the Hits were
566 Bool_t cH = (strstr(option,"H")!=0);
567 Bool_t cS = (strstr(option,"S")!=0);
568 Bool_t cD = (strstr(option,"D")!=0);
569 Bool_t cR = (strstr(option,"R")!=0);
570 Bool_t cRF = (strstr(option,"RF")!=0);
573 if(cH && (fHits == 0x0)) fHits = new TClonesArray("AliITShit", 1560);
575 AliDetector::MakeBranch(option);
577 if(cS) MakeBranchS(0);
578 if(cD) MakeBranchD(0);
579 if(cR) MakeBranchR(0);
580 if(cRF) MakeBranchRF(0);
582 //______________________________________________________________________
583 void AliITS::SetTreeAddress(){
584 // Set branch address for the Trees.
591 TTree *treeS = fLoader->TreeS();
592 TTree *treeD = fLoader->TreeD();
593 TTree *treeR = fLoader->TreeR();
594 if (fLoader->TreeH() && (fHits == 0x0))
595 fHits = new TClonesArray("AliITShit", 1560);
597 AliDetector::SetTreeAddress();
599 SetTreeAddressS(treeS);
600 SetTreeAddressD(treeD);
601 SetTreeAddressR(treeR);
603 //______________________________________________________________________
604 void AliITS::AddHit(Int_t track, Int_t *vol, Float_t *hits){
606 // The function to add information to the AliITShit class. See the
607 // AliITShit class for a full description. This function allocates the
608 // necessary new space for the hit information and passes the variable
609 // track, and the pointers *vol and *hits to the AliITShit constructor
612 // Int_t track Track number which produced this hit.
613 // Int_t *vol Array of Integer Hit information. See AliITShit.h
614 // Float_t *hits Array of Floating Hit information. see AliITShit.h
620 TClonesArray &lhits = *fHits;
621 new(lhits[fNhits++]) AliITShit(fIshunt,track,vol,hits);
623 //______________________________________________________________________
624 void AliITS::InitModules(Int_t size,Int_t &nmodules){
625 // Initialize the modules array.
627 // Int_t size Size of array of the number of modules to be
628 // created. If size <=0 then the number of modules
629 // is gotten from AliITSgeom class kept in fITSgeom.
631 // Int_t &nmodules The number of modules existing.
636 fITSmodules->Delete();
638 } // end fir fITSmoudles
640 Int_t nl,indexMAX,index;
642 if(size<=0){ // default to using data stored in AliITSgeom
644 Error("InitModules","fITSgeom not defined");
646 } // end if fITSgeom==0
647 nl = fITSgeom->GetNlayers();
648 indexMAX = fITSgeom->GetModuleIndex(nl,fITSgeom->GetNladders(nl),
649 fITSgeom->GetNdetectors(nl))+1;
651 fITSmodules = new TObjArray(indexMAX);
652 for(index=0;index<indexMAX;index++){
653 fITSmodules->AddAt( new AliITSmodule(index),index);
656 fITSmodules = new TObjArray(size);
657 for(index=0;index<size;index++) {
658 fITSmodules->AddAt( new AliITSmodule(index),index);
664 //______________________________________________________________________
665 void AliITS::FillModules(Int_t evnt,Int_t bgrev,Int_t nmodules,
666 Option_t *option, const char *filename){
667 // fill the modules with the sorted by module hits; add hits from
668 // background if option=Add.
670 // Int_t evnt Event to be processed.
671 // Int_t bgrev Background Hit tree number.
672 // Int_t nmodules Not used.
673 // Option_t *option String indicating if merging hits or not. To
674 // merge hits set equal to "Add". Otherwise no
675 // background hits are considered.
676 // Test_t *filename File name containing the background hits..
681 static TTree *trH1; //Tree with background hits
682 static Bool_t first=kTRUE;
684 const char *addBgr = strstr(option,"Add");
686 evnt = nmodules; // Dummy use of variables to remove warnings
689 file=new TFile(filename);
694 // Get Hits Tree header from file
695 if(trH1) delete trH1;
699 sprintf(treeName,"TreeH%d",bgrev);
700 trH1 = (TTree*)gDirectory->Get(treeName);
702 Error("FillModules","cannot find Hits Tree for event:%d",bgrev);
704 // Set branch addresses
707 FillModules(fLoader->TreeH(),0); // fill from this file's tree.
710 FillModules(trH1,10000000); // Default mask 10M.
711 TTree *fAli=fLoader->GetRunLoader()->TreeK();
713 if (fAli) fileAli =fAli->GetCurrentFile();
717 //______________________________________________________________________
718 void AliITS::FillModules(TTree *treeH, Int_t mask) {
719 // fill the modules with the sorted by module hits;
720 // can be called many times to do a merging
722 // TTree *treeH The tree containing the hits to be copied into
724 // Int_t mask The track number mask to indecate which file
725 // this hits came from.
733 Error("FillModules","Tree is NULL");
735 Int_t lay,lad,det,index;
739 sprintf(branchname,"%s",GetName());
740 TBranch *branch = treeH->GetBranch(branchname);
742 Error("FillModules","%s branch in TreeH not found",branchname);
745 branch->SetAddress(&fHits);
746 Int_t nTracks =(Int_t) treeH->GetEntries();
748 for(iPrimTrack=0; iPrimTrack<nTracks; iPrimTrack++){
750 Int_t nBytes = treeH->GetEvent(iPrimTrack);
751 if (nBytes <= 0) continue;
752 Int_t nHits = fHits->GetEntriesFast();
753 for(h=0; h<nHits; h++){
754 itsHit = (AliITShit *)fHits->UncheckedAt(h);
755 itsHit->GetDetectorID(lay,lad,det);
757 index = fITSgeom->GetModuleIndex(lay,lad,det);
759 index=det-1; // This should not be used.
760 } // end if [You must have fITSgeom for this to work!]
761 mod = GetModule(index);
762 itsHit->SetTrack(itsHit->GetTrack()+mask); // Set track mask.
763 mod->AddHit(itsHit,iPrimTrack,h);
764 } // end loop over hits
765 } // end loop over tracks
767 //______________________________________________________________________
768 void AliITS::MakeBranchS(const char *fl){
769 // Creates Tree Branch for the ITS summable digits.
771 // cont char *fl File name where SDigits branch is to be written
772 // to. If blank it write the SDigits to the same
773 // file in which the Hits were found.
778 Int_t buffersize = 4000;
781 // only one branch for SDigits.
782 sprintf(branchname,"%s",GetName());
785 if(fLoader->TreeS()){
786 if(fSDigits==0x0) fSDigits = new TClonesArray("AliITSpListItem",1000);
787 MakeBranchInTree(fLoader->TreeS(),branchname,&fSDigits,buffersize,fl);
790 //______________________________________________________________________
791 void AliITS::SetTreeAddressS(TTree *treeS){
792 // Set branch address for the ITS summable digits Trees.
794 // TTree *treeS Tree containing the SDigits.
802 if (fSDigits == 0x0) fSDigits = new TClonesArray("AliITSpListItem",1000);
804 sprintf(branchname,"%s",GetName());
805 branch = treeS->GetBranch(branchname);
806 if (branch) branch->SetAddress(&fSDigits);
808 //______________________________________________________________________
809 void AliITS::MakeBranchInTreeD(TTree *treeD,const char *file){
810 // Creates Tree branches for the ITS.
812 // TTree *treeD Pointer to the Digits Tree.
813 // cont char *file File name where Digits branch is to be written
814 // to. If blank it write the SDigits to the same
815 // file in which the Hits were found.
820 // one branch for digits per type of detector
821 const Char_t *det[3] = {"SPD","SDD","SSD"};
824 Int_t buffersize = 4000;
825 Char_t branchname[30];
827 if (fDtype == 0x0) fDtype = new TObjArray(fNDetTypes);
828 for (i=0; i<kNTYPES ;i++) {
829 digclass = DetType(i)->GetDigitClassName();
831 if(!(fDtype->At(i))){
832 fDtype->AddAt(new TClonesArray(digclass.Data(),1000),i);
836 if (kNTYPES==3) sprintf(branchname,"%sDigits%s",GetName(),det[i]);
837 else sprintf(branchname,"%sDigits%d",GetName(),i+1);
838 if (fDtype && treeD) {
839 MakeBranchInTree(treeD,branchname,&((*fDtype)[i]),buffersize,file);
843 for (i=0; i<kNTYPES ;i++) {
844 if (kNTYPES==3) sprintf(branchname,"%sDigits%s",GetName(),det[i]);
845 else sprintf(branchname,"%sDigits%d",GetName(),i+1);
846 if (fDtype && treeD) {
847 MakeBranchInTree(treeD,branchname,&((*fDtype)[i]),buffersize,file);
852 //______________________________________________________________________
853 void AliITS::SetTreeAddressD(TTree *treeD){
854 // Set branch address for the Trees.
856 // TTree *treeD Tree containing the Digits.
861 const char *det[3] = {"SPD","SDD","SSD"};
868 if (fDtype == 0x0) fDtype = new TObjArray(fNDetTypes);
869 for (i=0; i<kNTYPES; i++) {
870 digclass = DetType(i)->GetDigitClassName();
872 if(!(fDtype->At(i))) {
873 fDtype->AddAt(new TClonesArray(digclass.Data(),1000),i);
877 if (kNTYPES==3) sprintf(branchname,"%sDigits%s",GetName(),det[i]);
878 else sprintf(branchname,"%sDigits%d",GetName(),i+1);
880 branch = treeD->GetBranch(branchname);
881 if (branch) branch->SetAddress(&((*fDtype)[i]));
885 //______________________________________________________________________
886 void AliITS::Hits2SDigits(){
887 // Standard Hits to summable Digits function.
893 fLoader->LoadHits("read");
894 fLoader->LoadSDigits("recreate");
895 AliRunLoader* rl = fLoader->GetRunLoader();
897 for (Int_t iEvent = 0; iEvent < rl->GetNumberOfEvents(); iEvent++) {
898 // Do the Hits to Digits operation. Use Standard input values.
899 // Event number from file, no background hit merging , use size from
900 // AliITSgeom class, option="All", input from this file only.
901 rl->GetEvent(iEvent);
902 if (!fLoader->TreeS()) fLoader->MakeTree("S");
905 HitsToPreDigits(iEvent,0,-1," ",fOpt," ");
908 fLoader->UnloadHits();
909 fLoader->UnloadSDigits();
911 //______________________________________________________________________
912 void AliITS::SDigitsToDigits(Option_t *opt){
913 // Standard Summable digits to Digits function.
918 char name[20] = {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};
920 if(!GetITSgeom()) return; // need transformations to do digitization.
921 AliITSgeom *geom = GetITSgeom();
923 const char *all = strstr(opt,"All");
924 const char *det[3] = {strstr(opt,"SPD"),strstr(opt,"SDD"),
926 if( !det[0] && !det[1] && !det[2] ) all = "All";
928 static Bool_t setDef = kTRUE;
929 if(setDef) SetDefaultSimulation();
932 AliITSsimulation *sim = 0;
933 AliITSDetType *iDetType = 0;
934 TTree *trees = fLoader->TreeS();
935 if( !(trees && this->GetSDigits()) ){
936 Error("SDigits2Digits","Error: No trees or SDigits. Returning.");
939 sprintf( name, "%s", this->GetName() );
940 TBranch *brchSDigits = trees->GetBranch( name );
943 for(module=0;module<geom->GetIndexMax();module++){
944 id = geom->GetModuleType(module);
945 if (!all && !det[id]) continue;
946 iDetType = DetType(id);
947 sim = (AliITSsimulation*)iDetType->GetSimulationModel();
949 Error("SDigit2Digits","The simulation class was not "
950 "instanciated for module %d type %s!",module,
951 geom->GetModuleTypeName(module));
954 sim->InitSimulationModule(module,gAlice->GetEvNumber());
956 // add summable digits to module
957 this->GetSDigits()->Clear();
958 brchSDigits->GetEvent(module);
959 sim->AddSDigitsToModule(GetSDigits(),0);
961 // Digitise current module sum(SDigits)->Digits
962 sim->FinishSDigitiseModule();
964 // fills all branches - wasted disk space
965 fLoader->TreeD()->Fill();
969 fLoader->TreeD()->GetEntries();
971 fLoader->TreeD()->AutoSave();
973 fLoader->TreeD()->Reset();
976 //______________________________________________________________________
977 void AliITS::Hits2Digits(){
978 // Standard Hits to Digits function.
984 fLoader->LoadHits("read");
985 fLoader->LoadDigits("recreate");
986 AliRunLoader* rl = fLoader->GetRunLoader();
988 for (Int_t iEvent = 0; iEvent < rl->GetNumberOfEvents(); iEvent++) {
989 // Do the Hits to Digits operation. Use Standard input values.
990 // Event number from file, no background hit merging , use size from
991 // AliITSgeom class, option="All", input from this file only.
992 rl->GetEvent(iEvent);
993 if (!fLoader->TreeD()) fLoader->MakeTree("D");
996 HitsToDigits(iEvent,0,-1," ",fOpt," ");
999 fLoader->UnloadHits();
1000 fLoader->UnloadDigits();
1002 //______________________________________________________________________
1003 void AliITS::HitsToPreDigits(Int_t evNumber,Int_t bgrev,Int_t size,
1004 Option_t *option,Option_t *opt,
1005 const char *filename){
1006 // Keep galice.root for signal and name differently the file for
1007 // background when add! otherwise the track info for signal will be lost !
1008 // the condition below will disappear when the geom class will be
1009 // initialized for all versions - for the moment it is only for v5 !
1010 // 7 is the SDD beam test version.
1012 // Int_t evnt Event to be processed.
1013 // Int_t bgrev Background Hit tree number.
1014 // Int_t nmodules Not used.
1015 // Option_t *option String indicating if merging hits or not. To
1016 // merge hits set equal to "Add". Otherwise no
1017 // background hits are considered.
1018 // Test_t *filename File name containing the background hits..
1024 if(!GetITSgeom()) return; // need transformations to do digitization.
1025 AliITSgeom *geom = GetITSgeom();
1027 const char *all = strstr(opt,"All");
1028 const char *det[3] = {strstr(opt,"SPD"),strstr(opt,"SDD"),
1030 static Bool_t setDef=kTRUE;
1031 if (setDef) SetDefaultSimulation();
1035 InitModules(size,nmodules);
1036 FillModules(evNumber,bgrev,nmodules,option,filename);
1038 AliITSsimulation *sim = 0;
1039 AliITSDetType *iDetType = 0;
1040 AliITSmodule *mod = 0;
1042 for(module=0;module<geom->GetIndexMax();module++){
1043 id = geom->GetModuleType(module);
1044 if (!all && !det[id]) continue;
1045 iDetType = DetType(id);
1046 sim = (AliITSsimulation*)iDetType->GetSimulationModel();
1048 Error("HitsToSDigits","The simulation class was not "
1049 "instanciated for module %d type %s!",module,
1050 geom->GetModuleTypeName(module));
1053 mod = (AliITSmodule *)fITSmodules->At(module);
1054 sim->SDigitiseModule(mod,module,evNumber);
1055 // fills all branches - wasted disk space
1056 fLoader->TreeS()->Fill();
1062 fLoader->TreeS()->GetEntries();
1063 fLoader->TreeS()->AutoSave();
1064 fLoader->WriteSDigits("OVERWRITE");
1066 fLoader->TreeS()->Reset();
1068 //______________________________________________________________________
1069 void AliITS::HitsToDigits(Int_t evNumber,Int_t bgrev,Int_t size,
1070 Option_t *option,Option_t *opt,
1071 const char *filename){
1072 // Keep galice.root for signal and name differently the file for
1073 // background when add! otherwise the track info for signal will be lost !
1074 // the condition below will disappear when the geom class will be
1075 // initialized for all versions - for the moment it is only for v5 !
1076 // 7 is the SDD beam test version.
1078 // Int_t evnt Event to be processed.
1079 // Int_t bgrev Background Hit tree number.
1080 // Int_t nmodules Not used.
1081 // Option_t *option String indicating if merging hits or not. To
1082 // merge hits set equal to "Add". Otherwise no
1083 // background hits are considered.
1084 // Test_t *filename File name containing the background hits..
1090 if(!GetITSgeom()) return; // need transformations to do digitization.
1091 AliITSgeom *geom = GetITSgeom();
1093 const char *all = strstr(opt,"All");
1094 const char *det[3] = {strstr(opt,"SPD"),strstr(opt,"SDD"),
1096 static Bool_t setDef=kTRUE;
1097 if (setDef) SetDefaultSimulation();
1101 InitModules(size,nmodules);
1102 FillModules(evNumber,bgrev,nmodules,option,filename);
1104 AliITSsimulation *sim = 0;
1105 AliITSDetType *iDetType = 0;
1106 AliITSmodule *mod = 0;
1108 for(module=0;module<geom->GetIndexMax();module++){
1109 id = geom->GetModuleType(module);
1110 if (!all && !det[id]) continue;
1111 iDetType = DetType(id);
1112 sim = (AliITSsimulation*)iDetType->GetSimulationModel();
1114 Error("HitsToDigits","The simulation class was not "
1115 "instanciated for module %d type %s!",module,
1116 geom->GetModuleTypeName(module));
1119 mod = (AliITSmodule *)fITSmodules->At(module);
1120 sim->DigitiseModule(mod,module,evNumber);
1121 // fills all branches - wasted disk space
1122 fLoader->TreeD()->Fill();
1128 fLoader->TreeD()->GetEntries();
1129 fLoader->TreeD()->AutoSave();
1131 fLoader->TreeD()->Reset();
1133 //______________________________________________________________________
1134 void AliITS::ResetDigits(){
1135 // Reset number of digits and the digits array for the ITS detector.
1141 if (!fDtype) return;
1144 for (i=0;i<kNTYPES;i++ ) {
1148 //______________________________________________________________________
1149 void AliITS::ResetDigits(Int_t i){
1150 // Reset number of digits and the digits array for this branch.
1156 if (fDtype->At(i)) ((TClonesArray*)fDtype->At(i))->Clear();
1157 if (fNdtype) fNdtype[i]=0;
1159 //______________________________________________________________________
1160 void AliITS::AddSumDigit(AliITSpListItem &sdig){
1161 // Adds the a module full of summable digits to the summable digits tree.
1163 // AliITSpListItem &sdig SDigit to be added to SDigits tree.
1169 TClonesArray &lsdig = *fSDigits;
1170 new(lsdig[fNSDigits++]) AliITSpListItem(sdig);
1172 //______________________________________________________________________
1173 void AliITS::AddRealDigit(Int_t id, Int_t *digits){
1174 // Add a real digit - as coming from data.
1176 // Int_t id Detector type number.
1177 // Int_t *digits Integer array containing the digits info. See
1184 TClonesArray &ldigits = *((TClonesArray*)fDtype->At(id));
1185 new(ldigits[fNdtype[id]++]) AliITSdigit(digits);
1187 //______________________________________________________________________
1188 void AliITS::AddSimDigit(Int_t id, AliITSdigit *d){
1189 // Add a simulated digit.
1191 // Int_t id Detector type number.
1192 // AliITSdigit *d Digit to be added to the Digits Tree. See
1199 TClonesArray &ldigits = *((TClonesArray*)fDtype->At(id));
1203 new(ldigits[fNdtype[id]++]) AliITSdigitSPD(*((AliITSdigitSPD*)d));
1206 new(ldigits[fNdtype[id]++]) AliITSdigitSDD(*((AliITSdigitSDD*)d));
1209 new(ldigits[fNdtype[id]++]) AliITSdigitSSD(*((AliITSdigitSSD*)d));
1213 //______________________________________________________________________
1214 void AliITS::AddSimDigit(Int_t id,Float_t phys,Int_t *digits,Int_t *tracks,
1215 Int_t *hits,Float_t *charges){
1216 // Add a simulated digit to the list.
1218 // Int_t id Detector type number.
1219 // Float_t phys Physics indicator. See AliITSdigits.h
1220 // Int_t *digits Integer array containing the digits info. See
1222 // Int_t *tracks Integer array [AliITSdigitS?D::GetNTracks()]
1223 // containing the track numbers that contributed to
1225 // Int_t *hits Integer array [AliITSdigitS?D::GetNTracks()]
1226 // containing the hit numbers, from AliITSmodule, that
1227 // contributed to this digit.
1228 // Float_t *charge Floating point array of the signals contributed
1229 // to this digit by each track.
1235 TClonesArray &ldigits = *((TClonesArray*)fDtype->At(id));
1236 AliITSresponseSDD *resp = 0;
1239 new(ldigits[fNdtype[id]++]) AliITSdigitSPD(digits,tracks,hits);
1242 resp = (AliITSresponseSDD*)DetType(1)->GetResponseModel();
1243 new(ldigits[fNdtype[id]++]) AliITSdigitSDD(phys,digits,tracks,
1247 new(ldigits[fNdtype[id]++]) AliITSdigitSSD(digits,tracks,hits);
1251 //______________________________________________________________________
1252 void AliITS::Digits2Raw(){
1253 // convert digits of the current event to raw data
1255 fLoader->LoadDigits();
1256 TTree* digits = fLoader->TreeD();
1258 Error("Digits2Raw", "no digits tree");
1261 SetTreeAddressD(digits);
1263 AliITSDDLRawData rawWriter;
1267 // 2: txt files with digits
1268 //BE CAREFUL, verbose level 2 MUST be used only for debugging and
1269 //it is highly suggested to use this mode only for debugging digits files
1270 //reasonably small, because otherwise the size of the txt files can reach
1271 //quickly several MB wasting time and disk space.
1272 rawWriter.SetVerbose(0);
1274 //SILICON PIXEL DETECTOR
1275 Info("Digits2Raw", "Formatting raw data for SPD");
1276 rawWriter.RawDataSPD(digits->GetBranch("ITSDigitsSPD"));
1278 //SILICON DRIFT DETECTOR
1279 Info("Digits2Raw", "Formatting raw data for SDD");
1280 rawWriter.RawDataSDD(digits->GetBranch("ITSDigitsSDD"));
1282 //SILICON STRIP DETECTOR
1283 Info("Digits2Raw", "Formatting raw data for SSD");
1284 rawWriter.RawDataSSD(digits->GetBranch("ITSDigitsSSD"));
1286 fLoader->UnloadDigits();
1289 //______________________________________________________________________
1290 void AliITS::MakeTreeC(Option_t *option){
1291 // Create a separate tree to store the clusters.
1293 // Option_t *option string which must contain "C" otherwise
1294 // no Cluster Tree is created.
1300 AliITSLoader *pITSLoader = (AliITSLoader*)fLoader;
1302 if (pITSLoader == 0x0) {
1303 Error("MakeTreeC","fLoader == 0x0 option=%s",option);
1306 if (pITSLoader->TreeC() == 0x0) pITSLoader->MakeTree("C");
1309 //----------------------------------------------------------------------
1310 void AliITS::MakeBranchC(){
1311 //Makes barnches in treeC
1312 AliITSLoader *pITSLoader = (AliITSLoader*)fLoader;
1313 if (pITSLoader == 0x0) {
1314 Error("MakeTreeC","fLoader == 0x0");
1317 TTree * lTC = pITSLoader->TreeC();
1319 Error("MakeTreeC","Can not get TreeC from Loader");
1323 Int_t buffersize = 4000;
1324 char branchname[30];
1325 const char *det[3] = {"SPD","SDD","SSD"};
1329 // one branch for Clusters per type of detector
1331 for (i=0; i<kNTYPES ;i++) {
1332 AliITSDetType *iDetType=DetType(i);
1333 iDetType->GetClassNames(digclass,clclass);
1335 if (fCtype == 0x0) fCtype = new TObjArray(fNDetTypes);
1336 if(!ClustersAddress(i)){
1337 fCtype->AddAt(new TClonesArray(clclass,1000),i);
1339 if (kNTYPES==3) sprintf(branchname,"%sClusters%s",GetName(),det[i]);
1340 else sprintf(branchname,"%sClusters%d",GetName(),i+1);
1341 if (fCtype && lTC) {
1342 if (lTC->GetBranch(branchname)){
1343 Warning("MakeBranchC","Branch %s alread exists in TreeC",
1346 Info("MakeBranchC","Creating branch %s in TreeC",branchname);
1347 lTC->Branch(branchname,&((*fCtype)[i]), buffersize);
1349 } // end if fCtype && lTC
1352 //______________________________________________________________________
1353 void AliITS::GetTreeC(Int_t event){
1354 // Get the clusters tree for this event and set the branch address.
1356 // Int_t event Event number for the cluster tree.
1361 char branchname[30];
1362 const char *det[3] = {"SPD","SDD","SSD"};
1364 AliITSLoader *pITSLoader = (AliITSLoader*)fLoader;
1365 TTree * lTC = pITSLoader->TreeC();
1369 pITSLoader->CleanRawClusters();
1378 for (i=0; i<kNTYPES; i++) {
1379 AliITSDetType *iDetType=DetType(i);
1380 iDetType->GetClassNames(digclass,clclass);
1382 if (fCtype == 0x0) fCtype = new TObjArray(fNDetTypes);
1383 if(!fCtype->At(i)) fCtype->AddAt(new TClonesArray(clclass,1000),i);
1384 if(kNTYPES==3) sprintf(branchname,"%sClusters%s",GetName(),det[i]);
1385 else sprintf(branchname,"%sClusters%d",GetName(),i+1);
1387 branch = lTC->GetBranch(branchname);
1388 if (branch) branch->SetAddress(&((*fCtype)[i]));
1392 Error("GetTreeC","cannot find Clusters Tree for event:%d",event);
1395 //______________________________________________________________________
1396 void AliITS::AddCluster(Int_t id, AliITSRawCluster *c){
1397 // Add a cluster to the list.
1399 // Int_t id Detector type number.
1400 // AliITSRawCluster *c Cluster class to be added to the tree of
1407 TClonesArray &lc = *((TClonesArray*)fCtype->At(id));
1411 new(lc[fNctype[id]++]) AliITSRawClusterSPD(*((AliITSRawClusterSPD*)c));
1414 new(lc[fNctype[id]++]) AliITSRawClusterSDD(*((AliITSRawClusterSDD*)c));
1417 new(lc[fNctype[id]++]) AliITSRawClusterSSD(*((AliITSRawClusterSSD*)c));
1421 //______________________________________________________________________
1422 void AliITS::ResetClusters(Int_t i){
1423 // Reset number of clusters and the clusters array for this branch.
1425 // Int_t i Detector type number.
1431 if (fCtype->At(i)) ((TClonesArray*)fCtype->At(i))->Clear();
1432 if (fNctype) fNctype[i]=0;
1434 //______________________________________________________________________
1435 void AliITS::MakeBranchR(const char *file, Option_t *opt){
1436 // Creates Tree branches for the ITS Reconstructed points.
1438 // cont char *file File name where RecPoints branch is to be written
1439 // to. If blank it write the SDigits to the same
1440 // file in which the Hits were found.
1445 Int_t buffsz = 4000;
1446 char branchname[30];
1448 // only one branch for rec points for all detector types
1449 Bool_t oFast= (strstr(opt,"Fast")!=0);
1451 sprintf(branchname,"%sRecPointsF",GetName());
1453 sprintf(branchname,"%sRecPoints",GetName());
1456 if(!fRecPoints)fRecPoints = new TClonesArray("AliITSRecPoint",1000);
1457 if (fLoader->TreeR()) {
1458 if(fRecPoints==0x0) fRecPoints = new TClonesArray("AliITSRecPoint",
1460 MakeBranchInTree(fLoader->TreeR(),branchname,&fRecPoints,buffsz,file);
1463 //______________________________________________________________________
1464 void AliITS::SetTreeAddressR(TTree *treeR){
1465 // Set branch address for the Reconstructed points Trees.
1467 // TTree *treeR Tree containing the RecPoints.
1472 char branchname[30];
1475 if(fRecPoints==0x0) fRecPoints = new TClonesArray("AliITSRecPoint",1000);
1477 sprintf(branchname,"%sRecPoints",GetName());
1478 branch = treeR->GetBranch(branchname);
1480 branch->SetAddress(&fRecPoints);
1482 sprintf(branchname,"%sRecPointsF",GetName());
1483 branch = treeR->GetBranch(branchname);
1485 branch->SetAddress(&fRecPoints);
1489 //______________________________________________________________________
1490 void AliITS::AddRecPoint(const AliITSRecPoint &r){
1491 // Add a reconstructed space point to the list
1493 // const AliITSRecPoint &r RecPoint class to be added to the tree
1494 // of reconstructed points TreeR.
1500 TClonesArray &lrecp = *fRecPoints;
1501 new(lrecp[fNRecPoints++]) AliITSRecPoint(r);
1503 //______________________________________________________________________
1504 void AliITS::HitsToFastRecPoints(Int_t evNumber,Int_t bgrev,Int_t size,
1505 Option_t *opt0,Option_t *opt1,
1507 // keep galice.root for signal and name differently the file for
1508 // background when add! otherwise the track info for signal will be lost !
1509 // the condition below will disappear when the geom class will be
1510 // initialized for all versions - for the moment it is only for v5 !
1512 // Int_t evnt Event to be processed.
1513 // Int_t bgrev Background Hit tree number.
1514 // Int_t size Size used by InitModules. See InitModules.
1515 // Option_t *opt0 Option passed to FillModules. See FillModules.
1516 // Option_t *opt1 String indicating if merging hits or not. To
1517 // merge hits set equal to "Add". Otherwise no
1518 // background hits are considered.
1519 // Test_t *flnm File name containing the background hits..
1525 if(!GetITSgeom()) return;
1526 AliITSLoader *pITSloader = (AliITSLoader*)fLoader;
1527 AliITSgeom *geom = GetITSgeom();
1529 const char *all = strstr(opt1,"All");
1530 const char *det[3] ={strstr(opt1,"SPD"),strstr(opt1,"SDD"),
1531 strstr(opt1,"SSD")};
1533 InitModules(size,nmodules);
1534 FillModules(evNumber,bgrev,nmodules,opt0,flnm);
1536 AliITSsimulation *sim = 0;
1537 AliITSDetType *iDetType = 0;
1538 AliITSmodule *mod = 0;
1541 //m.b. : this change is nothing but a nice way to make sure
1544 if(GetDebug()) cout<<"HitsToFastRecPoints: N mod = "<<
1545 geom->GetIndexMax()<<endl;
1546 for(module=0;module<geom->GetIndexMax();module++){
1547 id = geom->GetModuleType(module);
1548 if (!all && !det[id]) continue;
1549 iDetType = DetType(id);
1550 sim = (AliITSsimulation*)iDetType->GetSimulationModel();
1552 Error("HitsToFastPoints","The simulation class was not "
1553 "instanciated for module %d type %x!",module,
1554 geom->GetModuleTypeName(module));
1557 mod = (AliITSmodule *)fITSmodules->At(module);
1558 sim->CreateFastRecPoints(mod,module,gRandom);
1559 cout<<module<<"\r";fflush(0);
1560 //gAlice->TreeR()->Fill();
1561 TTree *lTR = pITSloader->TreeR();
1562 TBranch *br=lTR->GetBranch("ITSRecPointsF");
1568 fLoader->WriteRecPoints("OVERWRITE");
1570 //______________________________________________________________________
1571 void AliITS::DigitsToRecPoints(Int_t evNumber,Int_t lastentry,Option_t *opt){
1572 // cluster finding and reconstruction of space points
1573 // the condition below will disappear when the geom class will be
1574 // initialized for all versions - for the moment it is only for v5 !
1575 // 7 is the SDD beam test version
1577 // Int_t evNumber Event number to be processed.
1578 // Int_t lastentry Offset for module when not all of the modules
1580 // Option_t *opt String indicating which ITS sub-detectors should
1581 // be processed. If ="All" then all of the ITS
1582 // sub detectors are processed.
1588 if(!GetITSgeom()) return;
1589 AliITSgeom *geom = GetITSgeom();
1591 const char *all = strstr(opt,"All");
1592 const char *det[3] = {strstr(opt,"SPD"),strstr(opt,"SDD"),
1594 static Bool_t setRec=kTRUE;
1595 if (setRec) SetDefaultClusterFinders();
1598 AliITSLoader *pITSloader = (AliITSLoader*)fLoader;
1599 TTree *treeC=pITSloader->TreeC();
1600 AliITSClusterFinder *rec = 0;
1601 AliITSDetType *iDetType = 0;
1602 Int_t id,module,first=0;
1603 for(module=0;module<geom->GetIndexMax();module++){
1604 id = geom->GetModuleType(module);
1605 if (!all && !det[id]) continue;
1606 if(det[id]) first = geom->GetStartDet(id);
1607 iDetType = DetType(id);
1608 rec = (AliITSClusterFinder*)iDetType->GetReconstructionModel();
1609 TClonesArray *itsDigits = this->DigitsAddress(id);
1611 Error("DigitsToRecPoints",
1612 "The reconstruction class was not instanciated! event=%d",
1616 this->ResetDigits();
1617 TTree *lTD = pITSloader->TreeD();
1619 lTD->GetEvent(lastentry+module);
1621 lTD->GetEvent(lastentry+(module-first));
1623 Int_t ndigits = itsDigits->GetEntriesFast();
1625 rec->SetDigits(DigitsAddress(id));
1626 rec->SetClusters(ClustersAddress(id));
1627 rec->FindRawClusters(module);
1629 pITSloader->TreeR()->Fill();
1635 pITSloader->WriteRecPoints("OVERWRITE");
1636 pITSloader->WriteRawClusters("OVERWRITE");
1638 //______________________________________________________________________
1639 AliLoader* AliITS::MakeLoader(const char* topfoldername){
1640 //builds ITSgetter (AliLoader type)
1641 //if detector wants to use castomized getter, it must overload this method
1643 Info("MakeLoader","Creating AliITSLoader. Top folder is %s.",
1645 fLoader = new AliITSLoader(GetName(),topfoldername);