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 ///////////////////////////////////////////////////////////////////////////////
69 #include <TClonesArray.h>
71 #include <TParticle.h>
74 #include <TVirtualMC.h>
75 #include "AliDetector.h"
77 #include "AliITSDetTypeSim.h"
78 #include "AliITSDDLRawData.h"
79 #include "AliITSLoader.h"
80 #include "AliITShit.h"
81 #include "AliITSmodule.h"
82 #include "AliITSpListItem.h"
83 #include "AliITSsimulation.h"
84 #include "AliITSsimulationFastPoints.h"
86 #include "AliITSDigitizer.h"
87 #include "AliITSRecPoint.h"
88 #include "AliITSsegmentationSPD.h"
89 #include "AliITSsegmentationSDD.h"
90 #include "AliITSsimulationSDD.h"
91 #include "AliITSCalibrationSDD.h"
92 #include "AliITSCalibrationSSD.h"
93 #include "AliITSsegmentationSSD.h"
94 #include "AliITSRawStreamSPD.h"
95 #include "AliITSRawStreamSSD.h"
96 #include "AliITSRawStreamSDD.h"
97 #include "AliRawReader.h"
100 #include "AliITSInitGeometry.h"
101 #include "AliITSFOSignalsSPD.h"
105 //______________________________________________________________________
106 AliITS::AliITS() : AliDetector(),
117 // Default initializer for ITS
118 // The default constructor of the AliITS class. In addition to
119 // creating the AliITS class it zeros the variables fIshunt (a member
120 // of AliDetector class), fEuclidOut, and fIdN, and zeros the pointers
121 // fIdSens, and fIdName. The AliDetector default constructor
124 // SetDetectors(); // default to fOpt="All". This variable not written out.
125 //PH SetMarkerColor(kRed);
127 //______________________________________________________________________
128 AliITS::AliITS(const Char_t *title):
129 AliDetector("ITS",title),
140 // The standard Constructor for the ITS class.
141 // It also zeros the variables
142 // fIshunt (a member of AliDetector class), fEuclidOut, and zeros
143 // the pointers fIdSens and fIdName. To help in displaying hits via the
144 // ROOT macro display.C AliITS also sets the marker color to red. The
145 // variables passes with this constructor, const char *name and *title,
146 // are used by the constructor of AliDetector class. See AliDetector
147 // class for a description of these parameters and its constructor
150 // Char_t *title Simulation title for the ITS
156 fHits = new TClonesArray("AliITShit",1560); // from AliDetector
157 if(gAlice->GetMCApp()) gAlice->GetMCApp()->AddHitList(fHits);
158 //fNhits=0; //done in AliDetector(name,title)
159 SetDetectors(); // default to fOpt="All". This variable not written out.
160 fDetTypeSim = new AliITSDetTypeSim();
161 //PH SetMarkerColor(kRed);
162 if(!fLoader) MakeLoader(AliConfig::GetDefaultEventFolderName());
163 fDetTypeSim->SetLoader((AliITSLoader*)fLoader);
165 //______________________________________________________________________
166 AliITS::AliITS(const char *name, const char *title):
167 AliDetector(name,title),
178 // The standard Constructor for the ITS class.
179 // It also zeros the variables
180 // fIshunt (a member of AliDetector class), fEuclidOut, and zeros
181 // the pointers fIdSens and fIdName. To help in displaying hits via the
182 // ROOT macro display.C AliITS also sets the marker color to red. The
183 // variables passes with this constructor, const char *name and *title,
184 // are used by the constructor of AliDetector class. See AliDetector
185 // class for a description of these parameters and its constructor
188 fHits = new TClonesArray("AliITShit",1560);
189 if(gAlice->GetMCApp()) gAlice->GetMCApp()->AddHitList(fHits);
190 //fNhits=0; //done in AliDetector(name,title)
192 SetDetectors(); // default to fOpt="All". This variable not written out.
194 fDetTypeSim = new AliITSDetTypeSim();
195 //PH SetMarkerColor(kRed);
196 if(!fLoader) MakeLoader(AliConfig::GetDefaultEventFolderName());
197 fDetTypeSim->SetLoader((AliITSLoader*)fLoader);
200 //______________________________________________________________________
202 // Default destructor for ITS.
203 // The default destructor of the AliITS class. In addition to deleting
204 // the AliITS class it deletes the memory pointed to by
205 // fIdSens, fIdName, fDetTypeSim and it's contents.
219 this->ClearModules();
222 }// end if fITSmodules!=0
224 delete[] fIdName; // Array of TStrings
236 //______________________________________________________________________
237 AliDigitizer* AliITS::CreateDigitizer(AliRunDigitizer* manager)const{
238 // Creates the AliITSDigitizer in a standard way for use via AliModule.
239 // This function can not be included in the .h file because of problems
240 // with the order of inclusion (recursive).
242 // AliRunDigitizer *manager The Manger class for Digitization
246 // A new AliITSRunDigitizer (cast as a AliDigitizer).
248 return new AliITSDigitizer(manager);
250 //______________________________________________________________________
252 // Initializer ITS after it has been built
253 // This routine initializes the AliITS class. It is intended to be
254 // called from the Init function in AliITSv?. Besides displaying a banner
255 // indicating that it has been called it initializes the array fIdSens
256 // and sets the default segmentation, response, digit and raw cluster
257 // classes therefore it should be called after a call to CreateGeometry.
266 if(gMC) for(i=0;i<fIdN;i++) fIdSens[i] = gMC->VolId(fIdName[i]);
269 //______________________________________________________________________
270 void AliITS::SetDefaults(){
271 // sets the default segmentation, response, digit and raw cluster classes.
278 AliInfoClass("AliITS::Setting Defaults");
280 Error("SetDefaults()","fDetTypeSim is 0!");
284 fDetTypeSim->SetDefaults();
285 if(fSimuParam) fDetTypeSim->SetSimuParam(fSimuParam);
288 //______________________________________________________________________
289 void AliITS::SetDefaultSimulation(){
290 // sets the default simulation.
298 Error("SetDefaultSimulation()","fDetTypeSim is 0!");
302 fDetTypeSim->SetDefaultSimulation();
303 if(fSimuParam) fDetTypeSim->SetSimuParam(fSimuParam);
308 //______________________________________________________________________
309 void AliITS::MakeBranch(Option_t* option){
310 // Creates Tree branches for the ITS.
312 // Option_t *option String of Tree types S,D, and/or R.
313 // const char *file String of the file name where these branches
314 // are to be stored. If blank then these branches
315 // are written to the same tree as the Hits were
322 Error("MakeBranch","fDetTypeSim is 0!");
326 Bool_t cH = (strstr(option,"H")!=0);
327 Bool_t cS = (strstr(option,"S")!=0);
328 Bool_t cD = (strstr(option,"D")!=0);
330 if(cH && (fHits == 0x0)) fHits = new TClonesArray("AliITShit", 1560);
331 AliDetector::MakeBranch(option);
333 if(cS) MakeBranchS(0);
334 if(cD) MakeBranchD(0);
338 //___________________________________________________________________
339 void AliITS::MakeBranchS(const char* fl){
341 // Creates Tree Branch for the ITS summable digits.
343 // cont char *fl File name where SDigits branch is to be written
344 // to. If blank it write the SDigits to the same
345 // file in which the Hits were found.
349 Error("MakeBranchS","fDetTypeSim is 0!");
351 Int_t buffersize = 4000;
354 // only one branch for SDigits.
355 sprintf(branchname,"%s",GetName());
357 if(fLoader->TreeS()){
358 TClonesArray* sdig = (TClonesArray*)fDetTypeSim->GetSDigits();
359 MakeBranchInTree(fLoader->TreeS(),branchname,&sdig,buffersize,fl);
362 //______________________________________________________________________
363 void AliITS::MakeBranchD(const char* file){
365 //Make branch for digits
367 Warning("MakeBranchD","fDetTypeSim is 0!");
370 fDetTypeSim->SetLoader((AliITSLoader*)fLoader);
371 if(fSimuParam) fDetTypeSim->SetSimuParam(fSimuParam);
372 MakeBranchInTreeD(fLoader->TreeD(),file);
375 //___________________________________________________________________
376 void AliITS:: MakeBranchInTreeD(TTree* treeD, const char* file){
377 // Creates Tree branches for the ITS.
380 Error("MakeBranchS","fDetTypeSim is 0!");
382 fDetTypeSim->SetLoader((AliITSLoader*)fLoader);
383 if(fSimuParam) fDetTypeSim->SetSimuParam(fSimuParam);
385 const Char_t *det[3] = {"SPD","SDD","SSD"};
386 const Char_t* digclass;
387 Int_t buffersize = 4000;
388 Char_t branchname[30];
390 if(!fDetTypeSim->GetDigits()){
391 fDetTypeSim->SetDigits(new TObjArray(fgkNTYPES));
393 for(Int_t i=0;i<fgkNTYPES;i++){
394 digclass = fDetTypeSim->GetDigitClassName(i);
395 TString classn = digclass;
396 if(!((fDetTypeSim->GetDigits())->At(i))){
397 (fDetTypeSim->GetDigits())->AddAt(new TClonesArray(classn.Data(),1000),i);
400 if(fgkNTYPES==3) sprintf(branchname,"%sDigits%s",GetName(),det[i]);
401 else sprintf(branchname,"%sDigits%d",GetName(),i+1);
402 TObjArray* dig = DigitsAddress(i);
403 if(GetDigits() && treeD) AliDetector::MakeBranchInTree(treeD,branchname, &dig,buffersize,file);
407 //______________________________________________________________________
408 void AliITS::SetTreeAddress(){
409 // Set branch address for the Trees.
418 Error("SetTreeAddress","fDetTypeSim is 0!");
422 fDetTypeSim->SetLoader((AliITSLoader*)fLoader);
423 if(fSimuParam) fDetTypeSim->SetSimuParam(fSimuParam);
425 TTree *treeS = fLoader->TreeS();
426 TTree *treeD = fLoader->TreeD();
427 if (fLoader->TreeH() && (fHits == 0x0)) {
428 fHits = new TClonesArray("AliITShit", 1560);
430 AliDetector::SetTreeAddress();
432 fDetTypeSim->SetTreeAddressS(treeS, (Char_t*)GetName());
433 fDetTypeSim->SetTreeAddressD(treeD, (Char_t*)GetName());
435 //______________________________________________________________________
436 void AliITS::AddHit(Int_t track, Int_t *vol, Float_t *hits){
438 // The function to add information to the AliITShit class. See the
439 // AliITShit class for a full description. This function allocates the
440 // necessary new space for the hit information and passes the variable
441 // track, and the pointers *vol and *hits to the AliITShit constructor
444 // Int_t track Track number which produced this hit.
445 // Int_t *vol Array of Integer Hit information. See AliITShit.h
446 // Float_t *hits Array of Floating Hit information. see AliITShit.h
451 TClonesArray &lhits = *fHits;
452 new(lhits[fNhits++]) AliITShit(fIshunt,track,vol,hits);
455 //______________________________________________________________________
456 void AliITS::FillModules(Int_t evnt,Int_t bgrev,Int_t nmodules,
457 Option_t *option, const char *filename){
458 // fill the modules with the sorted by module hits; add hits from
459 // background if option=Add.
461 static TTree *trH1; //Tree with background hits
462 static Bool_t first=kTRUE;
464 const char *addBgr = strstr(option,"Add");
466 evnt = nmodules; // Dummy use of variables to remove warnings
469 file=new TFile(filename);
474 // Get Hits Tree header from file
475 if(trH1) delete trH1;
479 sprintf(treeName,"TreeH%d",bgrev);
480 trH1 = (TTree*)gDirectory->Get(treeName);
482 Error("FillModules","cannot find Hits Tree for event:%d",bgrev);
484 // Set branch addresses
487 FillModules(fLoader->TreeH(),0); // fill from this file's tree.
490 FillModules(trH1,10000000); // Default mask 10M.
491 TTree *fAli=fLoader->GetRunLoader()->TreeK();
493 if (fAli) fileAli =fAli->GetCurrentFile();
499 //______________________________________________________________________
500 void AliITS::FillModules(TTree *treeH, Int_t mask) {
501 // fill the modules with the sorted by module hits;
502 // can be called many times to do a merging
504 // TTree *treeH The tree containing the hits to be copied into
506 // Int_t mask The track number mask to indecate which file
507 // this hits came from.
515 Error("FillModules","Tree is NULL");
517 Int_t lay,lad,det,index;
521 sprintf(branchname,"%s",GetName());
522 TBranch *branch = treeH->GetBranch(branchname);
524 Error("FillModules","%s branch in TreeH not found",branchname);
527 branch->SetAddress(&fHits);
528 Int_t nTracks =(Int_t) treeH->GetEntries();
530 for(iPrimTrack=0; iPrimTrack<nTracks; iPrimTrack++){
532 Int_t nBytes = treeH->GetEvent(iPrimTrack);
533 if (nBytes <= 0) continue;
534 Int_t nHits = fHits->GetEntriesFast();
535 for(h=0; h<nHits; h++){
536 itsHit = (AliITShit *)fHits->UncheckedAt(h);
537 itsHit->GetDetectorID(lay,lad,det);
539 index = GetITSgeom()->GetModuleIndex(lay,lad,det);
541 index=det-1; // This should not be used.
542 } // end if [You must have fITSgeom for this to work!]
543 mod = GetModule(index);
544 itsHit->SetTrack(itsHit->GetTrack()+mask); // Set track mask.
545 mod->AddHit(itsHit,iPrimTrack,h);
546 } // end loop over hits
547 } // end loop over tracks
550 //______________________________________________________________________
551 Bool_t AliITS::InitModules(Int_t size,Int_t &nmodules){
552 // Initialize the modules array.
554 // Int_t size Size of array of the number of modules to be
555 // created. If size <=0 then the number of modules
556 // is gotten from AliITSgeom class kept in fITSgeom.
558 // Int_t &nmodules The number of modules existing.
563 fITSmodules->Delete();
565 } // end fir fITSmoudles
568 Error("InitModules","fDetTypeSim is null!");
571 if(fSimuParam) fDetTypeSim->SetSimuParam(fSimuParam);
573 Int_t nl,indexMAX,index;
575 if(size<=0){ // default to using data stored in AliITSgeom
576 if(fDetTypeSim->GetITSgeom()==0) {
577 Error("InitModules","fITSgeom not defined");
579 } // end if fITSgeom==0
580 nl = fDetTypeSim->GetITSgeom()->GetNlayers();
581 indexMAX = fDetTypeSim->GetITSgeom()->GetIndexMax();
583 fITSmodules = new TObjArray(indexMAX);
584 for(index=0;index<indexMAX;index++){
585 fITSmodules->AddAt( new AliITSmodule(index),index);
588 fITSmodules = new TObjArray(size);
589 for(index=0;index<size;index++) {
590 fITSmodules->AddAt( new AliITSmodule(index),index);
597 //______________________________________________________________________
598 void AliITS::Hits2SDigits(){
599 // Standard Hits to summable Digits function.
607 Error("Hits2SDigits","fDetTypeSim is null!");
612 fLoader->LoadHits("read");
613 fLoader->LoadSDigits("recreate");
614 AliRunLoader* rl = fLoader->GetRunLoader();
615 fDetTypeSim->SetLoader((AliITSLoader*)fLoader);
616 if(fSimuParam) fDetTypeSim->SetSimuParam(fSimuParam);
618 for (Int_t iEvent = 0; iEvent < rl->GetNumberOfEvents(); iEvent++) {
619 // Do the Hits to Digits operation. Use Standard input values.
620 // Event number from file, no background hit merging , use size from
621 // AliITSgeom class, option="All", input from this file only.
622 rl->GetEvent(iEvent);
623 if (!fLoader->TreeS()) fLoader->MakeTree("S");
626 HitsToPreDigits(iEvent,0,-1," ",fOpt," ");
629 fLoader->UnloadHits();
630 fLoader->UnloadSDigits();
633 //______________________________________________________________________
634 void AliITS::Hits2Digits(){
636 //Conversion from hits to digits
638 Error("Hits2SDigits","fDetTypeSim is 0!");
642 fDetTypeSim->SetLoader((AliITSLoader*)fLoader);
643 if(fSimuParam) fDetTypeSim->SetSimuParam(fSimuParam);
646 fLoader->LoadHits("read");
647 fLoader->LoadDigits("recreate");
648 AliRunLoader* rl = fLoader->GetRunLoader();
649 for (Int_t iEvent = 0; iEvent < rl->GetNumberOfEvents(); iEvent++) {
650 rl->GetEvent(iEvent);
651 if (!fLoader->TreeD()) fLoader->MakeTree("D");
654 HitsToDigits(iEvent,0,-1," ",fOpt," ");
657 fLoader->UnloadHits();
658 fLoader->UnloadDigits();
662 //______________________________________________________________________
663 void AliITS::HitsToDigits(Int_t evNumber,Int_t bgrev,Int_t size,
664 Option_t *option,Option_t *opt,
665 const char *filename){
666 // Keep galice.root for signal and name differently the file for
667 // background when add! otherwise the track info for signal will be lost !
668 // the condition below will disappear when the geom class will be
669 // initialized for all versions - for the moment it is only for v5 !
670 // 7 is the SDD beam test version.
672 // Int_t evnt Event to be processed.
673 // Int_t bgrev Background Hit tree number.
674 // Int_t nmodules Not used.
675 // Option_t *option String indicating if merging hits or not. To
676 // merge hits set equal to "Add". Otherwise no
677 // background hits are considered.
678 // Test_t *filename File name containing the background hits..
685 Error("HitsToDigits","fDetTypeSim is null!");
688 fDetTypeSim->SetLoader((AliITSLoader*)fLoader);
689 if(fSimuParam) fDetTypeSim->SetSimuParam(fSimuParam);
690 if(!GetITSgeom()) return; // need transformations to do digitization.
691 AliITSgeom *geom = GetITSgeom();
693 const char *all = strstr(opt,"All");
694 const char *det[3] = {strstr(opt,"SPD"),strstr(opt,"SDD"),
696 static Bool_t setDef=kTRUE;
697 if (setDef) SetDefaultSimulation();
701 InitModules(size,nmodules);
702 FillModules(evNumber,bgrev,nmodules,option,filename);
704 // Reset Fast-OR signals for this event
705 fDetTypeSim->ResetFOSignals();
707 AliITSsimulation *sim = 0;
708 AliITSmodule *mod = 0;
710 for(Int_t module=0;module<geom->GetIndexMax();module++){
711 id = geom->GetModuleType(module);
712 if (!all && !det[id]) continue;
713 sim = (AliITSsimulation*)fDetTypeSim->GetSimulationModel(id);
715 Error("HitsToDigits","The simulation class was not "
716 "instanciated for module %d type %s!",module,
717 geom->GetModuleTypeName(module));
720 mod = (AliITSmodule *)fITSmodules->At(module);
721 sim->DigitiseModule(mod,module,evNumber);
722 // fills all branches - wasted disk space
723 fLoader->TreeD()->Fill();
729 // Add random noise to FO signals
730 if (all || det[0]) { // SPD present
731 fDetTypeSim->ProcessNoiseForFastOr();
734 // Add Fast-OR signals to event (only one object per event)
735 if (all || det[0]) { // SPD present
736 fDetTypeSim->WriteFOSignals();
740 fLoader->TreeD()->GetEntries();
741 fLoader->TreeD()->AutoSave();
743 fLoader->TreeD()->Reset();
745 //_____________________________________________________________________
746 void AliITS::Hits2PreDigits(){
747 // Turn hits into SDigits
750 Error("Hits2SDigits","fDetTypeSim is 0!");
754 fDetTypeSim->SetLoader((AliITSLoader*)fLoader);
755 if(fSimuParam) fDetTypeSim->SetSimuParam(fSimuParam);
758 HitsToPreDigits(fLoader->GetRunLoader()->GetEventNumber(),
762 //______________________________________________________________________
763 void AliITS::HitsToPreDigits(Int_t evNumber,Int_t bgrev,Int_t size,
764 Option_t *option,Option_t *opt,
765 const char *filename){
766 // Keep galice.root for signal and name differently the file for
767 // background when add! otherwise the track info for signal will be lost !
768 // the condition below will disappear when the geom class will be
769 // initialized for all versions - for the moment it is only for v5 !
770 // 7 is the SDD beam test version.
772 // Int_t evnt Event to be processed.
773 // Int_t bgrev Background Hit tree number.
774 // Int_t nmodules Not used.
775 // Option_t *option String indicating if merging hits or not. To
776 // merge hits set equal to "Add". Otherwise no
777 // background hits are considered.
778 // Test_t *filename File name containing the background hits..
786 Error("HitsToPreDigits","fDetTypeSim is null!");
789 fDetTypeSim->SetLoader((AliITSLoader*)fLoader);
790 if(fSimuParam) fDetTypeSim->SetSimuParam(fSimuParam);
793 Error("HitsToPreDigits","fGeom is null!");
794 return; // need transformations to do digitization.
796 AliITSgeom *geom = GetITSgeom();
798 const char *all = strstr(opt,"All");
799 const char *det[3] = {strstr(opt,"SPD"),strstr(opt,"SDD"),
801 static Bool_t setDef=kTRUE;
802 if (setDef) SetDefaultSimulation();
806 InitModules(size,nmodules);
807 FillModules(evNumber,bgrev,nmodules,option,filename);
810 AliITSsimulation *sim = 0;
811 AliITSmodule *mod = 0;
813 for(module=0;module<geom->GetIndexMax();module++){
814 id = geom->GetModuleType(module);
815 if (!all && !det[id]) continue;
816 sim = (AliITSsimulation*)GetSimulationModel(id);
818 Error("HitsToPreDigits","The simulation class was not "
819 "instanciated for module %d type %s!",module,
820 geom->GetModuleTypeName(module));
823 mod = (AliITSmodule *)fITSmodules->At(module);
824 sim->SDigitiseModule(mod,module,evNumber);
825 // fills all branches - wasted disk space
826 fLoader->TreeS()->Fill();
827 fDetTypeSim->ResetSDigits();
833 fLoader->TreeS()->GetEntries();
834 fLoader->TreeS()->AutoSave();
835 fLoader->WriteSDigits("OVERWRITE");
837 fLoader->TreeS()->Reset();
840 //_____________________________________________________________________
841 void AliITS::HitsToFastRecPoints(Int_t evNumber,Int_t bgrev,Int_t size,
842 Option_t *opt0,Option_t *opt1,
844 // keep galice.root for signal and name differently the file for
845 // background when add! otherwise the track info for signal will be lost !
846 // the condition below will disappear when the geom class will be
847 // initialized for all versions - for the moment it is only for v5 !
849 // Int_t evnt Event to be processed.
850 // Int_t bgrev Background Hit tree number.
851 // Int_t size Size used by InitModules. See InitModules.
852 // Option_t *opt0 Option passed to FillModules. See FillModules.
853 // Option_t *opt1 String indicating if merging hits or not. To
854 // merge hits set equal to "Add". Otherwise no
855 // background hits are considered.
856 // Test_t *flnm File name containing the background hits..
865 Error("HitsToPreDigits","fGeom is null!");
866 return; // need transformations to do digitization.
868 AliITSgeom *geom = GetITSgeom();
870 AliITSLoader *pITSloader = (AliITSLoader*)fLoader;
872 const char *all = strstr(opt1,"All");
873 const char *det[3] ={strstr(opt1,"SPD"),strstr(opt1,"SDD"),
876 InitModules(size,nmodules);
877 FillModules(evNumber,bgrev,nmodules,opt0,flnm);
879 AliITSsimulation *sim = 0;
880 AliITSmodule *mod = 0;
883 TTree *lTR = pITSloader->TreeR();
885 pITSloader->MakeTree("R");
886 lTR = pITSloader->TreeR();
889 TClonesArray* ptarray = new TClonesArray("AliITSRecPoint",1000);
890 TBranch* branch = (TBranch*)lTR->Branch("ITSRecPointsF",&ptarray);
891 branch->SetAddress(&ptarray);
892 //m.b. : this change is nothing but a nice way to make sure
894 for(module=0;module<geom->GetIndexMax();module++){
895 id = geom->GetModuleType(module);
896 if (!all && !det[id]) continue;
897 sim = (AliITSsimulation*)GetSimulationModel(id);
899 Error("HitsToFastPoints","The simulation class was not "
900 "instanciated for module %d type %x!",module,
901 geom->GetModuleTypeName(module));
904 mod = (AliITSmodule *)fITSmodules->At(module);
905 sim->CreateFastRecPoints(mod,module,gRandom,ptarray);
911 fLoader->WriteRecPoints("OVERWRITE");
914 //_____________________________________________________________________
915 Int_t AliITS::Hits2Clusters(TTree *hTree, TTree *cTree) {
916 //------------------------------------------------------------
917 // This function creates ITS clusters
918 //------------------------------------------------------------
920 Error("HitsToPreDigits","fGeom is null!");
921 return 1; // need transformations to do digitization.
923 AliITSgeom *geom=GetITSgeom();
924 Int_t mmax=geom->GetIndexMax();
926 InitModules(-1,mmax);
927 FillModules(hTree,0);
929 TClonesArray *points = new TClonesArray("AliITSRecPoint",1000);
930 TBranch *branch=cTree->GetBranch("ITSRecPoints");
931 if (!branch) cTree->Branch("ITSRecPoints",&points);
932 else branch->SetAddress(&points);
934 AliITSsimulationFastPoints sim;
936 for (Int_t m=0; m<mmax; m++) {
937 AliITSmodule *mod=GetModule(m);
938 sim.CreateFastRecPoints(mod,m,gRandom,points);
939 ncl+=points->GetEntriesFast();
944 AliDebug(1,Form("Number of found fast clusters : %d",ncl));
952 //_____________________________________________________________________
953 void AliITS::CheckLabels(Int_t lab[3]) const {
954 //------------------------------------------------------------
955 // Tries to find mother's labels
956 //------------------------------------------------------------
958 if(lab[0]<0 && lab[1]<0 && lab[2]<0) return; // In case of no labels just exit
960 Int_t ntracks = gAlice->GetMCApp()->GetNtrack();
961 for (Int_t i=0;i<3;i++){
962 Int_t label = lab[i];
963 if (label>=0 && label<ntracks) {
964 TParticle *part=(TParticle*)gAlice->GetMCApp()->Particle(label);
965 if (part->P() < 0.005) {
966 Int_t m=part->GetFirstMother();
970 if (part->GetStatusCode()>0) {
980 //______________________________________________________________________
981 void AliITS::SDigitsToDigits(Option_t *opt){
982 // Standard Summable digits to Digits function.
988 AliError("fDetTypeSim is 0!");
992 const char *all = strstr(opt,"All");
993 const char *det[3] ={strstr(opt,"SPD"),strstr(opt,"SDD"),
996 // Reset Fast-OR signals for this event
997 fDetTypeSim->ResetFOSignals();
999 fDetTypeSim->SetLoader((AliITSLoader*)fLoader);
1001 if(fSimuParam) fDetTypeSim->SetSimuParam(fSimuParam);
1002 fDetTypeSim->SDigitsToDigits(opt,(Char_t*)GetName());
1004 // Add random noise to FO signals
1005 if (all || det[0]) { // SPD present
1006 fDetTypeSim->ProcessNoiseForFastOr();
1008 // Add Fast-OR signals to event (only one object per event)
1009 if (all || det[0]) { // SPD present
1010 fDetTypeSim->WriteFOSignals();
1014 //______________________________________________________________________
1015 void AliITS::ResetDigits(){
1016 // Reset number of digits and the digits array for the ITS detector.
1022 Error("ResetDigits","fDetTypeSim is 0!");
1026 fDetTypeSim->ResetDigits();
1030 //______________________________________________________________________
1031 void AliITS::ResetDigits(Int_t branch){
1032 // Reset number of digits and the digits array for this branch.
1039 Error("ResetDigits","fDetTypeSim is 0!");
1043 fDetTypeSim->ResetDigits(branch);
1046 //______________________________________________________________________
1047 void AliITS::AddSumDigit(AliITSpListItem &sdig){
1048 // Adds the a module full of summable digits to the summable digits tree.
1050 // AliITSpListItem &sdig SDigit to be added to SDigits tree.
1057 Error("AddSumDigit","fDetTypeSim is 0!");
1060 fDetTypeSim->AddSumDigit(sdig);
1063 //______________________________________________________________________
1064 void AliITS::AddSimDigit(Int_t branch, AliITSdigit *d){
1065 // Add a simulated digit.
1067 // Int_t id Detector type number.
1068 // AliITSdigit *d Digit to be added to the Digits Tree. See
1076 Error("AddSimDigit","fDetTypeSim is 0!");
1079 fDetTypeSim->AddSimDigit(branch,d);
1082 //______________________________________________________________________
1083 void AliITS::AddSimDigit(Int_t branch,Float_t phys,Int_t *digits,Int_t *tracks,
1084 Int_t *hits,Float_t *charges, Int_t sigexpanded){
1085 // Add a simulated digit to the list.
1087 // Int_t id Detector type number.
1088 // Float_t phys Physics indicator. See AliITSdigits.h
1089 // Int_t *digits Integer array containing the digits info. See
1091 // Int_t *tracks Integer array [AliITSdigitS?D::GetNTracks()]
1092 // containing the track numbers that contributed to
1094 // Int_t *hits Integer array [AliITSdigitS?D::GetNTracks()]
1095 // containing the hit numbers, from AliITSmodule, that
1096 // contributed to this digit.
1097 // Float_t *charge Floating point array of the signals contributed
1098 // to this digit by each track.
1105 Error("AddSimDigit","fDetTypeSim is 0!");
1108 fDetTypeSim->AddSimDigit(branch,phys,digits,tracks,hits,charges,sigexpanded);
1111 //______________________________________________________________________
1112 void AliITS::Digits2Raw(){
1113 // convert digits of the current event to raw data
1116 Error("Digits2Raw","fDetTypeSim is 0!");
1119 fDetTypeSim->SetLoader((AliITSLoader*)fLoader);
1121 if(fSimuParam) fDetTypeSim->SetSimuParam(fSimuParam);
1122 fDetTypeSim->GetLoader()->LoadDigits();
1123 TTree* digits = fDetTypeSim->GetLoader()->TreeD();
1125 Error("Digits2Raw", "no digits tree");
1128 fDetTypeSim->SetTreeAddressD(digits,(Char_t*)GetName());
1130 // Get the FO signals for this event
1131 AliITSFOSignalsSPD* foSignals = NULL;
1132 AliRunLoader* runLoader = AliRunLoader::Instance();
1133 AliITSLoader* itsLoader = (AliITSLoader*) runLoader->GetLoader("ITSLoader");
1135 AliError("ITS loader is NULL.");
1138 if(!itsLoader->TreeD()) AliError(" !!! No TreeD available !!!");
1139 foSignals = (AliITSFOSignalsSPD*)itsLoader->TreeD()->GetUserInfo()->FindObject("AliITSFOSignalsSPD");
1140 if(!foSignals) AliError("FO signals not retrieved");
1143 Bool_t deleteFOsignalsLater = kFALSE;
1145 AliError("FO signals not available. No FO bits will be written.");
1146 foSignals = new AliITSFOSignalsSPD(); // make a temporary dummy signals object
1147 deleteFOsignalsLater = kTRUE;
1151 AliITSDDLModuleMapSDD* ddlsdd=fDetTypeSim->GetDDLModuleMapSDD();
1152 Char_t rawSDD=fDetTypeSim->GetSimuParam()->GetSDDRawDataFormat();
1153 AliITSDDLRawData rawWriter;
1155 rawWriter.SetSDDRawFormat(rawSDD);
1159 // 2: txt files with digits
1160 //BE CAREFUL, verbose level 2 MUST be used only for debugging and
1161 //it is highly suggested to use this mode only for debugging digits files
1162 //reasonably small, because otherwise the size of the txt files can reach
1163 //quickly several MB wasting time and disk space.
1164 rawWriter.SetVerbose(0);
1166 //SILICON PIXEL DETECTOR
1167 AliDebug(1,"Formatting raw data for SPD");
1168 rawWriter.RawDataSPD(digits->GetBranch("ITSDigitsSPD"),foSignals);
1169 if(deleteFOsignalsLater) delete foSignals;
1171 //SILICON DRIFT DETECTOR
1172 AliDebug(1,Form("Formatting raw data for SDD - Format code =%d",rawSDD));
1173 rawWriter.RawDataSDD(digits->GetBranch("ITSDigitsSDD"),ddlsdd);
1175 //SILICON STRIP DETECTOR
1176 AliDebug(1,"Formatting raw data for SSD");
1177 rawWriter.RawDataSSD(digits->GetBranch("ITSDigitsSSD"));
1179 fLoader->UnloadDigits();
1181 //______________________________________________________________________
1182 AliLoader* AliITS::MakeLoader(const char* topfoldername){
1183 //builds ITSgetter (AliLoader type)
1184 //if detector wants to use castomized getter, it must overload this method
1186 AliDebug(1,Form("Creating AliITSLoader. Top folder is %s.",
1188 fLoader = new AliITSLoader(GetName(),topfoldername);
1191 //______________________________________________________________________
1192 Bool_t AliITS::Raw2SDigits(AliRawReader* rawReader)
1195 // Converts RAW data to SDigits
1200 Int_t size = GetITSgeom()->GetIndexMax();
1201 TClonesArray** modA = new TClonesArray*[size];
1202 for (Int_t mod = 0; mod < size; mod++) modA[mod] = new TClonesArray("AliITSpListItem", 10000);
1204 AliLoader* loader = (AliRunLoader::Instance())->GetLoader("ITSLoader");
1206 Error("Open","Can not get ITS loader from Run Loader");
1211 tree = loader->TreeS();
1213 loader->MakeTree("S");
1214 tree = loader->TreeS();
1217 // Array for SDigits
1219 TClonesArray aSDigits("AliITSpListItem",10000), *itsSDigits=&aSDigits;
1220 Int_t bufsize = 32000;
1221 tree->Branch("ITS", &itsSDigits, bufsize);
1226 AliITSsegmentationSPD* segSPD = (AliITSsegmentationSPD*) fDetTypeSim->GetSegmentationModel(0);
1228 AliWarning("Set AliITS defaults");
1230 segSPD = (AliITSsegmentationSPD*) fDetTypeSim->GetSegmentationModel(0);
1232 npx = segSPD->Npx();
1233 Double_t thr, sigma;
1235 AliITSRawStreamSPD inputSPD(rawReader);
1237 Bool_t next = inputSPD.Next();
1240 Int_t module = inputSPD.GetModuleID();
1241 Int_t column = inputSPD.GetColumn();
1242 Int_t row = inputSPD.GetRow();
1243 Int_t index = npx * column + row;
1245 if (module >= size) continue;
1247 last = (modA[module])->GetEntries();
1248 TClonesArray& dum = *modA[module];
1249 fDetTypeSim->GetSimuParam()->SPDThresholds(module,thr,sigma);
1251 new (dum[last]) AliITSpListItem(-1, -1, module, index, thr);
1258 AliITSsegmentationSDD* segSDD = (AliITSsegmentationSDD*) fDetTypeSim->GetSegmentationModel(1);
1259 npx = segSDD->Npx();
1260 Int_t scalef=AliITSsimulationSDD::ScaleFourier(segSDD);
1261 Int_t firstSDD=AliITSgeomTGeo::GetModuleIndex(3,1,1);
1262 Int_t firstSSD=AliITSgeomTGeo::GetModuleIndex(5,1,1);
1264 AliITSRawStream* inputSDD=AliITSRawStreamSDD::CreateRawStreamSDD(rawReader);
1265 for(Int_t iMod=firstSDD; iMod<firstSSD; iMod++){
1266 AliITSCalibrationSDD* cal = (AliITSCalibrationSDD*)fDetTypeSim->GetCalibrationModel(iMod);
1267 Bool_t isZeroSupp=cal->GetZeroSupp();
1269 for(Int_t iSid=0; iSid<2; iSid++) inputSDD->SetZeroSuppLowThreshold(iMod-firstSDD,iSid,cal->GetZSLowThreshold(iSid));
1271 for(Int_t iSid=0; iSid<2; iSid++) inputSDD->SetZeroSuppLowThreshold(iMod-firstSDD,iSid,0);
1275 AliITSDDLModuleMapSDD* ddlmap=fDetTypeSim->GetDDLModuleMapSDD();
1276 inputSDD->SetDDLModuleMap(ddlmap);
1277 while(inputSDD->Next()){
1278 if(inputSDD->IsCompletedModule()==kFALSE &&
1279 inputSDD->IsCompletedDDL()==kFALSE){
1281 Int_t module = inputSDD->GetModuleID();
1282 Int_t anode = inputSDD->GetCoord1()+segSDD->NpzHalf()*inputSDD->GetChannel();
1283 Int_t time = inputSDD->GetCoord2();
1284 Int_t signal10 = inputSDD->GetSignal();
1285 Int_t index = AliITSpList::GetIndex(anode,time,scalef*npx);
1287 if (module >= size) continue;
1288 last = modA[module]->GetEntries();
1289 TClonesArray& dum = *modA[module];
1290 new (dum[last]) AliITSpListItem(-1, -1, module, index, Double_t(signal10));
1291 ((AliITSpListItem*) dum.At(last))->AddSignalAfterElect(module, index, Double_t(signal10));
1300 AliITSsegmentationSSD* segSSD = (AliITSsegmentationSSD*) fDetTypeSim->GetSegmentationModel(2);
1301 npx = segSSD->Npx();
1302 AliITSRawStreamSSD inputSSD(rawReader);
1304 Bool_t next = inputSSD.Next();
1307 Int_t module = inputSSD.GetModuleID();
1308 Int_t side = inputSSD.GetSideFlag();
1309 Int_t strip = inputSSD.GetStrip();
1310 Int_t signal = inputSSD.GetSignal();
1311 Int_t index = npx * side + strip;
1313 if (module >= size) continue;
1315 last = modA[module]->GetEntries();
1316 TClonesArray& dum = *modA[module];
1317 new (dum[last]) AliITSpListItem(-1, -1, module, index, Double_t(signal));
1320 AliITSpListItem* sdig = 0;
1322 Int_t firstssd = GetITSgeom()->GetStartDet(kSSD);
1323 Double_t adcToEv = 1.;
1324 for (Int_t mod = 0; mod < size; mod++)
1327 AliITSCalibrationSSD* calssd = (AliITSCalibrationSSD*)fDetTypeSim->GetCalibrationModel(mod);
1328 adcToEv = 1./calssd->GetSSDDEvToADC(1.);
1330 Int_t nsdig = modA[mod]->GetEntries();
1331 for (Int_t ie = 0; ie < nsdig; ie++) {
1332 sdig = (AliITSpListItem*) (modA[mod]->At(ie));
1333 Int_t digsig = sdig->GetSignal();
1334 if(mod>=firstssd) digsig*=adcToEv; // for SSD: convert back charge from ADC to electron
1335 new (aSDigits[ie]) AliITSpListItem(-1, -1, mod, sdig->GetIndex(), digsig);
1336 Float_t sig = sdig->GetSignalAfterElect();
1337 if(mod>=firstssd) sig*=adcToEv;
1339 sdig = (AliITSpListItem*)aSDigits[ie];
1340 sdig->AddSignalAfterElect(mod, sdig->GetIndex(), Double_t(sig));
1348 loader->WriteSDigits("OVERWRITE");
1354 //______________________________________________________________________
1355 void AliITS::UpdateInternalGeometry(){
1357 //reads new geometry from TGeo
1358 // AliDebug(1,"Delete ITSgeom and create a new one reading TGeo");
1360 AliITSVersion_t version = (AliITSVersion_t)IsVersion();
1362 if(version==kvPPRasymmFMD) minor=2; // default minor version for this geom.
1363 AliITSInitGeometry initgeom;
1364 AliITSgeom* geom = initgeom.CreateAliITSgeom(version,minor);
1367 //______________________________________________________________________
1368 AliTriggerDetector* AliITS::CreateTriggerDetector() const {
1369 // create an AliITSTrigger object (and set trigger conditions as input)
1370 return new AliITSTrigger(fDetTypeSim->GetTriggerConditions());