Commit 8c4a2700 authored by positron cool guys's avatar positron cool guys
Browse files

added script to convert into multiplexed map micromegas

parent 4d4db6f3
#include <vector>
#ifdef __MAKECINT__
#pragma link C++ class vector<vector<short> >+;
#endif
//#pragma link C++ class vector<vector<short> >+;
#include <iostream>
#include <string>
using namespace std;
#include "Riostream.h"
#include "TH1.h"
#include "TH2.h"
#include "TF1.h"
#include "TH1D.h"
#include "TROOT.h"
#include "TCanvas.h"
#include "TRandom.h"
#include "TStyle.h"
#include "TLegend.h"
#include "TFile.h"
#include "TMath.h"
#include "TLatex.h"
#include "TBranch.h"
#include "TTree.h"
#include "TKey.h"
#include "TClass.h"
#include "TDirectory.h"
//#define sleontsi
//TFile *root_file;
#include "apv_raw.C"
#include "APV_RAW_PED.C"
apv_raw *apv_raw_obj;
APV_RAW_PED *apv_raw_ped;
void CopyDir(TDirectory *source) {
//copy all objects and subdirs of directory source as a subdir of the current directory
TDirectory *savdir = gDirectory;
TDirectory *adir = savdir->mkdir("config");
adir->cd();
//loop on all entries of this directory
TKey *key;
TIter nextkey(source->GetListOfKeys());
while ((key = (TKey*)nextkey())) {
const char *classname = key->GetClassName();
TClass *cl = gROOT->GetClass(classname);
if (!cl) continue;
if (cl->InheritsFrom(TDirectory::Class())) {
source->cd(key->GetName());
TDirectory *subdir = gDirectory;
adir->cd();
CopyDir(subdir);
adir->cd();
// }
// else if (cl->InheritsFrom(TTree::Class())) {
// TTree *T = (TTree*)source->Get(key->GetName());
// adir->cd();
// TTree *newT = T->CloneTree(-1,"fast");
// newT->Write();
} else {
source->cd();
TObject *obj = key->ReadObj();
TObjString *takis = new TObjString(obj->GetName());
savdir->cd();
takis->Write(key->GetName());
}
}
adir->SaveSelf(kTRUE);
savdir->cd();
}
int main(int argc, char *argv[]){
if(argc != 2)
{
std::cout << "Usage: ./map_multiplex [inputRootFile]" << std::endl;
std::exit(-1);
}
std::string file(argv[1]);
TFile *root_file = new TFile(file.c_str(),"READ");
apv_raw_obj = new apv_raw((TTree*)root_file->Get("apv_raw"));
apv_raw_ped = new APV_RAW_PED((TTree*)root_file->Get("apv_raw_ped"));
int entries = (apv_raw_obj->fChain)->GetEntries();
int entries_ped = (apv_raw_ped->fChain)->GetEntries();
std::size_t found_run = file.find("run");
std::size_t found_dotroot = file.find(".root");
std::string run_name = file.substr(found_run,found_dotroot-found_run);
std::string path = file.substr(0,found_run);
std::string new_file = path+run_name+"_mapped.root";
TFile *ntuple = new TFile(new_file.c_str(), "RECREATE");
TTree *aux;
aux = new TTree("apv_raw", "apv_raw");
ULong64_t write_evt;
ULong64_t write_evt_temp=0;
UInt_t write_error;
Int_t write_daqTimeSec;
Int_t write_daqTimeMicroSec;
Int_t write_srsTimeStamp;
UInt_t write_srsTrigger;
std::vector<unsigned int> write_srsFec;
std::vector<unsigned int> write_srsChip;
std::vector<unsigned int> write_srsChan;
std::vector<string> write_mmChamber;
std::vector<int> write_mmLayer;
std::vector<char> write_mmReadout;
std::vector<int> write_mmStrip;
std::vector<vector<short> > write_raw_q_parse;
std::vector<short> charge_info_to_be_puched_back_temp;
aux->Branch("evt" , &write_evt );
aux->Branch("error" , &write_error );
aux->Branch("daqTimeSec" , &write_daqTimeSec );
aux->Branch("daqTimeMicroSec" , &write_daqTimeMicroSec);
aux->Branch("srsTimeStamp" , &write_srsTimeStamp );
aux->Branch("srsTrigger" , &write_srsTrigger );
aux->Branch("srsFec" , &write_srsFec );
aux->Branch("srsChip" , &write_srsChip );
aux->Branch("srsChan" , &write_srsChan );
aux->Branch("mmChamber" , &write_mmChamber );
aux->Branch("mmLayer" , &write_mmLayer );
aux->Branch("mmReadout" , &write_mmReadout );
aux->Branch("mmStrip" , &write_mmStrip );
aux->Branch("raw_q" , &write_raw_q_parse );
// loop on multiplexed map file X
int numOfLines_mapx=320;
double first_mapx[numOfLines_mapx], second_mapx[numOfLines_mapx], third_mapx[numOfLines_mapx], fourth_mapx[numOfLines_mapx], fifth_mapx[numOfLines_mapx];
ifstream InputRead_mapx ("Mapping_new_1.txt");
for (int i=0; i<numOfLines_mapx; i++) {
InputRead_mapx >> first_mapx[i] >> second_mapx[i] >> third_mapx[i] >> fourth_mapx[i] >> fifth_mapx[i];
std::cout<< first_mapx[i] <<" "<< second_mapx[i] <<" "<< third_mapx[i] <<" "<< fourth_mapx[i] <<" "<< fifth_mapx[i] <<" "<<std::endl;
} // loop on map file
// loop on multiplexed map file X
// loop on multiplexed map file Y
int numOfLines_mapy=320;
double first_mapy[numOfLines_mapy], second_mapy[numOfLines_mapy], third_mapy[numOfLines_mapy], fourth_mapy[numOfLines_mapy], fifth_mapy[numOfLines_mapy];
ifstream InputRead_mapy ("Mapping_new_2.txt");
for (int i=0; i<numOfLines_mapy; i++) {
InputRead_mapy >> first_mapy[i] >> second_mapy[i] >> third_mapy[i] >> fourth_mapy[i] >> fifth_mapy[i];
} // loop on map file
// loop on multiplexed map file Y
for(int iEntry=0; iEntry<entries; iEntry++) {
if(iEntry%200==0)
cout << "\r" << (double)iEntry/(double)entries*100 << "\% processed" << flush;
(apv_raw_obj->fChain)->GetEntry(iEntry);
write_srsFec.clear();
write_srsChip.clear();
write_srsChan.clear();
write_mmChamber.clear();
write_mmLayer.clear();
write_mmReadout.clear();
write_mmStrip.clear();
write_raw_q_parse.clear();
write_evt = apv_raw_obj->evt;
write_error = apv_raw_obj->error;
write_daqTimeSec = apv_raw_obj->daqTimeSec;
write_daqTimeMicroSec = apv_raw_obj->daqTimeMicroSec;
write_srsTimeStamp = apv_raw_obj->srsTimeStamp;
write_srsTrigger = apv_raw_obj->srsTrigger;
for (int j=0; j<(int)apv_raw_obj->srsFec->size(); j++) {
if(apv_raw_obj->mmChamber->at(j)=="Chamber_1"){
//X remapping
if(apv_raw_obj->mmReadout->at(j)==49){
for (int p=0; p<numOfLines_mapx; p++) {
if(apv_raw_obj->srsChan->at(j)==(int)first_mapx[p]-2)
{
charge_info_to_be_puched_back_temp.clear();
for(int i_sample=0; i_sample<apv_raw_obj->raw_q->at(j).size(); i_sample++)
{
charge_info_to_be_puched_back_temp.push_back(apv_raw_obj->raw_q->at(j).at(i_sample));
}
write_raw_q_parse.push_back(charge_info_to_be_puched_back_temp);
write_mmStrip.push_back(fifth_mapx[p]);
write_srsChan.push_back(apv_raw_obj->srsChan->at(j));
write_srsFec.push_back(apv_raw_obj->srsFec->at(j));
write_srsChip.push_back(apv_raw_obj->srsChip->at(j));
write_mmChamber.push_back(apv_raw_obj->mmChamber->at(j));
write_mmLayer.push_back(apv_raw_obj->mmLayer->at(j));
write_mmReadout.push_back(apv_raw_obj->mmReadout->at(j));
}
}
}
//Y remapping
else if(apv_raw_obj->mmReadout->at(j)==48){
for (int p=0; p<numOfLines_mapy; p++) {
if(apv_raw_obj->srsChan->at(j)==(int)first_mapy[p]-2)
{
charge_info_to_be_puched_back_temp.clear();
for(int i_sample=0; i_sample<apv_raw_obj->raw_q->at(j).size(); i_sample++)
{
charge_info_to_be_puched_back_temp.push_back(apv_raw_obj->raw_q->at(j).at(i_sample));
}
write_raw_q_parse.push_back(charge_info_to_be_puched_back_temp);
write_mmStrip.push_back(fifth_mapy[p]);
write_srsChan.push_back(apv_raw_obj->srsChan->at(j));
write_srsFec.push_back(apv_raw_obj->srsFec->at(j));
write_srsChip.push_back(apv_raw_obj->srsChip->at(j));
write_mmChamber.push_back(apv_raw_obj->mmChamber->at(j));
write_mmLayer.push_back(apv_raw_obj->mmLayer->at(j));
write_mmReadout.push_back(apv_raw_obj->mmReadout->at(j));
}
}
}
}
else {
charge_info_to_be_puched_back_temp.clear();
for(int i_sample=0; i_sample<apv_raw_obj->raw_q->at(j).size(); i_sample++)
{
charge_info_to_be_puched_back_temp.push_back(apv_raw_obj->raw_q->at(j).at(i_sample));
}
write_raw_q_parse.push_back(charge_info_to_be_puched_back_temp);
write_mmStrip.push_back(apv_raw_obj->mmStrip->at(j));
write_srsChan.push_back(apv_raw_obj->srsChan->at(j));
write_srsFec.push_back(apv_raw_obj->srsFec->at(j));
write_srsChip.push_back(apv_raw_obj->srsChip->at(j));
write_mmChamber.push_back(apv_raw_obj->mmChamber->at(j));
write_mmLayer.push_back(apv_raw_obj->mmLayer->at(j));
write_mmReadout.push_back(apv_raw_obj->mmReadout->at(j));
}
}
aux->Fill();
}
// make second tree
TTree *aux_ped;
aux_ped = new TTree("apv_raw_ped", "apv_raw_ped");
ULong64_t write_pedevt;
UInt_t write_pederror;
Int_t write_peddaqTimeSec;
Int_t write_peddaqTimeMicroSec;
Int_t write_pedsrsTimeStamp;
UInt_t write_pedsrsTrigger;
std::vector<unsigned int> write_pedsrsFec;
std::vector<unsigned int> write_pedsrsChip;
std::vector<unsigned int> write_pedsrsChan;
std::vector<string> write_pedmmChamber;
std::vector<int> write_pedmmLayer;
std::vector<char> write_pedmmReadout;
std::vector<int> write_pedmmStrip;
std::vector<double> write_pedped_mean;
std::vector<double> write_pedped_stdev;
std::vector<double> write_pedped_sigma;
aux_ped->Branch("evt" , &write_pedevt );
aux_ped->Branch("error" , &write_pederror );
aux_ped->Branch("daqTimeSec" , &write_peddaqTimeSec );
aux_ped->Branch("daqTimeMicroSec" , &write_peddaqTimeMicroSec);
aux_ped->Branch("srsTimeStamp" , &write_pedsrsTimeStamp );
aux_ped->Branch("srsTrigger" , &write_pedsrsTrigger );
aux_ped->Branch("srsFec" , &write_pedsrsFec );
aux_ped->Branch("srsChip" , &write_pedsrsChip );
aux_ped->Branch("srsChan" , &write_pedsrsChan );
aux_ped->Branch("mmChamber" , &write_pedmmChamber );
aux_ped->Branch("mmLayer" , &write_pedmmLayer );
aux_ped->Branch("mmReadout" , &write_pedmmReadout );
aux_ped->Branch("mmStrip" , &write_pedmmStrip );
aux_ped->Branch("ped_mean" , &write_pedped_mean );
aux_ped->Branch("ped_stdev" , &write_pedped_stdev );
aux_ped->Branch("ped_sigma" , &write_pedped_sigma );
cout << endl;
for(int iEntry=0; iEntry<entries_ped; iEntry++) {
if(iEntry%200==0)
cout << std::setprecision(2) << "\r" << (double)iEntry/(double)entries_ped*100 << "\% processed" << flush;
(apv_raw_ped->fChain)->GetEntry(iEntry);
write_pedsrsFec.clear();
write_pedsrsChip.clear();
write_pedsrsChan.clear();
write_pedmmChamber.clear();
write_pedmmLayer.clear();
write_pedmmReadout.clear();
write_pedmmStrip.clear();
write_pedevt = apv_raw_ped->evt;
write_pederror = apv_raw_ped->error;
write_peddaqTimeSec = apv_raw_ped->daqTimeSec;
write_peddaqTimeMicroSec = apv_raw_ped->daqTimeMicroSec;
write_pedsrsTimeStamp = apv_raw_ped->srsTimeStamp;
write_pedsrsTrigger = apv_raw_ped->srsTrigger;
for (int j=0; j<(int)apv_raw_ped->srsFec->size(); j++) {
write_pedsrsFec.push_back(apv_raw_ped->srsFec->at(j));
write_pedsrsChip.push_back(apv_raw_ped->srsChip->at(j));
write_pedsrsChan.push_back(apv_raw_ped->srsChan->at(j));
write_pedmmChamber.push_back(apv_raw_ped->mmChamber->at(j));
write_pedmmLayer.push_back(apv_raw_ped->mmLayer->at(j));
write_pedmmReadout.push_back(apv_raw_ped->mmReadout->at(j));
write_pedmmStrip.push_back(apv_raw_ped->mmStrip->at(j));
write_pedped_mean.push_back(apv_raw_ped->ped_mean->at(j));
write_pedped_stdev.push_back(apv_raw_ped->ped_stdev->at(j));
write_pedped_sigma.push_back(apv_raw_ped->ped_sigma->at(j));
}
aux_ped->Fill();
}
ntuple->cd();
TDirectory *target = gDirectory;
target->cd();
CopyDir(root_file);
target->cd();
ntuple->Write();
ntuple->Close();
cout << endl;
return 0;
}
2 0 1 1 1
4 0 1 1 2
6 0 1 1 3
8 0 1 1 4
10 0 1 1 5
12 0 1 1 6
14 0 1 1 7
16 0 1 1 8
18 0 1 1 9
20 0 1 1 10
22 0 1 1 11
24 0 1 1 12
26 0 1 1 13
28 0 1 1 14
30 0 1 1 15
32 0 1 1 16
34 0 1 1 17
36 0 1 1 18
38 0 1 1 19
40 0 1 1 20
42 0 1 1 21
44 0 1 1 22
46 0 1 1 23
48 0 1 1 24
50 0 1 1 25
52 0 1 1 26
54 0 1 1 27
56 0 1 1 28
58 0 1 1 29
60 0 1 1 30
62 0 1 1 31
64 0 1 1 32
66 0 1 1 33
68 0 1 1 34
70 0 1 1 35
72 0 1 1 36
74 0 1 1 37
76 0 1 1 38
78 0 1 1 39
80 0 1 1 40
82 0 1 1 41
84 0 1 1 42
86 0 1 1 43
88 0 1 1 44
90 0 1 1 45
92 0 1 1 46
94 0 1 1 47
96 0 1 1 48
98 0 1 1 49
100 0 1 1 50
102 0 1 1 51
104 0 1 1 52
106 0 1 1 53
108 0 1 1 54
110 0 1 1 55
112 0 1 1 56
114 0 1 1 57
116 0 1 1 58
118 0 1 1 59
120 0 1 1 60
122 0 1 1 61
124 0 1 1 62
126 0 1 1 63
128 0 1 1 64
2 0 1 1 65
16 0 1 1 66
30 0 1 1 67
44 0 1 1 68
58 0 1 1 69
72 0 1 1 70
86 0 1 1 71
100 0 1 1 72
114 0 1 1 73
128 0 1 1 74
14 0 1 1 75
28 0 1 1 76
42 0 1 1 77
56 0 1 1 78
70 0 1 1 79
84 0 1 1 80
98 0 1 1 81
112 0 1 1 82
126 0 1 1 83
12 0 1 1 84
26 0 1 1 85
40 0 1 1 86
54 0 1 1 87
68 0 1 1 88
82 0 1 1 89
96 0 1 1 90
110 0 1 1 91
124 0 1 1 92
10 0 1 1 93
24 0 1 1 94
38 0 1 1 95
52 0 1 1 96
66 0 1 1 97
80 0 1 1 98
94 0 1 1 99
108 0 1 1 100
122 0 1 1 101
8 0 1 1 102
22 0 1 1 103
36 0 1 1 104
50 0 1 1 105
64 0 1 1 106
78 0 1 1 107
92 0 1 1 108
106 0 1 1 109
120 0 1 1 110
6 0 1 1 111
20 0 1 1 112
34 0 1 1 113
48 0 1 1 114
62 0 1 1 115
76 0 1 1 116
90 0 1 1 117
104 0 1 1 118
118 0 1 1 119
4 0 1 1 120
18 0 1 1 121
32 0 1 1 122
46 0 1 1 123
60 0 1 1 124
74 0 1 1 125
88 0 1 1 126
102 0 1 1 127
116 0 1 1 128
2 0 1 1 129
28 0 1 1 130
54 0 1 1 131
80 0 1 1 132
106 0 1 1 133
4 0 1 1 134
30 0 1 1 135
56 0 1 1 136
82 0 1 1 137
108 0 1 1 138
6 0 1 1 139
32 0 1 1 140
58 0 1 1 141
84 0 1 1 142
110 0 1 1 143
8 0 1 1 144
34 0 1 1 145
60 0 1 1 146
86 0 1 1 147
112 0 1 1 148
10 0 1 1 149
36 0 1 1 150
62 0 1 1 151
88 0 1 1 152
114 0 1 1 153
12 0 1 1 154
38 0 1 1 155
64 0 1 1 156
90 0 1 1 157
116 0 1 1 158
14 0 1 1 159
40 0 1 1 160
66 0 1 1 161
92 0 1 1 162
118 0 1 1 163
16 0 1 1 164
42 0 1 1 165
68 0 1 1 166
94 0 1 1 167
120 0 1 1 168
18 0 1 1 169
44 0 1 1 170
70 0 1 1 171
96 0 1 1 172
122 0 1 1 173
20 0 1 1 174
46 0 1 1 175
72 0 1 1 176
98 0 1 1 177
124 0 1 1 178
22 0 1 1 179
48 0 1 1 180
74 0 1 1 181
100 0 1 1 182
126 0 1 1 183
24 0 1 1 184
50 0 1 1 185
76 0 1 1 186
102 0 1 1 187
128 0 1 1 188
26 0 1 1 189
52 0 1 1 190
78 0 1 1 191
104 0 1 1 192
2 0 1 1 193
40 0 1 1 194
78 0 1 1 195
116 0 1 1 196
26 0 1 1 197
64 0 1 1 198
102 0 1 1 199
12 0 1 1 200
50 0 1 1 201
88 0 1 1 202
126 0 1 1 203
36 0 1 1 204
74 0 1 1 205
112 0 1 1 206
22 0 1 1 207
60 0 1 1 208
98 0 1 1 209
8 0 1 1 210
46 0 1 1 211
84 0 1 1 212
122 0 1 1 213
32 0 1 1 214
70 0 1 1 215
108 0 1 1 216
18 0 1 1 217
56 0 1 1 218
94 0 1 1 219
4 0 1 1 220
42 0 1 1 221
80 0 1 1 222
118 0 1 1 223
28 0 1 1 224
66 0 1 1 225
104 0 1 1 226
14 0 1 1 227
52 0 1 1 228
90 0 1 1 229
128 0 1 1 230
38 0 1 1 231
76 0 1 1 232
114 0 1 1 233
24 0 1 1 234
62 0 1 1 235
100 0 1 1 236
10 0 1 1 237
48 0 1 1 238
86 0 1 1 239
124 0 1 1 240
34 0 1 1 241
72 0 1 1 242
110 0 1 1 243
20 0 1 1 244
58 0 1 1 245
96 0 1 1 246
6 0 1 1 247
44 0 1 1 248
82 0 1 1 249
120 0 1 1 250
30 0 1 1 251
68 0 1 1 252
106 0 1 1 253
16 0 1 1 254
54 0 1 1 255
92 0 1 1 256
2 0 1 1 257
52 0 1 1 258
102 0 1 1 259
24 0 1 1 260
74 0 1 1 261
124 0 1 1 262
46 0 1 1 263
96 0 1 1 264
18 0 1 1 265
68 0 1 1 266
118 0 1 1 267
40 0 1 1 268
90 0 1 1 269
12 0 1 1 270
62 0 1 1 271
112 0 1 1 272
34 0 1 1 273
84 0 1 1 274
6 0 1 1 275
56 0 1 1 276
106 0 1 1 277
28 0 1 1 278
78 0 1 1 279