]> git.uio.no Git - u/mrichter/AliRoot.git/blame - PHOS/macros/RawSimulation/AliPHOSMakeRaw.C
Separate library for pi0 calibration.
[u/mrichter/AliRoot.git] / PHOS / macros / RawSimulation / AliPHOSMakeRaw.C
CommitLineData
31fb4e32 1/* $Id$ */
09808120 2MakeRaw()
3{
4 // Create DDL files manually by firing each crystal.
5 // The DDL files are stored into directory raw0
6 // Yuri Kharlov. 15 February 2006
7
8 const Int_t kAdcThreshold = 1; // Lower ADC threshold to write to raw data
9
10 Int_t prevDDL = -1;
11
12 // Create a shaper pulse object
13 AliPHOSPulseGenerator pulse;
14
15 Int_t *adcValuesLow = new Int_t[pulse.GetRawFormatTimeBins()];
16 Int_t *adcValuesHigh= new Int_t[pulse.GetRawFormatTimeBins()];
17
18 const Int_t maxDDL = 20;
19 AliAltroBuffer *buffer[maxDDL];
20 AliAltroMapping *mapping[maxDDL];
21
22 // loop over digits
23 Float_t energy = 2.;
24 Float_t time = 15.6e-09;
25 Int_t module = 1;
26 for (Int_t iX=0; iX<64; iX++) {
27 for (Int_t iZ=0; iZ<56; iZ++) {
28
29 Int_t iRCU = -111;
30 if ( 0<=iX&&iX<32 && 0<=iZ&&iZ<28) iRCU=0;
31 else if( 0<=iX&&iX<32 && 28<=iZ&&iZ<56) iRCU=1;
32 else if(32<=iX&&iX<64 && 0<=iZ&&iZ<28) iRCU=2;
33 else if(32<=iX&&iX<64 && 28<=iZ&&iZ<56) iRCU=3;
34 Int_t iDDL = 4 * (module - 1) + iRCU;
35
36 // new DDL
37 if (iDDL != prevDDL) {
38 if (buffer[iDDL] == 0) {
39 // open new file and write dummy header
40 TString fileName = AliDAQ::DdlFileName("PHOS",iDDL);
41
42 TString path = gSystem->Getenv("ALICE_ROOT");
43 path += "/PHOS/mapping/RCU";
44 path += iRCU;
45 path += ".data";
46
47 // printf("DDL %d, mapping %s\n",iDDL,path.Data());
48 mapping[iDDL] = new AliCaloAltroMapping(path.Data());
49 buffer[iDDL] = new AliAltroBuffer(fileName.Data(),mapping[iDDL]);
50 buffer[iDDL]->WriteDataHeader(kTRUE, kFALSE); //Dummy;
51 }
52 prevDDL = iDDL;
53 }
54
55 // if a signal is out of time range, write only trailer
56 if (time > pulse.GetRawFormatTimeMax()*0.5 ) {
57 AliInfo("Signal is out of time range.\n");
58 buffer[iDDL]->FillBuffer(0);
59 buffer[iDDL]->FillBuffer(pulse.GetRawFormatTimeBins() ); // time bin
60 buffer[iDDL]->FillBuffer(3); // bunch length
61 buffer[iDDL]->WriteTrailer(3, iZ, iX, 0); // trailer
62 }
63 pulse.SetAmplitude(energy);
64 pulse.SetTZero(time);
65 pulse.MakeSamples();
66 pulse.GetSamples(adcValuesHigh, adcValuesLow) ;
67 // printf("digit E=%.4f GeV, t=%g s, (mod,iZ,iX)=(%d,%d,%d)\n",
68 // energy,time,module-1,iZ,iX);
69 buffer[iDDL]->WriteChannel(iZ, iX, 0,
70 pulse.GetRawFormatTimeBins(),
71 adcValuesLow , kAdcThreshold);
72 buffer[iDDL]->WriteChannel(iZ, iX, 1,
73 pulse.GetRawFormatTimeBins(),
74 adcValuesHigh, kAdcThreshold);
75 }
76 }
77 // write real header and close last file
78 for (Int_t iDDL=0; iDDL<maxDDL; iDDL++) {
79 if (buffer[iDDL]) {
80 buffer[iDDL]->Flush();
81 buffer[iDDL]->WriteDataHeader(kFALSE, kFALSE);
82 delete buffer[iDDL];
83 if (mapping[iDDL]) delete mapping[iDDL];
84 }
85 }
86
87 // move DDL files to directory raw0
88 gSystem->Exec("mkdir -p raw0; mv *.ddl raw0");
89}
90//-----------------------------------------------------------------------------
91PlotRawDDL()
92{
93 // Macro to read raw data from the DDL files
94 // and fill histogram with fired channels.
95 // Yuri Kharlov. 19 October 2006
96
97 AliRawReaderFile* rf = new AliRawReaderFile(".");
98 AliCaloRawStream in(rf,"PHOS");
99 in.SetOldRCUFormat(kFALSE); // Set to kTRUE for beam test 2006 only
100 Int_t iBin = 0;
101 Int_t iEvent=0;
102
103 TFile *file = new TFile("PlotRawDDL.root","recreate");
104 TH2F *hXY = new TH2F("hXY","X,Y of raw data",64,0.,64.,56,0.,56.);
105 TH2F *hXYmodule[5];
106 for (Int_t iMod=0; iMod<5; iMod++) {
107 TString name="hXY";
108 TString title="X,Y of raw data in module ";
109 hXYmodule[iMod] = new TH2F(name+iMod,title+iMod,64,0.,64.,56,0.,56.);
110 }
111
112 // Loop over events
113 while (rf->NextEvent()) {
114 Int_t runNum = rf->GetRunNumber();
115 cout << "Run "<<runNum<<", event "<<iEvent<<" of type "
116 << rf->GetType() << endl;
117
118 // Loop over channels within this event
119
120 while ( in.Next() ) {
121 if (in.IsNewHWAddress()) {
122 hXY->Fill((Double_t)in.GetRow(),(Double_t)in.GetColumn());
123 hXYmodule[in.GetModule()]->Fill((Double_t)in.GetRow(),(Double_t)in.GetColumn());
124 }
125 }
126 iEvent++;
127 }
128 file->Write();
129 file->Close();
130}