]> git.uio.no Git - u/mrichter/AliRoot.git/blob - TOF/AliTOFDDLRawData.cxx
New version of TOF tracker which uses TOF clusters as an input (A. De Caro)
[u/mrichter/AliRoot.git] / TOF / AliTOFDDLRawData.cxx
1 /**************************************************************************
2  * Copyright(c) 1998-2003, 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
16 /*
17 Revision 0.02  2005/7/25 A.De Caro
18         Update number of bits allocated for time-of-flight
19                and 'charge' measurements
20
21 Revision 0.01  2004/6/11 A.De Caro, S.B.Sellitto, R.Silvestri
22         First implementation: global methods RawDataTOF
23                                              GetDigits
24 */
25
26 //////////////////////////////////////////////////////////////////
27 //
28 // This class contains the methods to create the Raw Data files
29 // for the TOF detector starting from the Digits.
30 // In this preliminary implementation, we defined the structure
31 // of the ALICE-TOF raw data starting from the current format
32 // for the TOF digits and the TOF raw data.
33 //
34 //////////////////////////////////////////////////////////////////
35
36 #include <stdlib.h>
37 #include <Riostream.h>
38 #include <TClonesArray.h>
39 #include <TTree.h>
40 #include <TMath.h>
41 #include "AliLog.h"
42
43 #include "AliRawDataHeader.h"
44 #include "AliBitPacking.h"
45
46 #include "AliTOFGeometry.h"
47 #include "AliTOFdigit.h"
48 #include "AliTOFRawStream.h"
49 #include "AliTOFDDLRawData.h"
50
51 ClassImp(AliTOFDDLRawData)
52
53 //----------------------------------------------------------------------------------------
54 AliTOFDDLRawData::AliTOFDDLRawData()
55 {
56   //Default constructor
57   fIndex=-1;
58   fVerbose=0;
59 }
60
61 //----------------------------------------------------------------------------------------
62
63 AliTOFDDLRawData::AliTOFDDLRawData(const AliTOFDDLRawData &source) : 
64     TObject(source){
65   //Copy Constructor
66   this->fIndex=source.fIndex;
67   this->fVerbose=source.fVerbose;
68   return;
69 }
70
71 //---------------------------------------------------------------------------------------
72
73 AliTOFDDLRawData& AliTOFDDLRawData::operator=(const AliTOFDDLRawData &source){
74   //Assigment operator
75   this->fIndex=source.fIndex;
76   this->fVerbose=source.fVerbose;
77   return *this;
78 }
79
80 //---------------------------------------------------------------------------------------
81
82 void AliTOFDDLRawData::GetDigits(TClonesArray *TOFdigits,Int_t nDDL,UInt_t *buf)
83 {
84
85   //This method packs the TOF digits in a proper 32 bits structure
86
87   Int_t iDDL    = nDDL%AliTOFGeometry::NDDL();//(Int_t)((nDDL/4.-(Int_t)(nDDL/4.))*4);
88   Int_t iSector = (Int_t)((Float_t)nDDL/AliTOFGeometry::NDDL());
89   Int_t iTRM = 0;
90   Int_t iTDC = 0;
91   Int_t iCH  =-1;
92   Int_t sector; 
93   Int_t plate;
94   Int_t strip;
95   Int_t padx;
96   Int_t padz;
97   Int_t totCharge;
98   Int_t timeOfFlight;
99   Int_t error=0;
100   Int_t eureka;
101   UInt_t word;
102   UInt_t baseWord;
103   Int_t ndigits = TOFdigits->GetEntries();
104   AliTOFdigit *digs;
105   ofstream ftxt;
106   if(!ndigits) 
107     {
108       AliError("No found TOF digits");
109       return;
110     }
111
112   if (fVerbose==2) ftxt.open("TOFdigits.txt",ios::app);
113
114   for (Int_t digit=0;digit<ndigits;digit++) {
115     digs = (AliTOFdigit*)TOFdigits->UncheckedAt(digit);
116     sector = digs->GetSector(); // Sector Number (0-17)
117     plate  = digs->GetPlate();  // Plate Number (0-4)
118     strip  = digs->GetStrip();  // Strip Number (0-14/18/19)
119     padx   = digs->GetPadx();   // Pad Number in x direction (0-47)
120     padz   = digs->GetPadz();   // Pad Number in z direction (0-1)
121     eureka = digs->GetTotPad(); // Global Pad Number inside a Sector
122     totCharge = (Int_t)digs->GetAdc();
123     timeOfFlight = (Int_t)digs->GetTdc();
124
125     if (sector!=iSector || (Int_t)((Float_t)eureka/AliTOFGeometry::NPadXTRM()/AliTOFGeometry::NTRM())!=iDDL) continue;
126     
127     if (fVerbose==2) ftxt << " Sector: " << sector << " Plate: " << plate << " Strip: " << strip << " PadZ: " << padz << " PadX: " << padx << " totPadNumber " << eureka << endl;
128     
129     iTRM = (Int_t)((Float_t)eureka/AliTOFGeometry::NPadXTRM()) - iDDL*AliTOFGeometry::NTRM();
130
131     
132     iTDC = (Int_t)((Float_t)eureka/AliTOFGeometry::NCh()) - (iDDL*AliTOFGeometry::NTRM() + iTRM) * AliTOFGeometry::NTdc();
133     /*
134     iTDC = (Int_t)(AliTOFGeometry::NTdc()* 
135                    (
136                     (Float_t)eureka/AliTOFGeometry::NPadXTRM() -
137                     (Int_t)((Float_t)eureka/AliTOFGeometry::NPadXTRM())
138                     )
139                    );
140     */
141
142     iCH  = eureka - ((iDDL*AliTOFGeometry::NTRM() + iTRM) * AliTOFGeometry::NTdc() + iTDC) * AliTOFGeometry::NCh();
143     /*
144     iCH  = (Int_t)(AliTOFGeometry::NCh() * 
145                    (
146                     (Float_t)eureka/AliTOFGeometry::NPadXTRM()*AliTOFGeometry::NTdc() - (Int_t)((Float_t)eureka/AliTOFGeometry::NPadXTRM()*AliTOFGeometry::NTdc()) -
147                     (Int_t)((Float_t)eureka/AliTOFGeometry::NPadXTRM()*AliTOFGeometry::NTdc() - (Int_t)((Float_t)eureka/AliTOFGeometry::NPadXTRM()*AliTOFGeometry::NTdc()))
148                     )
149                    );
150     */
151
152     if (fVerbose==2) ftxt << "DDL: "<<nDDL<<" TRM: "<<iTRM<<" TDC: "<<iTDC<<" Channel: "<<iCH<<" totCharge: "<<totCharge<<" tof: "<<timeOfFlight<<endl;
153
154     //AliInfo(Form("%2i %2i %2i %2i   %2i %2i %2i %2i %2i %7i %8i",nDDL,iTRM,iTDC,iCH,sector,plate,strip,padz,padx,totCharge,timeOfFlight));
155     AliDebug(2,Form("%2i %2i %2i %2i   %2i %2i %2i %2i %2i %7i %8i",nDDL,iTRM,iTDC,iCH,sector,plate,strip,padz,padx,totCharge,timeOfFlight));
156     
157     baseWord=0;
158     
159     word=iTRM;
160     AliBitPacking::PackWord(word,baseWord, 0, 3); // TRM ID
161     word=iTDC;
162     AliBitPacking::PackWord(word,baseWord, 4, 8); // TDC ID
163     word=iCH;
164     AliBitPacking::PackWord(word,baseWord, 9,11); // CH ID
165
166     // temporary control
167     if (totCharge<0) word=TMath::Abs(totCharge);
168     else word=totCharge;
169     AliBitPacking::PackWord(word,baseWord,12,31); // Charge (TOT) // v0.01
170     //AliBitPacking::PackWord(word,baseWord,12,19); // Charge (TOT) // v0.02
171     //AliBitPacking::PackWord(0,baseWord,20,31); // v0.02
172
173     fIndex++;
174     buf[fIndex]=baseWord;
175     
176     baseWord=0;
177     
178     word=error;
179     AliBitPacking::PackWord(word,baseWord,0, 7); // Error flag
180     word=timeOfFlight;
181     AliBitPacking::PackWord(word,baseWord,8,31); // time-of-flight // v0.01
182     //AliBitPacking::PackWord(word,baseWord,8,19); // time-of-flight // v0.02
183     //AliBitPacking::PackWord(0,baseWord,20,30); // v0.02
184     //AliBitPacking::PackWord(1,baseWord,31,31); // v0.02
185     
186     fIndex++;
187     buf[fIndex]=baseWord;
188     word=0;
189     baseWord=0;
190     
191   }//end for
192   
193   if (fVerbose==2) ftxt.close();
194
195   return;
196
197 }//end GetDigits
198
199 //---------------------------------------------------------------------------------------
200
201 Int_t AliTOFDDLRawData::RawDataTOF(TBranch* branch){
202   //
203   // This method creates the Raw data files for TOF detector
204   //
205
206   const Int_t kSize = 5000; //max number of digits per DDL file times 2
207
208   UInt_t buf[kSize];
209   //UInt_t baseWord; // v0.01
210   //UInt_t word; // v0.01
211
212   fIndex=-1;
213
214   TClonesArray*& digits = * (TClonesArray**) branch->GetAddress();
215   char fileName[15];
216   ofstream outfile;         // logical name of the output file 
217   AliRawDataHeader header;
218   UInt_t sizeRawData = 0;
219
220   //loop over TOF DDL files
221   for(Int_t i = 0; i<AliTOFGeometry::NDDL()*AliTOFGeometry::NSectors(); i++){
222
223     sprintf(fileName,"TOF_%d.ddl",i+AliTOFRawStream::kDDLOffset); //The name of the output file
224 #ifndef __DECCXX
225     outfile.open(fileName,ios::binary);
226 #else
227     outfile.open(fileName);
228 #endif
229
230     //write Dummy DATA HEADER
231     UInt_t dataHeaderPosition=outfile.tellp();
232     outfile.write((char*)(&header),sizeof(header));
233
234     /*
235     // v0.01
236     baseWord=0;
237     word=i;
238     //AliBitPacking::PackWord(word,baseWord,0, 31); // Number of DDL file
239     AliBitPacking::PackWord(word,baseWord,0, 6); // Number of DDL file
240     AliBitPacking::PackWord(0,baseWord,7,31);
241
242     fIndex++;
243     buf[fIndex]=baseWord;
244     */
245
246     branch->GetEvent();
247
248     //For each DDL file, buf contains the array of data words in Binary format
249     //fIndex gives the number of 32 bits words in the buffer for each DDL file
250     GetDigits(digits,i,buf);
251     outfile.write((char *)buf,((fIndex+1)*sizeof(UInt_t)));
252
253     for(Int_t ii=0;ii<(fIndex+1);ii++) buf[ii]=0;
254     fIndex=-1;
255     
256     //Write REAL DATA HEADER
257     UInt_t currentFilePosition=outfile.tellp();
258     sizeRawData = currentFilePosition - dataHeaderPosition - sizeof(header);
259     header.fSize=currentFilePosition-dataHeaderPosition;
260     header.SetAttribute(0);  // valid data
261     outfile.seekp(dataHeaderPosition);
262     outfile.write((char*)(&header),sizeof(header));
263     outfile.seekp(currentFilePosition);
264
265     outfile.close();
266
267   }//end for
268   
269   return 0;  
270 }
271
272 //---------------------------------------------------------------------------