+ if(!fDetTypeSim) {
+ Error("Hits2SDigits","fDetTypeSim is 0!");
+ return;
+ }
+
+ fDetTypeSim->SetLoader((AliITSLoader*)fLoader);
+ if(fSimuParam) fDetTypeSim->SetSimuParam(fSimuParam);
+ SetDefaults();
+
+ HitsToPreDigits(fLoader->GetRunLoader()->GetEventNumber(),
+ 0,-1," ",fOpt," ");
+}
+
+//______________________________________________________________________
+void AliITS::HitsToPreDigits(Int_t evNumber,Int_t bgrev,Int_t size,
+ Option_t *option,Option_t *opt,
+ const char *filename){
+ // Keep galice.root for signal and name differently the file for
+ // background when add! otherwise the track info for signal will be lost !
+ // the condition below will disappear when the geom class will be
+ // initialized for all versions - for the moment it is only for v5 !
+ // 7 is the SDD beam test version.
+ // Inputs:
+ // Int_t evnt Event to be processed.
+ // Int_t bgrev Background Hit tree number.
+ // Int_t nmodules Not used.
+ // Option_t *option String indicating if merging hits or not. To
+ // merge hits set equal to "Add". Otherwise no
+ // background hits are considered.
+ // Test_t *filename File name containing the background hits..
+ // Outputs:
+ // none.
+ // Return:
+ // none.
+
+
+ if(!fDetTypeSim) {
+ Error("HitsToPreDigits","fDetTypeSim is null!");
+ return;
+ }
+ fDetTypeSim->SetLoader((AliITSLoader*)fLoader);
+ if(fSimuParam) fDetTypeSim->SetSimuParam(fSimuParam);
+
+ if(!GetITSgeom()){
+ Error("HitsToPreDigits","fGeom is null!");
+ return; // need transformations to do digitization.
+ }
+ AliITSgeom *geom = GetITSgeom();
+
+ const char *all = strstr(opt,"All");
+ const char *det[3] = {strstr(opt,"SPD"),strstr(opt,"SDD"),
+ strstr(opt,"SSD")};
+ static Bool_t setDef=kTRUE;
+ if (setDef) SetDefaultSimulation();
+ setDef=kFALSE;
+
+ Int_t nmodules;
+ InitModules(size,nmodules);
+ FillModules(evNumber,bgrev,nmodules,option,filename);
+
+
+ AliITSsimulation *sim = 0;
+ AliITSmodule *mod = 0;
+ Int_t id,module;
+ for(module=0;module<geom->GetIndexMax();module++){
+ id = geom->GetModuleType(module);
+ if (!all && !det[id]) continue;
+ sim = (AliITSsimulation*)GetSimulationModel(id);
+ if (!sim) {
+ Error("HitsToPreDigits","The simulation class was not "
+ "instanciated for module %d type %s!",module,
+ geom->GetModuleTypeName(module));
+ exit(1);
+ } // end if !sim
+ mod = (AliITSmodule *)fITSmodules->At(module);
+ sim->SDigitiseModule(mod,module,evNumber);
+ // fills all branches - wasted disk space
+ fLoader->TreeS()->Fill();
+ fDetTypeSim->ResetSDigits();
+ } // end for module
+
+ ClearModules();
+
+
+ fLoader->TreeS()->GetEntries();
+ fLoader->TreeS()->AutoSave();
+ fLoader->WriteSDigits("OVERWRITE");
+ // reset tree
+ fLoader->TreeS()->Reset();
+}
+
+//_____________________________________________________________________
+void AliITS::HitsToFastRecPoints(Int_t evNumber,Int_t bgrev,Int_t size,
+ Option_t *opt0,Option_t *opt1,
+ const char *flnm){
+ // keep galice.root for signal and name differently the file for
+ // background when add! otherwise the track info for signal will be lost !
+ // the condition below will disappear when the geom class will be
+ // initialized for all versions - for the moment it is only for v5 !
+ // Inputs:
+ // Int_t evnt Event to be processed.
+ // Int_t bgrev Background Hit tree number.
+ // Int_t size Size used by InitModules. See InitModules.
+ // Option_t *opt0 Option passed to FillModules. See FillModules.
+ // Option_t *opt1 String indicating if merging hits or not. To
+ // merge hits set equal to "Add". Otherwise no
+ // background hits are considered.
+ // Test_t *flnm File name containing the background hits..
+ // Outputs:
+ // none.
+ // Return:
+ // none.
+
+
+
+ if(!GetITSgeom()){
+ Error("HitsToPreDigits","fGeom is null!");
+ return; // need transformations to do digitization.
+ }
+ AliITSgeom *geom = GetITSgeom();
+
+ AliITSLoader *pITSloader = (AliITSLoader*)fLoader;
+
+ const char *all = strstr(opt1,"All");
+ const char *det[3] ={strstr(opt1,"SPD"),strstr(opt1,"SDD"),
+ strstr(opt1,"SSD")};
+ Int_t nmodules;
+ InitModules(size,nmodules);
+ FillModules(evNumber,bgrev,nmodules,opt0,flnm);
+
+ AliITSsimulation *sim = 0;
+ AliITSmodule *mod = 0;
+ Int_t id,module;
+
+ TTree *lTR = pITSloader->TreeR();
+ if(!lTR) {
+ pITSloader->MakeTree("R");
+ lTR = pITSloader->TreeR();
+ }
+
+ TClonesArray* ptarray = new TClonesArray("AliITSRecPoint",1000);
+ TBranch* branch = (TBranch*)lTR->Branch("ITSRecPointsF",&ptarray);
+ branch->SetAddress(&ptarray);
+ //m.b. : this change is nothing but a nice way to make sure
+ //the CPU goes up !
+ for(module=0;module<geom->GetIndexMax();module++){
+ id = geom->GetModuleType(module);
+ if (!all && !det[id]) continue;
+ sim = (AliITSsimulation*)GetSimulationModel(id);
+ if (!sim) {
+ Error("HitsToFastPoints","The simulation class was not "
+ "instanciated for module %d type %x!",module,
+ geom->GetModuleTypeName(module));
+ exit(1);
+ } // end if !sim
+ mod = (AliITSmodule *)fITSmodules->At(module);
+ sim->CreateFastRecPoints(mod,module,gRandom,ptarray);
+ lTR->Fill();
+ ptarray->Clear();
+ } // end for module
+
+ ClearModules();
+ fLoader->WriteRecPoints("OVERWRITE");
+ delete ptarray;
+}
+//_____________________________________________________________________
+Int_t AliITS::Hits2Clusters(TTree *hTree, TTree *cTree) {
+ //------------------------------------------------------------
+ // This function creates ITS clusters
+ //------------------------------------------------------------
+ if(!GetITSgeom()){
+ Error("HitsToPreDigits","fGeom is null!");
+ return 1; // need transformations to do digitization.
+ }
+ AliITSgeom *geom=GetITSgeom();
+ Int_t mmax=geom->GetIndexMax();
+
+ InitModules(-1,mmax);
+ FillModules(hTree,0);
+
+ TClonesArray *points = new TClonesArray("AliITSRecPoint",1000);
+ TBranch *branch=cTree->GetBranch("ITSRecPoints");
+ if (!branch) cTree->Branch("ITSRecPoints",&points);
+ else branch->SetAddress(&points);
+
+ AliITSsimulationFastPoints sim;
+ Int_t ncl=0;
+ for (Int_t m=0; m<mmax; m++) {
+ AliITSmodule *mod=GetModule(m);
+ sim.CreateFastRecPoints(mod,m,gRandom,points);
+ ncl+=points->GetEntriesFast();
+ cTree->Fill();
+ points->Clear();
+ }
+
+ AliDebug(1,Form("Number of found fast clusters : %d",ncl));
+
+ //cTree->Write();
+
+ delete points;
+ return 0;
+}
+
+//_____________________________________________________________________
+void AliITS::CheckLabels(Int_t lab[3]) const {
+ //------------------------------------------------------------
+ // Tries to find mother's labels
+ //------------------------------------------------------------
+
+ if(lab[0]<0 && lab[1]<0 && lab[2]<0) return; // In case of no labels just exit
+
+ Int_t ntracks = gAlice->GetMCApp()->GetNtrack();
+ for (Int_t i=0;i<3;i++){
+ Int_t label = lab[i];
+ if (label>=0 && label<ntracks) {
+ TParticle *part=(TParticle*)gAlice->GetMCApp()->Particle(label);
+ if (part->P() < 0.005) {
+ Int_t m=part->GetFirstMother();
+ if (m<0) {
+ continue;
+ }
+ if (part->GetStatusCode()>0) {
+ continue;
+ }
+ lab[i]=m;
+ }
+ }
+ }
+
+}
+
+//______________________________________________________________________
+void AliITS::SDigitsToDigits(Option_t *opt){
+ // Standard Summable digits to Digits function.
+ // Inputs:
+ // none.
+ // Outputs:
+ // none.
+ if (!fDetTypeSim) {
+ AliError("fDetTypeSim is 0!");
+ return;
+ }
+
+ const char *all = strstr(opt,"All");
+ const char *det[3] ={strstr(opt,"SPD"),strstr(opt,"SDD"),
+ strstr(opt,"SSD")};
+
+ // Reset Fast-OR signals for this event
+ fDetTypeSim->ResetFOSignals();
+
+ fDetTypeSim->SetLoader((AliITSLoader*)fLoader);
+ SetDefaults();
+ if(fSimuParam) fDetTypeSim->SetSimuParam(fSimuParam);
+ fDetTypeSim->SDigitsToDigits(opt,(Char_t*)GetName());
+
+ // Add random noise to FO signals
+ if (all || det[0]) { // SPD present
+ fDetTypeSim->ProcessNoiseForFastOr();
+ }
+ // Add Fast-OR signals to event (only one object per event)
+ if (all || det[0]) { // SPD present
+ fDetTypeSim->WriteFOSignals();
+ }
+}
+
+//______________________________________________________________________
+void AliITS::ResetDigits(){
+ // Reset number of digits and the digits array for the ITS detector.
+ // Inputs:
+ // none.
+ // Outputs:
+ // none.
+ if(!fDetTypeSim) {
+ Error("ResetDigits","fDetTypeSim is 0!");
+ return;
+ }
+
+ fDetTypeSim->ResetDigits();
+
+
+}
+//______________________________________________________________________
+void AliITS::ResetDigits(Int_t branch){
+ // Reset number of digits and the digits array for this branch.
+ // Inputs:
+ // none.
+ // Outputs:
+ // none.
+
+ if(!fDetTypeSim) {
+ Error("ResetDigits","fDetTypeSim is 0!");
+ return;
+ }
+
+ fDetTypeSim->ResetDigits(branch);
+
+}
+//______________________________________________________________________
+void AliITS::AddSumDigit(AliITSpListItem &sdig){
+ // Adds the a module full of summable digits to the summable digits tree.
+ // Inputs:
+ // AliITSpListItem &sdig SDigit to be added to SDigits tree.
+ // Outputs:
+ // none.
+ // Return:
+ // none.
+
+ if(!fDetTypeSim) {
+ Error("AddSumDigit","fDetTypeSim is 0!");
+ return;
+ }
+ fDetTypeSim->AddSumDigit(sdig);
+
+}
+//______________________________________________________________________
+void AliITS::AddSimDigit(Int_t branch, AliITSdigit *d){
+ // Add a simulated digit.
+ // Inputs:
+ // Int_t id Detector type number.
+ // AliITSdigit *d Digit to be added to the Digits Tree. See
+ // AliITSdigit.h
+ // Outputs:
+ // none.
+ // Return:
+ // none.
+
+ if(!fDetTypeSim) {
+ Error("AddSimDigit","fDetTypeSim is 0!");
+ return;
+ }
+ fDetTypeSim->AddSimDigit(branch,d);
+
+}
+//______________________________________________________________________
+void AliITS::AddSimDigit(Int_t branch,Float_t phys,Int_t *digits,Int_t *tracks,
+ Int_t *hits,Float_t *charges, Int_t sigexpanded){
+ // Add a simulated digit to the list.
+ // Inputs:
+ // Int_t id Detector type number.
+ // Float_t phys Physics indicator. See AliITSdigits.h
+ // Int_t *digits Integer array containing the digits info. See
+ // AliITSdigit.h
+ // Int_t *tracks Integer array [AliITSdigitS?D::GetNTracks()]
+ // containing the track numbers that contributed to
+ // this digit.
+ // Int_t *hits Integer array [AliITSdigitS?D::GetNTracks()]
+ // containing the hit numbers, from AliITSmodule, that
+ // contributed to this digit.
+ // Float_t *charge Floating point array of the signals contributed
+ // to this digit by each track.
+ // Outputs:
+ // none.
+ // Return:
+ // none.
+
+ if(!fDetTypeSim) {
+ Error("AddSimDigit","fDetTypeSim is 0!");
+ return;
+ }
+ fDetTypeSim->AddSimDigit(branch,phys,digits,tracks,hits,charges,sigexpanded);
+
+}
+//______________________________________________________________________
+void AliITS::Digits2Raw(){
+ // convert digits of the current event to raw data
+
+ if(!fDetTypeSim) {
+ Error("Digits2Raw","fDetTypeSim is 0!");
+ return;
+ }
+ fDetTypeSim->SetLoader((AliITSLoader*)fLoader);
+ SetDefaults();
+ if(fSimuParam) fDetTypeSim->SetSimuParam(fSimuParam);
+ fDetTypeSim->GetLoader()->LoadDigits();
+ TTree* digits = fDetTypeSim->GetLoader()->TreeD();
+ if (!digits) {
+ Error("Digits2Raw", "no digits tree");
+ return;
+ }
+ fDetTypeSim->SetTreeAddressD(digits,(Char_t*)GetName());
+
+ // Get the FO signals for this event
+ AliITSFOSignalsSPD* foSignals = NULL;
+ AliRunLoader* runLoader = AliRunLoader::Instance();
+ AliITSLoader* itsLoader = (AliITSLoader*) runLoader->GetLoader("ITSLoader");
+ if (!itsLoader) {
+ AliError("ITS loader is NULL.");
+ }
+ else {
+ if(!itsLoader->TreeD()) AliError(" !!! No TreeD available !!!");
+ foSignals = (AliITSFOSignalsSPD*)itsLoader->TreeD()->GetUserInfo()->FindObject("AliITSFOSignalsSPD");
+ if(!foSignals) AliError("FO signals not retrieved");
+ }
+
+ Bool_t deleteFOsignalsLater = kFALSE;
+ if (!foSignals) {
+ AliError("FO signals not available. No FO bits will be written.");
+ foSignals = new AliITSFOSignalsSPD(); // make a temporary dummy signals object
+ deleteFOsignalsLater = kTRUE;
+ }
+
+
+ AliITSDDLModuleMapSDD* ddlsdd=fDetTypeSim->GetDDLModuleMapSDD();
+ Char_t rawSDD=fDetTypeSim->GetSimuParam()->GetSDDRawDataFormat();
+ AliITSDDLRawData rawWriter;
+
+ rawWriter.SetSDDRawFormat(rawSDD);
+ //Verbose level
+ // 0: Silent
+ // 1: cout messages
+ // 2: txt files with digits
+ //BE CAREFUL, verbose level 2 MUST be used only for debugging and
+ //it is highly suggested to use this mode only for debugging digits files
+ //reasonably small, because otherwise the size of the txt files can reach
+ //quickly several MB wasting time and disk space.
+ rawWriter.SetVerbose(0);
+
+ //SILICON PIXEL DETECTOR
+ AliDebug(1,"Formatting raw data for SPD");
+ rawWriter.RawDataSPD(digits->GetBranch("ITSDigitsSPD"),foSignals);
+ if(deleteFOsignalsLater) delete foSignals;
+
+ //SILICON DRIFT DETECTOR
+ AliDebug(1,Form("Formatting raw data for SDD - Format code =%d",rawSDD));
+ rawWriter.RawDataSDD(digits->GetBranch("ITSDigitsSDD"),ddlsdd);
+
+ //SILICON STRIP DETECTOR
+ AliDebug(1,"Formatting raw data for SSD");
+ rawWriter.RawDataSSD(digits->GetBranch("ITSDigitsSSD"));
+
+ fLoader->UnloadDigits();
+}
+//______________________________________________________________________
+AliLoader* AliITS::MakeLoader(const char* topfoldername){
+ //builds ITSgetter (AliLoader type)
+ //if detector wants to use castomized getter, it must overload this method
+
+ AliDebug(1,Form("Creating AliITSLoader. Top folder is %s.",
+ topfoldername));
+ fLoader = new AliITSLoader(GetName(),topfoldername);
+ return fLoader;
+}
+//______________________________________________________________________
+Bool_t AliITS::Raw2SDigits(AliRawReader* rawReader)
+{