CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
DeDxDiscriminatorLearnerFromCalibTree.cc
Go to the documentation of this file.
1 // -*- C++ -*-
2 //
3 // Package: DeDxDiscriminatorLearnerFromCalibTree
4 // Class: DeDxDiscriminatorLearnerFromCalibTree
5 //
13 //
14 // Original Author: Loic Quertenmont(querten)
15 // Created: Mon October 20 10:09:02 CEST 2008
16 //
17 
18 
19 // system include files
20 #include <memory>
21 
23 
24 //#include "DataFormats/TrackReco/interface/DeDxData.h"
27 
31 
32 using namespace reco;
33 using namespace std;
34 using namespace edm;
35 
37 {
38 std::cout << "TEST 0 " << endl;
39 
40  P_Min = iConfig.getParameter<double> ("P_Min" );
41  P_Max = iConfig.getParameter<double> ("P_Max" );
42  P_NBins = iConfig.getParameter<int> ("P_NBins");
43  Path_Min = iConfig.getParameter<double> ("Path_Min" );
44  Path_Max = iConfig.getParameter<double> ("Path_Max" );
45  Path_NBins = iConfig.getParameter<int> ("Path_NBins");
46  Charge_Min = iConfig.getParameter<double> ("Charge_Min" );
47  Charge_Max = iConfig.getParameter<double> ("Charge_Max" );
48  Charge_NBins = iConfig.getParameter<int> ("Charge_NBins");
49 
50  MinTrackTMomentum = iConfig.getUntrackedParameter<double> ("minTrackMomentum" , 5.0);
51  MaxTrackTMomentum = iConfig.getUntrackedParameter<double> ("maxTrackMomentum" , 99999.0);
52  MinTrackEta = iConfig.getUntrackedParameter<double> ("minTrackEta" , -5.0);
53  MaxTrackEta = iConfig.getUntrackedParameter<double> ("maxTrackEta" , 5.0);
54  MaxNrStrips = iConfig.getUntrackedParameter<unsigned>("maxNrStrips" , 255);
55  MinTrackHits = iConfig.getUntrackedParameter<unsigned>("MinTrackHits" , 4);
56 
57  HistoFile = iConfig.getUntrackedParameter<string> ("HistoFile" , "out.root");
58 
59  VInputFiles = iConfig.getParameter<vector<string> > ("InputFiles");
60 
61 std::cout << "TEST 1 " << endl;
62 
63 
64  useCalibration = iConfig.getUntrackedParameter<bool>("UseCalibration", false);
65  m_calibrationPath = iConfig.getUntrackedParameter<string>("calibrationPath");
66 
67 std::cout << "TEST 2 " << endl;
68 
69 }
70 
71 
73 
74 std::cout << "TEST Z " << endl;
75 }
76 
77 // ------------ method called once each job just before starting event loop ------------
78 
80 {
81 std::cout << "TEST 3 " << endl;
82 
83 // Charge_Vs_Path = new TH2F ("Charge_Vs_Path" , "Charge_Vs_Path" , 24, 0.2, 1.4, 250, 0, 5000);
84  Charge_Vs_Path = new TH3F ("Charge_Vs_Path" , "Charge_Vs_Path" , P_NBins, P_Min, P_Max, Path_NBins, Path_Min, Path_Max, Charge_NBins, Charge_Min, Charge_Max);
85 
86 std::cout << "TEST A " << endl;
87 
89  iSetup.get<TrackerDigiGeometryRecord>().get( tkGeom );
90  m_tracker = tkGeom.product();
91 
92  auto const & Det = tkGeom->dets();
93  for(unsigned int i=0;i<Det.size();i++){
94  DetId Detid = Det[i]->geographicalId();
95  int SubDet = Detid.subdetId();
96 
97  if( SubDet == StripSubdetector::TIB || SubDet == StripSubdetector::TID ||
98  SubDet == StripSubdetector::TOB || SubDet == StripSubdetector::TEC ){
99 
100  auto DetUnit = dynamic_cast<StripGeomDetUnit const*> (Det[i]);
101  if(!DetUnit)continue;
102 
103  const StripTopology& Topo = DetUnit->specificTopology();
104  unsigned int NAPV = Topo.nstrips()/128;
105 
106  double Eta = DetUnit->position().basicVector().eta();
107  double R = DetUnit->position().basicVector().transverse();
108  double Thick = DetUnit->surface().bounds().thickness();
109  for(unsigned int j=0;j<NAPV;j++){
110 
111  stAPVInfo* APV = new stAPVInfo;
112  APV->DetId = Detid.rawId();
113  APV->SubDet = SubDet;
114  APV->Eta = Eta;
115  APV->R = R;
116  APV->Thickness = Thick;
117  APV->APVId = j;
118  APVsColl[APV->DetId<<3 | APV->APVId] = APV;
119  }
120  }
121  }
122 
123 std::cout << "TEST B " << endl;
124 
125 
127 std::cout << "TEST C " << endl;
128 
129 
131 std::cout << "TEST D " << endl;
132 
133 }
134 
135 // ------------ method called once each job just after ending the event loop ------------
136 
137 
139 {
140  TFile* Output = new TFile(HistoFile.c_str(), "RECREATE");
141  Charge_Vs_Path->Write();
142  Output->Write();
143  Output->Close();
144  TFile* Input = new TFile(HistoFile.c_str() );
145  Charge_Vs_Path = (TH3F*)(Input->FindObjectAny("Charge_Vs_Path"))->Clone();
146  Input->Close();
147 }
148 
150 {
151 }
152 
153 
155 {
156  unsigned int NEvent = 0;
157  for(unsigned int i=0;i<VInputFiles.size();i++){
158  printf("Openning file %3i/%3i --> %s\n",i+1, (int)VInputFiles.size(), (char*)(VInputFiles[i].c_str())); fflush(stdout);
159  TChain* tree = new TChain("gainCalibrationTree/tree");
160  tree->Add(VInputFiles[i].c_str());
161 
162  TString EventPrefix("");
163  TString EventSuffix("");
164 
165  TString TrackPrefix("track");
166  TString TrackSuffix("");
167 
168  TString CalibPrefix("GainCalibration");
169  TString CalibSuffix("");
170 
171  unsigned int eventnumber = 0; tree->SetBranchAddress(EventPrefix + "event" + EventSuffix, &eventnumber , NULL);
172  unsigned int runnumber = 0; tree->SetBranchAddress(EventPrefix + "run" + EventSuffix, &runnumber , NULL);
173  std::vector<bool>* TrigTech = 0; tree->SetBranchAddress(EventPrefix + "TrigTech" + EventSuffix, &TrigTech , NULL);
174 
175  std::vector<double>* trackchi2ndof = 0; tree->SetBranchAddress(TrackPrefix + "chi2ndof" + TrackSuffix, &trackchi2ndof , NULL);
176  std::vector<float>* trackp = 0; tree->SetBranchAddress(TrackPrefix + "momentum" + TrackSuffix, &trackp , NULL);
177  std::vector<float>* trackpt = 0; tree->SetBranchAddress(TrackPrefix + "pt" + TrackSuffix, &trackpt , NULL);
178  std::vector<double>* tracketa = 0; tree->SetBranchAddress(TrackPrefix + "eta" + TrackSuffix, &tracketa , NULL);
179  std::vector<double>* trackphi = 0; tree->SetBranchAddress(TrackPrefix + "phi" + TrackSuffix, &trackphi , NULL);
180  std::vector<unsigned int>* trackhitsvalid = 0; tree->SetBranchAddress(TrackPrefix + "hitsvalid" + TrackSuffix, &trackhitsvalid, NULL);
181 
182  std::vector<int>* trackindex = 0; tree->SetBranchAddress(CalibPrefix + "trackindex" + CalibSuffix, &trackindex , NULL);
183  std::vector<unsigned int>* rawid = 0; tree->SetBranchAddress(CalibPrefix + "rawid" + CalibSuffix, &rawid , NULL);
184  std::vector<unsigned short>* firststrip = 0; tree->SetBranchAddress(CalibPrefix + "firststrip" + CalibSuffix, &firststrip , NULL);
185  std::vector<unsigned short>* nstrips = 0; tree->SetBranchAddress(CalibPrefix + "nstrips" + CalibSuffix, &nstrips , NULL);
186  std::vector<unsigned int>* charge = 0; tree->SetBranchAddress(CalibPrefix + "charge" + CalibSuffix, &charge , NULL);
187  std::vector<float>* path = 0; tree->SetBranchAddress(CalibPrefix + "path" + CalibSuffix, &path , NULL);
188  std::vector<unsigned char>* amplitude = 0; tree->SetBranchAddress(CalibPrefix + "amplitude" + CalibSuffix, &amplitude , NULL);
189  std::vector<double>* gainused = 0; tree->SetBranchAddress(CalibPrefix + "gainused" + CalibSuffix, &gainused , NULL);
190 
191  printf("Number of Events = %i + %i = %i\n",NEvent,(unsigned int)tree->GetEntries(),(unsigned int)(NEvent+tree->GetEntries()));NEvent+=tree->GetEntries();
192  printf("Progressing Bar :0%% 20%% 40%% 60%% 80%% 100%%\n");
193  printf("Looping on the Tree :");
194  int TreeStep = tree->GetEntries()/50;if(TreeStep<=1)TreeStep=1;
195  for (unsigned int ientry = 0; ientry < tree->GetEntries(); ientry++) {
196  if(ientry%TreeStep==0){printf(".");fflush(stdout);}
197  tree->GetEntry(ientry);
198 
199  int FirstAmplitude = 0;
200  for(unsigned int c=0;c<(*path).size();c++){
201  FirstAmplitude+=(*nstrips)[c];
202  int t = (*trackindex)[c];
203  if((*trackpt)[t]<5)continue;
204  if((*trackhitsvalid)[t]<5)continue;
205 
206  int Charge = 0;
207  if(useCalibration){
208  stAPVInfo* APV = APVsColl[((*rawid)[c]<<3) | (unsigned int)((*firststrip)[c]/128)];
209  for(unsigned int s=0;s<(*nstrips)[c];s++){
210  int StripCharge = (*amplitude)[FirstAmplitude-(*nstrips)[c]+s];
211  if(StripCharge<254){
212  StripCharge=(int)(StripCharge/APV->CalibGain);
213  if(StripCharge>=1024){
214  StripCharge = 255;
215  }else if(StripCharge>=254){
216  StripCharge = 254;
217  }
218  }
219  Charge += StripCharge;
220  }
221  }else{
222  Charge = (*charge)[c];
223  }
224 
225 // printf("ChargeDifference = %i Vs %i with Gain = %f\n",(*charge)[c],Charge,Gains[(*rawid)[c]]);
226  double ClusterChargeOverPath = ( (double) Charge )/(*path)[c] ;
227  Charge_Vs_Path->Fill((*trackp)[t],(*path)[c],ClusterChargeOverPath);
228  }
229  }printf("\n");
230  }
231 }
232 
233 
235 {
236 std::cout << "TEST X " << endl;
237 
238 
239 // if( strcmp(algoMode.c_str(),"MultiJob")==0)return NULL;
240 
243  Charge_Vs_Path->GetNbinsX(), Charge_Vs_Path->GetXaxis()->GetXmin(), Charge_Vs_Path->GetXaxis()->GetXmax(),
244  Charge_Vs_Path->GetNbinsY(), Charge_Vs_Path->GetYaxis()->GetXmin(), Charge_Vs_Path->GetYaxis()->GetXmax(),
245  Charge_Vs_Path->GetNbinsZ(), Charge_Vs_Path->GetZaxis()->GetXmin(), Charge_Vs_Path->GetZaxis()->GetXmax());
246 
247 std::cout << "TEST Y " << endl;
248 
249 
250  for(int ix=0; ix<=Charge_Vs_Path->GetNbinsX()+1; ix++){
251  for(int iy=0; iy<=Charge_Vs_Path->GetNbinsY()+1; iy++){
252  for(int iz=0; iz<=Charge_Vs_Path->GetNbinsZ()+1; iz++){
253  obj->setBinContent(ix, iy, iz, Charge_Vs_Path->GetBinContent(ix,iy, iz) );
254 // if(Charge_Vs_Path->GetBinContent(ix,iy)!=0)printf("%i %i %i --> %f\n",ix,iy, iz, Charge_Vs_Path->GetBinContent(ix,iy,iz));
255  }
256  }
257  }
258 
259 std::cout << "TEST W " << endl;
260 
261  return obj;
262 }
263 
264 
265 
267  if(!useCalibration)return;
268 
269 
270  TChain* t1 = new TChain("SiStripCalib/APVGain");
271  t1->Add(m_calibrationPath.c_str());
272 
273  unsigned int tree_DetId;
274  unsigned char tree_APVId;
275  double tree_Gain;
276 
277  t1->SetBranchAddress("DetId" ,&tree_DetId );
278  t1->SetBranchAddress("APVId" ,&tree_APVId );
279  t1->SetBranchAddress("Gain" ,&tree_Gain );
280 
281  for (unsigned int ientry = 0; ientry < t1->GetEntries(); ientry++) {
282  t1->GetEntry(ientry);
283  stAPVInfo* APV = APVsColl[(tree_DetId<<3) | (unsigned int)tree_APVId];
284  APV->CalibGain = tree_Gain;
285  }
286 
287 }
288 
289 
290 //define this as a plug-in
T getParameter(std::string const &) const
virtual int nstrips() const =0
T getUntrackedParameter(std::string const &, T const &) const
int i
Definition: DBlmapReader.cc:9
#define Input(cl)
Definition: vmac.h:188
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:17
#define NULL
Definition: scimark2.h:8
double charge(const std::vector< uint8_t > &Ampls)
uint32_t rawId() const
get the raw id
Definition: DetId.h:43
int iEvent
Definition: GenABIO.cc:230
tuple path
else: Piece not in the list, fine.
Histogram3D< double > HistogramD3D
Definition: Histogram3D.h:187
PhysicsTools::Calibration::HistogramD3D * getNewObject()
int j
Definition: DBlmapReader.cc:9
int subdetId() const
get the contents of the subdetector field (not cast into any detector&#39;s numbering enum) ...
Definition: DetId.h:37
Definition: DetId.h:18
const T & get() const
Definition: EventSetup.h:55
T const * product() const
Definition: ESHandle.h:62
string const
Definition: compareJSON.py:14
__gnu_cxx::hash_map< unsigned int, stAPVInfo *, __gnu_cxx::hash< unsigned int >, isEqual > APVsColl
#define Output(cl)
Definition: vmac.h:192
tuple cout
Definition: gather_cfg.py:121
virtual void algoAnalyze(const edm::Event &, const edm::EventSetup &)
void setBinContent(int bin, Value_t value)