]>
Commit | Line | Data |
---|---|---|
eb35e591 | 1 | /* |
2e0441d1 | 2 | Contact: cvetan.cheshkov@cern.ch |
3 | Link: http://alisoft.cern.ch/viewvc/trunk/ITS/ITSSPDVertexDiamondda.cxx?root=AliRoot&view=log , /afs/cern.ch/user/c/cheshkov/public/ITS/VD_da_test.date , /afs/cern.ch/user/c/cheshkov/public/08000058338016.30.root.date.gz | |
4 | Reference Run: 58338 | |
5 | Run Type: PHYSICS | |
6 | DA Type: MON | |
7 | Number of events needed: 100 | |
8 | Input Files: GRP/Geometry/Data , ITS/Align/Data , spd_noisy_ocdb , spd_dead_ocdb , TRIGGER/SPD/PITConditions (all the files are taken from SPD daqDetDB) | |
9 | Output Files: SPDVertexDiamondDA.root | |
10 | Trigger types used: PHYSICS, SPD-F0 | |
11 | */ | |
eb35e591 | 12 | |
97a75e92 | 13 | #define OUTPUT_FILE "SPDVertexDiamondDA.root" |
eb35e591 | 14 | |
15 | extern "C" { | |
16 | #include "daqDA.h" | |
17 | } | |
18 | ||
19 | #include "event.h" | |
20 | #include "monitor.h" | |
21 | ||
2e0441d1 | 22 | #define ALI_AMORE |
23 | ||
55c5e86d | 24 | #ifdef ALI_AMORE |
25 | #include <AmoreDA.h> | |
308c2f7c | 26 | //int amore::da::Updated(char const*) {} |
55c5e86d | 27 | #endif |
28 | ||
eb35e591 | 29 | #include <TPluginManager.h> |
30 | #include <TROOT.h> | |
cf0b1cea | 31 | #include <TH1.h> |
32 | #include <TH2.h> | |
694ea942 | 33 | #include <TPaveText.h> |
6bf5b296 | 34 | #include <TSystem.h> |
ee0a8262 | 35 | #include <TGeoGlobalMagField.h> |
eb35e591 | 36 | |
e1f6be44 | 37 | #include "AliLog.h" |
ee0a8262 | 38 | #include "AliMagF.h" |
eb35e591 | 39 | #include "AliRawReaderDate.h" |
eb35e591 | 40 | #include "AliCDBManager.h" |
cf0b1cea | 41 | #include "AliITSMeanVertexer.h" |
eb35e591 | 42 | |
43 | int main(int argc, char **argv) { | |
44 | ||
2e0441d1 | 45 | gROOT->GetPluginManager()->AddHandler("TVirtualStreamerInfo", |
46 | "*", | |
47 | "TStreamerInfo", | |
48 | "RIO", | |
49 | "TStreamerInfo()"); | |
50 | ||
51 | int status; | |
52 | if (argc<2) { | |
53 | printf("Wrong number of arguments\n"); | |
54 | return -1; | |
55 | } | |
56 | // get mean vertex quality cuts | |
57 | status = daqDA_DB_getFile("ITSSPD_VertexQualityTuning_DA.config","./ITSSPD_VertexQualityTuning_DA.config"); | |
58 | if (status) { | |
59 | printf("Failed to get config file (ITSSPD_VertexQualityTuning_DA.config) from DAQ DB, status=%d\n", status); | |
60 | return -1; | |
61 | } | |
62 | /* open the config file and retrieve running parameters */ | |
63 | Float_t errX = -1; | |
64 | Float_t r = -1; | |
65 | UInt_t minClInner = 999 ; | |
66 | UInt_t maxClInner = 999 ; | |
67 | Int_t nEvFirstLoop = 0; | |
68 | Int_t nEvAUTOSAVE = 0; | |
d3d3859c | 69 | Int_t zFiducialRegion=0; |
70 | ||
2e0441d1 | 71 | char name[10][10]; |
72 | ||
73 | FILE *fpConfig = fopen("ITSSPD_VertexQualityTuning_DA.config","r"); | |
d3d3859c | 74 | fscanf(fpConfig,"%s %f\n %s %f\n %s %d\n %s %d \n %s %d \n %s %d \n %s %d",&name[0], &errX, &name[1], &r, &name[2], &minClInner,&name[3], &maxClInner, &name[4],&nEvFirstLoop,&name[5],&nEvAUTOSAVE,&name[6],&zFiducialRegion); |
2e0441d1 | 75 | fclose(fpConfig); |
76 | ||
d3d3859c | 77 | printf("\n\n Mean Vertex quality cuts : \n- errX = %f\n- r = %f\n- minSPD0 = %d maxSPD0 = %d\n- nEventsFirstLoop = %d nEventsAUTOSAVE = %d \n- zFiducialRegion = %d\n\n\n",errX,r,minClInner,maxClInner,nEvFirstLoop,nEvAUTOSAVE,zFiducialRegion); |
2e0441d1 | 78 | |
79 | /* define data source : this is argument 1 */ | |
80 | status=monitorSetDataSource( argv[1] ); | |
81 | if (status!=0) { | |
82 | printf("monitorSetDataSource() failed : %s\n",monitorDecodeError(status)); | |
83 | return -1; | |
84 | } | |
85 | ||
86 | /* declare monitoring program */ | |
87 | status=monitorDeclareMp( __FILE__ ); | |
88 | if (status!=0) { | |
89 | printf("monitorDeclareMp() failed : %s\n",monitorDecodeError(status)); | |
90 | return -1; | |
91 | } | |
92 | ||
93 | /* define wait event timeout - 1s max */ | |
94 | monitorSetNowait(); | |
95 | monitorSetNoWaitNetworkTimeout(1000); | |
96 | ||
97 | /* log start of process */ | |
98 | printf("Vertex-Diamond SPD DA started\n"); | |
99 | ||
100 | /* init some counters */ | |
101 | int nevents_with_vertex = 0; | |
102 | int nevents_physics=0; | |
103 | int nevents_total=0; | |
104 | ||
105 | struct eventHeaderStruct *event; | |
106 | eventTypeType eventT; | |
107 | ||
108 | // Get run number | |
109 | if (getenv("DATE_RUN_NUMBER")==0) { | |
110 | printf("DATE_RUN_NUMBER not properly set.\n"); | |
111 | return -1; | |
112 | } | |
113 | int runNr = atoi(getenv("DATE_RUN_NUMBER")); | |
114 | ||
115 | // Get the necessary OCDB files from the DAQ detector DB | |
116 | if (gSystem->AccessPathName("localOCDB/GRP/Geometry/Data",kFileExists)) { | |
117 | if (gSystem->mkdir("localOCDB/GRP/Geometry/Data",kTRUE) != 0) { | |
118 | printf("Failed to create directory: localOCDB/GRP/Geometry/Data"); | |
119 | return -1; | |
694ea942 | 120 | } |
2e0441d1 | 121 | } |
122 | status = daqDA_DB_getFile("GRP/Geometry/Data","localOCDB/GRP/Geometry/Data/Run0_999999999_v0_s0.root"); | |
123 | if (status) { | |
124 | printf("Failed to get geometry file (GRP/Geometry/Data) from DAQdetDB, status=%d\n", status); | |
125 | return -1; | |
126 | } | |
127 | ||
128 | if (gSystem->AccessPathName("localOCDB/ITS/Align/Data",kFileExists)) { | |
129 | if (gSystem->mkdir("localOCDB/ITS/Align/Data",kTRUE) != 0) { | |
130 | printf("Failed to create directory: localOCDB/ITS/Align/Data"); | |
131 | return -1; | |
eb35e591 | 132 | } |
2e0441d1 | 133 | } |
134 | status = daqDA_DB_getFile("ITS/Align/Data","localOCDB/ITS/Align/Data/Run0_999999999_v0_s0.root"); | |
135 | if (status) { | |
136 | printf("Failed to get its-alignment file (ITS/Align/Data) from DAQdetDB, status=%d\n", status); | |
137 | return -1; | |
138 | } | |
139 | ||
140 | if (gSystem->AccessPathName("localOCDB/ITS/Calib/SPDNoisy",kFileExists)) { | |
141 | if (gSystem->mkdir("localOCDB/ITS/Calib/SPDNoisy",kTRUE) != 0) { | |
142 | printf("Failed to create directory: localOCDB/ITS/Calib/SPDNoisy"); | |
143 | return -1; | |
6bf5b296 | 144 | } |
2e0441d1 | 145 | } |
146 | status = daqDA_DB_getFile("spd_noisy_ocdb","localOCDB/ITS/Calib/SPDNoisy/Run0_999999999_v0_s0.root"); | |
147 | if (status) { | |
148 | printf("Failed to get spd file (spd_noisy_ocdb) from DAQdetDB, status=%d\n", status); | |
149 | return -1; | |
150 | } | |
151 | ||
152 | if (gSystem->AccessPathName("localOCDB/ITS/Calib/SPDDead",kFileExists)) { | |
153 | if (gSystem->mkdir("localOCDB/ITS/Calib/SPDDead",kTRUE) != 0) { | |
154 | printf("Failed to create directory: localOCDB/ITS/Calib/SPDDead"); | |
155 | return -1; | |
6bf5b296 | 156 | } |
2e0441d1 | 157 | } |
158 | status = daqDA_DB_getFile("spd_dead_ocdb","localOCDB/ITS/Calib/SPDDead/Run0_999999999_v0_s0.root"); | |
159 | if (status) { | |
160 | printf("Failed to get spd file (spd_dead_ocdb) from DAQdetDB, status=%d\n", status); | |
161 | return -1; | |
162 | } | |
163 | ||
164 | if (gSystem->AccessPathName("localOCDB/ITS/Calib/SPDSparseDead",kFileExists)) { | |
165 | if (gSystem->mkdir("localOCDB/ITS/Calib/SPDSparseDead",kTRUE) != 0) { | |
166 | printf("Failed to create directory: localOCDB/ITS/Calib/SPDSparseDead"); | |
167 | return -1; | |
6bf5b296 | 168 | } |
2e0441d1 | 169 | } |
170 | ||
171 | status = daqDA_DB_getFile("spd_sparsedead_ocdb","localOCDB/ITS/Calib/SPDSparseDead/Run0_999999999_v0_s0.root"); | |
172 | if (status) { | |
173 | printf("Failed to get spd file (spd_sparsedead_ocdb) from DAQdetDB, status=%d\n", status); | |
174 | return -1; | |
175 | } | |
176 | ||
177 | if (gSystem->AccessPathName("localOCDB/TRIGGER/SPD/PITConditions",kFileExists)) { | |
178 | if (gSystem->mkdir("localOCDB/TRIGGER/SPD/PITConditions",kTRUE) != 0) { | |
179 | printf("Failed to create directory: localOCDB/TRIGGER/SPD/PITConditions"); | |
180 | return -1; | |
6bf5b296 | 181 | } |
2e0441d1 | 182 | } |
183 | status = daqDA_DB_getFile("TRIGGER/SPD/PITConditions","localOCDB/TRIGGER/SPD/PITConditions/Run0_999999999_v0_s0.root"); | |
184 | if (status) { | |
185 | printf("Failed to get spd trigger file (TRIGGER/SPD/PITConditions) from DAQdetDB, status=%d\n", status); | |
186 | return -1; | |
187 | } | |
188 | ||
189 | status = daqDA_DB_getFile("mfchebKGI_sym.root","localOCDB/mfchebKGI_sym.root"); | |
190 | if (status) { | |
191 | printf("Failed to get spd file (mfchebKGI_sym.root) from DAQdetDB, status=%d\n", status); | |
192 | return -1; | |
193 | } | |
194 | ||
195 | // Global initializations | |
196 | ||
197 | // The B filed is required in AliITSClusterFinderV2SPD | |
198 | // for the Lorentz angle correction. B set to 0. | |
199 | TGeoGlobalMagField::Instance()->SetField(new AliMagF("Maps","Maps", 0., 0., AliMagF::k5kGUniform,AliMagF::kBeamTypeAA,-1,2,15,"localOCDB/mfchebKGI_sym.root")); | |
200 | AliLog::SetGlobalLogLevel(AliLog::kError); | |
201 | AliCDBManager *man = AliCDBManager::Instance(); | |
202 | man->SetDefaultStorage("local://localOCDB"); | |
203 | man->SetRun(runNr); | |
204 | ||
205 | // Init mean vertexer | |
206 | AliITSMeanVertexer *mv = new AliITSMeanVertexer(); | |
4f40f207 | 207 | |
208 | // Optionally change the Z fiducial region here (default +/- 40 cm | |
d3d3859c | 209 | mv->SetZFiducialRegion(zFiducialRegion); |
4f40f207 | 210 | |
2e0441d1 | 211 | if (!mv->Init()) { |
212 | printf("Initialization of mean vertexer object failed ! Check the log for details"); | |
213 | return -1; | |
214 | } | |
215 | ||
216 | mv->SetCutOnErrX(errX); | |
217 | mv->SetCutOnR(r); | |
218 | mv->SetCutOnCls(minClInner,maxClInner); | |
219 | ||
220 | // Initialization of AMORE sender | |
221 | #ifdef ALI_AMORE | |
222 | amore::da::AmoreDA vtxAmore(amore::da::AmoreDA::kSender); | |
223 | #endif | |
a33265ea | 224 | Int_t amore_status = 0; |
2e0441d1 | 225 | /* main loop (infinite) */ |
226 | for(;;) { | |
6bf5b296 | 227 | |
2e0441d1 | 228 | /* check shutdown condition */ |
229 | if (daqDA_checkShutdown()) {break;} | |
69ebd58d | 230 | |
2e0441d1 | 231 | /* get next event (blocking call until timeout) */ |
232 | status=monitorGetEventDynamic((void **)&event); | |
233 | if (status==MON_ERR_EOF) { | |
234 | printf ("End of File detected\n"); | |
235 | break; /* end of monitoring file has been reached */ | |
69ebd58d | 236 | } |
237 | ||
2e0441d1 | 238 | if (status!=0) { |
239 | printf("monitorGetEventDynamic() failed : %s\n",monitorDecodeError(status)); | |
240 | break; | |
2a16d0d6 | 241 | } |
bdffed96 | 242 | |
2e0441d1 | 243 | /* retry if got no event */ |
244 | if (event==NULL) { | |
245 | continue; | |
37add1d1 | 246 | } |
eb35e591 | 247 | |
2e0441d1 | 248 | nevents_total++; |
249 | eventT=event->eventType; | |
250 | switch (event->eventType){ | |
251 | ||
252 | /* START OF RUN */ | |
253 | case START_OF_RUN: | |
254 | break; | |
255 | /* END START OF RUN */ | |
256 | ||
257 | /* END OF RUN */ | |
258 | case END_OF_RUN: | |
259 | break; | |
260 | ||
261 | case PHYSICS_EVENT: | |
262 | nevents_physics++; | |
263 | AliRawReader *rawReader = new AliRawReaderDate((void*)event); | |
264 | ||
265 | // Run mean-vertexer reco | |
266 | if (mv->Reconstruct(rawReader)) nevents_with_vertex++; | |
267 | if(nevents_physics < nEvFirstLoop) continue; | |
268 | // Auto save | |
269 | if ((nevents_physics%nEvAUTOSAVE) == 0) { | |
270 | TH2F *histo = ((TH2F*)mv->GetVertexXY()); | |
271 | histo->SetStats(kFALSE); | |
272 | histo->SetTitle(""); | |
273 | histo->GetListOfFunctions()->SetOwner(kTRUE); | |
274 | if(histo->GetListOfFunctions()->GetEntries()<1) histo->GetListOfFunctions()->Add(new TPaveText(-5,4.5,5.,6.2,"br")); | |
275 | for(Int_t i=0; i<histo->GetListOfFunctions()->GetEntries(); i++){ | |
276 | TString funcName = histo->GetListOfFunctions()->At(i)->ClassName(); | |
277 | if(funcName.Contains("TPaveText")){ | |
278 | TPaveText *p = (TPaveText*)histo->GetListOfFunctions()->At(i); | |
279 | p->Clear(); | |
280 | p->AddText(Form("%f events with vertex (%i out of %i processed events)",((Double_t)nevents_with_vertex)/((Double_t)nevents_physics),nevents_with_vertex,nevents_physics)); | |
281 | p->AddText(Form("%f events with good vertex (%i out of %i events with vertex)",histo->GetEntries()/((Double_t)nevents_with_vertex),(Int_t)histo->GetEntries(),nevents_with_vertex)); | |
282 | } | |
283 | } | |
97a75e92 | 284 | mv->WriteVertices(OUTPUT_FILE); |
55c5e86d | 285 | #ifdef ALI_AMORE |
2e0441d1 | 286 | // send the histos to AMORE pool |
a33265ea | 287 | amore_status=vtxAmore.Send(mv->GetVertexXY()->GetName(),mv->GetVertexXY()); |
288 | if(amore_status) printf("AMORE XY send status: %d\n",amore_status); | |
2e0441d1 | 289 | TH1D *hProj = mv->GetVertexXY()->ProjectionX(); |
64cb91fb | 290 | amore_status=vtxAmore.Send(Form("%s_ProjX",mv->GetVertexXY()->GetName()),hProj); |
a33265ea | 291 | if(amore_status) printf("AMORE X send status: %d\n",amore_status); |
2e0441d1 | 292 | if(hProj) delete hProj; |
293 | hProj = mv->GetVertexXY()->ProjectionY(); | |
64cb91fb | 294 | amore_status=vtxAmore.Send(Form("%s_ProjY",mv->GetVertexXY()->GetName()),hProj); |
a33265ea | 295 | if(amore_status) printf("AMORE Y send status: %d\n",amore_status); |
2e0441d1 | 296 | if(hProj) hProj->Delete(); |
a33265ea | 297 | amore_status=vtxAmore.Send(mv->GetVertexZ()->GetName(),mv->GetVertexZ()); |
298 | if(amore_status) printf("AMORE Z send status: %d\n",amore_status); | |
55c5e86d | 299 | #endif |
eb35e591 | 300 | } |
301 | ||
2e0441d1 | 302 | delete rawReader; |
303 | } | |
eb35e591 | 304 | |
2e0441d1 | 305 | /* free resources */ |
306 | free(event); | |
6bf5b296 | 307 | |
2e0441d1 | 308 | /* exit when last event received, no need to wait for TERM signal */ |
309 | if (eventT==END_OF_RUN) { | |
310 | printf("EOR event detected\n"); | |
311 | break; | |
eb35e591 | 312 | } |
2e0441d1 | 313 | } |
314 | ||
315 | TH2F *histo = ((TH2F*)mv->GetVertexXY()); | |
316 | histo->SetStats(kFALSE); | |
317 | histo->SetTitle(""); | |
318 | histo->GetListOfFunctions()->SetOwner(kTRUE); | |
319 | if(histo->GetListOfFunctions()->GetEntries()<1) histo->GetListOfFunctions()->Add(new TPaveText(-5,4.5,5.,6.2,"br")); | |
320 | for(Int_t i=0; i<histo->GetListOfFunctions()->GetEntries(); i++){ | |
321 | TString funcName = histo->GetListOfFunctions()->At(i)->ClassName(); | |
322 | if(funcName.Contains("TPaveText")){ | |
323 | TPaveText *p = (TPaveText*)histo->GetListOfFunctions()->At(i); | |
324 | p->Clear(); | |
325 | p->AddText(Form("%f events with vertex (%i out of %i processed events)",((Double_t)nevents_with_vertex)/((Double_t)nevents_physics),nevents_with_vertex,nevents_physics)); | |
326 | p->AddText(Form("%f events with good vertex (%i out of %i events with vertex)",histo->GetEntries()/((Double_t)nevents_with_vertex),(Int_t)histo->GetEntries(),nevents_with_vertex)); | |
694ea942 | 327 | } |
2e0441d1 | 328 | } |
329 | mv->WriteVertices(OUTPUT_FILE); | |
eb35e591 | 330 | |
55c5e86d | 331 | #ifdef ALI_AMORE |
2e0441d1 | 332 | // send the histos to AMORE pool |
a33265ea | 333 | amore_status=vtxAmore.Send(mv->GetVertexXY()->GetName(),mv->GetVertexXY()); |
334 | if(amore_status) printf("AMORE XY send status: %d\n",amore_status); | |
2e0441d1 | 335 | TH1D *hProj = mv->GetVertexXY()->ProjectionX(); |
64cb91fb | 336 | amore_status=vtxAmore.Send(Form("%s_ProjX",mv->GetVertexXY()->GetName()),hProj); |
a33265ea | 337 | if(amore_status) printf("AMORE X send status: %d\n",amore_status); |
2e0441d1 | 338 | if(hProj) delete hProj; |
339 | hProj = mv->GetVertexXY()->ProjectionY(); | |
64cb91fb | 340 | amore_status=vtxAmore.Send(Form("%s_ProjY",mv->GetVertexXY()->GetName()),hProj); |
a33265ea | 341 | if(amore_status) printf("AMORE Y send status: %d\n",amore_status); |
2e0441d1 | 342 | if(hProj) hProj->Delete(); |
a33265ea | 343 | amore_status=vtxAmore.Send(mv->GetVertexZ()->GetName(),mv->GetVertexZ()); |
344 | if(amore_status) printf("AMORE Z send status: %d\n",amore_status); | |
55c5e86d | 345 | #endif |
346 | ||
2e0441d1 | 347 | delete mv; |
eb35e591 | 348 | |
2e0441d1 | 349 | /* write report */ |
350 | printf("Run #%s, received %d events with vertex, out of %d physics and out of %d total events\n",getenv("DATE_RUN_NUMBER"),nevents_with_vertex,nevents_physics,nevents_total); | |
eb35e591 | 351 | |
2e0441d1 | 352 | status=0; |
eb35e591 | 353 | |
2e0441d1 | 354 | /* export file to FXS */ |
355 | if (daqDA_FES_storeFile(OUTPUT_FILE, "VertexDiamond")) { | |
356 | status=-2; | |
357 | } | |
358 | ||
359 | return status; | |
eb35e591 | 360 | } |