67 #include "TObjString.h"
77 #include <ext/hash_map>
84 using namespace __gnu_cxx;
85 using __gnu_cxx::hash_map;
123 virtual void algoEndJob ();
126 void algoAnalyzeTheTree();
127 void algoComputeMPVandGain();
129 void getPeakOfLandau(TH1* InputHisto,
double* FitResults,
double LowRange=50,
double HighRange=5400);
130 bool IsGoodLandauFit(
double* FitResults);
133 void MakeCalibrationMap();
183 template <
class T>
bool operator () (
const T& PseudoDetId1,
const T& PseudoDetId2) {
return PseudoDetId1==PseudoDetId2; }
187 __gnu_cxx::hash_map<unsigned int, stAPVGain*, __gnu_cxx::hash<unsigned int>,
isEqual >
APVsColl;
238 vector<GeomDet*>
Det = tkGeom->dets();
242 if(!gainHandle.
isValid()){printf(
"\n#####################\n\nERROR --> gainHandle is not valid\n\n#####################\n\n");
exit(0);}
245 for(
unsigned int i=0;
i<gainHandle->getNumberOfTags();
i++){
246 printf(
"Reccord %i --> Rcd Name = %s Label Name = %s\n",
i,gainHandle->getRcdName(
i).c_str(), gainHandle->getLabelName(
i).c_str());
254 unsigned int Index=0;
255 for(
unsigned int i=0;
i<Det.size();
i++){
256 DetId Detid = Det[
i]->geographicalId();
263 if(!DetUnit)
continue;
266 unsigned int NAPV = Topo.
nstrips()/128;
267 for(
unsigned int j=0;
j<NAPV;
j++){
292 if(gainHandle->getNumberOfTags()!=2){printf(
"ERROR: NUMBER OF GAIN TAG IS EXPECTED TO BE 2\n");fflush(stdout);
exit(0);};
332 FitResults[0] = -0.5;
334 FitResults[2] = -0.5;
336 FitResults[4] = -0.5;
341 TF1* MyLandau =
new TF1(
"MyLandau",
"landau",LowRange, HighRange);
342 MyLandau->SetParameter(1,300);
343 InputHisto->Fit(
"MyLandau",
"0QR WW");
346 FitResults[0] = MyLandau->GetParameter(1);
347 FitResults[1] = MyLandau->GetParError(1);
348 FitResults[2] = MyLandau->GetParameter(2);
349 FitResults[3] = MyLandau->GetParError(2);
350 FitResults[4] = MyLandau->GetChisquare() / MyLandau->GetNDF();
356 if(FitResults[0] < 2 )
return false;
366 printf(
"Openning file %3i/%3i --> %s\n",
i+1, (
int)
VInputFiles.size(), (
char*)(
VInputFiles[
i].c_str())); fflush(stdout);
367 TChain*
tree =
new TChain(
"gainCalibrationTree/tree");
370 TString EventPrefix(
"");
371 TString EventSuffix(
"");
373 TString TrackPrefix(
"track");
374 TString TrackSuffix(
"");
376 TString CalibPrefix(
"GainCalibration");
377 TString CalibSuffix(
"");
379 unsigned int eventnumber = 0; tree->SetBranchAddress(EventPrefix +
"event" + EventSuffix, &eventnumber ,
NULL);
380 unsigned int runnumber = 0; tree->SetBranchAddress(EventPrefix +
"run" + EventSuffix, &runnumber ,
NULL);
381 std::vector<bool>* TrigTech = 0; tree->SetBranchAddress(EventPrefix +
"TrigTech" + EventSuffix, &TrigTech ,
NULL);
383 std::vector<double>* trackchi2ndof = 0; tree->SetBranchAddress(TrackPrefix +
"chi2ndof" + TrackSuffix, &trackchi2ndof ,
NULL);
384 std::vector<float>* trackp = 0; tree->SetBranchAddress(TrackPrefix +
"momentum" + TrackSuffix, &trackp ,
NULL);
385 std::vector<float>* trackpt = 0; tree->SetBranchAddress(TrackPrefix +
"pt" + TrackSuffix, &trackpt ,
NULL);
386 std::vector<double>* tracketa = 0; tree->SetBranchAddress(TrackPrefix +
"eta" + TrackSuffix, &tracketa ,
NULL);
387 std::vector<double>* trackphi = 0; tree->SetBranchAddress(TrackPrefix +
"phi" + TrackSuffix, &trackphi ,
NULL);
388 std::vector<unsigned int>* trackhitsvalid = 0; tree->SetBranchAddress(TrackPrefix +
"hitsvalid" + TrackSuffix, &trackhitsvalid,
NULL);
390 std::vector<int>* trackindex = 0; tree->SetBranchAddress(CalibPrefix +
"trackindex" + CalibSuffix, &trackindex ,
NULL);
391 std::vector<unsigned int>* rawid = 0; tree->SetBranchAddress(CalibPrefix +
"rawid" + CalibSuffix, &rawid ,
NULL);
392 std::vector<float>* localdirx = 0; tree->SetBranchAddress(CalibPrefix +
"localdirx" + CalibSuffix, &localdirx ,
NULL);
393 std::vector<float>* localdiry = 0; tree->SetBranchAddress(CalibPrefix +
"localdiry" + CalibSuffix, &localdiry ,
NULL);
394 std::vector<float>* localdirz = 0; tree->SetBranchAddress(CalibPrefix +
"localdirz" + CalibSuffix, &localdirz ,
NULL);
395 std::vector<unsigned short>* firststrip = 0; tree->SetBranchAddress(CalibPrefix +
"firststrip" + CalibSuffix, &firststrip ,
NULL);
396 std::vector<unsigned short>* nstrips = 0; tree->SetBranchAddress(CalibPrefix +
"nstrips" + CalibSuffix, &nstrips ,
NULL);
397 std::vector<bool>* saturation = 0; tree->SetBranchAddress(CalibPrefix +
"saturation" + CalibSuffix, &saturation ,
NULL);
398 std::vector<bool>* overlapping = 0; tree->SetBranchAddress(CalibPrefix +
"overlapping" + CalibSuffix, &overlapping ,
NULL);
399 std::vector<bool>* farfromedge = 0; tree->SetBranchAddress(CalibPrefix +
"farfromedge" + CalibSuffix, &farfromedge ,
NULL);
400 std::vector<unsigned int>*
charge = 0; tree->SetBranchAddress(CalibPrefix +
"charge" + CalibSuffix, &charge ,
NULL);
401 std::vector<float>*
path = 0; tree->SetBranchAddress(CalibPrefix +
"path" + CalibSuffix, &path ,
NULL);
402 std::vector<float>* chargeoverpath = 0; tree->SetBranchAddress(CalibPrefix +
"chargeoverpath" + CalibSuffix, &chargeoverpath,
NULL);
403 std::vector<unsigned char>* amplitude = 0; tree->SetBranchAddress(CalibPrefix +
"amplitude" + CalibSuffix, &litude ,
NULL);
404 std::vector<double>* gainused = 0; tree->SetBranchAddress(CalibPrefix +
"gainused" + CalibSuffix, &gainused ,
NULL);
407 printf(
"Number of Events = %i + %i = %i\n",
NEvent,(
unsigned int)tree->GetEntries(),(
unsigned int)(
NEvent+tree->GetEntries()));
408 printf(
"Progressing Bar :0%% 20%% 40%% 60%% 80%% 100%%\n");
409 printf(
"Looping on the Tree :");
410 int TreeStep = tree->GetEntries()/50;
if(TreeStep<=1)TreeStep=1;
411 for (
unsigned int ientry = 0; ientry < tree->GetEntries(); ientry++) {
413 if(ientry%TreeStep==0){printf(
".");fflush(stdout);}
414 tree->GetEntry(ientry);
422 unsigned int FirstAmplitude=0;
423 for(
unsigned int i=0;
i<(*chargeoverpath).size();
i++){
424 FirstAmplitude+=(*nstrips)[
i];
425 int TI = (*trackindex)[
i];
432 if((*farfromedge)[
i] ==
false )
continue;
433 if((*overlapping)[
i] ==
true )
continue;
456 bool Saturation =
false;
457 for(
unsigned int s=0;
s<(*nstrips)[
i];
s++){
458 int StripCharge = (*amplitude)[FirstAmplitude-(*nstrips)[
i]+
s];
462 if(StripCharge>1024){
465 }
else if(StripCharge>254){
469 Charge += StripCharge;
473 Charge = (*charge)[
i];
478 double ClusterChargeOverPath = ( (double) Charge )/(*path)[
i] ;
479 if(
Validation) {ClusterChargeOverPath/=(*gainused)[
i];}
496 }
else if(APV->
Eta>0){
514 double FitResults[5];
515 double MPVmean = 300;
517 printf(
"Progressing Bar :0%% 20%% 40%% 60%% 80%% 100%%\n");
518 printf(
"Fitting Charge Distribution :");
521 if(I%TreeStep==0){printf(
".");fflush(stdout);}
530 int SecondAPVId = APV->
APVId;
531 if(SecondAPVId%2==0){ SecondAPVId = SecondAPVId+1; }
else{ SecondAPVId = SecondAPVId-1; }
534 if(Proj2){Proj->Add(Proj2,1);
delete Proj2;}
536 for(
unsigned int i=0;
i<6;
i++){
537 __gnu_cxx::hash_map<unsigned int, stAPVGain*, __gnu_cxx::hash<unsigned int>,
isEqual >::iterator tmpit;
544 if(Proj2){Proj->Add(Proj2,1);
delete Proj2;}
552 APV->
FitMPV = FitResults[0];
580 unsigned int tree_Index;
581 unsigned int tree_Bin;
582 unsigned int tree_DetId;
583 unsigned char tree_APVId;
584 unsigned char tree_SubDet;
591 float tree_Thickness;
593 float tree_FitMPVErr;
595 float tree_FitWidthErr;
596 float tree_FitChi2NDF;
598 double tree_PrevGain;
599 double tree_NEntries;
603 MyTree =
tfs->
make<TTree> (
"APVGain",
"APVGain");
604 MyTree->Branch(
"Index" ,&tree_Index ,
"Index/i");
605 MyTree->Branch(
"Bin" ,&tree_Bin ,
"Bin/i");
606 MyTree->Branch(
"DetId" ,&tree_DetId ,
"DetId/i");
607 MyTree->Branch(
"APVId" ,&tree_APVId ,
"APVId/b");
608 MyTree->Branch(
"SubDet" ,&tree_SubDet ,
"SubDet/b");
609 MyTree->Branch(
"x" ,&tree_x ,
"x/F");
610 MyTree->Branch(
"y" ,&tree_y ,
"y/F");
611 MyTree->Branch(
"z" ,&tree_z ,
"z/F");
612 MyTree->Branch(
"Eta" ,&tree_Eta ,
"Eta/F");
613 MyTree->Branch(
"R" ,&tree_R ,
"R/F");
614 MyTree->Branch(
"Phi" ,&tree_Phi ,
"Phi/F");
615 MyTree->Branch(
"Thickness" ,&tree_Thickness ,
"Thickness/F");
616 MyTree->Branch(
"FitMPV" ,&tree_FitMPV ,
"FitMPV/F");
617 MyTree->Branch(
"FitMPVErr" ,&tree_FitMPVErr ,
"FitMPVErr/F");
618 MyTree->Branch(
"FitWidth" ,&tree_FitWidth ,
"FitWidth/F");
619 MyTree->Branch(
"FitWidthErr" ,&tree_FitWidthErr,
"FitWidthErr/F");
620 MyTree->Branch(
"FitChi2NDF" ,&tree_FitChi2NDF ,
"FitChi2NDF/F");
621 MyTree->Branch(
"Gain" ,&tree_Gain ,
"Gain/D");
622 MyTree->Branch(
"PrevGain" ,&tree_PrevGain ,
"PrevGain/D");
623 MyTree->Branch(
"NEntries" ,&tree_NEntries ,
"NEntries/D");
624 MyTree->Branch(
"isMasked" ,&tree_isMasked ,
"isMasked/O");
628 fprintf(Gains,
"NEvents = %i\n",
NEvent);
629 fprintf(Gains,
"NTracks = %i\n",
NTrack);
630 fprintf(Gains,
"NClusters = %i\n",
NCluster);
631 fprintf(Gains,
"Number of APVs = %lu\n",static_cast<unsigned long>(
APVsColl.size()));
632 fprintf(Gains,
"GoodFits = %i BadFits = %i ratio = %f\n",
GOOD,
BAD,(100.0*
GOOD)/(
GOOD+
BAD));
636 if(APV==
NULL)
continue;
640 tree_Index = APV->
Index;
642 tree_DetId = APV->
DetId;
643 tree_APVId = APV->
APVId;
644 tree_SubDet = APV->
SubDet;
652 tree_FitMPV = APV->
FitMPV;
656 tree_FitChi2NDF = APV->
FitChi2;
657 tree_Gain = APV->
Gain;
674 std::vector<float>* theSiStripVector =
NULL;
675 unsigned int PreviousDetId = 0;
679 if(APV==
NULL){ printf(
"Bug\n");
continue; }
680 if(APV->
DetId != PreviousDetId){
681 if(theSiStripVector!=
NULL){
683 if ( !obj->
put(PreviousDetId,range) ) printf(
"Bug to put detId = %i\n",PreviousDetId);
685 theSiStripVector =
new std::vector<float>;
686 PreviousDetId = APV->
DetId;
688 theSiStripVector->push_back(APV->
Gain);
690 if(theSiStripVector!=
NULL){
692 if ( !obj->
put(PreviousDetId,range) ) printf(
"Bug to put detId = %i\n",PreviousDetId);
707 TChain* t1 =
new TChain(
"SiStripCalib/APVGain");
710 unsigned int tree_DetId;
711 unsigned char tree_APVId;
714 t1->SetBranchAddress(
"DetId" ,&tree_DetId );
715 t1->SetBranchAddress(
"APVId" ,&tree_APVId );
716 t1->SetBranchAddress(
"Gain" ,&tree_Gain );
718 for (
unsigned int ientry = 0; ientry < t1->GetEntries(); ientry++) {
719 t1->GetEntry(ientry);
T getParameter(std::string const &) const
virtual int nstrips() const =0
T getUntrackedParameter(std::string const &, T const &) const
unsigned int MinTrackHits
T y() const
Cartesian y coordinate.
edm::Service< TFileService > tfs
T x() const
Cartesian x coordinate.
virtual void algoEndJob()
~SiStripGainFromCalibTree()
#define DEFINE_FWK_MODULE(type)
virtual void algoBeginJob(const edm::EventSetup &)
SiStripGainFromCalibTree(const edm::ParameterSet &)
TH2F * Charge_Vs_PathlengthTECP2
Geom::Phi< T > phi() const
virtual const StripTopology & specificTopology() const
Returns a reference to the strip proxy topology.
TH2F * Charge_Vs_PathlengthTECP1
void MakeCalibrationMap()
double MaxTrackChiOverNdf
bool put(const uint32_t &detID, Range input)
uint32_t rawId() const
get the raw id
virtual float thickness() const =0
TH2F * Charge_Vs_PathlengthTOB
std::vector< stAPVGain * > APVsCollOrdered
__gnu_cxx::hash_map< unsigned int, stAPVGain *, __gnu_cxx::hash< unsigned int >, isEqual > APVsColl
void algoComputeMPVandGain()
const Surface::PositionType & position() const
The position (origin of the R.F.)
TH2F * Charge_Vs_PathlengthTIB
T z() const
Cartesian z coordinate.
bool IsGoodLandauFit(double *FitResults)
TH2F * Charge_Vs_PathlengthTIDM
TH2F * Charge_Vs_Index_Absolute
std::pair< ContainerIterator, ContainerIterator > Range
const std::complex< double > I
int subdetId() const
get the contents of the subdetector field (not cast into any detector's numbering enum) ...
TH2F * Charge_Vs_PathlengthTECM2
vector< string > VInputFiles
SiStripApvGain * getNewObject()
const Bounds & bounds() const
void getPeakOfLandau(TH1 *InputHisto, double *FitResults, double LowRange=50, double HighRange=5400)
void algoAnalyzeTheTree()
virtual void algoAnalyze(const edm::Event &, const edm::EventSetup &)
const BoundPlane & surface() const
The nominal surface of the GeomDet.
T transverse() const
Another name for perp()
T * make() const
make new ROOT object
TH2F * Charge_Vs_PathlengthTECM1
const BasicVectorType & basicVector() const
TH2F * Charge_Vs_PathlengthTIDP