]> git.uio.no Git - u/mrichter/AliRoot.git/blame - MUON/MUONTRKOCCda.cxx
add calculation and histograms for MC cross section
[u/mrichter/AliRoot.git] / MUON / MUONTRKOCCda.cxx
CommitLineData
2825ba79 1/*
2 MCH DA for online occupancy
3
4 Contact: Laurent Aphecetche <laurent.aphecetche@subatech.in2p3.fr>, Jean-Luc Charvet <jean-luc.charvet@cea.fr>, Alberto Baldisseri <alberto.baldisseri@cea.fr>
5 Link:
6 Run Type: PHYSICS STANDALONE
7 DA Type: MON
8 Number of events needed: all (or at least as much as possible...)
eedea469 9 Input Files: 10000119041028.20.raw 10000130367042.10.raw 10000120691024.50.raw
2825ba79 10 Output Files: mch.occupancy, to be exported to the DAQ FXS
11 Trigger types used: PHYSICS_EVENT
12*/
13
14/**************************************************************************
15 * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
16 * *
17 * Author: The ALICE Off-line Project. *
18 * Contributors are mentioned in the code where appropriate. *
19 * *
20 * Permission to use, copy, modify and distribute this software and its *
21 * documentation strictly for non-commercial purposes is hereby granted *
22 * without fee, provided that the above copyright notice appears in all *
23 * copies and that both the copyright notice and this permission notice *
24 * appear in the supporting documentation. The authors make no claims *
25 * about the suitability of this software for any purpose. It is *
26 * provided "as is" without express or implied warranty. *
27 **************************************************************************/
28
29///
30/// MUON TRACKER DA to compute the hit count at manu level.
31///
32/// In the end, this DA produces an ASCII file containing
33/// the hit count of all the manus (that were seen in the data flow)
34/// of the MUON Tracker (and the number of seen events, so we can
35/// later on compute the occupancy)
36///
37/// $Id$
38
33d94e07 39#include "AliDAQ.h"
2825ba79 40#include "AliMUON2DMap.h"
41#include "AliMUONCalibParamNI.h"
42#include "AliMUONRawStreamTrackerHP.h"
43#include "AliMpConstants.h"
44#include "AliRawEventHeaderBase.h"
134d9649 45#include "AliRawReaderDate.h"
2825ba79 46#include "Riostream.h"
47#include "TPluginManager.h"
48#include "TROOT.h"
49#include "TString.h"
50#include "TTimeStamp.h"
51#include "TStopwatch.h"
52#include "daqDA.h"
53#include "event.h"
134d9649 54#include "monitor.h"
65cd97ed 55#include "signal.h"
2825ba79 56
57#ifdef ALI_AMORE
58#include <AmoreDA.h>
5431405e 59#include "TObjString.h"
60#include "TSystem.h"
61#include <sstream>
2825ba79 62#endif
63
64const char* OUTPUT_FILE = "mch.occupancy";
eedea469 65const char* DAVERSION = "MUONTRKOCCda v1.61 ($Id$)";
2825ba79 66
67//______________________________________________________________________________
68void Add(AliMUONVStore& destStore, const AliMUONVStore& srcStore)
69{
70 /// Add all elements from srcStore to destStore
71 /// Each element of srcStore is supposed to be an AliMUONCalibParamNI,
72 /// with ID0=busPatchId and ID1=manuId
73
74 TIter next(srcStore.CreateIterator());
75 AliMUONVCalibParam* source;
76
77 while ( ( source = static_cast<AliMUONVCalibParam*>(next()) ) )
78 {
79 AliMUONCalibParamNI* dest = static_cast<AliMUONCalibParamNI*>(destStore.FindObject(source->ID0(),source->ID1()));
80 if (!dest)
81 {
82 dest = static_cast<AliMUONCalibParamNI*>(source->Clone());
83 destStore.Add(dest);
84 }
85 else
86 {
87 for ( Int_t i = 0; i < source->Size(); ++i )
88 {
89 for ( Int_t j = 0; j < source->Dimension(); ++j )
90 {
be9b25ed 91 dest->SetValueAsIntFast(i,j,dest->ValueAsIntFast(i,j)+source->ValueAsIntFast(i,j));
2825ba79 92 }
93 }
94 }
95 }
96}
97
98//______________________________________________________________________________
99void GenerateOutputFile(const AliMUONVStore& store, ostream& out,
33d94e07 100 Int_t runNumber, Int_t nevents, Int_t numberOfEventsWithMCH)
2825ba79 101{
102 /// Write the channel hit count (grouped by manu) in the output file.
103
104 TIter next(store.CreateIterator());
105 AliMUONVCalibParam* manu;
106
107 out << "//===========================================================================" << endl;
108 out << "// Hit counter file calculated by " << __FILE__ << endl;
109 out << "//===========================================================================" << endl;
110 out << "//" << endl;
111 out << "// * Run Number : " << runNumber << endl;
112 out << "// * File Creation Date : " << TTimeStamp().AsString("l") << endl;
113 out << "//---------------------------------------------------------------------------" << endl;
114 out << "// BP MANU SUM_N NEVENTS" << endl;
115 out << "//---------------------------------------------------------------------------" << endl;
33d94e07 116
117 Int_t nlines(0);
2825ba79 118
119 while ( ( manu = static_cast<AliMUONVCalibParam*>(next()) ) )
120 {
121 Int_t sum(0);
2825ba79 122
123 for ( Int_t i = 0; i < manu->Size(); ++i )
124 {
125 sum += manu->ValueAsInt(i);
2825ba79 126 }
127
128 out << Form("%5d %5d %10d %10d",manu->ID0(),manu->ID1(),sum,nevents) << endl;
33d94e07 129 ++nlines;
130 }
131
132 if (!nlines)
133 {
134 // ok : empty output. Is it because the run was empty ?
135 if ( !numberOfEventsWithMCH )
136 {
137 // yes. Let give a hint in the file so the Shuttle preprocessor will know about this...
138 out << Form("%5d %5d %10d %10d",-1,-1,0,0) << endl;
139 }
140 // else the preprocessor will fail, and that's good because there's something wrong somewhere...
2825ba79 141 }
142}
143
144//______________________________________________________________________________
145int main(int argc, char **argv)
146{
147 /// Main method.
148 ///
149 /// We loop over all physics events.
150 /// For each event we store the channels that were hit for that event.
151 /// If the event is good, we then increment the list of channels hit for
152 /// the whole run.
153 /// We delete the store for a single event and move to next event.
154 ///
155 /// In the end we output an ASCII file with the necessary information
156 /// to compute the occupancy later on, i.e. the number of times channels
157 /// were seen per manu, and the number of events.
158 ///
159
a9d45f70 160 signal(SIGSEGV,SIG_DFL); // to be able to get core dumps...
161
2825ba79 162 TStopwatch timers;
163 timers.Start(kTRUE);
164
165 ios::sync_with_stdio();
166
167 cout << "Running " << DAVERSION << endl;
168
169 if ( argc < 2 )
170 {
171 cout << "Wrong number of arguments" << endl;
172 cout << "Usage : " << argv[0] << " datasource1 [datasource2] ..." << endl;
173 return -1;
174 }
175
176 // needed for streamer application
177 gROOT->GetPluginManager()->AddHandler("TVirtualStreamerInfo",
178 "*",
179 "TStreamerInfo",
180 "RIO",
181 "TStreamerInfo()");
182
183 Int_t numberOfEvents(0);
184 Int_t numberOfPhysicsEvent(0);
185 Int_t numberOfBadEvents(0);
186 Int_t numberOfUsedEvents(0);
187
33d94e07 188 Int_t numberOfEventsWithMCH(0);
189
2825ba79 190 AliMUON2DMap oneEventData(kTRUE);
191 AliMUON2DMap accumulatedData(kTRUE);
192
193 UInt_t runNumber(0);
194
195 for ( Int_t i = 1; i < argc; ++i )
196 {
134d9649 197 int status;
198 AliRawReaderDate* rawReader(0x0);
199
200// define data source :
033da0c5 201 status=monitorSetDataSource(argv[i]);
134d9649 202 if (status!=0)
203 {
204 printf("MCH Occupancy DA ERROR: monitorSetDataSource() failed: %s\n", monitorDecodeError(status));
205 return -1;
206 }
207
208// Declare monitoring program
209 status=monitorDeclareMp("MUON_TRK_OCC");
210 if (status!=0)
211 {
212 printf("MCH Occupancy DA ERROR: monitorDeclareMp() failed: %s\n", monitorDecodeError(status));
213 return -1;
214 }
215// Define wait event timeout - 1s max
216 monitorSetNowait();
217 monitorSetNoWaitNetworkTimeout(1000);
218
219 for(;;)
2825ba79 220 {
63108d64 221 struct eventHeaderStruct *event(0x0);
134d9649 222 eventTypeType eventT;
223
224 status=monitorGetEventDynamic((void **)&event);
225 if (status!=0)
226 {
be9b25ed 227 printf("MCH Occupancy DA ERROR: %s\n", monitorDecodeError(status));
228 delete event;
229 break;
134d9649 230 }
231
2825ba79 232 /* check shutdown condition */
be9b25ed 233 if (daqDA_checkShutdown())
2825ba79 234 {
be9b25ed 235 delete event;
236 break;
2825ba79 237 }
be9b25ed 238
134d9649 239 /* retry if got no event */
240 if (event==NULL) continue;
241
242 ++numberOfEvents;
243
244 eventT=event->eventType;
be9b25ed 245 if ((eventT == END_OF_RUN)||(eventT == END_OF_RUN_FILES))
246 {
247 delete event;
248 break;
249 }
250 if (eventT != PHYSICS_EVENT)
251 {
252 delete event;
253 continue;
254 }
134d9649 255
2825ba79 256 ++numberOfPhysicsEvent;
257
134d9649 258 rawReader = new AliRawReaderDate((void*)event);
259
2825ba79 260 if ( rawReader->GetRunNumber() != runNumber )
261 {
262 if ( runNumber != 0 )
263 {
264 cout << "Uh oh. That's bad... Changing of run number ???" << endl;
be9b25ed 265 delete event;
266 delete rawReader;
2825ba79 267 return -9999;
268 }
269 runNumber = rawReader->GetRunNumber();
270 }
271
33d94e07 272 // *without* using the MUONTRK event decoder, we update the number
273 // of events where we have information about MUONTRK.
274 // this should be what is called subevents in the logbook
275 // we do *not* use the MCH decoder on purpose, to not mistakenly
276 // believe there's no event if the data is corrupted (and thus the decoder
277 // "sees" nothing).
278
279 Bool_t mchThere(kFALSE);
280
281 for ( int iDDL = 0; iDDL < AliDAQ::NumberOfDdls("MUONTRK") && !mchThere; ++iDDL )
282 {
283 rawReader->Reset();
284 rawReader->Select("MUONTRK",iDDL,iDDL);
285 if (rawReader->ReadHeader() )
286 {
287 if (rawReader->GetEquipmentSize() ) mchThere = kTRUE;
288 }
289 }
290
291 if ( mchThere) ++numberOfEventsWithMCH;
292
293 rawReader->Reset();
294
295 // now do our real work with the MCH decoder
296
2825ba79 297 AliMUONRawStreamTrackerHP stream(rawReader);
298
299 stream.DisableWarnings();
2825ba79 300
301 oneEventData.Clear();
302
303 Int_t buspatchId;
304 UShort_t manuId;
305 UChar_t manuChannel;
306 UShort_t adc;
307
308 stream.First();
134d9649 309
2825ba79 310 while ( stream.Next(buspatchId,manuId,manuChannel,adc,kTRUE) )
311 {
312 AliMUONVCalibParam* one = static_cast<AliMUONVCalibParam*>(oneEventData.FindObject(buspatchId,manuId));
313
314 if (!one)
315 {
316 one = new AliMUONCalibParamNI(1,AliMpConstants::ManuNofChannels(),buspatchId,manuId);
317 oneEventData.Add(one);
318 }
319
320 one->SetValueAsInt(manuChannel,0,one->ValueAsInt(manuChannel,0)+1);
321 }
322
323 Bool_t badEvent = stream.HasPaddingError() || stream.HasGlitchError();
324
325 if ( !badEvent )
326 {
327 ++numberOfUsedEvents;
328 Add(accumulatedData,oneEventData);
329 }
330 else
331 {
332 ++numberOfBadEvents;
333 }
be9b25ed 334
be9b25ed 335 delete event;
336
337 delete rawReader;
338 }
2825ba79 339 }
340
341
33d94e07 342 cout << Form("%12d events processed : %12d physics %d used ones %d bad ones [ %d with MCH information ]",
343 numberOfEvents,numberOfPhysicsEvent,numberOfUsedEvents,numberOfBadEvents,numberOfEventsWithMCH) << endl;
2825ba79 344
345 ofstream fout(OUTPUT_FILE);
346
33d94e07 347 GenerateOutputFile(accumulatedData,fout,runNumber,numberOfUsedEvents,numberOfEventsWithMCH);
2825ba79 348
349 fout.close();
350
7aec9986 351 /* store the result file on FXS */
352 if (daqDA_FES_storeFile(OUTPUT_FILE,"OCCUPANCY")) return -9;
353
2825ba79 354#ifdef ALI_AMORE
355
4b50c4a8 356 if ( numberOfUsedEvents ) // do not update the AMORE pool with an empty object...
2825ba79 357 {
4b50c4a8 358 // Send occupancy store (as a big string) to the AMORE DB
359 amore::da::AmoreDA amoreDA(amore::da::AmoreDA::kSender);
360
361 ostringstream str;
362
33d94e07 363 GenerateOutputFile(accumulatedData,str,runNumber,numberOfUsedEvents,numberOfEventsWithMCH);
4b50c4a8 364
365 TObjString occupancyAsString(str.str().c_str());
366
7aec9986 367 cout << "will send to amore" << endl;
368
4b50c4a8 369 Int_t status = amoreDA.Send("Occupancy",&occupancyAsString);
370 if ( status )
371 {
372 cerr << "ERROR : Failed to write occupancies in the AMORE database : " << status << endl;
373 }
374 }
2825ba79 375
7aec9986 376#endif
377
2825ba79 378 timers.Stop();
379 printf("\nExecution time : R:%7.2fs C:%7.2fs\n", timers.RealTime(), timers.CpuTime());
380
381 return 0;
382}