Store only the first, the last and any other measurement that differs more than 50...
[u/mrichter/AliRoot.git] / ITS / AliITS.cxx
CommitLineData
4c039060 1/**************************************************************************
2 * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
3 * *
4 * Author: The ALICE Off-line Project. *
5 * Contributors are mentioned in the code where appropriate. *
6 * *
7 * Permission to use, copy, modify and distribute this software and its *
8 * documentation strictly for non-commercial purposes is hereby granted *
9 * without fee, provided that the above copyright notice appears in all *
10 * copies and that both the copyright notice and this permission notice *
11 * appear in the supporting documentation. The authors make no claims *
12 * about the suitability of this software for any purpose. It is *
13 * provided "as is" without express or implied warranty. *
14 **************************************************************************/
15
88cb7938 16/* $Id$ */
2ab0c725 17
4c039060 18
fe4da5cc 19///////////////////////////////////////////////////////////////////////////////
04366a57 20// //
21// An overview of the basic philosophy of the ITS code development //
22// and analysis is show in the figure below. //
23//Begin_Html //
24/*
a92b2b7d 25<img src="picts/ITS/ITS_Analysis_schema.gif">
fe4da5cc 26</pre>
27<br clear=left>
28<font size=+2 color=red>
58005f18 29<p>Roberto Barbera is in charge of the ITS Offline code (1999).
fe4da5cc 30<a href="mailto:roberto.barbera@ct.infn.it">Roberto Barbera</a>.
31</font>
32<pre>
33*/
34//End_Html
58005f18 35//
36// AliITS. Inner Traking System base class.
37// This class contains the base procedures for the Inner Tracking System
38//
39//Begin_Html
40/*
a92b2b7d 41<img src="picts/ITS/AliITS_Class_Diagram.gif">
58005f18 42</pre>
43<br clear=left>
44<font size=+2 color=red>
45<p>This show the class diagram of the different elements that are part of
46the AliITS class.
47</font>
48<pre>
49*/
50//End_Html
51//
52// Version: 0
53// Written by Rene Brun, Federico Carminati, and Roberto Barbera
54//
55// Version: 1
56// Modified and documented by Bjorn S. Nilsen
57// July 11 1999
58//
3bd79107 59// Version: 2
60// Modified and documented by A. Bologna
61// October 18 1999
62//
58005f18 63// AliITS is the general base class for the ITS. Also see AliDetector for
64// futher information.
65//
fe4da5cc 66///////////////////////////////////////////////////////////////////////////////
88cb7938 67
143d1056 68#include <stdlib.h>
caf37aec 69#include <TClonesArray.h>
9c74c52b 70#include <TFile.h>
7d62fb64 71#include <TParticle.h>
d5da1ecf 72#include <TString.h>
88cb7938 73#include <TTree.h>
88cb7938 74#include <TVirtualMC.h>
7d62fb64 75#include "AliDetector.h"
3bd79107 76#include "AliITS.h"
7d62fb64 77#include "AliITSDetTypeSim.h"
f77f13c8 78#include "AliITSDDLRawData.h"
88cb7938 79#include "AliITSLoader.h"
88cb7938 80#include "AliITShit.h"
81#include "AliITSmodule.h"
7d62fb64 82#include "AliITSpListItem.h"
83#include "AliITSsimulation.h"
84#include "AliITSsimulationFastPoints.h"
5d12ce38 85#include "AliMC.h"
7d62fb64 86#include "AliITSDigitizer.h"
87#include "AliITSRecPoint.h"
0b5bf101 88#include "AliITSsegmentationSPD.h"
89#include "AliITSsegmentationSDD.h"
dee45d79 90#include "AliITSsimulationSDD.h"
91#include "AliITSCalibrationSDD.h"
8b3448d3 92#include "AliITSCalibrationSSD.h"
0b5bf101 93#include "AliITSsegmentationSSD.h"
94#include "AliITSRawStreamSPD.h"
95#include "AliITSRawStreamSSD.h"
96#include "AliITSRawStreamSDD.h"
0b5bf101 97#include "AliRawReader.h"
f77f13c8 98#include "AliRun.h"
7d62fb64 99#include "AliLog.h"
ef7ff1f9 100#include "AliITSInitGeometry.h"
ad7f2bfa 101#include "AliITSFOSignalsSPD.h"
828e06c7 102
3bd79107 103ClassImp(AliITS)
3bd79107 104
2aea926d 105//______________________________________________________________________
ed9289c8 106AliITS::AliITS() : AliDetector(),
107fDetTypeSim(0),
108fEuclidOut(0),
109fOpt("All"),
110fIdN(0),
111fIdSens(0),
112fIdName(0),
012f0f4c 113fITSmodules(0),
c8af5b8f 114fTiming(kFALSE),
afbc83e9 115fSimuParam(0),
116fModA(0),
117fpSDigits(0)
ed9289c8 118{
7d62fb64 119 // Default initializer for ITS
120 // The default constructor of the AliITS class. In addition to
121 // creating the AliITS class it zeros the variables fIshunt (a member
122 // of AliDetector class), fEuclidOut, and fIdN, and zeros the pointers
123 // fIdSens, and fIdName. The AliDetector default constructor
124 // is also called.
125
aa044888 126// SetDetectors(); // default to fOpt="All". This variable not written out.
e939a978 127//PH SetMarkerColor(kRed);
fe4da5cc 128}
2aea926d 129//______________________________________________________________________
c8af5b8f 130AliITS::AliITS(const Char_t *title):
131 AliDetector("ITS",title),
132 fDetTypeSim(0),
133 fEuclidOut(0),
134 fOpt("All"),
135 fIdN(0),
136 fIdSens(0),
137 fIdName(0),
138 fITSmodules(0),
139 fTiming(kFALSE),
afbc83e9 140 fSimuParam(0),
141 fModA(0),
142 fpSDigits(0)
012f0f4c 143{
144 // The standard Constructor for the ITS class.
145 // It also zeros the variables
146 // fIshunt (a member of AliDetector class), fEuclidOut, and zeros
147 // the pointers fIdSens and fIdName. To help in displaying hits via the
148 // ROOT macro display.C AliITS also sets the marker color to red. The
149 // variables passes with this constructor, const char *name and *title,
150 // are used by the constructor of AliDetector class. See AliDetector
151 // class for a description of these parameters and its constructor
152 // functions.
153 // Inputs:
154 // Char_t *title Simulation title for the ITS
155 // Outputs:
156 // none.
157 // Return:
158 // none.
159
160 fHits = new TClonesArray("AliITShit",1560); // from AliDetector
161 if(gAlice->GetMCApp()) gAlice->GetMCApp()->AddHitList(fHits);
162 //fNhits=0; //done in AliDetector(name,title)
163 SetDetectors(); // default to fOpt="All". This variable not written out.
164 fDetTypeSim = new AliITSDetTypeSim();
165 //PH SetMarkerColor(kRed);
166 if(!fLoader) MakeLoader(AliConfig::GetDefaultEventFolderName());
167 fDetTypeSim->SetLoader((AliITSLoader*)fLoader);
168}
169//______________________________________________________________________
c8af5b8f 170AliITS::AliITS(const char *name, const char *title):
171 AliDetector(name,title),
172 fDetTypeSim(0),
173 fEuclidOut(0),
174 fOpt("All"),
175 fIdN(0),
176 fIdSens(0),
177 fIdName(0),
178 fITSmodules(0),
179 fTiming(kFALSE),
afbc83e9 180 fSimuParam(0),
181 fModA(0),
182 fpSDigits(0)
ed9289c8 183{
7d62fb64 184 // The standard Constructor for the ITS class.
185 // It also zeros the variables
186 // fIshunt (a member of AliDetector class), fEuclidOut, and zeros
187 // the pointers fIdSens and fIdName. To help in displaying hits via the
188 // ROOT macro display.C AliITS also sets the marker color to red. The
189 // variables passes with this constructor, const char *name and *title,
190 // are used by the constructor of AliDetector class. See AliDetector
191 // class for a description of these parameters and its constructor
192 // functions.
193
7d62fb64 194 fHits = new TClonesArray("AliITShit",1560);
195 if(gAlice->GetMCApp()) gAlice->GetMCApp()->AddHitList(fHits);
ed9289c8 196 //fNhits=0; //done in AliDetector(name,title)
7d62fb64 197
7d62fb64 198 SetDetectors(); // default to fOpt="All". This variable not written out.
ed9289c8 199
7d62fb64 200 fDetTypeSim = new AliITSDetTypeSim();
e939a978 201 //PH SetMarkerColor(kRed);
023ae34b 202 if(!fLoader) MakeLoader(AliConfig::GetDefaultEventFolderName());
203 fDetTypeSim->SetLoader((AliITSLoader*)fLoader);
fe4da5cc 204
3bd79107 205}
2aea926d 206//______________________________________________________________________
58005f18 207AliITS::~AliITS(){
4a5bebc2 208 // Default destructor for ITS.
2aea926d 209 // The default destructor of the AliITS class. In addition to deleting
7d62fb64 210 // the AliITS class it deletes the memory pointed to by
211 // fIdSens, fIdName, fDetTypeSim and it's contents.
4a5bebc2 212 // Inputs:
213 // none.
214 // Outputs:
215 // none.
216 // Return:
217 // none.
023ae34b 218
88cb7938 219 if (fHits) {
220 fHits->Delete();
221 delete fHits;
222 fHits=0;
223 }
88cb7938 224 if(fITSmodules) {
225 this->ClearModules();
226 delete fITSmodules;
279a35d7 227 fITSmodules = 0;
88cb7938 228 }// end if fITSmodules!=0
229
7d62fb64 230 delete[] fIdName; // Array of TStrings
231 delete[] fIdSens;
afbc83e9 232 Int_t size = 0;
7d62fb64 233 if (fDetTypeSim){
4ce766eb 234 if (GetITSgeom()) size = GetITSgeom()->GetIndexMax();
7d62fb64 235 delete fDetTypeSim;
236 fDetTypeSim = 0;
c8af5b8f 237 }
238 if(fSimuParam){
239 delete fSimuParam;
240 fSimuParam=0;
241 }
afbc83e9 242 if(fModA){
243 if(size>0){
244 for(Int_t j=0; j<size; j++){
245 fModA[j]->Delete();
246 delete fModA[j];
247 }
248 }
249 delete []fModA;
250 }
251 if(fpSDigits){
252 fpSDigits->Delete();
253 delete fpSDigits;
254 }
3bd79107 255}
2aea926d 256//______________________________________________________________________
aacedc3e 257AliDigitizer* AliITS::CreateDigitizer(AliRunDigitizer* manager)const{
258 // Creates the AliITSDigitizer in a standard way for use via AliModule.
259 // This function can not be included in the .h file because of problems
260 // with the order of inclusion (recursive).
4a5bebc2 261 // Inputs:
aacedc3e 262 // AliRunDigitizer *manager The Manger class for Digitization
263 // Output:
264 // none.
4a5bebc2 265 // Return:
aacedc3e 266 // A new AliITSRunDigitizer (cast as a AliDigitizer).
3bd79107 267
aacedc3e 268 return new AliITSDigitizer(manager);
3bd79107 269}
2aea926d 270//______________________________________________________________________
271void AliITS::Init(){
4a5bebc2 272 // Initializer ITS after it has been built
2aea926d 273 // This routine initializes the AliITS class. It is intended to be
274 // called from the Init function in AliITSv?. Besides displaying a banner
275 // indicating that it has been called it initializes the array fIdSens
276 // and sets the default segmentation, response, digit and raw cluster
277 // classes therefore it should be called after a call to CreateGeometry.
4a5bebc2 278 // Inputs:
279 // none.
280 // Outputs:
281 // none.
282 // Return:
283 // none.
3bd79107 284 Int_t i;
2aea926d 285 // Array of TStrings
0e73d04c 286 if(gMC) for(i=0;i<fIdN;i++) fIdSens[i] = gMC->VolId(fIdName[i]);
7d62fb64 287
3bd79107 288}
2aea926d 289//______________________________________________________________________
290void AliITS::SetDefaults(){
4a5bebc2 291 // sets the default segmentation, response, digit and raw cluster classes.
292 // Inputs:
293 // none.
294 // Outputs:
295 // none.
296 // Return:
297 // none.
023ae34b 298 AliInfoClass("AliITS::Setting Defaults");
7d62fb64 299 if(!fDetTypeSim) {
300 Error("SetDefaults()","fDetTypeSim is 0!");
301 return;
302 }
303
304 fDetTypeSim->SetDefaults();
c8af5b8f 305 if(fSimuParam) fDetTypeSim->SetSimuParam(fSimuParam);
7d62fb64 306
3bd79107 307}
2aea926d 308//______________________________________________________________________
309void AliITS::SetDefaultSimulation(){
4a5bebc2 310 // sets the default simulation.
311 // Inputs:
312 // none.
313 // Outputs:
314 // none.
315 // Return:
316 // none.
7d62fb64 317 if(!fDetTypeSim) {
318 Error("SetDefaultSimulation()","fDetTypeSim is 0!");
319 return;
320 }
321
322 fDetTypeSim->SetDefaultSimulation();
c8af5b8f 323 if(fSimuParam) fDetTypeSim->SetSimuParam(fSimuParam);
04366a57 324
04366a57 325}
326
327
2aea926d 328//______________________________________________________________________
88cb7938 329void AliITS::MakeBranch(Option_t* option){
2aea926d 330 // Creates Tree branches for the ITS.
4a5bebc2 331 // Inputs:
332 // Option_t *option String of Tree types S,D, and/or R.
333 // const char *file String of the file name where these branches
334 // are to be stored. If blank then these branches
335 // are written to the same tree as the Hits were
336 // read from.
337 // Outputs:
338 // none.
339 // Return:
340 // none.
7d62fb64 341 if(!fDetTypeSim) {
342 Error("MakeBranch","fDetTypeSim is 0!");
343 return;
344 }
04366a57 345
7d62fb64 346 Bool_t cH = (strstr(option,"H")!=0);
347 Bool_t cS = (strstr(option,"S")!=0);
348 Bool_t cD = (strstr(option,"D")!=0);
349
350 if(cH && (fHits == 0x0)) fHits = new TClonesArray("AliITShit", 1560);
351 AliDetector::MakeBranch(option);
352
353 if(cS) MakeBranchS(0);
354 if(cD) MakeBranchD(0);
355
356
357}
358//___________________________________________________________________
359void AliITS::MakeBranchS(const char* fl){
360
361 // Creates Tree Branch for the ITS summable digits.
362 // Inputs:
363 // cont char *fl File name where SDigits branch is to be written
364 // to. If blank it write the SDigits to the same
365 // file in which the Hits were found.
366
367
368 if(!fDetTypeSim){
369 Error("MakeBranchS","fDetTypeSim is 0!");
370 }
371 Int_t buffersize = 4000;
372 char branchname[30];
373
374 // only one branch for SDigits.
375 sprintf(branchname,"%s",GetName());
376
377 if(fLoader->TreeS()){
7d62fb64 378 TClonesArray* sdig = (TClonesArray*)fDetTypeSim->GetSDigits();
379 MakeBranchInTree(fLoader->TreeS(),branchname,&sdig,buffersize,fl);
380 }
381}
382//______________________________________________________________________
383void AliITS::MakeBranchD(const char* file){
384
385 //Make branch for digits
386 if(!fDetTypeSim) {
387 Warning("MakeBranchD","fDetTypeSim is 0!");
388 return;
389 }
023ae34b 390 fDetTypeSim->SetLoader((AliITSLoader*)fLoader);
c8af5b8f 391 if(fSimuParam) fDetTypeSim->SetSimuParam(fSimuParam);
7d62fb64 392 MakeBranchInTreeD(fLoader->TreeD(),file);
393}
394
395//___________________________________________________________________
396void AliITS:: MakeBranchInTreeD(TTree* treeD, const char* file){
397 // Creates Tree branches for the ITS.
398
399 if(!fDetTypeSim){
400 Error("MakeBranchS","fDetTypeSim is 0!");
401 }
023ae34b 402 fDetTypeSim->SetLoader((AliITSLoader*)fLoader);
c8af5b8f 403 if(fSimuParam) fDetTypeSim->SetSimuParam(fSimuParam);
7d62fb64 404
405 const Char_t *det[3] = {"SPD","SDD","SSD"};
a6e0ebfe 406 const Char_t* digclass;
7d62fb64 407 Int_t buffersize = 4000;
408 Char_t branchname[30];
409
410 if(!fDetTypeSim->GetDigits()){
411 fDetTypeSim->SetDigits(new TObjArray(fgkNTYPES));
412 }
413 for(Int_t i=0;i<fgkNTYPES;i++){
414 digclass = fDetTypeSim->GetDigitClassName(i);
415 TString classn = digclass;
416 if(!((fDetTypeSim->GetDigits())->At(i))){
417 (fDetTypeSim->GetDigits())->AddAt(new TClonesArray(classn.Data(),1000),i);
418 }
419 else ResetDigits(i);
420 if(fgkNTYPES==3) sprintf(branchname,"%sDigits%s",GetName(),det[i]);
421 else sprintf(branchname,"%sDigits%d",GetName(),i+1);
422 TObjArray* dig = DigitsAddress(i);
423 if(GetDigits() && treeD) AliDetector::MakeBranchInTree(treeD,branchname, &dig,buffersize,file);
424 }
2aea926d 425
fe4da5cc 426}
2aea926d 427//______________________________________________________________________
428void AliITS::SetTreeAddress(){
429 // Set branch address for the Trees.
4a5bebc2 430 // Inputs:
431 // none.
432 // Outputs:
433 // none.
434 // Return:
435 // none.
023ae34b 436
7d62fb64 437 if(!fDetTypeSim) {
438 Error("SetTreeAddress","fDetTypeSim is 0!");
439 return;
440 }
441
023ae34b 442 fDetTypeSim->SetLoader((AliITSLoader*)fLoader);
c8af5b8f 443 if(fSimuParam) fDetTypeSim->SetSimuParam(fSimuParam);
7d62fb64 444
445 TTree *treeS = fLoader->TreeS();
446 TTree *treeD = fLoader->TreeD();
447 if (fLoader->TreeH() && (fHits == 0x0)) {
448 fHits = new TClonesArray("AliITShit", 1560);
449 }
450 AliDetector::SetTreeAddress();
451
452 fDetTypeSim->SetTreeAddressS(treeS, (Char_t*)GetName());
453 fDetTypeSim->SetTreeAddressD(treeD, (Char_t*)GetName());
fe4da5cc 454}
2aea926d 455//______________________________________________________________________
2aea926d 456void AliITS::AddHit(Int_t track, Int_t *vol, Float_t *hits){
457 // Add an ITS hit
458 // The function to add information to the AliITShit class. See the
459 // AliITShit class for a full description. This function allocates the
460 // necessary new space for the hit information and passes the variable
461 // track, and the pointers *vol and *hits to the AliITShit constructor
462 // function.
4a5bebc2 463 // Inputs:
464 // Int_t track Track number which produced this hit.
465 // Int_t *vol Array of Integer Hit information. See AliITShit.h
466 // Float_t *hits Array of Floating Hit information. see AliITShit.h
467 // Outputs:
468 // none.
469 // Return:
470 // none.
7d62fb64 471 TClonesArray &lhits = *fHits;
472 new(lhits[fNhits++]) AliITShit(fIshunt,track,vol,hits);
3bd79107 473}
3bd79107 474
2aea926d 475//______________________________________________________________________
476void AliITS::FillModules(Int_t evnt,Int_t bgrev,Int_t nmodules,
8e8eae84 477 Option_t *option, const char *filename){
7d62fb64 478 // fill the modules with the sorted by module hits; add hits from
479 // background if option=Add.
480
481 static TTree *trH1; //Tree with background hits
482 static Bool_t first=kTRUE;
483 static TFile *file;
484 const char *addBgr = strstr(option,"Add");
485
486 evnt = nmodules; // Dummy use of variables to remove warnings
487 if (addBgr ) {
488 if(first) {
489 file=new TFile(filename);
490 } // end if first
491 first=kFALSE;
492 file->cd();
493 file->ls();
494 // Get Hits Tree header from file
495 if(trH1) delete trH1;
496 trH1=0;
497
498 char treeName[20];
499 sprintf(treeName,"TreeH%d",bgrev);
500 trH1 = (TTree*)gDirectory->Get(treeName);
501 if (!trH1) {
502 Error("FillModules","cannot find Hits Tree for event:%d",bgrev);
503 } // end if !trH1
504 // Set branch addresses
505 } // end if addBgr
506
507 FillModules(fLoader->TreeH(),0); // fill from this file's tree.
3bd79107 508
7d62fb64 509 if (addBgr ) {
510 FillModules(trH1,10000000); // Default mask 10M.
511 TTree *fAli=fLoader->GetRunLoader()->TreeK();
512 TFile *fileAli=0;
513 if (fAli) fileAli =fAli->GetCurrentFile();
514 fileAli->cd();
515 } // end if add
516
517
3bd79107 518}
2aea926d 519//______________________________________________________________________
b4012daf 520void AliITS::FillModules(TTree *treeH, Int_t mask) {
521 // fill the modules with the sorted by module hits;
522 // can be called many times to do a merging
523 // Inputs:
524 // TTree *treeH The tree containing the hits to be copied into
525 // the modules.
526 // Int_t mask The track number mask to indecate which file
527 // this hits came from.
528 // Outputs:
529 // none.
530 // Return:
531 // none.
532
88cb7938 533 if (treeH == 0x0)
534 {
535 Error("FillModules","Tree is NULL");
536 }
b4012daf 537 Int_t lay,lad,det,index;
538 AliITShit *itsHit=0;
539 AliITSmodule *mod=0;
540 char branchname[20];
541 sprintf(branchname,"%s",GetName());
542 TBranch *branch = treeH->GetBranch(branchname);
543 if (!branch) {
88cb7938 544 Error("FillModules","%s branch in TreeH not found",branchname);
545 return;
b4012daf 546 } // end if !branch
547 branch->SetAddress(&fHits);
548 Int_t nTracks =(Int_t) treeH->GetEntries();
549 Int_t iPrimTrack,h;
550 for(iPrimTrack=0; iPrimTrack<nTracks; iPrimTrack++){
88cb7938 551 ResetHits();
552 Int_t nBytes = treeH->GetEvent(iPrimTrack);
553 if (nBytes <= 0) continue;
554 Int_t nHits = fHits->GetEntriesFast();
555 for(h=0; h<nHits; h++){
556 itsHit = (AliITShit *)fHits->UncheckedAt(h);
557 itsHit->GetDetectorID(lay,lad,det);
7d62fb64 558 if (GetITSgeom()) {
559 index = GetITSgeom()->GetModuleIndex(lay,lad,det);
88cb7938 560 } else {
561 index=det-1; // This should not be used.
562 } // end if [You must have fITSgeom for this to work!]
563 mod = GetModule(index);
564 itsHit->SetTrack(itsHit->GetTrack()+mask); // Set track mask.
565 mod->AddHit(itsHit,iPrimTrack,h);
566 } // end loop over hits
b4012daf 567 } // end loop over tracks
568}
7d62fb64 569
b4012daf 570//______________________________________________________________________
6f5308d9 571Bool_t AliITS::InitModules(Int_t size,Int_t &nmodules){
7d62fb64 572 // Initialize the modules array.
4a5bebc2 573 // Inputs:
7d62fb64 574 // Int_t size Size of array of the number of modules to be
575 // created. If size <=0 then the number of modules
576 // is gotten from AliITSgeom class kept in fITSgeom.
4a5bebc2 577 // Outputs:
7d62fb64 578 // Int_t &nmodules The number of modules existing.
4a5bebc2 579 // Return:
580 // none.
2ab0c725 581
7d62fb64 582 if(fITSmodules){
583 fITSmodules->Delete();
584 delete fITSmodules;
585 } // end fir fITSmoudles
88cb7938 586
7d62fb64 587 if(!fDetTypeSim) {
588 Error("InitModules","fDetTypeSim is null!");
6f5308d9 589 return kFALSE;
7d62fb64 590 }
c8af5b8f 591 if(fSimuParam) fDetTypeSim->SetSimuParam(fSimuParam);
828e06c7 592
7d62fb64 593 Int_t nl,indexMAX,index;
594
595 if(size<=0){ // default to using data stored in AliITSgeom
596 if(fDetTypeSim->GetITSgeom()==0) {
597 Error("InitModules","fITSgeom not defined");
6f5308d9 598 return kFALSE;
7d62fb64 599 } // end if fITSgeom==0
600 nl = fDetTypeSim->GetITSgeom()->GetNlayers();
601 indexMAX = fDetTypeSim->GetITSgeom()->GetIndexMax();
602 nmodules = indexMAX;
603 fITSmodules = new TObjArray(indexMAX);
604 for(index=0;index<indexMAX;index++){
605 fITSmodules->AddAt( new AliITSmodule(index),index);
606 } // end for index
607 }else{
608 fITSmodules = new TObjArray(size);
609 for(index=0;index<size;index++) {
610 fITSmodules->AddAt( new AliITSmodule(index),index);
611 } // end for index
612
613 nmodules = size;
614 } // end i size<=0
6f5308d9 615 return kTRUE;
2aea926d 616}
617//______________________________________________________________________
618void AliITS::Hits2SDigits(){
619 // Standard Hits to summable Digits function.
4a5bebc2 620 // Inputs:
621 // none.
622 // Outputs:
623 // none.
7d62fb64 624
2aea926d 625
7d62fb64 626 if(!fDetTypeSim) {
627 Error("Hits2SDigits","fDetTypeSim is null!");
ad7f2bfa 628 return;
7d62fb64 629 }
630
631 SetDefaults();
632 fLoader->LoadHits("read");
633 fLoader->LoadSDigits("recreate");
634 AliRunLoader* rl = fLoader->GetRunLoader();
023ae34b 635 fDetTypeSim->SetLoader((AliITSLoader*)fLoader);
c8af5b8f 636 if(fSimuParam) fDetTypeSim->SetSimuParam(fSimuParam);
637
7d62fb64 638 for (Int_t iEvent = 0; iEvent < rl->GetNumberOfEvents(); iEvent++) {
aacedc3e 639 // Do the Hits to Digits operation. Use Standard input values.
640 // Event number from file, no background hit merging , use size from
641 // AliITSgeom class, option="All", input from this file only.
7d62fb64 642 rl->GetEvent(iEvent);
643 if (!fLoader->TreeS()) fLoader->MakeTree("S");
644 MakeBranch("S");
645 SetTreeAddress();
646 HitsToPreDigits(iEvent,0,-1," ",fOpt," ");
647 } // end for iEvent
88cb7938 648
7d62fb64 649 fLoader->UnloadHits();
650 fLoader->UnloadSDigits();
651
85a5290f 652}
653//______________________________________________________________________
7d62fb64 654void AliITS::Hits2Digits(){
655
656 //Conversion from hits to digits
657 if(!fDetTypeSim) {
658 Error("Hits2SDigits","fDetTypeSim is 0!");
659 return;
660 }
661
023ae34b 662 fDetTypeSim->SetLoader((AliITSLoader*)fLoader);
c8af5b8f 663 if(fSimuParam) fDetTypeSim->SetSimuParam(fSimuParam);
7d62fb64 664 SetDefaults();
665
666 fLoader->LoadHits("read");
667 fLoader->LoadDigits("recreate");
668 AliRunLoader* rl = fLoader->GetRunLoader();
669 for (Int_t iEvent = 0; iEvent < rl->GetNumberOfEvents(); iEvent++) {
670 rl->GetEvent(iEvent);
671 if (!fLoader->TreeD()) fLoader->MakeTree("D");
672 MakeBranch("D");
673 SetTreeAddress();
674 HitsToDigits(iEvent,0,-1," ",fOpt," ");
675 }
676
677 fLoader->UnloadHits();
678 fLoader->UnloadDigits();
679
2aea926d 680}
7d62fb64 681
2aea926d 682//______________________________________________________________________
7d62fb64 683void AliITS::HitsToDigits(Int_t evNumber,Int_t bgrev,Int_t size,
684 Option_t *option,Option_t *opt,
685 const char *filename){
686 // Keep galice.root for signal and name differently the file for
687 // background when add! otherwise the track info for signal will be lost !
688 // the condition below will disappear when the geom class will be
689 // initialized for all versions - for the moment it is only for v5 !
690 // 7 is the SDD beam test version.
4a5bebc2 691 // Inputs:
7d62fb64 692 // Int_t evnt Event to be processed.
693 // Int_t bgrev Background Hit tree number.
694 // Int_t nmodules Not used.
695 // Option_t *option String indicating if merging hits or not. To
696 // merge hits set equal to "Add". Otherwise no
697 // background hits are considered.
698 // Test_t *filename File name containing the background hits..
4a5bebc2 699 // Outputs:
700 // none.
7d62fb64 701 // Return:
702 // none.
2aea926d 703
7d62fb64 704 if(!fDetTypeSim) {
705 Error("HitsToDigits","fDetTypeSim is null!");
706 return;
707 }
023ae34b 708 fDetTypeSim->SetLoader((AliITSLoader*)fLoader);
c8af5b8f 709 if(fSimuParam) fDetTypeSim->SetSimuParam(fSimuParam);
7d62fb64 710 if(!GetITSgeom()) return; // need transformations to do digitization.
711 AliITSgeom *geom = GetITSgeom();
85a5290f 712
7d62fb64 713 const char *all = strstr(opt,"All");
714 const char *det[3] = {strstr(opt,"SPD"),strstr(opt,"SDD"),
715 strstr(opt,"SSD")};
716 static Bool_t setDef=kTRUE;
717 if (setDef) SetDefaultSimulation();
718 setDef=kFALSE;
719
720 Int_t nmodules;
721 InitModules(size,nmodules);
722 FillModules(evNumber,bgrev,nmodules,option,filename);
ad7f2bfa 723
724 // Reset Fast-OR signals for this event
725 fDetTypeSim->ResetFOSignals();
7d62fb64 726
727 AliITSsimulation *sim = 0;
728 AliITSmodule *mod = 0;
729 Int_t id;
730 for(Int_t module=0;module<geom->GetIndexMax();module++){
731 id = geom->GetModuleType(module);
732 if (!all && !det[id]) continue;
733 sim = (AliITSsimulation*)fDetTypeSim->GetSimulationModel(id);
734 if (!sim) {
735 Error("HitsToDigits","The simulation class was not "
736 "instanciated for module %d type %s!",module,
737 geom->GetModuleTypeName(module));
738 exit(1);
739 } // end if !sim
740 mod = (AliITSmodule *)fITSmodules->At(module);
741 sim->DigitiseModule(mod,module,evNumber);
742 // fills all branches - wasted disk space
743 fLoader->TreeD()->Fill();
744 ResetDigits();
745 } // end for module
746
747 ClearModules();
a0d76912 748
ad7f2bfa 749 // Add random noise to FO signals
750 if (all || det[0]) { // SPD present
751 fDetTypeSim->ProcessNoiseForFastOr();
752 }
753
754 // Add Fast-OR signals to event (only one object per event)
755 if (all || det[0]) { // SPD present
756 fDetTypeSim->WriteFOSignals();
757 }
758
759
7d62fb64 760 fLoader->TreeD()->GetEntries();
761 fLoader->TreeD()->AutoSave();
762 // reset tree
763 fLoader->TreeD()->Reset();
2aea926d 764}
7d62fb64 765//_____________________________________________________________________
766void AliITS::Hits2PreDigits(){
767 // Turn hits into SDigits
768
769 if(!fDetTypeSim) {
770 Error("Hits2SDigits","fDetTypeSim is 0!");
771 return;
772 }
773
023ae34b 774 fDetTypeSim->SetLoader((AliITSLoader*)fLoader);
c8af5b8f 775 if(fSimuParam) fDetTypeSim->SetSimuParam(fSimuParam);
7d62fb64 776 SetDefaults();
777
778 HitsToPreDigits(fLoader->GetRunLoader()->GetEventNumber(),
779 0,-1," ",fOpt," ");
780}
781
2aea926d 782//______________________________________________________________________
2aea926d 783void AliITS::HitsToPreDigits(Int_t evNumber,Int_t bgrev,Int_t size,
aacedc3e 784 Option_t *option,Option_t *opt,
785 const char *filename){
4a5bebc2 786 // Keep galice.root for signal and name differently the file for
2aea926d 787 // background when add! otherwise the track info for signal will be lost !
788 // the condition below will disappear when the geom class will be
4a5bebc2 789 // initialized for all versions - for the moment it is only for v5 !
790 // 7 is the SDD beam test version.
791 // Inputs:
792 // Int_t evnt Event to be processed.
793 // Int_t bgrev Background Hit tree number.
794 // Int_t nmodules Not used.
795 // Option_t *option String indicating if merging hits or not. To
796 // merge hits set equal to "Add". Otherwise no
797 // background hits are considered.
798 // Test_t *filename File name containing the background hits..
799 // Outputs:
800 // none.
801 // Return:
802 // none.
2aea926d 803
7d62fb64 804
805 if(!fDetTypeSim) {
806 Error("HitsToPreDigits","fDetTypeSim is null!");
807 return;
808 }
023ae34b 809 fDetTypeSim->SetLoader((AliITSLoader*)fLoader);
c8af5b8f 810 if(fSimuParam) fDetTypeSim->SetSimuParam(fSimuParam);
7d62fb64 811
812 if(!GetITSgeom()){
813 Error("HitsToPreDigits","fGeom is null!");
814 return; // need transformations to do digitization.
815 }
816 AliITSgeom *geom = GetITSgeom();
817
818 const char *all = strstr(opt,"All");
819 const char *det[3] = {strstr(opt,"SPD"),strstr(opt,"SDD"),
820 strstr(opt,"SSD")};
821 static Bool_t setDef=kTRUE;
822 if (setDef) SetDefaultSimulation();
823 setDef=kFALSE;
824
825 Int_t nmodules;
826 InitModules(size,nmodules);
827 FillModules(evNumber,bgrev,nmodules,option,filename);
828
829
830 AliITSsimulation *sim = 0;
831 AliITSmodule *mod = 0;
832 Int_t id,module;
833 for(module=0;module<geom->GetIndexMax();module++){
834 id = geom->GetModuleType(module);
835 if (!all && !det[id]) continue;
836 sim = (AliITSsimulation*)GetSimulationModel(id);
837 if (!sim) {
838 Error("HitsToPreDigits","The simulation class was not "
839 "instanciated for module %d type %s!",module,
840 geom->GetModuleTypeName(module));
841 exit(1);
842 } // end if !sim
843 mod = (AliITSmodule *)fITSmodules->At(module);
844 sim->SDigitiseModule(mod,module,evNumber);
845 // fills all branches - wasted disk space
846 fLoader->TreeS()->Fill();
847 fDetTypeSim->ResetSDigits();
848 } // end for module
849
850 ClearModules();
851
852
853 fLoader->TreeS()->GetEntries();
854 fLoader->TreeS()->AutoSave();
855 fLoader->WriteSDigits("OVERWRITE");
856 // reset tree
857 fLoader->TreeS()->Reset();
2aea926d 858}
7d62fb64 859
860//_____________________________________________________________________
861void AliITS::HitsToFastRecPoints(Int_t evNumber,Int_t bgrev,Int_t size,
862 Option_t *opt0,Option_t *opt1,
863 const char *flnm){
864 // keep galice.root for signal and name differently the file for
2aea926d 865 // background when add! otherwise the track info for signal will be lost !
866 // the condition below will disappear when the geom class will be
4a5bebc2 867 // initialized for all versions - for the moment it is only for v5 !
4a5bebc2 868 // Inputs:
869 // Int_t evnt Event to be processed.
870 // Int_t bgrev Background Hit tree number.
7d62fb64 871 // Int_t size Size used by InitModules. See InitModules.
872 // Option_t *opt0 Option passed to FillModules. See FillModules.
873 // Option_t *opt1 String indicating if merging hits or not. To
4a5bebc2 874 // merge hits set equal to "Add". Otherwise no
875 // background hits are considered.
7d62fb64 876 // Test_t *flnm File name containing the background hits..
4a5bebc2 877 // Outputs:
878 // none.
879 // Return:
880 // none.
881
04366a57 882
00a7cc50 883
7d62fb64 884 if(!GetITSgeom()){
885 Error("HitsToPreDigits","fGeom is null!");
886 return; // need transformations to do digitization.
887 }
888 AliITSgeom *geom = GetITSgeom();
889
890 AliITSLoader *pITSloader = (AliITSLoader*)fLoader;
891
892 const char *all = strstr(opt1,"All");
893 const char *det[3] ={strstr(opt1,"SPD"),strstr(opt1,"SDD"),
894 strstr(opt1,"SSD")};
895 Int_t nmodules;
896 InitModules(size,nmodules);
897 FillModules(evNumber,bgrev,nmodules,opt0,flnm);
898
899 AliITSsimulation *sim = 0;
900 AliITSmodule *mod = 0;
901 Int_t id,module;
902
903 TTree *lTR = pITSloader->TreeR();
00a7cc50 904 if(!lTR) {
905 pITSloader->MakeTree("R");
906 lTR = pITSloader->TreeR();
907 }
908
7d62fb64 909 TClonesArray* ptarray = new TClonesArray("AliITSRecPoint",1000);
00a7cc50 910 TBranch* branch = (TBranch*)lTR->Branch("ITSRecPointsF",&ptarray);
911 branch->SetAddress(&ptarray);
7d62fb64 912 //m.b. : this change is nothing but a nice way to make sure
023ae34b 913 //the CPU goes up !
7d62fb64 914 for(module=0;module<geom->GetIndexMax();module++){
915 id = geom->GetModuleType(module);
916 if (!all && !det[id]) continue;
917 sim = (AliITSsimulation*)GetSimulationModel(id);
918 if (!sim) {
919 Error("HitsToFastPoints","The simulation class was not "
a5a317a9 920 "instantiated for module %d type %s!",module,
7d62fb64 921 geom->GetModuleTypeName(module));
922 exit(1);
923 } // end if !sim
924 mod = (AliITSmodule *)fITSmodules->At(module);
925 sim->CreateFastRecPoints(mod,module,gRandom,ptarray);
926 lTR->Fill();
f1bfe73f 927 ptarray->Clear();
7d62fb64 928 } // end for module
929
930 ClearModules();
931 fLoader->WriteRecPoints("OVERWRITE");
932 delete ptarray;
2aea926d 933}
7d62fb64 934//_____________________________________________________________________
935Int_t AliITS::Hits2Clusters(TTree *hTree, TTree *cTree) {
936 //------------------------------------------------------------
937 // This function creates ITS clusters
938 //------------------------------------------------------------
939 if(!GetITSgeom()){
940 Error("HitsToPreDigits","fGeom is null!");
941 return 1; // need transformations to do digitization.
942 }
943 AliITSgeom *geom=GetITSgeom();
944 Int_t mmax=geom->GetIndexMax();
945
946 InitModules(-1,mmax);
947 FillModules(hTree,0);
948
7d62fb64 949 TClonesArray *points = new TClonesArray("AliITSRecPoint",1000);
00a7cc50 950 TBranch *branch=cTree->GetBranch("ITSRecPoints");
951 if (!branch) cTree->Branch("ITSRecPoints",&points);
952 else branch->SetAddress(&points);
7d62fb64 953
954 AliITSsimulationFastPoints sim;
955 Int_t ncl=0;
956 for (Int_t m=0; m<mmax; m++) {
957 AliITSmodule *mod=GetModule(m);
958 sim.CreateFastRecPoints(mod,m,gRandom,points);
00a7cc50 959 ncl+=points->GetEntriesFast();
7d62fb64 960 cTree->Fill();
7d62fb64 961 points->Clear();
962 }
963
15e6a32c 964 AliDebug(1,Form("Number of found fast clusters : %d",ncl));
7d62fb64 965
966 //cTree->Write();
967
7d62fb64 968 delete points;
969 return 0;
970}
7d62fb64 971
7d62fb64 972//_____________________________________________________________________
973void AliITS::CheckLabels(Int_t lab[3]) const {
974 //------------------------------------------------------------
975 // Tries to find mother's labels
976 //------------------------------------------------------------
977
978 if(lab[0]<0 && lab[1]<0 && lab[2]<0) return; // In case of no labels just exit
979
980 Int_t ntracks = gAlice->GetMCApp()->GetNtrack();
981 for (Int_t i=0;i<3;i++){
982 Int_t label = lab[i];
983 if (label>=0 && label<ntracks) {
984 TParticle *part=(TParticle*)gAlice->GetMCApp()->Particle(label);
985 if (part->P() < 0.005) {
986 Int_t m=part->GetFirstMother();
987 if (m<0) {
988 continue;
989 }
990 if (part->GetStatusCode()>0) {
991 continue;
992 }
993 lab[i]=m;
994 }
995 }
996 }
997
998}
999
1000//______________________________________________________________________
1001void AliITS::SDigitsToDigits(Option_t *opt){
ad7f2bfa 1002 // Standard Summable digits to Digits function.
1003 // Inputs:
1004 // none.
1005 // Outputs:
1006 // none.
1007 if (!fDetTypeSim) {
1008 AliError("fDetTypeSim is 0!");
1009 return;
1010 }
7d62fb64 1011
ad7f2bfa 1012 const char *all = strstr(opt,"All");
1013 const char *det[3] ={strstr(opt,"SPD"),strstr(opt,"SDD"),
1014 strstr(opt,"SSD")};
1015
1016 // Reset Fast-OR signals for this event
1017 fDetTypeSim->ResetFOSignals();
1018
1019 fDetTypeSim->SetLoader((AliITSLoader*)fLoader);
1020 SetDefaults();
c8af5b8f 1021 if(fSimuParam) fDetTypeSim->SetSimuParam(fSimuParam);
ad7f2bfa 1022 fDetTypeSim->SDigitsToDigits(opt,(Char_t*)GetName());
1023
1024 // Add random noise to FO signals
1025 if (all || det[0]) { // SPD present
1026 fDetTypeSim->ProcessNoiseForFastOr();
1027 }
1028 // Add Fast-OR signals to event (only one object per event)
1029 if (all || det[0]) { // SPD present
1030 fDetTypeSim->WriteFOSignals();
1031 }
7d62fb64 1032}
1033
2aea926d 1034//______________________________________________________________________
2aea926d 1035void AliITS::ResetDigits(){
4a5bebc2 1036 // Reset number of digits and the digits array for the ITS detector.
1037 // Inputs:
1038 // none.
1039 // Outputs:
1040 // none.
7d62fb64 1041 if(!fDetTypeSim) {
1042 Error("ResetDigits","fDetTypeSim is 0!");
1043 return;
1044 }
1045
1046 fDetTypeSim->ResetDigits();
3bd79107 1047
1048
2aea926d 1049}
1050//______________________________________________________________________
7d62fb64 1051void AliITS::ResetDigits(Int_t branch){
4a5bebc2 1052 // Reset number of digits and the digits array for this branch.
1053 // Inputs:
1054 // none.
1055 // Outputs:
1056 // none.
828e06c7 1057
7d62fb64 1058 if(!fDetTypeSim) {
1059 Error("ResetDigits","fDetTypeSim is 0!");
1060 return;
1061 }
1062
1063 fDetTypeSim->ResetDigits(branch);
1064
2aea926d 1065}
1066//______________________________________________________________________
1067void AliITS::AddSumDigit(AliITSpListItem &sdig){
4a5bebc2 1068 // Adds the a module full of summable digits to the summable digits tree.
1069 // Inputs:
1070 // AliITSpListItem &sdig SDigit to be added to SDigits tree.
1071 // Outputs:
1072 // none.
1073 // Return:
1074 // none.
828e06c7 1075
7d62fb64 1076 if(!fDetTypeSim) {
1077 Error("AddSumDigit","fDetTypeSim is 0!");
1078 return;
1079 }
1080 fDetTypeSim->AddSumDigit(sdig);
1081
828e06c7 1082}
2aea926d 1083//______________________________________________________________________
7d62fb64 1084void AliITS::AddSimDigit(Int_t branch, AliITSdigit *d){
4a5bebc2 1085 // Add a simulated digit.
1086 // Inputs:
1087 // Int_t id Detector type number.
1088 // AliITSdigit *d Digit to be added to the Digits Tree. See
1089 // AliITSdigit.h
1090 // Outputs:
1091 // none.
1092 // Return:
1093 // none.
2aea926d 1094
7d62fb64 1095 if(!fDetTypeSim) {
1096 Error("AddSimDigit","fDetTypeSim is 0!");
1097 return;
1098 }
1099 fDetTypeSim->AddSimDigit(branch,d);
1100
2aea926d 1101}
1102//______________________________________________________________________
7d62fb64 1103void AliITS::AddSimDigit(Int_t branch,Float_t phys,Int_t *digits,Int_t *tracks,
83ec5e27 1104 Int_t *hits,Float_t *charges, Int_t sigexpanded){
7f1a504b 1105 // Add a simulated digit to the list.
1106 // Inputs:
1107 // Int_t id Detector type number.
1108 // Float_t phys Physics indicator. See AliITSdigits.h
1109 // Int_t *digits Integer array containing the digits info. See
1110 // AliITSdigit.h
1111 // Int_t *tracks Integer array [AliITSdigitS?D::GetNTracks()]
1112 // containing the track numbers that contributed to
1113 // this digit.
1114 // Int_t *hits Integer array [AliITSdigitS?D::GetNTracks()]
1115 // containing the hit numbers, from AliITSmodule, that
1116 // contributed to this digit.
1117 // Float_t *charge Floating point array of the signals contributed
1118 // to this digit by each track.
1119 // Outputs:
1120 // none.
1121 // Return:
1122 // none.
2aea926d 1123
7d62fb64 1124 if(!fDetTypeSim) {
1125 Error("AddSimDigit","fDetTypeSim is 0!");
1126 return;
1127 }
83ec5e27 1128 fDetTypeSim->AddSimDigit(branch,phys,digits,tracks,hits,charges,sigexpanded);
7d62fb64 1129
2aea926d 1130}
0421c3d1 1131//______________________________________________________________________
aacedc3e 1132void AliITS::Digits2Raw(){
1133 // convert digits of the current event to raw data
0421c3d1 1134
7d62fb64 1135 if(!fDetTypeSim) {
1136 Error("Digits2Raw","fDetTypeSim is 0!");
1137 return;
1138 }
023ae34b 1139 fDetTypeSim->SetLoader((AliITSLoader*)fLoader);
7d62fb64 1140 SetDefaults();
c8af5b8f 1141 if(fSimuParam) fDetTypeSim->SetSimuParam(fSimuParam);
7d62fb64 1142 fDetTypeSim->GetLoader()->LoadDigits();
1143 TTree* digits = fDetTypeSim->GetLoader()->TreeD();
0421c3d1 1144 if (!digits) {
aacedc3e 1145 Error("Digits2Raw", "no digits tree");
1146 return;
0421c3d1 1147 }
7d62fb64 1148 fDetTypeSim->SetTreeAddressD(digits,(Char_t*)GetName());
ad7f2bfa 1149
1150 // Get the FO signals for this event
1151 AliITSFOSignalsSPD* foSignals = NULL;
1152 AliRunLoader* runLoader = AliRunLoader::Instance();
1153 AliITSLoader* itsLoader = (AliITSLoader*) runLoader->GetLoader("ITSLoader");
1154 if (!itsLoader) {
1155 AliError("ITS loader is NULL.");
1156 }
a0d76912 1157 else {
1158 if(!itsLoader->TreeD()) AliError(" !!! No TreeD available !!!");
1159 foSignals = (AliITSFOSignalsSPD*)itsLoader->TreeD()->GetUserInfo()->FindObject("AliITSFOSignalsSPD");
1160 if(!foSignals) AliError("FO signals not retrieved");
1161 }
1162
ad7f2bfa 1163 Bool_t deleteFOsignalsLater = kFALSE;
1164 if (!foSignals) {
1165 AliError("FO signals not available. No FO bits will be written.");
1166 foSignals = new AliITSFOSignalsSPD(); // make a temporary dummy signals object
1167 deleteFOsignalsLater = kTRUE;
1168 }
1169
1170
979b5a5f 1171 AliITSDDLModuleMapSDD* ddlsdd=fDetTypeSim->GetDDLModuleMapSDD();
d9ed1779 1172 Char_t rawSDD=fDetTypeSim->GetSimuParam()->GetSDDRawDataFormat();
0421c3d1 1173 AliITSDDLRawData rawWriter;
d9ed1779 1174
1175 rawWriter.SetSDDRawFormat(rawSDD);
0421c3d1 1176 //Verbose level
1177 // 0: Silent
1178 // 1: cout messages
1179 // 2: txt files with digits
1180 //BE CAREFUL, verbose level 2 MUST be used only for debugging and
1181 //it is highly suggested to use this mode only for debugging digits files
1182 //reasonably small, because otherwise the size of the txt files can reach
1183 //quickly several MB wasting time and disk space.
1184 rawWriter.SetVerbose(0);
1185
1186 //SILICON PIXEL DETECTOR
15e6a32c 1187 AliDebug(1,"Formatting raw data for SPD");
ad7f2bfa 1188 rawWriter.RawDataSPD(digits->GetBranch("ITSDigitsSPD"),foSignals);
1189 if(deleteFOsignalsLater) delete foSignals;
0421c3d1 1190
1191 //SILICON DRIFT DETECTOR
d9ed1779 1192 AliDebug(1,Form("Formatting raw data for SDD - Format code =%d",rawSDD));
979b5a5f 1193 rawWriter.RawDataSDD(digits->GetBranch("ITSDigitsSDD"),ddlsdd);
0421c3d1 1194
1195 //SILICON STRIP DETECTOR
15e6a32c 1196 AliDebug(1,"Formatting raw data for SSD");
0421c3d1 1197 rawWriter.RawDataSSD(digits->GetBranch("ITSDigitsSSD"));
1198
1199 fLoader->UnloadDigits();
2aea926d 1200}
04366a57 1201//______________________________________________________________________
aacedc3e 1202AliLoader* AliITS::MakeLoader(const char* topfoldername){
1203 //builds ITSgetter (AliLoader type)
1204 //if detector wants to use castomized getter, it must overload this method
1205
64f311fe 1206 AliDebug(1,Form("Creating AliITSLoader. Top folder is %s.",
1207 topfoldername));
aacedc3e 1208 fLoader = new AliITSLoader(GetName(),topfoldername);
1209 return fLoader;
2aea926d 1210}
ad7f2bfa 1211//______________________________________________________________________
0b5bf101 1212Bool_t AliITS::Raw2SDigits(AliRawReader* rawReader)
1213{
1214 //
1215 // Converts RAW data to SDigits
1216 //
1217 // Get TreeS
1218 //
afbc83e9 1219 Int_t last = -1;
1220 Int_t size = GetITSgeom()->GetIndexMax();
1221 if(!fModA) {
1222 fModA = new TClonesArray*[size];
1223 for (Int_t mod = 0; mod < size; mod++) fModA[mod] = new TClonesArray("AliITSpListItem", 10000);
1224 }
1225 AliLoader* loader = (AliRunLoader::Instance())->GetLoader("ITSLoader");
1226 if (!loader){
1227 Error("Open","Can not get ITS loader from Run Loader");
1228 return kFALSE;
1229 }
0b5bf101 1230
afbc83e9 1231 TTree* tree = 0;
1232 tree = loader->TreeS();
1233 if (!tree){
1234 loader->MakeTree("S");
0b5bf101 1235 tree = loader->TreeS();
afbc83e9 1236 }
1237 //
1238 // Array for SDigits
1239 //
1240 if(!fpSDigits){
1241 fpSDigits = new TClonesArray("AliITSpListItem",10000);
1242 }
1243 TClonesArray& aSDigits = *fpSDigits;
1244 Int_t bufsize = 32000;
1245 tree->Branch("ITS", &fpSDigits, bufsize);
1246 Int_t npx = 0;
1247 //
1248 // SPD
1249 //
1250 AliITSsegmentationSPD* segSPD = (AliITSsegmentationSPD*) fDetTypeSim->GetSegmentationModel(0);
1251 if(!segSPD){
1252 AliWarning("Set AliITS defaults");
1253 SetDefaults();
1254 segSPD = (AliITSsegmentationSPD*) fDetTypeSim->GetSegmentationModel(0);
1255 }
1256 npx = segSPD->Npx();
1257 Double_t thr, sigma;
0b5bf101 1258
afbc83e9 1259 AliITSRawStreamSPD inputSPD(rawReader);
1260 while(1){
1261 Bool_t next = inputSPD.Next();
1262 if (!next) break;
0b5bf101 1263
afbc83e9 1264 Int_t module = inputSPD.GetModuleID();
1265 Int_t column = inputSPD.GetColumn();
1266 Int_t row = inputSPD.GetRow();
1267 Int_t index = npx * column + row;
0b5bf101 1268
afbc83e9 1269 if (module >= size) continue;
0b5bf101 1270
afbc83e9 1271 last = (fModA[module])->GetEntries();
1272 TClonesArray& dum = *fModA[module];
1273 fDetTypeSim->GetSimuParam()->SPDThresholds(module,thr,sigma);
1274 thr += 1.;
1275 new (dum[last]) AliITSpListItem(-1, -1, module, index, thr);
1276 }
1277 rawReader->Reset();
1278
1279 //
1280 // SDD
1281 //
1282 AliITSsegmentationSDD* segSDD = (AliITSsegmentationSDD*) fDetTypeSim->GetSegmentationModel(1);
1283 npx = segSDD->Npx();
1284 Int_t scalef=AliITSsimulationSDD::ScaleFourier(segSDD);
1285 Int_t firstSDD=AliITSgeomTGeo::GetModuleIndex(3,1,1);
1286 Int_t firstSSD=AliITSgeomTGeo::GetModuleIndex(5,1,1);
1287
1288 AliITSRawStream* inputSDD=AliITSRawStreamSDD::CreateRawStreamSDD(rawReader);
1289 for(Int_t iMod=firstSDD; iMod<firstSSD; iMod++){
1290 AliITSCalibrationSDD* cal = (AliITSCalibrationSDD*)fDetTypeSim->GetCalibrationModel(iMod);
1291 Bool_t isZeroSupp=cal->GetZeroSupp();
1292 if(isZeroSupp){
1293 for(Int_t iSid=0; iSid<2; iSid++) inputSDD->SetZeroSuppLowThreshold(iMod-firstSDD,iSid,cal->GetZSLowThreshold(iSid));
1294 }else{
1295 for(Int_t iSid=0; iSid<2; iSid++) inputSDD->SetZeroSuppLowThreshold(iMod-firstSDD,iSid,0);
dee45d79 1296 }
afbc83e9 1297 }
dee45d79 1298
afbc83e9 1299 AliITSDDLModuleMapSDD* ddlmap=fDetTypeSim->GetDDLModuleMapSDD();
1300 inputSDD->SetDDLModuleMap(ddlmap);
1301 while(inputSDD->Next()){
1302 if(inputSDD->IsCompletedModule()==kFALSE &&
1303 inputSDD->IsCompletedDDL()==kFALSE){
1304
1305 Int_t module = inputSDD->GetModuleID();
1306 Int_t anode = inputSDD->GetCoord1()+segSDD->NpzHalf()*inputSDD->GetChannel();
1307 Int_t time = inputSDD->GetCoord2();
1308 Int_t signal10 = inputSDD->GetSignal();
1309 Int_t index = AliITSpList::GetIndex(anode,time,scalef*npx);
1310
1311 if (module >= size) continue;
1312 last = fModA[module]->GetEntries();
1313 TClonesArray& dum = *fModA[module];
1314 new (dum[last]) AliITSpListItem(-1, -1, module, index, Double_t(signal10));
1315 ((AliITSpListItem*) dum.At(last))->AddSignalAfterElect(module, index, Double_t(signal10));
0b5bf101 1316 }
afbc83e9 1317 }
1318 delete inputSDD;
1319 rawReader->Reset();
a4998655 1320
afbc83e9 1321 //
1322 // SSD
1323 //
1324 AliITSsegmentationSSD* segSSD = (AliITSsegmentationSSD*) fDetTypeSim->GetSegmentationModel(2);
1325 npx = segSSD->Npx();
1326 AliITSRawStreamSSD inputSSD(rawReader);
1327 while(1){
1328 Bool_t next = inputSSD.Next();
1329 if (!next) break;
1330
1331 Int_t module = inputSSD.GetModuleID();
1332 Int_t side = inputSSD.GetSideFlag();
1333 Int_t strip = inputSSD.GetStrip();
1334 Int_t signal = inputSSD.GetSignal();
1335 Int_t index = npx * side + strip;
1336
1337 if (module >= size) continue;
0b5bf101 1338
afbc83e9 1339 last = fModA[module]->GetEntries();
1340 TClonesArray& dum = *fModA[module];
1341 new (dum[last]) AliITSpListItem(-1, -1, module, index, Double_t(signal));
1342 }
1343 rawReader->Reset();
1344 AliITSpListItem* sdig = 0;
0b5bf101 1345
afbc83e9 1346 Int_t firstssd = GetITSgeom()->GetStartDet(kSSD);
1347 Double_t adcToEv = 1.;
1348 for (Int_t mod = 0; mod < size; mod++)
1349 {
8b3448d3 1350 if(mod>=firstssd) {
1351 AliITSCalibrationSSD* calssd = (AliITSCalibrationSSD*)fDetTypeSim->GetCalibrationModel(mod);
1352 adcToEv = 1./calssd->GetSSDDEvToADC(1.);
1353 }
afbc83e9 1354 Int_t nsdig = fModA[mod]->GetEntries();
8b3448d3 1355 for (Int_t ie = 0; ie < nsdig; ie++) {
afbc83e9 1356 sdig = (AliITSpListItem*) (fModA[mod]->At(ie));
8b3448d3 1357 Int_t digsig = sdig->GetSignal();
1358 if(mod>=firstssd) digsig*=adcToEv; // for SSD: convert back charge from ADC to electron
1359 new (aSDigits[ie]) AliITSpListItem(-1, -1, mod, sdig->GetIndex(), digsig);
afbc83e9 1360 Float_t sig = sdig->GetSignalAfterElect();
1361 if(mod>=firstssd) sig*=adcToEv;
1362 if (sig > 0.) {
1363 sdig = (AliITSpListItem*)aSDigits[ie];
1364 sdig->AddSignalAfterElect(mod, sdig->GetIndex(), Double_t(sig));
0b5bf101 1365 }
afbc83e9 1366 }
0b5bf101 1367
afbc83e9 1368 tree->Fill();
1369 aSDigits.Clear();
1370 fModA[mod]->Clear();
0b5bf101 1371 }
afbc83e9 1372 loader->WriteSDigits("OVERWRITE");
1373 return kTRUE;
0b5bf101 1374}
1375
ef7ff1f9 1376//______________________________________________________________________
1377void AliITS::UpdateInternalGeometry(){
ed9289c8 1378 //reads new geometry from TGeo
012f0f4c 1379// AliDebug(1,"Delete ITSgeom and create a new one reading TGeo");
1380
108bd0fe 1381 AliITSVersion_t version = (AliITSVersion_t)IsVersion();
1382 Int_t minor = 0;
012f0f4c 1383 if(version==kvPPRasymmFMD) minor=2; // default minor version for this geom.
1384 AliITSInitGeometry initgeom;
1385 AliITSgeom* geom = initgeom.CreateAliITSgeom(version,minor);
ef7ff1f9 1386 SetITSgeom(geom);
ef7ff1f9 1387}
ad7f2bfa 1388//______________________________________________________________________
1389AliTriggerDetector* AliITS::CreateTriggerDetector() const {
1390 // create an AliITSTrigger object (and set trigger conditions as input)
1391 return new AliITSTrigger(fDetTypeSim->GetTriggerConditions());
1392}