]> git.uio.no Git - u/mrichter/AliRoot.git/blob - HLT/PHOS/AliHLTPHOSMIPCounterComponent.cxx
AliCDBId's in the list of retrieved OCDB parameters in the ESD's user info
[u/mrichter/AliRoot.git] / HLT / PHOS / AliHLTPHOSMIPCounterComponent.cxx
1  /**************************************************************************
2  * This file is property of and copyright by the ALICE HLT Project        *
3  * All rights reserved.                                                   *
4  *                                                                        *
5  * Primary Authors: Oystein Djuvsland                                     *
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 #include "AliHLTPHOSMIPCounterComponent.h"
17 #include "AliHLTPHOSProcessor.h"
18 #include "AliHLTPHOSMIPCounter.h"
19 #include "TH1I.h"
20 #include "TH1F.h"
21 #include "TH2I.h"
22 #include "TFile.h"
23 #include "AliHLTPHOSDigitContainerDataStruct.h"
24
25
26 const AliHLTComponentDataType AliHLTPHOSMIPCounterComponent::fgkInputDataTypes[]={kAliHLTVoidDataType,{0,"",""}};
27
28 AliHLTPHOSMIPCounterComponent gAliHLTPHOSMIPCounterComponent;
29
30 AliHLTPHOSMIPCounterComponent::AliHLTPHOSMIPCounterComponent()
31     : AliHLTPHOSProcessor(),
32     fEvtCnt ( 0 ),
33     fInterval ( 0 ),
34     fMIPCount ( 0 ),
35     fTRUThreshold ( 0 ),
36     fMIPCountInterval ( 0 ),
37     fPath ( 0 ),
38     fMIPCounterPtr ( 0 ),
39     fHistPtr ( 0 ),
40     fIntervalHistPtr ( 0 ),
41     fRateHistPtr ( 0 ),
42     fChannelHistPtr ( 0 ),
43     fRatioHistPtr ( 0 )
44 {
45 }
46
47
48 AliHLTPHOSMIPCounterComponent::~AliHLTPHOSMIPCounterComponent()
49 {
50 }
51
52 int 
53 AliHLTPHOSMIPCounterComponent::Deinit()
54 {
55   printf("AliHLTPHOSMIPCounterComponent::Deinit()\n");
56   char filename[50];
57   sprintf(filename, "%s/MIPCount_TRUThreshold%s.root", fPath, fTRUThreshold);
58   TFile *outfile = new TFile(filename, "recreate");
59   fHistPtr->Write();
60   fIntervalHistPtr->Write();
61   fRateHistPtr->Write();
62   fChannelHistPtr->Write();
63   fRatioHistPtr->Write();
64   outfile->Close();
65   
66   printf("Total number of MIPs in %d events: %d\nGives a rate of: %f\n", fEvtCnt, fMIPCounterPtr->GetMIPCountTotal(),
67          ((float)(fMIPCounterPtr->GetMIPCountTotal()))/((float)fEvtCnt));
68       
69   return 0;
70 }
71
72 const char*
73 AliHLTPHOSMIPCounterComponent::GetComponentID()
74 {
75   return "PhosMIPCounter";
76 }
77
78 void
79     AliHLTPHOSMIPCounterComponent::GetInputDataTypes(vector<AliHLTComponentDataType>& list)
80
81  //Get datatypes for input
82   const AliHLTComponentDataType* pType=fgkInputDataTypes;
83   while (pType->fID!=0) {
84     list.push_back(*pType); 
85     pType++;
86   }
87 }
88
89 AliHLTComponentDataType 
90 AliHLTPHOSMIPCounterComponent::GetOutputDataType()
91 {
92   return AliHLTPHOSDefinitions::fgkAliHLTMIPDataType;
93 }
94
95
96 void 
97     AliHLTPHOSMIPCounterComponent::GetOutputDataSize(unsigned long& constBase, double& inputMultiplier)
98 {
99   constBase = 30;
100   inputMultiplier = 1;
101 }
102
103 int 
104 AliHLTPHOSMIPCounterComponent::DoEvent(const AliHLTComponentEventData& evtData, const AliHLTComponentBlockData* blocks,
105                                         AliHLTComponentTriggerData& /*trigData*/, AliHLTUInt8_t* /*outputPtr*/, AliHLTUInt32_t& /*size*/, //TODO: I think size should be set to zero when returning from this method if not data was written to the output buffer.
106                                         vector<AliHLTComponentBlockData>& /*outputBlocks*/)
107 {
108    //Do event
109   int digitCount = 0;
110   
111   const AliHLTComponentBlockData* iter = 0; 
112   unsigned long ndx; 
113
114   for( ndx = 0; ndx < evtData.fBlockCnt; ndx++ )
115   {
116     iter = blocks+ndx;
117       
118     if(iter->fDataType != AliHLTPHOSDefinitions::fgkAliHLTDigitDataType)
119     {
120         //  cout << "Warning: data type is not fgkCellEnergyDataType " << endl;
121       continue;
122     }
123     digitCount += (reinterpret_cast<AliHLTPHOSDigitContainerDataStruct*>(iter->fPtr))->fNDigits;
124     fMIPCount += fMIPCounterPtr->CountMIPs(reinterpret_cast<AliHLTPHOSDigitContainerDataStruct*>(iter->fPtr));
125   }
126   fRatioHistPtr->Fill((float)(((float)fMIPCount)/((float)digitCount)));
127   fEvtCnt++;
128   fMIPCountInterval += fMIPCount;
129   fMIPCount = 0;
130   
131   if(fEvtCnt % fInterval == 0)
132   {
133     printf("Event #: %d -- Number of MIPs the last %d events: %d -- Which gives a rate of: %f\n",
134            fEvtCnt, fInterval, Int_t(fMIPCountInterval), ((Float_t)fMIPCountInterval/(Float_t)fInterval));   //TODO: check that the proper things are being written to screen.
135     fIntervalHistPtr->Fill(fMIPCountInterval);
136     fRateHistPtr->Fill((Float_t)fMIPCountInterval/(Float_t)fInterval);
137     fMIPCountInterval = 0;
138   }
139  
140   return 0;
141 }
142
143
144 int
145 AliHLTPHOSMIPCounterComponent::DoInit(int argc, const char** argv )
146 {
147   //Do initialization
148   cout << "Initializing AliHLTPHOSMIPCounterComponent...\n";
149   cout << endl;
150   Char_t intervalHistName[50];
151   Char_t rateHistName[50];
152   fPath = new Char_t[50];
153   fTRUThreshold = new Char_t[50];
154   fMIPCounterPtr = new AliHLTPHOSMIPCounter();
155   for(int i = 0; i < argc; i++)
156   {
157       if(!strcmp("-interval", argv[i]))
158       {
159         fInterval = atoi(argv[i+1]);
160       }
161       if(!strcmp("-path", argv[i]))
162       {
163         strcpy(fPath, argv[i+1]);
164       }
165       if(!strcmp("-upperbound", argv[i]))
166       {
167         fMIPCounterPtr->SetUpperBound(atoi(argv[i+1]));
168       }
169       if(!strcmp("-lowerbound", argv[i]))
170       {
171         fMIPCounterPtr->SetLowerBound(atoi(argv[i+1]));
172       }
173       if(!strcmp("-zerothreshold", argv[i]))
174       {
175         fMIPCounterPtr->SetZeroThreshold(atoi(argv[i+1]));
176       }
177       if(!strcmp("-truthreshold", argv[i]))
178       {
179         strcpy(fTRUThreshold, argv[i+1]);
180       }
181       if(!strcmp("-lowerstarttime", argv[i]))
182       {
183         fMIPCounterPtr->SetLowerStartTime(atoi(argv[i+1]));
184       }
185       if(!strcmp("-upperstarttime", argv[i]))
186       {
187         fMIPCounterPtr->SetUpperStartTime(atoi(argv[i+1]));
188       }
189   }
190   
191   sprintf(intervalHistName, "Number of MIPs in %d Events", fInterval);
192   sprintf(rateHistName, "MIP Rate for %d Events", fInterval);
193   
194   fHistPtr = new TH1I("MIPHist", "Number of MIPs in event", 20, 0, 100);
195   fIntervalHistPtr = new TH1I("intervalMIPHist", intervalHistName, 100, 0, 500);
196   fRateHistPtr = new TH1F("rateHist", rateHistName, 100, 0, 100);
197   fChannelHistPtr = new TH2I("channelHist", "MIP Hits in Channels", 64, 0, 63, 56, 0, 55);
198   fRatioHistPtr = new TH1F("ratioHist", "Ratio of MIP digits in Event", 100, 0, 0.2);
199      
200   fMIPCounterPtr->SetChannelHistogram(fChannelHistPtr);
201   
202
203   return 0;  
204 }
205
206 AliHLTComponent*
207     AliHLTPHOSMIPCounterComponent::Spawn()
208 {
209   return new AliHLTPHOSMIPCounterComponent();
210 }